@tangle-network/agent-app 4.0.8 → 4.0.9
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/dist/assistant/index.js +2 -1
- package/dist/assistant/index.js.map +1 -1
- package/dist/chat-routes/detached-turn.d.ts +2 -0
- package/dist/chat-routes/failure-wording.d.ts +56 -0
- package/dist/chat-routes/index.js +13 -5
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-routes/sandbox-producer.d.ts +6 -14
- package/dist/chat-routes/turn-event-stream.d.ts +5 -0
- package/dist/chat-routes/turn-route-contracts.d.ts +23 -0
- package/dist/chat-routes/turn-routes.d.ts +3 -1
- package/dist/{chunk-ASWAPIJM.js → chunk-AYTNVTDP.js} +2 -2
- package/dist/{chunk-FZOHBYGV.js → chunk-KPCNNFBO.js} +13 -2
- package/dist/chunk-KPCNNFBO.js.map +1 -0
- package/dist/{chunk-QXPOBDPU.js → chunk-M4LA7JMU.js} +1 -21
- package/dist/chunk-M4LA7JMU.js.map +1 -0
- package/dist/chunk-QUV5M7SZ.js +23 -0
- package/dist/chunk-QUV5M7SZ.js.map +1 -0
- package/dist/{chunk-A2M75YRP.js → chunk-VTMMTQ4P.js} +2 -2
- package/dist/chunk-VTMMTQ4P.js.map +1 -0
- package/dist/{chunk-4OR7NNYB.js → chunk-XZ37VCTP.js} +364 -264
- package/dist/chunk-XZ37VCTP.js.map +1 -0
- package/dist/journeys/cli.js +1 -1
- package/dist/journeys/index.js +1 -1
- package/dist/preset-cloudflare/index.js +1 -1
- package/dist/public-consultation/index.js +4 -3
- package/dist/public-consultation/index.js.map +1 -1
- package/dist/sandbox/index.js +2 -2
- package/dist/turn-health/index.js +2 -1
- package/dist/turn-health/index.js.map +1 -1
- package/dist/turn-health/sweep.d.ts +1 -1
- package/dist/turn-stream/adapters.d.ts +14 -1
- package/dist/turn-stream/core.d.ts +2 -0
- package/dist/turn-stream/do.d.ts +17 -0
- package/dist/turn-stream/index.d.ts +1 -1
- package/dist/turn-stream/index.js +11 -2
- package/dist/turn-stream/index.js.map +1 -1
- package/dist/web-react/index.d.ts +1 -1
- package/dist/web-react/index.js +4 -2
- package/package.json +1 -1
- package/dist/chunk-4OR7NNYB.js.map +0 -1
- package/dist/chunk-A2M75YRP.js.map +0 -1
- package/dist/chunk-FZOHBYGV.js.map +0 -1
- package/dist/chunk-QXPOBDPU.js.map +0 -1
- /package/dist/{chunk-ASWAPIJM.js.map → chunk-AYTNVTDP.js.map} +0 -0
- /package/dist/{web-react → web}/turn-funding-recovery.d.ts +0 -0
|
@@ -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,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a person reads when a sandbox turn fails. A reason the producer can word plainly (a provider wait, a refused
|
|
3
|
+
* model key, the Router's own budget or balance refusal) becomes that sentence. A refusal that would fail the same way
|
|
4
|
+
* again, and a funding, billing or admission refusal the client's recovery UI reads, keep their words. Any other reason
|
|
5
|
+
* (a harness error, a tool list, a repeated-call loop, a stack) is withheld: the person reads one plain sentence and the
|
|
6
|
+
* server keeps the reason, in its log and under a Symbol key the route's own failure hooks read.
|
|
7
|
+
*/
|
|
8
|
+
import { type JsonRecord } from '../stream/index.js';
|
|
9
|
+
type Log = (message: string, meta?: Record<string, unknown>) => void;
|
|
10
|
+
/** A harness's provider retry wait (OpenCode's raw `retry` status) as one sentence: the provider's words and the next attempt. */
|
|
11
|
+
export declare function providerRetryNotice(event: {
|
|
12
|
+
type: string;
|
|
13
|
+
data?: unknown;
|
|
14
|
+
}): string | undefined;
|
|
15
|
+
/** A terminal provider wait (`…, reset at <ISO>`, agent-container provider-retry-wait.ts) as one sentence. */
|
|
16
|
+
export declare function providerResetSentence(message: string): string | undefined;
|
|
17
|
+
/** The typed code for a harness whose model refused its key, so a product can tell it from other stream failures. */
|
|
18
|
+
export declare const MODEL_KEY_REFUSED_CODE = "model.key_refused";
|
|
19
|
+
/** A harness whose model provider refused its key ("Invalid API key", OpenCode's `OPENCODE_ERROR`) as plain words, true
|
|
20
|
+
* both for a newly started box whose harness called the model before its minted key was in place (it recovers within
|
|
21
|
+
* minutes) and for a key that is wrong. The raw error goes to the log and the failure note, never to the person. */
|
|
22
|
+
export declare function modelKeyRefusedSentence(message: string): string | undefined;
|
|
23
|
+
/** A failure reason as the plain sentence the person reads, when the producer has one for it. */
|
|
24
|
+
export declare function plainFailureSentence(message: string): string | undefined;
|
|
25
|
+
export declare function sandboxStreamErrorMessage(data: unknown): string;
|
|
26
|
+
/** The typed reason a sandbox `error` event carries, or a generic stream-error code. */
|
|
27
|
+
export declare function sandboxStreamErrorCode(data: unknown): string;
|
|
28
|
+
/** A failure event the person can read (`error`, `warning`, `done`, `session.run.failed`): when a reason field is one the
|
|
29
|
+
* producer words plainly, every reason field carries that sentence and the raw text moves to `details.raw`. The client
|
|
30
|
+
* prints an error event's `message`, and the route's failure card reads `message`/`error`/`reason`. */
|
|
31
|
+
export declare function plainFailureEvent(event: JsonRecord): JsonRecord;
|
|
32
|
+
export declare const FAILED_TURN_TEXT = "That answer stopped before it finished. Please send your question again.";
|
|
33
|
+
/** True when a terminal failure's reason (a harness error, a tool list, a call loop, a stack) is withheld: the person
|
|
34
|
+
* reads the failed-turn text and the server log (`log`, else `console.warn`) keeps the reason under one class, with
|
|
35
|
+
* `meta` (the ids and failure note the producer has). Passing through: a plainly worded reason (a provider reset, a
|
|
36
|
+
* refused model key, a Router budget or balance refusal); HTTP 402; a {@link REFUSAL_CODES} refusal; and what the
|
|
37
|
+
* client's recovery UI reads (`getChatFundingRecovery`: `insufficient_credits`, `paid_access_required`,
|
|
38
|
+
* `funding_required`, or its words). */
|
|
39
|
+
export declare function withheld(log: Log | undefined, reason: string, code: string | undefined, status: unknown, meta?: Record<string, unknown>): boolean;
|
|
40
|
+
/** The turn, thread, session and execution ids a record carries, for the server log. */
|
|
41
|
+
export declare function failureIds(source: unknown): Record<string, string>;
|
|
42
|
+
/** A failure event whose reason is withheld: every reason field (`message`, `error`, `reason`) reads `text`, the
|
|
43
|
+
* detail fields that carry text are dropped, and the original data rides under `WITHHELD_FAILURE`, which JSON (the
|
|
44
|
+
* wire, the turn buffer) drops and the route's hooks read. */
|
|
45
|
+
export declare function withheldFailureEvent(event: JsonRecord, text: string): JsonRecord;
|
|
46
|
+
/** A thrown sandbox stream as what the person reads, the operator's failure note, its code and its raw reason. */
|
|
47
|
+
export declare function sandboxStreamFailureDiagnostic(error: unknown): {
|
|
48
|
+
userMessage: string;
|
|
49
|
+
failureNote: string;
|
|
50
|
+
code: string;
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
53
|
+
/** A tool part as the person may read it, live and stored: it never carries the harness's list of every tool. The
|
|
54
|
+
* harness's `invalid` repair tool, which stands in for a call to a tool the model does not have, reads one sentence. */
|
|
55
|
+
export declare function withoutToolList(part: JsonRecord): JsonRecord;
|
|
56
|
+
export {};
|
|
@@ -88,14 +88,15 @@ import {
|
|
|
88
88
|
turnPromptText,
|
|
89
89
|
valueRedactor,
|
|
90
90
|
withProducerStream
|
|
91
|
-
} from "../chunk-
|
|
91
|
+
} from "../chunk-XZ37VCTP.js";
|
|
92
|
+
import "../chunk-QUV5M7SZ.js";
|
|
92
93
|
import "../chunk-SBHFMDR7.js";
|
|
93
94
|
import "../chunk-H6BRJU5M.js";
|
|
94
95
|
import "../chunk-4DBHC63F.js";
|
|
95
96
|
import "../chunk-RN4WPTBH.js";
|
|
96
97
|
import "../chunk-MM6RLOXF.js";
|
|
97
98
|
import "../chunk-M4QITAQV.js";
|
|
98
|
-
import "../chunk-
|
|
99
|
+
import "../chunk-AYTNVTDP.js";
|
|
99
100
|
import "../chunk-F4TUZYMX.js";
|
|
100
101
|
import {
|
|
101
102
|
redactErrorMessage
|
|
@@ -129,7 +130,7 @@ import {
|
|
|
129
130
|
DEFAULT_STALE_TURN_LOCK_GRACE_MS,
|
|
130
131
|
DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS,
|
|
131
132
|
reconcileStaleTurnLock
|
|
132
|
-
} from "../chunk-
|
|
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
|
-
...
|
|
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;
|