@dvina/sdk 5.0.58 → 5.0.62

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,5 +1,5 @@
1
1
  import { UIMessage, DefaultChatTransport } from 'ai';
2
- import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-NAQIrauv.js';
2
+ import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-CMF68az0.js';
3
3
  import '../types-0oS5PBdX.js';
4
4
  import 'graphql';
5
5
  import '../connection-DkvWhViN.js';
@@ -7,8 +7,6 @@ import 'dexie';
7
7
  import '../error-aFALORBM.js';
8
8
  import '../billing/index.js';
9
9
 
10
- /** How a turn ended: `waiting` for the user's approval or answer, `incomplete` when it ended before finishing. */
11
- type DvinaTurnOutcome = 'done' | 'waiting' | 'incomplete' | 'failed' | 'stopped';
12
10
  /** Where the supervisor sent a user message: answered itself, relayed it to a task, or started a new task. */
13
11
  type DvinaMessageRoute = {
14
12
  to: 'supervisor' | 'task' | 'new-task';
@@ -17,32 +15,6 @@ type DvinaMessageRoute = {
17
15
  /** The supervisor's one-line reason for a relay or a new task. */
18
16
  reason?: string;
19
17
  };
20
- /** A task's state as a badge shows it: running (also while queued or resuming), or how its latest turn ended. */
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`), an app signed in to (`reconnect`, the app in `app`: again, or the first time with `connect`),
26
- * or the user's computer
27
- * unlocked again for a step that sees its screen (`locked`), or the user handing back a page Dvina's browser handed them
28
- * to sign in, pay or decide (`hand-over`). Only `reconnect`, `quota` and `hand-over` are the user's to act on in Dvina;
29
- * the others ask nothing of it.
30
- */
31
- type DvinaHoldReason = 'service' | 'computer' | 'desktop' | 'quota' | 'reconnect' | 'locked' | 'hand-over';
32
- /** A turn on hold (`DvinaMessageMetadata.onHold`): why, since when, and what lifts it. */
33
- type DvinaTurnHold = {
34
- reason: DvinaHoldReason;
35
- /** When the turn began to wait (ISO): the app's calm line grows with it. */
36
- since: string;
37
- /** When the hold lifts by itself (ISO): the usage window's reset. */
38
- until?: string;
39
- /** The app to sign in to again (its provider key), for `reconnect`. */
40
- app?: string;
41
- /** The app's name as the user knows it, for `reconnect`. */
42
- appName?: string;
43
- /** For `reconnect`: the app was never connected, so the user connects it, rather than signing in to it again. */
44
- connect?: boolean;
45
- };
46
18
  /** Metadata attached to every Dvina chat message. */
47
19
  type DvinaMessageMetadata = {
48
20
  createdAt?: string;
@@ -53,30 +25,8 @@ type DvinaMessageMetadata = {
53
25
  * or approval, an app to be connected). What the app says as the run's duration.
54
26
  */
55
27
  workedMs?: number;
56
- /** The reply was stopped by the user before it finished. */
57
- stopped?: boolean;
58
28
  /** Why the model ended the reply's last step, as the AI SDK reports it (`stop`, `length`, `tool-calls`, …). */
59
29
  finishReason?: string;
60
- /**
61
- * How the turn that wrote this reply ended, decided by the server. `done` only when the model ended on
62
- * its own; absent on replies saved before outcomes were recorded.
63
- */
64
- outcome?: DvinaTurnOutcome;
65
- /** Why an `incomplete` or `failed` turn ended: `budget` (step or token limit), `error`, or a finish reason. */
66
- outcomeReason?: string;
67
- /**
68
- * When the reader closed the card of a task's reply that ended needing them ("Not now"): the reply waits on them no
69
- * more, on any device, and is never asked again; only a later reply that asks again does.
70
- */
71
- dismissedAt?: string;
72
- /** The ask-supervisor call whose question was sent to the supervisor (sent once per call, kept across restarts). */
73
- askSentFor?: string;
74
- /**
75
- * A task's `incomplete` reply whose work goes on by itself in a next turn: true from its save until that turn starts
76
- * (the task reads as working, not as cut short); false once the work does not go on (it ended, or waits for the
77
- * usage window).
78
- */
79
- continuing?: boolean;
80
30
  /** Model that produced an assistant message. */
81
31
  model?: string;
82
32
  usage?: {
@@ -153,22 +103,12 @@ type DvinaMessageMetadata = {
153
103
  * panel shows that message's own words; a message the supervisor added on its own has none.
154
104
  */
155
105
  triggeredBy?: string;
156
- /**
157
- * On a task's brief: how many items its goal asks for (delegate-task's `expectedItems`). Its hand-in is checked
158
- * against it, and it is done only with them all (task-result checkTaskResult, turn-outcome unfinishedHandIn).
159
- */
160
- expectedItems?: number;
161
106
  /**
162
107
  * On a message a task chat received from the supervisor on its own, with no message of the user's behind it (it
163
108
  * answered the task's question for the user, or passed it another task's word): the run it starts goes on with the
164
109
  * user's request, so its report updates that request's report in place, as one row (Muhammed 2026-11-03).
165
110
  */
166
111
  followUp?: boolean;
167
- /**
168
- * On a hidden input of the main chat: its reply is Dvina's own business, stored hidden and never drawn (the turn on a
169
- * task's question, which it answers for the user from what they said, or leaves to the question's card).
170
- */
171
- unseenReply?: boolean;
172
112
  /**
173
113
  * On an assistant reply: the user's predicted next message, shown in an empty composer (ghost text), and when
174
114
  * it was predicted; `null` when none fits. Absent until the client asks for it.
@@ -185,11 +125,6 @@ type DvinaMessageMetadata = {
185
125
  * without it (sent before, or a chip that knew no file) shows the item as it is now.
186
126
  */
187
127
  resourceFiles?: Record<string, string>;
188
- /**
189
- * On an assistant reply whose turn waits for something outside it (`DvinaTurnHold`) and then goes on by itself in
190
- * this reply. Cleared when the turn goes on.
191
- */
192
- onHold?: DvinaTurnHold;
193
128
  };
194
129
  /** Custom data parts streamed alongside text and tool parts. */
195
130
  type DvinaDataParts = {
@@ -359,54 +294,16 @@ type DvinaDataParts = {
359
294
  summary: string;
360
295
  recent: string;
361
296
  };
297
+ /** The user stopped this reply's turn (E5): recorded in the reply, read by the model as its ask closed. */
298
+ stopped: {
299
+ at: string;
300
+ };
362
301
  /**
363
- * "While you were away": the tasks that finished while the user was away, one row each (failures too),
364
- * written when they come back. A row opens that task's result (`messageId`, in the task chat).
302
+ * Data protection refused this turn before the model read it (no model output, no finish reason carries it): the
303
+ * refusing rules by label, empty when any rule. The user reads why; the model leaves the turn out.
365
304
  */
366
- 'away-summary': {
367
- /** When the first of them finished (ISO). */
368
- since: string;
369
- items: {
370
- chatId: string;
371
- title: string;
372
- state: DvinaTaskStatus;
373
- /** One line of its result, or of what stopped it. */
374
- gist: string;
375
- /** When it finished (ISO). */
376
- at: string;
377
- messageId?: string;
378
- }[];
379
- };
380
- 'task-badge': {
381
- chatId: string;
382
- /** The task's name when the badge was written. */
383
- title: string;
384
- via: 'delegate' | 'relay' | 'result' | 'candidate';
385
- /** The task's state when the badge was written. */
386
- state: DvinaTaskStatus;
387
- /** When the badge was written (ISO). */
388
- at: string;
389
- /** The task input message for this run. Shared by delegate/relay and result badges; not the reply's ID. */
390
- messageId?: string;
391
- /**
392
- * On a relay: the task's state just before it, which the previous badge of the task shows once this one is
393
- * live. A badge with no later badge for its task shows its own `state`.
394
- */
395
- previous?: {
396
- state: DvinaTaskStatus;
397
- at: string;
398
- };
399
- /** The task's current step, when known. */
400
- step?: string;
401
- progress?: {
402
- done: number;
403
- total: number;
404
- };
405
- /**
406
- * On a result badge of a task that did not finish: the text after it is the task's own words to the user on why
407
- * (it needs them, its goal could not be reached, it could do nothing), shown under the badge.
408
- */
409
- explained?: true;
305
+ 'dlp-blocked': {
306
+ rules: string[];
410
307
  };
411
308
  /** Older replies: a user reply the supervisor passed to a task chat (now `task-badge`). */
412
309
  'task-follow-up': {
@@ -595,6 +492,21 @@ type DvinaToolMetadata = {
595
492
  toolKit?: string;
596
493
  };
597
494
  /** What a stored message says of the messages it links to, as a reply's task is read from them. */
495
+ /**
496
+ * The text formats a user watches being written as a live deliverable, by file extension (the app's live artifacts),
497
+ * and the ones a task delivers to One Chat when it wrote them (writeFile / editFile's `delivers.formats`). Scripts and
498
+ * scratch files are left out. One list for the API, the SDK (generated copy) and the app.
499
+ */
500
+ declare const LIVE_FILE_FORMATS: {
501
+ readonly html: "html";
502
+ readonly htm: "html";
503
+ readonly md: "markdown";
504
+ readonly markdown: "markdown";
505
+ readonly csv: "csv";
506
+ readonly svg: "svg";
507
+ readonly mmd: "mermaid";
508
+ readonly mermaid: "mermaid";
509
+ };
598
510
  type DvinaMessageLinks = {
599
511
  inResponseToId?: string | null;
600
512
  referencedChatId?: string | null;
@@ -633,7 +545,7 @@ declare function createDvinaChatTransport(options: DvinaChatTransportOptions): D
633
545
  declare function createDvinaTemporaryChatTransport(options: DvinaChatTransportOptions): DefaultChatTransport<DvinaUIMessage>;
634
546
 
635
547
  /** The chat actions of the SDK, as the functions below call them. */
636
- type DvinaChatActionsSdk = Pick<DvinaSdk, 'sendChatMessageWhileRunning' | 'chatNextPrompt' | 'stopChat' | 'grantChatApproval' | 'respondChatApproval' | 'answerChatQuestion' | 'dismissTaskQuestion' | 'returnToMainChat' | 'startChatDay'>;
548
+ type DvinaChatActionsSdk = Pick<DvinaSdk, 'sendChatMessageWhileRunning' | 'chatNextPrompt' | 'stopChat' | 'grantChatApproval' | 'respondChatApproval' | 'answerChatQuestion' | 'startChatDay'>;
637
549
  /**
638
550
  * Sends a user message while the chat's turn runs: the server stores it at once (every device shows it) and answers it
639
551
  * with the chat's next turn, without cutting the running reply off. Sending it again under the same id changes nothing,
@@ -665,17 +577,6 @@ declare function respondDvinaApproval(sdk: DvinaChatActionsSdk, chatId: string,
665
577
  }): Promise<DvinaAnswerOutcome>;
666
578
  /** Answers a chat's waiting question from outside the chat (a notification's reply): one answer list per question. */
667
579
  declare function answerDvinaQuestion(sdk: DvinaChatActionsSdk, chatId: string, toolCallId: string, answers: string[][]): Promise<DvinaAnswerOutcome>;
668
- /**
669
- * The reader's "Not now" on the card of a task whose run ended needing them: that run (the task's latest reply,
670
- * `replyId`) waits on them no more, on every device, and is not asked again. A task that asked again since keeps its
671
- * new wait (the server changes nothing then).
672
- */
673
- declare function dismissDvinaTaskQuestion(sdk: DvinaChatActionsSdk, taskChatId: string, replyId: string): Promise<void>;
674
- /**
675
- * Tells the server the user is back (the app opened or came to the foreground): the results that finished while
676
- * they were away arrive as one summary in the main chat. Idempotent within one absence.
677
- */
678
- declare function returnToDvinaMainChat(sdk: DvinaChatActionsSdk): Promise<void>;
679
580
  /**
680
581
  * Starts the reader's day (their local day, from `x-user-timezone`) as the app opens or comes to the foreground: the
681
582
  * day's first call queues its work (pending day digests, the cards kept for the morning, the night's ideas); later
@@ -732,4 +633,4 @@ type DvinaLazyToolOutput = {
732
633
  /** The held-back output a tool part carries instead of its output, or `null` for a whole output. */
733
634
  declare function lazyToolOutputOf(output: unknown): DvinaLazyToolOutput | null;
734
635
 
735
- export { type DvinaAnswerOutcome, type DvinaChatActionsSdk, type DvinaChatMessageNode, type DvinaChatTransportOptions, type DvinaDataParts, type DvinaGoal, type DvinaGoalCriterion, type DvinaGoalEvaluation, type DvinaGoalStatus, type DvinaHoldReason, type DvinaLazyToolOutput, type DvinaMessageLinks, type DvinaMessageMetadata, type DvinaMessagePage, type DvinaMessageRoute, type DvinaTaskStatus, type DvinaToolMetadata, type DvinaTurnHold, type DvinaTurnOutcome, type DvinaUIMessage, MAX_MESSAGE_PAGE, answerDvinaQuestion, createDvinaChatTransport, createDvinaTemporaryChatTransport, dismissDvinaTaskQuestion, dvinaMessagePageOf, dvinaUIMessageOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, grantDvinaTaskApproval, lazyToolOutputOf, postDvinaChatMessage, replyTargetIn, respondDvinaApproval, returnToDvinaMainChat, startDvinaDay, stopDvinaChat };
636
+ export { type DvinaAnswerOutcome, type DvinaChatActionsSdk, type DvinaChatMessageNode, type DvinaChatTransportOptions, type DvinaDataParts, type DvinaGoal, type DvinaGoalCriterion, type DvinaGoalEvaluation, type DvinaGoalStatus, type DvinaLazyToolOutput, type DvinaMessageLinks, type DvinaMessageMetadata, type DvinaMessagePage, type DvinaMessageRoute, type DvinaToolMetadata, type DvinaUIMessage, LIVE_FILE_FORMATS, MAX_MESSAGE_PAGE, answerDvinaQuestion, createDvinaChatTransport, createDvinaTemporaryChatTransport, dvinaMessagePageOf, dvinaUIMessageOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, grantDvinaTaskApproval, lazyToolOutputOf, postDvinaChatMessage, replyTargetIn, respondDvinaApproval, startDvinaDay, stopDvinaChat };
package/dist/ai/index.js CHANGED
@@ -1 +1 @@
1
- import {a}from'../chunk-32KGDH2Q.js';import {b as b$1,c as c$1}from'../chunk-37LLNIGO.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';function*k(e,{named:t=true}={}){if(e?.role!=="user")return;if(t&&e.metadata?.inResponseToTaskChatId)return e.metadata.inResponseToTaskChatId;let n=e.metadata?.inResponseToId??void 0;for(let a=0;n&&a<2;a++){let s=yield n;if(s?.referencedChatId)return s.referencedChatId;n=s?.inResponseToId??void 0;}}function f(e,t){let n=k(e),a=n.next();for(;!a.done;)a=n.next(t(a.value));return a.value}function A(e){let t=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`;return new DefaultChatTransport({api:t,fetch:D(b(e)),prepareSendMessagesRequest:({id:n,messages:a,trigger:s,messageId:i,body:r})=>({api:`${t}/${encodeURIComponent(n)}`,body:{...r,trigger:s,messageId:i,message:a[a.length-1]}}),prepareReconnectToStreamRequest:({id:n})=>({api:`${t}/${encodeURIComponent(n)}/stream`})})}function w(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:D(b(e))})}var S=[1e3,2e3,4e3,8e3,15e3,3e4],R=429,P=6e4;function D(e,t=S,n=[503]){return async(a,s)=>{for(let i of t){let r=await e(a,s).catch(d=>{if(s?.signal?.aborted||!(d instanceof TypeError))throw d;return null}),o=r?.status===R;if(r&&!o&&!n.includes(r.status))return r;await r?.body?.cancel().catch(()=>{}),await E(o?_(r,i):i,s?.signal??void 0);}return e(a,s)}}function _(e,t){let n=Number.NaN;return e.headers.forEach((a,s)=>{Number.isNaN(n)&&s.toLowerCase().startsWith("retry-after")&&(n=Number(a));}),Number.isFinite(n)&&n>0?Math.min(Math.max(n*1e3,t),P):t}function E(e,t){return new Promise((n,a)=>{if(t?.aborted)return a(t.reason);let s=setTimeout(()=>{t?.removeEventListener("abort",i),n();},e),i=()=>{clearTimeout(s),a(t?.reason);};t?.addEventListener("abort",i,{once:true});})}var O=a();function b(e){let t=e.fetch??globalThis.fetch.bind(globalThis),n=async(a,s,i)=>{let r=new Headers(s?.headers);r.set("Authorization",`Bearer ${await e.getToken({forceRefresh:i})}`);let o=O();o&&!r.has("x-user-timezone")&&r.set("x-user-timezone",o);let d=e.getLanguage?.();return d&&!r.has("x-preferred-language")&&r.set("x-preferred-language",d),t(a,{...s,headers:r})};return async(a,s)=>{let i=await n(a,s,false);return i.status===401?n(a,s,true):i}}async function U(e,t,n,a){await u(()=>e.sendChatMessageWhileRunning({chatId:t,message:n}),{statuses:B,rateLimited:true,signal:a});}async function N(e,t){let n=await u(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof n=="string"&&n.trim()?n:null}async function L(e,t){await u(()=>e.stopChat({chatId:t}),{statuses:g});}async function G(e,t,n){await u(()=>e.grantChatApproval({chatId:t,toolName:n}),{statuses:g,signal:AbortSignal.timeout(c)});}function z(e,t,n,a){return M(()=>e.respondChatApproval({chatId:t,toolCallId:n,approved:a.approved,always:a.always}))}function j(e,t,n,a){return M(()=>e.answerChatQuestion({chatId:t,toolCallId:n,answers:a}))}async function H(e,t,n){await u(()=>e.dismissTaskQuestion({chatId:t,messageId:n}),{statuses:g,signal:AbortSignal.timeout(c)});}async function Q(e){await e.returnToMainChat();}async function Y(e){return {started:await e.startChatDay()}}async function M(e){try{return await u(e,{statuses:g,signal:AbortSignal.timeout(c)}),"sent"}catch(t){if(W(t))return "answered-elsewhere";throw t}}function W(e){return e instanceof b$1&&e.errors.some(t=>t.message===T||t.extensions?.code===T)}var T="NOT_WAITING";function $(e){return e instanceof c$1?e.status===y: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===y)}var F=[1e3,2e3,4e3,8e3,15e3,3e4],q=[503],B=[500,502,503,504],y=429,g=[502,503,504],c=9e4,C=0;async function u(e,{delaysMs:t=F,statuses:n=q,rateLimited:a=false,signal:s}={}){let i=r=>r instanceof c$1&&(r.status===C||n.includes(r.status??C))||a&&$(r);for(let r of t){try{return await I(e(),s)}catch(o){if(s?.aborted||!i(o))throw o}await X(r,s);}return I(e(),s)}function I(e,t){return t?t.aborted?Promise.reject(t.reason):new Promise((n,a)=>{let s=()=>a(t.reason);t.addEventListener("abort",s,{once:true}),e.then(n,a).finally(()=>t.removeEventListener("abort",s));}):e}function X(e,t){return new Promise((n,a)=>{if(t?.aborted)return a(t.reason);let s=setTimeout(()=>{t?.removeEventListener("abort",i),n();},e),i=()=>{clearTimeout(s),a(t?.reason);};t?.addEventListener("abort",i,{once:true});})}function m(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function K(e){let{pageInfo:t}=e;return {messages:e.nodes.map(m),hasOlder:t.hasPreviousPage,hasNewer:t.hasNextPage,...t.startCursor?{startCursor:t.startCursor}:{},...t.endCursor?{endCursor:t.endCursor}:{}}}var x=200;async function V(e,t,{pageSize:n=x}={}){let a=[],s;for(;;){let i=await e.chatMessages({...t,first:n,after:s}).fetch();a.push(...i.nodes.map(m));let r=i.pageInfo.endCursor??void 0;if(!i.pageInfo.hasNextPage||!r||r===s)return a;s=r;}}function J(e){if(!e||typeof e!="object"||!("dvinaLazyOutput"in e))return null;let t=e.dvinaLazyOutput;if(!t||typeof t!="object")return null;let{bytes:n,preview:a,urls:s}=t;return {bytes:typeof n=="number"?n:0,preview:typeof a=="string"?a:"",urls:Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}}export{x as MAX_MESSAGE_PAGE,j as answerDvinaQuestion,A as createDvinaChatTransport,w as createDvinaTemporaryChatTransport,H as dismissDvinaTaskQuestion,K as dvinaMessagePageOf,m as dvinaUIMessageOf,V as fetchAllDvinaChatMessages,N as fetchDvinaNextPrompt,G as grantDvinaTaskApproval,J as lazyToolOutputOf,U as postDvinaChatMessage,f as replyTargetIn,z as respondDvinaApproval,Q as returnToDvinaMainChat,Y as startDvinaDay,L as stopDvinaChat};
1
+ import {a}from'../chunk-32KGDH2Q.js';import {b as b$1,c as c$1}from'../chunk-37LLNIGO.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';var v={html:"html",htm:"html",md:"markdown",markdown:"markdown",csv:"csv",svg:"svg",mmd:"mermaid",mermaid:"mermaid"},k=2;function*w(e,{named:t=true}={}){if(e?.role!=="user")return;if(t&&e.metadata?.inResponseToTaskChatId)return e.metadata.inResponseToTaskChatId;let n=e.metadata?.inResponseToId??void 0;for(let a=0;n&&a<k;a++){let r=yield n;if(r?.referencedChatId)return r.referencedChatId;n=r?.inResponseToId??void 0;}}function f(e,t){let n=w(e),a=n.next();for(;!a.done;)a=n.next(t(a.value));return a.value}function S(e){let t=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`;return new DefaultChatTransport({api:t,fetch:D(b(e)),prepareSendMessagesRequest:({id:n,messages:a,trigger:r,messageId:o,body:s})=>({api:`${t}/${encodeURIComponent(n)}`,body:{...s,trigger:r,messageId:o,message:a[a.length-1]}}),prepareReconnectToStreamRequest:({id:n})=>({api:`${t}/${encodeURIComponent(n)}/stream`})})}function R(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:D(b(e))})}var _=[1e3,2e3,4e3,8e3,15e3,3e4],E=429,P=6e4;function D(e,t=_,n=[503]){return async(a,r)=>{for(let o of t){let s=await e(a,r).catch(u=>{if(r?.signal?.aborted||!(u instanceof TypeError))throw u;return null}),i=s?.status===E;if(s&&!i&&!n.includes(s.status))return s;await s?.body?.cancel().catch(()=>{}),await U(i?O(s,o):o,r?.signal??void 0);}return e(a,r)}}function O(e,t){let n=Number.NaN;return e.headers.forEach((a,r)=>{Number.isNaN(n)&&r.toLowerCase().startsWith("retry-after")&&(n=Number(a));}),Number.isFinite(n)&&n>0?Math.min(Math.max(n*1e3,t),P):t}function U(e,t){return new Promise((n,a)=>{if(t?.aborted)return a(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",o),n();},e),o=()=>{clearTimeout(r),a(t?.reason);};t?.addEventListener("abort",o,{once:true});})}var N=a();function b(e){let t=e.fetch??globalThis.fetch.bind(globalThis),n=async(a,r,o)=>{let s=new Headers(r?.headers);s.set("Authorization",`Bearer ${await e.getToken({forceRefresh:o})}`);let i=N();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(a,{...r,headers:s})};return async(a,r)=>{let o=await n(a,r,false);return o.status===401?n(a,r,true):o}}async function L(e,t,n,a){await d(()=>e.sendChatMessageWhileRunning({chatId:t,message:n}),{statuses:V,rateLimited:true,signal:a});}async function G(e,t){let n=await d(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof n=="string"&&n.trim()?n:null}async function z(e,t){await d(()=>e.stopChat({chatId:t}),{statuses:l});}async function j(e,t,n){await d(()=>e.grantChatApproval({chatId:t,toolName:n}),{statuses:l,signal:AbortSignal.timeout(x)});}function F(e,t,n,a){return M(()=>e.respondChatApproval({chatId:t,toolCallId:n,approved:a.approved,always:a.always}))}function Y(e,t,n,a){return M(()=>e.answerChatQuestion({chatId:t,toolCallId:n,answers:a}))}async function W(e){return {started:await e.startChatDay()}}async function M(e){try{return await d(e,{statuses:l,signal:AbortSignal.timeout(x)}),"sent"}catch(t){if($(t))return "answered-elsewhere";throw t}}function $(e){return e instanceof b$1&&e.errors.some(t=>t.message===y||t.extensions?.code===y)}var y="NOT_WAITING";function Q(e){return e instanceof c$1?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 q=[1e3,2e3,4e3,8e3,15e3,3e4],B=[503],V=[500,502,503,504],T=429,l=[502,503,504],x=9e4,C=0;async function d(e,{delaysMs:t=q,statuses:n=B,rateLimited:a=false,signal:r}={}){let o=s=>s instanceof c$1&&(s.status===C||n.includes(s.status??C))||a&&Q(s);for(let s of t){try{return await I(e(),r)}catch(i){if(r?.aborted||!o(i))throw i}await H(s,r);}return I(e(),r)}function I(e,t){return t?t.aborted?Promise.reject(t.reason):new Promise((n,a)=>{let r=()=>a(t.reason);t.addEventListener("abort",r,{once:true}),e.then(n,a).finally(()=>t.removeEventListener("abort",r));}):e}function H(e,t){return new Promise((n,a)=>{if(t?.aborted)return a(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",o),n();},e),o=()=>{clearTimeout(r),a(t?.reason);};t?.addEventListener("abort",o,{once:true});})}function c(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function X(e){let{pageInfo:t}=e;return {messages:e.nodes.map(c),hasOlder:t.hasPreviousPage,hasNewer:t.hasNextPage,...t.startCursor?{startCursor:t.startCursor}:{},...t.endCursor?{endCursor:t.endCursor}:{}}}var A=200;async function K(e,t,{pageSize:n=A}={}){let a=[],r;for(;;){let o=await e.chatMessages({...t,first:n,after:r}).fetch();a.push(...o.nodes.map(c));let s=o.pageInfo.endCursor??void 0;if(!o.pageInfo.hasNextPage||!s||s===r)return a;r=s;}}function J(e){if(!e||typeof e!="object"||!("dvinaLazyOutput"in e))return null;let t=e.dvinaLazyOutput;if(!t||typeof t!="object")return null;let{bytes:n,preview:a,urls:r}=t;return {bytes:typeof n=="number"?n:0,preview:typeof a=="string"?a:"",urls:Array.isArray(r)?r.filter(o=>typeof o=="string"):[]}}export{v as LIVE_FILE_FORMATS,A as MAX_MESSAGE_PAGE,Y as answerDvinaQuestion,S as createDvinaChatTransport,R as createDvinaTemporaryChatTransport,X as dvinaMessagePageOf,c as dvinaUIMessageOf,K as fetchAllDvinaChatMessages,G as fetchDvinaNextPrompt,j as grantDvinaTaskApproval,J as lazyToolOutputOf,L as postDvinaChatMessage,f as replyTargetIn,F as respondDvinaApproval,W as startDvinaDay,z as stopDvinaChat};