@dvina/sdk 5.0.77 → 5.0.79

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,8 +1,8 @@
1
1
  import { UIMessage, DefaultChatTransport } from 'ai';
2
- import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-DOY0tRiW.js';
2
+ import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-BMxoHk-1.js';
3
3
  import '../types-DlNXHZQK.js';
4
4
  import 'graphql';
5
- import '../connection-DsemtinG.js';
5
+ import '../connection-BSL5UyZp.js';
6
6
  import 'dexie';
7
7
  import '../error-CuX-RKTE.js';
8
8
  import '../billing/index.js';
@@ -96,6 +96,11 @@ type DvinaMessageMetadata = {
96
96
  };
97
97
  /** The scheduled message that sent this user message when it was due. */
98
98
  scheduledMessageId?: string;
99
+ /**
100
+ * On a user message: the reader's earlier message it sends again, whose reply failed (Try again on an older failed
101
+ * message). It goes at the chat's end as a message of its own; the earlier one reads as sent again.
102
+ */
103
+ retryOf?: string;
99
104
  /** On a main chat user message: where the supervisor routed it (stored when its turn ends). */
100
105
  route?: DvinaMessageRoute;
101
106
  /**
@@ -322,9 +327,10 @@ type DvinaDataParts = {
322
327
  text: string;
323
328
  /**
324
329
  * The task waits for another run to let go of the computer it needs: `mac` the user's own, `computer` Dvina's
325
- * cloud desktop. The app says so in the user's language instead of `text`, until the line comes without it.
330
+ * cloud desktop; or `device`: the user's own computer took the step and has sent nothing since. The app says so in
331
+ * the user's language instead of `text`, until the line comes without it.
326
332
  */
327
- waitingFor?: 'mac' | 'computer';
333
+ waitingFor?: 'mac' | 'computer' | 'device';
328
334
  };
329
335
  /**
330
336
  * Something Dvina noticed on its own (proactive), in its own message, never inside a reply. The card reads the
@@ -528,6 +534,31 @@ declare function replyTargetIn(message: DvinaUIMessage | undefined, links: (mess
528
534
  * by the task's One Chat writes): the app marks it "Updated". Only tool parts carry call metadata.
529
535
  */
530
536
  declare function wasUpdated(part: object): boolean;
537
+ /**
538
+ * One task a hand-off (delegate-task, continue-task-chat) starts or reaches: its chat (null while the server still makes
539
+ * it), its title, and its key in the call (the call's id for its first task, `<call id>:<n>` for the n-th more, as the
540
+ * API keys its delegations), so its capsule keeps one key from its call's first words to its result.
541
+ */
542
+ type DvinaHandedTask = {
543
+ chatId: string | null;
544
+ title: string | null;
545
+ key: string;
546
+ };
547
+ /** A hand-off tool part as handedTasksOf reads it; an AI SDK tool UI part is one. */
548
+ type DvinaHandOffPart = {
549
+ toolCallId: string;
550
+ state?: string;
551
+ input?: unknown;
552
+ output?: unknown;
553
+ };
554
+ /**
555
+ * The tasks a hand-off names, in its order, the one rule the API and the app both read it by. A delegate-task call that
556
+ * starts several lists each in its result's `tasks` (the first is also its `chatId`); a call of one task, a
557
+ * continue-task-chat call and calls stored before `tasks` name theirs by `chatId` alone. Before its result, the call's
558
+ * input names its tasks by title (the first, then `tasks`), and a continue-task-chat call its task by `chatId`; an
559
+ * input still streaming holds part of an id, so none is read from it. A task the call could not start is in none.
560
+ */
561
+ declare function handedTasksOf(part: DvinaHandOffPart): DvinaHandedTask[];
531
562
  /** A task's state, in Claude's few words (task core v2 plan §3a). */
532
563
  type DvinaTaskState = 'starting' | 'working' | 'waiting' | 'ready' | 'done' | 'stopped';
533
564
  /** The lifecycle columns of a task's Chat row its state is read from (dates as the API or the SDK hold them). */
