@squidcloud/backend 1.0.498 → 1.0.500

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 +1 @@
1
- import{getPassiveSquid as t,metadata as e}from"@squidcloud/backend";import{Command as a}from"@langchain/langgraph";import{BaseCheckpointSaver as n,WRITES_IDX_MAP as o,copyCheckpoint as i,getCheckpointId as r}from"@langchain/langgraph-checkpoint";let c=t=>new Error(t);function s(t,e,...a){t||function(t,...e){const a=function(t){return void 0===t?"":"string"==typeof t?t:t()}(t);if("object"==typeof a)throw a;throw c(a||"Assertion error",...e)}(e,...a)}const d=36e5;class h extends n{constructor(t){super(),this.graphId=t}async getTuple(t){const{threadId:e,checkpointNs:a,checkpointId:n}=p(t),{graphId:o}=this,i=n?await this.postUnlessNotFound("getCheckpoint",{graphId:o,threadId:e,checkpointId:n}):await this.postUnlessNotFound("getLatestCheckpoint",{graphId:o,threadId:e,checkpointNs:a});return i&&await this.toTuple(i)}async*list(t,e={}){const{threadId:a,checkpointNs:n}=p(t),{limit:o,before:i,filter:c}=e,s={graphId:this.graphId,threadId:a,checkpointNs:n,limit:c?void 0:o,beforeCheckpointId:i&&r(i)||void 0},{checkpoints:d}=await this.post("listCheckpoints",s);let h=o??1/0;for(const t of d){if(h<=0)return;const e=await this.toTuple(t),a=e.metadata??{};c&&!Object.entries(c).every(([t,e])=>a[t]===e)||(h--,yield e)}}async put(t,e,a,n){const{threadId:o,checkpointNs:r,checkpointId:c}=p(t),s={graphId:this.graphId,threadId:o,checkpointNs:r,checkpointId:e.id,checkpoint:await this.dump(i(e)),parentCheckpointId:c??null,metadata:await this.dump(a)};return await this.post("saveCheckpoint",s),{configurable:{thread_id:o,checkpoint_ns:r,checkpoint_id:e.id}}}async putWrites(t,e,a){const{threadId:n,checkpointNs:i,checkpointId:r}=p(t);s(r,"Failed to put writes: the config has no checkpoint_id");const c=await Promise.all(e.map(async([t,e],n)=>({channel:t,taskId:a,idx:o[t]??n,value:await this.dump(e)}))),d={graphId:this.graphId,threadId:n,checkpointNs:i,checkpointId:r,writes:c};await this.post("savePendingWrites",d)}async deleteThread(t){await this.post("deleteCheckpoints",{graphId:this.graphId,threadId:t})}async toTuple(t){const{threadId:e,checkpointNs:a,checkpointId:n,parentCheckpointId:o}=t,i=t=>({configurable:{thread_id:e,checkpoint_ns:a,checkpoint_id:t}}),r=await Promise.all(t.pendingWrites.map(async({taskId:t,channel:e,value:a})=>[t,e,await this.load(a)]));return{config:i(n),checkpoint:await this.load(t.checkpoint),metadata:t.metadata?await this.load(t.metadata):void 0,parentConfig:o?i(o):void 0,pendingWrites:r}}async dump(t){const[e,a]=await this.serde.dumpsTyped(t),n=[e,{__bytes__:Buffer.from(a).toString("base64")}];return JSON.stringify(n)}async load(t){const[e,{__bytes__:a}]=JSON.parse(t);return await this.serde.loadsTyped(e,Buffer.from(a,"base64"))}async post(e,a){return await t().rpcManager.post(`langgraph/${e}`,a)}async postUnlessNotFound(t,e){try{return await this.post(t,e)}catch(t){if(404===t.statusCode)return;throw t}}}function p(t){const e=t.configurable?.thread_id;s("string"==typeof e&&e,"The LangGraph config has no thread_id");const a=t.configurable?.checkpoint_ns;return{threadId:e,checkpointNs:"string"==typeof a?a:"",checkpointId:r(t)||void 0}}async function u(t,e){const{graphId:n,operation:o,input:i,resumePayload:r,timeoutMs:c}=e,s=new h(n),p=t.compile({checkpointer:s}),u=e.threadId??("function"==typeof globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})),l={configurable:{thread_id:u}};if("getState"!==o){const t="resume"===o&&await s.getTuple(l)?new a({resume:r}):i??{},e=AbortSignal.timeout(c??d);try{await p.invoke(t,{...l,signal:e})}catch(t){if(e.aborted)return{ok:!1,errorCode:"TIMEOUT",error:`The graph run did not finish within ${c??d} ms`};throw t}}const g=await p.getState(l),f=[...g.next],k=(I=g.values)&&"object"==typeof I?JSON.parse(JSON.stringify(I)):{};var I;return"getState"===o?{ok:!0,threadId:u,state:k,next:f}:{ok:!0,threadId:u,status:f.length?"interrupted":"completed",state:k,next:f}}function l(t,a={}){return function(n,o,i){e.langGraph(t,`${n.constructor.name}:${o}`,a.description);const r=function(t,e,...a){return s(t,e,...a),t}(i.value,()=>`@langGraph can only decorate a method: ${o}`);return i.value=function(...t){const[e]=t;return(a=e)&&"object"==typeof a&&!0===a.__squidLangGraphRun__?async function(t,e,a){const n=await t;return s(function(t){return"function"==typeof t?.compile}(n),()=>`@langGraph function '${e}' must return an uncompiled StateGraph, got ${function(t){return null===t?"null":"object"==typeof t?t.constructor?.name??"object":typeof t}(n)}`),await u(n,a)}(r.apply(this,[]),o,e):r.apply(this,[]);var a},i}}export{h as SquidCheckpointer,l as langGraph,u as runLangGraphRequest};
1
+ import{getPassiveSquid as t,metadata as e}from"@squidcloud/backend";import{Command as a}from"@langchain/langgraph";import{BaseCheckpointSaver as n,WRITES_IDX_MAP as o,copyCheckpoint as i,getCheckpointId as r}from"@langchain/langgraph-checkpoint";let c=t=>new Error(t);function s(t,e,...a){t||function(t,...e){const a=function(t){return void 0===t?"":"string"==typeof t?t:t()}(t);if("object"==typeof a)throw a;throw c(a||"Assertion error",...e)}(e,...a)}const h=36e5;class d extends n{constructor(t){super(),this.graphId=t}async getTuple(t){const{threadId:e,checkpointNs:a,checkpointId:n}=p(t),{graphId:o}=this,i=n?await this.postUnlessNotFound("getCheckpoint",{graphId:o,threadId:e,checkpointId:n}):await this.postUnlessNotFound("getLatestCheckpoint",{graphId:o,threadId:e,checkpointNs:a});return i&&await this.toTuple(i)}async*list(t,e={}){const{threadId:a,checkpointNs:n}=p(t),{limit:o,before:i,filter:c}=e,s={graphId:this.graphId,threadId:a,checkpointNs:n,limit:c?void 0:o,beforeCheckpointId:i&&r(i)||void 0},{checkpoints:h}=await this.post("listCheckpoints",s);let d=o??1/0;for(const t of h){if(d<=0)return;const e=await this.toTuple(t),a=e.metadata??{};c&&!Object.entries(c).every(([t,e])=>a[t]===e)||(d--,yield e)}}async put(t,e,a,n){const{threadId:o,checkpointNs:r,checkpointId:c}=p(t),s={graphId:this.graphId,threadId:o,checkpointNs:r,checkpointId:e.id,checkpoint:await this.dump(i(e)),parentCheckpointId:c??null,metadata:await this.dump(a)};return await this.post("saveCheckpoint",s),{configurable:{thread_id:o,checkpoint_ns:r,checkpoint_id:e.id}}}async putWrites(t,e,a){const{threadId:n,checkpointNs:i,checkpointId:r}=p(t);s(r,"Failed to put writes: the config has no checkpoint_id");const c=await Promise.all(e.map(async([t,e],n)=>({channel:t,taskId:a,idx:o[t]??n,value:await this.dump(e)}))),h={graphId:this.graphId,threadId:n,checkpointNs:i,checkpointId:r,writes:c};await this.post("savePendingWrites",h)}async deleteThread(t){await this.post("deleteCheckpoints",{graphId:this.graphId,threadId:t})}async toTuple(t){const{threadId:e,checkpointNs:a,checkpointId:n,parentCheckpointId:o}=t,i=t=>({configurable:{thread_id:e,checkpoint_ns:a,checkpoint_id:t}}),r=await Promise.all(t.pendingWrites.map(async({taskId:t,channel:e,value:a})=>[t,e,await this.load(a)]));return{config:i(n),checkpoint:await this.load(t.checkpoint),metadata:t.metadata?await this.load(t.metadata):void 0,parentConfig:o?i(o):void 0,pendingWrites:r}}async dump(t){const[e,a]=await this.serde.dumpsTyped(t),n=[e,{__bytes__:Buffer.from(a).toString("base64")}];return JSON.stringify(n)}async load(t){const[e,{__bytes__:a}]=JSON.parse(t);return await this.serde.loadsTyped(e,Buffer.from(a,"base64"))}async post(e,a){return await t().rpcManager.post(`langgraph/${e}`,a)}async postUnlessNotFound(t,e){try{return await this.post(t,e)}catch(t){if(404===t.statusCode)return;throw t}}}function p(t){const e=t.configurable?.thread_id;s("string"==typeof e&&e,"The LangGraph config has no thread_id");const a=t.configurable?.checkpoint_ns;return{threadId:e,checkpointNs:"string"==typeof a?a:"",checkpointId:r(t)||void 0}}async function u(t,e){const{graphId:n,operation:o,input:i,resumePayload:r,timeoutMs:c,graphContext:s}=e,p=new d(n),u=t.compile({checkpointer:p}),l=e.threadId??("function"==typeof globalThis.crypto?.randomUUID?globalThis.crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)})),g={configurable:{thread_id:l}};if("getState"!==o){const t="resume"===o&&await p.getTuple(g)?new a({resume:r}):i??{},e=AbortSignal.timeout(c??h);try{await u.invoke(t,{...g,signal:e,context:s})}catch(t){if(e.aborted)return{ok:!1,errorCode:"TIMEOUT",error:`The graph run did not finish within ${c??h} ms`};throw t}}const f=await u.getState(g),k=[...f.next],I=(m=f.values)&&"object"==typeof m?JSON.parse(JSON.stringify(m)):{};var m;return"getState"===o?{ok:!0,threadId:l,state:I,next:k}:{ok:!0,threadId:l,status:k.length?"interrupted":"completed",state:I,next:k}}function l(t,a={}){return function(n,o,i){e.langGraph(t,`${n.constructor.name}:${o}`,a.description);const r=function(t,e,...a){return s(t,e,...a),t}(i.value,()=>`@langGraph can only decorate a method: ${o}`);return i.value=function(...t){const[e]=t;return(a=e)&&"object"==typeof a&&!0===a.__squidLangGraphRun__?async function(t,e,a){const n=await t;return s(function(t){return"function"==typeof t?.compile}(n),()=>`@langGraph function '${e}' must return an uncompiled StateGraph, got ${function(t){return null===t?"null":"object"==typeof t?t.constructor?.name??"object":typeof t}(n)}`),await u(n,a)}(r.apply(this,[]),o,e):r.apply(this,[]);var a},i}}export{d as SquidCheckpointer,l as langGraph,u as runLangGraphRequest};
@@ -1,4 +1,4 @@
1
- import { AiConnectedIntegrationMetadata, AiSessionContext, AllAiAgentChatOptions } from '@squidcloud/client';
1
+ import { AiChatRequestOptions, AiConnectedIntegrationMetadata, AiSessionContext } from '@squidcloud/client';
2
2
  import { AiFunctionId } from '@squidcloud/client';
