@halonicjs/testing 0.1.1 → 0.1.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/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +4 -2
- package/dist/core/events/src/index.js +2 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +3 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +3 -2
- package/dist/core/format/src/index.js +3 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +13 -3
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/package.json +9 -2
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import type { RunFailureKind } from "../../events/src/index.js";
|
|
2
|
+
import type { DefinitionSource } from "./definition-store.js";
|
|
3
|
+
import type { HttpClient } from "./http-client.js";
|
|
4
|
+
import type { TokenStore } from "./token-store.js";
|
|
5
|
+
/** Version of the {@link DeployTarget} port. A breaking change bumps it and comes with an ADR. */
|
|
6
|
+
export declare const deployTargetVersion = 1;
|
|
7
|
+
/** One deployment from `deployments.yaml`, with where it lives on its host. */
|
|
8
|
+
export interface DeploymentRef {
|
|
9
|
+
/** The deployment's name in `deployments.yaml`, such as "web". */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The account on the host, by its id. The account is always shown before anything changes. */
|
|
12
|
+
readonly accountId: string;
|
|
13
|
+
/** The service the deployment runs as on the host, such as the Worker "acme". */
|
|
14
|
+
readonly service: string;
|
|
15
|
+
/** A production deploy refuses uncommitted changes; a development one counts and ignores them. */
|
|
16
|
+
readonly environment: "production" | "development";
|
|
17
|
+
}
|
|
18
|
+
/** An account a token reaches. */
|
|
19
|
+
export interface DeployAccount {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
/** The name the host shows, such as "sam@example.com's Account". */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One thing a deploy creates or destroy removes, in the words the user meets
|
|
26
|
+
* on the host's dashboard and bill: an address, a Worker, a database, a bucket.
|
|
27
|
+
*/
|
|
28
|
+
export interface DeployResource {
|
|
29
|
+
readonly kind: "address" | "service" | "database" | "bucket";
|
|
30
|
+
readonly name: string;
|
|
31
|
+
}
|
|
32
|
+
/** A version of a deployment. `number` counts from 1 per deployment; `id` is the host's own. */
|
|
33
|
+
export interface DeployedVersion {
|
|
34
|
+
readonly number: number;
|
|
35
|
+
readonly id: string;
|
|
36
|
+
/** The commit it was deployed from, when the host still says. */
|
|
37
|
+
readonly commit: string | undefined;
|
|
38
|
+
/** The Halonic version it runs, when the host still says. */
|
|
39
|
+
readonly halonicVersion: string | undefined;
|
|
40
|
+
/** When it went live, as an ISO time. */
|
|
41
|
+
readonly liveSince: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Who holds a deployment's lock. `who` is the git email of whoever started
|
|
45
|
+
* the deploy, or the computer's name when there's none, and never anything
|
|
46
|
+
* else about the machine or the host. Times are ISO. The lock frees itself at
|
|
47
|
+
* `expiresAt`, 10 minutes after its last renewal.
|
|
48
|
+
*/
|
|
49
|
+
export interface DeployLockHolder {
|
|
50
|
+
readonly who: string;
|
|
51
|
+
readonly startedAt: string;
|
|
52
|
+
readonly expiresAt: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One address the deployment talks to from the host, and the secret it sends
|
|
56
|
+
* there, by name only. `secret` is `undefined` when it sends none.
|
|
57
|
+
*/
|
|
58
|
+
export interface DeployReach {
|
|
59
|
+
/** A host name such as "api.anthropic.com", or "*" for any web address. */
|
|
60
|
+
readonly address: string;
|
|
61
|
+
readonly secret: string | undefined;
|
|
62
|
+
}
|
|
63
|
+
/** What a deploy uploads, taken by the caller from one commit. */
|
|
64
|
+
export interface DeploySnapshot {
|
|
65
|
+
readonly commit: string;
|
|
66
|
+
/** The workspace's files at `commit`, read-only. */
|
|
67
|
+
readonly files: DefinitionSource;
|
|
68
|
+
/** The Halonic version of the command line that deploys; the deployment then runs it. */
|
|
69
|
+
readonly halonicVersion: string;
|
|
70
|
+
}
|
|
71
|
+
/** What `plan` and `deploy` are given. */
|
|
72
|
+
export interface DeployRequest {
|
|
73
|
+
readonly deployment: DeploymentRef;
|
|
74
|
+
readonly snapshot: DeploySnapshot;
|
|
75
|
+
/**
|
|
76
|
+
* Secret values by name: the sign-in password's hash and the workspace's
|
|
77
|
+
* keys. A target sends them to the host and nowhere else: never into a
|
|
78
|
+
* result, an event, an error or a log.
|
|
79
|
+
*/
|
|
80
|
+
readonly secrets: ReadonlyMap<string, string>;
|
|
81
|
+
/**
|
|
82
|
+
* What the workspace reaches, as the caller read it from the files. The
|
|
83
|
+
* target keeps it with the version, so the next `plan` can say what's new.
|
|
84
|
+
*/
|
|
85
|
+
readonly reaches: readonly DeployReach[];
|
|
86
|
+
/** Use resources with Halonic's names that Halonic didn't create. */
|
|
87
|
+
readonly adopt?: boolean;
|
|
88
|
+
/** Allow a database change that deletes data. Without it such a change is refused with `denied`. */
|
|
89
|
+
readonly allowDataLoss?: boolean;
|
|
90
|
+
/** Aborting stops at the next safe point; see {@link DeployTarget.deploy}. */
|
|
91
|
+
readonly signal?: AbortSignal;
|
|
92
|
+
}
|
|
93
|
+
/** What a deploy would do, measured against what's live. Nothing was changed. */
|
|
94
|
+
export interface DeployPlan {
|
|
95
|
+
readonly account: DeployAccount;
|
|
96
|
+
/** The address once live; `undefined` when the host only gives it on the first deploy. */
|
|
97
|
+
readonly url: string | undefined;
|
|
98
|
+
/** What the deploy would create, in order. Empty when it all exists. */
|
|
99
|
+
readonly creates: readonly DeployResource[];
|
|
100
|
+
/** Ids of the database changes it would apply, in order. */
|
|
101
|
+
readonly databaseChanges: readonly string[];
|
|
102
|
+
/** `true` when one of those changes deletes data. */
|
|
103
|
+
readonly deletesData: boolean;
|
|
104
|
+
/** The live version, or `undefined` when nothing is live. */
|
|
105
|
+
readonly live: DeployedVersion | undefined;
|
|
106
|
+
/** What the live version reaches, or `undefined` when nothing is live or it doesn't say. */
|
|
107
|
+
readonly liveReaches: readonly DeployReach[] | undefined;
|
|
108
|
+
/** The lock's holder when another deploy is running, checked before any question is asked. */
|
|
109
|
+
readonly lockedBy: DeployLockHolder | undefined;
|
|
110
|
+
/** `true` when the live version has the same commit and Halonic version, so a deploy changes nothing. */
|
|
111
|
+
readonly unchanged: boolean;
|
|
112
|
+
/** Every file the deploy would upload, for `--plan`. */
|
|
113
|
+
readonly files: readonly string[];
|
|
114
|
+
}
|
|
115
|
+
/** One step of a deploy, as its events name it. */
|
|
116
|
+
export type DeployStep = {
|
|
117
|
+
readonly step: "create";
|
|
118
|
+
readonly resource: DeployResource;
|
|
119
|
+
}
|
|
120
|
+
/** `first` is `true` when the database is set up rather than updated. */
|
|
121
|
+
| {
|
|
122
|
+
readonly step: "database";
|
|
123
|
+
readonly changes: number;
|
|
124
|
+
readonly first: boolean;
|
|
125
|
+
} | {
|
|
126
|
+
readonly step: "upload";
|
|
127
|
+
readonly version: number;
|
|
128
|
+
readonly files: number;
|
|
129
|
+
readonly secrets: number;
|
|
130
|
+
} | {
|
|
131
|
+
readonly step: "self-test";
|
|
132
|
+
readonly version: number;
|
|
133
|
+
} | {
|
|
134
|
+
readonly step: "switch";
|
|
135
|
+
readonly version: number;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* What a deploy reports as it goes, in order. Each step is `started`, then
|
|
139
|
+
* `done`; `waiting` comes while a step has waited over 10 seconds for the
|
|
140
|
+
* host; `warning` is a line the user must see, such as a database change that
|
|
141
|
+
* goes live without a trial.
|
|
142
|
+
*/
|
|
143
|
+
export type DeployEvent = (DeployStep & {
|
|
144
|
+
readonly phase: "started" | "done";
|
|
145
|
+
}) | {
|
|
146
|
+
readonly phase: "waiting";
|
|
147
|
+
readonly step: DeployStep["step"];
|
|
148
|
+
/** Whole seconds since the step started. */
|
|
149
|
+
readonly seconds: number;
|
|
150
|
+
} | {
|
|
151
|
+
readonly phase: "warning";
|
|
152
|
+
readonly message: string;
|
|
153
|
+
};
|
|
154
|
+
/** A deploy that went live. */
|
|
155
|
+
export interface DeployDone {
|
|
156
|
+
readonly outcome: "deployed";
|
|
157
|
+
readonly url: string;
|
|
158
|
+
readonly version: DeployedVersion;
|
|
159
|
+
/** The version before it, which a rollback goes back to; `undefined` on the first deploy. */
|
|
160
|
+
readonly previous: DeployedVersion | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* What went wrong after traffic switched, such as the lock lost after the
|
|
163
|
+
* switch. The deploy is live. A caller shows every entry.
|
|
164
|
+
*/
|
|
165
|
+
readonly warnings: readonly string[];
|
|
166
|
+
}
|
|
167
|
+
/** A deploy whose commit and Halonic version were live already. No new version was made. */
|
|
168
|
+
export interface DeployUnchanged {
|
|
169
|
+
readonly outcome: "unchanged";
|
|
170
|
+
readonly url: string;
|
|
171
|
+
readonly version: DeployedVersion;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The new version failed its self-test. `stillLive` is the version that
|
|
175
|
+
* still serves, or `undefined` when the new one went live before the test (a
|
|
176
|
+
* first deploy, or a change the host only applies by going live) and doesn't
|
|
177
|
+
* work. `restoreFailed` is `true` when putting the previous version back failed.
|
|
178
|
+
*/
|
|
179
|
+
export interface DeploySelfTestFailed {
|
|
180
|
+
readonly outcome: "self-test-failed";
|
|
181
|
+
readonly version: DeployedVersion;
|
|
182
|
+
readonly failedChecks: readonly string[];
|
|
183
|
+
readonly stillLive: DeployedVersion | undefined;
|
|
184
|
+
readonly restoreFailed: boolean;
|
|
185
|
+
}
|
|
186
|
+
/** How a deploy ended when nothing was thrown. */
|
|
187
|
+
export type DeployResult = DeployDone | DeployUnchanged | DeploySelfTestFailed;
|
|
188
|
+
/** Runs by state, for `status`. Only these states are counted; nothing about a run leaves the count. */
|
|
189
|
+
export interface DeployRunCounts {
|
|
190
|
+
readonly running: number;
|
|
191
|
+
readonly waiting: number;
|
|
192
|
+
readonly lastDay: number;
|
|
193
|
+
}
|
|
194
|
+
/** What `status` reads. It never changes anything. */
|
|
195
|
+
export interface DeploymentStatus {
|
|
196
|
+
readonly account: DeployAccount;
|
|
197
|
+
readonly url: string | undefined;
|
|
198
|
+
readonly live: DeployedVersion | undefined;
|
|
199
|
+
/** The version a rollback would go back to. */
|
|
200
|
+
readonly previous: DeployedVersion | undefined;
|
|
201
|
+
/** Whether the address answers, and when the routine tick last ran (ISO). */
|
|
202
|
+
readonly health: {
|
|
203
|
+
readonly answering: true;
|
|
204
|
+
readonly lastRoutineTick: string | undefined;
|
|
205
|
+
} | {
|
|
206
|
+
readonly answering: false;
|
|
207
|
+
};
|
|
208
|
+
/** `undefined` when the count failed: status never fails on it. */
|
|
209
|
+
readonly runs: DeployRunCounts | undefined;
|
|
210
|
+
readonly lockedBy: DeployLockHolder | undefined;
|
|
211
|
+
/** The step the last deploy stopped in, when it stopped without finishing. */
|
|
212
|
+
readonly unfinished: DeployStep["step"] | undefined;
|
|
213
|
+
}
|
|
214
|
+
/** What `rollback` did, or would do with `plan`. */
|
|
215
|
+
export interface DeployRollback {
|
|
216
|
+
readonly mode: "plan" | "rolled-back";
|
|
217
|
+
readonly from: DeployedVersion;
|
|
218
|
+
readonly to: DeployedVersion;
|
|
219
|
+
}
|
|
220
|
+
/** How much `export` wrote or `import` read. Secrets and tokens are never in a transfer. */
|
|
221
|
+
export interface DeployTransferCounts {
|
|
222
|
+
readonly runs: number;
|
|
223
|
+
readonly records: number;
|
|
224
|
+
readonly files: number;
|
|
225
|
+
readonly bytes: number;
|
|
226
|
+
}
|
|
227
|
+
/** One thing destroy removes, with what it holds, for the list the user confirms. */
|
|
228
|
+
export interface DestroyItem {
|
|
229
|
+
readonly resource: DeployResource;
|
|
230
|
+
readonly secrets?: number;
|
|
231
|
+
readonly runs?: number;
|
|
232
|
+
readonly bytes?: number;
|
|
233
|
+
}
|
|
234
|
+
/** What `destroy` is given. */
|
|
235
|
+
export interface DestroyRequest {
|
|
236
|
+
/**
|
|
237
|
+
* Shown the list before anything is removed; `false` stops with nothing
|
|
238
|
+
* removed. The caller asks the user to type the service's name.
|
|
239
|
+
*/
|
|
240
|
+
readonly confirm: (items: readonly DestroyItem[]) => Promise<boolean>;
|
|
241
|
+
/** List what would be removed and remove nothing. */
|
|
242
|
+
readonly plan?: boolean;
|
|
243
|
+
readonly signal?: AbortSignal;
|
|
244
|
+
}
|
|
245
|
+
/** What `destroy` did. `left` holds what it didn't remove because Halonic didn't create it. */
|
|
246
|
+
export interface DestroyResult {
|
|
247
|
+
readonly mode: "plan" | "destroyed" | "cancelled";
|
|
248
|
+
readonly items: readonly DestroyItem[];
|
|
249
|
+
readonly left: readonly DeployResource[];
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Why a target call failed. `code` is stable and goes into `--json`; callers
|
|
253
|
+
* branch on `kind`, so a new code keeps the port's version.
|
|
254
|
+
*/
|
|
255
|
+
export type DeployFailureCode = "token-missing" | "token-inactive" | "missing-permission" | "no-account" | "ambiguous-account" | "free-plan" | "host-unreachable" | "host-request-failed" | "unmarked-resources" | "uncommitted-changes" | "deploy-locked" | "older-than-live" | "data-loss" | "not-deployed" | "nothing-to-roll-back" | "rollback-not-possible" | "transfer-failed" | "destroy-changed" | "stopped";
|
|
256
|
+
/**
|
|
257
|
+
* What every {@link DeployTarget} method rejects with when it fails: an
|
|
258
|
+
* `Error` with one of the kit's error kinds (`RunFailureKind`, which the
|
|
259
|
+
* engine's type test keeps equal to `@halonicjs/std`'s `ErrorKind`), so
|
|
260
|
+
* `errorKindOf` reads it and the command line's exit code needs no new number. The message and `fix` are
|
|
261
|
+
* safe to show: no token, secret or host response body.
|
|
262
|
+
*
|
|
263
|
+
* `stopped` (kind `conflict`) is the abort of a request's signal. Its `live`
|
|
264
|
+
* says what still serves, so the caller can say "Version 1 is still live."
|
|
265
|
+
*/
|
|
266
|
+
export interface DeployFailure extends Error {
|
|
267
|
+
readonly kind: RunFailureKind;
|
|
268
|
+
readonly code: DeployFailureCode;
|
|
269
|
+
readonly fix: string | undefined;
|
|
270
|
+
/** What serves after the failure: a version, `"none"`, or `undefined` when not known. */
|
|
271
|
+
readonly live?: DeployedVersion | "none";
|
|
272
|
+
/** The step a `stopped` deploy stopped after. */
|
|
273
|
+
readonly stoppedAfter?: DeployStep;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* What a target is created with. The caller's host builds it; the target
|
|
277
|
+
* gets nothing else from the machine.
|
|
278
|
+
*/
|
|
279
|
+
export interface DeployTargetContext {
|
|
280
|
+
readonly http: HttpClient;
|
|
281
|
+
/** Where `login` keeps the host's token: the user's keychain. */
|
|
282
|
+
readonly tokens: TokenStore;
|
|
283
|
+
/** A token from the environment, for CI. It wins over the saved one and is never saved. */
|
|
284
|
+
readonly environmentToken: string | undefined;
|
|
285
|
+
/** Who runs this, for the lock: the git email, else the computer's name. */
|
|
286
|
+
readonly who: string;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Deploys a workspace to a host such as Cloudflare, and reads, rolls back,
|
|
290
|
+
* moves data in and out of and removes what it deployed (ADR 5.6; requirement
|
|
291
|
+
* `ports.deploy-target`). The `halonic deploy` command calls it through the
|
|
292
|
+
* deploy app service, and never imports a target package: it loads one by
|
|
293
|
+
* name and checks its {@link DeployTargetEntry}.
|
|
294
|
+
*
|
|
295
|
+
* Every method that changes the host holds the deployment's lock while it
|
|
296
|
+
* does; a second one rejects with `deploy-locked` and the holder. Results are
|
|
297
|
+
* data. Failures are {@link DeployFailure}s.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* const target = entry.create({ http, tokens, environmentToken, who });
|
|
301
|
+
* const plan = await target.plan(request);
|
|
302
|
+
* if (plan.lockedBy === undefined && (await ask(plan))) {
|
|
303
|
+
* const result = await target.deploy(request, (event) => output.show(event));
|
|
304
|
+
* }
|
|
305
|
+
*/
|
|
306
|
+
export interface DeployTarget {
|
|
307
|
+
/**
|
|
308
|
+
* Checks a pasted token, saves it and lists the accounts it reaches.
|
|
309
|
+
* Rejects with `token-inactive` or `missing-permission`.
|
|
310
|
+
*/
|
|
311
|
+
login(token: string): Promise<{
|
|
312
|
+
readonly accounts: readonly DeployAccount[];
|
|
313
|
+
}>;
|
|
314
|
+
/** Measures a deploy against what's live. Changes nothing and takes no lock. */
|
|
315
|
+
plan(request: DeployRequest): Promise<DeployPlan>;
|
|
316
|
+
/**
|
|
317
|
+
* Creates what's missing, updates the database, uploads a new version,
|
|
318
|
+
* self-tests it and makes it live, reporting each step to `onEvent`.
|
|
319
|
+
* Aborting the signal stops at once before anything changed or during the
|
|
320
|
+
* self-test, finishes the step it's in otherwise, and rejects with
|
|
321
|
+
* `stopped`; making it live is one step and always finishes.
|
|
322
|
+
*/
|
|
323
|
+
deploy(request: DeployRequest, onEvent: (event: DeployEvent) => void): Promise<DeployResult>;
|
|
324
|
+
status(deployment: DeploymentRef): Promise<DeploymentStatus>;
|
|
325
|
+
/** Goes back one version. Rejects with `rollback-not-possible` when the database has moved on. */
|
|
326
|
+
rollback(deployment: DeploymentRef, options?: {
|
|
327
|
+
readonly plan?: boolean;
|
|
328
|
+
readonly signal?: AbortSignal;
|
|
329
|
+
}): Promise<DeployRollback>;
|
|
330
|
+
/** Writes the deployment's runs, records and files to a local folder. */
|
|
331
|
+
export(deployment: DeploymentRef, folder: string, options?: {
|
|
332
|
+
readonly signal?: AbortSignal;
|
|
333
|
+
}): Promise<DeployTransferCounts>;
|
|
334
|
+
/** Reads a folder `export` wrote into the deployment. */
|
|
335
|
+
import(deployment: DeploymentRef, folder: string, options?: {
|
|
336
|
+
readonly signal?: AbortSignal;
|
|
337
|
+
}): Promise<DeployTransferCounts>;
|
|
338
|
+
/** Frees a lock left by a deploy that stopped without finishing. Gives the holder it freed, if any. */
|
|
339
|
+
unlock(deployment: DeploymentRef): Promise<{
|
|
340
|
+
readonly freed: DeployLockHolder | undefined;
|
|
341
|
+
}>;
|
|
342
|
+
/** Signs out every browser signed in to the deployment. */
|
|
343
|
+
revokeSessions(deployment: DeploymentRef): Promise<void>;
|
|
344
|
+
/** Removes what Halonic created for the deployment, after `confirm` says yes. */
|
|
345
|
+
destroy(deployment: DeploymentRef, request: DestroyRequest): Promise<DestroyResult>;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* What a target package exports as `deployTarget`. The loader checks `host`
|
|
349
|
+
* and `version` before it calls `create`, and that what `create` gives has
|
|
350
|
+
* every {@link DeployTarget} method.
|
|
351
|
+
*/
|
|
352
|
+
export interface DeployTargetEntry {
|
|
353
|
+
/** The `host` in `deployments.yaml` this target serves, such as "cloudflare". */
|
|
354
|
+
readonly host: string;
|
|
355
|
+
/** The port version the target was built against. */
|
|
356
|
+
readonly version: number;
|
|
357
|
+
create(context: DeployTargetContext): DeployTarget;
|
|
358
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { ToolOutcome, Usage } from "../../events/src/index.js";
|
|
1
|
+
import type { RunEventBody, ToolOutcome, Usage } from "../../events/src/index.js";
|
|
2
2
|
import type { ToolDefinition } from "./chat.js";
|
|
3
3
|
import type { HarnessBridge, HarnessEvent } from "./harness.js";
|
|
4
4
|
import { type ModelPrice } from "./model-price.js";
|
|
5
5
|
/** Version of the {@link HarnessBridgeServer} port. A breaking change bumps it and comes with an ADR. */
|
|
6
6
|
export declare const harnessBridgeServerVersion = 1;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* The API a model provider speaks, which the bridge passes requests on in:
|
|
9
|
+
* Anthropic's Messages API, or OpenAI's Responses API. Each is at a fixed
|
|
10
|
+
* host the adapter knows, unless a keyed access names its own `baseUrl`.
|
|
11
|
+
*/
|
|
8
12
|
export type BridgeProvider = "anthropic" | "openai";
|
|
9
13
|
/** How the agent reaches one provider through the bridge. */
|
|
10
14
|
export type BridgeProviderAccess =
|
|
@@ -13,10 +17,35 @@ export type BridgeProviderAccess =
|
|
|
13
17
|
* this name, from the `Secrets` port, in place of the program's key, and
|
|
14
18
|
* records the cost from the model's price. A model without a price is
|
|
15
19
|
* recorded without a cost, so the run shows it as unpriced.
|
|
20
|
+
*
|
|
21
|
+
* `baseUrl` is the provider file's address for a host that speaks the
|
|
22
|
+
* same API, such as `https://api.z.ai/api/anthropic`. The bridge sends
|
|
23
|
+
* this agent's calls, and the key, to that one origin only; without it,
|
|
24
|
+
* to the API's own host. The host has already checked that the key may
|
|
25
|
+
* go there (the workspace's trust and the key's allowed addresses).
|
|
26
|
+
*
|
|
27
|
+
* `providerId` is the id of the provider file the key comes from, such
|
|
28
|
+
* as `zai`. The bridge names it as the call's `provider` in `llm.request`
|
|
29
|
+
* and `llm.response`, so the run log shows where the call went; without
|
|
30
|
+
* it, the API's own name (`anthropic`, `openai`).
|
|
31
|
+
*
|
|
32
|
+
* `models` are the models the host resolved for this agent at this
|
|
33
|
+
* provider: its alias's model, and the models of its fallbacks that use
|
|
34
|
+
* the same provider file. The bridge refuses, before it reads the key, a
|
|
35
|
+
* call that names any other model, exactly as written, a call that names
|
|
36
|
+
* other models of its own (Messages' `fallbacks`, or a tool with its own
|
|
37
|
+
* `model`), so the key is spent only on models the host priced. With a
|
|
38
|
+
* `baseUrl`, it also refuses every call when the list is missing or
|
|
39
|
+
* empty, since a compatible provider can serve models that reach the
|
|
40
|
+
* network from its own side. Without a `baseUrl`, a missing list still
|
|
41
|
+
* lets any model through, until every host sends one (HAL-12488).
|
|
16
42
|
*/
|
|
17
43
|
{
|
|
18
44
|
kind: "key";
|
|
19
45
|
secret: string;
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
providerId?: string;
|
|
48
|
+
models?: readonly string[];
|
|
20
49
|
}
|
|
21
50
|
/**
|
|
22
51
|
* With the person's own subscription: the bridge passes the program's own
|
|
@@ -29,13 +58,22 @@ export type BridgeProviderAccess =
|
|
|
29
58
|
| {
|
|
30
59
|
kind: "sign-in";
|
|
31
60
|
};
|
|
32
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* What is recorded of the bridge: the model calls and Halonic tool calls that
|
|
63
|
+
* go through it, and the failures it told the program the run log has the
|
|
64
|
+
* details of (`bridge.failed`, from {@link HarnessBridgeOptions.reportError}).
|
|
65
|
+
*/
|
|
33
66
|
export type BridgeEvent = Extract<HarnessEvent, {
|
|
34
67
|
type: "llm.request" | "llm.response" | "tool.called" | "tool.result";
|
|
68
|
+
}> | Extract<RunEventBody, {
|
|
69
|
+
type: "bridge.failed";
|
|
35
70
|
}>;
|
|
36
71
|
/** Writes the bridge's events to the run's log. The engine adds `runId`, `seq`, `at` and the `state`. */
|
|
37
72
|
export interface BridgeRecorder {
|
|
38
73
|
/**
|
|
74
|
+
* A `bridge.failed` never counts towards the budget, so recording one never
|
|
75
|
+
* throws `limit_reached`.
|
|
76
|
+
*
|
|
39
77
|
* @throws KindedError `limit_reached` for an `llm.request` once the run's
|
|
40
78
|
* budget is reached: the bridge then sends the model call nowhere and
|
|
41
79
|
* answers the program with 429 and the error's message
|
|
@@ -46,13 +84,15 @@ export interface BridgeRecorder {
|
|
|
46
84
|
* What to do with a tool call before it runs, by the same rules as the
|
|
47
85
|
* built-in loop: the agent's `allow` and `approve` lists, the connection's
|
|
48
86
|
* "allow sending" setting and the workspace's trust. `ask`: run it only once
|
|
49
|
-
* a person says yes
|
|
87
|
+
* a person says yes; `connector` names the connector the tool comes from,
|
|
88
|
+
* when it comes from one, for the approval's record. `refused`: don't run it; `reason` goes back to the
|
|
50
89
|
* program as the call's result.
|
|
51
90
|
*/
|
|
52
91
|
export type BridgeToolCheck = {
|
|
53
92
|
kind: "run";
|
|
54
93
|
} | {
|
|
55
94
|
kind: "ask";
|
|
95
|
+
connector?: string;
|
|
56
96
|
} | {
|
|
57
97
|
kind: "refused";
|
|
58
98
|
reason: string;
|
|
@@ -85,6 +125,8 @@ export interface BridgeApprovalRequest {
|
|
|
85
125
|
/** Unique in the run; the bridge makes it up. */
|
|
86
126
|
callId: string;
|
|
87
127
|
tool: string;
|
|
128
|
+
/** The connector the tool comes from, when it comes from one; `tool` stays the bare name. */
|
|
129
|
+
connector?: string;
|
|
88
130
|
args: unknown;
|
|
89
131
|
}
|
|
90
132
|
/** A person's answer to a {@link BridgeApprovalRequest}. */
|
|
@@ -124,6 +166,15 @@ export interface HarnessBridgeOptions {
|
|
|
124
166
|
recorder: BridgeRecorder;
|
|
125
167
|
tools: BridgeTools;
|
|
126
168
|
approvals: BridgeApprovals;
|
|
169
|
+
/**
|
|
170
|
+
* Hears of a request that failed for a reason the bridge doesn't name to the
|
|
171
|
+
* program, so the run log can hold what the program was told is there.
|
|
172
|
+
* `kind` is the error kind of `@halonicjs/std`; `message` never holds the run token. It must not throw.
|
|
173
|
+
*/
|
|
174
|
+
reportError?(failure: {
|
|
175
|
+
kind: string;
|
|
176
|
+
message: string;
|
|
177
|
+
}): void;
|
|
127
178
|
/** Aborting it closes the bridge, as {@link OpenHarnessBridge.close} does. */
|
|
128
179
|
signal?: AbortSignal;
|
|
129
180
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentResume, RunEventBody, RunEventType } from "../../events/src/index.js";
|
|
2
|
+
import type { BridgeProvider } from "./harness-bridge-server.js";
|
|
2
3
|
import type { SandboxProfile, SandboxSession } from "./sandbox.js";
|
|
3
4
|
/** Version of the {@link Harness} port. A breaking change bumps it and comes with an ADR. */
|
|
4
5
|
export declare const harnessVersion = 3;
|
|
@@ -75,10 +76,28 @@ export interface HarnessTask {
|
|
|
75
76
|
agentId: string;
|
|
76
77
|
/** The agent's instructions from its file; empty when it has none. */
|
|
77
78
|
instructions: string;
|
|
79
|
+
/**
|
|
80
|
+
* The run's own folder of pinned instruction files, which the sandbox
|
|
81
|
+
* opens read-only: `AGENTS.md` and each selected skill as
|
|
82
|
+
* `skills/<id>/SKILL.md`. Absent when the agent has none. The harness
|
|
83
|
+
* hands the skills to its program and never writes in the folder.
|
|
84
|
+
*/
|
|
85
|
+
instructionsFolder?: string;
|
|
78
86
|
/** What the agent is asked to do in this run: the task step's prompt, or the chat message. */
|
|
79
87
|
prompt: string;
|
|
80
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* The model the agent's file names, or for a `models.yaml` alias its
|
|
90
|
+
* provider's model id; the harness's own default when absent.
|
|
91
|
+
*/
|
|
81
92
|
model?: string;
|
|
93
|
+
/**
|
|
94
|
+
* True when `model` came from an alias: the file named exactly one model,
|
|
95
|
+
* so the harness uses it for every call of its program, its background
|
|
96
|
+
* and subagent calls too, rather than the program's own smaller models,
|
|
97
|
+
* which a compatible provider doesn't have. Absent for a name the program
|
|
98
|
+
* resolves itself, such as `sonnet`.
|
|
99
|
+
*/
|
|
100
|
+
modelForEveryCall?: true;
|
|
82
101
|
}
|
|
83
102
|
/**
|
|
84
103
|
* The request header that carries the run's bridge token. The token has a
|
|
@@ -111,6 +130,14 @@ export interface HarnessBridge {
|
|
|
111
130
|
* one instead of a loopback port. Absent for a loopback bridge.
|
|
112
131
|
*/
|
|
113
132
|
socketPath?: string;
|
|
133
|
+
/**
|
|
134
|
+
* The providers this bridge calls with a key Halonic keeps, which it puts
|
|
135
|
+
* in place of the program's own (requirement `harness-bridge.key-providers`).
|
|
136
|
+
* A program that won't call its model without a key of its own, such as
|
|
137
|
+
* Claude Code, then gets a stand-in that holds no secret. Absent when every
|
|
138
|
+
* provider is reached with the program's own sign-in.
|
|
139
|
+
*/
|
|
140
|
+
keyProviders?: readonly BridgeProvider[];
|
|
114
141
|
}
|
|
115
142
|
/** The body of the run log event with this `type`. */
|
|
116
143
|
type RunEventOf<Type extends RunEventType> = Extract<RunEventBody, {
|
|
@@ -228,9 +255,13 @@ export interface Harness {
|
|
|
228
255
|
* with {@link addHarnessEnvironment}, so `session.profile` stays exactly
|
|
229
256
|
* what the program gets.
|
|
230
257
|
*
|
|
258
|
+
* `model` is the task's model, which the engine knows before the sandbox
|
|
259
|
+
* opens, so a harness can point its program's background models at it
|
|
260
|
+
* when `modelForEveryCall` is set. Left out, the task names no model.
|
|
261
|
+
*
|
|
231
262
|
* Optional: the built-in loop starts no program, so it has none.
|
|
232
263
|
*/
|
|
233
|
-
environment?(bridge: HarnessBridge, folders: Pick<SandboxProfile, "workingFolder" | "tempFolder" | "settingsFolder">): Record<string, string>;
|
|
264
|
+
environment?(bridge: HarnessBridge, folders: Pick<SandboxProfile, "workingFolder" | "tempFolder" | "settingsFolder">, model?: Pick<HarnessTask, "model" | "modelForEveryCall">): Record<string, string>;
|
|
234
265
|
/**
|
|
235
266
|
* Starts the agent on `task` inside the sandbox `session`, pointed at the
|
|
236
267
|
* run's `bridge`. Returns at once; a program that can't start ends the
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a remote {@link RunExecutor.send} throws, sending nothing, when the answer names a wait
|
|
3
|
+
* step and the host is too old to check it (requirement `ports.host-too-old`). A caller that
|
|
4
|
+
* answers a person, such as an Inbox card, can then ask to update the host instead of offering
|
|
5
|
+
* a **Try again** that can't work.
|
|
6
|
+
*
|
|
7
|
+
* It is a `RangeError`, as the refusal threw before, so a caller that caught that still does.
|
|
8
|
+
* Check for it with {@link isHostTooOld}, not `instanceof`: an executor may be built against its
|
|
9
|
+
* own copy of this package.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* throw new HostTooOld("This host is too old to check which wait step an answer is for.");
|
|
13
|
+
*/
|
|
14
|
+
export declare class HostTooOld extends RangeError {
|
|
15
|
+
readonly name = "HostTooOld";
|
|
16
|
+
/** @param message - safe to log; Studio shows its own words for it */
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether `value` is a {@link HostTooOld}: an `Error` named "HostTooOld". It works across copies
|
|
21
|
+
* of this package, where `instanceof` doesn't.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isHostTooOld(value: unknown): value is HostTooOld;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a remote {@link RunExecutor.send} throws, sending nothing, when the answer names a wait
|
|
3
|
+
* step and the host is too old to check it (requirement `ports.host-too-old`). A caller that
|
|
4
|
+
* answers a person, such as an Inbox card, can then ask to update the host instead of offering
|
|
5
|
+
* a **Try again** that can't work.
|
|
6
|
+
*
|
|
7
|
+
* It is a `RangeError`, as the refusal threw before, so a caller that caught that still does.
|
|
8
|
+
* Check for it with {@link isHostTooOld}, not `instanceof`: an executor may be built against its
|
|
9
|
+
* own copy of this package.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* throw new HostTooOld("This host is too old to check which wait step an answer is for.");
|
|
13
|
+
*/
|
|
14
|
+
export class HostTooOld extends RangeError {
|
|
15
|
+
name = "HostTooOld";
|
|
16
|
+
/** @param message - safe to log; Studio shows its own words for it */
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether `value` is a {@link HostTooOld}: an `Error` named "HostTooOld". It works across copies
|
|
23
|
+
* of this package, where `instanceof` doesn't.
|
|
24
|
+
*/
|
|
25
|
+
export function isHostTooOld(value) {
|
|
26
|
+
return value instanceof Error && value.name === "HostTooOld";
|
|
27
|
+
}
|