Files
PaperClipAI/packages/paperclip-runner/scripts/kimi-instructions-runtime.mjs
T
DottaandPaperclip b866fa4bdc feat(runner): add pinned Kimi Code native runtime (#18028)
Add the pinned Kimi Code runtime, native instruction and model admission, scoped credentials, and pending-candidate recovery contracts. Retain current master release attestations and provider-pack compatibility.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-30 21:58:12 -05:00

35 lines
1.9 KiB
JavaScript

export const KIMI_INSTRUCTION_RUNTIME_SOURCE = [
"function createKimiInstructionRuntime(raw, { createHash, byteLength }) {",
" const schema = \"paperclip.kimi.instructions.v1\";",
" const fail = () => { throw new Error(\"Kimi instruction binding is missing or invalid\"); };",
" if (typeof raw !== \"string\" || byteLength(raw) > 200_000) fail();",
" let value;",
" try { value = JSON.parse(raw); } catch { fail(); }",
" if (!value || typeof value !== \"object\" || Array.isArray(value)",
" || Object.keys(value).sort().join(\",\") !== \"byteLength,content,digest,schema\"",
" || value.schema !== schema || typeof value.content !== \"string\"",
" || value.content.includes(\"\\0\") || !value.content.isWellFormed()",
" || byteLength(value.content) > 32_768 || value.byteLength !== byteLength(value.content)",
" || typeof value.digest !== \"string\") fail();",
" const digest = text => `sha256:${createHash(\"sha256\").update(text, \"utf8\").digest(\"hex\")}`;",
" const content = value.content;",
" if (value.digest !== digest(content)) fail();",
" const suffix = content.length === 0 ? \"\" : `\\n\\n${content}`;",
" const append = base => {",
" if (typeof base !== \"string\" || byteLength(base) > 2_097_152) fail();",
" return suffix.length === 0 || base.endsWith(suffix) ? base : `${base}${suffix}`;",
" };",
" return Object.freeze({",
" append,",
" receipt(sessionId, effectivePrompt) {",
" if (typeof sessionId !== \"string\" || !sessionId.trim() || append(effectivePrompt) !== effectivePrompt) fail();",
" return Object.freeze({ schema, sessionId, digest: value.digest,",
" byteLength: byteLength(content), effectiveDigest: digest(effectivePrompt),",
" effectiveByteLength: byteLength(effectivePrompt) });",
" },",
" });",
"}",
].join("\n");
export const createKimiInstructionRuntime = new Function(`return (${KIMI_INSTRUCTION_RUNTIME_SOURCE});`)();