@tangle-network/agent-app 4.0.8 → 4.0.11

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 (63) hide show
  1. package/dist/assistant/index.js +2 -1
  2. package/dist/assistant/index.js.map +1 -1
  3. package/dist/billing/identity-bound.d.ts +7 -0
  4. package/dist/billing/index.d.ts +1 -1
  5. package/dist/billing/index.js +3 -1
  6. package/dist/chat-routes/detached-turn.d.ts +2 -0
  7. package/dist/chat-routes/failure-wording.d.ts +61 -0
  8. package/dist/chat-routes/index.js +30 -22
  9. package/dist/chat-routes/index.js.map +1 -1
  10. package/dist/chat-routes/sandbox-producer.d.ts +6 -14
  11. package/dist/chat-routes/turn-event-stream.d.ts +5 -0
  12. package/dist/chat-routes/turn-route-contracts.d.ts +23 -0
  13. package/dist/chat-routes/turn-routes.d.ts +3 -1
  14. package/dist/{chunk-R5PW3FO4.js → chunk-2IGXFHUO.js} +13 -2
  15. package/dist/chunk-2IGXFHUO.js.map +1 -0
  16. package/dist/{chunk-4OR7NNYB.js → chunk-CD4SJXYC.js} +125 -730
  17. package/dist/chunk-CD4SJXYC.js.map +1 -0
  18. package/dist/{chunk-FTGKXM7O.js → chunk-EK7A5Y7P.js} +12 -4
  19. package/dist/chunk-EK7A5Y7P.js.map +1 -0
  20. package/dist/{chunk-FZOHBYGV.js → chunk-KPCNNFBO.js} +13 -2
  21. package/dist/chunk-KPCNNFBO.js.map +1 -0
  22. package/dist/{chunk-QXPOBDPU.js → chunk-M4LA7JMU.js} +1 -21
  23. package/dist/chunk-M4LA7JMU.js.map +1 -0
  24. package/dist/{chunk-ASWAPIJM.js → chunk-QMQB725F.js} +4 -14
  25. package/dist/chunk-QMQB725F.js.map +1 -0
  26. package/dist/chunk-QUV5M7SZ.js +23 -0
  27. package/dist/chunk-QUV5M7SZ.js.map +1 -0
  28. package/dist/chunk-RNDWCT4O.js +1136 -0
  29. package/dist/chunk-RNDWCT4O.js.map +1 -0
  30. package/dist/{chunk-W2DIPVHW.js → chunk-TMWUWKLU.js} +6 -5
  31. package/dist/chunk-TMWUWKLU.js.map +1 -0
  32. package/dist/{chunk-A2M75YRP.js → chunk-VTMMTQ4P.js} +2 -2
  33. package/dist/chunk-VTMMTQ4P.js.map +1 -0
  34. package/dist/journeys/cli.js +1 -1
  35. package/dist/journeys/index.js +1 -1
  36. package/dist/preset-cloudflare/index.js +8 -5
  37. package/dist/preset-cloudflare/index.js.map +1 -1
  38. package/dist/public-consultation/index.js +6 -5
  39. package/dist/public-consultation/index.js.map +1 -1
  40. package/dist/sandbox/index.js +4 -4
  41. package/dist/turn-health/index.js +2 -1
  42. package/dist/turn-health/index.js.map +1 -1
  43. package/dist/turn-health/sweep.d.ts +1 -1
  44. package/dist/turn-stream/adapters.d.ts +14 -1
  45. package/dist/turn-stream/core.d.ts +2 -0
  46. package/dist/turn-stream/do.d.ts +17 -0
  47. package/dist/turn-stream/index.d.ts +1 -1
  48. package/dist/turn-stream/index.js +11 -2
  49. package/dist/turn-stream/index.js.map +1 -1
  50. package/dist/web-react/index.d.ts +1 -1
  51. package/dist/web-react/index.js +4 -2
  52. package/package.json +1 -1
  53. package/dist/chunk-4OR7NNYB.js.map +0 -1
  54. package/dist/chunk-A2M75YRP.js.map +0 -1
  55. package/dist/chunk-ASWAPIJM.js.map +0 -1
  56. package/dist/chunk-FTGKXM7O.js.map +0 -1
  57. package/dist/chunk-FZOHBYGV.js.map +0 -1
  58. package/dist/chunk-K4YIDNX5.js +0 -263
  59. package/dist/chunk-K4YIDNX5.js.map +0 -1
  60. package/dist/chunk-QXPOBDPU.js.map +0 -1
  61. package/dist/chunk-R5PW3FO4.js.map +0 -1
  62. package/dist/chunk-W2DIPVHW.js.map +0 -1
  63. /package/dist/{web-react → web}/turn-funding-recovery.d.ts +0 -0
