@sponsio/sdk 0.1.0-alpha.3

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.
Files changed (113) hide show
  1. package/contracts/capability/credentials.yaml +188 -0
  2. package/contracts/capability/database.yaml +141 -0
  3. package/contracts/capability/filesystem-strict.yaml +101 -0
  4. package/contracts/capability/filesystem.yaml +239 -0
  5. package/contracts/capability/self-modify.yaml +152 -0
  6. package/contracts/capability/shell.yaml +246 -0
  7. package/contracts/capability/subagent.yaml +184 -0
  8. package/contracts/core/llm_safety.yaml +130 -0
  9. package/contracts/core/runaway.yaml +43 -0
  10. package/contracts/core/universal.yaml +34 -0
  11. package/contracts/incident/claude-code-secret-bypass.yaml +197 -0
  12. package/contracts/incident/cursor-railway-wipe.yaml +164 -0
  13. package/contracts/incident/mcp-composition.yaml +418 -0
  14. package/contracts/incident/openclaw.yaml +500 -0
  15. package/contracts/incident/subagent-escape.yaml +177 -0
  16. package/contracts/premium/.gitkeep +7 -0
  17. package/dist/contract.d.ts +59 -0
  18. package/dist/contract.d.ts.map +1 -0
  19. package/dist/contract.js +97 -0
  20. package/dist/contract.js.map +1 -0
  21. package/dist/core/config-loader.d.ts +90 -0
  22. package/dist/core/config-loader.d.ts.map +1 -0
  23. package/dist/core/config-loader.js +530 -0
  24. package/dist/core/config-loader.js.map +1 -0
  25. package/dist/core/evaluator.d.ts +15 -0
  26. package/dist/core/evaluator.d.ts.map +1 -0
  27. package/dist/core/evaluator.js +87 -0
  28. package/dist/core/evaluator.js.map +1 -0
  29. package/dist/core/formula.d.ts +103 -0
  30. package/dist/core/formula.d.ts.map +1 -0
  31. package/dist/core/formula.js +167 -0
  32. package/dist/core/formula.js.map +1 -0
  33. package/dist/core/grounding.d.ts +43 -0
  34. package/dist/core/grounding.d.ts.map +1 -0
  35. package/dist/core/grounding.js +269 -0
  36. package/dist/core/grounding.js.map +1 -0
  37. package/dist/core/nl-parser.d.ts +12 -0
  38. package/dist/core/nl-parser.d.ts.map +1 -0
  39. package/dist/core/nl-parser.js +152 -0
  40. package/dist/core/nl-parser.js.map +1 -0
  41. package/dist/core/pack-loader.d.ts +15 -0
  42. package/dist/core/pack-loader.d.ts.map +1 -0
  43. package/dist/core/pack-loader.js +220 -0
  44. package/dist/core/pack-loader.js.map +1 -0
  45. package/dist/core/parser.d.ts +19 -0
  46. package/dist/core/parser.d.ts.map +1 -0
  47. package/dist/core/parser.js +235 -0
  48. package/dist/core/parser.js.map +1 -0
  49. package/dist/core/pattern-factory.d.ts +38 -0
  50. package/dist/core/pattern-factory.d.ts.map +1 -0
  51. package/dist/core/pattern-factory.js +222 -0
  52. package/dist/core/pattern-factory.js.map +1 -0
  53. package/dist/core/patterns.d.ts +67 -0
  54. package/dist/core/patterns.d.ts.map +1 -0
  55. package/dist/core/patterns.js +585 -0
  56. package/dist/core/patterns.js.map +1 -0
  57. package/dist/core/session-log.d.ts +91 -0
  58. package/dist/core/session-log.d.ts.map +1 -0
  59. package/dist/core/session-log.js +196 -0
  60. package/dist/core/session-log.js.map +1 -0
  61. package/dist/core/spans.d.ts +92 -0
  62. package/dist/core/spans.d.ts.map +1 -0
  63. package/dist/core/spans.js +148 -0
  64. package/dist/core/spans.js.map +1 -0
  65. package/dist/core/sto.d.ts +120 -0
  66. package/dist/core/sto.d.ts.map +1 -0
  67. package/dist/core/sto.js +147 -0
  68. package/dist/core/sto.js.map +1 -0
  69. package/dist/index.d.ts +267 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +540 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/integrations/claude-agent.d.ts +29 -0
  74. package/dist/integrations/claude-agent.d.ts.map +1 -0
  75. package/dist/integrations/claude-agent.js +40 -0
  76. package/dist/integrations/claude-agent.js.map +1 -0
  77. package/dist/integrations/google-adk.d.ts +27 -0
  78. package/dist/integrations/google-adk.d.ts.map +1 -0
  79. package/dist/integrations/google-adk.js +81 -0
  80. package/dist/integrations/google-adk.js.map +1 -0
  81. package/dist/integrations/langchain.d.ts +26 -0
  82. package/dist/integrations/langchain.d.ts.map +1 -0
  83. package/dist/integrations/langchain.js +74 -0
  84. package/dist/integrations/langchain.js.map +1 -0
  85. package/dist/integrations/openai-agents.d.ts +45 -0
  86. package/dist/integrations/openai-agents.d.ts.map +1 -0
  87. package/dist/integrations/openai-agents.js +81 -0
  88. package/dist/integrations/openai-agents.js.map +1 -0
  89. package/dist/integrations/openai.d.ts +24 -0
  90. package/dist/integrations/openai.d.ts.map +1 -0
  91. package/dist/integrations/openai.js +77 -0
  92. package/dist/integrations/openai.js.map +1 -0
  93. package/dist/integrations/vercel-ai.d.ts +38 -0
  94. package/dist/integrations/vercel-ai.d.ts.map +1 -0
  95. package/dist/integrations/vercel-ai.js +107 -0
  96. package/dist/integrations/vercel-ai.js.map +1 -0
  97. package/dist/render/components.d.ts +23 -0
  98. package/dist/render/components.d.ts.map +1 -0
  99. package/dist/render/components.js +133 -0
  100. package/dist/render/components.js.map +1 -0
  101. package/dist/render/derive.d.ts +23 -0
  102. package/dist/render/derive.d.ts.map +1 -0
  103. package/dist/render/derive.js +92 -0
  104. package/dist/render/derive.js.map +1 -0
  105. package/dist/render/session-view.d.ts +19 -0
  106. package/dist/render/session-view.d.ts.map +1 -0
  107. package/dist/render/session-view.js +236 -0
  108. package/dist/render/session-view.js.map +1 -0
  109. package/dist/render/tokens.d.ts +44 -0
  110. package/dist/render/tokens.d.ts.map +1 -0
  111. package/dist/render/tokens.js +72 -0
  112. package/dist/render/tokens.js.map +1 -0
  113. package/package.json +83 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Per-session JSONL event log for the TypeScript runtime.
