oh-my-openagent 5.1.72 → 5.1.73

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 (76) hide show
  1. package/dist/cli/index.js +2280 -463
  2. package/dist/cli-node/index.js +2280 -463
  3. package/dist/index.js +13 -13
  4. package/dist/skills/browser/runtime/omowright/manifest.json +1 -1
  5. package/dist/skills/frontend/references/design/print-paged-media.md +1 -1
  6. package/dist/skills/ulw-execute/SKILL.md +2 -2
  7. package/dist/skills/ulw-plan/references/full-workflow.md +1 -1
  8. package/dist/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  9. package/dist/skills/ulw-research/references/research-collection.md +1 -1
  10. package/dist/tui.js +13 -13
  11. package/package.json +13 -13
  12. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  13. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
  14. package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
  15. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  16. package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
  17. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  18. package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
  19. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
  20. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
  21. package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +2 -2
  22. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  23. package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
  24. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  25. package/packages/omo-codex/plugin/components/rules/package.json +1 -1
  26. package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
  27. package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
  28. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  29. package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
  30. package/packages/omo-codex/plugin/components/ultrawork/agents/plan.toml +2 -2
  31. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  32. package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
  33. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +1 -1
  34. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  35. package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +1 -1
  36. package/packages/omo-codex/plugin/components/ulw-execute-continuation/package.json +1 -1
  37. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +5 -5
  38. package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
  39. package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/full-workflow.md +1 -1
  40. package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
  41. package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
  42. package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
  43. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
  44. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
  45. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
  46. package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
  47. package/packages/omo-codex/plugin/hooks/post-tool-use-recording-spawn-admission.json +1 -1
  48. package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
  49. package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
  50. package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
  51. package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
  52. package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
  53. package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
  54. package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
  55. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-execute-continuation.json +1 -1
  56. package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
  57. package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
  58. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
  59. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
  60. package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
  61. package/packages/omo-codex/plugin/package-lock.json +12 -12
  62. package/packages/omo-codex/plugin/package.json +1 -1
  63. package/packages/omo-codex/plugin/skills/browser/runtime/omowright/manifest.json +1 -1
  64. package/packages/omo-codex/plugin/skills/frontend/references/design/print-paged-media.md +1 -1
  65. package/packages/omo-codex/plugin/skills/ulw-execute/SKILL.md +2 -2
  66. package/packages/omo-codex/plugin/skills/ulw-loop/references/full-workflow.md +1 -1
  67. package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +1 -1
  68. package/packages/omo-codex/plugin/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  69. package/packages/omo-codex/plugin/skills/ulw-research/references/research-collection.md +1 -1
  70. package/packages/omo-codex/scripts/install-dist/install-local.mjs +2 -2
  71. package/packages/shared-skills/skills/browser/runtime/omowright/manifest.json +1 -1
  72. package/packages/shared-skills/skills/frontend/references/design/print-paged-media.md +1 -1
  73. package/packages/shared-skills/skills/ulw-execute/SKILL.md +2 -2
  74. package/packages/shared-skills/skills/ulw-plan/references/full-workflow.md +1 -1
  75. package/packages/shared-skills/skills/ulw-plan/scripts/plan-templates.mjs +1 -1
  76. package/packages/shared-skills/skills/ulw-research/references/research-collection.md +1 -1
package/dist/cli/index.js CHANGED
@@ -2132,7 +2132,7 @@ var package_default;
2132
2132
  var init_package = __esm(() => {
2133
2133
  package_default = {
2134
2134
  name: "oh-my-opencode",
2135
- version: "5.1.72",
2135
+ version: "5.1.73",
2136
2136
  description: "The Best AI Agent Harness - Batteries-Included OpenCode Plugin with Multi-Model Orchestration, Parallel Background Agents, and Crafted LSP/AST Tools",
2137
2137
  main: "./dist/index.js",
2138
2138
  types: "dist/index.d.ts",
@@ -2403,18 +2403,18 @@ var init_package = __esm(() => {
2403
2403
  typescript: "^7.0.2"
2404
2404
  },
2405
2405
  optionalDependencies: {
2406
- "oh-my-opencode-darwin-arm64": "5.1.72",
2407
- "oh-my-opencode-darwin-x64": "5.1.72",
2408
- "oh-my-opencode-darwin-x64-baseline": "5.1.72",
2409
- "oh-my-opencode-linux-arm64": "5.1.72",
2410
- "oh-my-opencode-linux-arm64-musl": "5.1.72",
2411
- "oh-my-opencode-linux-x64": "5.1.72",
2412
- "oh-my-opencode-linux-x64-baseline": "5.1.72",
2413
- "oh-my-opencode-linux-x64-musl": "5.1.72",
2414
- "oh-my-opencode-linux-x64-musl-baseline": "5.1.72",
2415
- "oh-my-opencode-windows-arm64": "5.1.72",
2416
- "oh-my-opencode-windows-x64": "5.1.72",
2417
- "oh-my-opencode-windows-x64-baseline": "5.1.72"
2406
+ "oh-my-opencode-darwin-arm64": "5.1.73",
2407
+ "oh-my-opencode-darwin-x64": "5.1.73",
2408
+ "oh-my-opencode-darwin-x64-baseline": "5.1.73",
2409
+ "oh-my-opencode-linux-arm64": "5.1.73",
2410
+ "oh-my-opencode-linux-arm64-musl": "5.1.73",
2411
+ "oh-my-opencode-linux-x64": "5.1.73",
2412
+ "oh-my-opencode-linux-x64-baseline": "5.1.73",
2413
+ "oh-my-opencode-linux-x64-musl": "5.1.73",
2414
+ "oh-my-opencode-linux-x64-musl-baseline": "5.1.73",
2415
+ "oh-my-opencode-windows-arm64": "5.1.73",
2416
+ "oh-my-opencode-windows-x64": "5.1.73",
2417
+ "oh-my-opencode-windows-x64-baseline": "5.1.73"
2418
2418
  },
2419
2419
  overrides: {
2420
2420
  hono: "^4.13.8",
@@ -92877,7 +92877,7 @@ var package_default2;
92877
92877
  var init_package2 = __esm(() => {
92878
92878
  package_default2 = {
92879
92879
  name: "@oh-my-opencode/omo-codex",
92880
- version: "5.1.72",
92880
+ version: "5.1.73",
92881
92881
  type: "module",
92882
92882
  private: true,
92883
92883
  description: "Codex harness adapter for oh-my-openagent. Vendored Codex plugin namespace (omo) + TypeScript installer + telemetry.",
@@ -116003,20 +116003,25 @@ var CLOSED_WHOAMI_HELP = `Show the current OmO device sign-in.
116003
116003
  omo whoami [--api <url>]
116004
116004
 
116005
116005
  This runs while OmO accounts are closed.`;
116006
+ var CLOSED_AUTH_HELP = { login: CLOSED_LOGIN_HELP, logout: CLOSED_LOGOUT_HELP, whoami: CLOSED_WHOAMI_HELP };
116006
116007
  function refuseClosedServiceAuth() {
116007
116008
  console.error(CLOSED_LOGIN_MESSAGE);
116008
116009
  process.exit(1);
116009
116010
  }
116010
116011
  function describeClosedAuthCommand(name) {
116011
116012
  return () => {
116012
- console.log(name === "login" ? CLOSED_LOGIN_HELP : name === "logout" ? CLOSED_LOGOUT_HELP : CLOSED_WHOAMI_HELP);
116013
+ console.log(CLOSED_AUTH_HELP[name]);
116013
116014
  process.exit(0);
116014
116015
  };
116015
116016
  }
116016
116017
  function configureClosedServiceAuthCommands(program, hooks) {
116017
116018
  configureClosedDeviceLogin(program, hooks);
116018
116019
  for (const name of ["logout", "whoami"]) {
116019
- const command = program.command(name, { hidden: true }).helpOption(false).allowUnknownOption().allowExcessArguments().option("--api <url>").action((options) => {
116020
+ const command = program.command(name, { hidden: true }).helpOption(false).allowUnknownOption().allowExcessArguments().option("--api <url>").option("--help").action((options) => {
116021
+ if (options.help === true) {
116022
+ console.log(CLOSED_AUTH_HELP[name]);
116023
+ return;
116024
+ }
116020
116025
  if (command.args.length !== 0)
116021
116026
  refuseClosedServiceAuth();
116022
116027
  return run3(name, options, hooks);
@@ -116051,11 +116056,19 @@ function configureServiceAuthCommands(program, open = serviceAccountsOpen(), hoo
116051
116056
  import { existsSync as existsSync68 } from "fs";
116052
116057
 
116053
116058
  // packages/device-service-core/src/device-service.ts
116054
- import { join as join121 } from "path";
116059
+ import { join as join122 } from "path";
116055
116060
 
116056
116061
  // packages/device-service-core/src/local-api/access.ts
116057
- import { createHmac as createHmac2, randomBytes as randomBytes7, timingSafeEqual as timingSafeEqual2 } from "crypto";
116058
- import { chmodSync as chmodSync8, closeSync as closeSync5, lstatSync as lstatSync6, openSync as openSync5, readFileSync as readFileSync46, renameSync as renameSync10, rmSync as rmSync10, writeFileSync as writeFileSync18 } from "fs";
116062
+ import {
116063
+ chmodSync as chmodSync8,
116064
+ closeSync as closeSync5,
116065
+ lstatSync as lstatSync6,
116066
+ openSync as openSync5,
116067
+ readFileSync as readFileSync46,
116068
+ renameSync as renameSync10,
116069
+ rmSync as rmSync10,
116070
+ writeFileSync as writeFileSync18
116071
+ } from "fs";
116059
116072
  import { join as join118 } from "path";
116060
116073
 
116061
116074
  // packages/device-service-core/src/local-api/errors.ts
@@ -116066,7 +116079,9 @@ class LocalApiError extends Error {
116066
116079
  limit_chars;
116067
116080
  path_refusal;
116068
116081
  command_id;
116069
- not_sent;
116082
+ candidates;
116083
+ incomplete;
116084
+ sign_in_reason;
116070
116085
  constructor(code, reason, extra = {}) {
116071
116086
  super(`${code}: ${reason}`);
116072
116087
  this.name = "LocalApiError";
@@ -116079,40 +116094,112 @@ class LocalApiError extends Error {
116079
116094
  this.path_refusal = extra.path_refusal;
116080
116095
  if (extra.command_id !== undefined)
116081
116096
  this.command_id = extra.command_id;
116082
- if (extra.not_sent === true)
116083
- this.not_sent = true;
116097
+ if (extra.candidates !== undefined)
116098
+ this.candidates = extra.candidates;
116099
+ if (extra.incomplete !== undefined)
116100
+ this.incomplete = extra.incomplete;
116101
+ if (extra.sign_in_reason !== undefined)
116102
+ this.sign_in_reason = extra.sign_in_reason;
116084
116103
  }
116085
116104
  }
116086
116105
  var protocolViolation = (detail) => {
116087
116106
  throw new LocalApiError("protocol_violation", detail);
116088
116107
  };
116089
116108
 
116109
+ // packages/device-service-core/src/local-api/proof.ts
116110
+ import { createHmac as createHmac2, randomBytes as randomBytes7, timingSafeEqual as timingSafeEqual2 } from "crypto";
116111
+
116112
+ // packages/device-service-core/src/local-api/bytes-encoding.ts
116113
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
116114
+ var portable = {
116115
+ hex: (bytes) => Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""),
116116
+ base64: (bytes) => {
116117
+ let out = "";
116118
+ for (let i = 0;i < bytes.length; i += 3) {
116119
+ const [a = 0, b = 0, c = 0] = [bytes[i], bytes[i + 1], bytes[i + 2]];
116120
+ const n = a << 16 | b << 8 | c;
116121
+ out += ALPHABET.charAt(n >> 18 & 63) + ALPHABET.charAt(n >> 12 & 63);
116122
+ out += i + 1 < bytes.length ? ALPHABET.charAt(n >> 6 & 63) : "=";
116123
+ out += i + 2 < bytes.length ? ALPHABET.charAt(n & 63) : "=";
116124
+ }
116125
+ return out;
116126
+ },
116127
+ fromBase64url: (text) => {
116128
+ if (!/^[A-Za-z0-9_-]*={0,2}$/.test(text))
116129
+ throw new SyntaxError("invalid base64url");
116130
+ const clean = text.replaceAll("-", "+").replaceAll("_", "/").replace(/=+$/, "");
116131
+ if (clean.length % 4 === 1)
116132
+ throw new SyntaxError("invalid base64url");
116133
+ const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
116134
+ let bits = 0;
116135
+ let value = 0;
116136
+ let at = 0;
116137
+ for (const ch of clean) {
116138
+ value = value << 6 | ALPHABET.indexOf(ch);
116139
+ bits += 6;
116140
+ if (bits >= 8) {
116141
+ bits -= 8;
116142
+ out[at++] = value >> bits & 255;
116143
+ }
116144
+ }
116145
+ return out;
116146
+ }
116147
+ };
116148
+ var native = (bytes) => bytes;
116149
+ var from = Uint8Array;
116150
+ var toHex = (bytes) => native(bytes).toHex?.() ?? portable.hex(bytes);
116151
+ var toBase64 = (bytes) => native(bytes).toBase64?.() ?? portable.base64(bytes);
116152
+ var toBase64url = (bytes) => native(bytes).toBase64?.({ alphabet: "base64url", omitPadding: true }) ?? portable.base64(bytes).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
116153
+ var fromBase64url = (text) => from.fromBase64?.(text, { alphabet: "base64url" }) ?? portable.fromBase64url(text);
116154
+ var fromBase64 = (text) => {
116155
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(text))
116156
+ throw new SyntaxError("invalid base64");
116157
+ return from.fromBase64?.(text) ?? portable.fromBase64url(text.replaceAll("+", "-").replaceAll("/", "_"));
116158
+ };
116159
+
116160
+ // packages/device-service-core/src/local-api/proof.ts
116161
+ var NONCE_BYTES = 32;
116162
+ var mintNonce = () => toBase64url(randomBytes7(NONCE_BYTES));
116163
+ var mintId = () => toBase64url(randomBytes7(16));
116164
+ var decodedBytes = (value, bytes, what) => {
116165
+ const violation = () => new LocalApiError("protocol_violation", `${what} is not ${bytes} base64url bytes`);
116166
+ let out;
116167
+ try {
116168
+ out = fromBase64url(value);
116169
+ } catch (error) {
116170
+ if (error instanceof Error)
116171
+ throw violation();
116172
+ throw error;
116173
+ }
116174
+ if (out.length !== bytes || toBase64url(out) !== value)
116175
+ throw violation();
116176
+ return out;
116177
+ };
116178
+ var proof = (token, label, nonce, endpoint) => toBase64url(createHmac2("sha256", token).update(label).update(decodedBytes(nonce, NONCE_BYTES, "a nonce")).update(endpoint).digest());
116179
+ var serverProof = (token, clientNonce, endpoint) => proof(token, "server", clientNonce, endpoint);
116180
+ var clientProof = (token, serverNonce, endpoint) => proof(token, "client", serverNonce, endpoint);
116181
+ var proofMatches = (expected, actual) => {
116182
+ const a = new TextEncoder().encode(expected);
116183
+ const b = new TextEncoder().encode(actual);
116184
+ return a.length === b.length && timingSafeEqual2(a, b);
116185
+ };
116186
+
116090
116187
  // packages/device-service-core/src/local-api/dacl.ts
116091
116188
  import { spawn as spawn6 } from "child_process";
116092
116189
  var runPowerShell = async (script, env) => {
116093
116190
  const encoded = Buffer.from(script, "utf16le").toString("base64");
116094
116191
  const proc = spawn6("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
116095
116192
  const chunks = [];
116096
- const errChunks = [];
116097
116193
  proc.stdout.on("data", (chunk) => chunks.push(chunk));
116098
- proc.stderr.on("data", (chunk) => errChunks.push(chunk));
116194
+ proc.stderr.resume();
116099
116195
  const code = await new Promise((resolve, reject) => {
116100
116196
  proc.once("error", reject);
116101
116197
  proc.once("close", (exitCode) => resolve(exitCode ?? -1));
116102
116198
  });
116103
- return {
116104
- code,
116105
- out: Buffer.concat(chunks).toString("utf8"),
116106
- err: Buffer.concat(errChunks).toString("utf8")
116107
- };
116108
- };
116109
- var firstErrorLine = (err) => {
116110
- const line = (err ?? "").split(/\r?\n/).find((text) => text.trim() !== "" && !text.startsWith("#< CLIXML"))?.trim() ?? "";
116111
- return line === "" ? "" : `: ${line.slice(0, 300)}`;
116199
+ return { code, out: new TextDecoder().decode(Buffer.concat(chunks)) };
116112
116200
  };
116113
- var APPLY = String.raw`
116201
+ var APPLY_DACL_SCRIPT = String.raw`
116114
116202
  $ErrorActionPreference = 'Stop'
116115
- trap { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }
116116
116203
  $sid = New-Object System.Security.Principal.SecurityIdentifier($env:LA_SID)
116117
116204
  if ($env:LA_KIND -eq 'dir') {
116118
116205
  $acl = New-Object System.Security.AccessControl.DirectorySecurity
@@ -116127,11 +116214,7 @@ $rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid,
116127
116214
  $acl.SetAccessRuleProtection($true, $false)
116128
116215
  $acl.SetOwner($sid)
116129
116216
  $acl.AddAccessRule($rule)
116130
- if ($env:LA_KIND -eq 'dir') {
116131
- [System.IO.Directory]::SetAccessControl($env:LA_PATH, $acl)
116132
- } else {
116133
- [System.IO.File]::SetAccessControl($env:LA_PATH, $acl)
116134
- }
116217
+ Set-Acl -LiteralPath $env:LA_PATH -AclObject $acl
116135
116218
  Write-Output 'applied'
116136
116219
  `;
116137
116220
  var DESCRIBE_DACL_SCRIPT = String.raw`
@@ -116164,10 +116247,6 @@ public static class LaSddl {
116164
116247
  '@
116165
116248
  [LaSddl]::Read($env:LA_PATH)
116166
116249
  `;
116167
- var SID_TOKEN_SCRIPT = String.raw`
116168
- $ErrorActionPreference = 'Stop'
116169
- (New-Object System.Security.AccessControl.RawSecurityDescriptor("O:$env:LA_SID")).GetSddlForm('Owner')
116170
- `;
116171
116250
  var CURRENT_USER_SID_SCRIPT = "[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value";
116172
116251
  var ACE_TYPES = new Set([
116173
116252
  "A",
@@ -116253,10 +116332,9 @@ var parseSddl = (sddl) => {
116253
116332
  }
116254
116333
  return { sddl, owner, protected: tokens.includes("P"), flags: tokens.join(""), aces };
116255
116334
  };
116256
- var exactDaclVerdict = (dacl, userSid, kind, userAlias) => {
116257
- const isUser = (token) => token === userSid || userAlias !== undefined && token === userAlias;
116335
+ var exactDaclVerdict = (dacl, userSid, kind) => {
116258
116336
  const [ace, ...others] = dacl.aces;
116259
- return isUser(dacl.owner) && dacl.flags === "PAI" && ace !== undefined && others.length === 0 && ace.type === "A" && ace.flags === (kind === "dir" ? "OICI" : "") && ace.rights === "FA" && ace.objectGuid === "" && ace.inheritObjectGuid === "" && isUser(ace.sid) && ace.extra === undefined;
116337
+ return dacl.owner === userSid && dacl.flags === "PAI" && ace !== undefined && others.length === 0 && ace.type === "A" && ace.flags === (kind === "dir" ? "OICI" : "") && ace.rights === "FA" && ace.objectGuid === "" && ace.inheritObjectGuid === "" && ace.sid === userSid && ace.extra === undefined;
116260
116338
  };
116261
116339
  var currentUserSid = async (run = runPowerShell) => {
116262
116340
  const { code, out } = await run(CURRENT_USER_SID_SCRIPT, {});
@@ -116265,16 +116343,6 @@ var currentUserSid = async (run = runPowerShell) => {
116265
116343
  throw new LocalApiError("insecure_state_dir", "the user SID is unreadable");
116266
116344
  return sid;
116267
116345
  };
116268
- var userSidToken = async (userSid, run = runPowerShell) => {
116269
- const { code, out } = await run(SID_TOKEN_SCRIPT, { LA_SID: userSid });
116270
- const match = code === 0 ? /^O:(S-1-\d+(?:-\d+)+|[A-Z]{2})$/.exec(out.trim()) : null;
116271
- return match?.[1];
116272
- };
116273
- var applyExactDacl = async (path, userSid, kind, run = runPowerShell) => {
116274
- const { code, err } = await run(APPLY, { LA_PATH: path, LA_SID: userSid, LA_KIND: kind });
116275
- if (code !== 0)
116276
- throw new LocalApiError("insecure_state_dir", `the exact DACL could not be applied${firstErrorLine(err)}`);
116277
- };
116278
116346
  var describeDacl = async (path, run = runPowerShell) => {
116279
116347
  const { code, out } = await run(DESCRIBE_DACL_SCRIPT, { LA_PATH: path });
116280
116348
  const dacl = code === 0 ? parseSddl(out.trim()) : undefined;
@@ -116282,51 +116350,16 @@ var describeDacl = async (path, run = runPowerShell) => {
116282
116350
  throw new LocalApiError("insecure_state_dir", "the DACL could not be read back");
116283
116351
  return dacl;
116284
116352
  };
116285
- var verifyExactDacl = async (path, userSid, kind, run = runPowerShell) => {
116286
- let dacl;
116287
- try {
116288
- dacl = await describeDacl(path, run);
116289
- } catch (error) {
116290
- if (error instanceof LocalApiError)
116291
- return false;
116292
- throw error;
116293
- }
116294
- return exactDaclVerdict(dacl, userSid, kind, await userSidToken(userSid, run));
116295
- };
116296
- var windowsSecureFile = (userSid, run = runPowerShell) => async (path, kind) => {
116297
- const target = kind === "dir" ? "dir" : "file";
116298
- await applyExactDacl(path, userSid, target, run);
116299
- if (!await verifyExactDacl(path, userSid, target, run))
116300
- throw new LocalApiError("insecure_state_dir", "the DACL is not exactly one ACE for the user");
116301
- };
116302
116353
 
116303
116354
  // packages/device-service-core/src/local-api/access.ts
116304
116355
  var TOKEN_FILE = "token";
116305
116356
  var TOKEN_BYTES = 32;
116306
- var NONCE_BYTES = 32;
116307
116357
  var SOCKET_FILE = "service.sock";
116308
- var base64url2 = (bytes) => Buffer.from(bytes).toString("base64url");
116309
- var mintNonce = () => base64url2(randomBytes7(NONCE_BYTES));
116310
- var mintId = () => base64url2(randomBytes7(16));
116311
116358
  var insecure = (detail) => {
116312
116359
  throw new LocalApiError("insecure_state_dir", detail);
116313
116360
  };
116314
- var decoded = (value, bytes, what) => {
116315
- const out = Buffer.from(value, "base64url");
116316
- if (out.length !== bytes || base64url2(out) !== value)
116317
- throw new LocalApiError("protocol_violation", `${what} is not ${bytes} base64url bytes`);
116318
- return out;
116319
- };
116320
116361
  var UNIX_ENDPOINT = "unix";
116321
116362
  var tcpEndpoint = (port) => `tcp:${port}`;
116322
- var proof = (token, label, nonce, endpoint) => base64url2(createHmac2("sha256", token).update(label).update(decoded(nonce, NONCE_BYTES, "a nonce")).update(endpoint, "utf8").digest());
116323
- var serverProof = (token, clientNonce, endpoint) => proof(token, "server", clientNonce, endpoint);
116324
- var clientProof = (token, serverNonce, endpoint) => proof(token, "client", serverNonce, endpoint);
116325
- var proofMatches = (expected, actual) => {
116326
- const a = Buffer.from(expected);
116327
- const b = Buffer.from(actual);
116328
- return a.length === b.length && timingSafeEqual2(a, b);
116329
- };
116330
116363
  var isMissing = (error) => typeof error === "object" && error !== null && ("code" in error) && (error.code === "ENOENT" || error.code === "ENOTDIR");
116331
116364
  var currentUid = () => process.getuid?.() ?? insecure("this platform has no uid");
116332
116365
  var privateEntry = (path, kind, uid, checkMode = true) => {
@@ -116368,7 +116401,7 @@ var readToken = (stateDir) => {
116368
116401
  throw error;
116369
116402
  }
116370
116403
  try {
116371
- return decoded(value, TOKEN_BYTES, "the token");
116404
+ return decodedBytes(value, TOKEN_BYTES, "the token");
116372
116405
  } catch (error) {
116373
116406
  if (error instanceof LocalApiError)
116374
116407
  return insecure("the token is malformed");
@@ -116380,31 +116413,45 @@ var readToken = (stateDir) => {
116380
116413
  import { createHash as createHash16 } from "crypto";
116381
116414
 
116382
116415
  // packages/device-service-core/src/local-api/spec-proto.ts
116416
+ class ProtoError extends Error {
116417
+ code;
116418
+ constructor(code, detail) {
116419
+ super(`${code}: ${detail}`);
116420
+ this.code = code;
116421
+ this.name = "ProtoError";
116422
+ }
116423
+ }
116383
116424
  var SESSION_BLOB_MAX = 16777216;
116384
- var SESSION_COMMAND_TEXT_MAX_CHARS = 1e6;
116385
- var SESSION_COMMAND_TEXT_MAX_BYTES = 3000000;
116425
+ var SESSION_KIND_MAX_CHARS = 32;
116426
+ var SESSION_ID_MAX_CHARS = 128;
116386
116427
  var SESSION_DEVICE_MAX_CHARS = 64;
116387
116428
  var SESSION_PROJECT_MAX_CHARS = 256;
116388
- var SESSION_ID_MAX_CHARS = 128;
116389
- var SESSION_KIND_MAX_CHARS = 32;
116390
116429
  var SESSION_READ_TAIL_MAX = 200;
116391
116430
  var SESSION_SUMMARY_TITLE_MAX_CHARS = 256;
116392
116431
  var SESSION_SUMMARY_PROJECT_MAX_CHARS = 128;
116393
116432
  var SESSION_SUMMARY_PATH_MAX_CHARS = 1024;
116394
-
116395
- class ProtoError extends Error {
116396
- code;
116397
- constructor(code, message) {
116398
- super(message);
116399
- this.code = code;
116400
- }
116401
- }
116402
- var validateCommandText = (text) => {
116403
- if (typeof text !== "string" || !text.isWellFormed())
116404
- throw new ProtoError("malformed", "command text");
116405
- if (text.length > SESSION_COMMAND_TEXT_MAX_CHARS || new TextEncoder().encode(text).length > SESSION_COMMAND_TEXT_MAX_BYTES)
116406
- throw new ProtoError("payload_too_large", "session command text over the limit");
116407
- return text;
116433
+ var SESSION_MODEL_PROVIDER_MAX_CHARS = 64;
116434
+ var SESSION_MODEL_ID_MAX_CHARS = 128;
116435
+ var SESSION_SETTLED_DAYS_MAX = 36500;
116436
+ var SESSION_SETTLED_THREAD_TITLE_MAX_CHARS = 256;
116437
+ var SESSION_KEY_CHARS = 22;
116438
+ var UNSAFE_KEYS2 = ["__proto__", "constructor", "prototype"];
116439
+ var sessionFail = (detail) => {
116440
+ throw new ProtoError("bad_request", `session payload ${detail}`);
116441
+ };
116442
+ var B64URL = /^[A-Za-z0-9_-]+$/;
116443
+ var base64UrlId = (v, n, detail) => typeof v === "string" && v.length === n && B64URL.test(v) ? v : sessionFail(detail);
116444
+ var sessionKeyOf = (v) => base64UrlId(v, SESSION_KEY_CHARS, "session key");
116445
+ var safeKey = (key, detail) => UNSAFE_KEYS2.includes(key) ? sessionFail(detail) : key;
116446
+ var STREAM_INLINE_MAX = 12000;
116447
+ var validateStreamSessionKey = (v) => sessionKeyOf(v);
116448
+ var validRosterDeviceId = (value) => typeof value === "string" && value.length > 0 && value.length <= 64 && value.isWellFormed();
116449
+ var METHOD = /^(?=.{1,64}$)[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$/;
116450
+ var methodOf = (v, what) => {
116451
+ const type = typeof v === "string" && METHOD.test(v) ? v : sessionFail(what);
116452
+ for (const segment of type.split("."))
116453
+ safeKey(segment, what);
116454
+ return type;
116408
116455
  };
116409
116456
 
116410
116457
  // packages/device-service-core/src/local-api/limits.ts
@@ -116412,6 +116459,10 @@ var LOCAL_INLINE_MAX = 524288;
116412
116459
  var LOCAL_CHUNK_MAX = 262144;
116413
116460
  var LOCAL_JSON_EXPANSION_MAX = 6;
116414
116461
  var LOCAL_BLOB_MAX = LOCAL_JSON_EXPANSION_MAX * SESSION_BLOB_MAX;
116462
+ var MACHINE_UPLOAD_MAX_BYTES = 3840000;
116463
+ var MACHINE_UPLOAD_PARTS_MAX = Math.ceil(MACHINE_UPLOAD_MAX_BYTES / LOCAL_CHUNK_MAX);
116464
+ var grouped = (n) => n.toLocaleString("en-US");
116465
+ var MACHINE_UPLOAD_LIMIT = `an uploaded batch is at most ${grouped(MACHINE_UPLOAD_MAX_BYTES)} bytes (${MACHINE_UPLOAD_PARTS_MAX} parts of ${grouped(LOCAL_CHUNK_MAX)} bytes)`;
116415
116466
  var encoder2 = new TextEncoder;
116416
116467
  var lineBytes = (value) => encoder2.encode(JSON.stringify(value)).length + 1;
116417
116468
  var sha256Hex = (data) => createHash16("sha256").update(data).digest("hex");
@@ -116420,7 +116471,7 @@ var chunkPayload = (data) => {
116420
116471
  for (let off = 0;off < data.length; off += LOCAL_CHUNK_MAX)
116421
116472
  chunks.push({
116422
116473
  off,
116423
- b: Buffer.from(data.subarray(off, off + LOCAL_CHUNK_MAX)).toString("base64")
116474
+ b: toBase64(data.subarray(off, off + LOCAL_CHUNK_MAX))
116424
116475
  });
116425
116476
  return chunks;
116426
116477
  };
@@ -116443,8 +116494,10 @@ var STATUS_STATES = [
116443
116494
  "authorization_stale",
116444
116495
  "service_degraded",
116445
116496
  "update_required",
116446
- "signed_out"
116497
+ "signed_out",
116498
+ "fail_closed"
116447
116499
  ];
116500
+ var STATUS_UPDATE_PHASES = ["trial", "committed"];
116448
116501
  var POLICY_STATES = ["off", "pending", "active"];
116449
116502
  var THIS_DEVICE_STATES = [
116450
116503
  "unclassified",
@@ -116470,9 +116523,26 @@ var ROUND_DEVICE_STATES = [
116470
116523
  var LISTING_SOURCES = ["live", "cache"];
116471
116524
  var SESSION_ROW_STATES = ["running", "idle", "ended"];
116472
116525
  var FILTER_KEYS = ["device", "project", "state"];
116526
+ var LISTING_SETTLED_BY_KINDS = [
116527
+ "user",
116528
+ "agent",
116529
+ "pr-merged",
116530
+ "pr-closed",
116531
+ "inactivity"
116532
+ ];
116473
116533
  var BLOB_OF = ["state", "record", "entry"];
116474
- var BLOB_ABORT_REASONS = ["digest_mismatch", "source_gone", "too_large", "detached"];
116475
- var UPLOAD_ABORT_REASONS = ["message_too_long", "parts_conflict", "malformed", "detached"];
116534
+ var BLOB_ABORT_REASONS = [
116535
+ "digest_mismatch",
116536
+ "source_gone",
116537
+ "too_large",
116538
+ "detached"
116539
+ ];
116540
+ var UPLOAD_ABORT_REASONS = [
116541
+ "message_too_long",
116542
+ "parts_conflict",
116543
+ "malformed",
116544
+ "detached"
116545
+ ];
116476
116546
  var DETACH_REASONS = [
116477
116547
  "authorization_expired",
116478
116548
  "activation_pending",
@@ -116485,6 +116555,14 @@ var DETACH_REASONS = [
116485
116555
  "session_closed",
116486
116556
  "session_replaced"
116487
116557
  ];
116558
+ var UPDATE_NOTICE_PHASES = [
116559
+ "draining",
116560
+ "final",
116561
+ "updated",
116562
+ "rolled_back",
116563
+ "failed"
116564
+ ];
116565
+ var UPDATE_POLICIES = ["defer", "force", "ask"];
116488
116566
  var ATTACH_PENDING_REASONS = ["stream_key_pending"];
116489
116567
  var COMMAND_ID_CHARS = 22;
116490
116568
  var COMMAND_STATES = [
@@ -116509,7 +116587,8 @@ var COMMAND_UNCERTAIN_REASONS = [
116509
116587
  "cancelled",
116510
116588
  "hand_restarted",
116511
116589
  "result_expired",
116512
- "record_too_large"
116590
+ "record_too_large",
116591
+ "result_undecodable"
116513
116592
  ];
116514
116593
  var COMMAND_REFUSAL_REASONS = [
116515
116594
  "parts_conflict",
@@ -116527,9 +116606,15 @@ var COMMAND_REFUSAL_REASONS = [
116527
116606
  "scope_unknown",
116528
116607
  "scope_closed",
116529
116608
  "epoch_fenced",
116530
- "epoch_step_exceeded"
116609
+ "epoch_step_exceeded",
116610
+ "route_unlisted",
116611
+ "rate_limited",
116612
+ "unknown_reason"
116613
+ ];
116614
+ var RETRYABLE_STATES = [
116615
+ "not confirmed",
116616
+ "not delivered: never_sent"
116531
116617
  ];
116532
- var RETRYABLE_STATES = ["not confirmed", "not delivered: never_sent"];
116533
116618
  var ERROR_CODES = [
116534
116619
  "unauthenticated",
116535
116620
  "client_proof_invalid",
@@ -116551,6 +116636,7 @@ var ERROR_CODES = [
116551
116636
  "peer_not_found",
116552
116637
  "peer_not_session_client",
116553
116638
  "session_not_found",
116639
+ "session_ambiguous",
116554
116640
  "engine_too_old",
116555
116641
  "not_attached",
116556
116642
  "command_id_conflict",
@@ -116563,6 +116649,13 @@ var ERROR_CODES = [
116563
116649
  "unsupported",
116564
116650
  "unknown_delivery"
116565
116651
  ];
116652
+ var ALIAS_INCOMPLETE_REASONS = [
116653
+ "cache",
116654
+ "timed_out",
116655
+ "undelivered",
116656
+ "skipped",
116657
+ "stopped"
116658
+ ];
116566
116659
  var PATH_REFUSAL_PROBLEMS = [
116567
116660
  "not_absolute",
116568
116661
  "not_found",
@@ -116573,6 +116666,16 @@ var PATH_REFUSAL_PROBLEMS = [
116573
116666
  "world_writable",
116574
116667
  "windows_acl"
116575
116668
  ];
116669
+ var MACHINE_OP_STATES = [
116670
+ "queued",
116671
+ "transport_confirmed",
116672
+ "host_dispatched",
116673
+ "host_applied",
116674
+ "link_down"
116675
+ ];
116676
+ var MACHINE_STATES = ["online", "offline", "unsupported"];
116677
+ var MACHINE_LOOKUP_STATES = ["in_flight", "terminal", "unknown"];
116678
+ var MACHINE_BLOB_ABORT_REASONS = ["digest_mismatch", "source_gone", "too_large"];
116576
116679
  var CHANNEL_CLOSED_REASONS = [
116577
116680
  "event_overflow",
116578
116681
  "event_too_large",
@@ -116652,11 +116755,18 @@ var sha256Field = (v, what) => typeof v === "string" && SHA256_HEX.test(v) ? v :
116652
116755
  var base64Bytes = (v, max, what) => {
116653
116756
  if (typeof v !== "string" || v.length === 0 || v.length > 4 * Math.ceil(max / 3))
116654
116757
  return fail(what);
116655
- const bytes = Buffer.from(v, "base64");
116656
- return bytes.length <= max && bytes.toString("base64") === v ? new Uint8Array(bytes) : fail(what);
116758
+ let bytes;
116759
+ try {
116760
+ bytes = fromBase64(v);
116761
+ } catch (error) {
116762
+ if (error instanceof Error)
116763
+ return fail(what);
116764
+ throw error;
116765
+ }
116766
+ return bytes.length <= max && toBase64(bytes) === v ? bytes : fail(what);
116657
116767
  };
116658
- var UNSAFE_KEYS2 = ["__proto__", "constructor", "prototype"];
116659
- var safeKey = (key, what) => UNSAFE_KEYS2.includes(key) ? fail(what) : key;
116768
+ var UNSAFE_KEYS3 = ["__proto__", "constructor", "prototype"];
116769
+ var safeKey2 = (key, what) => UNSAFE_KEYS3.includes(key) ? fail(what) : key;
116660
116770
  var jsonValue = (v, what) => {
116661
116771
  if (v === null || typeof v === "boolean" || typeof v === "string")
116662
116772
  return v;
@@ -116676,9 +116786,20 @@ var jsonObject = (v, what) => {
116676
116786
  out[key] = jsonValue(item, what);
116677
116787
  return out;
116678
116788
  };
116789
+ // packages/device-service-core/src/local-api/command-text.ts
116790
+ var COMMAND_TEXT_MAX_CHARS = 1e6;
116791
+ var COMMAND_TEXT_MAX_BYTES = 3000000;
116792
+ var validateCommandText = (text) => {
116793
+ if (typeof text !== "string" || !text.isWellFormed())
116794
+ throw new ProtoError("bad_request", "session payload command text");
116795
+ if (text.length > COMMAND_TEXT_MAX_CHARS || new TextEncoder().encode(text).length > COMMAND_TEXT_MAX_BYTES)
116796
+ throw new ProtoError("payload_too_large", "session command text over the limit");
116797
+ return text;
116798
+ };
116799
+
116679
116800
  // packages/device-service-core/src/local-api/upload.ts
116680
- var MESSAGE_LIMIT_CHARS = SESSION_COMMAND_TEXT_MAX_CHARS;
116681
- var LOCAL_UPLOAD_PARTS_MAX = Math.ceil(SESSION_COMMAND_TEXT_MAX_BYTES / LOCAL_CHUNK_MAX);
116801
+ var MESSAGE_LIMIT_CHARS = COMMAND_TEXT_MAX_CHARS;
116802
+ var LOCAL_UPLOAD_PARTS_MAX = Math.ceil(COMMAND_TEXT_MAX_BYTES / LOCAL_CHUNK_MAX);
116682
116803
  var checkCommandText = (value) => {
116683
116804
  try {
116684
116805
  validateCommandText(value);
@@ -116712,7 +116833,7 @@ class LocalBlobAssembler {
116712
116833
  return;
116713
116834
  case "session.blob_chunk": {
116714
116835
  const open = this.#current(event.id);
116715
- const data = Buffer.from(event.b, "base64");
116836
+ const data = fromBase64(event.b);
116716
116837
  const end = this.#received + data.length;
116717
116838
  if (event.off !== this.#received || end > open.bytes)
116718
116839
  return protocolViolation("blob chunk out of order");
@@ -116819,6 +116940,107 @@ class ListingTracker {
116819
116940
  }
116820
116941
  }
116821
116942
 
116943
+ // packages/device-service-core/src/local-api/session-ref.ts
116944
+ var KEY_CHARS = 22;
116945
+ var MIN_CHARS = KEY_CHARS + 2;
116946
+ var MAX_CHARS = KEY_CHARS + 65;
116947
+ var isStreamSessionKey = (v) => {
116948
+ try {
116949
+ validateStreamSessionKey(v);
116950
+ return true;
116951
+ } catch (error) {
116952
+ if (error instanceof ProtoError)
116953
+ return false;
116954
+ throw error;
116955
+ }
116956
+ };
116957
+ var parseSessionRef = (v) => {
116958
+ if (typeof v !== "string" || !v.isWellFormed())
116959
+ return;
116960
+ if (v.length < MIN_CHARS || v.length > MAX_CHARS || v[v.length - KEY_CHARS - 1] !== ".")
116961
+ return;
116962
+ const device = v.slice(0, -KEY_CHARS - 1);
116963
+ const key = v.slice(-KEY_CHARS);
116964
+ return isStreamSessionKey(key) && validRosterDeviceId(device) ? { device, key } : undefined;
116965
+ };
116966
+ var formatSessionRef = (ref) => {
116967
+ if (!isStreamSessionKey(ref.key) || !validRosterDeviceId(ref.device))
116968
+ throw new RangeError("not a session id: the device or the key is malformed");
116969
+ return `${ref.device}.${ref.key}`;
116970
+ };
116971
+ var CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
116972
+ var ALIAS_MAX_CHARS = 256;
116973
+ var unsafeAlias = (s) => s !== s.trim() || CONTROL.test(s) || parseSessionRef(s) !== undefined || isStreamSessionKey(s);
116974
+
116975
+ // packages/device-service-core/src/local-api/validate-snapshot-from.ts
116976
+ var SNAPSHOT_OPTIONAL_FIELDS = ["from"];
116977
+ var snapshotFromOf = (v) => {
116978
+ const m = known(v, ["last_entry_id", "delta"], [], "from");
116979
+ return {
116980
+ last_entry_id: entryId(m["last_entry_id"], "from.last_entry_id"),
116981
+ delta: bool(m["delta"], "from.delta")
116982
+ };
116983
+ };
116984
+
116985
+ // packages/device-service-core/src/local-api/protocol-status.ts
116986
+ var SIGN_IN_REASONS = ["not_adopted", "device_revoked", "reauth_required"];
116987
+
116988
+ // packages/device-service-core/src/local-api/validate-session-answer.ts
116989
+ var refOf = (v, what) => {
116990
+ const m = known(v, ["device", "key", "session"], [], what);
116991
+ const ref = parseSessionRef(m["session"]);
116992
+ if (ref === undefined || ref.device !== m["device"] || ref.key !== m["key"])
116993
+ return fail(what);
116994
+ return { device: ref.device, key: ref.key, session: formatSessionRef(ref) };
116995
+ };
116996
+ var commandAnswerOf = (v) => {
116997
+ const m = known(v, ["command_id"], ["device", "key", "session"], "session.command data");
116998
+ const command_id = commandId(m["command_id"]);
116999
+ if (m["device"] === undefined && m["key"] === undefined && m["session"] === undefined)
117000
+ return { command_id };
117001
+ const { device, key, session } = m;
117002
+ return { command_id, ...refOf({ device, key, session }, "session.command data") };
117003
+ };
117004
+ var listOf = (v, item, what) => Array.isArray(v) ? v.map(item) : fail(what);
117005
+ var incompleteOf = (v) => {
117006
+ const m = known(v, ["device", "reason"], [], "error.incomplete");
117007
+ const device = m["device"];
117008
+ if (typeof device !== "string" || device.length === 0)
117009
+ return fail("error.incomplete");
117010
+ return { device, reason: oneOf(ALIAS_INCOMPLETE_REASONS, m["reason"], "error.incomplete") };
117011
+ };
117012
+ var aliasErrorFields = (code, m) => {
117013
+ const { candidates, incomplete } = m;
117014
+ if (candidates !== undefined !== (code === "session_ambiguous"))
117015
+ return fail("error.candidates");
117016
+ if (incomplete !== undefined && code !== "session_not_found")
117017
+ return fail("error.incomplete");
117018
+ return {
117019
+ ...candidates === undefined ? {} : {
117020
+ candidates: listOf(candidates, (c) => refOf(c, "error.candidates"), "error.candidates")
117021
+ },
117022
+ ...incomplete === undefined ? {} : { incomplete: listOf(incomplete, incompleteOf, "error.incomplete") }
117023
+ };
117024
+ };
117025
+
117026
+ // packages/device-service-core/src/local-api/validate-update.ts
117027
+ var READY_REASON_MAX_CHARS = 64;
117028
+ var statusUpdateOf = (v) => {
117029
+ const m = known(v, ["update_id", "phase", "target_version", "ready", "ready_reason"], [], "status.update");
117030
+ return {
117031
+ update_id: localId(m["update_id"], "status.update.update_id"),
117032
+ phase: oneOf(STATUS_UPDATE_PHASES, m["phase"], "status.update.phase"),
117033
+ target_version: semver(m["target_version"], "status.update.target_version"),
117034
+ ready: bool(m["ready"], "status.update.ready"),
117035
+ ready_reason: nullable2(m["ready_reason"], (r) => text(r, READY_REASON_MAX_CHARS, "status.update.ready_reason"))
117036
+ };
117037
+ };
117038
+ var updateCommittedOf = (m, id) => ({
117039
+ id,
117040
+ type: "owner.update_committed",
117041
+ update_id: localId(m["update_id"], "update_id")
117042
+ });
117043
+
116822
117044
  // packages/device-service-core/src/local-api/validate-shapes.ts
116823
117045
  var CODE = /^[a-z_]{1,64}$/;
116824
117046
  var ATTACH_ID_MAX = 4294967295;
@@ -116855,9 +117077,8 @@ var policyOf = (v) => {
116855
117077
  };
116856
117078
  };
116857
117079
  var statusOf = (v) => {
116858
- const m = known(v, ["state", "since_ms", "device", "origin_configured", "enabled"], ["detail", "policy"], "status");
116859
- const detail = m["detail"];
116860
- const policy = m["policy"];
117080
+ const m = known(v, ["state", "since_ms", "device", "origin_configured", "enabled"], ["detail", "policy", "update", "exe"], "status");
117081
+ const { detail, policy, update, exe } = m;
116861
117082
  return {
116862
117083
  state: oneOf(STATUS_STATES, m["state"], "status.state"),
116863
117084
  since_ms: millis(m["since_ms"], "status.since_ms"),
@@ -116865,60 +117086,41 @@ var statusOf = (v) => {
116865
117086
  device: nullable2(m["device"], (d) => deviceRef(d, "status.device", known)),
116866
117087
  origin_configured: bool(m["origin_configured"], "status.origin_configured"),
116867
117088
  enabled: bool(m["enabled"], "status.enabled"),
116868
- ...policy === undefined ? {} : { policy: policyOf(policy) }
117089
+ ...policy === undefined ? {} : { policy: policyOf(policy) },
117090
+ ...update === undefined ? {} : { update: statusUpdateOf(update) },
117091
+ ...exe === undefined ? {} : { exe: absolutePath(exe, "status.exe") }
116869
117092
  };
116870
117093
  };
116871
117094
  var detailOf = (v) => {
116872
- const m = known(v, ["code", "action"], [], "status.detail");
116873
- const code = m["code"];
117095
+ const m = known(v, ["code", "action"], ["sign_in_reason"], "status.detail");
117096
+ const { code, sign_in_reason: reason } = m;
116874
117097
  return {
116875
117098
  code: typeof code === "string" && CODE.test(code) ? code : fail("status.detail.code"),
116876
- action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "status.detail.action"))
117099
+ action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "status.detail.action")),
117100
+ ...reason === undefined ? {} : { sign_in_reason: oneOf(SIGN_IN_REASONS, reason, "status.detail.sign_in_reason") }
116877
117101
  };
116878
117102
  };
116879
117103
  var deviceRowOf = (v) => {
116880
- const m = known(v, ["device", "label", "kind", "platform", "last_seen_ms", "online"], [], "device row");
117104
+ const m = known(v, ["device", "label", "kind", "platform", "last_seen_ms", "online"], ["managed"], "device row");
117105
+ const managed = m["managed"];
116881
117106
  return {
116882
117107
  device: deviceId(m["device"]),
116883
117108
  label: text(m["label"], LABEL_MAX_CHARS, "label", 0),
116884
117109
  kind: text(m["kind"], 64, "kind", 0),
116885
117110
  platform: text(m["platform"], 64, "platform", 0),
116886
117111
  last_seen_ms: nullable2(m["last_seen_ms"], (t) => millis(t, "last_seen_ms")),
116887
- online: bool(m["online"], "online")
117112
+ online: bool(m["online"], "online"),
117113
+ ...managed === undefined ? {} : { managed: bool(managed, "managed") }
116888
117114
  };
116889
117115
  };
116890
- var ROW_FIELDS = ["device", "session_id", "title", "project", "path", "state", "updated_ms", "source", "as_of"];
116891
- var ROW_KIND = new RegExp(`^[a-z][a-z0-9_-]{0,${SESSION_KIND_MAX_CHARS - 1}}$`);
116892
- var rowLinks = (m) => {
116893
- const kind = m["kind"];
116894
- if (Object.hasOwn(m, "parent") !== Object.hasOwn(m, "parent_listed"))
116895
- fail("parent_listed");
116896
- return {
116897
- ...kind === undefined ? {} : { kind: typeof kind === "string" && ROW_KIND.test(kind) ? kind : fail("row kind") },
116898
- ...m["parent"] === undefined ? {} : {
116899
- parent: sessionId(m["parent"]),
116900
- parent_listed: bool(m["parent_listed"], "parent_listed")
116901
- }
116902
- };
116903
- };
116904
- var listingRowOf = (v) => {
116905
- const m = known(v, ROW_FIELDS, ["kind", "parent", "parent_listed", "durable_id"], "listing row");
116906
- const durable = m["durable_id"];
116907
- return {
116908
- ...rowLinks(m),
116909
- ...durable === undefined ? {} : { durable_id: text(durable, SESSION_ID_MAX_CHARS, "durable_id") },
116910
- device: deviceId(m["device"]),
116911
- session_id: sessionId(m["session_id"]),
116912
- title: text(m["title"], SESSION_SUMMARY_TITLE_MAX_CHARS, "title", 0),
116913
- project: text(m["project"], SESSION_SUMMARY_PROJECT_MAX_CHARS, "project"),
116914
- path: text(m["path"], SESSION_SUMMARY_PATH_MAX_CHARS, "path"),
116915
- state: oneOf(SESSION_ROW_STATES, m["state"], "row state"),
116916
- updated_ms: millis(m["updated_ms"], "updated_ms"),
116917
- source: oneOf(LISTING_SOURCES, m["source"], "row source"),
116918
- as_of: millis(m["as_of"], "as_of")
116919
- };
116920
- };
116921
- var BODY_FIELDS = ["attach_id", "cursor", "state", "entries", "history_truncated", "oldest_entry_id"];
117116
+ var BODY_FIELDS = [
117117
+ "attach_id",
117118
+ "cursor",
117119
+ "state",
117120
+ "entries",
117121
+ "history_truncated",
117122
+ "oldest_entry_id"
117123
+ ];
116922
117124
  var snapshotBodyOf = (m) => {
116923
117125
  const cursor = known(m["cursor"], ["marker_id", "last_entry_id"], [], "cursor");
116924
117126
  const entries = m["entries"];
@@ -116933,10 +117135,11 @@ var snapshotBodyOf = (m) => {
116933
117135
  state: jsonObject(m["state"], "state"),
116934
117136
  entries: entries.map((e) => jsonValue(e, "entries")),
116935
117137
  history_truncated: bool(m["history_truncated"], "history_truncated"),
116936
- oldest_entry_id: nullable2(m["oldest_entry_id"], (e) => entryId(e, "oldest_entry_id"))
117138
+ oldest_entry_id: nullable2(m["oldest_entry_id"], (e) => entryId(e, "oldest_entry_id")),
117139
+ ...m["from"] === undefined ? {} : { from: snapshotFromOf(m["from"]) }
116937
117140
  };
116938
117141
  };
116939
- var snapshotBlobOf = (v) => snapshotBodyOf(known(v, BODY_FIELDS, [], "snapshot"));
117142
+ var snapshotBlobOf = (v) => snapshotBodyOf(known(v, BODY_FIELDS, SNAPSHOT_OPTIONAL_FIELDS, "snapshot"));
116940
117143
  var SNAPSHOT_FIELDS = BODY_FIELDS;
116941
117144
  var readEntryOf = (v) => {
116942
117145
  const m = known(v, ["kind", "entry_id"], ["entry", "bytes", "sha256"], "read entry");
@@ -116963,8 +117166,11 @@ var pathRefusalOf = (v) => {
116963
117166
  };
116964
117167
  };
116965
117168
  var errorBodyOf = (v) => {
116966
- const m = known(v, ["code", "reason", "action"], ["limit_chars", "path_refusal"], "error");
117169
+ const m = known(v, ["code", "reason", "action"], ["limit_chars", "path_refusal", "candidates", "incomplete", "sign_in_reason"], "error");
116967
117170
  const code = oneOf(ERROR_CODES, m["code"], "error.code");
117171
+ const reason = m["sign_in_reason"];
117172
+ if (reason !== undefined && code !== "sign_in_required")
117173
+ return fail("error.sign_in_reason");
116968
117174
  const limit = m["limit_chars"];
116969
117175
  if (code === "message_too_long" !== (limit !== undefined))
116970
117176
  return fail("error.limit_chars");
@@ -116976,78 +117182,12 @@ var errorBodyOf = (v) => {
116976
117182
  reason: text(m["reason"], REASON_MAX_CHARS, "error.reason", 0),
116977
117183
  action: nullable2(m["action"], (a) => text(a, LABEL_MAX_CHARS, "error.action")),
116978
117184
  ...limit === undefined ? {} : { limit_chars: uint(limit, 1, MILLIS_MAX, "error.limit_chars") },
116979
- ...refusal === undefined ? {} : { path_refusal: pathRefusalOf(refusal) }
117185
+ ...refusal === undefined ? {} : { path_refusal: pathRefusalOf(refusal) },
117186
+ ...reason === undefined ? {} : { sign_in_reason: oneOf(SIGN_IN_REASONS, reason, "error.sign_in_reason") },
117187
+ ...aliasErrorFields(code, m)
116980
117188
  };
116981
117189
  };
116982
117190
 
116983
- // packages/device-service-core/src/local-api/validate-command.ts
116984
- var commandRpcOf = (v) => jsonObject(v, "rpc");
116985
- var requestFields = (v, names, optional = []) => exactly(v, ["id", "type", ...names], optional, "request");
116986
- var commandIdField = (v) => v === undefined ? {} : { command_id: commandId(v) };
116987
- var ROUTE_FIELDS = ["command_id", "delegated", "endpoint"];
116988
- var routeFields = (m) => {
116989
- const delegated = m["delegated"];
116990
- if (delegated !== undefined && delegated !== true)
116991
- return fail("delegated");
116992
- return {
116993
- ...delegated === true ? { delegated: true } : {},
116994
- ...m["endpoint"] === undefined ? {} : { endpoint: endpointKey(m["endpoint"]) }
116995
- };
116996
- };
116997
- var COMMAND_REQUEST_VALIDATORS = {
116998
- "session.command": (v, id) => {
116999
- if (Object.hasOwn(v, "device")) {
117000
- const m = requestFields(v, ["device", "endpoint", "rpc"], ["command_id", "locate"]);
117001
- const locate = m["locate"];
117002
- if (locate !== undefined && locate !== true)
117003
- return fail("locate");
117004
- return {
117005
- id,
117006
- type: "session.command",
117007
- device: deviceId(m["device"]),
117008
- endpoint: endpointKey(m["endpoint"]),
117009
- ...commandIdField(m["command_id"]),
117010
- ...locate === true ? { locate: true } : {},
117011
- rpc: commandRpcOf(m["rpc"])
117012
- };
117013
- }
117014
- if (Object.hasOwn(v, "upload_id")) {
117015
- const m = requestFields(v, ["attach", "upload_id"], ROUTE_FIELDS);
117016
- return {
117017
- id,
117018
- type: "session.command",
117019
- attach: localId(m["attach"], "attach"),
117020
- ...commandIdField(m["command_id"]),
117021
- upload_id: localId(m["upload_id"], "upload_id"),
117022
- ...routeFields(m)
117023
- };
117024
- }
117025
- const m = requestFields(v, ["attach", "rpc"], ROUTE_FIELDS);
117026
- return {
117027
- id,
117028
- type: "session.command",
117029
- attach: localId(m["attach"], "attach"),
117030
- ...commandIdField(m["command_id"]),
117031
- rpc: commandRpcOf(m["rpc"]),
117032
- ...routeFields(m)
117033
- };
117034
- },
117035
- "session.command_part": (v, id) => {
117036
- const m = requestFields(v, ["attach", "upload_id", "index", "count", "b"]);
117037
- const count = uint(m["count"], 1, LOCAL_UPLOAD_PARTS_MAX, "count");
117038
- base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117039
- return {
117040
- id,
117041
- type: "session.command_part",
117042
- attach: localId(m["attach"], "attach"),
117043
- upload_id: localId(m["upload_id"], "upload_id"),
117044
- index: uint(m["index"], 0, count - 1, "index"),
117045
- count,
117046
- b: typeof m["b"] === "string" ? m["b"] : fail("b")
117047
- };
117048
- }
117049
- };
117050
-
117051
117191
  // packages/device-service-core/src/local-api/validate-stream-events.ts
117052
117192
  var eventFields = (v, names, optional = []) => known(v, ["type", "kind", ...names], optional, "event");
117053
117193
  var attachOf = (m) => localId(m["attach"], "attach");
@@ -117074,9 +117214,15 @@ var targetOf = (m) => {
117074
117214
  }
117075
117215
  }
117076
117216
  };
117217
+ var seqsOf = (v, count) => {
117218
+ if (!Array.isArray(v) || v.length !== count)
117219
+ return fail("seqs");
117220
+ const seqs = v.map((s) => uint(s, 1, Number.MAX_SAFE_INTEGER, "seq"));
117221
+ return seqs.every((s, i) => i === 0 || s > (seqs[i - 1] ?? s)) ? seqs : fail("seqs order");
117222
+ };
117077
117223
  var STREAM_EVENT_VALIDATORS = {
117078
117224
  "session.snapshot": (v) => {
117079
- const m = eventFields(v, ["attach", ...SNAPSHOT_FIELDS]);
117225
+ const m = eventFields(v, ["attach", ...SNAPSHOT_FIELDS], SNAPSHOT_OPTIONAL_FIELDS);
117080
117226
  return { type: "event", kind: "session.snapshot", attach: attachOf(m), ...snapshotBodyOf(m) };
117081
117227
  },
117082
117228
  "session.snapshot_loading": (v) => {
@@ -117089,7 +117235,7 @@ var STREAM_EVENT_VALIDATORS = {
117089
117235
  };
117090
117236
  },
117091
117237
  "session.records": (v) => {
117092
- const m = eventFields(v, ["attach", "attach_id", "records"]);
117238
+ const m = eventFields(v, ["attach", "attach_id", "records"], ["seqs"]);
117093
117239
  const records = m["records"];
117094
117240
  if (!Array.isArray(records) || records.length === 0)
117095
117241
  return fail("records");
@@ -117099,7 +117245,8 @@ var STREAM_EVENT_VALIDATORS = {
117099
117245
  kind: "session.records",
117100
117246
  attach: attachOf(m),
117101
117247
  attach_id,
117102
- records: records.map((r) => jsonObject(r, "record"))
117248
+ records: records.map((r) => jsonObject(r, "record")),
117249
+ ...m["seqs"] === undefined ? {} : { seqs: seqsOf(m["seqs"], records.length) }
117103
117250
  };
117104
117251
  },
117105
117252
  "session.blob_open": (v) => {
@@ -117163,32 +117310,97 @@ var STREAM_EVENT_VALIDATORS = {
117163
117310
  // packages/device-service-core/src/local-api/validate-delegated.ts
117164
117311
  var ENDPOINT_KEY = /^[A-Za-z0-9_-]{22}$/;
117165
117312
  var ENDPOINTS_MAX = 16;
117313
+ var ENVIRONMENTS_MAX = 4;
117166
117314
  var endpointKey = (v, what = "endpoint") => typeof v === "string" && ENDPOINT_KEY.test(v) ? v : fail(what);
117167
- var ENGINE_ID_MAX_CHARS = 128;
117168
- var engineId = (v) => typeof v === "string" && v.length >= 1 && v.length <= ENGINE_ID_MAX_CHARS && v.isWellFormed() ? v : fail("engine_id");
117315
+ var engineId = (v) => typeof v === "string" && v.length >= 1 && v.length <= SESSION_ID_MAX_CHARS && v.isWellFormed() ? v : fail("engine_id");
117169
117316
  var DELEGATED_REQUEST_VALIDATORS = {
117170
- "session.endpoints": (v, id) => ({
117171
- id,
117172
- type: "session.endpoints",
117173
- device: deviceId(requestFields(v, ["device"])["device"])
117174
- }),
117317
+ "session.endpoints": (v, id) => {
117318
+ const m = requestFields(v, ["device"], ["primary", "environments"]);
117319
+ if (m["primary"] !== undefined && m["primary"] !== true)
117320
+ return fail("primary");
117321
+ if (m["environments"] !== undefined && m["environments"] !== true)
117322
+ return fail("environments");
117323
+ return {
117324
+ id,
117325
+ type: "session.endpoints",
117326
+ device: deviceId(m["device"]),
117327
+ ...m["primary"] === true ? { primary: true } : {},
117328
+ ...m["environments"] === true ? { environments: true } : {}
117329
+ };
117330
+ },
117175
117331
  "session.locate": (v, id) => {
117176
- const m = requestFields(v, ["device", "engine_id"]);
117177
- return { id, type: "session.locate", device: deviceId(m["device"]), engine_id: engineId(m["engine_id"]) };
117332
+ const m = requestFields(v, ["device", "engine_id"], ["single"]);
117333
+ if (m["single"] !== undefined && m["single"] !== true)
117334
+ return fail("single");
117335
+ return {
117336
+ id,
117337
+ type: "session.locate",
117338
+ device: deviceId(m["device"]),
117339
+ engine_id: engineId(m["engine_id"]),
117340
+ ...m["single"] === true ? { single: true } : {}
117341
+ };
117178
117342
  }
117179
117343
  };
117180
- var locateData = (v) => {
117181
- const m = known(v, ["device", "key", "session"], [], "data");
117182
- const device = deviceId(m["device"]);
117183
- const key = endpointKey(m["key"], "key");
117184
- return m["session"] === `${device}.${key}` ? { device, key, session: `${device}.${key}` } : fail("session");
117344
+ var keysOf2 = (v, max, what) => {
117345
+ if (!Array.isArray(v) || v.length > max)
117346
+ return fail(what);
117347
+ const keys = v.map((e) => endpointKey(e, what));
117348
+ return new Set(keys).size === keys.length ? keys : fail(what);
117185
117349
  };
117186
117350
  var endpointsData = (v) => {
117187
- const endpoints = known(v, ["endpoints"], [], "data")["endpoints"];
117188
- if (!Array.isArray(endpoints) || endpoints.length > ENDPOINTS_MAX)
117189
- return fail("endpoints");
117190
- const keys = endpoints.map((e) => endpointKey(e, "endpoints"));
117191
- return new Set(keys).size === keys.length ? { endpoints: keys } : fail("endpoints");
117351
+ const m = known(v, ["endpoints"], ["environments", "primary"], "data");
117352
+ const endpoints = keysOf2(m["endpoints"], ENDPOINTS_MAX, "endpoints");
117353
+ const primary = m["primary"] === undefined ? undefined : endpointKey(m["primary"], "primary");
117354
+ if (primary !== undefined && !endpoints.includes(primary))
117355
+ return fail("primary");
117356
+ return {
117357
+ endpoints,
117358
+ ...m["environments"] === undefined ? {} : { environments: keysOf2(m["environments"], ENVIRONMENTS_MAX, "environments") },
117359
+ ...primary === undefined ? {} : { primary }
117360
+ };
117361
+ };
117362
+ var agentDirOf = (v) => absolutePath(requestFields(v, ["agent_dir"])["agent_dir"], "agent_dir");
117363
+ var environmentOf = (v, required) => {
117364
+ const m = requestFields(v, required);
117365
+ return m["kind"] === "environment" ? m : fail("kind");
117366
+ };
117367
+ var endpointsRegister = (v, id) => {
117368
+ if (v["kind"] === undefined)
117369
+ return { id, type: "endpoints.register", agent_dir: agentDirOf(v) };
117370
+ const m = environmentOf(v, ["kind", "socket", "key_root"]);
117371
+ return {
117372
+ id,
117373
+ type: "endpoints.register",
117374
+ kind: "environment",
117375
+ socket: absolutePath(m["socket"], "socket"),
117376
+ key_root: absolutePath(m["key_root"], "key_root")
117377
+ };
117378
+ };
117379
+ var endpointsUnregister = (v, id) => {
117380
+ if (v["kind"] === undefined)
117381
+ return { id, type: "endpoints.unregister", agent_dir: agentDirOf(v) };
117382
+ const m = environmentOf(v, ["kind", "socket"]);
117383
+ return {
117384
+ id,
117385
+ type: "endpoints.unregister",
117386
+ kind: "environment",
117387
+ socket: absolutePath(m["socket"], "socket")
117388
+ };
117389
+ };
117390
+ var endpointsList = (v, id) => {
117391
+ requestFields(v, []);
117392
+ return { id, type: "endpoints.list" };
117393
+ };
117394
+ var endpointsListData = (m) => {
117395
+ const dirs = m["agent_dirs"];
117396
+ if (!Array.isArray(dirs))
117397
+ return fail("agent_dirs");
117398
+ return { agent_dirs: dirs.map((d) => absolutePath(d, "agent_dirs")) };
117399
+ };
117400
+ var endpointRequests = {
117401
+ "endpoints.register": endpointsRegister,
117402
+ "endpoints.unregister": endpointsUnregister,
117403
+ "endpoints.list": endpointsList
117192
117404
  };
117193
117405
  var blobId = (m) => localId(m["id"], "blob id");
117194
117406
  var blobRefOf = (v) => {
@@ -117201,7 +117413,9 @@ var blobRefOf = (v) => {
117201
117413
  };
117202
117414
  var locatedOf = (device, v) => {
117203
117415
  const m = known(v, ["key", "session"], [], "located");
117204
- const key = endpointKey(m["key"], "located key");
117416
+ const key = m["key"];
117417
+ if (typeof key !== "string" || !isStreamSessionKey(key))
117418
+ return fail("located key");
117205
117419
  return m["session"] === `${device}.${key}` ? { key, session: `${device}.${key}` } : fail("located session");
117206
117420
  };
117207
117421
  var COMMAND_EVENT_FIELDS = ["blob", "frame", "command_id", "response", "located"];
@@ -117258,6 +117472,451 @@ var DELEGATED_EVENT_VALIDATORS = {
117258
117472
  }
117259
117473
  };
117260
117474
 
117475
+ // packages/device-service-core/src/local-api/validate-command.ts
117476
+ var commandRpcOf = (v) => jsonObject(v, "rpc");
117477
+ var requestFields = (v, names, optional = []) => exactly(v, ["id", "type", ...names], optional, "request");
117478
+ var acceptsField = (v) => {
117479
+ if (v === undefined)
117480
+ return {};
117481
+ if (!Array.isArray(v) || v.length !== 1 || v[0] !== "session-wake:v1")
117482
+ return fail("accepts");
117483
+ return { accepts: ["session-wake:v1"] };
117484
+ };
117485
+ var commandIdField = (v) => v === undefined ? {} : { command_id: commandId(v) };
117486
+ var ROUTE_FIELDS = ["command_id", "delegated", "endpoint", "locate"];
117487
+ var routeFields = (m) => {
117488
+ const delegated = m["delegated"];
117489
+ if (delegated !== undefined && delegated !== true)
117490
+ return fail("delegated");
117491
+ const locate = m["locate"];
117492
+ if (locate !== undefined && locate !== true)
117493
+ return fail("locate");
117494
+ return {
117495
+ ...delegated === true ? { delegated: true } : {},
117496
+ ...locate === true ? { locate: true } : {},
117497
+ ...m["endpoint"] === undefined ? {} : { endpoint: endpointKey(m["endpoint"]) }
117498
+ };
117499
+ };
117500
+ var TARGETS = ["attach", "device", "session", "alias", "wake"];
117501
+ var targetField = (v) => {
117502
+ const named = TARGETS.filter((f) => Object.hasOwn(v, f));
117503
+ const [only] = named;
117504
+ return named.length === 1 && only !== undefined ? only : fail("request names one target");
117505
+ };
117506
+ var TARGET_FIELDS = {
117507
+ attach: ["attach"],
117508
+ device: ["device", "endpoint"],
117509
+ session: ["session"],
117510
+ alias: ["alias"],
117511
+ wake: ["wake"]
117512
+ };
117513
+ var sessionField = (v) => typeof v === "string" && parseSessionRef(v) !== undefined ? v : fail("session");
117514
+ var aliasField = (v) => typeof v === "string" && v.length >= 1 && v.length <= ALIAS_MAX_CHARS && v.isWellFormed() && !unsafeAlias(v) ? v : fail("alias");
117515
+ var wakeField = (v) => {
117516
+ const m = exactly(v, ["device", "durable_id"], [], "wake");
117517
+ return { device: deviceId(m["device"], "wake.device"), durable_id: durableId(m["durable_id"]) };
117518
+ };
117519
+ var oneField = (m, field) => {
117520
+ switch (field) {
117521
+ case "attach":
117522
+ return { attach: localId(m["attach"], "attach") };
117523
+ case "session":
117524
+ return { session: sessionField(m["session"]) };
117525
+ case "alias":
117526
+ return { alias: aliasField(m["alias"]) };
117527
+ case "wake":
117528
+ return { wake: wakeField(m["wake"]) };
117529
+ }
117530
+ };
117531
+ var targetOf2 = (m, field) => field === "device" ? { device: deviceId(m["device"]), endpoint: endpointKey(m["endpoint"]) } : oneField(m, field);
117532
+ var partTargetOf = (m, field) => field === "device" ? { device: deviceId(m["device"]) } : oneField(m, field);
117533
+ var COMMAND_REQUEST_VALIDATORS = {
117534
+ "session.command": (v, id) => {
117535
+ const field = targetField(v);
117536
+ if (field !== "device" && Object.hasOwn(v, "locate"))
117537
+ return fail("locate acts only on a device and endpoint command");
117538
+ const target = TARGET_FIELDS[field];
117539
+ const body = Object.hasOwn(v, "upload_id") ? "upload_id" : "rpc";
117540
+ const delegated = field === "session" || field === "alias" || field === "wake";
117541
+ const optional = [
117542
+ ...delegated ? ["command_id"] : ROUTE_FIELDS.filter((f) => !target.includes(f)),
117543
+ "accepts"
117544
+ ];
117545
+ const m = requestFields(v, [...target, body], optional);
117546
+ return {
117547
+ id,
117548
+ type: "session.command",
117549
+ ...commandIdField(m["command_id"]),
117550
+ ...acceptsField(m["accepts"]),
117551
+ ...body === "upload_id" ? { upload_id: localId(m["upload_id"], "upload_id") } : { rpc: commandRpcOf(m["rpc"]) },
117552
+ ...routeFields(m),
117553
+ ...targetOf2(m, field)
117554
+ };
117555
+ },
117556
+ "session.command_part": (v, id) => {
117557
+ const target = targetField(v);
117558
+ const m = requestFields(v, [target, "upload_id", "index", "count", "b"]);
117559
+ const count = uint(m["count"], 1, LOCAL_UPLOAD_PARTS_MAX, "count");
117560
+ base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117561
+ return {
117562
+ id,
117563
+ type: "session.command_part",
117564
+ ...partTargetOf(m, target),
117565
+ upload_id: localId(m["upload_id"], "upload_id"),
117566
+ index: uint(m["index"], 0, count - 1, "index"),
117567
+ count,
117568
+ b: typeof m["b"] === "string" ? m["b"] : fail("b")
117569
+ };
117570
+ }
117571
+ };
117572
+
117573
+ // packages/device-service-core/src/local-api/validate-machine.ts
117574
+ var MACHINE_OPS_MAX = 4096;
117575
+ var MACHINE_REF_MAX_CHARS = 128;
117576
+ var MACHINE_CREDIT_MAX_BYTES = SESSION_BLOB_MAX;
117577
+ var BASE64URL2 = /^[A-Za-z0-9_-]+$/;
117578
+ var machineId = (v, what) => typeof v === "string" && v.length === COMMAND_ID_CHARS && BASE64URL2.test(v) ? v : fail(what);
117579
+ var machineRef = (v, what) => text(v, MACHINE_REF_MAX_CHARS, what);
117580
+ var opName = (v) => {
117581
+ try {
117582
+ return methodOf(v, "op");
117583
+ } catch (error) {
117584
+ if (error instanceof ProtoError)
117585
+ return fail("op");
117586
+ throw error;
117587
+ }
117588
+ };
117589
+ var opOf = (v) => {
117590
+ const m = exactly(v, ["op_id", "op", "args"], ["deadline_ms", "constraints"], "op");
117591
+ const deadline = m["deadline_ms"];
117592
+ const constraints = m["constraints"];
117593
+ return {
117594
+ op_id: machineId(m["op_id"], "op_id"),
117595
+ op: opName(m["op"]),
117596
+ args: jsonObject(m["args"], "args"),
117597
+ ...deadline === undefined ? {} : { deadline_ms: uint(deadline, 1, Number.MAX_SAFE_INTEGER, "deadline_ms") },
117598
+ ...constraints === undefined ? {} : { constraints: jsonObject(constraints, "constraints") }
117599
+ };
117600
+ };
117601
+ var uniqueIds = (ids, what) => new Set(ids).size === ids.length ? ids : fail(`duplicate ${what}`);
117602
+ var machineOpsOf = (v) => {
117603
+ if (!Array.isArray(v) || v.length === 0 || v.length > MACHINE_OPS_MAX)
117604
+ return fail("ops");
117605
+ const ops = v.map(opOf);
117606
+ uniqueIds(ops.map((o) => o.op_id), "op_id");
117607
+ return ops;
117608
+ };
117609
+ var refOf2 = (m) => m["session_ref"] === undefined ? {} : { session_ref: machineRef(m["session_ref"], "session_ref") };
117610
+ var bare = (v) => {
117611
+ requestFields(v, []);
117612
+ };
117613
+ var MACHINE_REQUEST_VALIDATORS = {
117614
+ "machine.list": (v, id) => {
117615
+ bare(v);
117616
+ return { id, type: "machine.list" };
117617
+ },
117618
+ "machine.events.subscribe": (v, id) => {
117619
+ bare(v);
117620
+ return { id, type: "machine.events.subscribe" };
117621
+ },
117622
+ "machine.describe": (v, id) => ({
117623
+ id,
117624
+ type: "machine.describe",
117625
+ device: deviceId(requestFields(v, ["device"])["device"])
117626
+ }),
117627
+ "machine.batch": (v, id) => {
117628
+ if (Object.hasOwn(v, "upload_id")) {
117629
+ const m = requestFields(v, ["device", "upload_id"], ["session_ref"]);
117630
+ const upload_id = localId(m["upload_id"], "upload_id");
117631
+ return { id, type: "machine.batch", device: deviceId(m["device"]), upload_id, ...refOf2(m) };
117632
+ }
117633
+ const m = requestFields(v, ["device", "ops"], ["session_ref"]);
117634
+ if (lineBytes(v) > LOCAL_INLINE_MAX)
117635
+ return fail("an inline batch over LOCAL_INLINE_MAX is an upload");
117636
+ return {
117637
+ id,
117638
+ type: "machine.batch",
117639
+ device: deviceId(m["device"]),
117640
+ ops: machineOpsOf(m["ops"]),
117641
+ ...refOf2(m)
117642
+ };
117643
+ },
117644
+ "machine.batch_part": (v, id) => {
117645
+ const m = requestFields(v, ["upload_id", "index", "count", "b"]);
117646
+ const count = uint(m["count"], 1, MACHINE_UPLOAD_PARTS_MAX, `count: ${MACHINE_UPLOAD_LIMIT}`);
117647
+ base64Bytes(m["b"], LOCAL_CHUNK_MAX, "b");
117648
+ return {
117649
+ id,
117650
+ type: "machine.batch_part",
117651
+ upload_id: localId(m["upload_id"], "upload_id"),
117652
+ index: uint(m["index"], 0, count - 1, "index"),
117653
+ count,
117654
+ b: typeof m["b"] === "string" ? m["b"] : fail("b")
117655
+ };
117656
+ },
117657
+ "machine.cancel": (v, id) => {
117658
+ const ids = requestFields(v, ["op_ids"])["op_ids"];
117659
+ if (!Array.isArray(ids) || ids.length === 0 || ids.length > MACHINE_OPS_MAX)
117660
+ return fail("op_ids");
117661
+ const op_ids = uniqueIds(ids.map((o) => machineId(o, "op_id")), "op_id");
117662
+ return { id, type: "machine.cancel", op_ids };
117663
+ },
117664
+ "machine.credit": (v, id) => {
117665
+ const m = requestFields(v, ["handle", "bytes"]);
117666
+ return {
117667
+ id,
117668
+ type: "machine.credit",
117669
+ handle: machineRef(m["handle"], "handle"),
117670
+ bytes: uint(m["bytes"], 1, MACHINE_CREDIT_MAX_BYTES, "bytes")
117671
+ };
117672
+ },
117673
+ "machine.result_of": (v, id) => ({
117674
+ id,
117675
+ type: "machine.result_of",
117676
+ op_id: machineId(requestFields(v, ["op_id"])["op_id"], "op_id")
117677
+ })
117678
+ };
117679
+ var empty = (v) => {
117680
+ known(v, [], [], "data");
117681
+ return {};
117682
+ };
117683
+ var fields = (v, names) => known(v, names, [], "data");
117684
+ var LEGACY_MACHINE_ROUTE_KINDS = ["internet", "lan"];
117685
+ var legacyRouteOf = (v) => {
117686
+ const r = known(v, ["kind", "online"], [], "machine route");
117687
+ const kind = oneOf(LEGACY_MACHINE_ROUTE_KINDS, r["kind"], "machine route kind");
117688
+ bool(r["online"], "online");
117689
+ return kind;
117690
+ };
117691
+ var machineRowOf = (v) => {
117692
+ const m = known(v, ["device", "label", "state"], ["routes"], "machine row");
117693
+ const routes = m["routes"];
117694
+ if (routes !== undefined && (!Array.isArray(routes) || routes.length > LEGACY_MACHINE_ROUTE_KINDS.length))
117695
+ return fail("routes");
117696
+ const listed = routes?.map(legacyRouteOf);
117697
+ if (listed !== undefined && new Set(listed).size !== listed.length)
117698
+ return fail("routes");
117699
+ return {
117700
+ device: deviceId(m["device"]),
117701
+ label: text(m["label"], LABEL_MAX_CHARS, "label", 0),
117702
+ state: oneOf(MACHINE_STATES, m["state"], "machine state")
117703
+ };
117704
+ };
117705
+ var MACHINE_DATA = {
117706
+ "machine.list": (v) => {
117707
+ const machines = fields(v, ["machines"])["machines"];
117708
+ return Array.isArray(machines) ? { machines: machines.map(machineRowOf) } : fail("machines");
117709
+ },
117710
+ "machine.describe": (v) => {
117711
+ const m = fields(v, ["device", "description"]);
117712
+ if (!isRecord19(m["description"]))
117713
+ return fail("description");
117714
+ return {
117715
+ device: deviceId(m["device"]),
117716
+ description: jsonObject(m["description"], "description")
117717
+ };
117718
+ },
117719
+ "machine.batch": (v) => ({
117720
+ batch_id: machineId(fields(v, ["batch_id"])["batch_id"], "batch_id")
117721
+ }),
117722
+ "machine.batch_part": (v) => ({
117723
+ received: uint(fields(v, ["received"])["received"], 0, MACHINE_UPLOAD_PARTS_MAX - 1, "received")
117724
+ }),
117725
+ "machine.cancel": empty,
117726
+ "machine.credit": empty,
117727
+ "machine.result_of": (v) => ({
117728
+ state: oneOf(MACHINE_LOOKUP_STATES, fields(v, ["state"])["state"], "lookup state")
117729
+ }),
117730
+ "machine.events.subscribe": empty
117731
+ };
117732
+
117733
+ // packages/device-service-core/src/local-api/validate-machine-events.ts
117734
+ var MACHINE_OUTPUT_MAX_BYTES = STREAM_INLINE_MAX;
117735
+ var blobId2 = (m) => localId(m["id"], "blob id");
117736
+ var blobRefOf2 = (v) => {
117737
+ const m = known(v, ["id", "bytes", "sha256"], [], "blob");
117738
+ return {
117739
+ id: blobId2(m),
117740
+ bytes: uint(m["bytes"], 1, LOCAL_BLOB_MAX, "blob bytes"),
117741
+ sha256: sha256Field(m["sha256"], "blob sha256")
117742
+ };
117743
+ };
117744
+ var base64Of = (v, max, what) => {
117745
+ base64Bytes(v, max, what);
117746
+ return typeof v === "string" ? v : fail(what);
117747
+ };
117748
+ var TIMING_FIELDS = [
117749
+ "enqueued_ms",
117750
+ "flushed_ms",
117751
+ "confirmed_ms",
117752
+ "dispatched_ms",
117753
+ "settled_ms",
117754
+ "applied_ms"
117755
+ ];
117756
+ var timingOf = (v) => {
117757
+ const m = known(v, [], TIMING_FIELDS, "timing");
117758
+ return Object.fromEntries(TIMING_FIELDS.flatMap((k) => m[k] === undefined ? [] : [[k, uint(m[k], 0, Number.MAX_SAFE_INTEGER, k)]]));
117759
+ };
117760
+ var opResultOf = (v) => {
117761
+ const head = { type: "event", kind: "machine.op_result" };
117762
+ const all = eventFields(v, ["op_id"], ["blob", "response"]);
117763
+ const shape = (name) => exactly(all, ["type", "kind", "op_id", name], [], "event");
117764
+ if (Object.hasOwn(all, "blob")) {
117765
+ const m = shape("blob");
117766
+ return { ...head, op_id: machineId(m["op_id"], "op_id"), blob: blobRefOf2(m["blob"]) };
117767
+ }
117768
+ const m = shape("response");
117769
+ if (lineBytes(v) > LOCAL_INLINE_MAX)
117770
+ return fail("an inline result over LOCAL_INLINE_MAX is a blob");
117771
+ return {
117772
+ ...head,
117773
+ op_id: machineId(m["op_id"], "op_id"),
117774
+ response: jsonObject(m["response"], "response")
117775
+ };
117776
+ };
117777
+ var MACHINE_EVENT_VALIDATORS = {
117778
+ "machine.op_state": (v) => {
117779
+ const m = eventFields(v, ["op_id", "state"], ["timing"]);
117780
+ return {
117781
+ type: "event",
117782
+ kind: "machine.op_state",
117783
+ op_id: machineId(m["op_id"], "op_id"),
117784
+ state: oneOf(MACHINE_OP_STATES, m["state"], "op state"),
117785
+ ...m["timing"] === undefined ? {} : { timing: timingOf(m["timing"]) }
117786
+ };
117787
+ },
117788
+ "machine.op_result": opResultOf,
117789
+ "machine.output": (v) => {
117790
+ const m = eventFields(v, ["handle", "seq", "bytes"]);
117791
+ return {
117792
+ type: "event",
117793
+ kind: "machine.output",
117794
+ handle: machineRef(m["handle"], "handle"),
117795
+ seq: uint(m["seq"], 0, Number.MAX_SAFE_INTEGER, "seq"),
117796
+ bytes: base64Of(m["bytes"], MACHINE_OUTPUT_MAX_BYTES, "bytes")
117797
+ };
117798
+ },
117799
+ "machine.changed": (v) => {
117800
+ const m = eventFields(v, ["device", "state"]);
117801
+ return {
117802
+ type: "event",
117803
+ kind: "machine.changed",
117804
+ device: deviceId(m["device"]),
117805
+ state: oneOf(MACHINE_STATES, m["state"], "machine state")
117806
+ };
117807
+ },
117808
+ "machine.blob_chunk": (v) => {
117809
+ const m = eventFields(v, ["id", "off", "b"]);
117810
+ return {
117811
+ type: "event",
117812
+ kind: "machine.blob_chunk",
117813
+ id: blobId2(m),
117814
+ off: uint(m["off"], 0, LOCAL_BLOB_MAX, "blob off"),
117815
+ b: base64Of(m["b"], LOCAL_CHUNK_MAX, "blob chunk")
117816
+ };
117817
+ },
117818
+ "machine.blob_done": (v) => ({
117819
+ type: "event",
117820
+ kind: "machine.blob_done",
117821
+ id: blobId2(eventFields(v, ["id"]))
117822
+ }),
117823
+ "machine.blob_abort": (v) => {
117824
+ const m = eventFields(v, ["id", "reason"]);
117825
+ return {
117826
+ type: "event",
117827
+ kind: "machine.blob_abort",
117828
+ id: blobId2(m),
117829
+ reason: oneOf(MACHINE_BLOB_ABORT_REASONS, m["reason"], "blob abort reason")
117830
+ };
117831
+ }
117832
+ };
117833
+
117834
+ // packages/device-service-core/src/local-api/protocol-presenter.ts
117835
+ var PRESENTER_LOCAL_LANES = ["control", "delegated"];
117836
+ var PRESENTER_LOCAL_LINE_MAX = {
117837
+ control: 16 * 1024,
117838
+ delegated: 1024 * 1024
117839
+ };
117840
+ var PRESENTER_ENDED_REASONS = [
117841
+ "viewer_closed",
117842
+ "engine_closed",
117843
+ "no_control_endpoint",
117844
+ "no_delegated_connection",
117845
+ "not_granted",
117846
+ "conn_collision",
117847
+ "busy",
117848
+ "idle",
117849
+ "event_lost",
117850
+ "too_large",
117851
+ "malformed",
117852
+ "rate"
117853
+ ];
117854
+
117855
+ // packages/device-service-core/src/local-api/validate-presenter.ts
117856
+ var BASE64URL3 = /^[A-Za-z0-9_-]+$/;
117857
+ var presenterLineText = (v, lane) => {
117858
+ const max = PRESENTER_LOCAL_LINE_MAX[lane];
117859
+ if (typeof v !== "string" || v.length === 0 || v.length > Math.ceil(max * 4 / 3))
117860
+ return fail("line too long");
117861
+ if (!BASE64URL3.test(v))
117862
+ return fail("line");
117863
+ let bytes;
117864
+ try {
117865
+ bytes = fromBase64url(v);
117866
+ } catch (error) {
117867
+ if (error instanceof Error)
117868
+ return fail("line");
117869
+ throw error;
117870
+ }
117871
+ return bytes.length <= max && toBase64url(bytes) === v ? v : fail("line");
117872
+ };
117873
+ var laneOf = (v) => oneOf(PRESENTER_LOCAL_LANES, v["lane"], "lane");
117874
+ var PRESENTER_REQUEST_VALIDATORS = {
117875
+ "session.presenter_open": (v, id) => {
117876
+ const m = requestFields(v, ["device", "session"]);
117877
+ return {
117878
+ id,
117879
+ type: "session.presenter_open",
117880
+ device: deviceId(m["device"]),
117881
+ session: sessionId(m["session"])
117882
+ };
117883
+ },
117884
+ "session.presenter_send": (v, id) => {
117885
+ const m = requestFields(v, ["device", "lane", "b"]);
117886
+ const lane = laneOf(m);
117887
+ return {
117888
+ id,
117889
+ type: "session.presenter_send",
117890
+ device: deviceId(m["device"]),
117891
+ lane,
117892
+ b: presenterLineText(m["b"], lane)
117893
+ };
117894
+ }
117895
+ };
117896
+ var frameOf = (v) => {
117897
+ const m = eventFields(v, ["device", "lane", "b"]);
117898
+ const lane = laneOf(m);
117899
+ return {
117900
+ type: "event",
117901
+ kind: "session.presenter_frame",
117902
+ device: deviceId(m["device"]),
117903
+ lane,
117904
+ b: presenterLineText(m["b"], lane)
117905
+ };
117906
+ };
117907
+ var PRESENTER_EVENT_VALIDATORS = {
117908
+ "session.presenter_frame": frameOf,
117909
+ "session.presenter_ended": (v) => {
117910
+ const m = eventFields(v, ["device", "reason"]);
117911
+ return {
117912
+ type: "event",
117913
+ kind: "session.presenter_ended",
117914
+ device: deviceId(m["device"]),
117915
+ reason: oneOf(PRESENTER_ENDED_REASONS, m["reason"], "presenter end reason")
117916
+ };
117917
+ }
117918
+ };
117919
+
117261
117920
  // packages/device-service-core/src/local-api/validate-deliveries.ts
117262
117921
  var PROTOCOL_MAX = 1e6;
117263
117922
  var PAIRS_MAX = 4096;
@@ -117272,9 +117931,17 @@ var DELIVERIES_REQUEST_VALIDATORS = {
117272
117931
  const pairs = requestFields(v, ["pairs"])["pairs"];
117273
117932
  if (!Array.isArray(pairs) || pairs.length > PAIRS_MAX)
117274
117933
  return fail("pairs");
117275
- return { id, type: "delivery.pending", pairs: pairs.map((p) => pairOf(exactly(p, PAIR_FIELDS, [], "pair"))) };
117934
+ return {
117935
+ id,
117936
+ type: "delivery.pending",
117937
+ pairs: pairs.map((p) => pairOf(exactly(p, PAIR_FIELDS, [], "pair")))
117938
+ };
117276
117939
  },
117277
- "delivery.drained": (v, id) => ({ id, type: "delivery.drained", ...pairOf(requestFields(v, PAIR_FIELDS)) }),
117940
+ "delivery.drained": (v, id) => ({
117941
+ id,
117942
+ type: "delivery.drained",
117943
+ ...pairOf(requestFields(v, PAIR_FIELDS))
117944
+ }),
117278
117945
  "deliveries.serve": (v, id) => {
117279
117946
  const m = requestFields(v, ["agent_dir", "v"]);
117280
117947
  return {
@@ -117296,19 +117963,31 @@ var DELIVERIES_REQUEST_VALIDATORS = {
117296
117963
  },
117297
117964
  "delivery.held": (v, id) => {
117298
117965
  const m = requestFields(v, ["ask_id", "holds"]);
117299
- return { id, type: "delivery.held", ask_id: localId(m["ask_id"], "ask_id"), holds: bool(m["holds"], "holds") };
117966
+ return {
117967
+ id,
117968
+ type: "delivery.held",
117969
+ ask_id: localId(m["ask_id"], "ask_id"),
117970
+ holds: bool(m["holds"], "holds")
117971
+ };
117300
117972
  },
117301
- "peer.admitted": (v, id) => ({ id, type: "peer.admitted", device: deviceId(requestFields(v, ["device"])["device"]) })
117973
+ "peer.admitted": (v, id) => ({
117974
+ id,
117975
+ type: "peer.admitted",
117976
+ device: deviceId(requestFields(v, ["device"])["device"])
117977
+ })
117302
117978
  };
117303
- var empty = (v) => {
117979
+ var empty2 = (v) => {
117304
117980
  known(v, [], [], "data");
117305
117981
  return {};
117306
117982
  };
117307
117983
  var DELIVERIES_DATA = {
117308
- "deliveries.serve": (v) => ({ wake: bool(known(v, ["wake"], [], "data")["wake"], "wake") }),
117309
- "delivery.answer": empty,
117310
- "delivery.held": empty,
117311
- "delivery.pending": empty,
117984
+ "deliveries.serve": (v) => {
117985
+ const m = known(v, ["wake"], [], "data");
117986
+ return { wake: bool(m["wake"], "wake") };
117987
+ },
117988
+ "delivery.answer": empty2,
117989
+ "delivery.held": empty2,
117990
+ "delivery.pending": empty2,
117312
117991
  "delivery.drained": (v) => {
117313
117992
  const m = known(v, ["kept"], ["expecting"], "data");
117314
117993
  const kept = bool(m["kept"], "kept");
@@ -117316,14 +117995,15 @@ var DELIVERIES_DATA = {
117316
117995
  return m["expecting"] === undefined ? { kept } : fail("expecting");
117317
117996
  return { kept, expecting: commandId(m["expecting"]) };
117318
117997
  },
117319
- "peer.admitted": (v) => ({ admitted: bool(known(v, ["admitted"], [], "data")["admitted"], "admitted") })
117998
+ "peer.admitted": (v) => ({
117999
+ admitted: bool(known(v, ["admitted"], [], "data")["admitted"], "admitted")
118000
+ })
117320
118001
  };
117321
118002
  var DELIVERIES_EVENT_VALIDATORS = {
117322
- "delivery.wake": (v) => ({
117323
- type: "event",
117324
- kind: "delivery.wake",
117325
- enabled: bool(eventFields(v, ["enabled"])["enabled"], "enabled")
117326
- }),
118003
+ "delivery.wake": (v) => {
118004
+ const m = eventFields(v, ["enabled"]);
118005
+ return { type: "event", kind: "delivery.wake", enabled: bool(m["enabled"], "enabled") };
118006
+ },
117327
118007
  "delivery.inbound": (v) => {
117328
118008
  const m = eventFields(v, ["command_id", "sender_device", "durable_id", "record"]);
117329
118009
  return {
@@ -117346,6 +118026,116 @@ var DELIVERIES_EVENT_VALIDATORS = {
117346
118026
  }
117347
118027
  };
117348
118028
 
118029
+ // packages/device-service-core/src/local-api/validate-listing-row.ts
118030
+ var ROW_FIELDS = [
118031
+ "device",
118032
+ "session_id",
118033
+ "title",
118034
+ "project",
118035
+ "path",
118036
+ "state",
118037
+ "updated_ms",
118038
+ "source",
118039
+ "as_of"
118040
+ ];
118041
+ var ROW_KIND = new RegExp(`^[a-z][a-z0-9_-]{0,${SESSION_KIND_MAX_CHARS - 1}}$`);
118042
+ var rowLinks = (m) => {
118043
+ const kind = m["kind"];
118044
+ if (Object.hasOwn(m, "parent") !== Object.hasOwn(m, "parent_listed"))
118045
+ fail("parent_listed");
118046
+ return {
118047
+ ...kind === undefined ? {} : { kind: typeof kind === "string" && ROW_KIND.test(kind) ? kind : fail("row kind") },
118048
+ ...m["parent"] === undefined ? {} : {
118049
+ parent: sessionId(m["parent"]),
118050
+ parent_listed: bool(m["parent_listed"], "parent_listed")
118051
+ }
118052
+ };
118053
+ };
118054
+ var rowModel = (v) => {
118055
+ if (v === undefined)
118056
+ return {};
118057
+ const m = known(v, ["provider", "id"], [], "model");
118058
+ return {
118059
+ model: {
118060
+ provider: text(m["provider"], SESSION_MODEL_PROVIDER_MAX_CHARS, "model provider"),
118061
+ id: text(m["id"], SESSION_MODEL_ID_MAX_CHARS, "model id")
118062
+ }
118063
+ };
118064
+ };
118065
+ var settledByOf = (v) => {
118066
+ const named = known(v, ["kind"], [], "settled_by")["kind"];
118067
+ if (typeof named !== "string")
118068
+ return fail("settled_by kind");
118069
+ const kind = LISTING_SETTLED_BY_KINDS.find((k) => k === named);
118070
+ switch (kind) {
118071
+ case undefined:
118072
+ return;
118073
+ case "user":
118074
+ return { kind };
118075
+ case "agent": {
118076
+ const m = known(v, ["kind"], ["threadId", "threadTitle"], "settled_by");
118077
+ const id = m["threadId"];
118078
+ const title = m["threadTitle"];
118079
+ return {
118080
+ kind,
118081
+ ...id === undefined ? {} : { threadId: text(id, SESSION_ID_MAX_CHARS, "settled_by threadId") },
118082
+ ...title === undefined ? {} : {
118083
+ threadTitle: text(title, SESSION_SETTLED_THREAD_TITLE_MAX_CHARS, "settled_by threadTitle", 0)
118084
+ }
118085
+ };
118086
+ }
118087
+ case "pr-merged":
118088
+ case "pr-closed": {
118089
+ const n = known(v, ["kind"], ["pullRequestNumber"], "settled_by")["pullRequestNumber"];
118090
+ return {
118091
+ kind,
118092
+ ...n === undefined ? {} : {
118093
+ pullRequestNumber: uint(n, 0, Number.MAX_SAFE_INTEGER, "settled_by pullRequestNumber")
118094
+ }
118095
+ };
118096
+ }
118097
+ case "inactivity": {
118098
+ const days = known(v, ["kind", "days"], [], "settled_by")["days"];
118099
+ return { kind, days: uint(days, 0, SESSION_SETTLED_DAYS_MAX, "settled_by days") };
118100
+ }
118101
+ default:
118102
+ return assertNever(kind);
118103
+ }
118104
+ };
118105
+ var rowSettled = (m) => {
118106
+ const reason = m["settled_by"];
118107
+ if (m["settled"] === undefined)
118108
+ return reason === undefined ? {} : fail("settled_by");
118109
+ const settled = bool(m["settled"], "settled");
118110
+ if (reason === undefined)
118111
+ return { settled };
118112
+ if (!settled)
118113
+ return fail("settled_by");
118114
+ const by = settledByOf(reason);
118115
+ return by === undefined ? { settled } : { settled, settled_by: by };
118116
+ };
118117
+ var listingRowOf = (v) => {
118118
+ const m = known(v, ROW_FIELDS, ["kind", "parent", "parent_listed", "durable_id", "model", "archived", "settled", "settled_by"], "listing row");
118119
+ const durable = m["durable_id"];
118120
+ const archived = m["archived"];
118121
+ return {
118122
+ ...rowLinks(m),
118123
+ ...rowModel(m["model"]),
118124
+ ...rowSettled(m),
118125
+ ...archived === undefined ? {} : { archived: archived === true ? true : fail("archived") },
118126
+ ...durable === undefined ? {} : { durable_id: text(durable, SESSION_ID_MAX_CHARS, "durable_id") },
118127
+ device: deviceId(m["device"]),
118128
+ session_id: sessionId(m["session_id"]),
118129
+ title: text(m["title"], SESSION_SUMMARY_TITLE_MAX_CHARS, "title", 0),
118130
+ project: text(m["project"], SESSION_SUMMARY_PROJECT_MAX_CHARS, "project"),
118131
+ path: text(m["path"], SESSION_SUMMARY_PATH_MAX_CHARS, "path"),
118132
+ state: oneOf(SESSION_ROW_STATES, m["state"], "row state"),
118133
+ updated_ms: millis(m["updated_ms"], "updated_ms"),
118134
+ source: oneOf(LISTING_SOURCES, m["source"], "row source"),
118135
+ as_of: millis(m["as_of"], "as_of")
118136
+ };
118137
+ };
118138
+
117349
118139
  // packages/device-service-core/src/local-api/validate-events.ts
117350
118140
  var revisionOf = (m) => uint(m["revision"], 1, Number.MAX_SAFE_INTEGER, "revision");
117351
118141
  var devicesOf = (v) => {
@@ -117353,7 +118143,7 @@ var devicesOf = (v) => {
117353
118143
  return fail("round devices");
117354
118144
  const out = {};
117355
118145
  for (const [device, state] of Object.entries(v))
117356
- out[safeKey(deviceId(device), "round device")] = oneOf(ROUND_DEVICE_STATES, state, "round device state");
118146
+ out[safeKey2(deviceId(device), "round device")] = oneOf(ROUND_DEVICE_STATES, state, "round device state");
117357
118147
  return out;
117358
118148
  };
117359
118149
  var commandStateOf = (v) => {
@@ -117396,7 +118186,9 @@ var commandStateOf = (v) => {
117396
118186
  };
117397
118187
  var VALIDATORS = {
117398
118188
  ...STREAM_EVENT_VALIDATORS,
118189
+ ...MACHINE_EVENT_VALIDATORS,
117399
118190
  ...DELEGATED_EVENT_VALIDATORS,
118191
+ ...PRESENTER_EVENT_VALIDATORS,
117400
118192
  ...DELIVERIES_EVENT_VALIDATORS,
117401
118193
  "status.changed": (v) => ({
117402
118194
  type: "event",
@@ -117436,6 +118228,15 @@ var VALIDATORS = {
117436
118228
  rows: rows.map(listingRowOf)
117437
118229
  };
117438
118230
  },
118231
+ "sessions.listing_changed": (v) => {
118232
+ const m = eventFields(v, ["device", "generation"]);
118233
+ return {
118234
+ type: "event",
118235
+ kind: "sessions.listing_changed",
118236
+ device: deviceId(m["device"]),
118237
+ generation: nullable2(m["generation"], (g) => uint(g, 0, Number.MAX_SAFE_INTEGER, "generation"))
118238
+ };
118239
+ },
117439
118240
  "sessions.listing_end": (v) => {
117440
118241
  const m = eventFields(v, ["query_id", "revision", "incomplete"]);
117441
118242
  const incomplete = m["incomplete"];
@@ -117469,6 +118270,20 @@ var VALIDATORS = {
117469
118270
  next_before
117470
118271
  };
117471
118272
  },
118273
+ "host.update_notice": (v) => {
118274
+ const m = eventFields(v, ["target_version", "phase", "policy"], ["update_id", "deadline_ms"]);
118275
+ const id = m["update_id"];
118276
+ const deadline = m["deadline_ms"];
118277
+ return {
118278
+ type: "event",
118279
+ kind: "host.update_notice",
118280
+ ...id === undefined ? {} : { update_id: localId(id, "update_id") },
118281
+ target_version: semver(m["target_version"], "target_version"),
118282
+ phase: oneOf(UPDATE_NOTICE_PHASES, m["phase"], "update notice phase"),
118283
+ ...deadline === undefined ? {} : { deadline_ms: millis(deadline, "deadline_ms") },
118284
+ policy: oneOf(UPDATE_POLICIES, m["policy"], "update policy")
118285
+ };
118286
+ },
117472
118287
  "session.upload_abort": (v) => {
117473
118288
  const m = eventFields(v, ["upload_id", "reason"]);
117474
118289
  const reason = oneOf(UPLOAD_ABORT_REASONS, m["reason"], "upload abort reason");
@@ -117487,8 +118302,36 @@ var validateEventFields = (v) => {
117487
118302
  return VALIDATORS[oneOf(EVENT_KINDS, v["kind"], "event kind")](v);
117488
118303
  };
117489
118304
 
118305
+ // packages/device-service-core/src/local-api/validate-session-wake.ts
118306
+ var SESSION_WAKE_VALIDATORS = {
118307
+ "control.session_wake.get": (v, id) => {
118308
+ requestFields(v, []);
118309
+ return { id, type: "control.session_wake.get" };
118310
+ },
118311
+ "control.session_wake.set": (v, id) => {
118312
+ const raw = requestFields(v, ["enabled"])["enabled"];
118313
+ return {
118314
+ id,
118315
+ type: "control.session_wake.set",
118316
+ enabled: raw === null ? null : bool(raw, "enabled")
118317
+ };
118318
+ }
118319
+ };
118320
+ var storedOf = (v) => v === null || v === "unreadable" || typeof v === "boolean" ? v : fail("stored");
118321
+ var sessionWakeState = (v) => {
118322
+ const m = known(v, ["enabled", "stored", "changedAt", "overridden"], [], "data");
118323
+ const stored = m["stored"];
118324
+ const changedAt = m["changedAt"];
118325
+ return {
118326
+ enabled: bool(m["enabled"], "enabled"),
118327
+ stored: storedOf(stored),
118328
+ changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt"),
118329
+ overridden: bool(m["overridden"], "overridden")
118330
+ };
118331
+ };
118332
+
117490
118333
  // packages/device-service-core/src/local-api/validate-requests.ts
117491
- var ENVIRONMENTS_MAX = 1024;
118334
+ var ENVIRONMENTS_MAX2 = 1024;
117492
118335
  var PKCS8_KEY_BYTES = 48;
117493
118336
  var PKCS8_PREFIX = {
117494
118337
  ed25519: "302e020100300506032b657004220420",
@@ -117496,7 +118339,7 @@ var PKCS8_PREFIX = {
117496
118339
  };
117497
118340
  var pkcs8 = (v, algorithm, what) => {
117498
118341
  const bytes = base64Bytes(v, PKCS8_KEY_BYTES, what);
117499
- const prefix = Buffer.from(bytes.subarray(0, 16)).toString("hex");
118342
+ const prefix = toHex(bytes.subarray(0, 16));
117500
118343
  const exact = bytes.length === PKCS8_KEY_BYTES && prefix === PKCS8_PREFIX[algorithm];
117501
118344
  return exact && typeof v === "string" ? v : fail(what);
117502
118345
  };
@@ -117509,7 +118352,7 @@ var filterOf = (v) => {
117509
118352
  };
117510
118353
  };
117511
118354
  var environmentsOf = (v) => {
117512
- if (!Array.isArray(v) || v.length > ENVIRONMENTS_MAX)
118355
+ if (!Array.isArray(v) || v.length > ENVIRONMENTS_MAX2)
117513
118356
  return fail("environments");
117514
118357
  const rows = v.map((e) => {
117515
118358
  const m = exactly(e, ["environment_id", "revoked", "closed"], [], "environment");
@@ -117521,43 +118364,62 @@ var environmentsOf = (v) => {
117521
118364
  });
117522
118365
  return new Set(rows.map((r) => r.environment_id)).size === rows.length ? rows : fail("duplicate environment_id");
117523
118366
  };
117524
- var bare = (v) => {
118367
+ var resumeOf = (v) => {
118368
+ const m = exactly(v, ["attach_id", "seq"], [], "resume");
118369
+ const seq = uint(m["seq"], 0, Number.MAX_SAFE_INTEGER, "resume.seq");
118370
+ return { attach_id: attachId(m["attach_id"]), seq };
118371
+ };
118372
+ var fromOf = (v) => {
118373
+ const m = exactly(v, ["last_entry_id"], [], "from");
118374
+ return { last_entry_id: entryId(m["last_entry_id"], "from.last_entry_id") };
118375
+ };
118376
+ var bare2 = (v) => {
117525
118377
  requestFields(v, []);
117526
118378
  };
117527
- var agentDir = (v) => absolutePath(requestFields(v, ["agent_dir"])["agent_dir"], "agent_dir");
117528
118379
  var VALIDATORS2 = {
117529
118380
  ...COMMAND_REQUEST_VALIDATORS,
118381
+ ...MACHINE_REQUEST_VALIDATORS,
117530
118382
  ...DELEGATED_REQUEST_VALIDATORS,
118383
+ ...PRESENTER_REQUEST_VALIDATORS,
117531
118384
  ...DELIVERIES_REQUEST_VALIDATORS,
117532
118385
  authenticate: (v, id) => {
117533
118386
  const m = requestFields(v, ["client_proof"]);
117534
118387
  return { id, type: "authenticate", client_proof: text(m["client_proof"], 64, "client_proof") };
117535
118388
  },
117536
118389
  "status.get": (v, id) => {
117537
- bare(v);
117538
- return { id, type: "status.get" };
118390
+ const { exe, sign_in_reason: reason } = requestFields(v, [], ["exe", "sign_in_reason"]);
118391
+ if (exe !== undefined && exe !== true)
118392
+ return fail("exe");
118393
+ if (reason !== undefined && reason !== true)
118394
+ return fail("sign_in_reason");
118395
+ return {
118396
+ id,
118397
+ type: "status.get",
118398
+ ...exe === true ? { exe } : {},
118399
+ ...reason === true ? { sign_in_reason: reason } : {}
118400
+ };
117539
118401
  },
117540
118402
  "status.subscribe": (v, id) => {
117541
- bare(v);
118403
+ bare2(v);
117542
118404
  return { id, type: "status.subscribe" };
117543
118405
  },
117544
- "control.session_wake.get": (v, id) => {
117545
- bare(v);
117546
- return { id, type: "control.session_wake.get" };
117547
- },
117548
- "control.session_wake.set": (v, id) => {
117549
- const value = requestFields(v, ["enabled"])["enabled"];
117550
- const enabled = value === null || typeof value === "boolean" ? value : fail("enabled");
117551
- return { id, type: "control.session_wake.set", enabled };
117552
- },
117553
118406
  "control.attach.get": (v, id) => {
117554
- bare(v);
118407
+ bare2(v);
117555
118408
  return { id, type: "control.attach.get" };
117556
118409
  },
117557
118410
  "control.attach.set": (v, id) => {
117558
118411
  const attached = bool(requestFields(v, ["attached"])["attached"], "attached");
117559
118412
  return { id, type: "control.attach.set", attached };
117560
118413
  },
118414
+ "control.remote_commands.get": (v, id) => {
118415
+ bare2(v);
118416
+ return { id, type: "control.remote_commands.get" };
118417
+ },
118418
+ "control.remote_commands.set": (v, id) => {
118419
+ const enabled = bool(requestFields(v, ["enabled"])["enabled"], "enabled");
118420
+ return { id, type: "control.remote_commands.set", enabled };
118421
+ },
118422
+ ...SESSION_WAKE_VALIDATORS,
117561
118423
  "service.set_enabled": (v, id) => {
117562
118424
  const enabled = bool(requestFields(v, ["enabled"])["enabled"], "enabled");
117563
118425
  return { id, type: "service.set_enabled", enabled };
@@ -117573,32 +118435,42 @@ var VALIDATORS2 = {
117573
118435
  };
117574
118436
  },
117575
118437
  "device.adopt": (v, id) => {
117576
- const m = requestFields(v, ["device", "signing_private_key", "sealing_private_key"]);
118438
+ const m = requestFields(v, ["device", "signing_private_key", "sealing_private_key"], ["account", "sign_in_reason"]);
118439
+ const reason = m["sign_in_reason"];
118440
+ if (reason !== undefined && reason !== true)
118441
+ return fail("sign_in_reason");
117577
118442
  return {
117578
118443
  id,
117579
118444
  type: "device.adopt",
117580
118445
  device: deviceRef(m["device"]),
118446
+ ...m["account"] === undefined ? {} : { account: text(m["account"], 256, "account") },
118447
+ ...reason === true ? { sign_in_reason: reason } : {},
117581
118448
  signing_private_key: pkcs8(m["signing_private_key"], "ed25519", "signing_private_key"),
117582
118449
  sealing_private_key: pkcs8(m["sealing_private_key"], "x25519", "sealing_private_key")
117583
118450
  };
117584
118451
  },
117585
118452
  "device.forget": (v, id) => {
117586
- bare(v);
118453
+ bare2(v);
117587
118454
  return { id, type: "device.forget" };
117588
118455
  },
117589
118456
  "device.info": (v, id) => {
117590
- bare(v);
118457
+ bare2(v);
117591
118458
  return { id, type: "device.info" };
117592
118459
  },
117593
- "endpoints.register": (v, id) => ({ id, type: "endpoints.register", agent_dir: agentDir(v) }),
117594
- "endpoints.unregister": (v, id) => ({ id, type: "endpoints.unregister", agent_dir: agentDir(v) }),
118460
+ ...endpointRequests,
117595
118461
  "devices.list": (v, id) => {
117596
- bare(v);
117597
- return { id, type: "devices.list" };
118462
+ const { managed } = requestFields(v, [], ["managed"]);
118463
+ if (managed !== undefined && managed !== true)
118464
+ return fail("managed");
118465
+ return { id, type: "devices.list", ...managed === undefined ? {} : { managed } };
118466
+ },
118467
+ "sessions.events.subscribe": (v, id) => {
118468
+ bare2(v);
118469
+ return { id, type: "sessions.events.subscribe" };
117598
118470
  },
117599
118471
  "sessions.list": (v, id) => {
117600
118472
  const { filter, rows } = requestFields(v, [], ["filter", "rows"]);
117601
- if (rows !== undefined && rows !== 2 && rows !== 3)
118473
+ if (rows !== undefined && rows !== 2 && rows !== 3 && rows !== 4 && rows !== 5)
117602
118474
  return fail("rows");
117603
118475
  return {
117604
118476
  id,
@@ -117608,12 +118480,20 @@ var VALIDATORS2 = {
117608
118480
  };
117609
118481
  },
117610
118482
  "session.attach": (v, id) => {
117611
- const m = requestFields(v, ["device", "session_id"]);
118483
+ const m = requestFields(v, ["device", "session_id"], ["seqs", "resume", "from"]);
118484
+ const { seqs, resume, from, session_id } = m;
118485
+ if (seqs !== undefined && seqs !== true)
118486
+ return fail("seqs");
118487
+ if (!isStreamSessionKey(session_id))
118488
+ return fail("session_id");
117612
118489
  return {
117613
118490
  id,
117614
118491
  type: "session.attach",
117615
118492
  device: deviceId(m["device"]),
117616
- session_id: sessionId(m["session_id"])
118493
+ session_id,
118494
+ ...seqs === undefined ? {} : { seqs },
118495
+ ...resume === undefined ? {} : { resume: resumeOf(resume) },
118496
+ ...from === undefined ? {} : { from: fromOf(from) }
117617
118497
  };
117618
118498
  },
117619
118499
  "session.detach": (v, id) => ({
@@ -117647,7 +118527,8 @@ var VALIDATORS2 = {
117647
118527
  "owner.shutdown_for_upgrade": (v, id) => {
117648
118528
  const target_version = semver(requestFields(v, ["target_version"])["target_version"], "target_version");
117649
118529
  return { id, type: "owner.shutdown_for_upgrade", target_version };
117650
- }
118530
+ },
118531
+ "owner.update_committed": (v, id) => updateCommittedOf(requestFields(v, ["update_id"]), id)
117651
118532
  };
117652
118533
  var REQUEST_TYPES = keysOf(VALIDATORS2);
117653
118534
 
@@ -117668,7 +118549,16 @@ var validateWelcome = (v) => asViolation(() => {
117668
118549
  }
117669
118550
  if (isRecord19(v) && v["type"] === "welcome" && v["v"] !== LOCAL_API_VERSION)
117670
118551
  return { type: "refused", reason: "version" };
117671
- const fields = ["type", "v", "service_version", "owner", "server_proof", "server_nonce", "capabilities", "state"];
118552
+ const fields = [
118553
+ "type",
118554
+ "v",
118555
+ "service_version",
118556
+ "owner",
118557
+ "server_proof",
118558
+ "server_nonce",
118559
+ "capabilities",
118560
+ "state"
118561
+ ];
117672
118562
  const m = known(v, fields, [], "welcome");
117673
118563
  const capabilities = m["capabilities"];
117674
118564
  if (m["type"] !== "welcome" || m["owner"] !== "service")
@@ -117686,7 +118576,7 @@ var validateWelcome = (v) => asViolation(() => {
117686
118576
  state: statusOf(m["state"])
117687
118577
  };
117688
118578
  });
117689
- var empty2 = (v) => {
118579
+ var empty3 = (v) => {
117690
118580
  known(v, [], [], "data");
117691
118581
  return {};
117692
118582
  };
@@ -117699,51 +118589,57 @@ var attachState = (v) => {
117699
118589
  changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt")
117700
118590
  };
117701
118591
  };
117702
- var sessionWakeState = (v) => {
117703
- const m = known(v, ["enabled", "stored", "changedAt", "overridden"], [], "data");
117704
- const s = m["stored"];
118592
+ var remoteCommandsState = (v) => {
118593
+ const m = known(v, ["enabled", "changedAt", "overridden"], [], "data");
117705
118594
  const changedAt = m["changedAt"];
117706
118595
  return {
117707
118596
  enabled: bool(m["enabled"], "enabled"),
117708
- stored: s === null || typeof s === "boolean" ? s : s === "unreadable" ? "unreadable" : fail("stored"),
117709
118597
  changedAt: typeof changedAt === "string" ? changedAt : fail("changedAt"),
117710
118598
  overridden: bool(m["overridden"], "overridden")
117711
118599
  };
117712
118600
  };
117713
118601
  var DATA = {
117714
- authenticate: empty2,
118602
+ authenticate: empty3,
117715
118603
  "status.get": statusOf,
117716
- "status.subscribe": empty2,
118604
+ "status.subscribe": empty3,
117717
118605
  "service.set_enabled": (v) => ({ enabled: bool(one(v, "enabled"), "enabled") }),
117718
- "refresher.register": empty2,
118606
+ "refresher.register": empty3,
117719
118607
  "device.adopt": (v) => ({ device: deviceRef(one(v, "device"), "device", known) }),
117720
- "device.forget": empty2,
118608
+ "device.forget": empty3,
117721
118609
  "device.info": (v) => ({
117722
118610
  device: nullable2(one(v, "device"), (d) => deviceRef(d, "device", known))
117723
118611
  }),
117724
- "endpoints.register": empty2,
117725
- "endpoints.unregister": empty2,
118612
+ "endpoints.register": empty3,
118613
+ "endpoints.unregister": empty3,
118614
+ "endpoints.list": (v) => endpointsListData(known(v, ["agent_dirs"], [], "data")),
118615
+ "session.presenter_open": empty3,
118616
+ "session.presenter_send": empty3,
117726
118617
  "devices.list": (v) => {
117727
118618
  const devices = one(v, "devices");
117728
118619
  return Array.isArray(devices) ? { devices: devices.map(deviceRowOf) } : fail("devices");
117729
118620
  },
117730
118621
  "sessions.list": (v) => ({ query_id: localId(one(v, "query_id"), "query_id") }),
118622
+ "sessions.events.subscribe": empty3,
117731
118623
  "session.attach": (v) => ({ attach: localId(one(v, "attach"), "attach") }),
117732
- "session.detach": empty2,
117733
- "session.command": (v) => ({ command_id: commandId(one(v, "command_id")) }),
118624
+ "session.detach": empty3,
118625
+ "session.command": commandAnswerOf,
117734
118626
  "session.command_part": (v) => ({
117735
118627
  received: uint(one(v, "received"), 0, LOCAL_UPLOAD_PARTS_MAX - 1, "received")
117736
118628
  }),
117737
118629
  "session.read": (v) => ({ query_id: localId(one(v, "query_id"), "query_id") }),
117738
- "enforcement.report": empty2,
117739
- "owner.shutdown_for_upgrade": empty2,
117740
- "session.endpoints": endpointsData,
117741
- "session.locate": locateData,
117742
- ...DELIVERIES_DATA,
118630
+ "enforcement.report": empty3,
118631
+ "owner.shutdown_for_upgrade": empty3,
118632
+ "owner.update_committed": empty3,
118633
+ "control.attach.get": attachState,
118634
+ "control.attach.set": attachState,
118635
+ "control.remote_commands.get": remoteCommandsState,
118636
+ "control.remote_commands.set": remoteCommandsState,
117743
118637
  "control.session_wake.get": sessionWakeState,
117744
118638
  "control.session_wake.set": sessionWakeState,
117745
- "control.attach.get": attachState,
117746
- "control.attach.set": attachState
118639
+ "session.endpoints": endpointsData,
118640
+ "session.locate": (v) => refOf(v, "session.locate data"),
118641
+ ...MACHINE_DATA,
118642
+ ...DELIVERIES_DATA
117747
118643
  };
117748
118644
  var validateResponse = (v, type) => asViolation(() => {
117749
118645
  const m = known(v, ["id", "type", "ok"], ["data", "error"], "response");
@@ -117820,16 +118716,27 @@ class EventAssembler {
117820
118716
  case "session.detached":
117821
118717
  return this.#detached(event.attach);
117822
118718
  case "status.changed":
118719
+ case "sessions.listing_changed":
117823
118720
  case "session.snapshot":
117824
118721
  case "session.snapshot_loading":
117825
118722
  case "session.records":
117826
118723
  case "session.attach_pending":
117827
118724
  case "session.command_state":
117828
118725
  case "session.upload_abort":
118726
+ case "machine.op_state":
118727
+ case "machine.op_result":
118728
+ case "machine.output":
118729
+ case "machine.changed":
118730
+ case "machine.blob_chunk":
118731
+ case "machine.blob_done":
118732
+ case "machine.blob_abort":
117829
118733
  case "session.command_event":
117830
118734
  case "session.command_blob_chunk":
117831
118735
  case "session.command_blob_done":
117832
118736
  case "session.channel_closed":
118737
+ case "session.presenter_frame":
118738
+ case "session.presenter_ended":
118739
+ case "host.update_notice":
117833
118740
  case "delivery.inbound":
117834
118741
  case "delivery.holds":
117835
118742
  case "delivery.wake":
@@ -117877,7 +118784,8 @@ class EventAssembler {
117877
118784
  kind: "session.records",
117878
118785
  attach,
117879
118786
  attach_id: open.position.attach_id,
117880
- records
118787
+ records,
118788
+ seqs: [open.position.seq]
117881
118789
  });
117882
118790
  }
117883
118791
  case "entry": {
@@ -118100,12 +119008,8 @@ class ClientConnection {
118100
119008
  throw error;
118101
119009
  }
118102
119010
  if (!response.ok) {
118103
- const { code, reason, action, limit_chars, path_refusal } = response.error;
118104
- reject(new LocalApiError(code, reason, {
118105
- action,
118106
- ...limit_chars === undefined ? {} : { limit_chars },
118107
- ...path_refusal === undefined ? {} : { path_refusal }
118108
- }));
119011
+ const { code, reason, ...extra } = response.error;
119012
+ reject(new LocalApiError(code, reason, extra));
118109
119013
  return;
118110
119014
  }
118111
119015
  onAnswer?.(response.data);
@@ -118163,64 +119067,7 @@ class ClientConnection {
118163
119067
  }
118164
119068
  }
118165
119069
 
118166
- // packages/device-service-core/src/local-api/transport.ts
118167
- import { lstatSync as lstatSync7, readFileSync as readFileSync47, unlinkSync as unlinkSync11 } from "fs";
118168
- import { createConnection, createServer as createServer4 } from "net";
118169
- import { join as join119 } from "path";
118170
- var ENDPOINT_FILE = "endpoint.json";
118171
- var wrap = (socket, endpoint) => {
118172
- const closeListeners = [];
118173
- let closed = false;
118174
- socket.on("close", () => {
118175
- closed = true;
118176
- for (const listener of closeListeners.splice(0))
118177
- listener();
118178
- });
118179
- socket.on("error", () => {});
118180
- return {
118181
- endpoint,
118182
- write: (bytes) => {
118183
- if (!closed)
118184
- socket.write(bytes);
118185
- },
118186
- close: () => {
118187
- socket.end();
118188
- },
118189
- destroy: () => {
118190
- socket.destroy();
118191
- },
118192
- onData: (listener) => {
118193
- socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
118194
- },
118195
- onClose: (listener) => {
118196
- if (closed)
118197
- listener();
118198
- else
118199
- closeListeners.push(listener);
118200
- }
118201
- };
118202
- };
118203
- var readEndpointPort = (stateDir) => {
118204
- const parsed = JSON.parse(readFileSync47(join119(stateDir, ENDPOINT_FILE), "utf8"));
118205
- const port = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "port") : undefined;
118206
- if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
118207
- throw new LocalApiError("insecure_state_dir", "endpoint.json holds no port");
118208
- return port;
118209
- };
118210
- var connectLocal = (stateDir, options = {}) => new Promise((resolve, reject) => {
118211
- const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
118212
- const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
118213
- const socket = port === undefined ? createConnection({ path: join119(stateDir, SOCKET_FILE) }) : createConnection({ host: "127.0.0.1", port });
118214
- if (options.background === true)
118215
- socket.unref();
118216
- socket.once("error", reject);
118217
- socket.once("connect", () => {
118218
- socket.off("error", reject);
118219
- resolve(wrap(socket, endpoint));
118220
- });
118221
- });
118222
-
118223
- // packages/device-service-core/src/local-api/client.ts
119070
+ // packages/device-service-core/src/local-api/client-open.ts
118224
119071
  var HANDSHAKE_TIMEOUT_MS = 1e4;
118225
119072
  var REQUEST_TIMEOUT_MS = 30000;
118226
119073
  var realTimer = (expire, ms) => {
@@ -118239,7 +119086,7 @@ var proveAndAuthenticate = async (connection, options) => {
118239
119086
  const welcome = validateWelcome(await connection.firstMessage());
118240
119087
  if (welcome.type === "refused")
118241
119088
  throw new LocalApiError("refused", welcome.reason);
118242
- const token = (options.readToken ?? (() => readToken(options.stateDir)))();
119089
+ const token = options.readToken();
118243
119090
  if (!proofMatches(serverProof(token, nonce, connection.endpoint), welcome.server_proof))
118244
119091
  throw new LocalApiError("server_proof_invalid", "the owner did not prove the per-boot token");
118245
119092
  await connection.request("authenticate", {
@@ -118258,8 +119105,13 @@ var handshake = (connection, options) => new Promise((resolve, reject) => {
118258
119105
  }, HANDSHAKE_TIMEOUT_MS);
118259
119106
  proveAndAuthenticate(connection, options).then(resolve, reject).finally(cancel);
118260
119107
  });
118261
- var sendCommand = async (connection, attach, rpc, command_id, route, accepts) => {
118262
- const marked = accepts === undefined ? {} : { accepts };
119108
+ var sendCommand = async (connection, target, rpc, command_id, given = {}, mark = {}) => {
119109
+ const marked = mark.accepts === undefined ? {} : { accepts: mark.accepts };
119110
+ const route = {
119111
+ ...given.delegated === true && (("attach" in target) || ("endpoint" in target)) ? { delegated: true } : {},
119112
+ ...given.endpoint !== undefined && "attach" in target ? { endpoint: given.endpoint } : {},
119113
+ ...given.locate === true && "endpoint" in target ? { locate: true } : {}
119114
+ };
118263
119115
  const sent = command_id ?? mintId();
118264
119116
  const id = { command_id: sent };
118265
119117
  const timedOut = (error) => {
@@ -118272,8 +119124,9 @@ var sendCommand = async (connection, attach, rpc, command_id, route, accepts) =>
118272
119124
  const draft = {
118273
119125
  id: "x".repeat(REQUEST_ID_MAX_CHARS),
118274
119126
  type: "session.command",
118275
- attach,
119127
+ ...target,
118276
119128
  ...id,
119129
+ ...marked,
118277
119130
  ...route,
118278
119131
  rpc
118279
119132
  };
@@ -118284,50 +119137,14 @@ var sendCommand = async (connection, attach, rpc, command_id, route, accepts) =>
118284
119137
  limit_chars: MESSAGE_LIMIT_CHARS
118285
119138
  });
118286
119139
  const upload_id = mintId();
118287
- const parts = uploadParts(json).map((part) => connection.request("session.command_part", { attach, upload_id, ...part }));
119140
+ const on = "device" in target ? { device: target.device } : target;
119141
+ const parts = uploadParts(json).map((part) => connection.request("session.command_part", { ...on, upload_id, ...part }));
118288
119142
  await Promise.all(parts);
118289
- return (await connection.request("session.command", { attach, ...id, ...marked, ...route, upload_id }).catch(timedOut)).command_id;
119143
+ return (await connection.request("session.command", { ...target, ...id, ...marked, ...route, upload_id }).catch(timedOut)).command_id;
118290
119144
  }
118291
- return (await connection.request("session.command", { attach, ...id, ...marked, ...route, rpc }).catch(timedOut)).command_id;
119145
+ return (await connection.request("session.command", { ...target, ...id, ...marked, ...route, rpc }).catch(timedOut)).command_id;
118292
119146
  };
118293
- var sendWakeCommand = async (connection, device, durableId, rpc, command_id) => {
118294
- const sent = command_id ?? mintId();
118295
- const params = { wake: { device, durable_id: durableId }, command_id: sent, rpc };
118296
- if (lineBytes({ id: "x".repeat(REQUEST_ID_MAX_CHARS), type: "session.command", ...params }) > LOCAL_INLINE_MAX)
118297
- throw new LocalApiError("message_too_long", "a wake command travels inline only", {
118298
- limit_chars: MESSAGE_LIMIT_CHARS
118299
- });
118300
- try {
118301
- return (await connection.request("session.command", params)).command_id;
118302
- } catch (error) {
118303
- if (error instanceof LocalApiError && error.code === "request_timeout")
118304
- throw new LocalApiError("request_timeout", `command ${sent} may have been dispatched; follow its command state`, {
118305
- command_id: sent
118306
- });
118307
- throw error;
118308
- }
118309
- };
118310
- var sendEndpointCommand = async (connection, device, endpoint, rpc, command_id, locate) => {
118311
- const sent = command_id ?? mintId();
118312
- const params = { device, endpoint, command_id: sent, ...locate ? { locate: true } : {}, rpc };
118313
- if (lineBytes({ id: "x".repeat(REQUEST_ID_MAX_CHARS), type: "session.command", ...params }) > LOCAL_INLINE_MAX)
118314
- throw new LocalApiError("message_too_long", "an endpoint command travels inline only", {
118315
- limit_chars: MESSAGE_LIMIT_CHARS
118316
- });
118317
- try {
118318
- return (await connection.request("session.command", params)).command_id;
118319
- } catch (error) {
118320
- if (error instanceof LocalApiError && error.code === "request_timeout")
118321
- throw new LocalApiError("request_timeout", `command ${sent} may have been dispatched; follow its command state`, {
118322
- command_id: sent
118323
- });
118324
- throw error;
118325
- }
118326
- };
118327
- var connectLocalApi = async (options) => {
118328
- if (process.platform !== "win32")
118329
- checkPosixAccess(options.stateDir);
118330
- const transport = await (options.transport ?? (() => connectLocal(options.stateDir)))();
119147
+ var openLocalApiClient = async (transport, options) => {
118331
119148
  const listeners = new Set;
118332
119149
  const assembler = new EventAssembler((event) => {
118333
119150
  for (const listener of [...listeners])
@@ -118348,9 +119165,8 @@ var connectLocalApi = async (options) => {
118348
119165
  listeners.delete(listener);
118349
119166
  };
118350
119167
  },
118351
- command: (attach, rpc, command_id, route = {}, options) => sendCommand(connection, attach, rpc, command_id, route, options?.accepts),
118352
- wakeCommand: (device, durableId, rpc, command_id) => sendWakeCommand(connection, device, durableId, rpc, command_id),
118353
- endpointCommand: (device, endpoint, rpc, command_id, options) => sendEndpointCommand(connection, device, endpoint, rpc, command_id, options?.locate === true),
119168
+ command: (attach, rpc, command_id) => sendCommand(connection, { attach }, rpc, command_id),
119169
+ commandTo: (target, rpc, command_id, route, mark) => sendCommand(connection, target, rpc, command_id, route, mark),
118354
119170
  list: (filter, onRevision, rows) => new Promise((resolve, reject) => {
118355
119171
  const params = {
118356
119172
  ...filter === undefined ? {} : { filter },
@@ -118369,6 +119185,134 @@ var connectLocalApi = async (options) => {
118369
119185
  };
118370
119186
  };
118371
119187
 
119188
+ // packages/device-service-core/src/local-api/transport.ts
119189
+ import { lstatSync as lstatSync7, readFileSync as readFileSync47, unlinkSync as unlinkSync11 } from "fs";
119190
+ import { createConnection, createServer as createServer4 } from "net";
119191
+ import { join as join119 } from "path";
119192
+ var ENDPOINT_FILE = "endpoint.json";
119193
+ var wrap = (socket, endpoint) => {
119194
+ const closeListeners = [];
119195
+ let closed = false;
119196
+ socket.on("close", () => {
119197
+ closed = true;
119198
+ for (const listener of closeListeners.splice(0))
119199
+ listener();
119200
+ });
119201
+ socket.on("error", () => {});
119202
+ return {
119203
+ endpoint,
119204
+ write: (bytes) => {
119205
+ if (!closed)
119206
+ socket.write(bytes);
119207
+ },
119208
+ close: () => {
119209
+ socket.end();
119210
+ },
119211
+ destroy: () => {
119212
+ socket.destroy();
119213
+ },
119214
+ onData: (listener) => {
119215
+ socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
119216
+ },
119217
+ onClose: (listener) => {
119218
+ if (closed)
119219
+ listener();
119220
+ else
119221
+ closeListeners.push(listener);
119222
+ }
119223
+ };
119224
+ };
119225
+ var readEndpointPort = (stateDir) => {
119226
+ const parsed = JSON.parse(readFileSync47(join119(stateDir, ENDPOINT_FILE), "utf8"));
119227
+ const port = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "port") : undefined;
119228
+ if (typeof port !== "number" || !Number.isInteger(port) || port < 1 || port > 65535)
119229
+ throw new LocalApiError("insecure_state_dir", "endpoint.json holds no port");
119230
+ return port;
119231
+ };
119232
+ var connectLocal = (stateDir) => new Promise((resolve, reject) => {
119233
+ const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
119234
+ const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
119235
+ const socket = port === undefined ? createConnection({ path: join119(stateDir, SOCKET_FILE) }) : createConnection({ host: "127.0.0.1", port });
119236
+ socket.once("error", reject);
119237
+ socket.once("connect", () => {
119238
+ socket.off("error", reject);
119239
+ resolve(wrap(socket, endpoint));
119240
+ });
119241
+ });
119242
+
119243
+ // packages/device-service-core/src/local-api/client.ts
119244
+ var connectLocalApi = async (options) => {
119245
+ if (process.platform !== "win32")
119246
+ checkPosixAccess(options.stateDir);
119247
+ const transport = await (options.transport ?? (() => connectLocal(options.stateDir)))();
119248
+ return openLocalApiClient(transport, {
119249
+ client: options.client,
119250
+ readToken: options.readToken ?? (() => readToken(options.stateDir)),
119251
+ ...options.handshakeTimer === undefined ? {} : { handshakeTimer: options.handshakeTimer },
119252
+ ...options.requestTimer === undefined ? {} : { requestTimer: options.requestTimer }
119253
+ });
119254
+ };
119255
+
119256
+ // packages/device-service-core/src/background-transport.ts
119257
+ import { createConnection as createConnection2 } from "net";
119258
+ import { join as join120 } from "path";
119259
+ var wrap2 = (socket, endpoint) => {
119260
+ const closeListeners = [];
119261
+ let closed = false;
119262
+ socket.on("close", () => {
119263
+ closed = true;
119264
+ for (const listener of closeListeners.splice(0))
119265
+ listener();
119266
+ });
119267
+ socket.on("error", () => {});
119268
+ return {
119269
+ endpoint,
119270
+ write: (bytes) => {
119271
+ if (!closed)
119272
+ socket.write(bytes);
119273
+ },
119274
+ close: () => {
119275
+ socket.end();
119276
+ },
119277
+ destroy: () => {
119278
+ socket.destroy();
119279
+ },
119280
+ onData: (listener) => {
119281
+ socket.on("data", (chunk) => listener(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)));
119282
+ },
119283
+ onClose: (listener) => {
119284
+ if (closed)
119285
+ listener();
119286
+ else
119287
+ closeListeners.push(listener);
119288
+ }
119289
+ };
119290
+ };
119291
+ var connectLocalBackground = (stateDir) => new Promise((resolve, reject) => {
119292
+ const port = process.platform === "win32" ? readEndpointPort(stateDir) : undefined;
119293
+ const endpoint = port === undefined ? UNIX_ENDPOINT : tcpEndpoint(port);
119294
+ const socket = port === undefined ? createConnection2({ path: join120(stateDir, SOCKET_FILE) }) : createConnection2({ host: "127.0.0.1", port });
119295
+ socket.unref();
119296
+ socket.once("error", reject);
119297
+ socket.once("connect", () => {
119298
+ socket.off("error", reject);
119299
+ resolve(wrap2(socket, endpoint));
119300
+ });
119301
+ });
119302
+
119303
+ // packages/device-service-core/src/not-sent-error.ts
119304
+ class NotSentError extends LocalApiError {
119305
+ not_sent = true;
119306
+ }
119307
+ var markNotSent = (error) => error instanceof LocalApiError ? new NotSentError(error.code, error.reason, {
119308
+ action: error.action,
119309
+ ...error.limit_chars === undefined ? {} : { limit_chars: error.limit_chars },
119310
+ ...error.path_refusal === undefined ? {} : { path_refusal: error.path_refusal },
119311
+ ...error.candidates === undefined ? {} : { candidates: error.candidates },
119312
+ ...error.incomplete === undefined ? {} : { incomplete: error.incomplete },
119313
+ ...error.sign_in_reason === undefined ? {} : { sign_in_reason: error.sign_in_reason }
119314
+ }) : error;
119315
+
118372
119316
  // packages/device-service-core/src/remote-attach.ts
118373
119317
  import { randomBytes as randomBytes8 } from "crypto";
118374
119318
 
@@ -118506,7 +119450,12 @@ var toRemote = (event) => {
118506
119450
  return { kind: "snapshot", snapshot };
118507
119451
  }
118508
119452
  case "session.records":
118509
- return { kind: "records", attach_id: event.attach_id, records: event.records };
119453
+ return {
119454
+ kind: "records",
119455
+ attach_id: event.attach_id,
119456
+ records: event.records,
119457
+ ...event.seqs === undefined ? {} : { seqs: event.seqs }
119458
+ };
118510
119459
  case "session.attach_pending":
118511
119460
  return { kind: "pending", reason: event.reason };
118512
119461
  case "session.detached":
@@ -118642,7 +119591,7 @@ function openAttach(client, device, sessionId) {
118642
119591
  resolve(response === undefined ? { outcome: event } : { outcome: event, response });
118643
119592
  });
118644
119593
  commands.add(end);
118645
- client.command(attach, rpc, commandId, { delegated: true }, options).catch((error) => {
119594
+ client.commandTo({ attach }, rpc, commandId, { delegated: true }, options).catch((error) => {
118646
119595
  settle();
118647
119596
  reject(error);
118648
119597
  });
@@ -118729,19 +119678,19 @@ var compareVersions4 = (a, b) => {
118729
119678
  // packages/device-service-core/src/state-dir.ts
118730
119679
  import { readFileSync as readFileSync48, statSync as statSync10 } from "fs";
118731
119680
  import { homedir as homedir36 } from "os";
118732
- import { dirname as dirname49, join as join120, posix as posix17, win32 as win3212 } from "path";
119681
+ import { dirname as dirname49, join as join121, posix as posix17, win32 as win3212 } from "path";
118733
119682
  var DEVICE_SERVICE_STATE_DIR_ENV = "OMO_DEVICE_SERVICE_STATE_DIR";
118734
119683
  var LOCATION_FILE = "device-service.location.json";
118735
119684
  var isAbsoluteOn = (platform, path) => (platform === "win32" ? win3212 : posix17).isAbsolute(path);
118736
119685
  function defaultStateDir(platform, env, home) {
118737
119686
  if (platform !== "win32")
118738
- return join120(home, ".omo", "device-service");
118739
- const localAppData = env.LOCALAPPDATA ?? join120(home, "AppData", "Local");
118740
- return join120(localAppData, "OmO", "device-service");
119687
+ return join121(home, ".omo", "device-service");
119688
+ const localAppData = env.LOCALAPPDATA ?? join121(home, "AppData", "Local");
119689
+ return join121(localAppData, "OmO", "device-service");
118741
119690
  }
118742
119691
  function discoveredStateDir(platform, defaultDir) {
118743
119692
  try {
118744
- const parsed = JSON.parse(readFileSync48(join120(dirname49(defaultDir), LOCATION_FILE), "utf8"));
119693
+ const parsed = JSON.parse(readFileSync48(join121(dirname49(defaultDir), LOCATION_FILE), "utf8"));
118745
119694
  if (typeof parsed !== "object" || parsed === null || !("v" in parsed) || !("state_dir" in parsed))
118746
119695
  return;
118747
119696
  const { v, state_dir: stateDir } = parsed;
@@ -118763,7 +119712,7 @@ function deviceServiceStateDir(platform = process.platform, env = process.env, h
118763
119712
  var ENDPOINT_COMMAND_WAIT_MS = 120000;
118764
119713
  function sendToEndpoint(client, device, endpoint, rpc, locate) {
118765
119714
  return followDelegatedCommand(client, device, (commandId) => {
118766
- const send = (asked) => client.endpointCommand(device, endpoint, rpc, commandId, { locate: asked });
119715
+ const send = (asked) => client.commandTo({ device, endpoint }, rpc, commandId, asked ? { locate: true } : {});
118767
119716
  return send(locate).catch((error) => locate && error instanceof LocalApiError && error.code === "invalid_request" ? send(false) : Promise.reject(error));
118768
119717
  });
118769
119718
  }
@@ -118805,14 +119754,8 @@ function followDelegatedCommand(client, device, send) {
118805
119754
  send(commandId).catch(fail);
118806
119755
  });
118807
119756
  }
118808
- var markNotSent = (error) => error instanceof LocalApiError ? new LocalApiError(error.code, error.reason, {
118809
- action: error.action,
118810
- ...error.limit_chars === undefined ? {} : { limit_chars: error.limit_chars },
118811
- ...error.path_refusal === undefined ? {} : { path_refusal: error.path_refusal },
118812
- not_sent: true
118813
- }) : error;
118814
119757
  function deviceServiceEndpointPath(stateDir, platform = process.platform) {
118815
- return join121(stateDir, platform === "win32" ? ENDPOINT_FILE : SOCKET_FILE);
119758
+ return join122(stateDir, platform === "win32" ? ENDPOINT_FILE : SOCKET_FILE);
118816
119759
  }
118817
119760
  var ADOPT_ACCOUNT_MIN_SERVICE_VERSION = "0.1.3";
118818
119761
  var acceptsAdoptAccount = (serviceVersion) => compareVersions4(serviceVersion, ADOPT_ACCOUNT_MIN_SERVICE_VERSION) >= 0;
@@ -118824,7 +119767,7 @@ async function connectDeviceService(options) {
118824
119767
  const client = await (options.connect ?? connectLocalApi)({
118825
119768
  stateDir,
118826
119769
  client: { name: "omo", version: options.version },
118827
- ...options.background === true ? { transport: () => connectLocal(stateDir, { background: true }) } : {}
119770
+ ...options.background === true ? { transport: () => connectLocalBackground(stateDir) } : {}
118828
119771
  });
118829
119772
  const wakeMarkMinimum = minimumInEffect(options.minimums, "wakeMark", WAKE_MARK_MIN_SERVICE_VERSION);
118830
119773
  const carriesWakeMark = serviceAtLeast(client.welcome.service_version, wakeMarkMinimum);
@@ -118885,7 +119828,7 @@ async function connectDeviceService(options) {
118885
119828
  throw markNotSent(error);
118886
119829
  }
118887
119830
  if (endpoint === undefined)
118888
- throw new LocalApiError("unsupported", "the device lists no engine endpoint", { not_sent: true });
119831
+ throw new NotSentError("unsupported", "the device lists no engine endpoint");
118889
119832
  return await sendToEndpoint(client, device, endpoint, rpc, options?.locate === true);
118890
119833
  },
118891
119834
  close: () => client.close(),
@@ -118897,8 +119840,8 @@ async function connectDeviceService(options) {
118897
119840
  }),
118898
119841
  wakeCommand: async (device, durableId, rpc) => {
118899
119842
  if (!carriesWakeMark)
118900
- throw new LocalApiError("unsupported", "this device service does not carry the wake target", { not_sent: true });
118901
- return await followDelegatedCommand(client, device, (commandId) => client.wakeCommand(device, durableId, rpc, commandId).catch((error) => {
119843
+ throw new NotSentError("unsupported", "this device service does not carry the wake target");
119844
+ return await followDelegatedCommand(client, device, (commandId) => client.commandTo({ wake: { device, durable_id: durableId } }, rpc, commandId).catch((error) => {
118902
119845
  throw error instanceof LocalApiError && error.command_id === undefined ? markNotSent(error) : error;
118903
119846
  }));
118904
119847
  }
@@ -118969,6 +119912,61 @@ var SERVICE_TABLE_ENV = "OMO_RELAYD_SERVICES";
118969
119912
 
118970
119913
  // packages/device-service-core/src/cold-wake/darwin.ts
118971
119914
  var TABLE_KEY = `EnvironmentVariables.${SERVICE_TABLE_ENV}`;
119915
+ // packages/device-service-core/src/release/windows-dacl.ts
119916
+ import { spawn as spawn7 } from "child_process";
119917
+ var SID_TOKEN_SCRIPT = String.raw`
119918
+ $ErrorActionPreference = 'Stop'
119919
+ (New-Object System.Security.AccessControl.RawSecurityDescriptor("O:$env:LA_SID")).GetSddlForm('Owner')
119920
+ `;
119921
+ var runPowerShell2 = async (script, env) => {
119922
+ const encoded = Buffer.from(script, "utf16le").toString("base64");
119923
+ const proc = spawn7("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded], { env: { ...process.env, ...env }, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
119924
+ const chunks = [];
119925
+ const errChunks = [];
119926
+ proc.stdout.on("data", (chunk) => chunks.push(chunk));
119927
+ proc.stderr.on("data", (chunk) => errChunks.push(chunk));
119928
+ const code = await new Promise((resolve, reject) => {
119929
+ proc.once("error", reject);
119930
+ proc.once("close", (exitCode) => resolve(exitCode ?? -1));
119931
+ });
119932
+ return { code, out: Buffer.concat(chunks).toString("utf8"), err: Buffer.concat(errChunks).toString("utf8") };
119933
+ };
119934
+ var firstErrorLine = (err) => {
119935
+ const line = (err ?? "").split(/\r?\n/).find((text) => text.trim() !== "" && !text.startsWith("#< CLIXML"))?.trim() ?? "";
119936
+ return line === "" ? "" : `: ${line.slice(0, 300)}`;
119937
+ };
119938
+ var userSidToken = async (userSid, run = runPowerShell2) => {
119939
+ const { code, out } = await run(SID_TOKEN_SCRIPT, { LA_SID: userSid });
119940
+ const match = code === 0 ? /^O:(S-1-\d+(?:-\d+)+|[A-Z]{2})$/.exec(out.trim()) : null;
119941
+ return match?.[1];
119942
+ };
119943
+ var aliasedDaclVerdict = (dacl, userSid, kind, userAlias) => {
119944
+ const asSid = (token) => userAlias !== undefined && token === userAlias ? userSid : token;
119945
+ return exactDaclVerdict({ ...dacl, owner: asSid(dacl.owner), aces: dacl.aces.map((ace) => ({ ...ace, sid: asSid(ace.sid) })) }, userSid, kind);
119946
+ };
119947
+ var applyExactDacl2 = async (path, userSid, kind, run = runPowerShell2) => {
119948
+ const { code, err } = await run(APPLY_DACL_SCRIPT, { LA_PATH: path, LA_SID: userSid, LA_KIND: kind });
119949
+ if (code !== 0)
119950
+ throw new LocalApiError("insecure_state_dir", `the exact DACL could not be applied${firstErrorLine(err)}`);
119951
+ };
119952
+ var verifyExactDacl2 = async (path, userSid, kind, run = runPowerShell2) => {
119953
+ let dacl;
119954
+ try {
119955
+ dacl = await describeDacl(path, run);
119956
+ } catch (error) {
119957
+ if (error instanceof LocalApiError)
119958
+ return false;
119959
+ throw error;
119960
+ }
119961
+ return aliasedDaclVerdict(dacl, userSid, kind, await userSidToken(userSid, run));
119962
+ };
119963
+ var windowsSecureFile2 = (userSid, run = runPowerShell2) => async (path, kind) => {
119964
+ const target = kind === "dir" ? "dir" : "file";
119965
+ await applyExactDacl2(path, userSid, target, run);
119966
+ if (!await verifyExactDacl2(path, userSid, target, run))
119967
+ throw new LocalApiError("insecure_state_dir", "the DACL is not exactly one ACE for the user");
119968
+ };
119969
+
118972
119970
  // packages/device-service-core/src/release/release-assets.ts
118973
119971
  var MANIFEST = "latest.json";
118974
119972
  var CHECKSUMS_MAX_BYTES = 64 * 1024;
@@ -119034,13 +120032,13 @@ var parseReleaseKeySet = (value) => {
119034
120032
  };
119035
120033
  var DEVICE_SERVICE_RELEASE_KEYS = parseReleaseKeySet(release_key_default);
119036
120034
  // packages/device-service-core/src/release/acquire.ts
119037
- var platformSecure = process.platform === "win32" ? async (path, kind) => windowsSecureFile(await currentUserSid())(path, kind) : posixSecureFile;
120035
+ var platformSecure = process.platform === "win32" ? async (path, kind) => windowsSecureFile2(await currentUserSid())(path, kind) : posixSecureFile;
119038
120036
  // packages/device-service-core/src/registrant.ts
119039
120037
  var NONE2 = Symbol("none registered");
119040
120038
  // packages/omo-native/package.json
119041
120039
  var package_default4 = {
119042
120040
  name: "omo-ai",
119043
- version: "5.1.72",
120041
+ version: "5.1.73",
119044
120042
  type: "module",
119045
120043
  description: "OmO Native - the standalone omo command with the OMO extension built in: bun add -g omo-ai",
119046
120044
  bin: {
@@ -119142,6 +120140,825 @@ function cliDeviceServiceHandoff(options) {
119142
120140
  };
119143
120141
  }
119144
120142
 
120143
+ // packages/memory-core/src/journal/fsync.ts
120144
+ var SKIPPABLE_SYNC_CODES = new Set(["ENOENT", "EISDIR", "EPERM", "EACCES", "EINVAL"]);
120145
+
120146
+ // packages/memory-core/src/sync/crypto/vendor/sync-format/keys.ts
120147
+ var hexBytes = (hex) => {
120148
+ const pairs = hex.match(/../g);
120149
+ return Uint8Array.from((pairs ?? []).map((pair) => Number.parseInt(pair, 16)));
120150
+ };
120151
+ var ED25519_PKCS8_PREFIX = hexBytes("302e020100300506032b657004220420");
120152
+ var ED25519_SPKI_PREFIX = hexBytes("302a300506032b6570032100");
120153
+ // packages/memory-core/src/sync/crypto/anchor.ts
120154
+ var anchors = new WeakSet;
120155
+ var candidates = new WeakSet;
120156
+ var bootstraps = new WeakSet;
120157
+
120158
+ // packages/memory-core/src/sync/crypto/strict-ed25519/strict-ed25519.ts
120159
+ var P2 = (1n << 255n) - 19n;
120160
+ var L2 = (1n << 252n) + 27742317777372353535851937790883648493n;
120161
+ var mod2 = (n) => {
120162
+ const r = n % P2;
120163
+ return r < 0n ? r + P2 : r;
120164
+ };
120165
+ var power2 = (base, exponent) => {
120166
+ let result = 1n;
120167
+ let b = mod2(base);
120168
+ for (let n = exponent;n > 0n; n >>= 1n) {
120169
+ if (n & 1n)
120170
+ result = mod2(result * b);
120171
+ b = mod2(b * b);
120172
+ }
120173
+ return result;
120174
+ };
120175
+ var D2 = mod2(-121665n * power2(121666n, P2 - 2n));
120176
+ var SQRT_MINUS_ONE2 = power2(2n, (P2 - 1n) / 4n);
120177
+ var keyCache2 = new Map;
120178
+
120179
+ // packages/memory-core/src/sync/crypto/trust-pin.ts
120180
+ var SOURCES = new Set(["pairing", "recovery", "creator"]);
120181
+
120182
+ // packages/omo-senpi/src/components/thread/errors.ts
120183
+ var THREAD_ERROR_CODES = [
120184
+ "invalid_arguments",
120185
+ "caller_context_missing",
120186
+ "not_found",
120187
+ "reply_target_mismatch",
120188
+ "ambiguous_target",
120189
+ "scope_denied",
120190
+ "name_conflict",
120191
+ "not_resumable",
120192
+ "orphaned",
120193
+ "foreign_live_owner",
120194
+ "no_active_turn",
120195
+ "turn_conflict",
120196
+ "not_steerable",
120197
+ "message_too_large",
120198
+ "queue_full",
120199
+ "cursor_invalid",
120200
+ "cursor_stale",
120201
+ "idempotency_conflict",
120202
+ "idempotency_in_progress",
120203
+ "idempotency_uncertain",
120204
+ "approval_unavailable",
120205
+ "approval_route_locked",
120206
+ "partial_commit",
120207
+ "unsupported",
120208
+ "overloaded",
120209
+ "transport_closed",
120210
+ "host_unavailable",
120211
+ "internal_error",
120212
+ "model_not_found",
120213
+ "model_ambiguous",
120214
+ "thinking_level_unsupported",
120215
+ "loop_detected",
120216
+ "binding_conflict",
120217
+ "binding_mismatch",
120218
+ "binding_inactive",
120219
+ "stale_revision",
120220
+ "stale_token",
120221
+ "already_answered",
120222
+ "answer_in_progress",
120223
+ "device_offline",
120224
+ "relay_requires_paid_plan",
120225
+ "alias_taken"
120226
+ ];
120227
+ var CODE_SET = new Set(THREAD_ERROR_CODES);
120228
+
120229
+ // packages/omo-senpi/src/components/thread/remote/outcome.ts
120230
+ var READ_UNCERTAIN = {
120231
+ request_gone: "retry",
120232
+ no_receipt: "retry",
120233
+ engine_restarted: "retry",
120234
+ recipient_revoked: "retry",
120235
+ transport_expired: "retry",
120236
+ unconfirmed: "retry",
120237
+ lease_expired: "retry",
120238
+ cancelled: "retry",
120239
+ hand_restarted: "retry",
120240
+ result_expired: "retry",
120241
+ record_too_large: "too_large",
120242
+ result_undecodable: "retry"
120243
+ };
120244
+ var UNANSWERED = new Set([
120245
+ "closed",
120246
+ "protocol_violation",
120247
+ "internal",
120248
+ "read_failed",
120249
+ "request_timeout",
120250
+ "handshake_timeout",
120251
+ "attach_failed",
120252
+ "reply_lost",
120253
+ "host_not_answering",
120254
+ "peer_not_found",
120255
+ "engine_stale",
120256
+ ...Object.entries(READ_UNCERTAIN).filter(([, answer]) => answer === "retry").map(([reason]) => reason)
120257
+ ]);
120258
+
120259
+ // packages/omo-native/remote-attach.ts
120260
+ var MAX_LINE_CHARS = 64 * 1024 * 1024;
120261
+
120262
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/metrics.mjs
120263
+ var Metrics = {
120264
+ assign: 0,
120265
+ create: 0,
120266
+ clone: 0,
120267
+ discard: 0,
120268
+ update: 0
120269
+ };
120270
+
120271
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/guard/guard.mjs
120272
+ function IsArray(value) {
120273
+ return Array.isArray(value);
120274
+ }
120275
+ function IsBigInt(value) {
120276
+ return IsEqual(typeof value, "bigint");
120277
+ }
120278
+ function IsBoolean(value) {
120279
+ return IsEqual(typeof value, "boolean");
120280
+ }
120281
+ function IsNull(value) {
120282
+ return IsEqual(value, null);
120283
+ }
120284
+ function IsNumber(value) {
120285
+ return Number.isFinite(value);
120286
+ }
120287
+ function IsObject(value) {
120288
+ return IsEqual(typeof value, "object") && !IsNull(value);
120289
+ }
120290
+ function IsString(value) {
120291
+ return IsEqual(typeof value, "string");
120292
+ }
120293
+ function IsEqual(left, right) {
120294
+ return left === right;
120295
+ }
120296
+ function IsClassInstance(value) {
120297
+ if (!IsObject(value))
120298
+ return false;
120299
+ const proto = globalThis.Object.getPrototypeOf(value);
120300
+ if (IsNull(proto))
120301
+ return false;
120302
+ return IsEqual(typeof proto.constructor, "function") && !(IsEqual(proto.constructor, globalThis.Object) || IsEqual(proto.constructor.name, "Object"));
120303
+ }
120304
+ function IsUnsafePropertyKey(key) {
120305
+ return IsEqual(key, "__proto__") || IsEqual(key, "constructor") || IsEqual(key, "prototype");
120306
+ }
120307
+ function HasPropertyKey(value, key) {
120308
+ return IsUnsafePropertyKey(key) ? Object.prototype.hasOwnProperty.call(value, key) : (key in value);
120309
+ }
120310
+ function Keys(value) {
120311
+ return Object.getOwnPropertyNames(value);
120312
+ }
120313
+ function Symbols(value) {
120314
+ return Object.getOwnPropertySymbols(value);
120315
+ }
120316
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/guard/globals.mjs
120317
+ function IsTypeArray(value) {
120318
+ return globalThis.ArrayBuffer.isView(value);
120319
+ }
120320
+ function IsRegExp(value) {
120321
+ return value instanceof globalThis.RegExp;
120322
+ }
120323
+ function IsSet(value) {
120324
+ return value instanceof globalThis.Set;
120325
+ }
120326
+ function IsMap(value) {
120327
+ return value instanceof globalThis.Map;
120328
+ }
120329
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/settings/settings.mjs
120330
+ var settings2 = {
120331
+ immutableTypes: false,
120332
+ maxErrors: 8,
120333
+ maxParseErrors: 1,
120334
+ maxInstantiationCount: 128,
120335
+ useAcceleration: true,
120336
+ exactOptionalPropertyTypes: false,
120337
+ enumerableKind: false,
120338
+ correctiveParse: false,
120339
+ unionPrioritySort: true
120340
+ };
120341
+ function Get() {
120342
+ return settings2;
120343
+ }
120344
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/freeze.mjs
120345
+ function Freeze(value) {
120346
+ return Get().immutableTypes ? Object.freeze(value) : value;
120347
+ }
120348
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/clone.mjs
120349
+ function FromClassInstance(value) {
120350
+ return value;
120351
+ }
120352
+ function IsSchemaObject(value) {
120353
+ return HasPropertyKey(value, "~kind") || HasPropertyKey(value, "~unsafe");
120354
+ }
120355
+ function FromSchemaObject(value) {
120356
+ const result = {};
120357
+ for (const key of Keys(value)) {
120358
+ if (IsUnsafePropertyKey(key))
120359
+ continue;
120360
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
120361
+ descriptor.value = FromValue(descriptor.value);
120362
+ if (IsEqual(descriptor.enumerable, true)) {
120363
+ result[key] = descriptor.value;
120364
+ } else {
120365
+ Object.defineProperty(result, key, descriptor);
120366
+ }
120367
+ }
120368
+ return result;
120369
+ }
120370
+ function FromPlainObject(value) {
120371
+ const result = {};
120372
+ for (const key of Keys(value)) {
120373
+ if (IsUnsafePropertyKey(key))
120374
+ continue;
120375
+ result[key] = FromValue(value[key]);
120376
+ }
120377
+ for (const key of Symbols(value)) {
120378
+ result[key] = FromValue(value[key]);
120379
+ }
120380
+ return result;
120381
+ }
120382
+ function FromObject(value) {
120383
+ return IsClassInstance(value) ? FromClassInstance(value) : IsSchemaObject(value) ? FromSchemaObject(value) : FromPlainObject(value);
120384
+ }
120385
+ function FromArray(value) {
120386
+ return value.map((element) => FromValue(element));
120387
+ }
120388
+ function FromTypedArray(value) {
120389
+ return value.slice();
120390
+ }
120391
+ function FromRegExp(value) {
120392
+ return new RegExp(value.source, value.flags);
120393
+ }
120394
+ function FromMap(value) {
120395
+ return new Map(FromValue([...value.entries()]));
120396
+ }
120397
+ function FromSet(value) {
120398
+ return new Set(FromValue([...value.values()]));
120399
+ }
120400
+ function FromValue(value) {
120401
+ return IsTypeArray(value) ? FromTypedArray(value) : IsRegExp(value) ? FromRegExp(value) : IsMap(value) ? FromMap(value) : IsSet(value) ? FromSet(value) : IsArray(value) ? FromArray(value) : IsObject(value) ? FromObject(value) : value;
120402
+ }
120403
+ function Clone(value) {
120404
+ Metrics.clone += 1;
120405
+ return FromValue(value);
120406
+ }
120407
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/create.mjs
120408
+ function MergeHidden(left, right) {
120409
+ for (const key of Object.keys(right)) {
120410
+ Object.defineProperty(left, key, {
120411
+ configurable: true,
120412
+ writable: true,
120413
+ enumerable: false,
120414
+ value: right[key]
120415
+ });
120416
+ }
120417
+ return left;
120418
+ }
120419
+ function Merge(left, right) {
120420
+ return { ...left, ...right };
120421
+ }
120422
+ function Create(hidden, enumerable, options = {}) {
120423
+ Metrics.create += 1;
120424
+ const withOptions = Merge(enumerable, options);
120425
+ const withHidden = Get().enumerableKind ? Merge(withOptions, hidden) : MergeHidden(withOptions, hidden);
120426
+ return Freeze(withHidden);
120427
+ }
120428
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/memory/update.mjs
120429
+ function Update(current, hidden, enumerable) {
120430
+ Metrics.update += 1;
120431
+ const settings = Get();
120432
+ const result = Clone(current);
120433
+ for (const key of Object.keys(hidden)) {
120434
+ Object.defineProperty(result, key, {
120435
+ configurable: true,
120436
+ writable: true,
120437
+ enumerable: settings.enumerableKind,
120438
+ value: hidden[key]
120439
+ });
120440
+ }
120441
+ for (const key of Object.keys(enumerable)) {
120442
+ Object.defineProperty(result, key, {
120443
+ configurable: true,
120444
+ enumerable: true,
120445
+ writable: true,
120446
+ value: enumerable[key]
120447
+ });
120448
+ }
120449
+ return Freeze(result);
120450
+ }
120451
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/optional/instantiate_add.mjs
120452
+ function AddOptionalOperation(type) {
120453
+ return Update(type, { "~optional": true }, {});
120454
+ }
120455
+ function AddOptionalAction(type, options) {
120456
+ const result = Update(AddOptionalOperation(type), {}, options);
120457
+ return result;
120458
+ }
120459
+
120460
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/action/_add_optional.mjs
120461
+ function AddOptional(type, options = {}) {
120462
+ return AddOptionalAction(type, options);
120463
+ }
120464
+
120465
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/_optional.mjs
120466
+ function Optional(type) {
120467
+ return AddOptional(type);
120468
+ }
120469
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/system/hashing/hash.mjs
120470
+ var ByteMarker;
120471
+ (function(ByteMarker) {
120472
+ ByteMarker[ByteMarker["Array"] = 0] = "Array";
120473
+ ByteMarker[ByteMarker["BigInt"] = 1] = "BigInt";
120474
+ ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
120475
+ ByteMarker[ByteMarker["Date"] = 3] = "Date";
120476
+ ByteMarker[ByteMarker["Constructor"] = 4] = "Constructor";
120477
+ ByteMarker[ByteMarker["Function"] = 5] = "Function";
120478
+ ByteMarker[ByteMarker["Null"] = 6] = "Null";
120479
+ ByteMarker[ByteMarker["Number"] = 7] = "Number";
120480
+ ByteMarker[ByteMarker["Object"] = 8] = "Object";
120481
+ ByteMarker[ByteMarker["RegExp"] = 9] = "RegExp";
120482
+ ByteMarker[ByteMarker["String"] = 10] = "String";
120483
+ ByteMarker[ByteMarker["Symbol"] = 11] = "Symbol";
120484
+ ByteMarker[ByteMarker["TypeArray"] = 12] = "TypeArray";
120485
+ ByteMarker[ByteMarker["Undefined"] = 13] = "Undefined";
120486
+ })(ByteMarker || (ByteMarker = {}));
120487
+ var Accumulator = BigInt("14695981039346656037");
120488
+ var [Prime, Size] = [BigInt("1099511628211"), BigInt("18446744073709551616")];
120489
+ var Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i));
120490
+ var F64 = new Float64Array(1);
120491
+ var F64In = new DataView(F64.buffer);
120492
+ var F64Out = new Uint8Array(F64.buffer);
120493
+ var encoder4 = new TextEncoder;
120494
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/boolean.mjs
120495
+ function Boolean2(options) {
120496
+ return Create({ "~kind": "Boolean" }, { type: "boolean" }, options);
120497
+ }
120498
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/integer.mjs
120499
+ var IntegerPattern = "-?(?:0|[1-9][0-9]*)";
120500
+ function Integer(options) {
120501
+ return Create({ "~kind": "Integer" }, { type: "integer" }, options);
120502
+ }
120503
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/literal.mjs
120504
+ class InvalidLiteralValue extends Error {
120505
+ constructor(value) {
120506
+ super(`Invalid Literal value`);
120507
+ Object.defineProperty(this, "cause", {
120508
+ value: { value },
120509
+ writable: false,
120510
+ configurable: false,
120511
+ enumerable: false
120512
+ });
120513
+ }
120514
+ }
120515
+ function LiteralTypeName(value) {
120516
+ return IsBigInt(value) ? "bigint" : IsBoolean(value) ? "boolean" : IsNumber(value) ? "number" : IsString(value) ? "string" : (() => {
120517
+ throw new InvalidLiteralValue(value);
120518
+ })();
120519
+ }
120520
+ function Literal(value, options) {
120521
+ return Create({ "~kind": "Literal" }, { type: LiteralTypeName(value), const: value }, options);
120522
+ }
120523
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/number.mjs
120524
+ var NumberPattern = "-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?";
120525
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/string.mjs
120526
+ var StringPattern = ".*";
120527
+ function String2(options) {
120528
+ return Create({ "~kind": "String" }, { type: "string" }, options);
120529
+ }
120530
+
120531
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/union.mjs
120532
+ function Union(anyOf, options = {}) {
120533
+ return Create({ "~kind": "Union" }, { anyOf }, options);
120534
+ }
120535
+
120536
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/types/record.mjs
120537
+ var IntegerKey = `^${IntegerPattern}$`;
120538
+ var NumberKey = `^${NumberPattern}$`;
120539
+ var StringKey = `^${StringPattern}$`;
120540
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/internal/char.mjs
120541
+ function Range(start, end) {
120542
+ return Array.from({ length: end - start + 1 }, (_, i) => String.fromCharCode(start + i));
120543
+ }
120544
+ var Alpha = [
120545
+ ...Range(97, 122),
120546
+ ...Range(65, 90)
120547
+ ];
120548
+ var Zero = "0";
120549
+ var NonZero = Range(49, 57);
120550
+ var Digit = [Zero, ...NonZero];
120551
+ var UnderScore = "_";
120552
+ var DollarSign = "$";
120553
+
120554
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/unsigned_integer.mjs
120555
+ var AllowedDigits = [...Digit, UnderScore];
120556
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/ident.mjs
120557
+ var Initial = [...Alpha, UnderScore, DollarSign];
120558
+ var Remaining = [...Initial, ...Digit];
120559
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/script/token/unsigned_number.mjs
120560
+ var AllowedDigits2 = [...Digit, UnderScore];
120561
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/helpers/keys.mjs
120562
+ var integerKeyPattern = new RegExp("^(?:0|[1-9][0-9]*)$");
120563
+
120564
+ // node_modules/.bun/typebox@1.3.34/node_modules/typebox/build/type/engine/indexed/from_object.mjs
120565
+ var NumericKeyPattern = new RegExp(IntegerKey);
120566
+ // packages/omo-senpi/src/components/thread/gateway/bindings.ts
120567
+ var BINDING_MAX_TTL_SECONDS = 366 * 24 * 60 * 60;
120568
+ var OUTBOX_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120569
+ var RELAY_TEXT_MAX_BYTES = 32768;
120570
+
120571
+ // packages/omo-senpi/src/components/thread/contracts/fields.ts
120572
+ var THREAD_MESSAGE_MAX_BYTES = 32768;
120573
+ var THREAD_SUMMARY_MAX_LENGTH = 200;
120574
+ var ThreadAddress = String2({
120575
+ description: "Recipient thread id or unique name as returned by thread_list; a name shared by several threads returns ambiguous_target with candidates."
120576
+ });
120577
+ var AllScope = Optional(Boolean2({
120578
+ description: "Address threads in every workspace on this machine instead of only the caller's workspace; left unset, an exact id from another workspace returns scope_denied."
120579
+ }));
120580
+ var IdempotencyKey = Optional(String2({
120581
+ description: "Caller-chosen key that makes a retried call return the earlier result instead of repeating the side effect; reusing the key with different arguments returns idempotency_conflict."
120582
+ }));
120583
+ var ExpectedTurnId = Optional(String2({
120584
+ description: "Turn id the steer applies to; required with delivery steer, and a changed active turn returns turn_conflict with the message held undelivered."
120585
+ }));
120586
+ var Summary = Optional(String2({
120587
+ maxLength: THREAD_SUMMARY_MAX_LENGTH,
120588
+ description: "One-line preview shown to the caller when the completion notice arrives."
120589
+ }));
120590
+ var Message2 = String2({
120591
+ maxLength: THREAD_MESSAGE_MAX_BYTES,
120592
+ description: `Instruction to deliver to the target thread; longer than ${THREAD_MESSAGE_MAX_BYTES} UTF-8 bytes returns message_too_large.`
120593
+ });
120594
+ var BindingId = String2({
120595
+ minLength: 1,
120596
+ description: "Binding id as returned by thread_bind or thread_bindings."
120597
+ });
120598
+ var ExpectedRevision = Integer({
120599
+ minimum: 1,
120600
+ description: "Revision the caller last saw for this binding; a binding that moved since returns stale_revision."
120601
+ });
120602
+ var RelayText = String2({
120603
+ description: `Text relayed to or from the external thread; longer than ${RELAY_TEXT_MAX_BYTES} UTF-8 bytes returns message_too_large.`
120604
+ });
120605
+ var ThreadDeliveryMode = Union([Literal("auto"), Literal("steer"), Literal("follow_up")], {
120606
+ description: "auto steers the running turn when one is active and starts a new turn otherwise; steer requires expected_turn_id and becomes turn_conflict when the active turn changed; follow_up queues the message behind the running turn."
120607
+ });
120608
+
120609
+ // packages/omo-native/remote-session-args.ts
120610
+ var SESSION_VERBS = ["open", "send", "model", "interrupt", "close"];
120611
+
120612
+ // packages/omo-senpi/src/components/thread/control/port.ts
120613
+ var REFUSAL = Symbol.for("omo.thread.control.refusal");
120614
+
120615
+ // packages/omo-senpi/src/components/thread/control/close-ladder.ts
120616
+ var SESSION_GONE = new Set([
120617
+ "unknown_session",
120618
+ "session_identity_mismatch",
120619
+ "session_not_attached",
120620
+ "not_attached"
120621
+ ]);
120622
+
120623
+ // packages/omo-senpi/src/components/thread/thread-link.ts
120624
+ var THREAD_LINK_SCHEME = "omo-thread";
120625
+ var PREFIX = `${THREAD_LINK_SCHEME}://v1/`;
120626
+
120627
+ // packages/omo-senpi/src/components/thread/remote/address-book.ts
120628
+ var REMOTE_NOT_SET_UP = new Set(["not_configured", "disabled", "signed_out", "sign_in_required"]);
120629
+
120630
+ // packages/omo-senpi/src/components/thread/session-facts.ts
120631
+ var SESSION_FACTS_WINDOW_BYTES = 64 * 1024;
120632
+ var SESSION_FACTS_LAST_LINE_MAX_BYTES = SESSION_FACTS_WINDOW_BYTES * 4;
120633
+
120634
+ // packages/omo-senpi/src/components/thread/metadata.ts
120635
+ var THREAD_TOOL_EXPOSURE = "eval";
120636
+ var ROUTE_TO_TASK = "; to spawn a child task instead, use task.";
120637
+ var THREAD_TOOL_METADATA = [
120638
+ {
120639
+ name: "thread_create",
120640
+ label: "Create session",
120641
+ description: "Starts a fresh agent session that runs alongside this one, for when the user wants a second session working in parallel" + ROUTE_TO_TASK,
120642
+ exposure: THREAD_TOOL_EXPOSURE
120643
+ },
120644
+ {
120645
+ name: "thread_list",
120646
+ label: "List sessions",
120647
+ description: "Shows every addressable session on this device and the account's other devices with its id, name, status and device, plus the account's devices, for when the user needs a valid target address before acting on a session" + ROUTE_TO_TASK,
120648
+ exposure: THREAD_TOOL_EXPOSURE
120649
+ },
120650
+ {
120651
+ name: "thread_read",
120652
+ label: "Read session",
120653
+ description: "Returns the transcript and latest output of another session, for when the user asks what another session said or produced" + ROUTE_TO_TASK,
120654
+ exposure: THREAD_TOOL_EXPOSURE
120655
+ },
120656
+ {
120657
+ name: "thread_send",
120658
+ label: "Send message to session",
120659
+ description: "Delivers a message into another session that is already running, for when the user wants to talk to that session mid-task; its reply comes back through thread_read, and a bound chat thread's replies through thread_report and thread_answer" + ROUTE_TO_TASK,
120660
+ exposure: THREAD_TOOL_EXPOSURE
120661
+ },
120662
+ {
120663
+ name: "thread_interrupt",
120664
+ label: "Interrupt session turn",
120665
+ description: "Stops the turn running in another session, for when the user wants to halt a session that is going down the wrong path" + ROUTE_TO_TASK,
120666
+ exposure: THREAD_TOOL_EXPOSURE
120667
+ },
120668
+ {
120669
+ name: "thread_close",
120670
+ label: "Close session",
120671
+ description: "Closes another session on this device or on another of the account's devices, for when the user is done with that session and wants it shut down" + ROUTE_TO_TASK,
120672
+ exposure: THREAD_TOOL_EXPOSURE
120673
+ },
120674
+ {
120675
+ name: "thread_handoff",
120676
+ label: "Hand off session",
120677
+ description: "Moves the current request to an old session that has the context, for when the user says to hand this off or reopen that earlier conversation" + ROUTE_TO_TASK,
120678
+ exposure: THREAD_TOOL_EXPOSURE
120679
+ },
120680
+ {
120681
+ name: "thread_rename",
120682
+ label: "Rename session",
120683
+ description: "Changes the label a session is listed under, for when the user asks to call a session something clearer",
120684
+ exposure: THREAD_TOOL_EXPOSURE
120685
+ },
120686
+ {
120687
+ name: "thread_set_model",
120688
+ label: "Switch session model",
120689
+ description: "Moves a session onto a different model, for when the user asks to switch that session to another model or a cheaper one",
120690
+ exposure: THREAD_TOOL_EXPOSURE
120691
+ },
120692
+ {
120693
+ name: "thread_set_reasoning",
120694
+ label: "Set session reasoning level",
120695
+ description: "Sets how much reasoning a session applies, for when the user asks to raise or lower the thinking effort of a session",
120696
+ exposure: THREAD_TOOL_EXPOSURE
120697
+ },
120698
+ {
120699
+ name: "thread_bind",
120700
+ label: "Bind session to chat thread",
120701
+ description: "Attaches a session to an external chat thread on Discord, Telegram, Slack, Notion, Feishu, herdr or a custom connector, for when the user wants a chat conversation connected to a session",
120702
+ exposure: THREAD_TOOL_EXPOSURE
120703
+ },
120704
+ {
120705
+ name: "thread_unbind",
120706
+ label: "Unbind chat thread",
120707
+ description: "Detaches a session from its bound chat thread, for when the user wants that chat connection closed",
120708
+ exposure: THREAD_TOOL_EXPOSURE
120709
+ },
120710
+ {
120711
+ name: "thread_rebind",
120712
+ label: "Rebind chat thread",
120713
+ description: "Moves a bound chat thread over to another session, for when the user wants that chat served by a different session",
120714
+ exposure: THREAD_TOOL_EXPOSURE
120715
+ },
120716
+ {
120717
+ name: "thread_bindings",
120718
+ label: "List chat bindings",
120719
+ description: "Shows which chat threads are bound to which sessions with their revisions, for when the user needs a binding id or its revision",
120720
+ exposure: THREAD_TOOL_EXPOSURE
120721
+ },
120722
+ {
120723
+ name: "thread_report",
120724
+ label: "Report to chat thread",
120725
+ description: "Posts a milestone, result, question or completion from this session to its bound chat thread, for when the user wants progress relayed to that chat; replies flow back through thread_read, thread_report and thread_answer",
120726
+ exposure: THREAD_TOOL_EXPOSURE
120727
+ },
120728
+ {
120729
+ name: "thread_outbox",
120730
+ label: "Read chat outbox",
120731
+ description: "Returns the reports waiting for a bound chat thread with a cursor, for when a connector collects what sessions posted",
120732
+ exposure: THREAD_TOOL_EXPOSURE
120733
+ },
120734
+ {
120735
+ name: "thread_outbox_ack",
120736
+ label: "Acknowledge chat outbox",
120737
+ description: "Marks outbox rows up to a cursor as posted to the chat, for when a connector confirms delivery",
120738
+ exposure: THREAD_TOOL_EXPOSURE
120739
+ },
120740
+ {
120741
+ name: "thread_answer",
120742
+ label: "Answer relayed question",
120743
+ description: "Resolves a question a session relayed to a chat thread with the answer that arrived there, for when a connector hands back a chat user's reply",
120744
+ exposure: THREAD_TOOL_EXPOSURE
120745
+ }
120746
+ ];
120747
+
120748
+ // packages/omo-senpi/src/components/thread/control/relay-control.ts
120749
+ var IN_PROGRESS = new Set(["running", "compacting", "opening"]);
120750
+ var RUN_RECORDS = new Set([
120751
+ "agent_start",
120752
+ "turn_start",
120753
+ "message_start",
120754
+ "message_update",
120755
+ "message_end",
120756
+ "tool_execution_start",
120757
+ "tool_execution_update",
120758
+ "tool_execution_end",
120759
+ "turn_end",
120760
+ "agent_end"
120761
+ ]);
120762
+
120763
+ // packages/omo-senpi/src/components/thread/remote/session-state.ts
120764
+ var ACCESS_ENDED = new Set([
120765
+ "authorization_expired",
120766
+ "peer_revoked",
120767
+ "owner_transfer",
120768
+ "service_disabled"
120769
+ ]);
120770
+ var ACCESS_REFUSED = new Set([
120771
+ "unauthenticated",
120772
+ "forbidden",
120773
+ "owner_transfer",
120774
+ "signed_out",
120775
+ "service_disabled",
120776
+ "sign_in_required",
120777
+ "plan_required",
120778
+ "peer_not_found",
120779
+ "peer_not_session_client",
120780
+ "account_changed",
120781
+ "device_changed",
120782
+ "capability_missing",
120783
+ "engine_too_old"
120784
+ ]);
120785
+ var SESSION_LEFT = new Set(["session_closed", "session_replaced"]);
120786
+ var SESSION_GONE2 = new Set([
120787
+ "session_not_found",
120788
+ "unknown_session",
120789
+ "session_identity_mismatch"
120790
+ ]);
120791
+
120792
+ // packages/omo-senpi/src/components/thread/remote/device-service.ts
120793
+ var REFUSED_BEFORE_SENDING = new Set([
120794
+ "unauthenticated",
120795
+ "client_proof_invalid",
120796
+ "invalid_request",
120797
+ "unknown_type",
120798
+ "forbidden",
120799
+ "owner_transfer",
120800
+ "signed_out",
120801
+ "device_mismatch",
120802
+ "device_changed",
120803
+ "account_changed",
120804
+ "device_key_invalid",
120805
+ "service_disabled",
120806
+ "sign_in_required",
120807
+ "plan_required",
120808
+ "activation_pending",
120809
+ "authorization_stale",
120810
+ "peer_not_found",
120811
+ "peer_not_session_client",
120812
+ "session_not_found",
120813
+ "engine_too_old",
120814
+ "not_attached",
120815
+ "command_id_conflict",
120816
+ "message_too_long",
120817
+ "upload_incomplete",
120818
+ "malformed",
120819
+ "method_unclassified",
120820
+ "method_local_only",
120821
+ "host_not_answering",
120822
+ "unsupported"
120823
+ ]);
120824
+ var READ_ONLY_RECORDS = new Set(["get_state", "get_messages"]);
120825
+ var MARKED_RECORDS = new Set(["admit_external_message"]);
120826
+ var LOOKUP_NONE = new Set(["session_not_found", "peer_not_found", "peer_not_session_client"]);
120827
+
120828
+ // packages/omo-senpi/src/components/thread/gateway/constants.ts
120829
+ var QUEUED_TTL_MS = 24 * 60 * 60 * 1000;
120830
+ var ROOT_LIFETIME_MS = 7 * 24 * 60 * 60 * 1000;
120831
+ var TARGET_MAX_BYTES = 1024 * 1024;
120832
+ var GATEWAY_RECEIPT_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120833
+ var DELIVERY_RETENTION_MS = 30 * 24 * 60 * 60 * 1000;
120834
+ var RETENTION_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
120835
+
120836
+ // packages/omo-senpi/src/components/thread/gateway/session-args-schema.ts
120837
+ var TYPES = new Set(["object", "string", "number", "integer", "boolean", "array", "null"]);
120838
+ var ANNOTATIONS = new Set(["title", "description", "default", "examples"]);
120839
+ var COUNTS = ["minLength", "maxLength", "minItems", "maxItems"];
120840
+ var BOUNDS = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum"];
120841
+ var KEYWORDS = new Set([
120842
+ "type",
120843
+ "properties",
120844
+ "required",
120845
+ "additionalProperties",
120846
+ "enum",
120847
+ "const",
120848
+ "pattern",
120849
+ "items",
120850
+ "anyOf",
120851
+ ...COUNTS,
120852
+ ...BOUNDS,
120853
+ ...ANNOTATIONS
120854
+ ]);
120855
+
120856
+ // packages/omo-senpi/src/components/thread/remote/relay-transport.ts
120857
+ var ADMIT_UNSUPPORTED = new Set([
120858
+ "method_unclassified",
120859
+ "delegation_unclassified",
120860
+ "unknown_command",
120861
+ "engine_capability_missing",
120862
+ "unsupported_command",
120863
+ "method_unknown"
120864
+ ]);
120865
+ var WAITS = new Set(["wake", "hold", "approval"]);
120866
+
120867
+ // packages/omo-senpi/src/components/thread/remote/this-device.ts
120868
+ var known2 = new WeakMap;
120869
+
120870
+ // packages/omo-native/bin/lib/package-paths.js
120871
+ import { fileURLToPath as fileURLToPath9 } from "url";
120872
+ var packageRoot = fileURLToPath9(new URL("../..", import.meta.url));
120873
+
120874
+ // packages/omo-native/remote-session-verbs.ts
120875
+ var NO_SUCH_SESSION = new Set(["session_not_found", "unknown_session"]);
120876
+
120877
+ // packages/omo-native/remote-usage.ts
120878
+ var USAGE_HEAD = "usage: omo remote <command> [--json]";
120879
+ var USAGE_ENTRIES = [
120880
+ {
120881
+ verbs: ["status"],
120882
+ text: " status the device service's connection state"
120883
+ },
120884
+ {
120885
+ verbs: ["devices"],
120886
+ text: " devices the devices on this account"
120887
+ },
120888
+ {
120889
+ verbs: ["sessions"],
120890
+ text: ` sessions [--device D] [--project P] [--state running|idle|ended]
120891
+ sessions across the account's devices`
120892
+ },
120893
+ {
120894
+ verbs: ["enable", "disable"],
120895
+ text: " enable | disable turn remote sessions on or off for this device"
120896
+ },
120897
+ {
120898
+ verbs: ["control"],
120899
+ text: ` control [on|off] whether your other signed-in devices can view and command this
120900
+ device's sessions (on unless you turn it off)`
120901
+ },
120902
+ {
120903
+ verbs: ["wake"],
120904
+ text: ` wake [on|off|default] whether sessions on this device that are not running may be started
120905
+ by a message from your other signed-in devices; on unless turned off`
120906
+ },
120907
+ {
120908
+ verbs: ["bootstrap"],
120909
+ text: " bootstrap set up this device's service for your sign-in (every omo start runs it)"
120910
+ },
120911
+ {
120912
+ verbs: ["attach"],
120913
+ text: " attach <session> open a session in the terminal UI; also takes <device>/<session>"
120914
+ },
120915
+ {
120916
+ verbs: ["open"],
120917
+ text: ` open <device> [--project P] [--model provider/id] [--thinking LEVEL] [--permission-preset MODE]
120918
+ [--worktree [--branch B] [--base REF]] [--prompt TEXT [--steer|--follow-up]]
120919
+ start a session on another device; prints <device>/<session>; it runs
120920
+ in MODE (default: this device's own setting, else full-access), on the
120921
+ model and thinking level given (a model it cannot run opens nothing),
120922
+ in a new git worktree of P with --worktree, and is handed TEXT first`
120923
+ },
120924
+ {
120925
+ verbs: ["send"],
120926
+ text: ` send <session> <text> [--steer|--follow-up] [--no-wait]
120927
+ send a message and print the answer as it arrives (--steer: into the
120928
+ running turn; --no-wait: return once the session took it).
120929
+ Use the durable thread_id from open --json, or <device>/<session>.`
120930
+ },
120931
+ {
120932
+ verbs: ["model"],
120933
+ text: " model <session> <provider/id> switch the model; also takes <device>/<session>"
120934
+ },
120935
+ {
120936
+ verbs: ["interrupt"],
120937
+ text: " interrupt <session> stop the running turn; also takes <device>/<session>"
120938
+ },
120939
+ {
120940
+ verbs: ["close"],
120941
+ text: " close <session> end the session; also takes <device>/<session>"
120942
+ }
120943
+ ];
120944
+ var REMOTE_USAGE = [USAGE_HEAD, ...USAGE_ENTRIES.map((entry) => entry.text)].join(`
120945
+ `);
120946
+
120947
+ // packages/omo-native/remote-verbs.ts
120948
+ var VERBS = [
120949
+ "status",
120950
+ "devices",
120951
+ "sessions",
120952
+ "enable",
120953
+ "disable",
120954
+ "control",
120955
+ "wake",
120956
+ "bootstrap",
120957
+ ...SESSION_VERBS
120958
+ ];
120959
+ // packages/omo-native/remote-entry.ts
120960
+ var testSkipKey = Symbol.for("omo.test.skipRemoteLoginSetup");
120961
+
119145
120962
  // packages/omo-native/service-auth-command.ts
119146
120963
  var cliServiceAuthHooks = {
119147
120964
  deviceService: (api) => cliDeviceServiceHandoff({ api, log: (line) => process.stderr.write(`${line}
@@ -119351,7 +121168,7 @@ async function boulder(options) {
119351
121168
  return 0;
119352
121169
  }
119353
121170
  // packages/omo-opencode/src/cli/codex-ulw-loop.ts
119354
- import { spawn as spawn7 } from "child_process";
121171
+ import { spawn as spawn8 } from "child_process";
119355
121172
  import { existsSync as existsSync70, readFileSync as readFileSync49, realpathSync as realpathSync14 } from "fs";
119356
121173
  import { homedir as homedir37 } from "os";
119357
121174
  var ULW_LOOP_DELEGATION_SENTINEL = "OMO_ULW_LOOP_DELEGATED";
@@ -119381,7 +121198,7 @@ async function codexUlwLoop(args) {
119381
121198
  return 1;
119382
121199
  }
119383
121200
  const { promise, resolve } = Promise.withResolvers();
119384
- const child = spawn7(command.executable, [...command.argsPrefix, ...args], {
121201
+ const child = spawn8(command.executable, [...command.argsPrefix, ...args], {
119385
121202
  stdio: "inherit",
119386
121203
  env: { ...process.env, [ULW_LOOP_DELEGATION_SENTINEL]: "1" }
119387
121204
  });