@@ -201,6 +201,11 @@ export interface DurableWorkspaceKeyManagerOptions {
201
201
  now?: () => Date;
202
202
  /** Local lifetime used when the remote response omits an expiry. */
203
203
  keyLifetimeMs?: number;
204
+ /**
205
+ * Least remaining life a reused key needs: the app's longest turn plus a margin, shorter than `keyLifetimeMs`. Below
206
+ * it a fresh key is minted and the old one retired at its own expiry, never revoked under a turn that holds it.
207
+ */
208
+ minRemainingLifetimeMs?: number;
204
209
  /** Lease lifetime for remote operations. */
205
210
  leaseMs?: number;
206
211
  /** Maximum time to wait for another issuer to release the scope lease. */
@@ -220,6 +225,8 @@ export interface DurableWorkspaceKeyManagerOptions {
220
225
  /** Recognize a missing remote key without depending on a provider SDK. */
221
226
  isRemoteMissing?: (error: unknown) => boolean;
222
227
  }
228
+ /** Default reuse floor: a 15 min turn plus a 5 min margin; this package sets no turn limit, so longer turns pass their own. */
229
+ export declare const DEFAULT_MIN_REMAINING_KEY_LIFETIME_MS: number;
223
230
  /**
224
231
  * Create a product-neutral manager for child-key issuance and cleanup.
225
232
  *
@@ -256,4 +256,4 @@ export interface PlatformBalanceManager<Plan extends string> {
256
256
  export declare function createPlatformBalanceManager<Plan extends string>(opts: PlatformBalanceManagerOptions<Plan>): PlatformBalanceManager<Plan>;
257
257
  /** Create a workspace key manager that handles key provisioning and budget tracking */
258
258
  export declare function createWorkspaceKeyManager(opts: WorkspaceKeyManagerOptions): WorkspaceKeyManager;
259
- export { createIdentityBoundWorkspaceKeyManager, type DurableWorkspaceKeyManager, type DurableWorkspaceKeyManagerOptions, type DurableWorkspaceKeyCreateInput, type DurableWorkspaceKeyConditionalWrites, type DurableWorkspaceKeyProvisioner, type DurableWorkspaceKeyProvisioningRecord, type DurableWorkspaceKeyRecord, type DurableWorkspaceKeyScope, type DurableWorkspaceKeyStore, type WorkspaceKeyIdentity, type WorkspaceKeyProduct, type WorkspaceKeyStatus, type WorkspaceKeyUsage, type WorkspaceRuntimeKey, } from './identity-bound.js';
259
+ export { createIdentityBoundWorkspaceKeyManager, DEFAULT_MIN_REMAINING_KEY_LIFETIME_MS, type DurableWorkspaceKeyManager, type DurableWorkspaceKeyManagerOptions, type DurableWorkspaceKeyCreateInput, type DurableWorkspaceKeyConditionalWrites, type DurableWorkspaceKeyProvisioner, type DurableWorkspaceKeyProvisioningRecord, type DurableWorkspaceKeyRecord, type DurableWorkspaceKeyScope, type DurableWorkspaceKeyStore, type WorkspaceKeyIdentity, type WorkspaceKeyProduct, type WorkspaceKeyStatus, type WorkspaceKeyUsage, type WorkspaceRuntimeKey, } from './identity-bound.js';
@@ -1,12 +1,14 @@
1
1
  import {
2
+ DEFAULT_MIN_REMAINING_KEY_LIFETIME_MS,
2
3
  createIdentityBoundWorkspaceKeyManager,
3
4
  createPlatformBalanceManager,
4
5
  createTcloudKeyProvisioner,
5
6
  createWorkspaceKeyManager,
6
7
  readSharedBillingState
7
- } from "../chunk-FTGKXM7O.js";
8
+ } from "../chunk-EK7A5Y7P.js";
8
9
  import "../chunk-VGS2NXLB.js";