3
3
  import { AiAgentId, IntegrationId } from '@squidcloud/client';
4
4
  import { AuthWithBearer } from '@squidcloud/client';
@@ -44,7 +44,11 @@ export interface AiFunctionCallContextWithIntegration<AiConnectedIntegrationOpti
44
44
  export declare class SecureAiAgentContext {
45
45
  readonly prompt?: string;
46
46
  readonly agentId: AiAgentId;
47
- readonly options?: AllAiAgentChatOptions;
47
+ /**
48
+ * The request's chat options. `model` may be a routing choice the caller asked for: check
49
+ * `'models' in model` before reading it as a concrete model selection.
50
+ */
51
+ readonly options?: AiChatRequestOptions;
48
52
  }
49
53
  /**
50
54
  * Provides context to a knowledge base's `accessControl.scopeResolver` function, which turns the caller
@@ -11,6 +11,10 @@ export declare class SecureLangGraphContext {
11
11
  readonly operation: SecureLangGraphOperation;
12
12
  readonly graphId: string;
13
13
  readonly threadId?: string;
14
+ /** The input of the run (`invoke`). */
14
15
  readonly input?: Record<string, unknown>;
16
+ /** The value the run resumes with (`resume`). */
15
17
  readonly resumePayload?: unknown;
18
+ /** The context the caller passed for the run (`invoke` and `resume`), which nodes read as `runtime.context`. */
19
+ readonly graphContext?: Record<string, unknown>;
16
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squidcloud/backend",
3
- "version": "1.0.498",
3
+ "version": "1.0.500",
4
4
  "description": "Squid Cloud's backend SDK",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -68,7 +68,7 @@
68
68
  "@langchain/core": "^1.1.48",
69
69
  "@langchain/langgraph": "^1.4.0",
70
70
  "@langchain/langgraph-checkpoint": "^1.1.0",
71
- "@squidcloud/client": "^1.0.498"
71
+ "@squidcloud/client": "^1.0.500"
72
72
  },
73
73
  "peerDependenciesMeta": {
74
74
  "@langchain/core": {