zeitlich 0.2.37 → 0.2.38
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/{activities-Bb-nAjwQ.d.ts → activities-BKhMtKDd.d.ts} +4 -2
- package/dist/{activities-vkI4_3CC.d.cts → activities-CDcwkRZs.d.cts} +4 -2
- package/dist/adapters/sandbox/bedrock/index.cjs +3 -3
- package/dist/adapters/sandbox/bedrock/index.cjs.map +1 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +6 -6
- package/dist/adapters/sandbox/bedrock/index.d.ts +6 -6
- package/dist/adapters/sandbox/bedrock/index.js +3 -3
- package/dist/adapters/sandbox/bedrock/index.js.map +1 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +2 -2
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +3 -3
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +4 -4
- package/dist/adapters/sandbox/daytona/index.d.ts +4 -4
- package/dist/adapters/sandbox/daytona/index.js +3 -3
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +26 -14
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +24 -4
- package/dist/adapters/sandbox/e2b/index.d.ts +24 -4
- package/dist/adapters/sandbox/e2b/index.js +26 -14
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +3 -3
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +4 -4
- package/dist/adapters/sandbox/inmemory/index.d.ts +4 -4
- package/dist/adapters/sandbox/inmemory/index.js +3 -3
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +1 -1
- package/dist/adapters/thread/anthropic/index.cjs +23 -3
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +5 -5
- package/dist/adapters/thread/anthropic/index.d.ts +5 -5
- package/dist/adapters/thread/anthropic/index.js +23 -3
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.cjs +2 -1
- package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
- package/dist/adapters/thread/anthropic/workflow.js +2 -1
- package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.cjs +27 -3
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +5 -5
- package/dist/adapters/thread/google-genai/index.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.js +27 -3
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.cjs +2 -1
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
- package/dist/adapters/thread/google-genai/workflow.js +2 -1
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
- package/dist/adapters/thread/langchain/index.cjs +23 -3
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +5 -5
- package/dist/adapters/thread/langchain/index.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.js +23 -3
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.cjs +2 -1
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
- package/dist/adapters/thread/langchain/workflow.js +2 -1
- package/dist/adapters/thread/langchain/workflow.js.map +1 -1
- package/dist/index.cjs +120 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +121 -31
- package/dist/index.js.map +1 -1
- package/dist/{proxy-0smGKvx8.d.ts → proxy-CUlKSvZS.d.ts} +1 -1
- package/dist/{proxy-DEtowJyd.d.cts → proxy-D_3x7RN4.d.cts} +1 -1
- package/dist/{thread-manager-C-C4pI2z.d.ts → thread-manager-CVu7o2cs.d.ts} +4 -2
- package/dist/{thread-manager-D4vgzYrh.d.cts → thread-manager-HSwyh28L.d.cts} +4 -2
- package/dist/{thread-manager-3fszQih4.d.ts → thread-manager-c1gPopAG.d.ts} +4 -2
- package/dist/{thread-manager-CzYln2OC.d.cts → thread-manager-wGi-LqIP.d.cts} +4 -2
- package/dist/{types-B37hKoWA.d.ts → types-BH_IRryz.d.ts} +10 -1
- package/dist/{types-D08CXPh8.d.cts → types-BaOw4hKI.d.cts} +10 -1
- package/dist/{types-CPKDl-y_.d.ts → types-C06FwR96.d.cts} +59 -4
- package/dist/{types-CNuWnvy9.d.ts → types-DAsQ21Rt.d.ts} +1 -1
- package/dist/{types-BO7Yju20.d.cts → types-DNr31FzL.d.ts} +59 -4
- package/dist/{types-DWEUmYAJ.d.cts → types-lm8tMNJQ.d.cts} +1 -1
- package/dist/{types-tQL9njTu.d.cts → types-yx0LzPGn.d.cts} +21 -7
- package/dist/{types-tQL9njTu.d.ts → types-yx0LzPGn.d.ts} +21 -7
- package/dist/{workflow-CjXHbZZc.d.ts → workflow-CSCkpwAL.d.ts} +2 -2
- package/dist/{workflow-Do_lzJpT.d.cts → workflow-DuvMZ8Vm.d.cts} +2 -2
- package/dist/workflow.cjs +94 -18
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3 -3
- package/dist/workflow.d.ts +3 -3
- package/dist/workflow.js +95 -19
- package/dist/workflow.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/sandbox/bedrock/index.ts +12 -3
- package/src/adapters/sandbox/daytona/index.ts +12 -3
- package/src/adapters/sandbox/e2b/index.ts +36 -14
- package/src/adapters/sandbox/e2b/types.ts +16 -0
- package/src/adapters/sandbox/inmemory/index.ts +12 -3
- package/src/adapters/thread/anthropic/activities.ts +9 -0
- package/src/adapters/thread/anthropic/model-invoker.ts +3 -1
- package/src/adapters/thread/anthropic/thread-manager.ts +3 -0
- package/src/adapters/thread/google-genai/activities.ts +13 -0
- package/src/adapters/thread/google-genai/model-invoker.ts +3 -1
- package/src/adapters/thread/google-genai/thread-manager.ts +3 -0
- package/src/adapters/thread/langchain/activities.ts +9 -0
- package/src/adapters/thread/langchain/model-invoker.ts +2 -1
- package/src/adapters/thread/langchain/thread-manager.ts +3 -0
- package/src/lib/lifecycle.ts +11 -4
- package/src/lib/model/types.ts +10 -0
- package/src/lib/sandbox/manager.ts +26 -18
- package/src/lib/sandbox/types.ts +27 -7
- package/src/lib/session/session-edge-cases.integration.test.ts +265 -1
- package/src/lib/session/session.integration.test.ts +22 -1
- package/src/lib/session/session.ts +61 -7
- package/src/lib/session/types.ts +12 -0
- package/src/lib/subagent/subagent.integration.test.ts +100 -104
- package/src/lib/thread/manager.ts +18 -0
- package/src/lib/thread/proxy.ts +1 -0
- package/src/lib/thread/types.ts +9 -0
- package/src/lib/tool-router/index.ts +2 -0
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +92 -0
- package/src/lib/tool-router/router.integration.test.ts +12 -0
- package/src/lib/tool-router/router.ts +89 -16
- package/src/lib/tool-router/types.ts +34 -1
- package/src/workflow.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":["workflowInfo","proxyActivities"],"mappings":";;;;;AAwBO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAASA,qBAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAOC,wBAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,KAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,aAAa,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAChG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,mBAAA,EAAqB,IAAA,CAAK,CAAA,CAAE,qBAAqB,CAAC,CAAA;AAAA,IAClD,UAAA,EAAY,IAAA,CAAK,CAAA,CAAE,YAAY,CAAC;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":["workflowInfo","proxyActivities"],"mappings":";;;;;AAwBO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAASA,qBAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAOC,wBAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,KAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,aAAa,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAChG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,mBAAA,EAAqB,IAAA,CAAK,CAAA,CAAE,qBAAqB,CAAC,CAAA;AAAA,IAClD,UAAA,EAAY,IAAA,CAAK,CAAA,CAAE,YAAY,CAAC,CAAA;AAAA,IAChC,cAAA,EAAgB,IAAA,CAAK,CAAA,CAAE,gBAAgB,CAAC;AAAA,GAC1C;AACF;;;AChCA,IAAM,cAAA,GAAiB,WAAA;AAEhB,SAAS,uBAAA,CACd,OACA,OAAA,EACmD;AACnD,EAAA,OAAO,oBAAA;AAAA,IACL,cAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"workflow.cjs","sourcesContent":["/**\n * Shared proxy helper for thread operations.\n *\n * Each adapter re-exports a thin wrapper that supplies its prefix and\n * casts the return type to carry the adapter's native content type.\n */\nimport {\n proxyActivities,\n workflowInfo,\n type ActivityInterfaceFor,\n} from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../session/types\";\n\n/**\n * Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.\n *\n * The proxy resolves activity names by combining the adapter prefix with\n * the workflow scope, so each adapter + workflow combination gets its own\n * namespace.\n *\n * @param adapterPrefix - Adapter identifier (e.g. \"anthropic\", \"googleGenAI\", \"langChain\")\n * @param scope - Optional workflow scope override. Defaults to `workflowInfo().workflowType`.\n * @param options - Optional Temporal `proxyActivities` options.\n */\nexport function createThreadOpsProxy(\n adapterPrefix: string,\n scope?: string,\n options?: Parameters<typeof proxyActivities>[0]\n): ActivityInterfaceFor<ThreadOps> {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const acts = proxyActivities<Record<string, (...args: any[]) => any>>(\n options ?? {\n startToCloseTimeout: \"10s\",\n retry: {\n maximumAttempts: 6,\n initialInterval: \"5s\",\n maximumInterval: \"15m\",\n backoffCoefficient: 4,\n },\n }\n );\n\n const prefix = `${adapterPrefix}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;\n const p = (key: string): string =>\n `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;\n\n return {\n initializeThread: acts[p(\"initializeThread\")],\n appendHumanMessage: acts[p(\"appendHumanMessage\")],\n appendToolResult: acts[p(\"appendToolResult\")],\n appendAgentMessage: acts[p(\"appendAgentMessage\")],\n appendSystemMessage: acts[p(\"appendSystemMessage\")],\n forkThread: acts[p(\"forkThread\")],\n truncateThread: acts[p(\"truncateThread\")],\n } as ActivityInterfaceFor<ThreadOps>;\n}\n","/**\n * Workflow-safe proxy for LangChain thread operations.\n *\n * Import this from `zeitlich/adapters/thread/langchain/workflow`\n * in your Temporal workflow files.\n *\n * By default the scope is derived from `workflowInfo().workflowType`,\n * so activities are automatically namespaced per workflow.\n *\n * @example\n * ```typescript\n * import { proxyLangChainThreadOps } from 'zeitlich/adapters/thread/langchain/workflow';\n *\n * // Auto-scoped to the current workflow name\n * const threadOps = proxyLangChainThreadOps();\n *\n * // Explicit scope override\n * const threadOps = proxyLangChainThreadOps(\"customScope\");\n * ```\n */\nimport { type ActivityInterfaceFor } from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../../../lib/session/types\";\nimport type { LangChainContent } from \"./thread-manager\";\nimport { createThreadOpsProxy } from \"../../../lib/thread/proxy\";\n\nconst ADAPTER_PREFIX = \"langChain\";\n\nexport function proxyLangChainThreadOps(\n scope?: string,\n options?: Parameters<typeof createThreadOpsProxy>[2]\n): ActivityInterfaceFor<ThreadOps<LangChainContent>> {\n return createThreadOpsProxy(\n ADAPTER_PREFIX,\n scope,\n options\n ) as ActivityInterfaceFor<ThreadOps<LangChainContent>>;\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ActivityInterfaceFor } from '@temporalio/workflow';
|
|
2
|
-
import { T as ThreadOps } from '../../../types-
|
|
3
|
-
import { L as LangChainContent } from '../../../thread-manager-
|
|
4
|
-
import { c as createThreadOpsProxy } from '../../../proxy-
|
|
2
|
+
import { T as ThreadOps } from '../../../types-C06FwR96.cjs';
|
|
3
|
+
import { L as LangChainContent } from '../../../thread-manager-wGi-LqIP.cjs';
|
|
4
|
+
import { c as createThreadOpsProxy } from '../../../proxy-D_3x7RN4.cjs';
|
|
5
5
|
import '@temporalio/common';
|
|
6
6
|
import '@temporalio/common/lib/interfaces';
|
|
7
7
|
import 'zod';
|
|
8
|
-
import '../../../types-
|
|
8
|
+
import '../../../types-yx0LzPGn.cjs';
|
|
9
9
|
import 'ioredis';
|
|
10
10
|
import '@langchain/core/messages';
|
|
11
|
-
import '../../../types-
|
|
11
|
+
import '../../../types-BaOw4hKI.cjs';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Workflow-safe proxy for LangChain thread operations.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ActivityInterfaceFor } from '@temporalio/workflow';
|
|
2
|
-
import { T as ThreadOps } from '../../../types-
|
|
3
|
-
import { L as LangChainContent } from '../../../thread-manager-
|
|
4
|
-
import { c as createThreadOpsProxy } from '../../../proxy-
|
|
2
|
+
import { T as ThreadOps } from '../../../types-DNr31FzL.js';
|
|
3
|
+
import { L as LangChainContent } from '../../../thread-manager-c1gPopAG.js';
|
|
4
|
+
import { c as createThreadOpsProxy } from '../../../proxy-CUlKSvZS.js';
|
|
5
5
|
import '@temporalio/common';
|
|
6
6
|
import '@temporalio/common/lib/interfaces';
|
|
7
7
|
import 'zod';
|
|
8
|
-
import '../../../types-
|
|
8
|
+
import '../../../types-yx0LzPGn.js';
|
|
9
9
|
import 'ioredis';
|
|
10
10
|
import '@langchain/core/messages';
|
|
11
|
-
import '../../../types-
|
|
11
|
+
import '../../../types-BH_IRryz.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Workflow-safe proxy for LangChain thread operations.
|
|
@@ -22,7 +22,8 @@ function createThreadOpsProxy(adapterPrefix, scope, options) {
|
|
|
22
22
|
appendToolResult: acts[p("appendToolResult")],
|
|
23
23
|
appendAgentMessage: acts[p("appendAgentMessage")],
|
|
24
24
|
appendSystemMessage: acts[p("appendSystemMessage")],
|
|
25
|
-
forkThread: acts[p("forkThread")]
|
|
25
|
+
forkThread: acts[p("forkThread")],
|
|
26
|
+
truncateThread: acts[p("truncateThread")]
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":[],"mappings":";;;AAwBO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAAS,YAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAO,eAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,KAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,aAAa,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAChG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,mBAAA,EAAqB,IAAA,CAAK,CAAA,CAAE,qBAAqB,CAAC,CAAA;AAAA,IAClD,UAAA,EAAY,IAAA,CAAK,CAAA,CAAE,YAAY,CAAC;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":[],"mappings":";;;AAwBO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAAS,YAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAO,eAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,KAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,aAAa,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAChG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,gBAAA,EAAkB,IAAA,CAAK,CAAA,CAAE,kBAAkB,CAAC,CAAA;AAAA,IAC5C,kBAAA,EAAoB,IAAA,CAAK,CAAA,CAAE,oBAAoB,CAAC,CAAA;AAAA,IAChD,mBAAA,EAAqB,IAAA,CAAK,CAAA,CAAE,qBAAqB,CAAC,CAAA;AAAA,IAClD,UAAA,EAAY,IAAA,CAAK,CAAA,CAAE,YAAY,CAAC,CAAA;AAAA,IAChC,cAAA,EAAgB,IAAA,CAAK,CAAA,CAAE,gBAAgB,CAAC;AAAA,GAC1C;AACF;;;AChCA,IAAM,cAAA,GAAiB,WAAA;AAEhB,SAAS,uBAAA,CACd,OACA,OAAA,EACmD;AACnD,EAAA,OAAO,oBAAA;AAAA,IACL,cAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF;AACF","file":"workflow.js","sourcesContent":["/**\n * Shared proxy helper for thread operations.\n *\n * Each adapter re-exports a thin wrapper that supplies its prefix and\n * casts the return type to carry the adapter's native content type.\n */\nimport {\n proxyActivities,\n workflowInfo,\n type ActivityInterfaceFor,\n} from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../session/types\";\n\n/**\n * Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.\n *\n * The proxy resolves activity names by combining the adapter prefix with\n * the workflow scope, so each adapter + workflow combination gets its own\n * namespace.\n *\n * @param adapterPrefix - Adapter identifier (e.g. \"anthropic\", \"googleGenAI\", \"langChain\")\n * @param scope - Optional workflow scope override. Defaults to `workflowInfo().workflowType`.\n * @param options - Optional Temporal `proxyActivities` options.\n */\nexport function createThreadOpsProxy(\n adapterPrefix: string,\n scope?: string,\n options?: Parameters<typeof proxyActivities>[0]\n): ActivityInterfaceFor<ThreadOps> {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const acts = proxyActivities<Record<string, (...args: any[]) => any>>(\n options ?? {\n startToCloseTimeout: \"10s\",\n retry: {\n maximumAttempts: 6,\n initialInterval: \"5s\",\n maximumInterval: \"15m\",\n backoffCoefficient: 4,\n },\n }\n );\n\n const prefix = `${adapterPrefix}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;\n const p = (key: string): string =>\n `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;\n\n return {\n initializeThread: acts[p(\"initializeThread\")],\n appendHumanMessage: acts[p(\"appendHumanMessage\")],\n appendToolResult: acts[p(\"appendToolResult\")],\n appendAgentMessage: acts[p(\"appendAgentMessage\")],\n appendSystemMessage: acts[p(\"appendSystemMessage\")],\n forkThread: acts[p(\"forkThread\")],\n truncateThread: acts[p(\"truncateThread\")],\n } as ActivityInterfaceFor<ThreadOps>;\n}\n","/**\n * Workflow-safe proxy for LangChain thread operations.\n *\n * Import this from `zeitlich/adapters/thread/langchain/workflow`\n * in your Temporal workflow files.\n *\n * By default the scope is derived from `workflowInfo().workflowType`,\n * so activities are automatically namespaced per workflow.\n *\n * @example\n * ```typescript\n * import { proxyLangChainThreadOps } from 'zeitlich/adapters/thread/langchain/workflow';\n *\n * // Auto-scoped to the current workflow name\n * const threadOps = proxyLangChainThreadOps();\n *\n * // Explicit scope override\n * const threadOps = proxyLangChainThreadOps(\"customScope\");\n * ```\n */\nimport { type ActivityInterfaceFor } from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../../../lib/session/types\";\nimport type { LangChainContent } from \"./thread-manager\";\nimport { createThreadOpsProxy } from \"../../../lib/thread/proxy\";\n\nconst ADAPTER_PREFIX = \"langChain\";\n\nexport function proxyLangChainThreadOps(\n scope?: string,\n options?: Parameters<typeof createThreadOpsProxy>[2]\n): ActivityInterfaceFor<ThreadOps<LangChainContent>> {\n return createThreadOpsProxy(\n ADAPTER_PREFIX,\n scope,\n options\n ) as ActivityInterfaceFor<ThreadOps<LangChainContent>>;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -117,7 +117,7 @@ function createToolRouter(options) {
|
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
async function processToolCall(toolCall, turn, sandboxId) {
|
|
120
|
+
async function processToolCall(toolCall, turn, sandboxId, onRewindRequested) {
|
|
121
121
|
const startTime = Date.now();
|
|
122
122
|
const tool = toolMap.get(toolCall.name);
|
|
123
123
|
const preResult = await runPreHooks(toolCall, tool, turn);
|
|
@@ -132,7 +132,7 @@ function createToolRouter(options) {
|
|
|
132
132
|
reason: "Skipped by PreToolUse hook"
|
|
133
133
|
})
|
|
134
134
|
});
|
|
135
|
-
return
|
|
135
|
+
return { kind: "skipped" };
|
|
136
136
|
}
|
|
137
137
|
const effectiveArgs = preResult.args;
|
|
138
138
|
workflow.log.debug("tool call dispatched", {
|
|
@@ -144,6 +144,7 @@ function createToolRouter(options) {
|
|
|
144
144
|
let content;
|
|
145
145
|
let resultAppended = false;
|
|
146
146
|
let metadata;
|
|
147
|
+
let rewindRequested = false;
|
|
147
148
|
try {
|
|
148
149
|
if (tool) {
|
|
149
150
|
const routerContext = {
|
|
@@ -161,11 +162,15 @@ function createToolRouter(options) {
|
|
|
161
162
|
content = response.toolResponse;
|
|
162
163
|
resultAppended = response.resultAppended === true;
|
|
163
164
|
metadata = response.metadata;
|
|
165
|
+
rewindRequested = response.rewind === true;
|
|
164
166
|
} else {
|
|
165
167
|
result = { error: `Unknown tool: ${toolCall.name}` };
|
|
166
168
|
content = JSON.stringify(result, null, 2);
|
|
167
169
|
}
|
|
168
170
|
} catch (error) {
|
|
171
|
+
if (workflow.isCancellation(error)) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
169
174
|
workflow.log.warn("tool call failed", {
|
|
170
175
|
toolName: toolCall.name,
|
|
171
176
|
toolCallId: toolCall.id,
|
|
@@ -183,6 +188,15 @@ function createToolRouter(options) {
|
|
|
183
188
|
result = recovery.result;
|
|
184
189
|
content = recovery.content;
|
|
185
190
|
}
|
|
191
|
+
if (rewindRequested) {
|
|
192
|
+
const signal = {
|
|
193
|
+
toolCallId: toolCall.id,
|
|
194
|
+
toolName: toolCall.name
|
|
195
|
+
};
|
|
196
|
+
workflow.log.info("tool requested rewind", { ...signal });
|
|
197
|
+
onRewindRequested?.(signal);
|
|
198
|
+
return { kind: "rewind", signal };
|
|
199
|
+
}
|
|
186
200
|
if (!resultAppended) {
|
|
187
201
|
const config = {
|
|
188
202
|
threadId: options.threadId,
|
|
@@ -219,7 +233,7 @@ function createToolRouter(options) {
|
|
|
219
233
|
turn,
|
|
220
234
|
durationMs
|
|
221
235
|
);
|
|
222
|
-
return toolResult;
|
|
236
|
+
return { kind: "result", value: toolResult };
|
|
223
237
|
}
|
|
224
238
|
return {
|
|
225
239
|
hasTools() {
|
|
@@ -254,27 +268,59 @@ function createToolRouter(options) {
|
|
|
254
268
|
}));
|
|
255
269
|
},
|
|
256
270
|
async processToolCalls(toolCalls, context) {
|
|
271
|
+
const attachRewind = (arr, rewind) => {
|
|
272
|
+
if (rewind) {
|
|
273
|
+
arr.rewind = rewind;
|
|
274
|
+
}
|
|
275
|
+
return arr;
|
|
276
|
+
};
|
|
257
277
|
if (toolCalls.length === 0) {
|
|
258
|
-
return [];
|
|
278
|
+
return attachRewind([], void 0);
|
|
259
279
|
}
|
|
260
280
|
const turn = context?.turn ?? 0;
|
|
261
281
|
const sandboxId = context?.sandboxId;
|
|
282
|
+
let rewindSignal;
|
|
262
283
|
if (options.parallel) {
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
284
|
+
const scope = new workflow.CancellationScope({ cancellable: true });
|
|
285
|
+
const onRewindRequested = (signal) => {
|
|
286
|
+
if (!rewindSignal) {
|
|
287
|
+
rewindSignal = signal;
|
|
288
|
+
scope.cancel();
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const outcomes = await scope.run(
|
|
292
|
+
async () => Promise.allSettled(
|
|
293
|
+
toolCalls.map(
|
|
294
|
+
(tc) => processToolCall(tc, turn, sandboxId, onRewindRequested)
|
|
295
|
+
)
|
|
296
|
+
)
|
|
268
297
|
);
|
|
298
|
+
const results2 = [];
|
|
299
|
+
for (const outcome of outcomes) {
|
|
300
|
+
if (outcome.status === "rejected") {
|
|
301
|
+
if (workflow.isCancellation(outcome.reason)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
throw outcome.reason;
|
|
305
|
+
}
|
|
306
|
+
if (outcome.value.kind === "result") {
|
|
307
|
+
results2.push(outcome.value.value);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return attachRewind(results2, rewindSignal);
|
|
269
311
|
}
|
|
270
312
|
const results = [];
|
|
271
313
|
for (const toolCall of toolCalls) {
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
|
|
314
|
+
const outcome = await processToolCall(toolCall, turn, sandboxId);
|
|
315
|
+
if (outcome.kind === "rewind") {
|
|
316
|
+
rewindSignal = outcome.signal;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
if (outcome.kind === "result") {
|
|
320
|
+
results.push(outcome.value);
|
|
275
321
|
}
|
|
276
322
|
}
|
|
277
|
-
return results;
|
|
323
|
+
return attachRewind(results, rewindSignal);
|
|
278
324
|
},
|
|
279
325
|
async processToolCallsByName(toolCalls, toolName, handler, context) {
|
|
280
326
|
const matchingCalls = toolCalls.filter((tc) => tc.name === toolName);
|
|
@@ -871,7 +917,8 @@ async function createSession({
|
|
|
871
917
|
initializeThread,
|
|
872
918
|
appendSystemMessage,
|
|
873
919
|
appendAgentMessage,
|
|
874
|
-
forkThread
|
|
920
|
+
forkThread,
|
|
921
|
+
truncateThread
|
|
875
922
|
} = threadOps;
|
|
876
923
|
const plugins = [];
|
|
877
924
|
let destroySubagentSandboxes;
|
|
@@ -965,8 +1012,10 @@ async function createSession({
|
|
|
965
1012
|
nonRetryable: true
|
|
966
1013
|
});
|
|
967
1014
|
}
|
|
1015
|
+
const forkInit = sandboxInit;
|
|
968
1016
|
sandboxId = await sandboxOps.forkSandbox(
|
|
969
|
-
|
|
1017
|
+
forkInit.sandboxId,
|
|
1018
|
+
forkInit.options
|
|
970
1019
|
);
|
|
971
1020
|
sandboxOwned = true;
|
|
972
1021
|
} else if (sandboxMode === "from-snapshot") {
|
|
@@ -976,8 +1025,11 @@ async function createSession({
|
|
|
976
1025
|
nonRetryable: true
|
|
977
1026
|
});
|
|
978
1027
|
}
|
|
979
|
-
const
|
|
980
|
-
sandboxId = await sandboxOps.restoreSandbox(
|
|
1028
|
+
const restoreInit = sandboxInit;
|
|
1029
|
+
sandboxId = await sandboxOps.restoreSandbox(
|
|
1030
|
+
restoreInit.snapshot,
|
|
1031
|
+
restoreInit.options
|
|
1032
|
+
);
|
|
981
1033
|
sandboxOwned = true;
|
|
982
1034
|
} else if (sandboxOps) {
|
|
983
1035
|
const skillFiles = skills ? collectSkillFiles(skills) : void 0;
|
|
@@ -1066,12 +1118,18 @@ async function createSession({
|
|
|
1066
1118
|
const currentTurn = stateManager.getTurns();
|
|
1067
1119
|
workflow.log.debug("turn started", { agentName, threadId, turn: currentTurn });
|
|
1068
1120
|
stateManager.setTools(toolRouter.getToolDefinitions());
|
|
1069
|
-
const {
|
|
1121
|
+
const {
|
|
1122
|
+
message,
|
|
1123
|
+
rawToolCalls,
|
|
1124
|
+
usage,
|
|
1125
|
+
threadLengthAtCall
|
|
1126
|
+
} = await runAgent({
|
|
1070
1127
|
threadId,
|
|
1071
1128
|
threadKey,
|
|
1072
1129
|
agentName,
|
|
1073
1130
|
metadata
|
|
1074
1131
|
});
|
|
1132
|
+
const preAssistantLength = threadLengthAtCall;
|
|
1075
1133
|
await appendAgentMessage(threadId, workflow.uuid4(), message, threadKey);
|
|
1076
1134
|
if (usage) {
|
|
1077
1135
|
stateManager.updateUsage(usage);
|
|
@@ -1117,6 +1175,24 @@ async function createSession({
|
|
|
1117
1175
|
stateManager.updateUsage(result.usage);
|
|
1118
1176
|
}
|
|
1119
1177
|
}
|
|
1178
|
+
const rewind = toolCallResults.rewind;
|
|
1179
|
+
if (rewind) {
|
|
1180
|
+
workflow.log.info("rewinding turn", {
|
|
1181
|
+
agentName,
|
|
1182
|
+
threadId,
|
|
1183
|
+
turn: currentTurn,
|
|
1184
|
+
toolCallId: rewind.toolCallId,
|
|
1185
|
+
toolName: rewind.toolName
|
|
1186
|
+
});
|
|
1187
|
+
if (preAssistantLength === void 0) {
|
|
1188
|
+
throw workflow.ApplicationFailure.create({
|
|
1189
|
+
message: "Rewind requested but runAgent did not report `threadLengthAtCall`; the adapter must populate it to support rewinds.",
|
|
1190
|
+
nonRetryable: true
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
await truncateThread(threadId, preAssistantLength, threadKey);
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1120
1196
|
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
1121
1197
|
const conditionMet = await workflow.condition(
|
|
1122
1198
|
() => stateManager.getStatus() === "RUNNING",
|
|
@@ -2338,6 +2414,20 @@ function createThreadManager(config) {
|
|
|
2338
2414
|
},
|
|
2339
2415
|
async delete() {
|
|
2340
2416
|
await redis.del(redisKey, metaKey);
|
|
2417
|
+
},
|
|
2418
|
+
async length() {
|
|
2419
|
+
await assertThreadExists();
|
|
2420
|
+
return redis.llen(redisKey);
|
|
2421
|
+
},
|
|
2422
|
+
async truncate(length) {
|
|
2423
|
+
await assertThreadExists();
|
|
2424
|
+
if (length <= 0) {
|
|
2425
|
+
await redis.del(redisKey);
|
|
2426
|
+
await redis.expire(metaKey, THREAD_TTL_SECONDS);
|
|
2427
|
+
} else {
|
|
2428
|
+
await redis.ltrim(redisKey, 0, length - 1);
|
|
2429
|
+
await redis.expire(redisKey, THREAD_TTL_SECONDS);
|
|
2430
|
+
}
|
|
2341
2431
|
}
|
|
2342
2432
|
};
|
|
2343
2433
|
}
|
|
@@ -2424,18 +2514,18 @@ var SandboxManager = class {
|
|
|
2424
2514
|
async resume(id) {
|
|
2425
2515
|
await this.provider.resume(id);
|
|
2426
2516
|
}
|
|
2427
|
-
async snapshot(id) {
|
|
2428
|
-
return this.provider.snapshot(id);
|
|
2517
|
+
async snapshot(id, options) {
|
|
2518
|
+
return this.provider.snapshot(id, options);
|
|
2429
2519
|
}
|
|
2430
|
-
async restore(snapshot) {
|
|
2431
|
-
const sandbox = await this.provider.restore(snapshot);
|
|
2520
|
+
async restore(snapshot, options) {
|
|
2521
|
+
const sandbox = await this.provider.restore(snapshot, options);
|
|
2432
2522
|
return sandbox.id;
|
|
2433
2523
|
}
|
|
2434
2524
|
async deleteSnapshot(snapshot) {
|
|
2435
2525
|
await this.provider.deleteSnapshot(snapshot);
|
|
2436
2526
|
}
|
|
2437
|
-
async fork(sandboxId) {
|
|
2438
|
-
const sandbox = await this.provider.fork(sandboxId);
|
|
2527
|
+
async fork(sandboxId, options) {
|
|
2528
|
+
const sandbox = await this.provider.fork(sandboxId, options);
|
|
2439
2529
|
return sandbox.id;
|
|
2440
2530
|
}
|
|
2441
2531
|
/**
|
|
@@ -2473,17 +2563,17 @@ var SandboxManager = class {
|
|
|
2473
2563
|
resumeSandbox: async (sandboxId) => {
|
|
2474
2564
|
await this.resume(sandboxId);
|
|
2475
2565
|
},
|
|
2476
|
-
snapshotSandbox: async (sandboxId) => {
|
|
2477
|
-
return this.snapshot(sandboxId);
|
|
2566
|
+
snapshotSandbox: async (sandboxId, options) => {
|
|
2567
|
+
return this.snapshot(sandboxId, options);
|
|
2478
2568
|
},
|
|
2479
|
-
restoreSandbox: async (snapshot) => {
|
|
2480
|
-
return this.restore(snapshot);
|
|
2569
|
+
restoreSandbox: async (snapshot, options) => {
|
|
2570
|
+
return this.restore(snapshot, options);
|
|
2481
2571
|
},
|
|
2482
2572
|
deleteSandboxSnapshot: async (snapshot) => {
|
|
2483
2573
|
await this.deleteSnapshot(snapshot);
|
|
2484
2574
|
},
|
|
2485
|
-
forkSandbox: async (sandboxId) => {
|
|
2486
|
-
return this.fork(sandboxId);
|
|
2575
|
+
forkSandbox: async (sandboxId, options) => {
|
|
2576
|
+
return this.fork(sandboxId, options);
|
|
2487
2577
|
}
|
|
2488
2578
|
};
|
|
2489
2579
|
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|