@fungi.computer/oyster 0.36.0 → 0.37.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.
@@ -0,0 +1,19 @@
1
+ import { type CapabilitySource } from "@fungi.computer/mycelium";
2
+ import type { AgentEntry } from "./agents.js";
3
+ import type { TenantPrincipal } from "../tenant.js";
4
+ import type { Avatar } from "@fungi.computer/sprite/avatar";
5
+ /** Expected refusals from the standalone identity owner. */
6
+ export type SelfIdentityRefusal = Readonly<{
7
+ error: "name_taken" | "not_found" | "not_granted";
8
+ }>;
9
+ /** The pinned directory's identity commands, called only as this Agent. */
10
+ export type SelfIdentityDirectory = Readonly<{
11
+ rename: (agentId: string, name: string, principal: TenantPrincipal) => AgentEntry | SelfIdentityRefusal | Promise<AgentEntry | SelfIdentityRefusal>;
12
+ setAvatar: (agentId: string, avatar: Avatar, principal: TenantPrincipal) => AgentEntry | SelfIdentityRefusal | Promise<AgentEntry | SelfIdentityRefusal>;
13
+ }>;
14
+ /** Standalone identity tools are bound to the host Agent, never a supplied target. */
15
+ export declare function createSelfSource(port: Readonly<{
16
+ agentId: string;
17
+ directory: () => Promise<SelfIdentityDirectory>;
18
+ isChannelSession: (sessionId: string) => boolean;
19
+ }>): CapabilitySource;
@@ -0,0 +1,72 @@
1
+ import { Mycelium } from "@fungi.computer/mycelium";
2
+ import { z } from "zod";
3
+ import { agentAvatarSchema } from "../agent-avatars.js";
4
+ const refusal = z.strictObject({
5
+ error: z.enum(["name_taken", "not_found", "not_granted"]),
6
+ });
7
+ /** Standalone identity tools are bound to the host Agent, never a supplied target. */
8
+ export function createSelfSource(port) {
9
+ const principal = {
10
+ actor: { kind: "agent", agentId: port.agentId },
11
+ };
12
+ return {
13
+ id: "oyster-agent-self",
14
+ acquire: ({ signal, session }) => {
15
+ signal.throwIfAborted();
16
+ const present = session !== undefined && !port.isChannelSession(session.sessionId);
17
+ return Promise.resolve({
18
+ snapshot: {
19
+ version: present ? "oyster-agent-self-v1" : "0",
20
+ modules: present
21
+ ? [
22
+ Mycelium.module({
23
+ id: "oyster-agent-self",
24
+ name: "self",
25
+ description: "Change your own Agent name and avatar.",
26
+ operations: {
27
+ rename: Mycelium.operation({
28
+ // Repeating the current value is a no-op, not permission to replay old values.
29
+ replay: "unsafe",
30
+ description: "Rename yourself. A name held by another Agent is refused.",
31
+ input: z.strictObject({
32
+ name: z.string().trim().min(1).max(256),
33
+ }),
34
+ output: z.union([
35
+ z.strictObject({
36
+ name: z.string(),
37
+ avatar: agentAvatarSchema,
38
+ }),
39
+ refusal,
40
+ ]),
41
+ execute: async ({ name }) => {
42
+ const result = await (await port.directory()).rename(port.agentId, name, principal);
43
+ return "error" in result
44
+ ? result
45
+ : { name: result.name, avatar: result.avatar };
46
+ },
47
+ }),
48
+ setAvatar: Mycelium.operation({
49
+ replay: "unsafe",
50
+ description: "Change your own avatar using the existing Avatar grammar.",
51
+ input: z.strictObject({ avatar: agentAvatarSchema }),
52
+ output: z.union([
53
+ z.strictObject({ avatar: agentAvatarSchema }),
54
+ refusal,
55
+ ]),
56
+ execute: async ({ avatar }) => {
57
+ const result = await (await port.directory()).setAvatar(port.agentId, avatar, principal);
58
+ return "error" in result
59
+ ? result
60
+ : { avatar: result.avatar };
61
+ },
62
+ }),
63
+ },
64
+ }),
65
+ ]
66
+ : [],
67
+ },
68
+ release: () => Promise.resolve(),
69
+ });
70
+ },
71
+ };
72
+ }
@@ -541,11 +541,11 @@ export declare class AgentDirectory extends DurableObject<StandaloneAgentEnv> {
541
541
  readCreator(agentId: string): string | null;
542
542
  /** Immutable creating Agent, distinct from the human credential owner. */
543
543
  createdBy(agentId: string): string | null;
544
- /** Owner-only rename; refuses a name already held by another Agent. */
544
+ /** An owner or the Agent itself may rename it; another Agent's name is refused. */
545
545
  rename(agentId: string, name: string, principal: TenantPrincipal): AgentEntry | Readonly<{
546
546
  error: "not_found" | "name_taken" | "not_granted";
547
547
  }>;
548
- /** Owner-only avatar change; the Agent wears it in every App and list. */
548
+ /** Owner or self avatar change; the Agent wears it in every App and list. */
549
549
  setAvatar(agentId: string, avatar: Avatar, principal: TenantPrincipal): AgentEntry | Readonly<{
550
550
  error: "not_found" | "not_granted";
551
551
  }>;
@@ -1,3 +1,5 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { createSelfSource } from "./agent-self.js";
1
3
  import { agentCodeExecutionTimeoutMs } from "@fungi.computer/computer-contract";
2
4
  import { isRetryableProviderRejection, normalizeModel, observeProviderStatus, providerDisplayNames, streamModel, } from "@fungi.computer/mule/effect";
3
5
  import { standaloneTenancy, } from "./tenancy.js";
@@ -65,7 +67,7 @@ import { AppInstanceError } from "../index.js";
65
67
  import { agentScheduleBindingArgs, appAgentScheduleListInputSchema, agentSchedulePageSchema, agentScheduleControlReceiptSchema, } from "../agent-schedules.js";
66
68
  import { readAgentSchedulePage, controlAgentSchedule, } from "@fungi.computer/shiitake-extensions/schedules/client";
67
69
  import { agentScheduleTargetSchema } from "@fungi.computer/shiitake-extensions/schedules";
68
- import { createAgentAvatarStore, } from "../agent-avatars.js";
70
+ import { agentAvatarSchema, createAgentAvatarStore, } from "../agent-avatars.js";
69
71
  import { createStarterLedger, ensureStarterAgent, seedStarterHome, } from "../starter-agent.js";
70
72
  import { agentIds, createAgentDirectory, createFleetSessions, commandSettlementSchema, DirectoryError, } from "@fungi.computer/shiitake/fleet";
71
73
  import { appToolPolicySchema, } from "../apps/index.js";
@@ -1386,6 +1388,17 @@ export class StandaloneAgentBase extends ShiitakeDO {
1386
1388
  return answer;
1387
1389
  },
1388
1390
  })),
