@atalk/sdk 0.1.0-alpha.1 → 0.1.0-alpha.11
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/README.md +101 -5
- package/dist/agent.d.ts +126 -4
- package/dist/agent.js +932 -42
- package/dist/agent.js.map +1 -1
- package/dist/credential-store.d.ts +19 -1
- package/dist/credential-store.js +15 -4
- package/dist/credential-store.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime-state-store.d.ts +51 -0
- package/dist/runtime-state-store.js +83 -0
- package/dist/runtime-state-store.js.map +1 -0
- package/dist/workrooms.d.ts +317 -0
- package/dist/workrooms.js +1093 -0
- package/dist/workrooms.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { decryptMandateTerms, type AppendWorkroomEvent, type AttachmentDescriptor, type MandateUseDecision, type MandateUseRequest, type PublicPeer, type SignedMandate, type SignedMandateCommitment, type SignedMandateRevocation, type SignedWorkroomApprovalDecision, type SignedWorkroomReceipt, type Workroom, type WorkroomContentPayload, type WorkroomDescriptor, type WorkroomEncryptedEnvelope, type WorkroomMember, type WorkroomRoutingMatch, type WorkroomThread } from "@atalk/protocol";
|
|
2
|
+
import type { AgentCredentials } from "./credential-store.js";
|
|
3
|
+
import type { AgentAttachmentFileInput, AgentAttachmentInput, AttachmentTransferOptions } from "./agent.js";
|
|
4
|
+
import type { AgentRuntimeState } from "./runtime-state-store.js";
|
|
5
|
+
interface WorkroomMembership extends WorkroomMember {
|
|
6
|
+
id: string;
|
|
7
|
+
workroomId: string;
|
|
8
|
+
addedByPeerId: string;
|
|
9
|
+
idempotencyKey: string;
|
|
10
|
+
}
|
|
11
|
+
interface WorkroomRecord extends Workroom {
|
|
12
|
+
currentKeyEpoch: number;
|
|
13
|
+
descriptorHash: string;
|
|
14
|
+
idempotencyKey: string;
|
|
15
|
+
}
|
|
16
|
+
interface WorkroomThreadRecord extends WorkroomThread {
|
|
17
|
+
headerHash?: string;
|
|
18
|
+
idempotencyKey: string;
|
|
19
|
+
}
|
|
20
|
+
interface WorkroomMandateRecord {
|
|
21
|
+
mandateId: string;
|
|
22
|
+
revision: number;
|
|
23
|
+
workroomId?: string;
|
|
24
|
+
principalPeerId: string;
|
|
25
|
+
actorPeerId: string;
|
|
26
|
+
issuedByPeerId: string;
|
|
27
|
+
validFrom: string;
|
|
28
|
+
validUntil: string;
|
|
29
|
+
termsHash: string;
|
|
30
|
+
encryptedTermsHash: string;
|
|
31
|
+
encryptedTermsEnvelope: Parameters<typeof decryptMandateTerms>[0]["envelope"];
|
|
32
|
+
signedCommitment: SignedMandateCommitment;
|
|
33
|
+
issuerSigningPublicKey: string;
|
|
34
|
+
}
|
|
35
|
+
interface WorkroomMandateView {
|
|
36
|
+
mandate: WorkroomMandateRecord;
|
|
37
|
+
revocation?: {
|
|
38
|
+
signedRevocation: SignedMandateRevocation;
|
|
39
|
+
revokerSigningPublicKey: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
interface WorkroomApprovalDecisionRecord {
|
|
43
|
+
signedDecision: SignedWorkroomApprovalDecision;
|
|
44
|
+
signingPublicKey: string;
|
|
45
|
+
}
|
|
46
|
+
interface WorkroomApprovalView {
|
|
47
|
+
requestId: string;
|
|
48
|
+
workroomId: string;
|
|
49
|
+
sourceEventId: string;
|
|
50
|
+
requestedByPeerId: string;
|
|
51
|
+
requiredApprovals: number;
|
|
52
|
+
eligiblePeerIds: string[];
|
|
53
|
+
requestCiphertextHash: string;
|
|
54
|
+
requestEnvelope: WorkroomEncryptedEnvelope;
|
|
55
|
+
expiresAt?: string;
|
|
56
|
+
status: "pending" | "approved" | "rejected" | "expired";
|
|
57
|
+
decisions: WorkroomApprovalDecisionRecord[];
|
|
58
|
+
}
|
|
59
|
+
export interface WorkroomDetail {
|
|
60
|
+
workroom: WorkroomRecord;
|
|
61
|
+
/** Locally verified and decrypted; never returned in plaintext by the relay. */
|
|
62
|
+
descriptor: WorkroomDescriptor;
|
|
63
|
+
membership: WorkroomMembership;
|
|
64
|
+
members: Array<{
|
|
65
|
+
membership: WorkroomMembership;
|
|
66
|
+
peer: PublicPeer | null;
|
|
67
|
+
}>;
|
|
68
|
+
threads: WorkroomThreadRecord[];
|
|
69
|
+
latestMandates: WorkroomMandateView[];
|
|
70
|
+
approvals: WorkroomApprovalView[];
|
|
71
|
+
latestReceiptHash: string | null;
|
|
72
|
+
events?: WorkroomEventRecord[];
|
|
73
|
+
nextAfterSequence?: number | null;
|
|
74
|
+
}
|
|
75
|
+
interface WorkroomEventRecord {
|
|
76
|
+
sequence: number;
|
|
77
|
+
event: AppendWorkroomEvent;
|
|
78
|
+
projection?: WorkroomEventProjection;
|
|
79
|
+
}
|
|
80
|
+
export interface DecryptedWorkroomEvent extends WorkroomEventRecord {
|
|
81
|
+
actor: PublicPeer;
|
|
82
|
+
content: WorkroomContentPayload;
|
|
83
|
+
/** Exact autonomous context derived after canonical routing validation. */
|
|
84
|
+
routing: WorkroomRoutingMatch;
|
|
85
|
+
/** Compatibility alias for routing.directedToMe. */
|
|
86
|
+
directedToMe: boolean;
|
|
87
|
+
}
|
|
88
|
+
export type WorkroomEventProjection = {
|
|
89
|
+
kind: "plan";
|
|
90
|
+
id: string;
|
|
91
|
+
version: number;
|
|
92
|
+
} | {
|
|
93
|
+
kind: "artifact_version";
|
|
94
|
+
id: string;
|
|
95
|
+
artifactId: string;
|
|
96
|
+
artifactVersion: number;
|
|
97
|
+
attachmentIds: string[];
|
|
98
|
+
} | {
|
|
99
|
+
kind: "deliverable";
|
|
100
|
+
id: string;
|
|
101
|
+
artifactId: string;
|
|
102
|
+
artifactVersionId: string;
|
|
103
|
+
} | {
|
|
104
|
+
kind: "cost";
|
|
105
|
+
id: string;
|
|
106
|
+
} | {
|
|
107
|
+
kind: "approval_request";
|
|
108
|
+
id: string;
|
|
109
|
+
requiredApprovals: number;
|
|
110
|
+
eligiblePeerIds: string[];
|
|
111
|
+
expiresAt?: string;
|
|
112
|
+
};
|
|
113
|
+
export interface WorkroomPublishOptions {
|
|
114
|
+
eventId?: string;
|
|
115
|
+
idempotencyKey?: string;
|
|
116
|
+
projection?: WorkroomEventProjection;
|
|
117
|
+
maxAttempts?: number;
|
|
118
|
+
}
|
|
119
|
+
export interface WorkroomPollOptions {
|
|
120
|
+
limit?: number;
|
|
121
|
+
signal?: AbortSignal;
|
|
122
|
+
maxAttempts?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface WorkroomEventPage {
|
|
125
|
+
events: DecryptedWorkroomEvent[];
|
|
126
|
+
nextAfterSequence: number | null;
|
|
127
|
+
}
|
|
128
|
+
export interface MandatedActionInput {
|
|
129
|
+
workroomId: string;
|
|
130
|
+
threadId: string;
|
|
131
|
+
/** UUID used to make approval requests, effects and receipts retry-safe. */
|
|
132
|
+
operationId: string;
|
|
133
|
+
mandateId?: string;
|
|
134
|
+
action: string;
|
|
135
|
+
rationale?: string;
|
|
136
|
+
summary?: string;
|
|
137
|
+
target?: {
|
|
138
|
+
type: string;
|
|
139
|
+
label: string;
|
|
140
|
+
reference?: string;
|
|
141
|
+
};
|
|
142
|
+
effect?: string;
|
|
143
|
+
financialImpact?: {
|
|
144
|
+
currency: string;
|
|
145
|
+
amountMinor: number;
|
|
146
|
+
kind: "exact" | "maximum";
|
|
147
|
+
};
|
|
148
|
+
dataCategories?: string[];
|
|
149
|
+
participantPeerIds?: string[];
|
|
150
|
+
tool?: MandateUseRequest["tool"];
|
|
151
|
+
dataAccesses?: MandateUseRequest["dataAccesses"];
|
|
152
|
+
spend?: MandateUseRequest["spend"];
|
|
153
|
+
spendUsedMinorByLimit?: MandateUseRequest["spendUsedMinorByLimit"];
|
|
154
|
+
volumeUsed?: MandateUseRequest["volumeUsed"];
|
|
155
|
+
volumeDelta?: MandateUseRequest["volumeDelta"];
|
|
156
|
+
delegationDepth?: number;
|
|
157
|
+
principalApprovedDelegation?: boolean;
|
|
158
|
+
metEndConditionIds?: string[];
|
|
159
|
+
}
|
|
160
|
+
export interface MandatedPublicationInput extends Omit<MandatedActionInput, "action"> {
|
|
161
|
+
payload: WorkroomContentPayload;
|
|
162
|
+
publish?: WorkroomPublishOptions;
|
|
163
|
+
}
|
|
164
|
+
export interface MandatedFilePublicationInput extends Omit<MandatedActionInput, "action" | "volumeDelta"> {
|
|
165
|
+
path: string;
|
|
166
|
+
name?: string;
|
|
167
|
+
mimeType?: string;
|
|
168
|
+
title?: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
artifactType?: string;
|
|
171
|
+
artifactId?: string;
|
|
172
|
+
artifactVersion?: number;
|
|
173
|
+
mentions?: Extract<WorkroomContentPayload, {
|
|
174
|
+
kind: "artifact_version";
|
|
175
|
+
}>["mentions"];
|
|
176
|
+
transfer?: AttachmentTransferOptions;
|
|
177
|
+
}
|
|
178
|
+
export type MandateGuardResult = {
|
|
179
|
+
status: "permitted";
|
|
180
|
+
mandate: SignedMandate;
|
|
181
|
+
} | {
|
|
182
|
+
status: "requires_approval";
|
|
183
|
+
decision: Extract<MandateUseDecision, {
|
|
184
|
+
status: "requires_approval";
|
|
185
|
+
}>;
|
|
186
|
+
requestIds: string[];
|
|
187
|
+
} | {
|
|
188
|
+
status: "denied";
|
|
189
|
+
decision: Extract<MandateUseDecision, {
|
|
190
|
+
status: "denied";
|
|
191
|
+
}>;
|
|
192
|
+
};
|
|
193
|
+
export interface MandatedEffectResult<T> {
|
|
194
|
+
value: T;
|
|
195
|
+
costs?: Array<Extract<WorkroomContentPayload, {
|
|
196
|
+
kind: "cost";
|
|
197
|
+
}>>;
|
|
198
|
+
}
|
|
199
|
+
export type MandatedExecutionResult<T> = {
|
|
200
|
+
status: "executed";
|
|
201
|
+
value: T;
|
|
202
|
+
receipt: SignedWorkroomReceipt;
|
|
203
|
+
} | Exclude<MandateGuardResult, {
|
|
204
|
+
status: "permitted";
|
|
205
|
+
}>;
|
|
206
|
+
interface WorkroomClientDependencies {
|
|
207
|
+
request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
208
|
+
credentials(): AgentCredentials;
|
|
209
|
+
runtimeState(): AgentRuntimeState;
|
|
210
|
+
mutateRuntimeState(mutator: (state: AgentRuntimeState) => void): Promise<void>;
|
|
211
|
+
uploadPart(scope: {
|
|
212
|
+
workroomId: string;
|
|
213
|
+
}, id: string, bytes: Uint8Array, transfer?: AttachmentTransferOptions): Promise<void>;
|
|
214
|
+
deletePart(id: string): Promise<void>;
|
|
215
|
+
downloadAttachment(descriptor: AttachmentDescriptor): Promise<Uint8Array>;
|
|
216
|
+
downloadAttachmentTo(descriptor: AttachmentDescriptor, path: string, transfer?: AttachmentTransferOptions): Promise<string>;
|
|
217
|
+
}
|
|
218
|
+
/** E2EE task client. The relay sees signed ciphertext and routing projections only. */
|
|
219
|
+
export declare class WorkroomClient {
|
|
220
|
+
private readonly dependencies;
|
|
221
|
+
private executionTail;
|
|
222
|
+
constructor(dependencies: WorkroomClientDependencies);
|
|
223
|
+
list(cursor?: string, limit?: number): Promise<{
|
|
224
|
+
workrooms: WorkroomDetail[];
|
|
225
|
+
nextCursor: string | null;
|
|
226
|
+
}>;
|
|
227
|
+
get(workroomId: string, afterSequence?: number, eventLimit?: number): Promise<WorkroomDetail>;
|
|
228
|
+
/**
|
|
229
|
+
* Polls from the last durably acknowledged sequence and invokes the agent
|
|
230
|
+
* handler only for events explicitly directed to this identity. Undirected
|
|
231
|
+
* events are still authenticated and consumed so shared Task conversation
|
|
232
|
+
* traffic cannot accidentally start a model turn. A handler failure does not
|
|
233
|
+
* advance the cursor, so the same directed event is retried after restart.
|
|
234
|
+
*/
|
|
235
|
+
poll(workroomId: string, handler: (event: DecryptedWorkroomEvent) => void | Promise<void>, options?: WorkroomPollOptions): Promise<number>;
|
|
236
|
+
/**
|
|
237
|
+
* Reads every authenticated event without advancing the autonomous handler
|
|
238
|
+
* cursor. This is the explicit operator/audit surface; never use it as a
|
|
239
|
+
* model-trigger loop because it includes traffic addressed to other agents.
|
|
240
|
+
*/
|
|
241
|
+
readAuditEvents(workroomId: string, afterSequence?: number, limit?: number, signal?: AbortSignal): Promise<WorkroomEventPage>;
|
|
242
|
+
/** Long-polls using the durable cursor until aborted. */
|
|
243
|
+
watch(workroomId: string, handler: (event: DecryptedWorkroomEvent) => void | Promise<void>, options?: WorkroomPollOptions & {
|
|
244
|
+
intervalMs?: number;
|
|
245
|
+
}): Promise<void>;
|
|
246
|
+
publish(workroomId: string, threadId: string, candidate: WorkroomContentPayload, options?: WorkroomPublishOptions): Promise<WorkroomEventRecord>;
|
|
247
|
+
message(workroomId: string, threadId: string, body: string, mentions?: Extract<WorkroomContentPayload, {
|
|
248
|
+
kind: "message";
|
|
249
|
+
}>["mentions"]): Promise<WorkroomEventRecord>;
|
|
250
|
+
activity(workroomId: string, threadId: string, activityType: string, summary: string, mentions?: Extract<WorkroomContentPayload, {
|
|
251
|
+
kind: "activity";
|
|
252
|
+
}>["mentions"]): Promise<WorkroomEventRecord>;
|
|
253
|
+
plan(workroomId: string, threadId: string, payload: Omit<Extract<WorkroomContentPayload, {
|
|
254
|
+
kind: "plan";
|
|
255
|
+
}>, "version" | "kind">, options?: WorkroomPublishOptions): Promise<WorkroomEventRecord>;
|
|
256
|
+
artifactVersion(workroomId: string, threadId: string, payload: Omit<Extract<WorkroomContentPayload, {
|
|
257
|
+
kind: "artifact_version";
|
|
258
|
+
}>, "version" | "kind">, options?: WorkroomPublishOptions): Promise<WorkroomEventRecord>;
|
|
259
|
+
deliverable(workroomId: string, threadId: string, payload: Omit<Extract<WorkroomContentPayload, {
|
|
260
|
+
kind: "deliverable";
|
|
261
|
+
}>, "version" | "kind">, options?: WorkroomPublishOptions): Promise<WorkroomEventRecord>;
|
|
262
|
+
/**
|
|
263
|
+
* Preferred publication boundary for agent runtimes. It derives the same
|
|
264
|
+
* action names as the app, checks the current signed mandate twice, and
|
|
265
|
+
* records durable counters plus a signed receipt after publication.
|
|
266
|
+
*/
|
|
267
|
+
publishMandated(input: MandatedPublicationInput): Promise<MandatedExecutionResult<WorkroomEventRecord>>;
|
|
268
|
+
/** Permission-aware local decryption for files supplied to an external agent. */
|
|
269
|
+
downloadAttachmentToMandated(input: Omit<MandatedActionInput, "action"> & {
|
|
270
|
+
descriptor: AttachmentDescriptor;
|
|
271
|
+
path: string;
|
|
272
|
+
transfer?: AttachmentTransferOptions;
|
|
273
|
+
}): Promise<MandatedExecutionResult<string>>;
|
|
274
|
+
/** Guard, upload and publish one encrypted Task file as a single runtime operation. */
|
|
275
|
+
submitFileMandated(input: MandatedFilePublicationInput): Promise<MandatedExecutionResult<{
|
|
276
|
+
descriptor: AttachmentDescriptor;
|
|
277
|
+
artifactId: string;
|
|
278
|
+
artifactVersion: number;
|
|
279
|
+
artifactVersionId: string;
|
|
280
|
+
record: WorkroomEventRecord;
|
|
281
|
+
}>>;
|
|
282
|
+
uploadAttachment(input: AgentAttachmentInput & {
|
|
283
|
+
workroomId: string;
|
|
284
|
+
}): Promise<AttachmentDescriptor>;
|
|
285
|
+
uploadAttachmentFile(input: AgentAttachmentFileInput & {
|
|
286
|
+
workroomId: string;
|
|
287
|
+
}): Promise<AttachmentDescriptor>;
|
|
288
|
+
downloadAttachment(descriptor: AttachmentDescriptor): Promise<Uint8Array>;
|
|
289
|
+
downloadAttachmentTo(descriptor: AttachmentDescriptor, path: string, transfer?: AttachmentTransferOptions): Promise<string>;
|
|
290
|
+
guardMandateUse(input: MandatedActionInput, createApproval?: boolean): Promise<MandateGuardResult>;
|
|
291
|
+
/**
|
|
292
|
+
* Revalidates immediately before the callback. Callbacks must use operationId
|
|
293
|
+
* as their external idempotency key so a crash cannot duplicate side effects.
|
|
294
|
+
*/
|
|
295
|
+
executeMandatedAction<T>(input: MandatedActionInput, effect: (context: {
|
|
296
|
+
operationId: string;
|
|
297
|
+
mandate: SignedMandate;
|
|
298
|
+
}) => Promise<MandatedEffectResult<T>>): Promise<MandatedExecutionResult<T>>;
|
|
299
|
+
private openDetail;
|
|
300
|
+
private decryptEvent;
|
|
301
|
+
private readEventPage;
|
|
302
|
+
private openMandate;
|
|
303
|
+
private verifiedApprovals;
|
|
304
|
+
private ensureApprovalRequests;
|
|
305
|
+
private appendExecutionReceipt;
|
|
306
|
+
private withDurableUsage;
|
|
307
|
+
private recordDurableUsage;
|
|
308
|
+
private serializedExecution;
|
|
309
|
+
private retry;
|
|
310
|
+
}
|
|
311
|
+
/** @internal Approval identity is bound to the complete proposed operation, not only its action name. */
|
|
312
|
+
export declare function approvalRequestId(input: MandatedActionInput, signed: SignedMandate, thresholdId: string): string;
|
|
313
|
+
/** Stable action identifiers emitted by the app's agent-permission editor. */
|
|
314
|
+
export declare function defaultWorkroomAction(kind: WorkroomContentPayload["kind"]): string;
|
|
315
|
+
/** Returns why autonomous execution must stop, independent of encrypted mandate terms. */
|
|
316
|
+
export declare function workroomStopReason(workroom: Pick<Workroom, "status" | "deadline">, now?: number): "completed" | "cancelled" | "expired" | "deadline" | undefined;
|
|
317
|
+
export {};
|