zeitlich 0.2.35 → 0.2.37

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 (199) hide show
  1. package/README.md +146 -92
  2. package/dist/{activities-BVI2lTwr.d.ts → activities-Bb-nAjwQ.d.ts} +2 -2
  3. package/dist/{activities-hd4aNnZE.d.cts → activities-vkI4_3CC.d.cts} +2 -2
  4. package/dist/adapters/sandbox/bedrock/index.cjs +14 -11
  5. package/dist/adapters/sandbox/bedrock/index.cjs.map +1 -1
  6. package/dist/adapters/sandbox/bedrock/index.d.cts +4 -3
  7. package/dist/adapters/sandbox/bedrock/index.d.ts +4 -3
  8. package/dist/adapters/sandbox/bedrock/index.js +14 -11
  9. package/dist/adapters/sandbox/bedrock/index.js.map +1 -1
  10. package/dist/adapters/sandbox/bedrock/workflow.cjs +2 -0
  11. package/dist/adapters/sandbox/bedrock/workflow.cjs.map +1 -1
  12. package/dist/adapters/sandbox/bedrock/workflow.d.cts +2 -2
  13. package/dist/adapters/sandbox/bedrock/workflow.d.ts +2 -2
  14. package/dist/adapters/sandbox/bedrock/workflow.js +2 -0
  15. package/dist/adapters/sandbox/bedrock/workflow.js.map +1 -1
  16. package/dist/adapters/sandbox/daytona/index.cjs +35 -6
  17. package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
  18. package/dist/adapters/sandbox/daytona/index.d.cts +3 -1
  19. package/dist/adapters/sandbox/daytona/index.d.ts +3 -1
  20. package/dist/adapters/sandbox/daytona/index.js +35 -6
  21. package/dist/adapters/sandbox/daytona/index.js.map +1 -1
  22. package/dist/adapters/sandbox/daytona/workflow.cjs +2 -0
  23. package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
  24. package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
  25. package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
  26. package/dist/adapters/sandbox/daytona/workflow.js +2 -0
  27. package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
  28. package/dist/adapters/sandbox/e2b/index.cjs +59 -10
  29. package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
  30. package/dist/adapters/sandbox/e2b/index.d.cts +5 -3
  31. package/dist/adapters/sandbox/e2b/index.d.ts +5 -3
  32. package/dist/adapters/sandbox/e2b/index.js +59 -10
  33. package/dist/adapters/sandbox/e2b/index.js.map +1 -1
  34. package/dist/adapters/sandbox/e2b/workflow.cjs +2 -0
  35. package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
  36. package/dist/adapters/sandbox/e2b/workflow.d.cts +1 -1
  37. package/dist/adapters/sandbox/e2b/workflow.d.ts +1 -1
  38. package/dist/adapters/sandbox/e2b/workflow.js +2 -0
  39. package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
  40. package/dist/adapters/sandbox/inmemory/index.cjs +5 -0
  41. package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
  42. package/dist/adapters/sandbox/inmemory/index.d.cts +2 -1
  43. package/dist/adapters/sandbox/inmemory/index.d.ts +2 -1
  44. package/dist/adapters/sandbox/inmemory/index.js +5 -0
  45. package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
  46. package/dist/adapters/sandbox/inmemory/workflow.cjs +2 -0
  47. package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
  48. package/dist/adapters/sandbox/inmemory/workflow.d.cts +1 -1
  49. package/dist/adapters/sandbox/inmemory/workflow.d.ts +1 -1
  50. package/dist/adapters/sandbox/inmemory/workflow.js +2 -0
  51. package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
  52. package/dist/adapters/thread/anthropic/index.cjs +71 -36
  53. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  54. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  55. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  56. package/dist/adapters/thread/anthropic/index.js +71 -36
  57. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  58. package/dist/adapters/thread/anthropic/workflow.cjs +5 -1
  59. package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -1
  60. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  61. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  62. package/dist/adapters/thread/anthropic/workflow.js +5 -1
  63. package/dist/adapters/thread/anthropic/workflow.js.map +1 -1
  64. package/dist/adapters/thread/google-genai/index.cjs +50 -25
  65. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  66. package/dist/adapters/thread/google-genai/index.d.cts +5 -5
  67. package/dist/adapters/thread/google-genai/index.d.ts +5 -5
  68. package/dist/adapters/thread/google-genai/index.js +50 -25
  69. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  70. package/dist/adapters/thread/google-genai/workflow.cjs +5 -1
  71. package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
  72. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  73. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  74. package/dist/adapters/thread/google-genai/workflow.js +5 -1
  75. package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
  76. package/dist/adapters/thread/langchain/index.cjs +34 -7
  77. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  78. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  79. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  80. package/dist/adapters/thread/langchain/index.js +34 -7
  81. package/dist/adapters/thread/langchain/index.js.map +1 -1
  82. package/dist/adapters/thread/langchain/workflow.cjs +5 -1
  83. package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
  84. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  85. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  86. package/dist/adapters/thread/langchain/workflow.js +5 -1
  87. package/dist/adapters/thread/langchain/workflow.js.map +1 -1
  88. package/dist/index.cjs +206 -120
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.cts +17 -11
  91. package/dist/index.d.ts +17 -11
  92. package/dist/index.js +207 -121
  93. package/dist/index.js.map +1 -1
  94. package/dist/{proxy-BjdFGPTm.d.ts → proxy-0smGKvx8.d.ts} +1 -1
  95. package/dist/{proxy-7RnVaPdJ.d.cts → proxy-DEtowJyd.d.cts} +1 -1
  96. package/dist/{thread-manager-DjN5JYul.d.ts → thread-manager-3fszQih4.d.ts} +2 -2
  97. package/dist/{thread-manager-CbpiGq1L.d.ts → thread-manager-C-C4pI2z.d.ts} +2 -2
  98. package/dist/{thread-manager-BBzNgQWH.d.cts → thread-manager-CzYln2OC.d.cts} +2 -2
  99. package/dist/{thread-manager-DzXm9eeI.d.cts → thread-manager-D4vgzYrh.d.cts} +2 -2
  100. package/dist/{types-yiXmqedU.d.ts → types-B37hKoWA.d.ts} +1 -1
  101. package/dist/{types-DQ1l_gXL.d.cts → types-BO7Yju20.d.cts} +63 -14
  102. package/dist/{types-wiGLvxWf.d.ts → types-CNuWnvy9.d.ts} +1 -1
  103. package/dist/{types-CADc5V_P.d.ts → types-CPKDl-y_.d.ts} +63 -14
  104. package/dist/{types-Mc_4BCfT.d.cts → types-D08CXPh8.d.cts} +1 -1
  105. package/dist/{types-CBH54cwr.d.cts → types-DWEUmYAJ.d.cts} +1 -1
  106. package/dist/{types-DxCpFNv_.d.cts → types-tQL9njTu.d.cts} +25 -0
  107. package/dist/{types-DxCpFNv_.d.ts → types-tQL9njTu.d.ts} +25 -0
  108. package/dist/{workflow-P2pTSfKu.d.ts → workflow-CjXHbZZc.d.ts} +2 -2
  109. package/dist/{workflow-DhtWRovz.d.cts → workflow-Do_lzJpT.d.cts} +2 -2
  110. package/dist/workflow.cjs +182 -114
  111. package/dist/workflow.cjs.map +1 -1
  112. package/dist/workflow.d.cts +3 -3
  113. package/dist/workflow.d.ts +3 -3
  114. package/dist/workflow.js +183 -115
  115. package/dist/workflow.js.map +1 -1
  116. package/package.json +1 -1
  117. package/src/adapters/sandbox/bedrock/filesystem.ts +6 -12
  118. package/src/adapters/sandbox/bedrock/index.ts +10 -8
  119. package/src/adapters/sandbox/bedrock/proxy.ts +2 -0
  120. package/src/adapters/sandbox/daytona/filesystem.ts +29 -6
  121. package/src/adapters/sandbox/daytona/index.ts +6 -0
  122. package/src/adapters/sandbox/daytona/proxy.ts +2 -0
  123. package/src/adapters/sandbox/e2b/filesystem.ts +5 -4
  124. package/src/adapters/sandbox/e2b/index.ts +63 -12
  125. package/src/adapters/sandbox/e2b/proxy.ts +2 -0
  126. package/src/adapters/sandbox/inmemory/index.ts +5 -0
  127. package/src/adapters/sandbox/inmemory/proxy.ts +2 -0
  128. package/src/adapters/thread/anthropic/activities.ts +49 -26
  129. package/src/adapters/thread/anthropic/model-invoker.ts +15 -6
  130. package/src/adapters/thread/anthropic/proxy.ts +6 -2
  131. package/src/adapters/thread/anthropic/thread-manager.test.ts +26 -7
  132. package/src/adapters/thread/anthropic/thread-manager.ts +60 -46
  133. package/src/adapters/thread/google-genai/activities.ts +7 -2
  134. package/src/adapters/thread/google-genai/model-invoker.ts +26 -8
  135. package/src/adapters/thread/google-genai/proxy.ts +6 -2
  136. package/src/adapters/thread/google-genai/thread-manager.test.ts +13 -3
  137. package/src/adapters/thread/google-genai/thread-manager.ts +54 -33
  138. package/src/adapters/thread/langchain/activities.ts +46 -24
  139. package/src/adapters/thread/langchain/hooks.test.ts +36 -49
  140. package/src/adapters/thread/langchain/hooks.ts +18 -5
  141. package/src/adapters/thread/langchain/model-invoker.ts +3 -3
  142. package/src/adapters/thread/langchain/proxy.ts +6 -2
  143. package/src/adapters/thread/langchain/thread-manager.test.ts +5 -1
  144. package/src/adapters/thread/langchain/thread-manager.ts +20 -9
  145. package/src/index.ts +4 -1
  146. package/src/lib/activity.ts +16 -6
  147. package/src/lib/hooks/types.ts +6 -6
  148. package/src/lib/lifecycle.ts +9 -1
  149. package/src/lib/model/proxy.ts +2 -2
  150. package/src/lib/observability/hooks.ts +4 -5
  151. package/src/lib/observability/index.ts +1 -4
  152. package/src/lib/sandbox/manager.ts +21 -4
  153. package/src/lib/sandbox/node-fs.ts +3 -6
  154. package/src/lib/sandbox/sandbox.test.ts +36 -3
  155. package/src/lib/sandbox/tree.integration.test.ts +10 -3
  156. package/src/lib/sandbox/types.ts +35 -1
  157. package/src/lib/session/session-edge-cases.integration.test.ts +51 -13
  158. package/src/lib/session/session.integration.test.ts +139 -0
  159. package/src/lib/session/session.ts +50 -19
  160. package/src/lib/session/types.ts +13 -5
  161. package/src/lib/skills/fs-provider.ts +12 -8
  162. package/src/lib/skills/handler.ts +1 -1
  163. package/src/lib/skills/parse.ts +3 -1
  164. package/src/lib/skills/register.ts +1 -3
  165. package/src/lib/skills/skills.integration.test.ts +25 -15
  166. package/src/lib/state/manager.integration.test.ts +12 -2
  167. package/src/lib/subagent/define.ts +1 -1
  168. package/src/lib/subagent/handler.ts +186 -71
  169. package/src/lib/subagent/index.ts +1 -5
  170. package/src/lib/subagent/register.ts +3 -2
  171. package/src/lib/subagent/signals.ts +1 -10
  172. package/src/lib/subagent/subagent.integration.test.ts +438 -156
  173. package/src/lib/subagent/tool.ts +4 -3
  174. package/src/lib/subagent/types.ts +50 -20
  175. package/src/lib/subagent/workflow.ts +9 -49
  176. package/src/lib/thread/id.test.ts +1 -1
  177. package/src/lib/thread/id.ts +1 -2
  178. package/src/lib/thread/proxy.ts +3 -4
  179. package/src/lib/thread/types.ts +11 -3
  180. package/src/lib/tool-router/index.ts +1 -5
  181. package/src/lib/tool-router/router-edge-cases.integration.test.ts +1 -1
  182. package/src/lib/tool-router/router.ts +3 -2
  183. package/src/lib/tool-router/types.ts +11 -3
  184. package/src/lib/tool-router/with-sandbox.ts +19 -5
  185. package/src/lib/virtual-fs/filesystem.ts +1 -1
  186. package/src/lib/virtual-fs/index.ts +5 -1
  187. package/src/lib/virtual-fs/mutations.ts +2 -4
  188. package/src/lib/virtual-fs/queries.ts +9 -5
  189. package/src/lib/virtual-fs/types.ts +4 -1
  190. package/src/lib/virtual-fs/virtual-fs.test.ts +9 -11
  191. package/src/lib/workflow.test.ts +7 -4
  192. package/src/lib/workflow.ts +1 -5
  193. package/src/tools/ask-user-question/tool.ts +1 -3
  194. package/src/tools/glob/handler.ts +1 -4
  195. package/src/tools/task-get/handler.ts +4 -5
  196. package/src/tools/task-list/handler.ts +1 -4
  197. package/src/tools/task-update/handler.ts +4 -5
  198. package/src/workflow.ts +20 -7
  199. package/tsup.config.ts +9 -6
