zeitlich 0.2.49 → 0.2.51
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 +26 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +3 -3
- package/dist/adapters/sandbox/daytona/index.d.ts +3 -3
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +2 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +2 -2
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/index.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.ts +1 -1
- package/dist/adapters/thread/anthropic/index.cjs +60 -55
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +20 -15
- package/dist/adapters/thread/anthropic/index.d.ts +20 -15
- package/dist/adapters/thread/anthropic/index.js +60 -55
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +7 -7
- package/dist/adapters/thread/anthropic/workflow.d.ts +7 -7
- package/dist/adapters/thread/google-genai/index.cjs +135 -66
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +200 -26
- package/dist/adapters/thread/google-genai/index.d.ts +200 -26
- package/dist/adapters/thread/google-genai/index.js +135 -66
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +8 -8
- package/dist/adapters/thread/google-genai/workflow.d.ts +8 -8
- package/dist/adapters/thread/langchain/index.cjs +67 -55
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +20 -15
- package/dist/adapters/thread/langchain/index.d.ts +20 -15
- package/dist/adapters/thread/langchain/index.js +67 -55
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +7 -7
- package/dist/adapters/thread/langchain/workflow.d.ts +7 -7
- package/dist/{cold-store-DKMAO1Dd.d.ts → cold-store-DyHodfAB.d.ts} +1 -1
- package/dist/{cold-store-CkWoNtMh.d.cts → cold-store-YOx9nmgR.d.cts} +1 -1
- package/dist/index.cjs +15050 -420
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -83
- package/dist/index.d.ts +79 -83
- package/dist/index.js +15051 -417
- package/dist/index.js.map +1 -1
- package/dist/{proxy-B7CWEV-T.d.cts → proxy-2htgGQrc.d.cts} +1 -1
- package/dist/{proxy-ByFHMVRX.d.ts → proxy-CmiTP4pp.d.ts} +1 -1
- package/dist/{thread-manager-nK-WcFzM.d.ts → thread-manager-BJ5pz5Cx.d.cts} +6 -7
- package/dist/{thread-manager-7AW4rhfu.d.ts → thread-manager-BQAbrYXH.d.cts} +6 -7
- package/dist/{thread-manager-Cibe0X5m.d.cts → thread-manager-CcvltOuq.d.ts} +6 -7
- package/dist/{thread-manager-B9rtMEVn.d.cts → thread-manager-DHAbncHX.d.ts} +6 -7
- package/dist/{types-gVa5XCWD.d.ts → types-BQvXWcft.d.ts} +1 -1
- package/dist/{types-XUUFvrJ9.d.cts → types-BjdqxKYp.d.cts} +709 -709
- package/dist/{types-CJ7tCdl6.d.ts → types-D8W5TnSa.d.cts} +3 -3
- package/dist/{types-CJ7tCdl6.d.cts → types-D8W5TnSa.d.ts} +3 -3
- package/dist/{types-DO4Tkwxo.d.ts → types-DEbkLA06.d.ts} +3 -3
- package/dist/{types-DeVNWqlb.d.ts → types-DiI7mZhI.d.ts} +709 -709
- package/dist/{types-BR-k7h0e.d.cts → types-N_LTWe4b.d.cts} +3 -3
- package/dist/{types-CjY93AWZ.d.cts → types-OEN1xrFg.d.cts} +1 -1
- package/dist/{workflow-uhOIj9D-.d.ts → workflow-CcgD6EUB.d.cts} +34 -3
- package/dist/{workflow-KbGsxpfh.d.cts → workflow-DBjPOKBr.d.ts} +34 -3
- package/dist/workflow.cjs +15008 -377
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3 -3
- package/dist/workflow.d.ts +3 -3
- package/dist/workflow.js +15009 -374
- package/dist/workflow.js.map +1 -1
- package/package.json +10 -37
- package/src/adapters/thread/anthropic/activities.test.ts +115 -0
- package/src/adapters/thread/anthropic/activities.ts +11 -19
- package/src/adapters/thread/anthropic/fork-transform.test.ts +17 -11
- package/src/adapters/thread/anthropic/model-invoker.test.ts +54 -3
- package/src/adapters/thread/anthropic/model-invoker.ts +11 -1
- package/src/adapters/thread/anthropic/thread-manager.test.ts +2 -2
- package/src/adapters/thread/anthropic/thread-manager.ts +3 -4
- package/src/adapters/thread/google-genai/activities.test.ts +162 -0
- package/src/adapters/thread/google-genai/activities.ts +38 -15
- package/src/adapters/thread/google-genai/fork-transform.test.ts +17 -11
- package/src/adapters/thread/google-genai/model-invoker.test.ts +386 -0
- package/src/adapters/thread/google-genai/model-invoker.ts +118 -23
- package/src/adapters/thread/google-genai/thread-manager.test.ts +2 -2
- package/src/adapters/thread/google-genai/thread-manager.ts +3 -4
- package/src/adapters/thread/langchain/activities.test.ts +88 -0
- package/src/adapters/thread/langchain/activities.ts +15 -12
- package/src/adapters/thread/langchain/fork-transform.test.ts +17 -11
- package/src/adapters/thread/langchain/model-invoker.test.ts +74 -0
- package/src/adapters/thread/langchain/model-invoker.ts +16 -3
- package/src/adapters/thread/langchain/thread-manager.test.ts +2 -2
- package/src/adapters/thread/langchain/thread-manager.ts +3 -4
- package/src/index.ts +2 -2
- package/src/lib/sandbox/capability-types.test.ts +2 -2
- package/src/lib/sandbox/manager.ts +2 -6
- package/src/lib/sandbox/sandbox.test.ts +1 -1
- package/src/lib/sandbox/types.ts +2 -2
- package/src/lib/session/session.integration.test.ts +92 -0
- package/src/lib/session/session.ts +23 -11
- package/src/lib/thread/keys.test.ts +9 -9
- package/src/lib/thread/keys.ts +1 -1
- package/src/lib/thread/manager.test.ts +24 -14
- package/src/lib/thread/manager.ts +19 -23
- package/src/lib/thread/snapshot.test.ts +51 -43
- package/src/lib/thread/snapshot.ts +54 -32
- package/src/lib/thread/test-utils.ts +106 -59
- package/src/lib/thread/tiered.test.ts +1 -1
- package/src/lib/thread/types.ts +2 -2
- package/src/lib/tool-router/router.integration.test.ts +44 -0
- package/src/lib/tool-router/router.ts +140 -32
- package/src/lib/workflow.ts +49 -0
- package/src/{adapters/sandbox/inmemory/proxy.ts → test-utils/in-memory-sandbox-proxy.ts} +5 -16
- package/src/{adapters/sandbox/inmemory/index.ts → test-utils/in-memory-sandbox.ts} +11 -3
- package/src/tools/bash/bash.test.ts +1 -1
- package/src/tools/edit/handler.test.ts +1 -1
- package/tsup.config.ts +2 -4
- package/dist/activities-7OcT_vdR.d.cts +0 -162
- package/dist/activities-zG_FBoY2.d.ts +0 -162
- package/dist/adapters/sandbox/inmemory/index.cjs +0 -214
- package/dist/adapters/sandbox/inmemory/index.cjs.map +0 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +0 -40
- package/dist/adapters/sandbox/inmemory/index.d.ts +0 -40
- package/dist/adapters/sandbox/inmemory/index.js +0 -211
- package/dist/adapters/sandbox/inmemory/index.js.map +0 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs +0 -36
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +0 -27
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +0 -27
- package/dist/adapters/sandbox/inmemory/workflow.js +0 -34
- package/dist/adapters/sandbox/inmemory/workflow.js.map +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import type { GenerateContentResponse, Part } from "@google/genai";
|
|
3
|
+
import { createGoogleGenAIAdapter } from "./activities";
|
|
4
|
+
import type { StoredContent } from "./thread-manager";
|
|
5
|
+
import { THREAD_TTL_SECONDS } from "../../../lib/thread/keys";
|
|
6
|
+
|
|
7
|
+
function createMockRedis(stored: StoredContent[]) {
|
|
8
|
+
return {
|
|
9
|
+
exists: vi.fn().mockResolvedValue(1),
|
|
10
|
+
lRange: vi.fn().mockResolvedValue(stored.map((m) => JSON.stringify(m))),
|
|
11
|
+
lTrim: vi.fn().mockResolvedValue("OK"),
|
|
12
|
+
get: vi.fn().mockResolvedValue(null),
|
|
13
|
+
del: vi.fn().mockResolvedValue(1),
|
|
14
|
+
set: vi.fn().mockResolvedValue("OK"),
|
|
15
|
+
rPush: vi.fn().mockResolvedValue(1),
|
|
16
|
+
expire: vi.fn().mockResolvedValue(1),
|
|
17
|
+
eval: vi.fn().mockResolvedValue(1),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createMockClient(parts: Part[] = [{ text: "ok" }]) {
|
|
22
|
+
const chunk: Partial<GenerateContentResponse> = {
|
|
23
|
+
candidates: [{ content: { role: "model", parts } }],
|
|
24
|
+
usageMetadata: { promptTokenCount: 10, candidatesTokenCount: 5 },
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
models: {
|
|
28
|
+
generateContentStream: vi.fn().mockResolvedValue({
|
|
29
|
+
async *[Symbol.asyncIterator]() {
|
|
30
|
+
yield chunk;
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
caches: {
|
|
35
|
+
create: vi.fn().mockResolvedValue({ name: "cached-content-ref" }),
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Tail stored under the `assistantMessageId`, so the invoker's
|
|
41
|
+
// `truncateFromId` trims it and re-stamps the surviving list key's TTL.
|
|
42
|
+
const retriedThread: StoredContent[] = [
|
|
43
|
+
{ id: "msg-1", content: { role: "user", parts: [{ text: "hi" }] } },
|
|
44
|
+
{ id: "assistant-1", content: { role: "model", parts: [{ text: "prior" }] } },
|
|
45
|
+
];
|
|
46
|
+
const listKey = "messages:thread:thread-1";
|
|
47
|
+
const metaKey = "messages:meta:thread:thread-1";
|
|
48
|
+
const invokerCall = {
|
|
49
|
+
threadId: "thread-1",
|
|
50
|
+
assistantMessageId: "assistant-1",
|
|
51
|
+
state: { tools: [] } as never,
|
|
52
|
+
agentName: "TestAgent",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
describe("createGoogleGenAIAdapter — TTL propagation", () => {
|
|
56
|
+
it("forwards adapter ttlSeconds to a created invoker's writes", async () => {
|
|
57
|
+
const redis = createMockRedis(retriedThread);
|
|
58
|
+
const client = createMockClient();
|
|
59
|
+
const adapter = createGoogleGenAIAdapter({
|
|
60
|
+
redis: redis as never,
|
|
61
|
+
ttlSeconds: 3600,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
await adapter.createModelInvoker(
|
|
65
|
+
"gemini-2.5-flash",
|
|
66
|
+
client as never
|
|
67
|
+
)(invokerCall);
|
|
68
|
+
|
|
69
|
+
expect(redis.expire).toHaveBeenCalledWith(listKey, 3600);
|
|
70
|
+
expect(redis.expire).not.toHaveBeenCalledWith(listKey, THREAD_TTL_SECONDS);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("forwards adapter ttlSeconds to the default invoker", async () => {
|
|
74
|
+
const redis = createMockRedis(retriedThread);
|
|
75
|
+
const client = createMockClient();
|
|
76
|
+
const adapter = createGoogleGenAIAdapter({
|
|
77
|
+
redis: redis as never,
|
|
78
|
+
client: client as never,
|
|
79
|
+
model: "gemini-2.5-flash",
|
|
80
|
+
ttlSeconds: 3600,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await adapter.invoker(invokerCall);
|
|
84
|
+
|
|
85
|
+
expect(redis.expire).toHaveBeenCalledWith(listKey, 3600);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("forwards adapter ttlSeconds to thread-op writes", async () => {
|
|
89
|
+
const redis = createMockRedis([]);
|
|
90
|
+
const adapter = createGoogleGenAIAdapter({
|
|
91
|
+
redis: redis as never,
|
|
92
|
+
ttlSeconds: 3600,
|
|
93
|
+
});
|
|
94
|
+
const acts = adapter.createActivities() as unknown as Record<
|
|
95
|
+
string,
|
|
96
|
+
(threadId: string, threadKey?: string) => Promise<void>
|
|
97
|
+
>;
|
|
98
|
+
const initialize = Object.entries(acts).find(([k]) =>
|
|
99
|
+
k.endsWith("InitializeThread")
|
|
100
|
+
)?.[1];
|
|
101
|
+
if (!initialize) throw new Error("initializeThread activity not found");
|
|
102
|
+
|
|
103
|
+
await initialize("thread-1");
|
|
104
|
+
|
|
105
|
+
expect(redis.set).toHaveBeenCalledWith(metaKey, "1", { EX: 3600 });
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("defaults to THREAD_TTL_SECONDS when adapter ttlSeconds is omitted", async () => {
|
|
109
|
+
const redis = createMockRedis(retriedThread);
|
|
110
|
+
const client = createMockClient();
|
|
111
|
+
const adapter = createGoogleGenAIAdapter({ redis: redis as never });
|
|
112
|
+
|
|
113
|
+
await adapter.createModelInvoker(
|
|
114
|
+
"gemini-2.5-flash",
|
|
115
|
+
client as never
|
|
116
|
+
)(invokerCall);
|
|
117
|
+
|
|
118
|
+
expect(redis.expire).toHaveBeenCalledWith(listKey, THREAD_TTL_SECONDS);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("createGoogleGenAIAdapter — cache/config forwarding", () => {
|
|
123
|
+
it("forwards adapter cache config to the invoker", async () => {
|
|
124
|
+
const multiThread: StoredContent[] = [
|
|
125
|
+
{ id: "m1", content: { role: "user", parts: [{ text: "a" }] } },
|
|
126
|
+
{ id: "m2", content: { role: "model", parts: [{ text: "b" }] } },
|
|
127
|
+
{ id: "m3", content: { role: "user", parts: [{ text: "c" }] } },
|
|
128
|
+
];
|
|
129
|
+
const redis = createMockRedis(multiThread);
|
|
130
|
+
const client = createMockClient();
|
|
131
|
+
const adapter = createGoogleGenAIAdapter({
|
|
132
|
+
redis: redis as never,
|
|
133
|
+
cache: { splitIndex: 1 },
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
await adapter.createModelInvoker(
|
|
137
|
+
"gemini-2.5-flash",
|
|
138
|
+
client as never
|
|
139
|
+
)(invokerCall);
|
|
140
|
+
|
|
141
|
+
expect(client.caches.create).toHaveBeenCalledOnce();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("forwards adapter generationConfig to generateContentStream", async () => {
|
|
145
|
+
const redis = createMockRedis([
|
|
146
|
+
{ id: "m1", content: { role: "user", parts: [{ text: "a" }] } },
|
|
147
|
+
]);
|
|
148
|
+
const client = createMockClient();
|
|
149
|
+
const adapter = createGoogleGenAIAdapter({
|
|
150
|
+
redis: redis as never,
|
|
151
|
+
generationConfig: { temperature: 0.5 },
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await adapter.createModelInvoker(
|
|
155
|
+
"gemini-2.5-flash",
|
|
156
|
+
client as never
|
|
157
|
+
)(invokerCall);
|
|
158
|
+
|
|
159
|
+
const streamCall = client.models.generateContentStream.mock.calls[0]?.[0];
|
|
160
|
+
expect(streamCall.config.temperature).toBe(0.5);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type Redis from "
|
|
2
|
-
import type {
|
|
1
|
+
import type { RedisClientType as Redis } from "redis";
|
|
2
|
+
import type {
|
|
3
|
+
GoogleGenAI,
|
|
4
|
+
Content,
|
|
5
|
+
Part,
|
|
6
|
+
GenerateContentConfig,
|
|
7
|
+
} from "@google/genai";
|
|
3
8
|
import type { ToolResultConfig } from "../../../lib/types";
|
|
4
9
|
import type { PersistedThreadState } from "../../../lib/state/types";
|
|
5
10
|
import type {
|
|
@@ -23,7 +28,10 @@ import {
|
|
|
23
28
|
type GoogleGenAIThreadManagerHooks,
|
|
24
29
|
type StoredContent,
|
|
25
30
|
} from "./thread-manager";
|
|
26
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
createGoogleGenAIModelInvoker,
|
|
33
|
+
type GoogleGenAIModelInvokerConfig,
|
|
34
|
+
} from "./model-invoker";
|
|
27
35
|
import { ADAPTER_ID } from "./adapter-id";
|
|
28
36
|
|
|
29
37
|
export type GoogleGenAIThreadOps<TScope extends string = ""> =
|
|
@@ -46,11 +54,22 @@ export interface GoogleGenAIAdapterConfig {
|
|
|
46
54
|
*/
|
|
47
55
|
coldStore?: ColdThreadStore;
|
|
48
56
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* more appropriate.
|
|
57
|
+
* Redis TTL for the thread's keys; defaults to 90 days. Use a shorter
|
|
58
|
+
* value (hours) with a cold tier.
|
|
52
59
|
*/
|
|
53
60
|
ttlSeconds?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Default generation config forwarded to every invoker the adapter
|
|
63
|
+
* builds (`invoker` and `createModelInvoker`). `systemInstruction`,
|
|
64
|
+
* `tools`, and `abortSignal` are managed by the invoker and override
|
|
65
|
+
* any values set here.
|
|
66
|
+
*/
|
|
67
|
+
generationConfig?: GenerateContentConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Default server-side context caching config forwarded to every
|
|
70
|
+
* invoker the adapter builds. See {@link createGoogleGenAIModelInvoker}.
|
|
71
|
+
*/
|
|
72
|
+
cache?: GoogleGenAIModelInvokerConfig["cache"];
|
|
54
73
|
}
|
|
55
74
|
|
|
56
75
|
/**
|
|
@@ -145,7 +164,7 @@ export interface GoogleGenAIAdapter {
|
|
|
145
164
|
* ...createRunAgentActivity(temporalClient, adapter.invoker, "codingAgent"),
|
|
146
165
|
* ...createRunAgentActivity(
|
|
147
166
|
* temporalClient,
|
|
148
|
-
* adapter.createModelInvoker('gemini-2.5-pro'),
|
|
167
|
+
* adapter.createModelInvoker('gemini-2.5-pro', client),
|
|
149
168
|
* "researchAgent",
|
|
150
169
|
* ),
|
|
151
170
|
* };
|
|
@@ -157,25 +176,26 @@ export function createGoogleGenAIAdapter(
|
|
|
157
176
|
): GoogleGenAIAdapter {
|
|
158
177
|
const { redis } = config;
|
|
159
178
|
|
|
160
|
-
|
|
179
|
+
// Single source for the adapter's `redis` handle and configured TTL, spread
|
|
180
|
+
// into every internal thread manager so all of them share one configuration.
|
|
181
|
+
const base = {
|
|
182
|
+
redis,
|
|
161
183
|
...(config.ttlSeconds !== undefined && { ttlSeconds: config.ttlSeconds }),
|
|
162
184
|
};
|
|
163
185
|
|
|
164
186
|
const makeProviderThread = (threadId: string, threadKey?: string) =>
|
|
165
187
|
createGoogleGenAIThreadManager({
|
|
166
|
-
|
|
188
|
+
...base,
|
|
167
189
|
threadId,
|
|
168
190
|
key: threadKey,
|
|
169
|
-
...baseExtras,
|
|
170
191
|
});
|
|
171
192
|
|
|
172
193
|
const makeTieredBase = (threadId: string, threadKey?: string) =>
|
|
173
194
|
createTieredThreadManager<StoredContent>({
|
|
174
|
-
|
|
195
|
+
...base,
|
|
175
196
|
threadId,
|
|
176
197
|
key: threadKey,
|
|
177
198
|
idOf: storedContentId,
|
|
178
|
-
...baseExtras,
|
|
179
199
|
...(config.coldStore && { coldStore: config.coldStore }),
|
|
180
200
|
});
|
|
181
201
|
|
|
@@ -235,11 +255,10 @@ export function createGoogleGenAIAdapter(
|
|
|
235
255
|
threadKey?: string
|
|
236
256
|
): Promise<void> {
|
|
237
257
|
const thread = createGoogleGenAIThreadManager({
|
|
238
|
-
|
|
258
|
+
...base,
|
|
239
259
|
threadId: sourceThreadId,
|
|
240
260
|
key: threadKey,
|
|
241
261
|
hooks: config.hooks,
|
|
242
|
-
...baseExtras,
|
|
243
262
|
});
|
|
244
263
|
await thread.fork(targetThreadId);
|
|
245
264
|
},
|
|
@@ -304,10 +323,14 @@ export function createGoogleGenAIAdapter(
|
|
|
304
323
|
client: GoogleGenAI
|
|
305
324
|
): ModelInvoker<Content> =>
|
|
306
325
|
createGoogleGenAIModelInvoker({
|
|
307
|
-
|
|
326
|
+
...base,
|
|
308
327
|
client,
|
|
309
328
|
model,
|
|
310
329
|
hooks: config.hooks,
|
|
330
|
+
...(config.generationConfig !== undefined && {
|
|
331
|
+
config: config.generationConfig,
|
|
332
|
+
}),
|
|
333
|
+
...(config.cache !== undefined && { cache: config.cache }),
|
|
311
334
|
});
|
|
312
335
|
|
|
313
336
|
const invoker: ModelInvoker<Content> =
|
|
@@ -7,27 +7,27 @@ function createStatefulRedis() {
|
|
|
7
7
|
const strings = new Map<string, string>();
|
|
8
8
|
|
|
9
9
|
return {
|
|
10
|
-
exists: vi.fn(async (
|
|
11
|
-
keys.reduce(
|
|
10
|
+
exists: vi.fn(async (keys: string | string[]) =>
|
|
11
|
+
(Array.isArray(keys) ? keys : [keys]).reduce(
|
|
12
12
|
(acc, k) => acc + (lists.has(k) || strings.has(k) ? 1 : 0),
|
|
13
13
|
0
|
|
14
14
|
)
|
|
15
15
|
),
|
|
16
|
-
|
|
16
|
+
lRange: vi.fn(async (key: string, start: number, stop: number) => {
|
|
17
17
|
const list = lists.get(key) ?? [];
|
|
18
18
|
const end = stop === -1 ? list.length : stop + 1;
|
|
19
19
|
return list.slice(start, end);
|
|
20
20
|
}),
|
|
21
|
-
|
|
21
|
+
rPush: vi.fn(async (key: string, element: string | string[]) => {
|
|
22
22
|
const list = lists.get(key) ?? [];
|
|
23
|
-
list.push(...
|
|
23
|
+
list.push(...(Array.isArray(element) ? element : [element]));
|
|
24
24
|
lists.set(key, list);
|
|
25
25
|
return list.length;
|
|
26
26
|
}),
|
|
27
|
-
|
|
28
|
-
del: vi.fn(async (
|
|
27
|
+
lTrim: vi.fn(async () => "OK"),
|
|
28
|
+
del: vi.fn(async (keys: string | string[]) => {
|
|
29
29
|
let removed = 0;
|
|
30
|
-
for (const k of keys) {
|
|
30
|
+
for (const k of Array.isArray(keys) ? keys : [keys]) {
|
|
31
31
|
if (lists.delete(k)) removed++;
|
|
32
32
|
if (strings.delete(k)) removed++;
|
|
33
33
|
}
|
|
@@ -39,10 +39,16 @@ function createStatefulRedis() {
|
|
|
39
39
|
}),
|
|
40
40
|
get: vi.fn(async (key: string) => strings.get(key) ?? null),
|
|
41
41
|
expire: vi.fn(async () => 1),
|
|
42
|
-
|
|
42
|
+
lLen: vi.fn(async (key: string) => (lists.get(key) ?? []).length),
|
|
43
43
|
eval: vi.fn(
|
|
44
|
-
async (
|
|
45
|
-
|
|
44
|
+
async (
|
|
45
|
+
_script: string,
|
|
46
|
+
options: { keys?: string[]; arguments?: string[] }
|
|
47
|
+
) => {
|
|
48
|
+
const keys = options.keys ?? [];
|
|
49
|
+
const argv = options.arguments ?? [];
|
|
50
|
+
const [dedupKey, listKey] = keys;
|
|
51
|
+
const serialised = argv.slice(1);
|
|
46
52
|
if (!dedupKey || !listKey) return 0;
|
|
47
53
|
if (strings.has(dedupKey)) return 0;
|
|
48
54
|
const list = lists.get(listKey) ?? [];
|