effect-durable-agent-cloudflare 0.1.0-alpha.19 → 0.1.0-alpha.21
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/dist/anthropic.d.ts +44 -0
- package/dist/anthropic.js +66 -0
- package/dist/anthropic.js.map +1 -0
- package/dist/durable-object.d.ts +16 -2
- package/dist/durable-object.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/openai.d.ts +10 -4
- package/dist/openai.js +20 -48
- package/dist/openai.js.map +1 -1
- package/dist/providers.d.ts +53 -0
- package/dist/providers.js +221 -0
- package/dist/providers.js.map +1 -0
- package/dist/{rpc-spec-Cko7gaMg.d.ts → rpc-spec-C8wknrbN.d.ts} +32 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/{session-controller-IrTPwdRt.js → session-controller-BGfz1DdS.js} +6 -4
- package/dist/session-controller-BGfz1DdS.js.map +1 -0
- package/dist/{session-controller-BfA5NAuY.d.ts → session-controller-DoeFP_Ej.d.ts} +9 -4
- package/dist/session-controller.d.ts +1 -1
- package/dist/session-controller.js +1 -1
- package/dist/transport-BzgK07l4.js +205 -0
- package/dist/transport-BzgK07l4.js.map +1 -0
- package/package.json +25 -7
- package/dist/session-controller-IrTPwdRt.js.map +0 -1
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { a as withBeta, i as prepareNativeCompaction, n as EDAProviderRequestOverride, t as ANTHROPIC_COMPACTION_BETA } from "./transport-BzgK07l4.js";
|
|
2
|
+
import { makeEDAAnthropicClientLayer, prepareEDAAnthropicPrompt } from "./anthropic.js";
|
|
3
|
+
import { makeEDAOpenAiClientLayer } from "./openai.js";
|
|
4
|
+
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic";
|
|
5
|
+
import { nativeCompactionSummaryMessage } from "effect-durable-agent/services/prompt-projector";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Exit from "effect/Exit";
|
|
9
|
+
import { CompactionExecutorId } from "effect-durable-agent/domain/context-projection";
|
|
10
|
+
import { CompactionError, CompactionExecutor, CompactionOutput, promptPrefixSummaryCompactionExecutor } from "effect-durable-agent/services/compaction";
|
|
11
|
+
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai";
|
|
12
|
+
import { ModelResolver } from "effect-durable-agent/services/model-resolver";
|
|
13
|
+
import { generateTextOfferingTools } from "effect-durable-agent/services/model-call";
|
|
14
|
+
//#region src/providers/providers.ts
|
|
15
|
+
/**
|
|
16
|
+
* Resolves each durable selection to the provider it names, sharing one client per provider for
|
|
17
|
+
* the runtime lifetime, and prepares prompts in that provider's cache and compaction shape.
|
|
18
|
+
*/
|
|
19
|
+
const makeEDAMultiProviderModelResolverLayer = (options) => {
|
|
20
|
+
const openAiClient = options.openai === void 0 ? void 0 : makeEDAOpenAiClientLayer(options.openai);
|
|
21
|
+
const anthropicClient = options.anthropic === void 0 ? void 0 : makeEDAAnthropicClientLayer(options.anthropic);
|
|
22
|
+
return Layer.effect(ModelResolver, Effect.gen(function* () {
|
|
23
|
+
const openAi = openAiClient === void 0 ? void 0 : yield* OpenAiClient.OpenAiClient.pipe(Effect.provide(openAiClient));
|
|
24
|
+
const anthropic = anthropicClient === void 0 ? void 0 : yield* AnthropicClient.AnthropicClient.pipe(Effect.provide(anthropicClient));
|
|
25
|
+
return {
|
|
26
|
+
resolve: Effect.fn("MultiProviderModelResolver.resolve")(function* (selection) {
|
|
27
|
+
const resolved = options.resolve(selection);
|
|
28
|
+
if (resolved.provider === "anthropic") {
|
|
29
|
+
if (anthropic === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("No Anthropic client is configured."));
|
|
30
|
+
return yield* AnthropicLanguageModel.make({
|
|
31
|
+
model: resolved.modelId,
|
|
32
|
+
config: resolved.config
|
|
33
|
+
}).pipe(Effect.provideService(AnthropicClient.AnthropicClient, anthropic));
|
|
34
|
+
}
|
|
35
|
+
if (openAi === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("No OpenAI client is configured."));
|
|
36
|
+
return yield* OpenAiLanguageModel.make({
|
|
37
|
+
model: resolved.modelId,
|
|
38
|
+
config: resolved.config
|
|
39
|
+
}).pipe(Effect.provideService(OpenAiClient.OpenAiClient, openAi));
|
|
40
|
+
}),
|
|
41
|
+
preparePrompt: (selection, prompt) => selection?.provider === "anthropic" ? prepareEDAAnthropicPrompt(prompt) : selection?.provider === "openai" ? prepareNativeCompaction("openai", prompt) : prompt
|
|
42
|
+
};
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Compacts with the session provider's own endpoint: OpenAI `/responses/compact`, Anthropic
|
|
47
|
+
* on-demand compaction (`compact-2026-09-04`). Each call carries the exact earlier request prompt,
|
|
48
|
+
* so it reads the conversation from the provider cache, and the returned native items replace the
|
|
49
|
+
* summarized history on later requests. Other providers fall back to a prompt-prefix summary.
|
|
50
|
+
*/
|
|
51
|
+
const makeEDANativeCompactionExecutorLayer = (options = {}) => Layer.effect(CompactionExecutor, Effect.gen(function* () {
|
|
52
|
+
const fallback = yield* CompactionExecutor.pipe(Effect.provide(promptPrefixSummaryCompactionExecutor()));
|
|
53
|
+
return {
|
|
54
|
+
id: CompactionExecutorId.make("provider-native"),
|
|
55
|
+
execute: (input) => {
|
|
56
|
+
switch (input.state.modelSelection?.provider) {
|
|
57
|
+
case "anthropic": return anthropicCompaction(input, options);
|
|
58
|
+
case "openai": return openAiCompaction(input);
|
|
59
|
+
default: return fallback.execute(input);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}));
|
|
64
|
+
/** Run the adapter's request with an override and return the raw provider response. */
|
|
65
|
+
const callWithOverride = (input, rewrite) => Effect.gen(function* () {
|
|
66
|
+
let captured;
|
|
67
|
+
const exit = yield* generateTextOfferingTools(input.model, input.prompt, input.toolkit).pipe(Effect.provideService(EDAProviderRequestOverride, {
|
|
68
|
+
rewrite,
|
|
69
|
+
onResponse: (status, body) => {
|
|
70
|
+
captured = {
|
|
71
|
+
status,
|
|
72
|
+
body
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}), Effect.exit);
|
|
76
|
+
if (captured === void 0) return yield* new CompactionError({ message: `compaction request failed before a provider response: ${Exit.isFailure(exit) ? String(exit.cause) : "no response"}` });
|
|
77
|
+
if (captured.status < 200 || captured.status >= 300) return yield* new CompactionError({ message: `compaction request failed with ${captured.status}: ${providerErrorMessage(captured.body)}` });
|
|
78
|
+
return captured.body;
|
|
79
|
+
});
|
|
80
|
+
const anthropicCompaction = (input, options) => Effect.gen(function* () {
|
|
81
|
+
const body = yield* callWithOverride(input, (request) => ({
|
|
82
|
+
...request,
|
|
83
|
+
headers: {
|
|
84
|
+
...withBeta(request.headers, ANTHROPIC_COMPACTION_BETA),
|
|
85
|
+
accept: "text/event-stream"
|
|
86
|
+
},
|
|
87
|
+
body: isRecord(request.body) ? {
|
|
88
|
+
...request.body,
|
|
89
|
+
max_tokens: options.anthropicMaxTokens ?? 16e3,
|
|
90
|
+
stream: true,
|
|
91
|
+
compaction: {
|
|
92
|
+
type: "summarize",
|
|
93
|
+
...options.anthropicInstructions === void 0 ? {} : { instructions: options.anthropicInstructions }
|
|
94
|
+
}
|
|
95
|
+
} : request.body
|
|
96
|
+
})).pipe(Effect.map(anthropicMessageFromStream));
|
|
97
|
+
const usage = anthropicCompactionUsage(body);
|
|
98
|
+
const block = isRecord(body) && Array.isArray(body.content) ? body.content[0] : void 0;
|
|
99
|
+
if (!isRecord(body) || body.stop_reason !== "compaction" || !isRecord(block) || block.type !== "compaction" || typeof block.content !== "string" || block.content.trim().length === 0) return yield* new CompactionError({
|
|
100
|
+
message: `anthropic compaction returned no summary (stop_reason ${isRecord(body) ? String(body.stop_reason) : "unknown"})`,
|
|
101
|
+
...usage === void 0 ? {} : { usage }
|
|
102
|
+
});
|
|
103
|
+
const text = block.content.trim();
|
|
104
|
+
return CompactionOutput.make({
|
|
105
|
+
text,
|
|
106
|
+
promptMessage: nativeCompactionSummaryMessage(`Conversation summary:\n\n${text}`, {
|
|
107
|
+
provider: "anthropic",
|
|
108
|
+
modelId: input.state.modelSelection?.modelId ?? "unknown",
|
|
109
|
+
items: [jsonValue(block)]
|
|
110
|
+
}),
|
|
111
|
+
executorId: CompactionExecutorId.make("anthropic-native"),
|
|
112
|
+
...usage === void 0 ? {} : { usage }
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
const openAiCompaction = (input) => Effect.gen(function* () {
|
|
116
|
+
const body = yield* callWithOverride(input, (request) => ({
|
|
117
|
+
...request,
|
|
118
|
+
url: new URL(request.url.pathname.replace(/\/responses$/u, "/responses/compact"), request.url),
|
|
119
|
+
body: isRecord(request.body) ? Object.fromEntries(Object.entries(request.body).filter(([key]) => [
|
|
120
|
+
"model",
|
|
121
|
+
"input",
|
|
122
|
+
"instructions",
|
|
123
|
+
"tools"
|
|
124
|
+
].includes(key))) : request.body
|
|
125
|
+
}));
|
|
126
|
+
const usage = openAiUsage(isRecord(body) ? body.usage : void 0);
|
|
127
|
+
const items = (isRecord(body) && Array.isArray(body.output) ? body.output : []).filter((item) => !(isRecord(item) && (item.role === "developer" || item.role === "system")));
|
|
128
|
+
if (!items.some((item) => isRecord(item) && item.type === "compaction")) return yield* new CompactionError({
|
|
129
|
+
message: "openai compaction returned no compaction item",
|
|
130
|
+
...usage === void 0 ? {} : { usage }
|
|
131
|
+
});
|
|
132
|
+
const text = `Earlier conversation compacted by OpenAI into an encrypted summary (${items.filter((item) => isRecord(item) && item.role === "user").length} user messages retained verbatim).`;
|
|
133
|
+
return CompactionOutput.make({
|
|
134
|
+
text,
|
|
135
|
+
promptMessage: nativeCompactionSummaryMessage(text, {
|
|
136
|
+
provider: "openai",
|
|
137
|
+
modelId: input.state.modelSelection?.modelId ?? "unknown",
|
|
138
|
+
items: items.map(jsonValue)
|
|
139
|
+
}),
|
|
140
|
+
executorId: CompactionExecutorId.make("openai-native"),
|
|
141
|
+
...usage === void 0 ? {} : { usage }
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Rebuild a Messages API response from its SSE stream. A compaction block arrives whole in its
|
|
146
|
+
* `content_block_start`; usage (with `iterations`) arrives on `message_delta`.
|
|
147
|
+
*/
|
|
148
|
+
const anthropicMessageFromStream = (body) => {
|
|
149
|
+
if (typeof body !== "string") return body;
|
|
150
|
+
let message = {};
|
|
151
|
+
const content = [];
|
|
152
|
+
for (const line of body.split("\n")) {
|
|
153
|
+
if (!line.startsWith("data: ")) continue;
|
|
154
|
+
const event = JSON.parse(line.slice(6));
|
|
155
|
+
if (!isRecord(event)) continue;
|
|
156
|
+
if (event.type === "message_start" && isRecord(event.message)) message = { ...event.message };
|
|
157
|
+
else if (event.type === "content_block_start" && typeof event.index === "number") content[event.index] = event.content_block;
|
|
158
|
+
else if (event.type === "message_delta") {
|
|
159
|
+
const delta = isRecord(event.delta) ? event.delta : {};
|
|
160
|
+
const usage = isRecord(message.usage) ? message.usage : {};
|
|
161
|
+
message = {
|
|
162
|
+
...message,
|
|
163
|
+
...delta,
|
|
164
|
+
usage: {
|
|
165
|
+
...usage,
|
|
166
|
+
...isRecord(event.usage) ? event.usage : {}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
} else if (event.type === "error") return { error: event.error };
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
...message,
|
|
173
|
+
content: content.filter((block) => block !== void 0)
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
/** Anthropic reports compaction cost only in `usage.iterations`; top-level fields are zero. */
|
|
177
|
+
const anthropicCompactionUsage = (body) => {
|
|
178
|
+
const usage = isRecord(body) ? body.usage : void 0;
|
|
179
|
+
const iterations = isRecord(usage) && Array.isArray(usage.iterations) ? usage.iterations : [];
|
|
180
|
+
if (iterations.length === 0) return void 0;
|
|
181
|
+
let uncached = 0;
|
|
182
|
+
let cacheRead = 0;
|
|
183
|
+
let cacheWrite = 0;
|
|
184
|
+
let output = 0;
|
|
185
|
+
for (const iteration of iterations) {
|
|
186
|
+
if (!isRecord(iteration)) continue;
|
|
187
|
+
uncached += count(iteration.input_tokens);
|
|
188
|
+
cacheRead += count(iteration.cache_read_input_tokens);
|
|
189
|
+
cacheWrite += count(iteration.cache_creation_input_tokens);
|
|
190
|
+
output += count(iteration.output_tokens);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
inputTokens: uncached + cacheRead + cacheWrite,
|
|
194
|
+
cachedInputTokens: cacheRead,
|
|
195
|
+
cacheWriteInputTokens: cacheWrite,
|
|
196
|
+
outputTokens: output
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const openAiUsage = (usage) => {
|
|
200
|
+
if (!isRecord(usage)) return void 0;
|
|
201
|
+
const details = isRecord(usage.input_tokens_details) ? usage.input_tokens_details : {};
|
|
202
|
+
return {
|
|
203
|
+
inputTokens: count(usage.input_tokens),
|
|
204
|
+
cachedInputTokens: count(details.cached_tokens),
|
|
205
|
+
cacheWriteInputTokens: count(details.cache_write_tokens),
|
|
206
|
+
outputTokens: count(usage.output_tokens)
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
const count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : 0;
|
|
210
|
+
const providerErrorMessage = (body) => {
|
|
211
|
+
if (isRecord(body) && isRecord(body.error) && typeof body.error.message === "string") return body.error.message;
|
|
212
|
+
return typeof body === "string" ? body.slice(0, 500) : JSON.stringify(body).slice(0, 500);
|
|
213
|
+
};
|
|
214
|
+
const jsonValue = (value) => {
|
|
215
|
+
return JSON.parse(JSON.stringify(value) ?? "null");
|
|
216
|
+
};
|
|
217
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
218
|
+
//#endregion
|
|
219
|
+
export { makeEDAMultiProviderModelResolverLayer, makeEDANativeCompactionExecutorLayer, prepareEDAAnthropicPrompt };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","names":[],"sources":["../src/providers/providers.ts"],"sourcesContent":["import { AnthropicClient, AnthropicLanguageModel } from \"@effect/ai-anthropic\";\nimport { OpenAiClient, OpenAiLanguageModel } from \"@effect/ai-openai\";\nimport {\n CompactionError,\n CompactionExecutor,\n CompactionOutput,\n promptPrefixSummaryCompactionExecutor,\n type CompactionExecutorInput,\n type CompactionExecutorShape,\n} from \"effect-durable-agent/services/compaction\";\nimport { generateTextOfferingTools } from \"effect-durable-agent/services/model-call\";\nimport { ModelResolver } from \"effect-durable-agent/services/model-resolver\";\nimport { nativeCompactionSummaryMessage } from \"effect-durable-agent/services/prompt-projector\";\nimport type { ModelSelectionPayload, UsagePayload } from \"effect-durable-agent/types/events\";\nimport { CompactionExecutorId } from \"effect-durable-agent/domain/context-projection\";\nimport * as Effect from \"effect/Effect\";\nimport * as Exit from \"effect/Exit\";\nimport * as Layer from \"effect/Layer\";\nimport type * as Schema from \"effect/Schema\";\n\nimport {\n makeEDAAnthropicClientLayer,\n prepareEDAAnthropicPrompt,\n type EDAAnthropicClientOptions,\n type EDAAnthropicModelConfig,\n} from \"./anthropic\";\nimport { makeEDAOpenAiClientLayer, type EDAOpenAiModelConfig } from \"./openai\";\nimport {\n ANTHROPIC_COMPACTION_BETA,\n EDAProviderRequestOverride,\n prepareNativeCompaction,\n withBeta,\n type EDAProviderRequest,\n} from \"./transport\";\n\n/** Model request settings the host derives from a durable selection. */\nexport type EDAResolvedModel =\n | {\n readonly provider: \"openai\";\n readonly modelId: string;\n readonly config: EDAOpenAiModelConfig;\n }\n | {\n readonly provider: \"anthropic\";\n readonly modelId: string;\n readonly config: EDAAnthropicModelConfig;\n };\n\n/** Clients for every provider a host serves; a session runs on the one its selection names. */\nexport interface EDAMultiProviderModelResolverOptions {\n readonly openai?: {\n readonly aiGateway?: AiGateway | undefined;\n readonly apiKey?: string | undefined;\n readonly apiUrl?: string | undefined;\n };\n readonly anthropic?: EDAAnthropicClientOptions;\n /** Host policy: validate the recorded selection and choose request settings. Throw to reject. */\n readonly resolve: (selection: ModelSelectionPayload | undefined) => EDAResolvedModel;\n}\n\n/**\n * Resolves each durable selection to the provider it names, sharing one client per provider for\n * the runtime lifetime, and prepares prompts in that provider's cache and compaction shape.\n */\nexport const makeEDAMultiProviderModelResolverLayer = (\n options: EDAMultiProviderModelResolverOptions,\n): Layer.Layer<ModelResolver> => {\n const openAiClient =\n options.openai === undefined ? undefined : makeEDAOpenAiClientLayer(options.openai);\n const anthropicClient =\n options.anthropic === undefined ? undefined : makeEDAAnthropicClientLayer(options.anthropic);\n return Layer.effect(\n ModelResolver,\n Effect.gen(function* () {\n const openAi =\n openAiClient === undefined\n ? undefined\n : yield* OpenAiClient.OpenAiClient.pipe(Effect.provide(openAiClient));\n const anthropic =\n anthropicClient === undefined\n ? undefined\n : yield* AnthropicClient.AnthropicClient.pipe(Effect.provide(anthropicClient));\n return {\n resolve: Effect.fn(\"MultiProviderModelResolver.resolve\")(function* (selection) {\n const resolved = options.resolve(selection);\n if (resolved.provider === \"anthropic\") {\n if (anthropic === undefined) {\n return yield* Effect.die(new Error(\"No Anthropic client is configured.\"));\n }\n return yield* AnthropicLanguageModel.make({\n model: resolved.modelId,\n config: resolved.config,\n }).pipe(Effect.provideService(AnthropicClient.AnthropicClient, anthropic));\n }\n if (openAi === undefined) {\n return yield* Effect.die(new Error(\"No OpenAI client is configured.\"));\n }\n return yield* OpenAiLanguageModel.make({\n model: resolved.modelId,\n config: resolved.config,\n }).pipe(Effect.provideService(OpenAiClient.OpenAiClient, openAi));\n }),\n preparePrompt: (selection, prompt) =>\n selection?.provider === \"anthropic\"\n ? prepareEDAAnthropicPrompt(prompt)\n : selection?.provider === \"openai\"\n ? prepareNativeCompaction(\"openai\", prompt)\n : prompt,\n };\n }),\n );\n};\n\n/** Options for provider-native compaction. */\nexport interface EDANativeCompactionOptions {\n /**\n * Custom summarization prompt for Anthropic (`compaction.instructions`, up to 16,384 characters).\n * OpenAI compaction takes no prompt.\n */\n readonly anthropicInstructions?: string | undefined;\n /** Output budget for the Anthropic summary call, thinking included. Defaults to 16,000. */\n readonly anthropicMaxTokens?: number | undefined;\n}\n\n/**\n * Compacts with the session provider's own endpoint: OpenAI `/responses/compact`, Anthropic\n * on-demand compaction (`compact-2026-09-04`). Each call carries the exact earlier request prompt,\n * so it reads the conversation from the provider cache, and the returned native items replace the\n * summarized history on later requests. Other providers fall back to a prompt-prefix summary.\n */\nexport const makeEDANativeCompactionExecutorLayer = (\n options: EDANativeCompactionOptions = {},\n): Layer.Layer<CompactionExecutor> =>\n Layer.effect(\n CompactionExecutor,\n Effect.gen(function* () {\n const fallback = yield* CompactionExecutor.pipe(\n Effect.provide(promptPrefixSummaryCompactionExecutor()),\n );\n return {\n id: CompactionExecutorId.make(\"provider-native\"),\n execute: (input) => {\n switch (input.state.modelSelection?.provider) {\n case \"anthropic\":\n return anthropicCompaction(input, options);\n case \"openai\":\n return openAiCompaction(input);\n default:\n return fallback.execute(input);\n }\n },\n } satisfies CompactionExecutorShape;\n }),\n );\n\ninterface CapturedResponse {\n readonly status: number;\n readonly body: unknown;\n}\n\n/** Run the adapter's request with an override and return the raw provider response. */\nconst callWithOverride = (\n input: CompactionExecutorInput,\n rewrite: (request: EDAProviderRequest) => EDAProviderRequest,\n) =>\n Effect.gen(function* () {\n let captured: CapturedResponse | undefined;\n const exit = yield* generateTextOfferingTools(input.model, input.prompt, input.toolkit).pipe(\n Effect.provideService(EDAProviderRequestOverride, {\n rewrite,\n onResponse: (status, body) => {\n captured = { status, body };\n },\n }),\n Effect.exit,\n );\n if (captured === undefined) {\n return yield* new CompactionError({\n message: `compaction request failed before a provider response: ${\n Exit.isFailure(exit) ? String(exit.cause) : \"no response\"\n }`,\n });\n }\n if (captured.status < 200 || captured.status >= 300) {\n return yield* new CompactionError({\n message: `compaction request failed with ${captured.status}: ${providerErrorMessage(captured.body)}`,\n });\n }\n return captured.body;\n });\n\nconst anthropicCompaction = (input: CompactionExecutorInput, options: EDANativeCompactionOptions) =>\n Effect.gen(function* () {\n const body = yield* callWithOverride(input, (request) => ({\n ...request,\n headers: {\n ...withBeta(request.headers, ANTHROPIC_COMPACTION_BETA),\n accept: \"text/event-stream\",\n },\n body: isRecord(request.body)\n ? {\n ...request.body,\n max_tokens: options.anthropicMaxTokens ?? 16_000,\n // Streaming keeps the connection active (pings) while the summary is written.\n stream: true,\n compaction: {\n type: \"summarize\",\n ...(options.anthropicInstructions === undefined\n ? {}\n : { instructions: options.anthropicInstructions }),\n },\n }\n : request.body,\n })).pipe(Effect.map(anthropicMessageFromStream));\n const usage = anthropicCompactionUsage(body);\n const block = isRecord(body) && Array.isArray(body.content) ? body.content[0] : undefined;\n if (\n !isRecord(body) ||\n body.stop_reason !== \"compaction\" ||\n !isRecord(block) ||\n block.type !== \"compaction\" ||\n typeof block.content !== \"string\" ||\n block.content.trim().length === 0\n ) {\n return yield* new CompactionError({\n message: `anthropic compaction returned no summary (stop_reason ${\n isRecord(body) ? String(body.stop_reason) : \"unknown\"\n })`,\n ...(usage === undefined ? {} : { usage }),\n });\n }\n const text = block.content.trim();\n return CompactionOutput.make({\n text,\n promptMessage: nativeCompactionSummaryMessage(`Conversation summary:\\n\\n${text}`, {\n provider: \"anthropic\",\n modelId: input.state.modelSelection?.modelId ?? \"unknown\",\n items: [jsonValue(block)],\n }),\n executorId: CompactionExecutorId.make(\"anthropic-native\"),\n ...(usage === undefined ? {} : { usage }),\n });\n });\n\nconst openAiCompaction = (input: CompactionExecutorInput) =>\n Effect.gen(function* () {\n const body = yield* callWithOverride(input, (request) => ({\n ...request,\n url: new URL(\n request.url.pathname.replace(/\\/responses$/u, \"/responses/compact\"),\n request.url,\n ),\n body: isRecord(request.body)\n ? Object.fromEntries(\n Object.entries(request.body).filter(([key]) =>\n [\"model\", \"input\", \"instructions\", \"tools\"].includes(key),\n ),\n )\n : request.body,\n }));\n const usage = openAiUsage(isRecord(body) ? body.usage : undefined);\n const output = isRecord(body) && Array.isArray(body.output) ? body.output : [];\n // The host sends its own instructions; keep only conversation items from the compacted window.\n const items = output.filter(\n (item) => !(isRecord(item) && (item.role === \"developer\" || item.role === \"system\")),\n );\n if (!items.some((item) => isRecord(item) && item.type === \"compaction\")) {\n return yield* new CompactionError({\n message: \"openai compaction returned no compaction item\",\n ...(usage === undefined ? {} : { usage }),\n });\n }\n const retainedUserMessages = items.filter(\n (item) => isRecord(item) && item.role === \"user\",\n ).length;\n const text = `Earlier conversation compacted by OpenAI into an encrypted summary (${retainedUserMessages} user messages retained verbatim).`;\n return CompactionOutput.make({\n text,\n promptMessage: nativeCompactionSummaryMessage(text, {\n provider: \"openai\",\n modelId: input.state.modelSelection?.modelId ?? \"unknown\",\n items: items.map(jsonValue),\n }),\n executorId: CompactionExecutorId.make(\"openai-native\"),\n ...(usage === undefined ? {} : { usage }),\n });\n });\n\n/**\n * Rebuild a Messages API response from its SSE stream. A compaction block arrives whole in its\n * `content_block_start`; usage (with `iterations`) arrives on `message_delta`.\n */\nconst anthropicMessageFromStream = (body: unknown): unknown => {\n if (typeof body !== \"string\") return body;\n let message: Record<string, unknown> = {};\n const content: Array<unknown> = [];\n for (const line of body.split(\"\\n\")) {\n if (!line.startsWith(\"data: \")) continue;\n const event: unknown = JSON.parse(line.slice(\"data: \".length));\n if (!isRecord(event)) continue;\n if (event.type === \"message_start\" && isRecord(event.message)) {\n message = { ...event.message };\n } else if (event.type === \"content_block_start\" && typeof event.index === \"number\") {\n content[event.index] = event.content_block;\n } else if (event.type === \"message_delta\") {\n const delta = isRecord(event.delta) ? event.delta : {};\n const usage = isRecord(message.usage) ? message.usage : {};\n message = {\n ...message,\n ...delta,\n usage: { ...usage, ...(isRecord(event.usage) ? event.usage : {}) },\n };\n } else if (event.type === \"error\") {\n return { error: event.error };\n }\n }\n return { ...message, content: content.filter((block) => block !== undefined) };\n};\n\n/** Anthropic reports compaction cost only in `usage.iterations`; top-level fields are zero. */\nconst anthropicCompactionUsage = (body: unknown): UsagePayload | undefined => {\n const usage = isRecord(body) ? body.usage : undefined;\n const iterations = isRecord(usage) && Array.isArray(usage.iterations) ? usage.iterations : [];\n if (iterations.length === 0) return undefined;\n let uncached = 0;\n let cacheRead = 0;\n let cacheWrite = 0;\n let output = 0;\n for (const iteration of iterations) {\n if (!isRecord(iteration)) continue;\n uncached += count(iteration.input_tokens);\n cacheRead += count(iteration.cache_read_input_tokens);\n cacheWrite += count(iteration.cache_creation_input_tokens);\n output += count(iteration.output_tokens);\n }\n return {\n inputTokens: uncached + cacheRead + cacheWrite,\n cachedInputTokens: cacheRead,\n cacheWriteInputTokens: cacheWrite,\n outputTokens: output,\n };\n};\n\nconst openAiUsage = (usage: unknown): UsagePayload | undefined => {\n if (!isRecord(usage)) return undefined;\n const details = isRecord(usage.input_tokens_details) ? usage.input_tokens_details : {};\n return {\n inputTokens: count(usage.input_tokens),\n cachedInputTokens: count(details.cached_tokens),\n cacheWriteInputTokens: count(details.cache_write_tokens),\n outputTokens: count(usage.output_tokens),\n };\n};\n\nconst count = (value: unknown): number =>\n typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0 ? value : 0;\n\nconst providerErrorMessage = (body: unknown): string => {\n if (isRecord(body) && isRecord(body.error) && typeof body.error.message === \"string\") {\n return body.error.message;\n }\n return typeof body === \"string\" ? body.slice(0, 500) : JSON.stringify(body).slice(0, 500);\n};\n\nconst jsonValue = (value: unknown): Schema.Json => {\n const parsed: Schema.Json = JSON.parse(JSON.stringify(value) ?? \"null\");\n return parsed;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nexport { prepareEDAAnthropicPrompt } from \"./anthropic\";\nexport type { EDAAnthropicModelConfig } from \"./anthropic\";\nexport type { EDAOpenAiModelConfig } from \"./openai\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgEA,MAAa,0CACX,YAC+B;CAC/B,MAA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ACrC,mBAAmB,MAAM,QAAQ,aAAa;EAC9C,uBAAuB,MAAM,QAAQ,kBAAkB;EACvD,cAAc,MAAM,MAAM,aAAa;CACzC;AACF;AAEA,MAAM,SAAS,UACb,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS,IAAI,QAAQ;AAEnF,MAAM,wBAAwB,SAA0B;CACtD,IAAI,SAAS,IAAI,KAAK,SAAS,KAAK,KAAK,KAAK,OAAO,KAAK,MAAM,YAAY,UAC1E,OAAO,KAAK,MAAM;CAEpB,OAAO,OAAO,SAAS,WAAW,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,MAAM,GAAG,GAAG;AAC1F;AAEA,MAAM,aAAa,UAAgC;CAEjD,OAD4B,KAAK,MAAM,KAAK,UAAU,KAAK,KAAK,MACpD;AACd;AAEA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK"}
|
|
@@ -341,6 +341,7 @@ declare const edaSessionRpc: {
|
|
|
341
341
|
readonly name: string;
|
|
342
342
|
readonly isFailure: boolean;
|
|
343
343
|
readonly result: unknown;
|
|
344
|
+
readonly providerExecuted: boolean;
|
|
344
345
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
345
346
|
readonly options: {
|
|
346
347
|
readonly [x: string]: Schema.Json;
|
|
@@ -392,6 +393,7 @@ declare const edaSessionRpc: {
|
|
|
392
393
|
readonly name: string;
|
|
393
394
|
readonly isFailure: boolean;
|
|
394
395
|
readonly result: unknown;
|
|
396
|
+
readonly providerExecuted: boolean;
|
|
395
397
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
396
398
|
readonly options: {
|
|
397
399
|
readonly [x: string]: Schema.Json;
|
|
@@ -1298,6 +1300,7 @@ declare const edaSessionRpc: {
|
|
|
1298
1300
|
readonly name: string;
|
|
1299
1301
|
readonly isFailure: boolean;
|
|
1300
1302
|
readonly result: unknown;
|
|
1303
|
+
readonly providerExecuted: boolean;
|
|
1301
1304
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1302
1305
|
readonly options: {
|
|
1303
1306
|
readonly [x: string]: Schema.Json;
|
|
@@ -1349,6 +1352,7 @@ declare const edaSessionRpc: {
|
|
|
1349
1352
|
readonly name: string;
|
|
1350
1353
|
readonly isFailure: boolean;
|
|
1351
1354
|
readonly result: unknown;
|
|
1355
|
+
readonly providerExecuted: boolean;
|
|
1352
1356
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1353
1357
|
readonly options: {
|
|
1354
1358
|
readonly [x: string]: Schema.Json;
|
|
@@ -1435,6 +1439,7 @@ declare const edaSessionRpc: {
|
|
|
1435
1439
|
readonly name: string;
|
|
1436
1440
|
readonly isFailure: boolean;
|
|
1437
1441
|
readonly result: unknown;
|
|
1442
|
+
readonly providerExecuted: boolean;
|
|
1438
1443
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1439
1444
|
readonly options: {
|
|
1440
1445
|
readonly [x: string]: Schema.Json;
|
|
@@ -1486,6 +1491,7 @@ declare const edaSessionRpc: {
|
|
|
1486
1491
|
readonly name: string;
|
|
1487
1492
|
readonly isFailure: boolean;
|
|
1488
1493
|
readonly result: unknown;
|
|
1494
|
+
readonly providerExecuted: boolean;
|
|
1489
1495
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1490
1496
|
readonly options: {
|
|
1491
1497
|
readonly [x: string]: Schema.Json;
|
|
@@ -1572,6 +1578,7 @@ declare const edaSessionRpc: {
|
|
|
1572
1578
|
readonly name: string;
|
|
1573
1579
|
readonly isFailure: boolean;
|
|
1574
1580
|
readonly result: unknown;
|
|
1581
|
+
readonly providerExecuted: boolean;
|
|
1575
1582
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1576
1583
|
readonly options: {
|
|
1577
1584
|
readonly [x: string]: Schema.Json;
|
|
@@ -1623,6 +1630,7 @@ declare const edaSessionRpc: {
|
|
|
1623
1630
|
readonly name: string;
|
|
1624
1631
|
readonly isFailure: boolean;
|
|
1625
1632
|
readonly result: unknown;
|
|
1633
|
+
readonly providerExecuted: boolean;
|
|
1626
1634
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
1627
1635
|
readonly options: {
|
|
1628
1636
|
readonly [x: string]: Schema.Json;
|
|
@@ -2167,6 +2175,7 @@ declare const edaSessionRpc: {
|
|
|
2167
2175
|
readonly toolCallId: string & import("effect/Brand").Brand<"ToolCallId">;
|
|
2168
2176
|
readonly promptPart: {
|
|
2169
2177
|
readonly type: "tool-result";
|
|
2178
|
+
readonly providerExecuted: boolean;
|
|
2170
2179
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
2171
2180
|
readonly options: {
|
|
2172
2181
|
readonly [x: string]: Schema.Json;
|
|
@@ -2244,6 +2253,7 @@ declare const edaSessionRpc: {
|
|
|
2244
2253
|
readonly toolCallId: string & import("effect/Brand").Brand<"ToolCallId">;
|
|
2245
2254
|
readonly promptPart: {
|
|
2246
2255
|
readonly type: "tool-result";
|
|
2256
|
+
readonly providerExecuted: boolean;
|
|
2247
2257
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
2248
2258
|
readonly options: {
|
|
2249
2259
|
readonly [x: string]: Schema.Json;
|
|
@@ -2291,6 +2301,7 @@ declare const edaSessionRpc: {
|
|
|
2291
2301
|
} | undefined;
|
|
2292
2302
|
readonly promptPart: {
|
|
2293
2303
|
readonly type: "tool-result";
|
|
2304
|
+
readonly providerExecuted: boolean;
|
|
2294
2305
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
2295
2306
|
readonly options: {
|
|
2296
2307
|
readonly [x: string]: Schema.Json;
|
|
@@ -3027,6 +3038,7 @@ declare const edaSessionRpc: {
|
|
|
3027
3038
|
readonly name: string;
|
|
3028
3039
|
readonly isFailure: boolean;
|
|
3029
3040
|
readonly result: unknown;
|
|
3041
|
+
readonly providerExecuted: boolean;
|
|
3030
3042
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
3031
3043
|
readonly options: {
|
|
3032
3044
|
readonly [x: string]: Schema.Json;
|
|
@@ -3078,6 +3090,7 @@ declare const edaSessionRpc: {
|
|
|
3078
3090
|
readonly name: string;
|
|
3079
3091
|
readonly isFailure: boolean;
|
|
3080
3092
|
readonly result: unknown;
|
|
3093
|
+
readonly providerExecuted: boolean;
|
|
3081
3094
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
3082
3095
|
readonly options: {
|
|
3083
3096
|
readonly [x: string]: Schema.Json;
|
|
@@ -3984,6 +3997,7 @@ declare const edaSessionRpc: {
|
|
|
3984
3997
|
readonly name: string;
|
|
3985
3998
|
readonly isFailure: boolean;
|
|
3986
3999
|
readonly result: unknown;
|
|
4000
|
+
readonly providerExecuted: boolean;
|
|
3987
4001
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
3988
4002
|
readonly options: {
|
|
3989
4003
|
readonly [x: string]: Schema.Json;
|
|
@@ -4035,6 +4049,7 @@ declare const edaSessionRpc: {
|
|
|
4035
4049
|
readonly name: string;
|
|
4036
4050
|
readonly isFailure: boolean;
|
|
4037
4051
|
readonly result: unknown;
|
|
4052
|
+
readonly providerExecuted: boolean;
|
|
4038
4053
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4039
4054
|
readonly options: {
|
|
4040
4055
|
readonly [x: string]: Schema.Json;
|
|
@@ -4121,6 +4136,7 @@ declare const edaSessionRpc: {
|
|
|
4121
4136
|
readonly name: string;
|
|
4122
4137
|
readonly isFailure: boolean;
|
|
4123
4138
|
readonly result: unknown;
|
|
4139
|
+
readonly providerExecuted: boolean;
|
|
4124
4140
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4125
4141
|
readonly options: {
|
|
4126
4142
|
readonly [x: string]: Schema.Json;
|
|
@@ -4172,6 +4188,7 @@ declare const edaSessionRpc: {
|
|
|
4172
4188
|
readonly name: string;
|
|
4173
4189
|
readonly isFailure: boolean;
|
|
4174
4190
|
readonly result: unknown;
|
|
4191
|
+
readonly providerExecuted: boolean;
|
|
4175
4192
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4176
4193
|
readonly options: {
|
|
4177
4194
|
readonly [x: string]: Schema.Json;
|
|
@@ -4258,6 +4275,7 @@ declare const edaSessionRpc: {
|
|
|
4258
4275
|
readonly name: string;
|
|
4259
4276
|
readonly isFailure: boolean;
|
|
4260
4277
|
readonly result: unknown;
|
|
4278
|
+
readonly providerExecuted: boolean;
|
|
4261
4279
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4262
4280
|
readonly options: {
|
|
4263
4281
|
readonly [x: string]: Schema.Json;
|
|
@@ -4309,6 +4327,7 @@ declare const edaSessionRpc: {
|
|
|
4309
4327
|
readonly name: string;
|
|
4310
4328
|
readonly isFailure: boolean;
|
|
4311
4329
|
readonly result: unknown;
|
|
4330
|
+
readonly providerExecuted: boolean;
|
|
4312
4331
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4313
4332
|
readonly options: {
|
|
4314
4333
|
readonly [x: string]: Schema.Json;
|
|
@@ -4853,6 +4872,7 @@ declare const edaSessionRpc: {
|
|
|
4853
4872
|
readonly toolCallId: string & import("effect/Brand").Brand<"ToolCallId">;
|
|
4854
4873
|
readonly promptPart: {
|
|
4855
4874
|
readonly type: "tool-result";
|
|
4875
|
+
readonly providerExecuted: boolean;
|
|
4856
4876
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4857
4877
|
readonly options: {
|
|
4858
4878
|
readonly [x: string]: Schema.Json;
|
|
@@ -4930,6 +4950,7 @@ declare const edaSessionRpc: {
|
|
|
4930
4950
|
readonly toolCallId: string & import("effect/Brand").Brand<"ToolCallId">;
|
|
4931
4951
|
readonly promptPart: {
|
|
4932
4952
|
readonly type: "tool-result";
|
|
4953
|
+
readonly providerExecuted: boolean;
|
|
4933
4954
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4934
4955
|
readonly options: {
|
|
4935
4956
|
readonly [x: string]: Schema.Json;
|
|
@@ -4977,6 +4998,7 @@ declare const edaSessionRpc: {
|
|
|
4977
4998
|
} | undefined;
|
|
4978
4999
|
readonly promptPart: {
|
|
4979
5000
|
readonly type: "tool-result";
|
|
5001
|
+
readonly providerExecuted: boolean;
|
|
4980
5002
|
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
4981
5003
|
readonly options: {
|
|
4982
5004
|
readonly [x: string]: Schema.Json;
|
|
@@ -6045,6 +6067,7 @@ declare const edaSessionRpc: {
|
|
|
6045
6067
|
readonly name: Schema.String;
|
|
6046
6068
|
readonly isFailure: Schema.Boolean;
|
|
6047
6069
|
readonly result: Schema.Unknown;
|
|
6070
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6048
6071
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6049
6072
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6050
6073
|
}>>;
|
|
@@ -6064,6 +6087,7 @@ declare const edaSessionRpc: {
|
|
|
6064
6087
|
readonly name: Schema.String;
|
|
6065
6088
|
readonly isFailure: Schema.Boolean;
|
|
6066
6089
|
readonly result: Schema.Unknown;
|
|
6090
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6067
6091
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6068
6092
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6069
6093
|
}>>;
|
|
@@ -6082,6 +6106,7 @@ declare const edaSessionRpc: {
|
|
|
6082
6106
|
readonly name: Schema.String;
|
|
6083
6107
|
readonly isFailure: Schema.Boolean;
|
|
6084
6108
|
readonly result: Schema.Unknown;
|
|
6109
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6085
6110
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6086
6111
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6087
6112
|
}>>;
|
|
@@ -6204,6 +6229,7 @@ declare const edaSessionRpc: {
|
|
|
6204
6229
|
readonly name: Schema.String;
|
|
6205
6230
|
readonly isFailure: Schema.Boolean;
|
|
6206
6231
|
readonly result: Schema.Unknown;
|
|
6232
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6207
6233
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6208
6234
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6209
6235
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6256,6 +6282,7 @@ declare const edaSessionRpc: {
|
|
|
6256
6282
|
readonly name: Schema.String;
|
|
6257
6283
|
readonly isFailure: Schema.Boolean;
|
|
6258
6284
|
readonly result: Schema.Unknown;
|
|
6285
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6259
6286
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6260
6287
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6261
6288
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6577,6 +6604,7 @@ declare const edaSessionRpc: {
|
|
|
6577
6604
|
readonly name: Schema.String;
|
|
6578
6605
|
readonly isFailure: Schema.Boolean;
|
|
6579
6606
|
readonly result: Schema.Unknown;
|
|
6607
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6580
6608
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6581
6609
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6582
6610
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6629,6 +6657,7 @@ declare const edaSessionRpc: {
|
|
|
6629
6657
|
readonly name: Schema.String;
|
|
6630
6658
|
readonly isFailure: Schema.Boolean;
|
|
6631
6659
|
readonly result: Schema.Unknown;
|
|
6660
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6632
6661
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6633
6662
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6634
6663
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6775,6 +6804,7 @@ declare const edaSessionRpc: {
|
|
|
6775
6804
|
readonly name: Schema.String;
|
|
6776
6805
|
readonly isFailure: Schema.Boolean;
|
|
6777
6806
|
readonly result: Schema.Unknown;
|
|
6807
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6778
6808
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6779
6809
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6780
6810
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6827,6 +6857,7 @@ declare const edaSessionRpc: {
|
|
|
6827
6857
|
readonly name: Schema.String;
|
|
6828
6858
|
readonly isFailure: Schema.Boolean;
|
|
6829
6859
|
readonly result: Schema.Unknown;
|
|
6860
|
+
readonly providerExecuted: Schema.withDecodingDefault<Schema.Boolean>;
|
|
6830
6861
|
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
6831
6862
|
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
6832
6863
|
}>>, Schema.toType<Schema.Struct<{
|
|
@@ -6901,4 +6932,4 @@ declare const edaSessionRpc: {
|
|
|
6901
6932
|
};
|
|
6902
6933
|
//#endregion
|
|
6903
6934
|
export { SessionOutcomeInput as a, SessionGrantRunInput as i, SessionBlockInput as n, SessionScopedInput as o, SessionCommandInput as r, edaSessionRpc as s, SessionBatchInput as t };
|
|
6904
|
-
//# sourceMappingURL=rpc-spec-
|
|
6935
|
+
//# sourceMappingURL=rpc-spec-C8wknrbN.d.ts.map
|
package/dist/rpc.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as SessionOutcomeInput, i as SessionGrantRunInput, n as SessionBlockInput, o as SessionScopedInput, r as SessionCommandInput, s as edaSessionRpc, t as SessionBatchInput } from "./rpc-spec-
|
|
1
|
+
import { a as SessionOutcomeInput, i as SessionGrantRunInput, n as SessionBlockInput, o as SessionScopedInput, r as SessionCommandInput, s as edaSessionRpc, t as SessionBatchInput } from "./rpc-spec-C8wknrbN.js";
|
|
2
2
|
import { a as encodeEdaRpcDurableEvent, i as encodeEdaRpcCommand, n as decodeEdaRpcCommand, o as encodeEdaRpcSubmittables, r as decodeEdaRpcSubmittables, t as EDARpcSubmittable } from "./rpc-codec-B2aLiNqt.js";
|
|
3
3
|
export { EDARpcSubmittable, SessionBatchInput, SessionBlockInput, SessionCommandInput, SessionGrantRunInput, SessionOutcomeInput, SessionScopedInput, decodeEdaRpcCommand, decodeEdaRpcSubmittables, edaSessionRpc, encodeEdaRpcCommand, encodeEdaRpcDurableEvent, encodeEdaRpcSubmittables };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "effect-durable-agent/services/prompt-projector";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
1
3
|
import * as Effect from "effect/Effect";
|
|
2
4
|
import * as Schema from "effect/Schema";
|
|
3
5
|
import { ContextRebasedPayload, DurableEventEnvelope, SummaryCreatedPayload, assistantMessageCommittedEventType, assistantMessageImportedEventType, assistantPartialCommittedEventType, commandAdmittedEventType, commandCancelledEventType, commandCompletedEventType, commandFailedEventType, commandStartedEventType, contextRebasedEventType, decodeDurableEventSync, effectDurableAgentNamespace, steeringMessageQueuedEventType, summaryCreatedEventType, systemMessageCommittedEventType, userMessageCommittedEventType } from "effect-durable-agent/types/events";
|
|
@@ -6,7 +8,6 @@ import { EDATraceMetadata, makeRootEDATraceMetadata } from "effect-durable-agent
|
|
|
6
8
|
import { EDASessionStore, EDASessionStoreError } from "effect-durable-agent/services/session-store";
|
|
7
9
|
import { EDARuntime } from "effect-durable-agent/services/runtime";
|
|
8
10
|
import { annotateEdaSpan, committedBatchAttributes, compactSpanAttributes, toEdaExternalSpan } from "effect-durable-agent/services/tracing";
|
|
9
|
-
import * as Layer from "effect/Layer";
|
|
10
11
|
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
11
12
|
import { SinkCheckpointStore } from "effect-durable-agent/services/sink-checkpoint-store";
|
|
12
13
|
import * as Cause from "effect/Cause";
|
|
@@ -16,7 +17,6 @@ import { CompactionSummaryArtifact } from "effect-durable-agent/domain/context-p
|
|
|
16
17
|
import { RunSchedulingWakeup } from "effect-durable-agent/services/run-scheduling-wakeup";
|
|
17
18
|
import "effect-durable-agent/services/compaction";
|
|
18
19
|
import { EDAKeepAlive } from "effect-durable-agent/services/keep-alive";
|
|
19
|
-
import "effect-durable-agent/services/prompt-projector";
|
|
20
20
|
import { EDAReducerRegistry } from "effect-durable-agent/services/reducer-registry";
|
|
21
21
|
import { makeEDARuntimeLayer } from "effect-durable-agent/services/runtime-layer";
|
|
22
22
|
import { SessionEventObserver } from "effect-durable-agent/services/session-event-observer";
|
|
@@ -846,12 +846,13 @@ const durableStoreError = (operation, cause) => new EDASessionStoreError({ messa
|
|
|
846
846
|
//#endregion
|
|
847
847
|
//#region src/runtime/runtime-layer.ts
|
|
848
848
|
/** Compose the platform-neutral runtime with Cloudflare persistence and lifecycle adapters. */
|
|
849
|
-
const makeEDADurableObjectRuntimeLayer = ({ appEvents, config, compactionExecutorLayer, compactionPolicyLayer, keepAlive, modelResolverLayer, promptProjectorLayer, reducers, runSchedulerLayer, sessionEventObserverLayer, sessionId, sinks, storage, toolkit, toolRegistry, tracer }) => {
|
|
849
|
+
const makeEDADurableObjectRuntimeLayer = ({ appEvents, config, idGeneratorLayer, compactionExecutorLayer, compactionPolicyLayer, keepAlive, modelResolverLayer, promptProjectorLayer, reducers, runSchedulerLayer, sessionEventObserverLayer, sessionId, sinks, storage, toolkit, toolRegistry, tracer }) => {
|
|
850
850
|
const lifecycle = keepAlive ?? new DurableObjectKeepAlive(storage);
|
|
851
851
|
const keepAliveLayer = EDAKeepAlive.FromAcquire(() => lifecycle.acquire());
|
|
852
852
|
return makeEDARuntimeLayer({
|
|
853
853
|
appEvents,
|
|
854
854
|
config,
|
|
855
|
+
idGeneratorLayer,
|
|
855
856
|
compactionExecutorLayer,
|
|
856
857
|
compactionPolicyLayer,
|
|
857
858
|
keepAliveLayer,
|
|
@@ -936,6 +937,7 @@ var EDASessionRuntime = class {
|
|
|
936
937
|
const runtime = ManagedRuntime.make(makeEDADurableObjectRuntimeLayer({
|
|
937
938
|
appEvents: this.options.appEvents,
|
|
938
939
|
config: this.options.config,
|
|
940
|
+
idGeneratorLayer: this.options.idGeneratorLayer,
|
|
939
941
|
compactionExecutorLayer: this.options.compactionExecutorLayer,
|
|
940
942
|
compactionPolicyLayer: this.options.compactionPolicyLayer,
|
|
941
943
|
keepAlive: this.keepAlive,
|
|
@@ -1460,4 +1462,4 @@ const hostSpanOptions = (trace, attributes) => ({
|
|
|
1460
1462
|
//#endregion
|
|
1461
1463
|
export { EDAWebSocketProjectionId as n, makeEDADurableObjectRuntimeLayer as r, EDASessionController as t };
|
|
1462
1464
|
|
|
1463
|
-
//# sourceMappingURL=session-controller-
|
|
1465
|
+
//# sourceMappingURL=session-controller-BGfz1DdS.js.map
|