@ziggs-ai/api-client 0.16.0 → 0.17.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.
@@ -2,22 +2,15 @@ import { runtimeLog } from '../shared/runtimeLog.js';
2
2
  import { getBackendUrl } from '../utils/urlUtils.js';
3
3
  import { OPEN_AGREEMENT_TARGET, ORG_AGREEMENT_TARGET, isBroadcastTarget, partySideIds } from '../types.js';
4
4
  import { throwApiError } from '../shared/apiError.js';
5
+ import { buildCredsHeaders } from './operatorHeaders.js';
5
6
  // Lazy: read at call time so a `configureApiClient` call that lands after this
6
7
  // module is imported still takes effect. Baking it at module-load time would
7
8
  // freeze the URL before the host has configured one.
8
9
  function getAgreementBaseUrl() {
9
10
  return `${getBackendUrl()}/agreements`;
10
11
  }
11
- function buildHeaders(creds) {
12
- return {
13
- 'content-type': 'application/json',
14
- Authorization: `Bearer ${creds.operatorKey}`,
15
- 'X-Agent-Id': creds.agentId,
16
- // the wake's lane, so the backend can fence this call to the
17
- // engagement it belongs to rather than the agent's whole authority.
18
- ...(creds.laneId ? { 'X-Ziggs-Lane': creds.laneId } : {}),
19
- };
20
- }
12
+ // Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
13
+ const buildHeaders = buildCredsHeaders;
21
14
  function assertCreds(creds, op) {
22
15
  if (!creds?.operatorKey)
23
16
  throw new Error(`operatorKey is required for ${op}`);
@@ -1,16 +1,9 @@
1
1
  import { runtimeLog } from '../shared/runtimeLog.js';
2
2
  import { getBackendUrl } from '../utils/urlUtils.js';
3
3
  import { throwApiError } from '../shared/apiError.js';
4
- function buildHeaders(creds) {
5
- return {
6
- 'content-type': 'application/json',
7
- Authorization: `Bearer ${creds.operatorKey}`,
8
- 'X-Agent-Id': creds.agentId,
9
- // the wake's lane, so the backend can fence this call to the
10
- // engagement it belongs to rather than the agent's whole authority.
11
- ...(creds.laneId ? { 'X-Ziggs-Lane': creds.laneId } : {}),
12
- };
13
- }
4
+ import { buildCredsHeaders } from './operatorHeaders.js';
5
+ // Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
6
+ const buildHeaders = buildCredsHeaders;
14
7
  function assertCreds(creds, op) {
15
8
  if (!creds?.operatorKey)
16
9
  throw new Error(`operatorKey is required for ${op}`);
@@ -1,5 +1,6 @@
1
1
  import { getBackendUrl } from '../utils/urlUtils.js';
2
2
  import { pollSurfaceError } from '../shared/rateLimit.js';
3
+ import { buildOperatorHeaders } from './operatorHeaders.js';
3
4
  export const CONTEXT_READ_TYPES = [
4
5
  'messages',
5
6
  'artifacts',
@@ -92,13 +93,7 @@ export class ContextReadClient {
92
93
  if (query.contextGrantId) {
93
94
  url.searchParams.set('contextGrantId', query.contextGrantId);
94
95
  }
95
- const headers = {
96
- Authorization: `Bearer ${this.operatorKey}`,
97
- };
98
- if (this.agentId)
99
- headers['X-Agent-Id'] = this.agentId;
100
- if (this.laneId)
101
- headers['X-Ziggs-Lane'] = this.laneId;
96
+ const headers = buildOperatorHeaders(this.operatorKey, this.agentId, undefined, this.laneId);
102
97
  if (query.contextGrantId) {
103
98
  headers['X-Context-Grant-Id'] = query.contextGrantId;
104
99
  }
@@ -131,13 +126,7 @@ export class ContextReadClient {
131
126
  if (opts.contextGrantId) {
132
127
  url.searchParams.set('contextGrantId', opts.contextGrantId);
133
128
  }
134
- const headers = {
135
- Authorization: `Bearer ${this.operatorKey}`,
136
- };
137
- if (this.agentId)
138
- headers['X-Agent-Id'] = this.agentId;
139
- if (this.laneId)
140
- headers['X-Ziggs-Lane'] = this.laneId;
129
+ const headers = buildOperatorHeaders(this.operatorKey, this.agentId, undefined, this.laneId);
141
130
  if (opts.contextGrantId) {
142
131
  headers['X-Context-Grant-Id'] = opts.contextGrantId;
143
132
  }
@@ -2,17 +2,10 @@
2
2
  import { shapeAgreement } from './AgreementClient.js';
3
3
  import { getBackendUrl } from '../utils/urlUtils.js';
4
4
  import { throwApiError } from '../shared/apiError.js';
5
+ import { buildCredsHeaders } from './operatorHeaders.js';
5
6
  function getMarketplaceBaseUrl() { return `${getBackendUrl()}/marketplace`; }
6
- function buildHeaders(creds) {
7
- return {
8
- 'content-type': 'application/json',
9
- Authorization: `Bearer ${creds.operatorKey}`,
10
- 'X-Agent-Id': creds.agentId,
11
- // the wake's lane, so the backend can fence this call to the
12
- // engagement it belongs to rather than the agent's whole authority.
13
- ...(creds.laneId ? { 'X-Ziggs-Lane': creds.laneId } : {}),
14
- };
15
- }
7
+ // Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
8
+ const buildHeaders = buildCredsHeaders;
16
9
  function assertCreds(creds, op) {
17
10
  if (!creds?.operatorKey)
18
11
  throw new Error(`operatorKey is required for ${op}`);
@@ -1,17 +1,10 @@
1
1
  import { getBackendUrl } from '../utils/urlUtils.js';
2
2
  import { partyActorIds } from '../types.js';
3
3
  import { throwApiError } from '../shared/apiError.js';
4
+ import { buildCredsHeaders } from './operatorHeaders.js';
4
5
  function getTaskBaseUrl() { return `${getBackendUrl()}/tasks`; }
5
- function buildHeaders(creds) {
6
- return {
7
- 'content-type': 'application/json',
8
- Authorization: `Bearer ${creds.operatorKey}`,
9
- 'X-Agent-Id': creds.agentId,
10
- // the wake's lane, so the backend can fence this call to the
11
- // engagement it belongs to rather than the agent's whole authority.
12
- ...(creds.laneId ? { 'X-Ziggs-Lane': creds.laneId } : {}),
13
- };
14
- }
6
+ // Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
7
+ const buildHeaders = buildCredsHeaders;
15
8
  function assertCreds(creds, op) {
16
9
  if (!creds?.operatorKey)
17
10
  throw new Error(`operatorKey is required for ${op}`);
@@ -28,3 +28,4 @@ export type { MyOrg, OrgResolution } from './OrgsClient.js';
28
28
  export { AgentSearchClient } from './AgentSearchClient.js';
29
29
  export { TelemetryClient } from './TelemetryClient.js';
30
30
  export { InboxClient } from './InboxClient.js';
31
+ export { WAKE_LANE_HEADER, laneHeader, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
@@ -19,3 +19,7 @@ export { fetchMyOrgs, resolveOrgSelector, fetchDelegateAccess, fetchHostedAgentA
19
19
  export { AgentSearchClient } from './AgentSearchClient.js';
20
20
  export { TelemetryClient } from './TelemetryClient.js';
21
21
  export { InboxClient } from './InboxClient.js';
22
+ // The lane header, built in one place — see operatorHeaders.ts. Exported
23
+ // because the MCP transports in agent-sdk and ziggs-mcp send it too, and a
24
+ // copy of a header nobody notices missing goes stale unseen.
25
+ export { WAKE_LANE_HEADER, laneHeader, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
@@ -1,8 +1,21 @@
1
1
  /**
2
- * Auth headers for operator-key HTTP clients. `X-Agent-Id` is only sent when
3
- * an agentId is present — agent-scoped keys identify the agent themselves;
4
- * fleet keys must pass one.
2
+ * Auth headers for operator-key HTTP clients.
3
+ *
4
+ * ONE place builds them, because the lane is the header a caller cannot be
5
+ * trusted to remember. Omitting `X-Ziggs-Lane` never fails: the server fences
6
+ * the wake to the agent's own org instead, so a door that forgets it answers
7
+ * short lists and refuses grants the agent's customer gave it — silently, and
8
+ * only for the agents that serve someone other than their owner. A header
9
+ * whose absence is indistinguishable from a legitimate answer has to be built
10
+ * in one place, not copied into each caller.
5
11
  */
12
+ /** The header the backend's wake fence reads (`access/wake-fence.ts`). */
13
+ export declare const WAKE_LANE_HEADER = "X-Ziggs-Lane";
14
+ /**
15
+ * The lane header, or nothing. `laneId` is a chat id, or `agrn-<agreementId>`
16
+ * for a task with no origin chat.
17
+ */
18
+ export declare function laneHeader(laneId?: string): Record<string, string>;
6
19
  export declare function buildOperatorHeaders(operatorKey: string, agentId?: string, extra?: Record<string, string>,
7
20
  /**
8
21
  * the lane this call belongs to, sent as `X-Ziggs-Lane`. The
@@ -10,3 +23,9 @@ export declare function buildOperatorHeaders(operatorKey: string, agentId?: stri
10
23
  * narrows to the agent's own org, so it can never widen reach.
11
24
  */
12
25
  laneId?: string): Record<string, string>;
26
+ /** What a `Creds`-shaped client sends on a JSON call: auth, agent, lane. */
27
+ export declare function buildCredsHeaders(creds: {
28
+ operatorKey: string;
29
+ agentId: string;
30
+ laneId?: string;
31
+ }): Record<string, string>;
@@ -1,8 +1,23 @@
1
1
  /**
2
- * Auth headers for operator-key HTTP clients. `X-Agent-Id` is only sent when
3
- * an agentId is present — agent-scoped keys identify the agent themselves;
4
- * fleet keys must pass one.
2
+ * Auth headers for operator-key HTTP clients.
3
+ *
4
+ * ONE place builds them, because the lane is the header a caller cannot be
5
+ * trusted to remember. Omitting `X-Ziggs-Lane` never fails: the server fences
6
+ * the wake to the agent's own org instead, so a door that forgets it answers
7
+ * short lists and refuses grants the agent's customer gave it — silently, and
8
+ * only for the agents that serve someone other than their owner. A header
9
+ * whose absence is indistinguishable from a legitimate answer has to be built
10
+ * in one place, not copied into each caller.
5
11
  */
12
+ /** The header the backend's wake fence reads (`access/wake-fence.ts`). */
13
+ export const WAKE_LANE_HEADER = 'X-Ziggs-Lane';
14
+ /**
15
+ * The lane header, or nothing. `laneId` is a chat id, or `agrn-<agreementId>`
16
+ * for a task with no origin chat.
17
+ */
18
+ export function laneHeader(laneId) {
19
+ return laneId ? { [WAKE_LANE_HEADER]: laneId } : {};
20
+ }
6
21
  export function buildOperatorHeaders(operatorKey, agentId, extra,
7
22
  /**
8
23
  * the lane this call belongs to, sent as `X-Ziggs-Lane`. The
@@ -12,8 +27,17 @@ export function buildOperatorHeaders(operatorKey, agentId, extra,
12
27
  laneId) {
13
28
  return {
14
29
  Authorization: `Bearer ${operatorKey}`,
30
+ // `X-Agent-Id` is only sent when an agentId is present — agent-scoped keys
31
+ // identify the agent themselves; fleet keys must pass one.
15
32
  ...(agentId ? { 'X-Agent-Id': agentId } : {}),
16
- ...(laneId ? { 'X-Ziggs-Lane': laneId } : {}),
33
+ ...laneHeader(laneId),
17
34
  ...extra,
18
35
  };
19
36
  }
37
+ /** What a `Creds`-shaped client sends on a JSON call: auth, agent, lane. */
38
+ export function buildCredsHeaders(creds) {
39
+ return {
40
+ 'content-type': 'application/json',
41
+ ...buildOperatorHeaders(creds.operatorKey, creds.agentId, undefined, creds.laneId),
42
+ };
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",