@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.
Files changed (122) hide show
  1. package/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
  2. package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
  3. package/dist/adapters/http-kit/src/index.d.ts +2 -0
  4. package/dist/adapters/http-kit/src/index.js +2 -0
  5. package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
  6. package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
  7. package/dist/adapters/integration-kit/src/index.d.ts +2 -1
  8. package/dist/adapters/integration-kit/src/index.js +1 -0
  9. package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
  10. package/dist/adapters/integration-kit/src/loader.js +3 -20
  11. package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
  12. package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
  13. package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
  14. package/dist/core/events/src/connector-listing-failed.js +1 -0
  15. package/dist/core/events/src/home-path.d.ts +4 -1
  16. package/dist/core/events/src/home-path.js +14 -3
  17. package/dist/core/events/src/index.d.ts +4 -2
  18. package/dist/core/events/src/index.js +2 -0
  19. package/dist/core/events/src/provider-notes.d.ts +16 -0
  20. package/dist/core/events/src/provider-notes.js +24 -0
  21. package/dist/core/events/src/run-basics.d.ts +103 -5
  22. package/dist/core/events/src/run-event.d.ts +72 -7
  23. package/dist/core/events/src/run-summary.d.ts +11 -1
  24. package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
  25. package/dist/core/events/src/sandbox-opened-read.js +27 -2
  26. package/dist/core/events/src/sandbox-opened.d.ts +37 -4
  27. package/dist/core/events/src/sandbox-opened.js +13 -3
  28. package/dist/core/events/src/summarize.js +3 -0
  29. package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
  30. package/dist/core/events/src/tool-failure-cause.js +66 -0
  31. package/dist/core/format/src/index.d.ts +3 -2
  32. package/dist/core/format/src/index.js +3 -1
  33. package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
  34. package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
  35. package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
  36. package/dist/core/format/src/kinds/agent/schema.js +3 -0
  37. package/dist/core/format/src/kinds/connector/kind.js +24 -3
  38. package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
  39. package/dist/core/format/src/kinds/connector/schema.js +18 -0
  40. package/dist/core/format/src/kinds/integration/schema.js +1 -1
  41. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
  42. package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
  43. package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
  44. package/dist/core/format/src/kinds/plugin/checks.js +17 -5
  45. package/dist/core/format/src/kinds/plugin/schema.js +24 -4
  46. package/dist/core/format/src/kinds/provider/kind.js +40 -1
  47. package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
  48. package/dist/core/format/src/kinds/provider/types.js +22 -0
  49. package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
  50. package/dist/core/format/src/kinds/routine/schema.js +21 -15
  51. package/dist/core/format/src/kinds/workspace/schema.js +5 -4
  52. package/dist/core/format/src/parse-file.js +3 -1
  53. package/dist/core/format/src/shared/fields.d.ts +9 -2
  54. package/dist/core/format/src/shared/fields.js +15 -6
  55. package/dist/core/format/src/shared/guard.d.ts +8 -0
  56. package/dist/core/format/src/shared/guard.js +50 -1
  57. package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
  58. package/dist/core/format/src/shared/missing-keys.js +110 -0
  59. package/dist/core/ports/src/chat.d.ts +8 -0
  60. package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
  61. package/dist/core/ports/src/connector-start-failure.js +32 -0
  62. package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
  63. package/dist/core/ports/src/connector-tool-error.js +40 -0
  64. package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
  65. package/dist/core/ports/src/definition-store-left-out.js +47 -0
  66. package/dist/core/ports/src/definition-store.d.ts +13 -3
  67. package/dist/core/ports/src/definition-store.js +1 -1
  68. package/dist/core/ports/src/deploy-target.d.ts +358 -0
  69. package/dist/core/ports/src/deploy-target.js +2 -0
  70. package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
  71. package/dist/core/ports/src/harness.d.ts +33 -2
  72. package/dist/core/ports/src/host-too-old.d.ts +23 -0
  73. package/dist/core/ports/src/host-too-old.js +27 -0
  74. package/dist/core/ports/src/index.d.ts +16 -5
  75. package/dist/core/ports/src/index.js +15 -3
  76. package/dist/core/ports/src/llm-provider.d.ts +37 -6
  77. package/dist/core/ports/src/llm-provider.js +43 -3
  78. package/dist/core/ports/src/pairing-codes.d.ts +111 -0
  79. package/dist/core/ports/src/pairing-codes.js +336 -0
  80. package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
  81. package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
  82. package/dist/core/ports/src/port-versions.d.ts +6 -2
  83. package/dist/core/ports/src/port-versions.js +8 -0
  84. package/dist/core/ports/src/remote-control.d.ts +159 -0
  85. package/dist/core/ports/src/remote-control.js +26 -0
  86. package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
  87. package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
  88. package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
  89. package/dist/core/ports/src/remote-gateway-session.js +241 -0
  90. package/dist/core/ports/src/run-executor.d.ts +39 -3
  91. package/dist/core/ports/src/run-executor.js +1 -1
  92. package/dist/core/ports/src/sandbox.d.ts +19 -0
  93. package/dist/core/ports/src/sandbox.js +14 -0
  94. package/dist/core/ports/src/secrets.d.ts +32 -1
  95. package/dist/core/ports/src/secrets.js +19 -2
  96. package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
  97. package/dist/core/ports/src/tunnel-provider.js +65 -0
  98. package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
  99. package/dist/core/ports/src/tunnel-resolver.js +36 -0
  100. package/dist/core/ports/src/vcs.d.ts +30 -0
  101. package/dist/core/schema-kit/src/builders.d.ts +5 -0
  102. package/dist/core/schema-kit/src/builders.js +5 -0
  103. package/dist/core/std/src/hidden-characters.d.ts +9 -0
  104. package/dist/core/std/src/hidden-characters.js +18 -0
  105. package/dist/core/std/src/index.d.ts +3 -1
  106. package/dist/core/std/src/index.js +3 -1
  107. package/dist/core/std/src/path-overlap.d.ts +22 -0
  108. package/dist/core/std/src/path-overlap.js +57 -0
  109. package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
  110. package/dist/core/std/src/public-suffixes.generated.js +0 -1
  111. package/dist/core/std/src/word-diff.d.ts +28 -0
  112. package/dist/core/std/src/word-diff.js +77 -0
  113. package/dist/core/yaml/src/edit-data.d.ts +7 -0
  114. package/dist/core/yaml/src/edit-data.js +62 -3
  115. package/dist/core/yaml/src/edit.d.ts +7 -0
  116. package/dist/core/yaml/src/edit.js +34 -3
  117. package/dist/core/yaml/src/splice-node.d.ts +6 -0
  118. package/dist/core/yaml/src/splice-node.js +10 -0
  119. package/dist/core/yaml/src/splice.js +20 -10
  120. package/dist/testing/integration/src/checks.d.ts +5 -3
  121. package/dist/testing/integration/src/checks.js +31 -3
  122. package/package.json +9 -2
