The best way to control Claude Code, Codex and more from any computer or phone

main
ts 118 lines 4.18 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as aiplatform from "@distilled.cloud/gcp/aiplatform_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (name: string) =>
15 aiplatform.getProjectsLocationsReasoningEnginesMemories({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("2 seconds"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsReasoningEnginesMemories on a missing memory fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30 yield* stack.destroy();
31
32 const error = yield* Effect.flip(
33 aiplatform.getProjectsLocationsReasoningEnginesMemories({
34 name: `projects/${project}/locations/us-central1/reasoningEngines/1234567890123456789/memories/1234567890123456789`,
35 }),
36 );
37 expect(error._tag).toEqual("NotFound");
38
39 yield* stack.destroy();
40 }).pipe(logLevel),
41 {
42 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
43 timeout: 90_000,
44 },
45 );
46
47 test.provider(
48 "create, update, and delete a reasoning engine memory",
49 (stack) =>
50 Effect.gen(function* () {
51 yield* stack.destroy();
52
53 const created = yield* stack.deploy(
54 Effect.gen(function* () {
55 const engine = yield* GCP.AIPlatform.ReasoningEngine("Agent", {
56 location: "us-central1",
57 displayName: "alchemy-memory-engine",
58 description: "test",
59 labels: { env: "test" },
60 spec: { agentFramework: "custom" },
61 });
62 const memory = yield* GCP.AIPlatform.ReasoningEnginesMemory("Pref", {
63 reasoningEngine: engine.name,
64 location: "us-central1",
65 scope: { user_id: "alchemy-user" },
66 fact: "the user prefers concise answers",
67 displayName: "user-pref",
68 description: "first",
69 });
70 return { engine, memory };
71 }),
72 );
73
74 expect(created.memory.name).toContain("/memories/");
75 expect(created.memory.reasoningEngine).toEqual(created.engine.name);
76 expect(created.memory.fact).toEqual("the user prefers concise answers");
77
78 const fetched = yield* aiplatform.getProjectsLocationsReasoningEnginesMemories({
79 name: created.memory.name,
80 });
81 expect(fetched.name).toEqual(created.memory.name);
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 const engine = yield* GCP.AIPlatform.ReasoningEngine("Agent", {
86 reasoningEngineId: created.engine.reasoningEngineId,
87 location: "us-central1",
88 displayName: "alchemy-memory-engine",
89 description: "test",
90 labels: { env: "test" },
91 spec: { agentFramework: "custom" },
92 });
93 const memory = yield* GCP.AIPlatform.ReasoningEnginesMemory("Pref", {
94 reasoningEngine: engine.name,
95 memoryId: created.memory.memoryId,
96 location: "us-central1",
97 scope: { user_id: "alchemy-user" },
98 fact: "the user prefers detailed answers",
99 displayName: "user-pref",
100 description: "second",
101 });
102 return { engine, memory };
103 }),
104 );
105
106 expect(updated.memory.name).toEqual(created.memory.name);
107 expect(updated.memory.fact).toEqual("the user prefers detailed answers");
108 expect(updated.memory.description).toEqual("second");
109
110 yield* stack.destroy();
111 const gone = yield* waitUntilGone(created.memory.name);
112 expect(gone).toEqual("gone");
113 }).pipe(logLevel),
114 {
115 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
116 timeout: 180_000,
117 },
118 );