stitchkit 0.70.5 → 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 (76) 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/purge.d.ts +28 -0
  19. package/dist/agent-runtime/purge.d.ts.map +1 -0
  20. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  21. package/dist/agent-runtime/runtime.d.ts +31 -1
  22. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  23. package/dist/agent-runtime/schemas.d.ts +1 -0
  24. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  25. package/dist/agent-runtime/sqlite-purge.d.ts +7 -0
  26. package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -0
  27. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  28. package/dist/agent-runtime/store-driver.d.ts +2 -0
  29. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  30. package/dist/agent-runtime/store-purge.d.ts +13 -0
  31. package/dist/agent-runtime/store-purge.d.ts.map +1 -0
  32. package/dist/agent-runtime/store.d.ts +3 -0
  33. package/dist/agent-runtime/store.d.ts.map +1 -1
  34. package/dist/agent-runtime-coding-tools.js +438 -124
  35. package/dist/agent-runtime-harness.js +4 -4
  36. package/dist/agent-runtime-openrouter.d.ts +19 -0
  37. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  38. package/dist/agent-runtime-openrouter.js +2 -1
  39. package/dist/agent-runtime-sqlite-bun.js +2 -2
  40. package/dist/agent-runtime-sqlite-node.js +2 -2
  41. package/dist/agent-runtime.d.ts +5 -2
  42. package/dist/agent-runtime.d.ts.map +1 -1
  43. package/dist/agent-runtime.js +128 -16
  44. package/dist/cli.js +5 -5
  45. package/dist/{index-cx84zg25.js → index-118v0z41.js} +1 -1
  46. package/dist/{index-jw81xr75.js → index-19eet1qx.js} +127 -51
  47. package/dist/{index-ejv31h14.js → index-7qy2ex0m.js} +1 -1
  48. package/dist/{index-9sx8tbz2.js → index-cksjz4eg.js} +50 -1
  49. package/dist/{index-trrf7nch.js → index-ezmn6ac6.js} +3 -3
  50. package/dist/{index-ekkt4gy9.js → index-jqtsc9mj.js} +2 -2
  51. package/dist/{index-hxtm2xr2.js → index-k2zczx1g.js} +1 -1
  52. package/dist/{index-35wcrke5.js → index-m668wzyc.js} +13 -2
  53. package/dist/{index-w9m1wznn.js → index-nemjkxjp.js} +118 -1
  54. package/dist/{index-tnazr5tc.js → index-pz7ytdga.js} +3 -3
  55. package/dist/{index-1z5xxfst.js → index-rqpdar1e.js} +102 -5
  56. package/dist/{index-qm87g51s.js → index-s4c8wy8m.js} +1 -1
  57. package/dist/node.js +2 -2
  58. package/dist/observability/index.js +1 -1
  59. package/dist/server/index.d.ts +1 -1
  60. package/dist/server/index.d.ts.map +1 -1
  61. package/dist/server/index.js +4 -2
  62. package/dist/server/request.d.ts +19 -0
  63. package/dist/server/request.d.ts.map +1 -1
  64. package/dist/telegram/init-data.d.ts +134 -0
  65. package/dist/telegram/init-data.d.ts.map +1 -0
  66. package/dist/telegram/send-failure.d.ts +73 -0
  67. package/dist/telegram/send-failure.d.ts.map +1 -0
  68. package/dist/telegram.d.ts +3 -0
  69. package/dist/telegram.d.ts.map +1 -0
  70. package/dist/telegram.js +224 -0
  71. package/dist/tool-invoker.js +4 -4
  72. package/dist/tools.js +7 -7
  73. package/llms-full.txt +332 -9
  74. package/native/darwin-arm64.node +0 -0
  75. package/native/darwin-x64.node +0 -0
  76. package/package.json +6 -2
@@ -3,10 +3,10 @@ import {
3
3
  composeAgentPrompt,
4
4
  createAgentRuntime,
5
5
  createAgentRuntimeEventSink
6
- } from "./index-35wcrke5.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;CA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AAkB,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,8 +1,8 @@
1
1
  import {
2
2
  createSqliteAgentRuntimeStore,
3
3
  initializeAgentRuntimeSqlite
4
- } from "./index-9sx8tbz2.js";
5
- import"./index-jw81xr75.js";
4
+ } from "./index-cksjz4eg.js";
5
+ import"./index-19eet1qx.js";
6
6
  import"./index-y2s6h5bf.js";
