zeitlich 0.2.50 → 0.2.53

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.
Files changed (74) hide show
  1. package/dist/adapters/thread/anthropic/index.cjs +15 -13
  2. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  3. package/dist/adapters/thread/anthropic/index.d.cts +15 -10
  4. package/dist/adapters/thread/anthropic/index.d.ts +15 -10
  5. package/dist/adapters/thread/anthropic/index.js +15 -13
  6. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  7. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  8. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  9. package/dist/adapters/thread/google-genai/index.cjs +18 -12
  10. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  11. package/dist/adapters/thread/google-genai/index.d.cts +181 -11
  12. package/dist/adapters/thread/google-genai/index.d.ts +181 -11
  13. package/dist/adapters/thread/google-genai/index.js +18 -12
  14. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  15. package/dist/adapters/thread/google-genai/workflow.d.cts +6 -6
  16. package/dist/adapters/thread/google-genai/workflow.d.ts +6 -6
  17. package/dist/adapters/thread/langchain/index.cjs +22 -13
  18. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  19. package/dist/adapters/thread/langchain/index.d.cts +15 -10
  20. package/dist/adapters/thread/langchain/index.d.ts +15 -10
  21. package/dist/adapters/thread/langchain/index.js +22 -13
  22. package/dist/adapters/thread/langchain/index.js.map +1 -1
  23. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  24. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  25. package/dist/{cold-store-CCnZYWjx.d.ts → cold-store-BbvJLhXJ.d.ts} +1 -1
  26. package/dist/{cold-store-C0uvYTSi.d.cts → cold-store-Ki_U0jyd.d.cts} +1 -1
  27. package/dist/index.cjs +38 -3
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +8 -8
  30. package/dist/index.d.ts +8 -8
  31. package/dist/index.js +38 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/{proxy-C4J1pNUk.d.ts → proxy-CwniAm8W.d.ts} +1 -1
  34. package/dist/{proxy-BVznA2_p.d.cts → proxy-wsNrEh2u.d.cts} +1 -1
  35. package/dist/{thread-manager-BqjzWsP7.d.ts → thread-manager-D1zfZnxi.d.ts} +4 -5
  36. package/dist/{thread-manager-SkSWRPRc.d.ts → thread-manager-DCXkMqHH.d.ts} +4 -5
  37. package/dist/{thread-manager-CzIs47uG.d.cts → thread-manager-DW7FqMdN.d.cts} +4 -5
  38. package/dist/{thread-manager-Dzl1fHhV.d.cts → thread-manager-DhvA5oDL.d.cts} +4 -5
  39. package/dist/{types-YNesmGKV.d.ts → types-DQQKF5FQ.d.ts} +24 -2
  40. package/dist/{types-DZnUqCAP.d.cts → types-DpHBKA8c.d.cts} +24 -2
  41. package/dist/{types-d2RvEP6v.d.cts → types-tJ9Or7u_.d.cts} +1 -1
  42. package/dist/{types-CbPnU4RM.d.ts → types-ziu6HZPh.d.ts} +1 -1
  43. package/dist/{workflow-Bkzg0cjB.d.ts → workflow-BeMiPEq4.d.ts} +2 -1
  44. package/dist/{workflow-B3oTe2_D.d.cts → workflow-CNTNwEnj.d.cts} +2 -1
  45. package/dist/workflow.cjs +38 -3
  46. package/dist/workflow.cjs.map +1 -1
  47. package/dist/workflow.d.cts +2 -2
  48. package/dist/workflow.d.ts +2 -2
  49. package/dist/workflow.js +38 -3
  50. package/dist/workflow.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/adapters/thread/anthropic/activities.test.ts +115 -0
  53. package/src/adapters/thread/anthropic/activities.ts +10 -18
  54. package/src/adapters/thread/anthropic/model-invoker.test.ts +50 -0
  55. package/src/adapters/thread/anthropic/model-invoker.ts +10 -0
  56. package/src/adapters/thread/anthropic/thread-manager.ts +2 -3
  57. package/src/adapters/thread/google-genai/activities.test.ts +162 -0
  58. package/src/adapters/thread/google-genai/activities.ts +37 -14
  59. package/src/adapters/thread/google-genai/model-invoker.test.ts +53 -4
  60. package/src/adapters/thread/google-genai/model-invoker.ts +11 -0
  61. package/src/adapters/thread/google-genai/thread-manager.ts +2 -3
  62. package/src/adapters/thread/langchain/activities.test.ts +88 -0
  63. package/src/adapters/thread/langchain/activities.ts +14 -11
  64. package/src/adapters/thread/langchain/model-invoker.test.ts +74 -0
  65. package/src/adapters/thread/langchain/model-invoker.ts +15 -2
  66. package/src/adapters/thread/langchain/thread-manager.ts +2 -3
  67. package/src/lib/hooks/index.ts +2 -0
  68. package/src/lib/hooks/types.ts +26 -1
  69. package/src/lib/observability/hooks.ts +17 -2
  70. package/src/lib/session/session.ts +31 -3
  71. package/src/lib/state/types.ts +9 -11
  72. package/src/workflow.ts +2 -0
  73. package/dist/activities-IuOIvPHO.d.ts +0 -162
  74. package/dist/activities-cIlq1y1y.d.cts +0 -162