@@ -0,0 +1,14 @@
1
+ import { type HostClass } from "./address-class.js";
2
+ /**
3
+ * Where an `http` connector's or an integration's address may lead: an
4
+ * address written as numbers to its own class, `localhost` to this computer,
5
+ * and any other name to the internet only. The address as written is what the
6
+ * person saw when they trusted the workspace; a name that resolves to a
7
+ * home-network address is refused, so a DNS answer can't move a request onto
8
+ * the person's own network.
9
+ *
10
+ * @example
11
+ * connectorHostClass(new URL("http://localhost:8080/mcp")); // "loopback"
12
+ * connectorHostClass(new URL("https://notes.acme.test/mcp")); // "public"
13
+ */
14
+ export declare function connectorHostClass(url: URL): HostClass | undefined;
@@ -0,0 +1,34 @@
1
+ import { classifyAddress } from "./address-class.js";
2
+ /**
3
+ * Where an `http` connector's or an integration's address may lead: an
4
+ * address written as numbers to its own class, `localhost` to this computer,
5
+ * and any other name to the internet only. The address as written is what the
6
+ * person saw when they trusted the workspace; a name that resolves to a
7
+ * home-network address is refused, so a DNS answer can't move a request onto
8
+ * the person's own network.
9
+ *
10
+ * @example
11
+ * connectorHostClass(new URL("http://localhost:8080/mcp")); // "loopback"
12
+ * connectorHostClass(new URL("https://notes.acme.test/mcp")); // "public"
13
+ */
14
+ export function connectorHostClass(url) {
15
+ const host = url.hostname.replace(/^\[|\]$/g, "").toLowerCase();
16
+ if (host === "localhost")
17
+ return "loopback";
18
+ const written = addressClassOf(host);
19
+ if (written === undefined)
20
+ return "public";
21
+ return written === "public" || written === "private" || written === "loopback"
22
+ ? written
23
+ : undefined;
24
+ }
25
+ /** The class of `host` when it is an IP address, or `undefined` for a name. */
26
+ function addressClassOf(host) {
27
+ try {
28
+ return classifyAddress(host);
29
+ }
30
+ catch {
31
+ // Not an address but a name: the caller decides.
32
+ return undefined;
33
+ }
34
+ }
@@ -1,3 +1,5 @@
1
1
  export type { AddressCheckingHttpClient } from "./address-checking.js";
2
2
  export { type AddressClass, addressAllowedFor, classifyAddress, type HostClass, } from "./address-class.js";
3
+ export { connectorHostClass } from "./connector-host-class.js";
3
4
  export { type IpAddress, parseIpAddress } from "./ip-address.js";
5
+ export { ollamaAnswerTimeoutMs, ollamaTagsUrl, readOllamaTags } from "./ollama-tags.js";
@@ -1,2 +1,4 @@
1
1
  export { addressAllowedFor, classifyAddress, } from "./address-class.js";
2
+ export { connectorHostClass } from "./connector-host-class.js";
2
3
  export { parseIpAddress } from "./ip-address.js";
