@sponsio/sdk 0.1.0 → 0.2.0-alpha.10
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/contracts/benchmark/agentdojo.yaml +551 -0
- package/contracts/benchmark/odcv_bench.yaml +393 -0
- package/contracts/benchmark/redcode_exec.yaml +488 -0
- package/contracts/benchmark/swebench.yaml +176 -0
- package/contracts/benchmark/tau2_bench.yaml +984 -0
- package/contracts/capability/destructive.yaml +213 -0
- package/contracts/capability/factual-claims.yaml +79 -0
- package/contracts/capability/host-config-integrity.yaml +42 -9
- package/contracts/capability/self-modify.yaml +58 -12
- package/contracts/capability/shell.yaml +19 -10
- package/contracts/incident/claude-code-secret-bypass.yaml +48 -16
- package/contracts/incident/cursor-railway-wipe.yaml +60 -4
- package/contracts/incident/openclaw.yaml +9 -62
- package/contracts/premium/.gitkeep +5 -6
- package/dist/cli/cli.js +32 -0
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/packs.d.ts.map +1 -1
- package/dist/cli/packs.js +14 -8
- package/dist/cli/packs.js.map +1 -1
- package/dist/cli/patterns.d.ts +5 -4
- package/dist/cli/patterns.d.ts.map +1 -1
- package/dist/cli/patterns.js +11 -10
- package/dist/cli/patterns.js.map +1 -1
- package/dist/cli/prompt.js +5 -5
- package/dist/cli/prompt.js.map +1 -1
- package/dist/cli/scan.js +2 -2
- package/dist/cli/skill.d.ts +1 -1
- package/dist/cli/skill.js +1 -1
- package/dist/cli/validate.js +5 -5
- package/dist/cli/validate.js.map +1 -1
- package/dist/cloud/client.d.ts +76 -0
- package/dist/cloud/client.d.ts.map +1 -0
- package/dist/cloud/client.js +204 -0
- package/dist/cloud/client.js.map +1 -0
- package/dist/cloud/evidence.d.ts +108 -0
- package/dist/cloud/evidence.d.ts.map +1 -0
- package/dist/cloud/evidence.js +184 -0
- package/dist/cloud/evidence.js.map +1 -0
- package/dist/cloud/privacy.d.ts +67 -0
- package/dist/cloud/privacy.d.ts.map +1 -0
- package/dist/cloud/privacy.js +170 -0
- package/dist/cloud/privacy.js.map +1 -0
- package/dist/cloud/view-model.d.ts +49 -0
- package/dist/cloud/view-model.d.ts.map +1 -0
- package/dist/cloud/view-model.js +172 -0
- package/dist/cloud/view-model.js.map +1 -0
- package/dist/core/config-loader.d.ts.map +1 -1
- package/dist/core/config-loader.js +81 -9
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/evaluator.d.ts +11 -1
- package/dist/core/evaluator.d.ts.map +1 -1
- package/dist/core/evaluator.js +275 -13
- package/dist/core/evaluator.js.map +1 -1
- package/dist/core/formula.d.ts +76 -17
- package/dist/core/formula.d.ts.map +1 -1
- package/dist/core/formula.js +95 -1
- package/dist/core/formula.js.map +1 -1
- package/dist/core/grounding.d.ts +44 -8
- package/dist/core/grounding.d.ts.map +1 -1
- package/dist/core/grounding.js +208 -26
- package/dist/core/grounding.js.map +1 -1
- package/dist/core/nl-parser.d.ts +2 -2
- package/dist/core/nl-parser.d.ts.map +1 -1
- package/dist/core/nl-parser.js +617 -41
- package/dist/core/nl-parser.js.map +1 -1
- package/dist/core/pack-loader.d.ts.map +1 -1
- package/dist/core/pack-loader.js +14 -2
- package/dist/core/pack-loader.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +30 -1
- package/dist/core/parser.js.map +1 -1
- package/dist/core/pattern-factory.d.ts.map +1 -1
- package/dist/core/pattern-factory.js +14 -1
- package/dist/core/pattern-factory.js.map +1 -1
- package/dist/core/patterns.d.ts +118 -1
- package/dist/core/patterns.d.ts.map +1 -1
- package/dist/core/patterns.js +189 -10
- package/dist/core/patterns.js.map +1 -1
- package/dist/core/session-log.d.ts.map +1 -1
- package/dist/core/session-log.js +20 -1
- package/dist/core/session-log.js.map +1 -1
- package/dist/core/sto.d.ts +21 -27
- package/dist/core/sto.d.ts.map +1 -1
- package/dist/core/sto.js +30 -33
- package/dist/core/sto.js.map +1 -1
- package/dist/core/tool-names.d.ts +59 -0
- package/dist/core/tool-names.d.ts.map +1 -0
- package/dist/core/tool-names.js +128 -0
- package/dist/core/tool-names.js.map +1 -0
- package/dist/index.d.ts +181 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +415 -67
- package/dist/index.js.map +1 -1
- package/dist/integrations/claude-agent.d.ts +5 -0
- package/dist/integrations/claude-agent.d.ts.map +1 -1
- package/dist/integrations/claude-agent.js +42 -13
- package/dist/integrations/claude-agent.js.map +1 -1
- package/dist/integrations/google-adk.d.ts +5 -3
- package/dist/integrations/google-adk.d.ts.map +1 -1
- package/dist/integrations/google-adk.js +9 -5
- package/dist/integrations/google-adk.js.map +1 -1
- package/dist/integrations/langchain.d.ts +7 -0
- package/dist/integrations/langchain.d.ts.map +1 -1
- package/dist/integrations/langchain.js +21 -3
- package/dist/integrations/langchain.js.map +1 -1
- package/dist/integrations/openai-agents.d.ts +22 -10
- package/dist/integrations/openai-agents.d.ts.map +1 -1
- package/dist/integrations/openai-agents.js +55 -15
- package/dist/integrations/openai-agents.js.map +1 -1
- package/dist/integrations/openai.d.ts +11 -0
- package/dist/integrations/openai.d.ts.map +1 -1
- package/dist/integrations/openai.js +130 -48
- package/dist/integrations/openai.js.map +1 -1
- package/dist/integrations/vercel-ai.d.ts +20 -9
- package/dist/integrations/vercel-ai.d.ts.map +1 -1
- package/dist/integrations/vercel-ai.js +131 -32
- package/dist/integrations/vercel-ai.js.map +1 -1
- package/package.json +17 -9
- package/prompts/onboard.md +26 -17
- package/prompts/scan.md +3 -5
- package/skills/SKILL.md +13 -83
- package/contracts/core/llm_safety.yaml +0 -140
- package/prompts/refresh.md +0 -118
package/dist/cli/prompt.js
CHANGED
|
@@ -3,24 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runPromptCli = runPromptCli;
|
|
4
4
|
/**
|
|
5
5
|
* ``sponsio prompt`` — print the agent-facing prompt template for a
|
|
6
|
-
* sponsio workflow (onboard / scan
|
|
6
|
+
* sponsio workflow (onboard / scan).
|
|
7
7
|
*
|
|
8
|
-
* Mirrors the Python ``sponsio prompt`` command. The same
|
|
9
|
-
*
|
|
8
|
+
* Mirrors the Python ``sponsio prompt`` command. The same .md files
|
|
9
|
+
* live in ``ts/packages/sdk/prompts/`` (mirrored from
|
|
10
10
|
* ``sponsio/prompts/``); this command just reads and prints the right
|
|
11
11
|
* one. Used by the Sponsio skill to drive contract authoring without
|
|
12
12
|
* a separate LLM API call.
|
|
13
13
|
*/
|
|
14
14
|
const node_fs_1 = require("node:fs");
|
|
15
15
|
const node_path_1 = require("node:path");
|
|
16
|
-
const FLOWS = new Set(["onboard", "scan"
|
|
16
|
+
const FLOWS = new Set(["onboard", "scan"]);
|
|
17
17
|
const HELP = "sponsio prompt — print the contract-authoring prompt for a workflow\n" +
|
|
18
18
|
"\n" +
|
|
19
19
|
"USAGE:\n" +
|
|
20
20
|
" sponsio prompt <flow>\n" +
|
|
21
21
|
"\n" +
|
|
22
22
|
"ARGUMENTS:\n" +
|
|
23
|
-
" <flow> onboard | scan
|
|
23
|
+
" <flow> onboard | scan\n" +
|
|
24
24
|
"\n" +
|
|
25
25
|
"EXAMPLES:\n" +
|
|
26
26
|
" sponsio prompt onboard\n" +
|
package/dist/cli/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[],"mappings":";;AAsCA,oCAcC;AApDD;;;;;;;;;GASG;AACH,qCAAmD;AACnD,yCAAiC;AAEjC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[],"mappings":";;AAsCA,oCAcC;AApDD;;;;;;;;;GASG;AACH,qCAAmD;AACnD,yCAAiC;AAEjC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAA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CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,IAAA,sBAAY,EAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,GAAG,IAAI,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;IACnE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/cli/scan.js
CHANGED
|
@@ -40,8 +40,8 @@ exports.runScanCli = runScanCli;
|
|
|
40
40
|
* Mirrors the Python ``sponsio scan`` library-maintenance flow: AST
|
|
41
41
|
* scan a path, infer deterministic contracts heuristically, write a
|
|
42
42
|
* sponsio.yaml (or append to an existing one). Used *after* ``onboard``
|
|
43
|
-
* has set up the project
|
|
44
|
-
*
|
|
43
|
+
* has set up the project, when you've added new tools and want to
|
|
44
|
+
* update the contract list.
|
|
45
45
|
*
|
|
46
46
|
* Differs from the default ``npx sponsio <patterns>`` mode (which
|
|
47
47
|
* emits a tools.json inventory) and from ``onboard`` (first-time
|
package/dist/cli/skill.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ``sponsio skill install`` — drop the universal SKILL.md
|
|
3
3
|
* into Cursor / Claude Code / Codex skill directories so your
|
|
4
|
-
* coding agent knows how to ``onboard`` / ``scan`` /
|
|
4
|
+
* coding agent knows how to ``onboard`` / ``scan`` /
|
|
5
5
|
* flip-to-enforce on every future project without re-pasting the
|
|
6
6
|
* one-prompt setup.
|
|
7
7
|
*
|
package/dist/cli/skill.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* ``sponsio skill install`` — drop the universal SKILL.md
|
|
4
4
|
* into Cursor / Claude Code / Codex skill directories so your
|
|
5
|
-
* coding agent knows how to ``onboard`` / ``scan`` /
|
|
5
|
+
* coding agent knows how to ``onboard`` / ``scan`` /
|
|
6
6
|
* flip-to-enforce on every future project without re-pasting the
|
|
7
7
|
* one-prompt setup.
|
|
8
8
|
*
|
package/dist/cli/validate.js
CHANGED
|
@@ -157,9 +157,9 @@ async function runValidateCli(argv) {
|
|
|
157
157
|
}
|
|
158
158
|
const hasWarnings = result.skipped.length > 0 ||
|
|
159
159
|
result.unparseableNl.length > 0 ||
|
|
160
|
-
// Sto contracts
|
|
161
|
-
//
|
|
162
|
-
//
|
|
160
|
+
// Sto contracts are not supported in this build (the engine is
|
|
161
|
+
// deterministic-only). They are rejected at load time. Surface as
|
|
162
|
+
// a strict-mode warning so CI catches it.
|
|
163
163
|
result.stoContracts > 0;
|
|
164
164
|
if (args.strict && hasWarnings)
|
|
165
165
|
process.exit(2);
|
|
@@ -170,8 +170,8 @@ function renderText(r) {
|
|
|
170
170
|
lines.push(` agent: ${r.agent}`);
|
|
171
171
|
lines.push(` runtime.mode: ${r.mode ?? "(unset — falls to observe)"}`);
|
|
172
172
|
lines.push(` det contracts: ${r.detContracts}`);
|
|
173
|
-
lines.push(` sto contracts: ${r.stoContracts}${r.stoContracts > 0 ? " (
|
|
174
|
-
lines.push(` judge configured: ${r.judgeConfigured ? "yes (
|
|
173
|
+
lines.push(` sto contracts: ${r.stoContracts}${r.stoContracts > 0 ? " (not supported in this build)" : ""}`);
|
|
174
|
+
lines.push(` judge configured: ${r.judgeConfigured ? "yes (not supported in this build)" : "no"}`);
|
|
175
175
|
if (r.unparseableNl.length) {
|
|
176
176
|
lines.push("");
|
|
177
177
|
lines.push(`! ${r.unparseableNl.length} contract(s) failed NL parsing:`);
|
package/dist/cli/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/cli/validate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AAiFH,wCAsFC;AArKD,qCAAqC;AACrC,yCAAoC;AAUpC,MAAM,IAAI,GACR;IACE,+EAA+E;IAC/E,EAAE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AAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,sCAAsC,CAAC,CAAC;QACxE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO;YAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAiBD,KAAK,UAAU,OAAO;IACpB,gEAAgE;IAChE,kEAAkE;IAClE,4DAA4D;IAC5D,+DAA+D;IAC/D,wCAAwC;IACxC,MAAM,aAAa,GAAG,IAAI,QAAQ,CAChC,GAAG,EACH,kBAAkB,CACe,CAAC;IACpC,IAAI,CAAC;QACH,OAAO,MAAM,aAAa,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,OAAO,GAAG,IAAA,mBAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAC7E,OAAO,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Talking to the cloud.
|
|
3
|
+
*
|
|
4
|
+
* Port of ``sponsio/cloud/client.py`` narrowed to the two calls an agent
|
|
5
|
+
* makes at runtime: pull the book it should enforce, and upload what it
|
|
6
|
+
* did. Everything else in the Python client belongs to the CLI.
|
|
7
|
+
*
|
|
8
|
+
* Until this existed the TypeScript SDK enforced correctly and uploaded
|
|
9
|
+
* nothing, so a customer running a TypeScript agent showed up in the
|
|
10
|
+
* console with no runs at all: rules could not be rolled out to them and
|
|
11
|
+
* nothing they did could be seen.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CloudError extends Error {
|
|
14
|
+
readonly status?: number;
|
|
15
|
+
constructor(message: string, status?: number);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* ``SPONSIO_API_KEY`` first, then ``~/.sponsio/credentials``. The
|
|
19
|
+
* environment wins so CI and one-off runs can override a logged-in
|
|
20
|
+
* machine without touching files.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readApiKey(): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* ``SPONSIO_PROJECT``, or null.
|
|
25
|
+
*
|
|
26
|
+
* Which customer a run belongs to is deployment configuration, not code.
|
|
27
|
+
* A platform running one agent for forty customers ships one image and
|
|
28
|
+
* varies the environment; naming the customer in the call would mean an
|
|
29
|
+
* image per customer.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readProject(): string | null;
|
|
32
|
+
export declare function baseUrl(): string;
|
|
33
|
+
export interface PulledRulebook {
|
|
34
|
+
yamlText: string;
|
|
35
|
+
versions?: string;
|
|
36
|
+
sha?: string;
|
|
37
|
+
agent?: string;
|
|
38
|
+
channel?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CloudClientOptions {
|
|
41
|
+
apiKey?: string | null;
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
/** Milliseconds. A run must not wait on telemetry. */
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class CloudClient {
|
|
47
|
+
readonly apiKey: string | null;
|
|
48
|
+
readonly base: string;
|
|
49
|
+
readonly timeoutMs: number;
|
|
50
|
+
constructor(opts?: CloudClientOptions);
|
|
51
|
+
/** Whether there is a credential to speak with at all. */
|
|
52
|
+
get configured(): boolean;
|
|
53
|
+
private request;
|
|
54
|
+
private static detail;
|
|
55
|
+
/**
|
|
56
|
+
* Fetch a project's rulebook.
|
|
57
|
+
*
|
|
58
|
+
* Without ``agent`` this returns every agent merged into one document:
|
|
59
|
+
* a guard binds by agent id and loads only its own section, so one
|
|
60
|
+
* request serves a whole repo.
|
|
61
|
+
*/
|
|
62
|
+
pullRulebook(project?: string | null, opts?: {
|
|
63
|
+
agent?: string;
|
|
64
|
+
version?: number;
|
|
65
|
+
}): Promise<PulledRulebook>;
|
|
66
|
+
/**
|
|
67
|
+
* Send a run to the cloud.
|
|
68
|
+
*
|
|
69
|
+
* Idempotent on the session key server-side, so a retry after a blip
|
|
70
|
+
* cannot double a run. Callers on the hot path must not wait on this:
|
|
71
|
+
* telemetry is outbound-only and best-effort, and losing it must never
|
|
72
|
+
* change what the agent does.
|
|
73
|
+
*/
|
|
74
|
+
ingestSession(project: string | null, payload: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/cloud/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH,qBAAa,UAAW,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAK7C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,MAAM,GAAG,IAAI,CAkB1C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,MAAM,GAAG,IAAI,CAE3C;AAcD,wBAAgB,OAAO,IAAI,MAAM,CAGhC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAW;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,IAAI,GAAE,kBAAuB;IAMzC,0DAA0D;IAC1D,IAAI,UAAU,IAAI,OAAO,CAExB;YAEa,OAAO;IA0BrB,OAAO,CAAC,MAAM,CAAC,MAAM;IAerB;;;;;;OAMG;IACG,YAAY,CAChB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,EACvB,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAC9C,OAAO,CAAC,cAAc,CAAC;IAkC1B;;;;;;;OAOG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAsBpC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Talking to the cloud.
|
|
3
|
+
*
|
|
4
|
+
* Port of ``sponsio/cloud/client.py`` narrowed to the two calls an agent
|
|
5
|
+
* makes at runtime: pull the book it should enforce, and upload what it
|
|
6
|
+
* did. Everything else in the Python client belongs to the CLI.
|
|
7
|
+
*
|
|
8
|
+
* Until this existed the TypeScript SDK enforced correctly and uploaded
|
|
9
|
+
* nothing, so a customer running a TypeScript agent showed up in the
|
|
10
|
+
* console with no runs at all: rules could not be rolled out to them and
|
|
11
|
+
* nothing they did could be seen.
|
|
12
|
+
*/
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
const DEFAULT_BASE_URL = "https://app.sponsio.dev";
|
|
17
|
+
/**
|
|
18
|
+
* Resolved per call: a path fixed at import ignores a later change of
|
|
19
|
+
* ``HOME``, which is how a test that moved HOME still read the real key.
|
|
20
|
+
*/
|
|
21
|
+
function credentialsPath() {
|
|
22
|
+
return join(homedir(), ".sponsio", "credentials");
|
|
23
|
+
}
|
|
24
|
+
export class CloudError extends Error {
|
|
25
|
+
status;
|
|
26
|
+
constructor(message, status) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "CloudError";
|
|
29
|
+
if (status !== undefined)
|
|
30
|
+
this.status = status;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ``SPONSIO_API_KEY`` first, then ``~/.sponsio/credentials``. The
|
|
35
|
+
* environment wins so CI and one-off runs can override a logged-in
|
|
36
|
+
* machine without touching files.
|
|
37
|
+
*/
|
|
38
|
+
export function readApiKey() {
|
|
39
|
+
const env = (process.env.SPONSIO_API_KEY ?? "").trim();
|
|
40
|
+
if (env)
|
|
41
|
+
return env;
|
|
42
|
+
try {
|
|
43
|
+
for (const line of readFileSync(credentialsPath(), "utf8").split("\n")) {
|
|
44
|
+
const t = line.trim();
|
|
45
|
+
if (!t || t.startsWith("#"))
|
|
46
|
+
continue;
|
|
47
|
+
const eq = t.indexOf("=");
|
|
48
|
+
if (eq < 0)
|
|
49
|
+
continue;
|
|
50
|
+
if (t.slice(0, eq).trim() === "api_key") {
|
|
51
|
+
const v = t.slice(eq + 1).trim();
|
|
52
|
+
if (v)
|
|
53
|
+
return v;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* ``SPONSIO_PROJECT``, or null.
|
|
64
|
+
*
|
|
65
|
+
* Which customer a run belongs to is deployment configuration, not code.
|
|
66
|
+
* A platform running one agent for forty customers ships one image and
|
|
67
|
+
* varies the environment; naming the customer in the call would mean an
|
|
68
|
+
* image per customer.
|
|
69
|
+
*/
|
|
70
|
+
export function readProject() {
|
|
71
|
+
return (process.env.SPONSIO_PROJECT ?? "").trim() || null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Strip trailing slashes without a regex.
|
|
75
|
+
*
|
|
76
|
+
* ``/\/+$/`` is quadratic on a string that is mostly slashes, and the
|
|
77
|
+
* base URL comes from the environment on a machine we do not run.
|
|
78
|
+
*/
|
|
79
|
+
function trimSlashes(url) {
|
|
80
|
+
let end = url.length;
|
|
81
|
+
while (end > 0 && url.charCodeAt(end - 1) === 47)
|
|
82
|
+
end--;
|
|
83
|
+
return url.slice(0, end);
|
|
84
|
+
}
|
|
85
|
+
export function baseUrl() {
|
|
86
|
+
const explicit = (process.env.SPONSIO_API_URL ?? "").trim();
|
|
87
|
+
return trimSlashes(explicit || DEFAULT_BASE_URL);
|
|
88
|
+
}
|
|
89
|
+
export class CloudClient {
|
|
90
|
+
apiKey;
|
|
91
|
+
base;
|
|
92
|
+
timeoutMs;
|
|
93
|
+
constructor(opts = {}) {
|
|
94
|
+
this.apiKey = opts.apiKey === undefined ? readApiKey() : opts.apiKey;
|
|
95
|
+
this.base = trimSlashes(opts.baseUrl ?? baseUrl());
|
|
96
|
+
this.timeoutMs = opts.timeoutMs ?? 10_000;
|
|
97
|
+
}
|
|
98
|
+
/** Whether there is a credential to speak with at all. */
|
|
99
|
+
get configured() {
|
|
100
|
+
return Boolean(this.apiKey);
|
|
101
|
+
}
|
|
102
|
+
async request(method, path, body, contentType) {
|
|
103
|
+
if (!this.apiKey)
|
|
104
|
+
throw new CloudError("no API key configured");
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
107
|
+
try {
|
|
108
|
+
const headers = {
|
|
109
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
110
|
+
};
|
|
111
|
+
if (contentType)
|
|
112
|
+
headers["Content-Type"] = contentType;
|
|
113
|
+
const res = await fetch(this.base + path, {
|
|
114
|
+
method,
|
|
115
|
+
headers,
|
|
116
|
+
...(body === undefined ? {} : { body }),
|
|
117
|
+
signal: controller.signal,
|
|
118
|
+
});
|
|
119
|
+
return { status: res.status, text: await res.text(), headers: res.headers };
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
static detail(text, fallback) {
|
|
126
|
+
try {
|
|
127
|
+
const parsed = JSON.parse(text);
|
|
128
|
+
const d = parsed.detail;
|
|
129
|
+
if (typeof d === "string")
|
|
130
|
+
return d;
|
|
131
|
+
if (d && typeof d === "object") {
|
|
132
|
+
const o = d;
|
|
133
|
+
return o.message ?? o.error ?? fallback;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
/* not JSON; the fallback says what happened */
|
|
138
|
+
}
|
|
139
|
+
return fallback;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Fetch a project's rulebook.
|
|
143
|
+
*
|
|
144
|
+
* Without ``agent`` this returns every agent merged into one document:
|
|
145
|
+
* a guard binds by agent id and loads only its own section, so one
|
|
146
|
+
* request serves a whole repo.
|
|
147
|
+
*/
|
|
148
|
+
async pullRulebook(project, opts = {}) {
|
|
149
|
+
const q = [];
|
|
150
|
+
if (project)
|
|
151
|
+
q.push(`project=${encodeURIComponent(project)}`);
|
|
152
|
+
if (opts.agent)
|
|
153
|
+
q.push(`agent=${encodeURIComponent(opts.agent)}`);
|
|
154
|
+
if (opts.version !== undefined)
|
|
155
|
+
q.push(`version=${opts.version}`);
|
|
156
|
+
const path = "/v1/rulebook" + (q.length ? "?" + q.join("&") : "");
|
|
157
|
+
const { status, text, headers } = await this.request("GET", path);
|
|
158
|
+
if (status === 404) {
|
|
159
|
+
// "Nothing published yet" rather than a failure: the caller may
|
|
160
|
+
// publish its local yaml instead of giving up.
|
|
161
|
+
throw new CloudError(CloudClient.detail(text, "no rulebook published"), 404);
|
|
162
|
+
}
|
|
163
|
+
if (status !== 200) {
|
|
164
|
+
throw new CloudError(CloudClient.detail(text, `pull failed (${status})`), status);
|
|
165
|
+
}
|
|
166
|
+
const out = { yamlText: text };
|
|
167
|
+
const v = headers.get("x-rulebook-versions") ?? headers.get("x-rulebook-version");
|
|
168
|
+
if (v)
|
|
169
|
+
out.versions = v;
|
|
170
|
+
const sha = headers.get("x-rulebook-sha");
|
|
171
|
+
if (sha)
|
|
172
|
+
out.sha = sha;
|
|
173
|
+
const agent = headers.get("x-rulebook-agent");
|
|
174
|
+
if (agent)
|
|
175
|
+
out.agent = agent;
|
|
176
|
+
const channel = headers.get("x-rulebook-channel");
|
|
177
|
+
if (channel)
|
|
178
|
+
out.channel = channel;
|
|
179
|
+
return out;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Send a run to the cloud.
|
|
183
|
+
*
|
|
184
|
+
* Idempotent on the session key server-side, so a retry after a blip
|
|
185
|
+
* cannot double a run. Callers on the hot path must not wait on this:
|
|
186
|
+
* telemetry is outbound-only and best-effort, and losing it must never
|
|
187
|
+
* change what the agent does.
|
|
188
|
+
*/
|
|
189
|
+
async ingestSession(project, payload) {
|
|
190
|
+
const path = "/v1/sessions/ingest" +
|
|
191
|
+
(project ? `?project=${encodeURIComponent(project)}` : "");
|
|
192
|
+
const { status, text } = await this.request("POST", path, JSON.stringify(payload), "application/json");
|
|
193
|
+
if (status !== 200) {
|
|
194
|
+
throw new CloudError(CloudClient.detail(text, `ingest failed (${status})`), status);
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
return JSON.parse(text);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
throw new CloudError("ingest returned a non-JSON body", status);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|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AAC,CAAC,EAAE,CAAC,CAAC;QAC7D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CACzC,MAAM,EACN,IAAI,EACJ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EACvB,kBAAkB,CACnB,CAAC;QACF,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,MAAM,IAAI,UAAU,CAClB,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,MAAM,GAAG,CAAC,EACrD,MAAM,CACP,CAAC;QACJ,CAAC;QACD,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,UAAU,CAAC,iCAAiC,EAAE,MAAM,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The evidence lane, from TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* Rules check what an agent *does*; evidence checks what it *says*. A
|
|
5
|
+
* model that reports "the three line items total $100" is making a claim
|
|
6
|
+
* that is either true of the numbers it was given or is not, and no
|
|
7
|
+
* amount of prompting settles it. This sends the claim to
|
|
8
|
+
* `/v1/evidence/verify`, which resolves it against the declared inputs
|
|
9
|
+
* and answers PASS, MISMATCH, or a verdict meaning it could not tell.
|
|
10
|
+
*
|
|
11
|
+
* Parity with `sponsio/cloud/evidence.py`: same endpoint, same wire
|
|
12
|
+
* shape, same verdict vocabulary. One service, one meter — the server
|
|
13
|
+
* records usage per tenant and cannot see which SDK called it.
|
|
14
|
+
*
|
|
15
|
+
* The judgement is entirely server-side. This file normalises inputs,
|
|
16
|
+
* makes one request, and classifies the answer.
|
|
17
|
+
*
|
|
18
|
+
* @module @sponsio/sdk/cloud/evidence
|
|
19
|
+
*/
|
|
20
|
+
/** A verdict the server can return. Anything else is treated as unknown. */
|
|
21
|
+
export type EvidenceVerdict = "PASS" | "MISMATCH" | "NO_EVIDENCE" | "SOURCE_UNAVAILABLE" | "UNDERDETERMINED";
|
|
22
|
+
/** What the server says to do about a verdict. */
|
|
23
|
+
export type EvidenceAction = "release" | "block" | "clarify";
|
|
24
|
+
/**
|
|
25
|
+
* One input, tagged with where its value came from.
|
|
26
|
+
*
|
|
27
|
+
* The tag is not decoration. Each predicate declares which sources it
|
|
28
|
+
* will accept, and the server refuses a value that arrived from anywhere
|
|
29
|
+
* else: a total the model made up must not be checked against itself.
|
|
30
|
+
* `GET /v1/evidence/predicates` lists the allowlist per predicate.
|
|
31
|
+
*/
|
|
32
|
+
export interface TaggedInput {
|
|
33
|
+
value: unknown;
|
|
34
|
+
source: string;
|
|
35
|
+
}
|
|
36
|
+
/** Ergonomic forms accepted per input: a tagged object or a `[value, source]` pair. */
|
|
37
|
+
export type InputSpec = TaggedInput | [unknown, string];
|
|
38
|
+
export interface EvidenceResult {
|
|
39
|
+
predicate: string;
|
|
40
|
+
verdict: EvidenceVerdict | string;
|
|
41
|
+
action: EvidenceAction | string;
|
|
42
|
+
/** The resolved values the verdict was reached from. */
|
|
43
|
+
values: unknown[];
|
|
44
|
+
evidenceTs?: number;
|
|
45
|
+
source?: string;
|
|
46
|
+
tableVersion?: string;
|
|
47
|
+
/** The right value, when the server knows it. Never invented. */
|
|
48
|
+
correction?: unknown;
|
|
49
|
+
/** What to ask about, on a clarify action. */
|
|
50
|
+
clarifyOn: unknown[];
|
|
51
|
+
/** Server-side record of this check, for an audit trail. */
|
|
52
|
+
attestationId?: string;
|
|
53
|
+
}
|
|
54
|
+
/** The check did not reach a verdict. The caller decides open or closed. */
|
|
55
|
+
export declare class EvidenceError extends Error {
|
|
56
|
+
readonly status?: number;
|
|
57
|
+
constructor(message: string, status?: number);
|
|
58
|
+
}
|
|
59
|
+
/** True when this verdict must stop the response. */
|
|
60
|
+
export declare function isBlocking(result: EvidenceResult): boolean;
|
|
61
|
+
/** True when this verdict asks the agent to clarify rather than stop. */
|
|
62
|
+
export declare function needsClarification(result: EvidenceResult): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Ergonomic input forms to the wire's tagged shape.
|
|
65
|
+
*
|
|
66
|
+
* An untagged input is rejected here rather than sent. The server would
|
|
67
|
+
* refuse it anyway under the taint rule, and failing locally names the
|
|
68
|
+
* input that is missing its tag.
|
|
69
|
+
*
|
|
70
|
+
* The pair form needs a string source. Without that check a two-element
|
|
71
|
+
* array of data read as a pair: `{ items: [40, 60] }` became
|
|
72
|
+
* `value: 40, source: "60"`, and the server then refused source `"60"`
|
|
73
|
+
* as untrusted, an error naming nothing the caller had written. A list
|
|
74
|
+
* value takes the explicit form, `[[40, 60], "submitted_output"]`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function normalizeInputs(inputs?: Record<string, InputSpec>): Record<string, TaggedInput>;
|
|
77
|
+
export interface EvidenceClientOptions {
|
|
78
|
+
/** Defaults to `SPONSIO_API_KEY`. */
|
|
79
|
+
apiKey?: string;
|
|
80
|
+
/** Defaults to `SPONSIO_API_URL`, then `https://app.sponsio.dev`. */
|
|
81
|
+
url?: string;
|
|
82
|
+
/** Per-request timeout in milliseconds. */
|
|
83
|
+
timeoutMs?: number;
|
|
84
|
+
}
|
|
85
|
+
export declare class EvidenceClient {
|
|
86
|
+
readonly url: string;
|
|
87
|
+
private readonly apiKey;
|
|
88
|
+
private readonly timeoutMs;
|
|
89
|
+
constructor(opts?: EvidenceClientOptions);
|
|
90
|
+
get configured(): boolean;
|
|
91
|
+
private post;
|
|
92
|
+
/**
|
|
93
|
+
* Verify one claim against fresh evidence, server-side.
|
|
94
|
+
*
|
|
95
|
+
* Throws `EvidenceError` when the check did not run to a verdict.
|
|
96
|
+
* Decide open or closed at the call site; closed means treating the
|
|
97
|
+
* throw as a block.
|
|
98
|
+
*/
|
|
99
|
+
verify(predicate: string, opts?: {
|
|
100
|
+
value?: unknown;
|
|
101
|
+
text?: string;
|
|
102
|
+
inputs?: Record<string, InputSpec>;
|
|
103
|
+
sessionId?: string;
|
|
104
|
+
}): Promise<EvidenceResult>;
|
|
105
|
+
/** The predicate catalog this key can reach. */
|
|
106
|
+
predicates(): Promise<Record<string, unknown>[]>;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../../src/cloud/evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,UAAU,GACV,aAAa,GACb,oBAAoB,GACpB,iBAAiB,CAAC;AAEtB,kDAAkD;AAClD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,uFAAuF;AACvF,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAExD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,cAAc,GAAG,MAAM,CAAC;IAChC,wDAAwD;IACxD,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,8CAA8C;IAC9C,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,4EAA4E;AAC5E,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ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