mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-07-23 14:33:28 +00:00
In hybrid mode ai artifacts can optionally automatically run. This is useful for cases where you may want to embed a survey and so on. Additionally, artifacts now allow for better fidelity around display: <div class="ai-artifact" data-ai-artifact-id="501" data-ai-artifact-height="300px" data-ai-artifact-autorun data-ai-artifact-seamless></div> User can supply height and seamless mode to be seamlessly rendered with no box shadow and show full screen button.
76 lines
2.2 KiB
Plaintext
76 lines
2.2 KiB
Plaintext
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"
|
|
);
|
|
|
|
const artifactVersion = artifactElement.getAttribute(
|
|
"data-ai-artifact-version"
|
|
);
|
|
|
|
const artifactHeight = artifactElement.getAttribute(
|
|
"data-ai-artifact-height"
|
|
);
|
|
|
|
const autorun =
|
|
artifactElement.getAttribute("data-ai-artifact-autorun") ||
|
|
artifactElement.hasAttribute("data-ai-artifact-autorun");
|
|
|
|
const seamless =
|
|
artifactElement.getAttribute("data-ai-artifact-seamless") ||
|
|
artifactElement.hasAttribute("data-ai-artifact-seamless");
|
|
|
|
const dataAttributes = {};
|
|
for (const attr of artifactElement.attributes) {
|
|
if (
|
|
attr.name.startsWith("data-") &&
|
|
attr.name !== "data-ai-artifact-id" &&
|
|
attr.name !== "data-ai-artifact-version" &&
|
|
attr.name !== "data-ai-artifact-height" &&
|
|
attr.name !== "data-ai-artifact-autorun" &&
|
|
attr.name !== "data-ai-artifact-seamless"
|
|
) {
|
|
dataAttributes[attr.name] = attr.value;
|
|
}
|
|
}
|
|
|
|
helper.renderGlimmer(
|
|
artifactElement,
|
|
<template>
|
|
<AiArtifact
|
|
@artifactId={{artifactId}}
|
|
@artifactVersion={{artifactVersion}}
|
|
@artifactHeight={{artifactHeight}}
|
|
@autorun={{autorun}}
|
|
@seamless={{seamless}}
|
|
@dataAttributes={{dataAttributes}}
|
|
/>
|
|
</template>
|
|
);
|
|
}
|
|
);
|
|
},
|
|
{
|
|
id: "ai-artifact",
|
|
onlyStream: true,
|
|
}
|
|
);
|
|
}
|
|
|
|
export default {
|
|
name: "ai-artifact",
|
|
initialize() {
|
|
withPluginApi("0.8.7", initializeAiArtifacts);
|
|
},
|
|
};
|