9
10
  export {
11
+ DEFAULT_MIN_REMAINING_KEY_LIFETIME_MS,
10
12
  createIdentityBoundWorkspaceKeyManager,
11
13
  createPlatformBalanceManager,
12
14
  createTcloudKeyProvisioner,
@@ -97,6 +97,8 @@ export interface DetachedTurnOptions {
97
97
  /** Opt-in eager promotion of harness-emitted `file` parts. Forwarded to the
98
98
  * producer (see its docs). */
99
99
  promoteFilePart?: SandboxChatProducerOptions['promoteFilePart'];
100
+ /** What the person reads for a failure whose reason is withheld. Forwarded to the producer. */
101
+ failedTurnText?: SandboxChatProducerOptions['failedTurnText'];
100
102
  /** Authoritative final receipt, consulted whenever a re-invoke finds a prior
101
103
  * buffer: (a) an already-`complete` turn returns it as the cached result,
102
104
  * (b) a `running` turn (crash mid-run) uses it to detect a run that finished
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What a person reads when a sandbox turn fails: only sentences written here. Harness, provider and Router text is read
3
+ * only to classify the failure, by its code, its HTTP status or a recognized phrase, and the person reads that class's
4
+ * fixed sentence. No part of the reason is shown; the only values in a sentence are times parsed and formatted here.
5
+ * The server keeps the reason, in its log and under a Symbol key the route's own failure hooks read. `personFacing`
6
+ * applies this to every event the sandbox producer yields.
7
+ */
8
+ import { type JsonRecord } from '../stream/index.js';
9
+ type Log = (message: string, meta?: Record<string, unknown>) => void;
10
+ export declare const FAILED_TURN_TEXT = "That answer stopped before it finished. Please send your question again.";
11
+ /** A harness's provider retry wait (OpenCode's raw `retry` status) as one sentence with its next attempt's time. */
12
+ export declare function providerRetryNotice(event: {
13
+ type: string;
14
+ data?: unknown;
15
+ }): string | undefined;
16
+ /** A terminal provider wait (`…, reset at <ISO>`, agent-container provider-retry-wait.ts) as one sentence with its time. */
17
+ export declare function providerResetSentence(message: string): string | undefined;
18
+ /** The typed code for a harness whose model refused its key, so a product can tell it from other stream failures. */
19
+ export declare const MODEL_KEY_REFUSED_CODE = "model.key_refused";
20
+ /** A harness whose model provider refused its key ("Invalid API key", OpenCode's `OPENCODE_ERROR`) as plain words, true
21
+ * both for a newly started box whose harness called the model before its minted key was in place (it recovers within
22
+ * minutes) and for a key that is wrong. The raw error goes to the log, never to the person. */
23
+ export declare function modelKeyRefusedSentence(message: string): string | undefined;
24
+ /** How a failure reads to the person: its class and that class's fixed sentence. */
25
+ export interface FailureView {
26
+ class: string;
27
+ shown: string;
28
+ }
29
+ /** The turn, thread, session and execution ids a record carries, for the server log. */
30
+ export declare function failureIds(source: unknown): Record<string, string>;
31
+ /** The text a failure adds to the answer: its sentence, after a lead line for the classes that carry one. */
32
+ export declare function failureText(view: FailureView, partialAnswer: string): string;
33
+ /** The reason a failure carries, wherever its producer put it: in `data`, a nested error, a session error's
34
+ * properties, the top level, or a raw harness event. Empty when there is none, so a failure always reads its class. */
35
+ export declare function failureReason(event: unknown): string;
36
+ /** One turn's person-facing filter. `view` classifies a failure reason; every reason is logged once, at warn (`log`,
37
+ * else `console.warn`), with its class and ids, and the same reason reads the same wherever it appears. `warning`
38
+ * gives an allowed warning's sentence. `event` is every event the producer yields as it may reach the client.
39
+ * `hasAnswer` says whether the turn already shows answer text. */
40
+ export declare function personFacing(options: {
41
+ log?: Log;
42
+ failedTurnText: string;
43
+ hasAnswer?: () => boolean;
44
+ }): {
45
+ view: (reason: string, code?: string, status?: unknown, meta?: Record<string, unknown>) => FailureView;
46
+ warning: (code: string | undefined, message: string, meta?: Record<string, unknown>) => string | undefined;
47
+ event: (event: JsonRecord) => JsonRecord | undefined;
48
+ };
49
+ /** A thrown sandbox stream as the operator's failure note, its code and its raw reason. */
50
+ export declare function sandboxStreamFailureDiagnostic(error: unknown): {
51
+ failureNote: string;
52
+ code: string;
53
+ reason: string;
54
+ };
55
+ /** The typed reason a sandbox `error` event carries, or a generic stream-error code. */
56
+ export declare function sandboxStreamErrorCode(data: unknown): string;
57
+ /** A tool part as the person may read it, live and stored: a failed call's `error` and `output` lose the harness's list
58
+ * of every tool, and the harness's `invalid` repair tool, which stands in for a call to a tool the model does not have,
59
+ * reads one sentence. Inputs, metadata and a completed call's output (a document it read) stay whole. */
60
+ export declare function withoutToolList(part: JsonRecord): JsonRecord;
61
+ export {};
@@ -40,76 +40,77 @@ import {
40
40
  observeNativeCompletion,
41
41
  readCompletedSandboxTurn,
42
42
  recoverSandboxAssistantMessage
43
- } from "../chunk-W2DIPVHW.js";
43
+ } from "../chunk-TMWUWKLU.js";
44
44
  import {
45
45
  runProtectedRouterTurn
46
46
  } from "../chunk-GWATTXFR.js";
47
47
  import {
48
- DEFAULT_MODEL_FIRST_RESPONSE_TIMEOUT_MS,
49
- DEFAULT_MODEL_STREAM_OPEN_TIMEOUT_MS,
50
48
  HYBRID_TURN_GUIDANCE,
51
49
  INTENT_LINE_HISTORY_MESSAGES,
52
50
  INTENT_LINE_MAX_CHARS,
53
51
  INTENT_LINE_TIMEOUT_MS,
54
- MAX_EMPTY_TURN_RETRIES,
55
- MODEL_KEY_REFUSED_CODE,
56
- ModelFailoverTimeoutError,
57
52
  SPEAKER_EVENT,
58
53
  UPLOAD_INLINE_MAX_BYTES,
59
54
  UPLOAD_MAX_FILE_BYTES,
60
55
  buildDispatchParts,
61
56
  bytesToBase64,
62
57
  cancelChatTurn,
63
- classifyTerminalFailure,
64
58
  composeAgentProducers,
65
59
  createChatTurnRoutes,
66
60
  createHybridTurnProducer,
67
61
  createRouterTurnProducer,
68
62
  createSandboxChatProducer,
69
63
  createUploadRoute,
70
- isCommittingSandboxEvent,
71
- isLiveLifecycleEvent,
72
- modelKeyRefusedSentence,
73
64
  normalizeChatPromptForSandbox,
74
65
  observeTurnCancellation,
75
66
  projectDispatchHistory,
76
- providerResetSentence,
77
- providerRetryNotice,
78
67
  redactEvents,
79
- resolveEmptyTurnRetries,
80
68
  routerTurnHistory,
81
69
  sanitizeUploadFilename,
82
70
  speakerPart,
83
71
  startHybridBox,
84
72
  streamChatRouteAsSandboxEvents,
85
- streamWithModelFailover,
86
- summarizeFailoverReason,
87
73
  turnCarriesFiles,
88
74
  turnPromptText,
89
75
  valueRedactor,
90
76
  withProducerStream
91
- } from "../chunk-4OR7NNYB.js";
77
+ } from "../chunk-CD4SJXYC.js";
92
78
  import "../chunk-SBHFMDR7.js";
