effect-durable-agent 0.1.0-alpha.1
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/CHANGELOG.md +10 -0
- package/CONTRIBUTING.md +26 -0
- package/LICENSE +21 -0
- package/README.md +305 -0
- package/SECURITY.md +8 -0
- package/dist/command-queues-CQ9cwRP7.d.ts +468 -0
- package/dist/commands-Ce1ec6kH.d.ts +104 -0
- package/dist/compaction-YayFKo_1.d.ts +144 -0
- package/dist/core-Hv3cFydL.d.ts +81 -0
- package/dist/domain/command-queues.d.ts +2 -0
- package/dist/domain/command-queues.js +97 -0
- package/dist/domain/command-queues.js.map +1 -0
- package/dist/domain/message-transcript.d.ts +2 -0
- package/dist/domain/message-transcript.js +111 -0
- package/dist/domain/message-transcript.js.map +1 -0
- package/dist/domain/reduced-state-schema.d.ts +996 -0
- package/dist/domain/reduced-state-schema.js +286 -0
- package/dist/domain/reduced-state-schema.js.map +1 -0
- package/dist/domain/reduced-state.d.ts +2 -0
- package/dist/domain/reduced-state.js +2 -0
- package/dist/durable-C3Rz7kg3.js +625 -0
- package/dist/durable-C3Rz7kg3.js.map +1 -0
- package/dist/durable-DlScwmCy.d.ts +7424 -0
- package/dist/durable-object-runtime-B7jwBY2R.js +1494 -0
- package/dist/durable-object-runtime-B7jwBY2R.js.map +1 -0
- package/dist/durable-object-runtime-pWv0ohlz.d.ts +257 -0
- package/dist/durable-object-storage-Czy7IPrh.d.ts +41 -0
- package/dist/events-Bb9-Cu-7.d.ts +918 -0
- package/dist/host/durable-object-runtime.d.ts +2 -0
- package/dist/host/durable-object-runtime.js +2 -0
- package/dist/host/durable-object-storage.d.ts +2 -0
- package/dist/host/durable-object-storage.js +0 -0
- package/dist/host/durable-object.d.ts +83 -0
- package/dist/host/durable-object.js +191 -0
- package/dist/host/durable-object.js.map +1 -0
- package/dist/host/websocket-wire.d.ts +2 -0
- package/dist/host/websocket-wire.js +88 -0
- package/dist/host/websocket-wire.js.map +1 -0
- package/dist/id-generator-C2Q15uZM.d.ts +33 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/keep-alive-DYDsH6qN.d.ts +111 -0
- package/dist/keep-alive-p8dIcSVy.js +109 -0
- package/dist/keep-alive-p8dIcSVy.js.map +1 -0
- package/dist/message-transcript-BCHdHAe2.d.ts +32 -0
- package/dist/prompt-projector-9_02lk5-.d.ts +40 -0
- package/dist/reduced-state-C4nVVzz9.js +910 -0
- package/dist/reduced-state-C4nVVzz9.js.map +1 -0
- package/dist/reducer-registry-C0svUa63.d.ts +69 -0
- package/dist/runtime-C56FQxiL.d.ts +60 -0
- package/dist/services/compaction.d.ts +2 -0
- package/dist/services/compaction.js +426 -0
- package/dist/services/compaction.js.map +1 -0
- package/dist/services/id-generator.d.ts +2 -0
- package/dist/services/id-generator.js +56 -0
- package/dist/services/id-generator.js.map +1 -0
- package/dist/services/prompt-projector.d.ts +2 -0
- package/dist/services/prompt-projector.js +27 -0
- package/dist/services/prompt-projector.js.map +1 -0
- package/dist/services/reducer-registry.d.ts +2 -0
- package/dist/services/reducer-registry.js +71 -0
- package/dist/services/reducer-registry.js.map +1 -0
- package/dist/services/runtime.d.ts +2 -0
- package/dist/services/runtime.js +84 -0
- package/dist/services/runtime.js.map +1 -0
- package/dist/services/session-query.d.ts +2 -0
- package/dist/services/session-query.js +2 -0
- package/dist/services/session-store.d.ts +2 -0
- package/dist/services/session-store.js +2 -0
- package/dist/services/sink-registry.d.ts +2 -0
- package/dist/services/sink-registry.js +2 -0
- package/dist/services/span-names.d.ts +28 -0
- package/dist/services/span-names.js +42 -0
- package/dist/services/span-names.js.map +1 -0
- package/dist/services/tool-registry.d.ts +2 -0
- package/dist/services/tool-registry.js +46 -0
- package/dist/services/tool-registry.js.map +1 -0
- package/dist/services/tracing.d.ts +76 -0
- package/dist/services/tracing.js +116 -0
- package/dist/services/tracing.js.map +1 -0
- package/dist/session-query-DOc1KanA.js +2930 -0
- package/dist/session-query-DOc1KanA.js.map +1 -0
- package/dist/session-query-DlRo5Ufc.d.ts +769 -0
- package/dist/session-store-D2Ore1QC.d.ts +295 -0
- package/dist/session-store-pYxQW9qh.js +214 -0
- package/dist/session-store-pYxQW9qh.js.map +1 -0
- package/dist/sink-registry-CFC6xjsN.js +312 -0
- package/dist/sink-registry-CFC6xjsN.js.map +1 -0
- package/dist/sink-registry-CIU0LD3m.d.ts +158 -0
- package/dist/testkit/layers.d.ts +101 -0
- package/dist/testkit/layers.js +108 -0
- package/dist/testkit/layers.js.map +1 -0
- package/dist/tool-registry-CcnkAAQK.d.ts +51 -0
- package/dist/tracing-BXHAkxkx.d.ts +111 -0
- package/dist/types/commands.d.ts +2 -0
- package/dist/types/commands.js +60 -0
- package/dist/types/commands.js.map +1 -0
- package/dist/types/core.d.ts +2 -0
- package/dist/types/core.js +68 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/events/durable.d.ts +2 -0
- package/dist/types/events/durable.js +2 -0
- package/dist/types/events.d.ts +4 -0
- package/dist/types/events.js +90 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/tracing.d.ts +2 -0
- package/dist/types/tracing.js +99 -0
- package/dist/types/tracing.js.map +1 -0
- package/dist/websocket-wire-DvOu_6BJ.d.ts +16773 -0
- package/docs/assets/architecture.svg +106 -0
- package/docs/assets/event-sequence.svg +143 -0
- package/docs/assets/gcp-trace.png +0 -0
- package/docs/message-steering.md +831 -0
- package/docs/releasing.md +57 -0
- package/docs/spec.md +774 -0
- package/docs/subagents.md +725 -0
- package/docs/testing.md +64 -0
- package/docs/ui-projection.md +742 -0
- package/docs/websocket-protocol.md +613 -0
- package/examples/001-no-tools/README.md +65 -0
- package/examples/001-no-tools/worker.ts +79 -0
- package/examples/002-slack-bridge/README.md +134 -0
- package/examples/002-slack-bridge/events.ts +115 -0
- package/examples/002-slack-bridge/reducer.ts +216 -0
- package/examples/002-slack-bridge/scenario.test.ts +223 -0
- package/examples/002-slack-bridge/sinks.ts +109 -0
- package/examples/002-slack-bridge/worker.ts +140 -0
- package/examples/003-sandbox-lifecycle/README.md +78 -0
- package/examples/003-sandbox-lifecycle/events.ts +203 -0
- package/examples/003-sandbox-lifecycle/reducer.ts +305 -0
- package/examples/003-sandbox-lifecycle/scenario.test.ts +202 -0
- package/examples/_shared/event-id.ts +12 -0
- package/examples/_shared/http.ts +27 -0
- package/examples/_shared/openai.ts +33 -0
- package/package.json +181 -0
- package/testing/offline-trace/README.md +63 -0
- package/tooling/oxlint/index.mjs +15 -0
- package/tooling/oxlint/rules/effect-span-from-catalog.mjs +152 -0
- package/tooling/oxlint/rules/span-catalog-format.mjs +74 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
|
|
3
|
+
import { IdGenerator } from "../../src/services/id-generator";
|
|
4
|
+
import { EventId } from "../../src/types/core";
|
|
5
|
+
|
|
6
|
+
export const mintExampleEventId = (): Promise<EventId> =>
|
|
7
|
+
Effect.runPromise(
|
|
8
|
+
Effect.gen(function* () {
|
|
9
|
+
const ids = yield* IdGenerator;
|
|
10
|
+
return yield* ids.makeEventId();
|
|
11
|
+
}).pipe(Effect.provide(IdGenerator.Live)),
|
|
12
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const json = (body: unknown, status = 200): Response =>
|
|
2
|
+
Response.json(body, {
|
|
3
|
+
headers: { "Cache-Control": "no-store" },
|
|
4
|
+
status,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export const parseJsonObject = async (request: Request): Promise<Record<string, unknown>> => {
|
|
8
|
+
const body = await request.json().catch(() => undefined);
|
|
9
|
+
return typeof body === "object" && body !== null && !Array.isArray(body)
|
|
10
|
+
? (body as Record<string, unknown>)
|
|
11
|
+
: {};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const requiredString = (body: Record<string, unknown>, key: string): string | undefined => {
|
|
15
|
+
const value = body[key];
|
|
16
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const optionalString = (value: string | undefined): string | undefined => {
|
|
20
|
+
const trimmed = value?.trim();
|
|
21
|
+
return trimmed === undefined || trimmed.length === 0 ? undefined : trimmed;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const pathParam = (pathname: string, pattern: RegExp): string | null => {
|
|
25
|
+
const match = pattern.exec(pathname);
|
|
26
|
+
return match === null ? null : decodeURIComponent(match[1]!);
|
|
27
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
edaRuntimeConfig,
|
|
3
|
+
type EDASessionDurableObjectOptions,
|
|
4
|
+
} from "../../src/host/durable-object";
|
|
5
|
+
import { makeEDADurableObjectOpenAiModelLayer } from "../../src/host/durable-object-runtime";
|
|
6
|
+
import { optionalString } from "./http";
|
|
7
|
+
|
|
8
|
+
export const EXAMPLE_DEFAULT_MODEL_ID = "gpt-4.1-mini";
|
|
9
|
+
|
|
10
|
+
export interface ExampleOpenAiEnv {
|
|
11
|
+
readonly EDA_OPENAI_API_URL?: string;
|
|
12
|
+
readonly EDA_OPENAI_MODEL?: string;
|
|
13
|
+
readonly EDA_SYSTEM_PROMPT?: string;
|
|
14
|
+
readonly OPENAI_API_KEY?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const makeExampleOpenAiOptions = (
|
|
18
|
+
env: ExampleOpenAiEnv,
|
|
19
|
+
): Pick<EDASessionDurableObjectOptions, "config" | "modelLayer"> => {
|
|
20
|
+
const modelId = optionalString(env.EDA_OPENAI_MODEL) ?? EXAMPLE_DEFAULT_MODEL_ID;
|
|
21
|
+
return {
|
|
22
|
+
config: edaRuntimeConfig({
|
|
23
|
+
modelId,
|
|
24
|
+
provider: "openai",
|
|
25
|
+
systemPrompt: optionalString(env.EDA_SYSTEM_PROMPT),
|
|
26
|
+
}),
|
|
27
|
+
modelLayer: makeEDADurableObjectOpenAiModelLayer({
|
|
28
|
+
apiKey: optionalString(env.OPENAI_API_KEY),
|
|
29
|
+
apiUrl: optionalString(env.EDA_OPENAI_API_URL),
|
|
30
|
+
modelId,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "effect-durable-agent",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "A Redux-inspired state-management and durable execution layer for agentic applications on Cloudflare Durable Objects.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agents",
|
|
7
|
+
"cloudflare",
|
|
8
|
+
"durable-objects",
|
|
9
|
+
"effect",
|
|
10
|
+
"event-sourcing",
|
|
11
|
+
"state-machine"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/advait/effect-durable-agent#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/advait/effect-durable-agent/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/advait/effect-durable-agent.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Advait Shinde",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"packageManager": "pnpm@10.33.2",
|
|
28
|
+
"files": [
|
|
29
|
+
"CHANGELOG.md",
|
|
30
|
+
"CONTRIBUTING.md",
|
|
31
|
+
"SECURITY.md",
|
|
32
|
+
"dist",
|
|
33
|
+
"docs",
|
|
34
|
+
"examples",
|
|
35
|
+
"testing/offline-trace/README.md",
|
|
36
|
+
"tooling/oxlint/index.mjs",
|
|
37
|
+
"tooling/oxlint/rules/*.mjs"
|
|
38
|
+
],
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/index.d.ts",
|
|
42
|
+
"import": "./dist/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./domain/command-queues": {
|
|
45
|
+
"types": "./dist/domain/command-queues.d.ts",
|
|
46
|
+
"import": "./dist/domain/command-queues.js"
|
|
47
|
+
},
|
|
48
|
+
"./domain/message-transcript": {
|
|
49
|
+
"types": "./dist/domain/message-transcript.d.ts",
|
|
50
|
+
"import": "./dist/domain/message-transcript.js"
|
|
51
|
+
},
|
|
52
|
+
"./domain/reduced-state": {
|
|
53
|
+
"types": "./dist/domain/reduced-state.d.ts",
|
|
54
|
+
"import": "./dist/domain/reduced-state.js"
|
|
55
|
+
},
|
|
56
|
+
"./domain/reduced-state-schema": {
|
|
57
|
+
"types": "./dist/domain/reduced-state-schema.d.ts",
|
|
58
|
+
"import": "./dist/domain/reduced-state-schema.js"
|
|
59
|
+
},
|
|
60
|
+
"./host/durable-object": {
|
|
61
|
+
"types": "./dist/host/durable-object.d.ts",
|
|
62
|
+
"import": "./dist/host/durable-object.js"
|
|
63
|
+
},
|
|
64
|
+
"./host/durable-object-runtime": {
|
|
65
|
+
"types": "./dist/host/durable-object-runtime.d.ts",
|
|
66
|
+
"import": "./dist/host/durable-object-runtime.js"
|
|
67
|
+
},
|
|
68
|
+
"./host/durable-object-storage": {
|
|
69
|
+
"types": "./dist/host/durable-object-storage.d.ts",
|
|
70
|
+
"import": "./dist/host/durable-object-storage.js"
|
|
71
|
+
},
|
|
72
|
+
"./host/websocket-wire": {
|
|
73
|
+
"types": "./dist/host/websocket-wire.d.ts",
|
|
74
|
+
"import": "./dist/host/websocket-wire.js"
|
|
75
|
+
},
|
|
76
|
+
"./services/compaction": {
|
|
77
|
+
"types": "./dist/services/compaction.d.ts",
|
|
78
|
+
"import": "./dist/services/compaction.js"
|
|
79
|
+
},
|
|
80
|
+
"./services/id-generator": {
|
|
81
|
+
"types": "./dist/services/id-generator.d.ts",
|
|
82
|
+
"import": "./dist/services/id-generator.js"
|
|
83
|
+
},
|
|
84
|
+
"./services/prompt-projector": {
|
|
85
|
+
"types": "./dist/services/prompt-projector.d.ts",
|
|
86
|
+
"import": "./dist/services/prompt-projector.js"
|
|
87
|
+
},
|
|
88
|
+
"./services/reducer-registry": {
|
|
89
|
+
"types": "./dist/services/reducer-registry.d.ts",
|
|
90
|
+
"import": "./dist/services/reducer-registry.js"
|
|
91
|
+
},
|
|
92
|
+
"./services/runtime": {
|
|
93
|
+
"types": "./dist/services/runtime.d.ts",
|
|
94
|
+
"import": "./dist/services/runtime.js"
|
|
95
|
+
},
|
|
96
|
+
"./services/session-query": {
|
|
97
|
+
"types": "./dist/services/session-query.d.ts",
|
|
98
|
+
"import": "./dist/services/session-query.js"
|
|
99
|
+
},
|
|
100
|
+
"./services/session-store": {
|
|
101
|
+
"types": "./dist/services/session-store.d.ts",
|
|
102
|
+
"import": "./dist/services/session-store.js"
|
|
103
|
+
},
|
|
104
|
+
"./services/sink-registry": {
|
|
105
|
+
"types": "./dist/services/sink-registry.d.ts",
|
|
106
|
+
"import": "./dist/services/sink-registry.js"
|
|
107
|
+
},
|
|
108
|
+
"./services/span-names": {
|
|
109
|
+
"types": "./dist/services/span-names.d.ts",
|
|
110
|
+
"import": "./dist/services/span-names.js"
|
|
111
|
+
},
|
|
112
|
+
"./services/tool-registry": {
|
|
113
|
+
"types": "./dist/services/tool-registry.d.ts",
|
|
114
|
+
"import": "./dist/services/tool-registry.js"
|
|
115
|
+
},
|
|
116
|
+
"./services/tracing": {
|
|
117
|
+
"types": "./dist/services/tracing.d.ts",
|
|
118
|
+
"import": "./dist/services/tracing.js"
|
|
119
|
+
},
|
|
120
|
+
"./testkit/layers": {
|
|
121
|
+
"types": "./dist/testkit/layers.d.ts",
|
|
122
|
+
"import": "./dist/testkit/layers.js"
|
|
123
|
+
},
|
|
124
|
+
"./tooling/oxlint": "./tooling/oxlint/index.mjs",
|
|
125
|
+
"./types/commands": {
|
|
126
|
+
"types": "./dist/types/commands.d.ts",
|
|
127
|
+
"import": "./dist/types/commands.js"
|
|
128
|
+
},
|
|
129
|
+
"./types/core": {
|
|
130
|
+
"types": "./dist/types/core.d.ts",
|
|
131
|
+
"import": "./dist/types/core.js"
|
|
132
|
+
},
|
|
133
|
+
"./types/events": {
|
|
134
|
+
"types": "./dist/types/events.d.ts",
|
|
135
|
+
"import": "./dist/types/events.js"
|
|
136
|
+
},
|
|
137
|
+
"./types/events/durable": {
|
|
138
|
+
"types": "./dist/types/events/durable.d.ts",
|
|
139
|
+
"import": "./dist/types/events/durable.js"
|
|
140
|
+
},
|
|
141
|
+
"./types/tracing": {
|
|
142
|
+
"types": "./dist/types/tracing.d.ts",
|
|
143
|
+
"import": "./dist/types/tracing.js"
|
|
144
|
+
},
|
|
145
|
+
"./package.json": "./package.json"
|
|
146
|
+
},
|
|
147
|
+
"scripts": {
|
|
148
|
+
"build": "vp pack",
|
|
149
|
+
"check": "pnpm run lint && pnpm run typecheck",
|
|
150
|
+
"ci": "pnpm run check && pnpm run test",
|
|
151
|
+
"lint": "vp fmt --check && vp lint",
|
|
152
|
+
"lint:fix": "vp fmt && vp lint --fix",
|
|
153
|
+
"package:check": "node scripts/check-package.mjs",
|
|
154
|
+
"prepack": "pnpm run build",
|
|
155
|
+
"release:check": "pnpm run ci && pnpm run build && pnpm run package:check",
|
|
156
|
+
"test": "vp test run --passWithNoTests",
|
|
157
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
158
|
+
},
|
|
159
|
+
"publishConfig": {
|
|
160
|
+
"access": "public",
|
|
161
|
+
"registry": "https://registry.npmjs.org/",
|
|
162
|
+
"tag": "alpha"
|
|
163
|
+
},
|
|
164
|
+
"peerDependencies": {
|
|
165
|
+
"@effect/ai-openai": "4.0.0-beta.102",
|
|
166
|
+
"effect": "4.0.0-beta.102"
|
|
167
|
+
},
|
|
168
|
+
"devDependencies": {
|
|
169
|
+
"@cloudflare/workers-types": "5.20260727.1",
|
|
170
|
+
"@effect/ai-openai": "4.0.0-beta.102",
|
|
171
|
+
"@types/node": "^25.7.0",
|
|
172
|
+
"effect": "4.0.0-beta.102",
|
|
173
|
+
"fast-check": "^4.8.0",
|
|
174
|
+
"oxlint": "1.63.0",
|
|
175
|
+
"publint": "^0.3.22",
|
|
176
|
+
"tsx": "4.21.0",
|
|
177
|
+
"typescript": "^6.0.3",
|
|
178
|
+
"vite-plus": "^0.1.21",
|
|
179
|
+
"vitest": "^4.1.8"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# EDA offline trace harness
|
|
2
|
+
|
|
3
|
+
This folder contains the non-Cloudflare, non-web integration harness for
|
|
4
|
+
`effect-durable-agent`. All EDA-specific harness code stays inside this package so the runtime
|
|
5
|
+
remains self-contained.
|
|
6
|
+
|
|
7
|
+
## Run a real OpenAI trace
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
OPENAI_API_KEY=... pnpm exec tsx testing/offline-trace/node/run.ts \
|
|
11
|
+
--scenario no-tools \
|
|
12
|
+
--out .eda-traces/no-tools-001
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Optional flags:
|
|
16
|
+
|
|
17
|
+
- `--scenario no-tools | multi-turn | prefix-cache | framework-tool | parallel-tools | rejected-tool`
|
|
18
|
+
- `--model <model-id>` (defaults to `EDA_OPENAI_MODEL` or `gpt-4.1-mini`)
|
|
19
|
+
- `--out <directory>`
|
|
20
|
+
|
|
21
|
+
If `OPENAI_API_KEY` is absent, the CLI writes a blocked report (`blocked.json` and `summary.md`) instead of pretending a real model run occurred.
|
|
22
|
+
|
|
23
|
+
## Artifacts
|
|
24
|
+
|
|
25
|
+
A successful run writes:
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
.eda-traces/<run>/
|
|
29
|
+
run.json
|
|
30
|
+
summary.md
|
|
31
|
+
trace.jsonl
|
|
32
|
+
durable-events.jsonl
|
|
33
|
+
live-events.jsonl
|
|
34
|
+
prompts/
|
|
35
|
+
attempt-0.json
|
|
36
|
+
attempt-0.sha256
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- `trace.jsonl` contains `model.request`, `model.part`, `model.finish`, durable/live event, and verification records.
|
|
40
|
+
- `durable-events.jsonl` is the committed replay source.
|
|
41
|
+
- `live-events.jsonl` captures live durable and ephemeral delivery.
|
|
42
|
+
- `prompts/*.json` is the canonical model-facing prompt message array.
|
|
43
|
+
- `prompts/*.sha256` is the stable prompt hash used by prefix verification.
|
|
44
|
+
|
|
45
|
+
## Verification intent
|
|
46
|
+
|
|
47
|
+
The prompt-prefix verifier proves the EDA-side invariant: later prompts preserve earlier model-facing message arrays exactly as a prefix. Cache metrics are reported separately from provider usage; a provider may report zero cache reads even when EDA preserved the prefix correctly.
|
|
48
|
+
|
|
49
|
+
For OpenAI Responses API, the provider cache is sensitive to the wire shape of system messages.
|
|
50
|
+
`@effect/ai-openai` sends `Prompt.SystemMessage` as
|
|
51
|
+
`content: [{ type: "input_text", text }]` instead of a plain string; real `prefix-cache` runs should
|
|
52
|
+
therefore report non-zero cached input tokens once the cache warms.
|
|
53
|
+
|
|
54
|
+
Provider-executed tools remain unsupported in this slice. Framework-owned tools are traced through durable `ToolCallCreated` / `ToolCallStarted` / `ToolCallCompleted` or failure/cancellation events.
|
|
55
|
+
|
|
56
|
+
## Scenario coverage
|
|
57
|
+
|
|
58
|
+
- `no-tools`: one no-tool turn that proves the harness can capture a real provider stream.
|
|
59
|
+
- `multi-turn`: four queued user commands that verify longer transcript continuity and prompt-prefix preservation across follow-up turns.
|
|
60
|
+
- `prefix-cache`: three turns with a large durable system prompt first in provider context, sized above OpenAI's prompt-cache threshold so real runs can report cached input tokens as well as EDA prefix metrics.
|
|
61
|
+
- `framework-tool`: one framework-owned tool call plus continuation from the tool result.
|
|
62
|
+
- `parallel-tools`: two framework-owned tool calls emitted in one model attempt; tests prove both handlers start concurrently while continuation prompts preserve the model's original tool-call/result order.
|
|
63
|
+
- `rejected-tool`: invalid tool parameters, durable rejection, and corrective prompt feedback.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { effectSpanFromCatalog } from "./rules/effect-span-from-catalog.mjs";
|
|
2
|
+
import { spanCatalogFormat } from "./rules/span-catalog-format.mjs";
|
|
3
|
+
|
|
4
|
+
/** Deterministic Effect span conventions that travel with effect-durable-agent. */
|
|
5
|
+
const plugin = {
|
|
6
|
+
meta: {
|
|
7
|
+
name: "effect-durable-agent",
|
|
8
|
+
},
|
|
9
|
+
rules: {
|
|
10
|
+
"effect-span-from-catalog": effectSpanFromCatalog,
|
|
11
|
+
"span-catalog-format": spanCatalogFormat,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default plugin;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const EFFECT_MODULES = new Set(["effect", "effect/Effect"]);
|
|
2
|
+
const SPAN_APIS = new Set([
|
|
3
|
+
"fn",
|
|
4
|
+
"makeSpan",
|
|
5
|
+
"makeSpanScoped",
|
|
6
|
+
"useSpan",
|
|
7
|
+
"withSpan",
|
|
8
|
+
"withSpanScoped",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const isIdentifier = (node) => node?.type === "Identifier";
|
|
12
|
+
|
|
13
|
+
const isAnonymousEffectFn = (node) =>
|
|
14
|
+
node?.type === "FunctionExpression" || node?.type === "ArrowFunctionExpression";
|
|
15
|
+
|
|
16
|
+
const resolvedImportIs = (sourceCode, identifier, importSpecifiers) => {
|
|
17
|
+
let scope = sourceCode.getScope(identifier);
|
|
18
|
+
while (scope !== null) {
|
|
19
|
+
const variable = scope.set.get(identifier.name);
|
|
20
|
+
if (variable !== undefined) {
|
|
21
|
+
return variable.defs.some(
|
|
22
|
+
(definition) =>
|
|
23
|
+
definition.type === "ImportBinding" && importSpecifiers.has(definition.node),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
scope = scope.upper;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const importedName = (specifier) =>
|
|
32
|
+
specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
33
|
+
|
|
34
|
+
const isStringLiteral = (node) => node?.type === "Literal" && typeof node.value === "string";
|
|
35
|
+
|
|
36
|
+
const spanNameArgument = (api, args) => {
|
|
37
|
+
if (api === "fn") {
|
|
38
|
+
return isAnonymousEffectFn(args[0]) ? undefined : args[0];
|
|
39
|
+
}
|
|
40
|
+
if (api !== "withSpan" && api !== "withSpanScoped") {
|
|
41
|
+
return args[0];
|
|
42
|
+
}
|
|
43
|
+
if (args[1] !== undefined && !isStringLiteral(args[0]) && args[1].type !== "ObjectExpression") {
|
|
44
|
+
return args[1];
|
|
45
|
+
}
|
|
46
|
+
return args[0];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Require named Effect spans to use a static name registered in the configured catalog. */
|
|
50
|
+
export const effectSpanFromCatalog = {
|
|
51
|
+
meta: {
|
|
52
|
+
type: "problem",
|
|
53
|
+
docs: {
|
|
54
|
+
description: "require named Effect spans to use a static name from an allowed catalog",
|
|
55
|
+
},
|
|
56
|
+
messages: {
|
|
57
|
+
dynamic: "Named Effect spans must use a static string literal.",
|
|
58
|
+
unknown: 'Span name "{{name}}" is not registered in the configured catalog.',
|
|
59
|
+
},
|
|
60
|
+
schema: [
|
|
61
|
+
{
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
catalogs: {
|
|
65
|
+
type: "array",
|
|
66
|
+
items: {
|
|
67
|
+
type: "array",
|
|
68
|
+
items: { type: "string", minLength: 1 },
|
|
69
|
+
minItems: 1,
|
|
70
|
+
uniqueItems: true,
|
|
71
|
+
},
|
|
72
|
+
minItems: 1,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
additionalProperties: false,
|
|
76
|
+
required: ["catalogs"],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
create(context) {
|
|
81
|
+
const sourceCode = context.sourceCode;
|
|
82
|
+
const options = context.options[0];
|
|
83
|
+
const allowedNames = new Set(options.catalogs.flat());
|
|
84
|
+
const effectNamespaceImports = new Set();
|
|
85
|
+
const namedEffectImports = new Map();
|
|
86
|
+
|
|
87
|
+
const resolveSpanApi = (callee) => {
|
|
88
|
+
if (isIdentifier(callee)) {
|
|
89
|
+
const imported = namedEffectImports.get(callee.name);
|
|
90
|
+
if (
|
|
91
|
+
imported !== undefined &&
|
|
92
|
+
resolvedImportIs(sourceCode, callee, new Set([imported.specifier]))
|
|
93
|
+
) {
|
|
94
|
+
return imported.api;
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
if (
|
|
99
|
+
callee?.type !== "MemberExpression" ||
|
|
100
|
+
callee.computed ||
|
|
101
|
+
!isIdentifier(callee.object) ||
|
|
102
|
+
!isIdentifier(callee.property) ||
|
|
103
|
+
!SPAN_APIS.has(callee.property.name) ||
|
|
104
|
+
!resolvedImportIs(sourceCode, callee.object, effectNamespaceImports)
|
|
105
|
+
) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return callee.property.name;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
ImportDeclaration(node) {
|
|
113
|
+
const source = node.source.value;
|
|
114
|
+
for (const specifier of node.specifiers) {
|
|
115
|
+
if (EFFECT_MODULES.has(source) && specifier.type === "ImportNamespaceSpecifier") {
|
|
116
|
+
effectNamespaceImports.add(specifier);
|
|
117
|
+
}
|
|
118
|
+
if (
|
|
119
|
+
source === "effect" &&
|
|
120
|
+
specifier.type === "ImportSpecifier" &&
|
|
121
|
+
importedName(specifier) === "Effect"
|
|
122
|
+
) {
|
|
123
|
+
effectNamespaceImports.add(specifier);
|
|
124
|
+
}
|
|
125
|
+
if (EFFECT_MODULES.has(source) && specifier.type === "ImportSpecifier") {
|
|
126
|
+
const api = importedName(specifier);
|
|
127
|
+
if (SPAN_APIS.has(api)) {
|
|
128
|
+
namedEffectImports.set(specifier.local.name, { api, specifier });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
CallExpression(node) {
|
|
134
|
+
const api = resolveSpanApi(node.callee);
|
|
135
|
+
if (api === undefined) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const name = spanNameArgument(api, node.arguments);
|
|
139
|
+
if (name === undefined) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!isStringLiteral(name)) {
|
|
143
|
+
context.report({ messageId: "dynamic", node: name });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (!allowedNames.has(name.value)) {
|
|
147
|
+
context.report({ data: { name: name.value }, messageId: "unknown", node: name });
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const SPAN_NAME_PATTERN = /^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9]*)+$/;
|
|
2
|
+
|
|
3
|
+
const stringValue = (node) =>
|
|
4
|
+
node?.type === "Literal" && typeof node.value === "string" ? node.value : undefined;
|
|
5
|
+
|
|
6
|
+
/** Validate configured catalogs as static, canonical, and duplicate-free. */
|
|
7
|
+
export const spanCatalogFormat = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: "problem",
|
|
10
|
+
docs: {
|
|
11
|
+
description: "enforce canonical lowercase dot-separated span catalog values",
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
duplicate: "Span name '{{name}}' is duplicated in the catalog.",
|
|
15
|
+
format:
|
|
16
|
+
"Span name '{{name}}' must contain only lowercase alphanumeric dot-separated segments.",
|
|
17
|
+
static: "Span catalogs must be static arrays of string literals.",
|
|
18
|
+
},
|
|
19
|
+
schema: [
|
|
20
|
+
{
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
catalogs: {
|
|
24
|
+
type: "array",
|
|
25
|
+
items: { type: "string", minLength: 1 },
|
|
26
|
+
minItems: 1,
|
|
27
|
+
uniqueItems: true,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
required: ["catalogs"],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
const catalogNames = new Set(context.options[0].catalogs);
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
|
|
39
|
+
const inspectArray = (array) => {
|
|
40
|
+
for (const element of array.elements) {
|
|
41
|
+
const value = stringValue(element);
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
context.report({ messageId: "static", node: element ?? array });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!SPAN_NAME_PATTERN.test(value)) {
|
|
47
|
+
context.report({ messageId: "format", data: { name: value }, node: element });
|
|
48
|
+
}
|
|
49
|
+
if (seen.has(value)) {
|
|
50
|
+
context.report({ messageId: "duplicate", data: { name: value }, node: element });
|
|
51
|
+
}
|
|
52
|
+
seen.add(value);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
VariableDeclarator(node) {
|
|
58
|
+
if (node.id.type !== "Identifier" || !catalogNames.has(node.id.name)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const initializer = node.init;
|
|
62
|
+
const catalog =
|
|
63
|
+
initializer?.type === "CallExpression" && initializer.arguments.length === 1
|
|
64
|
+
? initializer.arguments[0]
|
|
65
|
+
: initializer;
|
|
66
|
+
if (catalog?.type !== "ArrayExpression") {
|
|
67
|
+
context.report({ messageId: "static", node: initializer ?? node });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
inspectArray(catalog);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|