7
7
  import"./index-x1th9s8c.js";
8
8
 
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createSqliteAgentRuntimeStore,
3
3
  initializeAgentRuntimeSqlite
4
- } from "./index-9sx8tbz2.js";
5
- import"./index-jw81xr75.js";
4
+ } from "./index-cksjz4eg.js";
5
+ import"./index-19eet1qx.js";
6
6
  import"./index-y2s6h5bf.js";
7
7
  import"./index-x1th9s8c.js";
8
8
 
@@ -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,11 +10,14 @@ 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 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';
13
+ export { type AgentProviderFailure, type AgentProviderFailureReason, classifyProviderFailure, isToolResultFailure, } from './agent-runtime/provider-failure.js';
14
+ export { AgentConversationPurgedError, type AgentConversationPurgeInput, AgentConversationPurgeInputSchema, type AgentConversationPurgeResult, AgentConversationPurgeResultSchema, purgeAgentConversation, } from './agent-runtime/purge.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';
14
16
  export type { AgentRuntimeResult } from './agent-runtime/runtime-result.js';
15
17
  export * from './agent-runtime/schemas.js';
16
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';
17
19
  export { ACTIVE_AGENT_RUN_STATES, type AgentAdmissionReceipt, AgentAdmissionReceiptSchema, type AgentHistoryMutation, AgentHistoryMutationSchema, type AgentRuntimeHead, AgentRuntimeHeadSchema, type AgentRuntimeStoreDriver, type AgentStoreCompareAndSwapResult, type AgentStoredRun, AgentStoredRunSchema, createAgentRuntimeStore, createMemoryAgentRuntimeStore, } from './agent-runtime/store-driver.js';
20
+ export type { AgentConversationPurgeDriver } from './agent-runtime/store-purge.js';
18
21
  export { AgentRuntimeConflictError } from './agent-runtime/terminal-commit.js';
19
22
  export { type AgentHistoryEvidencePolicy, isAssistantHistoryEvidence, } from './agent-runtime/terminal-status.js';
20
23
  //# sourceMappingURL=agent-runtime.d.ts.map