3
+ *
4
+ * Mirrors ``sponsio/runtime/session_log.py`` byte-for-byte on the
5
+ * record schema so ``sponsio report --agent <id>`` reads
6
+ * Python-produced and TS-produced logs with the same reducer.
7
+ *
8
+ * Layout:
9
+ *
10
+ * ~/.sponsio/sessions/<sanitized_agent_id>/
11
+ * <YYYYMMDD_HHMMSS>_<pid>.jsonl
12
+ *
13
+ * Rotation on startup:
14
+ * * files older than `keepDays` days are unlinked
15
+ * * if the remaining total exceeds `maxMB` megabytes, the oldest
16
+ * remaining files are unlinked until the budget is met
17
+ *
18
+ * Stdlib-only — no filesystem dep beyond `node:fs`, `node:os`, `node:path`.
19
+ * Errors during rotation / writes are swallowed: a log failure must
20
+ * never take down the agent.
21
+ */
22
+ /**
23
+ * Prune old / oversized session files under ``baseDir``.
24
+ *
25
+ * Walks two levels (``<baseDir>/<agent_id>/*.jsonl``) since that's
26
+ * how session files are laid out in practice. Any IO error is
27
+ * swallowed silently.
28
+ */
29
+ export declare function rotateSessions(baseDir: string, keepDays?: number, maxMB?: number): string[];
30
+ /**
31
+ * Action strings emitted / consumed by the session log.
32
+ *
33
+ * The TS writer uses the three canonical values — ``allowed`` /
34
+ * ``blocked`` / ``observed`` — that map 1:1 to the common
35
+ * det-pipeline outcomes. The type also lists the extended values
36
+ * Python's sto pipeline can emit (``escalated`` / ``warned`` /
37
+ * ``retrying`` / ``redirected``) so TS readers can consume a JSONL
38
+ * produced by the Python runtime without a schema mismatch. TS
39
+ * never writes those extended values itself today.
40
+ *
41
+ * Historical: earlier TS builds wrote ``"allow" / "block" /
42
+ * "observe_log"``. The ``sponsio-scan-ts report`` reducer still
43
+ * accepts those legacy values so old logs on disk keep rendering —
44
+ * but new writes always use the canonical names.
45
+ */
46
+ export type SessionAction = "allowed" | "blocked" | "observed" | "escalated" | "warned" | "retrying" | "redirected";
47
+ export interface SessionRecord {
48
+ /** Unix seconds, to match the Python writer (float). */
49
+ ts: number;
50
+ agent_id: string;
51
+ action: SessionAction;
52
+ /**
53
+ * ``det`` — deterministic LTL/DFA evaluation.
54
+ * ``sto`` — stochastic (LLM-judged) evaluation. Paired with the
55
+ * optional ``sto`` field at the record root, which carries the
56
+ * judge's numeric score and a short evidence snippet — matching
57
+ * ``sponsio/runtime/session_log.py`` so ``sponsio report`` can
58
+ * read TS-emitted sto records without a schema change.
59
+ */
60
+ pipeline: "det" | "sto";
61
+ constraint: string;
62
+ result: {
63
+ action: SessionAction;
64
+ message: string;
65
+ };
66
+ /** Present only when ``pipeline === "sto"``. */
67
+ sto?: {
68
+ score: number;
69
+ evidence?: string;
70
+ };
71
+ }
72
+ export interface SessionLoggerOptions {
73
+ baseDir?: string;
74
+ keepDays?: number;
75
+ maxMB?: number;
76
+ /** Fixed stamp for deterministic tests. */
77
+ timestamp?: string;
78
+ /** Skip startup rotation (tests). */
79
+ skipRotation?: boolean;
80
+ }
81
+ /**
82
+ * Append-only JSONL logger. Instances own one file for the lifetime
83
+ * of the process; repeated guards from the same pid reuse it.
84
+ */
85
+ export declare class SessionLogger {
86
+ readonly agentId: string;
87
+ readonly path: string;
88
+ constructor(agentId: string, options?: SessionLoggerOptions);
89
+ log(record: SessionRecord): void;
90
+ }
91
+ //# sourceMappingURL=session-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-log.d.ts","sourceRoot":"","sources":["../../src/core/session-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAqEH;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAA0B,EACpC,KAAK,GAAE,MAAuB,GAC7B,MAAM,EAAE,CAgEV;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,SAAS,GACT,UAAU,GACV,WAAW,GACX,QAAQ,GACR,UAAU,GACV,YAAY,CAAC;AAEjB,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;IACtB;;;;;;;OAOG;IACH,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,aAAa,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,gDAAgD;IAChD,GAAG,CAAC,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB;IA8B/D,GAAG,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CAcjC"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Per-session JSONL event log for the TypeScript runtime.
3
+ *
4
+ * Mirrors ``sponsio/runtime/session_log.py`` byte-for-byte on the
5
+ * record schema so ``sponsio report --agent <id>`` reads
6
+ * Python-produced and TS-produced logs with the same reducer.
7
+ *
8
+ * Layout:
9
+ *
10
+ * ~/.sponsio/sessions/<sanitized_agent_id>/
11
+ * <YYYYMMDD_HHMMSS>_<pid>.jsonl
12
+ *
13
+ * Rotation on startup:
14
+ * * files older than `keepDays` days are unlinked
15
+ * * if the remaining total exceeds `maxMB` megabytes, the oldest
16
+ * remaining files are unlinked until the budget is met
17
+ *
18
+ * Stdlib-only — no filesystem dep beyond `node:fs`, `node:os`, `node:path`.
19
+ * Errors during rotation / writes are swallowed: a log failure must
20
+ * never take down the agent.
21
+ */
22
+ import { appendFileSync, existsSync, mkdirSync, readdirSync, statSync, unlinkSync, } from "node:fs";
23
+ import { homedir } from "node:os";
24
+ import { join } from "node:path";
25
+ /**
26
+ * Lazily resolve a process id, defaulting to ``0`` on runtimes
27
+ * without a ``process`` global. Cloudflare Workers / Vercel Edge
28
+ * expose a ``process`` shim but no ``pid`` — the previous
29
+ * top-level ``import { pid } from "node:process"`` blew up module
30
+ * load time on those runtimes, contradicting the package.json's
31
+ * "Edge/Serverless compatible" claim. Callers that actually need
32
+ * a distinct stamp per session (local dev + server processes) still
33
+ * get one; Edge users trivially collide with ``0`` but they also
34
+ * typically pass ``sessionLog: false`` because ``~/.sponsio`` isn't
35
+ * writable there. Either way the module loads.
36
+ */
37
+ function resolvePid() {
38
+ try {
39
+ const p = globalThis.process;
40
+ return typeof p?.pid === "number" ? p.pid : 0;
41
+ }
42
+ catch {
43
+ return 0;
44
+ }
45
+ }
46
+ const DEFAULT_KEEP_DAYS = 7;
47
+ const DEFAULT_MAX_MB = 100;
48
+ // Allow letters, digits, dot (``agent.v2``), dash, underscore, colon
49
+ // (``team:bot``). Disallow path separators and control characters.
50
+ // Matches the Python regex in ``session_log._SAFE_AGENT_ID_RE``.
51
+ const SAFE_AGENT_ID_RE = /[^A-Za-z0-9._:\-]/g;
52
+ function sanitizeAgentId(agentId) {
53
+ if (!agentId)
54
+ return "_unknown";
55
+ const cleaned = agentId.replace(SAFE_AGENT_ID_RE, "_").replace(/^[._]+|[._]+$/g, "");
56
+ if (!cleaned || cleaned === "." || cleaned === "..")
57
+ return "_unknown";
58
+ return cleaned.slice(0, 128);
59
+ }
60
+ function defaultBaseDir() {
61
+ return join(homedir(), ".sponsio", "sessions");
62
+ }
63
+ function pad2(n) {
64
+ return n < 10 ? `0${n}` : `${n}`;
65
+ }
66
+ function timestampStamp(d = new Date()) {
67
+ return (`${d.getFullYear()}` +
68
+ `${pad2(d.getMonth() + 1)}` +
69
+ `${pad2(d.getDate())}` +
70
+ "_" +
71
+ `${pad2(d.getHours())}` +
72
+ `${pad2(d.getMinutes())}` +
73
+ `${pad2(d.getSeconds())}`);
74
+ }
75
+ /**
76
+ * Prune old / oversized session files under ``baseDir``.
77
+ *
78
+ * Walks two levels (``<baseDir>/<agent_id>/*.jsonl``) since that's
79
+ * how session files are laid out in practice. Any IO error is
80
+ * swallowed silently.
81
+ */
82
+ export function rotateSessions(baseDir, keepDays = DEFAULT_KEEP_DAYS, maxMB = DEFAULT_MAX_MB) {
83
+ const removed = [];
84
+ if (!existsSync(baseDir))
85
+ return removed;
86
+ const now = Date.now();
87
+ const cutoffMs = now - keepDays * 86400 * 1000;
88
+ const files = [];
89
+ let agentDirs = [];
90
+ try {
91
+ agentDirs = readdirSync(baseDir);
92
+ }
93
+ catch {
94
+ return removed;
95
+ }
96
+ for (const entry of agentDirs) {
97
+ const dir = join(baseDir, entry);
98
+ let inner = [];
99
+ try {
100
+ inner = readdirSync(dir);
101
+ }
102
+ catch {
103
+ continue;
104
+ }
105
+ for (const f of inner) {
106
+ if (!f.endsWith(".jsonl"))
107
+ continue;
108
+ const p = join(dir, f);
109
+ let st;
110
+ try {
111
+ st = statSync(p);
112
+ }
113
+ catch {
114
+ continue;
115
+ }
116
+ const mtime = st.mtimeMs;
117
+ if (mtime < cutoffMs) {
118
+ try {
119
+ unlinkSync(p);
120
+ removed.push(p);
121
+ }
122
+ catch {
123
+ // ignore
124
+ }
125
+ continue;
126
+ }
127
+ files.push({ path: p, mtime, size: st.size });
128
+ }
129
+ }
130
+ const budget = maxMB * 1024 * 1024;
131
+ let total = files.reduce((acc, f) => acc + f.size, 0);
132
+ if (total > budget) {
133
+ files.sort((a, b) => a.mtime - b.mtime);
134
+ for (const f of files) {
135
+ if (total <= budget)
136
+ break;
137
+ try {
138
+ unlinkSync(f.path);
139
+ removed.push(f.path);
140
+ total -= f.size;
141
+ }
142
+ catch {
143
+ // ignore
144
+ }
145
+ }
146
+ }
147
+ return removed;
148
+ }
149
+ /**
150
+ * Append-only JSONL logger. Instances own one file for the lifetime
151
+ * of the process; repeated guards from the same pid reuse it.
152
+ */
153
+ export class SessionLogger {
154
+ agentId;
155
+ path;
156
+ constructor(agentId, options = {}) {
157
+ this.agentId = agentId;
158
+ const base = options.baseDir ?? defaultBaseDir();
159
+ const safe = sanitizeAgentId(agentId);
160
+ try {
161
+ mkdirSync(base, { recursive: true });
162
+ }
163
+ catch {
164
+ // ignore — write will fail loudly below if truly broken
165
+ }
166
+ const agentDir = join(base, safe);
167
+ try {
168
+ mkdirSync(agentDir, { recursive: true });
169
+ }
170
+ catch {
171
+ // ignore
172
+ }
173
+ if (!options.skipRotation) {
174
+ rotateSessions(base, options.keepDays ?? DEFAULT_KEEP_DAYS, options.maxMB ?? DEFAULT_MAX_MB);
175
+ }
176
+ const stamp = options.timestamp ?? timestampStamp();
177
+ this.path = join(agentDir, `${stamp}_${resolvePid()}.jsonl`);
178
+ }
179
+ log(record) {
180
+ let line;
181
+ try {
182
+ line = JSON.stringify(record);
183
+ }
184
+ catch {
185
+ // Never break the agent because of log serialization.
186
+ return;
187
+ }
188
+ try {
189
+ appendFileSync(this.path, line + "\n", "utf-8");
190
+ }
191
+ catch {
192
+ // Disk full, perms, etc. — silently drop.
193
+ }
194
+ }
195
+ }
196
+ //# sourceMappingURL=session-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-log.js","sourceRoot":"","sources":["../../src/core/session-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,WAAW,EACX,QAAQ,EACR,UAAU,GACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,SAAS,UAAU;IACjB,IAAI,CAAC;QACH,MAAM,CAAC,GAAI,UAA8C,CAAC,OAAO,CAAC;QAClE,OAAO,OAAO,CAAC,EAAE,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CA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0CAA0C;QAC5C,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Span data model — mirrors ``sponsio/models/spans.py``.
3
+ *
4
+ * The runtime monitor builds one ``AgentTurnSpan`` tree per
5
+ * ``guardBefore`` call. Children include per-contract evaluation
6
+ * spans, with grand-children for assumption / guarantee / violation /
7
+ * enforcement nodes. The session view renderer walks this tree to
8
+ * produce the ``contracts armed`` + ``trace`` + ``VERDICT`` zones.
9
+ *
10
+ * Subclasses match the Python ``span_type`` strings field-for-field
11
+ * so traces serialise identically across languages.
12
+ */
13
+ export type SpanStatus = "ok" | "violated" | "error";
14
+ export interface SpanLike {
15
+ spanType: string;
16
+ startTime: number;
17
+ endTime?: number;
18
+ status: SpanStatus;
19
+ attributes: Record<string, unknown>;
20
+ children: SpanLike[];
21
+ durationMs(): number | null;
22
+ finish(status?: SpanStatus): void;
23
+ }
24
+ export declare class Span implements SpanLike {
25
+ spanType: string;
26
+ startTime: number;
27
+ endTime?: number;
28
+ status: SpanStatus;
29
+ attributes: Record<string, unknown>;
30
+ children: SpanLike[];
31
+ constructor(spanType: string, attributes?: Record<string, unknown>);
32
+ durationMs(): number | null;
33
+ finish(status?: SpanStatus): void;
34
+ }
35
+ export declare class AgentTurnSpan extends Span {
36
+ agentId: string;
37
+ action: string;
38
+ totalContractsChecked: number;
39
+ detViolations: number;
40
+ stoViolations: number;
41
+ blocked: boolean;
42
+ constructor(agentId: string, action: string);
43
+ }
44
+ export declare class ContractCheckSpan extends Span {
45
+ contractName: string;
46
+ pipeline: "hard" | "sto";
47
+ constructor(contractName: string, pipeline?: "hard" | "sto");
48
+ }
49
+ export declare class PreconditionSpan extends Span {
50
+ formulaDesc: string;
51
+ result: boolean;
52
+ constructor(formulaDesc: string, result: boolean);
53
+ }
54
+ export declare class GuaranteeSpan extends Span {
55
+ formulaDesc: string;
56
+ result: boolean;
57
+ constructor(formulaDesc: string, result: boolean);
58
+ }
59
+ export declare class ViolationSpan extends Span {
60
+ kind: "assumption" | "guarantee" | "sto" | "liveness";
61
+ severity: "HIGH" | "MEDIUM" | "LOW";
62
+ evidence: string;
63
+ constructor(kind: ViolationSpan["kind"], severity?: ViolationSpan["severity"], evidence?: string);
64
+ }
65
+ export declare class EnforcementSpan extends Span {
66
+ strategy: string;
67
+ resultAction: "blocked" | "escalated" | "retrying" | "redirected" | "";
68
+ constructor(strategy: string, resultAction?: EnforcementSpan["resultAction"]);
69
+ }
70
+ /**
71
+ * SpanCollector — builds a span tree during one ``guardBefore`` call.
72
+ * Mirrors Python's ``models.spans.SpanCollector``: a stack of
73
+ * currently-open spans, push/pop to nest. The root is the
74
+ * ``AgentTurnSpan`` returned by ``rootSpan``.
75
+ */
76
+ export declare class SpanCollector {
77
+ private root;
78
+ private stack;
79
+ constructor(agentId: string, action: string);
80
+ rootSpan(): AgentTurnSpan;
81
+ push(span: SpanLike): void;
82
+ pop(status?: SpanStatus): void;
83
+ /** Add a leaf span (no children) and finalize it immediately. */
84
+ add(span: SpanLike, status?: SpanStatus): void;
85
+ /** Finalize the root after the guard call completes. */
86
+ finishRoot(blocked: boolean, totalContractsChecked: number, detViolations: number): AgentTurnSpan;
87
+ }
88
+ /**
89
+ * Walk a span tree depth-first, yielding every span (including the root).
90
+ */
91
+ export declare function walk(span: SpanLike): Generator<SpanLike>;
92
+ //# sourceMappingURL=spans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spans.d.ts","sourceRoot":"","sources":["../../src/core/spans.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC;AAErD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CA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itor builds one ``AgentTurnSpan`` tree per
5
+ * ``guardBefore`` call. Children include per-contract evaluation
6
+ * spans, with grand-children for assumption / guarantee / violation /
7
+ * enforcement nodes. The session view renderer walks this tree to
8
+ * produce the ``contracts armed`` + ``trace`` + ``VERDICT`` zones.
9
+ *
10
+ * Subclasses match the Python ``span_type`` strings field-for-field
11
+ * so traces serialise identically across languages.
12
+ */
13
+ export class Span {
14
+ spanType;
15
+ startTime;
16
+ endTime;
17
+ status;
18
+ attributes;
19
+ children;
20
+ constructor(spanType, attributes = {}) {
21
+ this.spanType = spanType;
22
+ this.startTime = performance.now();
23
+ this.status = "ok";
24
+ this.attributes = attributes;
25
+ this.children = [];
26
+ }
27
+ durationMs() {
28
+ if (this.endTime === undefined)
29
+ return null;
30
+ return this.endTime - this.startTime;
31
+ }
32
+ finish(status) {
33
+ this.endTime = performance.now();
34
+ if (status)
35
+ this.status = status;
36
+ }
37
+ }
38
+ export class AgentTurnSpan extends Span {
39
+ agentId = "";
40
+ action = "";
41
+ totalContractsChecked = 0;
42
+ detViolations = 0;
43
+ stoViolations = 0;
44
+ blocked = false;
45
+ constructor(agentId, action) {
46
+ super("sponsio.agent_turn");
47
+ this.agentId = agentId;
48
+ this.action = action;
49
+ }
50
+ }
51
+ export class ContractCheckSpan extends Span {
52
+ contractName;
53
+ pipeline;
54
+ constructor(contractName, pipeline = "hard") {
55
+ super("sponsio.contract_check");
56
+ this.contractName = contractName;
57
+ this.pipeline = pipeline;
58
+ }
59
+ }
60
+ export class PreconditionSpan extends Span {
61
+ formulaDesc;
62
+ result;
63
+ constructor(formulaDesc, result) {
64
+ super("sponsio.precondition");
65
+ this.formulaDesc = formulaDesc;
66
+ this.result = result;
67
+ }
68
+ }
69
+ export class GuaranteeSpan extends Span {
70
+ formulaDesc;
71
+ result;
72
+ constructor(formulaDesc, result) {
73
+ super("sponsio.guarantee");
74
+ this.formulaDesc = formulaDesc;
75
+ this.result = result;
76
+ }
77
+ }
78
+ export class ViolationSpan extends Span {
79
+ kind;
80
+ severity;
81
+ evidence;
82
+ constructor(kind, severity = "HIGH", evidence = "") {
83
+ super("sponsio.violation");
84
+ this.kind = kind;
85
+ this.severity = severity;
86
+ this.evidence = evidence;
87
+ }
88
+ }
89
+ export class EnforcementSpan extends Span {
90
+ strategy;
91
+ resultAction;
92
+ constructor(strategy, resultAction = "") {
93
+ super("sponsio.enforcement");
94
+ this.strategy = strategy;
95
+ this.resultAction = resultAction;
96
+ }
97
+ }
98
+ /**
99
+ * SpanCollector — builds a span tree during one ``guardBefore`` call.
100
+ * Mirrors Python's ``models.spans.SpanCollector``: a stack of
101
+ * currently-open spans, push/pop to nest. The root is the
102
+ * ``AgentTurnSpan`` returned by ``rootSpan``.
103
+ */
104
+ export class SpanCollector {
105
+ root;
106
+ stack;
107
+ constructor(agentId, action) {
108
+ this.root = new AgentTurnSpan(agentId, action);
109
+ this.stack = [this.root];
110
+ }
111
+ rootSpan() {
112
+ return this.root;
113
+ }
114
+ push(span) {
115
+ const parent = this.stack[this.stack.length - 1];
116
+ parent.children.push(span);
117
+ this.stack.push(span);
118
+ }
119
+ pop(status) {
120
+ const span = this.stack.pop();
121
+ if (span)
122
+ span.finish(status);
123
+ }
124
+ /** Add a leaf span (no children) and finalize it immediately. */
125
+ add(span, status) {
126
+ const parent = this.stack[this.stack.length - 1];
127
+ parent.children.push(span);
128
+ span.finish(status);
129
+ }
130
+ /** Finalize the root after the guard call completes. */
131
+ finishRoot(blocked, totalContractsChecked, detViolations) {
132
+ this.root.totalContractsChecked = totalContractsChecked;
133
+ this.root.detViolations = detViolations;
134
+ this.root.blocked = blocked;
135
+ this.root.finish(blocked ? "violated" : "ok");
136
+ return this.root;
137
+ }
138
+ }
139
+ /**
140
+ * Walk a span tree depth-first, yielding every span (including the root).
141
+ */
142
+ export function* walk(span) {
143
+ yield span;
144
+ for (const child of span.children) {
145
+ yield* walk(child);
146
+ }
147
+ }
148
+ //# sourceMappingURL=spans.js.map
@@ -0,0 +1 @@
1
+ {"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C,qBAAqB,GAAG,qBAAqB,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,IAAc;IAClC,MAAM,IAAI,CAAC;IACX,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Stub for the sto (stochastic / LLM-judge) pipeline.
3
+ *
4
+ * The real evaluator catalog (``tone`` / ``relevance`` / ``llm_judge`` /
5
+ * ``hallucination_free`` …) and the OpenAI-compatible judge client are
6
+ * Sponsio Cloud features, not bundled with the OSS engine. The OSS
7
+ * ``Sponsio`` constructor logs-and-skips sto contracts at load time
8
+ * with a one-time warning — matching Python's
9
+ * ``sponsio.patterns.sto_catalog`` behaviour.
10
+ *
11
+ * This file exists so that:
12
+ * - imports in ``index.ts`` resolve cleanly
13
+ * - downstream consumers depending on the type names
14
+ * (``StoEvaluator``, ``JudgeClient``, …) compile against the
15
+ * same surface
16
+ * - any code path that *constructs* an evaluator or *builds* a
17
+ * judge fails loudly with ``CloudFeatureError`` rather than
18
+ * silently pretending to enforce
19
+ *
20
+ * Operators who want the sto pipeline:
21
+ *
22
+ * pip install sponsio[cloud]
23
+ *
24
+ * or contact your Sponsio account team for managed sto access. See
25
+ * ``docs/oss_scope.md`` for the OSS / Cloud boundary.
26
+ */
27
+ export interface StoInput {
28
+ toolName: string;
29
+ output: string;
30
+ /** Per-turn context (cloud-only atom grounding fields). */
31
+ context?: StoContextSnapshot;
32
+ }
33
+ export interface StoContextSnapshot {
34
+ query?: string;
35
+ source?: string;
36
+ scope?: string;
37
+ history?: string;
38
+ }
39
+ export interface StoResult {
40
+ score: number;
41
+ passed: boolean;
42
+ evidence?: string;
43
+ }
44
+ export interface StoEvaluator {
45
+ readonly atom: string;
46
+ readonly desc: string;
47
+ readonly threshold: number;
48
+ evaluate(input: StoInput): Promise<StoResult>;
49
+ }
50
+ export interface JudgeConfig {
51
+ provider?: "openai";
52
+ model?: string;
53
+ apiKey?: string;
54
+ baseUrl?: string;
55
+ fallbackMode?: "allow" | "deny" | "skip";
56
+ }
57
+ export interface JudgeClient {
58
+ complete(prompt: string): Promise<string>;
59
+ }
60
+ export interface StoContract {
61
+ desc: string;
62
+ evaluator: StoEvaluator;
63
+ }
64
+ export declare class CloudFeatureError extends Error {
65
+ constructor(featureName: string);
66
+ }
67
+ /**
68
+ * Stub. The OSS engine does not ship a managed judge client; calling
69
+ * this throws ``CloudFeatureError``. The OSS ``Sponsio`` constructor
70
+ * never reaches this — yaml ``judge:`` blocks and ``options.judge``
71
+ * are routed through the ``skipped`` warning path instead.
72
+ */
73
+ export declare function createJudge(_config: JudgeConfig): JudgeClient;
74
+ /**
75
+ * Parse a 0–1 score from a judge response. Pure utility; safe to ship
76
+ * because it never calls a judge. Kept so any user calling it
77
+ * directly (rare) keeps working.
78
+ */
79
+ export declare function parseScore(raw: string): number;
80
+ declare abstract class _StubEvaluator implements StoEvaluator {
81
+ readonly desc: string;
82
+ readonly threshold: number;
83
+ abstract readonly atom: string;
84
+ constructor(desc: string, threshold: number);
85
+ evaluate(_input: StoInput): Promise<StoResult>;
86
+ }
87
+ export declare class LlmJudgeEvaluator extends _StubEvaluator {
88
+ readonly atom = "llm_judge";
89
+ constructor(desc: string, threshold: number, _judge: JudgeClient, _promptTemplate: string);
90
+ }
91
+ export declare class ToneEvaluator extends _StubEvaluator {
92
+ readonly atom = "tone";
93
+ constructor(desc: string, threshold: number, _judge: JudgeClient, _targetTone: string);
94
+ }
95
+ export declare class RelevanceEvaluator extends _StubEvaluator {
96
+ readonly atom = "relevance";
97
+ constructor(desc: string, threshold: number, _judge: JudgeClient);
98
+ }
99
+ export declare class SemanticPiiFreeEvaluator extends _StubEvaluator {
100
+ readonly atom = "semantic_pii_free";
101
+ constructor(desc: string, threshold: number, _judge: JudgeClient);
102
+ }
103
+ export declare class HallucinationFreeEvaluator extends _StubEvaluator {
104
+ readonly atom = "hallucination_free";
105
+ constructor(desc: string, threshold: number, _judge: JudgeClient);
106
+ }
107
+ export declare class ScopeRespectEvaluator extends _StubEvaluator {
108
+ readonly atom = "scope_respect";
109
+ constructor(desc: string, threshold: number, _judge: JudgeClient, _defaultScope: string);
110
+ }
111
+ export declare class MetricIntegrityEvaluator extends _StubEvaluator {
112
+ readonly atom = "metric_integrity";
113
+ constructor(desc: string, threshold: number, _judge: JudgeClient);
114
+ }
115
+ export declare class InjectionFreeEvaluator extends _StubEvaluator {
116
+ readonly atom = "injection_free";
117
+ constructor(desc: string, threshold: number, _judge: JudgeClient);
118
+ }
119
+ export {};
120
+ //# sourceMappingURL=sto.d.ts.map