@fungi.computer/oyster 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -2
- package/dist/agents.d.ts +82 -23
- package/dist/agents.js +187 -40
- package/dist/authorization.d.ts +25 -3
- package/dist/authorization.js +47 -14
- package/dist/browser/capability-source.d.ts +23 -5
- package/dist/browser/capability-source.js +19 -22
- package/dist/browser/index.d.ts +2 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/live-view.d.ts +38 -0
- package/dist/browser/live-view.js +179 -0
- package/dist/channels/binding.d.ts +2 -0
- package/dist/channels/run-decision.d.ts +33 -0
- package/dist/channels/run-decision.js +25 -0
- package/dist/channels/visitor-channel.d.ts +84 -14
- package/dist/channels/visitor-channel.js +55 -32
- package/dist/channels/visitor-edge.d.ts +18 -2
- package/dist/channels/visitor-edge.js +67 -5
- package/dist/channels/visitors.d.ts +4 -0
- package/dist/channels/visitors.js +22 -1
- package/dist/channels/web-binding.d.ts +117 -0
- package/dist/channels/web-binding.js +227 -0
- package/dist/computer-control-port.d.ts +20 -1
- package/dist/embed-metafiles.d.ts +8 -0
- package/dist/embed-metafiles.js +2 -0
- package/dist/embed-scripts.d.ts +8 -0
- package/dist/embed-scripts.js +3 -0
- package/dist/host.d.ts +3 -1
- package/dist/host.js +6 -1
- package/dist/mcp.d.ts +128 -0
- package/dist/mcp.js +63 -1
- package/dist/page/embed-challenge.d.ts +19 -0
- package/dist/page/embed-challenge.js +45 -0
- package/dist/page/embed-error.d.ts +2 -0
- package/dist/page/embed-error.js +16 -0
- package/dist/page/embed-loader-protocol.d.ts +12 -0
- package/dist/page/embed-loader-protocol.js +29 -0
- package/dist/standalone/agent-computers.d.ts +12 -1
- package/dist/standalone/agent-computers.js +35 -0
- package/dist/standalone/agent-connections.d.ts +50 -0
- package/dist/standalone/agent-connections.js +214 -0
- package/dist/standalone/agent-model-choice.d.ts +7 -3
- package/dist/standalone/agent-model-choice.js +33 -4
- package/dist/standalone/agents.d.ts +224 -9
- package/dist/standalone/agents.js +485 -115
- package/dist/standalone/browser.d.ts +16 -3
- package/dist/standalone/browser.js +54 -5
- package/dist/standalone/channel-session-door.d.ts +4 -0
- package/dist/standalone/channel-session-door.js +72 -0
- package/dist/standalone/computer-control.js +55 -1
- package/dist/standalone/computer-fleet.d.ts +21 -0
- package/dist/standalone/computer-fleet.js +30 -6
- package/dist/standalone/computer.d.ts +20 -1
- package/dist/standalone/computer.js +63 -1
- package/dist/standalone/model-key-vault.d.ts +50 -0
- package/dist/standalone/model-key-vault.js +147 -0
- package/dist/standalone/owner-routes.d.ts +4 -3
- package/dist/standalone/owner-routes.js +7 -1
- package/dist/standalone/registry.d.ts +23 -0
- package/dist/standalone/registry.js +30 -0
- package/dist/standalone/visitor-edge.d.ts +36 -0
- package/dist/standalone/visitor-edge.js +67 -0
- package/dist/standalone/visitor-proof.d.ts +23 -0
- package/dist/standalone/visitor-proof.js +67 -0
- package/dist/standalone/web.d.ts +10 -0
- package/dist/standalone/web.js +34 -0
- package/dist/standalone/website-channels.d.ts +134 -0
- package/dist/standalone/website-channels.js +262 -0
- package/dist/standalone/worker-routes.d.ts +6 -1
- package/dist/standalone/worker-routes.js +4 -0
- package/dist/standalone/worker.d.ts +2 -1
- package/dist/standalone/worker.js +13 -1
- package/dist/testing/capabilities.d.ts +3 -0
- package/dist/testing/capabilities.js +1 -0
- package/dist/testing/installation.d.ts +4 -2
- package/dist/testing/installation.js +7 -2
- package/dist/web/index.d.ts +3 -0
- package/dist/web/index.js +3 -0
- package/dist/web/search-contract.d.ts +19 -0
- package/dist/web/search-contract.js +14 -0
- package/dist/web/search.d.ts +25 -0
- package/dist/web/search.js +123 -0
- package/dist/web/source.d.ts +46 -0
- package/dist/web/source.js +335 -0
- package/dist/workers-git.js +3 -2
- package/docs/api/agents.md +184 -39
- package/docs/api/apps.md +129 -111
- package/docs/api/browser.md +115 -8
- package/docs/api/build-contract.md +27 -21
- package/docs/api/build.md +55 -54
- package/docs/api/git.md +3 -3
- package/docs/api/host.md +69 -60
- package/docs/api/mcp.md +81 -44
- package/docs/api/workers-git.md +6 -6
- package/docs/api/workers.md +53 -47
- package/package.json +52 -22
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standalone website channel: an owner puts a chat with one of their
|
|
3
|
+
* Agents on a separate website. The directory owns the bindings and the
|
|
4
|
+
* anonymous visitor identities; each website is served by a dedicated Agent
|
|
5
|
+
* instance (never the owner's own Agent), and the public edge authenticates a
|
|
6
|
+
* visitor once before any Agent is selected.
|
|
7
|
+
*/
|
|
8
|
+
import { Hono } from "hono";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { owner, routes } from "../authorization.js";
|
|
13
|
+
import { createWebsiteBindings, createWebsiteInputSchema, updateWebsiteInputSchema, WebsiteBindingError, } from "../channels/web-binding.js";
|
|
14
|
+
import { createChannelVisitors } from "../channels/visitors.js";
|
|
15
|
+
import { readTurnstileConfiguration } from "../turnstile.js";
|
|
16
|
+
import { tenantScope, defaultTenant } from "../tenant.js";
|
|
17
|
+
import { agentDirectoryForScope } from "./agent-directory.js";
|
|
18
|
+
import { standaloneVisitorEdge } from "./visitor-edge.js";
|
|
19
|
+
/**
|
|
20
|
+
* The directory's website owner: bindings and visitor identities on its own
|
|
21
|
+
* store, with the chosen Agent's identity read from the directory itself.
|
|
22
|
+
*/
|
|
23
|
+
export function createWebsiteChannelOwner(options) {
|
|
24
|
+
const bindings = createWebsiteBindings(options);
|
|
25
|
+
const visitors = createChannelVisitors({
|
|
26
|
+
sql: options.sql,
|
|
27
|
+
transactionSync: options.transactionSync,
|
|
28
|
+
now: () => Date.now(),
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
bindings,
|
|
32
|
+
visitors,
|
|
33
|
+
/** A public site key resolves only to an active site with a live Agent. */
|
|
34
|
+
site: (siteKey) => {
|
|
35
|
+
const binding = bindings.readBySiteKey(siteKey);
|
|
36
|
+
if (binding === null)
|
|
37
|
+
return null;
|
|
38
|
+
const agent = options.agentIdentity(binding.agentId);
|
|
39
|
+
if (agent === null)
|
|
40
|
+
return null;
|
|
41
|
+
const { origins, accent, turnstile } = binding.selector;
|
|
42
|
+
const facts = { ...agent, origins };
|
|
43
|
+
if (accent !== undefined)
|
|
44
|
+
facts.accent = accent;
|
|
45
|
+
if (turnstile === true)
|
|
46
|
+
facts.turnstile = true;
|
|
47
|
+
return { binding, facts };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Run one binding command, turning its closed failures into data. */
|
|
52
|
+
export function websiteOutcome(command) {
|
|
53
|
+
try {
|
|
54
|
+
return command();
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof WebsiteBindingError)
|
|
58
|
+
return { error: error.code };
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The website channel is not configured on this Oyster. */
|
|
63
|
+
class WebsiteConfigurationError extends Error {
|
|
64
|
+
constructor() {
|
|
65
|
+
super("Website channel host secrets are unavailable or invalid");
|
|
66
|
+
this.name = "WebsiteConfigurationError";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const hostKeySchema = z
|
|
70
|
+
.string()
|
|
71
|
+
.refine((value) => new TextEncoder().encode(value).byteLength >= 32);
|
|
72
|
+
function hostKey(value) {
|
|
73
|
+
const parsed = hostKeySchema.safeParse(value);
|
|
74
|
+
if (!parsed.success)
|
|
75
|
+
throw new WebsiteConfigurationError();
|
|
76
|
+
return parsed.data;
|
|
77
|
+
}
|
|
78
|
+
/** Rate-limit key: the client address hashed under a daily-rotating salt. */
|
|
79
|
+
async function addressHash(env, address) {
|
|
80
|
+
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(hostKey(env.OYSTER_WEBSITE_ADDRESS_KEY)), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
81
|
+
const day = new Date().toISOString().slice(0, 10);
|
|
82
|
+
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`${day}:${address ?? "unknown"}`));
|
|
83
|
+
return Array.from(new Uint8Array(signature).slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
84
|
+
}
|
|
85
|
+
const defaultDirectory = (env) => agentDirectoryForScope(env, tenantScope(defaultTenant, env.OYSTER_ORIGIN));
|
|
86
|
+
const embedAssets = async () => import("#embed-scripts");
|
|
87
|
+
const scriptHeaders = {
|
|
88
|
+
"content-type": "text/javascript; charset=utf-8",
|
|
89
|
+
"cache-control": "public, max-age=300",
|
|
90
|
+
"x-content-type-options": "nosniff",
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The public website surface, on the same paths as Hub's: the launcher, the
|
|
94
|
+
* visitor document and the visitor API. Every visitor request authenticates
|
|
95
|
+
* once here; Agents receive only a signed, short-lived assertion.
|
|
96
|
+
*/
|
|
97
|
+
export function standaloneWebsiteApp() {
|
|
98
|
+
const resolve = (context) => context.env;
|
|
99
|
+
const edge = standaloneVisitorEdge({
|
|
100
|
+
site: (context, siteKey) => defaultDirectory(resolve(context)).websiteSite(siteKey),
|
|
101
|
+
visitors: (context) => {
|
|
102
|
+
const directory = defaultDirectory(resolve(context));
|
|
103
|
+
return {
|
|
104
|
+
mint: (site, siteKey, address) => directory.websiteMint(site?.bindingId ?? "", siteKey, address),
|
|
105
|
+
refresh: (site, secret) => directory.websiteRefresh(site?.bindingId ?? "", secret),
|
|
106
|
+
rotate: (site, siteKey, token, address) => directory.websiteRotate(site?.bindingId ?? "", siteKey, token, address),
|
|
107
|
+
authenticate: (bindingId, token) => directory.websiteAuthenticate(bindingId, token),
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
// Visitors reach the chosen Agent itself, with its own tools.
|
|
111
|
+
agent: (context, binding) => resolve(context).AGENTS.getByName(binding.agentId),
|
|
112
|
+
proofKey: (context) => hostKey(resolve(context).OYSTER_WEBSITE_PROOF_KEY),
|
|
113
|
+
addressHash: (context) => addressHash(resolve(context), context.req.header("cf-connecting-ip")),
|
|
114
|
+
turnstile: (context) => {
|
|
115
|
+
const env = resolve(context);
|
|
116
|
+
return {
|
|
117
|
+
configuration: readTurnstileConfiguration(env, env.OYSTER_ORIGIN),
|
|
118
|
+
timeoutMs: 5_000,
|
|
119
|
+
onError: (cause) => {
|
|
120
|
+
console.error("website turnstile verification failed", cause);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
assetPath: (kind) => kind === "widget" ? "/embed/widget.js" : "/styles.css",
|
|
125
|
+
onError: (error, context) => {
|
|
126
|
+
if (error instanceof WebsiteConfigurationError)
|
|
127
|
+
return context.json({ error: "website_unavailable" }, 503);
|
|
128
|
+
console.error(error);
|
|
129
|
+
return context.json({ error: "internal" }, 500);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return new Hono()
|
|
133
|
+
.get("/embed/v1.js", async () => {
|
|
134
|
+
const { embedLoaderScript } = await embedAssets();
|
|
135
|
+
return new Response(embedLoaderScript, { headers: scriptHeaders });
|
|
136
|
+
})
|
|
137
|
+
.get("/embed/widget.js", async () => {
|
|
138
|
+
const { embedWidgetScript } = await embedAssets();
|
|
139
|
+
return new Response(embedWidgetScript, { headers: scriptHeaders });
|
|
140
|
+
})
|
|
141
|
+
.get("/styles.css", async () => {
|
|
142
|
+
const { embedStyles } = await embedAssets();
|
|
143
|
+
return new Response(embedStyles, {
|
|
144
|
+
headers: {
|
|
145
|
+
"content-type": "text/css; charset=utf-8",
|
|
146
|
+
"cache-control": "public, max-age=300",
|
|
147
|
+
"x-content-type-options": "nosniff",
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
})
|
|
151
|
+
.route("/", edge);
|
|
152
|
+
}
|
|
153
|
+
/** The owner's website controls over the directory and each website's Agent. */
|
|
154
|
+
export function standaloneWebsiteControl(env, directoryOf) {
|
|
155
|
+
// Only a binding the directory knows names an Agent whose conversations are read.
|
|
156
|
+
const agentOf = async (principal, bindingId) => {
|
|
157
|
+
const listed = await directoryOf().websiteList(principal);
|
|
158
|
+
const binding = "error" in listed
|
|
159
|
+
? undefined
|
|
160
|
+
: listed.find((item) => item.bindingId === bindingId);
|
|
161
|
+
return binding === undefined ? null : env.AGENTS.getByName(binding.agentId);
|
|
162
|
+
};
|
|
163
|
+
return {
|
|
164
|
+
read: async (principal) => {
|
|
165
|
+
const listed = await directoryOf().websiteList(principal);
|
|
166
|
+
return {
|
|
167
|
+
embedOrigin: env.OYSTER_ORIGIN,
|
|
168
|
+
agents: (await directoryOf().list()).map(({ agentId, name }) => ({
|
|
169
|
+
agentId,
|
|
170
|
+
name,
|
|
171
|
+
})),
|
|
172
|
+
websites: "error" in listed ? [] : listed,
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
create: (principal, input, requestId) => directoryOf().websiteCreate(principal, input, requestId),
|
|
176
|
+
update: (principal, bindingId, input) => directoryOf().websiteUpdate(principal, bindingId, input),
|
|
177
|
+
conversations: async (principal, bindingId) => {
|
|
178
|
+
const agent = await agentOf(principal, bindingId);
|
|
179
|
+
return agent === null
|
|
180
|
+
? []
|
|
181
|
+
: (await agent.websiteConversations(bindingId)).map(({ sessionId, label, lastEventAt }) => ({
|
|
182
|
+
sessionId,
|
|
183
|
+
label,
|
|
184
|
+
lastEventAt,
|
|
185
|
+
}));
|
|
186
|
+
},
|
|
187
|
+
transcript: async (principal, bindingId, sessionId) => {
|
|
188
|
+
const agent = await agentOf(principal, bindingId);
|
|
189
|
+
return agent === null
|
|
190
|
+
? null
|
|
191
|
+
: agent.websiteTranscript(bindingId, sessionId);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const refusalStatus = {
|
|
196
|
+
not_granted: 403,
|
|
197
|
+
not_found: 404,
|
|
198
|
+
version_conflict: 409,
|
|
199
|
+
request_conflict: 409,
|
|
200
|
+
invalid_input: 400,
|
|
201
|
+
};
|
|
202
|
+
function refused(value) {
|
|
203
|
+
return "error" in value;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The owner's website controls. Each route is owner-direct: an App cannot
|
|
207
|
+
* create a public surface, or read what its visitors said, on the owner's behalf.
|
|
208
|
+
*/
|
|
209
|
+
export function standaloneWebsiteRoutes(control) {
|
|
210
|
+
const table = routes();
|
|
211
|
+
// A body that is not JSON is a malformed request, not a thrown failure.
|
|
212
|
+
const parseBody = async (context) => {
|
|
213
|
+
const decoded = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json))(await context.req.text());
|
|
214
|
+
return Option.isSome(decoded)
|
|
215
|
+
? { ok: true, value: decoded.value }
|
|
216
|
+
: { ok: false };
|
|
217
|
+
};
|
|
218
|
+
table.get("/api/websites", owner("direct"), async (context, { principal }) => {
|
|
219
|
+
context.header("Cache-Control", "no-store");
|
|
220
|
+
return context.json(await control.read(principal));
|
|
221
|
+
});
|
|
222
|
+
table.post("/api/websites", owner("direct"), async (context, { principal }) => {
|
|
223
|
+
context.header("Cache-Control", "no-store");
|
|
224
|
+
const body = await parseBody(context);
|
|
225
|
+
if (!body.ok)
|
|
226
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
227
|
+
const parsed = createWebsiteInputSchema.safeParse(body.value);
|
|
228
|
+
if (!parsed.success)
|
|
229
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
230
|
+
const result = await control.create(principal, parsed.data, context.req.header("x-request-id") ?? "");
|
|
231
|
+
return refused(result)
|
|
232
|
+
? context.json(result, refusalStatus[result.error])
|
|
233
|
+
: context.json({ binding: result }, 201);
|
|
234
|
+
});
|
|
235
|
+
table.put("/api/websites/:bindingId", owner("direct"), async (context, { principal }) => {
|
|
236
|
+
context.header("Cache-Control", "no-store");
|
|
237
|
+
const body = await parseBody(context);
|
|
238
|
+
if (!body.ok)
|
|
239
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
240
|
+
const parsed = updateWebsiteInputSchema.safeParse(body.value);
|
|
241
|
+
if (!parsed.success)
|
|
242
|
+
return context.json({ error: "invalid_input" }, 400);
|
|
243
|
+
const result = await control.update(principal, context.req.param("bindingId"), parsed.data);
|
|
244
|
+
return refused(result)
|
|
245
|
+
? context.json(result, refusalStatus[result.error])
|
|
246
|
+
: context.json({ binding: result });
|
|
247
|
+
});
|
|
248
|
+
table.get("/api/websites/:bindingId/conversations", owner("direct"), async (context, { principal }) => {
|
|
249
|
+
context.header("Cache-Control", "no-store");
|
|
250
|
+
return context.json({
|
|
251
|
+
conversations: await control.conversations(principal, context.req.param("bindingId")),
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
table.get("/api/websites/:bindingId/conversations/:sessionId", owner("direct"), async (context, { principal }) => {
|
|
255
|
+
context.header("Cache-Control", "no-store");
|
|
256
|
+
const transcript = await control.transcript(principal, context.req.param("bindingId"), context.req.param("sessionId"));
|
|
257
|
+
return transcript === null
|
|
258
|
+
? context.json({ error: "not_found" }, 404)
|
|
259
|
+
: context.json(transcript);
|
|
260
|
+
});
|
|
261
|
+
return table;
|
|
262
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The standalone Worker's top-level table, before any tenant is selected:
|
|
3
|
-
* device enrollment and links,
|
|
3
|
+
* device enrollment and links, the public website visitor surface, attached-machine
|
|
4
|
+
* dials, signed Workflow webhook delivery, then the
|
|
4
5
|
* selected tenant's own declared host table for every other path. The Worker
|
|
5
6
|
* and the authorization law both compose it here.
|
|
6
7
|
*/
|
|
@@ -10,6 +11,10 @@ import { type Routes } from "../authorization.js";
|
|
|
10
11
|
export type StandaloneWorkerRoutePorts = Readonly<{
|
|
11
12
|
/** The machine-link doors' own table, served for this request. */
|
|
12
13
|
machineLink: (request: Request) => Promise<Response>;
|
|
14
|
+
/** The public website channel: launcher, visitor document and visitor API. */
|
|
15
|
+
website: (request: Request) => Promise<Response>;
|
|
16
|
+
/** A machine's signed dial to its attached Computer, verified by that Computer. */
|
|
17
|
+
localBackendDial: (request: Request) => Promise<Response>;
|
|
13
18
|
/** Signed Workflow webhook delivery, verified by the library's run owner. */
|
|
14
19
|
workflowWebhooks: Routes<BlankEnv>;
|
|
15
20
|
/** The selected tenant's declared host table. */
|
|
@@ -4,6 +4,10 @@ export function standaloneWorkerRoutes(ports) {
|
|
|
4
4
|
return routes()
|
|
5
5
|
.all("/local/mesh/join", door("machine enrollment; the join route verifies its key"), (context) => ports.machineLink(context.req.raw))
|
|
6
6
|
.all("/api/teams/:teamId/local/mesh/:deviceId/connect", door("a machine link; the device's link verifies Seam"), (context) => ports.machineLink(context.req.raw))
|
|
7
|
+
.all("/embed/*", door("a website visitor; the edge checks the site key and origin"), (context) => ports.website(context.req.raw))
|
|
8
|
+
.all("/styles.css", door("the website chat's public stylesheet"), (context) => ports.website(context.req.raw))
|
|
9
|
+
.all("/api/embed/*", door("a website visitor; the edge checks the site key, origin and bearer"), (context) => ports.website(context.req.raw))
|
|
10
|
+
.all("/api/computers/:computerId/backends/:backendId/connect", door("an attached machine's dial; the Computer verifies its Seam signature"), (context) => ports.localBackendDial(context.req.raw))
|
|
7
11
|
.include(ports.workflowWebhooks)
|
|
8
12
|
.all("*", door("the selected tenant's own declared host table"), (context) => ports.tenant(context.req.raw));
|
|
9
13
|
}
|
|
@@ -16,12 +16,13 @@ import { type StandaloneTenancyEnv } from "./tenancy.js";
|
|
|
16
16
|
export { StandaloneTenants } from "./tenancy.js";
|
|
17
17
|
import { type StandaloneMachineLinkBindings } from "./machine-link.js";
|
|
18
18
|
export { MachineLinkDO } from "./machine-link.js";
|
|
19
|
+
import { type StandaloneWebsiteEnv } from "./website-channels.js";
|
|
19
20
|
import { type OysterComputerEgressProps } from "./computer-egress.js";
|
|
20
21
|
import type { AppSourceBindingEnv } from "./app-source.js";
|
|
21
22
|
export { StandaloneGraphWorkflow } from "./workflows.js";
|
|
22
23
|
export { MediaOperationDO } from "@fungi.computer/darkroom/cloudflare";
|
|
23
24
|
/** Every binding the standalone Bonsai root receives. */
|
|
24
|
-
export type StandaloneEnv = OysterGitWorkerEnv & StandaloneTenancyEnv & StandaloneComputerEnv & StandaloneAgentsEnv & StandaloneMachineLinkBindings & OysterMediaEnv & StandaloneWorkflowEnv & AppSourceBindingEnv & {
|
|
25
|
+
export type StandaloneEnv = OysterGitWorkerEnv & StandaloneTenancyEnv & StandaloneComputerEnv & StandaloneAgentsEnv & StandaloneWebsiteEnv & StandaloneMachineLinkBindings & OysterMediaEnv & StandaloneWorkflowEnv & AppSourceBindingEnv & {
|
|
25
26
|
OYSTER_HOME_INSTALLATION: string;
|
|
26
27
|
/** `disabled` closes the Computer's public download lane. */
|
|
27
28
|
COMPUTER_PUBLIC_EGRESS?: string;
|
|
@@ -8,7 +8,7 @@ import { defaultTenant, tenantScope } from "../tenant.js";
|
|
|
8
8
|
import { oysterPrincipalIsOwner } from "../authorization.js";
|
|
9
9
|
import { standaloneComputerControl } from "./computer-control.js";
|
|
10
10
|
import { standalonePermissionResources } from "./permission-resources.js";
|
|
11
|
-
import { onBoxVmIngress } from "@fungi.computer/computer";
|
|
11
|
+
import { onBoxVmIngress, ownerLocalBackendDialPath, } from "@fungi.computer/computer";
|
|
12
12
|
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
13
13
|
import { installationWorkerEntrypoint } from "../installation-execution.js";
|
|
14
14
|
import { putContentObject } from "../build-contract.js";
|
|
@@ -31,6 +31,7 @@ import { serveDoors } from "../authorization.js";
|
|
|
31
31
|
import { standaloneWorkerRoutes } from "./worker-routes.js";
|
|
32
32
|
import { HTTPException } from "hono/http-exception";
|
|
33
33
|
import { standaloneOwnerRoutes } from "./owner-routes.js";
|
|
34
|
+
import { standaloneWebsiteApp, } from "./website-channels.js";
|
|
34
35
|
import { standaloneComputerSelection } from "./computer-fleet.js";
|
|
35
36
|
import { serveOysterComputerEgress, } from "./computer-egress.js";
|
|
36
37
|
export { StandaloneGraphWorkflow } from "./workflows.js";
|
|
@@ -161,6 +162,8 @@ export class OysterComputerEgress extends WorkerEntrypoint {
|
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
/** The public website channel: one edge, authenticated per request. */
|
|
166
|
+
const website = standaloneWebsiteApp();
|
|
164
167
|
const standaloneWorkerErrorHandler = (error, context) => {
|
|
165
168
|
if (error instanceof StandaloneSeedConfigurationChanged) {
|
|
166
169
|
const { refusal } = error;
|
|
@@ -189,6 +192,15 @@ export default {
|
|
|
189
192
|
// tenant host's own declared table.
|
|
190
193
|
return serveDoors(standaloneWorkerRoutes({
|
|
191
194
|
machineLink: (incoming) => serveDoors(standaloneMachineLinkRoutes(env).onError(standaloneWorkerErrorHandler)).fetch(incoming, env, context),
|
|
195
|
+
website: (incoming) => Promise.resolve(website.fetch(incoming, env, context)),
|
|
196
|
+
localBackendDial: async (incoming) => {
|
|
197
|
+
const dial = ownerLocalBackendDialPath.exec(new URL(incoming.url).pathname);
|
|
198
|
+
// Only a Computer this Oyster owns is addressed; no stray object is made.
|
|
199
|
+
if (dial === null ||
|
|
200
|
+
!(await computerRegistry(env).ownsComputer(dial[1] ?? "")))
|
|
201
|
+
return new Response(null, { status: 404 });
|
|
202
|
+
return env.COMPUTER.getByName(dial[1] ?? "").fetch(incoming);
|
|
203
|
+
},
|
|
192
204
|
workflowWebhooks: standaloneWorkflowWebhookRoutes(env, async (incoming) => {
|
|
193
205
|
const admitted = await oysterRoot.admit(env, incoming);
|
|
194
206
|
return admitted === null
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type AppCapabilityId } from "@fungi.computer/puffball/app";
|
|
2
2
|
import { type OysterAgents } from "../agents.js";
|
|
3
3
|
import type { LiveOysterKey } from "../keys.js";
|
|
4
|
+
import type { ResourceRef } from "../apps/index.js";
|
|
4
5
|
import { type FileSource } from "../files.js";
|
|
5
6
|
import { type OysterAuthResult, type OysterCapability } from "../host.js";
|
|
6
7
|
/** How one capability fixture host admits its single installation. */
|
|
@@ -13,6 +14,8 @@ export type CapabilityFixtureOptions = Readonly<{
|
|
|
13
14
|
adapters?: readonly OysterCapability[];
|
|
14
15
|
/** Grant the file adapters over this source instead of the probe. */
|
|
15
16
|
fileSource?: FileSource;
|
|
17
|
+
/** Capabilities the owner narrowed to exactly these resources. */
|
|
18
|
+
selected?: Partial<Record<AppCapabilityId, readonly ResourceRef[]>>;
|
|
16
19
|
/** `false` clears the owner's approval after install. */
|
|
17
20
|
admitted?: boolean;
|
|
18
21
|
authenticate?: (request: Request) => Promise<OysterAuthResult>;
|
|
@@ -70,6 +70,7 @@ export async function capabilityFixture(options = {}) {
|
|
|
70
70
|
release: declaredRelease,
|
|
71
71
|
declaration: declaration ?? emptyAppDeclaration,
|
|
72
72
|
descriptors: capabilities,
|
|
73
|
+
selected: options.selected ?? {},
|
|
73
74
|
});
|
|
74
75
|
if (options.admitted === false)
|
|
75
76
|
installation = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppDeclaration } from "@fungi.computer/puffball/app";
|
|
2
|
-
import { type CapabilityOperationDescriptor, type Installation } from "../apps/index.js";
|
|
1
|
+
import type { AppCapabilityId, AppDeclaration } from "@fungi.computer/puffball/app";
|
|
2
|
+
import { type CapabilityOperationDescriptor, type Installation, type ResourceRef } from "../apps/index.js";
|
|
3
3
|
/** Build fixture state through the same approval owner used by installation routes. */
|
|
4
4
|
export declare function approvedInstallation(input: Readonly<{
|
|
5
5
|
release: Installation["release"];
|
|
@@ -7,4 +7,6 @@ export declare function approvedInstallation(input: Readonly<{
|
|
|
7
7
|
installationId: string;
|
|
8
8
|
instanceId: Installation["instanceId"];
|
|
9
9
|
descriptors?: readonly CapabilityOperationDescriptor[];
|
|
10
|
+
/** Narrow these capabilities to exactly these resources, as the owner's picker does. */
|
|
11
|
+
selected?: Partial<Record<AppCapabilityId, readonly ResourceRef[]>>;
|
|
10
12
|
}>): Promise<Installation>;
|
|
@@ -23,11 +23,16 @@ export async function approvedInstallation(input) {
|
|
|
23
23
|
throw new Error(result.failure.code);
|
|
24
24
|
const installed = result.success.next;
|
|
25
25
|
const declaredOperations = await deriveDeclaredOperations(input.release, input.declaration, input.descriptors ?? []);
|
|
26
|
+
const selected = input.selected ?? {};
|
|
26
27
|
const changes = declaredOperations.capabilities
|
|
27
|
-
.filter(({ capability }) => permissionCatalog[capability].consent === "ask"
|
|
28
|
+
.filter(({ capability }) => permissionCatalog[capability].consent === "ask" ||
|
|
29
|
+
selected[capability] !== undefined)
|
|
28
30
|
.map(({ capability, operations }) => ({
|
|
29
31
|
capability,
|
|
30
|
-
grant: {
|
|
32
|
+
grant: {
|
|
33
|
+
operations,
|
|
34
|
+
resources: selected[capability] ?? "tenant-scope",
|
|
35
|
+
},
|
|
31
36
|
}));
|
|
32
37
|
if (changes.length === 0)
|
|
33
38
|
return installed;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createWebSource, fetchWebPage, WEB_FETCH_MAX_BYTES, type WebFetchResult, } from "./source.js";
|
|
2
|
+
export { parallelWebSearch, unconfiguredWebSearch, WebSearchError, type WebSearchReport, } from "./search.js";
|
|
3
|
+
export { webSearchInputSchema, webSearchOutputSchema, type WebSearch, type WebSearchInput, type WebSearchOutput, } from "./search-contract.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const webSearchInputSchema: z.ZodObject<{
|
|
3
|
+
objective: z.ZodString;
|
|
4
|
+
queries: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
5
|
+
maxResults: z.ZodDefault<z.ZodNumber>;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export declare const webSearchOutputSchema: z.ZodObject<{
|
|
8
|
+
results: z.ZodArray<z.ZodObject<{
|
|
9
|
+
url: z.ZodString;
|
|
10
|
+
title: z.ZodNullable<z.ZodString>;
|
|
11
|
+
publishDate: z.ZodNullable<z.ZodString>;
|
|
12
|
+
excerpts: z.ZodArray<z.ZodString>;
|
|
13
|
+
}, z.core.$strict>>;
|
|
14
|
+
}, z.core.$strict>;
|
|
15
|
+
export type WebSearchInput = z.output<typeof webSearchInputSchema>;
|
|
16
|
+
export type WebSearchOutput = z.output<typeof webSearchOutputSchema>;
|
|
17
|
+
export type WebSearch = Readonly<{
|
|
18
|
+
search: (input: WebSearchInput, signal: AbortSignal) => Promise<WebSearchOutput>;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const webSearchInputSchema = z.strictObject({
|
|
3
|
+
objective: z.string().trim().min(1).max(2_000),
|
|
4
|
+
queries: z.array(z.string().trim().min(1).max(200)).max(5).default([]),
|
|
5
|
+
maxResults: z.number().int().min(1).max(10).default(5),
|
|
6
|
+
});
|
|
7
|
+
export const webSearchOutputSchema = z.strictObject({
|
|
8
|
+
results: z.array(z.strictObject({
|
|
9
|
+
url: z.string(),
|
|
10
|
+
title: z.string().nullable(),
|
|
11
|
+
publishDate: z.string().nullable(),
|
|
12
|
+
excerpts: z.array(z.string()),
|
|
13
|
+
})),
|
|
14
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type VeilBindings } from "@fungi.computer/veil/gatekeeper";
|
|
2
|
+
import type { WebSearch } from "./search-contract.js";
|
|
3
|
+
export type WebSearchErrorCode = "unavailable" | "insufficient_credits" | "denied" | "provider";
|
|
4
|
+
/** A typed search failure whose message is safe to show the model. */
|
|
5
|
+
export declare class WebSearchError extends Error {
|
|
6
|
+
readonly code: WebSearchErrorCode;
|
|
7
|
+
constructor(code: WebSearchErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
/** A diagnostic a host decides how to record; it never carries a body or key. */
|
|
10
|
+
export type WebSearchReport = Readonly<{
|
|
11
|
+
kind: "response_body_unavailable";
|
|
12
|
+
status: number;
|
|
13
|
+
cause: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
/** The operation's behavior when no search provider is configured. */
|
|
16
|
+
export declare const unconfiguredWebSearch: WebSearch;
|
|
17
|
+
/**
|
|
18
|
+
* Parallel Search for a host's Worker environment: unconfigured without
|
|
19
|
+
* Veil's Parallel credential, otherwise Parallel through the AI Gateway when
|
|
20
|
+
* the host names one, else directly.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parallelWebSearch(env: VeilBindings, options: Readonly<{
|
|
23
|
+
fetch: typeof globalThis.fetch;
|
|
24
|
+
report: (event: WebSearchReport) => void;
|
|
25
|
+
}>): WebSearch;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { configuredProviderEgress, providerFetch, } from "@fungi.computer/veil/gatekeeper";
|
|
3
|
+
/**
|
|
4
|
+
* `web.search` through Parallel's Search API (routed through the AI Gateway
|
|
5
|
+
* when the host names one). Veil owns the key and the route: this module never
|
|
6
|
+
* sees the credential. Without a Parallel key the operation says so and
|
|
7
|
+
* fetches nothing; it never invents results. Funding is the host's decision:
|
|
8
|
+
* the Hub wraps this search in Team credits, a standalone Oyster's owner pays
|
|
9
|
+
* Parallel directly.
|
|
10
|
+
*/
|
|
11
|
+
/** Excerpt characters returned to the model across all results. */
|
|
12
|
+
const maxChars = 12_000;
|
|
13
|
+
/** A typed search failure whose message is safe to show the model. */
|
|
14
|
+
export class WebSearchError extends Error {
|
|
15
|
+
code;
|
|
16
|
+
constructor(code, message) {
|
|
17
|
+
super(`web.search ${code}: ${message}`);
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.name = "WebSearchError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Parallel's `/v1/search` answer; unknown fields are ignored. */
|
|
23
|
+
const parallelResponseSchema = z.looseObject({
|
|
24
|
+
results: z.array(z.looseObject({
|
|
25
|
+
url: z.url(),
|
|
26
|
+
title: z.string().nullish(),
|
|
27
|
+
publish_date: z.string().nullish(),
|
|
28
|
+
excerpts: z.array(z.string()).default([]),
|
|
29
|
+
})),
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Parallel Search over `baseUrl`, which is Parallel or the gateway route.
|
|
33
|
+
* `fetch` is Veil's `parallel` route: it carries the key, never this module.
|
|
34
|
+
*/
|
|
35
|
+
function createParallelSearch(options) {
|
|
36
|
+
return {
|
|
37
|
+
search: async (input, signal) => {
|
|
38
|
+
let response;
|
|
39
|
+
try {
|
|
40
|
+
response = await options.fetch(`${options.baseUrl}/v1/search`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
objective: input.objective,
|
|
47
|
+
search_queries: input.queries.length > 0
|
|
48
|
+
? input.queries
|
|
49
|
+
: [input.objective.slice(0, 200)],
|
|
50
|
+
mode: "basic",
|
|
51
|
+
max_chars_total: maxChars,
|
|
52
|
+
advanced_settings: { max_results: input.maxResults },
|
|
53
|
+
}),
|
|
54
|
+
signal,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
signal.throwIfAborted();
|
|
59
|
+
throw new WebSearchError("provider", "the search service is unreachable");
|
|
60
|
+
}
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
await response.body?.cancel();
|
|
63
|
+
throw new WebSearchError("provider", `the search service answered HTTP ${String(response.status)}`);
|
|
64
|
+
}
|
|
65
|
+
let body;
|
|
66
|
+
try {
|
|
67
|
+
body = await response.json();
|
|
68
|
+
}
|
|
69
|
+
catch (cause) {
|
|
70
|
+
signal.throwIfAborted();
|
|
71
|
+
options.report({
|
|
72
|
+
kind: "response_body_unavailable",
|
|
73
|
+
status: response.status,
|
|
74
|
+
cause,
|
|
75
|
+
});
|
|
76
|
+
throw new WebSearchError("provider", "the search answer could not be read");
|
|
77
|
+
}
|
|
78
|
+
const parsed = parallelResponseSchema.safeParse(body);
|
|
79
|
+
if (!parsed.success)
|
|
80
|
+
throw new WebSearchError("provider", "the search answer was malformed");
|
|
81
|
+
let budget = maxChars;
|
|
82
|
+
return {
|
|
83
|
+
results: parsed.data.results
|
|
84
|
+
.slice(0, input.maxResults)
|
|
85
|
+
.map((result) => {
|
|
86
|
+
const excerpts = [];
|
|
87
|
+
for (const excerpt of result.excerpts) {
|
|
88
|
+
if (budget <= 0)
|
|
89
|
+
break;
|
|
90
|
+
excerpts.push(excerpt.slice(0, budget));
|
|
91
|
+
budget -= excerpt.length;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
url: result.url,
|
|
95
|
+
title: result.title ?? null,
|
|
96
|
+
publishDate: result.publish_date ?? null,
|
|
97
|
+
excerpts,
|
|
98
|
+
};
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** The operation's behavior when no search provider is configured. */
|
|
105
|
+
export const unconfiguredWebSearch = {
|
|
106
|
+
search: () => Promise.reject(new WebSearchError("unavailable", "web search is not configured on this platform; no search was run")),
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Parallel Search for a host's Worker environment: unconfigured without
|
|
110
|
+
* Veil's Parallel credential, otherwise Parallel through the AI Gateway when
|
|
111
|
+
* the host names one, else directly.
|
|
112
|
+
*/
|
|
113
|
+
export function parallelWebSearch(env, options) {
|
|
114
|
+
const egress = configuredProviderEgress(env, { fetch: options.fetch });
|
|
115
|
+
const baseUrl = egress.baseUrl("parallel");
|
|
116
|
+
if (baseUrl === null)
|
|
117
|
+
return unconfiguredWebSearch;
|
|
118
|
+
return createParallelSearch({
|
|
119
|
+
baseUrl,
|
|
120
|
+
fetch: providerFetch(egress, "parallel"),
|
|
121
|
+
report: options.report,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type CapabilitySource } from "@fungi.computer/mycelium";
|
|
2
|
+
import { type PublicGet } from "@fungi.computer/veil/public-fetch";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { type WebSearch } from "./search-contract.js";
|
|
5
|
+
/**
|
|
6
|
+
* The Agent's bounded web reader: `web.fetch` GETs one public URL from the
|
|
7
|
+
* Worker (no Computer needed) and returns readable text plus page metadata.
|
|
8
|
+
* Every hop, redirects included, goes through Veil's public-fetch door, which
|
|
9
|
+
* resolves once, refuses non-public addresses and connects to exactly the
|
|
10
|
+
* address it checked; this module opens no connection of its own. The read is
|
|
11
|
+
* bounded in bytes, characters and time. The owner grants it per binding as
|
|
12
|
+
* the `web` tool.
|
|
13
|
+
*/
|
|
14
|
+
/** Bytes read from one response body before it is cut off. */
|
|
15
|
+
export declare const WEB_FETCH_MAX_BYTES: number;
|
|
16
|
+
declare const outputSchema: z.ZodObject<{
|
|
17
|
+
url: z.ZodString;
|
|
18
|
+
status: z.ZodNumber;
|
|
19
|
+
contentType: z.ZodString;
|
|
20
|
+
title: z.ZodNullable<z.ZodString>;
|
|
21
|
+
description: z.ZodNullable<z.ZodString>;
|
|
22
|
+
text: z.ZodString;
|
|
23
|
+
truncated: z.ZodBoolean;
|
|
24
|
+
bytes: z.ZodNumber;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
export type WebFetchResult = z.output<typeof outputSchema>;
|
|
27
|
+
/** Fetch one public page: GET only, redirects rechecked, bounded everywhere. */
|
|
28
|
+
export declare function fetchWebPage(input: Readonly<{
|
|
29
|
+
url: string;
|
|
30
|
+
maxChars?: number;
|
|
31
|
+
}>, options: Readonly<{
|
|
32
|
+
get: PublicGet;
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
}>): Promise<WebFetchResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Compose the `web` module (`web.fetch`, `web.search`) for one run lease; the
|
|
38
|
+
* host grants both through the `web` tool.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createWebSource(options: Readonly<{
|
|
41
|
+
/** Veil's public-fetch door, the only way this module reaches the web. */
|
|
42
|
+
get: PublicGet;
|
|
43
|
+
/** Metered search, or the explicit unconfigured refusal. */
|
|
44
|
+
search: WebSearch;
|
|
45
|
+
}>): CapabilitySource;
|
|
46
|
+
export {};
|