@ziggs-ai/api-client 0.1.28 → 0.1.29
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/http/ContextDiscoveryClient.d.ts +3 -14
- package/dist/http/ContextDiscoveryClient.js +3 -12
- package/dist/http/GrantsClient.d.ts +45 -0
- package/dist/http/GrantsClient.js +72 -0
- package/dist/http/grants.d.ts +6 -0
- package/dist/http/index.d.ts +3 -1
- package/dist/http/index.js +1 -0
- package/dist/websocket/WebSocketClient.js +9 -0
- package/package.json +1 -1
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
export interface ContextReachDescriptor {
|
|
3
|
-
grantId: string;
|
|
4
|
-
scope: {
|
|
5
|
-
kind: 'chat' | 'agreement' | 'org';
|
|
6
|
-
id: string;
|
|
7
|
-
};
|
|
8
|
-
temporal: 'from-now' | 'from-start';
|
|
9
|
-
watermarkAt: string;
|
|
10
|
-
expiresAt: string | null;
|
|
11
|
-
parentGrantId: string | null;
|
|
12
|
-
createdAt: string;
|
|
13
|
-
}
|
|
14
2
|
/** Labels-only pointer to context the agent could request access to (P4). */
|
|
15
3
|
export interface DiscoverableItem {
|
|
16
4
|
type: 'chat';
|
|
@@ -22,7 +10,9 @@ export interface DiscoverableItem {
|
|
|
22
10
|
orgId: string;
|
|
23
11
|
}
|
|
24
12
|
/**
|
|
25
|
-
*
|
|
13
|
+
* P4 discovery — labels-only pointers to context the agent could REQUEST but
|
|
14
|
+
* does not yet hold (`GET /context/discovery/available`). Grants the agent
|
|
15
|
+
* already holds are listed via the unified `GrantsClient` (GET /grants).
|
|
26
16
|
*/
|
|
27
17
|
export declare class ContextDiscoveryClient {
|
|
28
18
|
private readonly operatorKey;
|
|
@@ -33,7 +23,6 @@ export declare class ContextDiscoveryClient {
|
|
|
33
23
|
* @param agentId Required for fleet keys (sent as X-Agent-Id). Omit for agent-scoped keys.
|
|
34
24
|
*/
|
|
35
25
|
constructor(operatorKey: string, agentId?: string, baseUrl?: string);
|
|
36
|
-
discover(): Promise<ContextReachDescriptor[]>;
|
|
37
26
|
/**
|
|
38
27
|
* P4: what context EXISTS in the agent's engaged orgs that it does NOT hold
|
|
39
28
|
* a grant for — so it can request access rather than fail blind. Labels only.
|
|
@@ -2,7 +2,9 @@ import 'dotenv/config';
|
|
|
2
2
|
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
3
|
import { buildOperatorHeaders } from './operatorHeaders.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* P4 discovery — labels-only pointers to context the agent could REQUEST but
|
|
6
|
+
* does not yet hold (`GET /context/discovery/available`). Grants the agent
|
|
7
|
+
* already holds are listed via the unified `GrantsClient` (GET /grants).
|
|
6
8
|
*/
|
|
7
9
|
export class ContextDiscoveryClient {
|
|
8
10
|
operatorKey;
|
|
@@ -20,17 +22,6 @@ export class ContextDiscoveryClient {
|
|
|
20
22
|
this.agentId = agentId;
|
|
21
23
|
this.baseUrl = baseUrl || getBackendUrl();
|
|
22
24
|
}
|
|
23
|
-
async discover() {
|
|
24
|
-
const res = await fetch(`${this.baseUrl}/context/discovery`, {
|
|
25
|
-
headers: buildOperatorHeaders(this.operatorKey, this.agentId),
|
|
26
|
-
});
|
|
27
|
-
const body = await res.text().catch(() => '');
|
|
28
|
-
if (!res.ok) {
|
|
29
|
-
throw new Error(`ContextDiscoveryClient.discover ${res.status} ${body.slice(0, 200)}`);
|
|
30
|
-
}
|
|
31
|
-
const parsed = JSON.parse(body);
|
|
32
|
-
return parsed.reach ?? [];
|
|
33
|
-
}
|
|
34
25
|
/**
|
|
35
26
|
* P4: what context EXISTS in the agent's engaged orgs that it does NOT hold
|
|
36
27
|
* a grant for — so it can request access rather than fail blind. Labels only.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import type { GrantView, GrantScopeKind, GrantHealth } from './grants.js';
|
|
3
|
+
export interface ListGrantsQuery {
|
|
4
|
+
/**
|
|
5
|
+
* Filter to grants held by this agent. Admin-gated server-side when the caller
|
|
6
|
+
* is not impersonating that agent.
|
|
7
|
+
*/
|
|
8
|
+
holderId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Rail/resource filter. One kind or several (the context rail spans three
|
|
11
|
+
* kinds: chat, agreement, org). Absent = every rail.
|
|
12
|
+
*/
|
|
13
|
+
scopeKind?: GrantScopeKind | GrantScopeKind[];
|
|
14
|
+
/** Filter to grants of one health. */
|
|
15
|
+
health?: GrantHealth;
|
|
16
|
+
cursor?: string;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ListGrantsResult {
|
|
20
|
+
items: GrantView[];
|
|
21
|
+
nextCursor: string | null;
|
|
22
|
+
hasMore: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ZIG-648 — unified grant listing across every rail. `GET /grants` returns the
|
|
26
|
+
* canonical GrantView for each grant the caller holds (or, admin-gated, a named
|
|
27
|
+
* holder), filterable by scope kind and health, with cursor pagination. Replaces
|
|
28
|
+
* the old per-rail listers (context discovery, connection-grants,
|
|
29
|
+
* payment-grants).
|
|
30
|
+
*/
|
|
31
|
+
export declare class GrantsClient {
|
|
32
|
+
private readonly operatorKey;
|
|
33
|
+
private readonly agentId?;
|
|
34
|
+
private readonly baseUrl;
|
|
35
|
+
constructor(operatorKey: string, agentId?: string, baseUrl?: string);
|
|
36
|
+
listGrants(query?: ListGrantsQuery): Promise<ListGrantsResult>;
|
|
37
|
+
/**
|
|
38
|
+
* Every grant matching `query`, following the cursor to completion. Use when a
|
|
39
|
+
* caller needs the whole set (reach tagging, catch-up, an owner listing) rather
|
|
40
|
+
* than a single page — `listGrants` returns only one page (server default 30),
|
|
41
|
+
* so a holder with more grants than a page would otherwise be silently
|
|
42
|
+
* truncated. `maxPages` bounds the loop as a runaway guard.
|
|
43
|
+
*/
|
|
44
|
+
listAllGrants(query?: Omit<ListGrantsQuery, 'cursor'>, maxPages?: number): Promise<GrantView[]>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
|
+
import { buildOperatorHeaders } from './operatorHeaders.js';
|
|
4
|
+
/**
|
|
5
|
+
* ZIG-648 — unified grant listing across every rail. `GET /grants` returns the
|
|
6
|
+
* canonical GrantView for each grant the caller holds (or, admin-gated, a named
|
|
7
|
+
* holder), filterable by scope kind and health, with cursor pagination. Replaces
|
|
8
|
+
* the old per-rail listers (context discovery, connection-grants,
|
|
9
|
+
* payment-grants).
|
|
10
|
+
*/
|
|
11
|
+
export class GrantsClient {
|
|
12
|
+
operatorKey;
|
|
13
|
+
agentId;
|
|
14
|
+
baseUrl;
|
|
15
|
+
constructor(operatorKey, agentId, baseUrl) {
|
|
16
|
+
if (!operatorKey)
|
|
17
|
+
throw new Error('GrantsClient: operatorKey is required');
|
|
18
|
+
this.operatorKey = operatorKey;
|
|
19
|
+
this.agentId = agentId;
|
|
20
|
+
this.baseUrl = baseUrl || getBackendUrl();
|
|
21
|
+
}
|
|
22
|
+
async listGrants(query = {}) {
|
|
23
|
+
const url = new URL(`${this.baseUrl}/grants`);
|
|
24
|
+
if (query.holderId)
|
|
25
|
+
url.searchParams.set('holderId', query.holderId);
|
|
26
|
+
if (query.scopeKind) {
|
|
27
|
+
const kinds = Array.isArray(query.scopeKind)
|
|
28
|
+
? query.scopeKind
|
|
29
|
+
: [query.scopeKind];
|
|
30
|
+
for (const k of kinds)
|
|
31
|
+
url.searchParams.append('scopeKind', k);
|
|
32
|
+
}
|
|
33
|
+
if (query.health)
|
|
34
|
+
url.searchParams.set('health', query.health);
|
|
35
|
+
if (query.cursor)
|
|
36
|
+
url.searchParams.set('cursor', query.cursor);
|
|
37
|
+
if (query.limit != null)
|
|
38
|
+
url.searchParams.set('limit', String(query.limit));
|
|
39
|
+
const res = await fetch(url.toString(), {
|
|
40
|
+
headers: buildOperatorHeaders(this.operatorKey, this.agentId),
|
|
41
|
+
});
|
|
42
|
+
const body = await res.text().catch(() => '');
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
throw new Error(`GrantsClient.listGrants ${res.status} ${body.slice(0, 200)}`);
|
|
45
|
+
}
|
|
46
|
+
const parsed = JSON.parse(body);
|
|
47
|
+
return {
|
|
48
|
+
items: parsed.items ?? [],
|
|
49
|
+
nextCursor: parsed.nextCursor ?? null,
|
|
50
|
+
hasMore: parsed.hasMore ?? false,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Every grant matching `query`, following the cursor to completion. Use when a
|
|
55
|
+
* caller needs the whole set (reach tagging, catch-up, an owner listing) rather
|
|
56
|
+
* than a single page — `listGrants` returns only one page (server default 30),
|
|
57
|
+
* so a holder with more grants than a page would otherwise be silently
|
|
58
|
+
* truncated. `maxPages` bounds the loop as a runaway guard.
|
|
59
|
+
*/
|
|
60
|
+
async listAllGrants(query = {}, maxPages = 50) {
|
|
61
|
+
const all = [];
|
|
62
|
+
let cursor;
|
|
63
|
+
for (let page = 0; page < maxPages; page++) {
|
|
64
|
+
const res = await this.listGrants({ ...query, cursor });
|
|
65
|
+
all.push(...res.items);
|
|
66
|
+
if (!res.nextCursor)
|
|
67
|
+
return all;
|
|
68
|
+
cursor = res.nextCursor;
|
|
69
|
+
}
|
|
70
|
+
return all;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/http/grants.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export type GrantScopeKind = 'chat' | 'agreement' | 'org' | 'connection' | 'wall
|
|
|
15
15
|
export interface GrantScopeView {
|
|
16
16
|
kind: GrantScopeKind;
|
|
17
17
|
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* Human-readable name for the scoped resource, populated only by the unified
|
|
20
|
+
* list read (GET /grants / GrantsClient); the per-rail issue/delegate
|
|
21
|
+
* responses omit it. Optional so the one shape stays additive.
|
|
22
|
+
*/
|
|
23
|
+
label?: string;
|
|
18
24
|
}
|
|
19
25
|
export interface GrantCaveatView {
|
|
20
26
|
type: string;
|
package/dist/http/index.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ export type { ArtifactVisibility, ListArtifactsOptions, ListArtifactsQuery, List
|
|
|
9
9
|
export { ContextReadClient } from './ContextReadClient.js';
|
|
10
10
|
export type { ContextReadType, ContextReadQuery, ContextReadEnvelope, ContextSnapshotResult, } from './ContextReadClient.js';
|
|
11
11
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
12
|
-
export type {
|
|
12
|
+
export type { DiscoverableItem } from './ContextDiscoveryClient.js';
|
|
13
|
+
export { GrantsClient } from './GrantsClient.js';
|
|
14
|
+
export type { ListGrantsQuery, ListGrantsResult } from './GrantsClient.js';
|
|
13
15
|
export { ContextGrantsClient } from './ContextGrantsClient.js';
|
|
14
16
|
export type { ContextGrantRecord, ContextGrantScope, ContextGrantScopeKind, ContextTemporal, IssueContextGrantInput, DelegateContextGrantInput, } from './ContextGrantsClient.js';
|
|
15
17
|
export { grantCaveat } from './grants.js';
|
package/dist/http/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { MessagesClient } from './MessagesClient.js';
|
|
|
6
6
|
export { ArtifactsClient } from './ArtifactsClient.js';
|
|
7
7
|
export { ContextReadClient } from './ContextReadClient.js';
|
|
8
8
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
9
|
+
export { GrantsClient } from './GrantsClient.js';
|
|
9
10
|
export { ContextGrantsClient } from './ContextGrantsClient.js';
|
|
10
11
|
export { grantCaveat } from './grants.js';
|
|
11
12
|
export { AgentSearchClient } from './AgentSearchClient.js';
|
|
@@ -109,6 +109,15 @@ export class WebSocketClient {
|
|
|
109
109
|
this.socket.on('error', (error) => {
|
|
110
110
|
runtimeLog.error(this.label, `Socket.IO error: ${String(error)}`);
|
|
111
111
|
});
|
|
112
|
+
// ZIG-860: the send path is fire-and-forget (no ack callback), so the
|
|
113
|
+
// backend's structured rejection is the ONLY failure signal. Not listening
|
|
114
|
+
// made every rejected send silent — an agent's message just vanished (the
|
|
115
|
+
// a2a schema bug hid behind exactly this). Log loudly; delivery recovery
|
|
116
|
+
// stays with the inbox/catch-up machinery.
|
|
117
|
+
this.socket.on('chat:error', (payload) => {
|
|
118
|
+
const p = (payload ?? {});
|
|
119
|
+
runtimeLog.error(this.label, `chat:error [${p['code'] ?? 'UNKNOWN'}] chatId=${p['chatId'] ?? '-'} messageId=${p['messageId'] ?? '-'}: ${p['message'] ?? ''}`);
|
|
120
|
+
});
|
|
112
121
|
}
|
|
113
122
|
connectAsync(timeout = 10_000) {
|
|
114
123
|
if (this.socket?.connected)
|