MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / createArtifactTools

Function createArtifactTools

desktop/runtime/artifact-tools.ts:42–141  ·  view source on GitHub ↗
(adapter: ArtifactToolAdapter)

Source from the content-addressed store, hash-verified

40}
41
42export function createArtifactTools(adapter: ArtifactToolAdapter): ToolDefinition[] {
43 return [
44 {
45 name: 'create_artifact',
46 label: 'Create artifact',
47 description:
48 'Create an artifact for this chat. kind=html is standalone HTML/CSS/JS; kind=react is a default-exported React component; kind=markdown is Markdown text. CDN usage is allowed inside HTML artifacts.',
49 promptSnippet: 'Create an html, react, or markdown artifact for this chat',
50 parameters: {
51 type: 'object',
52 properties: { slug: stringSchema, kind: artifactKindSchema, content: stringSchema },
53 required: ['slug', 'kind', 'content'],
54 additionalProperties: false,
55 },
56 async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
57 const input = params as { slug: string; kind: ArtifactKind; content: string }
58 const artifact = await adapter.createArtifact({
59 conversationId: getConversationId(ctx),
60 slug: input.slug,
61 kind: input.kind,
62 content: input.content,
63 })
64 return textResult(`Created artifact ${artifact.slug} version ${artifact.version}.`, {
65 artifact,
66 })
67 },
68 },
69 {
70 name: 'edit_artifact',
71 label: 'Edit artifact',
72 description:
73 'Edit one artifact in this chat with exact text replacements. Each edits[].oldText must match a unique, non-overlapping region of the current artifact. Merge nearby changes into one edit; use multiple edits for disjoint changes.',
74 promptSnippet: 'Edit an artifact using exact text replacements',
75 parameters: {
76 type: 'object',
77 properties: {
78 id: stringSchema,
79 edits: {
80 type: 'array',
81 items: editSchema,
82 minItems: 1,
83 },
84 },
85 required: ['id', 'edits'],
86 additionalProperties: false,
87 },
88 async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
89 const input = params as { id: string; edits: ArtifactEdit[] }
90 const artifact = await adapter.editArtifact({
91 conversationId: getConversationId(ctx),
92 slug: input.id,
93 edits: input.edits,
94 })
95 return textResult(`Edited artifact ${artifact.slug} to version ${artifact.version}.`, {
96 artifact,
97 })
98 },
99 },

Callers 2

createRuntimeFunction · 0.90
createRuntimeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected