@capybara-hq/kernel 0.1.0-rc.92 → 0.1.0-rc.94

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 (57) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/admin/login-sources.controller.d.ts +30 -0
  3. package/dist/admin/login-sources.controller.js +77 -0
  4. package/dist/admin/login-sources.schemas.d.ts +25 -0
  5. package/dist/admin/login-sources.schemas.js +49 -0
  6. package/dist/catalog/marketplaces.service.d.ts +1 -1
  7. package/dist/config/schema.d.ts +0 -2
  8. package/dist/config/schema.js +0 -28
  9. package/dist/ctx/create-ctx.d.ts +5 -1
  10. package/dist/ctx/create-ctx.js +13 -2
  11. package/dist/device-access/device-access.service.d.ts +27 -4
  12. package/dist/device-access/device-access.service.js +183 -29
  13. package/dist/errors.d.ts +10 -0
  14. package/dist/errors.js +10 -0
  15. package/dist/extensions/instance.js +3 -1
  16. package/dist/http/api.module.js +2 -0
  17. package/dist/identity/auth.controller.d.ts +2 -0
  18. package/dist/identity/auth.controller.js +1 -1
  19. package/dist/identity/external.d.ts +78 -40
  20. package/dist/identity/external.js +157 -72
  21. package/dist/identity/identity.module.js +9 -0
  22. package/dist/identity/linked-accounts.d.ts +42 -0
  23. package/dist/identity/linked-accounts.js +78 -0
  24. package/dist/identity/login-sources.d.ts +160 -0
  25. package/dist/identity/login-sources.js +403 -0
  26. package/dist/identity/sso-decisions.d.ts +75 -0
  27. package/dist/identity/sso-decisions.js +42 -0
  28. package/dist/identity/sso-link.d.ts +61 -0
  29. package/dist/identity/sso-link.js +157 -0
  30. package/dist/identity/sso.controller.d.ts +98 -14
  31. package/dist/identity/sso.controller.js +222 -28
  32. package/dist/identity/sso.d.ts +75 -30
  33. package/dist/identity/sso.js +129 -70
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/infra/config/kernel-config.service.js +0 -3
  37. package/dist/infra/throttler/named-throttlers.d.ts +1 -1
  38. package/dist/infra/throttler/named-throttlers.js +1 -1
  39. package/dist/platform/exclusions.js +15 -0
  40. package/dist/platform/operation.js +4 -0
  41. package/dist/platform/ops/admin.ops.d.ts +3 -1
  42. package/dist/platform/ops/admin.ops.js +106 -2
  43. package/dist/platform/ops/extensions-admin.ops.d.ts +24 -2
  44. package/dist/platform/ops/extensions-admin.ops.js +54 -6
  45. package/dist/platform/route-schemas.js +2 -0
  46. package/dist/tools/builtins/sandbox/glob.js +7 -4
  47. package/dist/tools/builtins/sandbox/grep.d.ts +8 -1
  48. package/dist/tools/builtins/sandbox/grep.js +27 -33
  49. package/dist/tools/builtins/sandbox/search-command.d.ts +43 -0
  50. package/dist/tools/builtins/sandbox/search-command.js +86 -0
  51. package/dist/tools/call-scope.d.ts +19 -6
  52. package/dist/tools/call-scope.js +29 -0
  53. package/dist/tools/pipeline.d.ts +3 -2
  54. package/dist/tools/pipeline.js +29 -10
  55. package/dist/tools/questions.service.d.ts +2 -2
  56. package/dist/tools/questions.service.js +1 -1
  57. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import type { ToolCallContext } from "@capybara-hq/plugin-sdk";
1
+ import type { NetworkBlockLayer, ServiceBlockedHost, ToolCallContext } from "@capybara-hq/plugin-sdk";
2
2
  import type { ReviewRecord } from "../conversations/events.js";
3
3
  import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
4
4
  /**
@@ -43,14 +43,15 @@ export interface CallScope {
43
43
  review: ReviewRecord | null;
44
44
  /**
45
45
  * Hosts a device service (`ctx.deviceAccess.reportBlockedHosts`) saw refused by the device's
46
- * network allowlist during this call; null when nothing was reported. `deviceId` is the device
47
- * this call's own `ctx.deviceAccess` calls resolved, or null when the call made none (the
48
- * pipeline then asks about the device the call's conversation works in); `url` is the page the
49
- * refusals came from, when the service said.
46
+ * network during this call, each with the most restrictive layer reported for it
47
+ * ({@link strongerLayer}); null when nothing was reported. `deviceId` is the device this call's
48
+ * own `ctx.deviceAccess` calls resolved, or null when the call made none (the pipeline then asks
49
+ * about the device the call's conversation works in); `url` is the page the refusals came from,
50
+ * when the service said.
50
51
  */