4
+ export { ollamaAnswerTimeoutMs, ollamaTagsUrl, readOllamaTags } from "./ollama-tags.js";
@@ -0,0 +1,20 @@
1
+ import type { HttpClient } from "../../../core/ports/src/index.js";
2
+ /** Where Ollama lists its downloaded models: its own list, with the names `ollama pull` takes. */
3
+ export declare const ollamaTagsUrl = "http://localhost:11434/api/tags";
4
+ /**
5
+ * How long Ollama may take to send its whole answer. The model screen waits
6
+ * for it, so it is also the longest an Ollama that hangs keeps it waiting.
7
+ */
8
+ export declare const ollamaAnswerTimeoutMs = 3000;
9
+ /**
10
+ * Asks `GET http://localhost:11434/api/tags` and gives Ollama's answer as
11
+ * parsed JSON. It sends no key, refuses redirects, and gives up when the
12
+ * whole answer, body included, hasn't come within {@link ollamaAnswerTimeoutMs}.
13
+ *
14
+ * @throws when Ollama doesn't answer in time, answers with an error status,
15
+ * or sends what isn't JSON
16
+ *
17
+ * @example
18
+ * await detectLocalModels(ollamaDownloadedModelSource(() => readOllamaTags({ fetch })));
19
+ */
20
+ export declare function readOllamaTags(http: HttpClient): Promise<unknown>;
@@ -0,0 +1,38 @@
1
+ // Asks Ollama on this computer which models it has downloaded, for the model
2
+ // detection in `@halonicjs/app`. Here, so the CLI and Studio's services send
3
+ // the same request. Only Ollama, only this computer, at its usual address:
4
+ // v0.1 has no way to name another one.
5
+ //
6
+ // It gives the answer unread: `@halonicjs/app` reads the list. Importing
7
+ // `@halonicjs/app` here would put it in the fenced integration runner's file,
8
+ // which bundles this package and may import nothing but Node's own modules.
9
+ /** Where Ollama lists its downloaded models: its own list, with the names `ollama pull` takes. */
10
+ export const ollamaTagsUrl = "http://localhost:11434/api/tags";
11
+ /**
12
+ * How long Ollama may take to send its whole answer. The model screen waits
13
+ * for it, so it is also the longest an Ollama that hangs keeps it waiting.
14
+ */
15
+ export const ollamaAnswerTimeoutMs = 3_000;
16
+ /**
17
+ * Asks `GET http://localhost:11434/api/tags` and gives Ollama's answer as
18
+ * parsed JSON. It sends no key, refuses redirects, and gives up when the
19
+ * whole answer, body included, hasn't come within {@link ollamaAnswerTimeoutMs}.
20
+ *
21
+ * @throws when Ollama doesn't answer in time, answers with an error status,
22
+ * or sends what isn't JSON
23
+ *
24
+ * @example
25
+ * await detectLocalModels(ollamaDownloadedModelSource(() => readOllamaTags({ fetch })));
26
+ */
27
+ export async function readOllamaTags(http) {
28
+ // One signal for the request and the body, so a body that never ends times out too.
29
+ const response = await http.fetch(ollamaTagsUrl, {
30
+ redirect: "error",
31
+ signal: AbortSignal.timeout(ollamaAnswerTimeoutMs),
32
+ });
33
+ if (!response.ok) {
34
+ await response.body?.cancel();
35
+ throw new Error(`Ollama answered /api/tags with HTTP ${response.status}.`);
36
+ }
37
+ return response.json();
38
+ }
@@ -6,7 +6,7 @@ export { IntegrationRefusedError, IntegrationTimeoutError, type RefusalCode, } f
6
6
  export { leakAttemptCodes } from "./leak-attempt.js";
7
7
  export { createLimitedHttpClient, type LimitedHttpOptions, type RequestLimits, } from "./limited-http.js";
8
8
  export type { LoadProblem } from "./load-problem.js";
9
- export { type IntegrationSource, type LoadedIntegration, type LoadIntegrationOptions, loadIntegration, type PreparedIntegration, type PrepareIntegrationOptions, prepareIntegration, providerChoices, type WorkspaceChoices, } from "./loader.js";
9
+ export { type IntegrationSource, type LoadedIntegration, type LoadIntegrationOptions, loadIntegration, type PreparedIntegration, type PrepareIntegrationOptions, prepareIntegration, providerChoices, } from "./loader.js";
10
10
  export { pluginLoadProblems } from "./plugin-load.js";
11
11
  export { allowedUrl, type DeclaredPlacement, type DeclaredSecret, type DeclaredSignIn, type DeclaredSignInPlacement, type IntegrationPolicy, namePattern, } from "./policy.js";
12
12
  export { maxRequestBodyBytes } from "./request-body.js";
@@ -14,3 +14,4 @@ export { RequestLog, type RequestLogEntry } from "./request-log.js";
14
14
  export { scopedTokens, storedTokenName } from "./scoped-tokens.js";
15
15
  export { removeSecrets, removeSecretsFromHeaders, removeSecretsStream, type SecretForms, type SecretOnWire, SecretRemover, secretForms, secretRemoved, } from "./secret-filter.js";
16
16
  export { clampWaitMs, integrationWait } from "./wait.js";
17
+ export { choiceSettings, chosenSecrets, type WorkspaceChoices } from "./workspace-choices.js";
@@ -20,3 +20,4 @@ export { RequestLog } from "./request-log.js";
20
20
  export { scopedTokens, storedTokenName } from "./scoped-tokens.js";
21
21
  export { removeSecrets, removeSecretsFromHeaders, removeSecretsStream, SecretRemover, secretForms, secretRemoved, } from "./secret-filter.js";
22
22
  export { clampWaitMs, integrationWait } from "./wait.js";
23
+ export { choiceSettings, chosenSecrets } from "./workspace-choices.js";
@@ -1,11 +1,12 @@
1
1
  import type { AddressCheckingHttpClient } from "../../http-kit/src/index.js";
2
2
  import { type IntegrationSheet } from "../../../core/format/src/integration/index.js";
