@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { passesNameRule } from "../../../../ports/src/index.js";
|
|
1
|
+
import { isHalonicSecretName, isPluginSecretName, passesNameRule } from "../../../../ports/src/index.js";
|
|
2
2
|
import { isSecretVariableName } from "../../../../std/src/index.js";
|
|
3
3
|
import { checkKeysIn } from "../../shared/key-in-value.js";
|
|
4
4
|
import { checkSecretName, looksLikeKey } from "../../shared/secret-name.js";
|
|
@@ -39,9 +39,30 @@ function secretNames(connector) {
|
|
|
39
39
|
}
|
|
40
40
|
return names;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
/*
|
|
43
|
+
* The words are the team's, next to `secret-name.ts`: a small wording on a
|
|
44
|
+
* check the board already approved (HAL-11237).
|
|
45
|
+
*/
|
|
46
|
+
const reservedNameMessage = "This secret name belongs to Halonic or to a plugin, so a connector can't use it. Store the value under a name of your own, such as my-service-key.";
|
|
47
|
+
/**
|
|
48
|
+
* The secrets are named in the file, so a bad name or a pasted key is caught
|
|
49
|
+
* here, not at run time. A name that belongs to Halonic (`token-key`,
|
|
50
|
+
* `serve-password`) or to a plugin is refused too: the file is the
|
|
51
|
+
* workspace's, and what it names reaches a program or a server.
|
|
52
|
+
*/
|
|
43
53
|
function checkSecretNames(connector) {
|
|
44
|
-
return secretNames(connector).flatMap(([name, path]) =>
|
|
54
|
+
return secretNames(connector).flatMap(([name, path]) => {
|
|
55
|
+
const problem = checkSecretName(name, path);
|
|
56
|
+
if (problem !== undefined) {
|
|
57
|
+
return [problem];
|
|
58
|
+
}
|
|
59
|
+
if (isHalonicSecretName(name) || isPluginSecretName(name)) {
|
|
60
|
+
return [
|
|
61
|
+
{ severity: "error", code: "secret-name-reserved", path, message: reservedNameMessage },
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
});
|
|
45
66
|
}
|
|
46
67
|
/**
|
|
47
68
|
* A Google connector's `client` and `secret` name no secret. The account's
|
|
@@ -72,3 +72,17 @@ export declare function needsApproval(tools: Pick<Connector["tools"], "approve">
|
|
|
72
72
|
* marksRead({ approve: [] }, "search_issues"); // false
|
|
73
73
|
*/
|
|
74
74
|
export declare function marksRead(tools: Pick<Connector["tools"], "approve" | "read">, tool: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether every call to `tool` waits for a person: the rule the engine
|
|
77
|
+
* counts a listed tool's risk by, so `halonic tools review` and Studio say
|
|
78
|
+
* what a run then does. A tool runs without asking only when the workspace
|
|
79
|
+
* marks it as only reading ({@link marksRead}) and its listing doesn't say
|
|
80
|
+
* `send`: a server can raise its tool's risk, and the `read` list can't lower
|
|
81
|
+
* `send`. `listedRisk` is the risk its listing gives, absent when it gives none.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* asksBeforeEachUse({ approve: [] }, "lookup"); // true
|
|
85
|
+
* asksBeforeEachUse({ approve: [], read: ["lookup"] }, "lookup"); // false
|
|
86
|
+
* asksBeforeEachUse({ approve: [], read: ["mail"] }, "mail", "send"); // true
|
|
87
|
+
*/
|
|
88
|
+
export declare function asksBeforeEachUse(tools: Pick<Connector["tools"], "approve" | "read">, tool: string, listedRisk?: "read" | "write" | "send"): boolean;
|
|
@@ -141,3 +141,21 @@ export function needsApproval(tools, tool) {
|
|
|
141
141
|
export function marksRead(tools, tool) {
|
|
142
142
|
return (tools.read?.includes(tool) ?? false) && !needsApproval(tools, tool);
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Whether every call to `tool` waits for a person: the rule the engine
|
|
146
|
+
* counts a listed tool's risk by, so `halonic tools review` and Studio say
|
|
147
|
+
* what a run then does. A tool runs without asking only when the workspace
|
|
148
|
+
* marks it as only reading ({@link marksRead}) and its listing doesn't say
|
|
149
|
+
* `send`: a server can raise its tool's risk, and the `read` list can't lower
|
|
150
|
+
* `send`. `listedRisk` is the risk its listing gives, absent when it gives none.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* asksBeforeEachUse({ approve: [] }, "lookup"); // true
|
|
154
|
+
* asksBeforeEachUse({ approve: [], read: ["lookup"] }, "lookup"); // false
|
|
155
|
+
* asksBeforeEachUse({ approve: [], read: ["mail"] }, "mail", "send"); // true
|
|
156
|
+
*/
|
|
157
|
+
export function asksBeforeEachUse(tools, tool,
|
|
158
|
+
// Written out rather than ports' `ToolRisk`: the connector entry imports only schema-kit and std.
|
|
159
|
+
listedRisk) {
|
|
160
|
+
return listedRisk === "send" || !marksRead(tools, tool);
|
|
161
|
+
}
|
|
@@ -9,7 +9,7 @@ import { s } from "../../../../schema-kit/src/index.js";
|
|
|
9
9
|
export const INTEGRATION_NAME_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
10
|
const name = s
|
|
11
11
|
.string()
|
|
12
|
-
.regex(INTEGRATION_NAME_PATTERN, "use lower-case words joined by '-', such as 'weather-key'");
|
|
12
|
+
.regex(INTEGRATION_NAME_PATTERN, "use lower-case words joined by '-', such as 'weather' or 'weather-key'");
|
|
13
13
|
/**
|
|
14
14
|
* A host name in lower case, with at least one dot and a top-level name of
|
|
15
15
|
* letters, and an optional `:port`. No scheme, no path, no wildcards and no
|
|
@@ -4,7 +4,8 @@ import { type IntegrationSheet } from "./schema.js";
|
|
|
4
4
|
* The rules over a sheet's `signIns` and their client secrets: the sheet
|
|
5
5
|
* says `kit: 2`; the access token goes only to hosts the sheet declares; a
|
|
6
6
|
* `{ fromSetting }` URL reads a public host the sheet declares; Halonic's own
|
|
7
|
-
* authorize parameters stay Halonic's;
|
|
7
|
+
* authorize parameters stay Halonic's; a `revokeUrl` is on the host of the
|
|
8
|
+
* sign-in's `tokenUrl` or `authorizeUrl`; and a client secret has no hosts of
|
|
8
9
|
* its own and belongs to exactly one sign-in.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hostKey } from "./host-key.js";
|
|
2
|
-
import { isPlacedSecret } from "./schema.js";
|
|
2
|
+
import { isPlacedSecret, } from "./schema.js";
|
|
3
3
|
import { fixedSignInUrl, queryParameterNames, RESERVED_AUTHORIZE_PARAMETERS, } from "./sign-in-urls.js";
|
|
4
4
|
/** The first `kit` that has `signIns`. */
|
|
5
5
|
const SIGN_IN_KIT = 2;
|
|
@@ -14,7 +14,8 @@ const URL_FIELDS = [
|
|
|
14
14
|
* The rules over a sheet's `signIns` and their client secrets: the sheet
|
|
15
15
|
* says `kit: 2`; the access token goes only to hosts the sheet declares; a
|
|
16
16
|
* `{ fromSetting }` URL reads a public host the sheet declares; Halonic's own
|
|
17
|
-
* authorize parameters stay Halonic's;
|
|
17
|
+
* authorize parameters stay Halonic's; a `revokeUrl` is on the host of the
|
|
18
|
+
* sign-in's `tokenUrl` or `authorizeUrl`; and a client secret has no hosts of
|
|
18
19
|
* its own and belongs to exactly one sign-in.
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
@@ -24,7 +25,7 @@ export function checkSignIns(sheet) {
|
|
|
24
25
|
const entries = Object.entries(sheet.signIns);
|
|
25
26
|
const problems = [...kitProblems(sheet, entries.length)];
|
|
26
27
|
for (const [name, signIn] of entries) {
|
|
27
|
-
problems.push(...accessHostProblems(sheet, name, signIn), ...urlProblems(sheet, name, signIn));
|
|
28
|
+
problems.push(...accessHostProblems(sheet, name, signIn), ...urlProblems(sheet, name, signIn), ...revokeHostProblems(sheet, name, signIn));
|
|
28
29
|
}
|
|
29
30
|
problems.push(...clientSecretProblems(sheet));
|
|
30
31
|
return problems;
|
|
@@ -73,6 +74,35 @@ function urlProblems(sheet, name, signIn) {
|
|
|
73
74
|
}
|
|
74
75
|
return problems;
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A `revokeUrl` is on the host of the sign-in's `tokenUrl` or `authorizeUrl`.
|
|
79
|
+
* Sign-out sends it the refresh token, and the client secret too, so a third
|
|
80
|
+
* host would get them without the person having seen it in the trust check.
|
|
81
|
+
*/
|
|
82
|
+
function revokeHostProblems(sheet, name, signIn) {
|
|
83
|
+
if (signIn.revokeUrl === undefined) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const revokeHost = endpointHost(signIn.revokeUrl);
|
|
87
|
+
if ([signIn.tokenUrl, signIn.authorizeUrl].some((url) => endpointHost(url) === revokeHost)) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return [
|
|
91
|
+
problemAt(sheet, "sign-in-revoke-host", ["signIns", name, "revokeUrl"], `the revokeUrl of "${name}" must be on the host of its tokenUrl or authorizeUrl`),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Where a sign-in URL goes, as one text to compare: its host in lower case
|
|
96
|
+
* and without the default port, or the setting it reads.
|
|
97
|
+
*/
|
|
98
|
+
function endpointHost(url) {
|
|
99
|
+
const fixed = fixedSignInUrl(url);
|
|
100
|
+
if (fixed === undefined) {
|
|
101
|
+
return typeof url === "string" ? url : `fromSetting ${url.fromSetting}`;
|
|
102
|
+
}
|
|
103
|
+
const host = fixed.host.toLowerCase();
|
|
104
|
+
return host.endsWith(":443") ? host.slice(0, -4) : host;
|
|
105
|
+
}
|
|
76
106
|
/**
|
|
77
107
|
* A client secret is declared without `hosts` and `as`, named by exactly one
|
|
78
108
|
* sign-in, and every such secret is named by one.
|
|
@@ -4,8 +4,9 @@ import { type Plugin } from "./schema.js";
|
|
|
4
4
|
* The rules over several fields of a plugin: it has a backend or local
|
|
5
5
|
* tools, its id and secret names aren't too long, its backend passes the
|
|
6
6
|
* integration sheet's checks and starts no program, no id is used twice, no tool or secret name is in two parts, a
|
|
7
|
-
* local tool's environment names its own secrets and the plugin's settings
|
|
8
|
-
* and its `ui` names
|
|
7
|
+
* local tool's environment names its own secrets and the plugin's settings
|
|
8
|
+
* and sets none of the variables Halonic sets itself, and its `ui` names
|
|
9
|
+
* what the plugin declares.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* checkPlugin(plugin); // [] for the weather plugin in the ADR
|
|
@@ -7,8 +7,9 @@ import { uiProblems } from "./ui-checks.js";
|
|
|
7
7
|
* The rules over several fields of a plugin: it has a backend or local
|
|
8
8
|
* tools, its id and secret names aren't too long, its backend passes the
|
|
9
9
|
* integration sheet's checks and starts no program, no id is used twice, no tool or secret name is in two parts, a
|
|
10
|
-
* local tool's environment names its own secrets and the plugin's settings
|
|
11
|
-
* and its `ui` names
|
|
10
|
+
* local tool's environment names its own secrets and the plugin's settings
|
|
11
|
+
* and sets none of the variables Halonic sets itself, and its `ui` names
|
|
12
|
+
* what the plugin declares.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* checkPlugin(plugin); // [] for the weather plugin in the ADR
|
|
@@ -87,15 +88,26 @@ function localToolProblems(plugin) {
|
|
|
87
88
|
return problems;
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
|
|
91
|
+
* The variables Halonic sets itself for every local tool: its `PATH`, and
|
|
92
|
+
* its home and temp folders inside the session.
|
|
93
|
+
*/
|
|
94
|
+
const halonicVariables = new Set(["HOME", "PATH", "TMPDIR", "TEMP", "TMP"]);
|
|
95
|
+
/**
|
|
96
|
+
* An `env` variable isn't one Halonic sets itself. Its value names one of
|
|
97
|
+
* this local tool's own secrets, never another part's, so a secret reaches
|
|
98
|
+
* only the program it was declared for. A setting it names exists and isn't
|
|
99
|
+
* a `secret` field: secrets go by `secret`.
|
|
93
100
|
*/
|
|
94
101
|
function envProblems(plugin, localTool, index) {
|
|
95
102
|
const settings = plugin.ui?.settings ?? {};
|
|
96
103
|
const problems = [];
|
|
97
104
|
for (const [variable, value] of Object.entries(localTool.env)) {
|
|
98
105
|
const path = ["localTools", index, "env", variable];
|
|
106
|
+
if (halonicVariables.has(variable)) {
|
|
107
|
+
const message = `${variable} is set by Halonic for every local tool; use another name`;
|
|
108
|
+
problems.push(problem(plugin, "env-reserved", path, message));
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
99
111
|
if ("secret" in value) {
|
|
100
112
|
if (!Object.hasOwn(localTool.secrets, value.secret)) {
|
|
101
113
|
const message = `${variable} takes the secret ${value.secret}, which local tool "${localTool.id}" doesn't declare in its secrets`;
|
|
@@ -18,8 +18,23 @@ export const ARGUMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
|
18
18
|
const argumentName = s
|
|
19
19
|
.string()
|
|
20
20
|
.regex(ARGUMENT_NAME_PATTERN, "use the tool argument's name, such as 'city' or 'folderId'");
|
|
21
|
+
/**
|
|
22
|
+
* A control character, or a mark that turns the direction of the text around it.
|
|
23
|
+
* In text a person reads, either can make one name look like another, in the
|
|
24
|
+
* Plugins list and in the trust dialog. A line break is the one exception, and
|
|
25
|
+
* only in longer text.
|
|
26
|
+
*/
|
|
27
|
+
const HIDDEN_MARK = /[\p{Cc}\p{Bidi_Control}]/u;
|
|
28
|
+
const HIDDEN_MARK_BUT_LINE_BREAK = /(?!\n)[\p{Cc}\p{Bidi_Control}]/u;
|
|
29
|
+
const NO_HIDDEN_MARKS = "don't use control characters or text-direction marks";
|
|
30
|
+
/** Whether a description or help text has no hidden mark. It may break lines. */
|
|
31
|
+
const withoutHiddenMarks = (text) => !HIDDEN_MARK_BUT_LINE_BREAK.test(text);
|
|
21
32
|
/** Text a person reads: a title or a label. Studio shows it as untrusted text. */
|
|
22
|
-
const label = s
|
|
33
|
+
const label = s
|
|
34
|
+
.string()
|
|
35
|
+
.min(1)
|
|
36
|
+
.max(80)
|
|
37
|
+
.refine((text) => !HIDDEN_MARK.test(text), NO_HIDDEN_MARKS);
|
|
23
38
|
/**
|
|
24
39
|
* Why a local tool's `network` entry can't be used, or `null` when it can.
|
|
25
40
|
* The list is the sandbox's allow-list for code Halonic doesn't trust, so it
|
|
@@ -179,7 +194,7 @@ const LocalTool = s
|
|
|
179
194
|
/** What every field says, whatever its type. */
|
|
180
195
|
const fieldBase = {
|
|
181
196
|
label,
|
|
182
|
-
help: s.string().min(1).max(500).optional(),
|
|
197
|
+
help: s.string().min(1).max(500).refine(withoutHiddenMarks, NO_HIDDEN_MARKS).optional(),
|
|
183
198
|
required: s.boolean().default(false),
|
|
184
199
|
};
|
|
185
200
|
/** The field types a setting and a command's form share. */
|
|
@@ -192,7 +207,12 @@ const inputFields = [
|
|
|
192
207
|
.object({
|
|
193
208
|
...fieldBase,
|
|
194
209
|
type: s.literal("choice"),
|
|
195
|
-
choices: s
|
|
210
|
+
choices: s
|
|
211
|
+
.array(s
|
|
212
|
+
.string()
|
|
213
|
+
.min(1)
|
|
214
|
+
.refine((text) => !HIDDEN_MARK.test(text), NO_HIDDEN_MARKS))
|
|
215
|
+
.min(1),
|
|
196
216
|
default: s.string().optional(),
|
|
197
217
|
})
|
|
198
218
|
.strict(),
|
|
@@ -253,7 +273,7 @@ export const Plugin = s
|
|
|
253
273
|
sdk: IntegrationSheet.shape.kit,
|
|
254
274
|
name: label,
|
|
255
275
|
/** Empty for an `integration.yaml` read as a plugin, which has no description. */
|
|
256
|
-
description: s.string().max(500).default(""),
|
|
276
|
+
description: s.string().max(500).refine(withoutHiddenMarks, NO_HIDDEN_MARKS).default(""),
|
|
257
277
|
backend: Backend.optional(),
|
|
258
278
|
localTools: s.array(LocalTool).min(1).optional(),
|
|
259
279
|
ui: Ui.optional(),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { checkKeysIn } from "../../shared/key-in-value.js";
|
|
2
2
|
import { checkSecretName } from "../../shared/secret-name.js";
|
|
3
3
|
import { Provider } from "./schema.js";
|
|
4
|
+
import { isProviderType, providerTypesInWords } from "./types.js";
|
|
4
5
|
/** `providers/<id>.yaml` at the workspace root. */
|
|
5
6
|
export const providerKind = {
|
|
6
7
|
name: "provider",
|
|
@@ -13,12 +14,50 @@ export const providerKind = {
|
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* The secret is named in the file, so a bad name or a pasted key is caught
|
|
16
|
-
* here, not at run time. A key pasted into `options` is caught too
|
|
17
|
+
* here, not at run time. A key pasted into `options` is caught too, and so
|
|
18
|
+
* is a type Halonic can't call, or a `baseUrl` it can't reach, which would
|
|
19
|
+
* only fail once a run reached the model (HAL-14260).
|
|
17
20
|
*/
|
|
18
21
|
function checkProvider(provider) {
|
|
19
22
|
const problem = provider.secret === undefined ? undefined : checkSecretName(provider.secret, ["secret"]);
|
|
20
23
|
return [
|
|
24
|
+
...checkType(provider),
|
|
25
|
+
...checkBaseUrl(provider),
|
|
21
26
|
...(problem === undefined ? [] : [problem]),
|
|
22
27
|
...checkKeysIn(provider.options, ["options"], "provider-option"),
|
|
23
28
|
];
|
|
24
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* `provider-type` on the `type:` line, worded like the run's fix:
|
|
32
|
+
* "Halonic can't call provider type antropic: set type in
|
|
33
|
+
* providers/mock.yaml to one of anthropic, … or mock".
|
|
34
|
+
*/
|
|
35
|
+
function checkType(provider) {
|
|
36
|
+
if (isProviderType(provider.type))
|
|
37
|
+
return [];
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
severity: "error",
|
|
41
|
+
code: "provider-type",
|
|
42
|
+
path: ["type"],
|
|
43
|
+
message: `Halonic can't call provider type ${provider.type}: set type in providers/${provider.id}.yaml to one of ${providerTypesInWords}`,
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `provider-base-url` on the `baseUrl:` line when it doesn't start with
|
|
49
|
+
* http:// or https://. `localhost:11434` passes as a URL, but its scheme is
|
|
50
|
+
* "localhost:", so the run would try to reach an empty address.
|
|
51
|
+
*/
|
|
52
|
+
function checkBaseUrl(provider) {
|
|
53
|
+
if (provider.baseUrl === undefined || /^https?:\/\//iu.test(provider.baseUrl))
|
|
54
|
+
return [];
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
severity: "error",
|
|
58
|
+
code: "provider-base-url",
|
|
59
|
+
path: ["baseUrl"],
|
|
60
|
+
message: "baseUrl needs http:// or https://, such as http://localhost:11434",
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The types that speak OpenAI's chat completions API. */
|
|
2
|
+
export declare const openAiCompatibleTypes: readonly ["openai", "openai-compatible", "ollama", "lmstudio"];
|
|
3
|
+
/** Every type Halonic can call, in the order a fix lists them. */
|
|
4
|
+
export declare const providerTypes: readonly ["anthropic", "openai", "openai-compatible", "ollama", "lmstudio", "mock"];
|
|
5
|
+
/** One of {@link providerTypes}. */
|
|
6
|
+
export type ProviderType = (typeof providerTypes)[number];
|
|
7
|
+
/**
|
|
8
|
+
* The types as a fix lists them: "anthropic, openai, openai-compatible,
|
|
9
|
+
* ollama, lmstudio or mock".
|
|
10
|
+
*/
|
|
11
|
+
export declare const providerTypesInWords: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether Halonic can call a provider of this type.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* isProviderType("anthropic"); // true
|
|
17
|
+
* isProviderType("antropic"); // false
|
|
18
|
+
*/
|
|
19
|
+
export declare function isProviderType(type: string): type is ProviderType;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The provider types a workspace's provider file can name. The run builds a
|
|
2
|
+
// provider for each of them, and `halonic validate` refuses any other, so
|
|
3
|
+
// both read this one list and can't drift apart (HAL-14260).
|
|
4
|
+
/** The types that speak OpenAI's chat completions API. */
|
|
5
|
+
export const openAiCompatibleTypes = ["openai", "openai-compatible", "ollama", "lmstudio"];
|
|
6
|
+
/** Every type Halonic can call, in the order a fix lists them. */
|
|
7
|
+
export const providerTypes = ["anthropic", ...openAiCompatibleTypes, "mock"];
|
|
8
|
+
/**
|
|
9
|
+
* The types as a fix lists them: "anthropic, openai, openai-compatible,
|
|
10
|
+
* ollama, lmstudio or mock".
|
|
11
|
+
*/
|
|
12
|
+
export const providerTypesInWords = `${providerTypes.slice(0, -1).join(", ")} or ${providerTypes.at(-1)}`;
|
|
13
|
+
/**
|
|
14
|
+
* Whether Halonic can call a provider of this type.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* isProviderType("anthropic"); // true
|
|
18
|
+
* isProviderType("antropic"); // false
|
|
19
|
+
*/
|
|
20
|
+
export function isProviderType(type) {
|
|
21
|
+
return providerTypes.includes(type);
|
|
22
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { type Infer } from "../../../../schema-kit/src/index.js";
|
|
2
2
|
import { Guard } from "../../shared/guard.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* When a routine starts. A trigger that matches none of the kinds, such as
|
|
5
|
+
* two at once or `manual: false`, gets one message that names them all
|
|
6
|
+
* (HAL-14299), instead of Zod's "Invalid input". A mistake inside one kind,
|
|
7
|
+
* such as `every: 15`, still gets that kind's own message.
|
|
8
|
+
*/
|
|
4
9
|
export declare const RoutineTrigger: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
5
10
|
schedule: import("zod").ZodString;
|
|
6
11
|
timezone: import("zod").ZodOptional<import("zod").ZodString>;
|
|
7
12
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
8
|
-
every: import("zod").ZodString
|
|
13
|
+
every: import("zod").ZodPreprocess<import("zod").ZodString, unknown>;
|
|
9
14
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
10
15
|
manual: import("zod").ZodLiteral<true>;
|
|
11
16
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
@@ -17,7 +22,7 @@ export declare const RoutineTrigger: import("zod").ZodUnion<readonly [import("zo
|
|
|
17
22
|
mail: import("zod").ZodObject<{
|
|
18
23
|
connector: import("zod").ZodString;
|
|
19
24
|
query: import("zod").ZodDefault<import("zod").ZodString>;
|
|
20
|
-
every: import("zod").ZodDefault<import("zod").ZodString>;
|
|
25
|
+
every: import("zod").ZodPreprocess<import("zod").ZodDefault<import("zod").ZodString>, unknown>;
|
|
21
26
|
}, import("zod/v4/core").$strict>;
|
|
22
27
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
23
28
|
webhook: import("zod").ZodObject<{
|
|
@@ -46,7 +51,7 @@ export declare const Routine: import("zod").ZodObject<{
|
|
|
46
51
|
schedule: import("zod").ZodString;
|
|
47
52
|
timezone: import("zod").ZodOptional<import("zod").ZodString>;
|
|
48
53
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
49
|
-
every: import("zod").ZodString
|
|
54
|
+
every: import("zod").ZodPreprocess<import("zod").ZodString, unknown>;
|
|
50
55
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
51
56
|
manual: import("zod").ZodLiteral<true>;
|
|
52
57
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
@@ -58,7 +63,7 @@ export declare const Routine: import("zod").ZodObject<{
|
|
|
58
63
|
mail: import("zod").ZodObject<{
|
|
59
64
|
connector: import("zod").ZodString;
|
|
60
65
|
query: import("zod").ZodDefault<import("zod").ZodString>;
|
|
61
|
-
every: import("zod").ZodDefault<import("zod").ZodString>;
|
|
66
|
+
every: import("zod").ZodPreprocess<import("zod").ZodDefault<import("zod").ZodString>, unknown>;
|
|
62
67
|
}, import("zod/v4/core").$strict>;
|
|
63
68
|
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
64
69
|
webhook: import("zod").ZodObject<{
|
|
@@ -2,6 +2,13 @@ import { s } from "../../../../schema-kit/src/index.js";
|
|
|
2
2
|
import { DURATION_PATTERN, id, version } from "../../shared/fields.js";
|
|
3
3
|
import { Guard } from "../../shared/guard.js";
|
|
4
4
|
import { WEBHOOK_HEADER_PATTERN } from "./webhook-headers.js";
|
|
5
|
+
/**
|
|
6
|
+
* Reads a number as text, for an interval such as "15m". YAML reads
|
|
7
|
+
* `every: 15` as a number; as the text "15" it gets the interval's message
|
|
8
|
+
* for a count without a unit, instead of failing the whole trigger
|
|
9
|
+
* (HAL-12607). No number passes: the pattern needs a unit.
|
|
10
|
+
*/
|
|
11
|
+
const numberAsText = (value) => (typeof value === "number" ? String(value) : value);
|
|
5
12
|
/** On a schedule: five-field cron or a shortcut such as @daily, in a time zone. */
|
|
6
13
|
const ScheduleTrigger = s
|
|
7
14
|
.object({
|
|
@@ -13,9 +20,9 @@ const ScheduleTrigger = s
|
|
|
13
20
|
/** At a fixed interval. */
|
|
14
21
|
const EveryTrigger = s
|
|
15
22
|
.object({
|
|
16
|
-
every: s
|
|
23
|
+
every: s.preprocess(numberAsText, s
|
|
17
24
|
.string()
|
|
18
|
-
.regex(DURATION_PATTERN, 'use a number and a unit, e.g. "15m", "1h", "1d" (runs are placed from midnight UTC)'),
|
|
25
|
+
.regex(DURATION_PATTERN, 'use a number and a unit, e.g. "15m", "1h", "1d" (runs are placed from midnight UTC)')),
|
|
19
26
|
})
|
|
20
27
|
.strict();
|
|
21
28
|
/** Only when someone starts it. */
|
|
@@ -40,10 +47,7 @@ const MailTrigger = s
|
|
|
40
47
|
* any number of more than one digit, such as "15m"
|
|
41
48
|
* (format.routine-mail-interval).
|
|
42
49
|
*/
|
|
43
|
-
every: s
|
|
44
|
-
.string()
|
|
45
|
-
.regex(DURATION_PATTERN, 'use a number and a unit, e.g. "2m"')
|
|
46
|
-
.default("2m"),
|
|
50
|
+
every: s.preprocess(numberAsText, s.string().regex(DURATION_PATTERN, 'use a number and a unit, e.g. "2m"').default("2m")),
|
|
47
51
|
})
|
|
48
52
|
.strict(),
|
|
49
53
|
})
|
|
@@ -68,15 +72,17 @@ const WebhookTrigger = s
|
|
|
68
72
|
.strict(),
|
|
69
73
|
})
|
|
70
74
|
.strict();
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
/**
|
|
76
|
+
* When a routine starts. A trigger that matches none of the kinds, such as
|
|
77
|
+
* two at once or `manual: false`, gets one message that names them all
|
|
78
|
+
* (HAL-14299), instead of Zod's "Invalid input". A mistake inside one kind,
|
|
79
|
+
* such as `every: 15`, still gets that kind's own message.
|
|
80
|
+
*/
|
|
81
|
+
export const RoutineTrigger = s.union([ScheduleTrigger, EveryTrigger, ManualTrigger, SignalTrigger, MailTrigger, WebhookTrigger], {
|
|
82
|
+
error: (issue) => issue.code === "invalid_union"
|
|
83
|
+
? "trigger needs exactly one of: schedule, every, manual: true, signal, mail or webhook."
|
|
84
|
+
: undefined,
|
|
85
|
+
});
|
|
80
86
|
/** What a routine runs: a workflow with input, or one agent with a prompt. */
|
|
81
87
|
export const RoutineTarget = s.union([
|
|
82
88
|
s
|
|
@@ -33,10 +33,11 @@ export const WorkspaceSettings = s
|
|
|
33
33
|
.strict()
|
|
34
34
|
.default({ localOnly: false }),
|
|
35
35
|
/**
|
|
36
|
-
* Spending limits in `currency`, counted from model prices.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
* Spending limits in `currency`, counted from model prices. The engine
|
|
37
|
+
* stops a run (`run.failed` with the reason `budget`) before a model call
|
|
38
|
+
* once the run has spent `perRun` or the month has spent `monthly`
|
|
39
|
+
* (`engine.budget-stops`). `currency` names the currency the prices in
|
|
40
|
+
* `models.yaml` are written in; Halonic doesn't convert between currencies.
|
|
40
41
|
*/
|
|
41
42
|
budget: s
|
|
42
43
|
.object({
|
|
@@ -2,6 +2,7 @@ import { parse } from "../../schema-kit/src/index.js";
|
|
|
2
2
|
import { err, ok } from "../../std/src/index.js";
|
|
3
3
|
import { fileKinds } from "./registry.js";
|
|
4
4
|
import { isMap } from "./shared/legacy-keys.js";
|
|
5
|
+
import { wordIssues } from "./shared/missing-keys.js";
|
|
5
6
|
import { readSource } from "./source.js";
|
|
6
7
|
/**
|
|
7
8
|
* Reads and checks one workspace file of a known kind.
|
|
@@ -28,7 +29,8 @@ export function parseFile(kind, text, options = {}) {
|
|
|
28
29
|
const prepared = prepare(fileKind, source.data, options.id);
|
|
29
30
|
const parsed = parse(fileKind.schema, prepared.data);
|
|
30
31
|
if (!parsed.ok) {
|
|
31
|
-
const
|
|
32
|
+
const issues = wordIssues(parsed.error, prepared.data);
|
|
33
|
+
const problems = issues.map((issue) => schemaProblem(issue, source));
|
|
32
34
|
return err(prepared.idFromPlace ? problems.map((problem) => namePlaceId(problem, options.id)) : problems);
|
|
33
35
|
}
|
|
34
36
|
const found = fileKind.check?.(parsed.value) ?? [];
|
|
@@ -15,9 +15,16 @@ export declare const agentId: import("zod").ZodString;
|
|
|
15
15
|
* their names.
|
|
16
16
|
*/
|
|
17
17
|
export declare const collectionId: import("zod").ZodString;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The `version` key: `1`, and `1` when the file leaves it out. The message
|
|
20
|
+
* names the one allowed value instead of Zod's "Invalid input: expected 1".
|
|
21
|
+
*/
|
|
19
22
|
export declare const version: import("zod").ZodDefault<import("zod").ZodLiteral<1>>;
|
|
20
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* A whole number of up to five digits and a unit: minutes, hours or days
|
|
25
|
+
* ("30m", "4h", "2d"). The most is 99999 days, about 273 years: longer would
|
|
26
|
+
* leave the range of a date, so no timer could be set for it.
|
|
27
|
+
*/
|
|
21
28
|
export declare const DURATION_PATTERN: RegExp;
|
|
22
29
|
/** Tuning passed to a model (temperature, maxTokens, …). */
|
|
23
30
|
export declare const ModelParams: import("zod").ZodObject<{
|
|
@@ -7,7 +7,7 @@ export const SCHEMA_VERSION = 1;
|
|
|
7
7
|
export const id = s
|
|
8
8
|
.string()
|
|
9
9
|
.min(1)
|
|
10
|
-
.regex(/^[a-z0-9][a-z0-9-_]*$/, "use lowercase letters, digits, '-' or '_'");
|
|
10
|
+
.regex(/^[a-z0-9][a-z0-9-_]*$/, "use lowercase letters, digits, '-' or '_', starting with a letter or digit");
|
|
11
11
|
/**
|
|
12
12
|
* The most characters an id that names a folder may have. A deployment's runs
|
|
13
13
|
* live in `deployments/<id>/runs` and an agent's harness settings in
|
|
@@ -55,11 +55,20 @@ export const agentId = folderId("agent");
|
|
|
55
55
|
*/
|
|
56
56
|
export const collectionId = s
|
|
57
57
|
.string()
|
|
58
|
-
.regex(/^[a-z0-9][a-z0-9-]*$/, "use lowercase letters, digits or '-'");
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
.regex(/^[a-z0-9][a-z0-9-]*$/, "use lowercase letters, digits or '-', starting with a letter or digit");
|
|
59
|
+
/**
|
|
60
|
+
* The `version` key: `1`, and `1` when the file leaves it out. The message
|
|
61
|
+
* names the one allowed value instead of Zod's "Invalid input: expected 1".
|
|
62
|
+
*/
|
|
63
|
+
export const version = s
|
|
64
|
+
.literal(SCHEMA_VERSION, { error: `version must be ${SCHEMA_VERSION}` })
|
|
65
|
+
.default(SCHEMA_VERSION);
|
|
66
|
+
/**
|
|
67
|
+
* A whole number of up to five digits and a unit: minutes, hours or days
|
|
68
|
+
* ("30m", "4h", "2d"). The most is 99999 days, about 273 years: longer would
|
|
69
|
+
* leave the range of a date, so no timer could be set for it.
|
|
70
|
+
*/
|
|
71
|
+
export const DURATION_PATTERN = /^[1-9]\d{0,4}(m|h|d)$/;
|
|
63
72
|
/** Tuning passed to a model (temperature, maxTokens, …). */
|
|
64
73
|
export const ModelParams = s
|
|
65
74
|
.object({
|
|
@@ -28,5 +28,13 @@ export type Guard = {
|
|
|
28
28
|
} | {
|
|
29
29
|
any: Guard[];
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Says what is wrong with a value that is no condition, instead of Zod's
|
|
33
|
+
* "Invalid input": an unknown kind and the allowed ones, or what a known
|
|
34
|
+
* kind takes.
|
|
35
|
+
*/
|
|
36
|
+
export declare function guardProblem(input: unknown): string;
|
|
31
37
|
/** The schema of a `Guard`. It refers to itself for `not`, `all` and `any`. */
|
|
32
38
|
export declare const Guard: Schema<Guard>;
|
|
39
|
+
/** Whether a value is a condition the engine accepts, so callers can check before they write one. */
|
|
40
|
+
export declare function isGuard(value: unknown): value is Guard;
|