@ziggs-ai/api-client 0.37.28 → 0.38.2
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/CHANGELOG.md +19 -0
- package/dist/capabilities/agreements.js +2 -2
- package/dist/capabilities/artifacts.d.ts +6 -0
- package/dist/capabilities/artifacts.js +52 -9
- package/dist/capabilities/connections.js +3 -8
- package/dist/capabilities/context.js +28 -6
- package/dist/capabilities/grants.js +1 -4
- package/dist/capabilities/index.d.ts +2 -2
- package/dist/capabilities/index.js +2 -2
- package/dist/capabilities/introductions.d.ts +1 -0
- package/dist/capabilities/introductions.js +63 -8
- package/dist/capabilities/links.js +33 -11
- package/dist/capabilities/mcpBriefs.js +20 -7
- package/dist/capabilities/payments.js +2 -7
- package/dist/capabilities/tasks.d.ts +1 -0
- package/dist/capabilities/tasks.js +42 -1
- package/dist/http/AgreementClient.d.ts +19 -2
- package/dist/http/AgreementClient.js +6 -4
- package/dist/http/ArtifactsClient.d.ts +16 -9
- package/dist/http/ArtifactsClient.js +16 -11
- package/dist/http/AssistantConnectionClient.d.ts +1 -1
- package/dist/http/AssistantConnectionClient.js +2 -2
- package/dist/http/ConnectionsClient.d.ts +2 -12
- package/dist/http/ConnectionsClient.js +4 -15
- package/dist/http/ContextGrantsClient.d.ts +2 -0
- package/dist/http/ContextGrantsClient.js +1 -1
- package/dist/http/ContextOpenClient.d.ts +2 -3
- package/dist/http/ContextOpenClient.js +2 -4
- package/dist/http/ContextReadClient.d.ts +5 -13
- package/dist/http/ContextReadClient.js +4 -19
- package/dist/http/ExecutionContextClient.d.ts +3 -0
- package/dist/http/ExecutionContextClient.js +17 -0
- package/dist/http/GrantsClient.d.ts +2 -10
- package/dist/http/GrantsClient.js +3 -12
- package/dist/http/InboxClient.d.ts +2 -2
- package/dist/http/InboxClient.js +1 -3
- package/dist/http/IntroductionsClient.d.ts +28 -1
- package/dist/http/IntroductionsClient.js +6 -2
- package/dist/http/PaymentsClient.d.ts +2 -15
- package/dist/http/PaymentsClient.js +4 -18
- package/dist/http/TaskClient.d.ts +24 -1
- package/dist/http/TaskClient.js +27 -2
- package/dist/http/TelemetryClient.js +3 -3
- package/dist/http/ToolPickClient.js +2 -2
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +1 -1
- package/dist/http/operatorHeaders.d.ts +14 -36
- package/dist/http/operatorHeaders.js +26 -50
- package/dist/inboxAck.d.ts +14 -46
- package/dist/inboxAck.js +12 -102
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/types.d.ts +25 -16
- package/package.json +2 -2
|
@@ -49,7 +49,7 @@ export declare class InboxClient {
|
|
|
49
49
|
* refused.
|
|
50
50
|
*/
|
|
51
51
|
ack(upTo: string, opts?: {
|
|
52
|
-
|
|
52
|
+
handledDeliveryIds?: string[];
|
|
53
53
|
}): Promise<InboxAckResult>;
|
|
54
54
|
/** The person said to leave this proposal pending. Does not approve or reject. */
|
|
55
55
|
park(agreementId: string): Promise<{
|
|
@@ -62,7 +62,7 @@ export declare class InboxClient {
|
|
|
62
62
|
* A second host-conflict is a live competitor and is rethrown unchanged.
|
|
63
63
|
*/
|
|
64
64
|
ackOrTakeHost(upTo: string, opts?: {
|
|
65
|
-
|
|
65
|
+
handledDeliveryIds?: string[];
|
|
66
66
|
}): Promise<InboxAckResult>;
|
|
67
67
|
/**
|
|
68
68
|
* Drop this process's inbox host lease so another client can take
|
package/dist/http/InboxClient.js
CHANGED
|
@@ -119,9 +119,7 @@ export class InboxClient {
|
|
|
119
119
|
headers: this.headers(),
|
|
120
120
|
body: JSON.stringify({
|
|
121
121
|
upTo,
|
|
122
|
-
...(opts.
|
|
123
|
-
? { handledResourceIds: opts.handledResourceIds }
|
|
124
|
-
: {}),
|
|
122
|
+
...(opts.handledDeliveryIds ? { handledDeliveryIds: opts.handledDeliveryIds } : {}),
|
|
125
123
|
}),
|
|
126
124
|
});
|
|
127
125
|
const body = await res.text().catch(() => '');
|
|
@@ -44,11 +44,21 @@ export interface IntroductionView {
|
|
|
44
44
|
allowed: number;
|
|
45
45
|
left: number;
|
|
46
46
|
};
|
|
47
|
+
/** Ziggs emailed it, and only the person signed in with that address redeems it. */
|
|
48
|
+
addressed?: boolean;
|
|
47
49
|
agreementId: string | null;
|
|
48
50
|
redeemedBy: {
|
|
49
51
|
agentId: string | null;
|
|
50
52
|
orgId: string | null;
|
|
51
53
|
} | null;
|
|
54
|
+
/** The minter's list only: each redeemer and where they ended. */
|
|
55
|
+
redemptions?: Array<{
|
|
56
|
+
agentId: string | null;
|
|
57
|
+
orgId: string | null;
|
|
58
|
+
outcome: IntroductionOutcome;
|
|
59
|
+
agreementId: string | null;
|
|
60
|
+
at: string;
|
|
61
|
+
}>;
|
|
52
62
|
/** Returned to a redeemer only: the room its agent is now in. */
|
|
53
63
|
chatId?: string | null;
|
|
54
64
|
expiresAt: string;
|
|
@@ -77,6 +87,17 @@ export interface MintIntroductionInput {
|
|
|
77
87
|
venue?: string;
|
|
78
88
|
venueRef?: string;
|
|
79
89
|
note?: string;
|
|
90
|
+
/** What the token is about: a listing, request or proposal (agreement), a task, or a chat you hold. */
|
|
91
|
+
about?: {
|
|
92
|
+
kind: 'agreement' | 'task' | 'chat' | 'workspace';
|
|
93
|
+
id: string;
|
|
94
|
+
};
|
|
95
|
+
/** How many people it serves, 1 to 25. Your own sessions never use one up. */
|
|
96
|
+
redeems?: number;
|
|
97
|
+
/** A workspace string: the email it is for. Only that person redeems it. */
|
|
98
|
+
email?: string;
|
|
99
|
+
/** A workspace string: the role it gives (default member). */
|
|
100
|
+
role?: 'owner' | 'admin' | 'member';
|
|
80
101
|
/** What this text drew on. See {@link WriteSource}. */
|
|
81
102
|
sources?: WriteSource[];
|
|
82
103
|
}
|
|
@@ -93,7 +114,13 @@ export declare class IntroductionsClient {
|
|
|
93
114
|
private readonly baseUrl;
|
|
94
115
|
constructor(operatorKey: string, agentId?: string, baseUrl?: string);
|
|
95
116
|
mint(input?: MintIntroductionInput): Promise<IntroductionView>;
|
|
96
|
-
|
|
117
|
+
/**
|
|
118
|
+
* A workspace string joins only with `confirm: true`, which is the person's
|
|
119
|
+
* yes: without it the answer names the workspace and asks for that yes.
|
|
120
|
+
*/
|
|
121
|
+
redeem(token: string, opts?: {
|
|
122
|
+
confirm?: boolean;
|
|
123
|
+
}): Promise<IntroductionView>;
|
|
97
124
|
decline(token: string): Promise<IntroductionView>;
|
|
98
125
|
revoke(token: string): Promise<IntroductionView>;
|
|
99
126
|
listMine(limit?: number): Promise<IntroductionView[]>;
|
|
@@ -23,8 +23,12 @@ export class IntroductionsClient {
|
|
|
23
23
|
async mint(input = {}) {
|
|
24
24
|
return this.call('POST', '/introductions', input, 'mint');
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* A workspace string joins only with `confirm: true`, which is the person's
|
|
28
|
+
* yes: without it the answer names the workspace and asks for that yes.
|
|
29
|
+
*/
|
|
30
|
+
async redeem(token, opts = {}) {
|
|
31
|
+
return this.call('POST', `/introductions/${encodeURIComponent(token)}/redeem`, opts.confirm ? { confirm: true } : {}, 'redeem');
|
|
28
32
|
}
|
|
29
33
|
async decline(token) {
|
|
30
34
|
return this.call('POST', `/introductions/${encodeURIComponent(token)}/decline`, {}, 'decline');
|
|
@@ -61,21 +61,8 @@ export declare class PaymentsClient {
|
|
|
61
61
|
private readonly operatorKey;
|
|
62
62
|
private readonly agentId?;
|
|
63
63
|
private readonly baseUrl;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param laneId the wake's lane (a chat id, or `agrn-<agreementId>`), sent as
|
|
67
|
-
* X-Ziggs-Lane. It tells the backend which hire this wake is in, and the
|
|
68
|
-
* backend reads off it WHO the spend is for. An agent that serves several
|
|
69
|
-
* hirers holds all of their grants at once and the holder is the same agent
|
|
70
|
-
* in every one, so without a lane, spend authority one customer gave is
|
|
71
|
-
* spendable while the agent works for another. ConnectionsClient and
|
|
72
|
-
* ArtifactsClient send the same header for the same reason.
|
|
73
|
-
*
|
|
74
|
-
* Omitting it cannot widen anything — a stated lane can only cause a
|
|
75
|
-
* refusal — but it does leave the spend unfenced, so a caller that knows
|
|
76
|
-
* its lane should pass it.
|
|
77
|
-
*/
|
|
78
|
-
constructor(operatorKey: string, agentId?: string, baseUrl?: string, laneId?: string);
|
|
64
|
+
/** Authority is supplied by withWorkExecution / withWorkExecutionId. */
|
|
65
|
+
constructor(operatorKey: string, agentId?: string, baseUrl?: string);
|
|
79
66
|
balance(): Promise<WalletBalance>;
|
|
80
67
|
resolve({ userId, agentId }?: {
|
|
81
68
|
userId?: string;
|
|
@@ -22,27 +22,13 @@ export class PaymentsClient {
|
|
|
22
22
|
operatorKey;
|
|
23
23
|
agentId;
|
|
24
24
|
baseUrl;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @param laneId the wake's lane (a chat id, or `agrn-<agreementId>`), sent as
|
|
28
|
-
* X-Ziggs-Lane. It tells the backend which hire this wake is in, and the
|
|
29
|
-
* backend reads off it WHO the spend is for. An agent that serves several
|
|
30
|
-
* hirers holds all of their grants at once and the holder is the same agent
|
|
31
|
-
* in every one, so without a lane, spend authority one customer gave is
|
|
32
|
-
* spendable while the agent works for another. ConnectionsClient and
|
|
33
|
-
* ArtifactsClient send the same header for the same reason.
|
|
34
|
-
*
|
|
35
|
-
* Omitting it cannot widen anything — a stated lane can only cause a
|
|
36
|
-
* refusal — but it does leave the spend unfenced, so a caller that knows
|
|
37
|
-
* its lane should pass it.
|
|
38
|
-
*/
|
|
39
|
-
constructor(operatorKey, agentId, baseUrl, laneId) {
|
|
25
|
+
/** Authority is supplied by withWorkExecution / withWorkExecutionId. */
|
|
26
|
+
constructor(operatorKey, agentId, baseUrl) {
|
|
40
27
|
if (!operatorKey)
|
|
41
28
|
throw new Error('PaymentsClient: operatorKey is required');
|
|
42
29
|
this.operatorKey = operatorKey;
|
|
43
30
|
this.agentId = agentId;
|
|
44
31
|
this.baseUrl = baseUrl || getBackendUrl();
|
|
45
|
-
this.laneId = laneId;
|
|
46
32
|
}
|
|
47
33
|
async balance() {
|
|
48
34
|
const w = (await this._get('/payments/wallet'));
|
|
@@ -87,7 +73,7 @@ export class PaymentsClient {
|
|
|
87
73
|
* (retired GET /payments/grants), following the cursor to completion.
|
|
88
74
|
*/
|
|
89
75
|
async listGrants() {
|
|
90
|
-
const grants = new GrantsClient(this.operatorKey, this.agentId, this.baseUrl
|
|
76
|
+
const grants = new GrantsClient(this.operatorKey, this.agentId, this.baseUrl);
|
|
91
77
|
return grants.listAllGrants({ scopeKind: 'wallet', health: 'active' });
|
|
92
78
|
}
|
|
93
79
|
async faucet({ amount, description = 'Faucet', idempotencyKey, } = {}) {
|
|
@@ -100,7 +86,7 @@ export class PaymentsClient {
|
|
|
100
86
|
async _request(method, path, body) {
|
|
101
87
|
const init = {
|
|
102
88
|
method,
|
|
103
|
-
headers: buildOperatorHeaders(this.operatorKey, this.agentId, body !== undefined ? { 'content-type': 'application/json' } : {}
|
|
89
|
+
headers: buildOperatorHeaders(this.operatorKey, this.agentId, body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
104
90
|
};
|
|
105
91
|
if (body !== undefined)
|
|
106
92
|
init.body = JSON.stringify(body);
|
|
@@ -84,7 +84,7 @@ export interface CreateTaskData {
|
|
|
84
84
|
* server-side.
|
|
85
85
|
*/
|
|
86
86
|
assigneeId?: string;
|
|
87
|
-
/**
|
|
87
|
+
/** Required artifact handles; declaring them grants no access. */
|
|
88
88
|
inputArtifactIds?: string[];
|
|
89
89
|
/**
|
|
90
90
|
* Tasks this one waits for. The task is created immediately, but its assignee
|
|
@@ -250,3 +250,26 @@ export declare class TaskClient {
|
|
|
250
250
|
listTasks(options?: ListTasksOptions): Promise<ListTasksResult>;
|
|
251
251
|
countTasks(filters?: CountTasksFilters): Promise<number>;
|
|
252
252
|
}
|
|
253
|
+
/** Controlled work transfer; the source execution header is preserved. */
|
|
254
|
+
export declare function delegateTask(taskId: string, body: {
|
|
255
|
+
agreementId: string;
|
|
256
|
+
assigneeId: string;
|
|
257
|
+
instructionArtifactId: string;
|
|
258
|
+
inputArtifactIds?: string[];
|
|
259
|
+
idempotencyKey?: string;
|
|
260
|
+
}, creds: Creds): Promise<{
|
|
261
|
+
taskId: string;
|
|
262
|
+
agreementId: string;
|
|
263
|
+
parentTaskId: string;
|
|
264
|
+
}>;
|
|
265
|
+
export declare function returnTaskResult(taskId: string, artifactId: string, creds: Creds): Promise<{
|
|
266
|
+
taskId: string;
|
|
267
|
+
parentTaskId: string;
|
|
268
|
+
artifactId: string;
|
|
269
|
+
outcome: 'created' | 'existing';
|
|
270
|
+
}>;
|
|
271
|
+
export declare function refreshTaskReadiness(taskId: string, creds: Creds): Promise<{
|
|
272
|
+
taskId: string;
|
|
273
|
+
ready: boolean;
|
|
274
|
+
state: string;
|
|
275
|
+
}>;
|
package/dist/http/TaskClient.js
CHANGED
|
@@ -2,7 +2,7 @@ import { decodeOperatorKeyClaims } from '../shared/operatorKey.js';
|
|
|
2
2
|
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
3
|
import { partyActorIds } from '../types.js';
|
|
4
4
|
import { throwApiError } from '../shared/apiError.js';
|
|
5
|
-
import { buildCredsHeaders } from './operatorHeaders.js';
|
|
5
|
+
import { buildCredsHeaders, withoutExecution } from './operatorHeaders.js';
|
|
6
6
|
function getTaskBaseUrl() { return `${getBackendUrl()}/tasks`; }
|
|
7
7
|
// Auth, agent and the wake's lane, from the one helper — see operatorHeaders.
|
|
8
8
|
const buildHeaders = buildCredsHeaders;
|
|
@@ -38,7 +38,9 @@ async function writeTaskControl(taskId, path, method, body, creds) {
|
|
|
38
38
|
throw new Error('Task control requires a taskId');
|
|
39
39
|
assertCreds(creds, 'task control');
|
|
40
40
|
const res = await fetch(`${getTaskBaseUrl()}/${encodeURIComponent(taskId)}/${path}`, {
|
|
41
|
-
|
|
41
|
+
// A quiescence receipt must remain possible after the task execution has
|
|
42
|
+
// been stopped. The server still checks executor identity and requestId.
|
|
43
|
+
method, headers: path === 'control/ack' ? withoutExecution(buildHeaders(creds)) : buildHeaders(creds), body: JSON.stringify(body),
|
|
42
44
|
});
|
|
43
45
|
if (!res.ok)
|
|
44
46
|
throwApiError(res, await res.text().catch(() => ''), `Task control failed: ${res.status}`);
|
|
@@ -498,3 +500,26 @@ export class TaskClient {
|
|
|
498
500
|
listTasks(options) { return listTasks(options ?? {}, this.creds); }
|
|
499
501
|
countTasks(filters) { return countTasks(filters, this.creds); }
|
|
500
502
|
}
|
|
503
|
+
/** Controlled work transfer; the source execution header is preserved. */
|
|
504
|
+
export async function delegateTask(taskId, body, creds) {
|
|
505
|
+
const { idempotencyKey, ...payload } = body;
|
|
506
|
+
return taskTransfer(taskId, 'delegations', payload, creds, idempotencyKey);
|
|
507
|
+
}
|
|
508
|
+
export async function returnTaskResult(taskId, artifactId, creds) {
|
|
509
|
+
return taskTransfer(taskId, 'return', { artifactId }, creds);
|
|
510
|
+
}
|
|
511
|
+
export async function refreshTaskReadiness(taskId, creds) {
|
|
512
|
+
return taskTransfer(taskId, 'readiness', {}, creds);
|
|
513
|
+
}
|
|
514
|
+
async function taskTransfer(taskId, path, body, creds, key) {
|
|
515
|
+
assertCreds(creds, 'task transfer');
|
|
516
|
+
if (!taskId)
|
|
517
|
+
throw new Error('taskId is required');
|
|
518
|
+
const headers = buildHeaders(creds);
|
|
519
|
+
if (key)
|
|
520
|
+
headers['Idempotency-Key'] = key;
|
|
521
|
+
const res = await fetch(`${getTaskBaseUrl()}/${encodeURIComponent(taskId)}/${path}`, { method: 'POST', headers, body: JSON.stringify(body) });
|
|
522
|
+
if (!res.ok)
|
|
523
|
+
throwApiError(res, await res.text().catch(() => ''), `Task transfer failed: ${res.status}`);
|
|
524
|
+
return res.json();
|
|
525
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
2
2
|
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
|
-
import { buildOperatorHeaders } from './operatorHeaders.js';
|
|
3
|
+
import { buildOperatorHeaders, withoutExecution } from './operatorHeaders.js';
|
|
4
4
|
export class TelemetryClient {
|
|
5
5
|
operatorKey;
|
|
6
6
|
agentId;
|
|
@@ -36,9 +36,9 @@ export class TelemetryClient {
|
|
|
36
36
|
try {
|
|
37
37
|
const res = await fetch(url, {
|
|
38
38
|
method: 'POST',
|
|
39
|
-
headers: buildOperatorHeaders(this.operatorKey, this.agentId, {
|
|
39
|
+
headers: withoutExecution(buildOperatorHeaders(this.operatorKey, this.agentId, {
|
|
40
40
|
'content-type': 'application/json',
|
|
41
|
-
}),
|
|
41
|
+
})),
|
|
42
42
|
body: JSON.stringify({ payload }),
|
|
43
43
|
});
|
|
44
44
|
if (!res.ok) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildCredsHeaders } from './operatorHeaders.js';
|
|
1
|
+
import { buildCredsHeaders, withoutExecution } from './operatorHeaders.js';
|
|
2
2
|
import { getBackendUrl } from '../utils/urlUtils.js';
|
|
3
3
|
/** A listing is always the fallback, so waiting long for a pick buys nothing. */
|
|
4
4
|
const TIMEOUT_MS = 6000;
|
|
@@ -15,7 +15,7 @@ export function backendToolPick(creds) {
|
|
|
15
15
|
try {
|
|
16
16
|
const res = await fetch(`${getBackendUrl()}/internal/tool-pick`, {
|
|
17
17
|
method: 'POST',
|
|
18
|
-
headers: buildCredsHeaders(creds),
|
|
18
|
+
headers: withoutExecution(buildCredsHeaders(creds)),
|
|
19
19
|
body: JSON.stringify({ need, options }),
|
|
20
20
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
21
21
|
});
|
package/dist/http/index.d.ts
CHANGED
|
@@ -35,5 +35,5 @@ export { SessionsClient } from './SessionsClient.js';
|
|
|
35
35
|
export type { AssistantSessionRow } from './SessionsClient.js';
|
|
36
36
|
export { planInboxAck, planPartialInboxAck, inboxAckAllowed, inboxAckHandledIds, } from '../inboxAck.js';
|
|
37
37
|
export type { InboxAckDecision, InboxAckStep, InboxAckEnvelope, PlanInboxAckOptions, } from '../inboxAck.js';
|
|
38
|
-
export {
|
|
38
|
+
export { laneUnderAgreement, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
|
|
39
39
|
export { backendToolPick, type ToolPickOption, type ToolPickAnswer, type PickTool } from './ToolPickClient.js';
|
package/dist/http/index.js
CHANGED
|
@@ -26,5 +26,5 @@ export { planInboxAck, planPartialInboxAck, inboxAckAllowed, inboxAckHandledIds,
|
|
|
26
26
|
// The lane header, built in one place — see operatorHeaders.ts. Exported
|
|
27
27
|
// because the MCP transports in agent-sdk and ziggs-mcp send it too, and a
|
|
28
28
|
// copy of a header nobody notices missing goes stale unseen.
|
|
29
|
-
export {
|
|
29
|
+
export { laneUnderAgreement, buildOperatorHeaders, buildCredsHeaders, } from './operatorHeaders.js';
|
|
30
30
|
export { backendToolPick } from './ToolPickClient.js';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { WorkExecutionContext } from '@ziggs-ai/contracts';
|
|
1
2
|
type AssistantHints = {
|
|
3
|
+
executionContext?: WorkExecutionContext;
|
|
4
|
+
executionContextId?: string;
|
|
2
5
|
orgId?: string;
|
|
3
6
|
resource?: string;
|
|
4
7
|
clientSessionId?: string;
|
|
@@ -10,49 +13,24 @@ type AssistantHints = {
|
|
|
10
13
|
/** Node-only, opt-in request context. Ordinary HTTP clients remain browser-safe. */
|
|
11
14
|
export declare function withAssistantRequest<T>(hints: AssistantHints, run: () => T): Promise<Awaited<T>>;
|
|
12
15
|
export declare function assistantRequestHeaders(): Record<string, string>;
|
|
13
|
-
/**
|
|
14
|
-
* Auth headers for operator-key HTTP clients.
|
|
15
|
-
*
|
|
16
|
-
* ONE place builds them, because the lane is the header a caller cannot be
|
|
17
|
-
* trusted to remember. Omitting `X-Ziggs-Lane` never fails: the server fences
|
|
18
|
-
* the wake to the agent's own org instead, so a door that forgets it answers
|
|
19
|
-
* short lists and refuses grants the agent's customer gave it — silently, and
|
|
20
|
-
* only for the agents that serve someone other than their owner. A header
|
|
21
|
-
* whose absence is indistinguishable from a legitimate answer has to be built
|
|
22
|
-
* in one place, not copied into each caller.
|
|
23
|
-
*/
|
|
24
|
-
/** The header the backend's wake fence reads (`access/wake-fence.ts`). */
|
|
25
|
-
export declare const WAKE_LANE_HEADER = "X-Ziggs-Lane";
|
|
26
|
-
/**
|
|
27
|
-
* The header naming the agreement a room wake works under. The backend takes
|
|
28
|
-
* it only for an agreement the agent has mail under in that room, and reads
|
|
29
|
-
* it off that mail when it is absent.
|
|
30
|
-
*/
|
|
31
|
-
export declare const WAKE_AGREEMENT_HEADER = "X-Ziggs-Agreement";
|
|
32
|
-
/**
|
|
33
|
-
* A room lane that also names the agreement the wake works under:
|
|
34
|
-
* `<chatId>@<agreementId>`. Every client already carries the lane to
|
|
35
|
-
* {@link laneHeader}, so the agreement travels with it without a second
|
|
36
|
-
* parameter on each of them. An `agrn-` lane already is its agreement.
|
|
37
|
-
*/
|
|
16
|
+
/** A presentation routing key; it carries no authority. */
|
|
38
17
|
export declare function laneUnderAgreement(laneId: string, agreementId?: string | null): string;
|
|
18
|
+
export declare function buildOperatorHeaders(operatorKey: string, agentId?: string, extra?: Record<string, string>): Record<string, string>;
|
|
39
19
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*/
|
|
44
|
-
export declare function laneHeader(laneId?: string): Record<string, string>;
|
|
45
|
-
export declare function buildOperatorHeaders(operatorKey: string, agentId?: string, extra?: Record<string, string>,
|
|
46
|
-
/**
|
|
47
|
-
* the lane this call belongs to, sent as `X-Ziggs-Lane`. The
|
|
48
|
-
* backend narrows the wake's reach to the engagement's orgs; omitting it
|
|
49
|
-
* narrows to the agent's own org, so it can never widen reach.
|
|
20
|
+
* The host's own calls (wake gate, telemetry, tool picker) are not work
|
|
21
|
+
* actions: they never carry the selected execution, so they neither need a
|
|
22
|
+
* route that supports one nor record anything into it.
|
|
50
23
|
*/
|
|
51
|
-
|
|
24
|
+
export declare function withoutExecution(headers: Record<string, string>): Record<string, string>;
|
|
52
25
|
/** What a `Creds`-shaped client sends on a JSON call: auth, agent, lane. */
|
|
53
26
|
export declare function buildCredsHeaders(creds: {
|
|
54
27
|
operatorKey: string;
|
|
55
28
|
agentId: string;
|
|
56
29
|
laneId?: string;
|
|
30
|
+
executionContextId?: string;
|
|
57
31
|
}): Record<string, string>;
|
|
32
|
+
/** Async-local scope: parallel agreement positions never share request headers. */
|
|
33
|
+
export declare function withWorkExecution<T>(executionContext: WorkExecutionContext | undefined, run: () => T): Promise<Awaited<T>>;
|
|
34
|
+
export declare function currentWorkExecution(): WorkExecutionContext | undefined;
|
|
35
|
+
export declare function withWorkExecutionId<T>(executionContextId: string | undefined, run: () => T): Promise<Awaited<T>>;
|
|
58
36
|
export {};
|
|
@@ -14,6 +14,7 @@ export async function withAssistantRequest(hints, run) {
|
|
|
14
14
|
export function assistantRequestHeaders() {
|
|
15
15
|
const hints = assistantRequest?.getStore();
|
|
16
16
|
return {
|
|
17
|
+
...((hints?.executionContextId ?? hints?.executionContext?.contextId) ? { 'X-Ziggs-Execution': (hints?.executionContextId ?? hints?.executionContext?.contextId) } : {}),
|
|
17
18
|
...(hints?.orgId ? { 'X-Workspace-Id': hints.orgId } : {}),
|
|
18
19
|
...(hints?.resource ? { 'X-Ziggs-Resource': hints.resource } : {}),
|
|
19
20
|
...(hints?.clientSessionId ? { 'X-Ziggs-Session': hints.clientSessionId } : {}),
|
|
@@ -23,73 +24,48 @@ export function assistantRequestHeaders() {
|
|
|
23
24
|
...(hints?.sessionName ? { 'X-Ziggs-Session-Name': hints.sessionName } : {}),
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Auth headers for operator-key HTTP clients.
|
|
28
|
-
*
|
|
29
|
-
* ONE place builds them, because the lane is the header a caller cannot be
|
|
30
|
-
* trusted to remember. Omitting `X-Ziggs-Lane` never fails: the server fences
|
|
31
|
-
* the wake to the agent's own org instead, so a door that forgets it answers
|
|
32
|
-
* short lists and refuses grants the agent's customer gave it — silently, and
|
|
33
|
-
* only for the agents that serve someone other than their owner. A header
|
|
34
|
-
* whose absence is indistinguishable from a legitimate answer has to be built
|
|
35
|
-
* in one place, not copied into each caller.
|
|
36
|
-
*/
|
|
37
|
-
/** The header the backend's wake fence reads (`access/wake-fence.ts`). */
|
|
38
|
-
export const WAKE_LANE_HEADER = 'X-Ziggs-Lane';
|
|
39
|
-
/**
|
|
40
|
-
* The header naming the agreement a room wake works under. The backend takes
|
|
41
|
-
* it only for an agreement the agent has mail under in that room, and reads
|
|
42
|
-
* it off that mail when it is absent.
|
|
43
|
-
*/
|
|
44
|
-
export const WAKE_AGREEMENT_HEADER = 'X-Ziggs-Agreement';
|
|
45
|
-
/**
|
|
46
|
-
* A room lane that also names the agreement the wake works under:
|
|
47
|
-
* `<chatId>@<agreementId>`. Every client already carries the lane to
|
|
48
|
-
* {@link laneHeader}, so the agreement travels with it without a second
|
|
49
|
-
* parameter on each of them. An `agrn-` lane already is its agreement.
|
|
50
|
-
*/
|
|
27
|
+
/** A presentation routing key; it carries no authority. */
|
|
51
28
|
export function laneUnderAgreement(laneId, agreementId) {
|
|
52
29
|
if (!agreementId || laneId.startsWith('agrn-') || laneId.includes('@'))
|
|
53
30
|
return laneId;
|
|
54
31
|
return `${laneId}@${agreementId}`;
|
|
55
32
|
}
|
|
56
|
-
|
|
57
|
-
* The lane headers, or nothing. `laneId` is a chat id, `agrn-<agreementId>`
|
|
58
|
-
* for a task with no origin chat, or a chat id with the agreement the wake
|
|
59
|
-
* works under (`<chatId>@<agreementId>`, see {@link laneUnderAgreement}).
|
|
60
|
-
*/
|
|
61
|
-
export function laneHeader(laneId) {
|
|
62
|
-
if (!laneId)
|
|
63
|
-
return {};
|
|
64
|
-
const at = laneId.indexOf('@');
|
|
65
|
-
if (at <= 0)
|
|
66
|
-
return { [WAKE_LANE_HEADER]: laneId };
|
|
67
|
-
return {
|
|
68
|
-
[WAKE_LANE_HEADER]: laneId.slice(0, at),
|
|
69
|
-
[WAKE_AGREEMENT_HEADER]: laneId.slice(at + 1),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
export function buildOperatorHeaders(operatorKey, agentId, extra,
|
|
73
|
-
/**
|
|
74
|
-
* the lane this call belongs to, sent as `X-Ziggs-Lane`. The
|
|
75
|
-
* backend narrows the wake's reach to the engagement's orgs; omitting it
|
|
76
|
-
* narrows to the agent's own org, so it can never widen reach.
|
|
77
|
-
*/
|
|
78
|
-
laneId) {
|
|
33
|
+
export function buildOperatorHeaders(operatorKey, agentId, extra) {
|
|
79
34
|
return {
|
|
80
35
|
Authorization: `Bearer ${operatorKey}`,
|
|
81
36
|
...assistantRequestHeaders(),
|
|
82
37
|
// `X-Agent-Id` is only sent when an agentId is present — agent-scoped keys
|
|
83
38
|
// identify the agent themselves; fleet keys must pass one.
|
|
84
39
|
...(agentId ? { 'X-Agent-Id': agentId } : {}),
|
|
85
|
-
...laneHeader(laneId),
|
|
86
40
|
...extra,
|
|
87
41
|
};
|
|
88
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The host's own calls (wake gate, telemetry, tool picker) are not work
|
|
45
|
+
* actions: they never carry the selected execution, so they neither need a
|
|
46
|
+
* route that supports one nor record anything into it.
|
|
47
|
+
*/
|
|
48
|
+
export function withoutExecution(headers) {
|
|
49
|
+
const out = { ...headers };
|
|
50
|
+
delete out['X-Ziggs-Execution'];
|
|
51
|
+
delete out['x-ziggs-execution'];
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
89
54
|
/** What a `Creds`-shaped client sends on a JSON call: auth, agent, lane. */
|
|
90
55
|
export function buildCredsHeaders(creds) {
|
|
91
56
|
return {
|
|
92
57
|
'content-type': 'application/json',
|
|
93
|
-
...
|
|
58
|
+
...(creds.executionContextId ? { 'X-Ziggs-Execution': creds.executionContextId } : {}),
|
|
59
|
+
...buildOperatorHeaders(creds.operatorKey, creds.agentId),
|
|
94
60
|
};
|
|
95
61
|
}
|
|
62
|
+
/** Async-local scope: parallel agreement positions never share request headers. */
|
|
63
|
+
export async function withWorkExecution(executionContext, run) {
|
|
64
|
+
return withAssistantRequest({ ...assistantRequest?.getStore(), executionContext, executionContextId: executionContext?.contextId }, run);
|
|
65
|
+
}
|
|
66
|
+
export function currentWorkExecution() {
|
|
67
|
+
return assistantRequest?.getStore()?.executionContext;
|
|
68
|
+
}
|
|
69
|
+
export async function withWorkExecutionId(executionContextId, run) {
|
|
70
|
+
return withAssistantRequest({ ...assistantRequest?.getStore(), executionContextId: executionContextId ?? assistantRequest?.getStore()?.executionContextId }, run);
|
|
71
|
+
}
|
package/dist/inboxAck.d.ts
CHANGED
|
@@ -1,70 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One answer for "what does this envelope's ack list, and may we send it?"
|
|
3
|
-
*
|
|
4
|
-
* The SDK loop and the MCP inbox tool both call this. The bury-guard is the
|
|
5
|
-
* same question on both rails: list every assigned row this reader actually
|
|
6
|
-
* handled, and do not ack a window that is incomplete or that failed in its
|
|
7
|
-
* hands.
|
|
8
|
-
*/
|
|
1
|
+
/** Observation and handling are independent. Only explicit responsibility IDs settle work. */
|
|
9
2
|
export interface InboxAckEnvelope {
|
|
10
3
|
ackTo?: string | null;
|
|
11
4
|
deliveries?: ReadonlyArray<{
|
|
12
5
|
resourceId?: string | null;
|
|
6
|
+
responsibilityId?: string | null;
|
|
13
7
|
assigneeId?: string | null;
|
|
14
8
|
outOfReach?: unknown;
|
|
15
|
-
|
|
9
|
+
executionBlocked?: unknown;
|
|
16
10
|
ts?: string | null;
|
|
17
|
-
/** Mark covering this row and everything before it in this window. */
|
|
18
11
|
ackTo?: string | null;
|
|
19
12
|
}>;
|
|
20
13
|
openRequestsAwaitingMe?: ReadonlyArray<{
|
|
21
14
|
agreementId?: string | null;
|
|
15
|
+
responsibilityId?: string | null;
|
|
22
16
|
ts?: string | null;
|
|
23
17
|
}>;
|
|
24
18
|
}
|
|
25
|
-
export interface InboxAckDecision {
|
|
26
|
-
/** True when this envelope may be acknowledged. */
|
|
27
|
-
allowed: boolean;
|
|
28
|
-
handledResourceIds: string[];
|
|
29
|
-
}
|
|
30
19
|
export interface PlanInboxAckOptions {
|
|
31
|
-
/**
|
|
32
|
-
* Rows whose `assigneeId` equals this are mine. Empty or omitted: every
|
|
33
|
-
* delivery counts (the MCP tool with no configured self id).
|
|
34
|
-
*/
|
|
35
20
|
ownAgentId?: string;
|
|
36
21
|
ownAgentIds?: readonly string[];
|
|
37
|
-
/** Failed handovers hold the watermark unless `forceAck`. */
|
|
38
22
|
failures?: number;
|
|
39
23
|
forceAck?: boolean;
|
|
40
24
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export declare function planInboxAck(envelope: InboxAckEnvelope, opts?: PlanInboxAckOptions): InboxAckDecision;
|
|
46
|
-
/** How far a reader may ack right now, mid-pass. */
|
|
25
|
+
export interface InboxAckDecision {
|
|
26
|
+
allowed: boolean;
|
|
27
|
+
handledDeliveryIds: string[];
|
|
28
|
+
}
|
|
47
29
|
export interface InboxAckStep {
|
|
48
|
-
/** A row's own token — never one the client made up. */
|
|
49
30
|
ackTo: string;
|
|
50
|
-
|
|
31
|
+
handledDeliveryIds: string[];
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* which is long enough for the stand-in's 90s takeover to elapse while the
|
|
58
|
-
* agent is still working. This lets the reader give the mark back in steps.
|
|
59
|
-
*
|
|
60
|
-
* The stopping point is a global instant, NOT the reader's current unit of
|
|
61
|
-
* work. A mark advances every source it names at once, so acking after one
|
|
62
|
-
* chat fold would bury an older row from a different chat — the guard would
|
|
63
|
-
* refuse it, correctly. So: walk the instants the server minted a token for,
|
|
64
|
-
* and stop at the last one where everything at or before it is handled.
|
|
65
|
-
* Anything else is either refused or a bug.
|
|
66
|
-
*
|
|
67
|
-
* Returns null when the server minted no per-row tokens, which is how an older
|
|
68
|
-
* backend is handled: the caller keeps its single end-of-pass ack.
|
|
69
|
-
*/
|
|
33
|
+
export declare function inboxAckHandledIds(envelope: InboxAckEnvelope, ownAgentId?: string, ownAgentIds?: readonly string[]): string[];
|
|
34
|
+
export declare function inboxAckAllowed(envelope: InboxAckEnvelope, opts?: PlanInboxAckOptions): boolean;
|
|
35
|
+
/** Full-pass helper: only use after every listed responsibility succeeded. */
|
|
36
|
+
export declare function planInboxAck(envelope: InboxAckEnvelope, opts?: PlanInboxAckOptions): InboxAckDecision;
|
|
37
|
+
/** Successful jobs can be handled in any order, even when another job failed. */
|
|
70
38
|
export declare function planPartialInboxAck(envelope: InboxAckEnvelope, handled: ReadonlySet<string>, opts?: PlanInboxAckOptions): InboxAckStep | null;
|