@tangle-network/agent-app 0.60.112 → 0.60.113

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.
@@ -69,6 +69,29 @@ export declare function buildTurnPhaseEvent(phase: string, message: string, opts
69
69
  }): TurnPhaseEvent;
70
70
  /** True for a {@link TURN_PHASE_EVENT} with a usable `phase` and `message`. */
71
71
  export declare function isTurnPhaseEvent(event: unknown): event is TurnPhaseEvent;
72
+ /**
73
+ * Stream event carrying the turn's intent line: one plain sentence, written by
74
+ * a fast model call at admission, saying what the agent is about to do ("Looking
75
+ * at your three competitors' pricing pages, then I'll draft the comparison.").
76
+ * A client shows it as a labeled status line, never as the answer, until the
77
+ * turn's first answer text replaces it. It narrates intent; it never answers
78
+ * or acts. Non-terminal and never turn content; at most one per turn.
79
+ */
80
+ export declare const TURN_INTENT_EVENT = "session.run.intent";
81
+ /** The data of a {@link TURN_INTENT_EVENT}. */
82
+ export type TurnIntentData = {
83
+ /** The sentence, shown verbatim. */
84
+ text: string;
85
+ /** Milliseconds since the server received the request. */
86
+ sinceRequestMs?: number;
87
+ };
88
+ /** A {@link TURN_INTENT_EVENT} as it crosses the wire. */
89
+ export type TurnIntentEvent = {
90
+ type: typeof TURN_INTENT_EVENT;
91
+ data: TurnIntentData;
92
+ };
93
+ /** True for a {@link TURN_INTENT_EVENT} with non-empty text. */
94
+ export declare function isTurnIntentEvent(event: unknown): event is TurnIntentEvent;
72
95
  /** Terminal event of a progress-first stream that ended without a turn: the response the route returned instead. */
73
96
  export declare const TURN_RESPONSE_EVENT = "turn.response";
74
97
  /** The data of a {@link TURN_RESPONSE_EVENT}. */