@@ -566,6 +597,18 @@ declare function isHeldOutput(output: unknown): output is HeldCallOutput;
566
597
  declare function endingHoldIndex(reply: Pick<UIMessage, 'parts'>): number;
567
598
  /** The hold a reply's turn ended on (endingHoldIndex), or undefined. */
568
599
  declare function endingHoldOf(reply: Pick<UIMessage, 'parts'> | undefined): HeldCallOutput['hold'] | undefined;
600
+ /**
601
+ * A message whose turn failed, sent again (Try again, iMessage's way): the same words and files under a new id, at the
602
+ * chat's end, naming the one it sends again (`retryOf`); in a thread, to the same thread. The failed reply stays, with
603
+ * whatever its steps did, for the model to go on from: a failed turn is never made again in place. The one rule the
604
+ * app's Try again and the API build it by (the API from its own stored copy, whatever a device sent).
605
+ */
606
+ declare function sentAgain(failed: DvinaUIMessage, id: string, placed: Pick<DvinaMessageMetadata, 'createdAt' | 'afterReply'>): DvinaUIMessage;
607
+ /**
608
+ * The message a reply answers, which Try again on it sends again: the one it names (`inResponseToId`), else the last
609
+ * user message before it.
610
+ */
611
+ declare function answeredMessageOf(messages: readonly DvinaUIMessage[], reply: DvinaUIMessage): DvinaUIMessage | undefined;
569
612
 
