stitchkit 0.70.6 → 0.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/agent-runtime/coding-tool-contract.d.ts +11 -1
  2. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
  3. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
  4. package/dist/agent-runtime/coding-tool-listing.d.ts +15 -0
  5. package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -0
  6. package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -1
  7. package/dist/agent-runtime/coding-tool-refusals.d.ts +59 -0
  8. package/dist/agent-runtime/coding-tool-refusals.d.ts.map +1 -0
  9. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
  10. package/dist/agent-runtime/coding-tools.d.ts +3 -1
  11. package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
  12. package/dist/agent-runtime/compaction.d.ts +35 -0
  13. package/dist/agent-runtime/compaction.d.ts.map +1 -1
  14. package/dist/agent-runtime/contained-files.d.ts +21 -2
  15. package/dist/agent-runtime/contained-files.d.ts.map +1 -1
  16. package/dist/agent-runtime/provider-failure.d.ts +66 -0
  17. package/dist/agent-runtime/provider-failure.d.ts.map +1 -0
  18. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  19. package/dist/agent-runtime/runtime.d.ts +31 -1
  20. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  21. package/dist/agent-runtime/schemas.d.ts +1 -0
  22. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  23. package/dist/agent-runtime-coding-tools.js +438 -124
  24. package/dist/agent-runtime-harness.js +4 -4
  25. package/dist/agent-runtime-openrouter.d.ts +19 -0
  26. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  27. package/dist/agent-runtime-openrouter.js +2 -1
  28. package/dist/agent-runtime.d.ts +3 -2
  29. package/dist/agent-runtime.d.ts.map +1 -1
  30. package/dist/agent-runtime.js +118 -14
  31. package/dist/cli.js +5 -5
  32. package/dist/{index-cx84zg25.js → index-118v0z41.js} +1 -1
  33. package/dist/{index-ejv31h14.js → index-7qy2ex0m.js} +1 -1
  34. package/dist/{index-trrf7nch.js → index-ezmn6ac6.js} +3 -3
  35. package/dist/{index-ekkt4gy9.js → index-jqtsc9mj.js} +2 -2
  36. package/dist/{index-hxtm2xr2.js → index-k2zczx1g.js} +1 -1
  37. package/dist/{index-by57nwhc.js → index-m668wzyc.js} +10 -2
  38. package/dist/{index-w9m1wznn.js → index-nemjkxjp.js} +118 -1
  39. package/dist/{index-tnazr5tc.js → index-pz7ytdga.js} +3 -3
  40. package/dist/{index-1z5xxfst.js → index-rqpdar1e.js} +102 -5
  41. package/dist/{index-qm87g51s.js → index-s4c8wy8m.js} +1 -1
  42. package/dist/node.js +2 -2
  43. package/dist/observability/index.js +1 -1
  44. package/dist/server/index.d.ts +1 -1
  45. package/dist/server/index.d.ts.map +1 -1
  46. package/dist/server/index.js +4 -2
  47. package/dist/server/request.d.ts +19 -0
  48. package/dist/server/request.d.ts.map +1 -1
  49. package/dist/telegram/init-data.d.ts +134 -0
  50. package/dist/telegram/init-data.d.ts.map +1 -0
  51. package/dist/telegram/send-failure.d.ts +73 -0
  52. package/dist/telegram/send-failure.d.ts.map +1 -0
  53. package/dist/telegram.d.ts +3 -0
  54. package/dist/telegram.d.ts.map +1 -0
  55. package/dist/telegram.js +224 -0
  56. package/dist/tool-invoker.js +4 -4
  57. package/dist/tools.js +7 -7
  58. package/llms-full.txt +266 -9
  59. package/native/darwin-arm64.node +0 -0
  60. package/native/darwin-x64.node +0 -0
  61. package/package.json +6 -2
@@ -3,10 +3,10 @@ import {
3
3
  composeAgentPrompt,
4
4
  createAgentRuntime,
5
5
  createAgentRuntimeEventSink
6
- } from "./index-by57nwhc.js";
6
+ } from "./index-m668wzyc.js";
7
7
  import {
8
8
  walkContainedFiles
9
- } from "./index-1z5xxfst.js";
9
+ } from "./index-rqpdar1e.js";
10
10
  import {
11
11
  AgentModelDescriptorSchema
12
12
  } from "./index-tg3m2ec5.js";
