zeitlich 0.2.46 → 0.2.47
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/README.md +64 -6
- package/dist/{activities-CyeiqK_f.d.cts → activities-CPwKoUlD.d.cts} +3 -3
- package/dist/{activities-Bm4TLTid.d.ts → activities-DlaBxNID.d.ts} +3 -3
- package/dist/adapters/thread/anthropic/index.cjs +105 -6
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +48 -9
- package/dist/adapters/thread/anthropic/index.d.ts +48 -9
- package/dist/adapters/thread/anthropic/index.js +104 -7
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.cjs +38 -22
- package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -4
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -4
- package/dist/adapters/thread/anthropic/workflow.js +38 -22
- package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -5
- package/dist/adapters/thread/google-genai/index.d.ts +6 -5
- package/dist/adapters/thread/google-genai/workflow.cjs +38 -22
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +7 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +7 -5
- package/dist/adapters/thread/google-genai/workflow.js +38 -22
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +6 -5
- package/dist/adapters/thread/langchain/index.d.ts +6 -5
- package/dist/adapters/thread/langchain/workflow.cjs +38 -22
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -4
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -4
- package/dist/adapters/thread/langchain/workflow.js +38 -22
- package/dist/adapters/thread/langchain/workflow.js.map +1 -1
- package/dist/{cold-store-CFHwemBJ.d.ts → cold-store-BDgJpwLI.d.ts} +8 -11
- package/dist/{cold-store-BC5L5Z8A.d.cts → cold-store-Z2wvK2cV.d.cts} +8 -11
- package/dist/index.cjs +264 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +265 -93
- package/dist/index.js.map +1 -1
- package/dist/proxy-CDh3Rsa7.d.cts +40 -0
- package/dist/proxy-Du8ggERu.d.ts +40 -0
- package/dist/{thread-manager-D33SUmZa.d.cts → thread-manager-BjoYYXgd.d.cts} +2 -2
- package/dist/{thread-manager-9tezUcLW.d.cts → thread-manager-D8zKNFZ9.d.cts} +2 -2
- package/dist/{thread-manager-B-zy3xrs.d.ts → thread-manager-DtHYws2F.d.ts} +2 -2
- package/dist/{thread-manager-DduoSkvJ.d.ts → thread-manager-Dw96FKH1.d.ts} +2 -2
- package/dist/{types-oxt8GN97.d.cts → types-BMJrsHo0.d.cts} +1 -1
- package/dist/{types-L5bvbF-n.d.ts → types-CtdOquo3.d.ts} +1 -1
- package/dist/{types-CnuN9T6t.d.cts → types-DNEl5uxQ.d.cts} +16 -0
- package/dist/{types-CwN6_tAL.d.ts → types-qQVZfhoT.d.ts} +16 -0
- package/dist/{workflow-DIaIV7L2.d.cts → workflow-BH9ImDGq.d.cts} +17 -2
- package/dist/{workflow-B1TOcHbt.d.ts → workflow-Cdw3-RNB.d.ts} +17 -2
- package/dist/workflow.cjs +33 -3
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +33 -4
- package/dist/workflow.js.map +1 -1
- package/package.json +9 -3
- package/src/adapters/thread/anthropic/activities.ts +18 -11
- package/src/adapters/thread/anthropic/index.ts +8 -0
- package/src/adapters/thread/anthropic/model-invoker.test.ts +110 -0
- package/src/adapters/thread/anthropic/model-invoker.ts +26 -5
- package/src/adapters/thread/anthropic/prompt-cache.test.ts +134 -0
- package/src/adapters/thread/anthropic/prompt-cache.ts +163 -0
- package/src/adapters/thread/anthropic/proxy.ts +1 -0
- package/src/adapters/thread/google-genai/proxy.ts +1 -0
- package/src/adapters/thread/langchain/proxy.ts +1 -0
- package/src/index.ts +1 -1
- package/src/lib/subagent/define.ts +1 -0
- package/src/lib/subagent/handler.ts +11 -2
- package/src/lib/subagent/subagent.integration.test.ts +139 -0
- package/src/lib/subagent/types.ts +16 -0
- package/src/lib/thread/cold-store.test.ts +33 -5
- package/src/lib/thread/cold-store.ts +50 -31
- package/src/lib/thread/proxy.ts +79 -29
- package/src/tools/edit/handler.test.ts +177 -0
- package/src/tools/edit/handler.ts +249 -47
- package/src/tools/edit/tool.ts +40 -0
- package/src/tools/task-create/handler.ts +1 -1
- package/src/tools/task-update/handler.ts +1 -1
- package/src/workflow.ts +2 -2
- package/dist/proxy-BxFyd6cg.d.cts +0 -24
- package/dist/proxy-Cskmj4Yx.d.ts +0 -24
|
@@ -3,33 +3,49 @@
|
|
|
3
3
|
var workflow = require('@temporalio/workflow');
|
|
4
4
|
|
|
5
5
|
// src/lib/thread/proxy.ts
|
|
6
|
+
var DEFAULT_OPTIONS = {
|
|
7
|
+
startToCloseTimeout: "10s",
|
|
8
|
+
retry: {
|
|
9
|
+
maximumAttempts: 6,
|
|
10
|
+
initialInterval: "5s",
|
|
11
|
+
maximumInterval: "15m",
|
|
12
|
+
backoffCoefficient: 4
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var BUILTIN_PER_OP = {
|
|
16
|
+
hydrateThread: { startToCloseTimeout: "60s", heartbeatTimeout: "15s" },
|
|
17
|
+
flushThread: { startToCloseTimeout: "60s", heartbeatTimeout: "15s" }
|
|
18
|
+
};
|
|
19
|
+
function isProxyOptionsShape(o) {
|
|
20
|
+
return "defaults" in o || "perOp" in o;
|
|
21
|
+
}
|
|
6
22
|
function createThreadOpsProxy(adapterPrefix, scope, options) {
|
|
7
23
|
const resolvedScope = scope ?? workflow.workflowInfo().workflowType;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
retry: {
|
|
12
|
-
maximumAttempts: 6,
|
|
13
|
-
initialInterval: "5s",
|
|
14
|
-
maximumInterval: "15m",
|
|
15
|
-
backoffCoefficient: 4
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
);
|
|
24
|
+
const opts = options && isProxyOptionsShape(options) ? options : { defaults: options };
|
|
25
|
+
const base = opts.defaults ?? DEFAULT_OPTIONS;
|
|
26
|
+
const baseActs = workflow.proxyActivities(base);
|
|
19
27
|
const prefix = `${adapterPrefix}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
|
|
20
28
|
const p = (key) => `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
29
|
+
const pick = (op) => {
|
|
30
|
+
const overlay = { ...BUILTIN_PER_OP[op], ...opts.perOp?.[op] };
|
|
31
|
+
if (Object.keys(overlay).length === 0) return baseActs[p(op)];
|
|
32
|
+
return workflow.proxyActivities({
|
|
33
|
+
...base,
|
|
34
|
+
...overlay
|
|
35
|
+
})[p(op)];
|
|
36
|
+
};
|
|
21
37
|
return {
|
|
22
|
-
initializeThread:
|
|
23
|
-
appendHumanMessage:
|
|
24
|
-
appendToolResult:
|
|
25
|
-
appendAgentMessage:
|
|
26
|
-
appendSystemMessage:
|
|
27
|
-
forkThread:
|
|
28
|
-
truncateThread:
|
|
29
|
-
loadThreadState:
|
|
30
|
-
saveThreadState:
|
|
31
|
-
hydrateThread:
|
|
32
|
-
flushThread:
|
|
38
|
+
initializeThread: pick("initializeThread"),
|
|
39
|
+
appendHumanMessage: pick("appendHumanMessage"),
|
|
40
|
+
appendToolResult: pick("appendToolResult"),
|
|
41
|
+
appendAgentMessage: pick("appendAgentMessage"),
|
|
42
|
+
appendSystemMessage: pick("appendSystemMessage"),
|
|
43
|
+
forkThread: pick("forkThread"),
|
|
44
|
+
truncateThread: pick("truncateThread"),
|
|
45
|
+
loadThreadState: pick("loadThreadState"),
|
|
46
|
+
saveThreadState: pick("saveThreadState"),
|
|
47
|
+
hydrateThread: pick("hydrateThread"),
|
|
48
|
+
flushThread: pick("flushThread")
|
|
33
49
|
};
|
|
34
50
|
}
|
|
35
51
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/adapter-id.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":["workflowInfo","proxyActivities"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/adapter-id.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":["workflowInfo","proxyActivities"],"mappings":";;;;;AAiBA,IAAM,eAAA,GAAmC;AAAA,EACvC,mBAAA,EAAqB,KAAA;AAAA,EACrB,KAAA,EAAO;AAAA,IACL,eAAA,EAAiB,CAAA;AAAA,IACjB,eAAA,EAAiB,IAAA;AAAA,IACjB,eAAA,EAAiB,KAAA;AAAA,IACjB,kBAAA,EAAoB;AAAA;AAExB,CAAA;AASA,IAAM,cAAA,GAA2D;AAAA,EAC/D,aAAA,EAAe,EAAE,mBAAA,EAAqB,KAAA,EAAO,kBAAkB,KAAA,EAAM;AAAA,EACrE,WAAA,EAAa,EAAE,mBAAA,EAAqB,KAAA,EAAO,kBAAkB,KAAA;AAC/D,CAAA;AAsBA,SAAS,oBAAoB,CAAA,EAAuC;AAClE,EAAA,OAAO,UAAA,IAAc,KAAK,OAAA,IAAW,CAAA;AACvC;AASO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAASA,qBAAA,EAAa,CAAE,YAAA;AAE9C,EAAA,MAAM,IAAA,GACJ,WAAW,mBAAA,CAAoB,OAAO,IAAI,OAAA,GAAU,EAAE,UAAU,OAAA,EAAQ;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AA;AAAA,IACrC,eAAA,EAAiB,KAAK,iBAAiB,CAAA;AAAA,IACvC,eAAA,EAAiB,KAAK,iBAAiB,CAAA;AAAA,IACvC,aAAA,EAAe,KAAK,eAAe,CAAA;AAAA,IACnC,WAAA,EAAa,KAAK,aAAa;AAAA,GACjC;AACF;;;ACnGO,IAAM,UAAA,GAAa;;;ACiBnB,SAAS,uBAAA,CACd,OACA,OAAA,EACmD;AACnD,EAAA,OAAO,oBAAA;AAAA,IACL,UAAA;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 type ActivityOptions,\n} from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../session/types\";\n\ntype OpName = keyof ThreadOps;\n\n/** Tight `startToCloseTimeout` so a sick Redis surfaces quickly via retry. */\nconst DEFAULT_OPTIONS: ActivityOptions = {\n startToCloseTimeout: \"10s\",\n retry: {\n maximumAttempts: 6,\n initialInterval: \"5s\",\n maximumInterval: \"15m\",\n backoffCoefficient: 4,\n },\n};\n\n/**\n * `heartbeatTimeout` assumes the built-in S3 cold store's progress\n * events (multipart `Upload` + chunked stream read). Stalls trip via\n * heartbeat rather than `startToCloseTimeout`. Custom backends without\n * progress events should override via `perOp`. Harmless on Redis-only\n * deployments — the activities no-op.\n */\nconst BUILTIN_PER_OP: Partial<Record<OpName, ActivityOptions>> = {\n hydrateThread: { startToCloseTimeout: \"60s\", heartbeatTimeout: \"15s\" },\n flushThread: { startToCloseTimeout: \"60s\", heartbeatTimeout: \"15s\" },\n};\n\n/**\n * `perOp[op]` layers shallow-rightmost over `defaults` and the\n * built-in cold-tier overlay (`hydrateThread` / `flushThread`).\n * A bare {@link ActivityOptions} is also accepted (treated as `{ defaults }`).\n *\n * @example\n * ```typescript\n * proxyAnthropicThreadOps(undefined, {\n * defaults: { startToCloseTimeout: \"5s\" },\n * perOp: {\n * flushThread: { startToCloseTimeout: \"180s\" }, // heartbeatTimeout still inherited\n * },\n * });\n * ```\n */\nexport interface ThreadOpsProxyOptions {\n defaults?: ActivityOptions;\n perOp?: Partial<Record<OpName, ActivityOptions>>;\n}\n\nfunction isProxyOptionsShape(o: object): o is ThreadOpsProxyOptions {\n return \"defaults\" in o || \"perOp\" in o;\n}\n\n/**\n * Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.\n *\n * @param adapterPrefix - Adapter identifier (e.g. \"anthropic\", \"googleGenAI\", \"langChain\")\n * @param scope - Workflow scope. Defaults to `workflowInfo().workflowType`.\n * @param options - {@link ThreadOpsProxyOptions} or a bare {@link ActivityOptions}.\n */\nexport function createThreadOpsProxy(\n adapterPrefix: string,\n scope?: string,\n options?: ActivityOptions | ThreadOpsProxyOptions\n): ActivityInterfaceFor<ThreadOps> {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n const opts: ThreadOpsProxyOptions =\n options && isProxyOptionsShape(options) ? options : { defaults: options };\n\n const base = opts.defaults ?? DEFAULT_OPTIONS;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const baseActs = proxyActivities<Record<string, (...args: any[]) => any>>(base);\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 const pick = (op: OpName): unknown => {\n const overlay = { ...BUILTIN_PER_OP[op], ...opts.perOp?.[op] };\n if (Object.keys(overlay).length === 0) return baseActs[p(op)];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return proxyActivities<Record<string, (...args: any[]) => any>>({\n ...base,\n ...overlay,\n })[p(op)];\n };\n\n return {\n initializeThread: pick(\"initializeThread\"),\n appendHumanMessage: pick(\"appendHumanMessage\"),\n appendToolResult: pick(\"appendToolResult\"),\n appendAgentMessage: pick(\"appendAgentMessage\"),\n appendSystemMessage: pick(\"appendSystemMessage\"),\n forkThread: pick(\"forkThread\"),\n truncateThread: pick(\"truncateThread\"),\n loadThreadState: pick(\"loadThreadState\"),\n saveThreadState: pick(\"saveThreadState\"),\n hydrateThread: pick(\"hydrateThread\"),\n flushThread: pick(\"flushThread\"),\n } as ActivityInterfaceFor<ThreadOps>;\n}\n","/**\n * Public adapter identity for the LangChain thread adapter.\n *\n * This value is wire format — it appears as the prefix for Temporal\n * activity names (e.g. `langChainCodingAgentInitializeThread`) and must\n * never change, since renaming it would orphan existing persisted\n * threads and break in-flight workflows.\n *\n * Re-exported from `zeitlich/adapters/thread/langchain` so downstream\n * consumers can use the exact same literal the adapter uses internally,\n * typed as the narrow string literal `\"langChain\"`.\n */\nexport const ADAPTER_ID = \"langChain\" as const;\n\n/** Narrow string-literal type for {@link ADAPTER_ID}. */\nexport type AdapterId = typeof ADAPTER_ID;\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\";\nimport { ADAPTER_ID } from \"./adapter-id\";\n\nexport { ADAPTER_ID, type AdapterId } from \"./adapter-id\";\nexport type { ThreadOpsProxyOptions } from \"../../../lib/thread/proxy\";\n\nexport function proxyLangChainThreadOps(\n scope?: string,\n options?: Parameters<typeof createThreadOpsProxy>[2]\n): ActivityInterfaceFor<ThreadOps<LangChainContent>> {\n return createThreadOpsProxy(\n ADAPTER_ID,\n scope,\n options\n ) as ActivityInterfaceFor<ThreadOps<LangChainContent>>;\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
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-DNEl5uxQ.cjs';
|
|
3
|
+
import { L as LangChainContent } from '../../../thread-manager-BjoYYXgd.cjs';
|
|
4
|
+
import { c as createThreadOpsProxy } from '../../../proxy-CDh3Rsa7.cjs';
|
|
5
|
+
export { T as ThreadOpsProxyOptions } from '../../../proxy-CDh3Rsa7.cjs';
|
|
5
6
|
export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CbY2zeSt.cjs';
|
|
6
7
|
import '@temporalio/common/lib/interfaces';
|
|
7
8
|
import 'zod';
|
|
@@ -9,7 +10,7 @@ import '../../../types-CJ7tCdl6.cjs';
|
|
|
9
10
|
import '@temporalio/common';
|
|
10
11
|
import 'ioredis';
|
|
11
12
|
import '@langchain/core/messages';
|
|
12
|
-
import '../../../types-
|
|
13
|
+
import '../../../types-BMJrsHo0.cjs';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Workflow-safe proxy for LangChain thread operations.
|
|
@@ -1,7 +1,8 @@
|
|
|
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-qQVZfhoT.js';
|
|
3
|
+
import { L as LangChainContent } from '../../../thread-manager-Dw96FKH1.js';
|
|
4
|
+
import { c as createThreadOpsProxy } from '../../../proxy-Du8ggERu.js';
|
|
5
|
+
export { T as ThreadOpsProxyOptions } from '../../../proxy-Du8ggERu.js';
|
|
5
6
|
export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-CbY2zeSt.js';
|
|
6
7
|
import '@temporalio/common/lib/interfaces';
|
|
7
8
|
import 'zod';
|
|
@@ -9,7 +10,7 @@ import '../../../types-CJ7tCdl6.js';
|
|
|
9
10
|
import '@temporalio/common';
|
|
10
11
|
import 'ioredis';
|
|
11
12
|
import '@langchain/core/messages';
|
|
12
|
-
import '../../../types-
|
|
13
|
+
import '../../../types-CtdOquo3.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Workflow-safe proxy for LangChain thread operations.
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
import { workflowInfo, proxyActivities } from '@temporalio/workflow';
|
|
2
2
|
|
|
3
3
|
// src/lib/thread/proxy.ts
|
|
4
|
+
var DEFAULT_OPTIONS = {
|
|
5
|
+
startToCloseTimeout: "10s",
|
|
6
|
+
retry: {
|
|
7
|
+
maximumAttempts: 6,
|
|
8
|
+
initialInterval: "5s",
|
|
9
|
+
maximumInterval: "15m",
|
|
10
|
+
backoffCoefficient: 4
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var BUILTIN_PER_OP = {
|
|
14
|
+
hydrateThread: { startToCloseTimeout: "60s", heartbeatTimeout: "15s" },
|
|
15
|
+
flushThread: { startToCloseTimeout: "60s", heartbeatTimeout: "15s" }
|
|
16
|
+
};
|
|
17
|
+
function isProxyOptionsShape(o) {
|
|
18
|
+
return "defaults" in o || "perOp" in o;
|
|
19
|
+
}
|
|
4
20
|
function createThreadOpsProxy(adapterPrefix, scope, options) {
|
|
5
21
|
const resolvedScope = scope ?? workflowInfo().workflowType;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
retry: {
|
|
10
|
-
maximumAttempts: 6,
|
|
11
|
-
initialInterval: "5s",
|
|
12
|
-
maximumInterval: "15m",
|
|
13
|
-
backoffCoefficient: 4
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
);
|
|
22
|
+
const opts = options && isProxyOptionsShape(options) ? options : { defaults: options };
|
|
23
|
+
const base = opts.defaults ?? DEFAULT_OPTIONS;
|
|
24
|
+
const baseActs = proxyActivities(base);
|
|
17
25
|
const prefix = `${adapterPrefix}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
|
|
18
26
|
const p = (key) => `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
27
|
+
const pick = (op) => {
|
|
28
|
+
const overlay = { ...BUILTIN_PER_OP[op], ...opts.perOp?.[op] };
|
|
29
|
+
if (Object.keys(overlay).length === 0) return baseActs[p(op)];
|
|
30
|
+
return proxyActivities({
|
|
31
|
+
...base,
|
|
32
|
+
...overlay
|
|
33
|
+
})[p(op)];
|
|
34
|
+
};
|
|
19
35
|
return {
|
|
20
|
-
initializeThread:
|
|
21
|
-
appendHumanMessage:
|
|
22
|
-
appendToolResult:
|
|
23
|
-
appendAgentMessage:
|
|
24
|
-
appendSystemMessage:
|
|
25
|
-
forkThread:
|
|
26
|
-
truncateThread:
|
|
27
|
-
loadThreadState:
|
|
28
|
-
saveThreadState:
|
|
29
|
-
hydrateThread:
|
|
30
|
-
flushThread:
|
|
36
|
+
initializeThread: pick("initializeThread"),
|
|
37
|
+
appendHumanMessage: pick("appendHumanMessage"),
|
|
38
|
+
appendToolResult: pick("appendToolResult"),
|
|
39
|
+
appendAgentMessage: pick("appendAgentMessage"),
|
|
40
|
+
appendSystemMessage: pick("appendSystemMessage"),
|
|
41
|
+
forkThread: pick("forkThread"),
|
|
42
|
+
truncateThread: pick("truncateThread"),
|
|
43
|
+
loadThreadState: pick("loadThreadState"),
|
|
44
|
+
saveThreadState: pick("saveThreadState"),
|
|
45
|
+
hydrateThread: pick("hydrateThread"),
|
|
46
|
+
flushThread: pick("flushThread")
|
|
31
47
|
};
|
|
32
48
|
}
|
|
33
49
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/adapter-id.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/thread/proxy.ts","../../../../src/adapters/thread/langchain/adapter-id.ts","../../../../src/adapters/thread/langchain/proxy.ts"],"names":[],"mappings":";;;AAiBA,IAAM,eAAA,GAAmC;AAAA,EACvC,mBAAA,EAAqB,KAAA;AAAA,EACrB,KAAA,EAAO;AAAA,IACL,eAAA,EAAiB,CAAA;AAAA,IACjB,eAAA,EAAiB,IAAA;AAAA,IACjB,eAAA,EAAiB,KAAA;AAAA,IACjB,kBAAA,EAAoB;AAAA;AAExB,CAAA;AASA,IAAM,cAAA,GAA2D;AAAA,EAC/D,aAAA,EAAe,EAAE,mBAAA,EAAqB,KAAA,EAAO,kBAAkB,KAAA,EAAM;AAAA,EACrE,WAAA,EAAa,EAAE,mBAAA,EAAqB,KAAA,EAAO,kBAAkB,KAAA;AAC/D,CAAA;AAsBA,SAAS,oBAAoB,CAAA,EAAuC;AAClE,EAAA,OAAO,UAAA,IAAc,KAAK,OAAA,IAAW,CAAA;AACvC;AASO,SAAS,oBAAA,CACd,aAAA,EACA,KAAA,EACA,OAAA,EACiC;AACjC,EAAA,MAAM,aAAA,GAAgB,KAAA,IAAS,YAAA,EAAa,CAAE,YAAA;AAE9C,EAAA,MAAM,IAAA,GACJ,WAAW,mBAAA,CAAoB,OAAO,IAAI,OAAA,GAAU,EAAE,UAAU,OAAA,EAAQ;AAE1E,EAAA,MAAM,IAAA,GAAO,KAAK,QAAA,IAAY,eAAA;AAE9B,EAAA,MAAM,QAAA,GAAW,gBAAyD,IAAI,CAAA;AAE9E,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,aAAa,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE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AAA,GAAa;;;ACiBnB,SAAS,uBAAA,CACd,OACA,OAAA,EACmD;AACnD,EAAA,OAAO,oBAAA;AAAA,IACL,UAAA;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 type ActivityOptions,\n} from \"@temporalio/workflow\";\nimport type { ThreadOps } from \"../session/types\";\n\ntype OpName = keyof ThreadOps;\n\n/** Tight `startToCloseTimeout` so a sick Redis surfaces quickly via retry. */\nconst DEFAULT_OPTIONS: ActivityOptions = {\n startToCloseTimeout: \"10s\",\n retry: {\n maximumAttempts: 6,\n initialInterval: \"5s\",\n maximumInterval: \"15m\",\n backoffCoefficient: 4,\n },\n};\n\n/**\n * `heartbeatTimeout` assumes the built-in S3 cold store's progress\n * events (multipart `Upload` + chunked stream read). Stalls trip via\n * heartbeat rather than `startToCloseTimeout`. Custom backends without\n * progress events should override via `perOp`. Harmless on Redis-only\n * deployments — the activities no-op.\n */\nconst BUILTIN_PER_OP: Partial<Record<OpName, ActivityOptions>> = {\n hydrateThread: { startToCloseTimeout: \"60s\", heartbeatTimeout: \"15s\" },\n flushThread: { startToCloseTimeout: \"60s\", heartbeatTimeout: \"15s\" },\n};\n\n/**\n * `perOp[op]` layers shallow-rightmost over `defaults` and the\n * built-in cold-tier overlay (`hydrateThread` / `flushThread`).\n * A bare {@link ActivityOptions} is also accepted (treated as `{ defaults }`).\n *\n * @example\n * ```typescript\n * proxyAnthropicThreadOps(undefined, {\n * defaults: { startToCloseTimeout: \"5s\" },\n * perOp: {\n * flushThread: { startToCloseTimeout: \"180s\" }, // heartbeatTimeout still inherited\n * },\n * });\n * ```\n */\nexport interface ThreadOpsProxyOptions {\n defaults?: ActivityOptions;\n perOp?: Partial<Record<OpName, ActivityOptions>>;\n}\n\nfunction isProxyOptionsShape(o: object): o is ThreadOpsProxyOptions {\n return \"defaults\" in o || \"perOp\" in o;\n}\n\n/**\n * Creates a workflow-safe Temporal activity proxy for {@link ThreadOps}.\n *\n * @param adapterPrefix - Adapter identifier (e.g. \"anthropic\", \"googleGenAI\", \"langChain\")\n * @param scope - Workflow scope. Defaults to `workflowInfo().workflowType`.\n * @param options - {@link ThreadOpsProxyOptions} or a bare {@link ActivityOptions}.\n */\nexport function createThreadOpsProxy(\n adapterPrefix: string,\n scope?: string,\n options?: ActivityOptions | ThreadOpsProxyOptions\n): ActivityInterfaceFor<ThreadOps> {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n const opts: ThreadOpsProxyOptions =\n options && isProxyOptionsShape(options) ? options : { defaults: options };\n\n const base = opts.defaults ?? DEFAULT_OPTIONS;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const baseActs = proxyActivities<Record<string, (...args: any[]) => any>>(base);\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 const pick = (op: OpName): unknown => {\n const overlay = { ...BUILTIN_PER_OP[op], ...opts.perOp?.[op] };\n if (Object.keys(overlay).length === 0) return baseActs[p(op)];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return proxyActivities<Record<string, (...args: any[]) => any>>({\n ...base,\n ...overlay,\n })[p(op)];\n };\n\n return {\n initializeThread: pick(\"initializeThread\"),\n appendHumanMessage: pick(\"appendHumanMessage\"),\n appendToolResult: pick(\"appendToolResult\"),\n appendAgentMessage: pick(\"appendAgentMessage\"),\n appendSystemMessage: pick(\"appendSystemMessage\"),\n forkThread: pick(\"forkThread\"),\n truncateThread: pick(\"truncateThread\"),\n loadThreadState: pick(\"loadThreadState\"),\n saveThreadState: pick(\"saveThreadState\"),\n hydrateThread: pick(\"hydrateThread\"),\n flushThread: pick(\"flushThread\"),\n } as ActivityInterfaceFor<ThreadOps>;\n}\n","/**\n * Public adapter identity for the LangChain thread adapter.\n *\n * This value is wire format — it appears as the prefix for Temporal\n * activity names (e.g. `langChainCodingAgentInitializeThread`) and must\n * never change, since renaming it would orphan existing persisted\n * threads and break in-flight workflows.\n *\n * Re-exported from `zeitlich/adapters/thread/langchain` so downstream\n * consumers can use the exact same literal the adapter uses internally,\n * typed as the narrow string literal `\"langChain\"`.\n */\nexport const ADAPTER_ID = \"langChain\" as const;\n\n/** Narrow string-literal type for {@link ADAPTER_ID}. */\nexport type AdapterId = typeof ADAPTER_ID;\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\";\nimport { ADAPTER_ID } from \"./adapter-id\";\n\nexport { ADAPTER_ID, type AdapterId } from \"./adapter-id\";\nexport type { ThreadOpsProxyOptions } from \"../../../lib/thread/proxy\";\n\nexport function proxyLangChainThreadOps(\n scope?: string,\n options?: Parameters<typeof createThreadOpsProxy>[2]\n): ActivityInterfaceFor<ThreadOps<LangChainContent>> {\n return createThreadOpsProxy(\n ADAPTER_ID,\n scope,\n options\n ) as ActivityInterfaceFor<ThreadOps<LangChainContent>>;\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { P as PersistedThreadState } from './types-
|
|
1
|
+
import { P as PersistedThreadState } from './types-qQVZfhoT.js';
|
|
2
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Pluggable cold-tier interface for thread archives.
|
|
@@ -58,19 +59,15 @@ interface ColdThreadStore {
|
|
|
58
59
|
delete(threadKey: string, threadId: string): Promise<void>;
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
-
* `send(...)`
|
|
63
|
-
* `@aws-sdk/
|
|
64
|
-
*
|
|
62
|
+
* Alias for `@aws-sdk/client-s3`'s `S3Client`. The built-in store
|
|
63
|
+
* calls `send(...)` and accesses `client.config` (read by
|
|
64
|
+
* `@aws-sdk/lib-storage`'s `Upload`) — a duck-type with just `send`
|
|
65
|
+
* is not sufficient.
|
|
65
66
|
*/
|
|
66
|
-
|
|
67
|
-
send<TInput, TOutput>(command: {
|
|
68
|
-
input: TInput;
|
|
69
|
-
} & object): Promise<TOutput>;
|
|
70
|
-
}
|
|
67
|
+
type S3LikeClient = S3Client;
|
|
71
68
|
/** Configuration for the built-in S3 cold store. */
|
|
72
69
|
interface S3ColdStoreConfig {
|
|
73
|
-
/** An `@aws-sdk/client-s3` `S3Client
|
|
70
|
+
/** An `@aws-sdk/client-s3` `S3Client`. */
|
|
74
71
|
s3: S3LikeClient;
|
|
75
72
|
/** S3 bucket that holds the archive. */
|
|
76
73
|
bucket: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { P as PersistedThreadState } from './types-
|
|
1
|
+
import { P as PersistedThreadState } from './types-DNEl5uxQ.cjs';
|
|
2
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Pluggable cold-tier interface for thread archives.
|
|
@@ -58,19 +59,15 @@ interface ColdThreadStore {
|
|
|
58
59
|
delete(threadKey: string, threadId: string): Promise<void>;
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
-
* `send(...)`
|
|
63
|
-
* `@aws-sdk/
|
|
64
|
-
*
|
|
62
|
+
* Alias for `@aws-sdk/client-s3`'s `S3Client`. The built-in store
|
|
63
|
+
* calls `send(...)` and accesses `client.config` (read by
|
|
64
|
+
* `@aws-sdk/lib-storage`'s `Upload`) — a duck-type with just `send`
|
|
65
|
+
* is not sufficient.
|
|
65
66
|
*/
|
|
66
|
-
|
|
67
|
-
send<TInput, TOutput>(command: {
|
|
68
|
-
input: TInput;
|
|
69
|
-
} & object): Promise<TOutput>;
|
|
70
|
-
}
|
|
67
|
+
type S3LikeClient = S3Client;
|
|
71
68
|
/** Configuration for the built-in S3 cold store. */
|
|
72
69
|
interface S3ColdStoreConfig {
|
|
73
|
-
/** An `@aws-sdk/client-s3` `S3Client
|
|
70
|
+
/** An `@aws-sdk/client-s3` `S3Client`. */
|
|
74
71
|
s3: S3LikeClient;
|
|
75
72
|
/** S3 bucket that holds the archive. */
|
|
76
73
|
bucket: string;
|