@effect-agent/platform-cloudflare 0.1.0-beta.18 → 0.1.0-beta.19

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/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { Context, Crypto, Effect, Layer, Option, Schema, Scope } from "effect";
2
2
  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
3
  import { ConversationPortTransport, DoStorageFailpointHandler, DoStorageInitializationError } from "@effect-agent/storage-cloudflare";
4
4
  import { AgentInputError, ConversationId } from "@effect-agent/core";
5
+ import { RunContextPreparation } from "@effect-agent/engine";
5
6
  import { DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
6
7
  import { CodeExecutor, SandboxImplementation } from "@effect-agent/sandbox";
7
8
  import { DurableObject as DurableObject$1, WorkerEntrypoint } from "cloudflare:workers";
@@ -406,19 +407,31 @@ interface CloudflareDurableRuntimeOptions {
406
407
  * to the empty registration (every resolved claim fails closed).
407
408
  */
408
409
  readonly bindings?: CloudflareBindingSource | undefined;
410
+ /**
411
+ * Generic model-context preparation acquired with this Durable Object incarnation. The Layer
412
+ * may depend only on `Crypto.Crypto`, which this platform supplies with `BrowserCrypto`; hosts
413
+ * must close every application-specific service before passing it here. Default absent.
414
+ */
415
+ readonly runContext?: CloudflareRunContextSource | undefined;
409
416
  }
410
- /** Per-incarnation host values available while registered worker Bindings are captured. */
411
- interface CloudflareBindingSourceContext {
417
+ /** Per-incarnation host values available to Effect-native runtime extension factories. */
418
+ interface CloudflareRuntimeSourceContext {
412
419
  readonly ctx: DurableObjectState;
413
420
  readonly env: unknown;
414
421
  readonly conversationId: ConversationId;
415
422
  readonly producerId: ProducerId;
416
423
  }
424
+ /** Per-incarnation host values available while registered worker Bindings are captured. */
425
+ interface CloudflareBindingSourceContext extends CloudflareRuntimeSourceContext {}
417
426
  /**
418
427
  * Registered worker Bindings, or a closed Effect/callback that captures them once for each
419
428
  * Durable Object incarnation. Callback Effects cannot require services or fail typed.
420
429
  */
421
430
  type CloudflareBindingSource = ReadonlyArray<ResolvedBinding> | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never> | ((context: CloudflareBindingSourceContext) => ReadonlyArray<ResolvedBinding> | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>);
431
+ /** A closed context-preparation service whose only remaining requirement is platform Crypto. */
432
+ type CloudflareRunContextLayer = Layer.Layer<RunContextPreparation, never, Crypto.Crypto>;
433
+ /** One Layer or a per-incarnation factory over explicit Cloudflare host values. */
434
+ type CloudflareRunContextSource = CloudflareRunContextLayer | ((context: CloudflareRuntimeSourceContext) => CloudflareRunContextLayer);
422
435
  /** Every construction failure of the assembled Cloudflare durable runtime stack. */
423
436
  type CloudflareDurableRuntimeInitializationError = CloudflarePlatformConfigError | DoStorageInitializationError;
424
437
  /** The services `CloudflareDurableRuntime.layer` provides. */
@@ -633,6 +646,10 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
633
646
  readonly receiptId: string;
634
647
  readonly outcome: "aborted" | "completed" | "failed";
635
648
  readonly runDisposition?: Schema.Json | undefined;
649
+ readonly failure?: {
650
+ readonly errorTag: string;
651
+ readonly message: string;
652
+ } | undefined;
636
653
  readonly settledAt: string;
637
654
  };
638
655
  } | {
@@ -1620,5 +1637,5 @@ interface DynamicWorkerCodeExecutorOptions {
1620
1637
  /** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */
1621
1638
  declare const dynamicWorkerCodeExecutorLayer: (options: DynamicWorkerCodeExecutorOptions) => Layer.Layer<CodeExecutor>;
1622
1639
  //#endregion
1623
- 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, CodeModeHostEntrypoint, CodeModeHostStub, 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, cloudflareWakeSchedulerLayer, conversationNamespaceFromEnv, conversationNamespaceLayer, conversationPortTransportLayer, decodeAbortCommand, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObligationThresholds, decodeObservePageRequest, decodeReceipt, decodeRetryCommand, decodeSubmitRequest, decodeUnknownResolutionCommand, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeAdminResponse, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeConversationObjectClass };
1640
+ 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, CodeModeHostEntrypoint, CodeModeHostStub, 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, cloudflareWakeSchedulerLayer, conversationNamespaceFromEnv, conversationNamespaceLayer, conversationPortTransportLayer, decodeAbortCommand, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeApprovalDecisionCommand, decodeAwaitProgressRequest, decodeCancelProgressRequest, decodeHostResponse, decodeObligationThresholds, decodeObservePageRequest, decodeReceipt, decodeRetryCommand, decodeSubmitRequest, decodeUnknownResolutionCommand, dynamicWorkerCodeExecutorLayer, dynamicWorkerImplementation, encodeAbortCommand, encodeAdminResponse, encodeApprovalDecisionCommand, encodeAwaitProgressRequest, encodeCancelProgressRequest, encodeHostResponse, encodeObservePageRequest, encodeReceipt, encodeSubmitRequest, encodeUnknownResolutionCommand, makeConversationObjectClass };
1624
1641
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import { Cause, Clock, Context, Crypto, Deferred, Duration, Effect, Exit, Fiber,
2
2
  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
3
  import { ConversationPortTransport, DEFAULT_MAX_STORED_VALUE_BYTES, conversationStoreLayer, handleEncodedPortRequest, portTransportFailure, routedConversationStoreLayer, routedSubmissionLedgerLayer, storageConfigLayer, storageFailpointLayer, submissionLedgerLayer } from "@effect-agent/storage-cloudflare";
4
4
  import { AgentId, AgentInputError, ConversationId, SubmissionId } from "@effect-agent/core";
5
+ import { RunContextPreparationPassthrough } from "@effect-agent/engine";
5
6
  import { BrowserCrypto } from "@effect/platform-browser";
6
7
  import { SqliteClient } from "@effect/sql-sqlite-do";
7
8
  import { DurableObject, DurableObjectState, WorkerEnvironment } from "effect-cf";
@@ -648,6 +649,7 @@ const resolveBindings = (source, context) => source === void 0 ? Effect.succeed(
648
649
  const bindings = source(context);
649
650
  return Effect.isEffect(bindings) ? bindings : Effect.succeed(bindings);
650
651
  }) : Effect.succeed(source);
