@dvina/sdk 5.0.21 → 5.0.23
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/{_generated_documents-NBQDENAF.js → _generated_documents-MF2S74A4.js} +1 -1
- package/dist/{_generated_sdk-BkmfU2Ek.d.ts → _generated_sdk-KPygmd-D.d.ts} +32 -1
- package/dist/ai/index.d.ts +52 -9
- package/dist/ai/index.js +1 -3
- package/dist/chunk-JWGSNUFW.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +2 -2
- package/dist/chunk-BL2HFAU6.js +0 -1
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UIMessage, DefaultChatTransport } from 'ai';
|
|
2
|
-
import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-
|
|
2
|
+
import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-KPygmd-D.js';
|
|
3
3
|
import '../types-BfiQdtra.js';
|
|
4
4
|
import 'graphql';
|
|
5
5
|
import '../connection-ClMdDUce.js';
|
|
@@ -19,6 +19,25 @@ type DvinaMessageRoute = {
|
|
|
19
19
|
};
|
|
20
20
|
/** A task's state as a badge shows it: running (also while queued or resuming), or how its latest turn ended. */
|
|
21
21
|
type DvinaTaskStatus = 'running' | DvinaTurnOutcome;
|
|
22
|
+
/**
|
|
23
|
+
* What a turn waits for before it goes on by itself, in the same reply: the AI service answering again (`service`),
|
|
24
|
+
* Dvina's computer starting (`computer`), the user's Mac coming back online (`desktop`), the usage window resetting
|
|
25
|
+
* (`quota`, at `until`), or a connected app signed in to again (`reconnect`, the app in `app`). Only `reconnect` and
|
|
26
|
+
* `quota` are the user's to act on; the others ask nothing.
|
|
27
|
+
*/
|
|
28
|
+
type DvinaHoldReason = 'service' | 'computer' | 'desktop' | 'quota' | 'reconnect';
|
|
29
|
+
/** A turn on hold (`DvinaMessageMetadata.onHold`): why, since when, and what lifts it. */
|
|
30
|
+
type DvinaTurnHold = {
|
|
31
|
+
reason: DvinaHoldReason;
|
|
32
|
+
/** When the turn began to wait (ISO): the app's calm line grows with it. */
|
|
33
|
+
since: string;
|
|
34
|
+
/** When the hold lifts by itself (ISO): the usage window's reset. */
|
|
35
|
+
until?: string;
|
|
36
|
+
/** The app to sign in to again (its provider key), for `reconnect`. */
|
|
37
|
+
app?: string;
|
|
38
|
+
/** The app's name as the user knows it, for `reconnect`. */
|
|
39
|
+
appName?: string;
|
|
40
|
+
};
|
|
22
41
|
/** Metadata attached to every Dvina chat message. */
|
|
23
42
|
type DvinaMessageMetadata = {
|
|
24
43
|
createdAt?: string;
|
|
@@ -35,6 +54,12 @@ type DvinaMessageMetadata = {
|
|
|
35
54
|
outcome?: DvinaTurnOutcome;
|
|
36
55
|
/** Why an `incomplete` or `failed` turn ended: `budget` (step or token limit), `error`, or a finish reason. */
|
|
37
56
|
outcomeReason?: string;
|
|
57
|
+
/**
|
|
58
|
+
* A task's `incomplete` reply whose work goes on by itself in a next turn: true from its save until that turn starts
|
|
59
|
+
* (the task reads as working, not as cut short); false once the work does not go on (it ended, or waits for the
|
|
60
|
+
* usage window).
|
|
61
|
+
*/
|
|
62
|
+
continuing?: boolean;
|
|
38
63
|
/** Model that produced an assistant message. */
|
|
39
64
|
model?: string;
|
|
40
65
|
usage?: {
|
|
@@ -121,6 +146,11 @@ type DvinaMessageMetadata = {
|
|
|
121
146
|
} | null;
|
|
122
147
|
/** On a user message: it began as the predicted next message (accepted with Tab or a tap). */
|
|
123
148
|
nextPromptUsed?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* On an assistant reply whose turn waits for something outside it (`DvinaTurnHold`) and then goes on by itself in
|
|
151
|
+
* this reply. Cleared when the turn goes on.
|
|
152
|
+
*/
|
|
153
|
+
onHold?: DvinaTurnHold;
|
|
124
154
|
};
|
|
125
155
|
/** Custom data parts streamed alongside text and tool parts. */
|
|
126
156
|
type DvinaDataParts = {
|
|
@@ -204,8 +234,15 @@ type DvinaDataParts = {
|
|
|
204
234
|
startedAt: string;
|
|
205
235
|
/** When it ended (ISO); absent while it goes on. */
|
|
206
236
|
endedAt?: string;
|
|
207
|
-
/** Why it ended, as the server's session says (`ended`, `idle`, `
|
|
237
|
+
/** Why it ended, as the server's session says (`ended`, `idle`, `limit`, `unauthorized`…). */
|
|
208
238
|
endReason?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Until when the call is known to go on (ISO), renewed by its server while it lasts; past it, a card without an
|
|
241
|
+
* end belongs to a session that died without writing it. Absent on cards from older servers.
|
|
242
|
+
*/
|
|
243
|
+
liveUntil?: string;
|
|
244
|
+
/** For a call the usage limit ended (`limit`): when the limit opens again (ISO), its card's one line says it. */
|
|
245
|
+
limitResetsAt?: string;
|
|
209
246
|
durationMs?: number;
|
|
210
247
|
/** The user's and Dvina's messages in the call's thread. */
|
|
211
248
|
messageCount?: number;
|
|
@@ -242,6 +279,15 @@ type DvinaDataParts = {
|
|
|
242
279
|
* (`candidate`). In a chat, a task's latest delegate/relay badge is live and follows the task. An earlier one
|
|
243
280
|
* is frozen: it shows the `previous` state of the task's next badge, or its own `state` at `at`.
|
|
244
281
|
*/
|
|
282
|
+
/**
|
|
283
|
+
* A long conversation's checkpoint (agents `Checkpoint`), kept on the reply whose turn wrote it: the summary the
|
|
284
|
+
* chat's model wrote of the turns before it, and the newest of them as text. The model reads the chat from it on;
|
|
285
|
+
* the user never sees it.
|
|
286
|
+
*/
|
|
287
|
+
'conversation-checkpoint': {
|
|
288
|
+
summary: string;
|
|
289
|
+
recent: string;
|
|
290
|
+
};
|
|
245
291
|
/**
|
|
246
292
|
* "While you were away": the tasks that finished while the user was away, one row each (failures too),
|
|
247
293
|
* written when they come back. A row opens that task's result (`messageId`, in the task chat).
|
|
@@ -464,13 +510,10 @@ type DvinaChatTransportOptions = {
|
|
|
464
510
|
* - Retries once with a refreshed token when the API answers 401.
|
|
465
511
|
* - Retries with backoff while the API answers 503 during a restart.
|
|
466
512
|
*
|
|
467
|
-
* A resumed stream of a continued reply starts by replaying the reply as stored
|
|
468
|
-
*
|
|
469
|
-
* input); its replay is then skipped, as the legacy stream skips it, or the reply's parts would be added twice.
|
|
513
|
+
* A resumed stream of a continued reply starts by replaying the reply as stored; AI SDK takes it as a full replay
|
|
514
|
+
* (`resumeStreamIsReplay`, its default) and rebuilds the reply from it, whatever copy the chat held.
|
|
470
515
|
*/
|
|
471
|
-
declare function createDvinaChatTransport(options: DvinaChatTransportOptions
|
|
472
|
-
keepsReply?: () => boolean;
|
|
473
|
-
}): DefaultChatTransport<DvinaUIMessage>;
|
|
516
|
+
declare function createDvinaChatTransport(options: DvinaChatTransportOptions): DefaultChatTransport<DvinaUIMessage>;
|
|
474
517
|
/**
|
|
475
518
|
* Chat transport for a temporary chat (`POST /api/temporary-chat`): AI SDK's default, without persistence. The
|
|
476
519
|
* client holds the conversation and sends all of it with each turn; the server answers and stores nothing, so there
|
|
@@ -572,4 +615,4 @@ type DvinaLazyToolOutput = {
|
|
|
572
615
|
/** The held-back output a tool part carries instead of its output, or `null` for a whole output. */
|
|
573
616
|
declare function lazyToolOutputOf(output: unknown): DvinaLazyToolOutput | null;
|
|
574
617
|
|
|
575
|
-
export { type DvinaAnswerOutcome, type DvinaChatActionsSdk, type DvinaChatMessageNode, type DvinaChatTransportOptions, type DvinaDataParts, type DvinaGoal, type DvinaGoalCriterion, type DvinaGoalEvaluation, type DvinaGoalStatus, type DvinaLazyToolOutput, type DvinaMessageMetadata, type DvinaMessagePage, type DvinaMessageRoute, type DvinaTaskStatus, type DvinaToolMetadata, type DvinaTurnOutcome, type DvinaUIMessage, MAX_MESSAGE_PAGE, answerDvinaQuestion, createDvinaChatTransport, createDvinaTemporaryChatTransport, dvinaMessagePageOf, dvinaUIMessageOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, grantDvinaTaskApproval, lazyToolOutputOf, postDvinaChatMessage, respondDvinaApproval, returnToDvinaMainChat, startDvinaDay, stopDvinaChat };
|
|
618
|
+
export { type DvinaAnswerOutcome, type DvinaChatActionsSdk, type DvinaChatMessageNode, type DvinaChatTransportOptions, type DvinaDataParts, type DvinaGoal, type DvinaGoalCriterion, type DvinaGoalEvaluation, type DvinaGoalStatus, type DvinaHoldReason, type DvinaLazyToolOutput, type DvinaMessageMetadata, type DvinaMessagePage, type DvinaMessageRoute, type DvinaTaskStatus, type DvinaToolMetadata, type DvinaTurnHold, type DvinaTurnOutcome, type DvinaUIMessage, MAX_MESSAGE_PAGE, answerDvinaQuestion, createDvinaChatTransport, createDvinaTemporaryChatTransport, dvinaMessagePageOf, dvinaUIMessageOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, grantDvinaTaskApproval, lazyToolOutputOf, postDvinaChatMessage, respondDvinaApproval, returnToDvinaMainChat, startDvinaDay, stopDvinaChat };
|
package/dist/ai/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
import {a}from'../chunk-32KGDH2Q.js';import {b
|
|
2
|
-
|
|
3
|
-
`).join("");i&&s.enqueue(t.encode(i));},flush(r){a+=e.decode(),a&&n(a)&&r.enqueue(t.encode(a));}})}async function I(e,t,a,n){await p(()=>e.sendChatMessageWhileRunning({chatId:t,message:a}),{statuses:F,signal:n});}async function N(e,t){let a=await p(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof a=="string"&&a.trim()?a:null}async function L(e,t){await p(()=>e.stopChat({chatId:t}),{statuses:c});}async function z(e,t,a){await p(()=>e.grantChatApproval({chatId:t,toolName:a}),{statuses:c,signal:AbortSignal.timeout(C)});}function G(e,t,a,n){return A(()=>e.respondChatApproval({chatId:t,toolCallId:a,approved:n.approved,always:n.always}))}function j(e,t,a,n){return A(()=>e.answerChatQuestion({chatId:t,toolCallId:a,answers:n}))}async function W(e){await e.returnToMainChat();}async function $(e){return {started:await e.startChatDay()}}async function A(e){try{return await p(e,{statuses:c,signal:AbortSignal.timeout(C)}),"sent"}catch(t){if(Y(t))return "answered-elsewhere";throw t}}function Y(e){return e instanceof b&&e.errors.some(t=>t.message===D||t.extensions?.code===D)}var D="NOT_WAITING",Q=[1e3,2e3,4e3,8e3,15e3,3e4],q=[503],F=[500,502,503,504],c=[502,503,504],C=9e4,y=0;async function p(e,{delaysMs:t=Q,statuses:a=q,signal:n}={}){let r=s=>s instanceof c$1&&(s.status===y||a.includes(s.status??y));for(let s of t){try{return await T(e(),n)}catch(o){if(n?.aborted||!r(o))throw o}await X(s,n);}return T(e(),n)}function T(e,t){return t?t.aborted?Promise.reject(t.reason):new Promise((a,n)=>{let r=()=>n(t.reason);t.addEventListener("abort",r,{once:true}),e.then(a,n).finally(()=>t.removeEventListener("abort",r));}):e}function X(e,t){return new Promise((a,n)=>{if(t?.aborted)return n(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",s),a();},e),s=()=>{clearTimeout(r),n(t?.reason);};t?.addEventListener("abort",s,{once:true});})}function d(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function B(e){let{pageInfo:t}=e;return {messages:e.nodes.map(d),hasOlder:t.hasPreviousPage,hasNewer:t.hasNextPage,...t.startCursor?{startCursor:t.startCursor}:{},...t.endCursor?{endCursor:t.endCursor}:{}}}var M=200;async function H(e,t,{pageSize:a=M}={}){let n=[],r;for(;;){let s=await e.chatMessages({...t,first:a,after:r}).fetch();n.push(...s.nodes.map(d));let o=s.pageInfo.endCursor??void 0;if(!s.pageInfo.hasNextPage||!o||o===r)return n;r=o;}}function V(e){if(!e||typeof e!="object"||!("dvinaLazyOutput"in e))return null;let t=e.dvinaLazyOutput;if(!t||typeof t!="object")return null;let{bytes:a,preview:n,urls:r}=t;return {bytes:typeof a=="number"?a:0,preview:typeof n=="string"?n:"",urls:Array.isArray(r)?r.filter(s=>typeof s=="string"):[]}}export{M as MAX_MESSAGE_PAGE,j as answerDvinaQuestion,S as createDvinaChatTransport,x as createDvinaTemporaryChatTransport,B as dvinaMessagePageOf,d as dvinaUIMessageOf,H as fetchAllDvinaChatMessages,N as fetchDvinaNextPrompt,z as grantDvinaTaskApproval,V as lazyToolOutputOf,I as postDvinaChatMessage,G as respondDvinaApproval,W as returnToDvinaMainChat,$ as startDvinaDay,L as stopDvinaChat};
|
|
1
|
+
import {a}from'../chunk-32KGDH2Q.js';import {b as b$1,c}from'../chunk-37LLNIGO.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';function S(e){let t=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`;return new DefaultChatTransport({api:t,fetch:h(l(e)),prepareSendMessagesRequest:({id:a,messages:n,trigger:r,messageId:o,body:s})=>({api:`${t}/${encodeURIComponent(a)}`,body:{...s,trigger:r,messageId:o,message:n[n.length-1]}}),prepareReconnectToStreamRequest:({id:a})=>({api:`${t}/${encodeURIComponent(a)}/stream`})})}function w(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:h(l(e))})}var _=[1e3,2e3,4e3,8e3,15e3,3e4],x=429,E=6e4;function h(e,t=_,a=[503]){return async(n,r)=>{for(let o of t){let s=await e(n,r).catch(u=>{if(r?.signal?.aborted||!(u instanceof TypeError))throw u;return null}),i=s?.status===x;if(s&&!i&&!a.includes(s.status))return s;await s?.body?.cancel().catch(()=>{}),await R(i?P(s,o):o,r?.signal??void 0);}return e(n,r)}}function P(e,t){let a=Number.NaN;return e.headers.forEach((n,r)=>{Number.isNaN(a)&&r.toLowerCase().startsWith("retry-after")&&(a=Number(n));}),Number.isFinite(a)&&a>0?Math.min(Math.max(a*1e3,t),E):t}function R(e,t){return new Promise((a,n)=>{if(t?.aborted)return n(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",o),a();},e),o=()=>{clearTimeout(r),n(t?.reason);};t?.addEventListener("abort",o,{once:true});})}var O=a();function l(e){let t=e.fetch??globalThis.fetch.bind(globalThis),a=async(n,r,o)=>{let s=new Headers(r?.headers);s.set("Authorization",`Bearer ${await e.getToken({forceRefresh:o})}`);let i=O();i&&!s.has("x-user-timezone")&&s.set("x-user-timezone",i);let u=e.getLanguage?.();return u&&!s.has("x-preferred-language")&&s.set("x-preferred-language",u),t(n,{...r,headers:s})};return async(n,r)=>{let o=await a(n,r,false);return o.status===401?a(n,r,true):o}}async function I(e,t,a,n){await p(()=>e.sendChatMessageWhileRunning({chatId:t,message:a}),{statuses:q,rateLimited:true,signal:n});}async function N(e,t){let a=await p(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof a=="string"&&a.trim()?a:null}async function U(e,t){await p(()=>e.stopChat({chatId:t}),{statuses:f});}async function k(e,t,a){await p(()=>e.grantChatApproval({chatId:t,toolName:a}),{statuses:f,signal:AbortSignal.timeout(A)});}function L(e,t,a,n){return M(()=>e.respondChatApproval({chatId:t,toolCallId:a,approved:n.approved,always:n.always}))}function z(e,t,a,n){return M(()=>e.answerChatQuestion({chatId:t,toolCallId:a,answers:n}))}async function G(e){await e.returnToMainChat();}async function j(e){return {started:await e.startChatDay()}}async function M(e){try{return await p(e,{statuses:f,signal:AbortSignal.timeout(A)}),"sent"}catch(t){if(Y(t))return "answered-elsewhere";throw t}}function Y(e){return e instanceof b$1&&e.errors.some(t=>t.message===D||t.extensions?.code===D)}var D="NOT_WAITING";function W(e){return e instanceof c?e.status===T:e instanceof b$1&&e.errors.some(t=>/ThrottlerException|Too Many Requests/i.test(t.message)||t.extensions?.code==="TOO_MANY_REQUESTS"||t.extensions?.originalError?.statusCode===T)}var $=[1e3,2e3,4e3,8e3,15e3,3e4],Q=[503],q=[500,502,503,504],T=429,f=[502,503,504],A=9e4,y=0;async function p(e,{delaysMs:t=$,statuses:a=Q,rateLimited:n=false,signal:r}={}){let o=s=>s instanceof c&&(s.status===y||a.includes(s.status??y))||n&&W(s);for(let s of t){try{return await C(e(),r)}catch(i){if(r?.aborted||!o(i))throw i}await F(s,r);}return C(e(),r)}function C(e,t){return t?t.aborted?Promise.reject(t.reason):new Promise((a,n)=>{let r=()=>n(t.reason);t.addEventListener("abort",r,{once:true}),e.then(a,n).finally(()=>t.removeEventListener("abort",r));}):e}function F(e,t){return new Promise((a,n)=>{if(t?.aborted)return n(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",o),a();},e),o=()=>{clearTimeout(r),n(t?.reason);};t?.addEventListener("abort",o,{once:true});})}function v(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function H(e){let{pageInfo:t}=e;return {messages:e.nodes.map(v),hasOlder:t.hasPreviousPage,hasNewer:t.hasNextPage,...t.startCursor?{startCursor:t.startCursor}:{},...t.endCursor?{endCursor:t.endCursor}:{}}}var b=200;async function X(e,t,{pageSize:a=b}={}){let n=[],r;for(;;){let o=await e.chatMessages({...t,first:a,after:r}).fetch();n.push(...o.nodes.map(v));let s=o.pageInfo.endCursor??void 0;if(!o.pageInfo.hasNextPage||!s||s===r)return n;r=s;}}function B(e){if(!e||typeof e!="object"||!("dvinaLazyOutput"in e))return null;let t=e.dvinaLazyOutput;if(!t||typeof t!="object")return null;let{bytes:a,preview:n,urls:r}=t;return {bytes:typeof a=="number"?a:0,preview:typeof n=="string"?n:"",urls:Array.isArray(r)?r.filter(o=>typeof o=="string"):[]}}export{b as MAX_MESSAGE_PAGE,z as answerDvinaQuestion,S as createDvinaChatTransport,w as createDvinaTemporaryChatTransport,H as dvinaMessagePageOf,v as dvinaUIMessageOf,X as fetchAllDvinaChatMessages,N as fetchDvinaNextPrompt,k as grantDvinaTaskApproval,B as lazyToolOutputOf,I as postDvinaChatMessage,L as respondDvinaApproval,G as returnToDvinaMainChat,j as startDvinaDay,U as stopDvinaChat};
|