@dicamo/flint-ai-bridge 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,7 +59,7 @@ Ask about companies, stores, devices, media, scenes, users, login history, autom
59
59
 
60
60
  Every query respects your menu claims, company and store access scope, and server data policies. Owners have full read access. Data changes and remote commands are not supported. History and other child records require the parent resource ID first. Installed apps support bulk queries combining app name, package, and version with device company, store, and service/player version filters. This requires the administrator to apply the installed-app inventory SQL update. Counts refer to matching app records, not distinct devices. Statistics require the corresponding query functions on the server.
61
61
 
62
- Select the Claude model at the top of the chat: CLI default, Sonnet, Opus, or Haiku. Changes apply to the next message, and selection is disabled while a response is in progress. The actual model reported by the CLI is saved with usage data. Model availability depends on your Claude account.
62
+ Select the Claude model at the top of the chat or as the default in CMS settings. The list is the one Claude Code itself offers for your account (aliases such as Opus or Sonnet that follow the newest model, and pinned versions). The bridge reads it from Claude Code's `initialize` response at startup and every hour, without running a model, so new models appear when you update Claude Code. Changes apply to the next message, and selection is disabled while a response is in progress. The actual model reported by the CLI is saved with usage data. Model availability depends on your Claude account.
63
63
 
64
64
  ## Reconnect or stop
65
65
 
@@ -1,8 +1,9 @@
1
1
  // src/protocol.ts
2
2
  var PROTOCOL_VERSION = 1;
3
- var BRIDGE_VERSION = "1.1.0";
3
+ var BRIDGE_VERSION = "1.1.1";
4
4
  var PORTS = Array.from({ length: 10 }, (_, i) => 47820 + i);
5
5
  var CLAUDE_MODELS = ["default", "sonnet", "opus", "haiku"];
6
+ var CLAUDE_MODEL_PATTERN = /^(?:default|fable|opus|sonnet|haiku|claude-[a-z0-9]+(?:-[a-z0-9]+){0,4})$/;
6
7
  var AI_CLAIM = "enable:ai.assistant";
7
8
  var MAX_MESSAGE_BYTES = 256 * 1024;
8
9
  var RESOURCES = ["companies", "devices", "studio", "media", "dashboard", "users", "users.login_history", "automations", "holidays", "app_store", "alterra", "media_log"];
@@ -12,6 +13,7 @@ export {
12
13
  BRIDGE_VERSION,
13
14
  PORTS,
14
15
  CLAUDE_MODELS,
16
+ CLAUDE_MODEL_PATTERN,
15
17
  AI_CLAIM,
16
18
  MAX_MESSAGE_BYTES,
17
19
  RESOURCES
package/dist/cli.js CHANGED
@@ -2,11 +2,11 @@
2
2
  import {
3
3
  AI_CLAIM,
4
4
  BRIDGE_VERSION,
5
- CLAUDE_MODELS,
5
+ CLAUDE_MODEL_PATTERN,
6
6
  MAX_MESSAGE_BYTES,
7
7
  PORTS,
8
8
  RESOURCES
9
- } from "./chunk-SST2QOUV.js";
9
+ } from "./chunk-I26SVJRQ.js";
10
10
 
11
11
  // src/cli.ts
12
12
  import { fileURLToPath as fileURLToPath2 } from "url";
