@fungi.computer/oyster 0.25.0 → 0.27.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.
Files changed (49) hide show
  1. package/dist/agents.d.ts +24 -8
  2. package/dist/agents.js +12 -5
  3. package/dist/app-builds.d.ts +4 -2
  4. package/dist/app-builds.js +14 -0
  5. package/dist/apps/catalog.js +1 -1
  6. package/dist/boot-host-script.js +1 -1
  7. package/dist/build/build-memory.d.ts +13 -0
  8. package/dist/build/build-memory.js +29 -0
  9. package/dist/build/candidate-cli.mjs +25 -2
  10. package/dist/build/local-build.js +4 -5
  11. package/dist/cloudflare.d.ts +2 -2
  12. package/dist/cloudflare.js +3 -0
  13. package/dist/computer-control-port.d.ts +2 -0
  14. package/dist/embed-metafiles.js +2 -2
  15. package/dist/embed-scripts.js +1 -1
  16. package/dist/hello-app-script.js +1 -1
  17. package/dist/mcp.d.ts +26 -0
  18. package/dist/mcp.js +12 -2
  19. package/dist/media.d.ts +5 -0
  20. package/dist/media.js +1 -0
  21. package/dist/page-script.js +2 -2
  22. package/dist/release.d.ts +5 -0
  23. package/dist/standalone/agent-computers.js +17 -1
  24. package/dist/standalone/agents.d.ts +16 -8
  25. package/dist/standalone/agents.js +88 -25
  26. package/dist/standalone/app-set.d.ts +11 -3
  27. package/dist/standalone/app-set.js +26 -8
  28. package/dist/standalone/computer-control.js +7 -1
  29. package/dist/standalone/computer-fleet.d.ts +6 -0
  30. package/dist/standalone/computer-fleet.js +9 -1
  31. package/dist/standalone/computer-skill-source.d.ts +20 -0
  32. package/dist/standalone/computer-skill-source.js +165 -0
  33. package/dist/standalone/computer.d.ts +30 -4
  34. package/dist/standalone/computer.js +60 -3
  35. package/dist/standalone/install-apps-cli.js +9 -3
  36. package/dist/standalone/media.d.ts +9 -4
  37. package/dist/standalone/media.js +76 -7
  38. package/dist/standalone/registry.d.ts +8 -1
  39. package/dist/standalone/registry.js +10 -1
  40. package/docs/api/agents.md +204 -214
  41. package/docs/api/apps.md +33 -33
  42. package/docs/api/cloudflare.md +4 -1
  43. package/docs/api/mcp.md +52 -46
  44. package/docs/api/media.md +4 -0
  45. package/docs/api/workers-git.md +7 -7
  46. package/examples/standalone/wrangler.jsonc +3 -0
  47. package/package.json +19 -23
  48. package/dist/agent-instructions.d.ts +0 -35
  49. package/dist/agent-instructions.js +0 -42
package/dist/agents.d.ts CHANGED
@@ -14,6 +14,17 @@ export type { StarterOutcome };
14
14
  import type { AgentModelChoice, AgentModelRefusal } from "./standalone/agent-model-choice.js";
15
15
  export type { AgentModelChoice, AgentModelRefusal, } from "./standalone/agent-model-choice.js";
16
16
  import type { MemberInboxItem, MemberInboxSession } from "@fungi.computer/puffball/inbox";
17
+ /** An Agent's AGENTS.md on its Home Computer, with the byte limit the host enforces. */
18
+ export type OysterAgentInstructions = Readonly<{
19
+ /** The Home Computer holding the file; null when the Agent has none. */
20
+ home: Readonly<{
21
+ name: string;
22
+ }> | null;
23
+ /** The file's text; null when there is no Home or the file does not exist yet. */
24
+ content: string | null;
25
+ bytes: number;
26
+ limit: number;
27
+ }>;
17
28
  /** One agent as Apps see it, in Agar's `appAgentSchema` shape. */
