@ziggs-ai/api-client 0.1.8 → 0.1.9

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,53 @@
1
+ import 'dotenv/config';
2
+ export type InboxScopeKind = 'chat' | 'agreement' | 'org';
3
+ export interface InboxScopeEntry {
4
+ scope: {
5
+ kind: InboxScopeKind;
6
+ id: string;
7
+ };
8
+ newMessages: number;
9
+ newArtifacts: number;
10
+ latestAt: string | null;
11
+ since: string;
12
+ }
13
+ export interface InboxProposalRef {
14
+ agreementId: string;
15
+ title: string;
16
+ proposedAt: string | null;
17
+ }
18
+ export interface InboxEnvelope {
19
+ asOf: string;
20
+ scopes: InboxScopeEntry[];
21
+ truncatedScopes: number;
22
+ countCap: number;
23
+ proposalsAwaitingMe: InboxProposalRef[];
24
+ truncatedProposals: number;
25
+ }
26
+ export interface InboxAck {
27
+ kind: InboxScopeKind;
28
+ id: string;
29
+ upTo: string;
30
+ }
31
+ export interface InboxAckResult {
32
+ acked: Array<{
33
+ scope: {
34
+ kind: InboxScopeKind;
35
+ id: string;
36
+ };
37
+ ackedUpTo: string;
38
+ }>;
39
+ }
40
+ /**
41
+ * The doorbell, not the door (ZIG-434): references and counts since the
42
+ * agent's last ack — never content. Flow: inbox → read → act → ack (ZIG-446).
43
+ * Wraps `GET /agent-api/v1/inbox` and `POST /agent-api/v1/inbox/ack`.
44
+ */
45
+ export declare class InboxClient {
46
+ private readonly operatorKey;
47
+ private readonly agentId;
48
+ private readonly baseUrl;
49
+ constructor(operatorKey: string, agentId: string, baseUrl?: string);
50
+ private headers;
51
+ getInbox(): Promise<InboxEnvelope>;
52
+ ack(scopes: InboxAck[]): Promise<InboxAckResult>;
53
+ }
@@ -0,0 +1,53 @@
1
+ import 'dotenv/config';
2
+ import { getBackendUrl } from '../utils/urlUtils.js';
3
+ /**
4
+ * The doorbell, not the door (ZIG-434): references and counts since the
5
+ * agent's last ack — never content. Flow: inbox → read → act → ack (ZIG-446).
6
+ * Wraps `GET /agent-api/v1/inbox` and `POST /agent-api/v1/inbox/ack`.
7
+ */
8
+ export class InboxClient {
9
+ operatorKey;
10
+ agentId;
11
+ baseUrl;
12
+ constructor(operatorKey, agentId, baseUrl) {
13
+ if (!operatorKey)
14
+ throw new Error('InboxClient: operatorKey is required');
15
+ if (!agentId) {
16
+ throw new Error('InboxClient: agentId is required (operator-token impersonation)');
17
+ }
18
+ this.operatorKey = operatorKey;
19
+ this.agentId = agentId;
20
+ this.baseUrl = baseUrl || getBackendUrl();
21
+ }
22
+ headers() {
23
+ return {
24
+ Authorization: `Bearer ${this.operatorKey}`,
25
+ 'X-Agent-Id': this.agentId,
26
+ 'Content-Type': 'application/json',
27
+ };
28
+ }
29
+ async getInbox() {
30
+ const res = await fetch(`${this.baseUrl}/agent-api/v1/inbox`, {
31
+ headers: this.headers(),
32
+ });
33
+ const body = await res.text().catch(() => '');
34
+ if (!res.ok) {
35
+ throw new Error(`InboxClient.getInbox ${res.status} ${body.slice(0, 200)}`);
36
+ }
37
+ return JSON.parse(body);
38
+ }
39
+ async ack(scopes) {
40
+ if (!scopes.length)
41
+ throw new Error('InboxClient.ack: scopes are required');
42
+ const res = await fetch(`${this.baseUrl}/agent-api/v1/inbox/ack`, {
43
+ method: 'POST',
44
+ headers: this.headers(),
45
+ body: JSON.stringify({ scopes }),
46
+ });
47
+ const body = await res.text().catch(() => '');
48
+ if (!res.ok) {
49
+ throw new Error(`InboxClient.ack ${res.status} ${body.slice(0, 200)}`);
50
+ }
51
+ return JSON.parse(body);
52
+ }
53
+ }
@@ -16,3 +16,5 @@ export { ContextGrantsClient } from './ContextGrantsClient.js';
16
16
  export type { ContextGrantRecord, ContextGrantScope, ContextGrantScopeKind, ContextTemporal, IssueContextGrantInput, DelegateContextGrantInput, } from './ContextGrantsClient.js';
17
17
  export { AgentSearchClient } from './AgentSearchClient.js';
18
18
  export { TelemetryClient } from './TelemetryClient.js';
19
+ export { InboxClient } from './InboxClient.js';
20
+ export type { InboxScopeKind, InboxScopeEntry, InboxProposalRef, InboxEnvelope, InboxAck, InboxAckResult, } from './InboxClient.js';
@@ -10,3 +10,4 @@ export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
10
10
  export { ContextGrantsClient } from './ContextGrantsClient.js';
11
11
  export { AgentSearchClient } from './AgentSearchClient.js';
12
12
  export { TelemetryClient } from './TelemetryClient.js';
13
+ export { InboxClient } from './InboxClient.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ziggs-ai/api-client",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "HTTP and WebSocket client for the Ziggs backend API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",