93
79
  import "../chunk-H6BRJU5M.js";
94
80
  import "../chunk-4DBHC63F.js";
95
81
  import "../chunk-RN4WPTBH.js";
96
82
  import "../chunk-MM6RLOXF.js";
97
83
  import "../chunk-M4QITAQV.js";
98
- import "../chunk-ASWAPIJM.js";
84
+ import "../chunk-QMQB725F.js";
99
85
  import "../chunk-F4TUZYMX.js";
100
86
  import {
101
87
  redactErrorMessage
102
88
  } from "../chunk-MH74DY2I.js";
103
89
  import {
90
+ DEFAULT_MODEL_FIRST_RESPONSE_TIMEOUT_MS,
91
+ DEFAULT_MODEL_STREAM_OPEN_TIMEOUT_MS,
92
+ MAX_EMPTY_TURN_RETRIES,
93
+ MODEL_KEY_REFUSED_CODE,
94
+ ModelFailoverTimeoutError,
104
95
  TURN_USAGE_KEYS,
105
96
  assistantRowIdForTurn,
97
+ classifyTerminalFailure,
106
98
  createAssistantDraftWriter,
99
+ isCommittingSandboxEvent,
107
100
  isDraftContentEvent,
101
+ isLiveLifecycleEvent,
108
102
  measuredUsage,
103
+ modelKeyRefusedSentence,
104
+ providerResetSentence,
105
+ providerRetryNotice,
106
+ resolveEmptyTurnRetries,
109
107
  rowIdOf,
110
108
  storeSupportsDraftPersistence,
109
+ streamWithModelFailover,
110
+ summarizeFailoverReason,
111
111
  transformVisibleTextParts
112
- } from "../chunk-K4YIDNX5.js";
112
+ } from "../chunk-RNDWCT4O.js";
113
+ import "../chunk-QUV5M7SZ.js";
113
114
  import "../chunk-WGT32NQ4.js";
