@fungi.computer/oyster 0.50.1 → 0.50.3
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/standalone/agent-engine.d.ts +32 -0
- package/dist/standalone/agent-engine.js +24 -0
- package/dist/standalone/agents.d.ts +29 -4
- package/dist/standalone/agents.js +48 -13
- package/dist/standalone/model-key-usage.d.ts +10 -1
- package/dist/workers-git.d.ts +7 -0
- package/dist/workers-git.js +67 -16
- package/docs/api/workers-git.md +4 -1
- package/package.json +6 -6
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ColdSessionPage, ColdSessionPageRequest } from "@fungi.computer/shiitake";
|
|
2
|
+
import { type CloudflareShiitake, type CloudflareShiitakeOptions, type CloudflareShiitakeState, type SessionInboxChanges } from "@fungi.computer/shiitake/cloudflare";
|
|
3
|
+
import type { StandaloneAgentEnv } from "./agents.js";
|
|
4
|
+
/**
|
|
5
|
+
* The engine an Oyster Agent's Durable Object composes. The Durable Object
|
|
6
|
+
* keeps Oyster's own Agent state (policy pin, MCP servers, channels); the
|
|
7
|
+
* engine owns Sessions, their wire and their wakes. Shiitake is the only
|
|
8
|
+
* engine today.
|
|
9
|
+
*/
|
|
10
|
+
export type AgentEngine = Readonly<{
|
|
11
|
+
kind: "shiitake";
|
|
12
|
+
/** Serve one request on the Session wire. */
|
|
13
|
+
fetch: (request: Request) => Promise<Response>;
|
|
14
|
+
/** Reconcile due runtime and host work after a native alarm. */
|
|
15
|
+
alarm: () => Promise<void>;
|
|
16
|
+
/** Persist a wake and run one reconciliation pass now. */
|
|
17
|
+
wake: () => Promise<void>;
|
|
18
|
+
/** The open Session agent, for App sends, channels and fleet operations. */
|
|
19
|
+
agent: () => Promise<CloudflareShiitake>;
|
|
20
|
+
/** Bounded strict-after read of the Agent's changed inbox rows. */
|
|
21
|
+
inboxChanges: (after: number, limit: number) => Promise<SessionInboxChanges>;
|
|
22
|
+
/** Latest inbox clock, without reading Session rows. */
|
|
23
|
+
inboxRevision: () => Promise<number>;
|
|
24
|
+
/** Whether a readable Session is stored under this id. */
|
|
25
|
+
hasStoredSession: (sessionId: string) => Promise<boolean>;
|
|
26
|
+
/** One bounded page of cold Sessions for the store keeper. */
|
|
27
|
+
coldSessions: (request: ColdSessionPageRequest) => Promise<ColdSessionPage>;
|
|
28
|
+
/** Close owned resources before storage erasure; a cold engine has none. */
|
|
29
|
+
close: () => Promise<void>;
|
|
30
|
+
}>;
|
|
31
|
+
/** Shiitake as an Agent engine: its composable Cloudflare owner, unchanged. */
|
|
32
|
+
export declare function shiitakeEngine(ctx: CloudflareShiitakeState, env: StandaloneAgentEnv, options: () => CloudflareShiitakeOptions | Promise<CloudflareShiitakeOptions>): AgentEngine;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ShiitakeOwner, } from "@fungi.computer/shiitake/cloudflare";
|
|
2
|
+
/** Shiitake as an Agent engine: its composable Cloudflare owner, unchanged. */
|
|
3
|
+
export function shiitakeEngine(ctx, env, options) {
|
|
4
|
+
const owner = new (class extends ShiitakeOwner {
|
|
5
|
+
shiitakeOptions() {
|
|
6
|
+
return options();
|
|
7
|
+
}
|
|
8
|
+
})(ctx, env);
|
|
9
|
+
return {
|
|
10
|
+
kind: "shiitake",
|
|
11
|
+
fetch: (request) => owner.fetch(request),
|
|
12
|
+
alarm: () => owner.alarm(),
|
|
13
|
+
wake: () => owner.wakeRuntime(),
|
|
14
|
+
agent: () => owner.shiitake(),
|
|
15
|
+
inboxChanges: (after, limit) => owner.readInboxChanges(after, limit),
|
|
16
|
+
inboxRevision: async () => {
|
|
17
|
+
await owner.shiitake();
|
|
18
|
+
return owner.readInboxRevision();
|
|
19
|
+
},
|
|
20
|
+
hasStoredSession: (sessionId) => owner.hasStoredSession(sessionId),
|
|
21
|
+
coldSessions: (request) => owner.readColdSessions(request),
|
|
22
|
+
close: () => owner.closeShiitake(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -26,13 +26,14 @@ import type { VaultRequestData } from "@fungi.computer/computer/egress";
|
|
|
26
26
|
import type { ConnectionSubject, ConnectionUsage, HttpDestinations, Placement } from "@fungi.computer/veil/connections";
|
|
27
27
|
import { DurableObject } from "cloudflare:workers";
|
|
28
28
|
import { type StandaloneComputerEnv } from "./computer.js";
|
|
29
|
-
import {
|
|
29
|
+
import { type AgentEngine } from "./agent-engine.js";
|
|
30
30
|
import { type ModelKeyRecord, type ModelKeyRefusal, type ModelKeySealInput } from "./model-key-vault.js";
|
|
31
31
|
import type { VaultCommand, VaultResult } from "./vault.js";
|
|
32
32
|
import type { CloudflareShiitakeOptions } from "@fungi.computer/shiitake/cloudflare";
|
|
33
33
|
import { type AgentModelChoice, type AgentModelRefusal } from "./agent-model-choice.js";
|
|
34
34
|
import * as Schema from "effect/Schema";
|
|
35
35
|
import { type FingerprintSet } from "@fungi.computer/veil/redaction";
|
|
36
|
+
import type { ColdSessionPageRequest } from "@fungi.computer/shiitake";
|
|
36
37
|
import { type FrameBindingProps } from "../cloudflare.js";
|
|
37
38
|
import { type AppAgentScheduleListInput, type AgentSchedulePage, type AgentScheduleTarget, type AgentScheduleControlReceipt } from "../agent-schedules.js";
|
|
38
39
|
import { type StarterLedgerRow } from "../starter-agent.js";
|
|
@@ -106,9 +107,28 @@ export type AgentInboxRows = Readonly<{
|
|
|
106
107
|
rows: readonly OysterSessionRow[];
|
|
107
108
|
revision: number;
|
|
108
109
|
}>;
|
|
109
|
-
/**
|
|
110
|
-
|
|
110
|
+
/**
|
|
111
|
+
* One agent: this Durable Object keeps Oyster's own Agent state and composes
|
|
112
|
+
* one Session engine; its root supplies `hostFor`.
|
|
113
|
+
*/
|
|
114
|
+
export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv = StandaloneAgentEnv> extends DurableObject<Env> {
|
|
111
115
|
#private;
|
|
116
|
+
/** The Session engine this Agent composes; Shiitake over this Agent's options. */
|
|
117
|
+
protected engine(): AgentEngine;
|
|
118
|
+
private agentEngine;
|
|
119
|
+
/** The engine's open Session agent. */
|
|
120
|
+
protected shiitake(): Promise<import("@fungi.computer/shiitake/cloudflare").CloudflareShiitake>;
|
|
121
|
+
/** One bounded page of the engine's cold Sessions, for the store keeper. */
|
|
122
|
+
protected readColdSessions(request: ColdSessionPageRequest): Promise<Readonly<{
|
|
123
|
+
sessions: readonly import("@fungi.computer/shiitake").ColdSessionRow[];
|
|
124
|
+
next?: string;
|
|
125
|
+
}>>;
|
|
126
|
+
/** Persist a wake and run one engine reconciliation pass. */
|
|
127
|
+
protected wakeRuntime(): Promise<void>;
|
|
128
|
+
/** Reconcile due runtime and host work through the engine. */
|
|
129
|
+
alarm(): Promise<void>;
|
|
130
|
+
/** The host's own routes first, then the engine's Session wire. */
|
|
131
|
+
fetch(request: Request): Promise<Response>;
|
|
112
132
|
private archiveControlOwner;
|
|
113
133
|
private archiveControl;
|
|
114
134
|
/** Owner-local atomic transition. The caller checks human/creator authority. */
|
|
@@ -253,8 +273,13 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
253
273
|
private readComputerGeneration;
|
|
254
274
|
private readComputerSnapshot;
|
|
255
275
|
private ui;
|
|
276
|
+
/**
|
|
277
|
+
* The host's own routes, in front of the engine's: a response answers the
|
|
278
|
+
* request, undefined lets the engine serve it.
|
|
279
|
+
*/
|
|
256
280
|
protected hostFetch(request: Request): Promise<Response> | undefined;
|
|
257
281
|
private readAgentModels;
|
|
282
|
+
/** Close the browser connection and the engine before storage erasure. */
|
|
258
283
|
protected closeShiitake(): Promise<void>;
|
|
259
284
|
private controlDirectory;
|
|
260
285
|
private delegationOwner;
|
|
@@ -354,7 +379,7 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
354
379
|
status: "accepted";
|
|
355
380
|
commandId: string;
|
|
356
381
|
}>;
|
|
357
|
-
/** Latest inbox clock from the
|
|
382
|
+
/** Latest inbox clock from the engine, without reading Session rows. */
|
|
358
383
|
revision(): Promise<number>;
|
|
359
384
|
/** Every live Session of this agent, as inbox rows. */
|
|
360
385
|
inboxRows(): Promise<AgentInboxRows>;
|
|
@@ -30,8 +30,8 @@ import { createStandaloneMachineEnrollment, standaloneMachineAgentHome, standalo
|
|
|
30
30
|
import { createMachineLinkFences, MachineEnrollmentRefused, MachineLinkRefused, createMachineAgentClient, } from "../machine-link/index.js";
|
|
31
31
|
import { memberInboxItemSchema } from "@fungi.computer/puffball/inbox";
|
|
32
32
|
/**
|
|
33
|
-
* Agents on a standalone Oyster Worker. Each agent is
|
|
34
|
-
*
|
|
33
|
+
* Agents on a standalone Oyster Worker. Each agent is one Durable Object that
|
|
34
|
+
* composes its Session engine (Shiitake today, see `agent-engine.ts`); a directory
|
|
35
35
|
* Durable Object names them and keeps the member's visits. The model comes
|
|
36
36
|
* from a pluggable `ModelSource`; the default runs Workers AI through the
|
|
37
37
|
* Worker's AI binding, with no API token.
|
|
@@ -47,7 +47,7 @@ import { homeContract, homeInstructionsLimit, } from "@fungi.computer/shiitake-e
|
|
|
47
47
|
import { resolveHome } from "@fungi.computer/shiitake-extensions/home/host";
|
|
48
48
|
import { DurableObject } from "cloudflare:workers";
|
|
49
49
|
import { standaloneHomeInstructionsFile, } from "./computer.js";
|
|
50
|
-
import {
|
|
50
|
+
import { shiitakeEngine } from "./agent-engine.js";
|
|
51
51
|
import { agentStoreKeeping } from "./agent-store.js";
|
|
52
52
|
import { CredentialError, } from "@fungi.computer/veil/credential-store";
|
|
53
53
|
import { createInstanceCredentialStore, createModelKeyVault, instanceCredentialKeyring, instanceSecretCustody, ModelKeyRefused, } from "./model-key-vault.js";
|
|
@@ -338,8 +338,39 @@ const instructions = [
|
|
|
338
338
|
"Only the value your program returns is visible to you; console.log output is not. Always `return` the result.",
|
|
339
339
|
"Be direct and brief. Say plainly when you cannot do something.",
|
|
340
340
|
].join("\n");
|
|
341
|
-
/**
|
|
342
|
-
|
|
341
|
+
/**
|
|
342
|
+
* One agent: this Durable Object keeps Oyster's own Agent state and composes
|
|
343
|
+
* one Session engine; its root supplies `hostFor`.
|
|
344
|
+
*/
|
|
345
|
+
export class StandaloneAgentBase extends DurableObject {
|
|
346
|
+
#engine;
|
|
347
|
+
/** The Session engine this Agent composes; Shiitake over this Agent's options. */
|
|
348
|
+
engine() {
|
|
349
|
+
return shiitakeEngine(this.ctx, this.env, () => this.shiitakeOptions());
|
|
350
|
+
}
|
|
351
|
+
agentEngine() {
|
|
352
|
+
return (this.#engine ??= this.engine());
|
|
353
|
+
}
|
|
354
|
+
/** The engine's open Session agent. */
|
|
355
|
+
shiitake() {
|
|
356
|
+
return this.agentEngine().agent();
|
|
357
|
+
}
|
|
358
|
+
/** One bounded page of the engine's cold Sessions, for the store keeper. */
|
|
359
|
+
readColdSessions(request) {
|
|
360
|
+
return this.agentEngine().coldSessions(request);
|
|
361
|
+
}
|
|
362
|
+
/** Persist a wake and run one engine reconciliation pass. */
|
|
363
|
+
wakeRuntime() {
|
|
364
|
+
return this.agentEngine().wake();
|
|
365
|
+
}
|
|
366
|
+
/** Reconcile due runtime and host work through the engine. */
|
|
367
|
+
alarm() {
|
|
368
|
+
return this.agentEngine().alarm();
|
|
369
|
+
}
|
|
370
|
+
/** The host's own routes first, then the engine's Session wire. */
|
|
371
|
+
fetch(request) {
|
|
372
|
+
return this.hostFetch(request) ?? this.agentEngine().fetch(request);
|
|
373
|
+
}
|
|
343
374
|
archiveControlOwner;
|
|
344
375
|
archiveControl() {
|
|
345
376
|
return (this.archiveControlOwner ??= agentArchiveOwner({
|
|
@@ -829,9 +860,13 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
829
860
|
const { Knapsack } = await import("@fungi.computer/knapsack");
|
|
830
861
|
return (this.uiOwner ??= Knapsack.ui({
|
|
831
862
|
id: "oyster-ui",
|
|
832
|
-
hasSession: (sessionId) => this.hasStoredSession(sessionId),
|
|
863
|
+
hasSession: (sessionId) => this.agentEngine().hasStoredSession(sessionId),
|
|
833
864
|
}));
|
|
834
865
|
}
|
|
866
|
+
/**
|
|
867
|
+
* The host's own routes, in front of the engine's: a response answers the
|
|
868
|
+
* request, undefined lets the engine serve it.
|
|
869
|
+
*/
|
|
835
870
|
hostFetch(request) {
|
|
836
871
|
const pathname = new URL(request.url).pathname;
|
|
837
872
|
if (pathname === "/models" && request.method === "GET")
|
|
@@ -848,7 +883,7 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
848
883
|
if (request.method === "POST" &&
|
|
849
884
|
pathname.startsWith("/sessions/") &&
|
|
850
885
|
pathname.endsWith(`/extensions/${homeContract.id}/commands/home`))
|
|
851
|
-
return this.preparedComputerSnapshot().then(() => this.
|
|
886
|
+
return this.preparedComputerSnapshot().then(() => this.agentEngine().fetch(request));
|
|
852
887
|
return undefined;
|
|
853
888
|
}
|
|
854
889
|
async readAgentModels() {
|
|
@@ -879,12 +914,13 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
879
914
|
},
|
|
880
915
|
]));
|
|
881
916
|
}
|
|
917
|
+
/** Close the browser connection and the engine before storage erasure. */
|
|
882
918
|
async closeShiitake() {
|
|
883
919
|
try {
|
|
884
920
|
await (await this.ui()).close();
|
|
885
921
|
}
|
|
886
922
|
finally {
|
|
887
|
-
await
|
|
923
|
+
await this.agentEngine().close();
|
|
888
924
|
}
|
|
889
925
|
}
|
|
890
926
|
controlDirectory() {
|
|
@@ -1575,14 +1611,13 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
1575
1611
|
};
|
|
1576
1612
|
return sessions.send(grant, id, sessionId, message);
|
|
1577
1613
|
}
|
|
1578
|
-
/** Latest inbox clock from the
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
return this.readInboxRevision();
|
|
1614
|
+
/** Latest inbox clock from the engine, without reading Session rows. */
|
|
1615
|
+
revision() {
|
|
1616
|
+
return this.agentEngine().inboxRevision();
|
|
1582
1617
|
}
|
|
1583
1618
|
/** Every live Session of this agent, as inbox rows. */
|
|
1584
1619
|
async inboxRows() {
|
|
1585
|
-
const changes = await this.
|
|
1620
|
+
const changes = await this.agentEngine().inboxChanges(0, 1_000);
|
|
1586
1621
|
const rows = [];
|
|
1587
1622
|
for (const row of changes.rows) {
|
|
1588
1623
|
if ("deleted" in row)
|
|
@@ -17,8 +17,17 @@ export type ModelKeyUsage = Readonly<{
|
|
|
17
17
|
lastAt: number;
|
|
18
18
|
count: number;
|
|
19
19
|
}>;
|
|
20
|
+
/**
|
|
21
|
+
* The Durable Object SQL this store needs, as a structural type, so the
|
|
22
|
+
* published declarations never name the Workers-only `SqlStorage` global.
|
|
23
|
+
*/
|
|
24
|
+
export type ModelKeyUsageSql = Readonly<{
|
|
25
|
+
exec: (statement: string, ...bindings: (string | number | null)[]) => Readonly<{
|
|
26
|
+
toArray: () => readonly unknown[];
|
|
27
|
+
}>;
|
|
28
|
+
}>;
|
|
20
29
|
export declare function createModelKeyUsage(options: {
|
|
21
|
-
sql:
|
|
30
|
+
sql: ModelKeyUsageSql;
|
|
22
31
|
now?: () => number;
|
|
23
32
|
}): {
|
|
24
33
|
record(use: ModelKeyUse): void;
|
package/dist/workers-git.d.ts
CHANGED
|
@@ -96,6 +96,13 @@ export type WebhookDelivery = Readonly<{
|
|
|
96
96
|
state: "pending" | "delivered" | "failed";
|
|
97
97
|
attempts: number;
|
|
98
98
|
lastStatus: number | null;
|
|
99
|
+
/**
|
|
100
|
+
* Why a pending delivery is held without spending its retries: the host's
|
|
101
|
+
* keyring cannot open the subscription's signing secret. A delivery held
|
|
102
|
+
* past the hold limit is failed and keeps the reason, prefixed
|
|
103
|
+
* "Held 7 days: ". Null otherwise.
|
|
104
|
+
*/
|
|
105
|
+
heldReason: string | null;
|
|
99
106
|
updatedAt: number;
|
|
100
107
|
}>;
|
|
101
108
|
/**
|
package/dist/workers-git.js
CHANGED
|
@@ -494,6 +494,19 @@ export class OysterKeys extends DurableObject {
|
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
496
|
const RETRY_DELAYS_MS = [10_000, 60_000, 300_000, 1_800_000, 7_200_000];
|
|
497
|
+
/** How often a delivery held on the keyring checks it again. */
|
|
498
|
+
const HELD_RECHECK_MS = 60_000;
|
|
499
|
+
/** A held delivery fails after this long, so held rows cannot pile up forever. */
|
|
500
|
+
const HOLD_LIMIT_MS = 7 * 24 * 60 * 60 * 1000;
|
|
501
|
+
/**
|
|
502
|
+
* A keyring fault is the host's configuration, not the receiver's: the
|
|
503
|
+
* delivery waits for it without counting attempts, so none is lost.
|
|
504
|
+
*/
|
|
505
|
+
const heldReasons = {
|
|
506
|
+
"keyring-missing": "No webhook keyring is configured (OYSTER_CREDENTIAL_KEY), so this delivery is held until one is.",
|
|
507
|
+
"keyring-malformed": "The webhook keyring (OYSTER_CREDENTIAL_KEY) is malformed, so this delivery is held until it is fixed.",
|
|
508
|
+
"keyring-unknown-key": "The webhook keyring does not hold the key this subscription's secret was sealed with, so this delivery is held until that key is restored.",
|
|
509
|
+
};
|
|
497
510
|
const subscriptionRow = Schema.Struct({
|
|
498
511
|
id: Schema.String,
|
|
499
512
|
installation_id: Schema.String,
|
|
@@ -508,6 +521,11 @@ const deliveryRow = Schema.Struct({
|
|
|
508
521
|
state: Schema.Literals(["pending", "delivered", "failed"]),
|
|
509
522
|
attempts: Schema.Number,
|
|
510
523
|
last_status: Schema.NullOr(Schema.Number),
|
|
524
|
+
held_reason: Schema.NullOr(Schema.Literals([
|
|
525
|
+
"keyring-missing",
|
|
526
|
+
"keyring-malformed",
|
|
527
|
+
"keyring-unknown-key",
|
|
528
|
+
])),
|
|
511
529
|
updated_at: Schema.Number,
|
|
512
530
|
});
|
|
513
531
|
const typesSchema = Schema.fromJsonString(Schema.Array(Schema.String));
|
|
@@ -540,6 +558,27 @@ const webhookSubscriptions002 = {
|
|
|
540
558
|
};
|
|
541
559
|
},
|
|
542
560
|
};
|
|
561
|
+
/**
|
|
562
|
+
* Open a subscription's signing secret. A keyring fault holds the delivery;
|
|
563
|
+
* a corrupt or tampered secret, or any other failure to open, counts as a
|
|
564
|
+
* failed attempt, never sent unsigned.
|
|
565
|
+
*/
|
|
566
|
+
async function openSigningSecret(sealer, subscription, sealed) {
|
|
567
|
+
if (sealer === undefined)
|
|
568
|
+
return { kind: "held", reason: "keyring-missing" };
|
|
569
|
+
const opened = await Effect.runPromise(Effect.result(Effect.tryPromise({
|
|
570
|
+
try: () => sealer.open(subscriptionContext(subscription), sealed),
|
|
571
|
+
catch: (cause) => cause,
|
|
572
|
+
})));
|
|
573
|
+
if (Result.isSuccess(opened))
|
|
574
|
+
return { kind: "open", secret: opened.success };
|
|
575
|
+
const cause = opened.failure;
|
|
576
|
+
if (cause instanceof CredentialError && cause.code === "unavailable")
|
|
577
|
+
return { kind: "held", reason: "keyring-malformed" };
|
|
578
|
+
if (cause instanceof CredentialError && cause.code === "unknown-key")
|
|
579
|
+
return { kind: "held", reason: "keyring-unknown-key" };
|
|
580
|
+
return { kind: "unopened" };
|
|
581
|
+
}
|
|
543
582
|
function toSubscription(row) {
|
|
544
583
|
const decoded = Schema.decodeUnknownSync(subscriptionRow)(row);
|
|
545
584
|
return {
|
|
@@ -566,9 +605,19 @@ export class OysterWebhooks extends DurableObject {
|
|
|
566
605
|
CREATE TABLE IF NOT EXISTS oyster_deliveries (
|
|
567
606
|
id TEXT PRIMARY KEY, subscription TEXT NOT NULL, type TEXT NOT NULL, body TEXT NOT NULL,
|
|
568
607
|
state TEXT NOT NULL, attempts INTEGER NOT NULL, next_at INTEGER NOT NULL,
|
|
569
|
-
last_status INTEGER, updated_at INTEGER NOT NULL
|
|
608
|
+
last_status INTEGER, updated_at INTEGER NOT NULL, held_reason TEXT,
|
|
609
|
+
held_since INTEGER) STRICT;
|
|
570
610
|
CREATE INDEX IF NOT EXISTS oyster_deliveries_due ON oyster_deliveries(state, next_at);
|
|
571
611
|
`);
|
|
612
|
+
// An older Oyster's deliveries table has no hold columns; its rows keep
|
|
613
|
+
// their state and attempts and read as not held.
|
|
614
|
+
const deliveryColumns = Schema.decodeUnknownSync(columnNames)(ctx.storage.sql.exec("PRAGMA table_info(oyster_deliveries)").toArray()).map(({ name }) => name);
|
|
615
|
+
for (const [column, type] of [
|
|
616
|
+
["held_reason", "TEXT"],
|
|
617
|
+
["held_since", "INTEGER"],
|
|
618
|
+
])
|
|
619
|
+
if (!deliveryColumns.includes(column))
|
|
620
|
+
ctx.storage.sql.exec(`ALTER TABLE oyster_deliveries ADD COLUMN ${column} ${type}`);
|
|
572
621
|
this.#recipients = createRecipientDeliveries({
|
|
573
622
|
sql: ctx.storage.sql,
|
|
574
623
|
now: () => Date.now(),
|
|
@@ -660,7 +709,7 @@ export class OysterWebhooks extends DurableObject {
|
|
|
660
709
|
/** Recent deliveries for one subscription, newest first. */
|
|
661
710
|
deliveries(subscription) {
|
|
662
711
|
return this.ctx.storage.sql
|
|
663
|
-
.exec("SELECT id, subscription, type, state, attempts, last_status, updated_at FROM oyster_deliveries WHERE subscription = ? ORDER BY updated_at DESC LIMIT 50", subscription)
|
|
712
|
+
.exec("SELECT id, subscription, type, state, attempts, last_status, held_reason, updated_at FROM oyster_deliveries WHERE subscription = ? ORDER BY updated_at DESC LIMIT 50", subscription)
|
|
664
713
|
.toArray()
|
|
665
714
|
.map((row) => {
|
|
666
715
|
const decoded = Schema.decodeUnknownSync(deliveryRow)(row);
|
|
@@ -671,6 +720,11 @@ export class OysterWebhooks extends DurableObject {
|
|
|
671
720
|
state: decoded.state,
|
|
672
721
|
attempts: decoded.attempts,
|
|
673
722
|
lastStatus: decoded.last_status,
|
|
723
|
+
heldReason: decoded.held_reason === null
|
|
724
|
+
? null
|
|
725
|
+
: decoded.state === "failed"
|
|
726
|
+
? `Held 7 days: ${heldReasons[decoded.held_reason]}`
|
|
727
|
+
: heldReasons[decoded.held_reason],
|
|
674
728
|
updatedAt: decoded.updated_at,
|
|
675
729
|
};
|
|
676
730
|
});
|
|
@@ -703,31 +757,28 @@ export class OysterWebhooks extends DurableObject {
|
|
|
703
757
|
await ready();
|
|
704
758
|
const now = Date.now();
|
|
705
759
|
const due = this.ctx.storage.sql
|
|
706
|
-
.exec("SELECT id, subscription, type, body, attempts FROM oyster_deliveries WHERE state = 'pending' AND next_at <= ? ORDER BY next_at LIMIT 25", now)
|
|
760
|
+
.exec("SELECT id, subscription, type, body, attempts, held_since FROM oyster_deliveries WHERE state = 'pending' AND next_at <= ? ORDER BY next_at LIMIT 25", now)
|
|
707
761
|
.toArray();
|
|
708
762
|
await Promise.all(due.map(async (delivery) => {
|
|
709
763
|
const target = this.ctx.storage.sql
|
|
710
764
|
.exec("SELECT url, sealed_secret FROM oyster_subscriptions WHERE id = ?", delivery.subscription)
|
|
711
765
|
.toArray()[0];
|
|
712
|
-
let status = null;
|
|
713
|
-
// A secret that does not open counts as a failed attempt: retried,
|
|
714
|
-
// then failed like a refusal, never sent unsigned.
|
|
715
766
|
const secret = target === undefined
|
|
716
767
|
? undefined
|
|
717
|
-
: await
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const attempt = await attemptWebhook({ url: target.url, secret: secret.
|
|
768
|
+
: await openSigningSecret(sealer, delivery.subscription, target.sealed_secret);
|
|
769
|
+
if (secret?.kind === "held") {
|
|
770
|
+
const heldSince = delivery.held_since ?? now;
|
|
771
|
+
this.ctx.storage.sql.exec("UPDATE oyster_deliveries SET state = ?, next_at = ?, held_reason = ?, held_since = ?, updated_at = ? WHERE id = ?", now - heldSince >= HOLD_LIMIT_MS ? "failed" : "pending", now + HELD_RECHECK_MS, secret.reason, heldSince, Date.now(), delivery.id);
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
let status = null;
|
|
775
|
+
if (target !== undefined && secret?.kind === "open") {
|
|
776
|
+
const attempt = await attemptWebhook({ url: target.url, secret: secret.secret }, delivery);
|
|
726
777
|
status = attempt.kind === "response" ? attempt.status : null;
|
|
727
778
|
}
|
|
728
779
|
const attempts = delivery.attempts + 1;
|
|
729
780
|
const delivered = status !== null && status >= 200 && status < 300;
|
|
730
|
-
this.ctx.storage.sql.exec("UPDATE oyster_deliveries SET state = ?, attempts = ?, next_at = ?, last_status = ?, updated_at = ? WHERE id = ?", delivered
|
|
781
|
+
this.ctx.storage.sql.exec("UPDATE oyster_deliveries SET state = ?, attempts = ?, next_at = ?, last_status = ?, held_reason = NULL, held_since = NULL, updated_at = ? WHERE id = ?", delivered
|
|
731
782
|
? "delivered"
|
|
732
783
|
: target === undefined || attempts > RETRY_DELAYS_MS.length
|
|
733
784
|
? "failed"
|
package/docs/api/workers-git.md
CHANGED
|
@@ -400,6 +400,7 @@ deliveries(subscription): Readonly<{
|
|
|
400
400
|
state: "pending" | "failed" | "delivered";
|
|
401
401
|
attempts: number;
|
|
402
402
|
lastStatus: number | null;
|
|
403
|
+
heldReason: string | null;
|
|
403
404
|
updatedAt: number;
|
|
404
405
|
}>[];
|
|
405
406
|
```
|
|
@@ -416,7 +417,8 @@ Recent deliveries for one subscription, newest first.
|
|
|
416
417
|
|
|
417
418
|
`Readonly`\<\{ `id`: `string`; `subscription`: `string`; `type`: `string`;
|
|
418
419
|
`state`: `"pending"` \| `"failed"` \| `"delivered"`; `attempts`: `number`;
|
|
419
|
-
`lastStatus`: `number` \| `null`; `
|
|
420
|
+
`lastStatus`: `number` \| `null`; `heldReason`: `string` \| `null`; `updatedAt`:
|
|
421
|
+
`number`; \}\>[]
|
|
420
422
|
|
|
421
423
|
##### enqueue()
|
|
422
424
|
|
|
@@ -1623,6 +1625,7 @@ type WebhookDelivery = Readonly<{
|
|
|
1623
1625
|
state: "pending" | "delivered" | "failed";
|
|
1624
1626
|
attempts: number;
|
|
1625
1627
|
lastStatus: number | null;
|
|
1628
|
+
heldReason: string | null;
|
|
1626
1629
|
updatedAt: number;
|
|
1627
1630
|
}>;
|
|
1628
1631
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/oyster",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.3",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Oyster by Fungi: open-source Apps for people and AI agents. Try with one command or run on your own Cloudflare account.",
|
|
6
6
|
"homepage": "https://docs.fungi.computer/oyster",
|
|
@@ -380,19 +380,19 @@
|
|
|
380
380
|
"@fungi.computer/lantern": "0.4.2",
|
|
381
381
|
"@fungi.computer/mycelium": "0.4.7",
|
|
382
382
|
"@fungi.computer/nacre": "0.8.6",
|
|
383
|
-
"@fungi.computer/parakeet": "0.16.
|
|
383
|
+
"@fungi.computer/parakeet": "0.16.4",
|
|
384
384
|
"@fungi.computer/puffball": "0.12.0",
|
|
385
385
|
"@fungi.computer/seam": "0.2.6",
|
|
386
|
-
"@fungi.computer/shiitake": "0.21.
|
|
387
|
-
"@fungi.computer/shiitake-extensions": "0.12.
|
|
386
|
+
"@fungi.computer/shiitake": "0.21.12",
|
|
387
|
+
"@fungi.computer/shiitake-extensions": "0.12.1",
|
|
388
388
|
"@fungi.computer/sigils": "0.3.2",
|
|
389
389
|
"@fungi.computer/sprite": "0.2.2",
|
|
390
390
|
"@fungi.computer/sprite-zdog": "0.3.2",
|
|
391
|
-
"@fungi.computer/veil": "0.11.
|
|
391
|
+
"@fungi.computer/veil": "0.11.3",
|
|
392
392
|
"@fungi.computer/watchdog": "0.1.4",
|
|
393
393
|
"@fungi.computer/whistle": "0.3.0",
|
|
394
394
|
"@fungi.computer/workflows-wire": "0.7.4",
|
|
395
|
-
"@fungi.computer/zookeeper": "0.0.
|
|
395
|
+
"@fungi.computer/zookeeper": "0.0.54",
|
|
396
396
|
"@jellybrick/dbus-next": "0.11.4",
|
|
397
397
|
"@modelcontextprotocol/server": "2.0.0",
|
|
398
398
|
"@msgpack/msgpack": "3.1.3",
|