actorctl 0.3.0-rc.13 → 0.3.0-rc.15
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 +73 -59
- package/dist/user-worker.js +116 -156
- package/package.json +2 -2
package/dist/actorctl.js
CHANGED
|
@@ -26067,10 +26067,59 @@ class ArtifactStoreError extends TaggedError2("ArtifactStoreError") {
|
|
|
26067
26067
|
class ArtifactStore extends Service()("tardigrade-cloud/ArtifactStore") {
|
|
26068
26068
|
}
|
|
26069
26069
|
|
|
26070
|
+
// src/worker/webhooks.ts
|
|
26071
|
+
var CallMetadata = Record(String5, String5.check(isMaxLength(512))).check(makeFilter2((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."));
|
|
26072
|
+
var ReplyAddress = Struct({
|
|
26073
|
+
webhook: NonEmptyString,
|
|
26074
|
+
account: NonEmptyString,
|
|
26075
|
+
actor: NonEmptyString,
|
|
26076
|
+
thread: NonEmptyString,
|
|
26077
|
+
method: NonEmptyString,
|
|
26078
|
+
id: NonEmptyString,
|
|
26079
|
+
metadata: CallMetadata,
|
|
26080
|
+
url: String5
|
|
26081
|
+
});
|
|
26082
|
+
|
|
26083
|
+
// ../../src/services/webhooks.ts
|
|
26084
|
+
var WebhookEventType = Literals(["call.completed", "call.failed", "call.cancelled", "webhook.test"]);
|
|
26085
|
+
var WebhookEndpoint = Struct({
|
|
26086
|
+
id: String5,
|
|
26087
|
+
url: String5,
|
|
26088
|
+
events: ArraySchema(WebhookEventType),
|
|
26089
|
+
description: String5,
|
|
26090
|
+
status: Literals(["active", "disabled"]),
|
|
26091
|
+
createdAt: String5
|
|
26092
|
+
});
|
|
26093
|
+
var WebhookCreate = Struct({ url: String5, events: optionalKey2(ArraySchema(WebhookEventType)), description: optionalKey2(String5) });
|
|
26094
|
+
var WebhookPatch = Struct({
|
|
26095
|
+
url: optionalKey2(String5),
|
|
26096
|
+
events: optionalKey2(ArraySchema(WebhookEventType)),
|
|
26097
|
+
description: optionalKey2(String5),
|
|
26098
|
+
status: optionalKey2(Literals(["active", "disabled"]))
|
|
26099
|
+
});
|
|
26100
|
+
|
|
26101
|
+
class WebhookError extends TaggedError2("WebhookError") {
|
|
26102
|
+
}
|
|
26103
|
+
|
|
26104
|
+
class WebhookStore extends Service()("tardigrade-cloud/WebhookStore") {
|
|
26105
|
+
}
|
|
26106
|
+
var WebhookAttempt = Struct({ startedAt: Number6, finishedAt: NullOr(Number6), statusCode: NullOr(Number6), error: NullOr(String5) });
|
|
26107
|
+
var WebhookDelivery = Struct({
|
|
26108
|
+
id: String5,
|
|
26109
|
+
type: WebhookEventType,
|
|
26110
|
+
status: Literals(["pending", "delivered", "failed", "skipped"]),
|
|
26111
|
+
createdAt: Number6,
|
|
26112
|
+
attempts: ArraySchema(WebhookAttempt)
|
|
26113
|
+
});
|
|
26114
|
+
|
|
26115
|
+
class WebhookDeliveryService extends Service()("tardigrade-cloud/WebhookDeliveryService") {
|
|
26116
|
+
}
|
|
26117
|
+
|
|
26070
26118
|
// ../../src/services/metadata-store.ts
|
|
26071
26119
|
var Actor2 = Struct({
|
|
26072
26120
|
name: NonEmptyString,
|
|
26073
|
-
description: String5
|
|
26121
|
+
description: String5,
|
|
26122
|
+
metadata: optionalKey2(CallMetadata)
|
|
26074
26123
|
}).annotate({ identifier: "Actor" });
|
|
26075
26124
|
var Version2 = Struct({
|
|
26076
26125
|
id: NonEmptyString,
|
|
@@ -26118,9 +26167,9 @@ var Credits = Struct({
|
|
|
26118
26167
|
entries: ArraySchema(CreditEntry),
|
|
26119
26168
|
cursor: optionalKey2(NonEmptyString)
|
|
26120
26169
|
}).annotate({ identifier: "Credits" });
|
|
26121
|
-
var UsageGroup = Literals(["day", "model", "actor"]);
|
|
26170
|
+
var UsageGroup = Union2([Literals(["day", "model", "actor"]), String5.check(isPattern2(/^metadata\.[\s\S]{1,64}$/))]);
|
|
26122
26171
|
var UsageRow = Struct({
|
|
26123
|
-
key: String5,
|
|
26172
|
+
key: NullOr(String5),
|
|
26124
26173
|
requests: Int,
|
|
26125
26174
|
inputTokens: Int,
|
|
26126
26175
|
outputTokens: Int,
|
|
@@ -26146,54 +26195,6 @@ var CreditGrant = Struct({
|
|
|
26146
26195
|
var InsufficientCredits = Struct({
|
|
26147
26196
|
error: Struct({ type: Literal2("insufficient_credits"), message: String5, balanceMicros: Micros })
|
|
26148
26197
|
}).annotate({ identifier: "InsufficientCredits" });
|
|
26149
|
-
// src/worker/webhooks.ts
|
|
26150
|
-
var CallMetadata = Record(String5, String5.check(isMaxLength(512))).check(makeFilter2((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."));
|
|
26151
|
-
var ReplyAddress = Struct({
|
|
26152
|
-
webhook: NonEmptyString,
|
|
26153
|
-
account: NonEmptyString,
|
|
26154
|
-
actor: NonEmptyString,
|
|
26155
|
-
thread: NonEmptyString,
|
|
26156
|
-
method: NonEmptyString,
|
|
26157
|
-
id: NonEmptyString,
|
|
26158
|
-
metadata: CallMetadata,
|
|
26159
|
-
url: String5
|
|
26160
|
-
});
|
|
26161
|
-
|
|
26162
|
-
// ../../src/services/webhooks.ts
|
|
26163
|
-
var WebhookEventType = Literals(["call.completed", "call.failed", "call.cancelled", "webhook.test"]);
|
|
26164
|
-
var WebhookEndpoint = Struct({
|
|
26165
|
-
id: String5,
|
|
26166
|
-
url: String5,
|
|
26167
|
-
events: ArraySchema(WebhookEventType),
|
|
26168
|
-
description: String5,
|
|
26169
|
-
status: Literals(["active", "disabled"]),
|
|
26170
|
-
createdAt: String5
|
|
26171
|
-
});
|
|
26172
|
-
var WebhookCreate = Struct({ url: String5, events: optionalKey2(ArraySchema(WebhookEventType)), description: optionalKey2(String5) });
|
|
26173
|
-
var WebhookPatch = Struct({
|
|
26174
|
-
url: optionalKey2(String5),
|
|
26175
|
-
events: optionalKey2(ArraySchema(WebhookEventType)),
|
|
26176
|
-
description: optionalKey2(String5),
|
|
26177
|
-
status: optionalKey2(Literals(["active", "disabled"]))
|
|
26178
|
-
});
|
|
26179
|
-
|
|
26180
|
-
class WebhookError extends TaggedError2("WebhookError") {
|
|
26181
|
-
}
|
|
26182
|
-
|
|
26183
|
-
class WebhookStore extends Service()("tardigrade-cloud/WebhookStore") {
|
|
26184
|
-
}
|
|
26185
|
-
var WebhookAttempt = Struct({ startedAt: Number6, finishedAt: NullOr(Number6), statusCode: NullOr(Number6), error: NullOr(String5) });
|
|
26186
|
-
var WebhookDelivery = Struct({
|
|
26187
|
-
id: String5,
|
|
26188
|
-
type: WebhookEventType,
|
|
26189
|
-
status: Literals(["pending", "delivered", "failed", "skipped"]),
|
|
26190
|
-
createdAt: Number6,
|
|
26191
|
-
attempts: ArraySchema(WebhookAttempt)
|
|
26192
|
-
});
|
|
26193
|
-
|
|
26194
|
-
class WebhookDeliveryService extends Service()("tardigrade-cloud/WebhookDeliveryService") {
|
|
26195
|
-
}
|
|
26196
|
-
|
|
26197
26198
|
// ../../src/api.ts
|
|
26198
26199
|
var Health = Struct({ status: Literal2("ok") });
|
|
26199
26200
|
var Unauthorized = Struct({ code: Literal2("unauthorized"), message: String5 }).pipe(status(401));
|
|
@@ -26211,7 +26212,8 @@ var base = "/v1/accounts/:account/actors";
|
|
|
26211
26212
|
var actorPath = `${base}/:name`;
|
|
26212
26213
|
var pageQuery = { cursor: optionalKey2(Identifier) };
|
|
26213
26214
|
var ActorMetadata = Struct({
|
|
26214
|
-
description: optionalKey2(String5)
|
|
26215
|
+
description: optionalKey2(String5),
|
|
26216
|
+
metadata: optionalKey2(CallMetadata)
|
|
26215
26217
|
}).annotate({ identifier: "ActorMetadata" });
|
|
26216
26218
|
var ActorInfo = Struct({
|
|
26217
26219
|
...Actor2.fields,
|
|
@@ -26228,7 +26230,7 @@ var Actors = make37("actors").add(get7("getActor", actorPath, {
|
|
|
26228
26230
|
error: errors
|
|
26229
26231
|
}), get7("listActors", base, {
|
|
26230
26232
|
params: accountParams,
|
|
26231
|
-
query: pageQuery,
|
|
26233
|
+
query: { ...pageQuery, metadata: optionalKey2(fromJsonString2(CallMetadata)) },
|
|
26232
26234
|
success: Struct({ items: ArraySchema(Actor2), cursor: optionalKey2(Identifier) }),
|
|
26233
26235
|
error: errors
|
|
26234
26236
|
}), del("deleteActor", actorPath, {
|
|
@@ -26415,7 +26417,7 @@ var Credits2 = make37("credits").add(get7("getCredits", "/v1/accounts/:account/c
|
|
|
26415
26417
|
error: errors
|
|
26416
26418
|
}), get7("getUsage", "/v1/accounts/:account/usage", {
|
|
26417
26419
|
params: accountParams,
|
|
26418
|
-
query: { from: optionalKey2(queryInteger), to: optionalKey2(queryInteger), groupBy: optionalKey2(UsageGroup) },
|
|
26420
|
+
query: { from: optionalKey2(queryInteger), to: optionalKey2(queryInteger), groupBy: optionalKey2(UsageGroup), metadata: optionalKey2(fromJsonString2(CallMetadata)) },
|
|
26419
26421
|
success: Usage,
|
|
26420
26422
|
error: errors
|
|
26421
26423
|
}));
|
|
@@ -26987,16 +26989,18 @@ actorctl events main --last 20
|
|
|
26987
26989
|
import { existsSync as existsSync3, readdirSync } from "fs";
|
|
26988
26990
|
import { mkdir as mkdir3, writeFile as writeFile4 } from "fs/promises";
|
|
26989
26991
|
import { dirname as dirname2, join as join5, relative, resolve as resolve5 } from "path";
|
|
26992
|
+
var metadataFlag = optional6("metadata", 'Opaque metadata JSON, e.g. {"tenant":"user_123"}; replaces the map.');
|
|
26993
|
+
var readMetadata = (value) => isSome2(value) ? decodeUnknownEffect2(fromJsonString2(CallMetadata))(value.value).pipe(map7((metadata) => ({ metadata }))) : succeed6({});
|
|
26990
26994
|
var cursor = optional6("cursor", "Continue from a previous page cursor.");
|
|
26991
26995
|
var entry = String10("entry").pipe(optional4, withDescription2("Actor source file; defaults to entry in local config."));
|
|
26992
26996
|
var version = String10("version").pipe(withDescription2("Version identifier."));
|
|
26993
26997
|
var query = (cursor) => isSome2(cursor) ? { cursor: cursor.value } : {};
|
|
26994
|
-
var actorsList = make30("list", { ...remote, cursor }, (flags) => gen2(function* () {
|
|
26998
|
+
var actorsList = make30("list", { ...remote, cursor, metadata: metadataFlag }, (flags) => gen2(function* () {
|
|
26995
26999
|
const config = yield* resolveConfig(flags);
|
|
26996
27000
|
const client = yield* cloudClient(config.url);
|
|
26997
|
-
const result = yield* client.actors.listActors({ params: { account: config.account }, query: query(flags.cursor) });
|
|
27001
|
+
const result = yield* client.actors.listActors({ params: { account: config.account }, query: { ...query(flags.cursor), ...yield* readMetadata(flags.metadata) } });
|
|
26998
27002
|
yield* print(flags.json, result, [
|
|
26999
|
-
...result.items.length ? result.items.map((actor) => `${actor.name} ${actor.description}`) : ["No actors found."],
|
|
27003
|
+
...result.items.length ? result.items.map((actor) => `${actor.name} ${actor.description} ${JSON.stringify(actor.metadata ?? {})}`) : ["No actors found."],
|
|
27000
27004
|
...next(result.cursor)
|
|
27001
27005
|
]);
|
|
27002
27006
|
}).pipe(mapError2(userError))).pipe(withDescription4("List actors in an account."));
|
|
@@ -27007,12 +27011,22 @@ var actorsInfo = make30("info", { ...remote, name: String10("name") }, (flags) =
|
|
|
27007
27011
|
yield* print(flags.json, result, [
|
|
27008
27012
|
result.name,
|
|
27009
27013
|
result.description,
|
|
27014
|
+
`Metadata: ${JSON.stringify(result.metadata ?? {})}`,
|
|
27010
27015
|
`Active deployment: ${result.activeDeployment?.id ?? "none"}`,
|
|
27011
27016
|
`Active version: ${result.activeDeployment?.version ?? "none"}`,
|
|
27012
27017
|
`Endpoint: ${result.endpoint ?? "none"}`,
|
|
27013
27018
|
`Latest deployment: ${result.latestDeployment === null ? "none" : `${result.latestDeployment.id} (${result.latestDeployment.status})`}`
|
|
27014
27019
|
]);
|
|
27015
27020
|
}).pipe(mapError2(userError))).pipe(withDescription4("Inspect an actor and its deployment."));
|
|
27021
|
+
var actorsPut = make30("put", { ...remote, name: String10("name"), description: optional6("description", "Actor description."), metadata: metadataFlag }, (flags) => gen2(function* () {
|
|
27022
|
+
const config = yield* resolveConfig(flags);
|
|
27023
|
+
const client = yield* cloudClient(config.url);
|
|
27024
|
+
const result = yield* client.actors.putActor({ params: { account: config.account, name: flags.name }, payload: {
|
|
27025
|
+
...isSome2(flags.description) ? { description: flags.description.value } : {},
|
|
27026
|
+
...yield* readMetadata(flags.metadata)
|
|
27027
|
+
} });
|
|
27028
|
+
yield* print(flags.json, result, [result.name, result.description, `Metadata: ${JSON.stringify(result.metadata ?? {})}`]);
|
|
27029
|
+
}).pipe(mapError2(userError))).pipe(withDescription4("Register an actor or replace supplied fields; omitted metadata is preserved."));
|
|
27016
27030
|
var versionsList = make30("list", { ...scoped4, cursor }, (flags) => gen2(function* () {
|
|
27017
27031
|
const config = yield* resolveConfig(flags);
|
|
27018
27032
|
const name = yield* requireActor(config);
|
|
@@ -27139,13 +27153,13 @@ var actorctl = make30("actorctl").pipe(withDescription4("Deploy actors, run thre
|
|
|
27139
27153
|
call,
|
|
27140
27154
|
events2,
|
|
27141
27155
|
sql,
|
|
27142
|
-
make30("actors").pipe(withSubcommands([actorsList, actorsInfo, actorsDelete])),
|
|
27156
|
+
make30("actors").pipe(withSubcommands([actorsList, actorsInfo, actorsPut, actorsDelete])),
|
|
27143
27157
|
make30("versions").pipe(withSubcommands([versionsList, versionsView])),
|
|
27144
27158
|
make30("deployments").pipe(withSubcommands([deploymentsList])),
|
|
27145
27159
|
make30("secrets").pipe(withSubcommands([secretsPut, secretsDelete]))
|
|
27146
27160
|
]));
|
|
27147
27161
|
// package.json
|
|
27148
|
-
var version2 = "0.3.0-rc.
|
|
27162
|
+
var version2 = "0.3.0-rc.15";
|
|
27149
27163
|
|
|
27150
27164
|
// src/main.ts
|
|
27151
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";
|
|
@@ -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,27 +679,63 @@ var eventsPage = (rows, query) => ({
|
|
|
755
679
|
});
|
|
756
680
|
|
|
757
681
|
// ../../src/platform/cloudflare/router.ts
|
|
758
|
-
import { Effect as Effect16, Layer 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") {
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
// ../../src/services/metadata-store.ts
|
|
699
|
+
import { Context as Context9, Data as Data7, Schema as Schema4 } from "effect";
|
|
700
|
+
|
|
701
|
+
// ../../src/services/webhooks.ts
|
|
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
|
|
711
|
+
});
|
|
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"]))
|
|
718
|
+
});
|
|
719
|
+
var WebhookError = class extends Data6.TaggedError("WebhookError") {
|
|
720
|
+
};
|
|
721
|
+
var WebhookStore = class extends Context8.Service()("tardigrade-cloud/WebhookStore") {
|
|
722
|
+
};
|
|
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,
|
|
726
|
+
type: WebhookEventType,
|
|
727
|
+
status: Schema3.Literals(["pending", "delivered", "failed", "skipped"]),
|
|
728
|
+
createdAt: Schema3.Number,
|
|
729
|
+
attempts: Schema3.Array(WebhookAttempt)
|
|
730
|
+
});
|
|
731
|
+
var WebhookDeliveryService = class extends Context8.Service()("tardigrade-cloud/WebhookDeliveryService") {
|
|
772
732
|
};
|
|
773
733
|
|
|
774
734
|
// ../../src/services/metadata-store.ts
|
|
775
|
-
import { Context as Context9, Data as Data6, Schema as Schema4 } from "effect";
|
|
776
735
|
var Actor = Schema4.Struct({
|
|
777
736
|
name: Schema4.NonEmptyString,
|
|
778
|
-
description: Schema4.String
|
|
737
|
+
description: Schema4.String,
|
|
738
|
+
metadata: Schema4.optionalKey(CallMetadata)
|
|
779
739
|
}).annotate({ identifier: "Actor" });
|
|
780
740
|
var Version = Schema4.Struct({
|
|
781
741
|
id: Schema4.NonEmptyString,
|
|
@@ -790,7 +750,7 @@ var VersionRecord = Schema4.Struct({
|
|
|
790
750
|
...Version.fields,
|
|
791
751
|
artifactDigest: Schema4.String.check(Schema4.isPattern(/^sha256:[a-f0-9]{64}$/))
|
|
792
752
|
}).annotate({ identifier: "VersionRecord" });
|
|
793
|
-
var MetadataStoreError = class extends
|
|
753
|
+
var MetadataStoreError = class extends Data7.TaggedError("MetadataStoreError") {
|
|
794
754
|
};
|
|
795
755
|
var MetadataStore = class extends Context9.Service()("tardigrade-cloud/MetadataStore") {
|
|
796
756
|
};
|
|
@@ -803,7 +763,7 @@ var actorObjectName = (address) => JSON.stringify([address.accountId, address.ac
|
|
|
803
763
|
|
|
804
764
|
// ../../src/platform/cloudflare/runtime.ts
|
|
805
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() }));
|
|
806
|
-
var cloudflareHandler = (host) =>
|
|
766
|
+
var cloudflareHandler = (host) => HttpRouter.toWebHandler(hostRoutes(host), { disableLogger: true });
|
|
807
767
|
var DEFAULT_EVENT_PAGE_SIZE = 100;
|
|
808
768
|
var READY_PATH = "/__tardigrade/ready";
|
|
809
769
|
var cloudflareActorObject = (options) => class {
|
|
@@ -876,7 +836,7 @@ var cloudflareActorObject = (options) => class {
|
|
|
876
836
|
const input = await request.clone().json().catch(() => null);
|
|
877
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 });
|
|
878
838
|
}
|
|
879
|
-
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);
|
|
880
840
|
}
|
|
881
841
|
};
|
|
882
842
|
|
|
@@ -896,11 +856,11 @@ var createActorWorker = (actor, DurableObject, services, actorContext) => {
|
|
|
896
856
|
transports: { [WEBHOOK_TRANSPORT]: webhookTransport(env.WEBHOOKS) },
|
|
897
857
|
...actorContext ? { actorContext } : {},
|
|
898
858
|
services: (coordinate, runtime) => {
|
|
899
|
-
const platform =
|
|
859
|
+
const platform = Layer8.mergeAll(
|
|
900
860
|
ConfigProvider.layer(ConfigProvider.fromUnknown(secrets(env.SECRETS))),
|
|
901
861
|
boundAiGateway(deployment.accountId, env.INFERENCE)
|
|
902
862
|
);
|
|
903
|
-
return services ? services(runtime, coordinate).pipe(
|
|
863
|
+
return services ? services(runtime, coordinate).pipe(Layer8.provideMerge(platform)) : platform;
|
|
904
864
|
},
|
|
905
865
|
analytics: cloudflareAnalytics(deployment.accountId, env.ANALYTICS),
|
|
906
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.15",
|
|
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": "44da75311ba234a08beb4452bee1c55507dcd92c"
|
|
30
30
|
}
|
|
31
31
|
}
|