51
52
  blocked: {
52
53
  deviceId: string | null;
53
- hosts: Set<string>;
54
+ hosts: Map<string, NetworkBlockLayer>;
54
55
  url: string | null;
55
56
  } | null;
56
57
  /**
@@ -79,3 +80,15 @@ export declare function whileDeviceStarting<T>(ctx: ToolCallContext, fn: () => P
79
80
  * anything to a device service (the only case the pipeline's "still starting" text may describe).
80
81
  */
81
82
  export declare function stillStartingUnsent(scope: CallScope | undefined | null): boolean;
83
+ /**
84
+ * The more restrictive of two layers reported for one host: a report never makes a host more
85
+ * grantable than another report of the same call said it was.
86
+ */
87
+ export declare function strongerLayer(a: NetworkBlockLayer, b: NetworkBlockLayer): NetworkBlockLayer;
88
+ /** A refused host as the call scope keeps it: lower-cased, without a trailing dot. */
89
+ export declare function serviceHostKey(host: string): string;
90
+ /**
91
+ * Two lists of a service's refused hosts as one, in first-seen order: a host in both keeps the
92
+ * more restrictive layer ({@link strongerLayer}).
93
+ */
94
+ export declare function mergeServiceHosts(a: readonly ServiceBlockedHost[], b: readonly ServiceBlockedHost[]): ServiceBlockedHost[];
@@ -46,3 +46,32 @@ export async function whileDeviceStarting(ctx, fn) {
46
46
  export function stillStartingUnsent(scope) {
47
47
  return scope != null && scope.starting > 0 && !scope.reached;
48
48
  }
49
+ /**
50
+ * How restrictive a refusal layer is: `address` (no host grant lifts it) over `org` (only an
51
+ * admin) over `device` (the device owner may be asked) over `unknown` (nothing said).
52
+ */
53
+ const LAYER_RANK = { unknown: 0, device: 1, org: 2, address: 3 };
54
+ /**
55
+ * The more restrictive of two layers reported for one host: a report never makes a host more
56
+ * grantable than another report of the same call said it was.
57
+ */
58
+ export function strongerLayer(a, b) {
59
+ return LAYER_RANK[b] > LAYER_RANK[a] ? b : a;
60
+ }
61
+ /** A refused host as the call scope keeps it: lower-cased, without a trailing dot. */
62
+ export function serviceHostKey(host) {
63
+ return host.toLowerCase().replace(/\.$/, "");
64
+ }
65
+ /**
66
+ * Two lists of a service's refused hosts as one, in first-seen order: a host in both keeps the
67
+ * more restrictive layer ({@link strongerLayer}).
68
+ */
69
+ export function mergeServiceHosts(a, b) {
70
+ const out = new Map();
71
+ for (const h of [...a, ...b]) {
72
+ const key = serviceHostKey(h.host);
73
+ const had = out.get(key);
74
+ out.set(key, had === undefined ? h.layer : strongerLayer(had, h.layer));
75
+ }
76
+ return [...out].map(([host, layer]) => ({ host, layer }));
77
+ }
@@ -1,4 +1,4 @@
1
- import { type ConversationSource, type FormAnswer, type InputForm, type Logger, type ToolDisplay } from "@capybara-hq/plugin-sdk";
1
+ import { type ConversationSource, type FormAnswer, type InputForm, type Logger, type ServiceBlockedHost, type ToolDisplay } from "@capybara-hq/plugin-sdk";
2
2
  import type { AgentDefinition } from "../agents/definition.js";
3
3
  import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
4
4
  import { AttachmentsService } from "../conversations/attachments.service.js";
@@ -360,7 +360,8 @@ export type ToolResume = {
360
360
  export interface ServiceBlocked {
361
361
  /** The device the call's `ctx.deviceAccess` calls resolved; null: the conversation's device. */
362
362
  deviceId: string | null;
363
- hosts: string[];
363
+ /** Each host once, with the most restrictive layer reported for it. */
364
+ hosts: ServiceBlockedHost[];
364
365
  /** The page the refusals came from, when the service said. */
365
366
  url: string | null;
366
367
  }
@@ -62,7 +62,7 @@ import { DEVICE_CODE_PATTERN, deviceCodeIdemKey, GITHUB_DEVICE_LOGIN_URL, } from
62
62
  import { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./builtins/sandbox/device-owner.js";
63
63
  import { SendMessageInput } from "./builtins/send-message.js";
64
64
  import { isAlwaysLoaded, notLoadedText } from "./builtins/tool-search.js";
65
- import { attachCallScope, stillStartingUnsent } from "./call-scope.js";
65
+ import { attachCallScope, mergeServiceHosts, stillStartingUnsent, } from "./call-scope.js";
66
66
  import { canonicalJson } from "./canonical-json.js";
67
67
  import { CredentialMissing, Credentials } from "./credentials.js";
68
68
  import { ToolDrift } from "./drift.js";
@@ -431,7 +431,11 @@ function withBlocked(outcome, scope) {
431
431
  ...outcome,
432
432
  ...(blocked != null &&
433
433
  blocked.hosts.size > 0 && {
434
- blocked: { deviceId: blocked.deviceId, hosts: [...blocked.hosts], url: blocked.url },
434
+ blocked: {
435
+ deviceId: blocked.deviceId,
436
+ hosts: [...blocked.hosts].map(([host, layer]) => ({ host, layer })),
437
+ url: blocked.url,
438
+ },
435
439
  }),
436
440
  // a device service launch's review (ctx.deviceAccess), recorded with the call's result
437
441
  ...(review !== null && { review }),
@@ -456,16 +460,28 @@ function carriedOf(rounds) {
456
460
  ...(blocked !== undefined && { blocked }),
457
461
  };
458
462
  }
459
- /** Two refused-host reports of one call as one: the hosts of both, the later device and page. */
463
+ /**
464
+ * Two refused-host reports of one call as one: the hosts of both (a host in both keeps the more
465
+ * restrictive layer), the later device and page. A malformed host entry (a record written by
466
+ * another kernel version) is dropped.
467
+ */
460
468
  function mergeBlocked(a, b) {
461
- if (a === undefined)
462
- return { ...b, hosts: [...b.hosts] };
463
469
  return {
464
- deviceId: b.deviceId ?? a.deviceId,
465
- hosts: [...new Set([...a.hosts, ...b.hosts])],
466
- url: b.url ?? a.url,
470
+ deviceId: b.deviceId ?? a?.deviceId ?? null,
471
+ hosts: mergeServiceHosts(validServiceHosts(a?.hosts), validServiceHosts(b.hosts)),
472
+ url: b.url ?? a?.url ?? null,
467
473
  };
468
474
  }
475
+ /** The well-formed entries of a refused-host list ({@link ServiceBlocked.hosts}). */
476
+ function validServiceHosts(hosts) {
477
+ if (!Array.isArray(hosts))
478
+ return [];
479
+ return hosts.filter((h) => typeof h === "object" &&
480
+ h !== null &&
481
+ typeof h.host === "string" &&
482
+ h.host !== "" &&
483
+ ["device", "org", "address", "unknown"].includes(h.layer));
484
+ }
469
485
  /**
470
486
  * The outcome with what earlier input rounds carried: their launch review when this round
471
487
  * reviewed none, their refused hosts merged before this round's.
@@ -1380,8 +1396,11 @@ let ToolPipeline = class ToolPipeline {
1380
1396
  ? undefined
1381
1397
  : {
1382
1398
  deviceId: scoped.deviceId,
1383
- // a service reports host names only: the event carries the HTTPS port
1384
- blocked: scoped.hosts.map((host) => ({ host, port: 443, layer: "device" })),
1399
+ // a service reports host names with their layers only: the event carries the HTTPS
1400
+ // port. The layer is the service's word: it only chooses the note or the ask, and the
1401
+ // plan still refuses to ask about a host the device list cannot take (an IP literal
1402
+ // or other invalid name is always `address`)
1403
+ blocked: scoped.hosts.map(({ host, layer }) => ({ host, port: 443, layer })),
1385
1404
  });
1386
1405
  let content = spilled.content;
1387
1406
  if (report !== undefined) {
@@ -1,4 +1,4 @@
1
- import { type FormAnswer, type InputForm } from "@capybara-hq/plugin-sdk";
1
+ import { type FormAnswer, type InputForm, type ServiceBlockedHost } from "@capybara-hq/plugin-sdk";
2
2
  import { EventLog } from "../conversations/event-log.js";
3
3
  import type { ReviewRecord } from "../conversations/events.js";
4
4
  import { type PersonRef } from "../identity/account-avatar.js";
@@ -18,7 +18,7 @@ export interface QuestionCarried {
18
18
  review?: ReviewRecord;
19
19
  blocked?: {
20
20
  deviceId: string | null;
21
- hosts: string[];
21
+ hosts: ServiceBlockedHost[];
22
22
  url: string | null;
23
23
  };
24
24
  }
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { randomUUID } from "node:crypto";
11
- import { validateAnswer } from "@capybara-hq/plugin-sdk";
11
+ import { validateAnswer, } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { sql } from "kysely";
14
14
  import { EventLog } from "../conversations/event-log.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.92",
3
+ "version": "0.1.0-rc.94",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.75"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.77"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,7 +75,7 @@
75
75
  "@types/ws": "^8.18.2",
76
76
  "@types/yauzl": "3.4.0",
77
77
  "ws": "^8.22.0",
78
- "@capybara-hq/testing": "0.1.0-rc.42"
78
+ "@capybara-hq/testing": "0.1.0-rc.43"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc -b"