omk-agent-core 0.98.2 → 0.98.4
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/CHANGELOG.md +658 -0
- package/dist/agent-loop.d.ts +1 -31
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +15 -70
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent.d.ts +7 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +13 -34
- package/dist/agent.js.map +1 -1
- package/dist/effects/effect-journal.d.ts +43 -0
- package/dist/effects/effect-journal.d.ts.map +1 -0
- package/dist/effects/effect-journal.js +186 -0
- package/dist/effects/effect-journal.js.map +1 -0
- package/dist/effects/effect-recovery.d.ts +70 -0
- package/dist/effects/effect-recovery.d.ts.map +1 -0
- package/dist/effects/effect-recovery.js +120 -0
- package/dist/effects/effect-recovery.js.map +1 -0
- package/dist/effects/effect-transitions.d.ts +34 -0
- package/dist/effects/effect-transitions.d.ts.map +1 -0
- package/dist/effects/effect-transitions.js +148 -0
- package/dist/effects/effect-transitions.js.map +1 -0
- package/dist/effects/effect-types.d.ts +135 -0
- package/dist/effects/effect-types.d.ts.map +1 -0
- package/dist/effects/effect-types.js +32 -0
- package/dist/effects/effect-types.js.map +1 -0
- package/dist/harness/abort-delivery.d.ts +26 -0
- package/dist/harness/abort-delivery.d.ts.map +1 -0
- package/dist/harness/abort-delivery.js +36 -0
- package/dist/harness/abort-delivery.js.map +1 -0
- package/dist/harness/agent-harness.d.ts +18 -0
- package/dist/harness/agent-harness.d.ts.map +1 -1
- package/dist/harness/agent-harness.js +37 -28
- package/dist/harness/agent-harness.js.map +1 -1
- package/dist/harness/canonical-digest.d.ts +32 -0
- package/dist/harness/canonical-digest.d.ts.map +1 -0
- package/dist/harness/canonical-digest.js +164 -0
- package/dist/harness/canonical-digest.js.map +1 -0
- package/dist/harness/deferred-commands.d.ts +53 -0
- package/dist/harness/deferred-commands.d.ts.map +1 -0
- package/dist/harness/deferred-commands.js +96 -0
- package/dist/harness/deferred-commands.js.map +1 -0
- package/dist/harness/operation-outcome.d.ts +18 -10
- package/dist/harness/operation-outcome.d.ts.map +1 -1
- package/dist/harness/operation-outcome.js +71 -35
- package/dist/harness/operation-outcome.js.map +1 -1
- package/dist/harness/operation-trace-divergence.d.ts +60 -0
- package/dist/harness/operation-trace-divergence.d.ts.map +1 -0
- package/dist/harness/operation-trace-divergence.js +199 -0
- package/dist/harness/operation-trace-divergence.js.map +1 -0
- package/dist/harness/operation-trace.d.ts +134 -0
- package/dist/harness/operation-trace.d.ts.map +1 -0
- package/dist/harness/operation-trace.js +161 -0
- package/dist/harness/operation-trace.js.map +1 -0
- package/dist/harness/reverse-skill-text.d.ts +3 -0
- package/dist/harness/reverse-skill-text.d.ts.map +1 -0
- package/dist/harness/reverse-skill-text.js +20 -0
- package/dist/harness/reverse-skill-text.js.map +1 -0
- package/dist/harness/reverse-skill-tool-aliases.d.ts +3 -0
- package/dist/harness/reverse-skill-tool-aliases.d.ts.map +1 -0
- package/dist/harness/reverse-skill-tool-aliases.js +47 -0
- package/dist/harness/reverse-skill-tool-aliases.js.map +1 -0
- package/dist/harness/reverse-skill-types.d.ts +76 -0
- package/dist/harness/reverse-skill-types.d.ts.map +1 -0
- package/dist/harness/reverse-skill-types.js +2 -0
- package/dist/harness/reverse-skill-types.js.map +1 -0
- package/dist/harness/reverse-skill.d.ts +4 -78
- package/dist/harness/reverse-skill.d.ts.map +1 -1
- package/dist/harness/reverse-skill.js +113 -61
- package/dist/harness/reverse-skill.js.map +1 -1
- package/dist/harness/subscriber-fanout.d.ts +14 -1
- package/dist/harness/subscriber-fanout.d.ts.map +1 -1
- package/dist/harness/subscriber-fanout.js +25 -6
- package/dist/harness/subscriber-fanout.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/listener-delivery.d.ts +22 -0
- package/dist/listener-delivery.d.ts.map +1 -0
- package/dist/listener-delivery.js +36 -0
- package/dist/listener-delivery.js.map +1 -0
- package/dist/pending-message-queue.d.ts +11 -0
- package/dist/pending-message-queue.d.ts.map +1 -0
- package/dist/pending-message-queue.js +29 -0
- package/dist/pending-message-queue.js.map +1 -0
- package/dist/provider-input.d.ts +8 -0
- package/dist/provider-input.d.ts.map +1 -0
- package/dist/provider-input.js +28 -0
- package/dist/provider-input.js.map +1 -0
- package/dist/provider-payload-contract.d.ts +6 -0
- package/dist/provider-payload-contract.d.ts.map +1 -0
- package/dist/provider-payload-contract.js +43 -0
- package/dist/provider-payload-contract.js.map +1 -0
- package/dist/provider-request-types.d.ts +46 -0
- package/dist/provider-request-types.d.ts.map +1 -0
- package/dist/provider-request-types.js +2 -0
- package/dist/provider-request-types.js.map +1 -0
- package/dist/provider-request.d.ts +17 -0
- package/dist/provider-request.d.ts.map +1 -0
- package/dist/provider-request.js +110 -0
- package/dist/provider-request.js.map +1 -0
- package/dist/run-model-contract.d.ts +11 -0
- package/dist/run-model-contract.d.ts.map +1 -0
- package/dist/run-model-contract.js +121 -0
- package/dist/run-model-contract.js.map +1 -0
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vision-route.d.ts +19 -0
- package/dist/vision-route.d.ts.map +1 -0
- package/dist/vision-route.js +19 -0
- package/dist/vision-route.js.map +1 -0
- package/package.json +4 -3
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* falsely rejecting an unrelated concurrent caller that runs later while the
|
|
10
10
|
* listener's promise is merely pending.
|
|
11
11
|
*
|
|
12
|
+
* Delivery is observational: every subscriber runs even when an earlier one
|
|
13
|
+
* fails, and the failures are raised together afterwards.
|
|
14
|
+
*
|
|
12
15
|
* This module imports no harness or session types so it stays a leaf for the
|
|
13
16
|
* import-cycle ratchet; the harness passes the current operation id in.
|
|
14
17
|
*/
|
|
@@ -24,8 +27,19 @@ export class SubscriberFanout {
|
|
|
24
27
|
this.listeners.add(listener);
|
|
25
28
|
return () => this.listeners.delete(listener);
|
|
26
29
|
}
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Deliver `event` to every subscriber in registration order, then fail the
|
|
32
|
+
* emission once the fanout has completed.
|
|
33
|
+
*
|
|
34
|
+
* Observational subscribers must not starve each other: one throwing telemetry
|
|
35
|
+
* or audit listener cannot hide `settled` / `attempt_finished` from the
|
|
36
|
+
* listeners registered after it. Failures are collected and raised after the
|
|
37
|
+
* last listener ran — a single failure keeps its own classification, several
|
|
38
|
+
* become one `AggregateError` classified by the first. Policy and mutation
|
|
39
|
+
* hooks live on `AgentHarness.on()` and stay fail-fast.
|
|
40
|
+
*/
|
|
28
41
|
async emit(event, currentOperationId, signal) {
|
|
42
|
+
const failures = [];
|
|
29
43
|
for (const listener of this.listeners) {
|
|
30
44
|
const previousOperationId = this.operationId;
|
|
31
45
|
const previousEventType = this.eventType;
|
|
@@ -37,9 +51,7 @@ export class SubscriberFanout {
|
|
|
37
51
|
pending = listener(event, signal);
|
|
38
52
|
}
|
|
39
53
|
catch (error) {
|
|
40
|
-
|
|
41
|
-
this.eventType = previousEventType;
|
|
42
|
-
throw normalizeHarnessError(error, "hook");
|
|
54
|
+
failures.push(error);
|
|
43
55
|
}
|
|
44
56
|
finally {
|
|
45
57
|
this.syncFrameDepth -= 1;
|
|
@@ -48,13 +60,19 @@ export class SubscriberFanout {
|
|
|
48
60
|
await pending;
|
|
49
61
|
}
|
|
50
62
|
catch (error) {
|
|
51
|
-
|
|
63
|
+
failures.push(error);
|
|
52
64
|
}
|
|
53
65
|
finally {
|
|
54
66
|
this.operationId = previousOperationId;
|
|
55
67
|
this.eventType = previousEventType;
|
|
56
68
|
}
|
|
57
69
|
}
|
|
70
|
+
if (failures.length === 1)
|
|
71
|
+
throw normalizeHarnessError(failures[0], "hook");
|
|
72
|
+
if (failures.length > 1) {
|
|
73
|
+
const cause = new AggregateError(failures, `${failures.length} subscribers failed for ${event.type}`);
|
|
74
|
+
throw new AgentHarnessError(normalizeHarnessError(failures[0], "hook").code, cause.message, cause);
|
|
75
|
+
}
|
|
58
76
|
}
|
|
59
77
|
/**
|
|
60
78
|
* Fail closed when an awaited listener tries to wait on its own operation.
|
|
@@ -66,7 +84,8 @@ export class SubscriberFanout {
|
|
|
66
84
|
*/
|
|
67
85
|
assertNotSelfWait(api, currentOperationId) {
|
|
68
86
|
if (this.syncFrameDepth > 0 && currentOperationId !== undefined && currentOperationId === this.operationId) {
|
|
69
|
-
throw new AgentHarnessError("invalid_state", `${api} cannot await the current operation from an awaited ${this.eventType ?? "unknown"} callback`
|
|
87
|
+
throw new AgentHarnessError("invalid_state", `${api} cannot await the current operation from an awaited ${this.eventType ?? "unknown"} callback; ` +
|
|
88
|
+
"use runWhenIdle() to schedule work for after it settles");
|
|
70
89
|
}
|
|
71
90
|
}
|
|
72
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscriber-fanout.js","sourceRoot":"","sources":["../../src/harness/subscriber-fanout.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"subscriber-fanout.js","sourceRoot":"","sources":["../../src/harness/subscriber-fanout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,MAAM,OAAO,gBAAgB;IACX,SAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IACnE,+EAA+E;IACvE,cAAc,GAAG,CAAC,CAAC;IACnB,WAAW,CAAqB;IAChC,SAAS,CAAqB;IAEtC,SAAS,CAAC,QAAoC,EAAc;QAC3D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAAA,CAC7C;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa,EAAE,kBAAsC,EAAE,MAAoB,EAAiB;QACtG,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACvC,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC;YAC7C,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC;YACzC,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAC;YACtC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;YAC5B,IAAI,OAAmC,CAAC;YACxC,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC;YACzB,IAAI,CAAC;gBACJ,OAAO,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACnC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;oBAAS,CAAC;gBACV,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC;gBACJ,MAAM,OAAO,CAAC;YACf,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;oBAAS,CAAC;gBACV,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC;gBACvC,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;YACpC,CAAC;QACF,CAAC;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,MAAM,2BAA2B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACtG,MAAM,IAAI,iBAAiB,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACpG,CAAC;IAAA,CACD;IAED;;;;;;;OAOG;IACH,iBAAiB,CAAC,GAAW,EAAE,kBAAsC,EAAQ;QAC5E,IAAI,IAAI,CAAC,cAAc,GAAG,CAAC,IAAI,kBAAkB,KAAK,SAAS,IAAI,kBAAkB,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5G,MAAM,IAAI,iBAAiB,CAC1B,eAAe,EACf,GAAG,GAAG,uDAAuD,IAAI,CAAC,SAAS,IAAI,SAAS,aAAa;gBACpG,yDAAyD,CAC1D,CAAC;QACH,CAAC;IAAA,CACD;CACD","sourcesContent":["/**\n * Subscriber fan-out with a self-wait barrier, extracted from `AgentHarness`.\n *\n * A listener that awaits the end of the very operation whose emission it is\n * blocking forms a cycle. The call that closes that cycle (`waitForIdle()`,\n * `abort()`) is always made during the listener's *synchronous* prologue — an\n * async function body runs synchronously up to its first `await` — so marking\n * just that window identifies callback-originated waits exactly, without\n * falsely rejecting an unrelated concurrent caller that runs later while the\n * listener's promise is merely pending.\n *\n * Delivery is observational: every subscriber runs even when an earlier one\n * fails, and the failures are raised together afterwards.\n *\n * This module imports no harness or session types so it stays a leaf for the\n * import-cycle ratchet; the harness passes the current operation id in.\n */\n\nimport { AgentHarnessError } from \"./errors.ts\";\nimport { normalizeHarnessError } from \"./operation-outcome.ts\";\n\nexport type SubscriberListener<TEvent> = (event: TEvent, signal?: AbortSignal) => Promise<void> | void;\n\nexport class SubscriberFanout<TEvent extends { readonly type: string }> {\n\tprivate readonly listeners = new Set<SubscriberListener<TEvent>>();\n\t/** Non-zero only while a subscriber's synchronous prologue is on the stack. */\n\tprivate syncFrameDepth = 0;\n\tprivate operationId: string | undefined;\n\tprivate eventType: string | undefined;\n\n\tsubscribe(listener: SubscriberListener<TEvent>): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\t/**\n\t * Deliver `event` to every subscriber in registration order, then fail the\n\t * emission once the fanout has completed.\n\t *\n\t * Observational subscribers must not starve each other: one throwing telemetry\n\t * or audit listener cannot hide `settled` / `attempt_finished` from the\n\t * listeners registered after it. Failures are collected and raised after the\n\t * last listener ran — a single failure keeps its own classification, several\n\t * become one `AggregateError` classified by the first. Policy and mutation\n\t * hooks live on `AgentHarness.on()` and stay fail-fast.\n\t */\n\tasync emit(event: TEvent, currentOperationId: string | undefined, signal?: AbortSignal): Promise<void> {\n\t\tconst failures: unknown[] = [];\n\t\tfor (const listener of this.listeners) {\n\t\t\tconst previousOperationId = this.operationId;\n\t\t\tconst previousEventType = this.eventType;\n\t\t\tthis.operationId = currentOperationId;\n\t\t\tthis.eventType = event.type;\n\t\t\tlet pending: Promise<unknown> | unknown;\n\t\t\tthis.syncFrameDepth += 1;\n\t\t\ttry {\n\t\t\t\tpending = listener(event, signal);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t} finally {\n\t\t\t\tthis.syncFrameDepth -= 1;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait pending;\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t} finally {\n\t\t\t\tthis.operationId = previousOperationId;\n\t\t\t\tthis.eventType = previousEventType;\n\t\t\t}\n\t\t}\n\t\tif (failures.length === 1) throw normalizeHarnessError(failures[0], \"hook\");\n\t\tif (failures.length > 1) {\n\t\t\tconst cause = new AggregateError(failures, `${failures.length} subscribers failed for ${event.type}`);\n\t\t\tthrow new AgentHarnessError(normalizeHarnessError(failures[0], \"hook\").code, cause.message, cause);\n\t\t}\n\t}\n\n\t/**\n\t * Fail closed when an awaited listener tries to wait on its own operation.\n\t * Rejecting immediately turns a permanent deadlock into a classified error.\n\t *\n\t * Scope: this catches a wait issued from the listener's synchronous prologue,\n\t * which covers `await harness.waitForIdle()` / `await harness.abort()`. A wait\n\t * deferred behind an unrelated `await` inside the listener is not detected.\n\t */\n\tassertNotSelfWait(api: string, currentOperationId: string | undefined): void {\n\t\tif (this.syncFrameDepth > 0 && currentOperationId !== undefined && currentOperationId === this.operationId) {\n\t\t\tthrow new AgentHarnessError(\n\t\t\t\t\"invalid_state\",\n\t\t\t\t`${api} cannot await the current operation from an awaited ${this.eventType ?? \"unknown\"} callback; ` +\n\t\t\t\t\t\"use runWhenIdle() to schedule work for after it settles\",\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export * from "./agent.ts";
|
|
2
2
|
export * from "./agent-loop.ts";
|
|
3
|
+
export * from "./harness/abort-delivery.ts";
|
|
3
4
|
export * from "./harness/agent-harness.ts";
|
|
4
5
|
export { type BranchPreparation, type BranchSummaryDetails, type CollectEntriesResult, collectEntriesForBranchSummary, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.ts";
|
|
5
6
|
export { calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.ts";
|
|
7
|
+
export * from "./harness/deferred-commands.ts";
|
|
6
8
|
export * from "./harness/messages.ts";
|
|
7
9
|
export * from "./harness/prompt-templates.ts";
|
|
8
10
|
export * from "./harness/reverse-skill.ts";
|
|
@@ -17,7 +19,10 @@ export * from "./harness/types.ts";
|
|
|
17
19
|
export * from "./harness/utils/shell-output.ts";
|
|
18
20
|
export * from "./harness/utils/truncate.ts";
|
|
19
21
|
export { NEVER_PARALLEL_TOOLS, PARALLEL_SAFE_TOOLS, PATH_SCOPED_TOOLS, partitionToolBatchWaves, pathsOverlap, shouldParallelizeToolBatch, } from "./parallel-tool-batch.ts";
|
|
22
|
+
export { type ProviderInputProjection, projectToolImagesForModel } from "./provider-input.ts";
|
|
23
|
+
export { applyModelContract, type ProviderRequestEvent } from "./provider-request.ts";
|
|
20
24
|
export * from "./proxy.ts";
|
|
25
|
+
export * from "./run-model-contract.ts";
|
|
21
26
|
export { applyConcurrencyCap, assignDagLevels, computePlanKey, type DagSchedulePlan, type ResolvedClaimEntry, resolveBatchClaims, type ScheduleDagLevelsOptions, scheduleDagLevels, } from "./tool-dag-scheduler.ts";
|
|
22
27
|
export { type ClaimableToolCall, canonicalizeClaims, claimsConflict, compareClaims, type ResolveToolClaimsOptions, resolutionsConflict, resolvePathClaimKey, resolveToolClaims, type ToolClaimResolution, type ToolResourceAccess, type ToolResourceClaim, } from "./tool-resource-claims.ts";
|
|
23
28
|
export { createAbortedToolResult, createTimeoutToolResult, resolveToolExecutionPolicy, resolveToolTimeoutMs, type ToolDispositionEnvelope, type ToolLateSettlement, } from "./tool-timeout.ts";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACN,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAEtF,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AAExC,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,KAAK,wBAAwB,EAC7B,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACN,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,KAAK,wBAAwB,EAC7B,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,yBAAyB,GAC9B,MAAM,gCAAgC,CAAC;AAExC,cAAc,YAAY,CAAC","sourcesContent":["// Core Agent\nexport * from \"./agent.ts\";\n// Loop functions\nexport * from \"./agent-loop.ts\";\nexport * from \"./harness/abort-delivery.ts\";\nexport * from \"./harness/agent-harness.ts\";\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryDetails,\n\ttype CollectEntriesResult,\n\tcollectEntriesForBranchSummary,\n\tgenerateBranchSummary,\n\tprepareBranchEntries,\n} from \"./harness/compaction/branch-summarization.ts\";\nexport {\n\tcalculateContextTokens,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\tgenerateSummary,\n\tgetLastAssistantUsage,\n\tprepareCompaction,\n\tserializeConversation,\n\tshouldCompact,\n} from \"./harness/compaction/compaction.ts\";\nexport * from \"./harness/deferred-commands.ts\";\nexport * from \"./harness/messages.ts\";\nexport * from \"./harness/prompt-templates.ts\";\nexport * from \"./harness/reverse-skill.ts\";\nexport * from \"./harness/session/jsonl-repo.ts\";\nexport * from \"./harness/session/memory-repo.ts\";\nexport * from \"./harness/session/repo-utils.ts\";\nexport * from \"./harness/session/session.ts\";\nexport { uuidv7 } from \"./harness/session/uuid.ts\";\nexport * from \"./harness/skills.ts\";\nexport * from \"./harness/system-prompt.ts\";\n// Harness\nexport * from \"./harness/types.ts\";\nexport * from \"./harness/utils/shell-output.ts\";\nexport * from \"./harness/utils/truncate.ts\";\n// Parallel tool batch policy\nexport {\n\tNEVER_PARALLEL_TOOLS,\n\tPARALLEL_SAFE_TOOLS,\n\tPATH_SCOPED_TOOLS,\n\tpartitionToolBatchWaves,\n\tpathsOverlap,\n\tshouldParallelizeToolBatch,\n} from \"./parallel-tool-batch.ts\";\nexport { type ProviderInputProjection, projectToolImagesForModel } from \"./provider-input.ts\";\nexport { applyModelContract, type ProviderRequestEvent } from \"./provider-request.ts\";\n// Proxy utilities\nexport * from \"./proxy.ts\";\nexport * from \"./run-model-contract.ts\";\n// Deterministic resource-claim DAG scheduler (dag-v2)\nexport {\n\tapplyConcurrencyCap,\n\tassignDagLevels,\n\tcomputePlanKey,\n\ttype DagSchedulePlan,\n\ttype ResolvedClaimEntry,\n\tresolveBatchClaims,\n\ttype ScheduleDagLevelsOptions,\n\tscheduleDagLevels,\n} from \"./tool-dag-scheduler.ts\";\n// Resource-claim model (dag-v2)\nexport {\n\ttype ClaimableToolCall,\n\tcanonicalizeClaims,\n\tclaimsConflict,\n\tcompareClaims,\n\ttype ResolveToolClaimsOptions,\n\tresolutionsConflict,\n\tresolvePathClaimKey,\n\tresolveToolClaims,\n\ttype ToolClaimResolution,\n\ttype ToolResourceAccess,\n\ttype ToolResourceClaim,\n} from \"./tool-resource-claims.ts\";\n// Per-call timeout / cancellation / late settlement (ALG-004)\nexport {\n\tcreateAbortedToolResult,\n\tcreateTimeoutToolResult,\n\tresolveToolExecutionPolicy,\n\tresolveToolTimeoutMs,\n\ttype ToolDispositionEnvelope,\n\ttype ToolLateSettlement,\n} from \"./tool-timeout.ts\";\nexport {\n\tcreateSyntheticToolResult,\n\tinspectTranscriptIntegrity,\n\trepairTranscriptIntegrity,\n\tTranscriptIntegrityError,\n\ttype TranscriptIntegrityIssue,\n\ttype TranscriptIntegrityIssueKind,\n\ttype TranscriptIntegrityReport,\n} from \"./tool-transcript-integrity.ts\";\n// Types\nexport * from \"./types.ts\";\n"]}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
export * from "./agent.js";
|
|
3
3
|
// Loop functions
|
|
4
4
|
export * from "./agent-loop.js";
|
|
5
|
+
export * from "./harness/abort-delivery.js";
|
|
5
6
|
export * from "./harness/agent-harness.js";
|
|
6
7
|
export { collectEntriesForBranchSummary, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.js";
|
|
7
8
|
export { calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.js";
|
|
9
|
+
export * from "./harness/deferred-commands.js";
|
|
8
10
|
export * from "./harness/messages.js";
|
|
9
11
|
export * from "./harness/prompt-templates.js";
|
|
10
12
|
export * from "./harness/reverse-skill.js";
|
|
@@ -21,8 +23,11 @@ export * from "./harness/utils/shell-output.js";
|
|
|
21
23
|
export * from "./harness/utils/truncate.js";
|
|
22
24
|
// Parallel tool batch policy
|
|
23
25
|
export { NEVER_PARALLEL_TOOLS, PARALLEL_SAFE_TOOLS, PATH_SCOPED_TOOLS, partitionToolBatchWaves, pathsOverlap, shouldParallelizeToolBatch, } from "./parallel-tool-batch.js";
|
|
26
|
+
export { projectToolImagesForModel } from "./provider-input.js";
|
|
27
|
+
export { applyModelContract } from "./provider-request.js";
|
|
24
28
|
// Proxy utilities
|
|
25
29
|
export * from "./proxy.js";
|
|
30
|
+
export * from "./run-model-contract.js";
|
|
26
31
|
// Deterministic resource-claim DAG scheduler (dag-v2)
|
|
27
32
|
export { applyConcurrencyCap, assignDagLevels, computePlanKey, resolveBatchClaims, scheduleDagLevels, } from "./tool-dag-scheduler.js";
|
|
28
33
|
// Resource-claim model (dag-v2)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAC3B,iBAAiB;AACjB,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAIN,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,UAAU;AACV,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,6BAA6B;AAC7B,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,sDAAsD;AACtD,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,cAAc,EAGd,kBAAkB,EAElB,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AACjC,gCAAgC;AAChC,OAAO,EAEN,kBAAkB,EAClB,cAAc,EACd,aAAa,EAEb,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAIjB,MAAM,2BAA2B,CAAC;AACnC,8DAA8D;AAC9D,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,GAIxB,MAAM,gCAAgC,CAAC;AACxC,QAAQ;AACR,cAAc,YAAY,CAAC","sourcesContent":["// Core Agent\nexport * from \"./agent.ts\";\n// Loop functions\nexport * from \"./agent-loop.ts\";\nexport * from \"./harness/agent-harness.ts\";\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryDetails,\n\ttype CollectEntriesResult,\n\tcollectEntriesForBranchSummary,\n\tgenerateBranchSummary,\n\tprepareBranchEntries,\n} from \"./harness/compaction/branch-summarization.ts\";\nexport {\n\tcalculateContextTokens,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\tgenerateSummary,\n\tgetLastAssistantUsage,\n\tprepareCompaction,\n\tserializeConversation,\n\tshouldCompact,\n} from \"./harness/compaction/compaction.ts\";\nexport * from \"./harness/messages.ts\";\nexport * from \"./harness/prompt-templates.ts\";\nexport * from \"./harness/reverse-skill.ts\";\nexport * from \"./harness/session/jsonl-repo.ts\";\nexport * from \"./harness/session/memory-repo.ts\";\nexport * from \"./harness/session/repo-utils.ts\";\nexport * from \"./harness/session/session.ts\";\nexport { uuidv7 } from \"./harness/session/uuid.ts\";\nexport * from \"./harness/skills.ts\";\nexport * from \"./harness/system-prompt.ts\";\n// Harness\nexport * from \"./harness/types.ts\";\nexport * from \"./harness/utils/shell-output.ts\";\nexport * from \"./harness/utils/truncate.ts\";\n// Parallel tool batch policy\nexport {\n\tNEVER_PARALLEL_TOOLS,\n\tPARALLEL_SAFE_TOOLS,\n\tPATH_SCOPED_TOOLS,\n\tpartitionToolBatchWaves,\n\tpathsOverlap,\n\tshouldParallelizeToolBatch,\n} from \"./parallel-tool-batch.ts\";\n// Proxy utilities\nexport * from \"./proxy.ts\";\n// Deterministic resource-claim DAG scheduler (dag-v2)\nexport {\n\tapplyConcurrencyCap,\n\tassignDagLevels,\n\tcomputePlanKey,\n\ttype DagSchedulePlan,\n\ttype ResolvedClaimEntry,\n\tresolveBatchClaims,\n\ttype ScheduleDagLevelsOptions,\n\tscheduleDagLevels,\n} from \"./tool-dag-scheduler.ts\";\n// Resource-claim model (dag-v2)\nexport {\n\ttype ClaimableToolCall,\n\tcanonicalizeClaims,\n\tclaimsConflict,\n\tcompareClaims,\n\ttype ResolveToolClaimsOptions,\n\tresolutionsConflict,\n\tresolvePathClaimKey,\n\tresolveToolClaims,\n\ttype ToolClaimResolution,\n\ttype ToolResourceAccess,\n\ttype ToolResourceClaim,\n} from \"./tool-resource-claims.ts\";\n// Per-call timeout / cancellation / late settlement (ALG-004)\nexport {\n\tcreateAbortedToolResult,\n\tcreateTimeoutToolResult,\n\tresolveToolExecutionPolicy,\n\tresolveToolTimeoutMs,\n\ttype ToolDispositionEnvelope,\n\ttype ToolLateSettlement,\n} from \"./tool-timeout.ts\";\nexport {\n\tcreateSyntheticToolResult,\n\tinspectTranscriptIntegrity,\n\trepairTranscriptIntegrity,\n\tTranscriptIntegrityError,\n\ttype TranscriptIntegrityIssue,\n\ttype TranscriptIntegrityIssueKind,\n\ttype TranscriptIntegrityReport,\n} from \"./tool-transcript-integrity.ts\";\n// Types\nexport * from \"./types.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAC3B,iBAAiB;AACjB,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EAIN,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,UAAU;AACV,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,6BAA6B;AAC7B,OAAO,EACN,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,uBAAuB,EACvB,YAAY,EACZ,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAgC,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAA6B,MAAM,uBAAuB,CAAC;AACtF,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,sDAAsD;AACtD,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,cAAc,EAGd,kBAAkB,EAElB,iBAAiB,GACjB,MAAM,yBAAyB,CAAC;AACjC,gCAAgC;AAChC,OAAO,EAEN,kBAAkB,EAClB,cAAc,EACd,aAAa,EAEb,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAIjB,MAAM,2BAA2B,CAAC;AACnC,8DAA8D;AAC9D,OAAO,EACN,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,GAGpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,GAIxB,MAAM,gCAAgC,CAAC;AACxC,QAAQ;AACR,cAAc,YAAY,CAAC","sourcesContent":["// Core Agent\nexport * from \"./agent.ts\";\n// Loop functions\nexport * from \"./agent-loop.ts\";\nexport * from \"./harness/abort-delivery.ts\";\nexport * from \"./harness/agent-harness.ts\";\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryDetails,\n\ttype CollectEntriesResult,\n\tcollectEntriesForBranchSummary,\n\tgenerateBranchSummary,\n\tprepareBranchEntries,\n} from \"./harness/compaction/branch-summarization.ts\";\nexport {\n\tcalculateContextTokens,\n\tcompact,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateContextTokens,\n\testimateTokens,\n\tfindCutPoint,\n\tfindTurnStartIndex,\n\tgenerateSummary,\n\tgetLastAssistantUsage,\n\tprepareCompaction,\n\tserializeConversation,\n\tshouldCompact,\n} from \"./harness/compaction/compaction.ts\";\nexport * from \"./harness/deferred-commands.ts\";\nexport * from \"./harness/messages.ts\";\nexport * from \"./harness/prompt-templates.ts\";\nexport * from \"./harness/reverse-skill.ts\";\nexport * from \"./harness/session/jsonl-repo.ts\";\nexport * from \"./harness/session/memory-repo.ts\";\nexport * from \"./harness/session/repo-utils.ts\";\nexport * from \"./harness/session/session.ts\";\nexport { uuidv7 } from \"./harness/session/uuid.ts\";\nexport * from \"./harness/skills.ts\";\nexport * from \"./harness/system-prompt.ts\";\n// Harness\nexport * from \"./harness/types.ts\";\nexport * from \"./harness/utils/shell-output.ts\";\nexport * from \"./harness/utils/truncate.ts\";\n// Parallel tool batch policy\nexport {\n\tNEVER_PARALLEL_TOOLS,\n\tPARALLEL_SAFE_TOOLS,\n\tPATH_SCOPED_TOOLS,\n\tpartitionToolBatchWaves,\n\tpathsOverlap,\n\tshouldParallelizeToolBatch,\n} from \"./parallel-tool-batch.ts\";\nexport { type ProviderInputProjection, projectToolImagesForModel } from \"./provider-input.ts\";\nexport { applyModelContract, type ProviderRequestEvent } from \"./provider-request.ts\";\n// Proxy utilities\nexport * from \"./proxy.ts\";\nexport * from \"./run-model-contract.ts\";\n// Deterministic resource-claim DAG scheduler (dag-v2)\nexport {\n\tapplyConcurrencyCap,\n\tassignDagLevels,\n\tcomputePlanKey,\n\ttype DagSchedulePlan,\n\ttype ResolvedClaimEntry,\n\tresolveBatchClaims,\n\ttype ScheduleDagLevelsOptions,\n\tscheduleDagLevels,\n} from \"./tool-dag-scheduler.ts\";\n// Resource-claim model (dag-v2)\nexport {\n\ttype ClaimableToolCall,\n\tcanonicalizeClaims,\n\tclaimsConflict,\n\tcompareClaims,\n\ttype ResolveToolClaimsOptions,\n\tresolutionsConflict,\n\tresolvePathClaimKey,\n\tresolveToolClaims,\n\ttype ToolClaimResolution,\n\ttype ToolResourceAccess,\n\ttype ToolResourceClaim,\n} from \"./tool-resource-claims.ts\";\n// Per-call timeout / cancellation / late settlement (ALG-004)\nexport {\n\tcreateAbortedToolResult,\n\tcreateTimeoutToolResult,\n\tresolveToolExecutionPolicy,\n\tresolveToolTimeoutMs,\n\ttype ToolDispositionEnvelope,\n\ttype ToolLateSettlement,\n} from \"./tool-timeout.ts\";\nexport {\n\tcreateSyntheticToolResult,\n\tinspectTranscriptIntegrity,\n\trepairTranscriptIntegrity,\n\tTranscriptIntegrityError,\n\ttype TranscriptIntegrityIssue,\n\ttype TranscriptIntegrityIssueKind,\n\ttype TranscriptIntegrityReport,\n} from \"./tool-transcript-integrity.ts\";\n// Types\nexport * from \"./types.ts\";\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observational listener delivery for `Agent`.
|
|
3
|
+
*
|
|
4
|
+
* Kept as a leaf module (no agent state, no loop imports) so the delivery
|
|
5
|
+
* contract stays readable next to the harness' own `SubscriberFanout`.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentEvent } from "./types.ts";
|
|
8
|
+
export type AgentListener = (event: AgentEvent, signal: AbortSignal) => Promise<void> | void;
|
|
9
|
+
/**
|
|
10
|
+
* Deliver `event` to every listener in subscription order, then raise the
|
|
11
|
+
* failures together.
|
|
12
|
+
*
|
|
13
|
+
* Observation listeners must not starve each other: a throwing extension cannot
|
|
14
|
+
* hide `agent_start`, `turn_end`, or `agent_end` from the listeners registered
|
|
15
|
+
* after it. A single failure surfaces untouched so its own classification
|
|
16
|
+
* survives; several become one `AggregateError`.
|
|
17
|
+
*
|
|
18
|
+
* Each listener receives its own immutable snapshot, so one observer's view can
|
|
19
|
+
* never be rewritten into another's.
|
|
20
|
+
*/
|
|
21
|
+
export declare function deliverToListeners(listeners: Iterable<AgentListener>, event: AgentEvent, signal: AbortSignal): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=listener-delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener-delivery.d.ts","sourceRoot":"","sources":["../src/listener-delivery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE7F;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACvC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,EAClC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAaf","sourcesContent":["/**\n * Observational listener delivery for `Agent`.\n *\n * Kept as a leaf module (no agent state, no loop imports) so the delivery\n * contract stays readable next to the harness' own `SubscriberFanout`.\n */\n\nimport { createImmutableSnapshot } from \"./tool-execution-boundary.ts\";\nimport type { AgentEvent } from \"./types.ts\";\n\nexport type AgentListener = (event: AgentEvent, signal: AbortSignal) => Promise<void> | void;\n\n/**\n * Deliver `event` to every listener in subscription order, then raise the\n * failures together.\n *\n * Observation listeners must not starve each other: a throwing extension cannot\n * hide `agent_start`, `turn_end`, or `agent_end` from the listeners registered\n * after it. A single failure surfaces untouched so its own classification\n * survives; several become one `AggregateError`.\n *\n * Each listener receives its own immutable snapshot, so one observer's view can\n * never be rewritten into another's.\n */\nexport async function deliverToListeners(\n\tlisteners: Iterable<AgentListener>,\n\tevent: AgentEvent,\n\tsignal: AbortSignal,\n): Promise<void> {\n\tconst failures: unknown[] = [];\n\tfor (const listener of listeners) {\n\t\ttry {\n\t\t\tawait listener(createImmutableSnapshot(event), signal);\n\t\t} catch (error) {\n\t\t\tfailures.push(error);\n\t\t}\n\t}\n\tif (failures.length === 1) throw failures[0];\n\tif (failures.length > 1) {\n\t\tthrow new AggregateError(failures, `${failures.length} agent listeners failed for ${event.type}`);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observational listener delivery for `Agent`.
|
|
3
|
+
*
|
|
4
|
+
* Kept as a leaf module (no agent state, no loop imports) so the delivery
|
|
5
|
+
* contract stays readable next to the harness' own `SubscriberFanout`.
|
|
6
|
+
*/
|
|
7
|
+
import { createImmutableSnapshot } from "./tool-execution-boundary.js";
|
|
8
|
+
/**
|
|
9
|
+
* Deliver `event` to every listener in subscription order, then raise the
|
|
10
|
+
* failures together.
|
|
11
|
+
*
|
|
12
|
+
* Observation listeners must not starve each other: a throwing extension cannot
|
|
13
|
+
* hide `agent_start`, `turn_end`, or `agent_end` from the listeners registered
|
|
14
|
+
* after it. A single failure surfaces untouched so its own classification
|
|
15
|
+
* survives; several become one `AggregateError`.
|
|
16
|
+
*
|
|
17
|
+
* Each listener receives its own immutable snapshot, so one observer's view can
|
|
18
|
+
* never be rewritten into another's.
|
|
19
|
+
*/
|
|
20
|
+
export async function deliverToListeners(listeners, event, signal) {
|
|
21
|
+
const failures = [];
|
|
22
|
+
for (const listener of listeners) {
|
|
23
|
+
try {
|
|
24
|
+
await listener(createImmutableSnapshot(event), signal);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
failures.push(error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (failures.length === 1)
|
|
31
|
+
throw failures[0];
|
|
32
|
+
if (failures.length > 1) {
|
|
33
|
+
throw new AggregateError(failures, `${failures.length} agent listeners failed for ${event.type}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=listener-delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listener-delivery.js","sourceRoot":"","sources":["../src/listener-delivery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAKvE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,SAAkC,EAClC,KAAiB,EACjB,MAAmB,EACH;IAChB,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,IAAI,CAAC;YACJ,MAAM,QAAQ,CAAC,uBAAuB,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC7C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,cAAc,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,MAAM,+BAA+B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACnG,CAAC;AAAA,CACD","sourcesContent":["/**\n * Observational listener delivery for `Agent`.\n *\n * Kept as a leaf module (no agent state, no loop imports) so the delivery\n * contract stays readable next to the harness' own `SubscriberFanout`.\n */\n\nimport { createImmutableSnapshot } from \"./tool-execution-boundary.ts\";\nimport type { AgentEvent } from \"./types.ts\";\n\nexport type AgentListener = (event: AgentEvent, signal: AbortSignal) => Promise<void> | void;\n\n/**\n * Deliver `event` to every listener in subscription order, then raise the\n * failures together.\n *\n * Observation listeners must not starve each other: a throwing extension cannot\n * hide `agent_start`, `turn_end`, or `agent_end` from the listeners registered\n * after it. A single failure surfaces untouched so its own classification\n * survives; several become one `AggregateError`.\n *\n * Each listener receives its own immutable snapshot, so one observer's view can\n * never be rewritten into another's.\n */\nexport async function deliverToListeners(\n\tlisteners: Iterable<AgentListener>,\n\tevent: AgentEvent,\n\tsignal: AbortSignal,\n): Promise<void> {\n\tconst failures: unknown[] = [];\n\tfor (const listener of listeners) {\n\t\ttry {\n\t\t\tawait listener(createImmutableSnapshot(event), signal);\n\t\t} catch (error) {\n\t\t\tfailures.push(error);\n\t\t}\n\t}\n\tif (failures.length === 1) throw failures[0];\n\tif (failures.length > 1) {\n\t\tthrow new AggregateError(failures, `${failures.length} agent listeners failed for ${event.type}`);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgentMessage, QueueMode } from "./types.ts";
|
|
2
|
+
export declare class PendingMessageQueue {
|
|
3
|
+
private messages;
|
|
4
|
+
mode: QueueMode;
|
|
5
|
+
constructor(mode: QueueMode);
|
|
6
|
+
enqueue(message: AgentMessage): void;
|
|
7
|
+
hasItems(): boolean;
|
|
8
|
+
drain(): AgentMessage[];
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=pending-message-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-message-queue.d.ts","sourceRoot":"","sources":["../src/pending-message-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1D,qBAAa,mBAAmB;IAC/B,OAAO,CAAC,QAAQ,CAAsB;IAC/B,IAAI,EAAE,SAAS,CAAC;IAEvB,YAAY,IAAI,EAAE,SAAS,EAE1B;IAED,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAEnC;IAED,QAAQ,IAAI,OAAO,CAElB;IAED,KAAK,IAAI,YAAY,EAAE,CAUtB;IAED,KAAK,IAAI,IAAI,CAEZ;CACD","sourcesContent":["import type { AgentMessage, QueueMode } from \"./types.ts\";\n\nexport class PendingMessageQueue {\n\tprivate messages: AgentMessage[] = [];\n\tpublic mode: QueueMode;\n\n\tconstructor(mode: QueueMode) {\n\t\tthis.mode = mode;\n\t}\n\n\tenqueue(message: AgentMessage): void {\n\t\tthis.messages.push(message);\n\t}\n\n\thasItems(): boolean {\n\t\treturn this.messages.length > 0;\n\t}\n\n\tdrain(): AgentMessage[] {\n\t\tif (this.mode === \"all\") {\n\t\t\tconst drained = this.messages.slice();\n\t\t\tthis.messages = [];\n\t\t\treturn drained;\n\t\t}\n\t\tconst first = this.messages[0];\n\t\tif (!first) return [];\n\t\tthis.messages = this.messages.slice(1);\n\t\treturn [first];\n\t}\n\n\tclear(): void {\n\t\tthis.messages = [];\n\t}\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class PendingMessageQueue {
|
|
2
|
+
messages = [];
|
|
3
|
+
mode;
|
|
4
|
+
constructor(mode) {
|
|
5
|
+
this.mode = mode;
|
|
6
|
+
}
|
|
7
|
+
enqueue(message) {
|
|
8
|
+
this.messages.push(message);
|
|
9
|
+
}
|
|
10
|
+
hasItems() {
|
|
11
|
+
return this.messages.length > 0;
|
|
12
|
+
}
|
|
13
|
+
drain() {
|
|
14
|
+
if (this.mode === "all") {
|
|
15
|
+
const drained = this.messages.slice();
|
|
16
|
+
this.messages = [];
|
|
17
|
+
return drained;
|
|
18
|
+
}
|
|
19
|
+
const first = this.messages[0];
|
|
20
|
+
if (!first)
|
|
21
|
+
return [];
|
|
22
|
+
this.messages = this.messages.slice(1);
|
|
23
|
+
return [first];
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
this.messages = [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pending-message-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-message-queue.js","sourceRoot":"","sources":["../src/pending-message-queue.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAmB;IACvB,QAAQ,GAAmB,EAAE,CAAC;IAC/B,IAAI,CAAY;IAEvB,YAAY,IAAe,EAAE;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED,OAAO,CAAC,OAAqB,EAAQ;QACpC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAAA,CAC5B;IAED,QAAQ,GAAY;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAAA,CAChC;IAED,KAAK,GAAmB;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACzB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACtC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;YACnB,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,CAAC,KAAK;YAAE,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvC,OAAO,CAAC,KAAK,CAAC,CAAC;IAAA,CACf;IAED,KAAK,GAAS;QACb,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IAAA,CACnB;CACD","sourcesContent":["import type { AgentMessage, QueueMode } from \"./types.ts\";\n\nexport class PendingMessageQueue {\n\tprivate messages: AgentMessage[] = [];\n\tpublic mode: QueueMode;\n\n\tconstructor(mode: QueueMode) {\n\t\tthis.mode = mode;\n\t}\n\n\tenqueue(message: AgentMessage): void {\n\t\tthis.messages.push(message);\n\t}\n\n\thasItems(): boolean {\n\t\treturn this.messages.length > 0;\n\t}\n\n\tdrain(): AgentMessage[] {\n\t\tif (this.mode === \"all\") {\n\t\t\tconst drained = this.messages.slice();\n\t\t\tthis.messages = [];\n\t\t\treturn drained;\n\t\t}\n\t\tconst first = this.messages[0];\n\t\tif (!first) return [];\n\t\tthis.messages = this.messages.slice(1);\n\t\treturn [first];\n\t}\n\n\tclear(): void {\n\t\tthis.messages = [];\n\t}\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Api, Context, Model } from "omk-ai";
|
|
2
|
+
export interface ProviderInputProjection {
|
|
3
|
+
readonly context: Context;
|
|
4
|
+
readonly omittedToolImages: number;
|
|
5
|
+
}
|
|
6
|
+
/** A provider view, not a transcript rewrite or visual interpretation. User attachments stay intact. */
|
|
7
|
+
export declare function projectToolImagesForModel(context: Context, model: Pick<Model<Api>, "input">): ProviderInputProjection;
|
|
8
|
+
//# sourceMappingURL=provider-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-input.d.ts","sourceRoot":"","sources":["../src/provider-input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACnC;AAED,wGAAwG;AACxG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,uBAAuB,CA4BrH","sourcesContent":["import type { Api, Context, Model } from \"omk-ai\";\n\nexport interface ProviderInputProjection {\n\treadonly context: Context;\n\treadonly omittedToolImages: number;\n}\n\n/** A provider view, not a transcript rewrite or visual interpretation. User attachments stay intact. */\nexport function projectToolImagesForModel(context: Context, model: Pick<Model<Api>, \"input\">): ProviderInputProjection {\n\tif (\n\t\tmodel.input.includes(\"image\") ||\n\t\t!context.messages.some(\n\t\t\t(message) => message.role === \"toolResult\" && message.content.some((part) => part.type === \"image\"),\n\t\t)\n\t) {\n\t\treturn { context, omittedToolImages: 0 };\n\t}\n\tlet omittedToolImages = 0;\n\tconst messages = context.messages.map((message) => {\n\t\tif (message.role !== \"toolResult\" || !message.content.some((part) => part.type === \"image\")) return message;\n\t\treturn {\n\t\t\t...message,\n\t\t\tcontent: message.content.map((part) => {\n\t\t\t\tif (part.type !== \"image\") return part;\n\t\t\t\tomittedToolImages++;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\ttext:\n\t\t\t\t\t\t\"[Tool image omitted from this model request: the selected model accepts text only. \" +\n\t\t\t\t\t\t\"The image contents were not inspected. The original attachment remains in the session/tool source. \" +\n\t\t\t\t\t\t\"Use permitted local tools to inspect or extract text from the source artifact; do not infer its visual contents.]\",\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\treturn { context: { ...context, messages }, omittedToolImages };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** A provider view, not a transcript rewrite or visual interpretation. User attachments stay intact. */
|
|
2
|
+
export function projectToolImagesForModel(context, model) {
|
|
3
|
+
if (model.input.includes("image") ||
|
|
4
|
+
!context.messages.some((message) => message.role === "toolResult" && message.content.some((part) => part.type === "image"))) {
|
|
5
|
+
return { context, omittedToolImages: 0 };
|
|
6
|
+
}
|
|
7
|
+
let omittedToolImages = 0;
|
|
8
|
+
const messages = context.messages.map((message) => {
|
|
9
|
+
if (message.role !== "toolResult" || !message.content.some((part) => part.type === "image"))
|
|
10
|
+
return message;
|
|
11
|
+
return {
|
|
12
|
+
...message,
|
|
13
|
+
content: message.content.map((part) => {
|
|
14
|
+
if (part.type !== "image")
|
|
15
|
+
return part;
|
|
16
|
+
omittedToolImages++;
|
|
17
|
+
return {
|
|
18
|
+
type: "text",
|
|
19
|
+
text: "[Tool image omitted from this model request: the selected model accepts text only. " +
|
|
20
|
+
"The image contents were not inspected. The original attachment remains in the session/tool source. " +
|
|
21
|
+
"Use permitted local tools to inspect or extract text from the source artifact; do not infer its visual contents.]",
|
|
22
|
+
};
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return { context: { ...context, messages }, omittedToolImages };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=provider-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-input.js","sourceRoot":"","sources":["../src/provider-input.ts"],"names":[],"mappings":"AAOA,wGAAwG;AACxG,MAAM,UAAU,yBAAyB,CAAC,OAAgB,EAAE,KAAgC,EAA2B;IACtH,IACC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC7B,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CACnG,EACA,CAAC;QACF,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,EAAE,CAAC;IAC1C,CAAC;IACD,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC;YAAE,OAAO,OAAO,CAAC;QAC5G,OAAO;YACN,GAAG,OAAO;YACV,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACtC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;oBAAE,OAAO,IAAI,CAAC;gBACvC,iBAAiB,EAAE,CAAC;gBACpB,OAAO;oBACN,IAAI,EAAE,MAAe;oBACrB,IAAI,EACH,qFAAqF;wBACrF,qGAAqG;wBACrG,mHAAmH;iBACpH,CAAC;YAAA,CACF,CAAC;SACF,CAAC;IAAA,CACF,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,EAAE,CAAC;AAAA,CAChE","sourcesContent":["import type { Api, Context, Model } from \"omk-ai\";\n\nexport interface ProviderInputProjection {\n\treadonly context: Context;\n\treadonly omittedToolImages: number;\n}\n\n/** A provider view, not a transcript rewrite or visual interpretation. User attachments stay intact. */\nexport function projectToolImagesForModel(context: Context, model: Pick<Model<Api>, \"input\">): ProviderInputProjection {\n\tif (\n\t\tmodel.input.includes(\"image\") ||\n\t\t!context.messages.some(\n\t\t\t(message) => message.role === \"toolResult\" && message.content.some((part) => part.type === \"image\"),\n\t\t)\n\t) {\n\t\treturn { context, omittedToolImages: 0 };\n\t}\n\tlet omittedToolImages = 0;\n\tconst messages = context.messages.map((message) => {\n\t\tif (message.role !== \"toolResult\" || !message.content.some((part) => part.type === \"image\")) return message;\n\t\treturn {\n\t\t\t...message,\n\t\t\tcontent: message.content.map((part) => {\n\t\t\t\tif (part.type !== \"image\") return part;\n\t\t\t\tomittedToolImages++;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\ttext:\n\t\t\t\t\t\t\"[Tool image omitted from this model request: the selected model accepts text only. \" +\n\t\t\t\t\t\t\"The image contents were not inspected. The original attachment remains in the session/tool source. \" +\n\t\t\t\t\t\t\"Use permitted local tools to inspect or extract text from the source artifact; do not infer its visual contents.]\",\n\t\t\t\t};\n\t\t\t}),\n\t\t};\n\t});\n\treturn { context: { ...context, messages }, omittedToolImages };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Api, Model, SimpleStreamOptions } from "omk-ai";
|
|
2
|
+
type PayloadHook = NonNullable<SimpleStreamOptions["onPayload"]>;
|
|
3
|
+
/** Validate supported final payloads and preserve immutable user observation. */
|
|
4
|
+
export declare function createContractPayloadHook(model: Pick<Model<Api>, "api" | "id">, maxTokens: number, observer?: PayloadHook): PayloadHook;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=provider-payload-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-payload-contract.d.ts","sourceRoot":"","sources":["../src/provider-payload-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAI9D,KAAK,WAAW,GAAG,WAAW,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC;AAoBjE,iFAAiF;AACjF,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,EACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,WAAW,GACpB,WAAW,CAgBb","sourcesContent":["import type { Api, Model, SimpleStreamOptions } from \"omk-ai\";\nimport { createImmutableSnapshot } from \"./plain-data.ts\";\nimport { ModelContractViolation } from \"./run-model-contract.ts\";\n\ntype PayloadHook = NonNullable<SimpleStreamOptions[\"onPayload\"]>;\nconst contractHooks = new WeakSet<PayloadHook>();\n\nfunction assertCompletionPayload(payload: unknown, modelId: string, maxTokens: number): void {\n\tif (typeof payload !== \"object\" || payload === null || Array.isArray(payload) || !(\"model\" in payload)) {\n\t\tthrow new ModelContractViolation(\"invalid-request\");\n\t}\n\tif (payload.model !== modelId) throw new ModelContractViolation(\"model-not-allowed\");\n\tconst legacyLimit = \"max_tokens\" in payload ? payload.max_tokens : undefined;\n\tconst completionLimit = \"max_completion_tokens\" in payload ? payload.max_completion_tokens : undefined;\n\tif (legacyLimit !== undefined && completionLimit !== undefined) {\n\t\tthrow new ModelContractViolation(\"invalid-request-limit\");\n\t}\n\tconst limit = legacyLimit !== undefined ? legacyLimit : completionLimit;\n\tif (typeof limit !== \"number\" || !Number.isSafeInteger(limit) || limit <= 0) {\n\t\tthrow new ModelContractViolation(\"invalid-request-limit\");\n\t}\n\tif (limit > maxTokens) throw new ModelContractViolation(\"output-limit-exceeded\");\n}\n\n/** Validate supported final payloads and preserve immutable user observation. */\nexport function createContractPayloadHook(\n\tmodel: Pick<Model<Api>, \"api\" | \"id\">,\n\tmaxTokens: number,\n\tobserver?: PayloadHook,\n): PayloadHook {\n\tconst { api, id } = model;\n\tconst hook: PayloadHook = async (payload, requestModel) => {\n\t\tif (api === \"openai-completions\") assertCompletionPayload(payload, id, maxTokens);\n\t\tif (!observer) return;\n\t\t// The core and SDK both enforce contracts. Only the innermost user hook needs a snapshot.\n\t\tif (contractHooks.has(observer)) return observer(payload, requestModel);\n\t\tconst original = createImmutableSnapshot(payload);\n\t\tconst result = (await observer(original, createImmutableSnapshot(requestModel))) ?? original;\n\t\tif (JSON.stringify(result) !== JSON.stringify(original)) {\n\t\t\tthrow new TypeError(\"Model contract forbids payload replacement\");\n\t\t}\n\t\treturn structuredClone(original);\n\t};\n\tcontractHooks.add(hook);\n\treturn hook;\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createImmutableSnapshot } from "./plain-data.js";
|
|
2
|
+
import { ModelContractViolation } from "./run-model-contract.js";
|
|
3
|
+
const contractHooks = new WeakSet();
|
|
4
|
+
function assertCompletionPayload(payload, modelId, maxTokens) {
|
|
5
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload) || !("model" in payload)) {
|
|
6
|
+
throw new ModelContractViolation("invalid-request");
|
|
7
|
+
}
|
|
8
|
+
if (payload.model !== modelId)
|
|
9
|
+
throw new ModelContractViolation("model-not-allowed");
|
|
10
|
+
const legacyLimit = "max_tokens" in payload ? payload.max_tokens : undefined;
|
|
11
|
+
const completionLimit = "max_completion_tokens" in payload ? payload.max_completion_tokens : undefined;
|
|
12
|
+
if (legacyLimit !== undefined && completionLimit !== undefined) {
|
|
13
|
+
throw new ModelContractViolation("invalid-request-limit");
|
|
14
|
+
}
|
|
15
|
+
const limit = legacyLimit !== undefined ? legacyLimit : completionLimit;
|
|
16
|
+
if (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit <= 0) {
|
|
17
|
+
throw new ModelContractViolation("invalid-request-limit");
|
|
18
|
+
}
|
|
19
|
+
if (limit > maxTokens)
|
|
20
|
+
throw new ModelContractViolation("output-limit-exceeded");
|
|
21
|
+
}
|
|
22
|
+
/** Validate supported final payloads and preserve immutable user observation. */
|
|
23
|
+
export function createContractPayloadHook(model, maxTokens, observer) {
|
|
24
|
+
const { api, id } = model;
|
|
25
|
+
const hook = async (payload, requestModel) => {
|
|
26
|
+
if (api === "openai-completions")
|
|
27
|
+
assertCompletionPayload(payload, id, maxTokens);
|
|
28
|
+
if (!observer)
|
|
29
|
+
return;
|
|
30
|
+
// The core and SDK both enforce contracts. Only the innermost user hook needs a snapshot.
|
|
31
|
+
if (contractHooks.has(observer))
|
|
32
|
+
return observer(payload, requestModel);
|
|
33
|
+
const original = createImmutableSnapshot(payload);
|
|
34
|
+
const result = (await observer(original, createImmutableSnapshot(requestModel))) ?? original;
|
|
35
|
+
if (JSON.stringify(result) !== JSON.stringify(original)) {
|
|
36
|
+
throw new TypeError("Model contract forbids payload replacement");
|
|
37
|
+
}
|
|
38
|
+
return structuredClone(original);
|
|
39
|
+
};
|
|
40
|
+
contractHooks.add(hook);
|
|
41
|
+
return hook;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=provider-payload-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-payload-contract.js","sourceRoot":"","sources":["../src/provider-payload-contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,MAAM,aAAa,GAAG,IAAI,OAAO,EAAe,CAAC;AAEjD,SAAS,uBAAuB,CAAC,OAAgB,EAAE,OAAe,EAAE,SAAiB,EAAQ;IAC5F,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,EAAE,CAAC;QACxG,MAAM,IAAI,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,KAAK,OAAO;QAAE,MAAM,IAAI,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;IACrF,MAAM,WAAW,GAAG,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7E,MAAM,eAAe,GAAG,uBAAuB,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC;IACvG,IAAI,WAAW,KAAK,SAAS,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;QAChE,MAAM,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC;IACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,KAAK,GAAG,SAAS;QAAE,MAAM,IAAI,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;AAAA,CACjF;AAED,iFAAiF;AACjF,MAAM,UAAU,yBAAyB,CACxC,KAAqC,EACrC,SAAiB,EACjB,QAAsB,EACR;IACd,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAC1B,MAAM,IAAI,GAAgB,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC;QAC1D,IAAI,GAAG,KAAK,oBAAoB;YAAE,uBAAuB,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QAClF,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,0FAA0F;QAC1F,IAAI,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACxE,MAAM,QAAQ,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,QAAQ,EAAE,uBAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC;QAC7F,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,eAAe,CAAC,QAAQ,CAAC,CAAC;IAAA,CACjC,CAAC;IACF,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import type { Api, Model, SimpleStreamOptions } from \"omk-ai\";\nimport { createImmutableSnapshot } from \"./plain-data.ts\";\nimport { ModelContractViolation } from \"./run-model-contract.ts\";\n\ntype PayloadHook = NonNullable<SimpleStreamOptions[\"onPayload\"]>;\nconst contractHooks = new WeakSet<PayloadHook>();\n\nfunction assertCompletionPayload(payload: unknown, modelId: string, maxTokens: number): void {\n\tif (typeof payload !== \"object\" || payload === null || Array.isArray(payload) || !(\"model\" in payload)) {\n\t\tthrow new ModelContractViolation(\"invalid-request\");\n\t}\n\tif (payload.model !== modelId) throw new ModelContractViolation(\"model-not-allowed\");\n\tconst legacyLimit = \"max_tokens\" in payload ? payload.max_tokens : undefined;\n\tconst completionLimit = \"max_completion_tokens\" in payload ? payload.max_completion_tokens : undefined;\n\tif (legacyLimit !== undefined && completionLimit !== undefined) {\n\t\tthrow new ModelContractViolation(\"invalid-request-limit\");\n\t}\n\tconst limit = legacyLimit !== undefined ? legacyLimit : completionLimit;\n\tif (typeof limit !== \"number\" || !Number.isSafeInteger(limit) || limit <= 0) {\n\t\tthrow new ModelContractViolation(\"invalid-request-limit\");\n\t}\n\tif (limit > maxTokens) throw new ModelContractViolation(\"output-limit-exceeded\");\n}\n\n/** Validate supported final payloads and preserve immutable user observation. */\nexport function createContractPayloadHook(\n\tmodel: Pick<Model<Api>, \"api\" | \"id\">,\n\tmaxTokens: number,\n\tobserver?: PayloadHook,\n): PayloadHook {\n\tconst { api, id } = model;\n\tconst hook: PayloadHook = async (payload, requestModel) => {\n\t\tif (api === \"openai-completions\") assertCompletionPayload(payload, id, maxTokens);\n\t\tif (!observer) return;\n\t\t// The core and SDK both enforce contracts. Only the innermost user hook needs a snapshot.\n\t\tif (contractHooks.has(observer)) return observer(payload, requestModel);\n\t\tconst original = createImmutableSnapshot(payload);\n\t\tconst result = (await observer(original, createImmutableSnapshot(requestModel))) ?? original;\n\t\tif (JSON.stringify(result) !== JSON.stringify(original)) {\n\t\t\tthrow new TypeError(\"Model contract forbids payload replacement\");\n\t\t}\n\t\treturn structuredClone(original);\n\t};\n\tcontractHooks.add(hook);\n\treturn hook;\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SimpleStreamOptions } from "omk-ai";
|
|
2
|
+
type ContractThinkingLevel = "off" | NonNullable<SimpleStreamOptions["reasoning"]>;
|
|
3
|
+
export interface ModelIdentity {
|
|
4
|
+
readonly provider: string;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
}
|
|
7
|
+
/** Logical dispatch policy, not endpoint, credential, or serialized-payload attestation. */
|
|
8
|
+
export interface ModelContract {
|
|
9
|
+
readonly allowedModels: readonly ModelIdentity[];
|
|
10
|
+
readonly allowedProviders: readonly string[];
|
|
11
|
+
readonly allowedAuthOrigins: readonly string[];
|
|
12
|
+
readonly thinking: boolean;
|
|
13
|
+
readonly maxOutputTokens: number;
|
|
14
|
+
readonly thinkingLevel?: ContractThinkingLevel;
|
|
15
|
+
}
|
|
16
|
+
export interface RouteRequest {
|
|
17
|
+
readonly model: ModelIdentity;
|
|
18
|
+
readonly provider: string;
|
|
19
|
+
readonly thinking: boolean;
|
|
20
|
+
readonly maxOutputTokens?: number;
|
|
21
|
+
/** Logical credential resolver identity; omission means request.provider. */
|
|
22
|
+
readonly authOrigin?: string;
|
|
23
|
+
readonly thinkingLevel?: ContractThinkingLevel;
|
|
24
|
+
}
|
|
25
|
+
export type ModelContractViolationCode = "invalid-contract" | "invalid-contract-limit" | "invalid-request" | "invalid-request-limit" | "model-not-allowed" | "provider-not-allowed" | "provider-mismatch" | "auth-origin-not-allowed" | "thinking-not-allowed" | "thinking-level-mismatch" | "output-limit-exceeded";
|
|
26
|
+
export type ProviderRequestEvent = {
|
|
27
|
+
readonly type: "provider_denied";
|
|
28
|
+
readonly requestId: string;
|
|
29
|
+
readonly deniedReason: "contract-violation" | "aborted";
|
|
30
|
+
} | {
|
|
31
|
+
readonly type: "provider_request";
|
|
32
|
+
readonly requestId: string;
|
|
33
|
+
readonly provider: string;
|
|
34
|
+
readonly model: string;
|
|
35
|
+
readonly maxOutputTokens: number;
|
|
36
|
+
/** Tool attachments replaced by explicit text placeholders in this provider view. */
|
|
37
|
+
readonly omittedToolImages?: number;
|
|
38
|
+
readonly boundary: "stream-dispatch";
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "provider_request_end";
|
|
41
|
+
readonly requestId: string;
|
|
42
|
+
readonly outcome: "completed" | "error" | "aborted";
|
|
43
|
+
readonly boundary: "stream-dispatch";
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=provider-request-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request-types.d.ts","sourceRoot":"","sources":["../src/provider-request-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAElD,KAAK,qBAAqB,GAAG,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC;AACnF,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACpB;AAED,4FAA4F;AAC5F,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,aAAa,EAAE,SAAS,aAAa,EAAE,CAAC;IACjD,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,MAAM,MAAM,0BAA0B,GACnC,kBAAkB,GAClB,wBAAwB,GACxB,iBAAiB,GACjB,uBAAuB,GACvB,mBAAmB,GACnB,sBAAsB,GACtB,mBAAmB,GACnB,yBAAyB,GACzB,sBAAsB,GACtB,yBAAyB,GACzB,uBAAuB,CAAC;AAE3B,MAAM,MAAM,oBAAoB,GAC7B;IACA,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,oBAAoB,GAAG,SAAS,CAAC;CACvD,GACD;IACA,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,qFAAqF;IACrF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;CACpC,GACD;IACA,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;CACpC,CAAC","sourcesContent":["import type { SimpleStreamOptions } from \"omk-ai\";\n\ntype ContractThinkingLevel = \"off\" | NonNullable<SimpleStreamOptions[\"reasoning\"]>;\nexport interface ModelIdentity {\n\treadonly provider: string;\n\treadonly id: string;\n}\n\n/** Logical dispatch policy, not endpoint, credential, or serialized-payload attestation. */\nexport interface ModelContract {\n\treadonly allowedModels: readonly ModelIdentity[];\n\treadonly allowedProviders: readonly string[];\n\treadonly allowedAuthOrigins: readonly string[];\n\treadonly thinking: boolean;\n\treadonly maxOutputTokens: number;\n\treadonly thinkingLevel?: ContractThinkingLevel;\n}\n\nexport interface RouteRequest {\n\treadonly model: ModelIdentity;\n\treadonly provider: string;\n\treadonly thinking: boolean;\n\treadonly maxOutputTokens?: number;\n\t/** Logical credential resolver identity; omission means request.provider. */\n\treadonly authOrigin?: string;\n\treadonly thinkingLevel?: ContractThinkingLevel;\n}\n\nexport type ModelContractViolationCode =\n\t| \"invalid-contract\"\n\t| \"invalid-contract-limit\"\n\t| \"invalid-request\"\n\t| \"invalid-request-limit\"\n\t| \"model-not-allowed\"\n\t| \"provider-not-allowed\"\n\t| \"provider-mismatch\"\n\t| \"auth-origin-not-allowed\"\n\t| \"thinking-not-allowed\"\n\t| \"thinking-level-mismatch\"\n\t| \"output-limit-exceeded\";\n\nexport type ProviderRequestEvent =\n\t| {\n\t\t\treadonly type: \"provider_denied\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly deniedReason: \"contract-violation\" | \"aborted\";\n\t }\n\t| {\n\t\t\treadonly type: \"provider_request\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly provider: string;\n\t\t\treadonly model: string;\n\t\t\treadonly maxOutputTokens: number;\n\t\t\t/** Tool attachments replaced by explicit text placeholders in this provider view. */\n\t\t\treadonly omittedToolImages?: number;\n\t\t\treadonly boundary: \"stream-dispatch\";\n\t }\n\t| {\n\t\t\treadonly type: \"provider_request_end\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly outcome: \"completed\" | \"error\" | \"aborted\";\n\t\t\treadonly boundary: \"stream-dispatch\";\n\t };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request-types.js","sourceRoot":"","sources":["../src/provider-request-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SimpleStreamOptions } from \"omk-ai\";\n\ntype ContractThinkingLevel = \"off\" | NonNullable<SimpleStreamOptions[\"reasoning\"]>;\nexport interface ModelIdentity {\n\treadonly provider: string;\n\treadonly id: string;\n}\n\n/** Logical dispatch policy, not endpoint, credential, or serialized-payload attestation. */\nexport interface ModelContract {\n\treadonly allowedModels: readonly ModelIdentity[];\n\treadonly allowedProviders: readonly string[];\n\treadonly allowedAuthOrigins: readonly string[];\n\treadonly thinking: boolean;\n\treadonly maxOutputTokens: number;\n\treadonly thinkingLevel?: ContractThinkingLevel;\n}\n\nexport interface RouteRequest {\n\treadonly model: ModelIdentity;\n\treadonly provider: string;\n\treadonly thinking: boolean;\n\treadonly maxOutputTokens?: number;\n\t/** Logical credential resolver identity; omission means request.provider. */\n\treadonly authOrigin?: string;\n\treadonly thinkingLevel?: ContractThinkingLevel;\n}\n\nexport type ModelContractViolationCode =\n\t| \"invalid-contract\"\n\t| \"invalid-contract-limit\"\n\t| \"invalid-request\"\n\t| \"invalid-request-limit\"\n\t| \"model-not-allowed\"\n\t| \"provider-not-allowed\"\n\t| \"provider-mismatch\"\n\t| \"auth-origin-not-allowed\"\n\t| \"thinking-not-allowed\"\n\t| \"thinking-level-mismatch\"\n\t| \"output-limit-exceeded\";\n\nexport type ProviderRequestEvent =\n\t| {\n\t\t\treadonly type: \"provider_denied\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly deniedReason: \"contract-violation\" | \"aborted\";\n\t }\n\t| {\n\t\t\treadonly type: \"provider_request\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly provider: string;\n\t\t\treadonly model: string;\n\t\t\treadonly maxOutputTokens: number;\n\t\t\t/** Tool attachments replaced by explicit text placeholders in this provider view. */\n\t\t\treadonly omittedToolImages?: number;\n\t\t\treadonly boundary: \"stream-dispatch\";\n\t }\n\t| {\n\t\t\treadonly type: \"provider_request_end\";\n\t\t\treadonly requestId: string;\n\t\t\treadonly outcome: \"completed\" | \"error\" | \"aborted\";\n\t\t\treadonly boundary: \"stream-dispatch\";\n\t };\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Api, type AssistantMessage, type AssistantMessageEventStream, type Context, type Model, type SimpleStreamOptions } from "omk-ai";
|
|
2
|
+
import { type ModelContract } from "./run-model-contract.ts";
|
|
3
|
+
import type { AgentEvent, AgentLoopConfig, StreamFn } from "./types.ts";
|
|
4
|
+
export type { ProviderRequestEvent } from "./provider-request-types.ts";
|
|
5
|
+
/** Pin policy before any lifecycle subscriber can alter caller-owned configuration. */
|
|
6
|
+
export declare function pinProviderConfig(config: AgentLoopConfig, emit: (event: AgentEvent) => Promise<void> | void): Promise<AgentLoopConfig>;
|
|
7
|
+
/** Restrict logical dispatch and attach the supported final-payload checks. */
|
|
8
|
+
export declare function applyModelContract(contract: ModelContract, model: Model<Api>, options: SimpleStreamOptions): SimpleStreamOptions;
|
|
9
|
+
interface ProviderRuntime {
|
|
10
|
+
readonly signal?: AbortSignal;
|
|
11
|
+
readonly emit: (event: AgentEvent) => Promise<void> | void;
|
|
12
|
+
readonly streamFn?: StreamFn;
|
|
13
|
+
readonly consume: (stream: AssistantMessageEventStream) => Promise<AssistantMessage>;
|
|
14
|
+
}
|
|
15
|
+
/** Emit only bounded dispatch metadata; never payloads, headers, keys, or raw failures. */
|
|
16
|
+
export declare function requestAssistantResponse(context: Context, config: AgentLoopConfig, runtime: ProviderRuntime): Promise<AssistantMessage>;
|
|
17
|
+
//# sourceMappingURL=provider-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request.d.ts","sourceRoot":"","sources":["../src/provider-request.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EACR,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,mBAAmB,EAExB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAEN,KAAK,aAAa,EAGlB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGxE,YAAY,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE,uFAAuF;AACvF,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAC/C,OAAO,CAAC,eAAe,CAAC,CAU1B;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,mBAAmB,GAC1B,mBAAmB,CAerB;AAED,UAAU,eAAe;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,2BAA2B,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACrF;AAED,2FAA2F;AAC3F,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,eAAe,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAsE3B","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\ttype Model,\n\ttype SimpleStreamOptions,\n\tstreamSimple,\n} from \"omk-ai\";\nimport { projectToolImagesForModel } from \"./provider-input.ts\";\nimport { createContractPayloadHook } from \"./provider-payload-contract.ts\";\nimport {\n\tassertModelContract,\n\ttype ModelContract,\n\tModelContractViolation,\n\tsnapshotModelContract,\n} from \"./run-model-contract.ts\";\nimport type { AgentEvent, AgentLoopConfig, StreamFn } from \"./types.ts\";\nimport { getVisionRouteModel } from \"./vision-route.ts\";\n\nexport type { ProviderRequestEvent } from \"./provider-request-types.ts\";\n\n/** Pin policy before any lifecycle subscriber can alter caller-owned configuration. */\nexport async function pinProviderConfig(\n\tconfig: AgentLoopConfig,\n\temit: (event: AgentEvent) => Promise<void> | void,\n): Promise<AgentLoopConfig> {\n\tif (config.modelContract === undefined) return config;\n\ttry {\n\t\treturn { ...config, modelContract: snapshotModelContract(config.modelContract) };\n\t} catch (error) {\n\t\tif (error instanceof ModelContractViolation) {\n\t\t\tawait emit({ type: \"provider_denied\", requestId: crypto.randomUUID(), deniedReason: \"contract-violation\" });\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** Restrict logical dispatch and attach the supported final-payload checks. */\nexport function applyModelContract(\n\tcontract: ModelContract,\n\tmodel: Model<Api>,\n\toptions: SimpleStreamOptions,\n): SimpleStreamOptions {\n\tconst maxTokens = options.maxTokens ?? Math.min(model.maxTokens, contract.maxOutputTokens);\n\tassertModelContract(contract, {\n\t\tmodel,\n\t\tprovider: model.provider,\n\t\tauthOrigin: model.provider,\n\t\tthinking: options.reasoning !== undefined,\n\t\tthinkingLevel: options.reasoning ?? \"off\",\n\t\tmaxOutputTokens: maxTokens,\n\t});\n\treturn {\n\t\t...options,\n\t\tmaxTokens,\n\t\tonPayload: createContractPayloadHook(model, maxTokens, options.onPayload),\n\t};\n}\n\ninterface ProviderRuntime {\n\treadonly signal?: AbortSignal;\n\treadonly emit: (event: AgentEvent) => Promise<void> | void;\n\treadonly streamFn?: StreamFn;\n\treadonly consume: (stream: AssistantMessageEventStream) => Promise<AssistantMessage>;\n}\n\n/** Emit only bounded dispatch metadata; never payloads, headers, keys, or raw failures. */\nexport async function requestAssistantResponse(\n\tcontext: Context,\n\tconfig: AgentLoopConfig,\n\truntime: ProviderRuntime,\n): Promise<AssistantMessage> {\n\tconst { signal, emit, consume } = runtime;\n\tconst needsVisionRoute = context.messages.some(\n\t\t(message) =>\n\t\t\t(!config.modelContract || message.role !== \"toolResult\") &&\n\t\t\tArray.isArray(message.content) &&\n\t\t\tmessage.content.some((part) => part.type === \"image\"),\n\t);\n\tconst model =\n\t\tneedsVisionRoute && !(config.model.input ?? []).includes(\"image\")\n\t\t\t? getVisionRouteModel(config.model)\n\t\t\t: config.model;\n\tconst projection = config.modelContract\n\t\t? projectToolImagesForModel(context, model)\n\t\t: { context, omittedToolImages: 0 };\n\tconst changedProvider = model.provider !== config.model.provider;\n\tconst requestId = crypto.randomUUID();\n\tconst { modelContract, ...configured } = config;\n\tlet options: SimpleStreamOptions = configured;\n\ttry {\n\t\tif (signal?.aborted) {\n\t\t\tif (modelContract) await emit({ type: \"provider_denied\", requestId, deniedReason: \"aborted\" });\n\t\t\tsignal.throwIfAborted();\n\t\t}\n\t\tif (modelContract) options = applyModelContract(modelContract, model, configured);\n\t} catch (error) {\n\t\tif (error instanceof ModelContractViolation) {\n\t\t\tawait emit({ type: \"provider_denied\", requestId, deniedReason: \"contract-violation\" });\n\t\t}\n\t\tthrow error;\n\t}\n\tconst key = await config.getApiKey?.(model.provider);\n\tif (signal?.aborted) {\n\t\tif (modelContract) await emit({ type: \"provider_denied\", requestId, deniedReason: \"aborted\" });\n\t\tsignal.throwIfAborted();\n\t}\n\tconst requestOptions: SimpleStreamOptions = {\n\t\t...options,\n\t\tapiKey: key || (changedProvider ? undefined : options.apiKey),\n\t\theaders: changedProvider ? undefined : options.headers,\n\t\tsignal,\n\t};\n\tlet outcome: \"completed\" | \"error\" | \"aborted\" = \"error\";\n\ttry {\n\t\tif (modelContract) {\n\t\t\tawait emit({\n\t\t\t\ttype: \"provider_request\",\n\t\t\t\trequestId,\n\t\t\t\tprovider: model.provider,\n\t\t\t\tmodel: model.id,\n\t\t\t\tmaxOutputTokens: requestOptions.maxTokens ?? modelContract.maxOutputTokens,\n\t\t\t\t...(projection.omittedToolImages > 0 ? { omittedToolImages: projection.omittedToolImages } : {}),\n\t\t\t\tboundary: \"stream-dispatch\",\n\t\t\t});\n\t\t}\n\t\tsignal?.throwIfAborted();\n\t\tconst response = await (runtime.streamFn ?? streamSimple)(model, projection.context, requestOptions);\n\t\tconst message = await consume(response);\n\t\toutcome = message.stopReason === \"aborted\" ? \"aborted\" : message.stopReason === \"error\" ? \"error\" : \"completed\";\n\t\treturn message;\n\t} finally {\n\t\tif (modelContract) {\n\t\t\tawait emit({\n\t\t\t\ttype: \"provider_request_end\",\n\t\t\t\trequestId,\n\t\t\t\toutcome: signal?.aborted ? \"aborted\" : outcome,\n\t\t\t\tboundary: \"stream-dispatch\",\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
|