@@ -212,10 +212,10 @@ async function startBackground(directory, entry, chat) {
212
212
 
213
213
  // src/cli.ts
214
214
  import { homedir as homedir2 } from "os";
215
- import { join as join5, resolve } from "path";
215
+ import { join as join6, resolve } from "path";
216
216
  import { parseArgs } from "util";
217
217
  import { watchFile, unwatchFile } from "fs";
218
- import { access as access2, writeFile as writeFile5, mkdir as mkdir4, unlink as unlink4 } from "fs/promises";
218
+ import { access as access2, writeFile as writeFile6, mkdir as mkdir4, unlink as unlink4 } from "fs/promises";
219
219
  import { createInterface } from "readline";
220
220
 
221
221
  // src/config.ts
@@ -1004,7 +1004,7 @@ async function checkClaudeCapabilities(directory, cli, run3 = runJsonProcess) {
1004
1004
  var dbTurn = z8.object({ id: z8.string().uuid(), session_id: z8.string().uuid(), host_id: z8.string().uuid(), cli: z8.literal("claude"), status: z8.literal("running"), bridge_stream_id: z8.string().uuid(), prompt: z8.string().min(1).max(32e3), lease_expires_at: z8.string() });
1005
1005
  function createCmsExecutor(dataDir, cliVersion = "unknown") {
1006
1006
  return async (request) => {
1007
- const model = z8.enum(CLAUDE_MODELS).parse(request.model ?? "default");
1007
+ const model = z8.string().max(64).regex(CLAUDE_MODEL_PATTERN).parse(request.model ?? "default");
1008
1008
  const controller = new AbortController();
1009
1009
  const signal = AbortSignal.any([request.signal, controller.signal]);
1010
1010
  const active = () => {
@@ -1184,7 +1184,7 @@ var requestSchema = z9.discriminatedUnion("type", [
1184
1184
  accessibleResources: z9.array(z9.string().max(64)).max(32)
1185
1185
  }).strict(),
1186
1186
  z9.object({ ...envelope, type: z9.literal("auth.clear"), authContextId: z9.string().uuid() }).strict(),
1187
- z9.object({ ...turnFields, type: z9.literal("turn.start"), sessionId: z9.string().uuid(), model: z9.enum(CLAUDE_MODELS).optional() }).strict(),
1187
+ z9.object({ ...turnFields, type: z9.literal("turn.start"), sessionId: z9.string().uuid(), model: z9.string().max(64).regex(CLAUDE_MODEL_PATTERN).optional() }).strict(),
1188
1188
  z9.object({ ...turnFields, type: z9.literal("turn.cancel") }).strict(),
1189
1189
  z9.object({ ...turnFields, type: z9.literal("turn.ack") }).strict(),
1190
1190
  ...["status", "unpair"].map((type) => z9.object({ ...envelope, type: z9.literal(type) }).strict())
@@ -1200,6 +1200,19 @@ async function startBridge(options) {
1200
1200
  const detect = options.detect ?? detectClis;
1201
1201
  let clis = await detect();
1202
1202
  let lastDetection = Date.now();
1203
+ let models;
1204
+ let modelsAt = 0;
1205
+ let loadingModels;
1206
+ const refreshModels = () => {
1207
+ if (!options.listModels || loadingModels || Date.now() - modelsAt < 36e5) return loadingModels;
1208
+ loadingModels = options.listModels().then((list) => list, () => void 0).then((list) => {
1209
+ if (list) models = list;
1210
+ modelsAt = list ? Date.now() : Date.now() - 33e5;
1211
+ loadingModels = void 0;
1212
+ });
1213
+ return loadingModels;
1214
+ };
1215
+ await refreshModels();
1203
1216
  const http = createServer3((_req, res) => {
1204
1217
  res.writeHead(404, { "Cache-Control": "no-store" });
1205
1218
  res.end();
@@ -1295,6 +1308,7 @@ async function startBridge(options) {
1295
1308
  peer.pairingId = remembered.id;
1296
1309
  clearTimeout(peer.deadline);
1297
1310
  }
1311
+ void refreshModels();
1298
1312
  reply({
1299
1313
  type: "hello.ok",
1300
1314
  bridgeVersion: BRIDGE_VERSION,
@@ -1303,7 +1317,8 @@ async function startBridge(options) {
1303
1317
  connectionId: peer.id,
1304
1318
  paired: !!remembered,
1305
1319
  clis,
1306
- capabilities: { modelSelection: true, localApproval: !!options.approve, chat: !!options.execute, reason: options.execute ? "ready" : "preflight_required", autostart: !!options.autostart }
1320
+ ...models ? { models } : {},
1321
+ capabilities: { modelSelection: true, localApproval: !!options.approve, chat: !!options.execute, reason: options.execute ? "ready" : "preflight_required", autostart: !!options.autostart, anyModel: true }
1307
1322
  });
1308
1323
  return;
1309
1324
  }
@@ -1538,21 +1553,61 @@ async function startBridge(options) {
1538
1553
  };
1539
1554
  }
1540
1555
 
1556
+ // src/claudeModels.ts
1557
+ import { mkdtemp as mkdtemp3, rm as rm3, writeFile as writeFile4 } from "fs/promises";
1558
+ import { join as join4 } from "path";
1559
+ import { z as z10 } from "zod";
1560
+ var listSchema = z10.array(z10.object({ value: z10.string(), displayName: z10.string(), description: z10.string().optional() }).passthrough()).max(64);
1561
+ function parseModels(raw) {
1562
+ const list = listSchema.safeParse(raw);
1563
+ if (!list.success) return [];
1564
+ return list.data.filter((m) => CLAUDE_MODEL_PATTERN.test(m.value)).slice(0, 40).map((m) => ({
1565
+ value: m.value,
1566
+ displayName: m.displayName.slice(0, 60),
1567
+ ...m.description ? { description: m.description.slice(0, 120) } : {}
1568
+ }));
1569
+ }
1570
+ async function listClaudeModels(directory, run3 = runJsonProcess) {
1571
+ const dir = await mkdtemp3(join4(directory, "claude-models-"));
1572
+ let models;
1573
+ try {
1574
+ const config = join4(dir, "mcp.json");
1575
+ await writeFile4(config, JSON.stringify({ mcpServers: {} }), { mode: 384 });
1576
+ await run3({
1577
+ command: "claude",
1578
+ args: [...claudeIsolationArgs(config), "--input-format", "stream-json"],
1579
+ cwd: dir,
1580
+ env: claudeEnvironment(),
1581
+ input: JSON.stringify({ type: "control_request", request_id: "models", request: { subtype: "initialize" } }) + "\n",
1582
+ timeoutMs: 15e3,
1583
+ maxBytes: 1024 * 1024,
1584
+ onEvent(event) {
1585
+ const e = event;
1586
+ if (e.type === "control_response" && e.response?.request_id === "models") models = parseModels(e.response.response?.models);
1587
+ }
1588
+ }).catch(() => {
1589
+ });
1590
+ return models?.length ? models : void 0;
1591
+ } finally {
1592
+ await rm3(dir, { recursive: true, force: true });
1593
+ }
1594
+ }
1595
+
1541
1596
  // src/autostart.ts
1542
1597
  import { execFile as execFile3 } from "child_process";
1543
- import { access, mkdir as mkdir3, unlink as unlink3, writeFile as writeFile4 } from "fs/promises";
1598
+ import { access, mkdir as mkdir3, unlink as unlink3, writeFile as writeFile5 } from "fs/promises";
1544
1599
  import { homedir } from "os";
1545
- import { dirname as dirname2, join as join4 } from "path";
1600
+ import { dirname as dirname2, join as join5 } from "path";
1546
1601
  import { promisify as promisify3 } from "util";
1547
1602
  var run2 = promisify3(execFile3);
1548
1603
  var LAUNCH_LABEL = "dev.dicamo.flint-ai-bridge";
1549
1604
  var WINDOWS_RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
1550
1605
  var WINDOWS_VALUE = "FlintAiBridge";
1551
- var plistPath = () => join4(homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
1606
+ var plistPath = () => join5(homedir(), "Library", "LaunchAgents", `${LAUNCH_LABEL}.plist`);
1552
1607
  var xml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1553
1608
  var exists = (path) => access(path).then(() => true, () => false);
1554
1609
  async function npxPath() {
1555
- const candidate = join4(dirname2(process.execPath), process.platform === "win32" ? "npx.cmd" : "npx");
1610
+ const candidate = join5(dirname2(process.execPath), process.platform === "win32" ? "npx.cmd" : "npx");
1556
1611
  if (await exists(candidate)) return candidate;
1557
1612
  const { stdout } = await run2(process.platform === "win32" ? "where" : "which", ["npx"], { timeout: 5e3 });
1558
1613
  const found = stdout.split(/\r?\n/)[0]?.trim();
@@ -1564,7 +1619,7 @@ function bridgeArgs(version, directory, command) {
1564
1619
  }
1565
1620
  function launchAgentPlist(npx, args, directory, path) {
1566
1621
  const strings = (items) => items.map((item) => ` <string>${xml(item)}</string>`).join("\n");
1567
- const log = xml(join4(directory, "bridge.log"));
1622
+ const log = xml(join5(directory, "bridge.log"));
1568
1623
  return `<?xml version="1.0" encoding="UTF-8"?>
1569
1624
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1570
1625
  <plist version="1.0">
@@ -1591,7 +1646,7 @@ async function installAutostart(directory, version) {
1591
1646
  const npx = await npxPath();
1592
1647
  const path = plistPath();
1593
1648
  await mkdir3(dirname2(path), { recursive: true });
1594
- await writeFile4(path, launchAgentPlist(npx, bridgeArgs(version, directory, "serve"), directory, process.env.PATH ?? "/usr/bin:/bin"), { mode: 420 });
1649
+ await writeFile5(path, launchAgentPlist(npx, bridgeArgs(version, directory, "serve"), directory, process.env.PATH ?? "/usr/bin:/bin"), { mode: 420 });
1595
1650
  const domain = `gui/${process.getuid?.()}`;
1596
1651
  await run2("launchctl", ["bootout", `${domain}/${LAUNCH_LABEL}`]).catch(() => {
1597
1652
  });
@@ -1653,10 +1708,10 @@ serve: loopback connection and pairing. --enable-chat opts into Claude CMS chat
1653
1708
  While serving, type "pair" to issue a new five-minute pairing code.`);
1654
1709
  return;
1655
1710
  }
1656
- const path = join5(resolve(values["data-dir"] ?? join5(homedir2(), ".flint-ai-bridge")), "config.json");
1657
- const directory = resolve(values["data-dir"] ?? join5(homedir2(), ".flint-ai-bridge"));
1658
- const lockPath = join5(directory, "instance.lock");
1659
- const revokePath = join5(directory, "revoke.request");
1711
+ const path = join6(resolve(values["data-dir"] ?? join6(homedir2(), ".flint-ai-bridge")), "config.json");
1712
+ const directory = resolve(values["data-dir"] ?? join6(homedir2(), ".flint-ai-bridge"));
1713
+ const lockPath = join6(directory, "instance.lock");
1714
+ const revokePath = join6(directory, "revoke.request");
1660
1715
  const running = await instanceLocked(lockPath);
1661
1716
  const command = positionals[0] ?? "serve";
1662
1717
  if (command === "status") {
@@ -1682,7 +1737,7 @@ While serving, type "pair" to issue a new five-minute pairing code.`);
1682
1737
  await new Promise((resolve2) => setTimeout(resolve2, 500));
1683
1738
  state = await backgroundStatus(directory);
1684
1739
  }
1685
- if (!state.running) throw new Error(`Bridge did not start. Check ${join5(directory, "bridge.log")}`);
1740
+ if (!state.running) throw new Error(`Bridge did not start. Check ${join6(directory, "bridge.log")}`);
1686
1741
  } else state = await startBackground(directory, fileURLToPath2(import.meta.url), true);
1687
1742
  console.log(`FLiNT AI bridge is ready: ws://127.0.0.1:${state.port}
1688
1743
  Chat: ${state.chat ? "enabled" : `disabled${state.chatReason ? `: ${state.chatReason}` : ""}`}
@@ -1708,7 +1763,7 @@ You can close this terminal. The bridge will keep running in the background.
1708
1763
  To stop the bridge, run:
1709
1764
  npx @dicamo/flint-ai-bridge stop${dataDirOption}
1710
1765
 
1711
- Log: ${join5(directory, "bridge.log")}`);
1766
+ Log: ${join6(directory, "bridge.log")}`);
1712
1767
  return;
1713
1768
  }
1714
1769
  switch (command) {
@@ -1722,7 +1777,7 @@ Log: ${join5(directory, "bridge.log")}`);
1722
1777
  }
1723
1778
  case "unpair":
1724
1779
  if (running) {
1725
- await writeFile5(revokePath, String(Date.now()), { mode: 384 });
1780
+ await writeFile6(revokePath, String(Date.now()), { mode: 384 });
1726
1781
  console.log("Revocation requested. The running bridge processes it within one second.");
1727
1782
  } else {
1728
1783
  config.pairings = [];
@@ -1764,7 +1819,7 @@ Log: ${join5(directory, "bridge.log")}`);
1764
1819
  console.warn(`CMS chat unavailable: ${chatReason} Bridge discovery remains available.`);
1765
1820
  }
1766
1821
  }
1767
- const bridge = await startBridge({ config, persist, execute, autostart: await autostartInstalled(), approve: process.platform === "darwin" ? requestLocalApproval : void 0 });
1822
+ const bridge = await startBridge({ config, persist, execute, autostart: await autostartInstalled(), listModels: execute ? () => listClaudeModels(directory) : void 0, approve: process.platform === "darwin" ? requestLocalApproval : void 0 });
1768
1823
  const issue = () => {
1769
1824
  try {
1770
1825
  console.log(`Pairing code: ${bridge.pairing.issue()} (5 minutes; type pair to reissue)`);
@@ -14,9 +14,9 @@ declare const turnUsageSchema: z.ZodObject<{
14
14
  cache_write_tokens: z.ZodNullable<z.ZodNumber>;
15
15
  reasoning_tokens: z.ZodNullable<z.ZodNumber>;
16
16
  usage_status: z.ZodEnum<{
17
+ unavailable: "unavailable";
17
18
  complete: "complete";
18
19
  partial: "partial";
19
- unavailable: "unavailable";
20
20
  }>;
21
21
  source_scope: z.ZodLiteral<"turn">;
22
22
  }, z.core.$strict>;
@@ -24,10 +24,19 @@ type TurnUsage = z.infer<typeof turnUsageSchema>;
24
24
 
25
25
  /** Browser-safe protocol. Keep Node imports and runtime dependencies out of this file. */
26
26
  declare const PROTOCOL_VERSION: 1;
27
- declare const BRIDGE_VERSION = "1.1.0";
27
+ declare const BRIDGE_VERSION = "1.1.1";
28
28
  declare const PORTS: number[];
29
+ /** The only models bridges up to 1.1.0 accept. Newer bridges report capabilities.anyModel. */
29
30
  declare const CLAUDE_MODELS: readonly ["default", "sonnet", "opus", "haiku"];
30
- type ClaudeModel = typeof CLAUDE_MODELS[number];
31
+ /** An alias or a full Claude model name for `claude --model`. Never starts with "-", so it cannot become a CLI flag. */
32
+ declare const CLAUDE_MODEL_PATTERN: RegExp;
33
+ type ClaudeModel = string;
34
+ /** One model the user's Claude Code offers (from its `initialize` response). value goes to `--model`. */
35
+ type ModelInfo = {
36
+ value: string;
37
+ displayName: string;
38
+ description?: string;
39
+ };
31
40
  declare const AI_CLAIM = "enable:ai.assistant";
32
41
  declare const MAX_MESSAGE_BYTES: number;
33
42
  declare const RESOURCES: readonly ["companies", "devices", "studio", "media", "dashboard", "users", "users.login_history", "automations", "holidays", "app_store", "alterra", "media_log"];
@@ -98,12 +107,14 @@ type ResponseBody = {
98
107
  connectionId: string;
99
108
  paired: boolean;
100
109
  clis: CliInfo[];
110
+ models?: ModelInfo[];
101
111
  capabilities: {
102
112
  localApproval?: boolean;
103
113
  modelSelection?: boolean;
104
114
  chat: boolean;
105
115
  reason: 'preflight_required' | 'ready';
106
116
  autostart?: boolean;
117
+ anyModel?: boolean;
107
118
  };
108
119
  } | {
109
120
  type: 'pair.ok';
@@ -154,4 +165,4 @@ type BridgeResponse = ResponseBody & {
154
165
  };
155
166
  type ErrorCode = 'invalid_request' | 'version_unsupported' | 'pair_required' | 'pair_invalid' | 'pair_denied' | 'approval_unavailable' | 'pair_locked' | 'pair_expired' | 'rate_limited' | 'server_not_allowed' | 'auth_invalid' | 'api_key_invalid' | 'auth_forbidden' | 'auth_context_mismatch' | 'scope_unavailable' | 'preflight_required' | 'internal_error' | 'turn_busy' | 'turn_failed';
156
167
 
157
- export { AI_CLAIM, BRIDGE_VERSION, type BridgeRequest, type BridgeResponse, CLAUDE_MODELS, type ClaudeModel, type CliInfo, type ErrorCode, type Identity, MAX_MESSAGE_BYTES, PORTS, PROTOCOL_VERSION, RESOURCES, type RequestBody, type Resource, type ResponseBody };
168
+ export { AI_CLAIM, BRIDGE_VERSION, type BridgeRequest, type BridgeResponse, CLAUDE_MODELS, CLAUDE_MODEL_PATTERN, type ClaudeModel, type CliInfo, type ErrorCode, type Identity, MAX_MESSAGE_BYTES, type ModelInfo, PORTS, PROTOCOL_VERSION, RESOURCES, type RequestBody, type Resource, type ResponseBody };
package/dist/protocol.js CHANGED
@@ -2,15 +2,17 @@ import {
2
2
  AI_CLAIM,
3
3
  BRIDGE_VERSION,
4
4
  CLAUDE_MODELS,
5
+ CLAUDE_MODEL_PATTERN,
5
6
  MAX_MESSAGE_BYTES,
6
7
  PORTS,
7
8
  PROTOCOL_VERSION,
8
9
  RESOURCES
9
- } from "./chunk-SST2QOUV.js";
10
+ } from "./chunk-I26SVJRQ.js";
10
11
  export {
11
12
  AI_CLAIM,
12
13
  BRIDGE_VERSION,
13
14
  CLAUDE_MODELS,
15
+ CLAUDE_MODEL_PATTERN,
14
16
  MAX_MESSAGE_BYTES,
15
17
  PORTS,
16
18
  PROTOCOL_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dicamo/flint-ai-bridge",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Local CLI connection bridge for FLiNT CMS",
5
5
  "type": "module",
6
6
  "bin": {