652
+ const resolveRunContext = (source, context) => typeof source === "function" ? source(context) : source;
651
653
  /**
652
654
  * The DC Layer assembly (deployment §12: a Layer-assembly library, not an app entrypoint;
653
655
  * plan §1.4). `layer(options)` decodes the configuration, derives this Object's Conversation
@@ -717,8 +719,14 @@ var CloudflareDurableRuntime = class {
717
719
  conversationId,
718
720
  producerId
719
721
  }), (bindings) => AgentBindingResolver.fromBindings(bindings)));
722
+ const runContextLayer = options.runContext === void 0 ? RunContextPreparationPassthrough : resolveRunContext(options.runContext, {
723
+ ctx,
724
+ env,
725
+ conversationId,
726
+ producerId
727
+ }).pipe(Layer.provide(BrowserCrypto.layer));
720
728
  const base = Layer.mergeAll(identityLayer, cloudflareConfigLayer, DurableAlarmService.layer, maintenanceFailpointLayer, ProgressWaitRegistry.layer);
721
- const runtimeStack = DurableAgentRuntime.layer.pipe(Layer.provideMerge(routedPorts), Layer.provideMerge(cloudflareWakeSchedulerLayer), Layer.provideMerge(runtimeConfigLayer), Layer.provideMerge(bindingResolverLayer), Layer.provide(Layer.mergeAll(runtimeFailpointLayer, reconcilerLayer, authorizerLayer, BrowserCrypto.layer)), Layer.provideMerge(base));
729
+ const runtimeStack = DurableAgentRuntime.layerWithContext.pipe(Layer.provideMerge(routedPorts), Layer.provideMerge(cloudflareWakeSchedulerLayer), Layer.provideMerge(runtimeConfigLayer), Layer.provideMerge(bindingResolverLayer), Layer.provide(Layer.mergeAll(runtimeFailpointLayer, reconcilerLayer, authorizerLayer, runContextLayer, BrowserCrypto.layer)), Layer.provideMerge(base));
722
730
  return Layer.mergeAll(runtimeStack, ConversationMaintenance.layer.pipe(Layer.provide(runtimeStack)), portsEndpointLayer);
723
731
  }));
724
732
  }