@@ -27,7 +27,10 @@ const userMsg: StoredMessage = {
27
27
 
28
28
  const assistantMsg: StoredMessage = {
29
29
  id: "msg-2",
30
- message: { role: "assistant", content: [{ type: "text", text: "Hi there!" }] },
30
+ message: {
31
+ role: "assistant",
32
+ content: [{ type: "text", text: "Hi there!" }],
33
+ },
31
34
  };
32
35
 
33
36
  describe("Anthropic thread manager hooks", () => {
@@ -40,7 +43,9 @@ describe("Anthropic thread manager hooks", () => {
40
43
  ...msg,
41
44
  message: {
42
45
  ...msg.message,
43
- content: [{ type: "text" as const, text: `[modified] ${firstBlock?.text}` }],
46
+ content: [
47
+ { type: "text" as const, text: `[modified] ${firstBlock?.text}` },
48
+ ],
44
49
  },
45
50
  };
46
51
  });
@@ -55,10 +60,18 @@ describe("Anthropic thread manager hooks", () => {
55
60
  const { messages, system } = await tm.prepareForInvocation();
56
61
 
57
62
  expect(hook).toHaveBeenCalledTimes(3);
58
- expect(hook).toHaveBeenCalledWith(systemMsg, 0, [systemMsg, userMsg, assistantMsg]);
63
+ expect(hook).toHaveBeenCalledWith(systemMsg, 0, [
64
+ systemMsg,
65
+ userMsg,
66
+ assistantMsg,
67
+ ]);
59
68
  expect(system).toBe("You are helpful.");
60
- expect(messages[0]?.content).toEqual([{ type: "text", text: "[modified] Hello" }]);
61
- expect(messages[1]?.content).toEqual([{ type: "text", text: "[modified] Hi there!" }]);
69
+ expect(messages[0]?.content).toEqual([
70
+ { type: "text", text: "[modified] Hello" },
71
+ ]);
72
+ expect(messages[1]?.content).toEqual([
73
+ { type: "text", text: "[modified] Hi there!" },
74
+ ]);
62
75
  });
63
76
 
64
77
  it("is not called when not configured", async () => {
@@ -90,7 +103,9 @@ describe("Anthropic thread manager hooks", () => {
90
103
  const { messages } = await tm.prepareForInvocation();
91
104
 
92
105
  expect(hook).toHaveBeenCalledTimes(2);
93
- expect(messages[0]?.content).toEqual([{ type: "text", text: "[post] done" }]);
106
+ expect(messages[0]?.content).toEqual([
107
+ { type: "text", text: "[post] done" },
108
+ ]);
94
109
  });
95
110
 
96
111
  it("receives the full prepared messages array", async () => {
@@ -105,7 +120,11 @@ describe("Anthropic thread manager hooks", () => {
105
120
 
106
121
  await tm.prepareForInvocation();
107
122
 
108
- const args = hook.mock.calls[0] as unknown as [unknown, number, unknown[]];
123
+ const args = hook.mock.calls[0] as unknown as [
124
+ unknown,
125
+ number,
126
+ unknown[],
127
+ ];
109
128
  expect(args[2]).toHaveLength(2);
110
129
  });
111
130
  });
@@ -9,9 +9,7 @@ import type {
9
9
  } from "../../../lib/thread/types";
10
10
 
11
11
  /** SDK-native content type for Anthropic human messages */
12
- export type AnthropicContent =
13
- | string
14
- | Anthropic.Messages.ContentBlockParam[];
12
+ export type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
15
13
 
16
14
  /** SDK-native content type for Anthropic system prompts (supports cache_control blocks) */
17
15
  export type AnthropicSystemContent =
@@ -26,7 +24,10 @@ export interface StoredMessage {
26
24
  isSystem?: boolean;
27
25
  }
28
26
 
29
- export type AnthropicThreadManagerHooks = ThreadManagerHooks<StoredMessage, Anthropic.Messages.MessageParam>;
27
+ export type AnthropicThreadManagerHooks = ThreadManagerHooks<
28
+ StoredMessage,
29
+ Anthropic.Messages.MessageParam
30
+ >;
30
31
 
31
32
  export interface AnthropicThreadManagerConfig {
32
33
  redis: Redis;
@@ -43,11 +44,15 @@ export interface AnthropicInvocationPayload {
43
44
  }
44
45
 
45
46
  /** Thread manager with Anthropic MessageParam convenience helpers */
46
- export interface AnthropicThreadManager
47
- extends ProviderThreadManager<StoredMessage, AnthropicContent, JsonValue, AnthropicSystemContent> {
47
+ export interface AnthropicThreadManager extends ProviderThreadManager<
48
+ StoredMessage,
49
+ AnthropicContent,
50
+ JsonValue,
51
+ AnthropicSystemContent
52
+ > {
48
53
  appendAssistantMessage(
49
54
  id: string,
50
- content: Anthropic.Messages.ContentBlock[],
55
+ content: Anthropic.Messages.ContentBlock[]
51
56
  ): Promise<void>;
52
57
  prepareForInvocation(): Promise<AnthropicInvocationPayload>;
53
58
  }
@@ -58,7 +63,7 @@ function storedMessageId(msg: StoredMessage): string {
58
63
 
59
64
  /** Normalise content into an array of ContentBlockParam */
60
65
  function toContentBlocks(
61
- content: AnthropicContent,
66
+ content: AnthropicContent
62
67
  ): Anthropic.Messages.ContentBlockParam[] {
63
68
  if (typeof content === "string") {
64
69
  return [{ type: "text", text: content }];
@@ -72,7 +77,7 @@ function toContentBlocks(
72
77
  * merging, multiple sequential tool-result messages would violate this.
73
78
  */
74
79
  function mergeConsecutiveMessages(
75
- messages: Anthropic.Messages.MessageParam[],
80
+ messages: Anthropic.Messages.MessageParam[]
76
81
  ): Anthropic.Messages.MessageParam[] {
77
82
  const merged: Anthropic.Messages.MessageParam[] = [];
78
83
  for (const msg of messages) {
@@ -88,9 +93,7 @@ function mergeConsecutiveMessages(
88
93
  } else {
89
94
  merged.push({
90
95
  ...msg,
91
- content: Array.isArray(msg.content)
92
- ? [...msg.content]
93
- : msg.content,
96
+ content: Array.isArray(msg.content) ? [...msg.content] : msg.content,
94
97
  });
95
98
  }
96
99
  }
@@ -103,7 +106,7 @@ function mergeConsecutiveMessages(
103
106
  * appending typed messages.
104
107
  */
105
108
  export function createAnthropicThreadManager(
106
- config: AnthropicThreadManagerConfig,
109
+ config: AnthropicThreadManagerConfig
107
110
  ): AnthropicThreadManager {
108
111
  const baseConfig: ThreadManagerConfig<StoredMessage> = {
109
112
  redis: config.redis,
@@ -117,49 +120,56 @@ export function createAnthropicThreadManager(
117
120
  const helpers: Omit<AnthropicThreadManager, keyof typeof base> = {
118
121
  async appendUserMessage(
119
122
  id: string,
120
- content: AnthropicContent,
123
+ content: AnthropicContent
121
124
  ): Promise<void> {
122
- await base.append([{
123
- id,
124
- message: { role: "user", content: toContentBlocks(content) },
125
- }]);
125
+ await base.append([
126
+ {
127
+ id,
128
+ message: { role: "user", content: toContentBlocks(content) },
129
+ },
130
+ ]);
126
131
  },
127
132
 
128
133
  async appendSystemMessage(
129
134
  id: string,
130
- content: AnthropicSystemContent,
135
+ content: AnthropicSystemContent
131
136
  ): Promise<void> {
132
137
  await base.initialize();
133
- await base.append([{
134
- id,
135
- // Stored under a user-role placeholder to satisfy the MessageParam
136
- // shape; the `isSystem` flag steers extraction in prepareForInvocation.
137
- message: {
138
- role: "user",
139
- content: content as Anthropic.Messages.MessageParam["content"],
138
+ await base.append([
139
+ {
140
+ id,
141
+ // Stored under a user-role placeholder to satisfy the MessageParam
142
+ // shape; the `isSystem` flag steers extraction in prepareForInvocation.
143
+ message: {
144
+ role: "user",
145
+ content: content as Anthropic.Messages.MessageParam["content"],
146
+ },
147
+ isSystem: true,
140
148
  },
141
- isSystem: true,
142
- }]);
149
+ ]);
143
150
  },
144
151
 
145
152
  async appendAssistantMessage(
146
153
  id: string,
147
- content: Anthropic.Messages.ContentBlock[],
154
+ content: Anthropic.Messages.ContentBlock[]
148
155
  ): Promise<void> {
149
- await base.append([{
150
- id,
151
- message: {
152
- role: "assistant",
153
- content: content as unknown as Anthropic.Messages.ContentBlockParam[],
156
+ await base.append([
157
+ {
158
+ id,
159
+ message: {
160
+ role: "assistant",
161
+ content:
162
+ content as unknown as Anthropic.Messages.ContentBlockParam[],
163
+ },
154
164
  },
155
- }]);
165
+ ]);
156
166
  },
157
167
 
158
168
  async appendToolResult(
159
169
  id: string,
160
170
  toolCallId: string,
161
171
  _toolName: string,
162
- content: JsonValue,
172
+ content: JsonValue
163
173
  ): Promise<void> {
164
174
  const toolContent =
165
175
  typeof content === "string"
@@ -167,17 +177,21 @@ export function createAnthropicThreadManager(
167
177
  : Array.isArray(content)
168
178
  ? (content as unknown as Anthropic.Messages.ToolResultBlockParam["content"])
169
179
  : JSON.stringify(content);
170
- await base.append([{
171
- id,
172
- message: {
173
- role: "user",
174
- content: [{
175
- type: "tool_result" as const,
176
- tool_use_id: toolCallId,
177
- content: toolContent,
178
- }],
180
+ await base.append([
181
+ {
182
+ id,
183
+ message: {
184
+ role: "user",
185
+ content: [
186
+ {
187
+ type: "tool_result" as const,
188
+ tool_use_id: toolCallId,
189
+ content: toolContent,
190
+ },
191
+ ],
192
+ },
179
193
  },
180
- }]);
194
+ ]);
181
195
  },
182
196
 
183
197
  async prepareForInvocation(): Promise<AnthropicInvocationPayload> {
@@ -200,7 +200,7 @@ export function createGoogleGenAIAdapter(
200
200
  threadId: string,
201
201
  id: string,
202
202
  message: Content,
203
- threadKey?: string,
203
+ threadKey?: string
204
204
  ): Promise<void> {
205
205
  const thread = createGoogleGenAIThreadManager({
206
206
  redis,
@@ -240,7 +240,12 @@ export function createGoogleGenAIAdapter(
240
240
  model: string,
241
241
  client: GoogleGenAI
242
242
  ): ModelInvoker<Content> =>
243
- createGoogleGenAIModelInvoker({ redis, client, model, hooks: config.hooks });
243
+ createGoogleGenAIModelInvoker({
244
+ redis,
245
+ client,
246
+ model,
247
+ hooks: config.hooks,
248
+ });
244
249
 
245
250
  const invoker: ModelInvoker<Content> =
246
251
  config.model && config.client
@@ -1,8 +1,17 @@
1
1
  import type Redis from "ioredis";
2
- import type { GoogleGenAI, Content, FunctionDeclaration, Part, GenerateContentResponse } from "@google/genai";
2
+ import type {
3
+ GoogleGenAI,
4
+ Content,
5
+ FunctionDeclaration,
6
+ Part,
7
+ GenerateContentResponse,
8
+ } from "@google/genai";
3
9
  import type { SerializableToolDefinition } from "../../../lib/types";
4
10
  import type { AgentResponse, ModelInvokerConfig } from "../../../lib/model";
5
- import { createGoogleGenAIThreadManager, type GoogleGenAIThreadManagerHooks } from "./thread-manager";
11
+ import {
12
+ createGoogleGenAIThreadManager,
13
+ type GoogleGenAIThreadManagerHooks,
14
+ } from "./thread-manager";
6
15
  import { getActivityContext } from "../../../lib/activity";
7
16
 
8
17
  export interface GoogleGenAIModelInvokerConfig {
@@ -13,7 +22,7 @@ export interface GoogleGenAIModelInvokerConfig {
13
22
  }
14
23
 
15
24
  function toFunctionDeclarations(
16
- tools: SerializableToolDefinition[],
25
+ tools: SerializableToolDefinition[]
17
26
  ): FunctionDeclaration[] {
18
27
  return tools.map((t) => ({
19
28
  name: t.name,
@@ -53,14 +62,18 @@ export function createGoogleGenAIModelInvoker({
53
62
  hooks,
54
63
  }: GoogleGenAIModelInvokerConfig) {
55
64
  return async function invokeGoogleGenAIModel(
56
- config: ModelInvokerConfig,
65
+ config: ModelInvokerConfig
57
66
  ): Promise<AgentResponse<Content>> {
58
67
  const { threadId, threadKey, state } = config;
59
68
  const { heartbeat, signal } = getActivityContext();
60
69
 
61
- const thread = createGoogleGenAIThreadManager({ redis, threadId, key: threadKey, hooks });
62
- const { contents, systemInstruction } =
63
- await thread.prepareForInvocation();
70
+ const thread = createGoogleGenAIThreadManager({
71
+ redis,
72
+ threadId,
73
+ key: threadKey,
74
+ hooks,
75
+ });
76
+ const { contents, systemInstruction } = await thread.prepareForInvocation();
64
77
 
65
78
  const functionDeclarations = toFunctionDeclarations(state.tools);
66
79
  const tools =
@@ -125,6 +138,11 @@ export async function invokeGoogleGenAIModel({
125
138
  hooks?: GoogleGenAIThreadManagerHooks;
126
139
  config: ModelInvokerConfig;
127
140
  }): Promise<AgentResponse<Content>> {
128
- const invoker = createGoogleGenAIModelInvoker({ redis, client, model, hooks });
141
+ const invoker = createGoogleGenAIModelInvoker({
142
+ redis,
143
+ client,
144
+ model,
145
+ hooks,
146
+ });
129
147
  return invoker(config);
130
148
  }
@@ -27,7 +27,11 @@ const ADAPTER_PREFIX = "googleGenAI";
27
27
 
28
28
  export function proxyGoogleGenAIThreadOps(
29
29
  scope?: string,
30
- options?: Parameters<typeof createThreadOpsProxy>[2],
30
+ options?: Parameters<typeof createThreadOpsProxy>[2]
31
31
  ): ActivityInterfaceFor<ThreadOps<GoogleGenAIContent>> {
32
- return createThreadOpsProxy(ADAPTER_PREFIX, scope, options) as ActivityInterfaceFor<ThreadOps<GoogleGenAIContent>>;
32
+ return createThreadOpsProxy(
33
+ ADAPTER_PREFIX,
34
+ scope,
35
+ options
36
+ ) as ActivityInterfaceFor<ThreadOps<GoogleGenAIContent>>;
33
37
  }
@@ -39,7 +39,9 @@ describe("Google GenAI thread manager hooks", () => {
39
39
  ...msg,
40
40
  content: {
41
41
  ...msg.content,
42
- parts: [{ text: `[modified] ${msg.content.parts?.[0]?.text ?? ""}` }],
42
+ parts: [
43
+ { text: `[modified] ${msg.content.parts?.[0]?.text ?? ""}` },
44
+ ],
43
45
  },
44
46
  };
45
47
  });
@@ -54,7 +56,11 @@ describe("Google GenAI thread manager hooks", () => {
54
56
  const { contents, systemInstruction } = await tm.prepareForInvocation();
55
57
 
56
58
  expect(hook).toHaveBeenCalledTimes(3);
57
- expect(hook).toHaveBeenCalledWith(systemContent, 0, [systemContent, userContent, modelContent]);
59
+ expect(hook).toHaveBeenCalledWith(systemContent, 0, [
60
+ systemContent,
61
+ userContent,
62
+ modelContent,
63
+ ]);
58
64
  expect(systemInstruction).toEqual([{ text: "You are helpful." }]);
59
65
  expect(contents[0]?.parts?.[0]?.text).toBe("[modified] Hello");
60
66
  expect(contents[1]?.parts?.[0]?.text).toBe("[modified] Hi there!");
@@ -106,7 +112,11 @@ describe("Google GenAI thread manager hooks", () => {
106
112
 
107
113
  await tm.prepareForInvocation();
108
114
 
109
- const args = hook.mock.calls[0] as unknown as [Content, number, Content[]];
115
+ const args = hook.mock.calls[0] as unknown as [
116
+ Content,
117
+ number,
118
+ Content[],
119
+ ];
110
120
  expect(args[2]).toHaveLength(2);
111
121
  });
112
122
  });
@@ -20,7 +20,10 @@ export interface StoredContent {
20
20
  content: Content;
21
21
  }
22
22
 
23
- export type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<StoredContent, Content>;
23
+ export type GoogleGenAIThreadManagerHooks = ThreadManagerHooks<
24
+ StoredContent,
25
+ Content
26
+ >;
24
27
 
25
28
  export interface GoogleGenAIThreadManagerConfig {
26
29
  redis: Redis;
@@ -37,8 +40,12 @@ export interface GoogleGenAIInvocationPayload {
37
40
  }
38
41
 
39
42
  /** Thread manager with Google GenAI Content convenience helpers */
40
- export interface GoogleGenAIThreadManager
41
- extends ProviderThreadManager<StoredContent, GoogleGenAIContent, GoogleGenAIToolResponse, GoogleGenAISystemContent> {
43
+ export interface GoogleGenAIThreadManager extends ProviderThreadManager<
44
+ StoredContent,
45
+ GoogleGenAIContent,
46
+ GoogleGenAIToolResponse,
47
+ GoogleGenAISystemContent
48
+ > {
42
49
  appendModelContent(id: string, parts: Part[]): Promise<void>;
43
50
  prepareForInvocation(): Promise<GoogleGenAIInvocationPayload>;
44
51
  }
@@ -56,7 +63,9 @@ function toParts(content: GoogleGenAIContent): Part[] {
56
63
  }
57
64
 
58
65
  /** Convert a string or object into a Record suitable for functionResponse.response */
59
- function toFunctionResponse(content: string | Record<string, unknown>): Record<string, unknown> {
66
+ function toFunctionResponse(
67
+ content: string | Record<string, unknown>
68
+ ): Record<string, unknown> {
60
69
  if (typeof content === "object") {
61
70
  return content;
62
71
  }
@@ -87,7 +96,7 @@ function mergeConsecutiveContents(contents: Content[]): Content[] {
87
96
  * appending typed Content messages.
88
97
  */
89
98
  export function createGoogleGenAIThreadManager(
90
- config: GoogleGenAIThreadManagerConfig,
99
+ config: GoogleGenAIThreadManagerConfig
91
100
  ): GoogleGenAIThreadManager {
92
101
  const baseConfig: ThreadManagerConfig<StoredContent> = {
93
102
  redis: config.redis,
@@ -101,54 +110,64 @@ export function createGoogleGenAIThreadManager(
101
110
  const helpers: Omit<GoogleGenAIThreadManager, keyof typeof base> = {
102
111
  async appendUserMessage(
103
112
  id: string,
104
- content: GoogleGenAIContent,
113
+ content: GoogleGenAIContent
105
114
  ): Promise<void> {
106
- await base.append([{
107
- id,
108
- content: { role: "user", parts: toParts(content) },
109
- }]);
115
+ await base.append([
116
+ {
117
+ id,
118
+ content: { role: "user", parts: toParts(content) },
119
+ },
120
+ ]);
110
121
  },
111
122
 
112
123
  async appendSystemMessage(
113
124
  id: string,
114
- content: GoogleGenAISystemContent,
125
+ content: GoogleGenAISystemContent
115
126
  ): Promise<void> {
116
127
  const parts: Part[] =
117
128
  typeof content === "string" ? [{ text: content }] : content;
118
129
  await base.initialize();
119
- await base.append([{
120
- id,
121
- content: { role: "system", parts },
122
- }]);
130
+ await base.append([
131
+ {
132
+ id,
133
+ content: { role: "system", parts },
134
+ },
135
+ ]);
123
136
  },
124
137
 
125
138
  async appendModelContent(id: string, parts: Part[]): Promise<void> {
126
- await base.append([{
127
- id,
128
- content: { role: "model", parts },
129
- }]);
139
+ await base.append([
140
+ {
141
+ id,
142
+ content: { role: "model", parts },
143
+ },
144
+ ]);
130
145
  },
131
146
 
132
147
  async appendToolResult(
133
148
  id: string,
134
149
  toolCallId: string,
135
150
  toolName: string,
136
- content: GoogleGenAIToolResponse,
151
+ content: GoogleGenAIToolResponse
137
152
  ): Promise<void> {
138
153
  const parts: Part[] = Array.isArray(content)
139
- ? content as Part[]
140
- : [{
141
- functionResponse: {
142
- id: toolCallId,
143
- name: toolName,
144
- response: toFunctionResponse(content),
154
+ ? (content as Part[])
155
+ : [
156
+ {
157
+ functionResponse: {
158
+ id: toolCallId,
159
+ name: toolName,
160
+ response: toFunctionResponse(content),
161
+ },
145
162
  },
146
- }];
147
-
148
- await base.append([{
149
- id,
150
- content: { role: "user", parts },
151
- }]);
163
+ ];
164
+
165
+ await base.append([
166
+ {
167
+ id,
168
+ content: { role: "user", parts },
169
+ },
170
+ ]);
152
171
  },
153
172
 
154
173
  async prepareForInvocation(): Promise<GoogleGenAIInvocationPayload> {
@@ -174,7 +193,9 @@ export function createGoogleGenAIThreadManager(
174
193
  contents: onPreparedMessage
175
194
  ? contents.map((msg, i) => onPreparedMessage(msg, i, contents))
176
195
  : contents,
177
- ...(systemInstruction && systemInstruction.length > 0 ? { systemInstruction } : {}),
196
+ ...(systemInstruction && systemInstruction.length > 0
197
+ ? { systemInstruction }
198
+ : {}),
178
199
  };
179
200
  },
180
201
  };