@ziggs-ai/api-client 0.2.0 → 0.3.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.
- package/dist/ConnectionManager.d.ts +14 -4
- package/dist/ConnectionManager.js +14 -10
- package/dist/http/AgreementClient.d.ts +7 -0
- package/dist/http/AgreementClient.js +2 -0
- package/dist/http/ConnectionsClient.d.ts +1 -1
- package/dist/http/ConnectionsClient.js +1 -1
- package/dist/http/ContextDiscoveryClient.d.ts +7 -3
- package/dist/http/ContextReadClient.d.ts +1 -1
- package/dist/http/ContextReadClient.js +1 -1
- package/dist/http/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type InboxOperatorAgentEntry } from './http/InboxClient.js';
|
|
1
2
|
type OpenFn = () => Promise<unknown>;
|
|
2
3
|
type CloseFn = (handle: unknown) => Promise<void>;
|
|
3
4
|
export interface ConnectionManagerMeta {
|
|
@@ -14,13 +15,21 @@ export interface ConnectionManagerOptions {
|
|
|
14
15
|
* this manager lazily starts. `start()` long-polls `GET /inbox/operator` with
|
|
15
16
|
* this key; when an agent's slice shows actionable content, it starts that
|
|
16
17
|
* agent's host (which then consumes via its own per-agent inbox loop). No
|
|
17
|
-
* socket, no
|
|
18
|
+
* socket, no push notification — lazy process management driven by the poll. `wsUrl`
|
|
18
19
|
* is accepted for back-compat but unused (the poll is HTTP).
|
|
19
20
|
*/
|
|
20
21
|
control?: {
|
|
21
22
|
wsUrl?: string;
|
|
22
23
|
operatorKey?: string;
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Gate on the operator-poll lazy start (ZIG-910). Called for each agent
|
|
27
|
+
* slice with actionable content before its host is started; return false to
|
|
28
|
+
* leave the host down this pass. The slice stays in later envelopes (reading
|
|
29
|
+
* never acks), so the gate is consulted again on every poll. Explicit
|
|
30
|
+
* `startAgent()` calls are not gated. Default: everything actionable starts.
|
|
31
|
+
*/
|
|
32
|
+
shouldLazyStart?: (entry: InboxOperatorAgentEntry) => boolean;
|
|
24
33
|
}
|
|
25
34
|
export interface QueryFilter {
|
|
26
35
|
domain?: string;
|
|
@@ -36,8 +45,9 @@ export declare class ConnectionManager {
|
|
|
36
45
|
private _entries;
|
|
37
46
|
private _active;
|
|
38
47
|
private _meta;
|
|
39
|
-
private
|
|
40
|
-
|
|
48
|
+
private _starting;
|
|
49
|
+
private _shouldLazyStart;
|
|
50
|
+
constructor({ maxActive, idleTimeoutMs, control, shouldLazyStart }?: ConnectionManagerOptions);
|
|
41
51
|
register(id: string, openFn: OpenFn, closeFn: CloseFn, meta?: ConnectionManagerMeta): void;
|
|
42
52
|
start(operatorKey?: string): void;
|
|
43
53
|
stop(): Promise<void>;
|
|
@@ -49,7 +59,7 @@ export declare class ConnectionManager {
|
|
|
49
59
|
* the loop never exits until `stop()` (nothing to resynchronize).
|
|
50
60
|
*/
|
|
51
61
|
private _runOperatorPoll;
|
|
52
|
-
|
|
62
|
+
startAgent(id: string): Promise<unknown>;
|
|
53
63
|
sleep(id: string): Promise<void>;
|
|
54
64
|
sleepAll(): Promise<void>;
|
|
55
65
|
touch(id: string): void;
|
|
@@ -15,17 +15,19 @@ export class ConnectionManager {
|
|
|
15
15
|
_entries;
|
|
16
16
|
_active;
|
|
17
17
|
_meta;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
_starting;
|
|
19
|
+
_shouldLazyStart;
|
|
20
|
+
constructor({ maxActive = 50, idleTimeoutMs = 60_000, control, shouldLazyStart } = {}) {
|
|
20
21
|
this.maxActive = maxActive;
|
|
21
22
|
this.idleTimeoutMs = idleTimeoutMs;
|
|
23
|
+
this._shouldLazyStart = shouldLazyStart ?? null;
|
|
22
24
|
this._operatorKey = control?.operatorKey ?? null;
|
|
23
25
|
this._polling = false;
|
|
24
26
|
this._pollDone = null;
|
|
25
27
|
this._entries = new Map();
|
|
26
28
|
this._active = new Map();
|
|
27
29
|
this._meta = new Map();
|
|
28
|
-
this.
|
|
30
|
+
this._starting = new Map();
|
|
29
31
|
}
|
|
30
32
|
register(id, openFn, closeFn, meta) {
|
|
31
33
|
if (!id)
|
|
@@ -74,7 +76,9 @@ export class ConnectionManager {
|
|
|
74
76
|
// it isn't already running and we know how to open it.
|
|
75
77
|
if (!id || this._active.has(id) || !this._entries.has(id))
|
|
76
78
|
continue;
|
|
77
|
-
this.
|
|
79
|
+
if (this._shouldLazyStart && !this._shouldLazyStart(entry))
|
|
80
|
+
continue;
|
|
81
|
+
this.startAgent(id).catch((err) => runtimeLog.warn('ConnectionManager', `lazy-start("${id}") failed: ${err.message}`));
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
catch (err) {
|
|
@@ -88,13 +92,13 @@ export class ConnectionManager {
|
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
|
-
async
|
|
95
|
+
async startAgent(id) {
|
|
92
96
|
const existing = this._active.get(id);
|
|
93
97
|
if (existing) {
|
|
94
98
|
this._resetTimer(id);
|
|
95
99
|
return existing.handle;
|
|
96
100
|
}
|
|
97
|
-
const pending = this.
|
|
101
|
+
const pending = this._starting.get(id);
|
|
98
102
|
if (pending)
|
|
99
103
|
return pending;
|
|
100
104
|
const entry = this._entries.get(id);
|
|
@@ -102,7 +106,7 @@ export class ConnectionManager {
|
|
|
102
106
|
throw new Error(`[ConnectionManager] unknown id: "${id}"`);
|
|
103
107
|
if (this._active.size >= this.maxActive)
|
|
104
108
|
await this._evictLRU();
|
|
105
|
-
const
|
|
109
|
+
const startPromise = (async () => {
|
|
106
110
|
try {
|
|
107
111
|
const handle = await entry.openFn();
|
|
108
112
|
this._active.set(id, { handle, timer: null, lastActive: Date.now() });
|
|
@@ -110,11 +114,11 @@ export class ConnectionManager {
|
|
|
110
114
|
return handle;
|
|
111
115
|
}
|
|
112
116
|
finally {
|
|
113
|
-
this.
|
|
117
|
+
this._starting.delete(id);
|
|
114
118
|
}
|
|
115
119
|
})();
|
|
116
|
-
this.
|
|
117
|
-
return
|
|
120
|
+
this._starting.set(id, startPromise);
|
|
121
|
+
return startPromise;
|
|
118
122
|
}
|
|
119
123
|
async sleep(id) {
|
|
120
124
|
const entry = this._active.get(id);
|
|
@@ -128,6 +128,13 @@ export interface GetMyAgreementsFilters {
|
|
|
128
128
|
engagementKind?: EngagementKind;
|
|
129
129
|
proposalStatus?: string;
|
|
130
130
|
hasTask?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* ZIG-942: `scope=mine` alone returns every agreement the caller's grant can
|
|
133
|
+
* read in the active org — including ones the caller is not a party to
|
|
134
|
+
* (`isYou` all-false). Pass `partyOnly: true` for a true "mine": only
|
|
135
|
+
* agreements where the caller (key owner or impersonated agent) is a party.
|
|
136
|
+
*/
|
|
137
|
+
partyOnly?: boolean;
|
|
131
138
|
}
|
|
132
139
|
export declare function getMyAgreements(filters: GetMyAgreementsFilters | undefined, creds: Creds): Promise<Agreement[]>;
|
|
133
140
|
export declare function getAgreement(agreementId: string, creds: Creds): Promise<Agreement | null>;
|
|
@@ -284,6 +284,8 @@ export async function getMyAgreements(filters = {}, creds) {
|
|
|
284
284
|
url.searchParams.set('proposalStatus', filters.proposalStatus);
|
|
285
285
|
if (filters.hasTask != null)
|
|
286
286
|
url.searchParams.set('hasTask', String(filters.hasTask));
|
|
287
|
+
if (filters.partyOnly)
|
|
288
|
+
url.searchParams.set('partyOnly', 'true');
|
|
287
289
|
let res;
|
|
288
290
|
try {
|
|
289
291
|
res = await fetch(url.toString(), { method: 'GET', headers: buildHeaders(creds) });
|
|
@@ -29,7 +29,7 @@ export interface McpConnectionRequestParams {
|
|
|
29
29
|
/**
|
|
30
30
|
* ZIG-894 — the one connections client for every surface. Consolidates the
|
|
31
31
|
* former agent-sdk private ZiggsConnectClient and ziggs-mcp's inline fetches
|
|
32
|
-
* (
|
|
32
|
+
* (proxy, requestMcpConnection). Proxied provider calls never
|
|
33
33
|
* return the raw OAuth token; every proxy response is additionally scanned by
|
|
34
34
|
* the client-side leak guard before it reaches the caller. Grant *listing*
|
|
35
35
|
* across connections is the unified GET /grants; the per-connection grant
|
|
@@ -23,7 +23,7 @@ export function assertNoLeakedConnectionSecret(serialized) {
|
|
|
23
23
|
/**
|
|
24
24
|
* ZIG-894 — the one connections client for every surface. Consolidates the
|
|
25
25
|
* former agent-sdk private ZiggsConnectClient and ziggs-mcp's inline fetches
|
|
26
|
-
* (
|
|
26
|
+
* (proxy, requestMcpConnection). Proxied provider calls never
|
|
27
27
|
* return the raw OAuth token; every proxy response is additionally scanned by
|
|
28
28
|
* the client-side leak guard before it reaches the caller. Grant *listing*
|
|
29
29
|
* across connections is the unified GET /grants; the per-connection grant
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Labels-only pointer to context the agent could request access to (P4).
|
|
4
|
+
* ZIG-927: covers chats, agreements, and connections; connection labels are the
|
|
5
|
+
* provider name only (never tokens/account labels).
|
|
6
|
+
*/
|
|
3
7
|
export interface DiscoverableItem {
|
|
4
|
-
type: 'chat';
|
|
8
|
+
type: 'chat' | 'agreement' | 'connection';
|
|
5
9
|
label: string;
|
|
6
10
|
scopeRef: {
|
|
7
|
-
kind: 'chat' | 'agreement' | 'org';
|
|
11
|
+
kind: 'chat' | 'agreement' | 'org' | 'connection';
|
|
8
12
|
id: string;
|
|
9
13
|
};
|
|
10
14
|
orgId: string;
|
|
@@ -53,7 +53,7 @@ export declare class ContextReadClient {
|
|
|
53
53
|
/**
|
|
54
54
|
* Aggregated chat snapshot — `GET /context/snapshot?via=chat:<id>`. The
|
|
55
55
|
* server composes history + agreements + roster through the same grant-fenced
|
|
56
|
-
* readers as {@link read}, so hosted agents pull one fenced view per
|
|
56
|
+
* readers as {@link read}, so hosted agents pull one fenced view per poll cycle.
|
|
57
57
|
* Rejects with an `Error & { status }` on non-OK so callers can branch (404).
|
|
58
58
|
*/
|
|
59
59
|
snapshot(chatId: string, opts?: {
|
|
@@ -56,7 +56,7 @@ export class ContextReadClient {
|
|
|
56
56
|
/**
|
|
57
57
|
* Aggregated chat snapshot — `GET /context/snapshot?via=chat:<id>`. The
|
|
58
58
|
* server composes history + agreements + roster through the same grant-fenced
|
|
59
|
-
* readers as {@link read}, so hosted agents pull one fenced view per
|
|
59
|
+
* readers as {@link read}, so hosted agents pull one fenced view per poll cycle.
|
|
60
60
|
* Rejects with an `Error & { status }` on non-OK so callers can branch (404).
|
|
61
61
|
*/
|
|
62
62
|
async snapshot(chatId, opts = {}) {
|
package/dist/http/index.d.ts
CHANGED
|
@@ -25,4 +25,4 @@ export type { ConnectionsError, ConnectionProxyParams, McpConnectionRequestParam
|
|
|
25
25
|
export { AgentSearchClient } from './AgentSearchClient.js';
|
|
26
26
|
export { TelemetryClient } from './TelemetryClient.js';
|
|
27
27
|
export { InboxClient } from './InboxClient.js';
|
|
28
|
-
export type { InboxScopeKind, InboxScopeEntry, InboxProposalRef, InboxConnectionRequestRef, InboxMcpServerRequestRef, InboxHumanAttention, InboxEnvelope, InboxAck, InboxAckResult, } from './InboxClient.js';
|
|
28
|
+
export type { InboxScopeKind, InboxScopeEntry, InboxProposalRef, InboxConnectionRequestRef, InboxMcpServerRequestRef, InboxHumanAttention, InboxEnvelope, InboxAck, InboxAckResult, InboxOperatorAgentEntry, InboxOperatorEnvelope, } from './InboxClient.js';
|