@tangle-network/agent-app 0.60.46 → 0.60.48

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 (31) hide show
  1. package/dist/assistant/index.js +5 -5
  2. package/dist/chat-react/index.js +3 -3
  3. package/dist/chat-routes/index.d.ts +1 -0
  4. package/dist/chat-routes/index.js +39 -15
  5. package/dist/chat-routes/index.js.map +1 -1
  6. package/dist/chat-routes/turn-progress.d.ts +88 -0
  7. package/dist/chat-routes/turn-routes.d.ts +7 -1
  8. package/dist/chat-routes/wire.d.ts +3 -1
  9. package/dist/chat-store/index.js +2 -2
  10. package/dist/{chunk-FZJRATBY.js → chunk-7GMERKA3.js} +1104 -1068
  11. package/dist/chunk-7GMERKA3.js.map +1 -0
  12. package/dist/{chunk-FPCIJCS3.js → chunk-IKESHQ5B.js} +2 -2
  13. package/dist/{chunk-TCPRFFZK.js → chunk-MFDH4C2F.js} +2 -2
  14. package/dist/{chunk-GBGSC42G.js → chunk-MJRVFRJB.js} +2 -2
  15. package/dist/{chunk-4EVEBEJX.js → chunk-TNEFHE2K.js} +76 -4
  16. package/dist/chunk-TNEFHE2K.js.map +1 -0
  17. package/dist/{chunk-HOZMP3AR.js → chunk-VC5AGH7C.js} +126 -3
  18. package/dist/chunk-VC5AGH7C.js.map +1 -0
  19. package/dist/public-consultation/index.d.ts +1 -1
  20. package/dist/public-consultation/index.js +3 -3
  21. package/dist/web-react/chat-stream.d.ts +4 -0
  22. package/dist/web-react/index.d.ts +6 -1
  23. package/dist/web-react/index.js +26 -6
  24. package/dist/web-react/turn-progress.d.ts +24 -0
  25. package/package.json +1 -1
  26. package/dist/chunk-4EVEBEJX.js.map +0 -1
  27. package/dist/chunk-FZJRATBY.js.map +0 -1
  28. package/dist/chunk-HOZMP3AR.js.map +0 -1
  29. /package/dist/{chunk-FPCIJCS3.js.map → chunk-IKESHQ5B.js.map} +0 -0
  30. /package/dist/{chunk-TCPRFFZK.js.map → chunk-MFDH4C2F.js.map} +0 -0
  31. /package/dist/{chunk-GBGSC42G.js.map → chunk-MJRVFRJB.js.map} +0 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Turn progress: the real stage a chat turn is in, on the turn stream.
