@dicamo/flint-ai-bridge 1.0.5 → 1.0.6
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 +5 -3
- package/dist/cli.js +29 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Stop the running bridge before changing these URLs.
|
|
|
38
38
|
### 2. Start the bridge
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
npx @dicamo/flint-ai-bridge@1.0.
|
|
41
|
+
npx @dicamo/flint-ai-bridge@1.0.6 start --enable-chat
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
When chat is requested, startup checks Claude Code in a temporary directory and stops it after inspecting its initialization event. No CMS credentials or data are passed to this check. If the check fails, the bridge stays available for pairing and displays the reason chat is disabled. Retry by stopping and starting the bridge after resolving the issue.
|
|
@@ -71,8 +71,8 @@ The bridge does not reconnect automatically or save pairing credentials in the b
|
|
|
71
71
|
Check the bridge status or stop it:
|
|
72
72
|
|
|
73
73
|
```sh
|
|
74
|
-
npx @dicamo/flint-ai-bridge@1.0.
|
|
75
|
-
npx @dicamo/flint-ai-bridge@1.0.
|
|
74
|
+
npx @dicamo/flint-ai-bridge@1.0.6 status
|
|
75
|
+
npx @dicamo/flint-ai-bridge@1.0.6 stop
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
Run `start --enable-chat` again after restarting your computer. The bridge does not register itself to start at login. Runtime errors and fallback pairing codes are written to `~/.flint-ai-bridge/bridge.log`. To view output directly in a terminal, use `serve --enable-chat` and press `Ctrl+C` to stop.
|
|
@@ -99,3 +99,5 @@ npx @dicamo/flint-ai-bridge@latest --help
|
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
Snapshot metadata is available in device queries. If the server has snapshot analysis enabled, the assistant can filter dark-snapshot candidates across accessible devices. A dark image is not proof of a display failure; capture time and incomplete analysis must be considered.
|
|
102
|
+
|
|
103
|
+
On servers with snapshot image embeddings enabled, the assistant can find visually similar device snapshots using a reference device. Searches respect device permissions and return ranked matches, not a probability of a fault. Vector generation status is available separately; incomplete or stale embeddings are not searched.
|
package/dist/cli.js
CHANGED
|
@@ -405,6 +405,7 @@ var CMS_DATASETS = [
|
|
|
405
405
|
dataset("holiday_overrides", "Store opening exceptions", "holidays", "store_holiday_override", "store_id,date", { parent: { dataset: "stores", field: "store_id" } }, ["date", "store_id"]),
|
|
406
406
|
dataset("device_apps", "Installed apps across devices", "devices", "rpc/device_app_inventory", "id,device_id,name,package_name,version,version_code,installed_at,updated_at,device_name,company_id,store_id,online,service_version,service_version_code,player_app_version,player_app_version_code", { schema: "ai", company: "company_id", store: "store_id" }),
|
|
407
407
|
dataset("device_snapshots", "Snapshot brightness analysis", "devices", "rpc/device_snapshot_status", "device_id,device_name,company_id,store_id,online,snapshot_path,captured_at,analysis_status,black_pixel_ratio,mean_luminance,black_screen_candidate,analyzed_at,sample_width,sample_height,algorithm,error_code", { schema: "ai", company: "company_id", store: "store_id" }, ["device_id"]),
|
|
408
|
+
dataset("device_snapshot_vectors", "Snapshot vector generation status", "devices", "rpc/device_snapshot_vectors", "device_id,device_name,company_id,store_id,online,captured_at,embedding_status,embedding_model,embedded_at", { schema: "ai", company: "company_id", store: "store_id" }, ["device_id"]),
|
|
408
409
|
dataset("device_notes", "Device notes", "devices", "device_notes", "id,device_id,body,created_by,created_at,updated_at", { parent: { dataset: "devices", field: "device_id" } }),
|
|
409
410
|
dataset("scene_history", "Scene history", "studio", "scene_histories", "id,scene_id,action,name,description,changed_by,changed_at", { parent: { dataset: "scenes", field: "scene_id" } }),
|
|
410
411
|
dataset("scene_time_slots", "Scene time slots", "studio", "v_scene_time_slots", "scene_id,slot,screen_index,screen_id,tv_screen_id,screen_label,width,height,media", { parent: { dataset: "scenes", field: "scene_id" } }, ["slot", "screen_index"]),
|
|
@@ -427,6 +428,8 @@ var CATALOG_TOOLS = [
|
|
|
427
428
|
].map((tool) => ({ ...tool, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } }));
|
|
428
429
|
var reportArgs = z4.object({ report: z4.enum(["dashboard", "media_log"]), companyIds: z4.array(z4.number().int().nonnegative()).min(1).max(100).optional(), storeId: z4.number().int().nonnegative().optional(), days: z4.number().int().min(1).max(90).default(7) }).strict();
|
|
429
430
|
var REPORT_TOOL = { name: "get_cms_report", description: "Retrieve dashboard statistics (device uptime trends, media and scene totals) or media playback statistics. Specify company IDs to narrow the scope. Store-restricted accounts must specify one accessible storeId. Requires the statistics RPCs to be installed on the server.", inputSchema: { type: "object", properties: { report: { type: "string", enum: ["dashboard", "media_log"] }, companyIds: { type: "array", items: { type: "integer", minimum: 0 }, minItems: 1, maxItems: 100 }, storeId: { type: "integer", minimum: 0 }, days: { type: "integer", minimum: 1, maximum: 90 } }, required: ["report"], additionalProperties: false }, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } };
|
|
431
|
+
var similarSnapshotArgs = z4.object({ deviceId: z4.string().min(1).max(256).regex(/^[^\u0000-\u001f\u007f]+$/), limit: z4.number().int().min(1).max(50).default(10), minSimilarity: z4.number().min(-1).max(1).default(0.8), online: z4.boolean().optional() }).strict();
|
|
432
|
+
var SIMILAR_SNAPSHOT_TOOL = { name: "find_similar_snapshots", description: "Find accessible devices whose latest analysed snapshot is visually similar to a reference device snapshot. Requires a ready image embedding. Results are ranked top matches, not an exhaustive count. Similarity is cosine similarity, not a probability or proof of identical content or a display fault. Check capture times and current online state. Does not accept free-text image descriptions.", inputSchema: { type: "object", properties: { deviceId: { type: "string" }, limit: { type: "integer", minimum: 1, maximum: 50 }, minSimilarity: { type: "number", minimum: -1, maximum: 1 }, online: { type: "boolean" } }, required: ["deviceId"], additionalProperties: false }, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } };
|
|
430
433
|
|
|
431
434
|
// src/cmsTools.ts
|
|
432
435
|
var id = z5.number().int().nonnegative().safe();
|
|
@@ -439,9 +442,9 @@ var LEGACY_TOOLS = [
|
|
|
439
442
|
{ name: "get_device_status", description: "Retrieve the registration time (created_at) and status of one accessible device.", inputSchema: { type: "object", properties: { deviceId: { type: "string", minLength: 1, maxLength: 256 } }, required: ["deviceId"], additionalProperties: false } },
|
|
440
443
|
{ name: "list_companies", description: "Return the names and IDs of companies accessible to the current user.", inputSchema: { type: "object", properties: {}, additionalProperties: false } }
|
|
441
444
|
].map((tool) => ({ ...tool, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } }));
|
|
442
|
-
var CMS_TOOLS = [...LEGACY_TOOLS, ...CATALOG_TOOLS, REPORT_TOOL];
|
|
445
|
+
var CMS_TOOLS = [...LEGACY_TOOLS, ...CATALOG_TOOLS, REPORT_TOOL, SIMILAR_SNAPSHOT_TOOL];
|
|
443
446
|
function toolResource(name) {
|
|
444
|
-
return name === "list_companies" ? "companies" : name === "list_devices" || name === "get_device_status" ? "devices" : null;
|
|
447
|
+
return name === "list_companies" ? "companies" : name === "list_devices" || name === "get_device_status" || name === "find_similar_snapshots" ? "devices" : null;
|
|
445
448
|
}
|
|
446
449
|
var CmsReadTools = class {
|
|
447
450
|
options;
|
|
@@ -454,7 +457,11 @@ var CmsReadTools = class {
|
|
|
454
457
|
async readPage(table, query, count2 = false, payload, schema2) {
|
|
455
458
|
const o = this.options;
|
|
456
459
|
o.assertActive();
|
|
457
|
-
const response = await (o.fetch ?? fetch)(`${o.credentials.url}/rest/v1/${table}?${query}`, { method: payload ? "POST" : "GET", ...payload ? { body: JSON.stringify(payload) } : {}, headers: { "Content-Type": "application/json", apikey: o.credentials.anonKey, Authorization: `Bearer ${o.credentials.accessToken}`, ...schema2 ? { "Accept-Profile": schema2 } : {}, ...count2 ? { Prefer: "count=exact" } : {} }, redirect: "error", signal: AbortSignal.any([AbortSignal.timeout(8e3), ...o.signal ? [o.signal] : []]) });
|
|
460
|
+
const response = await (o.fetch ?? fetch)(`${o.credentials.url}/rest/v1/${table}?${query}`, { method: payload ? "POST" : "GET", ...payload ? { body: JSON.stringify(payload) } : {}, headers: { "Content-Type": "application/json", apikey: o.credentials.anonKey, Authorization: `Bearer ${o.credentials.accessToken}`, ...schema2 ? { "Accept-Profile": schema2, ...payload ? { "Content-Profile": schema2 } : {} } : {}, ...count2 ? { Prefer: "count=exact" } : {} }, redirect: "error", signal: AbortSignal.any([AbortSignal.timeout(8e3), ...o.signal ? [o.signal] : []]) });
|
|
461
|
+
if (!response.ok && table === "rpc/match_device_snapshots") {
|
|
462
|
+
await response.body?.cancel();
|
|
463
|
+
throw new Error(response.status === 404 ? "cms_snapshot_vectors_not_installed" : "cms_snapshot_similarity_unavailable");
|
|
464
|
+
}
|
|
458
465
|
if (!response.ok) throw new Error(response.status === 404 && schema2 === "ai" && table === "rpc/device_app_inventory" ? "cms_device_apps_not_installed" : response.status === 404 && schema2 === "ai" && table === "rpc/device_snapshot_status" ? "cms_snapshot_analysis_not_installed" : "cms_query_failed");
|
|
459
466
|
const reader = response.body?.getReader();
|
|
460
467
|
if (!reader) throw new Error("cms_invalid_response");
|
|
@@ -561,6 +568,20 @@ var CmsReadTools = class {
|
|
|
561
568
|
const hasMore = rows.length > input.limit;
|
|
562
569
|
return { rows: rows.slice(0, input.limit).map((row) => Object.fromEntries(requested.filter((f) => Object.hasOwn(row, f)).map((f) => [f, row[f]]))), total: page.total, hasMore, nextOffset: hasMore ? input.offset + input.limit : null, ...countUnit };
|
|
563
570
|
}
|
|
571
|
+
async similarSnapshots(input, user) {
|
|
572
|
+
if (!this.canRead(user, "devices")) throw new Error("cms_tool_forbidden");
|
|
573
|
+
const parent = await this.queryDataset(queryArgs.parse({ dataset: "devices", fields: ["id"], filters: [{ field: "id", op: "eq", value: input.deviceId }], limit: 1 }), user, true);
|
|
574
|
+
if (!parent.rows.length) throw new Error("cms_scope_forbidden");
|
|
575
|
+
const allowed = await this.scope(user);
|
|
576
|
+
const stores = user.scope.super_user || user.scope.is_owner ? null : user.scope.store_ids;
|
|
577
|
+
const page = await this.readPage("rpc/match_device_snapshots", new URLSearchParams(), false, { p_device_id: input.deviceId, p_limit: input.limit, p_min_similarity: input.minSimilarity, p_company_ids: allowed === null ? null : [...allowed], p_store_ids: stores, p_online: input.online ?? null }, "ai");
|
|
578
|
+
const rows = z5.array(z5.object({ device_id: deviceId, device_name: z5.string().nullable(), company_id: id.nullable(), store_id: id.nullable(), online: z5.boolean(), captured_at: z5.string(), similarity: z5.number().finite().min(-1.000001).max(1.000001), embedding_model: z5.string() })).max(input.limit).parse(page.rows);
|
|
579
|
+
for (const row of rows) {
|
|
580
|
+
if (allowed !== null && (row.company_id === null || !allowed.has(row.company_id)) || stores !== null && (row.store_id === null || !stores.includes(row.store_id))) throw new Error("cms_scope_violation");
|
|
581
|
+
if (row.device_id === input.deviceId || row.similarity < input.minSimilarity || input.online !== void 0 && row.online !== input.online) throw new Error("cms_filter_violation");
|
|
582
|
+
}
|
|
583
|
+
return { referenceDeviceId: input.deviceId, rows, rankedMatches: true, exhaustive: false };
|
|
584
|
+
}
|
|
564
585
|
assertRowScope(d, row, allowed, stores) {
|
|
565
586
|
if (d.company && allowed !== null && (typeof row[d.company] !== "number" || !allowed.has(row[d.company])) || d.store && stores !== null && (typeof row[d.store] !== "number" || !stores.includes(row[d.store]))) throw new Error("cms_scope_violation");
|
|
566
587
|
}
|
|
@@ -568,11 +589,12 @@ var CmsReadTools = class {
|
|
|
568
589
|
const o = this.options;
|
|
569
590
|
o.assertActive();
|
|
570
591
|
if (!CMS_TOOLS.some((tool) => tool.name === name)) throw new Error("cms_unknown_tool");
|
|
571
|
-
const parsed = name === "get_cms_report" ? reportArgs.parse(args) : name === "query_cms" ? queryArgs.parse(args) : name === "list_devices" ? listArgs.parse(args) : name === "get_device_status" ? z5.object({ deviceId }).strict().parse(args) : z5.object({}).strict().parse(args);
|
|
592
|
+
const parsed = name === "find_similar_snapshots" ? similarSnapshotArgs.parse(args) : name === "get_cms_report" ? reportArgs.parse(args) : name === "query_cms" ? queryArgs.parse(args) : name === "list_devices" ? listArgs.parse(args) : name === "get_device_status" ? z5.object({ deviceId }).strict().parse(args) : z5.object({}).strict().parse(args);
|
|
572
593
|
const user = await (o.verify ?? verifySupabase)(o.credentials);
|
|
573
594
|
o.assertActive();
|
|
574
595
|
if (user.userId !== o.userId || user.expiresAt <= Date.now() || !user.scope.is_owner && !user.claims.includes("enable:ai.assistant")) throw new Error("cms_auth_changed");
|
|
575
596
|
if (permissionsRevision(user) !== o.permissionsRevision) throw new Error("cms_permissions_changed");
|
|
597
|
+
if (name === "find_similar_snapshots") return this.similarSnapshots(parsed, user);
|
|
576
598
|
if (name === "get_cms_report") return this.report(parsed, user);
|
|
577
599
|
if (name === "describe_cms_queries") return { reports: ["dashboard", "media_log"].filter((r) => this.canRead(user, r)), deviceQueryGuidance: DEVICE_QUERY_GUIDANCE, datasets: CMS_DATASETS.filter((d) => this.canRead(user, d.resource)).map(({ name: name2, label, fields, parent }) => ({ name: name2, label, fields, ...name2 === "device_apps" ? { countUnit: "installed_app_records", bulkQuery: true } : {}, ...parent ? { requiredFilter: { field: parent.field, op: "eq", description: "Look up the parent resource ID first." } } : {} })), pagination: "Offset-based pagination. Data changes during retrieval may cause duplicates or omissions across pages." };
|
|
578
600
|
if (name === "query_cms") return this.queryDataset(parsed, user);
|
|
@@ -656,7 +678,7 @@ async function startCmsMcp(options) {
|
|
|
656
678
|
if (++calls > 64) throw new Error("tool_limit");
|
|
657
679
|
const args = z6.object({ name: z6.string(), arguments: z6.unknown().optional(), _meta: z6.record(z6.string(), z6.unknown()).optional() }).strict().parse(input.params);
|
|
658
680
|
if (!tools.some((tool) => tool.name === args.name)) throw new Error("tool_forbidden");
|
|
659
|
-
const label = { list_devices: "Device list", get_device_status: "Device status", list_companies: "Company list", describe_cms_queries: "Query catalog", query_cms: "CMS data", get_cms_report: "CMS statistics" }[args.name];
|
|
681
|
+
const label = { find_similar_snapshots: "Similar snapshots", list_devices: "Device list", get_device_status: "Device status", list_companies: "Company list", describe_cms_queries: "Query catalog", query_cms: "CMS data", get_cms_report: "CMS statistics" }[args.name];
|
|
660
682
|
options.onActivity?.(`${label}: querying\u2026`);
|
|
661
683
|
try {
|
|
662
684
|
const value = await service.call(args.name, args.arguments ?? {});
|
|
@@ -668,7 +690,7 @@ async function startCmsMcp(options) {
|
|
|
668
690
|
options.onActivity?.(`${label}: query failed`);
|
|
669
691
|
const code = error instanceof Error ? error.message : "";
|
|
670
692
|
const permission = ["cms_auth_changed", "cms_permissions_changed", "cms_tool_forbidden", "cms_scope_forbidden", "cms_scope_violation", "auth_forbidden"].includes(code);
|
|
671
|
-
const message = code === "cms_snapshot_analysis_not_installed" ? "Snapshot analysis requires the snapshot-analysis Edge Function and supabase/device_snapshot_analysis/01_install.sql. Missing analysis does not establish whether a screen is black." : code === "cms_device_apps_not_installed" ? "Bulk installed-app queries require the database administrator to apply 06_device_app_inventory.sql. The ai schema must also be exposed by PostgREST. Do not fall back to a per-device scan." : code === "cms_parent_required" ? "This query requires an eq filter on the parent ID. Check requiredFilter in describe_cms_queries." : ["cms_invalid_field", "cms_invalid_filter", "cms_unknown_dataset"].includes(code) ? "The query dataset or fields are invalid. Check describe_cms_queries." : error instanceof z6.ZodError ? "The bridge could not process the CMS response format or tool arguments. Do not assume this is a permission issue." : permission ? "Authentication or query scope validation failed." : "An error occurred while processing the CMS query. This error alone does not establish a permission issue.";
|
|
693
|
+
const message = code === "cms_snapshot_vectors_not_installed" ? "Snapshot vector search is not installed on this server." : code === "cms_snapshot_similarity_unavailable" ? "Snapshot similarity search is unavailable. The reference embedding may still be pending or stale. Query device_snapshot_vectors for its status; do not infer that no similar screens exist." : code === "cms_snapshot_analysis_not_installed" ? "Snapshot analysis requires the snapshot-analysis Edge Function and supabase/device_snapshot_analysis/01_install.sql. Missing analysis does not establish whether a screen is black." : code === "cms_device_apps_not_installed" ? "Bulk installed-app queries require the database administrator to apply 06_device_app_inventory.sql. The ai schema must also be exposed by PostgREST. Do not fall back to a per-device scan." : code === "cms_parent_required" ? "This query requires an eq filter on the parent ID. Check requiredFilter in describe_cms_queries." : ["cms_invalid_field", "cms_invalid_filter", "cms_unknown_dataset"].includes(code) ? "The query dataset or fields are invalid. Check describe_cms_queries." : error instanceof z6.ZodError ? "The bridge could not process the CMS response format or tool arguments. Do not assume this is a permission issue." : permission ? "Authentication or query scope validation failed." : "An error occurred while processing the CMS query. This error alone does not establish a permission issue.";
|
|
672
694
|
result = { isError: true, content: [{ type: "text", text: message + " Do not guess the query results." }] };
|
|
673
695
|
}
|
|
674
696
|
} else {
|
|
@@ -1206,7 +1228,7 @@ async function startBridge(options) {
|
|
|
1206
1228
|
if (request.bridgeToken) throw new BridgeError("pair_required");
|
|
1207
1229
|
reply({
|
|
1208
1230
|
type: "hello.ok",
|
|
1209
|
-
bridgeVersion: "1.0.
|
|
1231
|
+
bridgeVersion: "1.0.6",
|
|
1210
1232
|
hostId: config.hostId,
|
|
1211
1233
|
streamId,
|
|
1212
1234
|
connectionId: peer.id,
|