1391
+ createSelfSource({
1392
+ agentId: this.agentName(),
1393
+ isChannelSession: (sessionId) => this.channelConversations().sessionConversation(sessionId) !==
1394
+ null,
1395
+ directory: async () => {
1396
+ const pin = await this.policyDirectory();
1397
+ if (pin === null)
1398
+ throw new Error("Agent has no pinned directory");
1399
+ return this.env.AGENT_DIRECTORY.getByName(pin.directoryName);
1400
+ },
1401
+ }),
1389
1402
  conversationAgents.control(() => this.controlDirectory()),
1390
1403
  (await this.ui()).source,
1391
1404
  standaloneWebSource(this.env),
@@ -2179,19 +2192,23 @@ export class AgentDirectory extends DurableObject {
2179
2192
  ? (this.directory.read(this.grant(), id.value)?.createdBy ?? null)
2180
2193
  : null;
2181
2194
  }
2182
- /** Owner-only rename; refuses a name already held by another Agent. */
2195
+ /** An owner or the Agent itself may rename it; another Agent's name is refused. */
2183
2196
  rename(agentId, name, principal) {
2184
- if (!oysterPrincipalIsOwner(principal))
2197
+ if (principal.actor.kind === "agent"
2198
+ ? principal.actor.agentId !== agentId
2199
+ : !oysterPrincipalIsOwner(principal))
2185
2200
  return { error: "not_granted" };
2186
2201
  const id = agentIds.agent.parse(agentId);
2187
2202
  if (!id.ok)
2188
2203
  return { error: "not_found" };
2189
2204
  return this.ctx.storage.transactionSync(() => {
2190
2205
  try {
2206
+ const previous = this.directory.read(this.grant(), id.value);
2191
2207
  const renamed = this.directory.rename(this.grant(), id.value, {
2192
2208
  name,
2193
2209
  });
2194
- this.bump();
2210
+ if (previous?.name !== renamed.name)
2211
+ this.bump();
2195
2212
  return {
2196
2213
  agentId: renamed.agentId,
2197
2214
  createdBy: renamed.createdBy,
@@ -2208,19 +2225,24 @@ export class AgentDirectory extends DurableObject {
2208
2225
  }
2209
2226
  });
2210
2227
  }
2211
- /** Owner-only avatar change; the Agent wears it in every App and list. */
2228
+ /** Owner or self avatar change; the Agent wears it in every App and list. */
2212
2229
  setAvatar(agentId, avatar, principal) {
2213
- if (!oysterPrincipalIsOwner(principal))
2230
+ if (principal.actor.kind === "agent"
2231
+ ? principal.actor.agentId !== agentId
2232
+ : !oysterPrincipalIsOwner(principal))
2214
2233
  return { error: "not_granted" };
2215
2234
  const id = agentIds.agent.parse(agentId);
2216
2235
  if (!id.ok)
2217
2236
  return { error: "not_found" };
2237
+ const chosen = agentAvatarSchema.parse(avatar);
2218
2238
  return this.ctx.storage.transactionSync(() => {
2219
2239
  const agent = this.directory.read(this.grant(), id.value);
2220
2240
  if (agent === null)
2221
2241
  return { error: "not_found" };
2222
- this.avatars.write(agent.agentId, avatar);
2223
- this.bump();
2242
+ if (!isDeepStrictEqual(this.avatars.read(agent.agentId), chosen)) {
2243
+ this.avatars.write(agent.agentId, chosen);
2244
+ this.bump();
2245
+ }
2224
2246
  return {
2225
2247
  agentId: agent.agentId,
2226
2248
  createdBy: agent.createdBy,
@@ -53,6 +53,13 @@ export async function previewOrigins(env) {
53
53
  }
54
54
  export class PreviewRefused extends Error {
55
55
  }
56
+ // Public suffix rules only: a private-suffix preview domain still makes every
57
+ // workspace-* host one site, so the gate refuses siblings that browsers might
58
+ // treat as separate sites. Loaded on demand like previewOrigins' parser.
59
+ async function publicSite() {
60
+ const { getDomain } = await import("tldts");
61
+ return (url) => getDomain(url.hostname, { allowPrivateDomains: false });
62
+ }
56
63
  // The retained flat hostname uses the Computer's non-secret identity. Fleet
57
64
  // IDs have a computer_ prefix; configured standalone IDs can be simple labels.
58
65
  const hostnameComputer = z.string().regex(/^(?:computer_)?[a-z0-9]+$/u);
@@ -90,8 +97,12 @@ export function createStandalonePreview(storage, computerId, origins, native) {
90
97
  if (incoming.origin !== target.origin ||
91
98
  !incoming.pathname.startsWith(target.pathname))
92
99
  return new Response(null, { status: 404 });
100
+ const policy = {
101
+ entryUrl: entryUrl(origins, computerId, port),
102
+ site: await publicSite(),
103
+ };
93
104
  return access
94
- .gate(port, entryUrl(origins, computerId, port), async (admitted) => {
105
+ .gate(port, policy, async (admitted) => {
95
106
  const service = new URL("http://localhost");
96
107
  service.pathname = incoming.pathname;
97
108
  service.search = incoming.search;
@@ -579,18 +579,20 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
579
579
  };
580
580
  };
581
581
  readonly nodes: readonly ({
582
- readonly id: string;
583
- readonly kind: "code";
584
- readonly source: string;
585
- readonly input: {
582
+ readonly output: {
586
583
  readonly [x: string]: S.Json;
587
584
  };
588
- readonly output: {
585
+ readonly input: {
589
586
  readonly [x: string]: S.Json;
590
587
  };
591
588
  readonly values: {
592
589
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
593
590
  };
591
+ readonly kind: "code";
592
+ readonly id: string;
593
+ readonly source: string;
594
+ readonly title?: string | undefined;
595
+ readonly note?: string | undefined;
594
596
  } | {
595
597
  readonly values: {
596
598
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
@@ -600,6 +602,8 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
600
602
  readonly method: string;
601
603
  readonly app: string;
602
604
  readonly methodDigest: string;
605
+ readonly title?: string | undefined;
606
+ readonly note?: string | undefined;
603
607
  readonly retry?: {
604
608
  readonly attempts: number;
605
609
  } | undefined;
@@ -628,36 +632,47 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
628
632
  readonly id: string;
629
633
  readonly description?: string | undefined;
630
634
  }[] | undefined;
635
+ readonly note?: string | undefined;
631
636
  } | {
632
- readonly id: string;
633
637
  readonly kind: "condition";
638
+ readonly id: string;
634
639
  readonly test: import("@fungi.computer/braid").Predicate;
640
+ readonly title?: string | undefined;
641
+ readonly note?: string | undefined;
635
642
  } | {
636
- readonly id: string;
637
643
  readonly kind: "map";
644
+ readonly id: string;
645
+ readonly body: string;
638
646
  readonly over: {
639
647
  readonly node: string;
640
648
  readonly port: string;
641
649
  };
642
- readonly body: string;
643
650
  readonly concurrency: number;
644
651
  readonly maxItems: number;
652
+ readonly title?: string | undefined;
653
+ readonly note?: string | undefined;
645
654
  } | {
646
- readonly id: string;
647
655
  readonly kind: "repeat";
656
+ readonly id: string;
648
657
  readonly body: string;
649
- readonly maxRounds: number;
650
658
  readonly until: import("@fungi.computer/braid").Predicate;
659
+ readonly maxRounds: number;
660
+ readonly title?: string | undefined;
661
+ readonly note?: string | undefined;
651
662
  } | {
652
- readonly id: string;
653
663
  readonly kind: "wait";
664
+ readonly id: string;
654
665
  readonly for: number;
666
+ readonly title?: string | undefined;
667
+ readonly note?: string | undefined;
655
668
  } | {
656
- readonly id: string;
657
669
  readonly kind: "transform";
670
+ readonly id: string;
658
671
  readonly fields: {
659
672
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
660
673
  };
674
+ readonly title?: string | undefined;
675
+ readonly note?: string | undefined;
661
676
  })[];
662
677
  readonly edges: readonly {
663
678
  readonly from: {
@@ -676,18 +691,20 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
676
691
  readonly [x: string]: S.Json;
677
692
  };
678
693
  readonly nodes: readonly ({
679
- readonly id: string;
680
- readonly kind: "code";
681
- readonly source: string;
682
- readonly input: {
694
+ readonly output: {
683
695
  readonly [x: string]: S.Json;
684
696
  };
685
- readonly output: {
697
+ readonly input: {
686
698
  readonly [x: string]: S.Json;
687
699
  };
688
700
  readonly values: {
689
701
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
690
702
  };
703
+ readonly kind: "code";
704
+ readonly id: string;
705
+ readonly source: string;
706
+ readonly title?: string | undefined;
707
+ readonly note?: string | undefined;
691
708
  } | {
692
709
  readonly values: {
693
710
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
@@ -697,6 +714,8 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
697
714
  readonly method: string;
698
715
  readonly app: string;
699
716
  readonly methodDigest: string;
717
+ readonly title?: string | undefined;
718
+ readonly note?: string | undefined;
700
719
  readonly retry?: {
701
720
  readonly attempts: number;
702
721
  } | undefined;
@@ -725,36 +744,47 @@ export declare function createStandaloneWorkflowHost(owner: WatchdogSqliteOwner,
725
744
  readonly id: string;
726
745
  readonly description?: string | undefined;
727
746
  }[] | undefined;
747
+ readonly note?: string | undefined;
728
748
  } | {
729
- readonly id: string;
730
749
  readonly kind: "condition";
750
+ readonly id: string;
731
751
  readonly test: import("@fungi.computer/braid").Predicate;
752
+ readonly title?: string | undefined;
753
+ readonly note?: string | undefined;
732
754
  } | {
733
- readonly id: string;
734
755
  readonly kind: "map";
756
+ readonly id: string;
757
+ readonly body: string;
735
758
  readonly over: {
736
759
  readonly node: string;
737
760
  readonly port: string;
738
761
  };
739
- readonly body: string;
740
762
  readonly concurrency: number;
741
763
  readonly maxItems: number;
764
+ readonly title?: string | undefined;
765
+ readonly note?: string | undefined;
742
766
  } | {
743
- readonly id: string;
744
767
  readonly kind: "repeat";
768
+ readonly id: string;
745
769
  readonly body: string;
746
- readonly maxRounds: number;
747
770
  readonly until: import("@fungi.computer/braid").Predicate;
771
+ readonly maxRounds: number;
772
+ readonly title?: string | undefined;
773
+ readonly note?: string | undefined;
748
774
  } | {
749
- readonly id: string;
750
775
  readonly kind: "wait";
776
+ readonly id: string;
751
777
  readonly for: number;
778
+ readonly title?: string | undefined;
779
+ readonly note?: string | undefined;
752
780
  } | {
753
- readonly id: string;
754
781
  readonly kind: "transform";
782
+ readonly id: string;
755
783
  readonly fields: {
756
784
  readonly [x: string]: import("@fungi.computer/braid").Mapping;
757
785
  };
786
+ readonly title?: string | undefined;
787
+ readonly note?: string | undefined;
758
788
  })[];
759
789
  readonly edges: readonly {
760
790
  readonly from: {