18
29
  export type OysterAgent = Readonly<{
19
30
  agentId: string;
@@ -140,19 +151,24 @@ export type OysterAgents = Readonly<{
140
151
  }>>;
141
152
  /** Owner-only, secret-free Agent default; an unknown Agent cannot be configured. */
142
153
  readModelChoice(agentId: string): Promise<AgentModelChoice | null>;
143
- /** Owner-only read of the standing instructions this Agent follows on every turn. */
154
+ /** Owner-only read of the AGENTS.md on this Agent's Home Computer. */
144
155
  readInstructions(agentId: string, principal: TenantPrincipal): Promise<Readonly<{
145
156
  agentId: string;
146
- instructions: string;
147
- }> | Readonly<{
157
+ } & OysterAgentInstructions> | Readonly<{
148
158
  error: "not_found" | "not_granted";
149
159
  }>>;
150
- /** Owner-only replacement of them; empty clears. Appended after the host's fixed instructions. */
151
- setInstructions(agentId: string, instructions: string, principal: TenantPrincipal): Promise<Readonly<{
160
+ /**
161
+ * Owner-only replacement of it. `expectedContent` is what the owner last read;
162
+ * null creates the file only while absent. A file the Agent changed since is a
163
+ * `conflict`, never overwritten.
164
+ */
165
+ setInstructions(agentId: string, edit: Readonly<{
166
+ expectedContent: string | null;
167
+ content: string;
168
+ }>, principal: TenantPrincipal): Promise<Readonly<{
152
169
  agentId: string;
153
- instructions: string;
154
- }> | Readonly<{
155
- error: "not_found" | "not_granted";
170
+ } & OysterAgentInstructions> | Readonly<{
171
+ error: "not_found" | "not_granted" | "conflict" | "too_large" | "no_home";
156
172
  }>>;
157
173
  /** Parse the owner's JSON through the deployable Agent's model preference schema. */
158
174
  decodeModelChoice(json: string): AgentModelChoice | null;
package/dist/agents.js CHANGED
@@ -6,7 +6,7 @@ import { agentAvatarSchema } from "./agent-avatars.js";
6
6
  import { computerTargetParam } from "./computer-target.js";
7
7
  import { modelKeyProviderChoices } from "./standalone/model-key-providers.js";
8
8
  import { supportedAgentModels } from "./standalone/agent-model-choice.js";
9
- import { agentAvatar, agentInstructions, appAgentInstructionsMaxLength, agentList, agentManage, agentRename, agentSessionRead, agentSessionWrite, agentToolPolicy, } from "@fungi.computer/agar/agents";
9
+ import { agentAvatar, agentInstructions, agentList, agentManage, agentRename, agentSessionRead, agentSessionWrite, agentToolPolicy, } from "@fungi.computer/agar/agents";
10
10
  /** At most this many connections per Agent. */
11
11
  export const maxAgentConnections = 16;
12
12
  /** Owner input for one MCP connection: a guest identifier, an `https:` endpoint and an optional bearer. */
@@ -44,7 +44,8 @@ const renameSchema = Schema.Struct({
44
44
  });
45
45
  const avatarInputSchema = z.object({ avatar: agentAvatarSchema });
46
46
  const instructionsInputSchema = z.object({
47
- instructions: z.string().max(appAgentInstructionsMaxLength),
47
+ expectedContent: z.string().nullable(),
48
+ content: z.string(),
48
49
  });
49
50
  const visitSchema = Schema.Struct({
50
51
  agentId: Schema.String,
@@ -267,10 +268,16 @@ function createAgentRoutes(agents) {
267
268
  return refusal(404, "No such agent");
268
269
  const body = instructionsInputSchema.safeParse(await context.req.json());
269
270
  if (!body.success)
270
- return refusal(400, "Instructions are too long");
271
- const result = await agents.setInstructions(agentId, body.data.instructions, principal);
271
+ return refusal(400, "Invalid instructions edit");
272
+ const result = await agents.setInstructions(agentId, body.data, principal);
272
273
  if ("error" in result)
273
- return refusal(result.error === "not_found" ? 404 : 403, result.error);
274
+ return refusal(result.error === "not_found"
275
+ ? 404
276
+ : result.error === "not_granted"
277
+ ? 403
278
+ : result.error === "too_large"
279
+ ? 413
280
+ : 409, result.error);
274
281
  return Response.json(result);
275
282
  })
276
283
  .get("/agent-policies/:agentId", agent(), async (_context, { agentId }) => {
@@ -23,7 +23,7 @@ import { type Release } from "@fungi.computer/puffball";
23
23
  import { type AppPublisherCoreConfigInput } from "./build/effect.js";
24
24
  import { type TeamAppCandidateManifest } from "./build/submission-contract.js";
25
25
  import { type ContentObjectOwner } from "./build/content-objects.js";
26
- import { type ArtifactHeads, type ArtifactStore } from "./release.js";
26
+ import { type ArtifactDeletes, type ArtifactHeads, type ArtifactStore } from "./release.js";
27
27
  import type { PublisherTemplateSeedReceipts } from "./source/seed-receipt.js";
28
28
  /** A Computer's whole-build budget: a cold build on a 6 GiB Computer measured 185-270 s. */
29
29
  export declare const oysterAppBuildTimeoutMs = 900000;
@@ -164,13 +164,15 @@ export type OysterAppBuildOptions = Readonly<{
164
164
  port: OysterBuildComputer;
165
165
  }>;
166
166
  /** The host's artifact store; a build's objects are already in it. */
167
- artifacts: ArtifactStore & ArtifactHeads;
167
+ artifacts: ArtifactStore & ArtifactHeads & ArtifactDeletes;
168
168
  /** The seed receipts a template build must match. */
169
169
  templates: Pick<PublisherTemplateSeedReceipts, "read">;
170
170
  now?: () => number;
171
171
  }>;
172
172
  /** Create the current build tables and index atomically; an older store is refused, never converted. */
173
173
  export declare function migrateOysterAppBuilds(owner: WatchdogSqliteOwner): void;
174
+ /** Build logs kept per App; older logs are removed after each new one is written. */
175
+ export declare const retainedBuildLogs = 5;
174
176
  /** The build owner over one tenant's SQLite, Computer and artifact store. */
175
177
  export declare function createOysterAppBuilds(options: OysterAppBuildOptions): Readonly<{
176
178
  /** Record (or replace) an App's build source; the caller is the owner. */
@@ -127,6 +127,7 @@ const jobRow = Schema.Struct({
127
127
  executable_until: Schema.Number,
128
128
  });
129
129
  const decodeJob = Schema.decodeUnknownSync(jobRow);
130
+ const decodeJobId = Schema.decodeUnknownSync(Schema.Struct({ job_id: Schema.String }));
130
131
  const sourceRow = Schema.Struct({ source: Schema.String });
131
132
  const releaseRow = Schema.Struct({ release: Schema.String });
132
133
  const sourceCodec = Schema.fromJsonString(oysterBuildSourceSchema);
@@ -169,6 +170,8 @@ export function migrateOysterAppBuilds(owner) {
169
170
  sql.exec("CREATE TABLE IF NOT EXISTS oyster_build_releases (release_id TEXT PRIMARY KEY, job_id TEXT NOT NULL UNIQUE, release TEXT NOT NULL) STRICT");
170
171
  });
171
172
  }
173
+ /** Build logs kept per App; older logs are removed after each new one is written. */
174
+ export const retainedBuildLogs = 5;
172
175
  /** The build owner over one tenant's SQLite, Computer and artifact store. */
173
176
  export function createOysterAppBuilds(options) {
174
177
  const { owner } = options;
@@ -245,6 +248,16 @@ export function createOysterAppBuilds(options) {
245
248
  // It is read only through the owner build door, never exposed as a Release.
246
249
  const logRef = (jobId) => parseArtifactRef(`artifact:build-log-${jobId}`);
247
250
  const logCodec = Schema.fromJsonString(buildJobLogSchema);
251
+ // Job rows and statuses stay; only the older logs of one App are removed.
252
+ // The ranking is read from the job table each time, so replays, retries and
253
+ // an owner restart can never delete a log inside the retained five.
254
+ const pruneLogs = async (appId) => {
255
+ const stale = owner.sql
256
+ .exec("SELECT job_id FROM oyster_build_jobs WHERE app_id=? ORDER BY issued_at DESC, rowid DESC LIMIT -1 OFFSET ?", appId, retainedBuildLogs)
257
+ .toArray();
258
+ for (const row of stale)
259
+ await options.artifacts.delete(logRef(decodeJobId(row).job_id));
260
+ };
248
261
  const publisher = createTeamBuildPublisher({
249
262
  teamId: options.tenantId,
250
263
  now,
@@ -286,6 +299,7 @@ export function createOysterAppBuilds(options) {
286
299
  timeoutMs: input.timeoutMs,
287
300
  });
288
301
  await options.artifacts.put(logRef(input.jobId), new TextEncoder().encode(Schema.encodeUnknownSync(logCodec)(result.log)));
302
+ await pruneLogs(required(input.jobId).app_id);
289
303
  if (result.output === null)
290
304
  throw new BuildOutcomeUnknown();
291
305
  return result;
@@ -19,7 +19,7 @@ export const permissionCatalog = {
19
19
  "agent.manage": entry("agents", "Create and manage Agents", "create Agents and manage their sessions.", "createAgents", "install", "agent"),
20
20
  "agent.rename": entry("agents", "Rename Agents", "rename Agents you created.", "createAgents", "install"),
21
21
  "agent.avatar": entry("agents", "Change Agent avatars", "change the avatars of Agents you created.", "createAgents", "install"),
22
- "agent.instructions": entry("agents", "Change Agent instructions", "change the standing instructions of your Agents.", "createAgents", "install"),
22
+ "agent.instructions": entry("agents", "Change Agent instructions", "change the AGENTS.md instructions on your Agents' Home Computers.", "createAgents", "install"),
23
23
  "agent.toolPolicy": entry("agents", "Allow Agents to use Apps", "approve Agents to use your installed Apps.", "createAgents", "install"),
24
24
  "agent.read": entry("agents", "Read Agent conversations", "read Agent conversations.", "readConversations", "install", "agent"),
25
25
  "agent.send": entry("agents", "Send messages to Agents", "send messages to Agents.", "sendPrompts", "install", "agent"),