@fungi.computer/oyster 0.35.1 → 0.36.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/dist/host.d.ts CHANGED
@@ -7,7 +7,7 @@ export type { InstallationOperations };
7
7
  import { type AppTestCopy, type AppTestCopyAuthority } from "./app-test-copies.js";
8
8
  export { appTestCopySchema, appTestCopyAuthoritySchema, type AppTestCopy, type AppTestCopyAuthority, } from "./app-test-copies.js";
9
9
  import type { KnapsackComputer } from "@fungi.computer/knapsack";
10
- import type { TenantPrincipal } from "./tenant.js";
10
+ import type { TenantId, TenantPrincipal } from "./tenant.js";
11
11
  import { type GillCall, type GillReply } from "@fungi.computer/gills";
12
12
  import { type AppStorageWire } from "@fungi.computer/agar/storage";
13
13
  import type { OysterRootDirectory } from "./root-data.js";
@@ -184,6 +184,8 @@ export type OysterEnv = {
184
184
  };
185
185
  /** Everything a host supplies to run Oyster. */
186
186
  export type OysterHost = Readonly<{
187
+ /** Tenant selected by the host before admission, never by App input. */
188
+ tenantId: TenantId;
187
189
  /** Native approval home. A host without one cannot execute App tool writes. */
188
190
  approvals?: Readonly<{
189
191
  /** Wait for a decision and return the native home's in-call result. */
package/dist/host.js CHANGED
@@ -226,7 +226,7 @@ export function oysterRouteTable(host) {
226
226
  }, declaration, await deriveDeclaredOperations(installation.release, declaration, operationDescriptors), "team.workbenchHost") !== null);
227
227
  };