3
+ *
4
+ * A turn can spend seconds before its first answer token: authorization, the
5
+ * conversation load, the single-flight lock, the product's pre-turn work, a
6
+ * sandbox, the harness and the model's first token. `session.run.phase` events
7
+ * name those stages as they happen, so a chat shows where the turn is instead
8
+ * of a spinner.
9
+ *
10
+ * A client that sends {@link TURN_PROGRESS_HEADER} gets the response stream as
11
+ * soon as the request is parsed, before authorization. Anything the route
12
+ * would have answered with a non-stream response (a 401, 402, 409, 429, a
13
+ * gate's own response) then arrives as one {@link TURN_RESPONSE_EVENT} carrying
14
+ * that response's status, headers and body, and {@link settleTurnResponse}
15
+ * turns it back into the `Response` the caller already handles. A client that
16
+ * does not send the header gets exactly the responses it got before.
17
+ *
18
+ * Browser-safe and import-free: the server route and the web client share it.
19
+ */
20
+ /** Request header that asks for a progress-first turn stream. */
21
+ export declare const TURN_PROGRESS_HEADER = "x-turn-progress";
22
+ /** The only value of {@link TURN_PROGRESS_HEADER}. The route echoes it on a progress-first response. */
23
+ export declare const TURN_PROGRESS_FIRST = "first";
24
+ /** Stream event naming the turn's current stage. Non-terminal and never turn content. */
25
+ export declare const TURN_PHASE_EVENT = "session.run.phase";
26
+ /**
27
+ * Stages the shared route emits before the producer runs. Products add their
28
+ * own (a sandbox product emits `provisioning`, `starting`,
29
+ * `awaiting-first-token`).
30
+ * - `accepted`: the request is parsed; access and the conversation are loading.
31
+ * - `preparing`: the turn holds its lock; the product's pre-turn work is running.
32
+ */
33
+ export type TurnRoutePhase = 'accepted' | 'preparing';
34
+ /** The data of a {@link TURN_PHASE_EVENT}. */
35
+ export type TurnPhaseData = {
36
+ /** Stage id: a {@link TurnRoutePhase} or a product's own stage. */
37
+ phase: string;
38
+ /** Text the client shows verbatim. */
39
+ message: string;
40
+ /** A keepalive for the current stage rather than a new stage. */
41
+ heartbeat?: boolean;
42
+ /** Milliseconds since the current wait began. */
43
+ elapsedMs?: number;
44
+ /** Milliseconds since the server received the request. */
45
+ sinceRequestMs?: number;
46
+ };
47
+ /** A {@link TURN_PHASE_EVENT} as it crosses the wire. */
48
+ export type TurnPhaseEvent = {
49
+ type: typeof TURN_PHASE_EVENT;
50
+ data: TurnPhaseData;
51
+ };
52
+ /** Default text for the route's own stages. Products override it through `createChatTurnRoutes({ progressMessages })`. */
53
+ export declare const TURN_ROUTE_PHASE_MESSAGES: Record<TurnRoutePhase, string>;
54
+ /** Build a {@link TURN_PHASE_EVENT}. */
55
+ export declare function buildTurnPhaseEvent(phase: string, message: string, opts?: {
56
+ heartbeat?: boolean;
57
+ elapsedMs?: number;
58
+ sinceRequestMs?: number;
59
+ }): TurnPhaseEvent;
60
+ /** True for a {@link TURN_PHASE_EVENT} with a usable `phase` and `message`. */
61
+ export declare function isTurnPhaseEvent(event: unknown): event is TurnPhaseEvent;
62
+ /** Terminal event of a progress-first stream that ended without a turn: the response the route returned instead. */
63
+ export declare const TURN_RESPONSE_EVENT = "turn.response";
64
+ /** The data of a {@link TURN_RESPONSE_EVENT}. */
65
+ export type TurnResponseData = {
66
+ status: number;
67
+ /** Response headers other than `set-cookie` and framing headers. */
68
+ headers: Record<string, string>;
69
+ body: string;
70
+ };
71
+ /** Error code {@link settleTurnResponse} reports when a progress-first stream closes before the turn started. */
72
+ export declare const TURN_STREAM_LOST_CODE = "turn_stream_lost";
73
+ /** Serialize a non-stream response for a {@link TURN_RESPONSE_EVENT}. */
74
+ export declare function turnResponseEventFor(response: Response): Promise<{
75
+ type: typeof TURN_RESPONSE_EVENT;
76
+ data: TurnResponseData;
77
+ }>;
78
+ /**
79
+ * Settle a turn response for a client that sent {@link TURN_PROGRESS_HEADER}.
80
+ *
81
+ * Reads the stream's leading progress events, handing each to `onPhase`, until
82
+ * the first other event. A {@link TURN_RESPONSE_EVENT} resolves to a `Response`
83
+ * with the original status, headers and body, so the caller's existing error
84
+ * handling runs unchanged. Any other event resolves to a `Response` whose body
85
+ * starts at that event and continues with the rest of the stream. A response
86
+ * that is not progress-first is returned as it is.
87
+ */
88
+ export declare function settleTurnResponse(response: Response, onPhase: (phase: TurnPhaseData) => void): Promise<Response>;
@@ -52,6 +52,7 @@ import { type DraftPersistenceTuning } from './draft-persistence';
52
52
  import { type InteractionAnswerRoute, type InteractionAnswerRouteOptions } from '../interactions/route';
53
53
  import { type PersistedChatMessageForTurn, type TurnEventStore } from '../stream/index';
54
54
  import type { ModelFailoverAttempt } from '../model-resolution/failover';
55
+ import { type TurnRoutePhase } from './turn-progress';
55
56
  import { type ChatTurnPartInput, type ChatTurnRequestPayload } from './wire';
56
57
  /** Usage receipt persisted onto the assistant message (the flattened
57
58
  * `step-finish` shape `/chat-store`'s columns mirror). */
@@ -553,6 +554,9 @@ export interface CreateChatTurnRoutesOptions<TContext = void> {
553
554
  pollMs?: number;
554
555
  timeoutMs?: number;
555
556
  };
557
+ /** Text for the route's own stages on a progress-first stream (`./turn-progress`).
558
+ * Omitted stages keep `TURN_ROUTE_PHASE_MESSAGES`. */
559
+ progressMessages?: Partial<Record<TurnRoutePhase, string>>;
556
560
  log?: (message: string, meta?: Record<string, unknown>) => void;
557
561
  }
558
562
  /** Define routes to run, replay, and list running chat turns with streaming and reconnect support */
@@ -560,7 +564,9 @@ export interface ChatTurnRoutes {
560
564
  /** POST — run one turn, streaming NDJSON. First line is
561
565
  * `{type:'turn', turnId}` (the replay handle); the rest is the engine's
562
566
  * event protocol. Pass the platform's `waitUntil` so the turn keeps
563
- * running (and buffering) after a client disconnect. */
567
+ * running (and buffering) after a client disconnect. A request with
568
+ * `TURN_PROGRESS_HEADER` gets a progress-first stream instead
569
+ * (`./turn-progress`). */
564
570
  turn(request: Request, ctx?: ChatTurnRequestContext): Promise<Response>;
565
571
  /** GET — replay a buffered turn from `?fromSeq=` (0 = everything), then
566
572
  * follow it live until it completes. */
@@ -157,7 +157,9 @@ export interface ChatTurnRequestPayload {
157
157
  /** `fetch` init for the turn route — the one place the client wire shape is
158
158
  * serialized, so composer glue and products never drift from the server's
159
159
  * parser. */
160
- export declare function chatTurnRequestInit(payload: ChatTurnRequestPayload): RequestInit;
160
+ export declare function chatTurnRequestInit(payload: ChatTurnRequestPayload, options?: {
161
+ progressFirst?: boolean;
162
+ }): RequestInit;
161
163
  /** Define the maximum byte size allowed for inline parts in data processing */
162
164
  export declare const INLINE_PARTS_MAX_BYTES = 950000;
163
165
  /** Hard cap on the whole `/prompt` request body as it crosses the sandbox
@@ -14,8 +14,8 @@ import {
14
14
  mentionInputToPart,
15
15
  mentionPartsFromMessageParts,
16
16
  toChatMessageParts
17
- } from "../chunk-FPCIJCS3.js";
18
- import "../chunk-HOZMP3AR.js";
17
+ } from "../chunk-IKESHQ5B.js";
18
+ import "../chunk-VC5AGH7C.js";
19
19
  import "../chunk-ZVEEWGDK.js";
20
20
  import "../chunk-TXD5HXLE.js";
21
21
  import {