@aid-framework/runtime 0.0.0 → 0.1.48
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/LICENSE +201 -0
- package/README.md +183 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/agents/deep_agents.d.ts +78 -0
- package/dist/agents/deep_agents.d.ts.map +1 -0
- package/dist/agents/deep_agents.js +477 -0
- package/dist/agents/deep_agents.js.map +1 -0
- package/dist/agents/engine.d.ts +85 -0
- package/dist/agents/engine.d.ts.map +1 -0
- package/dist/agents/engine.js +129 -0
- package/dist/agents/engine.js.map +1 -0
- package/dist/agents/gateway_chat_model.d.ts +151 -0
- package/dist/agents/gateway_chat_model.d.ts.map +1 -0
- package/dist/agents/gateway_chat_model.js +350 -0
- package/dist/agents/gateway_chat_model.js.map +1 -0
- package/dist/agents/guardrail_middleware.d.ts +57 -0
- package/dist/agents/guardrail_middleware.d.ts.map +1 -0
- package/dist/agents/guardrail_middleware.js +85 -0
- package/dist/agents/guardrail_middleware.js.map +1 -0
- package/dist/agents/guardrails.d.ts +124 -0
- package/dist/agents/guardrails.d.ts.map +1 -0
- package/dist/agents/guardrails.js +336 -0
- package/dist/agents/guardrails.js.map +1 -0
- package/dist/agents/index.d.ts +15 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +15 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/ir.d.ts +144 -0
- package/dist/agents/ir.d.ts.map +1 -0
- package/dist/agents/ir.js +513 -0
- package/dist/agents/ir.js.map +1 -0
- package/dist/agents/loop.d.ts +145 -0
- package/dist/agents/loop.d.ts.map +1 -0
- package/dist/agents/loop.js +1025 -0
- package/dist/agents/loop.js.map +1 -0
- package/dist/agents/memory.d.ts +115 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/memory.js +258 -0
- package/dist/agents/memory.js.map +1 -0
- package/dist/agents/state.d.ts +137 -0
- package/dist/agents/state.d.ts.map +1 -0
- package/dist/agents/state.js +255 -0
- package/dist/agents/state.js.map +1 -0
- package/dist/concurrency.d.ts +36 -0
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/concurrency.js +86 -0
- package/dist/concurrency.js.map +1 -0
- package/dist/control.d.ts +116 -0
- package/dist/control.d.ts.map +1 -0
- package/dist/control.js +281 -0
- package/dist/control.js.map +1 -0
- package/dist/cost.d.ts +95 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +161 -0
- package/dist/cost.js.map +1 -0
- package/dist/errors.d.ts +213 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +316 -0
- package/dist/errors.js.map +1 -0
- package/dist/evals/dataset.d.ts +45 -0
- package/dist/evals/dataset.d.ts.map +1 -0
- package/dist/evals/dataset.js +147 -0
- package/dist/evals/dataset.js.map +1 -0
- package/dist/evals/gate.d.ts +236 -0
- package/dist/evals/gate.d.ts.map +1 -0
- package/dist/evals/gate.js +572 -0
- package/dist/evals/gate.js.map +1 -0
- package/dist/evals/metrics.d.ts +141 -0
- package/dist/evals/metrics.d.ts.map +1 -0
- package/dist/evals/metrics.js +364 -0
- package/dist/evals/metrics.js.map +1 -0
- package/dist/evals/predicate.d.ts +79 -0
- package/dist/evals/predicate.d.ts.map +1 -0
- package/dist/evals/predicate.js +178 -0
- package/dist/evals/predicate.js.map +1 -0
- package/dist/evals/runner.d.ts +94 -0
- package/dist/evals/runner.d.ts.map +1 -0
- package/dist/evals/runner.js +202 -0
- package/dist/evals/runner.js.map +1 -0
- package/dist/gateway.d.ts +118 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +250 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/json.d.ts +44 -0
- package/dist/internal/json.d.ts.map +1 -0
- package/dist/internal/json.js +90 -0
- package/dist/internal/json.js.map +1 -0
- package/dist/internal/text.d.ts +17 -0
- package/dist/internal/text.d.ts.map +1 -0
- package/dist/internal/text.js +22 -0
- package/dist/internal/text.js.map +1 -0
- package/dist/pipeline.d.ts +80 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +159 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/policy.d.ts +52 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +199 -0
- package/dist/policy.js.map +1 -0
- package/dist/prompts.d.ts +86 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +337 -0
- package/dist/prompts.js.map +1 -0
- package/dist/providers/base.d.ts +19 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +13 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/fake.d.ts +98 -0
- package/dist/providers/fake.d.ts.map +1 -0
- package/dist/providers/fake.js +181 -0
- package/dist/providers/fake.js.map +1 -0
- package/dist/providers/http.d.ts +62 -0
- package/dist/providers/http.d.ts.map +1 -0
- package/dist/providers/http.js +245 -0
- package/dist/providers/http.js.map +1 -0
- package/dist/retrieval/chunking.d.ts +88 -0
- package/dist/retrieval/chunking.d.ts.map +1 -0
- package/dist/retrieval/chunking.js +188 -0
- package/dist/retrieval/chunking.js.map +1 -0
- package/dist/retrieval/citations.d.ts +98 -0
- package/dist/retrieval/citations.d.ts.map +1 -0
- package/dist/retrieval/citations.js +134 -0
- package/dist/retrieval/citations.js.map +1 -0
- package/dist/retrieval/connectors.d.ts +74 -0
- package/dist/retrieval/connectors.d.ts.map +1 -0
- package/dist/retrieval/connectors.js +218 -0
- package/dist/retrieval/connectors.js.map +1 -0
- package/dist/retrieval/embedding.d.ts +116 -0
- package/dist/retrieval/embedding.d.ts.map +1 -0
- package/dist/retrieval/embedding.js +282 -0
- package/dist/retrieval/embedding.js.map +1 -0
- package/dist/retrieval/gate.d.ts +52 -0
- package/dist/retrieval/gate.d.ts.map +1 -0
- package/dist/retrieval/gate.js +91 -0
- package/dist/retrieval/gate.js.map +1 -0
- package/dist/retrieval/hybrid.d.ts +76 -0
- package/dist/retrieval/hybrid.d.ts.map +1 -0
- package/dist/retrieval/hybrid.js +150 -0
- package/dist/retrieval/hybrid.js.map +1 -0
- package/dist/retrieval/metrics.d.ts +126 -0
- package/dist/retrieval/metrics.d.ts.map +1 -0
- package/dist/retrieval/metrics.js +200 -0
- package/dist/retrieval/metrics.js.map +1 -0
- package/dist/retrieval/pgvector.d.ts +62 -0
- package/dist/retrieval/pgvector.d.ts.map +1 -0
- package/dist/retrieval/pgvector.js +262 -0
- package/dist/retrieval/pgvector.js.map +1 -0
- package/dist/retrieval/rerank.d.ts +61 -0
- package/dist/retrieval/rerank.d.ts.map +1 -0
- package/dist/retrieval/rerank.js +105 -0
- package/dist/retrieval/rerank.js.map +1 -0
- package/dist/retrieval/retriever.d.ts +125 -0
- package/dist/retrieval/retriever.d.ts.map +1 -0
- package/dist/retrieval/retriever.js +281 -0
- package/dist/retrieval/retriever.js.map +1 -0
- package/dist/retrieval/stores.d.ts +106 -0
- package/dist/retrieval/stores.d.ts.map +1 -0
- package/dist/retrieval/stores.js +142 -0
- package/dist/retrieval/stores.js.map +1 -0
- package/dist/retrieval/types.d.ts +314 -0
- package/dist/retrieval/types.d.ts.map +1 -0
- package/dist/retrieval/types.js +388 -0
- package/dist/retrieval/types.js.map +1 -0
- package/dist/steps.d.ts +156 -0
- package/dist/steps.d.ts.map +1 -0
- package/dist/steps.js +199 -0
- package/dist/steps.js.map +1 -0
- package/dist/structured.d.ts +91 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/structured.js +155 -0
- package/dist/structured.js.map +1 -0
- package/dist/tools.d.ts +100 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +201 -0
- package/dist/tools.js.map +1 -0
- package/dist/tracing.d.ts +104 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +155 -0
- package/dist/tracing.js.map +1 -0
- package/dist/types.d.ts +240 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +357 -0
- package/dist/types.js.map +1 -0
- package/package.json +80 -14
package/dist/gateway.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model gateway: alias resolution, capability negotiation, cost accounting.
|
|
3
|
+
*
|
|
4
|
+
* Three responsibilities, in this order:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Pinning.** An alias resolves to an exact provider model id. Unknown aliases are
|
|
7
|
+
* an error; there is no fall-through to a provider default, because a provider
|
|
8
|
+
* default is precisely the floating version a stored eval baseline cannot survive.
|
|
9
|
+
* 2. **Ordered fallback.** A caller may name fallback aliases. They are tried in the
|
|
10
|
+
* order given, and the aliases actually attempted are reported on the result.
|
|
11
|
+
* Escalation routing -- "use the strong model if the cheap one is unsure" -- is
|
|
12
|
+
* *not* implemented: "unsure" needs an agent loop to define.
|
|
13
|
+
* 3. **Budgets and tracing.** Every charged call opens a GenAI span and updates the
|
|
14
|
+
* ledger.
|
|
15
|
+
*/
|
|
16
|
+
import { CostLedger, estimatePromptCostUsd } from './cost.js';
|
|
17
|
+
import { BudgetExceededError, CapabilityMismatchError, ConfigurationError, FeatureDeferredError, ProviderError, UnknownModelAliasError, } from './errors.js';
|
|
18
|
+
import { ATTRIBUTES, recordCost, recordUsage, withLlmSpan, } from './tracing.js';
|
|
19
|
+
import { GenerationResult, PinnedModel, TokenUsage, } from './types.js';
|
|
20
|
+
/** Resolves aliases to pinned models and executes calls within a budget. */
|
|
21
|
+
export class ModelGateway {
|
|
22
|
+
_providers;
|
|
23
|
+
_aliases;
|
|
24
|
+
_ledger;
|
|
25
|
+
_budget;
|
|
26
|
+
_hooks;
|
|
27
|
+
_tracerName;
|
|
28
|
+
_limiter;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
const providers = new Map(Object.entries(options.providers));
|
|
31
|
+
const aliases = new Map(Object.entries(options.aliases));
|
|
32
|
+
if (providers.size === 0)
|
|
33
|
+
throw new ConfigurationError('the gateway needs at least one provider');
|
|
34
|
+
if (aliases.size === 0) {
|
|
35
|
+
throw new ConfigurationError('the gateway needs at least one pinned alias');
|
|
36
|
+
}
|
|
37
|
+
const resolved = new Map();
|
|
38
|
+
for (const [alias, value] of aliases) {
|
|
39
|
+
const spec = value instanceof PinnedModel ? value.model : value;
|
|
40
|
+
if (!providers.has(spec.provider)) {
|
|
41
|
+
const known = [...providers.keys()].sort();
|
|
42
|
+
throw new ConfigurationError(`alias ${JSON.stringify(alias)} names provider ${JSON.stringify(spec.provider)}, which is not among ${JSON.stringify(known)}`);
|
|
43
|
+
}
|
|
44
|
+
resolved.set(alias, spec);
|
|
45
|
+
}
|
|
46
|
+
this._providers = providers;
|
|
47
|
+
this._aliases = resolved;
|
|
48
|
+
this._ledger = options.ledger ?? new CostLedger();
|
|
49
|
+
this._budget = options.budget;
|
|
50
|
+
this._hooks = options.onCall ?? [];
|
|
51
|
+
this._tracerName = options.tracerName ?? 'aid_runtime';
|
|
52
|
+
this._limiter = options.limiter;
|
|
53
|
+
}
|
|
54
|
+
/** The pinned aliases, sorted. */
|
|
55
|
+
get aliases() {
|
|
56
|
+
return [...this._aliases.keys()].sort();
|
|
57
|
+
}
|
|
58
|
+
get ledger() {
|
|
59
|
+
return this._ledger;
|
|
60
|
+
}
|
|
61
|
+
get budget() {
|
|
62
|
+
return this._budget;
|
|
63
|
+
}
|
|
64
|
+
/** Resolve an alias to its pinned model, or fail loudly. */
|
|
65
|
+
resolve(alias) {
|
|
66
|
+
const spec = this._aliases.get(alias);
|
|
67
|
+
if (spec === undefined)
|
|
68
|
+
throw new UnknownModelAliasError(alias, this.aliases);
|
|
69
|
+
return new PinnedModel({ alias, model: spec });
|
|
70
|
+
}
|
|
71
|
+
/** The adapter that serves `alias`. Raises for an unknown alias. */
|
|
72
|
+
providerFor(alias) {
|
|
73
|
+
const provider = this._providers.get(this.resolve(alias).model.provider);
|
|
74
|
+
if (provider === undefined)
|
|
75
|
+
throw new UnknownModelAliasError(alias, this.aliases);
|
|
76
|
+
return provider;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Assert a pinned model *and* its adapter advertise every capability.
|
|
80
|
+
*
|
|
81
|
+
* Both sides are checked: a model that supports tool calling behind an adapter that
|
|
82
|
+
* does not serialise tool definitions cannot tool-call.
|
|
83
|
+
*/
|
|
84
|
+
require(alias, capabilities) {
|
|
85
|
+
const pinned = this.resolve(alias);
|
|
86
|
+
const required = new Set(capabilities);
|
|
87
|
+
const adapter = this._providers.get(pinned.model.provider);
|
|
88
|
+
const missing = new Set();
|
|
89
|
+
for (const capability of required) {
|
|
90
|
+
if (!pinned.model.capabilities.has(capability))
|
|
91
|
+
missing.add(capability);
|
|
92
|
+
if (adapter === undefined || !adapter.capabilities.has(capability))
|
|
93
|
+
missing.add(capability);
|
|
94
|
+
}
|
|
95
|
+
if (missing.size > 0)
|
|
96
|
+
throw new CapabilityMismatchError(alias, missing);
|
|
97
|
+
return pinned;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Run one call, falling back through `fallbacks` in order.
|
|
101
|
+
*
|
|
102
|
+
* A fallback is only tried for a failure another model could plausibly survive: a
|
|
103
|
+
* provider error or a missing capability. A {@link BudgetExceededError} propagates
|
|
104
|
+
* immediately -- retrying a different model cannot make an exhausted budget
|
|
105
|
+
* affordable.
|
|
106
|
+
*/
|
|
107
|
+
async generate(alias, request, options = {}) {
|
|
108
|
+
const chain = [alias, ...(options.fallbacks ?? [])];
|
|
109
|
+
const errors = [];
|
|
110
|
+
const budget = options.budget ?? this._budget;
|
|
111
|
+
for (const [index, candidate] of chain.entries()) {
|
|
112
|
+
const pinned = this.resolve(candidate);
|
|
113
|
+
try {
|
|
114
|
+
return await this.attempt(pinned, request, budget, chain.slice(0, index + 1));
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (!(error instanceof ProviderError) && !(error instanceof CapabilityMismatchError)) {
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
errors.push(`${candidate}: ${error.message}`);
|
|
121
|
+
if (index === chain.length - 1) {
|
|
122
|
+
throw new ProviderError(`every candidate failed (${chain.length} tried): ${errors.join('; ')}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
throw new ProviderError(`no candidate produced a response: ${errors.join('; ')}`);
|
|
127
|
+
}
|
|
128
|
+
/** Declared but not implemented; see the module docstring. */
|
|
129
|
+
async stream(_alias, _request) {
|
|
130
|
+
throw new FeatureDeferredError('streaming is a declared capability, not an implemented one; ' +
|
|
131
|
+
'Phase 0 serves request/response only');
|
|
132
|
+
}
|
|
133
|
+
async close() {
|
|
134
|
+
for (const provider of this._providers.values()) {
|
|
135
|
+
await provider.close();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* What this request's prompt would cost on top of what is already spent.
|
|
140
|
+
*
|
|
141
|
+
* Public because a routing decision needs the same number the preflight enforces: an
|
|
142
|
+
* agent stepping down a price ladder asks whether the *cheaper* alias fits before
|
|
143
|
+
* switching, and a second estimator would let the two disagree about the same ceiling.
|
|
144
|
+
*/
|
|
145
|
+
projectedCostUsd(alias, request) {
|
|
146
|
+
const pinned = this.resolve(alias);
|
|
147
|
+
let projected = this._ledger.costUsd;
|
|
148
|
+
for (const message of request.messages) {
|
|
149
|
+
projected += estimatePromptCostUsd(pinned.model, message.content);
|
|
150
|
+
}
|
|
151
|
+
return projected;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Whether this request still fits the budget. A question, never a charge.
|
|
155
|
+
*
|
|
156
|
+
* An unset ceiling always fits -- there is nothing to exceed. An *already* exceeded
|
|
157
|
+
* budget does not fit whatever the prompt, which is what makes a degraded agent stop
|
|
158
|
+
* rather than step down for every remaining step.
|
|
159
|
+
*/
|
|
160
|
+
fits(alias, request, budget) {
|
|
161
|
+
if (budget === undefined || budget.maxUsd === undefined)
|
|
162
|
+
return true;
|
|
163
|
+
if (this._ledger.costUsd > budget.maxUsd)
|
|
164
|
+
return false;
|
|
165
|
+
return this.projectedCostUsd(alias, request) <= budget.maxUsd;
|
|
166
|
+
}
|
|
167
|
+
async attempt(pinned, request, budget, attempted) {
|
|
168
|
+
if (budget !== undefined) {
|
|
169
|
+
this._ledger.check(budget);
|
|
170
|
+
this.preflight(pinned, request, budget);
|
|
171
|
+
}
|
|
172
|
+
const spec = pinned.model;
|
|
173
|
+
const provider = this._providers.get(spec.provider);
|
|
174
|
+
if (provider === undefined) {
|
|
175
|
+
throw new UnknownModelAliasError(pinned.alias, this.aliases);
|
|
176
|
+
}
|
|
177
|
+
const spanOptions = {
|
|
178
|
+
model: spec.name,
|
|
179
|
+
system: spec.provider,
|
|
180
|
+
alias: pinned.alias,
|
|
181
|
+
requestTemperature: request.temperature,
|
|
182
|
+
requestMaxTokens: request.maxOutputTokens,
|
|
183
|
+
tracerName: this._tracerName,
|
|
184
|
+
};
|
|
185
|
+
const { response, cost } = await this.limit(() => withLlmSpan(spanOptions, async (handle) => {
|
|
186
|
+
const answered = await provider.complete(request, spec);
|
|
187
|
+
const priced = spec.cost.costUsd(answered.usage);
|
|
188
|
+
recordUsage(handle.span, answered.usage.inputTokens, answered.usage.outputTokens);
|
|
189
|
+
recordCost(handle.span, priced);
|
|
190
|
+
handle.span.setAttribute(ATTRIBUTES.responseModel, answered.model);
|
|
191
|
+
handle.span.setAttribute(ATTRIBUTES.responseFinishReasons, [answered.finishReason]);
|
|
192
|
+
if (attempted.length > 1) {
|
|
193
|
+
handle.span.setAttribute(ATTRIBUTES.attempts, [...attempted]);
|
|
194
|
+
}
|
|
195
|
+
return { response: answered, cost: priced };
|
|
196
|
+
}));
|
|
197
|
+
const entry = {
|
|
198
|
+
alias: pinned.alias,
|
|
199
|
+
model: response.model,
|
|
200
|
+
provider: response.provider,
|
|
201
|
+
usage: response.usage,
|
|
202
|
+
costUsd: cost,
|
|
203
|
+
};
|
|
204
|
+
this._ledger.charge(budget, entry);
|
|
205
|
+
for (const hook of this._hooks)
|
|
206
|
+
hook(entry);
|
|
207
|
+
return new GenerationResult({
|
|
208
|
+
response,
|
|
209
|
+
alias: pinned.alias,
|
|
210
|
+
costUsd: cost,
|
|
211
|
+
attempts: [...attempted],
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Acquire the shared concurrency slot around one provider call.
|
|
216
|
+
*
|
|
217
|
+
* The slot wraps the call, not the surrounding bookkeeping, so a cache hit or a
|
|
218
|
+
* refused call never consumes one, and the slot is released on completion and on
|
|
219
|
+
* failure alike.
|
|
220
|
+
*/
|
|
221
|
+
async limit(body) {
|
|
222
|
+
if (this._limiter === undefined)
|
|
223
|
+
return body();
|
|
224
|
+
return this._limiter.run(body);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Refuse a call whose *prompt* alone already breaches the budget.
|
|
228
|
+
*
|
|
229
|
+
* Only the prompt is priced, and deliberately over-estimated, because the response
|
|
230
|
+
* is unknowable before the call. This catches gross overruns early; the post-call
|
|
231
|
+
* charge is what enforces the ceiling exactly.
|
|
232
|
+
*/
|
|
233
|
+
preflight(pinned, request, budget) {
|
|
234
|
+
if (budget.maxUsd === undefined)
|
|
235
|
+
return;
|
|
236
|
+
const projected = this.projectedCostUsd(pinned.alias, request);
|
|
237
|
+
if (projected > budget.maxUsd) {
|
|
238
|
+
throw new BudgetExceededError(budget.scope, budget.maxUsd, projected);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Token estimate for a set of strings, at the usual four characters per token. */
|
|
243
|
+
export function estimateUsage(texts) {
|
|
244
|
+
const list = typeof texts === 'string' ? [texts] : texts;
|
|
245
|
+
let input = 0;
|
|
246
|
+
for (const text of list)
|
|
247
|
+
input += (text.length + 3) >> 2;
|
|
248
|
+
return new TokenUsage({ inputTokens: input, outputTokens: 0 });
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACK,SAAS,CAAC,MAAmB,EAAE,OAA0B,EAAE,MAAc;QAC/E,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/D,IAAI,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,IAAI,mBAAmB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF;AAED,mFAAmF;AACnF,MAAM,UAAU,aAAa,CAAC,KAAiC;IAC7D,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,IAAI;QAAE,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACzD,OAAO,IAAI,UAAU,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AID runtime for TypeScript: the execution half of a generated application.
|
|
3
|
+
*
|
|
4
|
+
* The AID framework generates an application from an IR that declares *what* the app
|
|
5
|
+
* does. This package is what the generated code calls at runtime: pin a model, run a
|
|
6
|
+
* prompt, call a tool, trace it, stay inside a budget, and prove that quality did not
|
|
7
|
+
* regress.
|
|
8
|
+
*
|
|
9
|
+
* Design boundaries worth stating up front, because they are deliberate:
|
|
10
|
+
*
|
|
11
|
+
* - **Control flow is plain async TypeScript.** There is no graph or orchestration
|
|
12
|
+
* engine here. A generated app is ordinary code that is easy to read and to test.
|
|
13
|
+
* - **zod is used only for structured output.** No other responsibility is delegated
|
|
14
|
+
* to it.
|
|
15
|
+
* - **Streaming is declared, not implemented.** `Capability` includes it so a spec
|
|
16
|
+
* can require it and a gate can check it; calling `ModelGateway.stream` raises
|
|
17
|
+
* {@link FeatureDeferredError}.
|
|
18
|
+
* - **One HTTP provider adapter and one fake.** Breadth of vendor coverage is a
|
|
19
|
+
* Phase 2 concern; a narrow, correct seam is worth more now than a wide shallow one.
|
|
20
|
+
*
|
|
21
|
+
* This file mirrors the Python package's `__all__`. The exports it adds beyond that
|
|
22
|
+
* list are types a TypeScript consumer cannot avoid naming -- option bags, span
|
|
23
|
+
* handles, tool handler and parameter types -- because there is no structural way to
|
|
24
|
+
* pass them otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export * from './agents/index.js';
|
|
27
|
+
export { ConcurrencyLimiter, holdsSlot } from './concurrency.js';
|
|
28
|
+
export type { CompositeStep } from './control.js';
|
|
29
|
+
export { branch, DEPTH_KEY, INDEX_KEY, ITEM_KEY, LIMITER_KEY, MAX_STEP_DEPTH, mapStep, PRINCIPAL_KEY, parallel, REDUCED_KEY, RESERVED_KEYS, reduceStep, } from './control.js';
|
|
30
|
+
export { Budget, CostLedger, estimateCostUsd, estimatePromptCostUsd, LedgerEntry, SpendSummary, } from './cost.js';
|
|
31
|
+
export { AgentBudgetDegradedError, AgentHandoffUnsupportedError, AgentTransferCycleError, AidRuntimeError, BudgetExceededError, CapabilityMismatchError, ConfigurationError, DeepAgentsEngineError, DeepAgentsMaxStepsError, DeepAgentsUnavailableError, DeepAgentsVersionMismatchError, EvalError, FeatureDeferredError, GateConfigurationError, GuardrailBlockedError, PipelineError, PolicyEvaluationError, PromptNotFoundError, PromptRenderError, ProviderError, ProviderResponseError, StructuredOutputError, ToolArgumentError, ToolExecutionError, ToolNotFoundError, ToolPermissionError, UnknownModelAliasError, } from './errors.js';
|
|
32
|
+
export type { EvalCaseInit } from './evals/dataset.js';
|
|
33
|
+
export { Dataset, EvalCase } from './evals/dataset.js';
|
|
34
|
+
export type { BaselineGateOptions } from './evals/gate.js';
|
|
35
|
+
export { BaselineGate, EvalBaseline, EvalRun, GateResult, gateFromConfig, MetricBaseline, MetricGateResult, MetricRun, regressionZ, Threshold, zCritical, } from './evals/gate.js';
|
|
36
|
+
export type { JudgeCall, Metric } from './evals/metrics.js';
|
|
37
|
+
export { AssertMetric, defaultMetrics, ExactMatch, JsonSchemaValid, JudgeVerdict, LlmJudge, MetricResult, metricNames, NormalizedContains, normalize, } from './evals/metrics.js';
|
|
38
|
+
export type { GatewayRunnerOptions, Runner } from './evals/runner.js';
|
|
39
|
+
export { CaseOutcome, DatasetRun, evaluateOnce, GatewayRunner, gatewayJudge, runEvaluation, } from './evals/runner.js';
|
|
40
|
+
export type { AliasEntry, CallHook, ModelGatewayOptions } from './gateway.js';
|
|
41
|
+
export { estimateUsage, ModelGateway } from './gateway.js';
|
|
42
|
+
export type { NamedStep, Step, StepResult } from './pipeline.js';
|
|
43
|
+
export { Pipeline, PipelineContext, STEPS_KEY, StopPipeline } from './pipeline.js';
|
|
44
|
+
export type { PolicyNode } from './policy.js';
|
|
45
|
+
export { evaluatePolicy, POLICY_BUILTIN_ARITY, POLICY_BUILTINS, Principal, policySource, } from './policy.js';
|
|
46
|
+
export { Example, PromptRegistry, PromptTemplate, RenderedPrompt } from './prompts.js';
|
|
47
|
+
export type { Provider } from './providers/base.js';
|
|
48
|
+
export { supports } from './providers/base.js';
|
|
49
|
+
export type { FakeProviderOptions, Responder } from './providers/fake.js';
|
|
50
|
+
export { FakeProvider, ScriptedTurn } from './providers/fake.js';
|
|
51
|
+
export type { FetchLike, OpenAICompatibleOptions } from './providers/http.js';
|
|
52
|
+
export { DEFAULT_BASE_URL, OpenAICompatibleProvider } from './providers/http.js';
|
|
53
|
+
export type { Chunker, MarkerGroups } from './retrieval/chunking.js';
|
|
54
|
+
export { CodeChunker, chunkDocument, chunkerFor, FixedChunker, RecursiveChunker, } from './retrieval/chunking.js';
|
|
55
|
+
export { assembleContext, Citation, cite, RetrievalResult, RetrievedItem, } from './retrieval/citations.js';
|
|
56
|
+
export type { Connector } from './retrieval/connectors.js';
|
|
57
|
+
export { FileConnector, openConnector, SourceDocument } from './retrieval/connectors.js';
|
|
58
|
+
export type { Embedder } from './retrieval/embedding.js';
|
|
59
|
+
export { EmbeddingBatch, embedderFor, estimateTokens, FakeDeterministicEmbedder, OpenAICompatibleEmbedder, } from './retrieval/embedding.js';
|
|
60
|
+
export { RetrievalGate } from './retrieval/gate.js';
|
|
61
|
+
export { bm25Scores, fuse, lexicalRanking, RankedId, rrfScore, tokenize, } from './retrieval/hybrid.js';
|
|
62
|
+
export type { RetrievalMetric } from './retrieval/metrics.js';
|
|
63
|
+
export { CitationGrounding, MeanReciprocalRank, RecallAtK, RetrievalCase, retrievalMetrics, } from './retrieval/metrics.js';
|
|
64
|
+
export { PgVectorStore, parseVector, resolveUri, vectorLiteral } from './retrieval/pgvector.js';
|
|
65
|
+
export type { Reranker } from './retrieval/rerank.js';
|
|
66
|
+
export { LexicalReranker, lexicalScore, rerankerFor } from './retrieval/rerank.js';
|
|
67
|
+
export type { RetrieverOptions } from './retrieval/retriever.js';
|
|
68
|
+
export { DEFAULT_CANDIDATE_FACTOR, IngestReport, Retriever } from './retrieval/retriever.js';
|
|
69
|
+
export type { VectorStore } from './retrieval/stores.js';
|
|
70
|
+
export { createStore, InMemoryVectorStore, SearchHit, StoreRecord, similarity, } from './retrieval/stores.js';
|
|
71
|
+
export type { ChunkingStrategy, DistanceMetric, RefreshMode, SourceKind, StoreKind, } from './retrieval/types.js';
|
|
72
|
+
export { bindingFromSpec, Chunk, ChunkingSpec, chunkIdFor, DISTANCE_METRICS, EmbeddingCostProfile, EmbeddingSpec, IndexSpec, PinnedEmbedding, pinnedEmbedding, RefreshSpec, RerankSpec, RetrievalMetricSpec, RetrieverBinding, RetrieverSpec, ScoredChunk, SourceSpec, VectorStoreSpec, } from './retrieval/types.js';
|
|
73
|
+
export type { RetrieverSeam } from './steps.js';
|
|
74
|
+
export { EMITTED_KEY, emitStep, generateStep, resolveSource, retrieveStep, toolStep, } from './steps.js';
|
|
75
|
+
export type { AgentModel, StructuredOutput } from './structured.js';
|
|
76
|
+
export { buildAgent, formatProblems, parseStructured, repairPrompt, runStructured, StructuredAgent, structuredOutput, } from './structured.js';
|
|
77
|
+
export type { ToolHandler, ToolParameters } from './tools.js';
|
|
78
|
+
export { Tool, ToolExecutor, validateArguments } from './tools.js';
|
|
79
|
+
export type { LlmSpanHandle, LlmSpanOptions } from './tracing.js';
|
|
80
|
+
export { ATTRIBUTES, aidAttributes, GEN_AI_OPERATION_CHAT, getTracer, llmSpan, recordCost, recordException, recordUsage, } from './tracing.js';
|
|
81
|
+
export type { Capability, FinishReason, Role } from './types.js';
|
|
82
|
+
export { CompletionRequest, CompletionResponse, CostProfile, GenerationResult, Message, ModelSpec, PinnedModel, TokenUsage, ToolCall, ToolDefinition, ToolResult, } from './types.js';
|
|
83
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,QAAQ,EACR,WAAW,EACX,cAAc,EACd,OAAO,EACP,aAAa,EACb,QAAQ,EACR,WAAW,EACX,aAAa,EACb,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,MAAM,EACN,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,WAAW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AU,EACV,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EACL,UAAU,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACnE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,SAAS,EACT,OAAO,EACP,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,SAAS,EACT,WAAW,EACX,UAAU,EACV,QAAQ,EACR,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AID runtime for TypeScript: the execution half of a generated application.
|
|
3
|
+
*
|
|
4
|
+
* The AID framework generates an application from an IR that declares *what* the app
|
|
5
|
+
* does. This package is what the generated code calls at runtime: pin a model, run a
|
|
6
|
+
* prompt, call a tool, trace it, stay inside a budget, and prove that quality did not
|
|
7
|
+
* regress.
|
|
8
|
+
*
|
|
9
|
+
* Design boundaries worth stating up front, because they are deliberate:
|
|
10
|
+
*
|
|
11
|
+
* - **Control flow is plain async TypeScript.** There is no graph or orchestration
|
|
12
|
+
* engine here. A generated app is ordinary code that is easy to read and to test.
|
|
13
|
+
* - **zod is used only for structured output.** No other responsibility is delegated
|
|
14
|
+
* to it.
|
|
15
|
+
* - **Streaming is declared, not implemented.** `Capability` includes it so a spec
|
|
16
|
+
* can require it and a gate can check it; calling `ModelGateway.stream` raises
|
|
17
|
+
* {@link FeatureDeferredError}.
|
|
18
|
+
* - **One HTTP provider adapter and one fake.** Breadth of vendor coverage is a
|
|
19
|
+
* Phase 2 concern; a narrow, correct seam is worth more now than a wide shallow one.
|
|
20
|
+
*
|
|
21
|
+
* This file mirrors the Python package's `__all__`. The exports it adds beyond that
|
|
22
|
+
* list are types a TypeScript consumer cannot avoid naming -- option bags, span
|
|
23
|
+
* handles, tool handler and parameter types -- because there is no structural way to
|
|
24
|
+
* pass them otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export * from './agents/index.js';
|
|
27
|
+
export { ConcurrencyLimiter, holdsSlot } from './concurrency.js';
|
|
28
|
+
export { branch, DEPTH_KEY, INDEX_KEY, ITEM_KEY, LIMITER_KEY, MAX_STEP_DEPTH, mapStep, PRINCIPAL_KEY, parallel, REDUCED_KEY, RESERVED_KEYS, reduceStep, } from './control.js';
|
|
29
|
+
export { Budget, CostLedger, estimateCostUsd, estimatePromptCostUsd, LedgerEntry, SpendSummary, } from './cost.js';
|
|
30
|
+
export { AgentBudgetDegradedError, AgentHandoffUnsupportedError, AgentTransferCycleError, AidRuntimeError, BudgetExceededError, CapabilityMismatchError, ConfigurationError, DeepAgentsEngineError, DeepAgentsMaxStepsError, DeepAgentsUnavailableError, DeepAgentsVersionMismatchError, EvalError, FeatureDeferredError, GateConfigurationError, GuardrailBlockedError, PipelineError, PolicyEvaluationError, PromptNotFoundError, PromptRenderError, ProviderError, ProviderResponseError, StructuredOutputError, ToolArgumentError, ToolExecutionError, ToolNotFoundError, ToolPermissionError, UnknownModelAliasError, } from './errors.js';
|
|
31
|
+
export { Dataset, EvalCase } from './evals/dataset.js';
|
|
32
|
+
export { BaselineGate, EvalBaseline, EvalRun, GateResult, gateFromConfig, MetricBaseline, MetricGateResult, MetricRun, regressionZ, Threshold, zCritical, } from './evals/gate.js';
|
|
33
|
+
export { AssertMetric, defaultMetrics, ExactMatch, JsonSchemaValid, JudgeVerdict, LlmJudge, MetricResult, metricNames, NormalizedContains, normalize, } from './evals/metrics.js';
|
|
34
|
+
export { CaseOutcome, DatasetRun, evaluateOnce, GatewayRunner, gatewayJudge, runEvaluation, } from './evals/runner.js';
|
|
35
|
+
export { estimateUsage, ModelGateway } from './gateway.js';
|
|
36
|
+
export { Pipeline, PipelineContext, STEPS_KEY, StopPipeline } from './pipeline.js';
|
|
37
|
+
export { evaluatePolicy, POLICY_BUILTIN_ARITY, POLICY_BUILTINS, Principal, policySource, } from './policy.js';
|
|
38
|
+
export { Example, PromptRegistry, PromptTemplate, RenderedPrompt } from './prompts.js';
|
|
39
|
+
export { supports } from './providers/base.js';
|
|
40
|
+
export { FakeProvider, ScriptedTurn } from './providers/fake.js';
|
|
41
|
+
export { DEFAULT_BASE_URL, OpenAICompatibleProvider } from './providers/http.js';
|
|
42
|
+
export { CodeChunker, chunkDocument, chunkerFor, FixedChunker, RecursiveChunker, } from './retrieval/chunking.js';
|
|
43
|
+
export { assembleContext, Citation, cite, RetrievalResult, RetrievedItem, } from './retrieval/citations.js';
|
|
44
|
+
export { FileConnector, openConnector, SourceDocument } from './retrieval/connectors.js';
|
|
45
|
+
export { EmbeddingBatch, embedderFor, estimateTokens, FakeDeterministicEmbedder, OpenAICompatibleEmbedder, } from './retrieval/embedding.js';
|
|
46
|
+
export { RetrievalGate } from './retrieval/gate.js';
|
|
47
|
+
export { bm25Scores, fuse, lexicalRanking, RankedId, rrfScore, tokenize, } from './retrieval/hybrid.js';
|
|
48
|
+
export { CitationGrounding, MeanReciprocalRank, RecallAtK, RetrievalCase, retrievalMetrics, } from './retrieval/metrics.js';
|
|
49
|
+
export { PgVectorStore, parseVector, resolveUri, vectorLiteral } from './retrieval/pgvector.js';
|
|
50
|
+
export { LexicalReranker, lexicalScore, rerankerFor } from './retrieval/rerank.js';
|
|
51
|
+
export { DEFAULT_CANDIDATE_FACTOR, IngestReport, Retriever } from './retrieval/retriever.js';
|
|
52
|
+
export { createStore, InMemoryVectorStore, SearchHit, StoreRecord, similarity, } from './retrieval/stores.js';
|
|
53
|
+
export { bindingFromSpec, Chunk, ChunkingSpec, chunkIdFor, DISTANCE_METRICS, EmbeddingCostProfile, EmbeddingSpec, IndexSpec, PinnedEmbedding, pinnedEmbedding, RefreshSpec, RerankSpec, RetrievalMetricSpec, RetrieverBinding, RetrieverSpec, ScoredChunk, SourceSpec, VectorStoreSpec, } from './retrieval/types.js';
|
|
54
|
+
export { EMITTED_KEY, emitStep, generateStep, resolveSource, retrieveStep, toolStep, } from './steps.js';
|
|
55
|
+
export { buildAgent, formatProblems, parseStructured, repairPrompt, runStructured, StructuredAgent, structuredOutput, } from './structured.js';
|
|
56
|
+
export { Tool, ToolExecutor, validateArguments } from './tools.js';
|
|
57
|
+
export { ATTRIBUTES, aidAttributes, GEN_AI_OPERATION_CHAT, getTracer, llmSpan, recordCost, recordException, recordUsage, } from './tracing.js';
|
|
58
|
+
export { CompletionRequest, CompletionResponse, CostProfile, GenerationResult, Message, ModelSpec, PinnedModel, TokenUsage, ToolCall, ToolDefinition, ToolResult, } from './types.js';
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAA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,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE7F,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EACL,eAAe,EACf,KAAK,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,eAAe,EACf,eAAe,EACf,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,UAAU,EACV,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEnE,OAAO,EACL,UAAU,EACV,aAAa,EACb,qBAAqB,EACrB,SAAS,EACT,OAAO,EACP,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,SAAS,EACT,WAAW,EACX,UAAU,EACV,QAAQ,EACR,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON and hashing helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every hash in this runtime is taken over a canonical serialisation rather than
|
|
5
|
+
* over `JSON.stringify` of an object in insertion order, because an object built in
|
|
6
|
+
* a different order must still produce the same chunk id, the same fingerprint and
|
|
7
|
+
* the same fake-provider answer.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A Python-style `repr()` for a string.
|
|
11
|
+
*
|
|
12
|
+
* Error messages name the offending value, and quoting it the way the reference
|
|
13
|
+
* runtime does keeps the two runtimes' diagnostics greppable as one corpus.
|
|
14
|
+
*/
|
|
15
|
+
export declare function repr(value: string): string;
|
|
16
|
+
/** Round to a fixed number of decimal places. */
|
|
17
|
+
export declare function roundTo(value: number, digits: number): number;
|
|
18
|
+
/** Lowercase hex SHA-256 of a UTF-8 string. */
|
|
19
|
+
export declare function sha256Hex(text: string): string;
|
|
20
|
+
/** Lowercase hex SHA-256 of UTF-8 parts, each followed by a NUL separator. */
|
|
21
|
+
export declare function sha256Parts(parts: readonly string[]): string;
|
|
22
|
+
interface SortOptions {
|
|
23
|
+
/** Drop `null` members, mirroring `model_dump(exclude_none=True)`. */
|
|
24
|
+
readonly excludeNull?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* JSON with object keys sorted at every depth.
|
|
28
|
+
*
|
|
29
|
+
* Byte-for-byte stable across construction order, which is what makes it usable as
|
|
30
|
+
* hash input.
|
|
31
|
+
*/
|
|
32
|
+
export declare function canonicalJson(value: unknown, options?: SortOptions): string;
|
|
33
|
+
/**
|
|
34
|
+
* `json.dumps(value, sort_keys=True, default=str)`.
|
|
35
|
+
*
|
|
36
|
+
* Used where a tool hands back an arbitrary value: it must serialise rather than
|
|
37
|
+
* throw, because a tool result is data flowing back to a model, not a place to
|
|
38
|
+
* raise.
|
|
39
|
+
*/
|
|
40
|
+
export declare function dumpsSorted(value: unknown): string;
|
|
41
|
+
/** The first `count` hex characters of a SHA-256 digest. */
|
|
42
|
+
export declare function digestPrefix(text: string, count?: number): string;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/internal/json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK1C;AAED,iDAAiD;AACjD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,+CAA+C;AAC/C,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAO5D;AAED,UAAU,WAAW;IACnB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAuBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAE/E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMlD;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAE5D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON and hashing helpers.
|
|
3
|
+
*
|
|
4
|
+
* Every hash in this runtime is taken over a canonical serialisation rather than
|
|
5
|
+
* over `JSON.stringify` of an object in insertion order, because an object built in
|
|
6
|
+
* a different order must still produce the same chunk id, the same fingerprint and
|
|
7
|
+
* the same fake-provider answer.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
|
+
/**
|
|
11
|
+
* A Python-style `repr()` for a string.
|
|
12
|
+
*
|
|
13
|
+
* Error messages name the offending value, and quoting it the way the reference
|
|
14
|
+
* runtime does keeps the two runtimes' diagnostics greppable as one corpus.
|
|
15
|
+
*/
|
|
16
|
+
export function repr(value) {
|
|
17
|
+
if (value.includes("'") && !value.includes('"')) {
|
|
18
|
+
return `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"`;
|
|
19
|
+
}
|
|
20
|
+
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
21
|
+
}
|
|
22
|
+
/** Round to a fixed number of decimal places. */
|
|
23
|
+
export function roundTo(value, digits) {
|
|
24
|
+
const factor = 10 ** digits;
|
|
25
|
+
return Math.round(value * factor) / factor;
|
|
26
|
+
}
|
|
27
|
+
/** Lowercase hex SHA-256 of a UTF-8 string. */
|
|
28
|
+
export function sha256Hex(text) {
|
|
29
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
30
|
+
}
|
|
31
|
+
/** Lowercase hex SHA-256 of UTF-8 parts, each followed by a NUL separator. */
|
|
32
|
+
export function sha256Parts(parts) {
|
|
33
|
+
const hash = createHash('sha256');
|
|
34
|
+
for (const part of parts) {
|
|
35
|
+
hash.update(part, 'utf8');
|
|
36
|
+
hash.update(Buffer.from([0]));
|
|
37
|
+
}
|
|
38
|
+
return hash.digest('hex');
|
|
39
|
+
}
|
|
40
|
+
function sortValue(value, options) {
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
return value.map((entry) => sortValue(entry, options));
|
|
43
|
+
}
|
|
44
|
+
if (value instanceof Set) {
|
|
45
|
+
return [...value].map((entry) => sortValue(entry, options));
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'object' && value !== null) {
|
|
48
|
+
const source = value;
|
|
49
|
+
const sorted = {};
|
|
50
|
+
for (const key of Object.keys(source).sort()) {
|
|
51
|
+
const entry = source[key];
|
|
52
|
+
if (entry === undefined)
|
|
53
|
+
continue;
|
|
54
|
+
if (options.excludeNull === true && entry === null)
|
|
55
|
+
continue;
|
|
56
|
+
sorted[key] = sortValue(entry, options);
|
|
57
|
+
}
|
|
58
|
+
return sorted;
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* JSON with object keys sorted at every depth.
|
|
64
|
+
*
|
|
65
|
+
* Byte-for-byte stable across construction order, which is what makes it usable as
|
|
66
|
+
* hash input.
|
|
67
|
+
*/
|
|
68
|
+
export function canonicalJson(value, options = {}) {
|
|
69
|
+
return JSON.stringify(sortValue(value, options));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `json.dumps(value, sort_keys=True, default=str)`.
|
|
73
|
+
*
|
|
74
|
+
* Used where a tool hands back an arbitrary value: it must serialise rather than
|
|
75
|
+
* throw, because a tool result is data flowing back to a model, not a place to
|
|
76
|
+
* raise.
|
|
77
|
+
*/
|
|
78
|
+
export function dumpsSorted(value) {
|
|
79
|
+
try {
|
|
80
|
+
return canonicalJson(value);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return String(value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** The first `count` hex characters of a SHA-256 digest. */
|
|
87
|
+
export function digestPrefix(text, count = 8) {
|
|
88
|
+
return sha256Hex(text).slice(0, count);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/internal/json.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC;IACtE,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CA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
|
|
4
|
+
* Every function here takes arbitrary-length input, and a regex with a quantifier
|
|
5
|
+
* costs steps proportional to the run it consumes: `/\/+$/` on a string of a hundred
|
|
6
|
+
* thousand slashes is a polynomial number of steps for a one-line trim. Scans are
|
|
7
|
+
* linear whatever arrives, so these call sites cannot be turned into a denial of
|
|
8
|
+
* service by the value they are handed.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Drop every trailing `/`.
|
|
12
|
+
*
|
|
13
|
+
* Mirrors `/\/+$/` exactly, including the degenerate `'https://'` -> `'https:'`:
|
|
14
|
+
* stripping is unconditional, so a URL that is nothing but a scheme loses its `//`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function stripTrailingSlashes(value: string): string;
|
|
17
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/internal/text.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI1D"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small string helpers that are deliberately not written with regular expressions.
|
|
3
|
+
*
|
|
4
|
+
* Every function here takes arbitrary-length input, and a regex with a quantifier
|
|
5
|
+
* costs steps proportional to the run it consumes: `/\/+$/` on a string of a hundred
|
|
6
|
+
* thousand slashes is a polynomial number of steps for a one-line trim. Scans are
|
|
7
|
+
* linear whatever arrives, so these call sites cannot be turned into a denial of
|
|
8
|
+
* service by the value they are handed.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Drop every trailing `/`.
|
|
12
|
+
*
|
|
13
|
+
* Mirrors `/\/+$/` exactly, including the degenerate `'https://'` -> `'https:'`:
|
|
14
|
+
* stripping is unconditional, so a URL that is nothing but a scheme loses its `//`.
|
|
15
|
+
*/
|
|
16
|
+
export function stripTrailingSlashes(value) {
|
|
17
|
+
let end = value.length;
|
|
18
|
+
while (end > 0 && value[end - 1] === '/')
|
|
19
|
+
end -= 1;
|
|
20
|
+
return value.slice(0, end);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/internal/text.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG;QAAE,GAAG,IAAI,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|