@@ -16,8 +16,8 @@ import"./index-3xnq72rz.js";
16
16
  import {
17
17
  defineRuntimeTool
18
18
  } from "./index-wwst0td5.js";
19
- import"./index-qm87g51s.js";
20
- import"./index-w9m1wznn.js";
19
+ import"./index-s4c8wy8m.js";
20
+ import"./index-nemjkxjp.js";
21
21
  import {
22
22
  AgentMessagePartSchema,
23
23
  AgentSnapshotSchema
@@ -1,5 +1,7 @@
1
1
  import { type OpenRouterProviderSettings } from '@openrouter/ai-sdk-provider';
2
+ import type { LanguageModelUsage } from 'ai';
2
3
  import { type AgentLanguageModelProvider, type AgentModelCatalog } from './agent-runtime/models.js';
4
+ import type { AgentUsage } from './agent-runtime/schemas.js';
3
5
  export type { OpenRouterProviderSettings } from '@openrouter/ai-sdk-provider';
4
6
  export type OpenRouterCatalogFetch = (input: URL, init?: RequestInit) => Promise<Response>;
5
7
  export interface OpenRouterModelCatalogOptions {
@@ -16,4 +18,21 @@ export declare function openRouterModelCatalog(options: OpenRouterModelCatalogOp
16
18
  };
17
19
  /** Isolated OpenRouter adapter; credentials stay inside the provider instance. */
18
20
  export declare function openRouterProvider(settings: OpenRouterProviderSettings): AgentLanguageModelProvider;
21
+ /**
22
+ * Read OpenRouter's token counts and cost out of one SDK step, with provenance.
23
+ *
24
+ * Exported, and that is the point of it existing here at all. The same function
25
+ * has always run inside `openRouterProvider`, which means it was reachable only
26
+ * by building the whole agent runtime — durable store, execution protocol and
27
+ * recovery included. An application that calls `generateText` directly, and only
28
+ * wants an honest number for its own ledger, could not reach it and derived it
29
+ * again; two of them did, and more than half of the two files agree line for
30
+ * line.
31
+ *
32
+ * What is easy to get wrong when deriving it again is not the arithmetic but the
33
+ * provenance: a number the provider reported, a number nobody reported and a
34
+ * zero are three different facts, and a value invented for a missing field is
35
+ * the one that reads as true and is not.
36
+ */
37
+ export declare function normalizeOpenRouterUsage(usage: LanguageModelUsage, providerMetadata: unknown): AgentUsage;
19
38
  //# sourceMappingURL=agent-runtime-openrouter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-runtime-openrouter.d.ts","sourceRoot":"","sources":["../src/agent-runtime-openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,KAAK,0BAA0B,EAE/B,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAIhC,YAAY,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAkD9E,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE3F,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAyFD,+FAA+F;AAC/F,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,6BAA6B,GAAG;IAC9E,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE,CAyGA;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,0BAA0B,GACnC,0BAA0B,CAO5B"}
1
+ {"version":3,"file":"agent-runtime-openrouter.d.ts","sourceRoot":"","sources":["../src/agent-runtime-openrouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAE7C,OAAO,EACL,KAAK,0BAA0B,EAE/B,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,YAAY,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAkD9E,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE3F,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAyFD,+FAA+F;AAC/F,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,6BAA6B,GAAG;IAC9E,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE,CAyGA;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,0BAA0B,GACnC,0BAA0B,CAO5B;AA0BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,kBAAkB,EACzB,gBAAgB,EAAE,OAAO,GACxB,UAAU,CASZ"}
@@ -252,5 +252,6 @@ function normalizeOpenRouterUsage(usage, providerMetadata) {
252
252
  }
253
253
  export {
254
254
  openRouterProvider,
255
- openRouterModelCatalog
255
+ openRouterModelCatalog,
256
+ normalizeOpenRouterUsage
256
257
  };
@@ -1,4 +1,4 @@
1
- export { type AgentCompactionContext, type AgentCompactionResult, type StructuredCompactionConfig, structuredCompaction, } from './agent-runtime/compaction.js';
1
+ export { type AgentCompactionContext, type AgentCompactionResult, type CompactableHistory, type SelectCompactableHistoryOptions, type StructuredCompactionConfig, selectCompactableHistory, structuredCompaction, } from './agent-runtime/compaction.js';
2
2
  export { AgentContextOverflowError } from './agent-runtime/context-refusal.js';
3
3
  export { type AgentConversationMessagePage, AgentConversationMessagePageSchema, type AgentConversationPage, AgentConversationPageSchema, type AgentConversationReader, type AgentConversationSummary, AgentConversationSummarySchema, } from './agent-runtime/conversations.js';
4
4
  export { type AgentCoordinatedRun, type AgentInputPolicy, type AgentRunTicket, type AgentSessionCloseOptions, type AgentSessionCloseResult, type AgentSessionCoordinator, type AgentStopReason, createAgentSessionCoordinator, } from './agent-runtime/coordinator.js';
@@ -10,8 +10,9 @@ export { type AgentLanguageModelProvider, type AgentModelCapability, AgentModelC
10
10
  export { type AgentObservability, type AgentRunEvent, AgentRunEventSchema, type AgentRunSinkConfig, type AgentRunSinkDrop, type AgentRunSinkError, type AgentRunStartedEvent, AgentRunStartedEventSchema, type AgentRunTerminalEvent, AgentRunTerminalEventSchema, type AgentStepFinishedEvent, AgentStepFinishedEventSchema, createAgentObservability, } from './agent-runtime/observability.js';
11
11
  export { type AgentHistoryBudgetDecision, type AgentHistoryBudgetResult, type AgentPromptBudget, type AgentPromptSection, type AgentPromptSectionContext, type AgentTokenCount, AgentTokenCountSchema, type ComposeAgentPromptOptions, type ComposedAgentPrompt, composeAgentPrompt, type SelectAgentHistoryOptions, selectAgentHistory, } from './agent-runtime/prompt.js';
12
12
  export { type AgentProtocol, type AgentProtocolConfig, type AgentTerminalAcceptance, type AgentTerminalAcceptanceInput, defineAgentProtocol, hasAgentTerminalOutput, } from './agent-runtime/protocol.js';
13
+ export { type AgentProviderFailure, type AgentProviderFailureReason, classifyProviderFailure, isToolResultFailure, } from './agent-runtime/provider-failure.js';
13
14
  export { AgentConversationPurgedError, type AgentConversationPurgeInput, AgentConversationPurgeInputSchema, type AgentConversationPurgeResult, AgentConversationPurgeResultSchema, purgeAgentConversation, } from './agent-runtime/purge.js';
14
- export { type AgentRuntime, type AgentRuntimeAdmission, type AgentRuntimeConfig, type AgentRuntimeInput, type AgentRuntimeInterruptInput, type AgentRuntimePrepareStep, type AgentRuntimeProtocolInput, type AgentRuntimeRecordIds, type AgentRuntimeRecoverOptions, type AgentRuntimeRecoveryDecision, type AgentRuntimeRecoveryInput, type AgentRuntimeRecoveryOutcome, type AgentRuntimeRunContext, type AgentRuntimeStopPolicy, createAgentRuntime, } from './agent-runtime/runtime.js';
15
+ export { type AgentContextUsage, type AgentRuntime, type AgentRuntimeAdmission, type AgentRuntimeConfig, type AgentRuntimeInput, type AgentRuntimeInterruptInput, type AgentRuntimePrepareStep, type AgentRuntimeProtocolInput, type AgentRuntimeRecordIds, type AgentRuntimeRecoverOptions, type AgentRuntimeRecoveryDecision, type AgentRuntimeRecoveryInput, type AgentRuntimeRecoveryOutcome, type AgentRuntimeRunContext, type AgentRuntimeStopPolicy, createAgentRuntime, } from './agent-runtime/runtime.js';
15
16
  export type { AgentRuntimeResult } from './agent-runtime/runtime-result.js';
16
17
  export * from './agent-runtime/schemas.js';
17
18
  export { type AcceptInputAndAssignRun, AcceptInputAndAssignRunSchema, type AcquireAgentRun, AcquireAgentRunSchema, type AgentRecoverableDescriptor, AgentRecoverableDescriptorSchema, type AgentRecoverablePage, AgentRecoverablePageSchema, type AgentRuntimeStore, type AgentRunView, AgentRunViewSchema, AgentStoreAppliedSchema, AgentStoreConflictSchema, AgentStoreDuplicateSchema, type AgentStoreMutationResult, AgentStoreMutationResultSchema, AgentStoreNotFoundSchema, type CheckpointRunAssistant, CheckpointRunAssistantSchema, type CommitRunTerminal, CommitRunTerminalSchema, type RecoverAgentRun, RecoverAgentRunSchema, type ReplaceCompactedRange, ReplaceCompactedRangeSchema, type RequestRunInterrupt, RequestRunInterruptSchema, } from './agent-runtime/store.js';
@@ -1 +1 @@
1
- {"version":3,"file":"agent-runtime.d.ts","sourceRoot":"","sources":["../src/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAA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AiC,CAAC;AAC5E,OAAO,EACL,KAAK,0BAA0B,EAC/B,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC"}
@@ -27,7 +27,7 @@ import {
27
27
  registerDeferredToolRepair,
28
28
  repairedSearchCall,
29
29
  selectAgentHistory
30
- } from "./index-by57nwhc.js";
30
+ } from "./index-m668wzyc.js";
31
31
  import {
32
32
  AgentModelCapabilitySchema,
33
33
  AgentModelCatalogEntrySchema,
@@ -86,15 +86,15 @@ import {
86
86
  import {
87
87
  buildToolManifest,
88
88
  mountAgent
89
- } from "./index-trrf7nch.js";
89
+ } from "./index-ezmn6ac6.js";
90
90
  import"./index-3xnq72rz.js";
91
- import"./index-hxtm2xr2.js";
91
+ import"./index-k2zczx1g.js";
92
92
  import {
93
93
  defineRuntimeTool
94
94
  } from "./index-wwst0td5.js";
95
- import"./index-ejv31h14.js";
96
- import"./index-qm87g51s.js";
97
- import"./index-w9m1wznn.js";
95
+ import"./index-7qy2ex0m.js";
96
+ import"./index-s4c8wy8m.js";
97
+ import"./index-nemjkxjp.js";
98
98
  import {
99
99
  AgentAssistantPlaceholderSchema,
100
100
  AgentControlPartSchema,
@@ -137,7 +137,8 @@ import {
137
137
  import"./index-vj3vvpaa.js";
138
138
  import"./index-0w9abg87.js";
139
139
  import {
140
- executableAgentRuntimeTools
140
+ executableAgentRuntimeTools,
141
+ isRecord
141
142
  } from "./index-qyrqwr4c.js";
142
143
  import"./index-6k1937bx.js";
143
144
 
@@ -163,13 +164,22 @@ function groupProviderTurns(messages, evidencePolicy) {
163
164
  }
164
165
  return turns;
165
166
  }
166
- function eligibleForCompaction(messages, keepRecentTurns, evidencePolicy) {
167
- const withoutLeadingSummary = messages[0]?.role === "summary" ? messages.slice(1) : messages;
168
- const turns = groupProviderTurns(withoutLeadingSummary, evidencePolicy);
167
+ function selectCompactableHistory(options) {
168
+ if (!Number.isSafeInteger(options.keepRecentTurns) || options.keepRecentTurns < 0) {
169
+ throw new TypeError("keepRecentTurns must be a non-negative safe integer");
170
+ }
171
+ const leadingSummary = options.messages[0]?.role === "summary" ? options.messages[0] : undefined;
172
+ const rest = leadingSummary ? options.messages.slice(1) : options.messages;
173
+ const turns = groupProviderTurns(rest, options.evidencePolicy);
169
174
  const firstIncomplete = turns.findIndex((turn) => !turn.complete);
170
175
  const completeTurns = firstIncomplete === -1 ? turns : turns.slice(0, firstIncomplete);
171
- const eligibleCount = Math.max(0, completeTurns.length - keepRecentTurns);
172
- return completeTurns.slice(0, eligibleCount).flatMap((turn) => turn.messages);
176
+ const eligibleCount = Math.max(0, completeTurns.length - options.keepRecentTurns);
177
+ const compactable = completeTurns.slice(0, eligibleCount).flatMap((turn) => turn.messages);
178
+ return {
179
+ ...leadingSummary !== undefined && { leadingSummary },
180
+ compactable,
181
+ retained: rest.slice(compactable.length)
182
+ };
173
183
  }
174
184
  function mutationSnapshot(result, fallback, attempts) {
175
185
  if (result.outcome === "applied" || result.outcome === "duplicate") {
@@ -193,11 +203,14 @@ function structuredCompaction(config) {
193
203
  if (!await config.threshold(snapshot)) {
194
204
  return { outcome: "not_needed", snapshot, attempts: attempt };
195
205
  }
196
- const eligibleMessages = eligibleForCompaction(snapshot.messages, config.keepRecentTurns, config.evidencePolicy);
206
+ const { leadingSummary, compactable: eligibleMessages } = selectCompactableHistory({
207
+ messages: snapshot.messages,
208
+ keepRecentTurns: config.keepRecentTurns,
209
+ ...config.evidencePolicy !== undefined && { evidencePolicy: config.evidencePolicy }
210
+ });
197
211
  if (eligibleMessages.length === 0) {
198
212
  return { outcome: "nothing_eligible", snapshot, attempts: attempt };
199
213
  }
200
- const leadingSummary = snapshot.messages[0]?.role === "summary" ? snapshot.messages[0] : undefined;
201
214
  const previousSummary = leadingSummary && config.readPreviousSummary ? config.schema.parse(config.readPreviousSummary(leadingSummary)) : attempt === 1 ? input.previousSummary : undefined;
202
215
  const rawSummary = await config.summarize({
203
216
  conversationId: input.conversationId,
@@ -698,15 +711,105 @@ function defineAgentProtocol(config) {
698
711
  }
699
712
  };
700
713
  }
714
+ // src/agent-runtime/provider-failure.ts
715
+ var BY_STATUS = {
716
+ 402: "insufficient-credits",
717
+ 404: "model-unavailable",
718
+ 408: "timeout",
719
+ 413: "context-overflow",
720
+ 429: "rate-limited"
721
+ };
722
+ var BY_MESSAGE = [
723
+ [/insufficient|not enough credit|payment required|quota exceeded/i, "insufficient-credits"],
724
+ [/rate.?limit|too many requests|slow down/i, "rate-limited"],
725
+ [
726
+ /no endpoints found|model not found|unknown model|no allowed providers/i,
727
+ "model-unavailable"
728
+ ],
729
+ [/context length|maximum context|too many tokens|prompt is too long/i, "context-overflow"],
730
+ [/timed? ?out|deadline exceeded|etimedout/i, "timeout"],
731
+ [/abort|cancell?ed/i, "cancelled"]
732
+ ];
733
+ var RETRYABLE = new Set([
734
+ "rate-limited",
735
+ "timeout",
736
+ "insufficient-credits"
737
+ ]);
738
+ function statusOf(value) {
739
+ if (!isRecord(value))
740
+ return;
741
+ for (const key of ["statusCode", "status", "code"]) {
742
+ const candidate = value[key];
743
+ if (typeof candidate === "number" && candidate >= 400 && candidate < 600)
744
+ return candidate;
745
+ }
746
+ const nested = value.cause ?? value.response ?? value.error;
747
+ return nested === value ? undefined : statusOf(nested);
748
+ }
749
+ function messageOf(value) {
750
+ if (value instanceof Error)
751
+ return value.message;
752
+ if (typeof value === "string")
753
+ return value;
754
+ if (isRecord(value) && typeof value.message === "string")
755
+ return value.message;
756
+ return "";
757
+ }
758
+ function classifyProviderFailure(error) {
759
+ const status = statusOf(error);
760
+ const byStatus = status === undefined ? undefined : BY_STATUS[status];
761
+ if (byStatus) {
762
+ return {
763
+ reason: byStatus,
764
+ status,
765
+ retryable: RETRYABLE.has(byStatus),
766
+ evidence: "status"
767
+ };
768
+ }
769
+ const message = messageOf(error);
770
+ for (const [pattern, reason] of BY_MESSAGE) {
771
+ if (pattern.test(message)) {
772
+ return {
773
+ reason,
774
+ ...status !== undefined && { status },
775
+ retryable: RETRYABLE.has(reason),
776
+ evidence: "message"
777
+ };
778
+ }
779
+ }
780
+ return {
781
+ reason: "unknown",
782
+ ...status !== undefined && { status },
783
+ retryable: false,
784
+ evidence: "none"
785
+ };
786
+ }
787
+ function isToolResultFailure(output) {
788
+ const parsed = typeof output === "string" ? parseJson(output) : output;
789
+ if (!isRecord(parsed))
790
+ return false;
791
+ if ("error" in parsed)
792
+ return true;
793
+ return isRecord(parsed.value) && "error" in parsed.value;
794
+ }
795
+ function parseJson(value) {
796
+ try {
797
+ return JSON.parse(value);
798
+ } catch {
799
+ return;
800
+ }
801
+ }
701
802
  export {
702
803
  validateAgentModelSnapshot,
703
804
  structuredCompaction,
805
+ selectCompactableHistory,
704
806
  selectAgentHistory,
705
807
  searchAgentModelCatalog,
706
808
  runStateForTerminalReason,
707
809
  purgeAgentConversation,
708
810
  projectAgentHistoryDetailed,
709
811
  projectAgentHistory,
812
+ isToolResultFailure,
710
813
  isAssistantHistoryEvidence,
711
814
  hasAgentTerminalOutput,
712
815
  defineModelRegistry,
@@ -721,6 +824,7 @@ export {
721
824
  createAgentRuntime,
722
825
  createAgentObservability,
723
826
  composeAgentPrompt,
827
+ classifyProviderFailure,
724
828
  agentDurableEventId,
725
829
  advanceAgentRuntimeEventCursor,
726
830
  RequestRunInterruptSchema,
package/dist/cli.js CHANGED
@@ -5,12 +5,12 @@ import {
5
5
  emitResult,
6
6
  parseCliArgs,
7
7
  pollUntilDone
8
- } from "./index-tnazr5tc.js";
9
- import"./index-hxtm2xr2.js";
8
+ } from "./index-pz7ytdga.js";
9
+ import"./index-k2zczx1g.js";
10
10
  import"./index-wwst0td5.js";
11
- import"./index-ejv31h14.js";
12
- import"./index-qm87g51s.js";
13
- import"./index-w9m1wznn.js";
11
+ import"./index-7qy2ex0m.js";
12
+ import"./index-s4c8wy8m.js";
13
+ import"./index-nemjkxjp.js";
14
14
  import"./index-sbdmyz75.js";
15
15
  import"./index-22by16v6.js";
16
16
  import"./index-cby4ar3v.js";
@@ -18,7 +18,7 @@ import {
18
18
  runWithRequestContext,
19
19
  setRequestEndpoint,
20
20
  setRequestError
21
- } from "./index-w9m1wznn.js";
21
+ } from "./index-nemjkxjp.js";
22
22
  import {
23
23
  ShutdownOptionsSchema,
24
24
  isStreamCancellation,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  executeToolMethod
3
- } from "./index-qm87g51s.js";
3
+ } from "./index-s4c8wy8m.js";
4
4
  import {
5
5
  assertToolExtensionCompatible,
6
6
  mergeSchemas,
@@ -3,15 +3,15 @@ import {
3
3
  } from "./index-3xnq72rz.js";
4
4
  import {
5
5
  collectToolSurface
6
- } from "./index-hxtm2xr2.js";
6
+ } from "./index-k2zczx1g.js";
7
7
  import {
8
8
  createToolRunner,
9
9
  formatToolError
10
- } from "./index-ejv31h14.js";
10
+ } from "./index-7qy2ex0m.js";
11
11
  import {
12
12
  isToolExecutionControlError,
13
13
  toolResultFromError
14
- } from "./index-qm87g51s.js";
14
+ } from "./index-s4c8wy8m.js";
15
15
  import {
16
16
  isRecord
17
17
  } from "./index-qyrqwr4c.js";
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  collectTools,
3
3
  createToolRunner
4
- } from "./index-ejv31h14.js";
4
+ } from "./index-7qy2ex0m.js";
5
5
  import {
6
6
  toolErrorFromResult
7
- } from "./index-qm87g51s.js";
7
+ } from "./index-s4c8wy8m.js";
8
8
  import {
9
9
  assertUniqueToolName
10
10
  } from "./index-22by16v6.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-wwst0td5.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-ejv31h14.js";
6
+ } from "./index-7qy2ex0m.js";
7
7
  import {
8
8
  projectToolSurface
9
9
  } from "./index-22by16v6.js";
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  ToolExecutionControlError,
17
17
  isToolExecutionControlError
18
- } from "./index-qm87g51s.js";
18
+ } from "./index-s4c8wy8m.js";
19
19
  import {
20
20
  AgentAssistantPlaceholderSchema,
21
21
  AgentJsonObjectSchema,
@@ -1418,11 +1418,18 @@ function createRunExecutor(dependencies) {
1418
1418
  ...run.fencingToken !== undefined && { fencingToken: run.fencingToken }
1419
1419
  })
1420
1420
  });
