2024-11-18 17:22:39 -05:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import AiArtifact from "../discourse/components/ai-artifact";
|
|
|
|
|
|
|
|
function initializeAiArtifacts(api) {
|
|
|
|
api.decorateCookedElement(
|
|
|
|
(element, helper) => {
|
|
|
|
if (!helper.renderGlimmer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[...element.querySelectorAll("div.ai-artifact")].forEach(
|
|
|
|
(artifactElement) => {
|
|
|
|
const artifactId = artifactElement.getAttribute(
|
|
|
|
"data-ai-artifact-id"
|
|
|
|
);
|
|
|
|
|
2024-12-02 15:23:31 -05:00
|
|
|
const artifactVersion = artifactElement.getAttribute(
|
|
|
|
"data-ai-artifact-version"
|
|
|
|
);
|
|
|
|
|
2024-11-18 17:22:39 -05:00
|
|
|
helper.renderGlimmer(artifactElement, <template>
|
2024-12-02 15:23:31 -05:00
|
|
|
<AiArtifact
|
|
|
|
@artifactId={{artifactId}}
|
|
|
|
@artifactVersion={{artifactVersion}}
|
|
|
|
/>
|
2024-11-18 17:22:39 -05:00
|
|
|
</template>);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "ai-artifact",
|
|
|
|
onlyStream: true,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "ai-artifact",
|
|
|
|
initialize() {
|
|
|
|
withPluginApi("0.8.7", initializeAiArtifacts);
|
|
|
|
},
|
|
|
|
};
|