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,23 +1,67 @@
1
- export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.cjs';
2
- import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-cIlq1y1y.cjs';
3
- export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-cIlq1y1y.cjs';
1
+ import { A as ADAPTER_ID } from '../../../adapter-id-BB-mmrts.cjs';
2
+ export { a as AdapterId } from '../../../adapter-id-BB-mmrts.cjs';
4
3
  import { RedisClientType } from 'redis';
5
- import { GoogleGenAI, GenerateContentConfig, Content } from '@google/genai';
6
- import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-DZnUqCAP.cjs';
7
- import '../../../cold-store-C0uvYTSi.cjs';
8
- import '@aws-sdk/client-s3';
9
- import '../../../types-d2RvEP6v.cjs';
4
+ import { Part, Content, GoogleGenAI, GenerateContentConfig } from '@google/genai';
5
+ import { c as ModelInvokerConfig, d as AgentResponse, M as ModelInvoker, a as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, b as ToolHandlerResponse, A as ActivityToolHandler } from '../../../types-DpHBKA8c.cjs';
6
+ import { C as ColdThreadStore } from '../../../cold-store-Ki_U0jyd.cjs';
7
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from '../../../types-tJ9Or7u_.cjs';
10
8
  import '@temporalio/workflow';
11
9
  import '@temporalio/common/lib/interfaces';
12
10
  import 'zod';
13
11
  import '../../../types-D8W5TnSa.cjs';
14
12
  import '@temporalio/common';
13
+ import '@aws-sdk/client-s3';
14
+
15
+ /** SDK-native content type for Google GenAI human messages */
16
+ type GoogleGenAIContent = string | Part[];
17
+ /** SDK-native content type for Google GenAI system instructions */
18
+ type GoogleGenAISystemContent = string | Part[];
19
+ /** A Content with a unique ID for idempotent Redis storage */
20
+ interface StoredContent {
21
+ id: string;
22
+ content: Content;
23
+ }
24
+ type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<StoredContent, Content>;
25
+ interface GoogleGenAIThreadManagerConfig {
26
+ redis: RedisClientType;
27
+ threadId: string;
28
+ /** Thread key, defaults to 'messages' */
29
+ key?: string;
30
+ hooks?: GoogleGenAIThreadManagerHooks;
31
+ /**
32
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
33
+ * value (hours) with a cold tier.
34
+ */
35
+ ttlSeconds?: number;
36
+ }
37
+ /** Prepared payload ready to send to the Google GenAI API */
38
+ interface GoogleGenAIInvocationPayload {
39
+ contents: Content[];
40
+ systemInstruction?: Part[];
41
+ }
42
+ /** Thread manager with Google GenAI Content convenience helpers */
43
+ interface GoogleGenAIThreadManager extends ProviderThreadManager<StoredContent, GoogleGenAIContent, GoogleGenAIToolResponse, GoogleGenAISystemContent> {
44
+ appendModelContent(id: string, parts: Part[]): Promise<void>;
45
+ prepareForInvocation(): Promise<GoogleGenAIInvocationPayload>;
46
+ }
47
+ /**
48
+ * Creates a Google GenAI-specific thread manager that stores StoredContent
49
+ * instances in Redis and provides convenience helpers for creating and
50
+ * appending typed Content messages.
51
+ */
52
+ declare function createGoogleGenAIThreadManager(config: GoogleGenAIThreadManagerConfig): GoogleGenAIThreadManager;
15
53
 
