@ziggs-ai/api-client 0.32.0 → 0.32.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.
@@ -293,6 +293,10 @@ function openBodyFromArgs(args) {
293
293
  return body;
294
294
  }
295
295
  function presentOpenResult(result, env) {
296
+ // Resource-routed OAuth calls let the backend select the assistant. Their
297
+ // local credentials have no agent id, so only the response can name it.
298
+ const actingAgentId = result.actingAgentId !== undefined
299
+ ? result.actingAgentId : fullCreds(env).agentId || undefined;
296
300
  // Expose a request-only next action, never execute it as part of a read.
297
301
  const requestTool = env.surface === 'mcp' ? 'ziggs_access_request' : 'access_request';
298
302
  const chatTool = env.surface === 'mcp' ? 'ziggs_chat_open' : 'chat_open';
@@ -302,7 +306,7 @@ function presentOpenResult(result, env) {
302
306
  return [];
303
307
  const row = item;
304
308
  const ask = row.grantRequest;
305
- if (row.status !== 'active' || !isContextAccessRequest(ask) || ask.holderId !== fullCreds(env).agentId || !ask.scope?.id || !['artifact', 'chat', 'agreement', 'task'].includes(ask.scope.kind ?? ''))
309
+ if (row.status !== 'active' || !isContextAccessRequest(ask) || !actingAgentId || ask.holderId !== actingAgentId || !ask.scope?.id || !['artifact', 'chat', 'agreement', 'task'].includes(ask.scope.kind ?? ''))
306
310
  return [];
307
311
  return [{ kind: 'resume', tool: env.surface === 'mcp' ? 'ziggs_open' : 'open', args: { [`${ask.scope.kind}Id`]: ask.scope.id }, effect: 'read_only', note: 'Approval recorded. Open the original scope; the server rechecks expiry and revocation.' }];
308
312
  });
@@ -316,7 +320,7 @@ function presentOpenResult(result, env) {
316
320
  : result.ref.kind === 'artifact' && result.outcome === 'unreadable'
317
321
  ? [requestAccessAction({ scopeKind: 'artifact', scopeId: result.ref.id, permission: 'read', durationHours: 24 }, env)]
318
322
  : resumeActions,
319
- actingAgentId: fullCreds(env).agentId,
323
+ ...(actingAgentId !== undefined ? { actingAgentId } : {}),
320
324
  ...(!result.actions && result.ref.kind === 'artifact' && result.outcome !== 'ok' ? {
321
325
  requestAccessHint: `If a source you already read supplied this artifact reference and its human owner, ${requestTool} scopeKind=artifact can ask that owner for temporary read access without a prior grant. It needs a conversation with the owner; ${chatTool} can open or reuse one, subject to authorization. Discover the request tool's schema before calling it. This response does not confirm existence or ownership. A request grants no access until the human owner approves.`,
322
326
  } : {}),
@@ -451,8 +455,10 @@ export const accessRequestCapability = {
451
455
  durationHours, chatId: args.chatId,
452
456
  recipientId: typeof args.recipientId === 'string' ? args.recipientId.trim() : undefined,
453
457
  }, { idempotencyKey: args.idempotencyKey, laneId: creds.laneId });
458
+ const actingAgentId = result.actingAgentId ?? (creds.agentId || undefined);
454
459
  return {
455
- ...result, outcome: 'pending', state: 'requested', actingAgentId: creds.agentId,
460
+ ...result, outcome: 'pending', state: 'requested',
461
+ ...(actingAgentId ? { actingAgentId } : {}),
456
462
  scope: result.scope ?? { kind: scopeKind, id: scopeId },
457
463
  appUrl: `${(env.webUrl ?? 'https://ziggsai.com').replace(/\/$/, '')}/app/agreements/${encodeURIComponent(result.agreementId)}`,
458
464
  resumeAfterApproval: { tool: env.surface === 'mcp' ? 'ziggs_open' : 'open', args: result.scope ? { [`${result.scope.kind}Id`]: result.scope.id } : { [`${scopeKind}Id`]: scopeId } },
@@ -116,6 +116,7 @@ export declare class ContextGrantsClient {
116
116
  status: 'pending_approval';
117
117
  agreementId: string;
118
118
  accessGranted: false;
119
+ actingAgentId?: string;
119
120
  scope?: {
120
121
  kind: string;
121
122
  id: string;
@@ -80,7 +80,7 @@ export class ContextGrantsClient {
80
80
  if (result.status !== 'pending_approval' || !result.agreementId || result.accessGranted !== false) {
81
81
  throw new Error('Expected a pending access request with accessGranted=false');
82
82
  }
83
- return { status: 'pending_approval', agreementId: result.agreementId, accessGranted: false, ...(result.scope ? { scope: result.scope } : {}), ...sentToOf(result) };
83
+ return { status: 'pending_approval', agreementId: result.agreementId, accessGranted: false, ...(typeof result.actingAgentId === 'string' && result.actingAgentId ? { actingAgentId: result.actingAgentId } : {}), ...(result.scope ? { scope: result.scope } : {}), ...sentToOf(result) };
84
84
  }
85
85
  async requestArtifactAccess(artifactId, input, opts) {
86
86
  const res = await fetch(`${this.baseUrl}/context/artifacts/${encodeURIComponent(artifactId)}/access-requests`, {
@@ -51,6 +51,8 @@ export interface ContextOpenAccess {
51
51
  };
52
52
  }
53
53
  export interface ContextOpenResult {
54
+ /** Server-resolved caller; absent on older servers, null for human callers. */
55
+ actingAgentId?: string | null;
54
56
  /** Optional for servers predating resource action projections. */
55
57
  actions?: ResourceAction[];
56
58
  outcome: ContextOpenOutcome;
@@ -20,7 +20,9 @@ export declare class InboxClient {
20
20
  constructor(operatorKey: string, agentId?: string, baseUrl?: string, instanceId?: string);
21
21
  private headers;
22
22
  private inboxUrl;
23
- getInbox(opts?: InboxReadOptions): Promise<InboxEnvelope>;
23
+ getInbox(opts?: InboxReadOptions & {
24
+ signal?: AbortSignal;
25
+ }): Promise<InboxEnvelope>;
24
26
  /**
25
27
  * Wait for assigned mail without taking the host lease.
26
28
  * Still sends X-Ziggs-Instance; the server ignores it on this route.
@@ -50,6 +50,7 @@ export class InboxClient {
50
50
  async getInbox(opts = {}) {
51
51
  const res = await fetch(this.inboxUrl('/inbox', opts), {
52
52
  headers: this.headers(),
53
+ ...(opts.signal ? { signal: opts.signal } : {}),
53
54
  });
54
55
  const body = await res.text().catch(() => '');
55
56
  if (!res.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.32.0",
3
+ "version": "0.32.1",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",