mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 23:43:16 +01:00
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>
35 lines
1.9 KiB
JavaScript
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});`)();
|