@@ -88,11 +111,12 @@ export declare function turnResponseEventFor(response: Response): Promise<{
88
111
  /**
89
112
  * Settle a turn response for a client that sent {@link TURN_PROGRESS_HEADER}.
90
113
  *
91
- * Reads the stream's leading progress events, handing each to `onPhase`, until
92
- * the first other event. A {@link TURN_RESPONSE_EVENT} resolves to a `Response`
114
+ * Reads the stream's leading progress events, handing each to `onPhase` (and an
115
+ * intent line to `onIntent`, or dropping it when there is none), until the
116
+ * first other event. A {@link TURN_RESPONSE_EVENT} resolves to a `Response`
93
117
  * with the original status, headers and body, so the caller's existing error
94
118
  * handling runs unchanged. Any other event resolves to a `Response` whose body
95
119
  * starts at that event and continues with the rest of the stream. A response
96
120
  * that is not progress-first is returned as it is.
97
121
  */
98
- export declare function settleTurnResponse(response: Response, onPhase: (phase: TurnPhaseData) => void): Promise<Response>;
122
+ export declare function settleTurnResponse(response: Response, onPhase: (phase: TurnPhaseData) => void, onIntent?: (intent: TurnIntentData) => void): Promise<Response>;
@@ -252,6 +252,10 @@ export interface ChatTurnProduceArgs<TContext> {
252
252
  /** The turn-buffer id announced to the client for replay. */
253
253
  turnStreamId: string;
254
254
  priorMessages: PersistedChatMessageForTurn[];
255
+ /** The turn's intent line (`intentLine`), or null when it was off, slow or
256
+ * failed. Never rejects. A product puts it in the harness turn's context so
257
+ * the agent knows what the founder was told it would do. */
258
+ intentLine?: Promise<string | null>;
255
259
  /** Server-authenticated limits for this turn. Never copied from the body. */
256
260
  executionLimits?: ChatTurnExecutionLimits;
257
261
  /** The durable `role:'user'` row this turn is anchored to — the row the
@@ -599,8 +603,44 @@ export interface CreateChatTurnRoutesOptions<TContext = void> {
599
603
  /** Text for the route's own stages on a progress-first stream (`./turn-progress`).
600
604
  * Omitted stages keep `TURN_ROUTE_PHASE_MESSAGES`. */
601
605
  progressMessages?: Partial<Record<TurnRoutePhase, string>>;
606
+ /** Write and stream the turn's intent line ({@link ChatTurnIntentLine}). Omit → no line. */
607
+ intentLine?: ChatTurnIntentLine<TContext>;
602
608
  log?: (message: string, meta?: Record<string, unknown>) => void;
603
609
  }
610
+ /** What `intentLine.generate` receives: the admitted turn's message and the thread's last few turns. */
611
+ export interface ChatTurnIntentLineArgs<TContext> {
612
+ content: string;
613
+ /** The thread's last turns before this one, oldest first (at most {@link INTENT_LINE_HISTORY_MESSAGES}). */
614
+ history: ReadonlyArray<{
615
+ role: 'user' | 'assistant' | 'system' | 'tool';
616
+ content: string;
617
+ }>;
618
+ tenantId: string;
619
+ userId: string;
620
+ threadId: string;
621
+ context: TContext;
622
+ /** Aborted when the line is no longer wanted (its deadline passed). */
623
+ signal: AbortSignal;
624
+ }
625
+ /**
626
+ * The intent line: one plain sentence, written by a fast model call the moment
627
+ * a turn is admitted, saying what the agent is about to do. It reaches a
628
+ * progress-first client as a {@link TURN_INTENT_EVENT} while the harness boots,
629
+ * and the turn's first answer text replaces it. It narrates intent and must
630
+ * never answer or act. It fails open: a line later than `timeoutMs`, an error,
631
+ * or an empty answer shows nothing.
632
+ */
633
+ export interface ChatTurnIntentLine<TContext> {
634
+ generate(args: ChatTurnIntentLineArgs<TContext>): Promise<string | null>;
635
+ /** Longest wait for the line. Default {@link INTENT_LINE_TIMEOUT_MS}. */
636
+ timeoutMs?: number;
637
+ }
638
+ /** A line slower than this shows nothing. */
639
+ export declare const INTENT_LINE_TIMEOUT_MS = 1500;
640
+ /** Turns of the thread the line is written from. */
641
+ export declare const INTENT_LINE_HISTORY_MESSAGES = 6;
642
+ /** Longest line kept; anything longer is cut. */
643
+ export declare const INTENT_LINE_MAX_CHARS = 240;
604
644
  /** Define routes to run, replay, and list running chat turns with streaming and reconnect support */
605
645
  export interface ChatTurnRoutes {
606
646
  /** POST — run one turn, streaming NDJSON. First line is
@@ -14,9 +14,9 @@ import {
14
14
  mentionInputToPart,
15
15
  mentionPartsFromMessageParts,
16
16
  toChatMessageParts
17
- } from "../chunk-2YLSWZ5W.js";
17
+ } from "../chunk-4G7HH6WQ.js";
18
18
  import "../chunk-ZVEEWGDK.js";
19
- import "../chunk-6E7LKHYV.js";
19
+ import "../chunk-6XE77PTT.js";
20
20
  import "../chunk-TXD5HXLE.js";
21
21
  import {
22
22
  attachmentPartKey
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ZVEEWGDK.js";
4
4
  import {
5
5
  mentionKindForPath
6
- } from "./chunk-6E7LKHYV.js";
6
+ } from "./chunk-6XE77PTT.js";
7
7
  import {
8
8
  persistedPartToInteraction
9
9
  } from "./chunk-6VQCFJWP.js";
@@ -135,4 +135,4 @@ export {
135
135
  buildAttachmentPromptBlock,
136
136
  historyContentWithAttachments
137
137
  };
138
- //# sourceMappingURL=chunk-2YLSWZ5W.js.map
138
+ //# sourceMappingURL=chunk-4G7HH6WQ.js.map
@@ -33,12 +33,14 @@ import {
33
33
  } from "./chunk-LSUELMHY.js";
34
34
  import {
35
35
  attachmentPartsFromMessageParts
36
- } from "./chunk-2YLSWZ5W.js";
36
+ } from "./chunk-4G7HH6WQ.js";
37
37
  import {
38
+ TURN_INTENT_EVENT,
38
39
  TURN_PHASE_EVENT,
40
+ isTurnIntentEvent,
39
41
  isTurnPhaseEvent,
40
42
  settleTurnResponse
41
- } from "./chunk-6E7LKHYV.js";
43
+ } from "./chunk-6XE77PTT.js";
42
44
  import {
43
45
  cancelStatusFor,
44
46
  fieldAcceptsFreeText,
@@ -1352,6 +1354,9 @@ function dispatchChatStreamLine(line, cb) {
1352
1354
  case TURN_PHASE_EVENT:
1353
1355
  if (isTurnPhaseEvent(evt)) cb.onPhase?.(evt.data);
1354
1356
  break;
1357
+ case TURN_INTENT_EVENT:
1358
+ if (isTurnIntentEvent(evt)) cb.onIntent?.(evt.data);
1359
+ break;
1355
1360
  case "text":
1356
1361
  if (typeof evt.text === "string") {
1357
1362
  cb.onText?.(evt.text);
@@ -6799,4 +6804,4 @@ export {
6799
6804
  useThinkingSeconds,
6800
6805
  ChatMessages
6801
6806
  };
6802
- //# sourceMappingURL=chunk-FERGTHQF.js.map
6807
+ //# sourceMappingURL=chunk-56GPDCOJ.js.map