@fungi.computer/oyster 0.37.2 → 0.38.1
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/README.md +5 -4
- package/dist/agents.js +9 -2
- package/dist/app-builds.d.ts +1 -1
- package/dist/app-region.d.ts +94 -0
- package/dist/app-region.js +316 -0
- package/dist/authorization.d.ts +58 -9
- package/dist/authorization.js +56 -11
- package/dist/backend-request.d.ts +4 -0
- package/dist/backend-request.js +3 -10
- package/dist/boot-host-script.js +1 -1
- package/dist/build/candidate-builder.d.ts +1 -1
- package/dist/build/candidate-cli.mjs +284 -17
- package/dist/build/effect.d.ts +3 -3
- package/dist/build/submission-contract.d.ts +1 -1
- package/dist/build/workspace-build.d.ts +2 -2
- package/dist/channels/discord-replies.d.ts +8 -1
- package/dist/channels/discord-replies.js +80 -29
- package/dist/cloudflare.d.ts +1 -0
- package/dist/cloudflare.js +12 -2
- package/dist/credential-migration-001.d.ts +14 -0
- package/dist/credential-migration-001.js +13 -0
- package/dist/credential-migration-002.d.ts +38 -0
- package/dist/credential-migration-002.js +74 -0
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +23 -13
- package/dist/index.d.ts +15 -1
- package/dist/index.js +19 -0
- package/dist/invocation.d.ts +165 -0
- package/dist/invocation.js +67 -0
- package/dist/keys.d.ts +4 -3
- package/dist/keys.js +5 -4
- package/dist/mcp-owner.d.ts +4 -3
- package/dist/mcp-owner.js +3 -2
- package/dist/page/mount.js +5 -1
- package/dist/page/region.d.ts +6 -0
- package/dist/page/region.js +12 -0
- package/dist/page-config.d.ts +2 -0
- package/dist/page-config.js +2 -0
- package/dist/page-script.js +2 -2
- package/dist/source/seed-receipt.d.ts +1 -1
- package/dist/source/template-seed.d.ts +1 -1
- package/dist/standalone/agent-connections.d.ts +49 -1
- package/dist/standalone/agent-connections.js +101 -12
- package/dist/standalone/agent-self.js +2 -1
- package/dist/standalone/agents.d.ts +7 -3
- package/dist/standalone/agents.js +42 -19
- package/dist/standalone/computer-fleet.d.ts +12 -6
- package/dist/standalone/computer-fleet.js +70 -29
- package/dist/standalone/computer.js +39 -14
- package/dist/standalone/instance.d.ts +3 -1
- package/dist/standalone/instance.js +8 -0
- package/dist/standalone/model-key-vault.d.ts +33 -4
- package/dist/standalone/model-key-vault.js +74 -17
- package/dist/standalone/preview.js +11 -10
- package/dist/standalone/try-cli.d.ts +12 -2
- package/dist/standalone/try-cli.js +170 -32
- package/dist/standalone/try-worker.d.ts +2 -0
- package/dist/standalone/try-worker.js +15 -0
- package/dist/standalone/worker.js +3 -3
- package/dist/standalone/workflow-host.d.ts +1 -1
- package/dist/standalone/workflows.d.ts +3 -3
- package/dist/standalone/workflows.js +7 -0
- package/dist/testing/capabilities.d.ts +2 -0
- package/dist/testing/capabilities.js +2 -0
- package/dist/webhook-custody.d.ts +14 -3
- package/dist/webhook-custody.js +165 -43
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.js +15 -3
- package/dist/workers-git.d.ts +24 -8
- package/dist/workers-git.js +105 -15
- package/dist/workers.d.ts +16 -0
- package/dist/workers.js +95 -5
- package/docs/api/apps.md +31 -31
- package/docs/api/authorization.md +119 -17
- package/docs/api/build-contract.md +8 -8
- package/docs/api/build.md +163 -174
- package/docs/api/cloudflare.md +171 -0
- package/docs/api/host.md +1 -0
- package/docs/api/index.md +23 -0
- package/docs/api/invocation.md +623 -23
- package/docs/api/keys.md +6 -6
- package/docs/api/pack.md +3 -3
- package/docs/api/page/mount.md +22 -20
- package/docs/api/workers-git.md +273 -157
- package/docs/api/workers.md +257 -175
- package/package.json +19 -18
|
@@ -24,7 +24,7 @@ export declare const seedReceiptInputSchema: Schema.Struct<{
|
|
|
24
24
|
readonly backend: Schema.Union<readonly [Schema.Null, Schema.Struct<{
|
|
25
25
|
readonly entry: Schema.optional<Schema.String>;
|
|
26
26
|
readonly runtime: Schema.Struct<{
|
|
27
|
-
readonly kind: Schema.
|
|
27
|
+
readonly kind: Schema.Literals<readonly ["durable-facet", "region"]>;
|
|
28
28
|
readonly stateSchema: Schema.Number;
|
|
29
29
|
}>;
|
|
30
30
|
readonly compatibilityDate: Schema.String;
|
|
@@ -30,7 +30,7 @@ export declare const templateSeedClaimSchema: Schema.Struct<{
|
|
|
30
30
|
readonly backend: Schema.Union<readonly [Schema.Null, Schema.Struct<{
|
|
31
31
|
readonly entry: Schema.optional<Schema.String>;
|
|
32
32
|
readonly runtime: Schema.Struct<{
|
|
33
|
-
readonly kind: Schema.
|
|
33
|
+
readonly kind: Schema.Literals<readonly ["durable-facet", "region"]>;
|
|
34
34
|
readonly stateSchema: Schema.Number;
|
|
35
35
|
}>;
|
|
36
36
|
readonly compatibilityDate: Schema.String;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { McpServersConnectionOptions } from "@fungi.computer/knapsack";
|
|
2
|
-
import { createSealedCustody, type ConnectionProjection, type EgressRef, type McpRefusal, type McpRequestData, type SqlStore } from "@fungi.computer/veil/connections";
|
|
2
|
+
import { createSealedCustody, type ConnectionProjection, type ConnectionSubject, type ConnectionView, type EgressRef, type HttpDestinations, type Placement, type McpRefusal, type McpRequestData, type SqlStore } from "@fungi.computer/veil/connections";
|
|
3
3
|
import { type ConnectionAccess, type ConnectionAdded, type ConnectionInput, type ConnectionRefusal, type OysterConnection } from "../agents.js";
|
|
4
|
+
/** A secret grant the owner refuses: no such live subject, or a kind the Vault does not serve. */
|
|
5
|
+
type SecretGrantRefusal = ConnectionRefusal | Readonly<{
|
|
6
|
+
error: "unsupported_subject";
|
|
7
|
+
}>;
|
|
4
8
|
/**
|
|
5
9
|
* This instance's Agent MCP connections over Veil's connections core. The
|
|
6
10
|
* owner holds every credential; an Agent receives a secret-free projection and
|
|
@@ -12,6 +16,12 @@ export declare function createAgentMcpConnections(options: {
|
|
|
12
16
|
/** The checked public transport; credentials ride only on this one hop. */
|
|
13
17
|
send: (request: Request) => Promise<Response>;
|
|
14
18
|
hasAgent: (agentId: string) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a grant's subject still stands: the Agent or Computer exists, the
|
|
21
|
+
* key exists and is live. Asked when a secret is granted and before every
|
|
22
|
+
* send, so an ended subject cannot keep using a grant it held.
|
|
23
|
+
*/
|
|
24
|
+
subjectLive: (subject: ConnectionSubject) => Promise<boolean>;
|
|
15
25
|
/** Told after a change so the Agent drops captured tools. */
|
|
16
26
|
notify: (agentId: string) => Promise<void>;
|
|
17
27
|
ownerId: string;
|
|
@@ -19,6 +29,43 @@ export declare function createAgentMcpConnections(options: {
|
|
|
19
29
|
callbackUrl: string;
|
|
20
30
|
}): {
|
|
21
31
|
list: () => Promise<readonly OysterConnection[]>;
|
|
32
|
+
addSecret: (input: Readonly<{
|
|
33
|
+
name: string;
|
|
34
|
+
label?: string | undefined;
|
|
35
|
+
destinations: HttpDestinations;
|
|
36
|
+
placement: Placement;
|
|
37
|
+
secret: string;
|
|
38
|
+
}>) => Promise<Readonly<{
|
|
39
|
+
connectionId: string;
|
|
40
|
+
}> | ConnectionRefusal>;
|
|
41
|
+
secrets: () => Promise<readonly ConnectionView[]>;
|
|
42
|
+
grantSecret: (connectionId: string, subject: ConnectionSubject) => Promise<Readonly<{
|
|
43
|
+
ok: true;
|
|
44
|
+
}> | SecretGrantRefusal>;
|
|
45
|
+
ungrantSecret: (connectionId: string, subject: ConnectionSubject) => Promise<void>;
|
|
46
|
+
/** Every recorded use and refusal of one secret, without its value. */
|
|
47
|
+
secretUsage: (connectionId: string) => Promise<{
|
|
48
|
+
readonly firstAt: number;
|
|
49
|
+
readonly lastAt: number;
|
|
50
|
+
readonly count: number;
|
|
51
|
+
readonly requestId: string;
|
|
52
|
+
readonly connectionId: string;
|
|
53
|
+
readonly subject: {
|
|
54
|
+
readonly kind: "agent" | "computer" | "app" | "team-key";
|
|
55
|
+
readonly id: string;
|
|
56
|
+
};
|
|
57
|
+
readonly grantor: string | null;
|
|
58
|
+
readonly host: string | null;
|
|
59
|
+
readonly pathTemplate: "/" | "/:segment" | "/:segment/\u2026";
|
|
60
|
+
readonly pathLength: "short" | "medium" | "long";
|
|
61
|
+
readonly method: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "OTHER";
|
|
62
|
+
readonly outcome: "placed" | "refused_destination" | "refused_grant" | "upstream_status";
|
|
63
|
+
readonly status: number | null;
|
|
64
|
+
}[]>;
|
|
65
|
+
/** Complete one request with a secret on the owner side; the caller names its subject. */
|
|
66
|
+
fetchSecret: (subject: ConnectionSubject, ref: EgressRef, data: McpRequestData) => Promise<Response | Readonly<{
|
|
67
|
+
error: string;
|
|
68
|
+
}>>;
|
|
22
69
|
add: (input: ConnectionInput) => Promise<ConnectionAdded | ConnectionRefusal>;
|
|
23
70
|
grant: (connectionId: string, agentId: string, access: ConnectionAccess) => Promise<Readonly<{
|
|
24
71
|
ok: true;
|
|
@@ -48,3 +95,4 @@ export declare function agentMcpSourceOptions(input: {
|
|
|
48
95
|
onUnavailable: McpServersConnectionOptions["onUnavailable"];
|
|
49
96
|
fetch: (ref: EgressRef, request: Request) => Promise<Response>;
|
|
50
97
|
}): McpServersConnectionOptions;
|
|
98
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineIdFamily } from "@fungi.computer/cairn";
|
|
2
|
-
import { ConnectionsError, createConnections, createSealedCustody,
|
|
2
|
+
import { ConnectionsError, createConnections, createSealedCustody, answerEgressRequest, mcpAgentSource, } from "@fungi.computer/veil/connections";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import { maxAgentConnections, } from "../agents.js";
|
|
5
5
|
const ids = defineIdFamily({
|
|
@@ -23,14 +23,20 @@ export function createAgentMcpConnections(options) {
|
|
|
23
23
|
send: options.send,
|
|
24
24
|
}),
|
|
25
25
|
authorize: (actor) => actor === owner,
|
|
26
|
+
// The host's last word before every send: the subject must still stand.
|
|
27
|
+
check: (_grantor, grant) => grant.subject === null
|
|
28
|
+
? Promise.resolve(true)
|
|
29
|
+
: options.subjectLive(grant.subject),
|
|
26
30
|
oauth: { callbackUrl: options.callbackUrl, fetch: options.send },
|
|
27
31
|
clock: () => Date.now(),
|
|
28
32
|
ids: () => ids.connection.generate(),
|
|
29
33
|
});
|
|
30
34
|
const run = (effect) => Effect.runPromise(effect);
|
|
31
|
-
const projection = (agentId) => run(connections.projection(agentId));
|
|
35
|
+
const projection = (agentId) => run(connections.projection({ kind: "agent", id: agentId }));
|
|
32
36
|
const holdersOf = async (connectionId) => (await run(connections.list(owner))).flatMap((row) => row.connectionId === connectionId
|
|
33
|
-
? row.grants
|
|
37
|
+
? row.grants
|
|
38
|
+
.filter((grant) => grant.subject.kind === "agent")
|
|
39
|
+
.map((grant) => grant.subject.id)
|
|
34
40
|
: []);
|
|
35
41
|
const toolsFor = (access) => access === "all"
|
|
36
42
|
? "all"
|
|
@@ -39,7 +45,7 @@ export function createAgentMcpConnections(options) {
|
|
|
39
45
|
: [...access];
|
|
40
46
|
/** Every live connection with the Agents that may use it. */
|
|
41
47
|
async function list() {
|
|
42
|
-
return (await run(connections.list(owner))).flatMap((row) => row.state === "revoked"
|
|
48
|
+
return (await run(connections.list(owner))).flatMap((row) => row.state === "revoked" || row.surface.kind === "http"
|
|
43
49
|
? []
|
|
44
50
|
: [
|
|
45
51
|
{
|
|
@@ -54,8 +60,10 @@ export function createAgentMcpConnections(options) {
|
|
|
54
60
|
? "oauth"
|
|
55
61
|
: "none",
|
|
56
62
|
state: row.state === "active" ? "connected" : row.state,
|
|
57
|
-
grants: row.grants
|
|
58
|
-
|
|
63
|
+
grants: row.grants
|
|
64
|
+
.filter((grant) => grant.subject.kind === "agent")
|
|
65
|
+
.map((grant) => ({
|
|
66
|
+
agentId: grant.subject.id,
|
|
59
67
|
access: grant.tools === "all"
|
|
60
68
|
? "all"
|
|
61
69
|
: Array.isArray(grant.tools)
|
|
@@ -130,8 +138,9 @@ export function createAgentMcpConnections(options) {
|
|
|
130
138
|
return { error: "limit" };
|
|
131
139
|
try {
|
|
132
140
|
await run(connections.grant(owner, {
|
|
133
|
-
connectionId,
|
|
134
|
-
agentId,
|
|
141
|
+
target: { kind: "connection", id: connectionId },
|
|
142
|
+
subject: { kind: "agent", id: agentId },
|
|
143
|
+
capability: "connector.call",
|
|
135
144
|
tools: toolsFor(access),
|
|
136
145
|
}));
|
|
137
146
|
}
|
|
@@ -146,7 +155,11 @@ export function createAgentMcpConnections(options) {
|
|
|
146
155
|
async function ungrant(connectionId, agentId) {
|
|
147
156
|
if (!(await holdersOf(connectionId)).includes(agentId))
|
|
148
157
|
return false;
|
|
149
|
-
await run(connections.ungrant(owner, {
|
|
158
|
+
await run(connections.ungrant(owner, {
|
|
159
|
+
target: { kind: "connection", id: connectionId },
|
|
160
|
+
subject: { kind: "agent", id: agentId },
|
|
161
|
+
capability: "connector.call",
|
|
162
|
+
}));
|
|
150
163
|
await options.notify(agentId);
|
|
151
164
|
return true;
|
|
152
165
|
}
|
|
@@ -166,7 +179,9 @@ export function createAgentMcpConnections(options) {
|
|
|
166
179
|
try {
|
|
167
180
|
const { connectionId } = await run(connections.complete(owner, query));
|
|
168
181
|
const holders = (await run(connections.list(owner))).flatMap((row) => row.connectionId === connectionId
|
|
169
|
-
? row.grants
|
|
182
|
+
? row.grants
|
|
183
|
+
.filter((grant) => grant.subject.kind === "agent")
|
|
184
|
+
.map((grant) => grant.subject.id)
|
|
170
185
|
: []);
|
|
171
186
|
await Promise.all(holders.map((holder) => options.notify(holder)));
|
|
172
187
|
return { ok: true };
|
|
@@ -179,7 +194,7 @@ export function createAgentMcpConnections(options) {
|
|
|
179
194
|
}
|
|
180
195
|
async function remove(connectionId) {
|
|
181
196
|
const holders = await holdersOf(connectionId);
|
|
182
|
-
const known = (await list()).some((row) => row.connectionId === connectionId);
|
|
197
|
+
const known = (await run(connections.list(owner))).some((row) => row.connectionId === connectionId && row.state !== "revoked");
|
|
183
198
|
if (!known)
|
|
184
199
|
return false;
|
|
185
200
|
await run(connections.revoke(owner, { connectionId }));
|
|
@@ -187,9 +202,83 @@ export function createAgentMcpConnections(options) {
|
|
|
187
202
|
return true;
|
|
188
203
|
}
|
|
189
204
|
/** Complete one Agent request on the owner side: the only place a credential opens. */
|
|
190
|
-
const fetchFor = (agentId, ref, data) =>
|
|
205
|
+
const fetchFor = (agentId, ref, data) => answerEgressRequest(connections.egress, { kind: "agent", id: agentId }, ref, data);
|
|
206
|
+
/** Save one HTTP secret bound to exact destinations; no subject holds it until granted. */
|
|
207
|
+
async function addSecret(input) {
|
|
208
|
+
try {
|
|
209
|
+
const begun = await run(connections.begin(owner, {
|
|
210
|
+
requestId: ids.connection.generate(),
|
|
211
|
+
name: input.name,
|
|
212
|
+
label: input.label,
|
|
213
|
+
surface: { kind: "http", destinations: input.destinations },
|
|
214
|
+
credential: { kind: "static", placement: input.placement },
|
|
215
|
+
secret: input.secret,
|
|
216
|
+
}));
|
|
217
|
+
return { connectionId: begun.connectionId };
|
|
218
|
+
}
|
|
219
|
+
catch (cause) {
|
|
220
|
+
if (cause instanceof ConnectionsError) {
|
|
221
|
+
if (cause.code === "conflict")
|
|
222
|
+
return { error: "duplicate_name" };
|
|
223
|
+
if (cause.code === "invalid_input" || cause.code === "denied")
|
|
224
|
+
return { error: "invalid_endpoint" };
|
|
225
|
+
}
|
|
226
|
+
throw cause;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** This instance's live secrets with their bindings and holders; never a value. */
|
|
230
|
+
async function secrets() {
|
|
231
|
+
return (await run(connections.list(owner))).filter((row) => row.surface.kind === "http" && row.state !== "revoked");
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Let one Agent, Computer or Team key use a secret under the broker's
|
|
235
|
+
* `secret.use` scope. The subject must stand now; Apps hold no Vault power.
|
|
236
|
+
*/
|
|
237
|
+
async function grantSecret(connectionId, subject) {
|
|
238
|
+
if (subject.kind === "app")
|
|
239
|
+
return { error: "unsupported_subject" };
|
|
240
|
+
if ((subject.kind === "agent" && !options.hasAgent(subject.id)) ||
|
|
241
|
+
!(await options.subjectLive(subject)))
|
|
242
|
+
return { error: "not_found" };
|
|
243
|
+
try {
|
|
244
|
+
await run(connections.grant(owner, {
|
|
245
|
+
target: { kind: "secret", id: connectionId },
|
|
246
|
+
subject,
|
|
247
|
+
capability: "secret.use",
|
|
248
|
+
tools: "all",
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
catch (cause) {
|
|
252
|
+
if (cause instanceof ConnectionsError &&
|
|
253
|
+
(cause.code === "denied" || cause.code === "invalid_input"))
|
|
254
|
+
return { error: "not_found" };
|
|
255
|
+
if (cause instanceof ConnectionsError && cause.code === "unsupported")
|
|
256
|
+
return { error: "unsupported_subject" };
|
|
257
|
+
throw cause;
|
|
258
|
+
}
|
|
259
|
+
if (subject.kind === "agent")
|
|
260
|
+
await options.notify(subject.id);
|
|
261
|
+
return { ok: true };
|
|
262
|
+
}
|
|
263
|
+
async function ungrantSecret(connectionId, subject) {
|
|
264
|
+
await run(connections.ungrant(owner, {
|
|
265
|
+
target: { kind: "secret", id: connectionId },
|
|
266
|
+
subject,
|
|
267
|
+
capability: "secret.use",
|
|
268
|
+
}));
|
|
269
|
+
if (subject.kind === "agent")
|
|
270
|
+
await options.notify(subject.id);
|
|
271
|
+
}
|
|
191
272
|
return {
|
|
192
273
|
list,
|
|
274
|
+
addSecret,
|
|
275
|
+
secrets,
|
|
276
|
+
grantSecret,
|
|
277
|
+
ungrantSecret,
|
|
278
|
+
/** Every recorded use and refusal of one secret, without its value. */
|
|
279
|
+
secretUsage: (connectionId) => run(connections.audit(owner, connectionId)),
|
|
280
|
+
/** Complete one request with a secret on the owner side; the caller names its subject. */
|
|
281
|
+
fetchSecret: (subject, ref, data) => answerEgressRequest(connections.egress, subject, ref, data),
|
|
193
282
|
add,
|
|
194
283
|
grant,
|
|
195
284
|
ungrant,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Mycelium } from "@fungi.computer/mycelium";
|
|
2
|
+
import { agentNameSchema } from "@fungi.computer/agar/agents";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { agentAvatarSchema } from "../agent-avatars.js";
|
|
4
5
|
const refusal = z.strictObject({
|
|
@@ -29,7 +30,7 @@ export function createSelfSource(port) {
|
|
|
29
30
|
replay: "unsafe",
|
|
30
31
|
description: "Rename yourself. A name held by another Agent is refused.",
|
|
31
32
|
input: z.strictObject({
|
|
32
|
-
name:
|
|
33
|
+
name: agentNameSchema,
|
|
33
34
|
}),
|
|
34
35
|
output: z.union([
|
|
35
36
|
z.strictObject({
|
|
@@ -79,8 +79,11 @@ export type StandaloneAgentsEnv = Readonly<{
|
|
|
79
79
|
KEYS?: StandaloneTenancyEnv["KEYS"];
|
|
80
80
|
OYSTER_ORIGIN: string;
|
|
81
81
|
OYSTER_OWNER_KEY?: string;
|
|
82
|
-
/**
|
|
82
|
+
/** Active wrapping key (32 bytes, base64url), held outside the stored data. */
|
|
83
83
|
OYSTER_CREDENTIAL_KEY?: string;
|
|
84
|
+
OYSTER_CREDENTIAL_KEY_ID?: string;
|
|
85
|
+
/** JSON object of retained key ids to base64url wrapping keys. */
|
|
86
|
+
OYSTER_CREDENTIAL_PREVIOUS_KEYS?: string;
|
|
84
87
|
AGENTS: DurableObjectNamespace<StandaloneAgentBase>;
|
|
85
88
|
/** Host-only directory custody. Guest entrypoints expose operations, not this binding; Codemode receives only Mycelium modules. */
|
|
86
89
|
AGENT_DIRECTORY: DurableObjectNamespace<AgentDirectory>;
|
|
@@ -139,7 +142,7 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
139
142
|
* is recorded as owed before anything else, then paid off by the Agent's
|
|
140
143
|
* durable host work: an Agent evicted mid-run still answers when it wakes.
|
|
141
144
|
*/
|
|
142
|
-
askDiscord(bindingId: string, ask: DiscordAsk): void
|
|
145
|
+
askDiscord(bindingId: string, ask: DiscordAsk): Promise<void>;
|
|
143
146
|
private discordReplyOwner;
|
|
144
147
|
private discordReplies;
|
|
145
148
|
/** How long one pass waits on an unfinished run before looking again. */
|
|
@@ -253,7 +256,7 @@ export declare abstract class StandaloneAgentBase<Env extends StandaloneAgentEnv
|
|
|
253
256
|
deliver(envelope: PostEnvelope): Promise<import("@fungi.computer/carrier/post").PostDeliveryResult>;
|
|
254
257
|
private mailOwner;
|
|
255
258
|
private conversationAgentsOwner;
|
|
256
|
-
/**
|
|
259
|
+
/** This Agent's children by createdBy, and its conversations' watched sends. */
|
|
257
260
|
private conversationAgents;
|
|
258
261
|
private mail;
|
|
259
262
|
/** Undefined is disclosure refusal; unavailable evidence fails before RPC. */
|
|
@@ -332,6 +335,7 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
|
|
|
332
335
|
recordArchive(agentId: string, archived: boolean, revision: number): boolean;
|
|
333
336
|
/** Directory's bounded-stale projection, never the Agent's flag authority. */
|
|
334
337
|
archived(agentId: string): boolean;
|
|
338
|
+
private credentialOptions;
|
|
335
339
|
private modelKeys;
|
|
336
340
|
/** Domain refusals cross the DO RPC boundary as data, not as Error prototypes. */
|
|
337
341
|
sealModelKey(input: ModelKeySealInput): Promise<ModelKeyRecord | Readonly<{
|
|
@@ -15,7 +15,7 @@ import { transcriptLine, } from "@fungi.computer/nacre/website-channels";
|
|
|
15
15
|
import { personChannelInstructions, } from "../channels/web-binding.js";
|
|
16
16
|
import { decideChannelRunSafely } from "../channels/run-decision.js";
|
|
17
17
|
import { createWebsiteChannelOwner, websiteOutcome, } from "./website-channels.js";
|
|
18
|
-
import { createDiscordReplies, } from "../channels/discord-replies.js";
|
|
18
|
+
import { createDiscordReplies, discordReplies002, } from "../channels/discord-replies.js";
|
|
19
19
|
import { isDiscordBinding, createDiscordBindings, createDiscordInputSchema, updateDiscordInputSchema, } from "../channels/discord-binding.js";
|
|
20
20
|
import { DISCORD_SETTLEMENT_WAIT_MS, discordDenial, discordFailureText, patchOriginal, postChannelMessage, postFollowUp, quoted, STILL_WORKING_TEXT, splitDiscordMessage, registerAskCommand, } from "../channels/discord-interactions.js";
|
|
21
21
|
import { discordOutcome, sealDiscordToken, } from "./discord-channels.js";
|
|
@@ -47,7 +47,7 @@ import { standaloneHomeInstructionsFile, } from "./computer.js";
|
|
|
47
47
|
import { ShiitakeDO } from "@fungi.computer/shiitake/cloudflare";
|
|
48
48
|
import { agentStoreKeeping } from "./agent-store.js";
|
|
49
49
|
import { CredentialError, } from "@fungi.computer/veil/credential-store";
|
|
50
|
-
import { createInstanceCredentialStore, createModelKeyVault, ModelKeyRefused, } from "./model-key-vault.js";
|
|
50
|
+
import { createInstanceCredentialStore, createModelKeyVault, instanceCredentialKeyring, instanceSecretCustody, ModelKeyRefused, } from "./model-key-vault.js";
|
|
51
51
|
import { agentArchiveOwner } from "./agent-archive-owner.js";
|
|
52
52
|
import { agentArchiveProjection } from "../agent-archive-projection.js";
|
|
53
53
|
import { standaloneBrowserLiveView, standaloneBrowserSource, } from "./browser.js";
|
|
@@ -423,8 +423,8 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
423
423
|
* is recorded as owed before anything else, then paid off by the Agent's
|
|
424
424
|
* durable host work: an Agent evicted mid-run still answers when it wakes.
|
|
425
425
|
*/
|
|
426
|
-
askDiscord(bindingId, ask) {
|
|
427
|
-
this.discordReplies().record(bindingId, ask);
|
|
426
|
+
async askDiscord(bindingId, ask) {
|
|
427
|
+
await this.discordReplies().record(bindingId, ask);
|
|
428
428
|
this.ctx.waitUntil(this.wakeRuntime().catch((cause) => {
|
|
429
429
|
console.error("discord reply wake failed", cause);
|
|
430
430
|
}));
|
|
@@ -434,6 +434,12 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
434
434
|
return (this.discordReplyOwner ??= createDiscordReplies({
|
|
435
435
|
sql: this.ctx.storage.sql,
|
|
436
436
|
now: () => Date.now(),
|
|
437
|
+
...instanceSecretCustody({
|
|
438
|
+
owner: this.ctx.storage,
|
|
439
|
+
ownerId: this.ctx.id.toString(),
|
|
440
|
+
env: this.env,
|
|
441
|
+
tables: [discordReplies002],
|
|
442
|
+
}),
|
|
437
443
|
deliver: (reply) => this.deliverDiscord(reply),
|
|
438
444
|
onExpired: (interactionId) => {
|
|
439
445
|
console.warn("discord reply expired undelivered", interactionId);
|
|
@@ -968,10 +974,10 @@ export class StandaloneAgentBase extends ShiitakeDO {
|
|
|
968
974
|
}
|
|
969
975
|
mailOwner;
|
|
970
976
|
conversationAgentsOwner;
|
|
971
|
-
/**
|
|
977
|
+
/** This Agent's children by createdBy, and its conversations' watched sends. */
|
|
972
978
|
async conversationAgents() {
|
|
973
979
|
const { createConversationAgents } = await import("@fungi.computer/shiitake-extensions/roster/conversation-agents");
|
|
974
|
-
return (this.conversationAgentsOwner ??= createConversationAgents(this.ctx.storage));
|
|
980
|
+
return (this.conversationAgentsOwner ??= createConversationAgents(this.ctx.storage, () => this.ctx.id.name ?? this.ctx.id.toString()));
|
|
975
981
|
}
|
|
976
982
|
mail() {
|
|
977
983
|
return (this.mailOwner ??= agentMail({
|
|
@@ -1527,12 +1533,16 @@ export class AgentDirectory extends DurableObject {
|
|
|
1527
1533
|
archived(agentId) {
|
|
1528
1534
|
return this.archiveProjection().archived(agentId);
|
|
1529
1535
|
}
|
|
1536
|
+
credentialOptions() {
|
|
1537
|
+
return {
|
|
1538
|
+
owner: this.ctx.storage,
|
|
1539
|
+
ownerId: this.ctx.id.toString(),
|
|
1540
|
+
keyring: instanceCredentialKeyring(this.env),
|
|
1541
|
+
storage: credentialStorage(this.ctx.storage),
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1530
1544
|
modelKeys() {
|
|
1531
|
-
|
|
1532
|
-
return createModelKeyVault({
|
|
1533
|
-
credentialKey: this.env.OYSTER_CREDENTIAL_KEY,
|
|
1534
|
-
storage: credentialStorage(storage),
|
|
1535
|
-
});
|
|
1545
|
+
return createModelKeyVault(this.credentialOptions());
|
|
1536
1546
|
}
|
|
1537
1547
|
/** Domain refusals cross the DO RPC boundary as data, not as Error prototypes. */
|
|
1538
1548
|
async sealModelKey(input) {
|
|
@@ -1587,13 +1597,29 @@ export class AgentDirectory extends DurableObject {
|
|
|
1587
1597
|
return (this.mcpOwner ??= createAgentMcpConnections({
|
|
1588
1598
|
ownerId: this.ctx.id.name ?? "agents",
|
|
1589
1599
|
store: storage,
|
|
1590
|
-
vault: createInstanceCredentialStore(
|
|
1591
|
-
credentialKey: this.env.OYSTER_CREDENTIAL_KEY,
|
|
1592
|
-
storage: credentialStorage(storage),
|
|
1593
|
-
}),
|
|
1600
|
+
vault: createInstanceCredentialStore(this.credentialOptions()),
|
|
1594
1601
|
// The Worker's own egress: public internet only.
|
|
1595
1602
|
send: (request) => fetch(request),
|
|
1596
1603
|
hasAgent: (agentId) => this.has(agentId),
|
|
1604
|
+
// Asked at grant and before every secret send. The registry's
|
|
1605
|
+
// ownsComputer is the same owner frameComputerId re-admits through.
|
|
1606
|
+
// Outside the instance's own directory nothing stands (fail closed).
|
|
1607
|
+
subjectLive: async (subject) => {
|
|
1608
|
+
const scope = this.machineScope();
|
|
1609
|
+
if (this.ctx.id.name !== scope.durableName("agents"))
|
|
1610
|
+
return false;
|
|
1611
|
+
const bindings = this.env;
|
|
1612
|
+
switch (subject.kind) {
|
|
1613
|
+
case "agent":
|
|
1614
|
+
return this.has(subject.id);
|
|
1615
|
+
case "computer":
|
|
1616
|
+
return bindings.REGISTRY.getByName(scope.durableName("registry")).ownsComputer(subject.id);
|
|
1617
|
+
case "team-key":
|
|
1618
|
+
return ((await this.env.KEYS.getByName(scope.durableName("keys")).live(subject.id)) !== null);
|
|
1619
|
+
case "app":
|
|
1620
|
+
return false;
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1597
1623
|
notify: (agentId) => this.env.AGENTS.getByName(agentId).invalidateMcpConnections(),
|
|
1598
1624
|
callbackUrl: mcpCallbackUrl(this.env.OYSTER_ORIGIN),
|
|
1599
1625
|
}));
|
|
@@ -2005,10 +2031,7 @@ export class AgentDirectory extends DurableObject {
|
|
|
2005
2031
|
}));
|
|
2006
2032
|
}
|
|
2007
2033
|
discordVault() {
|
|
2008
|
-
return createInstanceCredentialStore(
|
|
2009
|
-
credentialKey: this.env.OYSTER_CREDENTIAL_KEY,
|
|
2010
|
-
storage: credentialStorage(this.ctx.storage),
|
|
2011
|
-
});
|
|
2034
|
+
return createInstanceCredentialStore(this.credentialOptions());
|
|
2012
2035
|
}
|
|
2013
2036
|
/** Owner read of every Discord application bound to one of this tenant's Agents. */
|
|
2014
2037
|
discordList(principal) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import
|
|
2
|
+
import type { OysterEnv } from "../host.js";
|
|
3
3
|
import { type Routes } from "../authorization.js";
|
|
4
|
+
import type { OysterKeysLivePort, OysterWorkspaceCaller } from "../workers-git.js";
|
|
4
5
|
import type { StandaloneRegistry } from "./registry.js";
|
|
5
6
|
export declare const standaloneFleetRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
7
|
operation: z.ZodLiteral<"create">;
|
|
@@ -68,10 +69,15 @@ export declare const standaloneFleetRequestSchema: z.ZodDiscriminatedUnion<[z.Zo
|
|
|
68
69
|
enabled: z.ZodBoolean;
|
|
69
70
|
}, z.core.$strict>], "operation">;
|
|
70
71
|
export type StandaloneFleetRequest = z.input<typeof standaloneFleetRequestSchema>;
|
|
71
|
-
/**
|
|
72
|
-
export declare function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
/** Whether `memberId` is the live canonical owner and owns this Computer. */
|
|
73
|
+
export declare function ownerHoldsComputer(registry: Pick<StandaloneRegistry, "computerFleet">, memberId: string, computerId: string): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* The Computer one host serves. The owner's current selection, unless the
|
|
76
|
+
* owner names another with `?computerId=`, or the caller is a key granted
|
|
77
|
+
* selected Computers: that key's own Computer, whatever the owner selects
|
|
78
|
+
* (`keyComputerChoice`). A window's requested context is a hint, never
|
|
79
|
+
* authority or a default mutation.
|
|
80
|
+
*/
|
|
81
|
+
export declare function standaloneComputerSelection(registry: Pick<StandaloneRegistry, "computerFleet" | "selectedComputer">, keysLive: OysterKeysLivePort, caller?: OysterWorkspaceCaller): Promise<string>;
|
|
76
82
|
/** Tenant-owner management controls over the same durable fleet as Hub. */
|
|
77
83
|
export declare function standaloneComputerFleetRoutes(registryFor: () => DurableObjectStub<StandaloneRegistry>): Routes<OysterEnv>;
|
|
@@ -2,8 +2,7 @@ import { endTime, startTime } from "hono/timing";
|
|
|
2
2
|
import { HTTPException } from "hono/http-exception";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { computerCreateRequestSchema, computerPageSchema, localBackendAttachSchema, localBackendDetachRequestSchema, localBackendDetachSchema, } from "@fungi.computer/computer/fleet";
|
|
5
|
-
import {} from "../
|
|
6
|
-
import { oysterPrincipalIsOwner, owner as ownerRoute, routes as routeTable, } from "../authorization.js";
|
|
5
|
+
import { keyComputerChoice, oysterPrincipalIsOwner, owner as ownerRoute, routes as routeTable, } from "../authorization.js";
|
|
7
6
|
import { computerTargetParam } from "../computer-target.js";
|
|
8
7
|
/** Fleet controls never accept an actor from the request body. */
|
|
9
8
|
const fleetComputerId = z.string().min(1).max(256);
|
|
@@ -74,36 +73,78 @@ function fleetResponse(result) {
|
|
|
74
73
|
status: fleetStatus(result),
|
|
75
74
|
});
|
|
76
75
|
}
|
|
77
|
-
/**
|
|
78
|
-
export async function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
/** Whether `memberId` is the live canonical owner and owns this Computer. */
|
|
77
|
+
export async function ownerHoldsComputer(registry, memberId, computerId) {
|
|
78
|
+
const result = await registry.computerFleet(memberId, {
|
|
79
|
+
operation: "resolve",
|
|
80
|
+
computerId,
|
|
81
|
+
});
|
|
82
|
+
return fleetStatus(result) === 200;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The Computer one host serves. The owner's current selection, unless the
|
|
86
|
+
* owner names another with `?computerId=`, or the caller is a key granted
|
|
87
|
+
* selected Computers: that key's own Computer, whatever the owner selects
|
|
88
|
+
* (`keyComputerChoice`). A window's requested context is a hint, never
|
|
89
|
+
* authority or a default mutation.
|
|
90
|
+
*/
|
|
91
|
+
export async function standaloneComputerSelection(registry, keysLive, caller) {
|
|
92
|
+
if (caller === undefined)
|
|
83
93
|
return registry.selectedComputer();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
let principal;
|
|
95
|
+
let requested = [];
|
|
96
|
+
if ("request" in caller) {
|
|
97
|
+
requested = new URL(caller.request.url).searchParams.getAll(computerTargetParam);
|
|
98
|
+
// One authentication per request: the route requirement reuses it.
|
|
99
|
+
const admission = await caller.auth.authenticate(caller.request);
|
|
100
|
+
if (admission.kind === "refused") {
|
|
101
|
+
// An unauthenticated request reaches no Computer; its route refuses it.
|
|
102
|
+
if (requested.length === 0)
|
|
103
|
+
return registry.selectedComputer();
|
|
104
|
+
throw new HTTPException(admission.status, {
|
|
105
|
+
res: Response.json({ error: "Computer selection refused" }, {
|
|
106
|
+
status: admission.status,
|
|
107
|
+
headers: admission.retryAfter === undefined
|
|
108
|
+
? {}
|
|
109
|
+
: { "Retry-After": String(admission.retryAfter) },
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
principal = admission.principal;
|
|
114
|
+
}
|
|
115
|
+
else
|
|
116
|
+
principal = caller.principal;
|
|
117
|
+
const named = z.tuple([fleetComputerId]).safeParse(requested);
|
|
118
|
+
if (requested.length > 0 && !named.success)
|
|
119
|
+
throw new HTTPException(400, { message: "Invalid Computer selection" });
|
|
120
|
+
const computerId = named.success ? named.data[0] : null;
|
|
121
|
+
// The fleet re-proves the canonical owner holds the Computer it hands out.
|
|
122
|
+
const held = async (memberId, id) => {
|
|
123
|
+
const result = await registry.computerFleet(memberId, {
|
|
124
|
+
operation: "resolve",
|
|
125
|
+
computerId: id,
|
|
93
126
|
});
|
|
94
|
-
|
|
127
|
+
const status = fleetStatus(result);
|
|
128
|
+
if (status !== 200)
|
|
129
|
+
throw new HTTPException(status, { res: fleetResponse(result) });
|
|
130
|
+
return id;
|
|
131
|
+
};
|
|
132
|
+
if (principal.actor.kind === "team-key") {
|
|
133
|
+
const key = await keysLive(principal.actor.keyId);
|
|
134
|
+
const choice = keyComputerChoice(key, computerId);
|
|
135
|
+
if (choice.kind === "owner-selection")
|
|
136
|
+
return registry.selectedComputer();
|
|
137
|
+
if (choice.kind === "refused")
|
|
138
|
+
throw new HTTPException(choice.status, {
|
|
139
|
+
res: Response.json({ error: choice.error }, { status: choice.status }),
|
|
140
|
+
});
|
|
141
|
+
return held(choice.owner, choice.computerId);
|
|
142
|
+
}
|
|
143
|
+
if (computerId === null)
|
|
144
|
+
return registry.selectedComputer();
|
|
145
|
+
if (!oysterPrincipalIsOwner(principal))
|
|
95
146
|
throw new HTTPException(403, { message: "Owner only" });
|
|
96
|
-
|
|
97
|
-
if (!computerId.success)
|
|
98
|
-
throw new HTTPException(400, { message: "Invalid Computer selection" });
|
|
99
|
-
const result = await registry.computerFleet(admission.principal.actor.memberId, {
|
|
100
|
-
operation: "resolve",
|
|
101
|
-
computerId: computerId.data[0],
|
|
102
|
-
});
|
|
103
|
-
const status = fleetStatus(result);
|
|
104
|
-
if (status !== 200)
|
|
105
|
-
throw new HTTPException(status, { res: fleetResponse(result) });
|
|
106
|
-
return computerId.data[0];
|
|
147
|
+
return held(principal.actor.memberId, computerId);
|
|
107
148
|
}
|
|
108
149
|
/** Tenant-owner management controls over the same durable fleet as Hub. */
|
|
109
150
|
export function standaloneComputerFleetRoutes(registryFor) {
|