@agentick/kernel 0.0.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/LICENSE +21 -0
- package/README.md +401 -0
- package/dist/.tsbuildinfo.build +1 -0
- package/dist/channel-helpers.d.ts +32 -0
- package/dist/channel-helpers.d.ts.map +1 -0
- package/dist/channel-helpers.js +62 -0
- package/dist/channel-helpers.js.map +1 -0
- package/dist/channel.d.ts +164 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +199 -0
- package/dist/channel.js.map +1 -0
- package/dist/context.d.ts +412 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +289 -0
- package/dist/context.js.map +1 -0
- package/dist/event-buffer.d.ts +208 -0
- package/dist/event-buffer.d.ts.map +1 -0
- package/dist/event-buffer.js +335 -0
- package/dist/event-buffer.js.map +1 -0
- package/dist/execution-helpers.d.ts +179 -0
- package/dist/execution-helpers.d.ts.map +1 -0
- package/dist/execution-helpers.js +212 -0
- package/dist/execution-helpers.js.map +1 -0
- package/dist/execution-tracker.d.ts +61 -0
- package/dist/execution-tracker.d.ts.map +1 -0
- package/dist/execution-tracker.js +319 -0
- package/dist/execution-tracker.js.map +1 -0
- package/dist/guard.d.ts +65 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +15 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +341 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +346 -0
- package/dist/logger.js.map +1 -0
- package/dist/metrics-helpers.d.ts +40 -0
- package/dist/metrics-helpers.d.ts.map +1 -0
- package/dist/metrics-helpers.js +72 -0
- package/dist/metrics-helpers.js.map +1 -0
- package/dist/otel-provider.d.ts +54 -0
- package/dist/otel-provider.d.ts.map +1 -0
- package/dist/otel-provider.js +107 -0
- package/dist/otel-provider.js.map +1 -0
- package/dist/procedure-graph.d.ts +136 -0
- package/dist/procedure-graph.d.ts.map +1 -0
- package/dist/procedure-graph.js +272 -0
- package/dist/procedure-graph.js.map +1 -0
- package/dist/procedure.d.ts +757 -0
- package/dist/procedure.d.ts.map +1 -0
- package/dist/procedure.js +895 -0
- package/dist/procedure.js.map +1 -0
- package/dist/schema.d.ts +153 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +385 -0
- package/dist/schema.js.map +1 -0
- package/dist/stream.d.ts +106 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +186 -0
- package/dist/stream.js.map +1 -0
- package/dist/telemetry.d.ts +182 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +124 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +55 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +96 -0
- package/dist/testing.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Procedure status
|
|
3
|
+
*/
|
|
4
|
+
export type ProcedureStatus = "running" | "completed" | "failed" | "cancelled";
|
|
5
|
+
/**
|
|
6
|
+
* Procedure node stored in the graph
|
|
7
|
+
*/
|
|
8
|
+
export declare class ProcedureNode {
|
|
9
|
+
readonly pid: string;
|
|
10
|
+
readonly parentPid?: string;
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
status: ProcedureStatus;
|
|
13
|
+
readonly startedAt: Date;
|
|
14
|
+
completedAt?: Date;
|
|
15
|
+
error?: Error;
|
|
16
|
+
metadata?: Record<string, any>;
|
|
17
|
+
readonly graph: ProcedureGraph;
|
|
18
|
+
metrics: Record<string, number>;
|
|
19
|
+
readonly executionId: string;
|
|
20
|
+
readonly isExecutionBoundary: boolean;
|
|
21
|
+
readonly executionType?: string;
|
|
22
|
+
constructor(graph: ProcedureGraph, pid: string, parentPid?: string, name?: string, metadata?: Record<string, any>, executionId?: string, isExecutionBoundary?: boolean, executionType?: string);
|
|
23
|
+
/**
|
|
24
|
+
* Add metric value (accumulates)
|
|
25
|
+
*/
|
|
26
|
+
addMetric(key: string, value: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Set metric value (overwrites)
|
|
29
|
+
*/
|
|
30
|
+
setMetric(key: string, value: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get metric value
|
|
33
|
+
*/
|
|
34
|
+
getMetric(key: string): number;
|
|
35
|
+
/**
|
|
36
|
+
* Merge metrics from another node (for propagation)
|
|
37
|
+
*/
|
|
38
|
+
mergeMetrics(sourceMetrics: Record<string, number>): void;
|
|
39
|
+
complete(): void;
|
|
40
|
+
fail(error: Error): void;
|
|
41
|
+
cancel(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get duration in milliseconds (undefined if not completed)
|
|
44
|
+
*/
|
|
45
|
+
get durationMs(): number | undefined;
|
|
46
|
+
getParentNode(): ProcedureNode | undefined;
|
|
47
|
+
getChildrenNodes(): ProcedureNode[];
|
|
48
|
+
hasAncestor(predicate: (node: ProcedureNode) => boolean): boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Procedure graph for tracking parent-child relationships
|
|
52
|
+
*/
|
|
53
|
+
export declare class ProcedureGraph {
|
|
54
|
+
private procedures;
|
|
55
|
+
private childrenMap;
|
|
56
|
+
private rootPid?;
|
|
57
|
+
/**
|
|
58
|
+
* Register a new procedure
|
|
59
|
+
*
|
|
60
|
+
* @param pid Procedure ID
|
|
61
|
+
* @param parentPid Parent procedure ID (undefined for root)
|
|
62
|
+
* @param name Procedure name (e.g., 'model:generate', 'tool:run')
|
|
63
|
+
* @param metadata Optional metadata
|
|
64
|
+
* @param executionId Execution ID this procedure belongs to
|
|
65
|
+
* @param isExecutionBoundary Whether this procedure is an execution entry point
|
|
66
|
+
* @param executionType Type of execution (derived from procedure name prefix)
|
|
67
|
+
*/
|
|
68
|
+
register(pid: string, parentPid?: string, name?: string, metadata?: Record<string, any>, executionId?: string, isExecutionBoundary?: boolean, executionType?: string): ProcedureNode;
|
|
69
|
+
/**
|
|
70
|
+
* Get procedure node by PID
|
|
71
|
+
*/
|
|
72
|
+
get(pid: string): ProcedureNode | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Get parent PID
|
|
75
|
+
*/
|
|
76
|
+
getParent(pid: string): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get parent node
|
|
79
|
+
*/
|
|
80
|
+
getParentNode(pid: string): ProcedureNode | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Get child procedure PIDs
|
|
83
|
+
*/
|
|
84
|
+
getChildren(parentPid: string): string[];
|
|
85
|
+
/**
|
|
86
|
+
* Get child procedure nodes
|
|
87
|
+
*/
|
|
88
|
+
getChildNodes(parentPid: string): ProcedureNode[];
|
|
89
|
+
/**
|
|
90
|
+
* Propagate metrics from child to parent
|
|
91
|
+
*/
|
|
92
|
+
propagateMetrics(childPid: string): void;
|
|
93
|
+
/**
|
|
94
|
+
* Update procedure status
|
|
95
|
+
*/
|
|
96
|
+
updateStatus(pid: string, status: ProcedureStatus, error?: Error): void;
|
|
97
|
+
/**
|
|
98
|
+
* Clear all procedures
|
|
99
|
+
*/
|
|
100
|
+
clear(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Get the root procedure node (O(1) lookup)
|
|
103
|
+
*/
|
|
104
|
+
getRoot(): ProcedureNode | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Get the root procedure PID
|
|
107
|
+
*/
|
|
108
|
+
getRootPid(): string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Get all procedure nodes
|
|
111
|
+
*/
|
|
112
|
+
getAllNodes(): ProcedureNode[];
|
|
113
|
+
/**
|
|
114
|
+
* Get count of procedures
|
|
115
|
+
*/
|
|
116
|
+
getCount(): number;
|
|
117
|
+
/**
|
|
118
|
+
* Check if any ancestor (parent chain) matches a predicate
|
|
119
|
+
* Traverses up the parent chain starting from the given PID
|
|
120
|
+
*
|
|
121
|
+
* @param pid Starting procedure PID
|
|
122
|
+
* @param predicate Function to test each ancestor node
|
|
123
|
+
* @returns True if any ancestor matches, false otherwise
|
|
124
|
+
*/
|
|
125
|
+
hasAncestor(pid: string, predicate: (node: ProcedureNode) => boolean): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Check if any ancestor has a specific procedure name
|
|
128
|
+
* Useful for determining if a procedure was called by Engine vs direct application call
|
|
129
|
+
*
|
|
130
|
+
* @param pid Starting procedure PID
|
|
131
|
+
* @param name Procedure name to search for (e.g., 'engine:execute', 'engine:stream')
|
|
132
|
+
* @returns True if any ancestor has the specified name
|
|
133
|
+
*/
|
|
134
|
+
hasAncestorWithName(pid: string, name: string): boolean;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=procedure-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-graph.d.ts","sourceRoot":"","sources":["../src/procedure-graph.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE/E;;GAEG;AACH,qBAAa,aAAa;IACxB,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,eAAe,CAAC;IAC/B,SAAgB,SAAS,EAAE,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtC,SAAgB,KAAK,EAAE,cAAc,CAAC;IAG/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAG5C,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,mBAAmB,EAAE,OAAO,CAAC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+
pid;
|
|
6
|
+
parentPid;
|
|
7
|
+
name;
|
|
8
|
+
status;
|
|
9
|
+
startedAt;
|
|
10
|
+
completedAt;
|
|
11
|
+
error;
|
|
12
|
+
metadata;
|
|
13
|
+
graph;
|
|
14
|
+
// Metrics stored in node (not context)
|
|
15
|
+
metrics = {};
|
|
16
|
+
// Execution boundary fields - tracks which logical execution this procedure belongs to
|
|
17
|
+
executionId;
|
|
18
|
+
isExecutionBoundary;
|
|
19
|
+
executionType;
|
|
20
|
+
constructor(graph, pid, parentPid, name, metadata, executionId, isExecutionBoundary, executionType) {
|
|
21
|
+
this.graph = graph;
|
|
22
|
+
this.pid = pid;
|
|
23
|
+
this.parentPid = parentPid;
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.status = "running";
|
|
26
|
+
this.startedAt = new Date();
|
|
27
|
+
this.metadata = metadata;
|
|
28
|
+
// Execution boundary: defaults to self as execution if not provided
|
|
29
|
+
this.executionId = executionId ?? pid;
|
|
30
|
+
this.isExecutionBoundary = isExecutionBoundary ?? false;
|
|
31
|
+
this.executionType = executionType;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Add metric value (accumulates)
|
|
35
|
+
*/
|
|
36
|
+
addMetric(key, value) {
|
|
37
|
+
this.metrics[key] = (this.metrics[key] || 0) + value;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set metric value (overwrites)
|
|
41
|
+
*/
|
|
42
|
+
setMetric(key, value) {
|
|
43
|
+
this.metrics[key] = value;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get metric value
|
|
47
|
+
*/
|
|
48
|
+
getMetric(key) {
|
|
49
|
+
return this.metrics[key] || 0;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Merge metrics from another node (for propagation)
|
|
53
|
+
*/
|
|
54
|
+
mergeMetrics(sourceMetrics) {
|
|
55
|
+
for (const [key, value] of Object.entries(sourceMetrics)) {
|
|
56
|
+
this.metrics[key] = (this.metrics[key] || 0) + value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
complete() {
|
|
60
|
+
this.status = "completed";
|
|
61
|
+
this.completedAt = new Date();
|
|
62
|
+
}
|
|
63
|
+
fail(error) {
|
|
64
|
+
this.status = "failed";
|
|
65
|
+
this.completedAt = new Date();
|
|
66
|
+
this.error = error;
|
|
67
|
+
}
|
|
68
|
+
cancel() {
|
|
69
|
+
this.status = "cancelled";
|
|
70
|
+
this.completedAt = new Date();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get duration in milliseconds (undefined if not completed)
|
|
74
|
+
*/
|
|
75
|
+
get durationMs() {
|
|
76
|
+
if (!this.completedAt) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return this.completedAt.getTime() - this.startedAt.getTime();
|
|
80
|
+
}
|
|
81
|
+
getParentNode() {
|
|
82
|
+
return this.parentPid ? this.graph.get(this.parentPid) : undefined;
|
|
83
|
+
}
|
|
84
|
+
getChildrenNodes() {
|
|
85
|
+
return this.graph.getChildNodes(this.pid);
|
|
86
|
+
}
|
|
87
|
+
hasAncestor(predicate) {
|
|
88
|
+
return this.graph.hasAncestor(this.pid, predicate);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Procedure graph for tracking parent-child relationships
|
|
93
|
+
*/
|
|
94
|
+
export class ProcedureGraph {
|
|
95
|
+
procedures = new Map();
|
|
96
|
+
childrenMap = new Map(); // parentPid -> Set<childPid>
|
|
97
|
+
rootPid; // Cached root procedure PID
|
|
98
|
+
/**
|
|
99
|
+
* Register a new procedure
|
|
100
|
+
*
|
|
101
|
+
* @param pid Procedure ID
|
|
102
|
+
* @param parentPid Parent procedure ID (undefined for root)
|
|
103
|
+
* @param name Procedure name (e.g., 'model:generate', 'tool:run')
|
|
104
|
+
* @param metadata Optional metadata
|
|
105
|
+
* @param executionId Execution ID this procedure belongs to
|
|
106
|
+
* @param isExecutionBoundary Whether this procedure is an execution entry point
|
|
107
|
+
* @param executionType Type of execution (derived from procedure name prefix)
|
|
108
|
+
*/
|
|
109
|
+
register(pid, parentPid, name, metadata, executionId, isExecutionBoundary, executionType) {
|
|
110
|
+
const node = new ProcedureNode(this, pid, parentPid, name, metadata, executionId, isExecutionBoundary, executionType);
|
|
111
|
+
this.procedures.set(pid, node);
|
|
112
|
+
// Track parent-child relationship
|
|
113
|
+
if (parentPid) {
|
|
114
|
+
if (!this.childrenMap.has(parentPid)) {
|
|
115
|
+
this.childrenMap.set(parentPid, new Set());
|
|
116
|
+
}
|
|
117
|
+
this.childrenMap.get(parentPid).add(pid);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// This is a root procedure - cache it
|
|
121
|
+
this.rootPid = pid;
|
|
122
|
+
}
|
|
123
|
+
return node;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get procedure node by PID
|
|
127
|
+
*/
|
|
128
|
+
get(pid) {
|
|
129
|
+
return this.procedures.get(pid);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get parent PID
|
|
133
|
+
*/
|
|
134
|
+
getParent(pid) {
|
|
135
|
+
return this.procedures.get(pid)?.parentPid;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get parent node
|
|
139
|
+
*/
|
|
140
|
+
getParentNode(pid) {
|
|
141
|
+
const node = this.procedures.get(pid);
|
|
142
|
+
return node?.parentPid ? this.procedures.get(node.parentPid) : undefined;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get child procedure PIDs
|
|
146
|
+
*/
|
|
147
|
+
getChildren(parentPid) {
|
|
148
|
+
const childPids = this.childrenMap.get(parentPid);
|
|
149
|
+
return childPids ? Array.from(childPids) : [];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get child procedure nodes
|
|
153
|
+
*/
|
|
154
|
+
getChildNodes(parentPid) {
|
|
155
|
+
return this.getChildren(parentPid)
|
|
156
|
+
.map((pid) => this.procedures.get(pid))
|
|
157
|
+
.filter((node) => node !== undefined);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Propagate metrics from child to parent
|
|
161
|
+
*/
|
|
162
|
+
propagateMetrics(childPid) {
|
|
163
|
+
const childNode = this.procedures.get(childPid);
|
|
164
|
+
if (!childNode || !childNode.parentPid) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const parentNode = this.procedures.get(childNode.parentPid);
|
|
168
|
+
if (parentNode) {
|
|
169
|
+
parentNode.mergeMetrics(childNode.metrics);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Update procedure status
|
|
174
|
+
*/
|
|
175
|
+
updateStatus(pid, status, error) {
|
|
176
|
+
const node = this.procedures.get(pid);
|
|
177
|
+
if (!node) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (status === "completed") {
|
|
181
|
+
node.complete();
|
|
182
|
+
// Propagate metrics to parent on completion
|
|
183
|
+
this.propagateMetrics(pid);
|
|
184
|
+
}
|
|
185
|
+
else if (status === "failed" && error) {
|
|
186
|
+
node.fail(error);
|
|
187
|
+
// Still propagate metrics even on failure
|
|
188
|
+
this.propagateMetrics(pid);
|
|
189
|
+
}
|
|
190
|
+
else if (status === "cancelled") {
|
|
191
|
+
node.cancel();
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
node.status = status;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Clear all procedures
|
|
199
|
+
*/
|
|
200
|
+
clear() {
|
|
201
|
+
this.procedures.clear();
|
|
202
|
+
this.childrenMap.clear();
|
|
203
|
+
this.rootPid = undefined;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get the root procedure node (O(1) lookup)
|
|
207
|
+
*/
|
|
208
|
+
getRoot() {
|
|
209
|
+
return this.rootPid ? this.procedures.get(this.rootPid) : undefined;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Get the root procedure PID
|
|
213
|
+
*/
|
|
214
|
+
getRootPid() {
|
|
215
|
+
return this.rootPid;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get all procedure nodes
|
|
219
|
+
*/
|
|
220
|
+
getAllNodes() {
|
|
221
|
+
return Array.from(this.procedures.values());
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get count of procedures
|
|
225
|
+
*/
|
|
226
|
+
getCount() {
|
|
227
|
+
return this.procedures.size;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check if any ancestor (parent chain) matches a predicate
|
|
231
|
+
* Traverses up the parent chain starting from the given PID
|
|
232
|
+
*
|
|
233
|
+
* @param pid Starting procedure PID
|
|
234
|
+
* @param predicate Function to test each ancestor node
|
|
235
|
+
* @returns True if any ancestor matches, false otherwise
|
|
236
|
+
*/
|
|
237
|
+
hasAncestor(pid, predicate) {
|
|
238
|
+
const node = this.procedures.get(pid);
|
|
239
|
+
if (!node) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
// Check current node
|
|
243
|
+
if (predicate(node)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
// Traverse up parent chain
|
|
247
|
+
let currentNode = node;
|
|
248
|
+
while (currentNode) {
|
|
249
|
+
const parentNode = currentNode.getParentNode();
|
|
250
|
+
if (!parentNode) {
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
if (predicate(parentNode)) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
currentNode = parentNode;
|
|
257
|
+
}
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Check if any ancestor has a specific procedure name
|
|
262
|
+
* Useful for determining if a procedure was called by Engine vs direct application call
|
|
263
|
+
*
|
|
264
|
+
* @param pid Starting procedure PID
|
|
265
|
+
* @param name Procedure name to search for (e.g., 'engine:execute', 'engine:stream')
|
|
266
|
+
* @returns True if any ancestor has the specified name
|
|
267
|
+
*/
|
|
268
|
+
hasAncestorWithName(pid, name) {
|
|
269
|
+
return this.hasAncestor(pid, (node) => node.name === name);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=procedure-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"procedure-graph.js","sourceRoot":"","sources":["../src/procedure-graph.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,OAAO,aAAa;IACR,GAAG,CAAS;IACZ,SAAS,CAAU;IACnB,IAAI,CAAU;IACvB,MAAM,CAAkB;IACf,SAAS,CAAO;IACzB,WAAW,CAAQ;IACnB,KAAK,CAAS;IACd,QAAQ,CAAuB;IACtB,KAAK,CAAiB;IAEtC,uCAAuC;IAChC,OAAO,GAA2B,EAAE,CAAC;IAE5C,uFAAuF;IACvE,WAAW,CAAS;IACpB,mBAAmB,CAAU;IAC7B,aAAa,CAAU;IAEvC,YACE,KAAqB,EACrB,GAAW,EACX,SAAkB,EAClB,IAAa,EACb,QAA8B,EAC9B,WAAoB,EACpB,mBAA6B,EAC7B,aAAsB;QAEtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,oEAAoE;QACpE,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,GAAG,CAAC;QACtC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,IAAI,KAAK,CAAC;QACxD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;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