@ziggs-ai/api-client 0.1.6 → 0.1.8
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.
|
@@ -26,9 +26,38 @@ export interface SendChatMessageResult {
|
|
|
26
26
|
messageId: string;
|
|
27
27
|
chatId: string;
|
|
28
28
|
}
|
|
29
|
+
export type ContextTemporal = 'from-now' | 'from-start';
|
|
30
|
+
export interface AddChatMemberInput {
|
|
31
|
+
chatId: string;
|
|
32
|
+
memberId: string;
|
|
33
|
+
memberType: 'user' | 'agent';
|
|
34
|
+
temporal?: ContextTemporal;
|
|
35
|
+
}
|
|
36
|
+
export interface ChatPendingAdmission {
|
|
37
|
+
admissionId: string;
|
|
38
|
+
agentId: string;
|
|
39
|
+
issuerId: string;
|
|
40
|
+
invitedBy: 'user' | 'agent';
|
|
41
|
+
temporal: ContextTemporal;
|
|
42
|
+
status: 'pending' | 'approved' | 'rejected';
|
|
43
|
+
approvals?: unknown[];
|
|
44
|
+
createdAt?: string;
|
|
45
|
+
}
|
|
46
|
+
export type AddChatMemberResult = {
|
|
47
|
+
status: 'pending';
|
|
48
|
+
pendingAdmission: ChatPendingAdmission;
|
|
49
|
+
} | {
|
|
50
|
+
status: 'approved';
|
|
51
|
+
chat?: unknown;
|
|
52
|
+
} | {
|
|
53
|
+
chat?: unknown;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* POST /chats/:chatId/members — add user/agent; agent-invite may return pending admission (ZIG-426).
|
|
57
|
+
*/
|
|
58
|
+
export declare function addChatMember(input: AddChatMemberInput, creds: Creds): Promise<AddChatMemberResult>;
|
|
29
59
|
/**
|
|
30
60
|
* POST /chats/:chatId/messages as an impersonated delegate agent.
|
|
31
|
-
* Requires operator token + X-Agent-Id (ZIG-222).
|
|
32
61
|
*/
|
|
33
62
|
export declare function sendChatMessage(input: SendChatMessageInput, creds: Creds): Promise<SendChatMessageResult>;
|
|
34
63
|
export declare function listMyChats(creds: Creds): Promise<ChatSummary[]>;
|
package/dist/http/ChatClient.js
CHANGED
|
@@ -32,7 +32,6 @@ export async function openConversation(participantId, creds) {
|
|
|
32
32
|
if (!participantId)
|
|
33
33
|
throw new Error('participantId is required for openConversation');
|
|
34
34
|
assertCreds(creds, 'open conversation');
|
|
35
|
-
// Canonical REST: POST /chats with { participantId }, returns { chatId }.
|
|
36
35
|
const res = await fetch(`${getBackendUrl()}/chats`, {
|
|
37
36
|
method: 'POST',
|
|
38
37
|
headers: buildHeaders(creds),
|
|
@@ -48,9 +47,39 @@ export async function openConversation(participantId, creds) {
|
|
|
48
47
|
}
|
|
49
48
|
return { chatId: data['chatId'] };
|
|
50
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* POST /chats/:chatId/members — add user/agent; agent-invite may return pending admission (ZIG-426).
|
|
52
|
+
*/
|
|
53
|
+
export async function addChatMember(input, creds) {
|
|
54
|
+
assertCreds(creds, 'add chat member');
|
|
55
|
+
const res = await fetch(`${getBackendUrl()}/chats/${encodeURIComponent(input.chatId)}/members`, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: buildHeaders(creds),
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
chatId: input.chatId,
|
|
60
|
+
memberId: input.memberId,
|
|
61
|
+
memberType: input.memberType,
|
|
62
|
+
temporal: input.temporal,
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
const body = await res.text().catch(() => '');
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
throwApiError(res, body, `addChatMember failed: ${res.status} ${res.statusText}`);
|
|
68
|
+
}
|
|
69
|
+
const data = JSON.parse(body);
|
|
70
|
+
if (data['status'] === 'pending' && data['pendingAdmission']) {
|
|
71
|
+
return {
|
|
72
|
+
status: 'pending',
|
|
73
|
+
pendingAdmission: data['pendingAdmission'],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (data['status'] === 'approved') {
|
|
77
|
+
return { status: 'approved', chat: data['chat'] };
|
|
78
|
+
}
|
|
79
|
+
return { chat: data['chat'] };
|
|
80
|
+
}
|
|
51
81
|
/**
|
|
52
82
|
* POST /chats/:chatId/messages as an impersonated delegate agent.
|
|
53
|
-
* Requires operator token + X-Agent-Id (ZIG-222).
|
|
54
83
|
*/
|
|
55
84
|
export async function sendChatMessage(input, creds) {
|
|
56
85
|
assertCreds(creds, 'send chat message');
|
|
@@ -84,7 +113,6 @@ export async function sendChatMessage(input, creds) {
|
|
|
84
113
|
export async function listMyChats(creds) {
|
|
85
114
|
assertCreds(creds, 'list my chats');
|
|
86
115
|
try {
|
|
87
|
-
// Canonical REST: GET /chats/mine.
|
|
88
116
|
const res = await fetch(`${getBackendUrl()}/chats/mine`, {
|
|
89
117
|
method: 'GET',
|
|
90
118
|
headers: buildHeaders(creds),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
export type ContextGrantScopeKind = 'chat' | 'agreement' | 'org';
|
|
3
|
+
export type ContextTemporal = 'from-now' | 'from-start';
|
|
4
|
+
export interface ContextGrantScope {
|
|
5
|
+
kind: ContextGrantScopeKind;
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ContextGrantRecord {
|
|
9
|
+
grantId: string;
|
|
10
|
+
issuerId: string;
|
|
11
|
+
holderId: string;
|
|
12
|
+
scopeKind: ContextGrantScopeKind;
|
|
13
|
+
scopeId: string;
|
|
14
|
+
temporal: ContextTemporal;
|
|
15
|
+
watermarkAt: string;
|
|
16
|
+
parentGrantId: string | null;
|
|
17
|
+
expiresAt: string | null;
|
|
18
|
+
revoked: boolean;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface IssueContextGrantInput {
|
|
22
|
+
holderId: string;
|
|
23
|
+
scope: ContextGrantScope;
|
|
24
|
+
temporal?: ContextTemporal;
|
|
25
|
+
expiresAt?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface DelegateContextGrantInput {
|
|
28
|
+
holderId: string;
|
|
29
|
+
scope: ContextGrantScope;
|
|
30
|
+
temporal: ContextTemporal;
|
|
31
|
+
expiresAt?: string | null;
|
|
32
|
+
watermarkAt?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* ZIG-411 context grant management — list / issue / delegate / revoke.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ContextGrantsClient {
|
|
38
|
+
private readonly operatorKey;
|
|
39
|
+
private readonly agentId;
|
|
40
|
+
private readonly baseUrl;
|
|
41
|
+
constructor(operatorKey: string, agentId: string, baseUrl?: string);
|
|
42
|
+
listGrants(holderId?: string): Promise<ContextGrantRecord[]>;
|
|
43
|
+
issueGrant(input: IssueContextGrantInput): Promise<ContextGrantRecord>;
|
|
44
|
+
delegateGrant(parentGrantId: string, input: DelegateContextGrantInput): Promise<ContextGrantRecord>;
|
|
45
|
+
revokeGrant(grantId: string): Promise<{
|
|
46
|
+
status: string;
|
|
47
|
+
revokedCount?: number;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
|
+
import { ApiError } from '../types.js';
|
|
4
|
+
function buildHeaders(creds) {
|
|
5
|
+
return {
|
|
6
|
+
'content-type': 'application/json',
|
|
7
|
+
Authorization: `Bearer ${creds.operatorKey}`,
|
|
8
|
+
'X-Agent-Id': creds.agentId,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function assertCreds(creds, op) {
|
|
12
|
+
if (!creds?.operatorKey)
|
|
13
|
+
throw new Error(`operatorKey is required for ${op}`);
|
|
14
|
+
if (!creds?.agentId)
|
|
15
|
+
throw new Error(`agentId is required for ${op}`);
|
|
16
|
+
}
|
|
17
|
+
function throwApiError(response, responseBody, defaultMessage) {
|
|
18
|
+
let message = defaultMessage;
|
|
19
|
+
if (responseBody) {
|
|
20
|
+
try {
|
|
21
|
+
const d = JSON.parse(responseBody);
|
|
22
|
+
message =
|
|
23
|
+
d['details'] ||
|
|
24
|
+
d['error'] ||
|
|
25
|
+
d['message'] ||
|
|
26
|
+
defaultMessage;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
message = responseBody || defaultMessage;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new ApiError(message, response.status, responseBody);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* ZIG-411 context grant management — list / issue / delegate / revoke.
|
|
36
|
+
*/
|
|
37
|
+
export class ContextGrantsClient {
|
|
38
|
+
operatorKey;
|
|
39
|
+
agentId;
|
|
40
|
+
baseUrl;
|
|
41
|
+
constructor(operatorKey, agentId, baseUrl) {
|
|
42
|
+
if (!operatorKey) {
|
|
43
|
+
throw new Error('ContextGrantsClient: operatorKey is required');
|
|
44
|
+
}
|
|
45
|
+
if (!agentId) {
|
|
46
|
+
throw new Error('ContextGrantsClient: agentId is required (operator-token impersonation)');
|
|
47
|
+
}
|
|
48
|
+
this.operatorKey = operatorKey;
|
|
49
|
+
this.agentId = agentId;
|
|
50
|
+
this.baseUrl = baseUrl || getBackendUrl();
|
|
51
|
+
}
|
|
52
|
+
async listGrants(holderId) {
|
|
53
|
+
assertCreds({ operatorKey: this.operatorKey, agentId: this.agentId }, 'listGrants');
|
|
54
|
+
const qs = holderId
|
|
55
|
+
? `?${new URLSearchParams({ holderId }).toString()}`
|
|
56
|
+
: '';
|
|
57
|
+
const res = await fetch(`${this.baseUrl}/context/grants${qs}`, {
|
|
58
|
+
headers: buildHeaders({
|
|
59
|
+
operatorKey: this.operatorKey,
|
|
60
|
+
agentId: this.agentId,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
const body = await res.text().catch(() => '');
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
throwApiError(res, body, `listGrants failed: ${res.status} ${res.statusText}`);
|
|
66
|
+
}
|
|
67
|
+
const parsed = JSON.parse(body);
|
|
68
|
+
return parsed.grants ?? [];
|
|
69
|
+
}
|
|
70
|
+
async issueGrant(input) {
|
|
71
|
+
assertCreds({ operatorKey: this.operatorKey, agentId: this.agentId }, 'issueGrant');
|
|
72
|
+
const res = await fetch(`${this.baseUrl}/context/grants`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: buildHeaders({
|
|
75
|
+
operatorKey: this.operatorKey,
|
|
76
|
+
agentId: this.agentId,
|
|
77
|
+
}),
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
holderId: input.holderId,
|
|
80
|
+
scope: input.scope,
|
|
81
|
+
temporal: input.temporal,
|
|
82
|
+
expiresAt: input.expiresAt,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
const body = await res.text().catch(() => '');
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
throwApiError(res, body, `issueGrant failed: ${res.status} ${res.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
const parsed = JSON.parse(body);
|
|
90
|
+
if (!parsed.grant?.grantId) {
|
|
91
|
+
throw new Error('Invalid response: expected { grant } from POST /context/grants');
|
|
92
|
+
}
|
|
93
|
+
return parsed.grant;
|
|
94
|
+
}
|
|
95
|
+
async delegateGrant(parentGrantId, input) {
|
|
96
|
+
assertCreds({ operatorKey: this.operatorKey, agentId: this.agentId }, 'delegateGrant');
|
|
97
|
+
const res = await fetch(`${this.baseUrl}/context/grants/${encodeURIComponent(parentGrantId)}/delegate`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: buildHeaders({
|
|
100
|
+
operatorKey: this.operatorKey,
|
|
101
|
+
agentId: this.agentId,
|
|
102
|
+
}),
|
|
103
|
+
body: JSON.stringify(input),
|
|
104
|
+
});
|
|
105
|
+
const body = await res.text().catch(() => '');
|
|
106
|
+
if (!res.ok) {
|
|
107
|
+
throwApiError(res, body, `delegateGrant failed: ${res.status} ${res.statusText}`);
|
|
108
|
+
}
|
|
109
|
+
const parsed = JSON.parse(body);
|
|
110
|
+
if (!parsed.grant?.grantId) {
|
|
111
|
+
throw new Error('Invalid response: expected { grant } from POST /context/grants/:id/delegate');
|
|
112
|
+
}
|
|
113
|
+
return parsed.grant;
|
|
114
|
+
}
|
|
115
|
+
async revokeGrant(grantId) {
|
|
116
|
+
assertCreds({ operatorKey: this.operatorKey, agentId: this.agentId }, 'revokeGrant');
|
|
117
|
+
const res = await fetch(`${this.baseUrl}/context/grants/${encodeURIComponent(grantId)}`, {
|
|
118
|
+
method: 'DELETE',
|
|
119
|
+
headers: buildHeaders({
|
|
120
|
+
operatorKey: this.operatorKey,
|
|
121
|
+
agentId: this.agentId,
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
const body = await res.text().catch(() => '');
|
|
125
|
+
if (!res.ok) {
|
|
126
|
+
throwApiError(res, body, `revokeGrant failed: ${res.status} ${res.statusText}`);
|
|
127
|
+
}
|
|
128
|
+
return JSON.parse(body);
|
|
129
|
+
}
|
|
130
|
+
}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -12,5 +12,7 @@ export { ContextReadClient } from './ContextReadClient.js';
|
|
|
12
12
|
export type { ContextReadType, ContextReadQuery, ContextReadEnvelope, } from './ContextReadClient.js';
|
|
13
13
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
14
14
|
export type { ContextReachDescriptor } from './ContextDiscoveryClient.js';
|
|
15
|
+
export { ContextGrantsClient } from './ContextGrantsClient.js';
|
|
16
|
+
export type { ContextGrantRecord, ContextGrantScope, ContextGrantScopeKind, ContextTemporal, IssueContextGrantInput, DelegateContextGrantInput, } from './ContextGrantsClient.js';
|
|
15
17
|
export { AgentSearchClient } from './AgentSearchClient.js';
|
|
16
18
|
export { TelemetryClient } from './TelemetryClient.js';
|
package/dist/http/index.js
CHANGED
|
@@ -7,5 +7,6 @@ export { ArtifactsClient } from './ArtifactsClient.js';
|
|
|
7
7
|
export { ScopeClient } from './ScopeClient.js';
|
|
8
8
|
export { ContextReadClient } from './ContextReadClient.js';
|
|
9
9
|
export { ContextDiscoveryClient } from './ContextDiscoveryClient.js';
|
|
10
|
+
export { ContextGrantsClient } from './ContextGrantsClient.js';
|
|
10
11
|
export { AgentSearchClient } from './AgentSearchClient.js';
|
|
11
12
|
export { TelemetryClient } from './TelemetryClient.js';
|