@deliverd/sdk 0.26.0 → 0.28.0
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 +81 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +123 -0
- package/dist/data-screen.d.ts.map +1 -1
- package/dist/data-screen.js +6 -0
- package/dist/decision-token.d.ts +102 -0
- package/dist/decision-token.d.ts.map +1 -0
- package/dist/decision-token.js +139 -0
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +15 -0
- package/dist/gates.d.ts +2 -0
- package/dist/gates.d.ts.map +1 -1
- package/dist/gates.js +3 -0
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +3 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +4 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +3963 -0
- package/dist/types.d.ts +381 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +161 -0
- package/src/data-screen.ts +3 -0
- package/src/decision-token.ts +184 -0
- package/src/dev.ts +18 -0
- package/src/gates.ts +3 -0
- package/src/http.ts +4 -1
- package/src/index.ts +25 -0
- package/src/messages.ts +4 -0
- package/src/released.ts +3965 -0
- package/src/types.ts +357 -1
package/src/dev.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ApprovalData,
|
|
3
3
|
CollectionData,
|
|
4
|
+
DeclaredAgent,
|
|
4
5
|
EvidencePack,
|
|
5
6
|
FlowData,
|
|
6
7
|
GateData,
|
|
@@ -129,6 +130,7 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
|
|
|
129
130
|
changes: [],
|
|
130
131
|
concerns: [],
|
|
131
132
|
requestedBy: "You (development mode)",
|
|
133
|
+
...declaredOf(body),
|
|
132
134
|
approvers: (body.approvers as string[] | undefined) ?? [],
|
|
133
135
|
/*
|
|
134
136
|
* One, always. A standing rule could raise it on a real organisation,
|
|
@@ -222,6 +224,7 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
|
|
|
222
224
|
externalId: (body.externalId as string | undefined) ?? null,
|
|
223
225
|
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
224
226
|
requestedBy: "You (development mode)",
|
|
227
|
+
...declaredOf(body),
|
|
225
228
|
requiredApprovals: (body.requiredApprovals as number | undefined) ?? 1,
|
|
226
229
|
reviewers,
|
|
227
230
|
verdicts: [],
|
|
@@ -483,6 +486,7 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
|
|
|
483
486
|
externalId: (body.externalId as string | undefined) ?? null,
|
|
484
487
|
metadata: (body.metadata as Record<string, unknown>) ?? {},
|
|
485
488
|
requestedBy: "You (development mode)",
|
|
489
|
+
...declaredOf(body),
|
|
486
490
|
requiredResponses: (body.requiredResponses as number | undefined) ?? (asked.length || 1),
|
|
487
491
|
questions,
|
|
488
492
|
responses: asked.map((who) => ({
|
|
@@ -719,6 +723,20 @@ export function developmentFetch(options: DevelopmentOptions = {}): typeof globa
|
|
|
719
723
|
return handle;
|
|
720
724
|
}
|
|
721
725
|
|
|
726
|
+
/**
|
|
727
|
+
* The agent and model a request declared, as the API echoes them: what was
|
|
728
|
+
* sent, every field present, null when nothing was. Development mode stores
|
|
729
|
+
* nothing, so this is the whole of it.
|
|
730
|
+
*/
|
|
731
|
+
function declaredOf(body: Record<string, unknown>): { agent: DeclaredAgent | null; model: string | null } {
|
|
732
|
+
const a = body.agent as { name?: string; provider?: string; externalId?: string } | undefined;
|
|
733
|
+
const agent =
|
|
734
|
+
a && (a.name || a.provider || a.externalId)
|
|
735
|
+
? { name: a.name ?? null, provider: a.provider ?? null, externalId: a.externalId ?? null }
|
|
736
|
+
: null;
|
|
737
|
+
return { agent, model: typeof body.model === "string" && body.model ? body.model : null };
|
|
738
|
+
}
|
|
739
|
+
|
|
722
740
|
function resolveOutcome(
|
|
723
741
|
outcome: DevelopmentOptions["outcome"],
|
|
724
742
|
body: Record<string, unknown>
|
package/src/gates.ts
CHANGED
|
@@ -136,6 +136,8 @@ export class Gate {
|
|
|
136
136
|
get scope(): GateData["scope"] { return this.data.scope; }
|
|
137
137
|
/** How long it lasts and how many uses are left. */
|
|
138
138
|
get authorisation(): GateData["authorisation"] { return this.data.authorisation; }
|
|
139
|
+
/** The signed yes to hand the code that performs the action. Null unless `canExecute`. */
|
|
140
|
+
get decisionToken(): string | null { return this.data.decisionToken ?? null; }
|
|
139
141
|
/** A person sent it back. Revise and ask again with `supersedesGateId: gate.id`. */
|
|
140
142
|
get changesRequested(): boolean { return this.data.status === "changes_requested"; }
|
|
141
143
|
|
|
@@ -175,6 +177,7 @@ export class Gate {
|
|
|
175
177
|
changes: this.data.changes ?? [],
|
|
176
178
|
id: this.data.id,
|
|
177
179
|
approvalUrl: this.data.approvalUrl,
|
|
180
|
+
decisionToken: this.data.decisionToken ?? null,
|
|
178
181
|
gate: this,
|
|
179
182
|
};
|
|
180
183
|
}
|
package/src/http.ts
CHANGED
|
@@ -43,6 +43,8 @@ interface RequestOptions {
|
|
|
43
43
|
* knows how to derive.
|
|
44
44
|
*/
|
|
45
45
|
idempotencyKey?: string;
|
|
46
|
+
/** `text` hands back the body as it came, for a route that returns a file. */
|
|
47
|
+
responseType?: "json" | "text";
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
const sleep = (ms: number, signal?: AbortSignal) =>
|
|
@@ -121,7 +123,7 @@ export class HttpClient {
|
|
|
121
123
|
method: options.method,
|
|
122
124
|
headers: {
|
|
123
125
|
Authorization: `Bearer ${this.apiKey}`,
|
|
124
|
-
Accept: "application/json",
|
|
126
|
+
Accept: options.responseType === "text" ? "text/markdown, application/json" : "application/json",
|
|
125
127
|
"User-Agent": USER_AGENT,
|
|
126
128
|
// One id per logical request, kept across retries: it is the
|
|
127
129
|
// thing to quote when something went wrong, and generating it
|
|
@@ -143,6 +145,7 @@ export class HttpClient {
|
|
|
143
145
|
if (response.status === 204) return undefined as T;
|
|
144
146
|
|
|
145
147
|
const text = await response.text();
|
|
148
|
+
if (options.responseType === "text" && response.ok) return text as T;
|
|
146
149
|
let json: unknown;
|
|
147
150
|
try {
|
|
148
151
|
json = text ? JSON.parse(text) : {};
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,10 @@ import { Reviews, type ReviewWaitOptions } from "./reviews.js";
|
|
|
6
6
|
import { Collections, type CollectWaitOptions } from "./collections.js";
|
|
7
7
|
import { Flows } from "./flows.js";
|
|
8
8
|
import { Tasks } from "./tasks.js";
|
|
9
|
+
import { Knowledge, Playbooks } from "./context.js";
|
|
9
10
|
import { AiGovernance } from "./governance.js";
|
|
10
11
|
import { Webhooks } from "./webhooks.js";
|
|
12
|
+
import { DecisionTokens } from "./decision-token.js";
|
|
11
13
|
import { WebhookEndpoints } from "./webhook-endpoints.js";
|
|
12
14
|
import { screen, Screened, type ScreenOptions } from "./screen.js";
|
|
13
15
|
import { developmentFetch, type DevelopmentOptions } from "./dev.js";
|
|
@@ -32,8 +34,22 @@ export { Review, Reviews, type ReviewWaitOptions } from "./reviews.js";
|
|
|
32
34
|
export { Collection, Collections, type CollectWaitOptions } from "./collections.js";
|
|
33
35
|
export { Flow, Flows, type FlowPrimitives } from "./flows.js";
|
|
34
36
|
export { Task, Tasks } from "./tasks.js";
|
|
37
|
+
export { Knowledge, Playbooks } from "./context.js";
|
|
35
38
|
export { AiGovernance, AiSystems, Incidents } from "./governance.js";
|
|
36
39
|
export { WebhookEndpoints } from "./webhook-endpoints.js";
|
|
40
|
+
export {
|
|
41
|
+
canonicalJson,
|
|
42
|
+
DECISION_TOKEN_CONTEXT,
|
|
43
|
+
DECISION_TOKEN_PREFIX,
|
|
44
|
+
decisionInputHash,
|
|
45
|
+
DecisionTokens,
|
|
46
|
+
EVIDENCE_KEY_PATH,
|
|
47
|
+
verifyDecisionToken,
|
|
48
|
+
type DecisionTokenClaims,
|
|
49
|
+
type DecisionTokenExpectation,
|
|
50
|
+
type DecisionTokenFailure,
|
|
51
|
+
type DecisionTokenResult,
|
|
52
|
+
} from "./decision-token.js";
|
|
37
53
|
export { Screened, type ScreenOptions } from "./screen.js";
|
|
38
54
|
export {
|
|
39
55
|
DATA_KINDS,
|
|
@@ -165,6 +181,10 @@ export class Deliverd {
|
|
|
165
181
|
readonly collections: Collections;
|
|
166
182
|
readonly flows: Flows;
|
|
167
183
|
readonly tasks: Tasks;
|
|
184
|
+
/** What your agents know: proposed by agents, confirmed by people, exported to anywhere. */
|
|
185
|
+
readonly knowledge: Knowledge;
|
|
186
|
+
/** Jobs written down as steps, each with the rule that applies before it acts. */
|
|
187
|
+
readonly playbooks: Playbooks;
|
|
168
188
|
/** Compliance Mode across the organisation: AI systems, incidents, authority, frameworks, the ICT register. */
|
|
169
189
|
readonly governance: AiGovernance;
|
|
170
190
|
readonly reports: Reports;
|
|
@@ -172,6 +192,8 @@ export class Deliverd {
|
|
|
172
192
|
readonly schedules: Schedules;
|
|
173
193
|
readonly webhooks: Webhooks;
|
|
174
194
|
readonly webhookEndpoints: WebhookEndpoints;
|
|
195
|
+
/** Check a gate's signed yes where the action happens, before it happens. */
|
|
196
|
+
readonly decisionTokens: DecisionTokens;
|
|
175
197
|
readonly http: HttpClient;
|
|
176
198
|
/** Whether an imaginary approver is deciding these. */
|
|
177
199
|
readonly development: boolean;
|
|
@@ -200,12 +222,15 @@ export class Deliverd {
|
|
|
200
222
|
*/
|
|
201
223
|
this.flows = new Flows(this.http, this);
|
|
202
224
|
this.tasks = new Tasks(this.http);
|
|
225
|
+
this.knowledge = new Knowledge(this.http);
|
|
226
|
+
this.playbooks = new Playbooks(this.http);
|
|
203
227
|
this.governance = new AiGovernance(this.http);
|
|
204
228
|
this.reports = new Reports(this.http);
|
|
205
229
|
this.comments = new Comments(this.http);
|
|
206
230
|
this.schedules = new Schedules(this.http);
|
|
207
231
|
this.webhooks = new Webhooks();
|
|
208
232
|
this.webhookEndpoints = new WebhookEndpoints(this.http);
|
|
233
|
+
this.decisionTokens = new DecisionTokens(this.http.baseUrl, options.fetch);
|
|
209
234
|
}
|
|
210
235
|
|
|
211
236
|
/**
|
package/src/messages.ts
CHANGED
|
@@ -181,6 +181,10 @@ export const EXPLANATIONS: Record<string, Explanation> = {
|
|
|
181
181
|
message: "That permission was withdrawn after it was given.",
|
|
182
182
|
hint: "Do not act. Read the gate for who revoked it and why, and ask again if the work still needs doing.",
|
|
183
183
|
},
|
|
184
|
+
agents_stopped: {
|
|
185
|
+
message: "A person has stopped every agent in this organisation.",
|
|
186
|
+
hint: "Do not act, and do not retry. Tell the user; nothing proceeds until somebody resumes the agents.",
|
|
187
|
+
},
|
|
184
188
|
gate_cancelled: {
|
|
185
189
|
message: "That request was withdrawn.",
|
|
186
190
|
hint: "Ask again if the work still needs doing.",
|