text stringlengths 0 1.47k |
|---|
const target = source ?? await ctx.fs.resolve(`viz/${slugOf(title)}-${contentHash(fragment)}.html`, resolveOpts); |
await ctx.fs.writeText(target, fragment, void 0, exec.signal, sandboxPolicy); |
return { |
action, |
path: target.displayPath, |
title, |
mode: args.mode ?? "inline", |
sizeBytes, |
fragment |
}; |
}, |
presentCall: () => ({ |
card: "generic", |
title: "Visualize", |
kind: "other" |
}), |
presentResult(_args, result) { |
if (result.isError) return void 0; |
const meta = visualizeMetaFrom(result.meta); |
if (meta === void 0) return void 0; |
return { |
card: "generic", |
title: `Visualization · ${meta.title}` |
}; |
} |
}); |
} |
/** |
* Take one argument the chosen action cannot run without. The parameter schema |
* cannot express "required on update only", so the per-action requirement is |
* enforced here and fails loud rather than defaulting into a wrong card. |
* @param value - the raw argument value. |
* @param name - the parameter name, as the model wrote it. |
* @param action - the action that requires it, named in the message. |
* @returns the raw value, whitespace preserved. |
* @throws Error naming the missing parameter; the tool surfaces it as `isError`. |
*/ |
function required(value, name, action) { |
if (value === void 0 || value.trim().length === 0) throw new Error(`invalid visualization: \`${name}\` is required when action is "${action}"`); |
return value; |
} |
/** |
* Take one argument that must be supplied but may legitimately be empty — an |
* empty `new_str` is how a patch deletes the region it matched. |
* @param value - the raw argument value. |
* @param name - the parameter name, as the model wrote it. |
* @param action - the action that requires it, named in the message. |
* @returns the raw value, including the empty string. |
* @throws Error naming the missing parameter; the tool surfaces it as `isError`. |
*/ |
function present(value, name, action) { |
if (value === void 0) throw new Error(`invalid visualization: \`${name}\` is required when action is "${action}"`); |
return value; |
} |
/** |
* Lowercase, hyphenated, ASCII-safe file slug of a card title. |
* @param title - the resolved card title. |
* @returns a non-empty slug. |
*/ |
function slugOf(title) { |
const slug = title.toLowerCase().replaceAll(/[^a-z0-9]+/gu, "-").replaceAll(/^-+|-+$/gu, "").slice(0, 48); |
return slug.length > 0 ? slug : "visualization"; |
} |
/** |
* Stable 8-hex-digit content hash (FNV-1a) naming the workspace copy. |
* @param text - the fragment content. |
* @returns the hash as fixed-width hex. |
*/ |
function contentHash(text) { |
let hash = 2166136261; |
for (let i = 0; i < text.length; i++) { |
hash ^= text.charCodeAt(i); |
hash = Math.imul(hash, 16777619); |
} |
return (hash >>> 0).toString(16).padStart(8, "0"); |
} |
//#endregion |
//#region src/index.ts |
/** Cordis plugin name. */ |
const name = "dsh-visualize"; |
/** Required services: the tool registry, the skill registry, and the fs seam. */ |
const inject = [ |
"tools", |
"skills", |
"fs" |
]; |
/** Schemastery configuration validated by the Loader. */ |
const Config = z.object({ maxFragmentBytes: z.natural().default(1e6) }); |
/** |
* Register the tool and the bundled skill provider. |
* @param ctx - registrant context. |
* @param config - validated deployment configuration. |
*/ |
function apply(ctx, config) { |
ctx.tools.register(visualizeTool(ctx, config.maxFragmentBytes)); |
ctx.skills.registerProvider(() => visualizeSkillProvider); |
} |
//#endregion |
export { Config, VISUALIZE_TOOL_NAME, apply, inject, name, validateFragment, visualizeMetaFrom }; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.