@xenosystem/agent-interface-host 0.1.72 → 0.1.73

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/index.js CHANGED
@@ -7,6 +7,7 @@ import { applyWorkspaceLifecycle } from './state/WorkspaceLifecycleService.js';
7
7
  import { assertNoDirectLifecycleMutation } from './state/workspaceLifecycle.js';
8
8
  import { assertNativeToolCategoryAdmission, assertToolCategoryAdmission } from './turns/toolCategoryAdmission.js';
9
9
  import { resolvePersistedToolCapabilities } from './turns/persistedToolPolicy.js';
10
+ import { authorizableTarget } from './account/authorizableTarget.js';
10
11
  import { AgentHostProtocolError, XENO_AGENT_HOST_MIN_PROTOCOL_VERSION, XENO_AGENT_HOST_PROTOCOL_VERSION, isAgentHostClientIdentity, isAgentProviderListResult, isAgentHostMaintenanceRequest, defaultRunIdOf, isAgentRuntimeEventEnvelope, } from '@xenosystem/agent-interface-contract';
11
12
  /**
12
13
  * Bounds on the instruction queue. Unbounded queues are how a stuck loop turns
@@ -1521,6 +1522,21 @@ export class AgentHostCoordinator {
1521
1522
  return result;
1522
1523
  }
1523
1524
  if (method === 'account.request') {
1525
+ /*
1526
+ * A connection that provides its own account (surface-account spec §4.5) is answered from
1527
+ * THAT fact, not from the host account: its turns never use the host account, so reporting
1528
+ * "signed out" would put a second sign-in in front of someone who is already signed in, and
1529
+ * reporting the host's account would show the wrong person. Only `status` is answered this
1530
+ * way; account-management actions belong to the app that owns the account.
1531
+ */
1532
+ const accountInput = input;
1533
+ const provided = this.surfaceAccountFor(accountInput.client);
1534
+ if (provided) {
1535
+ if (accountInput.action === 'status') {
1536
+ return { success: true, status: { state: 'signed-in', persistence: 'protected', providedBy: { clientId: provided.clientId } } };
1537
+ }
1538
+ return { success: false, code: 'REFUSED', error: 'This account is managed by the app you are signed in to.' };
1539
+ }
1524
1540
  if (!this.options.accountService)
1525
1541
  return { success: false, code: 'UNCONFIGURED', status: { state: 'unconfigured', persistence: 'unavailable', reason: 'Account authority is not configured on this host.' } };
1526
1542
  return await this.options.accountService.request(input);
@@ -2243,6 +2259,37 @@ export class AgentHostCoordinator {
2243
2259
  * it — and `canPresentElicitations` is exactly such a question, asked immediately before the
2244
2260
  * host puts a prompt to a person and waits with no timeout.
2245
2261
  */
2262
+ /** Surface-provided accounts, attached by the socket server that serves this host (spec §4.3). */
2263
+ surfaceAccounts;
2264
+ attachSurfaceAccounts(accounts) {
2265
+ this.surfaceAccounts = accounts;
2266
+ }
2267
+ /**
2268
+ * The account a turn from this client runs on, when the client provides its own (spec §4.4).
2269
+ *
2270
+ * 🔴 Refuses to sign anything off `AUTHORIZABLE_ORIGINS` BEFORE the question reaches the surface —
2271
+ * the product is asked only for requests to XENO's own services, and the URL it signs for is the
2272
+ * canonical one the gateway checks. `null` from here means "this account cannot authorize this";
2273
+ * the caller must not fall back to the host's own account.
2274
+ */
2275
+ surfaceAccountFor(client) {
2276
+ const accounts = this.surfaceAccounts;
2277
+ const instanceId = client?.instanceId;
2278
+ if (!accounts || !instanceId)
2279
+ return undefined;
2280
+ const capability = accounts.accountOf(instanceId);
2281
+ if (!capability)
2282
+ return undefined;
2283
+ return {
2284
+ clientId: capability.clientId,
2285
+ authorize: async (target) => {
2286
+ const signable = authorizableTarget(target?.method, target?.url);
2287
+ if (!signable)
2288
+ return null;
2289
+ return accounts.authorize(instanceId, signable);
2290
+ },
2291
+ };
2292
+ }
2246
2293
  releaseClient(instanceId) {
2247
2294
  this.connectedClients.delete(instanceId);
2248
2295
  this.clientCapabilities.delete(instanceId);
@@ -3232,8 +3279,10 @@ export class AgentHostCoordinator {
3232
3279
  if (this.closing || controller.signal.aborted)
3233
3280
  throw new Error('Host stopped before adapter dispatch.');
3234
3281
  adapterInvoked = true;
3282
+ const surfaceAccount = this.surfaceAccountFor(request.command?.client);
3235
3283
  return adapter.execute(request, provider, resolved.selection, {
3236
3284
  signal: controller.signal,
3285
+ ...(surfaceAccount ? { surfaceAccount } : {}),
3237
3286
  ...(workspaceEnvironment ? { workspaceEnvironment } : {}),
3238
3287
  ...(workspaceRules ? { workspaceRules } : {}),
3239
3288
  ...(hostBinding ? { hostBinding: structuredClone(hostBinding) } : {}),