16
54
  interface GoogleGenAIModelInvokerConfig {
17
55
  redis: RedisClientType;
18
56
  client: GoogleGenAI;
19
57
  model: string;
20
58
  hooks?: GoogleGenAIThreadManagerHooks;
59
+ /**
60
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
61
+ * value (hours) with a cold tier. Distinct from `cache.ttlSeconds`
62
+ * (server-side context caching).
63
+ */
64
+ ttlSeconds?: number;
21
65
  /** Passed through to `generateContentStream().config`.
22
66
  * `systemInstruction`, `tools`, and `abortSignal` are managed by the
23
67
  * invoker and will override any values set here. */
@@ -50,15 +94,141 @@ interface GoogleGenAIModelInvokerConfig {
50
94
  * return { ...createRunAgentActivity(client, invoker, "myAgent") };
51
95
  * ```
52
96
  */
53
- declare function createGoogleGenAIModelInvoker({ redis, client, model, hooks, config: generationConfig, cache: cacheConfig, }: GoogleGenAIModelInvokerConfig): (config: ModelInvokerConfig) => Promise<AgentResponse<Content>>;
54
- declare function invokeGoogleGenAIModel({ redis, client, model, hooks, config, generationConfig, cache, }: {
97
+ declare function createGoogleGenAIModelInvoker({ redis, client, model, hooks, ttlSeconds, config: generationConfig, cache: cacheConfig, }: GoogleGenAIModelInvokerConfig): (config: ModelInvokerConfig) => Promise<AgentResponse<Content>>;
98
+ declare function invokeGoogleGenAIModel({ redis, client, model, hooks, ttlSeconds, config, generationConfig, cache, }: {
55
99
  redis: RedisClientType;
56
100
  client: GoogleGenAI;
57
101
  model: string;
58
102
  hooks?: GoogleGenAIThreadManagerHooks;
103
+ ttlSeconds?: number;
59
104
  config: ModelInvokerConfig;
60
105
  generationConfig?: GenerateContentConfig;
61
106
  cache?: GoogleGenAIModelInvokerConfig["cache"];
62
107
  }): Promise<AgentResponse<Content>>;
63
108
 
64
- export { type GoogleGenAIModelInvokerConfig, createGoogleGenAIModelInvoker, invokeGoogleGenAIModel };
109
+ type GoogleGenAIThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, GoogleGenAIContent>;
110
+ interface GoogleGenAIAdapterConfig {
111
+ redis: RedisClientType;
112
+ client?: GoogleGenAI;
113
+ /** Default model name (e.g. 'gemini-2.5-flash'). If omitted, use `createModelInvoker()` */
114
+ model?: string;
115
+ hooks?: GoogleGenAIThreadManagerHooks;
116
+ /**
117
+ * Optional durable cold tier (e.g. S3, R2, GCS). When provided,
118
+ * the session hydrates the thread on entry (`continue`/`fork`) and
119
+ * flushes it on every exit path. When omitted, the adapter is
120
+ * Redis-only and `hydrateThread`/`flushThread` activities are no-ops.
121
+ */
122
+ coldStore?: ColdThreadStore;
123
+ /**
124
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
125
+ * value (hours) with a cold tier.
126
+ */
127
+ ttlSeconds?: number;
128
+ /**
129
+ * Default generation config forwarded to every invoker the adapter
130
+ * builds (`invoker` and `createModelInvoker`). `systemInstruction`,
131
+ * `tools`, and `abortSignal` are managed by the invoker and override
132
+ * any values set here.
133
+ */
134
+ generationConfig?: GenerateContentConfig;
135
+ /**
136
+ * Default server-side context caching config forwarded to every
137
+ * invoker the adapter builds. See {@link createGoogleGenAIModelInvoker}.
138
+ */
139
+ cache?: GoogleGenAIModelInvokerConfig["cache"];
140
+ }
141
+ /**
142
+ * Tool response type accepted by the Google GenAI adapter.
143
+ *
144
+ * Handlers can return:
145
+ * - **`string`** — plain text, wrapped in a `functionResponse` part.
146
+ * - **`Record<string, unknown>`** — structured object used as `functionResponse.response`.
147
+ * - **`Part[]`** — pre-built parts used directly as `Content.parts`.
148
+ * The handler is responsible for building correct Part objects (e.g. `functionResponse`,
149
+ * `inlineData`, `text`). Use `context.toolCallId` and `context.toolName` to construct
150
+ * `functionResponse` parts.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * adapter.wrapHandler(async (args, ctx) => ({
155
+ * toolResponse: [
156
+ * { functionResponse: { id: ctx.toolCallId, name: ctx.toolName, response: { result: "done" } } },
157
+ * { inlineData: { data: base64, mimeType: "image/png" } },
158
+ * ],
159
+ * data: null,
160
+ * }));
161
+ * ```
162
+ */
163
+ type GoogleGenAIToolResponse = string | Record<string, unknown> | Part[];
164
+ interface GoogleGenAIAdapter {
165
+ /** Model invoker using the default model (only available when `model` was provided) */
166
+ invoker: ModelInvoker<Content>;
167
+ /** Create an invoker for a specific model name (for multi-model setups) */
168
+ createModelInvoker(model: string, client: GoogleGenAI): ModelInvoker<Content>;
169
+ /**
170
+ * Create prefixed thread activities for registration on the worker.
171
+ *
172
+ * @param scope - Workflow name appended to the adapter prefix.
173
+ * Use different scopes for the main agent vs subagents to avoid collisions.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * adapter.createActivities("codingAgent")
178
+ * // → { googleGenAICodingAgentInitializeThread, googleGenAICodingAgentAppendHumanMessage, … }
179
+ *
180
+ * adapter.createActivities("researchAgent")
181
+ * // → { googleGenAIResearchAgentInitializeThread, … }
182
+ * ```
183
+ */
184
+ createActivities<S extends string = "">(scope?: S): GoogleGenAIThreadOps<S>;
185
+ /**
186
+ * Identity wrapper that types a tool handler for this adapter.
187
+ * Constrains `toolResponse` to {@link GoogleGenAIToolResponse}.
188
+ */
189
+ wrapHandler<TArgs, TResult, TContext extends RouterContext = RouterContext>(handler: (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult, GoogleGenAIToolResponse>>): ActivityToolHandler<TArgs, TResult, TContext, GoogleGenAIToolResponse>;
190
+ }
191
+ /**
192
+ * Creates a Google GenAI adapter that bundles thread operations and model
193
+ * invocation using the `@google/genai` SDK.
194
+ *
195
+ * Use `createActivities(scope)` to register scoped thread operations as
196
+ * Temporal activities on the worker. The `invoker` (or invokers created via
197
+ * `createModelInvoker`) should be wrapped with `createRunAgentActivity`.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * import { createGoogleGenAIAdapter } from 'zeitlich/adapters/thread/google-genai';
202
+ * import { createRunAgentActivity } from 'zeitlich';
203
+ * import { GoogleGenAI } from '@google/genai';
204
+ *
205
+ * const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
206
+ * const adapter = createGoogleGenAIAdapter({ redis, client, model: 'gemini-2.5-flash' });
207
+ *
208
+ * export function createActivities(temporalClient: WorkflowClient) {
209
+ * return {
210
+ * ...adapter.createActivities("codingAgent"),
211
+ * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
212
+ * };
213
+ * }
214
+ * ```
215
+ *
216
+ * @example Multi-agent worker (main + subagent share the adapter)
217
+ * ```typescript
218
+ * export function createActivities(temporalClient: WorkflowClient) {
219
+ * return {
220
+ * ...adapter.createActivities("codingAgent"),
221
+ * ...adapter.createActivities("researchAgent"),
222
+ * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
223
+ * ...createRunAgentActivity(
224
+ * temporalClient,
225
+ * adapter.createModelInvoker('gemini-2.5-pro', client),
226
+ * "researchAgent",
227
+ * ),
228
+ * };
229
+ * }
230
+ * ```
231
+ */
232
+ declare function createGoogleGenAIAdapter(config: GoogleGenAIAdapterConfig): GoogleGenAIAdapter;
233
+
234
+ export { ADAPTER_ID, type GoogleGenAIAdapter, type GoogleGenAIAdapterConfig, type GoogleGenAIContent, type GoogleGenAIInvocationPayload, type GoogleGenAIModelInvokerConfig, type GoogleGenAIThreadManager, type GoogleGenAIThreadManagerConfig, type GoogleGenAIThreadOps, type GoogleGenAIToolResponse, type StoredContent, createGoogleGenAIAdapter, createGoogleGenAIModelInvoker, createGoogleGenAIThreadManager, invokeGoogleGenAIModel };
@@ -1,23 +1,67 @@
1
- export { A as ADAPTER_ID, a as AdapterId } from '../../../adapter-id-BB-mmrts.js';
2
- import { G as GoogleGenAIThreadManagerHooks } from '../../../activities-IuOIvPHO.js';
3
- export { a as GoogleGenAIAdapter, b as GoogleGenAIAdapterConfig, c as GoogleGenAIContent, d as GoogleGenAIInvocationPayload, e as GoogleGenAIThreadManager, f as GoogleGenAIThreadManagerConfig, g as GoogleGenAIThreadOps, h as GoogleGenAIToolResponse, S as StoredContent, i as createGoogleGenAIAdapter, j as createGoogleGenAIThreadManager } from '../../../activities-IuOIvPHO.js';
1
+ import { A as ADAPTER_ID } from '../../../adapter-id-BB-mmrts.js';
2
+ export { a as AdapterId } from '../../../adapter-id-BB-mmrts.js';
4
3
  import { RedisClientType } from 'redis';
5
- import { GoogleGenAI, GenerateContentConfig, Content } from '@google/genai';
6
- import { M as ModelInvokerConfig, A as AgentResponse } from '../../../types-YNesmGKV.js';
7
- import '../../../cold-store-CCnZYWjx.js';
8
- import '@aws-sdk/client-s3';
9
- import '../../../types-CbPnU4RM.js';
4
+ import { Part, Content, GoogleGenAI, GenerateContentConfig } from '@google/genai';
5
+ import { c as ModelInvokerConfig, d as AgentResponse, M as ModelInvoker, a as PrefixedThreadOps, S as ScopedPrefix, R as RouterContext, b as ToolHandlerResponse, A as ActivityToolHandler } from '../../../types-DQQKF5FQ.js';
6
+ import { C as ColdThreadStore } from '../../../cold-store-BbvJLhXJ.js';
7
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from '../../../types-ziu6HZPh.js';
10
8
  import '@temporalio/workflow';
11
9
  import '@temporalio/common/lib/interfaces';
12
10
  import 'zod';
13
11
  import '../../../types-D8W5TnSa.js';
14
12
  import '@temporalio/common';
13
+ import '@aws-sdk/client-s3';
14
+
15
+ /** SDK-native content type for Google GenAI human messages */
16
+ type GoogleGenAIContent = string | Part[];
17
+ /** SDK-native content type for Google GenAI system instructions */
18
+ type GoogleGenAISystemContent = string | Part[];
19
+ /** A Content with a unique ID for idempotent Redis storage */
20
+ interface StoredContent {
21
+ id: string;
22
+ content: Content;
23
+ }
24
+ type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<StoredContent, Content>;
25
+ interface GoogleGenAIThreadManagerConfig {
26
+ redis: RedisClientType;
27
+ threadId: string;
28
+ /** Thread key, defaults to 'messages' */
29
+ key?: string;
30
+ hooks?: GoogleGenAIThreadManagerHooks;
31
+ /**
32
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
33
+ * value (hours) with a cold tier.
34
+ */
35
+ ttlSeconds?: number;
36
+ }
37
+ /** Prepared payload ready to send to the Google GenAI API */
38
+ interface GoogleGenAIInvocationPayload {
39
+ contents: Content[];
40
+ systemInstruction?: Part[];
41
+ }
42
+ /** Thread manager with Google GenAI Content convenience helpers */
43
+ interface GoogleGenAIThreadManager extends ProviderThreadManager<StoredContent, GoogleGenAIContent, GoogleGenAIToolResponse, GoogleGenAISystemContent> {
44
+ appendModelContent(id: string, parts: Part[]): Promise<void>;
45
+ prepareForInvocation(): Promise<GoogleGenAIInvocationPayload>;
46
+ }
47
+ /**
48
+ * Creates a Google GenAI-specific thread manager that stores StoredContent
49
+ * instances in Redis and provides convenience helpers for creating and
50
+ * appending typed Content messages.
51
+ */
52
+ declare function createGoogleGenAIThreadManager(config: GoogleGenAIThreadManagerConfig): GoogleGenAIThreadManager;
15
53
 
16
54
  interface GoogleGenAIModelInvokerConfig {
17
55
  redis: RedisClientType;
18
56
  client: GoogleGenAI;
19
57
  model: string;
20
58
  hooks?: GoogleGenAIThreadManagerHooks;
59
+ /**
60
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
61
+ * value (hours) with a cold tier. Distinct from `cache.ttlSeconds`
62
+ * (server-side context caching).
63
+ */
64
+ ttlSeconds?: number;
21
65
  /** Passed through to `generateContentStream().config`.
22
66
  * `systemInstruction`, `tools`, and `abortSignal` are managed by the
23
67
  * invoker and will override any values set here. */
@@ -50,15 +94,141 @@ interface GoogleGenAIModelInvokerConfig {
50
94
  * return { ...createRunAgentActivity(client, invoker, "myAgent") };
51
95
  * ```
52
96
  */
53
- declare function createGoogleGenAIModelInvoker({ redis, client, model, hooks, config: generationConfig, cache: cacheConfig, }: GoogleGenAIModelInvokerConfig): (config: ModelInvokerConfig) => Promise<AgentResponse<Content>>;
54
- declare function invokeGoogleGenAIModel({ redis, client, model, hooks, config, generationConfig, cache, }: {
97
+ declare function createGoogleGenAIModelInvoker({ redis, client, model, hooks, ttlSeconds, config: generationConfig, cache: cacheConfig, }: GoogleGenAIModelInvokerConfig): (config: ModelInvokerConfig) => Promise<AgentResponse<Content>>;
98
+ declare function invokeGoogleGenAIModel({ redis, client, model, hooks, ttlSeconds, config, generationConfig, cache, }: {
55
99
  redis: RedisClientType;
56
100
  client: GoogleGenAI;
57
101
  model: string;
58
102
  hooks?: GoogleGenAIThreadManagerHooks;
103
+ ttlSeconds?: number;
59
104
  config: ModelInvokerConfig;
60
105
  generationConfig?: GenerateContentConfig;
61
106
  cache?: GoogleGenAIModelInvokerConfig["cache"];
62
107
  }): Promise<AgentResponse<Content>>;
63
108
 
64
- export { type GoogleGenAIModelInvokerConfig, createGoogleGenAIModelInvoker, invokeGoogleGenAIModel };
109
+ type GoogleGenAIThreadOps<TScope extends string = ""> = PrefixedThreadOps<ScopedPrefix<TScope, typeof ADAPTER_ID>, GoogleGenAIContent>;
110
+ interface GoogleGenAIAdapterConfig {
111
+ redis: RedisClientType;
112
+ client?: GoogleGenAI;
113
+ /** Default model name (e.g. 'gemini-2.5-flash'). If omitted, use `createModelInvoker()` */
114
+ model?: string;
115
+ hooks?: GoogleGenAIThreadManagerHooks;
116
+ /**
117
+ * Optional durable cold tier (e.g. S3, R2, GCS). When provided,
118
+ * the session hydrates the thread on entry (`continue`/`fork`) and
119
+ * flushes it on every exit path. When omitted, the adapter is
120
+ * Redis-only and `hydrateThread`/`flushThread` activities are no-ops.
121
+ */
122
+ coldStore?: ColdThreadStore;
123
+ /**
124
+ * Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
125
+ * value (hours) with a cold tier.
126
+ */
127
+ ttlSeconds?: number;
128
+ /**
129
+ * Default generation config forwarded to every invoker the adapter
130
+ * builds (`invoker` and `createModelInvoker`). `systemInstruction`,
131
+ * `tools`, and `abortSignal` are managed by the invoker and override
132
+ * any values set here.
133
+ */
134
+ generationConfig?: GenerateContentConfig;
135
+ /**
136
+ * Default server-side context caching config forwarded to every
137
+ * invoker the adapter builds. See {@link createGoogleGenAIModelInvoker}.
138
+ */
139
+ cache?: GoogleGenAIModelInvokerConfig["cache"];
140
+ }
141
+ /**
142
+ * Tool response type accepted by the Google GenAI adapter.
143
+ *
144
+ * Handlers can return:
145
+ * - **`string`** — plain text, wrapped in a `functionResponse` part.
146
+ * - **`Record<string, unknown>`** — structured object used as `functionResponse.response`.
147
+ * - **`Part[]`** — pre-built parts used directly as `Content.parts`.
148
+ * The handler is responsible for building correct Part objects (e.g. `functionResponse`,
149
+ * `inlineData`, `text`). Use `context.toolCallId` and `context.toolName` to construct
150
+ * `functionResponse` parts.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * adapter.wrapHandler(async (args, ctx) => ({
155
+ * toolResponse: [
156
+ * { functionResponse: { id: ctx.toolCallId, name: ctx.toolName, response: { result: "done" } } },
157
+ * { inlineData: { data: base64, mimeType: "image/png" } },
158
+ * ],
159
+ * data: null,
160
+ * }));
161
+ * ```
162
+ */
163
+ type GoogleGenAIToolResponse = string | Record<string, unknown> | Part[];
164
+ interface GoogleGenAIAdapter {
165
+ /** Model invoker using the default model (only available when `model` was provided) */
166
+ invoker: ModelInvoker<Content>;
167
+ /** Create an invoker for a specific model name (for multi-model setups) */
168
+ createModelInvoker(model: string, client: GoogleGenAI): ModelInvoker<Content>;
169
+ /**
170
+ * Create prefixed thread activities for registration on the worker.
171
+ *
172
+ * @param scope - Workflow name appended to the adapter prefix.
173
+ * Use different scopes for the main agent vs subagents to avoid collisions.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * adapter.createActivities("codingAgent")
178
+ * // → { googleGenAICodingAgentInitializeThread, googleGenAICodingAgentAppendHumanMessage, … }
179
+ *
180
+ * adapter.createActivities("researchAgent")
181
+ * // → { googleGenAIResearchAgentInitializeThread, … }
182
+ * ```
183
+ */
184
+ createActivities<S extends string = "">(scope?: S): GoogleGenAIThreadOps<S>;
185
+ /**
186
+ * Identity wrapper that types a tool handler for this adapter.
187
+ * Constrains `toolResponse` to {@link GoogleGenAIToolResponse}.
188
+ */
189
+ wrapHandler<TArgs, TResult, TContext extends RouterContext = RouterContext>(handler: (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult, GoogleGenAIToolResponse>>): ActivityToolHandler<TArgs, TResult, TContext, GoogleGenAIToolResponse>;
190
+ }
191
+ /**
192
+ * Creates a Google GenAI adapter that bundles thread operations and model
193
+ * invocation using the `@google/genai` SDK.
194
+ *
195
+ * Use `createActivities(scope)` to register scoped thread operations as
196
+ * Temporal activities on the worker. The `invoker` (or invokers created via
197
+ * `createModelInvoker`) should be wrapped with `createRunAgentActivity`.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * import { createGoogleGenAIAdapter } from 'zeitlich/adapters/thread/google-genai';
202
+ * import { createRunAgentActivity } from 'zeitlich';
203
+ * import { GoogleGenAI } from '@google/genai';
204
+ *
205
+ * const client = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
206
+ * const adapter = createGoogleGenAIAdapter({ redis, client, model: 'gemini-2.5-flash' });
207
+ *
208
+ * export function createActivities(temporalClient: WorkflowClient) {
209
+ * return {
210
+ * ...adapter.createActivities("codingAgent"),
211
+ * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
212
+ * };
213
+ * }
214
+ * ```
215
+ *
216
+ * @example Multi-agent worker (main + subagent share the adapter)
217
+ * ```typescript
218
+ * export function createActivities(temporalClient: WorkflowClient) {
219
+ * return {
220
+ * ...adapter.createActivities("codingAgent"),
221
+ * ...adapter.createActivities("researchAgent"),
222
+ * ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
223
+ * ...createRunAgentActivity(
224
+ * temporalClient,
225
+ * adapter.createModelInvoker('gemini-2.5-pro', client),
226
+ * "researchAgent",
227
+ * ),
228
+ * };
229
+ * }
230
+ * ```
231
+ */
232
+ declare function createGoogleGenAIAdapter(config: GoogleGenAIAdapterConfig): GoogleGenAIAdapter;
233
+
234
+ export { ADAPTER_ID, type GoogleGenAIAdapter, type GoogleGenAIAdapterConfig, type GoogleGenAIContent, type GoogleGenAIInvocationPayload, type GoogleGenAIModelInvokerConfig, type GoogleGenAIThreadManager, type GoogleGenAIThreadManagerConfig, type GoogleGenAIThreadOps, type GoogleGenAIToolResponse, type StoredContent, createGoogleGenAIAdapter, createGoogleGenAIModelInvoker, createGoogleGenAIThreadManager, invokeGoogleGenAIModel };
@@ -434,6 +434,7 @@ function createGoogleGenAIModelInvoker({
434
434
  client,
435
435
  model,
436
436
  hooks,
437
+ ttlSeconds,
437
438
  config: generationConfig,
438
439
  cache: cacheConfig
439
440
  }) {
@@ -444,7 +445,8 @@ function createGoogleGenAIModelInvoker({
444
445
  redis,
445
446
  threadId,
446
447
  key: threadKey,
447
- hooks
448
+ hooks,
449
+ ...ttlSeconds !== void 0 && { ttlSeconds }
448
450
  });
449
451
  await thread.truncateFromId(assistantMessageId);
450
452
  const { contents, systemInstruction } = await thread.prepareForInvocation();
@@ -544,6 +546,7 @@ async function invokeGoogleGenAIModel({
544
546
  client,
545
547
  model,
546
548
  hooks,
549
+ ttlSeconds,
547
550
  config,
548
551
  generationConfig,
549
552
  cache
@@ -553,6 +556,7 @@ async function invokeGoogleGenAIModel({
553
556
  client,
554
557
  model,
555
558
  hooks,
559
+ ...ttlSeconds !== void 0 && { ttlSeconds },
556
560
  config: generationConfig,
557
561
  cache
558
562
  });
@@ -562,21 +566,20 @@ async function invokeGoogleGenAIModel({
562
566
  // src/adapters/thread/google-genai/activities.ts
563
567
  function createGoogleGenAIAdapter(config) {
564
568
  const { redis } = config;
565
- const baseExtras = {
569
+ const base = {
570
+ redis,
566
571
  ...config.ttlSeconds !== void 0 && { ttlSeconds: config.ttlSeconds }
567
572
  };
568
573
  const makeProviderThread = (threadId, threadKey) => createGoogleGenAIThreadManager({
569
- redis,
574
+ ...base,
570
575
  threadId,
571
- key: threadKey,
572
- ...baseExtras
576
+ key: threadKey
573
577
  });
574
578
  const makeTieredBase = (threadId, threadKey) => createTieredThreadManager({
575
- redis,
579
+ ...base,
576
580
  threadId,
577
581
  key: threadKey,
578
582
  idOf: storedContentId,
579
- ...baseExtras,
580
583
  ...config.coldStore && { coldStore: config.coldStore }
581
584
  });
582
585
  const threadOps = {
@@ -608,11 +611,10 @@ function createGoogleGenAIAdapter(config) {
608
611
  },
609
612
  async forkThread(sourceThreadId, targetThreadId, threadKey) {
610
613
  const thread = createGoogleGenAIThreadManager({
611
- redis,
614
+ ...base,
612
615
  threadId: sourceThreadId,
613
616
  key: threadKey,
614
- hooks: config.hooks,
615
- ...baseExtras
617
+ hooks: config.hooks
616
618
  });
617
619
  await thread.fork(targetThreadId);
618
620
  },
@@ -645,10 +647,14 @@ function createGoogleGenAIAdapter(config) {
645
647
  );
646
648
  }
647
649
  const makeInvoker = (model, client) => createGoogleGenAIModelInvoker({
648
- redis,
650
+ ...base,
649
651
  client,
650
652
  model,
651
- hooks: config.hooks
653
+ hooks: config.hooks,
654
+ ...config.generationConfig !== void 0 && {
655
+ config: config.generationConfig
656
+ },
657
+ ...config.cache !== void 0 && { cache: config.cache }
652
658
  });
653
659
  const invoker = config.model && config.client ? makeInvoker(config.model, config.client) : (() => {
654
660
  throw new Error(