114
115
  import "../chunk-YG66IHDU.js";
115
116
  import {
@@ -123,13 +124,13 @@ import {
123
124
  mergePersistedPart
124
125
  } from "../chunk-JM6ANMOA.js";
125
126
  import "../chunk-TB6KNPFI.js";
126
- import "../chunk-R5PW3FO4.js";
127
+ import "../chunk-2IGXFHUO.js";
127
128
  import "../chunk-ALIWB2P3.js";
128
129
  import {
129
130
  DEFAULT_STALE_TURN_LOCK_GRACE_MS,
130
131
  DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS,
131
132
  reconcileStaleTurnLock
132
- } from "../chunk-FZOHBYGV.js";
133
+ } from "../chunk-KPCNNFBO.js";
133
134
  import {
134
135
  coalesceDeltas,
135
136
  createBufferedTurnTap
@@ -324,8 +325,14 @@ function createProtectedRuntimeChatProducer(options) {
324
325
  reader = channel.readable.getReader();
325
326
  const emit = (event) => channelWriter.write(event);
326
327
  const { profileMaterializationAxes } = await import("@tangle-network/agent-interface");
328
+ let settings;
329
+ try {
330
+ settings = protectedTurnSettings(profile, tools, profileMaterializationAxes);
331
+ } catch (error) {
332
+ throw Object.assign(error, { code: "profile_unsupported" });
333
+ }
327
334
  execution = runProtectedRouterTurn({
328
- ...protectedTurnSettings(profile, tools, profileMaterializationAxes),
335
+ ...settings,
329
336
  grant: options.grant,
330
337
  userMessage: options.prompt,
331
338
  history: [...options.priorMessages ?? []],
@@ -383,7 +390,7 @@ function createProtectedRuntimeChatProducer(options) {
383
390
  if (finalText) await emit({ type: "message.part.updated", data: { part: { id: "text_delta", type: "text" }, delta: finalText } });
384
391
  await emit({ type: "result", data: { finalText } });
385
392
  }
386
- if (outcome.failure) throw new Error(outcome.failure.message);
393
+ if (outcome.failure) throw Object.assign(new Error(outcome.failure.message), { code: outcome.failure.code });
387
394
  await channelWriter.close();
388
395
  }).catch((error) => channelWriter.abort(error));
389
396
  for (; ; ) {
@@ -570,6 +577,7 @@ async function runDetachedTurn(opts) {
570
577
  isRenderableInteraction: opts.isRenderableInteraction,
571
578
  declineInteraction: opts.declineInteraction,
572
579
  promoteFilePart: opts.promoteFilePart,
580
+ failedTurnText: opts.failedTurnText,
573
581
  log: opts.log
574
582
  });
575
583
  let runError;