3
- import { type Integration, type IntegrationHost, type ProviderConfig, type Secrets, type SignInTokens, type TokenStore } from "../../../core/ports/src/index.js";
3
+ import type { Integration, IntegrationHost, ProviderConfig, Secrets, SignInTokens, TokenStore } from "../../../core/ports/src/index.js";
4
4
  import { type Result } from "../../../core/std/src/index.js";
5
5
  import { type CurrentSecretForms } from "./current-secret-forms.js";
6
6
  import type { LoadProblem } from "./load-problem.js";
7
7
  import type { RequestLog } from "./request-log.js";
8
8
  import type { SecretOnWire } from "./secret-filter.js";
9
+ import { type WorkspaceChoices } from "./workspace-choices.js";
9
10
  /** An integration and its permission sheet, as they were found. */
10
11
  export interface IntegrationSource {
11
12
  /**
@@ -30,17 +31,6 @@ export interface IntegrationSource {
30
31
  */
31
32
  readonly plugin?: boolean;
32
33
  }
33
- /** What the workspace chose for one integration. */
34
- export interface WorkspaceChoices {
35
- /** Its settings, such as the URL a `{ fromSetting }` host reads. Never a secret value. */
36
- readonly settings?: Readonly<Record<string, unknown>>;
37
- /**
38
- * For each secret in the sheet, the workspace secret the user picked for
39
- * it. A secret left out isn't configured: an optional one is left off the
40
- * request, any other is refused when a request needs it.
41
- */
42
- readonly secretNames?: Readonly<Record<string, string>>;
43
- }
44
34
  /** What {@link loadIntegration} needs: the integration and the raw ports, which the integration never sees. */
