@sinas/sdk 0.7.0 → 0.8.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.
- package/dist/{chunk-QDIOYYBA.js → chunk-RHQVV5O6.js} +220 -99
- package/dist/chunk-RHQVV5O6.js.map +1 -0
- package/dist/client.cjs +226 -98
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +228 -5
- package/dist/client.d.ts +228 -5
- package/dist/client.js +17 -1
- package/dist/index.cjs +494 -244
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -4
- package/dist/index.d.ts +62 -4
- package/dist/index.js +286 -147
- package/dist/index.js.map +1 -1
- package/dist/sinas-sdk.umd.js +486 -244
- package/dist/sinas-sdk.umd.js.map +1 -1
- package/package.json +6 -3
- package/dist/chunk-QDIOYYBA.js.map +0 -1
package/dist/client.d.ts
CHANGED
|
@@ -139,6 +139,12 @@ interface ChatDetail {
|
|
|
139
139
|
title: string;
|
|
140
140
|
messages: ChatMessageFull[];
|
|
141
141
|
pendingApprovals: ApprovalRequest[];
|
|
142
|
+
/**
|
|
143
|
+
* The ask_user questions the chat is suspended on. Present when the
|
|
144
|
+
* server reports them (Sinas 0.5+); undefined on older servers, which
|
|
145
|
+
* have no ask_user.
|
|
146
|
+
*/
|
|
147
|
+
pendingInputs?: PendingInput[];
|
|
142
148
|
}
|
|
143
149
|
interface ApprovalRequest {
|
|
144
150
|
type: string;
|
|
@@ -147,10 +153,133 @@ interface ApprovalRequest {
|
|
|
147
153
|
functionName: string;
|
|
148
154
|
arguments: Record<string, unknown>;
|
|
149
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* What happens to the round after an approval decision (Sinas 0.5+).
|
|
158
|
+
* `waiting`: other calls of the same round still wait for a decision, so
|
|
159
|
+
* nothing resumes yet and there is nothing to stream. `queued`: this was the
|
|
160
|
+
* round's last decision; the round resumes on `channelId` (this includes a
|
|
161
|
+
* final rejection, which the model gets as a rejection result).
|
|
162
|
+
*/
|
|
163
|
+
type ApprovalResume = 'waiting' | 'queued';
|
|
150
164
|
interface ApprovalResult {
|
|
151
165
|
status: string;
|
|
152
166
|
toolCallId: string;
|
|
153
167
|
channelId: string;
|
|
168
|
+
/** Undefined on servers before Sinas 0.5, which resume on every approval. */
|
|
169
|
+
resume?: ApprovalResume;
|
|
170
|
+
message?: string;
|
|
171
|
+
}
|
|
172
|
+
interface ApproveToolCallOptions {
|
|
173
|
+
/**
|
|
174
|
+
* Approve this tool for the rest of the chat: later calls of the same tool
|
|
175
|
+
* skip the ask. Only applies to an approval (ignored when rejecting).
|
|
176
|
+
*/
|
|
177
|
+
alwaysAllow?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/** An ask_user question the conversation is suspended on. */
|
|
180
|
+
interface PendingInput {
|
|
181
|
+
toolCallId: string;
|
|
182
|
+
question: string;
|
|
183
|
+
/** Suggested answers, or null for a free-text question. */
|
|
184
|
+
options: string[] | null;
|
|
185
|
+
/** ISO timestamp after which the question expires (the round then resumes without it). */
|
|
186
|
+
expiresAt: string | null;
|
|
187
|
+
createdAt: string | null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* How a synchronously answered turn ended.
|
|
191
|
+
* - `completed`: the final reply is in the response.
|
|
192
|
+
* - `input_required`: the agent asked the user; see `pendingInputs` and
|
|
193
|
+
* answer with `answerPendingInput`.
|
|
194
|
+
* - `in_progress`: the turn goes on without this request; follow it on
|
|
195
|
+
* `channelId` (`streamFromChannel`) or read the chat later.
|
|
196
|
+
* - `injected`: the chat was busy, so the message was delivered into the
|
|
197
|
+
* running (or parked) turn; nothing was answered by this request.
|
|
198
|
+
*/
|
|
199
|
+
type TurnStatus = 'completed' | 'input_required' | 'in_progress' | 'injected';
|
|
200
|
+
/** LLM usage of one request (the reply plus its tool rounds). */
|
|
201
|
+
interface TurnUsage {
|
|
202
|
+
calls: number;
|
|
203
|
+
promptTokens: number;
|
|
204
|
+
completionTokens: number;
|
|
205
|
+
totalTokens: number;
|
|
206
|
+
cacheReadTokens: number;
|
|
207
|
+
cacheWriteTokens: number;
|
|
208
|
+
/** Null when calls were made but none could be priced. */
|
|
209
|
+
costUsd: number | null;
|
|
210
|
+
unpricedCalls: number;
|
|
211
|
+
errors: number;
|
|
212
|
+
}
|
|
213
|
+
interface TurnState {
|
|
214
|
+
status: TurnStatus;
|
|
215
|
+
pendingInputs: PendingInput[];
|
|
216
|
+
/** Channel of the turn still going on (`in_progress`) or of the parked turn (`injected`). */
|
|
217
|
+
channelId: string | null;
|
|
218
|
+
/** Null when the server could not determine it (or predates Sinas 0.5). */
|
|
219
|
+
usage: TurnUsage | null;
|
|
220
|
+
}
|
|
221
|
+
/** Result of a non-streaming `sendMessage`. The base fields are unchanged; the turn state is Sinas 0.5+. */
|
|
222
|
+
interface MessageSendResult extends ChatMessage, TurnState {
|
|
223
|
+
}
|
|
224
|
+
interface InvokeOptions {
|
|
225
|
+
/** Session key for conversation continuity across invokes. */
|
|
226
|
+
sessionKey?: string;
|
|
227
|
+
/** Archive the session's existing chat and start fresh. */
|
|
228
|
+
reset?: boolean;
|
|
229
|
+
/** Agent input variables (only used when a new chat is created). */
|
|
230
|
+
input?: Record<string, unknown>;
|
|
231
|
+
}
|
|
232
|
+
interface InvokeResult extends TurnState {
|
|
233
|
+
/** The final reply (`completed`); what the agent said before asking or waiting otherwise; empty when `injected`. */
|
|
234
|
+
reply: string;
|
|
235
|
+
chatId: string;
|
|
236
|
+
sessionKey: string | null;
|
|
237
|
+
}
|
|
238
|
+
interface AnswerPendingInputOptions {
|
|
239
|
+
/**
|
|
240
|
+
* Wait for the resumed turn and return its result instead of a channel to
|
|
241
|
+
* stream it from.
|
|
242
|
+
*/
|
|
243
|
+
wait?: boolean;
|
|
244
|
+
}
|
|
245
|
+
/** The answer was recorded (HTTP 202, without `wait`). */
|
|
246
|
+
interface PendingInputAnswerAccepted {
|
|
247
|
+
status: 'answered';
|
|
248
|
+
toolCallId: string;
|
|
249
|
+
/** The answer was the round's last outstanding completion; its resume is queued. */
|
|
250
|
+
resumed: boolean;
|
|
251
|
+
/** The last completion, but the resume could not be queued yet; it is retried shortly. */
|
|
252
|
+
resumePending: boolean;
|
|
253
|
+
/** Where the resumed turn streams, when `resumed` or `resumePending`. */
|
|
254
|
+
channelId: string | null;
|
|
255
|
+
message: string;
|
|
256
|
+
}
|
|
257
|
+
/** The resumed turn's result (HTTP 200, with `wait: true`). */
|
|
258
|
+
interface PendingInputAnswerResult extends TurnState {
|
|
259
|
+
toolCallId: string;
|
|
260
|
+
chatId: string;
|
|
261
|
+
reply: string;
|
|
262
|
+
/** The message `reply` comes from, when there is one. */
|
|
263
|
+
message: ChatMessageFull | null;
|
|
264
|
+
}
|
|
265
|
+
interface StreamOptions {
|
|
266
|
+
/**
|
|
267
|
+
* Stream the model's thinking text (Sinas 0.5+). Without it, a stream still
|
|
268
|
+
* gets one empty `thinking` when the model starts thinking.
|
|
269
|
+
*/
|
|
270
|
+
includeThinking?: boolean;
|
|
271
|
+
}
|
|
272
|
+
interface StreamFromChannelOptions extends StreamOptions {
|
|
273
|
+
/** Last received stream entry id to resume after (default "0": from the start). */
|
|
274
|
+
lastId?: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* How a stream ended. `completed`: the turn finished. `suspended`: the turn
|
|
278
|
+
* is parked waiting on the user (an ask_user question); the answer resumes it
|
|
279
|
+
* on a new channel. `closed`: the connection ended without a `done` event.
|
|
280
|
+
*/
|
|
281
|
+
interface StreamDone {
|
|
282
|
+
status: 'completed' | 'suspended' | 'closed' | (string & {});
|
|
154
283
|
}
|
|
155
284
|
interface TextContentPart {
|
|
156
285
|
type: 'text';
|
|
@@ -186,6 +315,26 @@ interface SSEChunk {
|
|
|
186
315
|
event: string;
|
|
187
316
|
data: string;
|
|
188
317
|
}
|
|
318
|
+
/** Data of an `input_required` stream event: the agent asked the user (ask_user). */
|
|
319
|
+
interface InputRequiredEvent {
|
|
320
|
+
type: 'input_required';
|
|
321
|
+
tool_call_id: string;
|
|
322
|
+
question: string;
|
|
323
|
+
options?: string[] | null;
|
|
324
|
+
expires_at?: string | null;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Data of a `round_suspended` stream event: the tool round is parked on
|
|
328
|
+
* deferred work (questions, background runs, sub-agents). It resumes on
|
|
329
|
+
* `channel_id` when that work lands by itself.
|
|
330
|
+
*/
|
|
331
|
+
interface RoundSuspendedEvent {
|
|
332
|
+
type: 'round_suspended';
|
|
333
|
+
tool_call_ids: string[];
|
|
334
|
+
channel_id?: string | null;
|
|
335
|
+
pending_completion_id?: string;
|
|
336
|
+
usage?: Record<string, unknown> | null;
|
|
337
|
+
}
|
|
189
338
|
interface Collection {
|
|
190
339
|
id: string;
|
|
191
340
|
namespace: string;
|
|
@@ -380,11 +529,85 @@ declare function stateDelete(client: SinasClient, ns: string, key: string): Prom
|
|
|
380
529
|
declare function stateList(client: SinasClient, ns: string): Promise<StateListResult>;
|
|
381
530
|
|
|
382
531
|
declare function createChat(client: SinasClient, agentRef: string, input?: Record<string, unknown>): Promise<ChatCreateResult>;
|
|
383
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Send a message and wait for the turn (non-streaming). On Sinas 0.5+ the
|
|
534
|
+
* result says how the turn ended (`status`): with `input_required`, answer
|
|
535
|
+
* the questions in `pendingInputs` with `answerPendingInput`.
|
|
536
|
+
*/
|
|
537
|
+
declare function sendMessage(client: SinasClient, chatId: string, content: MessageContent): Promise<MessageSendResult>;
|
|
538
|
+
/**
|
|
539
|
+
* Synchronous agent invoke: send a message, get the reply. Creates the chat
|
|
540
|
+
* (or reuses the one for `sessionKey`). Check `status`: with
|
|
541
|
+
* `input_required`, answer `pendingInputs` via `answerPendingInput`
|
|
542
|
+
* (`{ wait: true }` returns the resumed turn's result the same way).
|
|
543
|
+
*/
|
|
544
|
+
declare function invokeAgent(client: SinasClient, agentRef: string, message: MessageContent, options?: InvokeOptions): Promise<InvokeResult>;
|
|
384
545
|
declare function getChat(client: SinasClient, chatId: string): Promise<ChatDetail>;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
546
|
+
/**
|
|
547
|
+
* Approve or reject a tool call that asked for approval. On Sinas 0.5+,
|
|
548
|
+
* `resume` says whether the round resumes now (`queued`, follow `channelId`)
|
|
549
|
+
* or waits for decisions on its other calls (`waiting`, nothing to stream);
|
|
550
|
+
* `approvalResumeChannel(result, approved)` picks the channel to follow.
|
|
551
|
+
*/
|
|
552
|
+
declare function approveToolCall(client: SinasClient, chatId: string, toolCallId: string, approved: boolean, options?: ApproveToolCallOptions): Promise<ApprovalResult>;
|
|
553
|
+
/** The ask_user questions the chat is suspended on (Sinas 0.5+). */
|
|
554
|
+
declare function listPendingInputs(client: SinasClient, chatId: string): Promise<PendingInput[]>;
|
|
555
|
+
/**
|
|
556
|
+
* Answer an ask_user question; the answer becomes the call's tool result.
|
|
557
|
+
* Without `wait`, resolves once the answer is recorded: follow
|
|
558
|
+
* `answerResumeChannel(result)` (when not null) to stream the resumed turn.
|
|
559
|
+
* With `{ wait: true }`, resolves with the resumed turn's result instead
|
|
560
|
+
* (`input_required` again if the agent asks again).
|
|
561
|
+
*/
|
|
562
|
+
declare function answerPendingInput(client: SinasClient, chatId: string, toolCallId: string, answer: string, options: AnswerPendingInputOptions & {
|
|
563
|
+
wait: true;
|
|
564
|
+
}): Promise<PendingInputAnswerResult>;
|
|
565
|
+
declare function answerPendingInput(client: SinasClient, chatId: string, toolCallId: string, answer: string, options?: AnswerPendingInputOptions & {
|
|
566
|
+
wait?: false;
|
|
567
|
+
}): Promise<PendingInputAnswerAccepted>;
|
|
568
|
+
declare function answerPendingInput(client: SinasClient, chatId: string, toolCallId: string, answer: string, options?: AnswerPendingInputOptions): Promise<PendingInputAnswerAccepted | PendingInputAnswerResult>;
|
|
569
|
+
/**
|
|
570
|
+
* Follow a stream channel: the stream of a resumed round (after an approval
|
|
571
|
+
* or an answer), an `in_progress` turn, or a reconnect.
|
|
572
|
+
*/
|
|
573
|
+
declare function streamFromChannel(client: SinasClient, chatId: string, channelId: string, onChunk: (chunk: SSEChunk) => void, onDone?: (done: StreamDone) => void, onError?: (error: Error) => void, options?: StreamFromChannelOptions): AbortController;
|
|
574
|
+
/** Send a message and stream the turn as SSE events. */
|
|
575
|
+
declare function streamMessage(client: SinasClient, chatId: string, content: MessageContent, onChunk: (chunk: SSEChunk) => void, onDone?: (done: StreamDone) => void, onError?: (error: Error) => void, options?: StreamOptions): AbortController;
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* One ask_user question from the API (`GET /chats/{id}/pending-input`, the
|
|
579
|
+
* chat detail, a turn result, or an `input_required` stream event), or null
|
|
580
|
+
* when the value isn't one.
|
|
581
|
+
*/
|
|
582
|
+
declare function parsePendingInput(raw: unknown): PendingInput | null;
|
|
583
|
+
declare function parsePendingInputs(raw: unknown): PendingInput[];
|
|
584
|
+
/**
|
|
585
|
+
* The question an SSE chunk announces, or null. Streams send it as its own
|
|
586
|
+
* `input_required` event; some earlier backends sent an inline turn's as a
|
|
587
|
+
* `message` event whose data has `type: "input_required"`. Both are handled.
|
|
588
|
+
*/
|
|
589
|
+
declare function pendingInputFromChunk(chunk: SSEChunk): PendingInput | null;
|
|
590
|
+
/**
|
|
591
|
+
* The channel to follow after an approval decision, or null when there is
|
|
592
|
+
* nothing to stream yet. A round with several asked calls resumes once,
|
|
593
|
+
* after its last decision; until then the response says `resume: "waiting"`.
|
|
594
|
+
* On servers before 0.5 (no `resume` field) only an approval resumed.
|
|
595
|
+
*/
|
|
596
|
+
declare function approvalResumeChannel(result: {
|
|
597
|
+
resume?: string | null;
|
|
598
|
+
channelId?: string | null;
|
|
599
|
+
}, approved?: boolean): string | null;
|
|
600
|
+
/**
|
|
601
|
+
* The channel to follow after answering a question (202 response), or null.
|
|
602
|
+
* The answer resumes the conversation only when it was the round's last
|
|
603
|
+
* outstanding completion (`resumed`) or that resume is being retried
|
|
604
|
+
* (`resumePending`).
|
|
605
|
+
*/
|
|
606
|
+
declare function answerResumeChannel(result: {
|
|
607
|
+
resumed?: boolean;
|
|
608
|
+
resumePending?: boolean;
|
|
609
|
+
channelId?: string | null;
|
|
610
|
+
}): string | null;
|
|
388
611
|
|
|
389
612
|
declare function listCollections(client: SinasClient): Promise<Collection[]>;
|
|
390
613
|
declare function listFiles(client: SinasClient, namespace: string, collection: string): Promise<FileInfo[]>;
|
|
@@ -428,4 +651,4 @@ declare class SinasTimeoutError extends SinasError {
|
|
|
428
651
|
constructor(message?: string);
|
|
429
652
|
}
|
|
430
653
|
|
|
431
|
-
export { type AgentBatchItem, type ApprovalRequest, type ApprovalResult, type AudioContentPart, type AuthMode, type AuthUser, type BatchExecutionItem, type BatchStatus, type ChatCreateResult, type ChatDetail, type ChatMessage, type ChatMessageFull, type Collection, type ComponentContentPart, type ContentPart, type EnqueueFunctionOptions, type EnqueueFunctionResult, type FileContentPart, type FileInfo, type FileUploadRequest, type FileUrlResult, type FunctionResult, type ImageContentPart, type InfoResponse, type LoginRequest, type LoginResponse, type MessageContent, type OTPVerifyRequest, type OTPVerifyResponse, type PermissionCheckRequest, type PermissionCheckResponse, type PermissionCheckResult, type QueryResult, type RefreshResponse, type SSEChunk, SinasAuthError, SinasClient, SinasClientAuth, type SinasClientOptions, type SinasConfig, SinasError, SinasNotFoundError, SinasPermissionError, SinasTimeoutError, type StateGetResult, type StateListResult, type SubmitAgentBatchOptions, type SubmitAgentBatchResult, type SubmitFunctionBatchOptions, type SubmitFunctionBatchResult, type TextContentPart, type ToolCallInfo, approveToolCall, cancelBatch, checkPermissions, createChat, enqueueFunction, executeFunction, executeQuery, generateFileUrl, getBatch, getChat, getInfo, getMe, listBatchExecutions, listCollections, listFiles, login, logout, refresh, sendMessage, stateDelete, stateGet, stateList, stateSet, streamFromChannel, streamMessage, submitAgentBatch, submitFunctionBatch, uploadFile, verifyOTP };
|
|
654
|
+
export { type AgentBatchItem, type AnswerPendingInputOptions, type ApprovalRequest, type ApprovalResult, type ApprovalResume, type ApproveToolCallOptions, type AudioContentPart, type AuthMode, type AuthUser, type BatchExecutionItem, type BatchStatus, type ChatCreateResult, type ChatDetail, type ChatMessage, type ChatMessageFull, type Collection, type ComponentContentPart, type ContentPart, type EnqueueFunctionOptions, type EnqueueFunctionResult, type FileContentPart, type FileInfo, type FileUploadRequest, type FileUrlResult, type FunctionResult, type ImageContentPart, type InfoResponse, type InputRequiredEvent, type InvokeOptions, type InvokeResult, type LoginRequest, type LoginResponse, type MessageContent, type MessageSendResult, type OTPVerifyRequest, type OTPVerifyResponse, type PendingInput, type PendingInputAnswerAccepted, type PendingInputAnswerResult, type PermissionCheckRequest, type PermissionCheckResponse, type PermissionCheckResult, type QueryResult, type RefreshResponse, type RoundSuspendedEvent, type SSEChunk, SinasAuthError, SinasClient, SinasClientAuth, type SinasClientOptions, type SinasConfig, SinasError, SinasNotFoundError, SinasPermissionError, SinasTimeoutError, type StateGetResult, type StateListResult, type StreamDone, type StreamFromChannelOptions, type StreamOptions, type SubmitAgentBatchOptions, type SubmitAgentBatchResult, type SubmitFunctionBatchOptions, type SubmitFunctionBatchResult, type TextContentPart, type ToolCallInfo, type TurnState, type TurnStatus, type TurnUsage, answerPendingInput, answerResumeChannel, approvalResumeChannel, approveToolCall, cancelBatch, checkPermissions, createChat, enqueueFunction, executeFunction, executeQuery, generateFileUrl, getBatch, getChat, getInfo, getMe, invokeAgent, listBatchExecutions, listCollections, listFiles, listPendingInputs, login, logout, parsePendingInput, parsePendingInputs, pendingInputFromChunk, refresh, sendMessage, stateDelete, stateGet, stateList, stateSet, streamFromChannel, streamMessage, submitAgentBatch, submitFunctionBatch, uploadFile, verifyOTP };
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
SinasNotFoundError,
|
|
7
7
|
SinasPermissionError,
|
|
8
8
|
SinasTimeoutError,
|
|
9
|
+
answerPendingInput,
|
|
10
|
+
answerResumeChannel,
|
|
11
|
+
approvalResumeChannel,
|
|
9
12
|
approveToolCall,
|
|
10
13
|
cancelBatch,
|
|
11
14
|
checkPermissions,
|
|
@@ -18,11 +21,16 @@ import {
|
|
|
18
21
|
getChat,
|
|
19
22
|
getInfo,
|
|
20
23
|
getMe,
|
|
24
|
+
invokeAgent,
|
|
21
25
|
listBatchExecutions,
|
|
22
26
|
listCollections,
|
|
23
27
|
listFiles,
|
|
28
|
+
listPendingInputs,
|
|
24
29
|
login,
|
|
25
30
|
logout,
|
|
31
|
+
parsePendingInput,
|
|
32
|
+
parsePendingInputs,
|
|
33
|
+
pendingInputFromChunk,
|
|
26
34
|
refresh,
|
|
27
35
|
sendMessage,
|
|
28
36
|
stateDelete,
|
|
@@ -35,7 +43,7 @@ import {
|
|
|
35
43
|
submitFunctionBatch,
|
|
36
44
|
uploadFile,
|
|
37
45
|
verifyOTP
|
|
38
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-RHQVV5O6.js";
|
|
39
47
|
export {
|
|
40
48
|
SinasAuthError,
|
|
41
49
|
SinasClient,
|
|
@@ -44,6 +52,9 @@ export {
|
|
|
44
52
|
SinasNotFoundError,
|
|
45
53
|
SinasPermissionError,
|
|
46
54
|
SinasTimeoutError,
|
|
55
|
+
answerPendingInput,
|
|
56
|
+
answerResumeChannel,
|
|
57
|
+
approvalResumeChannel,
|
|
47
58
|
approveToolCall,
|
|
48
59
|
cancelBatch,
|
|
49
60
|
checkPermissions,
|
|
@@ -56,11 +67,16 @@ export {
|
|
|
56
67
|
getChat,
|
|
57
68
|
getInfo,
|
|
58
69
|
getMe,
|
|
70
|
+
invokeAgent,
|
|
59
71
|
listBatchExecutions,
|
|
60
72
|
listCollections,
|
|
61
73
|
listFiles,
|
|
74
|
+
listPendingInputs,
|
|
62
75
|
login,
|
|
63
76
|
logout,
|
|
77
|
+
parsePendingInput,
|
|
78
|
+
parsePendingInputs,
|
|
79
|
+
pendingInputFromChunk,
|
|
64
80
|
refresh,
|
|
65
81
|
sendMessage,
|
|
66
82
|
stateDelete,
|