@anvia/client 1.0.0-rc.2 → 1.0.0-rc.4

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/README.md CHANGED
@@ -9,13 +9,16 @@ import { completionToClientStream, parseClientStreamRequest } from "@anvia/clien
9
9
  import { streamCompletion } from "@anvia/core";
10
10
 
11
11
  const request = parseClientStreamRequest(await httpRequest.json());
12
+ if (request.type !== "messages") throw new Error("This endpoint does not resume interactions.");
12
13
  const events = completionToClientStream({
13
14
  events: streamCompletion({ model, messages: request.messages }),
14
15
  });
15
16
  ```
16
17
 
17
18
  The request carries core `Message[]`; client-side `UIMessage[]` never crosses the server boundary.
18
- The response uses `ClientStreamEvent` records inside an always-framed `anvia.client.v2` stream.
19
+ The response uses `ClientStreamEvent` records inside an always-framed `anvia.client.v3` stream.
20
+ Agent endpoints accept either a `messages` request or an `interaction_response` request, while
21
+ keeping the matching `AgentContinuation` exclusively on the server.
19
22
 
20
23
  ## Public API
21
24
 
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { AgentStreamEvent } from '@anvia/core/agent';
1
+ import { AgentInteractionRequest, AgentInteractionResponse, AgentStreamEvent } from '@anvia/core/agent';
2
2
  import { JsonValue, JsonObject, ReasoningContentType, ReasoningDetail, ToolResultContentPart, CompletionSource, ImageDetail, ProviderToolCall, Usage, ContextUsage, Message, CompletionStreamEvent } from '@anvia/core/completion';
3
3
  import { GuardrailDecisionRecord } from '@anvia/core/guardrails';
4
4
  import { MemoryCompactionInfo } from '@anvia/core/memory';
5
5
  import { C as CreateFetchEventTransportOptions } from './event-transport-CC5RD-hT.js';
6
6
 
7
- declare const CLIENT_STREAM_PROTOCOL: "anvia.client.v2";
7
+ declare const CLIENT_STREAM_PROTOCOL: "anvia.client.v3";
8
8
  type ClientDataMap = Record<string, JsonValue>;
9
9
  type ClientMetadata = JsonObject;
10
10
  type ClientDataSchema<T extends JsonValue = JsonValue> = {
@@ -31,7 +31,7 @@ type ClientStreamError = {
31
31
  type UIError = ClientStreamError;
32
32
  type UIMessageGeneration = {
33
33
  runId?: string;
34
- status?: "completed" | "blocked" | "approval_required" | "cancelled" | "error";
34
+ status?: "completed" | "blocked" | "suspended" | "cancelled" | "error";
35
35
  usage?: Usage;
36
36
  contextUsage?: ContextUsage;
37
37
  trace?: {
@@ -116,9 +116,16 @@ type ClientStreamCursor = {
116
116
  streamId: string;
117
117
  after: number;
118
118
  };
119
- type ClientStreamRequest = {
119
+ type ClientStreamRequest<Metadata extends JsonObject = JsonObject> = {
120
+ type: "messages";
120
121
  messages: readonly Message[];
121
- metadata?: JsonObject;
122
+ metadata?: Metadata;
123
+ resume?: ClientStreamCursor;
124
+ } | {
125
+ type: "interaction_response";
126
+ interactionId: string;
127
+ response: AgentInteractionResponse;
128
+ metadata?: Metadata;
122
129
  resume?: ClientStreamCursor;
123
130
  };
124
131
  type ClientCompletionRequest<Metadata extends JsonObject = JsonObject> = {
@@ -133,53 +140,11 @@ type ClientStreamScope = {
133
140
  parentToolCallId?: string;
134
141
  parentInternalToolCallId?: string;
135
142
  };
136
- type ClientToolApprovalStatus = "pending" | "approved" | "rejected" | "timed_out" | "cancelled";
137
- type ToolApproval = {
138
- id: string;
139
- runId?: string;
140
- agentId?: string;
141
- sessionId?: string;
142
- toolName: string;
143
- callId?: string;
144
- internalCallId?: string;
145
- input?: JsonValue;
146
- status: ClientToolApprovalStatus;
147
- requestedAt?: string;
148
- resolvedAt?: string;
149
- reason?: string;
150
- };
151
- type ToolQuestionStatus = "pending" | "answered" | "cancelled";
152
- type ToolQuestionChoice = {
153
- label: string;
154
- value: string;
155
- };
156
- type ToolQuestionPrompt = {
157
- id: string;
158
- question: string;
159
- choices: ToolQuestionChoice[];
160
- };
161
- type ToolQuestionAnswer = {
162
- questionId: string;
163
- answer: string;
164
- choice?: string;
165
- custom?: boolean;
166
- };
167
- type ToolQuestion = {
168
- id: string;
169
- runId?: string;
170
- agentId?: string;
171
- sessionId?: string;
172
- toolName: string;
173
- callId?: string;
174
- internalCallId?: string;
175
- input?: JsonValue;
176
- questions: ToolQuestionPrompt[];
177
- status: ToolQuestionStatus;
178
- requestedAt?: string;
179
- answeredAt?: string;
180
- cancelledAt?: string;
181
- answers?: ToolQuestionAnswer[];
182
- };
143
+ type ClientInteraction = Readonly<{
144
+ request: AgentInteractionRequest;
145
+ runId: string;
146
+ status: "pending" | "responded" | "cancelled";
147
+ }>;
183
148
  type ClientStreamEventBase = {
184
149
  runId: string;
185
150
  turn?: number;
@@ -300,11 +265,8 @@ type ClientStandardStreamEvent<Metadata extends JsonObject, Data extends ClientD
300
265
  type: "provider_tool_call";
301
266
  toolCall: ProviderToolCall;
302
267
  } | {
303
- type: "tool_approval";
304
- approval: ToolApproval;
305
- } | {
306
- type: "tool_question";
307
- question: ToolQuestion;
268
+ type: "interaction";
269
+ interaction: AgentInteractionRequest;
308
270
  } | {
309
271
  type: "guardrail_decision";
310
272
  decision: GuardrailDecisionRecord;
@@ -326,7 +288,7 @@ type ClientStandardStreamEvent<Metadata extends JsonObject, Data extends ClientD
326
288
  firstDeltaMs?: number;
327
289
  } | {
328
290
  type: "run_end";
329
- status: "completed" | "blocked" | "approval_required" | "cancelled" | "error";
291
+ status: "completed" | "blocked" | "suspended" | "cancelled" | "error";
330
292
  text?: string;
331
293
  output?: JsonValue;
332
294
  usage?: Usage;
@@ -458,4 +420,4 @@ declare function applyClientStreamEvent<Metadata extends JsonObject, Data extend
458
420
  declare function messageText<Metadata extends JsonObject, Data extends ClientDataMap>(message: UIMessage<Metadata, Data>): string;
459
421
  declare function assistantText<Metadata extends JsonObject, Data extends ClientDataMap>(messages: readonly UIMessage<Metadata, Data>[]): string;
460
422
 
461
- export { type AgentClientStreamContext, type AgentClientStreamOptions, CLIENT_STREAM_PROTOCOL, type ClientCompletionRequest, type ClientDataMap, type ClientDataSchema, type ClientDataSchemas, type ClientErrorMapper, type ClientMetadata, type ClientMetadataSchema, type ClientOutputMapper, ClientProtocolError, type ClientStream, type ClientStreamAdapterOptions, type ClientStreamCursor, type ClientStreamError, type ClientStreamEvent, type ClientStreamFrame, type ClientStreamRequest, type ClientStreamScope, type ClientToolApprovalStatus, type ClientTransport, type ClientTransportSendOptions, type CompletionClientStreamOptions, type CreateDirectClientTransportOptions, type CreateHttpClientTransportOptions, type CreateUIAttachment, type ToolApproval, type ToolQuestion, type ToolQuestionAnswer, type ToolQuestionChoice, type ToolQuestionPrompt, type ToolQuestionStatus, type UIAttachment, type UIError, type UIMessage, type UIMessageGeneration, type UIMessagePart, type UIMessageRole, type UIToolMessagePart, agentToClientStream, applyClientStreamEvent, assistantText, completionToClientStream, createClientId, createDirectClientTransport, createHttpClientTransport, customAgentEventsToClientStream, maskedClientError, messageText, messagesToUIMessages, normalizeClientError, parseClientStreamEvent, parseClientStreamFrame, parseClientStreamRequest, parseUIMessage, parseUIMessages, uiMessagesToMessages };
423
+ export { type AgentClientStreamContext, type AgentClientStreamOptions, CLIENT_STREAM_PROTOCOL, type ClientCompletionRequest, type ClientDataMap, type ClientDataSchema, type ClientDataSchemas, type ClientErrorMapper, type ClientInteraction, type ClientMetadata, type ClientMetadataSchema, type ClientOutputMapper, ClientProtocolError, type ClientStream, type ClientStreamAdapterOptions, type ClientStreamCursor, type ClientStreamError, type ClientStreamEvent, type ClientStreamFrame, type ClientStreamRequest, type ClientStreamScope, type ClientTransport, type ClientTransportSendOptions, type CompletionClientStreamOptions, type CreateDirectClientTransportOptions, type CreateHttpClientTransportOptions, type CreateUIAttachment, type UIAttachment, type UIError, type UIMessage, type UIMessageGeneration, type UIMessagePart, type UIMessageRole, type UIToolMessagePart, agentToClientStream, applyClientStreamEvent, assistantText, completionToClientStream, createClientId, createDirectClientTransport, createHttpClientTransport, customAgentEventsToClientStream, maskedClientError, messageText, messagesToUIMessages, normalizeClientError, parseClientStreamEvent, parseClientStreamFrame, parseClientStreamRequest, parseUIMessage, parseUIMessages, uiMessagesToMessages };