@coasys/ad4m 0.12.0-dev-whisper-lang → 0.12.0-rc1-dev.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/lib/index.cjs +1746 -322
- package/lib/index.js +1745 -323
- package/lib/src/ai/AIClient.d.ts +1 -1
- package/lib/src/ai/AIClient.js +4 -5
- package/lib/src/ai/AIResolver.d.ts +1 -1
- package/lib/src/ai/AIResolver.js +2 -3
- package/lib/src/index.d.ts +2 -0
- package/lib/src/index.js +2 -0
- package/lib/src/model/Ad4mModel.js +21 -7
- package/lib/src/model/decorators.js +196 -6
- package/lib/src/model/util.d.ts +1 -1
- package/lib/src/model/util.js +15 -12
- package/lib/src/perspectives/PerspectiveClient.d.ts +11 -1
- package/lib/src/perspectives/PerspectiveClient.js +15 -4
- package/lib/src/perspectives/PerspectiveProxy.d.ts +124 -8
- package/lib/src/perspectives/PerspectiveProxy.js +573 -274
- package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -1
- package/lib/src/perspectives/PerspectiveResolver.js +5 -4
- package/lib/src/schema.gql +2 -2
- package/lib/src/shacl/SHACLFlow.d.ts +171 -0
- package/lib/src/shacl/SHACLFlow.js +370 -0
- package/lib/src/shacl/SHACLFlow.test.d.ts +1 -0
- package/lib/src/shacl/SHACLFlow.test.js +205 -0
- package/lib/src/shacl/SHACLShape.d.ts +108 -0
- package/lib/src/shacl/SHACLShape.js +566 -0
- package/lib/src/shacl/SHACLShape.test.d.ts +1 -0
- package/lib/src/shacl/SHACLShape.test.js +336 -0
- package/lib/src/typeDefs.js +2 -2
- package/package.json +1 -2
- package/src/ai/AIClient.ts +4 -6
- package/src/ai/AIResolver.ts +1 -2
- package/src/index.ts +2 -0
- package/src/model/Ad4mModel.ts +23 -7
- package/src/model/decorators.ts +221 -5
- package/src/model/util.ts +15 -12
- package/src/perspectives/PerspectiveClient.ts +15 -4
- package/src/perspectives/PerspectiveProxy.ts +588 -304
- package/src/perspectives/PerspectiveResolver.ts +1 -1
- package/src/shacl/SHACLFlow.test.ts +237 -0
- package/src/shacl/SHACLFlow.ts +503 -0
- package/src/shacl/SHACLShape.test.ts +400 -0
- package/src/shacl/SHACLShape.ts +755 -0
|
@@ -36,7 +36,7 @@ export default class PerspectiveResolver {
|
|
|
36
36
|
perspectiveLinkMutations(uuid: string, mutations: LinkMutations, status: LinkStatus, pubSub: any): LinkExpressionMutations;
|
|
37
37
|
perspectiveUpdateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput, batchId: string, pubSub: any): LinkExpression;
|
|
38
38
|
perspectiveAddLinkExpression(uuid: string, link: LinkExpressionInput, status: LinkStatus, batchId: string, pubSub: any): LinkExpression;
|
|
39
|
-
perspectiveAddSdna(uuid: string, name: string, sdnaCode: string, sdnaType: string, pubSub: any): Boolean;
|
|
39
|
+
perspectiveAddSdna(uuid: string, name: string, sdnaCode: string, sdnaType: string, shaclJson: string, pubSub: any): Boolean;
|
|
40
40
|
perspectiveExecuteCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Boolean;
|
|
41
41
|
perspectiveCreateSubject(uuid: string, SubjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Boolean;
|
|
42
42
|
perspectiveGetSubjectData(uuid: string, SubjectClass: string, expressionAddress: string): String;
|
|
@@ -190,7 +190,7 @@ let PerspectiveResolver = class PerspectiveResolver {
|
|
|
190
190
|
link.status = status;
|
|
191
191
|
return link;
|
|
192
192
|
}
|
|
193
|
-
perspectiveAddSdna(uuid, name, sdnaCode, sdnaType, pubSub) {
|
|
193
|
+
perspectiveAddSdna(uuid, name, sdnaCode, sdnaType, shaclJson, pubSub) {
|
|
194
194
|
return true;
|
|
195
195
|
}
|
|
196
196
|
perspectiveExecuteCommands(uuid, commands, expression, parameters, batchId) {
|
|
@@ -412,11 +412,12 @@ __decorate([
|
|
|
412
412
|
Mutation(returns => Boolean),
|
|
413
413
|
__param(0, Arg('uuid')),
|
|
414
414
|
__param(1, Arg('name')),
|
|
415
|
-
__param(2, Arg('sdnaCode')),
|
|
415
|
+
__param(2, Arg('sdnaCode', { nullable: true })),
|
|
416
416
|
__param(3, Arg('sdnaType')),
|
|
417
|
-
__param(4,
|
|
417
|
+
__param(4, Arg('shaclJson', { nullable: true })),
|
|
418
|
+
__param(5, PubSub()),
|
|
418
419
|
__metadata("design:type", Function),
|
|
419
|
-
__metadata("design:paramtypes", [String, String, String, String, Object]),
|
|
420
|
+
__metadata("design:paramtypes", [String, String, String, String, String, Object]),
|
|
420
421
|
__metadata("design:returntype", Boolean)
|
|
421
422
|
], PerspectiveResolver.prototype, "perspectiveAddSdna", null);
|
|
422
423
|
__decorate([
|
package/lib/src/schema.gql
CHANGED
|
@@ -314,7 +314,7 @@ type Mutation {
|
|
|
314
314
|
aiCloseTranscriptionStream(streamId: String!): String!
|
|
315
315
|
aiEmbed(modelId: String!, text: String!): String!
|
|
316
316
|
aiFeedTranscriptionStream(audio: [Float!]!, streamIds: [String!]!): String!
|
|
317
|
-
aiOpenTranscriptionStream(
|
|
317
|
+
aiOpenTranscriptionStream(modelId: String!, params: VoiceActivityParamsInput): String!
|
|
318
318
|
aiPrompt(prompt: String!, taskId: String!): String!
|
|
319
319
|
aiRemoveModel(modelId: String!): Boolean!
|
|
320
320
|
aiRemoveTask(taskId: String!): AITask!
|
|
@@ -340,7 +340,7 @@ type Mutation {
|
|
|
340
340
|
perspectiveAddLink(batchId: String, link: LinkInput!, status: String = "shared", uuid: String!): LinkExpression!
|
|
341
341
|
perspectiveAddLinkExpression(batchId: String, link: LinkExpressionInput!, status: String = "shared", uuid: String!): LinkExpression!
|
|
342
342
|
perspectiveAddLinks(batchId: String, links: [LinkInput!]!, status: String = "shared", uuid: String!): [LinkExpression!]!
|
|
343
|
-
perspectiveAddSdna(name: String!, sdnaCode: String
|
|
343
|
+
perspectiveAddSdna(name: String!, sdnaCode: String, sdnaType: String!, shaclJson: String, uuid: String!): Boolean!
|
|
344
344
|
perspectiveCommitBatch(batchId: String!, uuid: String!): LinkExpressionMutations!
|
|
345
345
|
perspectiveCreateBatch(uuid: String!): String!
|
|
346
346
|
perspectiveCreateSubject(batchId: String, expressionAddress: String!, initialValues: String, subjectClass: String!, uuid: String!): Boolean!
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Link } from "../links/Links";
|
|
2
|
+
import { AD4MAction } from "./SHACLShape";
|
|
3
|
+
export { AD4MAction };
|
|
4
|
+
/**
|
|
5
|
+
* Link pattern for state detection
|
|
6
|
+
* Used to check if an expression is in a particular state
|
|
7
|
+
*/
|
|
8
|
+
export interface LinkPattern {
|
|
9
|
+
/** Optional source pattern (if omitted, uses the expression address) */
|
|
10
|
+
source?: string;
|
|
11
|
+
/** Required predicate to match */
|
|
12
|
+
predicate: string;
|
|
13
|
+
/** Required target value to match */
|
|
14
|
+
target: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Flow State definition
|
|
18
|
+
* Represents a single state in the flow state machine
|
|
19
|
+
*/
|
|
20
|
+
export interface FlowState {
|
|
21
|
+
/** State name (e.g., "ready", "doing", "done") */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Numeric state value for ordering (e.g., 0, 0.5, 1) */
|
|
24
|
+
value: number;
|
|
25
|
+
/** Link pattern that indicates this state */
|
|
26
|
+
stateCheck: LinkPattern;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Flow Transition definition
|
|
30
|
+
* Represents a transition between two states
|
|
31
|
+
*/
|
|
32
|
+
export interface FlowTransition {
|
|
33
|
+
/** Name of this action (shown to users, e.g., "Start", "Finish") */
|
|
34
|
+
actionName: string;
|
|
35
|
+
/** State to transition from */
|
|
36
|
+
fromState: string;
|
|
37
|
+
/** State to transition to */
|
|
38
|
+
toState: string;
|
|
39
|
+
/** Actions to execute for this transition */
|
|
40
|
+
actions: AD4MAction[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Flowable condition - determines which expressions can enter this flow
|
|
44
|
+
* "any" means all expressions can start this flow
|
|
45
|
+
* Otherwise, a link pattern to check
|
|
46
|
+
*/
|
|
47
|
+
export type FlowableCondition = "any" | LinkPattern;
|
|
48
|
+
/**
|
|
49
|
+
* SHACL Flow - represents a state machine for AD4M expressions
|
|
50
|
+
*
|
|
51
|
+
* Flows define:
|
|
52
|
+
* - Which expressions can enter the flow (flowable condition)
|
|
53
|
+
* - What states exist and how to detect them (via link patterns)
|
|
54
|
+
* - How to transition between states (via actions)
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const todoFlow = new SHACLFlow('todo://TODO', 'todo://');
|
|
59
|
+
*
|
|
60
|
+
* // Any expression can become a TODO
|
|
61
|
+
* todoFlow.flowable = 'any';
|
|
62
|
+
*
|
|
63
|
+
* // Define states
|
|
64
|
+
* todoFlow.addState({
|
|
65
|
+
* name: 'ready',
|
|
66
|
+
* value: 0,
|
|
67
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
|
|
68
|
+
* });
|
|
69
|
+
* todoFlow.addState({
|
|
70
|
+
* name: 'doing',
|
|
71
|
+
* value: 0.5,
|
|
72
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
|
|
73
|
+
* });
|
|
74
|
+
* todoFlow.addState({
|
|
75
|
+
* name: 'done',
|
|
76
|
+
* value: 1,
|
|
77
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://done' }
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* // Define start action
|
|
81
|
+
* todoFlow.startAction = [{
|
|
82
|
+
* action: 'addLink',
|
|
83
|
+
* source: 'this',
|
|
84
|
+
* predicate: 'todo://state',
|
|
85
|
+
* target: 'todo://ready'
|
|
86
|
+
* }];
|
|
87
|
+
*
|
|
88
|
+
* // Define transitions
|
|
89
|
+
* todoFlow.addTransition({
|
|
90
|
+
* actionName: 'Start',
|
|
91
|
+
* fromState: 'ready',
|
|
92
|
+
* toState: 'doing',
|
|
93
|
+
* actions: [
|
|
94
|
+
* { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
|
|
95
|
+
* { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
|
|
96
|
+
* ]
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Store in perspective
|
|
100
|
+
* await perspective.addFlow('TODO', todoFlow);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare class SHACLFlow {
|
|
104
|
+
/** Flow name (e.g., "TODO") */
|
|
105
|
+
name: string;
|
|
106
|
+
/** Namespace for generated URIs */
|
|
107
|
+
namespace: string;
|
|
108
|
+
/** Condition for which expressions can start this flow */
|
|
109
|
+
flowable: FlowableCondition;
|
|
110
|
+
/** Actions to execute when starting the flow */
|
|
111
|
+
startAction: AD4MAction[];
|
|
112
|
+
/** States in this flow */
|
|
113
|
+
private _states;
|
|
114
|
+
/** Transitions between states */
|
|
115
|
+
private _transitions;
|
|
116
|
+
/**
|
|
117
|
+
* Create a new SHACL Flow
|
|
118
|
+
* @param name - Flow name (e.g., "TODO")
|
|
119
|
+
* @param namespace - Namespace for URIs (e.g., "todo://")
|
|
120
|
+
*/
|
|
121
|
+
constructor(name: string, namespace: string);
|
|
122
|
+
/** Get all states */
|
|
123
|
+
get states(): FlowState[];
|
|
124
|
+
/** Get all transitions */
|
|
125
|
+
get transitions(): FlowTransition[];
|
|
126
|
+
/**
|
|
127
|
+
* Add a state to the flow
|
|
128
|
+
* @param state - State definition
|
|
129
|
+
*/
|
|
130
|
+
addState(state: FlowState): void;
|
|
131
|
+
/**
|
|
132
|
+
* Add a transition to the flow
|
|
133
|
+
* @param transition - Transition definition
|
|
134
|
+
*/
|
|
135
|
+
addTransition(transition: FlowTransition): void;
|
|
136
|
+
/**
|
|
137
|
+
* Get the flow shape URI
|
|
138
|
+
*/
|
|
139
|
+
get flowUri(): string;
|
|
140
|
+
/**
|
|
141
|
+
* Get a state URI
|
|
142
|
+
*/
|
|
143
|
+
stateUri(stateName: string): string;
|
|
144
|
+
/**
|
|
145
|
+
* Get a transition URI
|
|
146
|
+
*/
|
|
147
|
+
transitionUri(fromState: string, toState: string): string;
|
|
148
|
+
/**
|
|
149
|
+
* Serialize the flow to AD4M links
|
|
150
|
+
* These links can be stored in a perspective and queried via SurrealDB
|
|
151
|
+
*
|
|
152
|
+
* @returns Array of Link objects representing the flow
|
|
153
|
+
*/
|
|
154
|
+
toLinks(): Link[];
|
|
155
|
+
/**
|
|
156
|
+
* Reconstruct a SHACLFlow from links
|
|
157
|
+
*
|
|
158
|
+
* @param links - Array of links containing the flow definition
|
|
159
|
+
* @param flowUri - The URI of the flow to reconstruct
|
|
160
|
+
* @returns Reconstructed SHACLFlow
|
|
161
|
+
*/
|
|
162
|
+
static fromLinks(links: Link[], flowUri: string): SHACLFlow;
|
|
163
|
+
/**
|
|
164
|
+
* Convert to JSON representation
|
|
165
|
+
*/
|
|
166
|
+
toJSON(): object;
|
|
167
|
+
/**
|
|
168
|
+
* Create from JSON representation
|
|
169
|
+
*/
|
|
170
|
+
static fromJSON(json: any): SHACLFlow;
|
|
171
|
+
}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { Literal } from "../Literal";
|
|
2
|
+
/**
|
|
3
|
+
* SHACL Flow - represents a state machine for AD4M expressions
|
|
4
|
+
*
|
|
5
|
+
* Flows define:
|
|
6
|
+
* - Which expressions can enter the flow (flowable condition)
|
|
7
|
+
* - What states exist and how to detect them (via link patterns)
|
|
8
|
+
* - How to transition between states (via actions)
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const todoFlow = new SHACLFlow('todo://TODO', 'todo://');
|
|
13
|
+
*
|
|
14
|
+
* // Any expression can become a TODO
|
|
15
|
+
* todoFlow.flowable = 'any';
|
|
16
|
+
*
|
|
17
|
+
* // Define states
|
|
18
|
+
* todoFlow.addState({
|
|
19
|
+
* name: 'ready',
|
|
20
|
+
* value: 0,
|
|
21
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://ready' }
|
|
22
|
+
* });
|
|
23
|
+
* todoFlow.addState({
|
|
24
|
+
* name: 'doing',
|
|
25
|
+
* value: 0.5,
|
|
26
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://doing' }
|
|
27
|
+
* });
|
|
28
|
+
* todoFlow.addState({
|
|
29
|
+
* name: 'done',
|
|
30
|
+
* value: 1,
|
|
31
|
+
* stateCheck: { predicate: 'todo://state', target: 'todo://done' }
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Define start action
|
|
35
|
+
* todoFlow.startAction = [{
|
|
36
|
+
* action: 'addLink',
|
|
37
|
+
* source: 'this',
|
|
38
|
+
* predicate: 'todo://state',
|
|
39
|
+
* target: 'todo://ready'
|
|
40
|
+
* }];
|
|
41
|
+
*
|
|
42
|
+
* // Define transitions
|
|
43
|
+
* todoFlow.addTransition({
|
|
44
|
+
* actionName: 'Start',
|
|
45
|
+
* fromState: 'ready',
|
|
46
|
+
* toState: 'doing',
|
|
47
|
+
* actions: [
|
|
48
|
+
* { action: 'addLink', source: 'this', predicate: 'todo://state', target: 'todo://doing' },
|
|
49
|
+
* { action: 'removeLink', source: 'this', predicate: 'todo://state', target: 'todo://ready' }
|
|
50
|
+
* ]
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Store in perspective
|
|
54
|
+
* await perspective.addFlow('TODO', todoFlow);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class SHACLFlow {
|
|
58
|
+
/**
|
|
59
|
+
* Create a new SHACL Flow
|
|
60
|
+
* @param name - Flow name (e.g., "TODO")
|
|
61
|
+
* @param namespace - Namespace for URIs (e.g., "todo://")
|
|
62
|
+
*/
|
|
63
|
+
constructor(name, namespace) {
|
|
64
|
+
/** Condition for which expressions can start this flow */
|
|
65
|
+
this.flowable = "any";
|
|
66
|
+
/** Actions to execute when starting the flow */
|
|
67
|
+
this.startAction = [];
|
|
68
|
+
/** States in this flow */
|
|
69
|
+
this._states = [];
|
|
70
|
+
/** Transitions between states */
|
|
71
|
+
this._transitions = [];
|
|
72
|
+
this.name = name;
|
|
73
|
+
this.namespace = namespace;
|
|
74
|
+
}
|
|
75
|
+
/** Get all states */
|
|
76
|
+
get states() {
|
|
77
|
+
return [...this._states];
|
|
78
|
+
}
|
|
79
|
+
/** Get all transitions */
|
|
80
|
+
get transitions() {
|
|
81
|
+
return [...this._transitions];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Add a state to the flow
|
|
85
|
+
* @param state - State definition
|
|
86
|
+
*/
|
|
87
|
+
addState(state) {
|
|
88
|
+
this._states.push(state);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Add a transition to the flow
|
|
92
|
+
* @param transition - Transition definition
|
|
93
|
+
*/
|
|
94
|
+
addTransition(transition) {
|
|
95
|
+
this._transitions.push(transition);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the flow shape URI
|
|
99
|
+
*/
|
|
100
|
+
get flowUri() {
|
|
101
|
+
return `${this.namespace}${this.name}Flow`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get a state URI
|
|
105
|
+
*/
|
|
106
|
+
stateUri(stateName) {
|
|
107
|
+
return `${this.namespace}${this.name}.${stateName}`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get a transition URI
|
|
111
|
+
*/
|
|
112
|
+
transitionUri(fromState, toState) {
|
|
113
|
+
return `${this.namespace}${this.name}.${fromState}To${toState}`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Serialize the flow to AD4M links
|
|
117
|
+
* These links can be stored in a perspective and queried via SurrealDB
|
|
118
|
+
*
|
|
119
|
+
* @returns Array of Link objects representing the flow
|
|
120
|
+
*/
|
|
121
|
+
toLinks() {
|
|
122
|
+
const links = [];
|
|
123
|
+
const flowUri = this.flowUri;
|
|
124
|
+
// Flow type
|
|
125
|
+
links.push({
|
|
126
|
+
source: flowUri,
|
|
127
|
+
predicate: "rdf://type",
|
|
128
|
+
target: "ad4m://Flow"
|
|
129
|
+
});
|
|
130
|
+
// Flow name
|
|
131
|
+
links.push({
|
|
132
|
+
source: flowUri,
|
|
133
|
+
predicate: "ad4m://flowName",
|
|
134
|
+
target: Literal.from(this.name).toUrl()
|
|
135
|
+
});
|
|
136
|
+
// Flowable condition
|
|
137
|
+
if (this.flowable === "any") {
|
|
138
|
+
links.push({
|
|
139
|
+
source: flowUri,
|
|
140
|
+
predicate: "ad4m://flowable",
|
|
141
|
+
target: "ad4m://any"
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
links.push({
|
|
146
|
+
source: flowUri,
|
|
147
|
+
predicate: "ad4m://flowable",
|
|
148
|
+
target: `literal://string:${encodeURIComponent(JSON.stringify(this.flowable))}`
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Start action
|
|
152
|
+
if (this.startAction.length > 0) {
|
|
153
|
+
links.push({
|
|
154
|
+
source: flowUri,
|
|
155
|
+
predicate: "ad4m://startAction",
|
|
156
|
+
target: `literal://string:${encodeURIComponent(JSON.stringify(this.startAction))}`
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
// States
|
|
160
|
+
for (const state of this._states) {
|
|
161
|
+
const stateUri = this.stateUri(state.name);
|
|
162
|
+
// Link flow to state
|
|
163
|
+
links.push({
|
|
164
|
+
source: flowUri,
|
|
165
|
+
predicate: "ad4m://hasState",
|
|
166
|
+
target: stateUri
|
|
167
|
+
});
|
|
168
|
+
// State type
|
|
169
|
+
links.push({
|
|
170
|
+
source: stateUri,
|
|
171
|
+
predicate: "rdf://type",
|
|
172
|
+
target: "ad4m://FlowState"
|
|
173
|
+
});
|
|
174
|
+
// State name
|
|
175
|
+
links.push({
|
|
176
|
+
source: stateUri,
|
|
177
|
+
predicate: "ad4m://stateName",
|
|
178
|
+
target: Literal.from(state.name).toUrl()
|
|
179
|
+
});
|
|
180
|
+
// State value
|
|
181
|
+
links.push({
|
|
182
|
+
source: stateUri,
|
|
183
|
+
predicate: "ad4m://stateValue",
|
|
184
|
+
target: Literal.from(state.value).toUrl()
|
|
185
|
+
});
|
|
186
|
+
// State check pattern
|
|
187
|
+
links.push({
|
|
188
|
+
source: stateUri,
|
|
189
|
+
predicate: "ad4m://stateCheck",
|
|
190
|
+
target: `literal://string:${encodeURIComponent(JSON.stringify(state.stateCheck))}`
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
// Transitions
|
|
194
|
+
for (const transition of this._transitions) {
|
|
195
|
+
const transitionUri = this.transitionUri(transition.fromState, transition.toState);
|
|
196
|
+
const fromStateUri = this.stateUri(transition.fromState);
|
|
197
|
+
const toStateUri = this.stateUri(transition.toState);
|
|
198
|
+
// Link flow to transition
|
|
199
|
+
links.push({
|
|
200
|
+
source: flowUri,
|
|
201
|
+
predicate: "ad4m://hasTransition",
|
|
202
|
+
target: transitionUri
|
|
203
|
+
});
|
|
204
|
+
// Transition type
|
|
205
|
+
links.push({
|
|
206
|
+
source: transitionUri,
|
|
207
|
+
predicate: "rdf://type",
|
|
208
|
+
target: "ad4m://FlowTransition"
|
|
209
|
+
});
|
|
210
|
+
// Action name
|
|
211
|
+
links.push({
|
|
212
|
+
source: transitionUri,
|
|
213
|
+
predicate: "ad4m://actionName",
|
|
214
|
+
target: Literal.from(transition.actionName).toUrl()
|
|
215
|
+
});
|
|
216
|
+
// From state
|
|
217
|
+
links.push({
|
|
218
|
+
source: transitionUri,
|
|
219
|
+
predicate: "ad4m://fromState",
|
|
220
|
+
target: fromStateUri
|
|
221
|
+
});
|
|
222
|
+
// To state
|
|
223
|
+
links.push({
|
|
224
|
+
source: transitionUri,
|
|
225
|
+
predicate: "ad4m://toState",
|
|
226
|
+
target: toStateUri
|
|
227
|
+
});
|
|
228
|
+
// Transition actions
|
|
229
|
+
links.push({
|
|
230
|
+
source: transitionUri,
|
|
231
|
+
predicate: "ad4m://transitionActions",
|
|
232
|
+
target: `literal://string:${encodeURIComponent(JSON.stringify(transition.actions))}`
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return links;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Reconstruct a SHACLFlow from links
|
|
239
|
+
*
|
|
240
|
+
* @param links - Array of links containing the flow definition
|
|
241
|
+
* @param flowUri - The URI of the flow to reconstruct
|
|
242
|
+
* @returns Reconstructed SHACLFlow
|
|
243
|
+
*/
|
|
244
|
+
static fromLinks(links, flowUri) {
|
|
245
|
+
// Extract namespace and name from flowUri
|
|
246
|
+
// Format: {namespace}{Name}Flow
|
|
247
|
+
const flowSuffix = "Flow";
|
|
248
|
+
if (!flowUri.endsWith(flowSuffix)) {
|
|
249
|
+
throw new Error(`Invalid flow URI: ${flowUri} (must end with 'Flow')`);
|
|
250
|
+
}
|
|
251
|
+
const withoutSuffix = flowUri.slice(0, -flowSuffix.length);
|
|
252
|
+
const lastSlashOrColon = Math.max(withoutSuffix.lastIndexOf('/'), withoutSuffix.lastIndexOf(':'));
|
|
253
|
+
const namespace = withoutSuffix.slice(0, lastSlashOrColon + 1);
|
|
254
|
+
const name = withoutSuffix.slice(lastSlashOrColon + 1);
|
|
255
|
+
const flow = new SHACLFlow(name, namespace);
|
|
256
|
+
// Find flowable condition
|
|
257
|
+
const flowableLink = links.find(l => l.source === flowUri && l.predicate === "ad4m://flowable");
|
|
258
|
+
if (flowableLink) {
|
|
259
|
+
if (flowableLink.target === "ad4m://any") {
|
|
260
|
+
flow.flowable = "any";
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
try {
|
|
264
|
+
const jsonStr = flowableLink.target.replace('literal://string:', '');
|
|
265
|
+
flow.flowable = JSON.parse(decodeURIComponent(jsonStr));
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
flow.flowable = "any";
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Find start action
|
|
273
|
+
const startActionLink = links.find(l => l.source === flowUri && l.predicate === "ad4m://startAction");
|
|
274
|
+
if (startActionLink) {
|
|
275
|
+
try {
|
|
276
|
+
const jsonStr = startActionLink.target.replace('literal://string:', '');
|
|
277
|
+
flow.startAction = JSON.parse(decodeURIComponent(jsonStr));
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// Ignore parse errors
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// Find states
|
|
284
|
+
const stateLinks = links.filter(l => l.source === flowUri && l.predicate === "ad4m://hasState");
|
|
285
|
+
// Build a map from state URI to state name for later lookup
|
|
286
|
+
const stateUriToName = new Map();
|
|
287
|
+
for (const stateLink of stateLinks) {
|
|
288
|
+
const stateUri = stateLink.target;
|
|
289
|
+
// Get state name
|
|
290
|
+
const nameLink = links.find(l => l.source === stateUri && l.predicate === "ad4m://stateName");
|
|
291
|
+
const stateName = nameLink ? Literal.fromUrl(nameLink.target).get() : "";
|
|
292
|
+
// Store mapping for transition lookup
|
|
293
|
+
stateUriToName.set(stateUri, stateName);
|
|
294
|
+
// Get state value
|
|
295
|
+
const valueLink = links.find(l => l.source === stateUri && l.predicate === "ad4m://stateValue");
|
|
296
|
+
const stateValue = valueLink ? Literal.fromUrl(valueLink.target).get() : 0;
|
|
297
|
+
// Get state check
|
|
298
|
+
const checkLink = links.find(l => l.source === stateUri && l.predicate === "ad4m://stateCheck");
|
|
299
|
+
let stateCheck = { predicate: "", target: "" };
|
|
300
|
+
if (checkLink) {
|
|
301
|
+
try {
|
|
302
|
+
const jsonStr = checkLink.target.replace('literal://string:', '');
|
|
303
|
+
stateCheck = JSON.parse(decodeURIComponent(jsonStr));
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
// Ignore parse errors
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
flow.addState({ name: stateName, value: stateValue, stateCheck });
|
|
310
|
+
}
|
|
311
|
+
// Find transitions
|
|
312
|
+
const transitionLinks = links.filter(l => l.source === flowUri && l.predicate === "ad4m://hasTransition");
|
|
313
|
+
for (const transitionLink of transitionLinks) {
|
|
314
|
+
const transitionUri = transitionLink.target;
|
|
315
|
+
// Get action name
|
|
316
|
+
const actionNameLink = links.find(l => l.source === transitionUri && l.predicate === "ad4m://actionName");
|
|
317
|
+
const actionName = actionNameLink ? Literal.fromUrl(actionNameLink.target).get() : "";
|
|
318
|
+
// Get from state
|
|
319
|
+
const fromStateLink = links.find(l => l.source === transitionUri && l.predicate === "ad4m://fromState");
|
|
320
|
+
const fromStateUri = fromStateLink?.target || "";
|
|
321
|
+
const fromState = stateUriToName.get(fromStateUri) || "";
|
|
322
|
+
// Get to state
|
|
323
|
+
const toStateLink = links.find(l => l.source === transitionUri && l.predicate === "ad4m://toState");
|
|
324
|
+
const toStateUri = toStateLink?.target || "";
|
|
325
|
+
const toState = stateUriToName.get(toStateUri) || "";
|
|
326
|
+
// Get actions
|
|
327
|
+
const actionsLink = links.find(l => l.source === transitionUri && l.predicate === "ad4m://transitionActions");
|
|
328
|
+
let actions = [];
|
|
329
|
+
if (actionsLink) {
|
|
330
|
+
try {
|
|
331
|
+
const jsonStr = actionsLink.target.replace('literal://string:', '');
|
|
332
|
+
actions = JSON.parse(decodeURIComponent(jsonStr));
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
// Ignore parse errors
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
flow.addTransition({ actionName, fromState, toState, actions });
|
|
339
|
+
}
|
|
340
|
+
return flow;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Convert to JSON representation
|
|
344
|
+
*/
|
|
345
|
+
toJSON() {
|
|
346
|
+
return {
|
|
347
|
+
name: this.name,
|
|
348
|
+
namespace: this.namespace,
|
|
349
|
+
flowable: this.flowable,
|
|
350
|
+
startAction: this.startAction,
|
|
351
|
+
states: this._states,
|
|
352
|
+
transitions: this._transitions
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Create from JSON representation
|
|
357
|
+
*/
|
|
358
|
+
static fromJSON(json) {
|
|
359
|
+
const flow = new SHACLFlow(json.name, json.namespace);
|
|
360
|
+
flow.flowable = json.flowable || "any";
|
|
361
|
+
flow.startAction = json.startAction || [];
|
|
362
|
+
for (const state of json.states || []) {
|
|
363
|
+
flow.addState(state);
|
|
364
|
+
}
|
|
365
|
+
for (const transition of json.transitions || []) {
|
|
366
|
+
flow.addTransition(transition);
|
|
367
|
+
}
|
|
368
|
+
return flow;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|