@@ -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,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EACL,KAAK,4BAA4B,EACjC,kCAAkC,EAClC,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,8BAA8B,EAC9B,KAAK,kCAAkC,EACvC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAChC,KAAK,sBAAsB,EAC3B,KAAK,8BAA8B,EACnC,4BAA4B,EAC5B,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,KAAK,8BAA8B,EACnC,kCAAkC,EAClC,KAAK,8BAA8B,EACnC,KAAK,kCAAkC,GACxC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,6BAA6B,EAC7B,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,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AAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,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-35wcrke5.js";
30
+ } from "./index-m668wzyc.js";
31
31
  import {
32
32
  AgentModelCapabilitySchema,
33
33
  AgentModelCatalogEntrySchema,
@@ -52,6 +52,9 @@ import {
52
52
  AgentAdmissionReceiptSchema,
53
53
  AgentConversationMessagePageSchema,
54
54
  AgentConversationPageSchema,
55
+ AgentConversationPurgeInputSchema,
56
+ AgentConversationPurgeResultSchema,
57
+ AgentConversationPurgedError,
55
58
  AgentConversationSummarySchema,
56
59
  AgentHistoryMutationSchema,
57
60
  AgentRecoverableDescriptorSchema,
@@ -70,8 +73,9 @@ import {
70
73
  ReplaceCompactedRangeSchema,
71
74
  RequestRunInterruptSchema,
72
75
  createAgentRuntimeStore,
73
- createMemoryAgentRuntimeStore
74
- } from "./index-jw81xr75.js";
76
+ createMemoryAgentRuntimeStore,
77
+ purgeAgentConversation
78
+ } from "./index-19eet1qx.js";
75
79
  import {
76
80
  isAssistantHistoryEvidence,
77
81
  isCompleteAgentHistoryTurn
@@ -82,15 +86,15 @@ import {
82
86
  import {
83
87
  buildToolManifest,
84
88
  mountAgent
85
- } from "./index-trrf7nch.js";
89
+ } from "./index-ezmn6ac6.js";
86
90
  import"./index-3xnq72rz.js";
87
- import"./index-hxtm2xr2.js";
91
+ import"./index-k2zczx1g.js";
88
92
  import {
89
93
  defineRuntimeTool
90
94
  } from "./index-wwst0td5.js";
91
- import"./index-ejv31h14.js";
92
- import"./index-qm87g51s.js";
93
- import"./index-w9m1wznn.js";
95
+ import"./index-7qy2ex0m.js";
96
+ import"./index-s4c8wy8m.js";
97
+ import"./index-nemjkxjp.js";
94
98
  import {
95
99
  AgentAssistantPlaceholderSchema,
96
100
  AgentControlPartSchema,
@@ -133,7 +137,8 @@ import {
133
137
  import"./index-vj3vvpaa.js";
134
138
  import"./index-0w9abg87.js";
135
139
  import {
136
- executableAgentRuntimeTools
140
+ executableAgentRuntimeTools,
141
+ isRecord
137
142
  } from "./index-qyrqwr4c.js";
138
143
  import"./index-6k1937bx.js";
139
144
 
@@ -159,13 +164,22 @@ function groupProviderTurns(messages, evidencePolicy) {
159
164
  }
160
165
  return turns;
161
166
  }
162
- function eligibleForCompaction(messages, keepRecentTurns, evidencePolicy) {
163
- const withoutLeadingSummary = messages[0]?.role === "summary" ? messages.slice(1) : messages;
164
- 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);
165
174
  const firstIncomplete = turns.findIndex((turn) => !turn.complete);
166
175
  const completeTurns = firstIncomplete === -1 ? turns : turns.slice(0, firstIncomplete);
167
- const eligibleCount = Math.max(0, completeTurns.length - keepRecentTurns);
168
- 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
+ };
169
183
  }
170
184
  function mutationSnapshot(result, fallback, attempts) {
171
185
  if (result.outcome === "applied" || result.outcome === "duplicate") {
@@ -189,11 +203,14 @@ function structuredCompaction(config) {
189
203
  if (!await config.threshold(snapshot)) {
190
204
  return { outcome: "not_needed", snapshot, attempts: attempt };
191
205
  }
192
- 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
+ });
193
211
  if (eligibleMessages.length === 0) {
194
212
  return { outcome: "nothing_eligible", snapshot, attempts: attempt };
195
213
  }
196
- const leadingSummary = snapshot.messages[0]?.role === "summary" ? snapshot.messages[0] : undefined;
197
214
  const previousSummary = leadingSummary && config.readPreviousSummary ? config.schema.parse(config.readPreviousSummary(leadingSummary)) : attempt === 1 ? input.previousSummary : undefined;
198
215
  const rawSummary = await config.summarize({
199
216
  conversationId: input.conversationId,
@@ -694,14 +711,105 @@ function defineAgentProtocol(config) {
694
711
  }
695
712
  };
696
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
+ }
697
802
  export {
698
803
  validateAgentModelSnapshot,
699
804
  structuredCompaction,
805
+ selectCompactableHistory,
700
806
  selectAgentHistory,
701
807
  searchAgentModelCatalog,
702
808
  runStateForTerminalReason,
809
+ purgeAgentConversation,
703
810
  projectAgentHistoryDetailed,
704
811
  projectAgentHistory,
812
+ isToolResultFailure,
705
813
  isAssistantHistoryEvidence,
706
814
  hasAgentTerminalOutput,
707
815
  defineModelRegistry,
@@ -716,6 +824,7 @@ export {
716
824
  createAgentRuntime,
717
825
  createAgentObservability,
718
826
  composeAgentPrompt,
827
+ classifyProviderFailure,
719
828
  agentDurableEventId,
720
829
  advanceAgentRuntimeEventCursor,
721
830
  RequestRunInterruptSchema,
@@ -792,6 +901,9 @@ export {
792
901
  AgentFilePartSchema,
793
902
  AgentCostValueSchema,
794
903
  AgentConversationSummarySchema,
904
+ AgentConversationPurgedError,
905
+ AgentConversationPurgeResultSchema,
906
+ AgentConversationPurgeInputSchema,
795
907
  AgentConversationPageSchema,
796
908
  AgentConversationMessagePageSchema,
797
909
  AgentControlPartSchema,
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,