theorum 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -9
- package/deno.json +57 -0
- package/deno.lock +469 -0
- package/{esm/mod.d.ts → mod.ts} +57 -15
- package/package.json +35 -44
- package/src/cli/commands/profile.ts +57 -0
- package/src/cli/commands/run.ts +66 -0
- package/src/cli/commands/test.ts +195 -0
- package/src/cli/index.ts +161 -0
- package/src/cli/matrix/fixtures.ts +96 -0
- package/src/cli/matrix/synthesizer.ts +240 -0
- package/src/guardrails/error.ts +142 -0
- package/src/guardrails/injection.ts +254 -0
- package/src/guardrails/mod.ts +40 -0
- package/src/guardrails/quota.ts +87 -0
- package/src/guardrails/sanitize.ts +165 -0
- package/src/guardrails/sensitive.ts +96 -0
- package/src/host/mint-trace.ts +54 -0
- package/{esm/src/host/mod.js → src/host/mod.ts} +11 -3
- package/src/host/reply.ts +32 -0
- package/src/kernel/engine/assert.ts +29 -0
- package/src/kernel/engine/boundary.ts +75 -0
- package/src/kernel/engine/delta.ts +440 -0
- package/src/kernel/engine/hash.ts +11 -0
- package/src/kernel/engine/record.ts +8 -0
- package/src/kernel/engine/repair.ts +56 -0
- package/src/kernel/engine/runner/gates.ts +338 -0
- package/src/kernel/engine/runner/mod.ts +135 -0
- package/src/kernel/engine/runner/state.ts +31 -0
- package/src/kernel/engine/runner/steps.ts +183 -0
- package/src/kernel/engine/runner/stream.ts +83 -0
- package/src/kernel/engine/runner/tokens.ts +47 -0
- package/src/kernel/engine/runner/tools.ts +266 -0
- package/{esm/src/kernel/engine/runner.d.ts → src/kernel/engine/runner.ts} +2 -1
- package/src/kernel/engine/tree.ts +18 -0
- package/src/kernel/mod.ts +39 -0
- package/src/kernel/registry/attachments.ts +195 -0
- package/src/kernel/registry/catalog.ts +181 -0
- package/src/kernel/registry/ingress.ts +223 -0
- package/src/kernel/registry/profiles.ts +165 -0
- package/src/kernel/registry/provider-request.ts +31 -0
- package/src/kernel/registry/resolve.ts +290 -0
- package/src/kernel/registry/schemas.ts +29 -0
- package/src/kernel/registry/tools.ts +45 -0
- package/{esm/src/kernel/registry/vault.d.ts → src/kernel/registry/vault.ts} +17 -2
- package/src/kernel/types.ts +576 -0
- package/{esm/src/observability/mod.js → src/observability/mod.ts} +11 -2
- package/src/observability/spans.ts +70 -0
- package/src/observability/trace-attach.ts +96 -0
- package/src/observability/trace-record.ts +254 -0
- package/src/observability/trace-usage.ts +36 -0
- package/src/observability/trace.ts +143 -0
- package/src/presets/google.ts +147 -0
- package/src/presets/mod.ts +24 -0
- package/src/providers/create-provider.ts +64 -0
- package/src/providers/gemini-tape.ts +59 -0
- package/src/providers/google-tap.ts +57 -0
- package/src/providers/interactions.ts +182 -0
- package/src/providers/keys.ts +182 -0
- package/{esm/src/providers/mod.js → src/providers/mod.ts} +4 -2
- package/{esm/src/providers/openrouter-mod.js → src/providers/openrouter-mod.ts} +7 -3
- package/src/providers/openrouter-payload.ts +232 -0
- package/src/providers/openrouter.ts +758 -0
- package/src/providers/pcm.ts +37 -0
- package/src/providers/provider.ts +206 -0
- package/src/providers/speech.ts +180 -0
- package/src/providers/sse.ts +59 -0
- package/esm/_dnt.polyfills.d.ts +0 -110
- package/esm/_dnt.polyfills.js +0 -144
- package/esm/_dnt.shims.d.ts +0 -5
- package/esm/_dnt.shims.js +0 -61
- package/esm/mod.js +0 -49
- package/esm/package.json +0 -3
- package/esm/src/cli/commands/profile.d.ts +0 -2
- package/esm/src/cli/commands/profile.js +0 -53
- package/esm/src/cli/commands/run.d.ts +0 -10
- package/esm/src/cli/commands/run.js +0 -55
- package/esm/src/cli/commands/test.d.ts +0 -15
- package/esm/src/cli/commands/test.js +0 -140
- package/esm/src/cli/index.d.ts +0 -4
- package/esm/src/cli/index.js +0 -148
- package/esm/src/cli/matrix/fixtures.d.ts +0 -13
- package/esm/src/cli/matrix/fixtures.js +0 -77
- package/esm/src/cli/matrix/synthesizer.d.ts +0 -29
- package/esm/src/cli/matrix/synthesizer.js +0 -187
- package/esm/src/guardrails/error.d.ts +0 -33
- package/esm/src/guardrails/error.js +0 -114
- package/esm/src/guardrails/injection.d.ts +0 -12
- package/esm/src/guardrails/injection.js +0 -220
- package/esm/src/guardrails/mod.d.ts +0 -14
- package/esm/src/guardrails/mod.js +0 -14
- package/esm/src/guardrails/sanitize.d.ts +0 -22
- package/esm/src/guardrails/sanitize.js +0 -133
- package/esm/src/guardrails/sensitive.d.ts +0 -12
- package/esm/src/guardrails/sensitive.js +0 -88
- package/esm/src/host/mint-trace.d.ts +0 -27
- package/esm/src/host/mint-trace.js +0 -33
- package/esm/src/host/mod.d.ts +0 -13
- package/esm/src/host/reply.d.ts +0 -14
- package/esm/src/host/reply.js +0 -27
- package/esm/src/kernel/engine/boundary.d.ts +0 -10
- package/esm/src/kernel/engine/boundary.js +0 -55
- package/esm/src/kernel/engine/delta.d.ts +0 -8
- package/esm/src/kernel/engine/delta.js +0 -389
- package/esm/src/kernel/engine/hash.d.ts +0 -1
- package/esm/src/kernel/engine/hash.js +0 -9
- package/esm/src/kernel/engine/record.d.ts +0 -2
- package/esm/src/kernel/engine/record.js +0 -7
- package/esm/src/kernel/engine/repair.d.ts +0 -7
- package/esm/src/kernel/engine/repair.js +0 -38
- package/esm/src/kernel/engine/runner/gates.d.ts +0 -4
- package/esm/src/kernel/engine/runner/gates.js +0 -206
- package/esm/src/kernel/engine/runner/mod.d.ts +0 -14
- package/esm/src/kernel/engine/runner/mod.js +0 -103
- package/esm/src/kernel/engine/runner/state.d.ts +0 -16
- package/esm/src/kernel/engine/runner/state.js +0 -8
- package/esm/src/kernel/engine/runner/steps.d.ts +0 -15
- package/esm/src/kernel/engine/runner/steps.js +0 -119
- package/esm/src/kernel/engine/runner/stream.d.ts +0 -11
- package/esm/src/kernel/engine/runner/stream.js +0 -65
- package/esm/src/kernel/engine/runner/tokens.d.ts +0 -3
- package/esm/src/kernel/engine/runner/tokens.js +0 -38
- package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
- package/esm/src/kernel/engine/runner/tools.js +0 -197
- package/esm/src/kernel/engine/runner.js +0 -6
- package/esm/src/kernel/engine/tree.d.ts +0 -2
- package/esm/src/kernel/engine/tree.js +0 -17
- package/esm/src/kernel/mod.d.ts +0 -18
- package/esm/src/kernel/mod.js +0 -16
- package/esm/src/kernel/registry/attachments.d.ts +0 -16
- package/esm/src/kernel/registry/attachments.js +0 -156
- package/esm/src/kernel/registry/catalog.d.ts +0 -31
- package/esm/src/kernel/registry/catalog.js +0 -135
- package/esm/src/kernel/registry/ingress.d.ts +0 -13
- package/esm/src/kernel/registry/ingress.js +0 -163
- package/esm/src/kernel/registry/profiles.d.ts +0 -34
- package/esm/src/kernel/registry/profiles.js +0 -120
- package/esm/src/kernel/registry/provider-request.d.ts +0 -4
- package/esm/src/kernel/registry/provider-request.js +0 -25
- package/esm/src/kernel/registry/resolve.d.ts +0 -19
- package/esm/src/kernel/registry/resolve.js +0 -217
- package/esm/src/kernel/registry/schemas.d.ts +0 -14
- package/esm/src/kernel/registry/schemas.js +0 -23
- package/esm/src/kernel/registry/tools.d.ts +0 -12
- package/esm/src/kernel/registry/tools.js +0 -36
- package/esm/src/kernel/registry/vault.js +0 -18
- package/esm/src/kernel/types.d.ts +0 -521
- package/esm/src/kernel/types.js +0 -10
- package/esm/src/observability/mod.d.ts +0 -12
- package/esm/src/observability/spans.d.ts +0 -16
- package/esm/src/observability/spans.js +0 -56
- package/esm/src/observability/trace-attach.d.ts +0 -16
- package/esm/src/observability/trace-attach.js +0 -67
- package/esm/src/observability/trace-record.d.ts +0 -112
- package/esm/src/observability/trace-record.js +0 -140
- package/esm/src/observability/trace-usage.d.ts +0 -3
- package/esm/src/observability/trace-usage.js +0 -32
- package/esm/src/observability/trace.d.ts +0 -23
- package/esm/src/observability/trace.js +0 -121
- package/esm/src/presets/google.d.ts +0 -50
- package/esm/src/presets/google.js +0 -96
- package/esm/src/presets/mod.d.ts +0 -11
- package/esm/src/presets/mod.js +0 -10
- package/esm/src/providers/create-provider.d.ts +0 -29
- package/esm/src/providers/create-provider.js +0 -38
- package/esm/src/providers/gemini-tape.d.ts +0 -2
- package/esm/src/providers/gemini-tape.js +0 -46
- package/esm/src/providers/google-tap.d.ts +0 -3
- package/esm/src/providers/google-tap.js +0 -48
- package/esm/src/providers/interactions.d.ts +0 -5
- package/esm/src/providers/interactions.js +0 -152
- package/esm/src/providers/keys.d.ts +0 -19
- package/esm/src/providers/keys.js +0 -129
- package/esm/src/providers/mod.d.ts +0 -12
- package/esm/src/providers/openrouter-mod.d.ts +0 -13
- package/esm/src/providers/openrouter-payload.d.ts +0 -32
- package/esm/src/providers/openrouter-payload.js +0 -179
- package/esm/src/providers/openrouter.d.ts +0 -15
- package/esm/src/providers/openrouter.js +0 -589
- package/esm/src/providers/pcm.d.ts +0 -7
- package/esm/src/providers/pcm.js +0 -35
- package/esm/src/providers/provider.d.ts +0 -15
- package/esm/src/providers/provider.js +0 -166
- package/esm/src/providers/speech.d.ts +0 -23
- package/esm/src/providers/speech.js +0 -125
- package/esm/src/providers/sse.d.ts +0 -7
- package/esm/src/providers/sse.js +0 -53
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prompt-injection span detection.
|
|
3
|
-
*
|
|
4
|
-
* These utilities return spans that can be redacted from untrusted user text
|
|
5
|
-
* before provider submission.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { blobAt, spansFromPatterns } from '../observability/spans.js';
|
|
10
|
-
const IGNORE_PREVIOUS = /ignore\s+(all\s+)?(previous|prior)\s+((?:safety|security|system|operational|internal|core|original|initial|existing|given|stated|provided|defined|specified|established)\s+)?(instructions?|rules?|guidelines?|constraints?|directives?)/gi;
|
|
11
|
-
const DISREGARD_INSTRUCTIONS = /disregard\s+(all\s+)?(previous|prior|above)\s+(instructions?|rules?|guidelines?|constraints?|directives?)/gi;
|
|
12
|
-
const FORGET_INSTRUCTIONS = /forget\s+(all\s+)?(previous|prior|above)\s+(instructions?|rules?|guidelines?|constraints?|directives?)/gi;
|
|
13
|
-
const NEW_INSTRUCTIONS = /new\s+instructions?:/gi;
|
|
14
|
-
const DO_NOT_FOLLOW = /do\s+not\s+follow\s+(the\s+)?(system|developer|previous|original)/gi;
|
|
15
|
-
const SUPERSEDE_INSTRUCTIONS = /supersedes?\s+(all\s+)?(prior|previous)\s+(instructions?|rules?|guidelines?|constraints?|directives?)/gi;
|
|
16
|
-
const VOID_INSTRUCTIONS = /(all\s+)?(previous|prior)\s+instructions?\s+(are|is)\s+(void|invalid|null|obsolete|cancelled|revoked)/gi;
|
|
17
|
-
const DEVELOPER_MODE = /you\s+are\s+now\s+(in\s+)?developer\s+mode/gi;
|
|
18
|
-
const ENTER_SPECIAL_MODE = /enter\s+(developer|admin|debug|maintenance)\s+mode/gi;
|
|
19
|
-
const ACTIVATE_SPECIAL_MODE = /activate\s+(developer|admin|debug|jailbreak)\s+mode/gi;
|
|
20
|
-
const SYSTEM_OVERRIDE = /\bsystem\s+override\b/gi;
|
|
21
|
-
const OVERRIDE_INSTRUCTIONS = /override\s+(your\s+)?(instructions?|rules?|guidelines?|constraints?|directives?)/gi;
|
|
22
|
-
const REVEAL_PROMPT = /reveal\s+((?:your?|yoru|yuor|the|my|its|his|her|our|their)\s+)?((?:(?:full|hidden|complete|internal|secret|original|entire|exact|actual|real)\s+){0,2})((?:system|systme|sysetm|systemp?)\s+)?prompt\b/gi;
|
|
23
|
-
const SHOW_PROMPT = /show\s+(me\s+)?((?:your?|yoru|yuor|the|my|its|his|her|our|their)\s+)((?:system|systme|sysetm|systemp?)\s+)?prompt\b/gi;
|
|
24
|
-
const WHAT_INSTRUCTIONS = /what\s+(are|were)\s+(your\s+)?(exact\s+)?instructions/gi;
|
|
25
|
-
const REPEAT_INSTRUCTIONS = /repeat\s+(the\s+)?(text|instructions?)\s+(above|before)/gi;
|
|
26
|
-
const OUTPUT_PROMPT = /output\s+(your\s+)?(initial|original|system)\s+(prompt|instructions?)/gi;
|
|
27
|
-
const REMOVE_RESTRICTIONS = /you\s+are\s+no\s+longer\s+(bound|restricted|limited)/gi;
|
|
28
|
-
const ACT_UNBOUND = /act\s+as\s+if\s+(you('re|\s+are)\s+)?not\s+bound/gi;
|
|
29
|
-
const PRETEND_DIFFERENT = /pretend\s+(you('re|\s+are)\s+)?(a\s+)?different\s+(ai|assistant|model)/gi;
|
|
30
|
-
const IDENTITY_HIJACK = /you\s+are\s+now\s+(?:(?:a|an)\s+)?\w+.{0,40}(without\s+(any\s+)?restrict|ignor\w*\s+(all|any|every|prev)|bypass|unrestrict|unlimit|obey\s+only|no\s+(rules|limits|restrict|boundari))/gi;
|
|
31
|
-
const DAN_JAILBREAK = /\bDAN\b[\s\S]{0,120}\bdo\s+anything\s+now\b/g;
|
|
32
|
-
const JAILBREAK_MODE = /jailbreak(ed)?\s+(mode|prompt)/gi;
|
|
33
|
-
const DO_ANYTHING_NOW = /\bdo\s+anything\s+now\b/gi;
|
|
34
|
-
const BYPASS_SAFETY = /bypass\s+(your\s+)?(safety|security|content|ethical)\s+(filters?|measures?|guidelines?|restrictions?)/gi;
|
|
35
|
-
const DISABLE_SAFETY = /disable\s+(your\s+)?(safety|security|content)\s+(filters?|measures?)/gi;
|
|
36
|
-
const IGNORE_SAFETY = /(ignore|disregard)\s+(all\s+)?(your\s+)?(safety|security|ethical|content)\s+(guidelines?|rules?|restrictions?|measures?|filters?|polic(?:y|ies)|protocols?)/gi;
|
|
37
|
-
const SYSTEM_TAG = /<\s*\/?\s*system\s*\/?>/gi;
|
|
38
|
-
const ROLE_TAG = /<\s*\/?\s*(assistant|developer|tool|function)\s*\/?>/gi;
|
|
39
|
-
const ROLE_DELIMITER = /\]\s*\n\s*\[?(system|assistant|user)\]?:/gi;
|
|
40
|
-
const BRACKETED_ROLE = /\[\s*(System\s*Message|System|Assistant|Internal)\s*\]/gi;
|
|
41
|
-
const SYSTEM_YOU_ARE = /^\s*System:\s+(you\s+are|ignore|override)/gim;
|
|
42
|
-
const CONTROL_TOKEN = /<\|(?:im_start|im_end|eot_id|start_header_id|end_header_id|endoftext)\|>/g;
|
|
43
|
-
const DEEPSEEK_CONTROL = /<\uFF5C(?:end\u2581of\u2581sentence|begin\u2581of\u2581sentence)\uFF5C>/g;
|
|
44
|
-
const LLAMA_INST = /\[\/?INST\]/gi;
|
|
45
|
-
const IGNORE_YOUR_INSTRUCTIONS = /ignore\s+(all\s+)?(your\s+)?(instructions?|rules?)\b/gi;
|
|
46
|
-
const UNRESTRICTED_MODE = /\bunrestricted\s+(ai|mode|model)\b/gi;
|
|
47
|
-
const INJECTION_PATTERNS = [
|
|
48
|
-
IGNORE_PREVIOUS,
|
|
49
|
-
DISREGARD_INSTRUCTIONS,
|
|
50
|
-
FORGET_INSTRUCTIONS,
|
|
51
|
-
NEW_INSTRUCTIONS,
|
|
52
|
-
DO_NOT_FOLLOW,
|
|
53
|
-
SUPERSEDE_INSTRUCTIONS,
|
|
54
|
-
VOID_INSTRUCTIONS,
|
|
55
|
-
DEVELOPER_MODE,
|
|
56
|
-
ENTER_SPECIAL_MODE,
|
|
57
|
-
ACTIVATE_SPECIAL_MODE,
|
|
58
|
-
SYSTEM_OVERRIDE,
|
|
59
|
-
OVERRIDE_INSTRUCTIONS,
|
|
60
|
-
REVEAL_PROMPT,
|
|
61
|
-
SHOW_PROMPT,
|
|
62
|
-
WHAT_INSTRUCTIONS,
|
|
63
|
-
REPEAT_INSTRUCTIONS,
|
|
64
|
-
OUTPUT_PROMPT,
|
|
65
|
-
REMOVE_RESTRICTIONS,
|
|
66
|
-
ACT_UNBOUND,
|
|
67
|
-
PRETEND_DIFFERENT,
|
|
68
|
-
IDENTITY_HIJACK,
|
|
69
|
-
DAN_JAILBREAK,
|
|
70
|
-
JAILBREAK_MODE,
|
|
71
|
-
DO_ANYTHING_NOW,
|
|
72
|
-
BYPASS_SAFETY,
|
|
73
|
-
DISABLE_SAFETY,
|
|
74
|
-
IGNORE_SAFETY,
|
|
75
|
-
SYSTEM_TAG,
|
|
76
|
-
ROLE_TAG,
|
|
77
|
-
ROLE_DELIMITER,
|
|
78
|
-
BRACKETED_ROLE,
|
|
79
|
-
SYSTEM_YOU_ARE,
|
|
80
|
-
CONTROL_TOKEN,
|
|
81
|
-
DEEPSEEK_CONTROL,
|
|
82
|
-
LLAMA_INST,
|
|
83
|
-
IGNORE_YOUR_INSTRUCTIONS,
|
|
84
|
-
UNRESTRICTED_MODE,
|
|
85
|
-
];
|
|
86
|
-
const TYPO_TARGETS = [
|
|
87
|
-
'ignore',
|
|
88
|
-
'bypass',
|
|
89
|
-
'override',
|
|
90
|
-
'reveal',
|
|
91
|
-
'delete',
|
|
92
|
-
'system',
|
|
93
|
-
'prompt',
|
|
94
|
-
'instructions',
|
|
95
|
-
];
|
|
96
|
-
const BASE64_BLOB = /[A-Za-z0-9+/]{16,}={0,2}/g;
|
|
97
|
-
const HEX_BLOB = /(?:[0-9a-f]{2}[\s]?){8,}/gi;
|
|
98
|
-
const SPACED_LETTERS = /\b(?:[A-Za-z] ){3,}[A-Za-z]\b/g;
|
|
99
|
-
const WORD = /\b[A-Za-z]{4,}\b/g;
|
|
100
|
-
const PRINTABLE_MIN = 0.85;
|
|
101
|
-
const CODE_TAB = 9;
|
|
102
|
-
const CODE_LF = 10;
|
|
103
|
-
const CODE_CR = 13;
|
|
104
|
-
const CODE_SPACE = 32;
|
|
105
|
-
const CODE_DEL = 127;
|
|
106
|
-
const HEX_RADIX = 16;
|
|
107
|
-
const HEX_STEP = 2;
|
|
108
|
-
function injectionSpansOn(text) {
|
|
109
|
-
return spansFromPatterns(text, INJECTION_PATTERNS, 'injection');
|
|
110
|
-
}
|
|
111
|
-
function sortedLetters(value) {
|
|
112
|
-
return [...value].sort().join('');
|
|
113
|
-
}
|
|
114
|
-
function firstLast(word) {
|
|
115
|
-
return { first: word.at(0), last: word.at(-1) };
|
|
116
|
-
}
|
|
117
|
-
function isTypoglycemia(word, target) {
|
|
118
|
-
if (word.length !== target.length) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const lower = word.toLowerCase();
|
|
122
|
-
if (lower === target) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
const wordEnds = firstLast(lower);
|
|
126
|
-
const targetEnds = firstLast(target);
|
|
127
|
-
if (wordEnds.first !== targetEnds.first || wordEnds.last !== targetEnds.last) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
return sortedLetters(lower.slice(1, -1)) === sortedLetters(target.slice(1, -1));
|
|
131
|
-
}
|
|
132
|
-
function typoNormalize(text) {
|
|
133
|
-
return text.replace(WORD, (word) => {
|
|
134
|
-
for (const target of TYPO_TARGETS) {
|
|
135
|
-
if (isTypoglycemia(word, target)) {
|
|
136
|
-
return target;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return word;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function isMostlyPrintable(value) {
|
|
143
|
-
if (!value) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
let ok = 0;
|
|
147
|
-
for (const ch of value) {
|
|
148
|
-
const code = ch.codePointAt(0) ?? 0;
|
|
149
|
-
const control = code === CODE_TAB || code === CODE_LF || code === CODE_CR;
|
|
150
|
-
const visible = code >= CODE_SPACE && code < CODE_DEL;
|
|
151
|
-
if (control || visible) {
|
|
152
|
-
ok += 1;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return ok / value.length >= PRINTABLE_MIN;
|
|
156
|
-
}
|
|
157
|
-
function decodedHits(decoded) {
|
|
158
|
-
if (!isMostlyPrintable(decoded)) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
return injectionSpansOn(decoded).length > 0;
|
|
162
|
-
}
|
|
163
|
-
function tryBase64(blob) {
|
|
164
|
-
try {
|
|
165
|
-
return atob(blob);
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
function tryHex(blob) {
|
|
172
|
-
const hex = blob.replaceAll(/\s/g, '');
|
|
173
|
-
if (hex.length % HEX_STEP !== 0) {
|
|
174
|
-
return undefined;
|
|
175
|
-
}
|
|
176
|
-
let out = '';
|
|
177
|
-
for (let i = 0; i < hex.length; i += HEX_STEP) {
|
|
178
|
-
out += String.fromCodePoint(Number.parseInt(hex.slice(i, i + HEX_STEP), HEX_RADIX));
|
|
179
|
-
}
|
|
180
|
-
return out;
|
|
181
|
-
}
|
|
182
|
-
function encodedFrom(text, pattern, decode) {
|
|
183
|
-
const spans = [];
|
|
184
|
-
for (const match of text.matchAll(pattern)) {
|
|
185
|
-
const found = blobAt(match);
|
|
186
|
-
if (found) {
|
|
187
|
-
const decoded = decode(found.blob);
|
|
188
|
-
if (decoded && decodedHits(decoded)) {
|
|
189
|
-
spans.push({ start: found.index, end: found.index + found.blob.length, kind: 'injection' });
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return spans;
|
|
194
|
-
}
|
|
195
|
-
function encodedSpans(text) {
|
|
196
|
-
return [...encodedFrom(text, BASE64_BLOB, tryBase64), ...encodedFrom(text, HEX_BLOB, tryHex)];
|
|
197
|
-
}
|
|
198
|
-
function spacedSpans(text) {
|
|
199
|
-
const spans = [];
|
|
200
|
-
for (const match of text.matchAll(SPACED_LETTERS)) {
|
|
201
|
-
const found = blobAt(match);
|
|
202
|
-
if (found) {
|
|
203
|
-
const collapsed = found.blob.replaceAll(' ', '');
|
|
204
|
-
if (injectionSpansOn(`${collapsed} previous instructions`).length > 0) {
|
|
205
|
-
spans.push({ start: found.index, end: found.index + found.blob.length, kind: 'injection' });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return spans;
|
|
210
|
-
}
|
|
211
|
-
/** Detect prompt-injection spans in a string. */
|
|
212
|
-
function injectionSpans(text) {
|
|
213
|
-
const shadow = typoNormalize(text);
|
|
214
|
-
let typo = [];
|
|
215
|
-
if (shadow !== text) {
|
|
216
|
-
typo = injectionSpansOn(shadow);
|
|
217
|
-
}
|
|
218
|
-
return [...injectionSpansOn(text), ...typo, ...encodedSpans(text), ...spacedSpans(text)];
|
|
219
|
-
}
|
|
220
|
-
export { injectionSpans };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic inbound and outbound guardrail primitives.
|
|
3
|
-
*
|
|
4
|
-
* This entrypoint exposes public-safe error mapping, prompt-injection span
|
|
5
|
-
* detection, sensitive-data span detection, and request sanitization. App-
|
|
6
|
-
* specific policy remains host-owned.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import "../../_dnt.polyfills.js";
|
|
11
|
-
export { PUBLIC_ACTION, PUBLIC_CANARY, PUBLIC_FILE_COUNT, PUBLIC_FILE_SIZE, PUBLIC_FILE_TYPE, PUBLIC_GENERIC, PUBLIC_IMAGE_SIZE, PUBLIC_UNAVAILABLE, publicError, TheorumError, UPSTREAM_FAILED, } from './error.js';
|
|
12
|
-
export { injectionSpans } from './injection.js';
|
|
13
|
-
export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './sanitize.js';
|
|
14
|
-
export { sensitiveSpans } from './sensitive.js';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic inbound and outbound guardrail primitives.
|
|
3
|
-
*
|
|
4
|
-
* This entrypoint exposes public-safe error mapping, prompt-injection span
|
|
5
|
-
* detection, sensitive-data span detection, and request sanitization. App-
|
|
6
|
-
* specific policy remains host-owned.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import "../../_dnt.polyfills.js";
|
|
11
|
-
export { PUBLIC_ACTION, PUBLIC_CANARY, PUBLIC_FILE_COUNT, PUBLIC_FILE_SIZE, PUBLIC_FILE_TYPE, PUBLIC_GENERIC, PUBLIC_IMAGE_SIZE, PUBLIC_UNAVAILABLE, publicError, TheorumError, UPSTREAM_FAILED, } from './error.js';
|
|
12
|
-
export { injectionSpans } from './injection.js';
|
|
13
|
-
export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './sanitize.js';
|
|
14
|
-
export { sensitiveSpans } from './sensitive.js';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request sanitization utilities for THEORUM.
|
|
3
|
-
*
|
|
4
|
-
* Sanitization removes inbound prompt-injection spans and sensitive-data spans
|
|
5
|
-
* according to the active profile guardrail flags. The host remains responsible
|
|
6
|
-
* for domain policy.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import type { NormalizedTurnRequest, TurnRequest } from '../kernel/types.js';
|
|
11
|
-
/** Sanitize one text value using prompt-injection and sensitive-data detectors. */
|
|
12
|
-
declare function sanitizeText(text: string, options?: {
|
|
13
|
-
sanitizeInput?: boolean;
|
|
14
|
-
redactSensitive?: boolean;
|
|
15
|
-
}): string;
|
|
16
|
-
/** Maximum retained length for trace-safe host project ids. */
|
|
17
|
-
declare const PROJECT_ID_MAX = 128;
|
|
18
|
-
/** Return a trace-safe project id or `undefined` when the input is unsafe. */
|
|
19
|
-
declare function sanitizeProjectId(id: string | undefined): string | undefined;
|
|
20
|
-
/** Sanitize all user-controlled text and blobs in a turn request. */
|
|
21
|
-
declare function sanitizeTurnRequest(req: TurnRequest): NormalizedTurnRequest;
|
|
22
|
-
export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest };
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request sanitization utilities for THEORUM.
|
|
3
|
-
*
|
|
4
|
-
* Sanitization removes inbound prompt-injection spans and sensitive-data spans
|
|
5
|
-
* according to the active profile guardrail flags. The host remains responsible
|
|
6
|
-
* for domain policy.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import { mapStrings } from '../kernel/engine/tree.js';
|
|
11
|
-
import { sanitizeTurnBlobsForProfile } from '../kernel/registry/attachments.js';
|
|
12
|
-
import { getProfile } from '../kernel/registry/profiles.js';
|
|
13
|
-
import { applySpans } from '../observability/spans.js';
|
|
14
|
-
import { injectionSpans } from './injection.js';
|
|
15
|
-
import { sensitiveSpans } from './sensitive.js';
|
|
16
|
-
/** Sanitize one text value using prompt-injection and sensitive-data detectors. */
|
|
17
|
-
function sanitizeText(text, options) {
|
|
18
|
-
const sanitizeInput = options?.sanitizeInput ?? true;
|
|
19
|
-
const redactSensitive = options?.redactSensitive ?? true;
|
|
20
|
-
if (!sanitizeInput && !redactSensitive) {
|
|
21
|
-
return text;
|
|
22
|
-
}
|
|
23
|
-
const spans = [
|
|
24
|
-
...(sanitizeInput ? injectionSpans(text) : []),
|
|
25
|
-
...(redactSensitive ? sensitiveSpans(text) : []),
|
|
26
|
-
];
|
|
27
|
-
return applySpans(text, spans);
|
|
28
|
-
}
|
|
29
|
-
function sanitizeSlots(slots, options) {
|
|
30
|
-
if (!slots) {
|
|
31
|
-
return slots;
|
|
32
|
-
}
|
|
33
|
-
const out = {};
|
|
34
|
-
for (const [key, value] of Object.entries(slots)) {
|
|
35
|
-
out[key] = sanitizeText(value, options);
|
|
36
|
-
}
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
function sanitizeArgs(args, options) {
|
|
40
|
-
const next = mapStrings(args, (t) => sanitizeText(t, options));
|
|
41
|
-
if (next && typeof next === 'object' && !Array.isArray(next)) {
|
|
42
|
-
return next;
|
|
43
|
-
}
|
|
44
|
-
return args;
|
|
45
|
-
}
|
|
46
|
-
/** Maximum retained length for trace-safe host project ids. */
|
|
47
|
-
const PROJECT_ID_MAX = 128;
|
|
48
|
-
const PROJECT_ID_OK = /^[A-Za-z0-9._-]+$/;
|
|
49
|
-
/** Return a trace-safe project id or `undefined` when the input is unsafe. */
|
|
50
|
-
function sanitizeProjectId(id) {
|
|
51
|
-
if (!id) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
const trimmed = id.trim().slice(0, PROJECT_ID_MAX);
|
|
55
|
-
if (!PROJECT_ID_OK.test(trimmed)) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
return trimmed;
|
|
59
|
-
}
|
|
60
|
-
function sanitizeRepair(repair, options) {
|
|
61
|
-
if (!repair) {
|
|
62
|
-
return repair;
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
previousOutput: sanitizeText(repair.previousOutput, options),
|
|
66
|
-
rejection: sanitizeText(repair.rejection, options),
|
|
67
|
-
guidance: repair.guidance ? sanitizeText(repair.guidance, options) : undefined,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function sanitizeHistory(history, options) {
|
|
71
|
-
if (!history) {
|
|
72
|
-
return history;
|
|
73
|
-
}
|
|
74
|
-
return history.map((m) => ({
|
|
75
|
-
role: m.role,
|
|
76
|
-
...(m.content !== undefined ? { content: sanitizeText(m.content, options) } : {}),
|
|
77
|
-
...(m.parts
|
|
78
|
-
? {
|
|
79
|
-
parts: m.parts.map((p) => p.type === 'text' ? { ...p, text: sanitizeText(p.text, options) } : p),
|
|
80
|
-
}
|
|
81
|
-
: {}),
|
|
82
|
-
...(m.tool_calls ? { tool_calls: m.tool_calls } : {}),
|
|
83
|
-
...(m.tool_call_id ? { tool_call_id: m.tool_call_id } : {}),
|
|
84
|
-
...(m.name ? { name: m.name } : {}),
|
|
85
|
-
...(m.metadata ? { metadata: m.metadata } : {}),
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
/** Sanitize all user-controlled text and blobs in a turn request. */
|
|
89
|
-
function sanitizeTurnRequest(req) {
|
|
90
|
-
let profileGuardrails;
|
|
91
|
-
try {
|
|
92
|
-
profileGuardrails = getProfile(req.profile)?.guardrails;
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
// If profile not registered yet, default to full guardrails
|
|
96
|
-
}
|
|
97
|
-
const options = {
|
|
98
|
-
sanitizeInput: profileGuardrails?.sanitizeInput ?? true,
|
|
99
|
-
redactSensitive: profileGuardrails?.redactSensitive ?? true,
|
|
100
|
-
};
|
|
101
|
-
const input = req.input ?? {};
|
|
102
|
-
const { toolInvoke } = req;
|
|
103
|
-
const { text: rawText } = input;
|
|
104
|
-
let invoke = toolInvoke;
|
|
105
|
-
if (toolInvoke) {
|
|
106
|
-
invoke = { ...toolInvoke, arguments: sanitizeArgs(toolInvoke.arguments, options) };
|
|
107
|
-
}
|
|
108
|
-
let text = rawText;
|
|
109
|
-
if (rawText !== undefined) {
|
|
110
|
-
text = sanitizeText(rawText, options);
|
|
111
|
-
}
|
|
112
|
-
let system = req.system;
|
|
113
|
-
if (system !== undefined) {
|
|
114
|
-
system = sanitizeText(system, options);
|
|
115
|
-
}
|
|
116
|
-
const { attachments, voice } = sanitizeTurnBlobsForProfile(req.profile, input.attachments, input.voice);
|
|
117
|
-
return {
|
|
118
|
-
...req,
|
|
119
|
-
system,
|
|
120
|
-
projectId: sanitizeProjectId(req.projectId),
|
|
121
|
-
input: {
|
|
122
|
-
...input,
|
|
123
|
-
text,
|
|
124
|
-
slots: sanitizeSlots(input.slots, options),
|
|
125
|
-
attachments,
|
|
126
|
-
voice,
|
|
127
|
-
repair: sanitizeRepair(input.repair, options),
|
|
128
|
-
history: sanitizeHistory(input.history, options),
|
|
129
|
-
},
|
|
130
|
-
toolInvoke: invoke,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sensitive-data span detection.
|
|
3
|
-
*
|
|
4
|
-
* Detects common credentials, tokens, card numbers, SSNs, and network secrets
|
|
5
|
-
* so host profiles can redact them before provider submission.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { type RedactSpan } from '../observability/spans.js';
|
|
10
|
-
/** Detect sensitive-data spans in a string. */
|
|
11
|
-
declare function sensitiveSpans(text: string): RedactSpan[];
|
|
12
|
-
export { sensitiveSpans };
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sensitive-data span detection.
|
|
3
|
-
*
|
|
4
|
-
* Detects common credentials, tokens, card numbers, SSNs, and network secrets
|
|
5
|
-
* so host profiles can redact them before provider submission.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { blobAt, spansFromPatterns } from '../observability/spans.js';
|
|
10
|
-
const SSN = /\b\d{3}-\d{2}-\d{4}\b/g;
|
|
11
|
-
const ITIN = /\b9\d{2}-\d{2}-\d{4}\b/g;
|
|
12
|
-
const EIN = /\b\d{2}-\d{7}\b/g;
|
|
13
|
-
const IBAN = /\b[A-Z]{2}\d{2}[A-Z0-9]{13,30}\b/g;
|
|
14
|
-
const IPV4 = /\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g;
|
|
15
|
-
const IPV6 = /\b(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}\b/gi;
|
|
16
|
-
const AWS_ACCESS = /\bAKIA[0-9A-Z]{16}\b/g;
|
|
17
|
-
const GOOGLE_API = /\bAIza[0-9A-Za-z_-]{35}\b/g;
|
|
18
|
-
const OPENAI_KEY = /\bsk-[A-Za-z0-9]{20,}\b/g;
|
|
19
|
-
const ANTHROPIC_KEY = /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g;
|
|
20
|
-
const OPENROUTER_KEY = /\bsk-or-[A-Za-z0-9_-]{20,}\b/g;
|
|
21
|
-
const GITHUB_PAT = /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g;
|
|
22
|
-
const GITHUB_TOKEN = /\bghp_[A-Za-z0-9]{36}\b/g;
|
|
23
|
-
const SLACK_TOKEN = /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g;
|
|
24
|
-
const BEARER = /\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi;
|
|
25
|
-
const PEM_KEY = /-----BEGIN (?:RSA )?PRIVATE KEY-----[\s\S]+?-----END (?:RSA )?PRIVATE KEY-----/g;
|
|
26
|
-
const CARD_CANDIDATE = /\b(?:\d[ -]*?){13,19}\b/g;
|
|
27
|
-
const KEY_PATTERNS = [
|
|
28
|
-
SSN,
|
|
29
|
-
ITIN,
|
|
30
|
-
EIN,
|
|
31
|
-
IBAN,
|
|
32
|
-
IPV4,
|
|
33
|
-
IPV6,
|
|
34
|
-
AWS_ACCESS,
|
|
35
|
-
GOOGLE_API,
|
|
36
|
-
OPENAI_KEY,
|
|
37
|
-
ANTHROPIC_KEY,
|
|
38
|
-
OPENROUTER_KEY,
|
|
39
|
-
GITHUB_PAT,
|
|
40
|
-
GITHUB_TOKEN,
|
|
41
|
-
SLACK_TOKEN,
|
|
42
|
-
BEARER,
|
|
43
|
-
PEM_KEY,
|
|
44
|
-
];
|
|
45
|
-
const LUHN_DOUBLE = 2;
|
|
46
|
-
const LUHN_NINE = 9;
|
|
47
|
-
const LUHN_TEN = 10;
|
|
48
|
-
const CARD_MIN_DIGITS = 13;
|
|
49
|
-
const CARD_MAX_DIGITS = 19;
|
|
50
|
-
function luhnOk(digits) {
|
|
51
|
-
let sum = 0;
|
|
52
|
-
let doubleIt = false;
|
|
53
|
-
for (let i = digits.length - 1; i >= 0; i -= 1) {
|
|
54
|
-
const ch = digits[i];
|
|
55
|
-
if (ch === undefined) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
let n = Number(ch);
|
|
59
|
-
if (doubleIt) {
|
|
60
|
-
n *= LUHN_DOUBLE;
|
|
61
|
-
if (n > LUHN_NINE) {
|
|
62
|
-
n -= LUHN_NINE;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
sum += n;
|
|
66
|
-
doubleIt = !doubleIt;
|
|
67
|
-
}
|
|
68
|
-
return sum % LUHN_TEN === 0;
|
|
69
|
-
}
|
|
70
|
-
function cardSpans(text) {
|
|
71
|
-
const spans = [];
|
|
72
|
-
for (const match of text.matchAll(CARD_CANDIDATE)) {
|
|
73
|
-
const found = blobAt(match);
|
|
74
|
-
if (found) {
|
|
75
|
-
const digits = found.blob.replaceAll(/[^\d]/g, '');
|
|
76
|
-
const inRange = digits.length >= CARD_MIN_DIGITS && digits.length <= CARD_MAX_DIGITS;
|
|
77
|
-
if (inRange && luhnOk(digits)) {
|
|
78
|
-
spans.push({ start: found.index, end: found.index + found.blob.length, kind: 'sensitive' });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return spans;
|
|
83
|
-
}
|
|
84
|
-
/** Detect sensitive-data spans in a string. */
|
|
85
|
-
function sensitiveSpans(text) {
|
|
86
|
-
return [...spansFromPatterns(text, KEY_PATTERNS, 'sensitive'), ...cardSpans(text)];
|
|
87
|
-
}
|
|
88
|
-
export { sensitiveSpans };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host cutout-trace helpers for apps that mint a final audit row after an
|
|
3
|
-
* upstream side effect (for example image cutout).
|
|
4
|
-
*
|
|
5
|
-
* Prefer importing from `theorum/host`.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { type TraceSink } from '../observability/trace.js';
|
|
10
|
-
import type { TraceRecord } from '../observability/trace-record.js';
|
|
11
|
-
interface CutoutTape {
|
|
12
|
-
ok: boolean;
|
|
13
|
-
ms: number;
|
|
14
|
-
url?: string;
|
|
15
|
-
inSha256?: string;
|
|
16
|
-
outSha256?: string;
|
|
17
|
-
http?: unknown;
|
|
18
|
-
error?: string;
|
|
19
|
-
}
|
|
20
|
-
declare function flushMintTrace(args: {
|
|
21
|
-
held: TraceRecord[];
|
|
22
|
-
app: Record<string, unknown>;
|
|
23
|
-
cutout: CutoutTape;
|
|
24
|
-
sink?: TraceSink;
|
|
25
|
-
}): Promise<void>;
|
|
26
|
-
export type { CutoutTape };
|
|
27
|
-
export { flushMintTrace };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host cutout-trace helpers for apps that mint a final audit row after an
|
|
3
|
-
* upstream side effect (for example image cutout).
|
|
4
|
-
*
|
|
5
|
-
* Prefer importing from `theorum/host`.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { publicError, UPSTREAM_FAILED } from '../guardrails/error.js';
|
|
10
|
-
import { noopSink, writeTrace } from '../observability/trace.js';
|
|
11
|
-
function attachMint(row, app, cutout) {
|
|
12
|
-
row.app = app;
|
|
13
|
-
row.cutout = cutout;
|
|
14
|
-
row.ms = Date.now() - row.ts;
|
|
15
|
-
if (!cutout.ok) {
|
|
16
|
-
row.ok = false;
|
|
17
|
-
const { error: cutoutError } = cutout;
|
|
18
|
-
let error = cutoutError;
|
|
19
|
-
if (!error) {
|
|
20
|
-
error = publicError(UPSTREAM_FAILED);
|
|
21
|
-
}
|
|
22
|
-
row.error = error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async function flushMintTrace(args) {
|
|
26
|
-
const [row] = args.held;
|
|
27
|
-
if (!row) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
attachMint(row, args.app, args.cutout);
|
|
31
|
-
await writeTrace(args.sink ?? noopSink(), Promise.resolve(row));
|
|
32
|
-
}
|
|
33
|
-
export { flushMintTrace };
|
package/esm/src/host/mod.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optional host-application helpers.
|
|
3
|
-
*
|
|
4
|
-
* These are not part of the turn kernel. They exist for Deno HTTP hosts that
|
|
5
|
-
* want shared reply status mapping and cutout-trace flushing without re-
|
|
6
|
-
* implementing the same glue in every app route.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import "../../_dnt.polyfills.js";
|
|
11
|
-
export type { CutoutTape } from './mint-trace.js';
|
|
12
|
-
export { flushMintTrace } from './mint-trace.js';
|
|
13
|
-
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json, } from './reply.js';
|
package/esm/src/host/reply.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optional Deno HTTP reply helpers for host applications.
|
|
3
|
-
*
|
|
4
|
-
* Not part of the turn kernel. Prefer importing from `theorum/host`.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
declare const HTTP_BUSY = 429;
|
|
9
|
-
declare const HTTP_OK = 200;
|
|
10
|
-
declare const HTTP_NOT_FOUND = 404;
|
|
11
|
-
declare const HTTP_METHOD = 405;
|
|
12
|
-
declare function json(status: number, body: unknown, cors: Record<string, string>): Response;
|
|
13
|
-
declare function caughtStatus(err: unknown): number;
|
|
14
|
-
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
package/esm/src/host/reply.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optional Deno HTTP reply helpers for host applications.
|
|
3
|
-
*
|
|
4
|
-
* Not part of the turn kernel. Prefer importing from `theorum/host`.
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
import { TheorumError } from '../guardrails/error.js';
|
|
9
|
-
const HTTP_BAD = 400;
|
|
10
|
-
const HTTP_BUSY = 429;
|
|
11
|
-
const HTTP_ERR = 500;
|
|
12
|
-
const HTTP_OK = 200;
|
|
13
|
-
const HTTP_NOT_FOUND = 404;
|
|
14
|
-
const HTTP_METHOD = 405;
|
|
15
|
-
function json(status, body, cors) {
|
|
16
|
-
return new Response(JSON.stringify(body), {
|
|
17
|
-
status,
|
|
18
|
-
headers: { ...cors, 'Content-Type': 'application/json' },
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function caughtStatus(err) {
|
|
22
|
-
if (err instanceof TheorumError) {
|
|
23
|
-
return HTTP_BAD;
|
|
24
|
-
}
|
|
25
|
-
return HTTP_ERR;
|
|
26
|
-
}
|
|
27
|
-
export { caughtStatus, HTTP_BUSY, HTTP_METHOD, HTTP_NOT_FOUND, HTTP_OK, json };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TurnEvent } from '../types.js';
|
|
2
|
-
declare const USER_OPEN = "<user_data>";
|
|
3
|
-
declare const USER_CLOSE = "</user_data>";
|
|
4
|
-
declare const OMIT_CANARY = "[omitted - canary]";
|
|
5
|
-
declare function mintCanary(): string;
|
|
6
|
-
declare function wrapUserData(text: string): string;
|
|
7
|
-
declare function bindCanary(system: string, canary: string): string;
|
|
8
|
-
declare function eventHasCanary(event: TurnEvent, canary: string): boolean;
|
|
9
|
-
declare function redactCanary(event: TurnEvent, canary: string): TurnEvent;
|
|
10
|
-
export { bindCanary, eventHasCanary, mintCanary, OMIT_CANARY, redactCanary, USER_CLOSE, USER_OPEN, wrapUserData, };
|