@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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/langgraph.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/langgraph.js +1 -1
- package/dist/internal-common/src/public-types-backend/ai-agent.public-context.d.ts +6 -2
- package/dist/internal-common/src/public-types-backend/langgraph.public-context.d.ts +4 -0
- package/package.json +2 -2
package/dist/cjs/langgraph.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const t={d:(e,n)=>{if(Array.isArray(n))for(var a=0;a<n.length;){var o=n[a++],r=n[a++];t.o(e,o)?0===r&&a++:0===r?Object.defineProperty(e,o,{enumerable:!0,value:n[a++]}):Object.defineProperty(e,o,{enumerable:!0,get:r})}else for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{SquidCheckpointer:()=>d,langGraph:()=>u,runLangGraphRequest:()=>h});const n=require("@squidcloud/backend");let a=t=>new Error(t);function o(t,e,...n){t||function(t,...e){const n=function(t){return void 0===t?"":"string"==typeof t?t:t()}(t);if("object"==typeof n)throw n;throw a(n||"Assertion error",...e)}(e,...n)}const r="__squidLangGraphRun__",i=require("@langchain/langgraph");const c=36e5,s=require("@langchain/langgraph-checkpoint");class d extends s.BaseCheckpointSaver{constructor(t){super(),this.graphId=t}async getTuple(t){const{threadId:e,checkpointNs:n,checkpointId:a}=p(t),{graphId:o}=this,r=a?await this.postUnlessNotFound("getCheckpoint",{graphId:o,threadId:e,checkpointId:a}):await this.postUnlessNotFound("getLatestCheckpoint",{graphId:o,threadId:e,checkpointNs:n});return r&&await this.toTuple(r)}async*list(t,e={}){const{threadId:n,checkpointNs:a}=p(t),{limit:o,before:r,filter:i}=e,c={graphId:this.graphId,threadId:n,checkpointNs:a,limit:i?void 0:o,beforeCheckpointId:r&&(0,s.getCheckpointId)(r)||void 0},{checkpoints:d}=await this.post("listCheckpoints",c);let h=o??1/0;for(const t of d){if(h<=0)return;const e=await this.toTuple(t),n=e.metadata??{};i&&!Object.entries(i).every(([t,e])=>n[t]===e)||(h--,yield e)}}async put(t,e,n,a){const{threadId:o,checkpointNs:r,checkpointId:i}=p(t),c={graphId:this.graphId,threadId:o,checkpointNs:r,checkpointId:e.id,checkpoint:await this.dump((0,s.copyCheckpoint)(e)),parentCheckpointId:i??null,metadata:await this.dump(n)};return await this.post("saveCheckpoint",c),{configurable:{thread_id:o,checkpoint_ns:r,checkpoint_id:e.id}}}async putWrites(t,e,n){const{threadId:a,checkpointNs:r,checkpointId:i}=p(t);o(i,"Failed to put writes: the config has no checkpoint_id");const c=await Promise.all(e.map(async([t,e],a)=>({channel:t,taskId:n,idx:s.WRITES_IDX_MAP[t]??a,value:await this.dump(e)}))),d={graphId:this.graphId,threadId:a,checkpointNs:r,checkpointId:i,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:n,checkpointId:a,parentCheckpointId:o}=t,r=t=>({configurable:{thread_id:e,checkpoint_ns:n,checkpoint_id:t}}),i=await Promise.all(t.pendingWrites.map(async({taskId:t,channel:e,value:n})=>[t,e,await this.load(n)]));return{config:r(a),checkpoint:await this.load(t.checkpoint),metadata:t.metadata?await this.load(t.metadata):void 0,parentConfig:o?r(o):void 0,pendingWrites:i}}async dump(t){const[e,n]=await this.serde.dumpsTyped(t),a=[e,{__bytes__:Buffer.from(n).toString("base64")}];return JSON.stringify(a)}async load(t){const[e,{__bytes__:n}]=JSON.parse(t);return await this.serde.loadsTyped(e,Buffer.from(n,"base64"))}async post(t,e){return await(0,n.getPassiveSquid)().rpcManager.post(`langgraph/${t}`,e)}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;o("string"==typeof e&&e,"The LangGraph config has no thread_id");const n=t.configurable?.checkpoint_ns;return{threadId:e,checkpointNs:"string"==typeof n?n:"",checkpointId:(0,s.getCheckpointId)(t)||void 0}}async function h(t,e){const{graphId:n,operation:a,input:o,resumePayload:r,timeoutMs:s}=e,
|
|
1
|
+
(()=>{"use strict";const t={d:(e,n)=>{if(Array.isArray(n))for(var a=0;a<n.length;){var o=n[a++],r=n[a++];t.o(e,o)?0===r&&a++:0===r?Object.defineProperty(e,o,{enumerable:!0,value:n[a++]}):Object.defineProperty(e,o,{enumerable:!0,get:r})}else for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}};let e={};t.r(e),t.d(e,{SquidCheckpointer:()=>d,langGraph:()=>u,runLangGraphRequest:()=>h});const n=require("@squidcloud/backend");let a=t=>new Error(t);function o(t,e,...n){t||function(t,...e){const n=function(t){return void 0===t?"":"string"==typeof t?t:t()}(t);if("object"==typeof n)throw n;throw a(n||"Assertion error",...e)}(e,...n)}const r="__squidLangGraphRun__",i=require("@langchain/langgraph");const c=36e5,s=require("@langchain/langgraph-checkpoint");class d extends s.BaseCheckpointSaver{constructor(t){super(),this.graphId=t}async getTuple(t){const{threadId:e,checkpointNs:n,checkpointId:a}=p(t),{graphId:o}=this,r=a?await this.postUnlessNotFound("getCheckpoint",{graphId:o,threadId:e,checkpointId:a}):await this.postUnlessNotFound("getLatestCheckpoint",{graphId:o,threadId:e,checkpointNs:n});return r&&await this.toTuple(r)}async*list(t,e={}){const{threadId:n,checkpointNs:a}=p(t),{limit:o,before:r,filter:i}=e,c={graphId:this.graphId,threadId:n,checkpointNs:a,limit:i?void 0:o,beforeCheckpointId:r&&(0,s.getCheckpointId)(r)||void 0},{checkpoints:d}=await this.post("listCheckpoints",c);let h=o??1/0;for(const t of d){if(h<=0)return;const e=await this.toTuple(t),n=e.metadata??{};i&&!Object.entries(i).every(([t,e])=>n[t]===e)||(h--,yield e)}}async put(t,e,n,a){const{threadId:o,checkpointNs:r,checkpointId:i}=p(t),c={graphId:this.graphId,threadId:o,checkpointNs:r,checkpointId:e.id,checkpoint:await this.dump((0,s.copyCheckpoint)(e)),parentCheckpointId:i??null,metadata:await this.dump(n)};return await this.post("saveCheckpoint",c),{configurable:{thread_id:o,checkpoint_ns:r,checkpoint_id:e.id}}}async putWrites(t,e,n){const{threadId:a,checkpointNs:r,checkpointId:i}=p(t);o(i,"Failed to put writes: the config has no checkpoint_id");const c=await Promise.all(e.map(async([t,e],a)=>({channel:t,taskId:n,idx:s.WRITES_IDX_MAP[t]??a,value:await this.dump(e)}))),d={graphId:this.graphId,threadId:a,checkpointNs:r,checkpointId:i,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:n,checkpointId:a,parentCheckpointId:o}=t,r=t=>({configurable:{thread_id:e,checkpoint_ns:n,checkpoint_id:t}}),i=await Promise.all(t.pendingWrites.map(async({taskId:t,channel:e,value:n})=>[t,e,await this.load(n)]));return{config:r(a),checkpoint:await this.load(t.checkpoint),metadata:t.metadata?await this.load(t.metadata):void 0,parentConfig:o?r(o):void 0,pendingWrites:i}}async dump(t){const[e,n]=await this.serde.dumpsTyped(t),a=[e,{__bytes__:Buffer.from(n).toString("base64")}];return JSON.stringify(a)}async load(t){const[e,{__bytes__:n}]=JSON.parse(t);return await this.serde.loadsTyped(e,Buffer.from(n,"base64"))}async post(t,e){return await(0,n.getPassiveSquid)().rpcManager.post(`langgraph/${t}`,e)}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;o("string"==typeof e&&e,"The LangGraph config has no thread_id");const n=t.configurable?.checkpoint_ns;return{threadId:e,checkpointNs:"string"==typeof n?n:"",checkpointId:(0,s.getCheckpointId)(t)||void 0}}async function h(t,e){const{graphId:n,operation:a,input:o,resumePayload:r,timeoutMs:s,graphContext:p}=e,h=new d(n),u=t.compile({checkpointer:h}),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"!==a){const t="resume"===a&&await h.getTuple(g)?new i.Command({resume:r}):o??{},e=AbortSignal.timeout(s??c);try{await u.invoke(t,{...g,signal:e,context:p})}catch(t){if(e.aborted)return{ok:!1,errorCode:"TIMEOUT",error:`The graph run did not finish within ${s??c} ms`};throw t}}const f=await u.getState(g),y=[...f.next],k=(I=f.values)&&"object"==typeof I?JSON.parse(JSON.stringify(I)):{};var I;return"getState"===a?{ok:!0,threadId:l,state:k,next:y}:{ok:!0,threadId:l,status:y.length?"interrupted":"completed",state:k,next:y}}function u(t,e={}){return function(a,i,c){n.metadata.langGraph(t,`${a.constructor.name}:${i}`,e.description);const s=function(t,e,...n){return o(t,e,...n),t}(c.value,()=>`@langGraph can only decorate a method: ${i}`);return c.value=function(...t){const[e]=t;return(n=e)&&"object"==typeof n&&!0===n[r]?async function(t,e,n){const a=await t;return o(function(t){return"function"==typeof t?.compile}(a),()=>`@langGraph function '${e}' must return an uncompiled StateGraph, got ${function(t){return null===t?"null":"object"==typeof t?t.constructor?.name??"object":typeof t}(a)}`),await h(a,n)}(s.apply(this,[]),i,e):s.apply(this,[]);var n},c}}const l=exports;for(var g in e)l[g]=e[g];e.__esModule&&Object.defineProperty(l,"__esModule",{value:!0})})();
|