effect-durable-agent-cloudflare 0.1.0-alpha.9 → 0.1.0
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 +5 -2
- package/dist/anthropic.d.ts +44 -0
- package/dist/anthropic.js +66 -0
- package/dist/anthropic.js.map +1 -0
- package/dist/durable-object-DAQzdio7.js +622 -0
- package/dist/durable-object-DAQzdio7.js.map +1 -0
- package/dist/durable-object-storage-Dec6HWQ9.d.ts +136 -0
- package/dist/durable-object-store-yY_KaFtw.js +1231 -0
- package/dist/durable-object-store-yY_KaFtw.js.map +1 -0
- package/dist/durable-object.d.ts +2352 -55
- package/dist/durable-object.js +2 -193
- package/dist/index.d.ts +227 -6
- package/dist/index.js +6 -5
- package/dist/openai.d.ts +10 -5
- 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-codec-B2aLiNqt.d.ts +44 -0
- package/dist/rpc-spec-BRNFIsY1.js +407 -0
- package/dist/rpc-spec-BRNFIsY1.js.map +1 -0
- package/dist/rpc-spec-O5conxmN.d.ts +8888 -0
- package/dist/rpc.d.ts +3 -16
- package/dist/rpc.js +2 -26
- package/dist/{session-controller-COHH8vA6.js → session-controller-BCtnyAEw.js} +689 -657
- package/dist/session-controller-BCtnyAEw.js.map +1 -0
- package/dist/{session-controller-Dp07FnPn.d.ts → session-controller-BZaYmBLr.d.ts} +107 -32
- package/dist/session-controller.d.ts +1 -1
- package/dist/session-controller.js +1 -1
- package/dist/storage.d.ts +1 -1
- package/dist/transport-BzgK07l4.js +205 -0
- package/dist/transport-BzgK07l4.js.map +1 -0
- package/package.json +29 -11
- package/dist/durable-object-storage-DCL2IyUe.d.ts +0 -41
- package/dist/durable-object.js.map +0 -1
- package/dist/rpc.js.map +0 -1
- package/dist/session-controller-COHH8vA6.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Cloudflare Durable Objects host for [`effect-durable-agent`](../effect-durable-a
|
|
|
5
5
|
Executable examples live in the repository's shared [`examples`](../../examples) directory.
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
pnpm add effect-durable-agent
|
|
8
|
+
pnpm add effect-durable-agent effect-durable-agent-cloudflare
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
```ts
|
|
@@ -36,7 +36,10 @@ request with `EDA_WEB_SOCKET_PROJECTION_HEADER`; the Durable Object still owns
|
|
|
36
36
|
the accepted socket and persists the app projection state through hibernation.
|
|
37
37
|
Do not build a Worker-side WebSocket bridge for protocol translation.
|
|
38
38
|
|
|
39
|
-
Durable Object RPC uses structured clone.
|
|
39
|
+
Durable Object RPC uses structured clone. `edaSessionRpc` exports the input and output
|
|
40
|
+
Schemas for each session method. Public methods accept each input Schema's `Encoded`
|
|
41
|
+
type and return encoded outputs; callers decode responses with the output Schema.
|
|
42
|
+
Snapshot Maps and existing wire fields remain unchanged. Encode Schema class instances before
|
|
40
43
|
passing commands or batches across the Worker-to-object boundary with
|
|
41
44
|
`encodeEdaRpcCommand` or `encodeEdaRpcSubmittables`.
|
|
42
45
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AnthropicClient, AnthropicLanguageModel } from "@effect/ai-anthropic";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Prompt from "effect/ai/Prompt";
|
|
4
|
+
//#region src/providers/anthropic.d.ts
|
|
5
|
+
/** Anthropic request defaults for one resolved model (everything but `model`). */
|
|
6
|
+
type EDAAnthropicModelConfig = Omit<typeof AnthropicLanguageModel.Config.Service, "model">;
|
|
7
|
+
/** Shared Anthropic transport and client options. */
|
|
8
|
+
interface EDAAnthropicClientOptions {
|
|
9
|
+
/** Cloudflare AI Gateway binding. With a gateway-stored key (BYOK) no `apiKey` is needed. */
|
|
10
|
+
readonly aiGateway?: AiGateway | undefined;
|
|
11
|
+
readonly apiKey?: string | undefined;
|
|
12
|
+
readonly apiUrl?: string | undefined;
|
|
13
|
+
/** Beta flags sent on every request, e.g. `thinking-binding-controls-2026-08-01`. */
|
|
14
|
+
readonly betas?: ReadonlyArray<string> | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Anthropic client layer over EDA's provider transport. */
|
|
17
|
+
declare const makeEDAAnthropicClientLayer: (options: EDAAnthropicClientOptions) => Layer.Layer<AnthropicClient.AnthropicClient>;
|
|
18
|
+
/** Beta that lets requests choose what happens to thinking bound to an edited conversation. */
|
|
19
|
+
declare const ANTHROPIC_THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
|
|
20
|
+
/** Agent request policy for Claude 5.5-generation models. */
|
|
21
|
+
interface EDAAnthropicAgentSettings {
|
|
22
|
+
/** Thinking depth; Opus 5.5 cannot disable thinking, so effort is the only control. */
|
|
23
|
+
readonly effort: "low" | "medium" | "high";
|
|
24
|
+
/** Output budget including thinking. Defaults to 64,000. */
|
|
25
|
+
readonly maxTokens?: number | undefined;
|
|
26
|
+
/** `summarized` streams readable reasoning summaries. Defaults to `summarized`. */
|
|
27
|
+
readonly thinkingDisplay?: "summarized" | "omitted" | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Explicit preserved-thinking policy (requires {@link ANTHROPIC_THINKING_BINDING_BETA}).
|
|
30
|
+
* `drop_block` degrades instead of failing when replayed thinking no longer matches.
|
|
31
|
+
*/
|
|
32
|
+
readonly prefixMismatchBehavior?: "error" | "drop_block" | undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Model config for EDA agent sessions on Anthropic. */
|
|
35
|
+
declare const anthropicAgentModelConfig: (settings: EDAAnthropicAgentSettings) => EDAAnthropicModelConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Anthropic prompt preparation: EDA cache hints become `cache_control` breakpoints (end of the
|
|
38
|
+
* instruction prefix and end of durable history), and Anthropic compaction summaries become the
|
|
39
|
+
* transport sentinel that is replayed as the signed `compaction` block.
|
|
40
|
+
*/
|
|
41
|
+
declare const prepareEDAAnthropicPrompt: (prompt: Prompt.Prompt) => Prompt.Prompt;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ANTHROPIC_THINKING_BINDING_BETA, EDAAnthropicAgentSettings, EDAAnthropicClientOptions, EDAAnthropicModelConfig, anthropicAgentModelConfig, makeEDAAnthropicClientLayer, prepareEDAAnthropicPrompt };
|
|
44
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { i as prepareNativeCompaction, r as makeEDAProviderHttpClient } from "./transport-BzgK07l4.js";
|
|
2
|
+
import { AnthropicClient } from "@effect/ai-anthropic";
|
|
3
|
+
import { isEDACacheBreakpoint } from "effect-durable-agent/services/prompt-projector";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
import * as Prompt from "effect/ai/Prompt";
|
|
7
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
8
|
+
//#region src/providers/anthropic.ts
|
|
9
|
+
/** Anthropic client layer over EDA's provider transport. */
|
|
10
|
+
const makeEDAAnthropicClientLayer = (options) => {
|
|
11
|
+
const apiKey = optionalNonEmptyString(options.apiKey);
|
|
12
|
+
if (apiKey === void 0 && options.aiGateway === void 0) throw new Error("ANTHROPIC_API_KEY is required unless Anthropic traffic goes through a Cloudflare AI Gateway binding with a stored key.");
|
|
13
|
+
return AnthropicClient.layer({
|
|
14
|
+
...apiKey === void 0 ? {} : { apiKey: Redacted.make(apiKey) },
|
|
15
|
+
...options.apiUrl === void 0 ? {} : { apiUrl: options.apiUrl }
|
|
16
|
+
}).pipe(Layer.provide(Layer.succeed(HttpClient.HttpClient, makeEDAProviderHttpClient({
|
|
17
|
+
provider: "anthropic",
|
|
18
|
+
aiGateway: options.aiGateway,
|
|
19
|
+
anthropicBetas: options.betas
|
|
20
|
+
}))));
|
|
21
|
+
};
|
|
22
|
+
/** Beta that lets requests choose what happens to thinking bound to an edited conversation. */
|
|
23
|
+
const ANTHROPIC_THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";
|
|
24
|
+
/** Model config for EDA agent sessions on Anthropic. */
|
|
25
|
+
const anthropicAgentModelConfig = (settings) => {
|
|
26
|
+
const thinking = {
|
|
27
|
+
type: "adaptive",
|
|
28
|
+
display: settings.thinkingDisplay ?? "summarized",
|
|
29
|
+
...settings.prefixMismatchBehavior === void 0 ? {} : { block_binding: { prefix_mismatch_behavior: settings.prefixMismatchBehavior } }
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
max_tokens: settings.maxTokens ?? 64e3,
|
|
33
|
+
output_config: { effort: settings.effort },
|
|
34
|
+
thinking,
|
|
35
|
+
strictJsonSchema: false
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Anthropic prompt preparation: EDA cache hints become `cache_control` breakpoints (end of the
|
|
40
|
+
* instruction prefix and end of durable history), and Anthropic compaction summaries become the
|
|
41
|
+
* transport sentinel that is replayed as the signed `compaction` block.
|
|
42
|
+
*/
|
|
43
|
+
const prepareEDAAnthropicPrompt = (prompt) => prepareNativeCompaction("anthropic", Prompt.fromMessages(prompt.content.map((message) => isEDACacheBreakpoint(message) ? withMessageOptions(message, { anthropic: {
|
|
44
|
+
...anthropicOptions(message.options),
|
|
45
|
+
cacheControl: { type: "ephemeral" }
|
|
46
|
+
} }) : message)));
|
|
47
|
+
const anthropicOptions = (options) => {
|
|
48
|
+
const current = options.anthropic;
|
|
49
|
+
return isJsonObject(current) ? current : {};
|
|
50
|
+
};
|
|
51
|
+
const isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
52
|
+
const withMessageOptions = (message, options) => ({
|
|
53
|
+
...message,
|
|
54
|
+
options: {
|
|
55
|
+
...message.options,
|
|
56
|
+
...options
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const optionalNonEmptyString = (value) => {
|
|
60
|
+
const trimmed = value?.trim();
|
|
61
|
+
return trimmed === void 0 || trimmed.length === 0 ? void 0 : trimmed;
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ANTHROPIC_THINKING_BINDING_BETA, anthropicAgentModelConfig, makeEDAAnthropicClientLayer, prepareEDAAnthropicPrompt };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","names":[],"sources":["../src/providers/anthropic.ts"],"sourcesContent":["import { AnthropicClient, AnthropicLanguageModel } from \"@effect/ai-anthropic\";\nimport { isEDACacheBreakpoint } from \"effect-durable-agent/services/prompt-projector\";\nimport * as Layer from \"effect/Layer\";\nimport * as Redacted from \"effect/Redacted\";\nimport type * as Schema from \"effect/Schema\";\nimport * as Prompt from \"effect/ai/Prompt\";\nimport * as HttpClient from \"effect/http/HttpClient\";\n\nimport { makeEDAProviderHttpClient, prepareNativeCompaction } from \"./transport\";\n\n/** Anthropic request defaults for one resolved model (everything but `model`). */\nexport type EDAAnthropicModelConfig = Omit<typeof AnthropicLanguageModel.Config.Service, \"model\">;\n\n/** Shared Anthropic transport and client options. */\nexport interface EDAAnthropicClientOptions {\n /** Cloudflare AI Gateway binding. With a gateway-stored key (BYOK) no `apiKey` is needed. */\n readonly aiGateway?: AiGateway | undefined;\n readonly apiKey?: string | undefined;\n readonly apiUrl?: string | undefined;\n /** Beta flags sent on every request, e.g. `thinking-binding-controls-2026-08-01`. */\n readonly betas?: ReadonlyArray<string> | undefined;\n}\n\n/** Anthropic client layer over EDA's provider transport. */\nexport const makeEDAAnthropicClientLayer = (\n options: EDAAnthropicClientOptions,\n): Layer.Layer<AnthropicClient.AnthropicClient> => {\n const apiKey = optionalNonEmptyString(options.apiKey);\n if (apiKey === undefined && options.aiGateway === undefined) {\n throw new Error(\n \"ANTHROPIC_API_KEY is required unless Anthropic traffic goes through a Cloudflare AI Gateway binding with a stored key.\",\n );\n }\n return AnthropicClient.layer({\n ...(apiKey === undefined ? {} : { apiKey: Redacted.make(apiKey) }),\n ...(options.apiUrl === undefined ? {} : { apiUrl: options.apiUrl }),\n }).pipe(\n Layer.provide(\n Layer.succeed(\n HttpClient.HttpClient,\n makeEDAProviderHttpClient({\n provider: \"anthropic\",\n aiGateway: options.aiGateway,\n anthropicBetas: options.betas,\n }),\n ),\n ),\n );\n};\n\n/** Beta that lets requests choose what happens to thinking bound to an edited conversation. */\nexport const ANTHROPIC_THINKING_BINDING_BETA = \"thinking-binding-controls-2026-08-01\";\n\n/** Agent request policy for Claude 5.5-generation models. */\nexport interface EDAAnthropicAgentSettings {\n /** Thinking depth; Opus 5.5 cannot disable thinking, so effort is the only control. */\n readonly effort: \"low\" | \"medium\" | \"high\";\n /** Output budget including thinking. Defaults to 64,000. */\n readonly maxTokens?: number | undefined;\n /** `summarized` streams readable reasoning summaries. Defaults to `summarized`. */\n readonly thinkingDisplay?: \"summarized\" | \"omitted\" | undefined;\n /**\n * Explicit preserved-thinking policy (requires {@link ANTHROPIC_THINKING_BINDING_BETA}).\n * `drop_block` degrades instead of failing when replayed thinking no longer matches.\n */\n readonly prefixMismatchBehavior?: \"error\" | \"drop_block\" | undefined;\n}\n\n/** Model config for EDA agent sessions on Anthropic. */\nexport const anthropicAgentModelConfig = (\n settings: EDAAnthropicAgentSettings,\n): EDAAnthropicModelConfig => {\n const thinking = {\n type: \"adaptive\" as const,\n display: settings.thinkingDisplay ?? \"summarized\",\n ...(settings.prefixMismatchBehavior === undefined\n ? {}\n : { block_binding: { prefix_mismatch_behavior: settings.prefixMismatchBehavior } }),\n };\n const config: EDAAnthropicModelConfig = {\n max_tokens: settings.maxTokens ?? 64_000,\n output_config: { effort: settings.effort },\n thinking,\n // EDA tool schemas are not written for strict mode's constraints.\n strictJsonSchema: false,\n };\n return config;\n};\n\n/**\n * Anthropic prompt preparation: EDA cache hints become `cache_control` breakpoints (end of the\n * instruction prefix and end of durable history), and Anthropic compaction summaries become the\n * transport sentinel that is replayed as the signed `compaction` block.\n */\nexport const prepareEDAAnthropicPrompt = (prompt: Prompt.Prompt): Prompt.Prompt =>\n prepareNativeCompaction(\n \"anthropic\",\n Prompt.fromMessages(\n prompt.content.map((message) =>\n isEDACacheBreakpoint(message)\n ? withMessageOptions(message, {\n anthropic: {\n ...anthropicOptions(message.options),\n cacheControl: { type: \"ephemeral\" },\n },\n })\n : message,\n ),\n ),\n );\n\nconst anthropicOptions = (\n options: Prompt.ProviderOptions,\n): Readonly<Record<string, Schema.Json>> => {\n const current = options.anthropic;\n return isJsonObject(current) ? current : {};\n};\n\nconst isJsonObject = (\n value: Schema.Json | null | undefined,\n): value is Readonly<Record<string, Schema.Json>> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst withMessageOptions = (\n message: Prompt.Message,\n options: Prompt.ProviderOptions,\n): Prompt.Message => ({ ...message, options: { ...message.options, ...options } });\n\nconst optionalNonEmptyString = (value: string | undefined): string | undefined => {\n const trimmed = value?.trim();\n return trimmed === undefined || trimmed.length === 0 ? undefined : trimmed;\n};\n"],"mappings":";;;;;;;;;AAwBA,MAAa,+BACX,YACiD;CACjD,MAAM,SAAS,uBAAuB,QAAQ,MAAM;CACpD,IAAI,WAAW,KAAA,KAAa,QAAQ,cAAc,KAAA,GAChD,MAAM,IAAI,MACR,wHACF;CAEF,OAAO,gBAAgB,MAAM;EAC3B,GAAI,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,SAAS,KAAK,MAAM,EAAE;EAChE,GAAI,QAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;CACnE,CAAC,CAAC,CAAC,KACD,MAAM,QACJ,MAAM,QACJ,WAAW,YACX,0BAA0B;EACxB,UAAU;EACV,WAAW,QAAQ;EACnB,gBAAgB,QAAQ;CAC1B,CAAC,CACH,CACF,CACF;AACF;;AAGA,MAAa,kCAAkC;;AAkB/C,MAAa,6BACX,aAC4B;CAC5B,MAAM,WAAW;EACf,MAAM;EACN,SAAS,SAAS,mBAAmB;EACrC,GAAI,SAAS,2BAA2B,KAAA,IACpC,CAAC,IACD,EAAE,eAAe,EAAE,0BAA0B,SAAS,uBAAuB,EAAE;CACrF;CAQA,OAAO;EANL,YAAY,SAAS,aAAa;EAClC,eAAe,EAAE,QAAQ,SAAS,OAAO;EACzC;EAEA,kBAAkB;CAER;AACd;;;;;;AAOA,MAAa,6BAA6B,WACxC,wBACE,aACA,OAAO,aACL,OAAO,QAAQ,KAAK,YAClB,qBAAqB,OAAO,IACxB,mBAAmB,SAAS,EAC1B,WAAW;CACT,GAAG,iBAAiB,QAAQ,OAAO;CACnC,cAAc,EAAE,MAAM,YAAY;AACpC,EACF,CAAC,IACD,OACN,CACF,CACF;AAEF,MAAM,oBACJ,YAC0C;CAC1C,MAAM,UAAU,QAAQ;CACxB,OAAO,aAAa,OAAO,IAAI,UAAU,CAAC;AAC5C;AAEA,MAAM,gBACJ,UAEA,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAErE,MAAM,sBACJ,SACA,aACoB;CAAE,GAAG;CAAS,SAAS;EAAE,GAAG,QAAQ;EAAS,GAAG;CAAQ;AAAE;AAEhF,MAAM,0BAA0B,UAAkD;CAChF,MAAM,UAAU,OAAO,KAAK;CAC5B,OAAO,YAAY,KAAA,KAAa,QAAQ,WAAW,IAAI,KAAA,IAAY;AACrE"}
|