@@ -1,162 +0,0 @@
1
- import { RedisClientType } from 'redis';
2
- import { Part, Content, GoogleGenAI } from '@google/genai';
3
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-YNesmGKV.js';
4
- import { C as ColdThreadStore } from './cold-store-CCnZYWjx.js';
5
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CbPnU4RM.js';
6
- import { A as ADAPTER_ID } from './adapter-id-BB-mmrts.js';
7
-
8
- /** SDK-native content type for Google GenAI human messages */
9
- type GoogleGenAIContent = string | Part[];
10
- /** SDK-native content type for Google GenAI system instructions */
11
- type GoogleGenAISystemContent = string | Part[];
12
- /** A Content with a unique ID for idempotent Redis storage */
13
- interface StoredContent {
14
- id: string;
15
- content: Content;
16
- }
17
- type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<StoredContent, Content>;
18
- interface GoogleGenAIThreadManagerConfig {
19
- redis: RedisClientType;
20
- threadId: string;
21
- /** Thread key, defaults to 'messages' */
22
- key?: string;
23
- hooks?: GoogleGenAIThreadManagerHooks;
24
- /**
25
- * Override the default thread TTL (90 days). When pairing the
26
- * adapter with a durable cold tier, a shorter TTL (hours) is
27
- * typically more appropriate.
28
- */
29
- ttlSeconds?: number;
30
- }
31
- /** Prepared payload ready to send to the Google GenAI API */
32
- interface GoogleGenAIInvocationPayload {
33
- contents: Content[];
34
- systemInstruction?: Part[];
35
- }
36
- /** Thread manager with Google GenAI Content convenience helpers */
37
- interface GoogleGenAIThreadManager extends ProviderThreadManager<StoredContent, GoogleGenAIContent, GoogleGenAIToolResponse, GoogleGenAISystemContent> {
38
- appendModelContent(id: string, parts: Part[]): Promise<void>;
39
- prepareForInvocation(): Promise<GoogleGenAIInvocationPayload>;
40
- }
41
- /**
42
- * Creates a Google GenAI-specific thread manager that stores StoredContent
43
- * instances in Redis and provides convenience helpers for creating and
44
- * appending typed Content messages.
45
- */
46
- declare function createGoogleGenAIThreadManager(config: GoogleGenAIThreadManagerConfig): GoogleGenAIThreadManager;
47
-
48
- type GoogleGenAIThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, GoogleGenAIContent>;
49
- interface GoogleGenAIAdapterConfig {
50
- redis: RedisClientType;
51
- client?: GoogleGenAI;
52
- /** Default model name (e.g. 'gemini-2.5-flash'). If omitted, use `createModelInvoker()` */
53
- model?: string;
54
- hooks?: GoogleGenAIThreadManagerHooks;
55
- /**
56
- * Optional durable cold tier (e.g. S3, R2, GCS). When provided,
57
- * the session hydrates the thread on entry (`continue`/`fork`) and
58
- * flushes it on every exit path. When omitted, the adapter is
59
- * Redis-only and `hydrateThread`/`flushThread` activities are no-ops.
60
- */
61
- coldStore?: ColdThreadStore;
62
- /**
63
- * Override the default Redis TTL (90 days). When pairing the
64
- * adapter with a `coldStore`, a shorter TTL (hours) is typically
65
- * more appropriate.
66
- */
67
- ttlSeconds?: number;
68
- }
69
- /**
70
- * Tool response type accepted by the Google GenAI adapter.
71
- *
72
- * Handlers can return:
73
- * - **`string`** — plain text, wrapped in a `functionResponse` part.
74
- * - **`Record<string, unknown>`** — structured object used as `functionResponse.response`.
75
- * - **`Part[]`** — pre-built parts used directly as `Content.parts`.
76
- * The handler is responsible for building correct Part objects (e.g. `functionResponse`,
77
- * `inlineData`, `text`). Use `context.toolCallId` and `context.toolName` to construct
78
- * `functionResponse` parts.
79
- *
80
- * @example
81
- * ```typescript
82
- * adapter.wrapHandler(async (args, ctx) => ({
83
- * toolResponse: [
84
- * { functionResponse: { id: ctx.toolCallId, name: ctx.toolName, response: { result: "done" } } },
85
- * { inlineData: { data: base64, mimeType: "image/png" } },
86
- * ],
87
- * data: null,
88
- * }));
89
- * ```
90
- */
91
- type GoogleGenAIToolResponse = string | Record<string, unknown> | Part[];
92
- interface GoogleGenAIAdapter {
93
- /** Model invoker using the default model (only available when `model` was provided) */
94
- invoker: ModelInvoker<Content>;
95
- /** Create an invoker for a specific model name (for multi-model setups) */
96
- createModelInvoker(model: string, client: GoogleGenAI): ModelInvoker<Content>;
97
- /**
98
- * Create prefixed thread activities for registration on the worker.
99
- *
100
- * @param scope - Workflow name appended to the adapter prefix.
101
- * Use different scopes for the main agent vs subagents to avoid collisions.
102
- *
103
- * @example
104
- * ```typescript
105
- * adapter.createActivities("codingAgent")
106
- * // → { googleGenAICodingAgentInitializeThread, googleGenAICodingAgentAppendHumanMessage, … }
107
- *
108
- * adapter.createActivities("researchAgent")
109
- * // → { googleGenAIResearchAgentInitializeThread, … }
110
- * ```
111
- */
112
- createActivities<S extends string = "">(scope?: S): GoogleGenAIThreadOps<S>;
113
- /**
114
- * Identity wrapper that types a tool handler for this adapter.
115
- * Constrains `toolResponse` to {@link GoogleGenAIToolResponse}.
116
- */
117
- wrapHandler<TArgs, TResult, TContext extends RouterContext = RouterContext>(handler: (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult, GoogleGenAIToolResponse>>): ActivityToolHandler<TArgs, TResult, TContext, GoogleGenAIToolResponse>;
118
- }
119
- /**
120
- * Creates a Google GenAI adapter that bundles thread operations and model
121
- * invocation using the `@google/genai` SDK.
122
- *
123
- * Use `createActivities(scope)` to register scoped thread operations as
124
- * Temporal activities on the worker. The `invoker` (or invokers created via
125
- * `createModelInvoker`) should be wrapped with `createRunAgentActivity`.
126
- *
127
- * @example
128
- * ```typescript
129
- * import { createGoogleGenAIAdapter } from 'zeitlich/adapters/thread/google-genai';
130
- * import { createRunAgentActivity } from 'zeitlich';
131
- * import { GoogleGenAI } from '@google/genai';
132
- *
133
- * const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
134
- * const adapter = createGoogleGenAIAdapter({ redis, client, model: 'gemini-2.5-flash' });
135
- *
136
- * export function createActivities(temporalClient: WorkflowClient) {
137
- * return {
138
- * ...adapter.createActivities("codingAgent"),
139
- * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
140
- * };
141
- * }
142
- * ```
143
- *
144
- * @example Multi-agent worker (main + subagent share the adapter)
145
- * ```typescript
146
- * export function createActivities(temporalClient: WorkflowClient) {
147
- * return {
148
- * ...adapter.createActivities("codingAgent"),
149
- * ...adapter.createActivities("researchAgent"),
150
- * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
151
- * ...createRunAgentActivity(
152
- * temporalClient,
153
- * adapter.createModelInvoker('gemini-2.5-pro'),
154
- * "researchAgent",
155
- * ),
156
- * };
157
- * }
158
- * ```
159
- */
160
- declare function createGoogleGenAIAdapter(config: GoogleGenAIAdapterConfig): GoogleGenAIAdapter;
161
-
162
- export { type GoogleGenAIThreadManagerHooks as G, type StoredContent as S, type GoogleGenAIAdapter as a, type GoogleGenAIAdapterConfig as b, type GoogleGenAIContent as c, type GoogleGenAIInvocationPayload as d, type GoogleGenAIThreadManager as e, type GoogleGenAIThreadManagerConfig as f, type GoogleGenAIThreadOps as g, type GoogleGenAIToolResponse as h, createGoogleGenAIAdapter as i, createGoogleGenAIThreadManager as j };
@@ -1,162 +0,0 @@
1
- import { RedisClientType } from 'redis';
2
- import { Part, Content, GoogleGenAI } from '@google/genai';
3
- import { a as ModelInvoker, b as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, c as ToolHandlerResponse, d as ActivityToolHandler } from './types-DZnUqCAP.cjs';
4
- import { C as ColdThreadStore } from './cold-store-C0uvYTSi.cjs';
5
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-d2RvEP6v.cjs';
6
- import { A as ADAPTER_ID } from './adapter-id-BB-mmrts.cjs';
7
-
8
- /** SDK-native content type for Google GenAI human messages */
9
- type GoogleGenAIContent = string | Part[];
10
- /** SDK-native content type for Google GenAI system instructions */
11
- type GoogleGenAISystemContent = string | Part[];
12
- /** A Content with a unique ID for idempotent Redis storage */
13
- interface StoredContent {
14
- id: string;
15
- content: Content;
16
- }
17
- type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<StoredContent, Content>;
18
- interface GoogleGenAIThreadManagerConfig {
19
- redis: RedisClientType;
20
- threadId: string;
21
- /** Thread key, defaults to 'messages' */
22
- key?: string;
23
- hooks?: GoogleGenAIThreadManagerHooks;
24
- /**
25
- * Override the default thread TTL (90 days). When pairing the
26
- * adapter with a durable cold tier, a shorter TTL (hours) is
27
- * typically more appropriate.
28
- */
29
- ttlSeconds?: number;
30
- }
31
- /** Prepared payload ready to send to the Google GenAI API */
32
- interface GoogleGenAIInvocationPayload {
33
- contents: Content[];
34
- systemInstruction?: Part[];
35
- }
36
- /** Thread manager with Google GenAI Content convenience helpers */
37
- interface GoogleGenAIThreadManager extends ProviderThreadManager<StoredContent, GoogleGenAIContent, GoogleGenAIToolResponse, GoogleGenAISystemContent> {
38
- appendModelContent(id: string, parts: Part[]): Promise<void>;
39
- prepareForInvocation(): Promise<GoogleGenAIInvocationPayload>;
40
- }
41
- /**
42
- * Creates a Google GenAI-specific thread manager that stores StoredContent
43
- * instances in Redis and provides convenience helpers for creating and
44
- * appending typed Content messages.
45
- */
46
- declare function createGoogleGenAIThreadManager(config: GoogleGenAIThreadManagerConfig): GoogleGenAIThreadManager;
47
-
48
- type GoogleGenAIThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, GoogleGenAIContent>;
49
- interface GoogleGenAIAdapterConfig {
50
- redis: RedisClientType;
51
- client?: GoogleGenAI;
52
- /** Default model name (e.g. 'gemini-2.5-flash'). If omitted, use `createModelInvoker()` */
53
- model?: string;
54
- hooks?: GoogleGenAIThreadManagerHooks;
55
- /**
56
- * Optional durable cold tier (e.g. S3, R2, GCS). When provided,
57
- * the session hydrates the thread on entry (`continue`/`fork`) and
58
- * flushes it on every exit path. When omitted, the adapter is
59
- * Redis-only and `hydrateThread`/`flushThread` activities are no-ops.
60
- */
61
- coldStore?: ColdThreadStore;
62
- /**
63
- * Override the default Redis TTL (90 days). When pairing the
64
- * adapter with a `coldStore`, a shorter TTL (hours) is typically
65
- * more appropriate.
66
- */
67
- ttlSeconds?: number;
68
- }
69
- /**
70
- * Tool response type accepted by the Google GenAI adapter.
71
- *
72
- * Handlers can return:
73
- * - **`string`** — plain text, wrapped in a `functionResponse` part.
74
- * - **`Record<string, unknown>`** — structured object used as `functionResponse.response`.
75
- * - **`Part[]`** — pre-built parts used directly as `Content.parts`.
76
- * The handler is responsible for building correct Part objects (e.g. `functionResponse`,
77
- * `inlineData`, `text`). Use `context.toolCallId` and `context.toolName` to construct
78
- * `functionResponse` parts.
79
- *
80
- * @example
81
- * ```typescript
82
- * adapter.wrapHandler(async (args, ctx) => ({
83
- * toolResponse: [
84
- * { functionResponse: { id: ctx.toolCallId, name: ctx.toolName, response: { result: "done" } } },
85
- * { inlineData: { data: base64, mimeType: "image/png" } },
86
- * ],
87
- * data: null,
88
- * }));
89
- * ```
90
- */
91
- type GoogleGenAIToolResponse = string | Record<string, unknown> | Part[];
92
- interface GoogleGenAIAdapter {
93
- /** Model invoker using the default model (only available when `model` was provided) */
94
- invoker: ModelInvoker<Content>;
95
- /** Create an invoker for a specific model name (for multi-model setups) */
96
- createModelInvoker(model: string, client: GoogleGenAI): ModelInvoker<Content>;
97
- /**
98
- * Create prefixed thread activities for registration on the worker.
99
- *
100
- * @param scope - Workflow name appended to the adapter prefix.
101
- * Use different scopes for the main agent vs subagents to avoid collisions.
102
- *
103
- * @example
104
- * ```typescript
105
- * adapter.createActivities("codingAgent")
106
- * // → { googleGenAICodingAgentInitializeThread, googleGenAICodingAgentAppendHumanMessage, … }
107
- *
108
- * adapter.createActivities("researchAgent")
109
- * // → { googleGenAIResearchAgentInitializeThread, … }
110
- * ```
111
- */
112
- createActivities<S extends string = "">(scope?: S): GoogleGenAIThreadOps<S>;
113
- /**
114
- * Identity wrapper that types a tool handler for this adapter.
115
- * Constrains `toolResponse` to {@link GoogleGenAIToolResponse}.
116
- */
117
- wrapHandler<TArgs, TResult, TContext extends RouterContext = RouterContext>(handler: (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult, GoogleGenAIToolResponse>>): ActivityToolHandler<TArgs, TResult, TContext, GoogleGenAIToolResponse>;
118
- }
119
- /**
120
- * Creates a Google GenAI adapter that bundles thread operations and model
121
- * invocation using the `@google/genai` SDK.
122
- *
123
- * Use `createActivities(scope)` to register scoped thread operations as
124
- * Temporal activities on the worker. The `invoker` (or invokers created via
125
- * `createModelInvoker`) should be wrapped with `createRunAgentActivity`.
126
- *
127
- * @example
128
- * ```typescript
129
- * import { createGoogleGenAIAdapter } from 'zeitlich/adapters/thread/google-genai';
130
- * import { createRunAgentActivity } from 'zeitlich';
131
- * import { GoogleGenAI } from '@google/genai';
132
- *
133
- * const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
134
- * const adapter = createGoogleGenAIAdapter({ redis, client, model: 'gemini-2.5-flash' });
135
- *
136
- * export function createActivities(temporalClient: WorkflowClient) {
137
- * return {
138
- * ...adapter.createActivities("codingAgent"),
139
- * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
140
- * };
141
- * }
142
- * ```
143
- *
144
- * @example Multi-agent worker (main + subagent share the adapter)
145
- * ```typescript
146
- * export function createActivities(temporalClient: WorkflowClient) {
147
- * return {
148
- * ...adapter.createActivities("codingAgent"),
149
- * ...adapter.createActivities("researchAgent"),
150
- * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
151
- * ...createRunAgentActivity(
152
- * temporalClient,
153
- * adapter.createModelInvoker('gemini-2.5-pro'),
154
- * "researchAgent",
155
- * ),
156
- * };
157
- * }
158
- * ```
159
- */
160
- declare function createGoogleGenAIAdapter(config: GoogleGenAIAdapterConfig): GoogleGenAIAdapter;
161
-
162
- export { type GoogleGenAIThreadManagerHooks as G, type StoredContent as S, type GoogleGenAIAdapter as a, type GoogleGenAIAdapterConfig as b, type GoogleGenAIContent as c, type GoogleGenAIInvocationPayload as d, type GoogleGenAIThreadManager as e, type GoogleGenAIThreadManagerConfig as f, type GoogleGenAIThreadOps as g, type GoogleGenAIToolResponse as h, createGoogleGenAIAdapter as i, createGoogleGenAIThreadManager as j };