@airalogy/aimd-recorder 1.17.0 → 1.19.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 +42 -10
- package/README.zh-CN.md +42 -10
- package/dist/AimdCodeField-BQUuM-EF.js +182 -0
- package/dist/{AimdDnaSequenceField-D6ZgCDpp.js → AimdDnaSequenceField-TBKunqU_.js} +2 -2
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-B5Tq4zPV.js → AimdEditor.vue_vue_type_style_index_0_lang-tdh0dJNa.js} +3922 -3829
- package/dist/AimdMarkdownField-DmNX2g4j.js +254 -0
- package/dist/AimdMarkdownNoteField-B5ruzmwS.js +259 -0
- package/dist/{_commonjsHelpers-CZXJ37nu.js → _commonjsHelpers-B5RozER-.js} +2 -2
- package/dist/aimd-recorder.css +1 -1
- package/dist/arc-B-vsgEXF.js +83 -0
- package/dist/architectureDiagram-3BPJPVTR-BwPNOtNH.js +4692 -0
- package/dist/blockDiagram-GPEHLZMM-CMUI4kKc.js +2425 -0
- package/dist/c4Diagram-AAUBKEIU-Cpmfsy_s.js +1577 -0
- package/dist/channel-DlMAXHQK.js +5 -0
- package/dist/chunk-2J33WTMH-DP9BS2ux.js +19 -0
- package/dist/chunk-4BX2VUAB-ncsOeLMb.js +8 -0
- package/dist/chunk-55IACEB6-C7wHk4B7.js +8 -0
- package/dist/chunk-727SXJPM-Caa5aVUO.js +1528 -0
- package/dist/chunk-AQP2D5EJ-CL8egKqD.js +1387 -0
- package/dist/chunk-FMBD7UC4-heVR6BSA.js +19 -0
- package/dist/chunk-ND2GUHAM-BYH-wC2J.js +68 -0
- package/dist/chunk-QZHKN3VN-Bx2K7vkq.js +15 -0
- package/dist/classDiagram-4FO5ZUOK-BLLfLYy0.js +16 -0
- package/dist/classDiagram-v2-Q7XG4LA2-BLLfLYy0.js +16 -0
- package/dist/components.js +3776 -2247
- package/dist/composables.js +96 -70
- package/dist/cose-bilkent-S5V4N54A-E1YmM_xr.js +2609 -0
- package/dist/cytoscape.esm-r59gEWFs.js +18710 -0
- package/dist/dagre-BM42HDAG-BsXpQirH.js +445 -0
- package/dist/defaultLocale-BgPVtth8.js +171 -0
- package/dist/diagram-2AECGRRQ-CamqbWlY.js +217 -0
- package/dist/diagram-5GNKFQAL-DZyRFcOC.js +123 -0
- package/dist/diagram-KO2AKTUF-CmkGcy7R.js +461 -0
- package/dist/diagram-LMA3HP47-IdDwQPZ-.js +142 -0
- package/dist/diagram-OG6HWLK6-t0LBcUIU.js +528 -0
- package/dist/erDiagram-TEJ5UH35-DJBY2iZG.js +899 -0
- package/dist/flowDiagram-I6XJVG4X-DE4MzPPk.js +1628 -0
- package/dist/ganttDiagram-6RSMTGT7-CmAc35Yw.js +2707 -0
- package/dist/gitGraphDiagram-PVQCEYII-DDQZ5flw.js +815 -0
- package/dist/graph-BsJ8-1Pq.js +1510 -0
- package/dist/index.js +110 -83
- package/dist/infoDiagram-5YYISTIA-DSZjFR5g.js +24 -0
- package/dist/init-DjUOC4st.js +16 -0
- package/dist/ishikawaDiagram-YF4QCWOH-DCO9dx2L.js +621 -0
- package/dist/journeyDiagram-JHISSGLW-b-PpuBqg.js +834 -0
- package/dist/kanban-definition-UN3LZRKU-BjclDuJZ.js +724 -0
- package/dist/katex-DNob3HGn.js +11690 -0
- package/dist/layout-D4wqKu72.js +1703 -0
- package/dist/linear-Voc3BJib.js +259 -0
- package/dist/mermaid.core-Dt_VbeGP.js +15940 -0
- package/dist/mindmap-definition-RKZ34NQL-B3vrXRVY.js +827 -0
- package/dist/ordinal-B6-f3MAq.js +61 -0
- package/dist/pieDiagram-4H26LBE5-DFpWxSxk.js +163 -0
- package/dist/quadrantDiagram-W4KKPZXB-BYHcrGoB.js +1024 -0
- package/dist/record.js +1199 -0
- package/dist/requirementDiagram-4Y6WPE33-C-FgWrRz.js +882 -0
- package/dist/sankeyDiagram-5OEKKPKP-IwN0Evji.js +847 -0
- package/dist/sequenceDiagram-3UESZ5HK-_OnqhBO2.js +2891 -0
- package/dist/stateDiagram-AJRCARHV-BRLv0Zcw.js +263 -0
- package/dist/stateDiagram-v2-BHNVJYJU-BofX0AdS.js +16 -0
- package/dist/timeline-definition-PNZ67QCA-C-DpPLpw.js +1055 -0
- package/dist/{useFieldRendering-xLajJhyA.js → useCodeBlockRendering-DoTZaJTW.js} +1528 -1725
- package/dist/useMonacoAutoHeight-D4T-El3J.js +66 -0
- package/dist/vennDiagram-CIIHVFJN-zTHQR9Oq.js +1557 -0
- package/dist/wardley-L42UT6IY-D7b2ujEZ.js +22512 -0
- package/dist/wardleyDiagram-YWT4CUSO-au5koizO.js +675 -0
- package/dist/xychartDiagram-2RQKCTM6-BNf12P8z.js +1342 -0
- package/package.json +13 -8
- package/src/__tests__/assigner-graph.test.ts +82 -0
- package/src/__tests__/assigner-runner-dependent-data.test.ts +32 -0
- package/src/__tests__/markdown-field.test.ts +150 -1
- package/src/__tests__/markdown-note-field.test.ts +86 -3
- package/src/__tests__/recorder-assigner-control.test.ts +993 -0
- package/src/__tests__/recorder-editor.test.ts +17 -0
- package/src/__tests__/recorder-markdown-assigner-integration.test.ts +49 -0
- package/src/__tests__/step-field.test.ts +47 -1
- package/src/__tests__/type-plugins.test.ts +1 -0
- package/src/__tests__/var-field-render.test.ts +806 -1
- package/src/components/AimdAssignerGraph.vue +816 -0
- package/src/components/AimdCodeField.vue +24 -5
- package/src/components/AimdMarkdownField.vue +556 -11
- package/src/components/AimdMarkdownNoteField.vue +241 -30
- package/src/components/AimdRecorder.vue +1619 -99
- package/src/components/AimdRecorderEditor.vue +276 -8
- package/src/components/AimdRecorderWysiwygFieldHost.vue +6 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +32 -0
- package/src/components/AimdStepCheckField.vue +82 -18
- package/src/components/AimdVarField.vue +694 -25
- package/src/components/AimdVarTableField.vue +325 -138
- package/src/components/icons/AimdAssignerCalculatorIcon.vue +18 -0
- package/src/components/icons/AimdAssignerCloudStatusIcon.vue +22 -0
- package/src/components/index.ts +9 -1
- package/src/components/recorderMilkdownPlugin.ts +14 -0
- package/src/composables/__tests__/useRecordState.test.ts +86 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +175 -0
- package/src/composables/index.ts +28 -1
- package/src/composables/useAssignerRunner.ts +376 -0
- package/src/composables/useCodeBlockRendering.ts +51 -0
- package/src/composables/useFieldRendering.ts +32 -4
- package/src/composables/useMonacoAutoHeight.ts +127 -0
- package/src/composables/useRecordState.ts +22 -3
- package/src/composables/useVarHelpers.ts +237 -32
- package/src/index.ts +20 -1
- package/src/locales.ts +45 -0
- package/src/record/index.ts +120 -0
- package/src/styles/aimd.css +216 -1
- package/src/type-plugins.ts +7 -0
- package/src/type-utils.ts +1 -3
- package/src/types.ts +130 -2
- package/dist/AimdCodeField-DC3DPvgc.js +0 -172
- package/dist/AimdMarkdownField-BJ20QtO8.js +0 -67
- package/dist/AimdMarkdownNoteField-DwAQhoyk.js +0 -186
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
|
|
2
|
+
import type {
|
|
3
|
+
AimdAssignerDefinition,
|
|
4
|
+
AimdAssignerMap,
|
|
5
|
+
AimdAssignerMode,
|
|
6
|
+
AimdProtocolRecordData,
|
|
7
|
+
AimdRecorderFieldType,
|
|
8
|
+
} from "../types"
|
|
9
|
+
import {
|
|
10
|
+
normalizeCheckLike,
|
|
11
|
+
normalizeStepLike,
|
|
12
|
+
} from "./useRecordState"
|
|
13
|
+
import { getFileValueId, isAiralogyFileId } from "./useVarHelpers"
|
|
14
|
+
|
|
15
|
+
export interface AimdResolvedAssigner {
|
|
16
|
+
assignedField: string
|
|
17
|
+
fieldKey: string
|
|
18
|
+
mode: string
|
|
19
|
+
dependentFields: string[]
|
|
20
|
+
assigner: AimdAssignerDefinition
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type AssignableRecorderFieldType = Exclude<AimdRecorderFieldType, "quiz">
|
|
24
|
+
|
|
25
|
+
interface AssignerFieldNameSets {
|
|
26
|
+
var?: ReadonlySet<string>
|
|
27
|
+
varTable?: ReadonlySet<string>
|
|
28
|
+
step?: ReadonlySet<string>
|
|
29
|
+
check?: ReadonlySet<string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
33
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isEmptyObjectRecord(value: unknown): boolean {
|
|
37
|
+
return isObjectRecord(value) && Object.keys(value).length === 0
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getStringProperty(record: Record<string, unknown>, keys: string[]): string | undefined {
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
const value = record[key]
|
|
43
|
+
if (typeof value === "string" && value.trim()) {
|
|
44
|
+
return value.trim()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getNestedErrorMessage(value: unknown): string | undefined {
|
|
51
|
+
if (typeof value === "string" && value.trim()) {
|
|
52
|
+
return value.trim()
|
|
53
|
+
}
|
|
54
|
+
if (!isObjectRecord(value)) {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
return getStringProperty(value, [
|
|
58
|
+
"error_message",
|
|
59
|
+
"errorMessage",
|
|
60
|
+
"message",
|
|
61
|
+
"detail",
|
|
62
|
+
"reason",
|
|
63
|
+
])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function collectAssignerResultCandidates(result: unknown): unknown[] {
|
|
67
|
+
const candidates: unknown[] = [result]
|
|
68
|
+
const appendNested = (value: unknown) => {
|
|
69
|
+
if (!isObjectRecord(value)) return
|
|
70
|
+
candidates.push(value.data)
|
|
71
|
+
candidates.push(value.result)
|
|
72
|
+
if (isObjectRecord(value.data)) {
|
|
73
|
+
candidates.push(value.data.result)
|
|
74
|
+
}
|
|
75
|
+
if (isObjectRecord(value.result)) {
|
|
76
|
+
candidates.push(value.result.data)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
appendNested(result)
|
|
81
|
+
if (isObjectRecord(result)) {
|
|
82
|
+
appendNested(result.data)
|
|
83
|
+
appendNested(result.result)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return candidates
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parsedFieldName(value: unknown): string {
|
|
90
|
+
if (typeof value === "string" && value.trim()) return value.trim()
|
|
91
|
+
if (!isObjectRecord(value)) return ""
|
|
92
|
+
|
|
93
|
+
const name = value.name ?? value.id
|
|
94
|
+
return typeof name === "string" && name.trim() ? name.trim() : ""
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function extractedFieldNameSet(value: unknown): Set<string> {
|
|
98
|
+
if (!Array.isArray(value)) return new Set<string>()
|
|
99
|
+
return new Set(value.map(parsedFieldName).filter(Boolean))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getAimdAssignerDependentFields(assigner: unknown): string[] {
|
|
103
|
+
if (!isObjectRecord(assigner)) return []
|
|
104
|
+
const fields = assigner.dependent_fields
|
|
105
|
+
if (!Array.isArray(fields)) return []
|
|
106
|
+
return fields
|
|
107
|
+
.map(field => (typeof field === "string" ? field.trim() : ""))
|
|
108
|
+
.filter(Boolean)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getAimdAssignerAssignedFields(assigner: unknown): string[] {
|
|
112
|
+
if (!isObjectRecord(assigner)) return []
|
|
113
|
+
const fields = Array.isArray(assigner.assigned_fields)
|
|
114
|
+
? assigner.assigned_fields
|
|
115
|
+
: Array.isArray(assigner.assignedFields)
|
|
116
|
+
? assigner.assignedFields
|
|
117
|
+
: []
|
|
118
|
+
return fields
|
|
119
|
+
.map(field => (typeof field === "string" ? field.trim() : ""))
|
|
120
|
+
.filter(Boolean)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getAimdAssignerMode(assigner: unknown): string {
|
|
124
|
+
if (!isObjectRecord(assigner)) return "manual"
|
|
125
|
+
const mode = assigner.mode
|
|
126
|
+
return typeof mode === "string" && mode.trim() ? mode.trim() : "manual"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function normalizeAimdAssignerMode(mode: string): AimdAssignerMode {
|
|
130
|
+
if (
|
|
131
|
+
mode === "auto"
|
|
132
|
+
|| mode === "auto_first"
|
|
133
|
+
|| mode === "auto_force"
|
|
134
|
+
|| mode === "manual"
|
|
135
|
+
|| mode === "manual_readonly"
|
|
136
|
+
|| mode === "auto_readonly"
|
|
137
|
+
) {
|
|
138
|
+
return mode
|
|
139
|
+
}
|
|
140
|
+
return "manual"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isReadonlyAimdAssignerMode(mode: string): boolean {
|
|
144
|
+
return mode === "auto_readonly" || mode === "manual_readonly"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function getAimdAssignerFieldNameSets(fields?: Partial<ExtractedAimdFields> | null): AssignerFieldNameSets {
|
|
148
|
+
return {
|
|
149
|
+
var: extractedFieldNameSet(fields?.var),
|
|
150
|
+
varTable: extractedFieldNameSet(fields?.var_table),
|
|
151
|
+
step: extractedFieldNameSet(fields?.step),
|
|
152
|
+
check: extractedFieldNameSet(fields?.check),
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function getAimdAssignerFieldKey(
|
|
157
|
+
assignedField: string,
|
|
158
|
+
fieldNameSets: AssignerFieldNameSets = {},
|
|
159
|
+
): string {
|
|
160
|
+
const normalized = assignedField.trim()
|
|
161
|
+
if (normalized.includes(".")) {
|
|
162
|
+
const [tableName, ...columnParts] = normalized.split(".")
|
|
163
|
+
return `var_table:${tableName}:${columnParts.join(".")}`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (fieldNameSets.varTable?.has(normalized)) return `var_table:${normalized}`
|
|
167
|
+
if (fieldNameSets.step?.has(normalized)) return `step:${normalized}`
|
|
168
|
+
if (fieldNameSets.check?.has(normalized)) return `check:${normalized}`
|
|
169
|
+
return `var:${normalized}`
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function resolveAimdAssigners(
|
|
173
|
+
assigners: AimdAssignerMap | undefined,
|
|
174
|
+
fields?: Partial<ExtractedAimdFields> | null,
|
|
175
|
+
): AimdResolvedAssigner[] {
|
|
176
|
+
if (!assigners || typeof assigners !== "object" || Array.isArray(assigners)) {
|
|
177
|
+
return []
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const fieldNameSets = getAimdAssignerFieldNameSets(fields)
|
|
181
|
+
return Object.entries(assigners)
|
|
182
|
+
.flatMap(([assignedField, assigner]) => {
|
|
183
|
+
const normalizedEntryField = assignedField.trim()
|
|
184
|
+
if (!normalizedEntryField) return []
|
|
185
|
+
const definition = isObjectRecord(assigner) ? assigner : {}
|
|
186
|
+
const mode = getAimdAssignerMode(definition)
|
|
187
|
+
const dependentFields = getAimdAssignerDependentFields(definition)
|
|
188
|
+
const assignedFields = new Set([
|
|
189
|
+
normalizedEntryField,
|
|
190
|
+
...getAimdAssignerAssignedFields(definition),
|
|
191
|
+
])
|
|
192
|
+
return [...assignedFields].map((normalizedAssignedField) => ({
|
|
193
|
+
assignedField: normalizedAssignedField,
|
|
194
|
+
fieldKey: getAimdAssignerFieldKey(normalizedAssignedField, fieldNameSets),
|
|
195
|
+
mode,
|
|
196
|
+
dependentFields,
|
|
197
|
+
assigner: definition,
|
|
198
|
+
} satisfies AimdResolvedAssigner))
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function normalizeAimdAssignerDependentValue(value: unknown): unknown {
|
|
203
|
+
if (value === "") return undefined
|
|
204
|
+
|
|
205
|
+
if (Array.isArray(value)) {
|
|
206
|
+
const normalizedItems = value
|
|
207
|
+
.map(item => normalizeAimdAssignerDependentValue(item))
|
|
208
|
+
.filter(item => item !== undefined && !isEmptyObjectRecord(item))
|
|
209
|
+
return normalizedItems
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (isObjectRecord(value)) {
|
|
213
|
+
const fileId = getFileValueId(value)
|
|
214
|
+
if (isAiralogyFileId(fileId)) {
|
|
215
|
+
return fileId
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const normalizedObject = Object.fromEntries(
|
|
219
|
+
Object.entries(value)
|
|
220
|
+
.map(([key, item]) => [key, normalizeAimdAssignerDependentValue(item)] as const)
|
|
221
|
+
.filter(([, item]) => item !== undefined),
|
|
222
|
+
)
|
|
223
|
+
return normalizedObject
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return value
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function normalizeAimdAssignerDependentData(value: unknown): Record<string, unknown> {
|
|
230
|
+
const normalized = normalizeAimdAssignerDependentValue(value)
|
|
231
|
+
return isObjectRecord(normalized) ? normalized : {}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function readRecordFieldValue(record: AimdProtocolRecordData, field: string): unknown {
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(record.var, field)) return record.var[field]
|
|
236
|
+
if (Object.prototype.hasOwnProperty.call(record.step, field)) return record.step[field]
|
|
237
|
+
if (Object.prototype.hasOwnProperty.call(record.check, field)) return record.check[field]
|
|
238
|
+
if (Object.prototype.hasOwnProperty.call(record.quiz, field)) return record.quiz[field]
|
|
239
|
+
|
|
240
|
+
if (field.includes(".")) {
|
|
241
|
+
const [tableName, ...columnParts] = field.split(".")
|
|
242
|
+
const columnName = columnParts.join(".")
|
|
243
|
+
const tableValue = record.var[tableName]
|
|
244
|
+
if (Array.isArray(tableValue) && columnName) {
|
|
245
|
+
return tableValue.map((row) => (isObjectRecord(row) ? row[columnName] : undefined))
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return undefined
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function buildAimdAssignerDependentData(
|
|
253
|
+
record: AimdProtocolRecordData,
|
|
254
|
+
assigner: Pick<AimdResolvedAssigner, "dependentFields"> | AimdAssignerDefinition | unknown,
|
|
255
|
+
): Record<string, unknown> {
|
|
256
|
+
const dependentFields = Array.isArray((assigner as { dependentFields?: unknown } | null)?.dependentFields)
|
|
257
|
+
? (assigner as { dependentFields: string[] }).dependentFields
|
|
258
|
+
: getAimdAssignerDependentFields(assigner)
|
|
259
|
+
|
|
260
|
+
if (dependentFields.length === 0) {
|
|
261
|
+
return normalizeAimdAssignerDependentData(record.var)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return Object.fromEntries(
|
|
265
|
+
dependentFields
|
|
266
|
+
.map((field) => [field, normalizeAimdAssignerDependentValue(readRecordFieldValue(record, field))] as const)
|
|
267
|
+
.filter(([, value]) => value !== undefined),
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function extractAimdAssignedFields(result: unknown): Record<string, unknown> {
|
|
272
|
+
const candidates = collectAssignerResultCandidates(result)
|
|
273
|
+
|
|
274
|
+
for (const candidate of candidates) {
|
|
275
|
+
if (!isObjectRecord(candidate)) continue
|
|
276
|
+
const snakeCase = candidate.assigned_fields
|
|
277
|
+
if (isObjectRecord(snakeCase)) return snakeCase
|
|
278
|
+
const camelCase = candidate.assignedFields
|
|
279
|
+
if (isObjectRecord(camelCase)) return camelCase
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function extractAimdAssignerErrorMessage(result: unknown): string | undefined {
|
|
286
|
+
const candidates = collectAssignerResultCandidates(result)
|
|
287
|
+
|
|
288
|
+
for (const candidate of candidates) {
|
|
289
|
+
if (!isObjectRecord(candidate)) continue
|
|
290
|
+
|
|
291
|
+
const success = candidate.success
|
|
292
|
+
const status = candidate.status
|
|
293
|
+
const failed = success === false
|
|
294
|
+
|| success === "false"
|
|
295
|
+
|| status === "error"
|
|
296
|
+
|| status === "failed"
|
|
297
|
+
|
|
298
|
+
if (!failed) {
|
|
299
|
+
continue
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return getStringProperty(candidate, [
|
|
303
|
+
"error_message",
|
|
304
|
+
"errorMessage",
|
|
305
|
+
"message",
|
|
306
|
+
"detail",
|
|
307
|
+
"reason",
|
|
308
|
+
"output",
|
|
309
|
+
])
|
|
310
|
+
?? getNestedErrorMessage(candidate.error)
|
|
311
|
+
?? getNestedErrorMessage(candidate.exception)
|
|
312
|
+
?? "Assigner failed"
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return undefined
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function applyAimdAssignedFieldsToRecord(
|
|
319
|
+
record: AimdProtocolRecordData,
|
|
320
|
+
assignedFields: Record<string, unknown>,
|
|
321
|
+
): boolean {
|
|
322
|
+
let changed = false
|
|
323
|
+
|
|
324
|
+
for (const [field, value] of Object.entries(assignedFields)) {
|
|
325
|
+
const normalizedField = field.trim()
|
|
326
|
+
if (!normalizedField) continue
|
|
327
|
+
|
|
328
|
+
if (normalizedField.includes(".")) {
|
|
329
|
+
const [tableName, ...columnParts] = normalizedField.split(".")
|
|
330
|
+
const columnName = columnParts.join(".")
|
|
331
|
+
const tableValue = record.var[tableName]
|
|
332
|
+
if (Array.isArray(tableValue) && columnName) {
|
|
333
|
+
if (Array.isArray(value)) {
|
|
334
|
+
tableValue.forEach((row, index) => {
|
|
335
|
+
if (isObjectRecord(row) && index < value.length) {
|
|
336
|
+
row[columnName] = value[index]
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
} else {
|
|
340
|
+
tableValue.forEach((row) => {
|
|
341
|
+
if (isObjectRecord(row)) {
|
|
342
|
+
row[columnName] = value
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
changed = true
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (Object.prototype.hasOwnProperty.call(record.step, normalizedField)) {
|
|
352
|
+
record.step[normalizedField] = normalizeStepLike(value)
|
|
353
|
+
changed = true
|
|
354
|
+
continue
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (Object.prototype.hasOwnProperty.call(record.check, normalizedField)) {
|
|
358
|
+
record.check[normalizedField] = normalizeCheckLike(value)
|
|
359
|
+
changed = true
|
|
360
|
+
continue
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
record.var[normalizedField] = value
|
|
364
|
+
changed = true
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return changed
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function getAimdAssignerPayloadFieldKey(
|
|
371
|
+
fieldType: AssignableRecorderFieldType,
|
|
372
|
+
fieldKey: string,
|
|
373
|
+
): string {
|
|
374
|
+
const prefix = `${fieldType}:`
|
|
375
|
+
return fieldKey.startsWith(prefix) ? fieldKey.slice(prefix.length) : fieldKey
|
|
376
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, shallowRef } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
createCodeBlockRenderer,
|
|
4
|
+
loadShikiHighlighter,
|
|
5
|
+
type ElementRenderer,
|
|
6
|
+
type ShikiHighlighter,
|
|
7
|
+
} from '@airalogy/aimd-renderer'
|
|
8
|
+
|
|
9
|
+
export function createChainedElementRenderer(...renderers: ElementRenderer[]): ElementRenderer {
|
|
10
|
+
return (node, children, ctx) => {
|
|
11
|
+
for (const renderer of renderers) {
|
|
12
|
+
const rendered = renderer(node, children, ctx)
|
|
13
|
+
if (rendered !== null && rendered !== undefined) {
|
|
14
|
+
return rendered
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useCodeBlockRendering(onHighlighterReady?: () => void) {
|
|
22
|
+
const highlighter = shallowRef<ShikiHighlighter | null>(null)
|
|
23
|
+
let cancelled = false
|
|
24
|
+
const preRenderer = createCodeBlockRenderer(() => highlighter.value, {
|
|
25
|
+
theme: 'github-light',
|
|
26
|
+
lineNumbers: true,
|
|
27
|
+
wrap: true,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
onMounted(() => {
|
|
31
|
+
void loadShikiHighlighter()
|
|
32
|
+
.then((loadedHighlighter) => {
|
|
33
|
+
if (cancelled) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
highlighter.value = loadedHighlighter
|
|
37
|
+
onHighlighterReady?.()
|
|
38
|
+
})
|
|
39
|
+
.catch(() => {
|
|
40
|
+
// Keep the non-highlighted renderer. Line numbers and wrapping still work.
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
onBeforeUnmount(() => {
|
|
45
|
+
cancelled = true
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
preRenderer,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { reactive, type VNode } from "vue"
|
|
2
2
|
import type { AimdVarNode } from "@airalogy/aimd-core/types"
|
|
3
|
+
import { formatAimdExampleValue, getAimdFieldExamples } from "@airalogy/aimd-core/utils"
|
|
3
4
|
import type { AimdFieldMeta, AimdFieldState, AimdTypePlugin, AimdTypePluginInitContext, AimdTypePluginValueContext } from "../types"
|
|
4
5
|
import {
|
|
5
6
|
normalizeVarTypeName,
|
|
@@ -31,6 +32,19 @@ export interface FieldRenderingOptions {
|
|
|
31
32
|
wrapField: () => ((fieldKey: string, fieldType: string, defaultVNode: VNode) => VNode) | undefined
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
function getFieldMetaExamples(meta?: AimdFieldMeta): unknown[] {
|
|
36
|
+
if (!meta) return []
|
|
37
|
+
if (Array.isArray(meta.examples)) {
|
|
38
|
+
return meta.examples.filter(value => value !== undefined && value !== null)
|
|
39
|
+
}
|
|
40
|
+
const singleExample = (meta as { example?: unknown }).example
|
|
41
|
+
return singleExample === undefined || singleExample === null ? [] : [singleExample]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isReadonlyAssignerMode(mode?: NonNullable<AimdFieldMeta["assigner"]>["mode"]): boolean {
|
|
45
|
+
return mode === "auto_force" || mode === "auto_readonly" || mode === "manual_readonly"
|
|
46
|
+
}
|
|
47
|
+
|
|
34
48
|
// ---------------------------------------------------------------------------
|
|
35
49
|
// Composable
|
|
36
50
|
// ---------------------------------------------------------------------------
|
|
@@ -57,7 +71,7 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
57
71
|
if (options.readonly()) return true
|
|
58
72
|
const meta = options.fieldMeta()?.[fieldKey]
|
|
59
73
|
const state = options.fieldState()?.[fieldKey]
|
|
60
|
-
return !!(meta?.disabled || state?.disabled || meta?.assigner?.mode
|
|
74
|
+
return !!(meta?.disabled || state?.disabled || isReadonlyAssignerMode(meta?.assigner?.mode))
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
// ── resolveNowDate ─────────────────────────────────────────────────────
|
|
@@ -123,6 +137,8 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
123
137
|
getVarInputKind(type, {
|
|
124
138
|
inputType: options.fieldMeta()?.[fieldKey]?.inputType,
|
|
125
139
|
codeLanguage: options.fieldMeta()?.[fieldKey]?.codeLanguage,
|
|
140
|
+
kwargs: node.definition?.kwargs,
|
|
141
|
+
fieldMeta: options.fieldMeta()?.[fieldKey],
|
|
126
142
|
typePlugin: getTypePlugin(fieldKey, type),
|
|
127
143
|
}) !== "number"
|
|
128
144
|
|| typeof node.definition?.default !== "number"
|
|
@@ -196,6 +212,8 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
196
212
|
const inputKind = getVarInputKind(type, {
|
|
197
213
|
inputType: options.fieldMeta()?.[fieldKey]?.inputType,
|
|
198
214
|
codeLanguage: options.fieldMeta()?.[fieldKey]?.codeLanguage,
|
|
215
|
+
kwargs: node.definition?.kwargs,
|
|
216
|
+
fieldMeta: options.fieldMeta()?.[fieldKey],
|
|
199
217
|
typePlugin,
|
|
200
218
|
})
|
|
201
219
|
if (inputKind === "checkbox") return false
|
|
@@ -227,9 +245,19 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
227
245
|
return value
|
|
228
246
|
}
|
|
229
247
|
|
|
230
|
-
function getVarPlaceholder(node: AimdVarNode): string | undefined {
|
|
231
|
-
const
|
|
232
|
-
|
|
248
|
+
function getVarPlaceholder(node: AimdVarNode, meta?: AimdFieldMeta): string | undefined {
|
|
249
|
+
const placeholder = node.definition?.kwargs?.placeholder
|
|
250
|
+
if (typeof placeholder === "string" && placeholder.trim()) {
|
|
251
|
+
return placeholder.trim()
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const metaExamples = getFieldMetaExamples(meta)
|
|
255
|
+
const [example] = metaExamples.length > 0 ? metaExamples : getAimdFieldExamples(node.definition)
|
|
256
|
+
if (example !== undefined && example !== null && typeof example !== "object") {
|
|
257
|
+
return formatAimdExampleValue(example)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return undefined
|
|
233
261
|
}
|
|
234
262
|
|
|
235
263
|
// ── ID helpers ─────────────────────────────────────────────────────────
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { nextTick, ref, type Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export type MonacoAutoHeightEditor = {
|
|
4
|
+
getContentHeight?: () => number
|
|
5
|
+
layout?: (dimension?: { width: number; height: number }) => void
|
|
6
|
+
onDidContentSizeChange?: (listener: (event: { contentHeight: number }) => void) => { dispose: () => void }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type MonacoAutoHeightOptions = {
|
|
10
|
+
getInitialValue: () => string
|
|
11
|
+
getLayoutElement: () => HTMLElement | null
|
|
12
|
+
lineHeight?: number
|
|
13
|
+
verticalPadding?: number
|
|
14
|
+
minHeight?: number
|
|
15
|
+
maxHeight?: number
|
|
16
|
+
estimatedCharsPerLine?: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type MonacoAutoHeightController = {
|
|
20
|
+
editorHeight: Ref<number>
|
|
21
|
+
lineHeight: number
|
|
22
|
+
minHeight: number
|
|
23
|
+
maxHeight: number
|
|
24
|
+
attachEditor: (editor: MonacoAutoHeightEditor) => void
|
|
25
|
+
dispose: () => void
|
|
26
|
+
estimateEditorHeight: (value: string) => number
|
|
27
|
+
layoutEditor: () => void
|
|
28
|
+
setEditorHeight: (height: number) => void
|
|
29
|
+
syncEstimatedEditorHeight: (value?: string) => void
|
|
30
|
+
syncMeasuredEditorHeight: () => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DEFAULT_LINE_HEIGHT = 21
|
|
34
|
+
const DEFAULT_VERTICAL_PADDING = 24
|
|
35
|
+
const DEFAULT_ESTIMATED_CHARS_PER_LINE = 96
|
|
36
|
+
|
|
37
|
+
export function estimateMonacoVisualLineCount(value: string, estimatedCharsPerLine = DEFAULT_ESTIMATED_CHARS_PER_LINE): number {
|
|
38
|
+
const lines = value.replace(/\r\n?/g, '\n').split('\n')
|
|
39
|
+
return lines.reduce((total, line) => {
|
|
40
|
+
const length = Array.from(line).length
|
|
41
|
+
return total + Math.max(1, Math.ceil(length / estimatedCharsPerLine))
|
|
42
|
+
}, 0)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createMonacoAutoHeight(options: MonacoAutoHeightOptions): MonacoAutoHeightController {
|
|
46
|
+
const lineHeight = options.lineHeight ?? DEFAULT_LINE_HEIGHT
|
|
47
|
+
const verticalPadding = options.verticalPadding ?? DEFAULT_VERTICAL_PADDING
|
|
48
|
+
const minHeight = options.minHeight ?? lineHeight + verticalPadding
|
|
49
|
+
const maxHeight = options.maxHeight ?? 560
|
|
50
|
+
const estimatedCharsPerLine = options.estimatedCharsPerLine ?? DEFAULT_ESTIMATED_CHARS_PER_LINE
|
|
51
|
+
const editorHeight = ref(estimateEditorHeight(options.getInitialValue()))
|
|
52
|
+
|
|
53
|
+
let editor: MonacoAutoHeightEditor | null = null
|
|
54
|
+
let contentSizeDisposable: { dispose: () => void } | null = null
|
|
55
|
+
|
|
56
|
+
function clampEditorHeight(height: number): number {
|
|
57
|
+
return Math.max(minHeight, Math.min(maxHeight, Math.ceil(height)))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function estimateEditorHeight(value: string): number {
|
|
61
|
+
return clampEditorHeight((estimateMonacoVisualLineCount(value, estimatedCharsPerLine) * lineHeight) + verticalPadding)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function layoutEditor() {
|
|
65
|
+
if (!editor?.layout) {
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const width = options.getLayoutElement()?.clientWidth ?? 0
|
|
70
|
+
if (width > 0) {
|
|
71
|
+
editor.layout({ width, height: editorHeight.value })
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
editor.layout()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function setEditorHeight(height: number) {
|
|
79
|
+
const nextHeight = clampEditorHeight(height)
|
|
80
|
+
if (nextHeight === editorHeight.value) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
editorHeight.value = nextHeight
|
|
85
|
+
void nextTick(layoutEditor)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function syncEstimatedEditorHeight(value = options.getInitialValue()) {
|
|
89
|
+
setEditorHeight(estimateEditorHeight(value))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function syncMeasuredEditorHeight() {
|
|
93
|
+
const contentHeight = editor?.getContentHeight?.()
|
|
94
|
+
if (typeof contentHeight === 'number' && Number.isFinite(contentHeight)) {
|
|
95
|
+
setEditorHeight(contentHeight)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function attachEditor(nextEditor: MonacoAutoHeightEditor) {
|
|
100
|
+
contentSizeDisposable?.dispose()
|
|
101
|
+
editor = nextEditor
|
|
102
|
+
contentSizeDisposable = editor.onDidContentSizeChange?.((event) => {
|
|
103
|
+
setEditorHeight(event.contentHeight)
|
|
104
|
+
}) ?? null
|
|
105
|
+
syncMeasuredEditorHeight()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function dispose() {
|
|
109
|
+
contentSizeDisposable?.dispose()
|
|
110
|
+
contentSizeDisposable = null
|
|
111
|
+
editor = null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
editorHeight,
|
|
116
|
+
lineHeight,
|
|
117
|
+
minHeight,
|
|
118
|
+
maxHeight,
|
|
119
|
+
attachEditor,
|
|
120
|
+
dispose,
|
|
121
|
+
estimateEditorHeight,
|
|
122
|
+
layoutEditor,
|
|
123
|
+
setEditorHeight,
|
|
124
|
+
syncEstimatedEditorHeight,
|
|
125
|
+
syncMeasuredEditorHeight,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -363,6 +363,14 @@ export function normalizeVarTableRows(raw: unknown, columns: string[]): Record<s
|
|
|
363
363
|
return rows
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
function isPlaceholderVarTableRows(rows: Record<string, string>[], columns: string[]): boolean {
|
|
367
|
+
if (rows.length !== 1) {
|
|
368
|
+
return false
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return columns.every(column => rows[0]?.[column] === "")
|
|
372
|
+
}
|
|
373
|
+
|
|
366
374
|
export interface VarTablePastedCell {
|
|
367
375
|
rowIndex: number
|
|
368
376
|
column: string
|
|
@@ -456,9 +464,20 @@ export function ensureDefaultsFromFields(localRecord: AimdProtocolRecordData, fi
|
|
|
456
464
|
|
|
457
465
|
for (const vt of normalizeVarTableFields(fields.var_table)) {
|
|
458
466
|
const columns = vt.subvars.map(subvar => subvar.id)
|
|
459
|
-
const
|
|
460
|
-
const
|
|
461
|
-
|
|
467
|
+
const hasExistingRows = vt.id in localRecord.var
|
|
468
|
+
const defaultRows = Array.isArray(vt.default) && vt.default.length > 0
|
|
469
|
+
? normalizeVarTableRows(vt.default, columns)
|
|
470
|
+
: undefined
|
|
471
|
+
const rows = hasExistingRows ? localRecord.var[vt.id] : (defaultRows ?? vt.default)
|
|
472
|
+
const existingRows = normalizeVarTableRows(rows, columns)
|
|
473
|
+
const shouldApplyDefaults = Boolean(
|
|
474
|
+
hasExistingRows
|
|
475
|
+
&& defaultRows
|
|
476
|
+
&& isPlaceholderVarTableRows(existingRows, columns)
|
|
477
|
+
&& !isPlaceholderVarTableRows(defaultRows, columns),
|
|
478
|
+
)
|
|
479
|
+
const normalizedRows = shouldApplyDefaults && defaultRows ? defaultRows : existingRows
|
|
480
|
+
if (!hasExistingRows || JSON.stringify(normalizedRows) !== JSON.stringify(rows)) {
|
|
462
481
|
localRecord.var[vt.id] = normalizedRows
|
|
463
482
|
changed = true
|
|
464
483
|
}
|