@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 @@
1
+ {"version":3,"file":"sto.d.ts","sourceRoot":"","sources":["../../src/core/sto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,CAAC,EAAE,kBAAkB,CAA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AyB,SAAQ,cAAc;IAC1D,QAAQ,CAAC,IAAI,sBAAsB;gBACvB,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;CAGjE;AAED,qBAAa,sBAAuB,SAAQ,cAAc;IACxD,QAAQ,CAAC,IAAI,oBAAoB;gBACrB,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;CAGjE"}
@@ -0,0 +1,147 @@
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
+ // ----- CloudFeatureError ---------------------------------------------
28
+ const CLOUD_HINT = "Sponsio's sto (LLM-judge) pipeline is a Cloud feature, not bundled " +
29
+ "with the OSS engine. Install `sponsio[cloud]` (Python) or contact " +
30
+ "your Sponsio account team for managed sto access. See " +
31
+ "https://github.com/SponsioLabs/Sponsio/blob/main/docs/oss_scope.md.";
32
+ export class CloudFeatureError extends Error {
33
+ constructor(featureName) {
34
+ super(`[sponsio] ${featureName} is not available in OSS. ${CLOUD_HINT}`);
35
+ this.name = "CloudFeatureError";
36
+ }
37
+ }
38
+ // ----- createJudge: stub ---------------------------------------------
39
+ /**
40
+ * Stub. The OSS engine does not ship a managed judge client; calling
41
+ * this throws ``CloudFeatureError``. The OSS ``Sponsio`` constructor
42
+ * never reaches this — yaml ``judge:`` blocks and ``options.judge``
43
+ * are routed through the ``skipped`` warning path instead.
44
+ */
45
+ export function createJudge(_config) {
46
+ throw new CloudFeatureError("createJudge()");
47
+ }
48
+ // ----- parseScore: pure utility, kept --------------------------------
49
+ /**
50
+ * Parse a 0–1 score from a judge response. Pure utility; safe to ship
51
+ * because it never calls a judge. Kept so any user calling it
52
+ * directly (rare) keeps working.
53
+ */
54
+ export function parseScore(raw) {
55
+ const trimmed = raw.trim();
56
+ if (trimmed.startsWith("{")) {
57
+ try {
58
+ const obj = JSON.parse(trimmed);
59
+ if (typeof obj.score === "number")
60
+ return clamp01(obj.score);
61
+ }
62
+ catch {
63
+ /* fall through */
64
+ }
65
+ }
66
+ const m = trimmed.match(/([01](?:\.\d+)?|0?\.\d+)/);
67
+ if (!m) {
68
+ throw new Error(`unparseable score: ${JSON.stringify(trimmed.slice(0, 80))}`);
69
+ }
70
+ const n = parseFloat(m[1]);
71
+ if (!Number.isFinite(n))
72
+ throw new Error(`non-finite score: ${m[1]}`);
73
+ return clamp01(n);
74
+ }
75
+ function clamp01(n) {
76
+ if (n < 0)
77
+ return 0;
78
+ if (n > 1)
79
+ return 1;
80
+ return n;
81
+ }
82
+ // ----- Evaluator class stubs -----------------------------------------
83
+ // Each class preserves the 3 public ``StoEvaluator`` fields that
84
+ // callers may inspect (``atom`` / ``desc`` / ``threshold``), but
85
+ // ``evaluate()`` rejects with ``CloudFeatureError``. The OSS Sponsio
86
+ // ctor never instantiates these — yaml sto specs flow through the
87
+ // ``skipped`` path before any evaluator is built.
88
+ class _StubEvaluator {
89
+ desc;
90
+ threshold;
91
+ constructor(desc, threshold) {
92
+ this.desc = desc;
93
+ this.threshold = threshold;
94
+ }
95
+ evaluate(_input) {
96
+ return Promise.reject(new CloudFeatureError(`${this.atom} evaluator`));
97
+ }
98
+ }
99
+ export class LlmJudgeEvaluator extends _StubEvaluator {
100
+ atom = "llm_judge";
101
+ constructor(desc, threshold, _judge, _promptTemplate) {
102
+ super(desc, threshold);
103
+ }
104
+ }
105
+ export class ToneEvaluator extends _StubEvaluator {
106
+ atom = "tone";
107
+ constructor(desc, threshold, _judge, _targetTone) {
108
+ super(desc, threshold);
109
+ }
110
+ }
111
+ export class RelevanceEvaluator extends _StubEvaluator {
112
+ atom = "relevance";
113
+ constructor(desc, threshold, _judge) {
114
+ super(desc, threshold);
115
+ }
116
+ }
117
+ export class SemanticPiiFreeEvaluator extends _StubEvaluator {
118
+ atom = "semantic_pii_free";
119
+ constructor(desc, threshold, _judge) {
120
+ super(desc, threshold);
121
+ }
122
+ }
123
+ export class HallucinationFreeEvaluator extends _StubEvaluator {
124
+ atom = "hallucination_free";
125
+ constructor(desc, threshold, _judge) {
126
+ super(desc, threshold);
127
+ }
128
+ }
129
+ export class ScopeRespectEvaluator extends _StubEvaluator {
130
+ atom = "scope_respect";
131
+ constructor(desc, threshold, _judge, _defaultScope) {
132
+ super(desc, threshold);
133
+ }
134
+ }
135
+ export class MetricIntegrityEvaluator extends _StubEvaluator {
136
+ atom = "metric_integrity";
137
+ constructor(desc, threshold, _judge) {
138
+ super(desc, threshold);
139
+ }
140
+ }
141
+ export class InjectionFreeEvaluator extends _StubEvaluator {
142
+ atom = "injection_free";
143
+ constructor(desc, threshold, _judge) {
144
+ super(desc, threshold);
145
+ }
146
+ }
147
+ //# sourceMappingURL=sto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sto.js","sourceRoot":"","sources":["../../src/core/sto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAgDH,wEAAwE;AAExE,MAAM,UAAU,GACd,qEAAqE;IACrE,oEAAoE;IACpE,wDAAwD;IACxD,qE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,IAAY,EAAE,SAAiB,EAAE,MAAmB;QAC9D,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,cAAc;IACnD,IAAI,GAAG,oBAAoB,CAAC;IACrC,YAAY,IAAY,EAAE,SAAiB,EAAE,MAAmB;QAC9D,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,cAAc;IAC9C,IAAI,GAAG,eAAe,CAAC;IAChC,YACE,IAAY,EACZ,SAAiB,EACjB,MAAmB,EACnB,aAAqB;QAErB,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,cAAc;IACjD,IAAI,GAAG,kBAAkB,CAAC;IACnC,YAAY,IAAY,EAAE,SAAiB,EAAE,MAAmB;QAC9D,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzB,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,cAAc;IAC/C,IAAI,GAAG,gBAAgB,CAAC;IACjC,YAAY,IAAY,EAAE,SAAiB,EAAE,MAAmB;QAC9D,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,267 @@
1
+ /**
2
+ * @sponsio/sdk — Runtime contract enforcement for LLM agents.
3
+ *
4
+ * Native TypeScript implementation. < 50KB bundle, zero cold start,
5
+ * Edge/Serverless compatible.
6
+ *
7
+ * Usage:
8
+ * import { Sponsio } from "@sponsio/sdk"
9
+ *
10
+ * // Inline contracts:
11
+ * const guard = new Sponsio({
12
+ * agentId: "refund_bot",
13
+ * contracts: ["tool `check_policy` must precede `issue_refund`"]
14
+ * })
15
+ *
16
+ * // Or loaded from a shared sponsio.yaml:
17
+ * const guard = new Sponsio({ config: "sponsio.yaml", agentId: "refund_bot" })
18
+ *
19
+ * const result = guard.guardBefore("issue_refund", { orderId: "#123" })
20
+ * if (result.blocked) { ... }
21
+ */
22
+ import { AgentTurnSpan } from "./core/spans.js";
23
+ import type { DetFormula } from "./core/patterns.js";
24
+ import { type JudgeClient, type JudgeConfig, type StoContextSnapshot } from "./core/sto.js";
25
+ export { evaluate } from "./core/evaluator.js";
26
+ export type { Valuation } from "./core/evaluator.js";
27
+ export * from "./core/formula.js";
28
+ export * from "./core/patterns.js";
29
+ export { parseNl } from "./core/nl-parser.js";
30
+ export { parseRepr, ParseError } from "./core/parser.js";
31
+ export { groundEvent, newGroundingState, collectContentAtoms, } from "./core/grounding.js";
32
+ export { loadSponsoConfig } from "./core/config-loader.js";
33
+ export type { LoadedConfig, SkippedItem } from "./core/config-loader.js";
34
+ export { SessionLogger, rotateSessions } from "./core/session-log.js";
35
+ export type { SessionRecord, SessionLoggerOptions, } from "./core/session-log.js";
36
+ export { contract, ContractBuilder } from "./contract.js";
37
+ export { createJudge, LlmJudgeEvaluator, ToneEvaluator, RelevanceEvaluator, SemanticPiiFreeEvaluator, HallucinationFreeEvaluator, ScopeRespectEvaluator, MetricIntegrityEvaluator, InjectionFreeEvaluator, parseScore, } from "./core/sto.js";
38
+ export type { StoEvaluator, StoContract, StoInput, StoResult, StoContextSnapshot, JudgeClient, JudgeConfig, } from "./core/sto.js";
39
+ /**
40
+ * One det violation, with enough structure to feed into downstream
41
+ * agent feedback — mirrors Python's ``EnforcementResult`` fields that
42
+ * examples reach for (``check.det_violations[0].message``).
43
+ *
44
+ * Phrasing contract (mirrors Python ``OutcomeBuilder``):
45
+ *
46
+ * - ``message`` is the **human-facing** log line —
47
+ * ``"BLOCKED: agent.tool — det constraint violated: …"``. It keeps
48
+ * the legacy prefix so log-parsing back-compat holds. Don't inject
49
+ * it into the LLM's next prompt; it's noise to the model.
50
+ * - ``agentMsg`` is the **agent-facing** line, phrased to nudge the
51
+ * model into the right reaction. For block this should read
52
+ * "abandon this action" rather than parroting the log line.
53
+ * Empty until the strategy populates it; integrations fall back to
54
+ * ``message`` when empty.
55
+ * - ``ruleId`` is a stable identifier (``DetFormula.patternName`` or
56
+ * sto atom name) integrations can group on without parsing
57
+ * free text.
58
+ * - ``retryHint`` is populated only on retry-style outcomes — the
59
+ * "to fix this, do X" guidance, kept distinct from ``agentMsg``
60
+ * so adapters can format the two parts in framework-native ways.
61
+ * - ``alternatives`` is an optional list of suggested replacement
62
+ * actions for blocked / redirected outcomes.
63
+ */
64
+ export interface DetViolation {
65
+ /** Human-readable contract description (``DetFormula.desc``). */
66
+ desc: string;
67
+ /** Formatted ``"[WOULD-]BLOCKED: agent.tool — det constraint …"``. */
68
+ message: string;
69
+ /** Stable rule identifier (pattern name / contract id). */
70
+ ruleId?: string;
71
+ /** Agent-facing line, tuned per action voice. Falls back to ``message``. */
72
+ agentMsg?: string;
73
+ /** "To fix this, do X" guidance. Only set on retry-style outcomes. */
74
+ retryHint?: string;
75
+ /** Suggested replacement actions for the agent. */
76
+ alternatives?: string[];
77
+ }
78
+ /**
79
+ * Best-effort accessor for the agent-facing line. Prefers the
80
+ * structured ``agentMsg`` field when populated; falls back to
81
+ * ``message`` for adapters that haven't migrated yet. Mirrors the
82
+ * Python ``select_agent_message`` helper.
83
+ */
84
+ export declare function selectAgentMessage(violations: DetViolation[], fallback?: string): string;
85
+ export interface CheckResult {
86
+ blocked: boolean;
87
+ allowed: boolean;
88
+ message: string;
89
+ /**
90
+ * Flat list of violation messages — kept for back-compat with
91
+ * existing TS call sites that only need a string feed.
92
+ */
93
+ violations: string[];
94
+ /**
95
+ * Structured det violations — parallel to Python's
96
+ * ``CheckResult.det_violations``. Populated in both enforce-block
97
+ * and observe-log paths; empty on a clean allow.
98
+ */
99
+ detViolations: DetViolation[];
100
+ /**
101
+ * Sto-pipeline violations — populated by ``guardAfter`` when
102
+ * stochastic contracts (e.g. ``tone``, ``llm_judge``) are declared
103
+ * in the yaml and a ``judge:`` block is configured. Empty on a
104
+ * clean pass or when no sto contracts exist.
105
+ */
106
+ stoViolations: DetViolation[];
107
+ }
108
+ export type SponsoMode = "enforce" | "observe";
109
+ export interface SponsoOptions {
110
+ /** Logical agent id — used for session log paths. */
111
+ agentId?: string;
112
+ /** Inline NL-string / DetFormula contracts. Merged with `config:` if both given. */
113
+ contracts?: (string | DetFormula)[];
114
+ /**
115
+ * Path to a ``sponsio.yaml`` config file. Loaded synchronously at
116
+ * construction time; contracts and runtime settings from the yaml
117
+ * merge with inline options.
118
+ *
119
+ * When set, the TS SDK reads:
120
+ * - ``runtime.mode`` (observe | enforce)
121
+ * - ``agents.<agentId>.contracts[]`` (NL strings; structured
122
+ * patterns and packs are skipped with a warning)
123
+ *
124
+ * Uses the ``yaml`` package (declared as a dependency of
125
+ * ``@sponsio/sdk``).
126
+ */
127
+ config?: string;
128
+ /**
129
+ * Runtime mode. Precedence (matches the Python SDK):
130
+ *
131
+ * SPONSIO_MODE env > ctor arg > yaml runtime.mode > "observe"
132
+ *
133
+ * ``observe`` (the default) logs every would-have-blocked decision
134
+ * to ``~/.sponsio/sessions/<agent_id>/*.jsonl`` without actually
135
+ * blocking. ``enforce`` returns ``blocked: true`` on violation.
136
+ */
137
+ mode?: SponsoMode;
138
+ /**
139
+ * Write session JSONL log to ``~/.sponsio/sessions/<agent_id>/…``.
140
+ * Defaults to ``true`` in observe mode, ``true`` in enforce mode
141
+ * (matches Python — the log is the audit trail, not an observe
142
+ * mode artefact). Pass ``false`` to disable (tests, edge runtimes
143
+ * without a writable home dir).
144
+ */
145
+ sessionLog?: boolean;
146
+ /** Override session log base dir (tests / alternative layouts). */
147
+ sessionLogBaseDir?: string;
148
+ /**
149
+ * Judge config for the sto pipeline. Either a plain config object
150
+ * (provider / model / apiKey / baseUrl / fallbackMode) or a
151
+ * pre-built ``JudgeClient``. Falls through to the yaml ``judge:``
152
+ * block if the ctor arg is omitted. When no sto contracts exist,
153
+ * the judge is never contacted.
154
+ */
155
+ judge?: JudgeConfig | JudgeClient;
156
+ }
157
+ export declare class Sponsio {
158
+ readonly agentId: string;
159
+ readonly mode: SponsoMode;
160
+ private _contracts;
161
+ private _stoContracts;
162
+ private _judge;
163
+ private _judgeFallback;
164
+ private _stoContext;
165
+ private _trace;
166
+ private _state;
167
+ private _contentAtoms;
168
+ private _violations;
169
+ private _logger;
170
+ private _turnSpans;
171
+ constructor(options?: SponsoOptions);
172
+ /**
173
+ * Check a tool call against contracts before execution.
174
+ *
175
+ * On block, **all** mutations made by ``groundEvent`` are rolled back via a
176
+ * pre-call snapshot. Previously only ``callCounts[toolName]`` was undone,
177
+ * leaving ``consecutiveCounts``, ``lastTool``, ``callWithCounts``,
178
+ * ``tokenCounts``, and ``delegationDepth`` in a stale state; subsequent
179
+ * guards saw counts as if the blocked call had executed.
180
+ *
181
+ * In **observe mode**, violations are logged to the session JSONL
182
+ * but not reported as blocks — the method always returns ``allowed: true``.
183
+ * In **enforce mode**, the first violation blocks the call.
184
+ */
185
+ /** Read the human-readable descs of all compiled contracts (det only). */
186
+ contractDescs(): string[];
187
+ guardBefore(toolName: string, args?: Record<string, unknown>): CheckResult;
188
+ /**
189
+ * Snapshot of the per-turn span trees this guard has produced since
190
+ * construction (or the last ``resetSession``). One root
191
+ * ``AgentTurnSpan`` per ``guardBefore`` call, with nested
192
+ * ``ContractCheckSpan`` / ``GuaranteeSpan`` / ``EnforcementSpan``
193
+ * children. Mirrors Python's ``RuntimeMonitor.turn_spans``.
194
+ */
195
+ turnSpans(): AgentTurnSpan[];
196
+ /** Drop accumulated turn spans (used between sessions in tests). */
197
+ resetSession(): void;
198
+ /**
199
+ * Render the end-of-session view to ``out`` (defaults to stderr) —
200
+ * banner, contracts armed, trace tree, verdict, perf, CTA. Mirrors
201
+ * Python's ``RuntimeMonitor.finish_session`` + ``render_session``
202
+ * pipeline. Call this once at the end of the agent's run.
203
+ */
204
+ finishSession(opts?: {
205
+ out?: NodeJS.WritableStream;
206
+ sessionId?: string;
207
+ tenant?: string;
208
+ env?: string;
209
+ sdk?: string;
210
+ ctas?: string[];
211
+ useColor?: boolean;
212
+ }): void;
213
+ /** Deep-copy the grounding state so it can be restored on a blocked call. */
214
+ private _snapshotState;
215
+ private _logViolations;
216
+ private _logAllow;
217
+ /**
218
+ * Record tool output after execution and run the sto pipeline.
219
+ *
220
+ * Returns a ``CheckResult`` whose ``stoViolations`` carries any
221
+ * stochastic rule failures (``tone`` / ``llm_judge``). When no sto
222
+ * contracts are declared the method returns synchronously in
223
+ * effect (the ``Promise`` resolves on the microtask queue) and
224
+ * never contacts the judge LLM.
225
+ *
226
+ * In **observe mode** violations are logged but the method still
227
+ * reports ``allowed: true``. In **enforce mode** the first sto
228
+ * violation flips ``blocked: true`` — but the tool output has
229
+ * already executed, so the caller is responsible for routing the
230
+ * result (retry with feedback, redirect to safe, etc.).
231
+ */
232
+ guardAfter(toolName: string, output?: string): Promise<CheckResult>;
233
+ private _logSto;
234
+ /**
235
+ * Reset guard state for a new session.
236
+ */
237
+ reset(): void;
238
+ /**
239
+ * Stash per-turn context for the sto pipeline. Atoms that need
240
+ * grounding — ``relevance`` (``query``), ``hallucination_free``
241
+ * (``source``), ``scope_respect`` (``scope`` override),
242
+ * ``metric_integrity`` (``history``) — read from this snapshot on
243
+ * the next ``guardAfter`` call.
244
+ *
245
+ * Merges with any previously-set context; pass ``{ query: undefined }``
246
+ * to explicitly clear a field. ``reset()`` clears the whole snapshot.
247
+ */
248
+ setContext(ctx: Partial<StoContextSnapshot>): void;
249
+ /**
250
+ * Get all violations from this session.
251
+ */
252
+ get violations(): string[];
253
+ /**
254
+ * Get a summary string. Returns a formatted list of violations
255
+ * observed in this session, or ``"No violations"`` if clean.
256
+ */
257
+ summary(): string;
258
+ /**
259
+ * Print the session summary to stdout — Python parity for
260
+ * ``guard.print_summary()``. Equivalent to
261
+ * ``console.log(guard.summary())``; exists so copy-pasted Python
262
+ * snippets compile (and so ad-hoc review in scripts reads the
263
+ * same way across both SDKs).
264
+ */
265
+ printSummary(): void;
266
+ }
267
+ //# sourceMappingURL=index.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