570
613
  type DvinaChatTransportOptions = {
571
614
  /** API origin including protocol, e.g. `https://api.dvina.ai`. */
@@ -695,4 +738,4 @@ type DvinaLazyToolOutput = {
695
738
  /** The held-back output a tool part carries instead of its output, or `null` for a whole output. */
696
739
  declare function lazyToolOutputOf(output: unknown): DvinaLazyToolOutput | null;
697
740
 
698
- 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 DvinaTaskRow, type DvinaTaskState, type DvinaToolMetadata, type DvinaUIMessage, type HeldCallOutput, LIVE_FILE_FORMATS, MAX_MESSAGE_PAGE, answerDvinaQuestion, answerDvinaToolCall, createDvinaChatTransport, createDvinaTemporaryChatTransport, dvinaMessagePageOf, dvinaUIMessageOf, endingHoldIndex, endingHoldOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, isHeldOutput, lazyToolOutputOf, postDvinaChatMessage, replyTargetIn, respondDvinaApproval, startDvinaDay, stopDvinaChat, taskStateOf, wasUpdated };
741
+ export { type DvinaAnswerOutcome, type DvinaChatActionsSdk, type DvinaChatMessageNode, type DvinaChatTransportOptions, type DvinaDataParts, type DvinaGoal, type DvinaGoalCriterion, type DvinaGoalEvaluation, type DvinaGoalStatus, type DvinaHandOffPart, type DvinaHandedTask, type DvinaLazyToolOutput, type DvinaMessageLinks, type DvinaMessageMetadata, type DvinaMessagePage, type DvinaMessageRoute, type DvinaTaskRow, type DvinaTaskState, type DvinaToolMetadata, type DvinaUIMessage, type HeldCallOutput, LIVE_FILE_FORMATS, MAX_MESSAGE_PAGE, answerDvinaQuestion, answerDvinaToolCall, answeredMessageOf, createDvinaChatTransport, createDvinaTemporaryChatTransport, dvinaMessagePageOf, dvinaUIMessageOf, endingHoldIndex, endingHoldOf, fetchAllDvinaChatMessages, fetchDvinaNextPrompt, handedTasksOf, isHeldOutput, lazyToolOutputOf, postDvinaChatMessage, replyTargetIn, respondDvinaApproval, sentAgain, startDvinaDay, stopDvinaChat, taskStateOf, wasUpdated };
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-XBOJ7CCU.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';var b={html:"html",htm:"html",md:"markdown",markdown:"markdown",csv:"csv",svg:"svg",mmd:"mermaid",mermaid:"mermaid"},P=2;function*_(e,{named:t=true}={}){if(e?.role!=="user")return;if(t&&e.metadata?.inResponseToTaskChatId)return e.metadata.inResponseToTaskChatId;let a=e.metadata?.inResponseToId??void 0;for(let n=0;a&&n<P;n++){let r=yield a;if(r?.referencedChatId)return r.referencedChatId;a=r?.inResponseToId??void 0;}}function T(e,t){let a=_(e),n=a.next();for(;!n.done;)n=a.next(t(n.value));return n.value}function C(e){return e.callProviderMetadata?.dvina?.updated===true}function x(e,t){if(e.waitingOn)return "waiting";let a=t===void 0||t==="running",n=r=>r?new Date(r).getTime():0;return a&&e.busyAt&&(!e.idleAt||n(e.busyAt)>n(e.idleAt))?"working":a&&e.queuedAt?"starting":t&&t!=="running"?"ready":e.idleOutcome==="interrupted"?"stopped":"done"}function c(e){let t=e;return typeof t=="object"&&t!==null&&t.guarded==="hold"&&typeof t.note=="string"&&typeof t.hold?.reason=="string"}function m(e){let t=n=>n.type.startsWith("tool-")||n.type==="dynamic-tool",a=e.parts.flatMap((n,r)=>n.type==="step-start"?[r]:[]);for(let n=a.length-1;n>=-1;n--){let r=n<0?0:a[n]??0,i=e.parts.slice(r,a[n+1]??e.parts.length);if(!i.some(t))continue;let s=i.findIndex(o=>t(o)&&o.state==="output-available"&&c(o.output));return s<0?-1:r+s}return -1}function I(e){if(!e)return;let t=m(e);return t<0?void 0:e.parts[t].output.hold}function U(e){let t=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`;return new DefaultChatTransport({api:t,fetch:k(w(e)),prepareSendMessagesRequest:({id:a,messages:n,trigger:r,messageId:i,body:s})=>({api:`${t}/${encodeURIComponent(a)}`,body:{...s,trigger:r,messageId:i,message:n[n.length-1]}}),prepareReconnectToStreamRequest:({id:a})=>({api:`${t}/${encodeURIComponent(a)}/stream`})})}function N(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:k(w(e))})}var f=[1e3,2e3,4e3,8e3,15e3,3e4],u=429,L=6e4;function k(e,t=f,a=[503]){return async(n,r)=>{for(let i of t){let s=await e(n,r).catch(d=>{if(r?.signal?.aborted||!(d instanceof TypeError))throw d;return null}),o=s?.status===u;if(s&&!o&&!a.includes(s.status))return s;await s?.body?.cancel().catch(()=>{}),await v(o?G(s,i):i,r?.signal??void 0);}return e(n,r)}}function G(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),L):t}function v(e,t){return new Promise((a,n)=>{if(t?.aborted)return n(t.reason);let r=setTimeout(()=>{t?.removeEventListener("abort",i),a();},e),i=()=>{clearTimeout(r),n(t?.reason);};t?.addEventListener("abort",i,{once:true});})}var z=a();function w(e){let t=e.fetch??globalThis.fetch.bind(globalThis),a=async(n,r,i)=>{let s=new Headers(r?.headers);s.set("Authorization",`Bearer ${await e.getToken({forceRefresh:i})}`);let o=z();o&&!s.has("x-user-timezone")&&s.set("x-user-timezone",o);let d=e.getLanguage?.();return d&&!s.has("x-preferred-language")&&s.set("x-preferred-language",d),t(n,{...r,headers:s})};return async(n,r)=>{let i=await a(n,r,false);return i.status===401?a(n,r,true):i}}async function H(e,t,a,n){await l(()=>e.sendChatMessageWhileRunning({chatId:t,message:a}),{statuses:X,rateLimited:true,signal:n});}async function j(e,t){let a=await l(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof a=="string"&&a.trim()?a:null}async function F(e,t){await l(()=>e.stopChat({chatId:t}),{statuses:O});}function W(e,t,a,n){return h(()=>e.respondChatApproval({chatId:t,toolCallId:a,approved:n.approved}))}function Y(e,t,a,n){return h(()=>e.answerChatQuestion({chatId:t,toolCallId:a,answers:n}))}function $(e,t,a,n){return h(()=>e.answerChatToolCall({chatId:t,toolCallId:a,...n}))}async function Q(e){return {started:await e.startChatDay()}}async function h(e){try{return await l(e,{statuses:O,signal:AbortSignal.timeout(K)}),"sent"}catch(t){if(q(t))return "answered-elsewhere";throw t}}function q(e){return e instanceof b$1&&e.errors.some(t=>t.message===A||t.extensions?.code===A)}var A="NOT_WAITING";function V(e){return e instanceof c$1?e.status===u: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===u)}var B=[503],X=[500,502,503,504],O=[502,503,504],K=9e4,R=0;async function l(e,{delaysMs:t=f,statuses:a=B,rateLimited:n=false,signal:r}={}){let i=s=>s instanceof c$1&&(s.status===R||a.includes(s.status??R))||n&&V(s);for(let s of t){try{return await S(e(),r)}catch(o){if(r?.aborted||!i(o))throw o}await v(s,r);}return S(e(),r)}function S(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 D(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function J(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 E=200;async function Z(e,t,{pageSize:a=E}={}){let n=[],r;for(;;){let i=await e.chatMessages({...t,first:a,after:r}).fetch();n.push(...i.nodes.map(D));let s=i.pageInfo.endCursor??void 0;if(!i.pageInfo.hasNextPage||!s||s===r)return n;r=s;}}function ee(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(i=>typeof i=="string"):[]}}export{b as LIVE_FILE_FORMATS,E as MAX_MESSAGE_PAGE,Y as answerDvinaQuestion,$ as answerDvinaToolCall,U as createDvinaChatTransport,N as createDvinaTemporaryChatTransport,J as dvinaMessagePageOf,D as dvinaUIMessageOf,m as endingHoldIndex,I as endingHoldOf,Z as fetchAllDvinaChatMessages,j as fetchDvinaNextPrompt,c as isHeldOutput,ee as lazyToolOutputOf,H as postDvinaChatMessage,T as replyTargetIn,W as respondDvinaApproval,Q as startDvinaDay,F as stopDvinaChat,x as taskStateOf,C as wasUpdated};
1
+ import {a}from'../chunk-32KGDH2Q.js';import {b,c as c$1}from'../chunk-XBOJ7CCU.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';var A={html:"html",htm:"html",md:"markdown",markdown:"markdown",csv:"csv",svg:"svg",mmd:"mermaid",mermaid:"mermaid"},$=2;function*Q(e,{named:t=true}={}){if(e?.role!=="user")return;if(t&&e.metadata?.inResponseToTaskChatId)return e.metadata.inResponseToTaskChatId;let a=e.metadata?.inResponseToId??void 0;for(let n=0;a&&n<$;n++){let s=yield a;if(s?.referencedChatId)return s.referencedChatId;a=s?.inResponseToId??void 0;}}function O(e,t){let a=Q(e),n=a.next();for(;!n.done;)n=a.next(t(n.value));return n.value}function R(e){return e.callProviderMetadata?.dvina?.updated===true}function S(e){let t=e.input??{},a=[t.title,...(Array.isArray(t.tasks)?t.tasks:[]).map(x)].map(u),n=i=>i===0?e.toolCallId:`${e.toolCallId}:${i}`;if(e.state==="output-available"){let i=e.output??{},r=(Array.isArray(i.tasks)?i.tasks:[]).flatMap(l=>{let g=u(l?.chatId);return g?[{chatId:g,title:u(x(l))}]:[]}),o=u(i.chatId)??u(t.chatId),d=r.length?r:o?[{chatId:o,title:a[0]??null}]:[],b=new Set;return d.map((l,g)=>{let I=a.findIndex((C,Y)=>!b.has(Y)&&!!C&&C===l.title),M=I>=0?I:g;return b.add(M),{...l,key:n(M)}})}let s=e.state==="input-streaming"?null:u(t.chatId);return s?[{chatId:s,title:a[0]??null,key:n(0)}]:a.map((i,r)=>({chatId:null,title:i,key:n(r)}))}function x(e){return e?.title}function u(e){return typeof e=="string"&&e.trim()?e.trim():null}function P(e,t){if(e.waitingOn)return "waiting";let a=t===void 0||t==="running",n=s=>s?new Date(s).getTime():0;return a&&e.busyAt&&(!e.idleAt||n(e.busyAt)>n(e.idleAt))?"working":a&&e.queuedAt?"starting":t&&t!=="running"?"ready":e.idleOutcome==="interrupted"?"stopped":"done"}function v(e){let t=e;return typeof t=="object"&&t!==null&&t.guarded==="hold"&&typeof t.note=="string"&&typeof t.hold?.reason=="string"}function h(e){let t=n=>n.type.startsWith("tool-")||n.type==="dynamic-tool",a=e.parts.flatMap((n,s)=>n.type==="step-start"?[s]:[]);for(let n=a.length-1;n>=-1;n--){let s=n<0?0:a[n]??0,i=e.parts.slice(s,a[n+1]??e.parts.length);if(!i.some(t))continue;let r=i.findIndex(o=>t(o)&&o.state==="output-available"&&v(o.output));return r<0?-1:s+r}return -1}function E(e){if(!e)return;let t=h(e);return t<0?void 0:e.parts[t].output.hold}var q=["threadId","inResponseToId","inResponseToExcerpt","inResponseToTaskChatId","resourceFiles","voiceInput","surface","screenContext","hidden"],V=new Set(["text","file","data-context"]);function _(e,t,a){let n={};for(let r of q){let o=e.metadata?.[r];o!=null&&o!==false&&Object.assign(n,{[r]:o});}let{createdAt:s,afterReply:i}=a;return {id:t,role:"user",parts:e.parts.filter(r=>V.has(r.type)),metadata:{...n,...s?{createdAt:s}:{},...i?{afterReply:i}:{},retryOf:e.id}}}function U(e,t){let a=t.metadata?.inResponseToId;if(a)return e.find(s=>s.id===a&&s.role==="user");let n=e.indexOf(t);return (n<0?e:e.slice(0,n)).findLast(s=>s.role==="user")}function B(e){let t=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`;return new DefaultChatTransport({api:t,fetch:L(G(e)),prepareSendMessagesRequest:({id:a,messages:n,trigger:s,messageId:i,body:r})=>({api:`${t}/${encodeURIComponent(a)}`,body:{...r,trigger:s,messageId:i,message:n[n.length-1]}}),prepareReconnectToStreamRequest:({id:a})=>({api:`${t}/${encodeURIComponent(a)}/stream`})})}function X(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:L(G(e))})}var D=[1e3,2e3,4e3,8e3,15e3,3e4],p=429,K=6e4;function L(e,t=D,a=[503]){return async(n,s)=>{for(let i of t){let r=await e(n,s).catch(d=>{if(s?.signal?.aborted||!(d instanceof TypeError))throw d;return null}),o=r?.status===p;if(r&&!o&&!a.includes(r.status))return r;await r?.body?.cancel().catch(()=>{}),await y(o?J(r,i):i,s?.signal??void 0);}return e(n,s)}}function J(e,t){let a=Number.NaN;return e.headers.forEach((n,s)=>{Number.isNaN(a)&&s.toLowerCase().startsWith("retry-after")&&(a=Number(n));}),Number.isFinite(a)&&a>0?Math.min(Math.max(a*1e3,t),K):t}function y(e,t){return new Promise((a,n)=>{if(t?.aborted)return n(t.reason);let s=setTimeout(()=>{t?.removeEventListener("abort",i),a();},e),i=()=>{clearTimeout(s),n(t?.reason);};t?.addEventListener("abort",i,{once:true});})}var Z=a();function G(e){let t=e.fetch??globalThis.fetch.bind(globalThis),a=async(n,s,i)=>{let r=new Headers(s?.headers);r.set("Authorization",`Bearer ${await e.getToken({forceRefresh:i})}`);let o=Z();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(n,{...s,headers:r})};return async(n,s)=>{let i=await a(n,s,false);return i.status===401?a(n,s,true):i}}async function ee(e,t,a,n){await c(()=>e.sendChatMessageWhileRunning({chatId:t,message:a}),{statuses:le,rateLimited:true,signal:n});}async function te(e,t){let a=await c(()=>e.chatNextPrompt({chatId:t}),{delaysMs:[1e3,3e3]});return typeof a=="string"&&a.trim()?a:null}async function ne(e,t){await c(()=>e.stopChat({chatId:t}),{statuses:F});}function ae(e,t,a,n){return T(()=>e.respondChatApproval({chatId:t,toolCallId:a,approved:n.approved}))}function se(e,t,a,n){return T(()=>e.answerChatQuestion({chatId:t,toolCallId:a,answers:n}))}function re(e,t,a,n){return T(()=>e.answerChatToolCall({chatId:t,toolCallId:a,...n}))}async function ie(e){return {started:await e.startChatDay()}}async function T(e){try{return await c(e,{statuses:F,signal:AbortSignal.timeout(ge)}),"sent"}catch(t){if(oe(t))return "answered-elsewhere";throw t}}function oe(e){return e instanceof b&&e.errors.some(t=>t.message===H||t.extensions?.code===H)}var H="NOT_WAITING";function de(e){return e instanceof c$1?e.status===p:e instanceof b&&e.errors.some(t=>/ThrottlerException|Too Many Requests/i.test(t.message)||t.extensions?.code==="TOO_MANY_REQUESTS"||t.extensions?.originalError?.statusCode===p)}var ue=[503],le=[500,502,503,504],F=[502,503,504],ge=9e4,z=0;async function c(e,{delaysMs:t=D,statuses:a=ue,rateLimited:n=false,signal:s}={}){let i=r=>r instanceof c$1&&(r.status===z||a.includes(r.status??z))||n&&de(r);for(let r of t){try{return await j(e(),s)}catch(o){if(s?.aborted||!i(o))throw o}await y(r,s);}return j(e(),s)}function j(e,t){return t?t.aborted?Promise.reject(t.reason):new Promise((a,n)=>{let s=()=>n(t.reason);t.addEventListener("abort",s,{once:true}),e.then(a,n).finally(()=>t.removeEventListener("abort",s));}):e}function k(e){return {id:e.id,role:e.role,parts:e.parts??[],...e.metadata?{metadata:e.metadata}:{}}}function pe(e){let{pageInfo:t}=e;return {messages:e.nodes.map(k),hasOlder:t.hasPreviousPage,hasNewer:t.hasNextPage,...t.startCursor?{startCursor:t.startCursor}:{},...t.endCursor?{endCursor:t.endCursor}:{}}}var W=200;async function ce(e,t,{pageSize:a=W}={}){let n=[],s;for(;;){let i=await e.chatMessages({...t,first:a,after:s}).fetch();n.push(...i.nodes.map(k));let r=i.pageInfo.endCursor??void 0;if(!i.pageInfo.hasNextPage||!r||r===s)return n;s=r;}}function me(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:s}=t;return {bytes:typeof a=="number"?a:0,preview:typeof n=="string"?n:"",urls:Array.isArray(s)?s.filter(i=>typeof i=="string"):[]}}export{A as LIVE_FILE_FORMATS,W as MAX_MESSAGE_PAGE,se as answerDvinaQuestion,re as answerDvinaToolCall,U as answeredMessageOf,B as createDvinaChatTransport,X as createDvinaTemporaryChatTransport,pe as dvinaMessagePageOf,k as dvinaUIMessageOf,h as endingHoldIndex,E as endingHoldOf,ce as fetchAllDvinaChatMessages,te as fetchDvinaNextPrompt,S as handedTasksOf,v as isHeldOutput,me as lazyToolOutputOf,ee as postDvinaChatMessage,O as replyTargetIn,ae as respondDvinaApproval,_ as sentAgain,ie as startDvinaDay,ne as stopDvinaChat,P as taskStateOf,R as wasUpdated};