cortena-ui 1.5.0 → 1.7.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.
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { A2UIChatBlock } from "./a2ui-block.js";
3
- import { AgentApprovalDecision, AgentApprovalRequest, AgentChatClient, AgentChatMessage, AgentSession } from "./types.js";
3
+ import { AgentApprovalDecision, AgentApprovalRequest, AgentChatClient, AgentChatMessage, AgentChatSendInput, AgentChatStep, AgentSession, AgentToolResultMetadata } from "./types.js";
4
4
  //#region src/agent-chat/store.d.ts
5
5
  export interface AgentToolEntry {
6
6
  id: string;
@@ -23,6 +23,26 @@ export interface AgentChatState {
23
23
  loadingHistory: boolean;
24
24
  toolOrder: string[];
25
25
  tools: Record<string, AgentToolEntry>;
26
+ /**
27
+ * The turn's tool calls in plain words, in arrival order (SKILLS-9).
28
+ *
29
+ * The same calls as `tools`, worded rather than dumped, and rendered under
30
+ * the assistant turn instead of in the strip at the foot. Cleared when the
31
+ * next run starts, so the list is always "what is happening now" or "what
32
+ * just happened", never a transcript.
33
+ */
34
+ steps: AgentChatStep[];
35
+ /**
36
+ * Ids of steps the `STEP_LIMIT` cap has already dropped.
37
+ *
38
+ * A runaway turn pushes the first calls off the front of the list, and their
39
+ * results arrive afterwards. Without this the store saw an id it did not
40
+ * know, took it for a call nobody announced, and appended a fresh
41
+ * "Working: tool" line at the BOTTOM of the strip — the oldest call in the
42
+ * turn, drawn as the newest, with no words on it. Bounded, because it exists
43
+ * to recognise a handful of stragglers, not to keep a transcript.
44
+ */
45
+ retiredSteps: string[];
26
46
  approvals: AgentApprovalRequest[];
27
47
  /**
28
48
  * Transcript RECORDS loaded, which is not `messages.length`.
@@ -40,6 +60,21 @@ export interface AgentChatState {
40
60
  /** A failure the user has to be told about, e.g. no template for the slug. */
41
61
  error: string | null;
42
62
  }
63
+ /**
64
+ * `TOOL_CALL_RESULT.metadata`, read defensively.
65
+ *
66
+ * `null` when nothing usable arrived, which a transport that predates the
67
+ * contract will produce. A step with no metadata at all is treated as a
68
+ * success by `tool.complete` and as a failure by `tool.error`, which is the
69
+ * most either event can honestly claim on its own.
70
+ *
71
+ * Note what is NOT here: any reading of `content`. The result text is the
72
+ * model's copy of the reply, in whatever shape the tool returned, and the
73
+ * client's previous attempt to find `ok: false` in it matched nothing real —
74
+ * a Cortena tool result is `{ content: [...], details }`, so the envelope it
75
+ * was looking for was two levels down when it existed at all.
76
+ */
77
+ export declare function readResultMetadata(raw: unknown): AgentToolResultMetadata | null;
43
78
  export interface UseAgentChatOptions {
44
79
  client: AgentChatClient;
45
80
  /**
@@ -51,17 +86,68 @@ export interface UseAgentChatOptions {
51
86
  /** Skip reading and writing `sessionStorage`; for a transient mount. */
52
87
  ephemeral?: boolean;
53
88
  thinking?: "low" | "medium" | "high";
89
+ /**
90
+ * Mint the key for a brand-new session. Defaults to `mintSessionKey(client.agentId)`,
91
+ * which binds the session to this client's agent template. A host whose
92
+ * sessions are bound some other way — cortenaweb lets the user pick an agent
93
+ * per chat, and a chat with no pick is bound server-side to the default —
94
+ * supplies its own.
95
+ */
96
+ mintSessionKey?: () => string;
97
+ /**
98
+ * Read the stored session key back on mount. Default `true`. A host whose
99
+ * URL names the session — `/chat/<key>` — is the source of truth itself and
100
+ * passes `false`: the key is still WRITTEN, so the rule "one window, one
101
+ * session" holds, but nothing is restored under the URL's feet and no
102
+ * history is fetched for a session the page is about to leave.
103
+ */
104
+ restoreSession?: boolean;
105
+ /**
106
+ * Fetch `sessions.list` on mount and after each send. Default `true`. A host
107
+ * with its own session list — cortenaweb's sidebar — passes `false` and the
108
+ * hook makes no session calls at all; `sessions` stays empty.
109
+ */
110
+ listSessions?: boolean;
111
+ }
112
+ /** What `send` accepts beside the text and the attachments. */
113
+ export interface AgentChatSendOptions {
114
+ /** The model for this run; the composer's selector. */
115
+ model?: AgentChatSendInput["model"];
116
+ /** Overrides the hook-level `thinking` for this run. */
117
+ thinking?: AgentChatSendInput["thinking"];
54
118
  }
55
119
  export interface UseAgentChatResult extends AgentChatState {
56
- send: (text: string, attachments?: unknown[]) => void;
120
+ send: (text: string, attachments?: unknown[], options?: AgentChatSendOptions) => void;
57
121
  sendAction: (action: NonNullable<Parameters<AgentChatClient["send"]>[0]["a2uiAction"]>) => void;
122
+ /** A click inside a rendered MCP App, as the next run's input. No user bubble. */
123
+ sendMcpAppAction: (action: NonNullable<AgentChatSendInput["mcpAppAction"]>) => void;
58
124
  abort: () => void;
59
125
  resolveApproval: (id: string, decision: AgentApprovalDecision) => void;
60
126
  newSession: () => void;
61
127
  resumeSession: (key: string) => void;
62
- loadOlder: () => void;
128
+ /**
129
+ * Leave the session without starting another. The transcript empties, the
130
+ * stored key is removed and the next `send` mints a fresh key — which is
131
+ * what a host's "New chat" wants when the URL should not change until the
132
+ * first message goes out. `newSession` mints immediately; this does not.
133
+ */
134
+ clearSession: () => void;
135
+ /**
136
+ * Ask again for the message this one answered: the bubble is dropped and the
137
+ * user turn before it is sent again, so the new answer takes its place. Also
138
+ * the Retry on a failed turn. A no-op while a run is live or when nothing
139
+ * precedes the message.
140
+ */
141
+ regenerate: (messageId: string) => void;
142
+ /**
143
+ * Ask for the next page of older history. `true` when a load was started;
144
+ * `false` when there is nothing to do — no session, a load already in
145
+ * flight, or no more history — so a caller that saves scroll position
146
+ * before a prepend knows whether one is coming.
147
+ */
148
+ loadOlder: () => boolean;
63
149
  refreshSessions: () => void;
64
150
  }
65
- export declare function useAgentChat({ client, storageScope, ephemeral, thinking }: UseAgentChatOptions): UseAgentChatResult;
151
+ export declare function useAgentChat({ client, storageScope, ephemeral, thinking, mintSessionKey: mintKey, restoreSession, listSessions }: UseAgentChatOptions): UseAgentChatResult;
66
152
  //#endregion
67
153
  //# sourceMappingURL=store.d.ts.map