@effect-agent/platform-cloudflare 0.1.0-beta.25 → 0.1.0-beta.27
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/browser-quick-action.d.mts +68 -0
- package/dist/browser-quick-action.mjs +303 -0
- package/dist/browser-quick-action.mjs.map +1 -0
- package/dist/index.d.mts +107 -35
- package/dist/index.mjs +43 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -9
- package/src/browser-quick-action.ts +514 -0
- package/src/code-mode-executor.ts +31 -82
- package/src/index.ts +1 -0
- package/src/layers.ts +6 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { BrowserQuickActionBrowserBinding, BrowserQuickActionCaptureOptions, BrowserQuickActionClient, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicy, BrowserQuickActionWorkersAiPolicyError, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer } from "./browser-quick-action.mjs";
|
|
1
2
|
import { Context, Crypto, Effect, Layer, Option, Schema, Scope } from "effect";
|
|
2
3
|
import { AbortCommand, AbortIntent, AdmissionConflict, AgentBindingResolver, AppendConflict, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, CanonicalRecordEnvelope, CanonicalSequence, ConversationNotMaterialized, ConversationStore, ConversationStoreError, DefinitionDigests, DigestError, DurableAgentRuntime, DurableBindingFailure, DurableRuntimeConfig, DurableRuntimeFailpointError, DurableRuntimeFailpointHandler, DurableSubmitAgent, DurableSubmitOptions, DurableWorkerFailure, FenceRejected, IntegrityReport, JoinedToHost, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizerService, OperationDenied, OwnershipLost, ProducerId, Receipt, RecoveryExplanation, RecoveryReport, ResolvedBinding, RetryCommand, RetryRefused, RunJournalError, Settlement, SettlementConflict, SubmissionLedger, ToolReconciler, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, WakeScheduler } from "@effect-agent/session";
|
|
3
4
|
import { ConversationPortTransport, DoStorageFailpointHandler, DoStorageInitializationError, PortRequest, PortResponse } from "@effect-agent/storage-cloudflare";
|
|
4
5
|
import { AgentInputError, ConversationId } from "@effect-agent/core";
|
|
5
|
-
import { RunContextPreparation } from "@effect-agent/engine";
|
|
6
|
+
import { RunContextPreparation, RunCostEstimator } from "@effect-agent/engine";
|
|
6
7
|
import { DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
|
|
7
8
|
import { CodeExecutor, SandboxImplementation } from "@effect-agent/sandbox";
|
|
8
|
-
import { DurableObject as DurableObject$1
|
|
9
|
+
import { DurableObject as DurableObject$1 } from "cloudflare:workers";
|
|
9
10
|
//#region src/bindings.d.ts
|
|
10
11
|
declare const CloudflareBindingError_base: Schema.Class<CloudflareBindingError, Schema.TaggedStruct<"CloudflareBindingError", {
|
|
11
12
|
readonly binding: Schema.String;
|
|
@@ -369,6 +370,8 @@ interface CloudflareDurableRuntimeOptions {
|
|
|
369
370
|
readonly leaseRenewalInterval?: number | undefined;
|
|
370
371
|
/** Milliseconds; default 500. */
|
|
371
372
|
readonly abortPollInterval?: number | undefined;
|
|
373
|
+
/** Deployment-owned pricing authority used by durable cost budgets and settlements. */
|
|
374
|
+
readonly estimateCostMicrousd?: RunCostEstimator | undefined;
|
|
372
375
|
/** Milliseconds; default 25. */
|
|
373
376
|
readonly observationPollInterval?: number | undefined;
|
|
374
377
|
/** Bytes; default just under the 2 MB platform value limit. */
|
|
@@ -644,6 +647,40 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
644
647
|
readonly receiptId: string;
|
|
645
648
|
readonly outcome: "aborted" | "completed" | "failed";
|
|
646
649
|
readonly runDisposition?: Schema.Json | undefined;
|
|
650
|
+
readonly usageSummary?: {
|
|
651
|
+
readonly modelCalls: number;
|
|
652
|
+
readonly inputTokens: {
|
|
653
|
+
readonly total: number;
|
|
654
|
+
readonly uncached: number;
|
|
655
|
+
readonly cacheRead: number;
|
|
656
|
+
readonly cacheWrite: number;
|
|
657
|
+
};
|
|
658
|
+
readonly outputTokens: {
|
|
659
|
+
readonly total: number;
|
|
660
|
+
readonly text: number;
|
|
661
|
+
readonly reasoning: number;
|
|
662
|
+
};
|
|
663
|
+
readonly costMicrousd: number;
|
|
664
|
+
readonly byModel: readonly {
|
|
665
|
+
readonly provider: string;
|
|
666
|
+
readonly model: string;
|
|
667
|
+
readonly serviceTier?: string | undefined;
|
|
668
|
+
readonly pricingVersion?: string | undefined;
|
|
669
|
+
readonly modelCalls: number;
|
|
670
|
+
readonly inputTokens: {
|
|
671
|
+
readonly total: number;
|
|
672
|
+
readonly uncached: number;
|
|
673
|
+
readonly cacheRead: number;
|
|
674
|
+
readonly cacheWrite: number;
|
|
675
|
+
};
|
|
676
|
+
readonly outputTokens: {
|
|
677
|
+
readonly total: number;
|
|
678
|
+
readonly text: number;
|
|
679
|
+
readonly reasoning: number;
|
|
680
|
+
};
|
|
681
|
+
readonly costMicrousd: number;
|
|
682
|
+
}[];
|
|
683
|
+
} | undefined;
|
|
647
684
|
readonly failure?: {
|
|
648
685
|
readonly errorTag: string;
|
|
649
686
|
readonly message: string;
|
|
@@ -688,6 +725,25 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
688
725
|
readonly turn: number;
|
|
689
726
|
readonly messages: Schema.Json;
|
|
690
727
|
readonly messagesDigest: string;
|
|
728
|
+
readonly runScopedPrefixLength?: number | undefined;
|
|
729
|
+
readonly modelUsage?: readonly {
|
|
730
|
+
readonly provider: string;
|
|
731
|
+
readonly model: string;
|
|
732
|
+
readonly serviceTier?: string | undefined;
|
|
733
|
+
readonly pricingVersion?: string | undefined;
|
|
734
|
+
readonly inputTokens: {
|
|
735
|
+
readonly total: number;
|
|
736
|
+
readonly uncached: number;
|
|
737
|
+
readonly cacheRead: number;
|
|
738
|
+
readonly cacheWrite: number;
|
|
739
|
+
};
|
|
740
|
+
readonly outputTokens: {
|
|
741
|
+
readonly total: number;
|
|
742
|
+
readonly text: number;
|
|
743
|
+
readonly reasoning: number;
|
|
744
|
+
};
|
|
745
|
+
readonly costMicrousd: number;
|
|
746
|
+
}[] | undefined;
|
|
691
747
|
readonly inputTokens?: number | undefined;
|
|
692
748
|
readonly outputTokens?: number | undefined;
|
|
693
749
|
readonly costMicrousd?: number | undefined;
|
|
@@ -765,6 +821,9 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
765
821
|
readonly _tag: "RunCompleted";
|
|
766
822
|
readonly runId: string;
|
|
767
823
|
readonly output: Schema.Json;
|
|
824
|
+
readonly runDisposition?: Schema.Json | undefined;
|
|
825
|
+
readonly finishReason?: "budget-exhausted" | undefined;
|
|
826
|
+
readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
|
|
768
827
|
} | {
|
|
769
828
|
readonly _tag: "AbortRequested";
|
|
770
829
|
readonly submissionId: string;
|
|
@@ -782,6 +841,40 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
782
841
|
readonly finishReason?: "budget-exhausted" | undefined;
|
|
783
842
|
readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
|
|
784
843
|
readonly policyLimit?: "cost" | "duration" | "repeated-failures" | "tokens" | "tool-calls" | "turns" | "usage" | undefined;
|
|
844
|
+
readonly usageSummary?: {
|
|
845
|
+
readonly modelCalls: number;
|
|
846
|
+
readonly inputTokens: {
|
|
847
|
+
readonly total: number;
|
|
848
|
+
readonly uncached: number;
|
|
849
|
+
readonly cacheRead: number;
|
|
850
|
+
readonly cacheWrite: number;
|
|
851
|
+
};
|
|
852
|
+
readonly outputTokens: {
|
|
853
|
+
readonly total: number;
|
|
854
|
+
readonly text: number;
|
|
855
|
+
readonly reasoning: number;
|
|
856
|
+
};
|
|
857
|
+
readonly costMicrousd: number;
|
|
858
|
+
readonly byModel: readonly {
|
|
859
|
+
readonly provider: string;
|
|
860
|
+
readonly model: string;
|
|
861
|
+
readonly serviceTier?: string | undefined;
|
|
862
|
+
readonly pricingVersion?: string | undefined;
|
|
863
|
+
readonly modelCalls: number;
|
|
864
|
+
readonly inputTokens: {
|
|
865
|
+
readonly total: number;
|
|
866
|
+
readonly uncached: number;
|
|
867
|
+
readonly cacheRead: number;
|
|
868
|
+
readonly cacheWrite: number;
|
|
869
|
+
};
|
|
870
|
+
readonly outputTokens: {
|
|
871
|
+
readonly total: number;
|
|
872
|
+
readonly text: number;
|
|
873
|
+
readonly reasoning: number;
|
|
874
|
+
};
|
|
875
|
+
readonly costMicrousd: number;
|
|
876
|
+
}[];
|
|
877
|
+
} | undefined;
|
|
785
878
|
} | {
|
|
786
879
|
readonly _tag: "SubagentRequested";
|
|
787
880
|
readonly runId: string;
|
|
@@ -896,6 +989,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
896
989
|
} | {
|
|
897
990
|
readonly _tag: "HostFailed";
|
|
898
991
|
readonly failure: {
|
|
992
|
+
readonly _tag: "AdmissionLimitExceeded";
|
|
993
|
+
readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
|
|
994
|
+
readonly actual: number;
|
|
995
|
+
readonly maximum: number;
|
|
996
|
+
} | {
|
|
899
997
|
readonly _tag: "HostProtocolError";
|
|
900
998
|
readonly message: string;
|
|
901
999
|
} | {
|
|
@@ -957,11 +1055,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
957
1055
|
} | {
|
|
958
1056
|
readonly _tag: "DurableRuntimeFailpointError";
|
|
959
1057
|
readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "claim:after-claim" | "compaction:after-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "resolve:after-intent" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append";
|
|
960
|
-
} | {
|
|
961
|
-
readonly _tag: "AdmissionLimitExceeded";
|
|
962
|
-
readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
|
|
963
|
-
readonly actual: number;
|
|
964
|
-
readonly maximum: number;
|
|
965
1058
|
} | {
|
|
966
1059
|
readonly _tag: "DurableAlarmError";
|
|
967
1060
|
readonly operation: string;
|
|
@@ -1603,45 +1696,24 @@ declare const makeConversationObjectClass: <EventLayerError = never, EventServic
|
|
|
1603
1696
|
* The Cloudflare Dynamic Worker `CodeExecutor` adapter (C4 of ADR-0017;
|
|
1604
1697
|
* DEPLOY-011). Each pass loads one fresh Worker through the Worker Loader
|
|
1605
1698
|
* with `globalOutbound: null`, so generated code has no ambient network,
|
|
1606
|
-
* bindings, or secrets; its only authority is the pass-scoped
|
|
1607
|
-
* routes back
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1611
|
-
*
|
|
1612
|
-
* isolate.
|
|
1699
|
+
* bindings, or secrets; its only authority is the pass-scoped RPC target that
|
|
1700
|
+
* routes back into the owning event's `CodeExecutionHost` service. Platform
|
|
1701
|
+
* CPU limits stop synchronous runaway programs; the executor-owned wall-clock
|
|
1702
|
+
* deadline interrupts asynchronously suspended passes. Deployment class `E`
|
|
1703
|
+
* only: the adapter records no persistent state and a later pass may run in a
|
|
1704
|
+
* completely different isolate.
|
|
1613
1705
|
*/
|
|
1614
1706
|
declare const dynamicWorkerImplementation: SandboxImplementation;
|
|
1615
|
-
/** The narrow host stub the dynamic worker receives (Workers RPC). */
|
|
1616
|
-
interface CodeModeHostStub {
|
|
1617
|
-
readonly call: (passId: string, hostCall: unknown) => Promise<unknown>;
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* The host-side RPC target for dynamic workers. The application exposes it
|
|
1621
|
-
* from its Worker entry (`export { CodeModeHostEntrypoint }`) and hands the
|
|
1622
|
-
* adapter a same-instance stub — `ctx.exports.CodeModeHostEntrypoint()` in
|
|
1623
|
-
* production (a self service binding may reach a different instance and must
|
|
1624
|
-
* not be used there); tests bind it through Miniflare's `kCurrentWorker`.
|
|
1625
|
-
*/
|
|
1626
|
-
declare class CodeModeHostEntrypoint extends WorkerEntrypoint {
|
|
1627
|
-
call(passId: unknown, hostCall: unknown): Promise<unknown>;
|
|
1628
|
-
}
|
|
1629
1707
|
/** Dispose a Cloudflare RPC handle when the runtime supplies its untyped disposal hook. @internal */
|
|
1630
1708
|
declare const disposeRpcHandle: (handle: unknown) => Effect.Effect<void>;
|
|
1631
1709
|
interface DynamicWorkerCodeExecutorOptions {
|
|
1632
1710
|
/** The `worker_loader` binding. */
|
|
1633
1711
|
readonly loader: WorkerLoader;
|
|
1634
|
-
/**
|
|
1635
|
-
* A SAME-INSTANCE stub of `CodeModeHostEntrypoint`. In production create it
|
|
1636
|
-
* with `ctx.exports.CodeModeHostEntrypoint()`; a cross-instance stub would
|
|
1637
|
-
* dispatch host calls into an isolate without this pass's registry entry.
|
|
1638
|
-
*/
|
|
1639
|
-
readonly hostStub: CodeModeHostStub;
|
|
1640
1712
|
/** Compatibility date for dynamic workers; defaults to `2025-05-01`. */
|
|
1641
1713
|
readonly compatibilityDate?: string | undefined;
|
|
1642
1714
|
}
|
|
1643
1715
|
/** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */
|
|
1644
1716
|
declare const dynamicWorkerCodeExecutorLayer: (options: DynamicWorkerCodeExecutorOptions) => Layer.Layer<CodeExecutor>;
|
|
1645
1717
|
//#endregion
|
|
1646
|
-
export { AbortRecorded, AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, ClientAbortFailure, ClientApprovalFailure, ClientAwaitFailure, ClientObserveFailure, ClientProgressFailure, ClientSubmitFailure, ClientUnknownFailure, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareBindingSource, CloudflareBindingSourceContext, CloudflareConversationClient, CloudflareDurableRuntime, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflareDurableRuntimeInitializationError, CloudflareDurableRuntimeOptions, CloudflareDurableRuntimeServices, CloudflarePlatformConfigError, CloudflareRunContextLayer, CloudflareRunContextSource, CloudflareRuntimeSourceContext,
|
|
1718
|
+
export { AbortRecorded, AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, BrowserQuickActionBrowserBinding, BrowserQuickActionCaptureOptions, BrowserQuickActionClient, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicy, BrowserQuickActionWorkersAiPolicyError, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, ClientAbortFailure, ClientApprovalFailure, ClientAwaitFailure, ClientObserveFailure, ClientProgressFailure, ClientSubmitFailure, ClientUnknownFailure, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareBindingSource, CloudflareBindingSourceContext, CloudflareConversationClient, CloudflareDurableRuntime, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflareDurableRuntimeInitializationError, CloudflareDurableRuntimeOptions, CloudflareDurableRuntimeServices, CloudflarePlatformConfigError, CloudflareRunContextLayer, CloudflareRunContextSource, CloudflareRuntimeSourceContext, ConversationClientError, ConversationMaintenance, ConversationMaintenanceFailpoint, ConversationMaintenanceFailpointHandler, ConversationMaintenanceFailpointLocation, ConversationObjectClass, ConversationObjectIdentity, ConversationObjectInstance, ConversationObjectNamespace, ConversationObjectOptions, ConversationObjectPorts, ConversationObjectRpc, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, DynamicWorkerCodeExecutorOptions, ExplainedRecovery, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassFailure, MaintenancePassReport, ObligationsScanned, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, RetryExecuted, SettlementReached, SubmitRequest, SubmitSucceeded, UnknownResolutionRecorded, VerifiedIntegrity, boundHostDiagnostic, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer, cloudflareWakeSchedulerLayer, conversationNamespaceFromEnv, conversationNamespaceLayer, conversationPortTransportLayer, decodeAbortCommand, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObligationThresholds, decodeObservePageRequest, decodeReceipt, decodeRetryCommand, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeAdminResponse, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeConversationObjectClass };
|
|
1647
1719
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BrowserQuickActionBrowserBinding, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicyError, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer } from "./browser-quick-action.mjs";
|
|
1
2
|
import { Clock, Context, Crypto, Deferred, Duration, Effect, Exit, Fiber, Layer, Option, Predicate, PubSub, Queue, Random, Ref, Schema, Semaphore, Stream } from "effect";
|
|
2
3
|
import { AbortCommand, AbortIntent, AdmissionConflict, AgentBindingResolver, AppendConflict, ApprovalConflict, ApprovalDecisionCommand, ApprovalDecisionIntent, CanonicalRecordEnvelope, CanonicalSequence, ConversationNotMaterialized, ConversationRead, ConversationStore, ConversationStoreError, DEFAULT_OWNERSHIP_LEASE_DURATION, DefinitionDigests, DeploymentId, DigestError, DurableAgentRuntime, DurableRuntimeConfig, DurableRuntimeFailpoint, DurableRuntimeFailpointError, FenceRejected, IdempotencyKey, IntegrityReport, JoinedToHost, LedgerError, ObligationReport, ObligationThresholds, OperationAuthorizationRequest, OperationAuthorizer, OperationDenied, OwnershipLost, PersistedJson, Principal, ProducerId, Receipt, RecoveryExplanation, RecoveryReport, RetryCommand, RetryRefused, RunJournalError, Settlement, SettlementConflict, SubmissionLedger, SubmissionLookupByKey, ToolReconciler, UnknownResolutionCommand, UnknownResolutionConflict, UnknownResolutionIntent, WakeScheduler, makeWakeSubscriptionHub, operationAuthorizerLayer } from "@effect-agent/session";
|
|
3
4
|
import { ConversationPortTransport, DEFAULT_MAX_STORED_VALUE_BYTES, conversationStoreLayer, decodePortRequest, encodePortResponse, executePortRequest, portTransportFailure, routedConversationStoreLayer, routedSubmissionLedgerLayer, storageConfigLayer, storageFailpointLayer, submissionLedgerLayer } from "@effect-agent/storage-cloudflare";
|
|
@@ -7,7 +8,7 @@ import { BrowserCrypto } from "@effect/platform-browser";
|
|
|
7
8
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
8
9
|
import { DurableObject, DurableObjectState, WorkerEnvironment } from "effect-cf";
|
|
9
10
|
import { CodeExecutionHost, CodeExecutionProtocolError, CodeExecutionResourceUse, CodeExecutionResult, CodeExecutionTimeoutError, CodeExecutor, CodeExecutorStartError, CodeExecutorTerminatedError, CodeExecutorUnsupportedError, CodeHostCall, CodeHostCallLimitError, CodeHostCallResult, CodeOutputLimitError, CodeProgramFailedError, CodeSourceError, SandboxImplementation } from "@effect-agent/sandbox";
|
|
10
|
-
import {
|
|
11
|
+
import { RpcTarget } from "cloudflare:workers";
|
|
11
12
|
//#region src/bindings.ts
|
|
12
13
|
/**
|
|
13
14
|
* Cloudflare platform bindings as Effect services (DEPLOY-010: "Cloudflare platform bindings
|
|
@@ -754,7 +755,8 @@ var CloudflareDurableRuntime = class {
|
|
|
754
755
|
producerId,
|
|
755
756
|
settlementPollInterval: Duration.millis(config.settlementPollInterval),
|
|
756
757
|
leaseRenewalInterval: Duration.millis(config.leaseRenewalInterval),
|
|
757
|
-
abortPollInterval: Duration.millis(config.abortPollInterval)
|
|
758
|
+
abortPollInterval: Duration.millis(config.abortPollInterval),
|
|
759
|
+
...options.estimateCostMicrousd === void 0 ? {} : { estimateCostMicrousd: options.estimateCostMicrousd }
|
|
758
760
|
}));
|
|
759
761
|
const runtimeFailpointLayer = options.runtimeFailpoint === void 0 ? DurableRuntimeFailpoint.layer : Layer.succeed(DurableRuntimeFailpoint)({ hit: options.runtimeFailpoint(ctx) });
|
|
760
762
|
const maintenanceFailpointLayer = options.maintenanceFailpoint === void 0 ? ConversationMaintenanceFailpoint.layer : Layer.succeed(ConversationMaintenanceFailpoint)({ hit: options.maintenanceFailpoint(ctx) });
|
|
@@ -1386,37 +1388,32 @@ const makeConversationObjectClass = (options, observability) => {
|
|
|
1386
1388
|
* The Cloudflare Dynamic Worker `CodeExecutor` adapter (C4 of ADR-0017;
|
|
1387
1389
|
* DEPLOY-011). Each pass loads one fresh Worker through the Worker Loader
|
|
1388
1390
|
* with `globalOutbound: null`, so generated code has no ambient network,
|
|
1389
|
-
* bindings, or secrets; its only authority is the pass-scoped
|
|
1390
|
-
* routes back
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
*
|
|
1394
|
-
*
|
|
1395
|
-
* isolate.
|
|
1391
|
+
* bindings, or secrets; its only authority is the pass-scoped RPC target that
|
|
1392
|
+
* routes back into the owning event's `CodeExecutionHost` service. Platform
|
|
1393
|
+
* CPU limits stop synchronous runaway programs; the executor-owned wall-clock
|
|
1394
|
+
* deadline interrupts asynchronously suspended passes. Deployment class `E`
|
|
1395
|
+
* only: the adapter records no persistent state and a later pass may run in a
|
|
1396
|
+
* completely different isolate.
|
|
1396
1397
|
*/
|
|
1397
1398
|
const dynamicWorkerImplementation = SandboxImplementation.make({
|
|
1398
1399
|
isolation: "isolated",
|
|
1399
1400
|
identity: "cloudflare-dynamic-worker"
|
|
1400
1401
|
});
|
|
1401
1402
|
/**
|
|
1402
|
-
*
|
|
1403
|
-
*
|
|
1404
|
-
* `
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
/**
|
|
1408
|
-
* The host-side RPC target for dynamic workers. The application exposes it
|
|
1409
|
-
* from its Worker entry (`export { CodeModeHostEntrypoint }`) and hands the
|
|
1410
|
-
* adapter a same-instance stub — `ctx.exports.CodeModeHostEntrypoint()` in
|
|
1411
|
-
* production (a self service binding may reach a different instance and must
|
|
1412
|
-
* not be used there); tests bind it through Miniflare's `kCurrentWorker`.
|
|
1403
|
+
* One object-capability endpoint for one execution pass. Workers RPC invokes
|
|
1404
|
+
* the target in the request context where it was created, so the native
|
|
1405
|
+
* Promise returned by `dispatch` and the Effect fiber that settles it share
|
|
1406
|
+
* one I/O owner. Passing the target as `run()`'s argument also scopes the
|
|
1407
|
+
* remote stub to that RPC call; no request state lives at module scope.
|
|
1413
1408
|
*/
|
|
1414
|
-
var
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1409
|
+
var CodeModePassHostTarget = class extends RpcTarget {
|
|
1410
|
+
#dispatch;
|
|
1411
|
+
constructor(dispatch) {
|
|
1412
|
+
super();
|
|
1413
|
+
this.#dispatch = dispatch;
|
|
1414
|
+
}
|
|
1415
|
+
call(hostCall) {
|
|
1416
|
+
return this.#dispatch(hostCall);
|
|
1420
1417
|
}
|
|
1421
1418
|
};
|
|
1422
1419
|
/**
|
|
@@ -1451,9 +1448,8 @@ const safeJson = (value) => {
|
|
|
1451
1448
|
};
|
|
1452
1449
|
|
|
1453
1450
|
export default class CodeModeHarness extends WorkerEntrypoint {
|
|
1454
|
-
async run() {
|
|
1451
|
+
async run(host) {
|
|
1455
1452
|
const config = this.env.CODE_MODE_PASS;
|
|
1456
|
-
const host = this.env.CODE_MODE_HOST;
|
|
1457
1453
|
const limits = config.limits;
|
|
1458
1454
|
const logs = [];
|
|
1459
1455
|
let logBytes = 0;
|
|
@@ -1491,7 +1487,7 @@ export default class CodeModeHarness extends WorkerEntrypoint {
|
|
|
1491
1487
|
};
|
|
1492
1488
|
throw new Error("code-mode host-call argument limit exceeded");
|
|
1493
1489
|
}
|
|
1494
|
-
const outcome = await host.call(
|
|
1490
|
+
const outcome = await host.call({
|
|
1495
1491
|
namespace,
|
|
1496
1492
|
method,
|
|
1497
1493
|
argument: JSON.parse(argText),
|
|
@@ -1616,7 +1612,6 @@ const HarnessOutcome = Schema.Union([
|
|
|
1616
1612
|
HarnessProtocol
|
|
1617
1613
|
]);
|
|
1618
1614
|
const HarnessPassConfig = Schema.Struct({
|
|
1619
|
-
passId: Schema.NonEmptyString,
|
|
1620
1615
|
namespaces: Schema.Array(Schema.Struct({
|
|
1621
1616
|
name: Schema.NonEmptyString,
|
|
1622
1617
|
methods: Schema.Array(Schema.NonEmptyString).check(Schema.isMaxLength(64))
|
|
@@ -1684,7 +1679,7 @@ const utf8ByteLength = (value) => {
|
|
|
1684
1679
|
};
|
|
1685
1680
|
/** Reserved global names the harness owns inside the dynamic worker. */
|
|
1686
1681
|
const reservedHarnessGlobals = /* @__PURE__ */ new Set(["console"]);
|
|
1687
|
-
const makeExecute = (options,
|
|
1682
|
+
const makeExecute = (options, clock) => Effect.fn("DynamicWorkerCodeExecutor.execute")(function* (request) {
|
|
1688
1683
|
if (request.network._tag !== "NetworkDisabled") return yield* CodeExecutorUnsupportedError.make({
|
|
1689
1684
|
implementation: dynamicWorkerImplementation,
|
|
1690
1685
|
feature: "network",
|
|
@@ -1702,11 +1697,6 @@ const makeExecute = (options, crypto, clock) => Effect.fn("DynamicWorkerCodeExec
|
|
|
1702
1697
|
message: `Namespace ${namespace.name} collides with a harness binding`
|
|
1703
1698
|
});
|
|
1704
1699
|
const host = yield* CodeExecutionHost;
|
|
1705
|
-
const passId = yield* crypto.randomUUIDv4.pipe(Effect.mapError((cause) => CodeExecutorStartError.make({
|
|
1706
|
-
implementation: dynamicWorkerImplementation,
|
|
1707
|
-
message: `Could not mint the Code Mode pass identity: ${safeCauseMessage(cause, "the crypto service failed without a diagnostic")}`.slice(0, 8e3),
|
|
1708
|
-
cause
|
|
1709
|
-
})), Effect.map((uuid) => `code-mode-pass-${uuid}`));
|
|
1710
1700
|
const startedAt = clock.monotonicTimeNanosUnsafe();
|
|
1711
1701
|
const passDeadline = startedAt + Duration.toNanosUnsafe(request.limits.maxWallTime);
|
|
1712
1702
|
const remainingPassWallTime = () => {
|
|
@@ -1821,12 +1811,9 @@ const makeExecute = (options, crypto, clock) => Effect.fn("DynamicWorkerCodeExec
|
|
|
1821
1811
|
};
|
|
1822
1812
|
const closeAdmission = Effect.sync(() => {
|
|
1823
1813
|
passOpen = false;
|
|
1824
|
-
passRegistry.delete(passId);
|
|
1825
1814
|
rejectQueuedHostCalls(/* @__PURE__ */ new Error("Code Mode pass is closing"));
|
|
1826
1815
|
});
|
|
1827
|
-
yield* Effect.
|
|
1828
|
-
passRegistry.set(passId, { dispatch });
|
|
1829
|
-
}), () => closeAdmission.pipe(Effect.andThen(Fiber.interrupt(server))));
|
|
1816
|
+
yield* Effect.addFinalizer(() => closeAdmission.pipe(Effect.andThen(Fiber.interrupt(server))));
|
|
1830
1817
|
const workerCode = {
|
|
1831
1818
|
compatibilityDate: options.compatibilityDate ?? "2025-05-01",
|
|
1832
1819
|
mainModule: "harness.js",
|
|
@@ -1834,22 +1821,18 @@ const makeExecute = (options, crypto, clock) => Effect.fn("DynamicWorkerCodeExec
|
|
|
1834
1821
|
"harness.js": HARNESS_MODULE,
|
|
1835
1822
|
"program.js": `export default (\n${request.source}\n);`
|
|
1836
1823
|
},
|
|
1837
|
-
env: {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
maxHostCallArgumentBytes: request.limits.maxHostCallArgumentBytes
|
|
1850
|
-
}
|
|
1851
|
-
})
|
|
1852
|
-
},
|
|
1824
|
+
env: { CODE_MODE_PASS: encodeHarnessPassConfig({
|
|
1825
|
+
namespaces: request.namespaces.map((namespace) => ({
|
|
1826
|
+
name: namespace.name,
|
|
1827
|
+
methods: namespace.methods
|
|
1828
|
+
})),
|
|
1829
|
+
limits: {
|
|
1830
|
+
maxLogBytes: request.limits.maxLogBytes,
|
|
1831
|
+
maxResultBytes: request.limits.maxResultBytes,
|
|
1832
|
+
maxHostCalls: request.limits.maxHostCalls,
|
|
1833
|
+
maxHostCallArgumentBytes: request.limits.maxHostCallArgumentBytes
|
|
1834
|
+
}
|
|
1835
|
+
}) },
|
|
1853
1836
|
globalOutbound: null,
|
|
1854
1837
|
...request.limits.cpuMillis === void 0 ? {} : { limits: {
|
|
1855
1838
|
cpuMs: request.limits.cpuMillis,
|
|
@@ -1877,7 +1860,7 @@ const makeExecute = (options, crypto, clock) => Effect.fn("DynamicWorkerCodeExec
|
|
|
1877
1860
|
catch: (cause) => classifyWorkerFailure(cause, request.limits.maxWallTime)
|
|
1878
1861
|
}), disposeRpcHandle);
|
|
1879
1862
|
const rpc = Effect.tryPromise({
|
|
1880
|
-
try: () => entrypoint.run(),
|
|
1863
|
+
try: () => entrypoint.run(new CodeModePassHostTarget(dispatch)),
|
|
1881
1864
|
catch: (cause) => classifyWorkerFailure(cause, request.limits.maxWallTime)
|
|
1882
1865
|
});
|
|
1883
1866
|
const exit = yield* Effect.raceFirst(rpc.pipe(Effect.timeoutOrElse({
|
|
@@ -1991,11 +1974,10 @@ const classifyWorkerFailure = (cause, maxWallTime) => {
|
|
|
1991
1974
|
};
|
|
1992
1975
|
/** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */
|
|
1993
1976
|
const dynamicWorkerCodeExecutorLayer = (options) => Layer.effect(CodeExecutor, Effect.gen(function* () {
|
|
1994
|
-
const crypto = yield* Crypto.Crypto;
|
|
1995
1977
|
const clock = yield* Clock.Clock;
|
|
1996
|
-
return CodeExecutor.of({ execute: makeExecute(options,
|
|
1997
|
-
}))
|
|
1978
|
+
return CodeExecutor.of({ execute: makeExecute(options, clock) });
|
|
1979
|
+
}));
|
|
1998
1980
|
//#endregion
|
|
1999
|
-
export { AbortRecorded, AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareConversationClient, CloudflareDurableRuntime, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError,
|
|
1981
|
+
export { AbortRecorded, AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, AdmissionLimitExceeded, ApprovalRecorded, AwaitProgressRequest, BrowserQuickActionBrowserBinding, BrowserQuickActionRpcError, BrowserQuickActionWorkersAi, BrowserQuickActionWorkersAiPolicyError, CLOUDFLARE_DATABASE_CAP_BYTES, CLOUDFLARE_RUNTIME_DEFAULTS, CancelProgressRequest, CloudflareAdmissionLimitsValue, CloudflareBindingError, CloudflareConversationClient, CloudflareDurableRuntime, CloudflareDurableRuntimeConfig, CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError, ConversationClientError, ConversationMaintenance, ConversationMaintenanceFailpoint, ConversationObjectIdentity, ConversationObjectNamespace, ConversationObjectPorts, DEFAULT_MAX_DATABASE_BYTES, DurableAlarmError, DurableAlarmService, DurableObjectContext, ExplainedRecovery, HostFailed, HostFailure, HostProtocolError, HostResponse, MaintenancePassReport, ObligationsScanned, ObservePageRequest, ObservedPage, ProgressCancelled, ProgressObserved, ProgressWaitRegistry, RetryExecuted, SettlementReached, SubmitRequest, SubmitSucceeded, UnknownResolutionRecorded, VerifiedIntegrity, boundHostDiagnostic, browserQuickActionCaptureLayer, browserQuickActionImplementation, browserQuickActionWorkersAiCaptureLayer, cloudflareWakeSchedulerLayer, conversationNamespaceFromEnv, conversationNamespaceLayer, conversationPortTransportLayer, decodeAbortCommand, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObligationThresholds, decodeObservePageRequest, decodeReceipt, decodeRetryCommand, decodeSubmitRequest, decodeUnknownResolutionCommand, disposeRpcHandle, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeAdminResponse, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeConversationObjectClass };
|
|
2000
1982
|
|
|
2001
1983
|
//# sourceMappingURL=index.mjs.map
|