@airalogy/aimd-recorder 1.22.0 → 1.23.0
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 +61 -0
- package/README.zh-CN.md +61 -0
- package/dist/{AimdDnaSequenceField-Bhj28fP8.js → AimdDnaSequenceField-JzxsGmRf.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-D7c01UqN.js → AimdEditor.vue_vue_type_style_index_0_lang-v82TdP_I.js} +1978 -1899
- package/dist/AimdEntityRefField-O0FwJDC0.js +229 -0
- package/dist/{AimdMarkdownField-GS15pv4z.js → AimdMarkdownField-Dd6M3zOI.js} +18 -18
- package/dist/{AimdMarkdownNoteField-H9WP8tR6.js → AimdMarkdownNoteField-DCkJg80X.js} +23 -23
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-B50G9-kH.js → arc-Bw7VOW6S.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-D9mBEbpY.js → architectureDiagram-3BPJPVTR-B4RdL02h.js} +2 -2
- package/dist/{blockDiagram-GPEHLZMM-Cs4swgto.js → blockDiagram-GPEHLZMM-B5skMgx6.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-C12HKS3r.js → c4Diagram-AAUBKEIU-DDxL4a7C.js} +2 -2
- package/dist/{channel-D69VnjVz.js → channel-CQ1fnqoz.js} +1 -1
- package/dist/{chunk-2J33WTMH-oc-89G5c.js → chunk-2J33WTMH-B08Yr5NK.js} +1 -1
- package/dist/{chunk-4BX2VUAB-BDJS9G3r.js → chunk-4BX2VUAB-CyCffaPa.js} +1 -1
- package/dist/{chunk-55IACEB6-BPl3uHcA.js → chunk-55IACEB6-CztHyBOI.js} +1 -1
- package/dist/{chunk-727SXJPM-pWe-vDGf.js → chunk-727SXJPM-CEVNkjmn.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-D-R5sIr1.js → chunk-AQP2D5EJ-C9t9hFOg.js} +3 -3
- package/dist/{chunk-FMBD7UC4-bo6Qyom1.js → chunk-FMBD7UC4-ulCTg3qb.js} +1 -1
- package/dist/{chunk-ND2GUHAM-DQMvtYV7.js → chunk-ND2GUHAM-D4Cbj52r.js} +1 -1
- package/dist/{chunk-QZHKN3VN-DlCn3HON.js → chunk-QZHKN3VN-Rpw3UPGi.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-DzUwWFwr.js → classDiagram-4FO5ZUOK-D8dNLFoj.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-DzUwWFwr.js → classDiagram-v2-Q7XG4LA2-D8dNLFoj.js} +2 -2
- package/dist/components.js +3459 -3146
- package/dist/composables.js +94 -90
- package/dist/{cose-bilkent-S5V4N54A-BXLMzfpO.js → cose-bilkent-S5V4N54A-CzjADqxr.js} +1 -1
- package/dist/{dagre-BM42HDAG-DHnofIh9.js → dagre-BM42HDAG-C79MwQe7.js} +3 -3
- package/dist/{diagram-2AECGRRQ-BqTTVPsm.js → diagram-2AECGRRQ-DaQ7DMBK.js} +2 -2
- package/dist/{diagram-5GNKFQAL-D5p1UVbw.js → diagram-5GNKFQAL-BpWKnfL3.js} +3 -3
- package/dist/{diagram-KO2AKTUF-Uuoz9cFn.js → diagram-KO2AKTUF-CedxET4p.js} +2 -2
- package/dist/{diagram-LMA3HP47-W001U31X.js → diagram-LMA3HP47-FKe9tb0g.js} +2 -2
- package/dist/{diagram-OG6HWLK6-DL516LDr.js → diagram-OG6HWLK6-Bmb8IKvp.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-CCxgMb67.js → erDiagram-TEJ5UH35-Chalz_c9.js} +4 -4
- package/dist/{flowDiagram-I6XJVG4X-nXGdmC0O.js → flowDiagram-I6XJVG4X-DPelWotf.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-Bi9Ro7_Z.js → ganttDiagram-6RSMTGT7-o_Jm8a5l.js} +2 -2
- package/dist/{gitGraphDiagram-PVQCEYII-w1kNAy4E.js → gitGraphDiagram-PVQCEYII-BiwDVfiM.js} +3 -3
- package/dist/{graph-CpOkL_eZ.js → graph-_GsibXVP.js} +1 -1
- package/dist/index-CGb0O6x4.js +2660 -0
- package/dist/index.js +118 -112
- package/dist/{infoDiagram-5YYISTIA-Bde_w9T1.js → infoDiagram-5YYISTIA-CaVHW6oJ.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-x5M1KR0l.js → ishikawaDiagram-YF4QCWOH--qCCMUuo.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-CIDQP8Zm.js → journeyDiagram-JHISSGLW-BsT-p1ex.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-CKgO7sG8.js → kanban-definition-UN3LZRKU-oCTOaobR.js} +2 -2
- package/dist/{layout-BZYprqYR.js → layout-CAhsv4x8.js} +2 -2
- package/dist/{linear-ClSH2F_v.js → linear-CumggsyF.js} +1 -1
- package/dist/{mermaid.core-CcRV6K2R.js → mermaid.core-D4wVfZ2X.js} +34 -34
- package/dist/{mindmap-definition-RKZ34NQL-s3h6uszV.js → mindmap-definition-RKZ34NQL-NTgweVec.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-CgiazyWv.js → pieDiagram-4H26LBE5-C1UJkrIn.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-DCPVgHoW.js → quadrantDiagram-W4KKPZXB-rCJc8QbP.js} +2 -2
- package/dist/record.js +4 -4
- package/dist/{requirementDiagram-4Y6WPE33-DE6F9oSB.js → requirementDiagram-4Y6WPE33-BzHGaPaB.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-DZZoFFr-.js → sankeyDiagram-5OEKKPKP-B--uus9e.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-DaYEOl60.js → sequenceDiagram-3UESZ5HK-D7javnYQ.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-BmgpHJlH.js → stateDiagram-AJRCARHV-DPsstQ8f.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-D49CHQD6.js → stateDiagram-v2-BHNVJYJU-BhhRcq6R.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-DdVLoCkC.js → timeline-definition-PNZ67QCA-DgnJrK74.js} +2 -2
- package/dist/useCodeBlockRendering-f5pBgZ96.js +5083 -0
- package/dist/{vennDiagram-CIIHVFJN-CCcMKcd7.js → vennDiagram-CIIHVFJN-D1Q51ENl.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-R4UGgGWY.js → wardleyDiagram-YWT4CUSO-DMfLoeaa.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-DyFhCubk.js → xychartDiagram-2RQKCTM6-DzF8t-UA.js} +2 -2
- package/package.json +4 -4
- package/src/__tests__/collector-field.test.ts +269 -0
- package/src/__tests__/record-search-render.test.ts +1 -0
- package/src/__tests__/var-field-render.test.ts +64 -2
- package/src/components/AimdCollectorField.vue +233 -0
- package/src/components/AimdEntityRefField.vue +314 -0
- package/src/components/AimdRecorder.vue +109 -2
- package/src/components/AimdRecorderEditor.vue +23 -0
- package/src/components/AimdRecorderWysiwygFieldHost.vue +6 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +31 -0
- package/src/components/AimdVarField.vue +39 -2
- package/src/components/index.ts +4 -0
- package/src/components/recorderMilkdownPlugin.ts +9 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +32 -0
- package/src/composables/index.ts +12 -0
- package/src/composables/useCollectors.ts +399 -0
- package/src/composables/useVarHelpers.ts +130 -2
- package/src/index.ts +20 -2
- package/src/locales.ts +110 -2
- package/src/styles/collector-field.css +281 -0
- package/src/styles/recorder-surface.css +163 -0
- package/src/styles/recorder.css +1 -0
- package/src/types.ts +127 -1
- package/dist/index-Dkrf2LJl.js +0 -1308
- package/dist/useCodeBlockRendering-CCuoP52e.js +0 -6103
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-
|
|
1
|
+
import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-D4wVfZ2X.js";
|
|
2
2
|
const kt = (t, n) => Gt(t, "a", -n), _t = 1e-10;
|
|
3
3
|
function st(t, n) {
|
|
4
4
|
const s = ae(t), e = s.filter((c) => re(c, t));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-
|
|
2
|
-
import { p as Bt } from "./chunk-4BX2VUAB-
|
|
1
|
+
import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-D4wVfZ2X.js";
|
|
2
|
+
import { p as Bt } from "./chunk-4BX2VUAB-CyCffaPa.js";
|
|
3
3
|
import { p as Rt } from "./wardley-L42UT6IY-D7b2ujEZ.js";
|
|
4
4
|
var G = /* @__PURE__ */ u((o, r) => {
|
|
5
5
|
const e = o <= 1 ? o * 100 : o;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-
|
|
1
|
+
import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-D4wVfZ2X.js";
|
|
2
2
|
import { i as _i } from "./init-DjUOC4st.js";
|
|
3
3
|
import { o as ki } from "./ordinal-B6-f3MAq.js";
|
|
4
|
-
import { l as zt } from "./linear-
|
|
4
|
+
import { l as zt } from "./linear-CumggsyF.js";
|
|
5
5
|
function Ri(e, t, i) {
|
|
6
6
|
e = +e, t = +t, i = (n = arguments.length) < 2 ? (t = e, e = 0, 1) : n < 3 ? 1 : +i;
|
|
7
7
|
for (var s = -1, n = Math.max(0, Math.ceil((t - e) / i)) | 0, o = new Array(n); ++s < n; )
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airalogy/aimd-recorder",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"description": "AIMD (Airalogy Markdown) recorder Vue components and UI",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"react": "^19.2.4",
|
|
64
64
|
"react-dom": "^19.2.4",
|
|
65
65
|
"seqviz": "^3.10.18",
|
|
66
|
-
"@airalogy/aimd-core": "^2.
|
|
67
|
-
"@airalogy/aimd-renderer": "^2.
|
|
68
|
-
"@airalogy/aimd-editor": "^1.
|
|
66
|
+
"@airalogy/aimd-core": "^2.14.0",
|
|
67
|
+
"@airalogy/aimd-renderer": "^2.11.0",
|
|
68
|
+
"@airalogy/aimd-editor": "^1.11.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/node": "^24.3.0",
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { flushPromises, mount } from "@vue/test-utils"
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest"
|
|
3
|
+
import AimdRecorder from "../components/AimdRecorder.vue"
|
|
4
|
+
|
|
5
|
+
vi.mock("../components/AimdCodeField.vue", () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
default: {
|
|
8
|
+
name: "AimdCodeField",
|
|
9
|
+
props: ["modelValue", "language", "disabled", "compact"],
|
|
10
|
+
emits: ["update:modelValue", "blur"],
|
|
11
|
+
template: "<textarea />",
|
|
12
|
+
},
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
function protocol(options: {
|
|
16
|
+
mode?: "snapshot" | "polling" | "stream"
|
|
17
|
+
interval?: string
|
|
18
|
+
manualFallback?: boolean
|
|
19
|
+
type?: string
|
|
20
|
+
} = {}): string {
|
|
21
|
+
const mode = options.mode ?? "snapshot"
|
|
22
|
+
const type = options.type ?? (mode === "snapshot" ? "Observation[float] | None" : "list[Observation[float]] | None")
|
|
23
|
+
return `
|
|
24
|
+
\`\`\`connectors
|
|
25
|
+
sensor_gateway:
|
|
26
|
+
kind: data_source
|
|
27
|
+
descriptor: ./sensor.yaml
|
|
28
|
+
\`\`\`
|
|
29
|
+
|
|
30
|
+
\`\`\`collectors
|
|
31
|
+
temperature_sensor:
|
|
32
|
+
connector: sensor_gateway
|
|
33
|
+
channel: room.temperature
|
|
34
|
+
mode: ${mode}
|
|
35
|
+
${mode === "polling" ? ` interval: ${options.interval ?? "10ms"}\n` : ""} manual_fallback: ${options.manualFallback ?? false}
|
|
36
|
+
\`\`\`
|
|
37
|
+
|
|
38
|
+
Temperature: {{var|temperature: ${type}, title="Temperature", unit="Cel", collector="temperature_sensor"}}
|
|
39
|
+
`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function settle(wrapper: ReturnType<typeof mount>): Promise<void> {
|
|
43
|
+
await flushPromises()
|
|
44
|
+
await wrapper.vm.$nextTick()
|
|
45
|
+
await vi.dynamicImportSettled()
|
|
46
|
+
await wrapper.vm.$nextTick()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function latestRecord(wrapper: ReturnType<typeof mount>) {
|
|
50
|
+
const updates = wrapper.emitted("update:modelValue") ?? []
|
|
51
|
+
return updates[updates.length - 1]?.[0] as { var: Record<string, unknown> } | undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe("AimdRecorder Collector fields", () => {
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
vi.useRealTimers()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it("reads a snapshot through an injected provider and stores a normalized Observation", async () => {
|
|
60
|
+
const read = vi.fn().mockResolvedValue({
|
|
61
|
+
value: 23.4,
|
|
62
|
+
observed_at: "2026-07-19T08:00:00+08:00",
|
|
63
|
+
device_id: "thermometer-01",
|
|
64
|
+
quality: "measured",
|
|
65
|
+
})
|
|
66
|
+
const requestCollectorPermission = vi.fn().mockResolvedValue("record")
|
|
67
|
+
const wrapper = mount(AimdRecorder, {
|
|
68
|
+
props: {
|
|
69
|
+
content: protocol(),
|
|
70
|
+
locale: "en-US",
|
|
71
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
72
|
+
collectorProviders: { sensor_gateway: { read } },
|
|
73
|
+
requestCollectorPermission,
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
await settle(wrapper)
|
|
77
|
+
|
|
78
|
+
expect(wrapper.find("textarea[data-rec-focus-key='var:temperature']").exists()).toBe(false)
|
|
79
|
+
const button = wrapper.find(".aimd-rec-collector__button--primary")
|
|
80
|
+
expect(button.text()).toBe("Read now")
|
|
81
|
+
await button.trigger("click")
|
|
82
|
+
await settle(wrapper)
|
|
83
|
+
|
|
84
|
+
expect(read).toHaveBeenCalledTimes(1)
|
|
85
|
+
expect(requestCollectorPermission).toHaveBeenCalledTimes(1)
|
|
86
|
+
const observation = latestRecord(wrapper)?.var.temperature as Record<string, any>
|
|
87
|
+
expect(observation).toMatchObject({
|
|
88
|
+
value: 23.4,
|
|
89
|
+
observed_at: "2026-07-19T00:00:00.000Z",
|
|
90
|
+
unit: "Cel",
|
|
91
|
+
quality: "measured",
|
|
92
|
+
source: {
|
|
93
|
+
kind: "collector",
|
|
94
|
+
connector: "sensor_gateway",
|
|
95
|
+
collector: "temperature_sensor",
|
|
96
|
+
device_id: "thermometer-01",
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
expect(observation.received_at).toMatch(/^\d{4}-\d{2}-\d{2}T/)
|
|
100
|
+
expect(wrapper.text()).toContain("23.4")
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it("polls without overlapping reads and stops through the field control", async () => {
|
|
104
|
+
vi.useFakeTimers()
|
|
105
|
+
let value = 20
|
|
106
|
+
const read = vi.fn(async () => ({ value: value += 1 }))
|
|
107
|
+
const wrapper = mount(AimdRecorder, {
|
|
108
|
+
props: {
|
|
109
|
+
content: protocol({ mode: "polling", interval: "10ms" }),
|
|
110
|
+
locale: "en-US",
|
|
111
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
112
|
+
collectorProviders: { sensor_gateway: { read } },
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
await settle(wrapper)
|
|
116
|
+
|
|
117
|
+
await wrapper.find(".aimd-rec-collector__button--primary").trigger("click")
|
|
118
|
+
await flushPromises()
|
|
119
|
+
await vi.advanceTimersByTimeAsync(25)
|
|
120
|
+
await settle(wrapper)
|
|
121
|
+
|
|
122
|
+
expect(read.mock.calls.length).toBeGreaterThanOrEqual(3)
|
|
123
|
+
const observations = latestRecord(wrapper)?.var.temperature as Array<Record<string, unknown>>
|
|
124
|
+
expect(observations.length).toBe(read.mock.calls.length)
|
|
125
|
+
expect(observations.map(item => item.value)).toEqual(
|
|
126
|
+
Array.from({ length: observations.length }, (_, index) => 21 + index),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const stop = wrapper.findAll("button").find(button => button.text() === "Stop")
|
|
130
|
+
expect(stop).toBeTruthy()
|
|
131
|
+
await stop!.trigger("click")
|
|
132
|
+
await flushPromises()
|
|
133
|
+
const callsAfterStop = read.mock.calls.length
|
|
134
|
+
await vi.advanceTimersByTimeAsync(30)
|
|
135
|
+
expect(read).toHaveBeenCalledTimes(callsAfterStop)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it("records an explicit manual fallback with provenance when no provider is available", async () => {
|
|
139
|
+
const wrapper = mount(AimdRecorder, {
|
|
140
|
+
props: {
|
|
141
|
+
content: protocol({ manualFallback: true }),
|
|
142
|
+
locale: "en-US",
|
|
143
|
+
collectorActorId: "operator-17",
|
|
144
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
await settle(wrapper)
|
|
148
|
+
|
|
149
|
+
expect(wrapper.text()).toContain("This data source is not available")
|
|
150
|
+
const manual = wrapper.findAll("button").find(button => button.text() === "Enter manually")
|
|
151
|
+
expect(manual).toBeTruthy()
|
|
152
|
+
await manual!.trigger("click")
|
|
153
|
+
|
|
154
|
+
await wrapper.find(".aimd-rec-collector__manual-value").setValue("21.75")
|
|
155
|
+
await wrapper.find(".aimd-rec-collector__manual-reason").setValue("Device is being calibrated")
|
|
156
|
+
const save = wrapper.findAll("button").find(button => button.text() === "Save observation")
|
|
157
|
+
await save!.trigger("click")
|
|
158
|
+
await settle(wrapper)
|
|
159
|
+
|
|
160
|
+
expect(latestRecord(wrapper)?.var.temperature).toMatchObject({
|
|
161
|
+
value: 21.75,
|
|
162
|
+
unit: "Cel",
|
|
163
|
+
source: {
|
|
164
|
+
kind: "manual",
|
|
165
|
+
collector: "temperature_sensor",
|
|
166
|
+
actor_id: "operator-17",
|
|
167
|
+
reason: "Device is being calibrated",
|
|
168
|
+
},
|
|
169
|
+
})
|
|
170
|
+
expect((latestRecord(wrapper)?.var.temperature as any).source.connector).toBeUndefined()
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it("does not call the provider when authorization is denied", async () => {
|
|
174
|
+
const read = vi.fn().mockResolvedValue(18)
|
|
175
|
+
const wrapper = mount(AimdRecorder, {
|
|
176
|
+
props: {
|
|
177
|
+
content: protocol(),
|
|
178
|
+
locale: "en-US",
|
|
179
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
180
|
+
collectorProviders: { sensor_gateway: { read } },
|
|
181
|
+
requestCollectorPermission: () => false,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
await settle(wrapper)
|
|
185
|
+
|
|
186
|
+
await wrapper.find(".aimd-rec-collector__button--primary").trigger("click")
|
|
187
|
+
await settle(wrapper)
|
|
188
|
+
|
|
189
|
+
expect(read).not.toHaveBeenCalled()
|
|
190
|
+
expect(wrapper.text()).toContain("Collector access was not authorized")
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it("discards a pending authorization when the protocol context changes", async () => {
|
|
194
|
+
let resolvePermission!: (decision: "record") => void
|
|
195
|
+
const permission = new Promise<"record">((resolve) => {
|
|
196
|
+
resolvePermission = resolve
|
|
197
|
+
})
|
|
198
|
+
const read = vi.fn().mockResolvedValue(18)
|
|
199
|
+
const originalContent = protocol()
|
|
200
|
+
const wrapper = mount(AimdRecorder, {
|
|
201
|
+
props: {
|
|
202
|
+
content: originalContent,
|
|
203
|
+
locale: "en-US",
|
|
204
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
205
|
+
collectorProviders: { sensor_gateway: { read } },
|
|
206
|
+
requestCollectorPermission: () => permission,
|
|
207
|
+
},
|
|
208
|
+
})
|
|
209
|
+
await settle(wrapper)
|
|
210
|
+
|
|
211
|
+
await wrapper.find(".aimd-rec-collector__button--primary").trigger("click")
|
|
212
|
+
await flushPromises()
|
|
213
|
+
expect(wrapper.text()).toContain("Waiting for permission")
|
|
214
|
+
|
|
215
|
+
await wrapper.setProps({ content: `${originalContent}\nChanged.` })
|
|
216
|
+
resolvePermission("record")
|
|
217
|
+
await settle(wrapper)
|
|
218
|
+
|
|
219
|
+
expect(read).not.toHaveBeenCalled()
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it("does not write a snapshot that resolves after the user stops it", async () => {
|
|
223
|
+
let resolveRead!: (value: number) => void
|
|
224
|
+
const readResult = new Promise<number>((resolve) => {
|
|
225
|
+
resolveRead = resolve
|
|
226
|
+
})
|
|
227
|
+
const wrapper = mount(AimdRecorder, {
|
|
228
|
+
props: {
|
|
229
|
+
content: protocol(),
|
|
230
|
+
locale: "en-US",
|
|
231
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
232
|
+
collectorProviders: { sensor_gateway: { read: () => readResult } },
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
await settle(wrapper)
|
|
236
|
+
|
|
237
|
+
await wrapper.find(".aimd-rec-collector__button--primary").trigger("click")
|
|
238
|
+
await flushPromises()
|
|
239
|
+
const stop = wrapper.findAll("button").find(button => button.text() === "Stop")
|
|
240
|
+
expect(stop).toBeTruthy()
|
|
241
|
+
await stop!.trigger("click")
|
|
242
|
+
resolveRead(99)
|
|
243
|
+
await settle(wrapper)
|
|
244
|
+
|
|
245
|
+
expect(latestRecord(wrapper)?.var.temperature).not.toMatchObject({ value: 99 })
|
|
246
|
+
expect(wrapper.text()).toContain("Completed")
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it("uses metadata-only protocol context for WYSIWYG single-field hosts", async () => {
|
|
250
|
+
const full = protocol()
|
|
251
|
+
const context = (full.match(/```(?:connectors|collectors)[\s\S]*?```/g) ?? []).join("\n\n")
|
|
252
|
+
const field = 'Temperature: {{var|temperature: Observation[float] | None, unit="Cel", collector="temperature_sensor"}}'
|
|
253
|
+
const wrapper = mount(AimdRecorder, {
|
|
254
|
+
props: {
|
|
255
|
+
content: field,
|
|
256
|
+
protocolContext: context,
|
|
257
|
+
locale: "en-US",
|
|
258
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
259
|
+
collectorProviders: { sensor_gateway: { read: () => 17.5 } },
|
|
260
|
+
},
|
|
261
|
+
})
|
|
262
|
+
await settle(wrapper)
|
|
263
|
+
|
|
264
|
+
expect(wrapper.find(".aimd-rec-collector").exists()).toBe(true)
|
|
265
|
+
await wrapper.find(".aimd-rec-collector__button--primary").trigger("click")
|
|
266
|
+
await settle(wrapper)
|
|
267
|
+
expect(latestRecord(wrapper)?.var.temperature).toMatchObject({ value: 17.5 })
|
|
268
|
+
})
|
|
269
|
+
})
|
|
@@ -71,6 +71,7 @@ describe('AimdRecorder record search', () => {
|
|
|
71
71
|
|
|
72
72
|
const toggle = wrapper.find('[data-rec-search-toggle]')
|
|
73
73
|
expect(toggle.exists()).toBe(true)
|
|
74
|
+
expect(toggle.text()).toContain('Search current record')
|
|
74
75
|
await toggle.trigger('click')
|
|
75
76
|
await wrapper.vm.$nextTick()
|
|
76
77
|
|
|
@@ -291,9 +291,9 @@ describe('AimdVarField render behavior', () => {
|
|
|
291
291
|
})
|
|
292
292
|
|
|
293
293
|
it('places code assigner actions in the field header instead of a side prefix', () => {
|
|
294
|
-
expect(source).toContain('["file", "code", "scalar-list"].includes(inputKind)')
|
|
294
|
+
expect(source).toContain('["file", "code", "scalar-list", "entity-ref"].includes(inputKind)')
|
|
295
295
|
expect(source).toMatch(/if \(inputKind === "code"\) \{[\s\S]*?"aimd-rec-inline--var-stacked--code",[\s\S]*?\{ controlRow: false \}/)
|
|
296
|
-
expect(recorderSource).toContain('["number", "date", "datetime", "time", "text", "textarea", "scalar-list", "checkbox", "boolean-select", "file", "code"].includes(inputKind)')
|
|
296
|
+
expect(recorderSource).toContain('["number", "date", "datetime", "time", "text", "textarea", "scalar-list", "entity-ref", "checkbox", "boolean-select", "file", "code"].includes(inputKind)')
|
|
297
297
|
})
|
|
298
298
|
|
|
299
299
|
it('renders nullable boolean vars as tri-state select fields', async () => {
|
|
@@ -1041,6 +1041,68 @@ describe('AimdVarField render behavior', () => {
|
|
|
1041
1041
|
expect(latest?.var?.blood_type).toBeNull()
|
|
1042
1042
|
})
|
|
1043
1043
|
|
|
1044
|
+
it('renders EntityRef vars with resolver-backed entity options', async () => {
|
|
1045
|
+
const search = vi.fn(async (query: string) => (
|
|
1046
|
+
query === 'pu'
|
|
1047
|
+
? [{
|
|
1048
|
+
entity: 'plasmid',
|
|
1049
|
+
source: 'lab_plasmid_registry',
|
|
1050
|
+
id: 'pUC19',
|
|
1051
|
+
label: 'pUC19 cloning vector',
|
|
1052
|
+
description: 'Ampicillin resistance',
|
|
1053
|
+
}]
|
|
1054
|
+
: []
|
|
1055
|
+
))
|
|
1056
|
+
const wrapper = mount(AimdRecorder, {
|
|
1057
|
+
props: {
|
|
1058
|
+
content: 'Parent: {{var|parent_plasmid: EntityRef | None, entity = "plasmid", source = "lab_plasmid_registry"}}',
|
|
1059
|
+
locale: 'en-US',
|
|
1060
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
1061
|
+
entityResolvers: {
|
|
1062
|
+
lab_plasmid_registry: { search },
|
|
1063
|
+
},
|
|
1064
|
+
},
|
|
1065
|
+
})
|
|
1066
|
+
|
|
1067
|
+
await flushPromises()
|
|
1068
|
+
await wrapper.vm.$nextTick()
|
|
1069
|
+
await vi.dynamicImportSettled()
|
|
1070
|
+
await wrapper.vm.$nextTick()
|
|
1071
|
+
|
|
1072
|
+
const input = wrapper.find<HTMLInputElement>('input[data-rec-focus-key="var:parent_plasmid"]')
|
|
1073
|
+
expect(input.exists()).toBe(true)
|
|
1074
|
+
expect(input.attributes('placeholder')).toBe('Search plasmid')
|
|
1075
|
+
|
|
1076
|
+
await input.setValue('pu')
|
|
1077
|
+
await flushPromises()
|
|
1078
|
+
await vi.dynamicImportSettled()
|
|
1079
|
+
await wrapper.vm.$nextTick()
|
|
1080
|
+
|
|
1081
|
+
expect(search).toHaveBeenCalledWith('pu', expect.objectContaining({
|
|
1082
|
+
entity: 'plasmid',
|
|
1083
|
+
source: 'lab_plasmid_registry',
|
|
1084
|
+
fieldKey: 'var:parent_plasmid',
|
|
1085
|
+
multiple: false,
|
|
1086
|
+
}))
|
|
1087
|
+
|
|
1088
|
+
const option = wrapper.find('.aimd-rec-entity-ref__option')
|
|
1089
|
+
expect(option.exists()).toBe(true)
|
|
1090
|
+
expect(option.text()).toContain('pUC19 cloning vector')
|
|
1091
|
+
|
|
1092
|
+
await option.trigger('click')
|
|
1093
|
+
await flushPromises()
|
|
1094
|
+
|
|
1095
|
+
const updates = wrapper.emitted('update:modelValue') ?? []
|
|
1096
|
+
const latest = updates[updates.length - 1]?.[0] as { var?: Record<string, unknown> } | undefined
|
|
1097
|
+
expect(latest?.var?.parent_plasmid).toEqual({
|
|
1098
|
+
entity: 'plasmid',
|
|
1099
|
+
source: 'lab_plasmid_registry',
|
|
1100
|
+
id: 'pUC19',
|
|
1101
|
+
label: 'pUC19 cloning vector',
|
|
1102
|
+
description: 'Ampicillin resistance',
|
|
1103
|
+
})
|
|
1104
|
+
})
|
|
1105
|
+
|
|
1044
1106
|
it('renders scalar list vars as repeatable inputs in AimdRecorder', async () => {
|
|
1045
1107
|
const wrapper = mount(AimdRecorder, {
|
|
1046
1108
|
props: {
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from "vue"
|
|
3
|
+
import { getAimdFieldDisplayLabel } from "@airalogy/aimd-core/utils"
|
|
4
|
+
import type { AimdVarNode } from "@airalogy/aimd-core/types"
|
|
5
|
+
import type { AimdRecorderMessages } from "../locales"
|
|
6
|
+
import { getAimdRecorderScopeLabel } from "../locales"
|
|
7
|
+
import type {
|
|
8
|
+
AimdCollectorObservation,
|
|
9
|
+
AimdCollectorRuntimeState,
|
|
10
|
+
AimdFieldMeta,
|
|
11
|
+
} from "../types"
|
|
12
|
+
import type { AimdCollectorBinding } from "../composables/useCollectors"
|
|
13
|
+
import {
|
|
14
|
+
getAimdCollectorManualValueType,
|
|
15
|
+
parseAimdCollectorManualValue,
|
|
16
|
+
} from "../composables/useCollectors"
|
|
17
|
+
|
|
18
|
+
const props = defineProps<{
|
|
19
|
+
node: AimdVarNode
|
|
20
|
+
binding: AimdCollectorBinding
|
|
21
|
+
value?: unknown
|
|
22
|
+
state: AimdCollectorRuntimeState
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
providerAvailable: boolean
|
|
25
|
+
messages: AimdRecorderMessages
|
|
26
|
+
fieldMeta?: AimdFieldMeta
|
|
27
|
+
extraClasses?: string[]
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
(event: "start"): void
|
|
32
|
+
(event: "stop"): void
|
|
33
|
+
(event: "manual", payload: { value: unknown; reason: string }): void
|
|
34
|
+
(event: "blur"): void
|
|
35
|
+
}>()
|
|
36
|
+
|
|
37
|
+
const showManual = ref(false)
|
|
38
|
+
const manualValue = ref("")
|
|
39
|
+
const manualReason = ref("")
|
|
40
|
+
const manualError = ref("")
|
|
41
|
+
|
|
42
|
+
const type = computed(() => props.node.definition?.type || "Observation[str]")
|
|
43
|
+
const manualValueType = computed(() => getAimdCollectorManualValueType(type.value))
|
|
44
|
+
const title = computed(() => props.fieldMeta?.title || getAimdFieldDisplayLabel(props.node.id, props.node.definition))
|
|
45
|
+
const isBusy = computed(() => ["waiting_for_permission", "connecting", "collecting", "stopping"].includes(props.state.status))
|
|
46
|
+
const canStart = computed(() => (
|
|
47
|
+
!props.disabled
|
|
48
|
+
&& props.providerAvailable
|
|
49
|
+
&& !isBusy.value
|
|
50
|
+
&& props.state.status !== "unsupported"
|
|
51
|
+
&& !props.binding.isSeries
|
|
52
|
+
&& props.binding.collector.mode !== "stream"
|
|
53
|
+
))
|
|
54
|
+
const canStop = computed(() => !props.disabled && ["connecting", "collecting"].includes(props.state.status))
|
|
55
|
+
|
|
56
|
+
const observations = computed<AimdCollectorObservation[]>(() => {
|
|
57
|
+
const values = Array.isArray(props.value) ? props.value : [props.value]
|
|
58
|
+
return values.filter((value): value is AimdCollectorObservation => Boolean(
|
|
59
|
+
value
|
|
60
|
+
&& typeof value === "object"
|
|
61
|
+
&& !Array.isArray(value)
|
|
62
|
+
&& Object.prototype.hasOwnProperty.call(value, "value"),
|
|
63
|
+
))
|
|
64
|
+
})
|
|
65
|
+
const latestObservation = computed(() => observations.value[observations.value.length - 1])
|
|
66
|
+
const displayedValue = computed(() => formatValue(latestObservation.value?.value))
|
|
67
|
+
const displayedUnit = computed(() => latestObservation.value?.unit || String(props.node.definition?.kwargs?.unit ?? ""))
|
|
68
|
+
const displayedObservedAt = computed(() => {
|
|
69
|
+
const value = latestObservation.value?.observed_at || props.state.lastObservedAt
|
|
70
|
+
if (!value) return ""
|
|
71
|
+
const date = new Date(value)
|
|
72
|
+
return Number.isNaN(date.getTime()) ? value : date.toLocaleString()
|
|
73
|
+
})
|
|
74
|
+
const issueMessage = computed(() => {
|
|
75
|
+
if (!props.providerAvailable) return props.messages.collector.providerUnavailable
|
|
76
|
+
if (props.state.status === "unsupported") return props.messages.collector.unsupported
|
|
77
|
+
if (props.state.error === "provider_unavailable") return props.messages.collector.providerUnavailable
|
|
78
|
+
if (props.state.error === "permission_denied") return props.messages.collector.permissionDenied
|
|
79
|
+
return props.state.error || ""
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
watch(
|
|
83
|
+
() => props.disabled,
|
|
84
|
+
disabled => {
|
|
85
|
+
if (disabled) showManual.value = false
|
|
86
|
+
},
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
function formatValue(value: unknown): string {
|
|
90
|
+
if (value === undefined || value === null) return ""
|
|
91
|
+
if (typeof value === "string") return value
|
|
92
|
+
if (["number", "boolean", "bigint"].includes(typeof value)) return String(value)
|
|
93
|
+
try {
|
|
94
|
+
return JSON.stringify(value)
|
|
95
|
+
} catch {
|
|
96
|
+
return String(value)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function start(): void {
|
|
101
|
+
manualError.value = ""
|
|
102
|
+
emit("start")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function toggleManual(): void {
|
|
106
|
+
showManual.value = !showManual.value
|
|
107
|
+
manualError.value = ""
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function submitManual(): void {
|
|
111
|
+
if (!manualReason.value.trim()) {
|
|
112
|
+
manualError.value = props.messages.collector.reasonRequired
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
const parsed = parseAimdCollectorManualValue(type.value, manualValue.value)
|
|
116
|
+
if (!parsed.ok) {
|
|
117
|
+
manualError.value = props.messages.collector.invalidValue
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
emit("manual", { value: parsed.value, reason: manualReason.value.trim() })
|
|
121
|
+
manualValue.value = ""
|
|
122
|
+
manualReason.value = ""
|
|
123
|
+
manualError.value = ""
|
|
124
|
+
showManual.value = false
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<template>
|
|
129
|
+
<span
|
|
130
|
+
class="aimd-rec-collector aimd-field-wrapper aimd-field-wrapper--inline"
|
|
131
|
+
:class="[
|
|
132
|
+
`aimd-rec-collector--${state.status}`,
|
|
133
|
+
...(extraClasses ?? []),
|
|
134
|
+
]"
|
|
135
|
+
:data-rec-collector="binding.collector.id"
|
|
136
|
+
>
|
|
137
|
+
<span class="aimd-rec-collector__header">
|
|
138
|
+
<span class="aimd-field__scope aimd-field__scope--var">{{ getAimdRecorderScopeLabel("var", messages) }}</span>
|
|
139
|
+
<span class="aimd-rec-collector__identity">
|
|
140
|
+
<span class="aimd-rec-collector__title">{{ title }}</span>
|
|
141
|
+
<span v-if="title !== node.id" class="aimd-rec-collector__key">{{ node.id }}</span>
|
|
142
|
+
</span>
|
|
143
|
+
<span class="aimd-rec-collector__source" :title="binding.connector.id">
|
|
144
|
+
{{ binding.collector.title || binding.collector.id }}
|
|
145
|
+
</span>
|
|
146
|
+
<span class="aimd-rec-collector__status" :class="`aimd-rec-collector__status--${state.status}`">
|
|
147
|
+
<span class="aimd-rec-collector__status-dot" aria-hidden="true" />
|
|
148
|
+
{{ messages.collector.status[state.status] }}
|
|
149
|
+
</span>
|
|
150
|
+
</span>
|
|
151
|
+
|
|
152
|
+
<span class="aimd-rec-collector__body">
|
|
153
|
+
<span class="aimd-rec-collector__reading">
|
|
154
|
+
<span v-if="displayedValue" class="aimd-rec-collector__value" :title="displayedValue">{{ displayedValue }}</span>
|
|
155
|
+
<span v-else class="aimd-rec-collector__empty">{{ messages.common.emptyValue }}</span>
|
|
156
|
+
<span v-if="displayedUnit" class="aimd-rec-collector__unit">{{ displayedUnit }}</span>
|
|
157
|
+
</span>
|
|
158
|
+
|
|
159
|
+
<span class="aimd-rec-collector__meta">
|
|
160
|
+
<span v-if="binding.isList">{{ messages.collector.sampleCount(observations.length) }}</span>
|
|
161
|
+
<span v-if="displayedObservedAt">{{ messages.collector.lastObserved(displayedObservedAt) }}</span>
|
|
162
|
+
</span>
|
|
163
|
+
|
|
164
|
+
<span class="aimd-rec-collector__actions">
|
|
165
|
+
<button
|
|
166
|
+
v-if="canStop"
|
|
167
|
+
type="button"
|
|
168
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--danger"
|
|
169
|
+
:disabled="disabled"
|
|
170
|
+
@click="emit('stop')"
|
|
171
|
+
>
|
|
172
|
+
{{ messages.collector.stop }}
|
|
173
|
+
</button>
|
|
174
|
+
<button
|
|
175
|
+
v-else
|
|
176
|
+
type="button"
|
|
177
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--primary"
|
|
178
|
+
:disabled="!canStart"
|
|
179
|
+
@click="start"
|
|
180
|
+
>
|
|
181
|
+
{{ state.status === "error"
|
|
182
|
+
? messages.collector.retry
|
|
183
|
+
: binding.collector.mode === "snapshot"
|
|
184
|
+
? messages.collector.snapshot
|
|
185
|
+
: messages.collector.start }}
|
|
186
|
+
</button>
|
|
187
|
+
<button
|
|
188
|
+
v-if="binding.collector.manual_fallback"
|
|
189
|
+
type="button"
|
|
190
|
+
class="aimd-rec-collector__button"
|
|
191
|
+
:disabled="disabled || isBusy"
|
|
192
|
+
:aria-expanded="showManual"
|
|
193
|
+
@click="toggleManual"
|
|
194
|
+
>
|
|
195
|
+
{{ showManual ? messages.collector.cancelManual : messages.collector.manualEntry }}
|
|
196
|
+
</button>
|
|
197
|
+
</span>
|
|
198
|
+
</span>
|
|
199
|
+
|
|
200
|
+
<span v-if="issueMessage" class="aimd-rec-collector__message" role="status">{{ issueMessage }}</span>
|
|
201
|
+
|
|
202
|
+
<span v-if="showManual" class="aimd-rec-collector__manual">
|
|
203
|
+
<textarea
|
|
204
|
+
v-model="manualValue"
|
|
205
|
+
:data-rec-focus-key="`var:${node.id}`"
|
|
206
|
+
class="aimd-rec-collector__manual-value"
|
|
207
|
+
rows="1"
|
|
208
|
+
:placeholder="`${messages.collector.valuePlaceholder} (${manualValueType})`"
|
|
209
|
+
:disabled="disabled"
|
|
210
|
+
@blur="emit('blur')"
|
|
211
|
+
/>
|
|
212
|
+
<input
|
|
213
|
+
v-model="manualReason"
|
|
214
|
+
class="aimd-rec-collector__manual-reason"
|
|
215
|
+
type="text"
|
|
216
|
+
:placeholder="messages.collector.reasonPlaceholder"
|
|
217
|
+
:disabled="disabled"
|
|
218
|
+
@blur="emit('blur')"
|
|
219
|
+
>
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
class="aimd-rec-collector__button aimd-rec-collector__button--primary"
|
|
223
|
+
:disabled="disabled"
|
|
224
|
+
@click="submitManual"
|
|
225
|
+
>
|
|
226
|
+
{{ messages.collector.saveManual }}
|
|
227
|
+
</button>
|
|
228
|
+
<span v-if="manualError" class="aimd-rec-collector__message aimd-rec-collector__message--error" role="alert">
|
|
229
|
+
{{ manualError }}
|
|
230
|
+
</span>
|
|
231
|
+
</span>
|
|
232
|
+
</span>
|
|
233
|
+
</template>
|