@intent-framework/core 0.1.0-alpha.0 → 0.1.0-alpha.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/dist/graph.d.ts +7 -0
- package/dist/index.js +61 -6
- package/dist/registry.d.ts +1 -0
- package/package.json +1 -1
package/dist/graph.d.ts
CHANGED
|
@@ -7,11 +7,14 @@ export type GraphDiagnostic = {
|
|
|
7
7
|
code: string;
|
|
8
8
|
message: string;
|
|
9
9
|
nodeId?: string;
|
|
10
|
+
semanticNodeId?: string;
|
|
10
11
|
};
|
|
11
12
|
export type InspectedScreen = {
|
|
12
13
|
name: string;
|
|
14
|
+
semanticId: string;
|
|
13
15
|
asks: Array<{
|
|
14
16
|
id: string;
|
|
17
|
+
semanticId: string;
|
|
15
18
|
label: string;
|
|
16
19
|
kind: string;
|
|
17
20
|
required: boolean;
|
|
@@ -21,6 +24,7 @@ export type InspectedScreen = {
|
|
|
21
24
|
}>;
|
|
22
25
|
acts: Array<{
|
|
23
26
|
id: string;
|
|
27
|
+
semanticId: string;
|
|
24
28
|
label: string;
|
|
25
29
|
primary: boolean;
|
|
26
30
|
enabled: boolean;
|
|
@@ -31,16 +35,19 @@ export type InspectedScreen = {
|
|
|
31
35
|
}>;
|
|
32
36
|
flows: Array<{
|
|
33
37
|
id: string;
|
|
38
|
+
semanticId: string;
|
|
34
39
|
name: string;
|
|
35
40
|
stepCount: number;
|
|
36
41
|
}>;
|
|
37
42
|
surfaces: Array<{
|
|
38
43
|
id: string;
|
|
44
|
+
semanticId: string;
|
|
39
45
|
name: string;
|
|
40
46
|
itemCount: number;
|
|
41
47
|
}>;
|
|
42
48
|
resources: Array<{
|
|
43
49
|
id: string;
|
|
50
|
+
semanticId: string;
|
|
44
51
|
name: string;
|
|
45
52
|
status: string;
|
|
46
53
|
hasValue: boolean;
|
package/dist/index.js
CHANGED
|
@@ -351,6 +351,11 @@ function getSurfaces() {
|
|
|
351
351
|
function getResources() {
|
|
352
352
|
return resourceMap;
|
|
353
353
|
}
|
|
354
|
+
function nextSuffix(baseId, exists) {
|
|
355
|
+
let counter = 2;
|
|
356
|
+
while (exists(`${baseId}-${counter}`)) counter++;
|
|
357
|
+
return `${baseId}-${counter}`;
|
|
358
|
+
}
|
|
354
359
|
|
|
355
360
|
//#endregion
|
|
356
361
|
//#region src/ask.ts
|
|
@@ -408,7 +413,9 @@ function computeAskError(node) {
|
|
|
408
413
|
var AskBuilder = class {
|
|
409
414
|
node;
|
|
410
415
|
constructor(label, stateRef) {
|
|
411
|
-
const
|
|
416
|
+
const baseId = `ask_${label.toLowerCase().replace(/\s+/g, "_")}`;
|
|
417
|
+
const existing = getAsks();
|
|
418
|
+
const id = existing.has(baseId) ? nextSuffix(baseId, (id$1) => existing.has(id$1)) : baseId;
|
|
412
419
|
const onChange = stateRef.onChange;
|
|
413
420
|
const subscribeToState = onChange ? (fn) => onChange((_v) => fn()) : void 0;
|
|
414
421
|
this.node = createAskNode(id, label, stateRef, subscribeToState);
|
|
@@ -520,7 +527,9 @@ async function executeAct(node, context, notify) {
|
|
|
520
527
|
var ActBuilder = class {
|
|
521
528
|
node;
|
|
522
529
|
constructor(label) {
|
|
523
|
-
const
|
|
530
|
+
const baseId = `act_${label.toLowerCase().replace(/\s+/g, "_")}`;
|
|
531
|
+
const existing = getActs();
|
|
532
|
+
const id = existing.has(baseId) ? nextSuffix(baseId, (id$1) => existing.has(id$1)) : baseId;
|
|
524
533
|
this.node = createActNode(id, label, [], null, void 0, false);
|
|
525
534
|
registerActNode(this.node);
|
|
526
535
|
}
|
|
@@ -578,7 +587,9 @@ var ActBuilder = class {
|
|
|
578
587
|
var FlowBuilder = class {
|
|
579
588
|
node;
|
|
580
589
|
constructor(name) {
|
|
581
|
-
const
|
|
590
|
+
const baseId = `flow_${name}`;
|
|
591
|
+
const existing = getFlows();
|
|
592
|
+
const id = existing.has(baseId) ? nextSuffix(baseId, (id$1) => existing.has(id$1)) : baseId;
|
|
582
593
|
this.node = {
|
|
583
594
|
id,
|
|
584
595
|
name,
|
|
@@ -623,7 +634,9 @@ var FlowBuilder = class {
|
|
|
623
634
|
var SurfaceBuilder = class {
|
|
624
635
|
node;
|
|
625
636
|
constructor(name) {
|
|
626
|
-
const
|
|
637
|
+
const baseId = `surface_${name}`;
|
|
638
|
+
const existing = getSurfaces();
|
|
639
|
+
const id = existing.has(baseId) ? nextSuffix(baseId, (id$1) => existing.has(id$1)) : baseId;
|
|
627
640
|
this.node = {
|
|
628
641
|
id,
|
|
629
642
|
name,
|
|
@@ -662,7 +675,8 @@ function screen(name, fn) {
|
|
|
662
675
|
flow: (n) => new FlowBuilder(n),
|
|
663
676
|
surface: (n) => new SurfaceBuilder(n),
|
|
664
677
|
resource: (n, config) => {
|
|
665
|
-
const
|
|
678
|
+
const baseId = `resource_${n}`;
|
|
679
|
+
const id = configs.some((c) => c.id === baseId) ? nextSuffix(baseId, (id$1) => configs.some((c) => c.id === id$1)) : baseId;
|
|
666
680
|
const ref = new ResourceRef(id, n, config.load, config.autoLoad ?? true);
|
|
667
681
|
configs.push({
|
|
668
682
|
id,
|
|
@@ -691,6 +705,28 @@ function screen(name, fn) {
|
|
|
691
705
|
|
|
692
706
|
//#endregion
|
|
693
707
|
//#region src/graph.ts
|
|
708
|
+
const NODE_KINDS = {
|
|
709
|
+
ask: "ask",
|
|
710
|
+
act: "action",
|
|
711
|
+
flow: "flow",
|
|
712
|
+
surface: "surface",
|
|
713
|
+
resource: "resource"
|
|
714
|
+
};
|
|
715
|
+
function slugify(text) {
|
|
716
|
+
return text.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
|
717
|
+
}
|
|
718
|
+
function createSemanticIdFactory(kind) {
|
|
719
|
+
const prefix = NODE_KINDS[kind] ?? kind;
|
|
720
|
+
const used = /* @__PURE__ */ new Map();
|
|
721
|
+
let unnamed = 0;
|
|
722
|
+
return (source) => {
|
|
723
|
+
const slug = slugify(source);
|
|
724
|
+
const base = slug.length > 0 ? slug : String(++unnamed);
|
|
725
|
+
const count = used.get(base) ?? 0;
|
|
726
|
+
used.set(base, count + 1);
|
|
727
|
+
return count === 0 ? `${prefix}:${base}` : `${prefix}:${base}-${count + 1}`;
|
|
728
|
+
};
|
|
729
|
+
}
|
|
694
730
|
function computeDiagnostics(screenDef) {
|
|
695
731
|
const diagnostics = [];
|
|
696
732
|
const primaryActions = screenDef.acts.filter((a) => a.primary);
|
|
@@ -728,10 +764,25 @@ function computeDiagnostics(screenDef) {
|
|
|
728
764
|
return diagnostics;
|
|
729
765
|
}
|
|
730
766
|
function inspectScreen(screenDef, runtimeResources) {
|
|
767
|
+
const diagnostics = computeDiagnostics(screenDef);
|
|
768
|
+
const askIds = createSemanticIdFactory("ask");
|
|
769
|
+
const actIds = createSemanticIdFactory("act");
|
|
770
|
+
const flowIds = createSemanticIdFactory("flow");
|
|
771
|
+
const surfaceIds = createSemanticIdFactory("surface");
|
|
772
|
+
const resourceIds = createSemanticIdFactory("resource");
|
|
773
|
+
const idToSemantic = /* @__PURE__ */ new Map();
|
|
774
|
+
for (const a of screenDef.asks) idToSemantic.set(a.id, askIds(a.label));
|
|
775
|
+
for (const a of screenDef.acts) idToSemantic.set(a.id, actIds(a.label));
|
|
776
|
+
const augmentedDiagnostics = diagnostics.map((d) => ({
|
|
777
|
+
...d,
|
|
778
|
+
semanticNodeId: d.nodeId ? idToSemantic.get(d.nodeId) : void 0
|
|
779
|
+
}));
|
|
731
780
|
return {
|
|
732
781
|
name: screenDef.name,
|
|
782
|
+
semanticId: `screen:${slugify(screenDef.name)}`,
|
|
733
783
|
asks: screenDef.asks.map((a) => ({
|
|
734
784
|
id: a.id,
|
|
785
|
+
semanticId: idToSemantic.get(a.id),
|
|
735
786
|
label: a.label,
|
|
736
787
|
kind: a.kind,
|
|
737
788
|
required: a.required,
|
|
@@ -741,6 +792,7 @@ function inspectScreen(screenDef, runtimeResources) {
|
|
|
741
792
|
})),
|
|
742
793
|
acts: screenDef.acts.map((a) => ({
|
|
743
794
|
id: a.id,
|
|
795
|
+
semanticId: idToSemantic.get(a.id),
|
|
744
796
|
label: a.label,
|
|
745
797
|
primary: a.primary,
|
|
746
798
|
enabled: a.enabled.current,
|
|
@@ -751,23 +803,26 @@ function inspectScreen(screenDef, runtimeResources) {
|
|
|
751
803
|
})),
|
|
752
804
|
flows: screenDef.flows.map((f) => ({
|
|
753
805
|
id: f.id,
|
|
806
|
+
semanticId: flowIds(f.name),
|
|
754
807
|
name: f.name,
|
|
755
808
|
stepCount: f.steps.length
|
|
756
809
|
})),
|
|
757
810
|
surfaces: screenDef.surfaces.map((s) => ({
|
|
758
811
|
id: s.id,
|
|
812
|
+
semanticId: surfaceIds(s.name),
|
|
759
813
|
name: s.name,
|
|
760
814
|
itemCount: s.items.length
|
|
761
815
|
})),
|
|
762
816
|
resources: (runtimeResources ?? []).map((r) => ({
|
|
763
817
|
id: r.id,
|
|
818
|
+
semanticId: resourceIds(r.name),
|
|
764
819
|
name: r.name,
|
|
765
820
|
status: r.status,
|
|
766
821
|
hasValue: r.value !== void 0,
|
|
767
822
|
stale: r.stale.current,
|
|
768
823
|
error: r.status === "failed" ? r.error instanceof Error ? r.error.message : String(r.error) : void 0
|
|
769
824
|
})),
|
|
770
|
-
diagnostics:
|
|
825
|
+
diagnostics: augmentedDiagnostics
|
|
771
826
|
};
|
|
772
827
|
}
|
|
773
828
|
|
package/dist/registry.d.ts
CHANGED
|
@@ -23,3 +23,4 @@ export declare function getActs(): Map<string, ActNode<any>>;
|
|
|
23
23
|
export declare function getFlows(): Map<string, FlowNode>;
|
|
24
24
|
export declare function getSurfaces(): Map<string, SurfaceNode>;
|
|
25
25
|
export declare function getResources(): Map<string, AnyResourceNode>;
|
|
26
|
+
export declare function nextSuffix(baseId: string, exists: (id: string) => boolean): string;
|