tardie 0.11.0 → 0.12.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tardie",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Clavia, Inc.",
|
|
6
6
|
"description": "A durable agent harness. State is a pure function of the log.",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"tardigrade": {
|
|
19
|
-
"sourceTree": "
|
|
19
|
+
"sourceTree": "08d69b6ce9e98f53871766428cc614668c943eec"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
package/src/cloudflare/host.ts
CHANGED
|
@@ -18,8 +18,8 @@ import { createLaneDriver, type DriverPolicy } from "tardie/host/driver"
|
|
|
18
18
|
import type { HostPorts } from "tardie/host/host"
|
|
19
19
|
import { CloudflareEventStore, layerWorkspace } from "./storage"
|
|
20
20
|
|
|
21
|
-
type CloudflarePorts = HostPorts | KeyValueStore.KeyValueStore
|
|
22
|
-
type CloudflareLaneEnv<R> = Layer.Layer<Exclude<R, CloudflarePorts>, never, CloudflarePorts>
|
|
21
|
+
export type CloudflarePorts = HostPorts | KeyValueStore.KeyValueStore
|
|
22
|
+
export type CloudflareLaneEnv<R> = Layer.Layer<Exclude<R, CloudflarePorts>, never, CloudflarePorts>
|
|
23
23
|
|
|
24
24
|
type LayersFor<R> = [Exclude<R, CloudflarePorts>] extends [never]
|
|
25
25
|
? { readonly layersFor?: (lane: string) => CloudflareLaneEnv<R> }
|
package/src/cloudflare/index.ts
CHANGED
|
@@ -3,6 +3,8 @@ export {
|
|
|
3
3
|
cloudflareWorker,
|
|
4
4
|
DEFAULT_CLOUDFLARE_MODEL_CATALOG_LOAD_POLICY,
|
|
5
5
|
DEFAULT_CLOUDFLARE_MODEL_CATALOG_TIMEOUT_MILLIS,
|
|
6
|
+
type CloudflareWorkerLayerContext,
|
|
7
|
+
type CloudflareWorkerOptions,
|
|
6
8
|
type Env
|
|
7
9
|
} from "./worker"
|
|
8
10
|
export { DEFAULT_ALARM_DELAY_MILLIS, DEFAULT_ALARM_POLICY, type AlarmPolicy } from "./alarm"
|
package/src/cloudflare/worker.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DurableObject } from "cloudflare:workers"
|
|
2
2
|
import { Clock, Context, Effect, Layer, Schema } from "effect"
|
|
3
|
-
import { FetchHttpClient, HttpEffect, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
|
|
3
|
+
import { FetchHttpClient, HttpClient, HttpEffect, HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http"
|
|
4
4
|
import { actor, agentMethods, agentsPackage, applyModelPolicy, budget, codeMode, compaction, fetchPackage, Infer, infer as inferAgent, intersectModelPolicies, modelAllowedBy, outputValidateOnce, workspacePackage, type Actor, type ActorMethods, type ModelPolicy, type ModelRef } from "tardie"
|
|
5
5
|
import type { Action } from "tardie/log/events"
|
|
6
6
|
import {
|
|
@@ -37,7 +37,12 @@ import {
|
|
|
37
37
|
type WorkerLoaderSandboxTransport
|
|
38
38
|
} from "tardie/worker-loader/sandbox"
|
|
39
39
|
import { alarmPolicyOf, armAt, scheduledAlarmAt, type AlarmPolicy } from "./alarm"
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
createCloudflareHost,
|
|
42
|
+
type CloudflareHost,
|
|
43
|
+
type CloudflareLaneEnv,
|
|
44
|
+
type CloudflarePorts
|
|
45
|
+
} from "./host"
|
|
41
46
|
import { layerCloudflareModelCatalogRepository } from "./catalog"
|
|
42
47
|
import { structuredWorkerConfigOf } from "./config"
|
|
43
48
|
|
|
@@ -74,6 +79,7 @@ interface MountedActor {
|
|
|
74
79
|
readonly name: string
|
|
75
80
|
readonly actor: DefaultAssembly
|
|
76
81
|
readonly methods: ActorMethods
|
|
82
|
+
readonly layersFor?: (context: CloudflareWorkerLayerContext<Env>) => CloudflareLaneEnv<never>
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
let mountedActor: MountedActor | undefined
|
|
@@ -455,7 +461,11 @@ export class ActorHost extends DurableObject<Env> {
|
|
|
455
461
|
storage: this.ctx.storage,
|
|
456
462
|
principal,
|
|
457
463
|
actorFor: (lane) => threadOf(lane) === undefined ? undefined : selectedAssembly,
|
|
458
|
-
layersFor: () =>
|
|
464
|
+
layersFor: (lane) => {
|
|
465
|
+
const framework = Layer.mergeAll(modelLayer(models, catalog), FetchHttpClient.layer, sandboxLayer)
|
|
466
|
+
const application = mountedActor?.layersFor?.({ env: this.env, lane })
|
|
467
|
+
return application === undefined ? framework : Layer.mergeAll(framework, application)
|
|
468
|
+
},
|
|
459
469
|
routes: [remoteRoute],
|
|
460
470
|
driver: driverPolicyOf({
|
|
461
471
|
maxConcurrentLanes: positiveInteger(
|
|
@@ -820,17 +830,49 @@ const worker = {
|
|
|
820
830
|
}
|
|
821
831
|
} satisfies ExportedHandler<Env>
|
|
822
832
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
833
|
+
type CloudflareWorkerProvided = CloudflarePorts | Infer | HttpClient.HttpClient
|
|
834
|
+
type CloudflareApplicationRequirements<R> = Exclude<R, CloudflareWorkerProvided>
|
|
835
|
+
|
|
836
|
+
// CloudflareWorkerLayerContext exposes the Worker bindings and lane identity used to construct application services.
|
|
837
|
+
export interface CloudflareWorkerLayerContext<WorkerEnv extends Env = Env> {
|
|
838
|
+
readonly env: WorkerEnv
|
|
839
|
+
readonly lane: string
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
type CloudflareWorkerLayersFor<R, WorkerEnv extends Env> = (
|
|
843
|
+
context: CloudflareWorkerLayerContext<WorkerEnv>
|
|
844
|
+
) => CloudflareLaneEnv<CloudflareApplicationRequirements<R>>
|
|
845
|
+
|
|
846
|
+
// CloudflareWorkerOptions supplies every actor requirement the Worker does not bind itself.
|
|
847
|
+
export type CloudflareWorkerOptions<R, WorkerEnv extends Env = Env> =
|
|
848
|
+
[CloudflareApplicationRequirements<R>] extends [never]
|
|
849
|
+
? { readonly layersFor?: CloudflareWorkerLayersFor<R, WorkerEnv> }
|
|
850
|
+
: { readonly layersFor: CloudflareWorkerLayersFor<R, WorkerEnv> }
|
|
851
|
+
|
|
852
|
+
type CloudflareWorkerArguments<R, WorkerEnv extends Env> =
|
|
853
|
+
[CloudflareApplicationRequirements<R>] extends [never]
|
|
854
|
+
? [options?: CloudflareWorkerOptions<R, WorkerEnv>]
|
|
855
|
+
: [options: CloudflareWorkerOptions<R, WorkerEnv>]
|
|
856
|
+
|
|
857
|
+
// cloudflareWorker mounts a defined actor and its application layers into the Worker host (test/actor.workers.ts, "a mounted actor receives lane application services").
|
|
858
|
+
export const cloudflareWorker = <
|
|
859
|
+
R,
|
|
860
|
+
const Methods extends ActorMethods,
|
|
861
|
+
WorkerEnv extends Env = Env
|
|
862
|
+
>(
|
|
863
|
+
definition: Actor<R, Methods>,
|
|
864
|
+
...[options]: CloudflareWorkerArguments<R, WorkerEnv>
|
|
865
|
+
): ExportedHandler<WorkerEnv> => {
|
|
827
866
|
mountedActor = {
|
|
828
867
|
name: definition.name,
|
|
829
868
|
actor: definition as unknown as DefaultAssembly,
|
|
830
|
-
methods: definition.methods
|
|
869
|
+
methods: definition.methods,
|
|
870
|
+
...(options?.layersFor === undefined ? {} : {
|
|
871
|
+
layersFor: options.layersFor as unknown as (context: CloudflareWorkerLayerContext<Env>) => CloudflareLaneEnv<never>
|
|
872
|
+
})
|
|
831
873
|
}
|
|
832
874
|
deployedActor = definition.name
|
|
833
|
-
return worker
|
|
875
|
+
return worker as ExportedHandler<WorkerEnv>
|
|
834
876
|
}
|
|
835
877
|
|
|
836
878
|
export default worker
|