actorctl 0.3.0-rc.14 → 0.3.0-rc.16
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/actorctl.js +1 -1
- package/dist/user-worker.js +120 -196
- package/package.json +2 -2
package/dist/actorctl.js
CHANGED
|
@@ -27159,7 +27159,7 @@ var actorctl = make30("actorctl").pipe(withDescription4("Deploy actors, run thre
|
|
|
27159
27159
|
make30("secrets").pipe(withSubcommands([secretsPut, secretsDelete]))
|
|
27160
27160
|
]));
|
|
27161
27161
|
// package.json
|
|
27162
|
-
var version2 = "0.3.0-rc.
|
|
27162
|
+
var version2 = "0.3.0-rc.16";
|
|
27163
27163
|
|
|
27164
27164
|
// src/main.ts
|
|
27165
27165
|
run5(actorctl, { version: version2 }).pipe(provide4(mergeAll2(layer10, layer12)), runMain2);
|
package/dist/user-worker.js
CHANGED
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
18
|
|
|
19
19
|
// ../../src/platform/cloudflare/user-worker.ts
|
|
20
|
-
import { ConfigProvider, Layer as
|
|
20
|
+
import { ConfigProvider, Layer as Layer8 } from "effect";
|
|
21
21
|
|
|
22
22
|
// ../../src/platform/cloudflare/analytics.ts
|
|
23
23
|
import { Effect as Effect2, Layer } from "effect";
|
|
@@ -62,7 +62,7 @@ var boundAiGateway = (accountId, binding) => Layer2.succeed(AiGateway, AiGateway
|
|
|
62
62
|
}));
|
|
63
63
|
|
|
64
64
|
// ../../src/platform/cloudflare/runtime.ts
|
|
65
|
-
import { Effect as
|
|
65
|
+
import { Effect as Effect17 } from "effect";
|
|
66
66
|
|
|
67
67
|
// ../../node_modules/.bun/@effect+sql-sqlite-do@4.1.2+edf248c88a527e3e/node_modules/@effect/sql-sqlite-do/dist/SqliteClient.js
|
|
68
68
|
var SqliteClient_exports = {};
|
|
@@ -262,11 +262,11 @@ var run = /* @__PURE__ */ Migrator.make({});
|
|
|
262
262
|
var layer3 = (options) => Layer4.effectDiscard(run(options));
|
|
263
263
|
|
|
264
264
|
// ../../src/platform/cloudflare/runtime.ts
|
|
265
|
-
import { HttpRouter
|
|
265
|
+
import { HttpRouter } from "effect/http";
|
|
266
266
|
import { hostRoutes } from "tardie/platform/http";
|
|
267
267
|
|
|
268
268
|
// ../../src/platform/exporting-host.ts
|
|
269
|
-
import { Context as
|
|
269
|
+
import { Context as Context5, Effect as Effect10, Fiber, Layer as Layer6, ManagedRuntime, Queue, Semaphore as Semaphore3, Schema as Schema2 } from "effect";
|
|
270
270
|
import { SqlClient as SqlClient3 } from "effect/sql";
|
|
271
271
|
import { createThreadHost, InitialState, InvalidMessage as InvalidMessage2, MessageConflict as MessageConflict2 } from "tardie/core";
|
|
272
272
|
|
|
@@ -355,99 +355,29 @@ var sqlEventExporter = (options) => Layer5.unwrap(Effect8.gen(function* () {
|
|
|
355
355
|
return eventExporter({ ...options, source });
|
|
356
356
|
}));
|
|
357
357
|
|
|
358
|
-
// ../../src/platform/actor-mcp.ts
|
|
359
|
-
import { Context as Context5, Effect as Effect9, Layer as Layer6, Schema } from "effect";
|
|
360
|
-
import { McpProtocol, McpSchema, McpServer, Tool } from "effect/ai";
|
|
361
|
-
import { HttpRouter } from "effect/http";
|
|
362
|
-
var ACTOR_MCP_PROTOCOLS = [McpProtocol.v2025_11_25, McpProtocol.v2025_06_18];
|
|
363
|
-
var identity2 = { thread: Schema.NonEmptyString, id: Schema.NonEmptyString };
|
|
364
|
-
var receipt = Schema.Struct({ id: Schema.String, position: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))) });
|
|
365
|
-
function actorMcp(host, instance, options = {}) {
|
|
366
|
-
const path = `/v1/actors/${encodeURIComponent(instance)}/mcp`;
|
|
367
|
-
let app;
|
|
368
|
-
const open = () => app ??= Effect9.runPromise(host.methodContracts({ instance })).then((contracts) => {
|
|
369
|
-
const register = Layer6.effectDiscard(Effect9.gen(function* () {
|
|
370
|
-
const server = yield* McpServer.McpServer;
|
|
371
|
-
const add2 = (name, description, input, output, run2) => server.addTool({
|
|
372
|
-
tool: new McpSchema.Tool({ name, description, inputSchema: Tool.getJsonSchemaFromSchema(input), outputSchema: Tool.getJsonSchemaFromSchema(output) }),
|
|
373
|
-
annotations: Context5.empty(),
|
|
374
|
-
handle: (payload) => Schema.decodeUnknownEffect(Schema.toType(input), { onExcessProperty: "error" })(payload).pipe(
|
|
375
|
-
Effect9.mapError((error) => new McpSchema.InvalidParams({ message: error.message })),
|
|
376
|
-
Effect9.flatMap((value) => run2(value).pipe(
|
|
377
|
-
Effect9.map((result) => new McpSchema.CallToolResult({ content: [{ type: "text", text: JSON.stringify(result) }], structuredContent: result })),
|
|
378
|
-
Effect9.catch((error) => Effect9.succeed(new McpSchema.CallToolResult({ isError: true, content: [{ type: "text", text: error.message }] })))
|
|
379
|
-
))
|
|
380
|
-
)
|
|
381
|
-
});
|
|
382
|
-
const thread = (name) => host.getThread({ instance, thread: name }).pipe(Effect9.flatMap((value) => value ? Effect9.succeed(value) : Effect9.fail(new Error("Unknown thread"))));
|
|
383
|
-
for (const [name, method] of Object.entries(contracts)) {
|
|
384
|
-
yield* add2(
|
|
385
|
-
`invoke_${name}`,
|
|
386
|
-
`Accept ${name}. Returns a durable call receipt; use call_get for the final result. Reuse id and input on retries.`,
|
|
387
|
-
Schema.Struct({ ...identity2, input: method.inputSchema }),
|
|
388
|
-
receipt,
|
|
389
|
-
(input) => thread(input.thread).pipe(Effect9.flatMap((current) => current.invoke(name, input.input, { id: input.id })))
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
yield* add2(
|
|
393
|
-
"call_get",
|
|
394
|
-
"Read a call's current status and final result.",
|
|
395
|
-
Schema.Struct(identity2),
|
|
396
|
-
Schema.Struct({ id: Schema.String, method: Schema.String, status: Schema.String, output: Schema.optionalKey(Schema.Json), error: Schema.optionalKey(Schema.String), reason: Schema.optionalKey(Schema.String) }),
|
|
397
|
-
(input) => thread(input.thread).pipe(Effect9.flatMap((current) => Effect9.gen(function* () {
|
|
398
|
-
const records = yield* current.records();
|
|
399
|
-
const invocation = records.find((record) => record.message?.id === input.id)?.message?.invocation;
|
|
400
|
-
return invocation ? { id: input.id, method: invocation.method, ...yield* current.methodState(invocation.method, input.id) } : void 0;
|
|
401
|
-
})), Effect9.flatMap((value) => value ? Effect9.succeed(value) : Effect9.fail(new Error("Unknown call"))))
|
|
402
|
-
);
|
|
403
|
-
yield* add2(
|
|
404
|
-
"call_cancel",
|
|
405
|
-
"Request cancellation of an accepted call. Returns acceptance, not cancellation completion.",
|
|
406
|
-
Schema.Struct({ ...identity2, reason: Schema.String }),
|
|
407
|
-
receipt,
|
|
408
|
-
(input) => thread(input.thread).pipe(Effect9.flatMap((current) => Effect9.gen(function* () {
|
|
409
|
-
const records = yield* current.records();
|
|
410
|
-
const invocation = records.find((record) => record.message?.id === input.id)?.message?.invocation;
|
|
411
|
-
return invocation ? { id: input.id, method: invocation.method, ...yield* current.methodState(invocation.method, input.id) } : void 0;
|
|
412
|
-
}).pipe(Effect9.flatMap((call) => call ? current.cancel(call.method, input.id, input.reason) : Effect9.fail(new Error("Unknown call"))))))
|
|
413
|
-
);
|
|
414
|
-
})).pipe(Layer6.provide(McpServer.layerHttp({ name: host.actor, version: "1.0.0", path, protocols: ACTOR_MCP_PROTOCOLS, ...options.allowedOrigins ? { allowedOrigins: options.allowedOrigins } : {} })));
|
|
415
|
-
return HttpRouter.toWebHandler(register, { disableLogger: true });
|
|
416
|
-
}).catch((error) => {
|
|
417
|
-
app = void 0;
|
|
418
|
-
throw error;
|
|
419
|
-
});
|
|
420
|
-
return {
|
|
421
|
-
request: async (request) => new URL(request.url).pathname === path ? (await open()).handler(request) : void 0,
|
|
422
|
-
close: async () => {
|
|
423
|
-
if (app) await (await app).dispose();
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
|
|
428
358
|
// src/worker/webhooks.ts
|
|
429
|
-
import { Effect as
|
|
359
|
+
import { Effect as Effect9, Schema } from "effect";
|
|
430
360
|
import { InvalidMessage, MessageConflict } from "tardie/core";
|
|
431
361
|
var REPLY_TO_HEADER = "x-tardigrade-reply-to";
|
|
432
362
|
var WEBHOOK_TRANSPORT = "tardigrade.webhook";
|
|
433
363
|
var REPLY_ACCEPTED = "accepted";
|
|
434
|
-
var CallMetadata =
|
|
435
|
-
|
|
364
|
+
var CallMetadata = Schema.Record(Schema.String, Schema.String.check(Schema.isMaxLength(512))).check(
|
|
365
|
+
Schema.makeFilter((value) => Object.keys(value).length <= 16 && Object.keys(value).every((key) => key.length <= 64) || "Metadata accepts at most 16 pairs with keys up to 64 characters.")
|
|
436
366
|
);
|
|
437
|
-
var ReplyAddress =
|
|
438
|
-
webhook:
|
|
439
|
-
account:
|
|
440
|
-
actor:
|
|
441
|
-
thread:
|
|
442
|
-
method:
|
|
443
|
-
id:
|
|
367
|
+
var ReplyAddress = Schema.Struct({
|
|
368
|
+
webhook: Schema.NonEmptyString,
|
|
369
|
+
account: Schema.NonEmptyString,
|
|
370
|
+
actor: Schema.NonEmptyString,
|
|
371
|
+
thread: Schema.NonEmptyString,
|
|
372
|
+
method: Schema.NonEmptyString,
|
|
373
|
+
id: Schema.NonEmptyString,
|
|
444
374
|
metadata: CallMetadata,
|
|
445
|
-
url:
|
|
375
|
+
url: Schema.String
|
|
446
376
|
});
|
|
447
377
|
var webhookTransport = (binding) => ({
|
|
448
|
-
deliver: (address, body, metadata) =>
|
|
378
|
+
deliver: (address, body, metadata) => Effect9.tryPromise({
|
|
449
379
|
try: async () => {
|
|
450
|
-
const reply =
|
|
380
|
+
const reply = Schema.decodeUnknownSync(ReplyAddress, { onExcessProperty: "error" })(address);
|
|
451
381
|
if (!binding) throw new Error("WEBHOOKS binding is required");
|
|
452
382
|
if (metadata.inReplyTo !== reply.id) throw new Error("Webhook reply identifies a different invocation");
|
|
453
383
|
await binding.enqueueReply(reply, body, metadata.inReplyTo);
|
|
@@ -465,14 +395,14 @@ async function receiveWebhookRequest(request, options) {
|
|
|
465
395
|
const id = request.headers.get("idempotency-key");
|
|
466
396
|
let address;
|
|
467
397
|
try {
|
|
468
|
-
address =
|
|
398
|
+
address = Schema.decodeUnknownSync(ReplyAddress, { onExcessProperty: "error" })(JSON.parse(request.headers.get(REPLY_TO_HEADER)));
|
|
469
399
|
if (!id?.trim() || address.id !== id || address.account !== instance || address.actor !== options.actor || address.thread !== thread || address.method !== method) throw new Error("Reply identity mismatch");
|
|
470
400
|
} catch {
|
|
471
401
|
return Response.json({ code: "invalid_message", message: "Invalid webhook reply address" }, { status: 400 });
|
|
472
402
|
}
|
|
473
403
|
const input = await request.json();
|
|
474
|
-
const
|
|
475
|
-
return Response.json(
|
|
404
|
+
const receipt = await options.receive({ target: { actor: options.actor, instance, thread }, body: { method, input }, message: { id, from: { transport: WEBHOOK_TRANSPORT, address } } });
|
|
405
|
+
return Response.json(receipt, { status: 202, headers: { [REPLY_TO_HEADER]: REPLY_ACCEPTED } });
|
|
476
406
|
}
|
|
477
407
|
const generic = /^\/v1\/actors\/([^/]+)\/threads\/([^/]+)\/calls\/([^/]+)(\/cancel)?$/.exec(path);
|
|
478
408
|
if (generic && (request.method === "GET" && !generic[4] || request.method === "POST" && generic[4])) {
|
|
@@ -482,7 +412,7 @@ async function receiveWebhookRequest(request, options) {
|
|
|
482
412
|
if (request.method === "GET") return Response.json({ id, method: call.method, ...call.state });
|
|
483
413
|
let reason;
|
|
484
414
|
try {
|
|
485
|
-
reason =
|
|
415
|
+
reason = Schema.decodeUnknownSync(Schema.Struct({ reason: Schema.String }), { onExcessProperty: "error" })(await request.json()).reason;
|
|
486
416
|
} catch {
|
|
487
417
|
return Response.json({ code: "invalid_message", message: "A cancellation reason is required" }, { status: 400 });
|
|
488
418
|
}
|
|
@@ -496,7 +426,7 @@ async function receiveWebhookRequest(request, options) {
|
|
|
496
426
|
if (call?.method !== method || !from || !("transport" in from) || from.transport !== WEBHOOK_TRANSPORT) return void 0;
|
|
497
427
|
let reason;
|
|
498
428
|
try {
|
|
499
|
-
reason =
|
|
429
|
+
reason = Schema.decodeUnknownSync(Schema.Struct({ reason: Schema.String }), { onExcessProperty: "error" })(await request.json()).reason;
|
|
500
430
|
} catch {
|
|
501
431
|
return Response.json({ code: "invalid_message", message: "A cancellation reason is required" }, { status: 400 });
|
|
502
432
|
}
|
|
@@ -513,7 +443,7 @@ async function receiveWebhookRequest(request, options) {
|
|
|
513
443
|
}
|
|
514
444
|
|
|
515
445
|
// ../../src/platform/exporting-host.ts
|
|
516
|
-
import { Tool
|
|
446
|
+
import { Tool } from "effect/ai";
|
|
517
447
|
var DEFAULT_EXPORT_FLUSH_TIMEOUT_MS = 3e4;
|
|
518
448
|
var isThreadEventJournal = (value, actor, account) => {
|
|
519
449
|
try {
|
|
@@ -530,16 +460,16 @@ async function createSqlExportingHost(options) {
|
|
|
530
460
|
const runtime = ManagedRuntime.make(options.sql);
|
|
531
461
|
const connections = /* @__PURE__ */ new Set();
|
|
532
462
|
try {
|
|
533
|
-
const state = await runtime.runPromise(
|
|
463
|
+
const state = await runtime.runPromise(Effect10.gen(function* () {
|
|
534
464
|
const sql = yield* SqlClient3.SqlClient;
|
|
535
465
|
yield* sql`CREATE TABLE IF NOT EXISTS event_export_identity (id INTEGER PRIMARY KEY CHECK (id = 1), account TEXT NOT NULL, actor TEXT NOT NULL, generation TEXT NOT NULL)`;
|
|
536
466
|
yield* sql`INSERT INTO event_export_identity VALUES (1, ${options.accountId}, ${options.actor.actorName}, ${crypto.randomUUID()}) ON CONFLICT (id) DO NOTHING`;
|
|
537
467
|
const rows = yield* sql`SELECT account, actor, generation FROM event_export_identity WHERE id = 1`;
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
468
|
+
const identity2 = rows[0];
|
|
469
|
+
if (identity2.account !== options.accountId || identity2.actor !== options.actor.actorName) return yield* Effect10.fail(new Error("Journal database belongs to a different account or actor."));
|
|
540
470
|
const signals = yield* Queue.make({ capacity: 1, strategy: "sliding" });
|
|
541
471
|
const lock = yield* Semaphore3.make(1);
|
|
542
|
-
return { sql, identity:
|
|
472
|
+
return { sql, identity: identity2, signals, lock };
|
|
543
473
|
}));
|
|
544
474
|
let closed = false;
|
|
545
475
|
const signal = () => {
|
|
@@ -549,10 +479,10 @@ async function createSqlExportingHost(options) {
|
|
|
549
479
|
const key = JSON.stringify(parts);
|
|
550
480
|
const opened = options.journalFactory({
|
|
551
481
|
actor: key,
|
|
552
|
-
layer:
|
|
482
|
+
layer: Layer6.succeed(SqlClient3.SqlClient, state.sql),
|
|
553
483
|
...options.transaction ? { transaction: options.transaction } : {},
|
|
554
|
-
flush:
|
|
555
|
-
if (options.sync) yield*
|
|
484
|
+
flush: Effect10.gen(function* () {
|
|
485
|
+
if (options.sync) yield* Effect10.tryPromise({ try: () => options.sync(), catch: (error) => error instanceof Error ? error : new Error(String(error)) });
|
|
556
486
|
if (exportEvents) signal();
|
|
557
487
|
})
|
|
558
488
|
});
|
|
@@ -571,59 +501,57 @@ async function createSqlExportingHost(options) {
|
|
|
571
501
|
checkAccount(coordinate.instance);
|
|
572
502
|
return journal([coordinate.actor, coordinate.instance, "thread", coordinate.thread, "events"], true);
|
|
573
503
|
},
|
|
574
|
-
close:
|
|
504
|
+
close: Effect10.gen(function* () {
|
|
575
505
|
for (const close of connections) yield* close;
|
|
576
506
|
connections.clear();
|
|
577
507
|
})
|
|
578
508
|
};
|
|
579
509
|
const allocations = Semaphore3.makeUnsafe(1);
|
|
580
|
-
const host = createThreadHost({ ...options, services: (coordinate, current) => options.services(coordinate, current).pipe(
|
|
581
|
-
const bootstrap = options.journalFactory({ actor: "bootstrap", layer:
|
|
510
|
+
const host = createThreadHost({ ...options, services: (coordinate, current) => options.services(coordinate, current).pipe(Layer6.provideMerge(Layer6.succeed(SqlClient3.SqlClient, state.sql))), storage, actorContext: options.actorContext ?? ((context) => context) });
|
|
511
|
+
const bootstrap = options.journalFactory({ actor: "bootstrap", layer: Layer6.succeed(SqlClient3.SqlClient, state.sql), ...options.transaction ? { transaction: options.transaction } : {} });
|
|
582
512
|
bootstrap.read();
|
|
583
|
-
await
|
|
584
|
-
const flush = state.lock.withPermits(1)(
|
|
513
|
+
await Effect10.runPromise(bootstrap.close);
|
|
514
|
+
const flush = state.lock.withPermits(1)(Effect10.scoped(Effect10.gen(function* () {
|
|
585
515
|
const rows = yield* state.sql`SELECT DISTINCT actor FROM experimental_events ORDER BY actor`;
|
|
586
516
|
const journals = rows.filter((row) => isThreadEventJournal(row.actor, options.actor.actorName, options.accountId));
|
|
587
517
|
const results = [];
|
|
588
518
|
if (journals.length === 0) return results;
|
|
589
|
-
const analytics =
|
|
519
|
+
const analytics = Context5.get(yield* Layer6.build(options.analytics), Analytics);
|
|
590
520
|
for (const row of journals) {
|
|
591
|
-
const result = yield*
|
|
521
|
+
const result = yield* Effect10.gen(function* () {
|
|
592
522
|
return yield* (yield* EventExporter).flush();
|
|
593
|
-
}).pipe(
|
|
523
|
+
}).pipe(Effect10.provide(sqlEventExporter({
|
|
594
524
|
accountId: options.accountId,
|
|
595
525
|
actor: options.actor.actorName,
|
|
596
526
|
sourceId: JSON.stringify([state.identity.generation, row.actor]),
|
|
597
527
|
destinationId: options.destinationId,
|
|
598
528
|
journal: row.actor,
|
|
599
529
|
...options.batchSize === void 0 ? {} : { batchSize: options.batchSize }
|
|
600
|
-
}).pipe(
|
|
530
|
+
}).pipe(Layer6.provide(Layer6.succeed(Analytics, analytics)))));
|
|
601
531
|
results.push(result);
|
|
602
532
|
}
|
|
603
533
|
return results;
|
|
604
|
-
})).pipe(
|
|
605
|
-
const worker = runtime.runFork(
|
|
534
|
+
})).pipe(Effect10.timeout(flushTimeoutMs)));
|
|
535
|
+
const worker = runtime.runFork(Effect10.forever(Effect10.gen(function* () {
|
|
606
536
|
yield* Queue.take(state.signals);
|
|
607
537
|
yield* flush.pipe(
|
|
608
|
-
|
|
538
|
+
Effect10.tap((results) => Effect10.sync(() => {
|
|
609
539
|
if (results.some((result) => result.hasMore)) signal();
|
|
610
540
|
})),
|
|
611
|
-
|
|
541
|
+
Effect10.catch((error) => Effect10.logWarning("Actor analytics export failed; the cursor is retained for the next flush.", { operation: error instanceof ExportError ? error.operation : "connection", flushTimeoutMs }))
|
|
612
542
|
);
|
|
613
543
|
})));
|
|
614
544
|
signal();
|
|
615
|
-
const mcp = actorMcp(host, options.accountId, options.mcp);
|
|
616
545
|
let closing;
|
|
617
546
|
return {
|
|
618
547
|
...host,
|
|
619
|
-
mcpRequest: mcp.request,
|
|
620
548
|
allocationRequest: async (request) => {
|
|
621
549
|
const parts = new URL(request.url).pathname.split("/");
|
|
622
550
|
if (request.method !== "POST" || parts.length !== 5 || parts[1] !== "v1" || parts[2] !== "actors" || parts[4] !== "threads") return void 0;
|
|
623
551
|
const input = await request.json().catch(() => void 0);
|
|
624
|
-
const schema =
|
|
625
|
-
const work = allocations.withPermit(
|
|
626
|
-
const body = yield*
|
|
552
|
+
const schema = Schema2.Struct({ name: Schema2.optionalKey(Schema2.NonEmptyString), parent: Schema2.optionalKey(Schema2.NonEmptyString), initialState: Schema2.optionalKey(InitialState) });
|
|
553
|
+
const work = allocations.withPermit(Effect10.gen(function* () {
|
|
554
|
+
const body = yield* Schema2.decodeUnknownEffect(schema)(input).pipe(Effect10.mapError(InvalidMessage2.from));
|
|
627
555
|
const instance = decodeURIComponent(parts[3]);
|
|
628
556
|
if (body.name && (yield* host.getThread({ instance, thread: body.name }))) return Response.json({ code: "thread_exists", message: "Thread already exists." }, { status: 409 });
|
|
629
557
|
const name = body.name === void 0 ? {} : { name: body.name };
|
|
@@ -631,22 +559,22 @@ async function createSqlExportingHost(options) {
|
|
|
631
559
|
const thread = yield* body.parent === void 0 ? host.allocateRootThread({ instance, ...name, ...seed }) : host.allocateChildThread({ parent: { actor: host.actor, instance, thread: body.parent }, ...name, ...seed });
|
|
632
560
|
return Response.json(thread.coordinate);
|
|
633
561
|
}));
|
|
634
|
-
return
|
|
562
|
+
return Effect10.runPromise(work.pipe(Effect10.catch((error) => Effect10.succeed(Response.json({ error: error.message }, { status: error instanceof InvalidMessage2 ? 400 : 500 })))));
|
|
635
563
|
},
|
|
636
564
|
methodRequest: async (request) => {
|
|
637
565
|
const parts = new URL(request.url).pathname.split("/");
|
|
638
566
|
if (parts[1] !== "v1" || parts[2] !== "actors" || decodeURIComponent(parts[3] ?? "") !== options.accountId) return void 0;
|
|
639
567
|
if (request.method === "GET" && parts.length === 5 && parts[4] === "methods") {
|
|
640
|
-
const contracts = await
|
|
568
|
+
const contracts = await Effect10.runPromise(host.methodContracts({ instance: options.accountId }));
|
|
641
569
|
return Response.json({ items: Object.entries(contracts).map(([name, method]) => ({
|
|
642
570
|
name,
|
|
643
|
-
inputSchema:
|
|
644
|
-
outputSchema:
|
|
571
|
+
inputSchema: Tool.getJsonSchemaFromSchema(method.inputSchema),
|
|
572
|
+
outputSchema: Tool.getJsonSchemaFromSchema(method.outputSchema),
|
|
645
573
|
cancellable: method.onCancel !== void 0
|
|
646
574
|
})) });
|
|
647
575
|
}
|
|
648
576
|
if (parts[4] === "threads" && parts[6] === "calls" && (request.method === "GET" && parts.length === 8 || request.method === "POST" && parts.length === 9 && parts[8] === "cancel")) {
|
|
649
|
-
const work2 =
|
|
577
|
+
const work2 = Effect10.gen(function* () {
|
|
650
578
|
const thread = yield* host.getThread({ instance: options.accountId, thread: decodeURIComponent(parts[5]) });
|
|
651
579
|
if (!thread) return new Response(null, { status: 404 });
|
|
652
580
|
const id2 = decodeURIComponent(parts[7]);
|
|
@@ -655,26 +583,26 @@ async function createSqlExportingHost(options) {
|
|
|
655
583
|
const call = invocation ? { id: id2, method: invocation.method, ...yield* thread.methodState(invocation.method, id2) } : void 0;
|
|
656
584
|
if (!call) return new Response(null, { status: 404 });
|
|
657
585
|
if (request.method === "GET") return Response.json(call);
|
|
658
|
-
const input2 = yield*
|
|
659
|
-
const body = yield*
|
|
586
|
+
const input2 = yield* Effect10.tryPromise(() => request.json()).pipe(Effect10.mapError(InvalidMessage2.from));
|
|
587
|
+
const body = yield* Schema2.decodeUnknownEffect(Schema2.Struct({ reason: Schema2.String }), { onExcessProperty: "error" })(input2).pipe(Effect10.mapError(InvalidMessage2.from));
|
|
660
588
|
const original = records.find((record) => record.message?.id === id2)?.message;
|
|
661
|
-
const
|
|
662
|
-
return Response.json(
|
|
589
|
+
const receipt = original?.from && "transport" in original.from && original.from.transport === WEBHOOK_TRANSPORT ? yield* host.receive({ target: thread.coordinate, body: { method: call.method, cancel: { id: id2, reason: body.reason } }, message: { id: JSON.stringify(["cancel", call.method, id2]), from: original.from } }) : yield* thread.cancel(call.method, id2, body.reason);
|
|
590
|
+
return Response.json(receipt, { status: 202 });
|
|
663
591
|
});
|
|
664
|
-
return
|
|
592
|
+
return Effect10.runPromise(work2.pipe(Effect10.catch((error) => Effect10.succeed(Response.json({ error: error.message }, { status: error instanceof InvalidMessage2 ? 400 : error instanceof MessageConflict2 ? 409 : 500 })))));
|
|
665
593
|
}
|
|
666
594
|
if (request.method === "POST" && parts.length === 8 && parts[4] === "threads" && parts[6] === "methods" && request.headers.has("x-tardigrade-reply-to")) {
|
|
667
|
-
const thread = await
|
|
595
|
+
const thread = await Effect10.runPromise(host.getThread({ instance: options.accountId, thread: decodeURIComponent(parts[5]) }));
|
|
668
596
|
if (!thread || !Object.hasOwn(thread.methods, decodeURIComponent(parts[7]))) return new Response(null, { status: 404 });
|
|
669
597
|
}
|
|
670
598
|
const webhook = await receiveWebhookRequest(request.clone(), {
|
|
671
599
|
actor: host.actor,
|
|
672
|
-
receive: (packet) =>
|
|
600
|
+
receive: (packet) => Effect10.runPromise(host.receive(packet)),
|
|
673
601
|
lookup: async (instance, thread, id2) => {
|
|
674
|
-
const handle = await
|
|
602
|
+
const handle = await Effect10.runPromise(host.getThread({ instance, thread }));
|
|
675
603
|
if (!handle) return void 0;
|
|
676
|
-
const message = (await
|
|
677
|
-
return message?.invocation ? { method: message.invocation.method, from: message.from, state: await
|
|
604
|
+
const message = (await Effect10.runPromise(handle.records())).find((record) => record.message?.id === id2 && record.message.invocation)?.message;
|
|
605
|
+
return message?.invocation ? { method: message.invocation.method, from: message.from, state: await Effect10.runPromise(handle.methodState(message.invocation.method, id2)) } : void 0;
|
|
678
606
|
}
|
|
679
607
|
}).catch((error) => Response.json({ error: error.message }, { status: error instanceof MessageConflict2 ? 409 : error instanceof InvalidMessage2 || error instanceof SyntaxError ? 400 : 500 }));
|
|
680
608
|
if (webhook) return webhook;
|
|
@@ -682,15 +610,15 @@ async function createSqlExportingHost(options) {
|
|
|
682
610
|
const id = request.headers.get("idempotency-key");
|
|
683
611
|
if (!id?.trim()) return Response.json({ error: "Idempotency-Key is required" }, { status: 400 });
|
|
684
612
|
const input = await request.json().catch(() => void 0);
|
|
685
|
-
const work =
|
|
613
|
+
const work = Effect10.gen(function* () {
|
|
686
614
|
const thread = yield* host.getThread({ instance: decodeURIComponent(parts[3]), thread: decodeURIComponent(parts[5]) });
|
|
687
615
|
const method = decodeURIComponent(parts[7]);
|
|
688
616
|
if (!thread || !Object.hasOwn(thread.methods, method)) return new Response(null, { status: 404 });
|
|
689
|
-
const body = yield*
|
|
690
|
-
const
|
|
691
|
-
return Response.json(
|
|
617
|
+
const body = yield* Schema2.decodeUnknownEffect(Schema2.Json)(input).pipe(Effect10.mapError(InvalidMessage2.from));
|
|
618
|
+
const receipt = yield* thread.invoke(method, body, { id });
|
|
619
|
+
return Response.json(receipt, { status: 202 });
|
|
692
620
|
});
|
|
693
|
-
return
|
|
621
|
+
return Effect10.runPromise(work.pipe(Effect10.catch((error) => Effect10.succeed(Response.json({ error: error.message }, { status: error instanceof MessageConflict2 ? 409 : error instanceof InvalidMessage2 ? 400 : 500 })))));
|
|
694
622
|
},
|
|
695
623
|
flushEvents: () => {
|
|
696
624
|
if (closed) return Promise.reject(new Error("Actor host is closed."));
|
|
@@ -699,19 +627,15 @@ async function createSqlExportingHost(options) {
|
|
|
699
627
|
close: () => closing ??= (async () => {
|
|
700
628
|
closed = true;
|
|
701
629
|
try {
|
|
702
|
-
|
|
703
|
-
await mcp.close();
|
|
704
|
-
} finally {
|
|
705
|
-
await Effect11.runPromise(host.close);
|
|
706
|
-
}
|
|
630
|
+
await Effect10.runPromise(host.close);
|
|
707
631
|
} finally {
|
|
708
|
-
await
|
|
632
|
+
await Effect10.runPromise(Fiber.interrupt(worker));
|
|
709
633
|
await runtime.dispose();
|
|
710
634
|
}
|
|
711
635
|
})()
|
|
712
636
|
};
|
|
713
637
|
} catch (error) {
|
|
714
|
-
for (const close of connections) await
|
|
638
|
+
for (const close of connections) await Effect10.runPromise(close);
|
|
715
639
|
await runtime.dispose();
|
|
716
640
|
throw error;
|
|
717
641
|
}
|
|
@@ -755,91 +679,91 @@ var eventsPage = (rows, query) => ({
|
|
|
755
679
|
});
|
|
756
680
|
|
|
757
681
|
// ../../src/platform/cloudflare/router.ts
|
|
758
|
-
import { Effect as
|
|
682
|
+
import { Effect as Effect16, Layer as Layer7 } from "effect";
|
|
759
683
|
|
|
760
684
|
// ../../src/services/actor-router.ts
|
|
761
|
-
import { Context as
|
|
685
|
+
import { Context as Context6, Data as Data4 } from "effect";
|
|
762
686
|
var ActorRouterError = class extends Data4.TaggedError("ActorRouterError") {
|
|
763
687
|
};
|
|
764
|
-
var ActorRouter = class extends
|
|
688
|
+
var ActorRouter = class extends Context6.Service()("tardigrade-cloud/ActorRouter") {
|
|
765
689
|
};
|
|
766
690
|
|
|
767
691
|
// ../../src/services/actor-runtime.ts
|
|
768
|
-
import { Context as
|
|
692
|
+
import { Context as Context7, Data as Data5 } from "effect";
|
|
769
693
|
var ActorRuntimeError = class extends Data5.TaggedError("ActorRuntimeError") {
|
|
770
694
|
};
|
|
771
|
-
var ActorRuntime = class extends
|
|
695
|
+
var ActorRuntime = class extends Context7.Service()("tardigrade-cloud/ActorRuntime") {
|
|
772
696
|
};
|
|
773
697
|
|
|
774
698
|
// ../../src/services/metadata-store.ts
|
|
775
|
-
import { Context as
|
|
699
|
+
import { Context as Context9, Data as Data7, Schema as Schema4 } from "effect";
|
|
776
700
|
|
|
777
701
|
// ../../src/services/webhooks.ts
|
|
778
|
-
import { Context as
|
|
779
|
-
var WebhookEventType =
|
|
780
|
-
var WebhookEndpoint =
|
|
781
|
-
id:
|
|
782
|
-
url:
|
|
783
|
-
events:
|
|
784
|
-
description:
|
|
785
|
-
status:
|
|
786
|
-
createdAt:
|
|
702
|
+
import { Context as Context8, Data as Data6, Schema as Schema3 } from "effect";
|
|
703
|
+
var WebhookEventType = Schema3.Literals(["call.completed", "call.failed", "call.cancelled", "webhook.test"]);
|
|
704
|
+
var WebhookEndpoint = Schema3.Struct({
|
|
705
|
+
id: Schema3.String,
|
|
706
|
+
url: Schema3.String,
|
|
707
|
+
events: Schema3.Array(WebhookEventType),
|
|
708
|
+
description: Schema3.String,
|
|
709
|
+
status: Schema3.Literals(["active", "disabled"]),
|
|
710
|
+
createdAt: Schema3.String
|
|
787
711
|
});
|
|
788
|
-
var WebhookCreate =
|
|
789
|
-
var WebhookPatch =
|
|
790
|
-
url:
|
|
791
|
-
events:
|
|
792
|
-
description:
|
|
793
|
-
status:
|
|
712
|
+
var WebhookCreate = Schema3.Struct({ url: Schema3.String, events: Schema3.optionalKey(Schema3.Array(WebhookEventType)), description: Schema3.optionalKey(Schema3.String) });
|
|
713
|
+
var WebhookPatch = Schema3.Struct({
|
|
714
|
+
url: Schema3.optionalKey(Schema3.String),
|
|
715
|
+
events: Schema3.optionalKey(Schema3.Array(WebhookEventType)),
|
|
716
|
+
description: Schema3.optionalKey(Schema3.String),
|
|
717
|
+
status: Schema3.optionalKey(Schema3.Literals(["active", "disabled"]))
|
|
794
718
|
});
|
|
795
719
|
var WebhookError = class extends Data6.TaggedError("WebhookError") {
|
|
796
720
|
};
|
|
797
|
-
var WebhookStore = class extends
|
|
721
|
+
var WebhookStore = class extends Context8.Service()("tardigrade-cloud/WebhookStore") {
|
|
798
722
|
};
|
|
799
|
-
var WebhookAttempt =
|
|
800
|
-
var WebhookDelivery =
|
|
801
|
-
id:
|
|
723
|
+
var WebhookAttempt = Schema3.Struct({ startedAt: Schema3.Number, finishedAt: Schema3.NullOr(Schema3.Number), statusCode: Schema3.NullOr(Schema3.Number), error: Schema3.NullOr(Schema3.String) });
|
|
724
|
+
var WebhookDelivery = Schema3.Struct({
|
|
725
|
+
id: Schema3.String,
|
|
802
726
|
type: WebhookEventType,
|
|
803
|
-
status:
|
|
804
|
-
createdAt:
|
|
805
|
-
attempts:
|
|
727
|
+
status: Schema3.Literals(["pending", "delivered", "failed", "skipped"]),
|
|
728
|
+
createdAt: Schema3.Number,
|
|
729
|
+
attempts: Schema3.Array(WebhookAttempt)
|
|
806
730
|
});
|
|
807
|
-
var WebhookDeliveryService = class extends
|
|
731
|
+
var WebhookDeliveryService = class extends Context8.Service()("tardigrade-cloud/WebhookDeliveryService") {
|
|
808
732
|
};
|
|
809
733
|
|
|
810
734
|
// ../../src/services/metadata-store.ts
|
|
811
|
-
var Actor =
|
|
812
|
-
name:
|
|
813
|
-
description:
|
|
814
|
-
metadata:
|
|
735
|
+
var Actor = Schema4.Struct({
|
|
736
|
+
name: Schema4.NonEmptyString,
|
|
737
|
+
description: Schema4.String,
|
|
738
|
+
metadata: Schema4.optionalKey(CallMetadata)
|
|
815
739
|
}).annotate({ identifier: "Actor" });
|
|
816
|
-
var Version =
|
|
817
|
-
id:
|
|
818
|
-
actor:
|
|
819
|
-
digest:
|
|
740
|
+
var Version = Schema4.Struct({
|
|
741
|
+
id: Schema4.NonEmptyString,
|
|
742
|
+
actor: Schema4.NonEmptyString,
|
|
743
|
+
digest: Schema4.NonEmptyString
|
|
820
744
|
}).annotate({ identifier: "Version" });
|
|
821
|
-
var Deployment =
|
|
822
|
-
id:
|
|
823
|
-
version:
|
|
745
|
+
var Deployment = Schema4.Struct({
|
|
746
|
+
id: Schema4.NonEmptyString,
|
|
747
|
+
version: Schema4.NonEmptyString
|
|
824
748
|
}).annotate({ identifier: "Deployment" });
|
|
825
|
-
var VersionRecord =
|
|
749
|
+
var VersionRecord = Schema4.Struct({
|
|
826
750
|
...Version.fields,
|
|
827
|
-
artifactDigest:
|
|
751
|
+
artifactDigest: Schema4.String.check(Schema4.isPattern(/^sha256:[a-f0-9]{64}$/))
|
|
828
752
|
}).annotate({ identifier: "VersionRecord" });
|
|
829
753
|
var MetadataStoreError = class extends Data7.TaggedError("MetadataStoreError") {
|
|
830
754
|
};
|
|
831
|
-
var MetadataStore = class extends
|
|
755
|
+
var MetadataStore = class extends Context9.Service()("tardigrade-cloud/MetadataStore") {
|
|
832
756
|
};
|
|
833
757
|
|
|
834
758
|
// ../../src/platform/router.ts
|
|
835
|
-
import { Effect as
|
|
759
|
+
import { Effect as Effect15, Option as Option2 } from "effect";
|
|
836
760
|
|
|
837
761
|
// ../../src/platform/cloudflare/router.ts
|
|
838
762
|
var actorObjectName = (address) => JSON.stringify([address.accountId, address.actorName]);
|
|
839
763
|
|
|
840
764
|
// ../../src/platform/cloudflare/runtime.ts
|
|
841
765
|
var createCloudflareExportingHost = (options) => import("tardie/platform/journal").then(({ sqlJournal }) => createSqlExportingHost({ ...options, journalFactory: sqlJournal, sql: SqliteClient_exports.layer({ storage: options.storage }), transaction: (work) => options.storage.transactionSync(work), sync: () => options.storage.sync() }));
|
|
842
|
-
var cloudflareHandler = (host) =>
|
|
766
|
+
var cloudflareHandler = (host) => HttpRouter.toWebHandler(hostRoutes(host), { disableLogger: true });
|
|
843
767
|
var DEFAULT_EVENT_PAGE_SIZE = 100;
|
|
844
768
|
var READY_PATH = "/__tardigrade/ready";
|
|
845
769
|
var cloudflareActorObject = (options) => class {
|
|
@@ -895,7 +819,7 @@ var cloudflareActorObject = (options) => class {
|
|
|
895
819
|
if (!Number.isSafeInteger(pageSize) || pageSize < 1) throw new Error("Event page size must be a positive integer.");
|
|
896
820
|
if (request.method === "GET" && parts.length === 7 && parts[6] === "events") {
|
|
897
821
|
const thread = decodeURIComponent(parts[5]);
|
|
898
|
-
if (!await
|
|
822
|
+
if (!await Effect17.runPromise(this.active.host.getThread({ instance: accountId, thread }))) return new Response(null, { status: 404 });
|
|
899
823
|
const query = parseEventsQuery(url.searchParams, pageSize);
|
|
900
824
|
if (!query) return new Response(null, { status: 400 });
|
|
901
825
|
const statement = eventsStatement(JSON.stringify([actorName, accountId, "thread", thread, "events"]), query);
|
|
@@ -904,15 +828,15 @@ var cloudflareActorObject = (options) => class {
|
|
|
904
828
|
if (request.method === "GET" && parts.length === 5 && parts[4] === "threads") {
|
|
905
829
|
const cursor = Number(url.searchParams.get("cursor") ?? 0);
|
|
906
830
|
if (!Number.isSafeInteger(cursor) || cursor < 0) return new Response(null, { status: 400 });
|
|
907
|
-
const store = await
|
|
831
|
+
const store = await Effect17.runPromise(this.active.host.supervisorStore(accountId));
|
|
908
832
|
const threads = store.threads.get().filter((thread) => thread.status === "registered");
|
|
909
833
|
return Response.json({ items: threads.slice(cursor, cursor + pageSize).map((thread) => ({ id: thread.coordinate.thread, ...thread.parent ? { parent: thread.parent } : {} })), ...cursor + pageSize < threads.length ? { cursor: String(cursor + pageSize) } : {} });
|
|
910
834
|
}
|
|
911
835
|
if (request.method === "POST" && parts.length === 5 && parts[4] === "threads") {
|
|
912
836
|
const input = await request.clone().json().catch(() => null);
|
|
913
|
-
if (typeof input?.name === "string" && await
|
|
837
|
+
if (typeof input?.name === "string" && await Effect17.runPromise(this.active.host.getThread({ instance: accountId, thread: input.name }))) return Response.json({ code: "thread_exists", message: "Thread already exists." }, { status: 409 });
|
|
914
838
|
}
|
|
915
|
-
return await this.active.host.allocationRequest(request.clone()) ?? await this.active.host.methodRequest(request.clone()) ??
|
|
839
|
+
return await this.active.host.allocationRequest(request.clone()) ?? await this.active.host.methodRequest(request.clone()) ?? this.active.app.handler(request);
|
|
916
840
|
}
|
|
917
841
|
};
|
|
918
842
|
|
|
@@ -932,11 +856,11 @@ var createActorWorker = (actor, DurableObject, services, actorContext) => {
|
|
|
932
856
|
transports: { [WEBHOOK_TRANSPORT]: webhookTransport(env.WEBHOOKS) },
|
|
933
857
|
...actorContext ? { actorContext } : {},
|
|
934
858
|
services: (coordinate, runtime) => {
|
|
935
|
-
const platform =
|
|
859
|
+
const platform = Layer8.mergeAll(
|
|
936
860
|
ConfigProvider.layer(ConfigProvider.fromUnknown(secrets(env.SECRETS))),
|
|
937
861
|
boundAiGateway(deployment.accountId, env.INFERENCE)
|
|
938
862
|
);
|
|
939
|
-
return services ? services(runtime, coordinate).pipe(
|
|
863
|
+
return services ? services(runtime, coordinate).pipe(Layer8.provideMerge(platform)) : platform;
|
|
940
864
|
},
|
|
941
865
|
analytics: cloudflareAnalytics(deployment.accountId, env.ANALYTICS),
|
|
942
866
|
destinationId: "aurora",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actorctl",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.16",
|
|
4
4
|
"description": "Deploy actors, run threads, and read events on Tardigrade Cloud.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"tardie": "*"
|
|
27
27
|
},
|
|
28
28
|
"tardigrade": {
|
|
29
|
-
"sourceTree": "
|
|
29
|
+
"sourceTree": "488e256a97b01d65b23f3da4d75eeb22e0dc3355"
|
|
30
30
|
}
|
|
31
31
|
}
|