@dvina/sdk 5.0.20 → 5.0.22

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-DJke28Sk.js';
2
+ import { D as DvinaSdk, C as ChatMessage, a as ChatMessageConnection } from '../_generated_sdk-BkmfU2Ek.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;
@@ -121,6 +140,11 @@ type DvinaMessageMetadata = {
121
140
  } | null;
122
141
  /** On a user message: it began as the predicted next message (accepted with Tab or a tap). */
123
142
  nextPromptUsed?: boolean;
143
+ /**
144
+ * On an assistant reply whose turn waits for something outside it (`DvinaTurnHold`) and then goes on by itself in
145
+ * this reply. Cleared when the turn goes on.
146
+ */
147
+ onHold?: DvinaTurnHold;
124
148
  };
125
149
  /** Custom data parts streamed alongside text and tool parts. */
126
150
  type DvinaDataParts = {
@@ -363,7 +387,10 @@ type DvinaDataParts = {
363
387
  type DvinaGoalStatus = 'proposed' | 'pursuing'
364
388
  /** Waiting on the user's decision: accept the best version, adjust, one more round or stop. */
365
389
  | 'checkpoint' | 'achieved'
366
- /** A limit (rounds, time, usage) ended it; the best round is the result. */
390
+ /**
391
+ * It ended with its best round as the result: at the Livespace admin's cap (rounds, usage) or the user's usage quota,
392
+ * or quietly at the system's safety ceiling.
393
+ */
367
394
  | 'limit'
368
395
  /** The user accepted a version that did not meet it. */
369
396
  | 'accepted' | 'stopped'
@@ -384,17 +411,18 @@ type DvinaGoalCriterion = {
384
411
  min?: number;
385
412
  };
386
413
  };
387
- /** A task's goal: what to achieve, when it is done, how that is judged (its rubric) and the run's limits. */
414
+ /** A task's goal: what to achieve, when it is done, and how that is judged (its rubric). It works until it is met. */
388
415
  type DvinaGoal = {
389
416
  objective: string;
390
417
  doneWhen: string;
391
418
  criteria: DvinaGoalCriterion[];
392
419
  /** Weighted score needed, 0 to 1. */
393
420
  threshold: number;
394
- limits: {
395
- maxRounds: number;
396
- maxMinutes: number;
397
- maxUsagePercent: number;
421
+ /** An older goal's own limits; a goal no longer has any (only the Livespace admin's caps apply). */
422
+ limits?: {
423
+ maxRounds?: number;
424
+ maxMinutes?: number;
425
+ maxUsagePercent?: number;
398
426
  };
399
427
  /** The rubric template (a skill) it follows. */
400
428
  template?: {
@@ -404,7 +432,8 @@ type DvinaGoal = {
404
432
  };
405
433
  type DvinaGoalEvaluation = {
406
434
  round: number;
407
- maxRounds: number;
435
+ /** An older evaluation's most rounds; a goal no longer has a limit of its own. */
436
+ maxRounds?: number;
408
437
  /** Weighted score, 0 to 1. */
409
438
  score: number;
410
439
  threshold: number;
@@ -567,4 +596,4 @@ type DvinaLazyToolOutput = {
567
596
  /** The held-back output a tool part carries instead of its output, or `null` for a whole output. */
568
597
  declare function lazyToolOutputOf(output: unknown): DvinaLazyToolOutput | null;
569
598
 
570
- 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 };
599
+ 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,3 @@
1
1
  import {a}from'../chunk-32KGDH2Q.js';import {b,c as c$1}from'../chunk-37LLNIGO.js';import'../chunk-EK7ODJWE.js';import {DefaultChatTransport}from'ai';var w="replay";function S(e,{keepsReply:t}={}){let a=`${e.apiUrl.replace(/\/+$/,"")}/api/chat`,n=g(l(e)),r=async(s,o)=>{let i=await n(s,o);return !((o?.method??"GET")==="GET"&&String(s).endsWith("/stream"))||!i.ok||!i.body||!t?.()?i:new Response(i.body.pipeThrough(k()),i)};return new DefaultChatTransport({api:a,fetch:r,prepareSendMessagesRequest:({id:s,messages:o,trigger:i,messageId:u,body:b})=>({api:`${a}/${encodeURIComponent(s)}`,body:{...b,trigger:i,messageId:u,message:o[o.length-1]}}),prepareReconnectToStreamRequest:({id:s})=>({api:`${a}/${encodeURIComponent(s)}/stream`})})}function x(e){return new DefaultChatTransport({api:`${e.apiUrl.replace(/\/+$/,"")}/api/temporary-chat`,fetch:g(l(e))})}var _=[1e3,2e3,4e3,8e3,15e3,3e4],E=429,P=6e4;function g(e,t=_,a=[503]){return async(n,r)=>{for(let s of t){let o=await e(n,r).catch(u=>{if(r?.signal?.aborted||!(u instanceof TypeError))throw u;return null}),i=o?.status===E;if(o&&!i&&!a.includes(o.status))return o;await o?.body?.cancel().catch(()=>{}),await O(i?R(o,s):s,r?.signal??void 0);}return e(n,r)}}function R(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),P):t}function O(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});})}var U=a();function l(e){let t=e.fetch??globalThis.fetch.bind(globalThis),a=async(n,r,s)=>{let o=new Headers(r?.headers);o.set("Authorization",`Bearer ${await e.getToken({forceRefresh:s})}`);let i=U();i&&!o.has("x-user-timezone")&&o.set("x-user-timezone",i);let u=e.getLanguage?.();return u&&!o.has("x-preferred-language")&&o.set("x-preferred-language",u),t(n,{...r,headers:o})};return async(n,r)=>{let s=await a(n,r,false);return s.status===401?a(n,r,true):s}}function k(){let e=new TextDecoder,t=new TextEncoder,a="",n=r=>!r.split(/\r?\n/).some(s=>s===`event: ${w}`);return new TransformStream({transform(r,s){a+=e.decode(r,{stream:true});let o=a.split(/\r?\n\r?\n/);a=o.pop()??"";let i=o.filter(n).map(u=>`${u}
2
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};
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 H(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 H(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 X(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 B(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,X as dvinaMessagePageOf,d as dvinaUIMessageOf,B 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};