228
228
  const reduceInstallation = async (current, command, release, principal, identity) => {
229
- const context = invocationCallerContext(principal, host.computerId ?? null);
229
+ const context = invocationCallerContext(principal, host.computerId ?? null, host.tenantId);
230
230
  const declaration = release.declaration ?? emptyAppDeclaration;
231
231
  return applyInstallationCommand(current, command, {
232
232
  by: context.actor,
@@ -910,7 +910,7 @@ export function oysterRouteTable(host) {
910
910
  const admitted = admits(await gateFacts(copyOwned.installation, release, copyOwned.principal), { kind: "method", name, input, via: "ui" });
911
911
  if (admitted.kind === "refused")
912
912
  return noStoreRefusal(admitted.code === "invalid_input" ? 400 : 403, admitted.code);
913
- const result = await copyOwned.copies.call(copyOwned.authority, copyId.data, name, input, invocationCallerContext(copyOwned.principal, null));
913
+ const result = await copyOwned.copies.call(copyOwned.authority, copyId.data, name, input, invocationCallerContext(copyOwned.principal, null, host.tenantId));
914
914
  return result.ok
915
915
  ? methodResponse(result.value)
916
916
  : instanceRefusal(result.code, result.causeClass);
@@ -1191,7 +1191,7 @@ export function oysterRouteTable(host) {
1191
1191
  const uiPath = `/ui/${installation.installationId}/${installation.release.releaseId}/`;
1192
1192
  // Immutable App documents also carry the host's sandbox policy.
1193
1193
  const uiUrl = `${uiPath}?${new URLSearchParams({ sandbox: appSandbox }).toString()}`;
1194
- const computerId = invocationCallerContext(principal, host.computerId ?? null).computerId;
1194
+ const computerId = invocationCallerContext(principal, host.computerId ?? null, host.tenantId).computerId;
1195
1195
  const config = {
1196
1196
  workbench,
1197
1197
  // The home shell's own code: the module its Release ships beside
@@ -1276,11 +1276,11 @@ export function oysterRouteTable(host) {
1276
1276
  });
1277
1277
  const response = await host.instances
1278
1278
  .get(selectionOf(installation).instanceId, limits)
1279
- .fetch(admittedCallerFacts(installation, release, invocationCallerContext(principal, host.computerId ?? null), decision.grants), request);
1279
+ .fetch(admittedCallerFacts(installation, release, invocationCallerContext(principal, host.computerId ?? null, host.tenantId), decision.grants), request);
1280
1280
  return appFacetResponse(response);
1281
1281
  });
1282
1282
  table.put("/apps/:installationId/gills", owner("direct-or-app"), async (context, { principal }) => {
1283
- const caller = invocationCallerContext(principal, host.computerId ?? null);
1283
+ const caller = invocationCallerContext(principal, host.computerId ?? null, host.tenantId);
1284
1284
  const installation = await enabled(context);
1285
1285
  if (installation === null)
1286
1286
  return refusal(404, "Not found");
@@ -1413,7 +1413,7 @@ export function oysterRouteTable(host) {
1413
1413
  return refusal(403, "not_declared");
1414
1414
  const result = await host.instances
1415
1415
  .get(selectionOf(installation).instanceId, limits)
1416
- .call(await admittedMethodCallerFacts(host, installation, release, invocationCallerContext(principal, host.computerId ?? null), decision.grants, { name, effect: method.effect }), release.api, name, input);
1416
+ .call(await admittedMethodCallerFacts(host, installation, release, invocationCallerContext(principal, host.computerId ?? null, host.tenantId), decision.grants, { name, effect: method.effect }), release.api, name, input);
1417
1417
  if (!result.ok)
1418
1418
  return instanceRefusal(result.code, result.causeClass);
1419
1419
  return methodResponse(result.value);
@@ -1456,12 +1456,12 @@ export function oysterRouteTable(host) {
1456
1456
  if (target === undefined)
1457
1457
  return refusal(409, "app_call_target_unavailable");
1458
1458
  const release = await releaseOf(target.release);
1459
- const admittedMember = invocationCallerContext(principal, host.computerId ?? null);
1459
+ const admittedMember = invocationCallerContext(principal, host.computerId ?? null, host.tenantId);
1460
1460
  const recheck = async () => {
1461
1461
  const fresh = await host.auth.resolve(admittedMember.actor);
1462
1462
  if (fresh === null)
1463
1463
  return refusal(403, "app_call_member_only");
1464
- const currentMember = invocationCallerContext(fresh, host.computerId ?? null);
1464
+ const currentMember = invocationCallerContext(fresh, host.computerId ?? null, host.tenantId);
1465
1465
  if (currentMember.actor.kind !== "member" ||
1466
1466
  currentMember.actor.memberId !== oysterPrincipalId(principal) ||
1467
1467
  currentMember.role !== admittedMember.role)
@@ -100,7 +100,7 @@ export async function deliverBackground(host, raw) {
100
100
  };
101
101
  return {
102
102
  kind: "admitted",
103
- context: invocationCallerContext(principal, host.computerId ?? null),
103
+ context: invocationCallerContext(principal, host.computerId ?? null, host.tenantId),
104
104
  };
105
105
  },
106
106
  });
@@ -1,4 +1,4 @@
1
- import type { TenantPrincipal } from "./tenant.js";
1
+ import type { TenantId, TenantPrincipal } from "./tenant.js";
2
2
  import type { OysterHost } from "./host.js";
3
3
  import type { VerifiedRelease } from "./release.js";
4
4
  import type { Installation } from "./apps/installation.js";
@@ -26,6 +26,13 @@ export declare const invocationFactsSchema: Schema.Struct<{
26
26
  readonly subject: Schema.Union<readonly [Schema.Struct<{
27
27
  readonly kind: Schema.Literal<"call">;
28
28
  readonly context: Schema.declareConstructor<{
29
+ scope: {
30
+ kind: "team";
31
+ teamId: string;
32
+ } | {
33
+ kind: "standalone";
34
+ tenant: string;
35
+ };
29
36
  computerId: string | null;
30
37
  actor: {
31
38
  kind: "member";
@@ -61,6 +68,13 @@ export declare const invocationFactsSchema: Schema.Struct<{
61
68
  } | undefined;
62
69
  idempotencyKey?: string | undefined;
63
70
  }, {
71
+ scope: {
72
+ kind: "team";
73
+ teamId: string;
74
+ } | {
75
+ kind: "standalone";
76
+ tenant: string;
77
+ };
64
78
  computerId: string | null;
65
79
  actor: {
66
80
  kind: "member";
@@ -96,6 +110,13 @@ export declare const invocationFactsSchema: Schema.Struct<{
96
110
  } | undefined;
97
111
  idempotencyKey?: string | undefined;
98
112
  }, readonly [], {
113
+ scope: {
114
+ kind: "team";
115
+ teamId: string;
116
+ } | {
117
+ kind: "standalone";
118
+ tenant: string;
119
+ };
99
120
  computerId: string | null;
100
121
  actor: {
101
122
  kind: "member";
@@ -234,11 +255,11 @@ export type InvocationDeadline = Readonly<{
234
255
  grantExpiresAt: number;
235
256
  }>;
236
257
  /**
237
- * Project an admitted principal into App attribution; only the host chooses
238
- * the fixed Computer context. Host admission reads the principal, never this
239
- * projection.
258
+ * Project an Oyster-admitted principal into App attribution using its host's
259
+ * tenant pin and fixed Computer context. Hub supplies Team scope separately.
260
+ * Host admission reads the principal, never this projection.
240
261
  */
241
- export declare function invocationCallerContext(principal: TenantPrincipal, computerId: string | null): AppMethodCallContext;
262
+ export declare function invocationCallerContext(principal: TenantPrincipal, computerId: string | null, tenant: TenantId): AppMethodCallContext;
242
263
  /** Shared host-held caller/Workflow fact builders, never guest argument decoders. */
243
264
  export declare const invocationFacts: {
244
265
  /** Combine host-admitted caller facts with the invocation and grant deadlines. */
@@ -246,6 +267,7 @@ export declare const invocationFacts: {
246
267
  /** Attribute an already host-admitted published node to its retained arming actor. */
247
268
  fromWorkflowNode: (authority: InvocationAuthority, input: Readonly<{
248
269
  workflow: WorkflowAttestation;
270
+ scope: AppMethodCallContext["scope"];
249
271
  computerId: string | null;
250
272
  role?: AppMethodCallContext["role"];
251
273
  idempotencyKey: string;
@@ -365,17 +365,18 @@ export function createInvocationGate(ports) {
365
365
  };
366
366
  }
367
367
  /**
368
- * Project an admitted principal into App attribution; only the host chooses
369
- * the fixed Computer context. Host admission reads the principal, never this
370
- * projection.
368
+ * Project an Oyster-admitted principal into App attribution using its host's
369
+ * tenant pin and fixed Computer context. Hub supplies Team scope separately.
370
+ * Host admission reads the principal, never this projection.
371
371
  */
372
- export function invocationCallerContext(principal, computerId) {
372
+ export function invocationCallerContext(principal, computerId, tenant) {
373
373
  const { actor } = principal;
374
+ const scope = { kind: "standalone", tenant };
374
375
  if (!("role" in principal))
375
- return { computerId, actor };
376
+ return { scope, computerId, actor };
376
377
  return principal.soleMember === true
377
- ? { computerId, actor, role: principal.role, soleMember: true }
378
- : { computerId, actor, role: principal.role };
378
+ ? { scope, computerId, actor, role: principal.role, soleMember: true }
379
+ : { scope, computerId, actor, role: principal.role };
379
380
  }
380
381
  /** Shared host-held caller/Workflow fact builders, never guest argument decoders. */
381
382
  export const invocationFacts = {
@@ -400,6 +401,7 @@ export const invocationFacts = {
400
401
  /** Attribute an already host-admitted published node to its retained arming actor. */
401
402
  fromWorkflowNode: (authority, input, deadline) => {
402
403
  const context = {
404
+ scope: input.scope,
403
405
  actor: input.workflow.armedBy,
404
406
  computerId: input.computerId,
405
407
  idempotencyKey: input.idempotencyKey,
package/dist/mcp.d.ts CHANGED
@@ -344,7 +344,7 @@ export type AppSurfaceCache = (release: Installation["release"]) => Promise<Rele
344
344
  /** Make one {@link AppSurfaceCache} for a host whose artifact store and capabilities stay fixed. */
345
345
  export declare function appSurfaceCache(host: Pick<OysterHost, "artifacts" | "capabilities">): AppSurfaceCache;
346
346
  /** Derive the current principal's admitted App modules and grants. */
347
- export declare function oysterAppSnapshot(host: Pick<OysterHost, "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "capabilities" | "appToolPolicy" | "keys" | "approvals">, surfaces: AppSurfaceCache, principal: TenantPrincipal, installations: readonly Installation[], access: OysterCallerAccess, sessionId: string | null, mode: "direct" | "approval"): Promise<Readonly<{
347
+ export declare function oysterAppSnapshot(host: Pick<OysterHost, "tenantId" | "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "capabilities" | "appToolPolicy" | "keys" | "approvals">, surfaces: AppSurfaceCache, principal: TenantPrincipal, installations: readonly Installation[], access: OysterCallerAccess, sessionId: string | null, mode: "direct" | "approval"): Promise<Readonly<{
348
348
  modules: Readonly<Record<string, ModuleRegistration>>;
349
349
  levels: Readonly<Record<string, AppToolPolicy["level"]>>;
350
350
  fences: Readonly<Record<string, string>>;
@@ -359,7 +359,7 @@ export declare function oysterAppSnapshot(host: Pick<OysterHost, "installations"
359
359
  * (`mycelium/src/access.ts`). Call again to capture changes to Releases,
360
360
  * installation authority or the caller's own grants.
361
361
  */
362
- export declare function oysterAppMethods(host: Pick<OysterHost, "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "capabilities" | "appToolPolicy" | "keys" | "approvals">, principal: TenantPrincipal, access: OysterCallerAccess, surfaces: AppSurfaceCache, preloadedInstallations?: readonly Installation[]): Promise<CapabilitySource & {
362
+ export declare function oysterAppMethods(host: Pick<OysterHost, "tenantId" | "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "capabilities" | "appToolPolicy" | "keys" | "approvals">, principal: TenantPrincipal, access: OysterCallerAccess, surfaces: AppSurfaceCache, preloadedInstallations?: readonly Installation[]): Promise<CapabilitySource & {
363
363
  readonly grants: Grants;
364
364
  }>;
365
365
  /**
@@ -383,4 +383,4 @@ export declare function oysterComputerTools(host: Pick<OysterHost, "computerId"
383
383
  * still re-admits the key, checks current App approval and passes the App's
384
384
  * gate.
385
385
  */
386
- export declare function oysterMcpCatalogLoad(host: Pick<OysterHost, "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "computer" | "computerControl" | "capabilities" | "appToolPolicy" | "keys" | "workflows">): (principal: TenantPrincipal) => Promise<OysterMcpCatalogSnapshot>;
386
+ export declare function oysterMcpCatalogLoad(host: Pick<OysterHost, "tenantId" | "installations" | "instances" | "artifacts" | "guestLimits" | "backgroundOriginKey" | "computerId" | "computer" | "computerControl" | "capabilities" | "appToolPolicy" | "keys" | "workflows">): (principal: TenantPrincipal) => Promise<OysterMcpCatalogSnapshot>;
package/dist/mcp.js CHANGED
@@ -236,7 +236,7 @@ export function appSurfaceCache(host) {
236
236
  export async function oysterAppSnapshot(host, surfaces, principal, installations, access, sessionId, mode) {
237
237
  const limits = guestLimits(host.guestLimits);
238
238
  const generation = await host.installations.generation();
239
- const caller = invocationCallerContext(principal, host.computerId ?? null);
239
+ const caller = invocationCallerContext(principal, host.computerId ?? null, host.tenantId);
240
240
  const { actor } = principal;
241
241
  const modules = {};
242
242
  const levels = {};