1421
+ let lastPromptTokens = { provenance: "unavailable" };
1421
1422
  const runtimeContext = {
1422
1423
  context: input.context,
1423
1424
  run,
1424
1425
  signal: executionSignal,
1425
- toolFenceLifecycle
1426
+ toolFenceLifecycle,
1427
+ get contextUsage() {
1428
+ const descriptor = selectedModel?.descriptor;
1429
+ if (!descriptor)
1430
+ return;
1431
+ return { usedTokens: lastPromptTokens, contextWindow: descriptor.contextWindow };
1432
+ }
1426
1433
  };
1427
1434
  selectedModel = await config.models.resolve({
1428
1435
  context: input.context,
@@ -1783,6 +1790,7 @@ function createRunExecutor(dependencies) {
1783
1790
  usage: part.usage,
1784
1791
  providerMetadata: part.providerMetadata
1785
1792
  }) ?? normalizeSdkUsage(part.usage);
1793
+ lastPromptTokens = stepUsage.inputTokens;
1786
1794
  modelUsage = addUsage(modelUsage, stepUsage);
1787
1795
  usage = nonModelUsage ? addUsage(nonModelUsage, modelUsage) : modelUsage;
1788
1796
  config.observe?.emit({
@@ -59,6 +59,123 @@ function parseQueryParams(url) {
59
59
  }
60
60
  return query;
61
61
  }
62
+ var IPV4_RESERVED = [
63
+ ["0.0.0.0", 8],
64
+ ["10.0.0.0", 8],
65
+ ["100.64.0.0", 10],
66
+ ["127.0.0.0", 8],
67
+ ["169.254.0.0", 16],
68
+ ["172.16.0.0", 12],
69
+ ["192.0.0.0", 24],
70
+ ["192.0.2.0", 24],
71
+ ["192.88.99.0", 24],
72
+ ["192.168.0.0", 16],
73
+ ["198.18.0.0", 15],
74
+ ["198.51.100.0", 24],
75
+ ["203.0.113.0", 24],
76
+ ["224.0.0.0", 4],
77
+ ["240.0.0.0", 4]
78
+ ];
79
+ function parseIpv4(value) {
80
+ const parts = value.split(".");
81
+ if (parts.length !== 4)
82
+ return;
83
+ let result = 0;
84
+ for (const part of parts) {
85
+ if (!/^(0|[1-9]\d{0,2})$/.test(part))
86
+ return;
87
+ const octet = Number(part);
88
+ if (octet > 255)
89
+ return;
90
+ result = result * 256 + octet;
91
+ }
92
+ return result;
93
+ }
94
+ function parseIpv6(value) {
95
+ const address = value.split("%")[0] ?? "";
96
+ if (!address.includes(":"))
97
+ return;
98
+ const halves = address.split("::");
99
+ if (halves.length > 2)
100
+ return;
101
+ const groups = [];
102
+ const tail = [];
103
+ const push = (into, text) => {
104
+ if (text === "")
105
+ return true;
106
+ for (const piece of text.split(":")) {
107
+ if (piece.includes(".")) {
108
+ const v4 = parseIpv4(piece);
109
+ if (v4 === undefined)
110
+ return false;
111
+ into.push(v4 >>> 16 & 65535, v4 & 65535);
112
+ continue;
113
+ }
114
+ if (!/^[0-9a-fA-F]{1,4}$/.test(piece))
115
+ return false;
116
+ into.push(Number.parseInt(piece, 16));
117
+ }
118
+ return true;
119
+ };
120
+ if (!push(groups, halves[0] ?? ""))
121
+ return;
122
+ if (halves.length === 2 && !push(tail, halves[1] ?? ""))
123
+ return;
124
+ const missing = 8 - groups.length - tail.length;
125
+ if (halves.length === 2 ? missing < 0 : missing !== 0)
126
+ return;
127
+ const words = [
128
+ ...groups,
129
+ ...Array(halves.length === 2 ? missing : 0).fill(0),
130
+ ...tail
131
+ ];
132
+ if (words.length !== 8)
133
+ return;
134
+ const bytes = new Uint8Array(16);
135
+ words.forEach((word, index) => {
136
+ bytes[index * 2] = word >>> 8 & 255;
137
+ bytes[index * 2 + 1] = word & 255;
138
+ });
139
+ return bytes;
140
+ }
141
+ function hasPrefix(bytes, prefix, bits) {
142
+ for (let index = 0;index < bits; index += 1) {
143
+ const byte = bytes[index >> 3] ?? 0;
144
+ const against = prefix[index >> 3] ?? 0;
145
+ const mask = 128 >> index % 8;
146
+ if ((byte & mask) !== (against & mask))
147
+ return false;
148
+ }
149
+ return true;
150
+ }
151
+ function isPublicIp(value) {
152
+ const address = value.trim();
153
+ if (!address)
154
+ return false;
155
+ const v4 = parseIpv4(address);
156
+ if (v4 !== undefined) {
157
+ return !IPV4_RESERVED.some(([network, bits]) => {
158
+ const base = parseIpv4(network);
159
+ if (base === undefined)
160
+ return false;
161
+ const mask = bits === 0 ? 0 : 4294967295 << 32 - bits >>> 0;
162
+ return (v4 & mask) >>> 0 === (base & mask) >>> 0;
163
+ });
164
+ }
165
+ const bytes = parseIpv6(address);
166
+ if (!bytes)
167
+ return false;
168
+ if (hasPrefix(bytes, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255], 96)) {
169
+ return isPublicIp(Array.from(bytes.slice(12)).join("."));
170
+ }
171
+ if (!hasPrefix(bytes, [32], 3))
172
+ return false;
173
+ if (hasPrefix(bytes, [32, 1, 0, 0], 23))
174
+ return false;
175
+ if (hasPrefix(bytes, [32, 1, 13, 184], 32))
176
+ return false;
177
+ return true;
178
+ }
62
179
 
63
180
  // src/observability/context.ts
64
181
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -114,4 +231,4 @@ function wrapInRequestContext(handler, options = {}) {
114
231
  };
115
232
  }
116
233
 
117
- export { generateTraceId, resolveTraceId, resolveSocketIp, extractIp, getClientInfo, parseQueryParams, runWithRequestContext, getRequestContext, getTraceId, getUserId, setRequestUser, setRequestEndpoint, setRequestDimensions, setRequestError, wrapInRequestContext };
234
+ export { generateTraceId, resolveTraceId, resolveSocketIp, extractIp, getClientInfo, parseQueryParams, isPublicIp, runWithRequestContext, getRequestContext, getTraceId, getUserId, setRequestUser, setRequestEndpoint, setRequestDimensions, setRequestError, wrapInRequestContext };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  collectToolSurface
3
- } from "./index-hxtm2xr2.js";
3
+ } from "./index-k2zczx1g.js";
4
4
  import {
5
5
  createToolRunner,
6
6
  formatToolError
7
- } from "./index-ejv31h14.js";
7
+ } from "./index-7qy2ex0m.js";
8
8
  import {
9
9
  coerceJsonArgs,
10
10
  toolResultFromError
11
- } from "./index-qm87g51s.js";
11
+ } from "./index-s4c8wy8m.js";
12
12
  import {
13
13
  isWithinDir
14
14
  } from "./index-sbdmyz75.js";