45
35
  export interface LoadIntegrationOptions {
46
36
  readonly source: IntegrationSource;
@@ -1,10 +1,10 @@
1
1
  import { integrationPolicy, isPlacedSecret, parseIntegrationSheet, } from "../../../core/format/src/integration/index.js";
2
- import { pluginSecrets, workspaceSecrets, } from "../../../core/ports/src/index.js";
3
2
  import { deepEqual, err, ok } from "../../../core/std/src/index.js";
4
3
  import { currentSecretForms } from "./current-secret-forms.js";
5
4
  import { declarationProblems } from "./declaration.js";
6
5
  import { createIntegrationHost } from "./host.js";
7
6
  import { checkSecretLength } from "./secret-placement.js";
7
+ import { choiceSettings, chosenSecrets } from "./workspace-choices.js";
8
8
  /**
9
9
  * Checks an integration against its permission sheet and builds its host. The
10
10
  * sheet must pass its schema, the code must be exactly what the sheet
@@ -45,7 +45,7 @@ function prepare(options, codeProblems) {
45
45
  return err(parsed.error);
46
46
  }
47
47
  const sheet = parsed.value;
48
- const settings = options.choices?.settings ?? {};
48
+ const settings = choiceSettings(options.choices);
49
49
  const secretNames = options.choices?.secretNames ?? {};
50
50
  const problems = [
51
51
  ...approvalProblems(source, sheet),
@@ -62,7 +62,7 @@ function prepare(options, codeProblems) {
62
62
  if (problems.length > 0 || !resolved.ok) {
63
63
  return err(problems);
64
64
  }
65
- const secrets = chosenSecrets(options.secrets, secretNames, source.plugin ? sheet.id : undefined);
65
+ const secrets = chosenSecrets(options.secrets, options.choices, source.plugin ? sheet.id : undefined);
66
66
  const { host, log } = createIntegrationHost({
67
67
  policy: resolved.value.policy,
68
68
  transport: options.transport,
@@ -200,23 +200,6 @@ function secretChoiceProblems(sheet, secretNames) {
200
200
  function requestLimits(limits) {
201
201
  return Object.fromEntries(Object.entries(limits).filter((entry) => entry[1] !== undefined));
202
202
  }
203
- /**
204
- * The raw secrets seen through the user's picks: the kit asks by the sheet's
205
- * name and reads the secret picked for it, or nothing. A workspace chose
206
- * those names, so they can't reach Halonic's own secrets, tokens or a
207
- * plugin's. A plugin's backend's names come from its manifest and can reach
208
- * only that plugin's own secrets (`plugin`).
209
- */
210
- function chosenSecrets(raw, secretNames, plugin) {
211
- const picks = new Map(Object.entries(secretNames));
212
- const readable = plugin === undefined ? workspaceSecrets(raw) : pluginSecrets(raw, plugin);
213
- return {
214
- get: async (name) => {
215
- const picked = picks.get(name);
216
- return picked === undefined ? null : await readable.get(picked);
217
- },
218
- };
219
- }
220
203
  /**
221
204
  * Each declared secret with a value, and its one placement, as {@link PreparedIntegration.readSecrets} gives them.
222
205
  *
@@ -0,0 +1,37 @@
1
+ import { type Secrets } from "../../../core/ports/src/index.js";
2
+ /** What the workspace chose for one integration. */
3
+ export interface WorkspaceChoices {
4
+ /** Its settings, such as the URL a `{ fromSetting }` host reads. Never a secret value. */
5
+ readonly settings?: Readonly<Record<string, unknown>>;
6
+ /**
7
+ * For each secret in the sheet, the workspace secret the user picked for
8
+ * it. A secret left out isn't configured: an optional one is left off the
9
+ * request, any other is refused when a request needs it.
10
+ */
11
+ readonly secretNames?: Readonly<Record<string, string>>;
12
+ }
13
+ /**
14
+ * The settings the workspace chose. The loader and the host's sign-ins
15
+ * (`createIntegrationSignIns`'s `current()`) both read them here, from the
16
+ * same `WorkspaceChoices`, so they never hold two copies.
17
+ *
18
+ * @example
19
+ * choiceSettings({ settings: { url: "http://localhost:11434" } }); // { url: "http://localhost:11434" }
20
+ * choiceSettings(undefined); // {}
21
+ */
22
+ export declare function choiceSettings(choices: WorkspaceChoices | undefined): Readonly<Record<string, unknown>>;
23
+ /**
24
+ * The raw secrets seen through the user's picks: the kit asks by the sheet's
25
+ * name and reads the secret picked for it, or nothing. A workspace chose
26
+ * those names, so they can't reach Halonic's own secrets, tokens or a
27
+ * plugin's. A plugin's backend's names come from its manifest and can reach
28
+ * only that plugin's own secrets (`plugin`).
29
+ *
30
+ * The host's sign-ins read the client secret through this same view, so the
31
+ * sheet's name is translated to the workspace's in one place.
32
+ *
33
+ * @example
34
+ * const secrets = chosenSecrets(raw, { secretNames: { "client-secret": "gitlab-secret" } });
35
+ * await secrets.get("client-secret"); // the workspace's "gitlab-secret"
36
+ */
37
+ export declare function chosenSecrets(raw: Secrets, choices: WorkspaceChoices | undefined, plugin?: string): Secrets;
@@ -0,0 +1,37 @@
1
+ import { pluginSecrets, workspaceSecrets } from "../../../core/ports/src/index.js";
2
+ /**
3
+ * The settings the workspace chose. The loader and the host's sign-ins
4
+ * (`createIntegrationSignIns`'s `current()`) both read them here, from the
5
+ * same `WorkspaceChoices`, so they never hold two copies.
6
+ *
7
+ * @example
8
+ * choiceSettings({ settings: { url: "http://localhost:11434" } }); // { url: "http://localhost:11434" }
9
+ * choiceSettings(undefined); // {}
10
+ */
11
+ export function choiceSettings(choices) {
12
+ return choices?.settings ?? {};
13
+ }
14
+ /**
15
+ * The raw secrets seen through the user's picks: the kit asks by the sheet's
16
+ * name and reads the secret picked for it, or nothing. A workspace chose
17
+ * those names, so they can't reach Halonic's own secrets, tokens or a
18
+ * plugin's. A plugin's backend's names come from its manifest and can reach
19
+ * only that plugin's own secrets (`plugin`).
20
+ *
21
+ * The host's sign-ins read the client secret through this same view, so the
22
+ * sheet's name is translated to the workspace's in one place.
23
+ *
24
+ * @example
25
+ * const secrets = chosenSecrets(raw, { secretNames: { "client-secret": "gitlab-secret" } });
26
+ * await secrets.get("client-secret"); // the workspace's "gitlab-secret"
27
+ */
28
+ export function chosenSecrets(raw, choices, plugin) {
29
+ const picks = new Map(Object.entries(choices?.secretNames ?? {}));
30
+ const readable = plugin === undefined ? workspaceSecrets(raw) : pluginSecrets(raw, plugin);
31
+ return {
32
+ get: async (name) => {
33
+ const picked = picks.get(name);
34
+ return picked === undefined ? null : await readable.get(picked);
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,18 @@
1
+ import type { ToolFailureCause } from "./run-basics.js";
2
+ /**
3
+ * A connector the agent's file lists couldn't list its tools when a model
4
+ * turn started, so the turn offered none of them and went on without them
5
+ * (requirement `events.connector-listing-failed`). `connector`: its id in
6
+ * the workspace. `cause`: why, as on `tool.result`: `why` is
7
+ * `program-missing` or `secret-not-set` with the program or the secret's
8
+ * `name` when the engine knows, else `other` with no name. It never holds
9
+ * the error's own text.
10
+ */
11
+ export interface ConnectorListingFailedEvent {
12
+ type: "connector.listing-failed";
13
+ agent: string;
14
+ connector: string;
15
+ cause: Extract<ToolFailureCause, {
16
+ code: "connector-not-started";
17
+ }>;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * `path` with the person's home folder written as `~`, or `path` as it is
3
3
  * when it is outside the home folder or the home folder is unknown. A folder
4
- * next to the home folder whose name starts the same stays as it is.
4
+ * next to the home folder whose name starts the same stays as it is. A
5
+ * Windows home folder (one that starts with a drive letter) is matched
6
+ * whatever the letter case, as Windows does, so a path that went through a
7
+ * canonical-case step is shortened too.
5
8
  *
6
9
  * @param path - an absolute path
7
10
  * @param home - the person's home folder, or `null` when it is unknown
@@ -1,7 +1,10 @@
1
1
  /**
2
2
  * `path` with the person's home folder written as `~`, or `path` as it is
3
3
  * when it is outside the home folder or the home folder is unknown. A folder
4
- * next to the home folder whose name starts the same stays as it is.
4
+ * next to the home folder whose name starts the same stays as it is. A
5
+ * Windows home folder (one that starts with a drive letter) is matched
6
+ * whatever the letter case, as Windows does, so a path that went through a
7
+ * canonical-case step is shortened too.
5
8
  *
6
9
  * @param path - an absolute path
7
10
  * @param home - the person's home folder, or `null` when it is unknown
@@ -16,11 +19,19 @@ export function shortenHome(path, home) {
16
19
  const root = home.replace(/[/\\]+$/, "");
17
20
  if (root === "")
18
21
  return path;
19
- if (path === root)
22
+ const foldCase = isWindowsPath(root)
23
+ ? (text) => text.toLowerCase()
24
+ : (text) => text;
25
+ if (foldCase(path) === foldCase(root))
20
26
  return "~";
21
27
  const separator = path.charAt(root.length);
22
- if (path.startsWith(root) && (separator === "/" || separator === "\\")) {
28
+ if (foldCase(path.slice(0, root.length)) === foldCase(root) &&
29
+ (separator === "/" || separator === "\\")) {
23
30
  return `~${path.slice(root.length)}`;
24
31
  }
25
32
  return path;
26
33
  }
34
+ /** Whether `path` starts with a drive letter, such as `C:\`, so it is on Windows, where names ignore case. */
35
+ function isWindowsPath(path) {
36
+ return /^[a-z]:[/\\]/i.test(path);
37
+ }
@@ -1,7 +1,8 @@
1
1
  export { addUsage } from "./add-usage.js";
2
2
  export type { AgentResume, LoggedToolCall } from "./agent-resume.js";
3
3
  export { type BlockedSite, type BlockedSitesOptions, blockedSites, type StepBlockedSites, } from "./blocked-sites.js";
4
- export type { ApprovalResolver, CantTryReason, CantTryStep, LeftOutReason, ModelSkipReason, ProviderText, RunCatchUp, RunFailureReason, RunKind, RunParent, RunStatus, RunTrigger, RunVersion, StoredBlob, ToolNoun, ToolOutcome, ToolRefusalReason, ToolRisk, ToolUnaskedReason, ToolVerb, Usage, } from "./run-basics.js";
4
+ export { providerNotes } from "./provider-notes.js";
5
+ export type { ApprovalResolver, CantTryReason, CantTryStep, ConnectorStartReason, HarnessStartCause, InstructionsRefusal, LeftOutReason, LoggedInstructionPin, ModelSkipReason, ProviderText, RunCatchUp, RunFailureCause, RunFailureKind, RunFailureReason, RunKind, RunParent, RunStatus, RunTrigger, RunVersion, StoredBlob, ToolFailureCause, ToolNotMadeReason, ToolNoun, ToolOutcome, ToolRefusalReason, ToolRisk, ToolUnaskedReason, ToolVerb, Usage, } from "./run-basics.js";
5
6
  export type { RunEvent, RunEventBase, RunEventBody, RunEventType } from "./run-event.js";
6
7
  export { draftsOf, readsOf } from "./run-reads.js";
7
8
  export type { RunSends, SendCount, SendGroup } from "./run-sends.js";
@@ -9,9 +10,10 @@ export { sendsOf } from "./run-sends.js";
9
10
  export type { PendingApproval, RunSummary, SentSignal } from "./run-summary.js";
10
11
  export type { LoggedSandboxBlock, SandboxBlock } from "./sandbox-blocked.js";
11
12
  export { maxBlockedTargetsPerStep, sandboxBlockedView } from "./sandbox-blocked.js";
12
- export type { DeniedPathGroup, DeniedPathGroupCode, SandboxOpenedOptions, SandboxOpenedView, SandboxStrength, ShownSandboxProfile, } from "./sandbox-opened.js";
13
+ export type { DeniedPathGroup, DeniedPathGroupCode, SandboxOpenedOptions, SandboxOpenedView, SandboxSignIn, SandboxStrength, ShownSandboxProfile, SubscriptionProvider, } from "./sandbox-opened.js";
13
14
  export { deniedPathGroupCodes, sandboxOpenedView } from "./sandbox-opened.js";
14
15
  export { readSandboxOpened } from "./sandbox-opened-read.js";
15
16
  export { summarize } from "./summarize.js";
16
17
  export { entryOf } from "./timeline-entry.js";
18
+ export { maxCauseNameLength, toolFailureCauseOf } from "./tool-failure-cause.js";
17
19
  export { parseEventLine, upgradeEvent } from "./upgrade.js";
@@ -1,5 +1,6 @@
1
1
  export { addUsage } from "./add-usage.js";
2
2
  export { blockedSites, } from "./blocked-sites.js";
3
+ export { providerNotes } from "./provider-notes.js";
3
4
  export { draftsOf, readsOf } from "./run-reads.js";
4
5
  export { sendsOf } from "./run-sends.js";
5
6
  export { maxBlockedTargetsPerStep, sandboxBlockedView } from "./sandbox-blocked.js";
@@ -7,4 +8,5 @@ export { deniedPathGroupCodes, sandboxOpenedView } from "./sandbox-opened.js";
7
8
  export { readSandboxOpened } from "./sandbox-opened-read.js";
8
9
  export { summarize } from "./summarize.js";
9
10
  export { entryOf } from "./timeline-entry.js";
11
+ export { maxCauseNameLength, toolFailureCauseOf } from "./tool-failure-cause.js";
10
12
  export { parseEventLine, upgradeEvent } from "./upgrade.js";
@@ -0,0 +1,16 @@
1
+ import type { RunEvent } from "./run-event.js";
2
+ /**
3
+ * The providers' notes on how they changed a run's model calls, each once
4
+ * (requirement `events.provider-notes`): the `notes` of every
5
+ * `llm.response`, in the order each note first came. A run whose calls all
6
+ * left out the same setting says so once. Pure.
7
+ *
8
+ * @param events - the run's events, oldest first
9
+ * @returns each note once; empty when no provider changed a call
10
+ *
11
+ * @example
12
+ * providerNotes(events);
13
+ * // three calls to claude-sonnet-5-5 with temperature set
14
+ * // => ["Left out temperature: claude-sonnet-5-5 doesn't take it."]
15
+ */
16
+ export declare function providerNotes(events: readonly RunEvent[]): string[];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The providers' notes on how they changed a run's model calls, each once
3
+ * (requirement `events.provider-notes`): the `notes` of every
4
+ * `llm.response`, in the order each note first came. A run whose calls all
5
+ * left out the same setting says so once. Pure.
6
+ *
7
+ * @param events - the run's events, oldest first
8
+ * @returns each note once; empty when no provider changed a call
9
+ *
10
+ * @example
11
+ * providerNotes(events);
12
+ * // three calls to claude-sonnet-5-5 with temperature set
13
+ * // => ["Left out temperature: claude-sonnet-5-5 doesn't take it."]
14
+ */
15
+ export function providerNotes(events) {
16
+ const notes = new Set();
17
+ for (const event of events) {
18
+ if (event.type !== "llm.response")
19
+ continue;
20
+ for (const note of event.notes ?? [])
21
+ notes.add(note);
22
+ }
23
+ return [...notes];
24
+ }
@@ -73,7 +73,8 @@ export interface Usage {
73
73
  }
74
74
  /** What started a run. Absent for runs started by hand from a workflow. */
75
75
  export interface RunTrigger {
76
- type: "manual" | "schedule" | "every" | "mail" | "signal" | "webhook";
76
+ /** `inbox`: the person started it from the Inbox's request form; `manual`: with Run, or a routine's Run now. */
77
+ type: "manual" | "inbox" | "schedule" | "every" | "mail" | "signal" | "webhook";
77
78
  /** Routine key: "<hubId>/<routineId>" or "@workspace/<routineId>". */
78
79
  routineId?: string;
79
80
  /** ISO time the run was due (the scheduled time, not when it actually started). */
@@ -130,6 +131,42 @@ export interface RunParent {
130
131
  * off without an answer, so it may or may not have done its work (`unknown`).
131
132
  */
132
133
  export type ToolOutcome = "ok" | "error" | "unknown";
134
+ /**
135
+ * Why the engine didn't make a connector call (requirement
136
+ * `events.tool-result-cause`): `not-connected`, the agent's connector isn't
137
+ * among the run's; `tool-gone`, the connector no longer offers the tool;
138
+ * `sending-off`, the tool sends and sending is off for the connector;
139
+ * `bad-arguments`, the call's arguments aren't an object.
140
+ */
141
+ export type ToolNotMadeReason = "not-connected" | "tool-gone" | "sending-off" | "bad-arguments";
142
+ /** Why a run's connectors didn't start, when the engine knows (requirement `events.tool-result-cause`). */
143
+ export type ConnectorStartReason = "program-missing" | "secret-not-set" | "other";
144
+ /**
145
+ * Why a tool call failed, when the engine knows (requirement
146
+ * `events.tool-result-cause`):
147
+ *
148
+ * - `time-limit`: the tool didn't answer within `seconds`.
149
+ * - `engine-stopped`: the engine stopped while the call was going.
150
+ * - `not-made`: the engine didn't make the call, for the reason in `why`.
151
+ * - `connector-not-started`: the run's connectors didn't start. `name` is
152
+ * the program or the secret's name as the connector's file writes it,
153
+ * never a secret's value or a program's output.
154
+ *
155
+ * Read it with `toolFailureCauseOf`: a cause it doesn't know reads as absent.
156
+ */
157
+ export type ToolFailureCause = {
158
+ readonly code: "time-limit";
159
+ readonly seconds: number;
160
+ } | {
161
+ readonly code: "engine-stopped";
162
+ } | {
163
+ readonly code: "not-made";
164
+ readonly why: ToolNotMadeReason;
165
+ } | {
166
+ readonly code: "connector-not-started";
167
+ readonly why: ConnectorStartReason;
168
+ readonly name?: string;
169
+ };
133
170
  /**
134
171
  * Why a model's tool call was refused before it ran (requirement
135
172
  * `events.tool-refused`): `not-offered`, the step offered no tool of that name.
@@ -187,10 +224,12 @@ export type ToolVerb = "sent" | "saved" | "created" | "updated" | "moved" | "dra
187
224
  * - `error`: something else went wrong; the `error` text says what.
188
225
  * - `model-unreachable`: the model's host didn't answer; `run.failed` names it in `host`.
189
226
  * - `model-out-of-memory`: the machine running the model ran out of memory for it.
227
+ * - `model-timeout`: the model's provider was reached but gave no first answer in time (5 minutes by default);
228
+ * `run.failed` names its host in `host` when it is known.
190
229
  * - `disk-full`: there was no disk space left to write what the run needed.
191
230
  * - `interrupted`: the engine stopped while the run was going, and found it on its next start.
192
231
  * - `sandbox-not-ready`: the sandbox check failed, so the step that needs the sandbox didn't
193
- * start; `run.failed` gives the check's reason code in `sandboxReason`.
232
+ * start; `run.failed` gives the check's reason code in `sandboxReason` and the refused agent in `agent`.
194
233
  * - `sandbox-start-failed`: the sandbox check had passed, but the sandbox didn't start for this run.
195
234
  * - `harness-start-failed`: the harness program failed to start for this run, or didn't send its
196
235
  * first event within its time limit (60 s by default).
@@ -204,8 +243,64 @@ export type ToolVerb = "sent" | "saved" | "created" | "updated" | "moved" | "dra
204
243
  * has no harnesses, as in workflow tests, which never start programs.
205
244
  * - `local-only`: the workspace is local only, and no model the step could use runs on this
206
245
  * computer, so Halonic called none of them.
246
+ * - `instructions-not-trusted`: the step's harness didn't start, because a person hasn't trusted
247
+ * the agent's instructions (or they changed since); `run.failed` gives the agent in `agent`,
248
+ * the pin the check saw in `pin` and whether something was trusted before in `changed`.
249
+ */
250
+ export type RunFailureReason = "budget" | "cancelled" | "model-missing" | "model-no-tools" | "error" | "model-unreachable" | "model-out-of-memory" | "model-timeout" | "disk-full" | "interrupted" | "sandbox-not-ready" | "sandbox-start-failed" | "harness-start-failed" | "key-refused" | "out-of-credit" | "provider-busy" | "answer-not-an-option" | "harness-unavailable" | "local-only" | "instructions-not-trusted";
251
+ /**
252
+ * The instructions a harness step started with: the digest of the whole set
253
+ * and each file's digest by name. Only digests, never the text, so a log
254
+ * that is shared doesn't carry what a person wrote.
255
+ */
256
+ export interface LoggedInstructionPin {
257
+ readonly digest: string;
258
+ readonly files: Readonly<Record<string, string>>;
259
+ }
260
+ /**
261
+ * What `run.failed` and a parallel branch's `agent.finished` carry with the
262
+ * reason `instructions-not-trusted` (requirement
263
+ * `events.run-failed-instructions-not-trusted`): the pin the check saw, so a
264
+ * page can ask a person to trust exactly that, and whether a person had
265
+ * trusted instructions for the agent before, so it says "changed" or "not
266
+ * trusted yet" without asking the store again. `changed` is absent when the
267
+ * check didn't answer.
268
+ */
269
+ export interface InstructionsRefusal {
270
+ readonly pin: LoggedInstructionPin;
271
+ readonly changed?: boolean;
272
+ }
273
+ /**
274
+ * Why a harness program didn't start, when the engine knows (requirement
275
+ * `events.run-failed-harness-cause`): `not-installed` when the program isn't
276
+ * on this computer, `signed-out` when it is but no one is signed in to it for
277
+ * the agent. A reader that doesn't know a cause reads it as absent.
278
+ */
279
+ export type HarnessStartCause = "not-installed" | "signed-out";
280
+ /**
281
+ * How a surface responds to a failure: the kit's error kinds. This package
282
+ * may not import `@halonicjs/std`, so it holds its own list; the engine's
283
+ * type test (requirement `engine.run-failure-cause-of`) fails when it and
284
+ * `ErrorKind` differ.
207
285
  */
208
- export type RunFailureReason = "budget" | "cancelled" | "model-missing" | "model-no-tools" | "error" | "model-unreachable" | "model-out-of-memory" | "disk-full" | "interrupted" | "sandbox-not-ready" | "sandbox-start-failed" | "harness-start-failed" | "key-refused" | "out-of-credit" | "provider-busy" | "answer-not-an-option" | "harness-unavailable" | "local-only";
286
+ export type RunFailureKind = "invalid_input" | "not_found" | "conflict" | "unauthenticated" | "denied" | "limit_reached" | "unavailable" | "internal";
287
+ /**
288
+ * The typed cause of a failed run, for a screen that has to tell one failure
289
+ * from another without reading the free-text `error` (requirement
290
+ * `events.run-failed-cause`), such as Studio's "API off" banner.
291
+ *
292
+ * `kind` is the error kind the failing error carried, one of the kit's eight
293
+ * (the engine's type test keeps {@link RunFailureKind} equal to `ErrorKind`). `code` is a stable
294
+ * string for a cause a screen knows by name, such as `google.api-disabled`;
295
+ * a reader that doesn't know a code still has `kind`. `detail` holds a few
296
+ * short strings that cause names, such as the API, the project and a link
297
+ * that fixes it. It never holds a credential or a provider's own text.
298
+ */
299
+ export interface RunFailureCause {
300
+ readonly kind: RunFailureKind;
301
+ readonly code?: string;
302
+ readonly detail?: Readonly<Record<string, string>>;
303
+ }
209
304
  /**
210
305
  * The model provider's own error text, kept in the run log for `--debug` and
211
306
  * Copy details only (requirement `events.provider-text`). Studio and the
@@ -224,5 +319,8 @@ export interface ProviderText {
224
319
  * (`local-only`).
225
320
  */
226
321
  export type ModelSkipReason = "no-key" | "local-only";
227
- /** Who resolved an approval: a person, or a rule that answers without asking anyone. */
228
- export type ApprovalResolver = "person" | "rule";
322
+ /**
323
+ * Who resolved an approval: a person at the screen, a person on a remote
324
+ * device (a phone), or a rule that answers without asking anyone.
325
+ */
326
+ export type ApprovalResolver = "person" | "remote-device" | "rule";