@sponsio/sdk 0.2.0-alpha.4 → 0.2.0-alpha.8
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/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 +32 -1
- package/contracts/capability/shell.yaml +19 -10
- package/contracts/incident/claude-code-secret-bypass.yaml +46 -14
- package/contracts/incident/cursor-railway-wipe.yaml +60 -4
- package/contracts/incident/openclaw.yaml +9 -63
- 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 +13 -7
- package/dist/cli/packs.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 +198 -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.js +16 -0
- package/dist/core/config-loader.js.map +1 -1
- package/dist/core/evaluator.d.ts +2 -0
- package/dist/core/evaluator.d.ts.map +1 -1
- package/dist/core/evaluator.js +90 -4
- package/dist/core/evaluator.js.map +1 -1
- package/dist/core/grounding.d.ts +43 -7
- package/dist/core/grounding.d.ts.map +1 -1
- package/dist/core/grounding.js +180 -25
- package/dist/core/grounding.js.map +1 -1
- package/dist/core/nl-parser.d.ts +1 -1
- package/dist/core/nl-parser.d.ts.map +1 -1
- package/dist/core/nl-parser.js +616 -40
- package/dist/core/nl-parser.js.map +1 -1
- package/dist/core/pattern-factory.d.ts.map +1 -1
- package/dist/core/pattern-factory.js +7 -1
- package/dist/core/pattern-factory.js.map +1 -1
- package/dist/core/patterns.d.ts +69 -0
- package/dist/core/patterns.d.ts.map +1 -1
- package/dist/core/patterns.js +133 -10
- package/dist/core/patterns.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 +144 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +367 -32
- 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 +51 -12
- 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 -50
- package/dist/integrations/vercel-ai.js.map +1 -1
- package/package.json +12 -8
- package/prompts/onboard.md +17 -4
- package/contracts/core/llm_safety.yaml +0 -138
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One canonical spelling for a tool name, shared by contracts and grounding.
|
|
3
|
+
*
|
|
4
|
+
* Port of sponsio/formulas/tool_names.py.
|
|
5
|
+
*
|
|
6
|
+
* Predicate keys are map keys: ``called(issue_refund)`` and
|
|
7
|
+
* ``called(Issue_Refund)`` are different entries, and a contract looks up
|
|
8
|
+
* the spelling its author typed. So a rule written against ``issue_refund``
|
|
9
|
+
* was silently inert against an event whose tool arrived as
|
|
10
|
+
* ``Issue_Refund``, as ``"issue_refund "`` with a stray space, or as
|
|
11
|
+
* ``mcp__finance__issue_refund`` (our own documented MCP wire format).
|
|
12
|
+
* ``mustPrecede`` compiles to ``Or(order-holds, never-called)``, so a name
|
|
13
|
+
* that never matches makes the second disjunct true and the contract
|
|
14
|
+
* reports satisfied while the guarded action runs unchecked.
|
|
15
|
+
*
|
|
16
|
+
* Two functions, used on opposite sides of the same join:
|
|
17
|
+
*
|
|
18
|
+
* - {@link canonicalTool}: what a *contract* keys on. Contracts are
|
|
19
|
+
* authored once, so they collapse to a single canonical spelling.
|
|
20
|
+
* - {@link toolAliases}: what an *event* answers to. A tool call is a fact
|
|
21
|
+
* and cannot be rewritten, so it is grounded under every spelling a
|
|
22
|
+
* contract might reasonably have used, canonical form included.
|
|
23
|
+
*
|
|
24
|
+
* Widening only ever makes more contracts apply to a given call, never
|
|
25
|
+
* fewer.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Claude Code / MCP wire format: ``mcp__<server>__<tool>``, prefix in any
|
|
29
|
+
* case (``MCP__finance__x`` is the same call). The server segment has no
|
|
30
|
+
* ``__`` of its own; the tool segment may, so the split is on the FIRST
|
|
31
|
+
* ``__`` after the prefix. ``[^\n]`` rather than ``.`` because
|
|
32
|
+
* Python's ``.`` excludes only ``\n`` while JavaScript's also excludes
|
|
33
|
+
* ``\r`` and U+2028/2029.
|
|
34
|
+
*/
|
|
35
|
+
export const MCP_TOOL_RE = /^mcp__([^_]+(?:_[^_]+)*)__([^\n]+)$/i;
|
|
36
|
+
/**
|
|
37
|
+
* OpenClaw's MCP wire format: ``<server>__<tool>`` with no ``mcp__``
|
|
38
|
+
* prefix. Same split; consulted only when {@link MCP_TOOL_RE} did not
|
|
39
|
+
* match, so the ``mcp`` of a prefixed name is never read as a server.
|
|
40
|
+
*/
|
|
41
|
+
export const SERVER_TOOL_RE = /^([^_]+(?:_[^_]+)*)__([^\n]+)$/;
|
|
42
|
+
/**
|
|
43
|
+
* Python ``str.strip()`` whitespace (``str.isspace``). Differs from
|
|
44
|
+
* ``String.prototype.trim`` on U+001C-001F and U+0085 (Python strips,
|
|
45
|
+
* JavaScript keeps) and U+FEFF (JavaScript strips, Python keeps).
|
|
46
|
+
*/
|
|
47
|
+
const PY_WS = "\\t\\n\\v\\f\\r\\x1c-\\x20\\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
|
|
48
|
+
const PY_STRIP_RE = new RegExp(`^[${PY_WS}]+|[${PY_WS}]+$`, "g");
|
|
49
|
+
function pyStrip(s) {
|
|
50
|
+
return s.replace(PY_STRIP_RE, "");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Python ``str.casefold()``, per code point.
|
|
54
|
+
*
|
|
55
|
+
* Lower-casing alone misses the full case folds (``ß`` -> ``ss``,
|
|
56
|
+
* ``ſ`` -> ``s``, final sigma -> ``σ``, ``µ`` -> ``μ``); folding through
|
|
57
|
+
* the upper case catches those. Two families need explicit handling:
|
|
58
|
+
* dotless ``ı`` has no fold in Python but upper-cases to ``I``, and
|
|
59
|
+
* Unicode folds lower-case Cherokee *to* the upper-case letters. Code
|
|
60
|
+
* points added in a Unicode version one runtime knows and the other does
|
|
61
|
+
* not can still differ; tool names are ASCII in practice.
|
|
62
|
+
*/
|
|
63
|
+
function pyCasefold(s) {
|
|
64
|
+
let out = "";
|
|
65
|
+
for (const ch of s) {
|
|
66
|
+
const cp = ch.codePointAt(0);
|
|
67
|
+
if (cp < 0x80) {
|
|
68
|
+
out += ch.toLowerCase();
|
|
69
|
+
}
|
|
70
|
+
else if (cp === 0x131) {
|
|
71
|
+
out += ch;
|
|
72
|
+
}
|
|
73
|
+
else if (cp >= 0xab70 && cp <= 0xabbf) {
|
|
74
|
+
out += String.fromCodePoint(cp - 0xab70 + 0x13a0);
|
|
75
|
+
}
|
|
76
|
+
else if (cp >= 0x13f8 && cp <= 0x13fd) {
|
|
77
|
+
out += String.fromCodePoint(cp - 8);
|
|
78
|
+
}
|
|
79
|
+
else if (cp >= 0x13a0 && cp <= 0x13f5) {
|
|
80
|
+
out += ch;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const lower = ch.toLowerCase();
|
|
84
|
+
const upper = lower.toUpperCase();
|
|
85
|
+
out += upper !== lower ? upper.toLowerCase() : lower;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/** ``mcp__finance__issue_refund`` -> ``issue_refund``; else ``null``. */
|
|
91
|
+
function stripMcp(name) {
|
|
92
|
+
const m = MCP_TOOL_RE.exec(name);
|
|
93
|
+
return m ? m[2] : null;
|
|
94
|
+
}
|
|
95
|
+
/** ``finance__issue_refund`` -> ``issue_refund``; else ``null``. */
|
|
96
|
+
function stripServer(name) {
|
|
97
|
+
const m = SERVER_TOOL_RE.exec(name);
|
|
98
|
+
return m ? m[2] : null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The single spelling a contract keys on.
|
|
102
|
+
*
|
|
103
|
+
* Strips surrounding whitespace and case-folds. The MCP prefix is *not*
|
|
104
|
+
* stripped here: a contract that deliberately names
|
|
105
|
+
* ``mcp__finance__issue_refund`` means that server's tool and should not
|
|
106
|
+
* widen to every tool of that name. Grounding supplies the bare-name
|
|
107
|
+
* alias so the reverse direction still joins.
|
|
108
|
+
*/
|
|
109
|
+
export function canonicalTool(tool) {
|
|
110
|
+
return pyCasefold(pyStrip(String(tool)));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Every spelling an event's tool call should answer to.
|
|
114
|
+
*
|
|
115
|
+
* Ordered, duplicate-free, and always contains the raw name first so
|
|
116
|
+
* existing traces and predicate keys keep working unchanged.
|
|
117
|
+
*/
|
|
118
|
+
export function toolAliases(tool) {
|
|
119
|
+
const raw = String(tool);
|
|
120
|
+
const out = [raw];
|
|
121
|
+
const stripped = pyStrip(raw);
|
|
122
|
+
out.push(stripped, pyCasefold(stripped));
|
|
123
|
+
const bare = stripMcp(stripped) ?? stripServer(stripped);
|
|
124
|
+
if (bare)
|
|
125
|
+
out.push(bare, pyCasefold(bare));
|
|
126
|
+
return [...new Set(out)].filter((k) => k);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=tool-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-names.js","sourceRoot":"","sources":["../../src/core/tool-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,sCAAsC,CAAC;AAElE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,gCAAgC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,KAAK,GAAG,+FAA+F,CAAC;AAC9G,MAAM,WAAW,GAAG,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,KAAK,KAAK,EAAE,GAAG,CAAC,CAAC;AAEjE,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;QACnB,MAAM,EAAE,GAAG,EAAE,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AC,IAAI,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACzB,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,IAAI;QAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* if (result.blocked) { ... }
|
|
21
21
|
*/
|
|
22
22
|
import { AgentTurnSpan } from "./core/spans.js";
|
|
23
|
+
import { CloudClient } from "./cloud/client.js";
|
|
23
24
|
import type { DetFormula } from "./core/patterns.js";
|
|
24
25
|
import type { JudgeClient, JudgeConfig, StoContextSnapshot } from "./core/sto.js";
|
|
25
26
|
export { evaluate } from "./core/evaluator.js";
|
|
@@ -35,6 +36,12 @@ export { SessionLogger, rotateSessions } from "./core/session-log.js";
|
|
|
35
36
|
export type { SessionRecord, SessionLoggerOptions, } from "./core/session-log.js";
|
|
36
37
|
export { contract, ContractBuilder } from "./contract.js";
|
|
37
38
|
export { parseScore, CloudFeatureError } from "./core/sto.js";
|
|
39
|
+
export { CloudClient, CloudError, readApiKey, readProject, baseUrl, } from "./cloud/client.js";
|
|
40
|
+
export type { PulledRulebook, CloudClientOptions } from "./cloud/client.js";
|
|
41
|
+
export { LEVELS as PRIVACY_LEVELS } from "./cloud/privacy.js";
|
|
42
|
+
export type { PrivacyLevel } from "./cloud/privacy.js";
|
|
43
|
+
export { buildViewModel, newSessionId } from "./cloud/view-model.js";
|
|
44
|
+
export type { RunSpan, ViewModelInput } from "./cloud/view-model.js";
|
|
38
45
|
export type { StoEvaluator, StoContract, StoInput, StoResult, StoContextSnapshot, JudgeClient, JudgeConfig, } from "./core/sto.js";
|
|
39
46
|
/**
|
|
40
47
|
* One det violation, with enough structure to feed into downstream
|
|
@@ -61,9 +68,28 @@ export type { StoEvaluator, StoContract, StoInput, StoResult, StoContextSnapshot
|
|
|
61
68
|
* - ``alternatives`` is an optional list of suggested replacement
|
|
62
69
|
* actions for blocked / redirected outcomes.
|
|
63
70
|
*/
|
|
71
|
+
/**
|
|
72
|
+
* What the runtime did about one violation, mirroring Python's
|
|
73
|
+
* ``DetViolation.action``. Every derived verdict property reads this
|
|
74
|
+
* rather than a separate boolean, so a new outcome cannot be added
|
|
75
|
+
* without every consumer seeing it.
|
|
76
|
+
*
|
|
77
|
+
* ``blocked`` and ``redirected`` both stop the original call and are the
|
|
78
|
+
* members of the stopping set; ``escalated`` hands the decision to a
|
|
79
|
+
* human without stopping, and ``observed`` / ``warned`` record only.
|
|
80
|
+
*/
|
|
81
|
+
export type DetAction = "blocked" | "redirected" | "escalated" | "observed" | "warned";
|
|
82
|
+
/** Actions after which the original tool call must NOT run. */
|
|
83
|
+
export declare const STOPPING_ACTIONS: ReadonlySet<DetAction>;
|
|
84
|
+
/** Parity with Python's ``is_stopping_action``. */
|
|
85
|
+
export declare function isStoppingAction(action: DetAction): boolean;
|
|
64
86
|
export interface DetViolation {
|
|
65
87
|
/** Human-readable contract description (``DetFormula.desc``). */
|
|
66
88
|
desc: string;
|
|
89
|
+
/** What the runtime did. Absent on rows written before this field existed. */
|
|
90
|
+
action?: DetAction;
|
|
91
|
+
/** The tool to call instead, set when ``action`` is ``redirected``. */
|
|
92
|
+
redirectedTo?: string;
|
|
67
93
|
/** Formatted ``"[WOULD-]BLOCKED: agent.tool — det constraint …"``. */
|
|
68
94
|
message: string;
|
|
69
95
|
/** Stable rule identifier (pattern name / contract id). */
|
|
@@ -107,7 +133,40 @@ export interface CheckResult {
|
|
|
107
133
|
* consistently across both surfaces.
|
|
108
134
|
*/
|
|
109
135
|
stoViolations: DetViolation[];
|
|
136
|
+
/** True when any violation returned an escalate outcome. */
|
|
137
|
+
escalated: boolean;
|
|
138
|
+
/** True when any violation returned a redirect outcome. */
|
|
139
|
+
redirected: boolean;
|
|
140
|
+
/** The substitute tool named by the first redirect, if any. */
|
|
141
|
+
redirectedTo?: string;
|
|
142
|
+
/**
|
|
143
|
+
* True when the original tool call must NOT run.
|
|
144
|
+
*
|
|
145
|
+
* **This is the gate an adapter branches on, not `blocked`.** A
|
|
146
|
+
* redirect leaves `blocked` false and `allowed` true, because the
|
|
147
|
+
* agent flow continues down the safe path; a caller reading `blocked`
|
|
148
|
+
* would run the exact call the contract forbade. Adapters that can
|
|
149
|
+
* substitute should branch on `redirected` / `redirectedTo` first and
|
|
150
|
+
* dispatch the safe tool; those that cannot must gate on this, so a
|
|
151
|
+
* redirect fails closed.
|
|
152
|
+
*/
|
|
153
|
+
stopOriginal: boolean;
|
|
154
|
+
/** Det and sto violations together, in that order. */
|
|
155
|
+
allViolations: DetViolation[];
|
|
156
|
+
/**
|
|
157
|
+
* True if any sto violation asked for a retry. Always false in this
|
|
158
|
+
* build: the engine is deterministic-only and `stoViolations` is
|
|
159
|
+
* always empty. Present so an adapter written against one runtime
|
|
160
|
+
* reads the same on the other.
|
|
161
|
+
*/
|
|
162
|
+
needsRetry: boolean;
|
|
110
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Fill the derived half of a verdict from the violations' actions. One
|
|
166
|
+
* place, so a new `DetAction` cannot be handled inconsistently across
|
|
167
|
+
* the several sites that build a `CheckResult`.
|
|
168
|
+
*/
|
|
169
|
+
export declare function deriveVerdict(detViolations: DetViolation[], stoViolations?: DetViolation[]): Pick<CheckResult, "blocked" | "escalated" | "redirected" | "redirectedTo" | "stopOriginal" | "allViolations" | "needsRetry">;
|
|
111
170
|
export type SponsoMode = "enforce" | "observe";
|
|
112
171
|
export interface SponsoOptions {
|
|
113
172
|
/** Logical agent id — used for session log paths. */
|
|
@@ -175,7 +234,45 @@ export declare class Sponsio {
|
|
|
175
234
|
private _violations;
|
|
176
235
|
private _logger;
|
|
177
236
|
private _turnSpans;
|
|
237
|
+
private _runSpans;
|
|
238
|
+
private _sessionId;
|
|
239
|
+
private _startedAt;
|
|
240
|
+
private _rulebookStamp;
|
|
178
241
|
constructor(options?: SponsoOptions);
|
|
242
|
+
/**
|
|
243
|
+
* Predicates whose truth depends on the *contents* of a tool call's
|
|
244
|
+
* arguments. If a call arrives with no arguments, none of these keys is
|
|
245
|
+
* written and the evaluator reads a missing key as false, which makes
|
|
246
|
+
* ``argBlacklist`` (``!arg_field_has(...)``) report "satisfied" for a
|
|
247
|
+
* call nothing looked at. Mirrors Python's
|
|
248
|
+
* ``BaseGuard._ARG_SHAPED_PREDICATES``.
|
|
249
|
+
*/
|
|
250
|
+
private static readonly ARG_SHAPED_PREDICATES;
|
|
251
|
+
/** Canonical names of the tools some contract reads the arguments of. */
|
|
252
|
+
private _toolsNeedingArgs;
|
|
253
|
+
/** ``[tool, field]`` pairs some ``arg_numeric`` rule reads. */
|
|
254
|
+
private _numericRuleTargets;
|
|
255
|
+
/**
|
|
256
|
+
* Refuse a call whose argument rules cannot be evaluated.
|
|
257
|
+
*
|
|
258
|
+
* Two cases, both of which used to read as "not violated":
|
|
259
|
+
*
|
|
260
|
+
* - The call arrived with no arguments (``{}``, ``undefined``, ``null``)
|
|
261
|
+
* but some rule reads this tool's arguments. An adapter that loses the
|
|
262
|
+
* arguments, a partial streamed call or a malformed payload all land
|
|
263
|
+
* here, and every argument check would pass vacuously.
|
|
264
|
+
* - A field an ``arg_numeric`` rule bounds is present but is not a
|
|
265
|
+
* number (``"five thousand"``). Grounding leaves ``arg_numeric`` unset
|
|
266
|
+
* and the evaluator reads the gap as 0, which passes every upper
|
|
267
|
+
* bound. An absent field is left alone: CLI-flag and positional rules
|
|
268
|
+
* on ``Bash`` legitimately see calls without their flag.
|
|
269
|
+
*
|
|
270
|
+
* ``SPONSIO_ALLOW_MISSING_ARGS=1`` restores the permissive behaviour.
|
|
271
|
+
* Mirrors Python ``BaseGuard._args_unevaluable`` and
|
|
272
|
+
* ``_unreadable_numeric_arg``; both block under rule id
|
|
273
|
+
* ``args:unevaluable``.
|
|
274
|
+
*/
|
|
275
|
+
private _unevaluableArgs;
|
|
179
276
|
/**
|
|
180
277
|
* Check a tool call against contracts before execution.
|
|
181
278
|
*
|
|
@@ -202,6 +299,28 @@ export declare class Sponsio {
|
|
|
202
299
|
turnSpans(): AgentTurnSpan[];
|
|
203
300
|
/** Drop accumulated turn spans (used between sessions in tests). */
|
|
204
301
|
resetSession(): void;
|
|
302
|
+
/**
|
|
303
|
+
* This run, in the shape the cloud stores.
|
|
304
|
+
*
|
|
305
|
+
* Exposed so a caller can see exactly what would be uploaded before
|
|
306
|
+
* uploading anything, which is the question a customer under a data
|
|
307
|
+
* agreement asks first.
|
|
308
|
+
*/
|
|
309
|
+
viewModel(): Record<string, unknown>;
|
|
310
|
+
/**
|
|
311
|
+
* Upload this run.
|
|
312
|
+
*
|
|
313
|
+
* Best-effort by construction: it resolves false rather than throwing,
|
|
314
|
+
* because losing telemetry must never change what an agent does, and a
|
|
315
|
+
* rejected upload at the end of a run is not a reason to fail the run.
|
|
316
|
+
* Silent only about the network; a misconfiguration is worth saying
|
|
317
|
+
* once, since the symptom otherwise is a customer with no runs and no
|
|
318
|
+
* explanation.
|
|
319
|
+
*/
|
|
320
|
+
uploadSession(opts?: {
|
|
321
|
+
project?: string | null;
|
|
322
|
+
client?: CloudClient;
|
|
323
|
+
}): Promise<boolean>;
|
|
205
324
|
/**
|
|
206
325
|
* Render the end-of-session view to ``out`` (defaults to stderr) —
|
|
207
326
|
* banner, contracts armed, trace tree, verdict, perf, CTA. Mirrors
|
|
@@ -252,9 +371,34 @@ export declare class Sponsio {
|
|
|
252
371
|
* violations the same way they branch on ``guardBefore``. In
|
|
253
372
|
* enforce mode, ``blocked: true`` rolls back the synthetic event.
|
|
254
373
|
*/
|
|
374
|
+
/**
|
|
375
|
+
* Record a claim-verification verdict in the trace and check the
|
|
376
|
+
* contracts that reference it.
|
|
377
|
+
*
|
|
378
|
+
* Grounds `claim_emitted(pred)`, `evidence_verdict(pred, V)` and
|
|
379
|
+
* `evidence_action(pred, a)` at one timestep, so contracts built from
|
|
380
|
+
* `claimRequiresEvidence` / `underdeterminedMustClarify` can decide.
|
|
381
|
+
* No verdict is computed here: the atoms restate what
|
|
382
|
+
* `/v1/evidence/verify` answered.
|
|
383
|
+
*
|
|
384
|
+
* Parity with feeding `EvidenceResult.to_event()` through Python's
|
|
385
|
+
* trace path.
|
|
386
|
+
*/
|
|
387
|
+
observeEvidence(predicate: string, verdict: string, action: string): CheckResult;
|
|
255
388
|
observeResponse(content: string, opts?: {
|
|
256
389
|
segment?: string;
|
|
257
390
|
}): CheckResult;
|
|
391
|
+
/**
|
|
392
|
+
* Check one synthetic (non-tool-call) event against every contract.
|
|
393
|
+
*
|
|
394
|
+
* The output lane and the evidence lane both push an event that is not
|
|
395
|
+
* a tool call and then judge the trace. Sharing the body keeps their
|
|
396
|
+
* verdicts identical: a second copy is how one lane ends up with a
|
|
397
|
+
* rollback the other lacks.
|
|
398
|
+
*
|
|
399
|
+
* `label` names the subject in violation messages and session logs.
|
|
400
|
+
*/
|
|
401
|
+
private _checkSynthetic;
|
|
258
402
|
private _logViolations;
|
|
259
403
|
private _logAllow;
|
|
260
404
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAsBH,OAAO,EACL,aAAa,EAKd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAO7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEX,kBAAkB,EAEnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,YAAY,EACV,aAAa,EACb,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAA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