@smithers-orchestrator/graph 0.16.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/LICENSE +21 -0
- package/package.json +35 -0
- package/src/AgentLike.ts +1 -0
- package/src/ApprovalOption.ts +1 -0
- package/src/CachePolicy.ts +1 -0
- package/src/ExtractGraph.ts +1 -0
- package/src/ExtractOptions.ts +1 -0
- package/src/ExtractResult.ts +8 -0
- package/src/GraphSnapshot.ts +9 -0
- package/src/HostElement.ts +1 -0
- package/src/HostNode.ts +1 -0
- package/src/HostText.ts +1 -0
- package/src/MemoryNamespace.ts +1 -0
- package/src/MemoryNamespaceKind.ts +1 -0
- package/src/RetryPolicy.ts +1 -0
- package/src/SamplingConfig.ts +1 -0
- package/src/ScoreResult.ts +1 -0
- package/src/Scorer.ts +1 -0
- package/src/ScorerBinding.ts +1 -0
- package/src/ScorerFn.ts +1 -0
- package/src/ScorerInput.ts +1 -0
- package/src/ScorersMap.ts +1 -0
- package/src/TaskDescriptor.ts +1 -0
- package/src/TaskMemoryConfig.ts +1 -0
- package/src/WorkflowGraph.ts +1 -0
- package/src/XmlElement.ts +1 -0
- package/src/XmlNode.ts +1 -0
- package/src/XmlText.ts +1 -0
- package/src/constants.js +5 -0
- package/src/dom/extract.js +796 -0
- package/src/extract.js +616 -0
- package/src/index.d.ts +212 -0
- package/src/index.js +32 -0
- package/src/types.ts +192 -0
- package/src/utils/tree-ids.js +22 -0
- package/src/utils/xml.js +42 -0
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AgentCapabilityRegistry } from '@smithers-orchestrator/agents/capability-registry';
|
|
3
|
+
|
|
4
|
+
type XmlNode$1 = XmlElement$1 | XmlText$1;
|
|
5
|
+
type XmlElement$1 = {
|
|
6
|
+
readonly kind: "element";
|
|
7
|
+
readonly tag: string;
|
|
8
|
+
readonly props: Record<string, string>;
|
|
9
|
+
readonly children: readonly XmlNode$1[];
|
|
10
|
+
};
|
|
11
|
+
type XmlText$1 = {
|
|
12
|
+
readonly kind: "text";
|
|
13
|
+
readonly text: string;
|
|
14
|
+
};
|
|
15
|
+
type HostNode$2 = HostElement$1 | HostText$1;
|
|
16
|
+
type HostElement$1 = {
|
|
17
|
+
readonly kind: "element";
|
|
18
|
+
readonly tag: string;
|
|
19
|
+
readonly props: Record<string, string>;
|
|
20
|
+
readonly rawProps: Record<string, unknown>;
|
|
21
|
+
readonly children: readonly HostNode$2[];
|
|
22
|
+
};
|
|
23
|
+
type HostText$1 = {
|
|
24
|
+
readonly kind: "text";
|
|
25
|
+
readonly text: string;
|
|
26
|
+
};
|
|
27
|
+
type RetryPolicy$1 = {
|
|
28
|
+
backoff?: "fixed" | "linear" | "exponential";
|
|
29
|
+
initialDelayMs?: number;
|
|
30
|
+
maxDelayMs?: number;
|
|
31
|
+
multiplier?: number;
|
|
32
|
+
jitter?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type CachePolicy$1<Ctx = unknown> = {
|
|
35
|
+
by?: (ctx: Ctx) => unknown;
|
|
36
|
+
version?: string;
|
|
37
|
+
key?: string;
|
|
38
|
+
ttlMs?: number;
|
|
39
|
+
scope?: "run" | "workflow" | "global";
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
type AgentLike$1 = {
|
|
43
|
+
id?: string;
|
|
44
|
+
tools?: Record<string, unknown>;
|
|
45
|
+
capabilities?: AgentCapabilityRegistry;
|
|
46
|
+
generate: (args: unknown) => Promise<unknown>;
|
|
47
|
+
};
|
|
48
|
+
type ScoreResult$1 = {
|
|
49
|
+
score: number;
|
|
50
|
+
reason?: string;
|
|
51
|
+
meta?: Record<string, unknown>;
|
|
52
|
+
};
|
|
53
|
+
type ScorerInput$1 = {
|
|
54
|
+
input: unknown;
|
|
55
|
+
output: unknown;
|
|
56
|
+
groundTruth?: unknown;
|
|
57
|
+
context?: unknown;
|
|
58
|
+
latencyMs?: number;
|
|
59
|
+
outputSchema?: z.ZodObject;
|
|
60
|
+
};
|
|
61
|
+
type ScorerFn$1 = (input: ScorerInput$1) => Promise<ScoreResult$1>;
|
|
62
|
+
type Scorer$1 = {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
score: ScorerFn$1;
|
|
67
|
+
};
|
|
68
|
+
type SamplingConfig$1 = {
|
|
69
|
+
type: "all";
|
|
70
|
+
} | {
|
|
71
|
+
type: "ratio";
|
|
72
|
+
rate: number;
|
|
73
|
+
} | {
|
|
74
|
+
type: "none";
|
|
75
|
+
};
|
|
76
|
+
type ScorerBinding$1 = {
|
|
77
|
+
scorer: Scorer$1;
|
|
78
|
+
sampling?: SamplingConfig$1;
|
|
79
|
+
};
|
|
80
|
+
type ScorersMap$1 = Record<string, unknown>;
|
|
81
|
+
type MemoryNamespaceKind$1 = "workflow" | "agent" | "user" | "global";
|
|
82
|
+
type MemoryNamespace$1 = {
|
|
83
|
+
kind: MemoryNamespaceKind$1;
|
|
84
|
+
id: string;
|
|
85
|
+
};
|
|
86
|
+
type TaskMemoryConfig$1 = {
|
|
87
|
+
recall?: {
|
|
88
|
+
namespace?: MemoryNamespace$1;
|
|
89
|
+
query?: string;
|
|
90
|
+
topK?: number;
|
|
91
|
+
};
|
|
92
|
+
remember?: {
|
|
93
|
+
namespace?: MemoryNamespace$1;
|
|
94
|
+
key?: string;
|
|
95
|
+
};
|
|
96
|
+
threadId?: string;
|
|
97
|
+
};
|
|
98
|
+
type ApprovalOption$1 = {
|
|
99
|
+
key: string;
|
|
100
|
+
label: string;
|
|
101
|
+
summary?: string;
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
};
|
|
104
|
+
type TaskDescriptor$1 = {
|
|
105
|
+
nodeId: string;
|
|
106
|
+
ordinal: number;
|
|
107
|
+
iteration: number;
|
|
108
|
+
ralphId?: string;
|
|
109
|
+
dependsOn?: string[];
|
|
110
|
+
needs?: Record<string, string>;
|
|
111
|
+
worktreeId?: string;
|
|
112
|
+
worktreePath?: string;
|
|
113
|
+
worktreeBranch?: string;
|
|
114
|
+
worktreeBaseBranch?: string;
|
|
115
|
+
outputTable: unknown | null;
|
|
116
|
+
outputTableName: string;
|
|
117
|
+
outputRef?: z.ZodObject;
|
|
118
|
+
outputSchema?: z.ZodObject;
|
|
119
|
+
parallelGroupId?: string;
|
|
120
|
+
parallelMaxConcurrency?: number;
|
|
121
|
+
needsApproval: boolean;
|
|
122
|
+
waitAsync?: boolean;
|
|
123
|
+
approvalMode?: "gate" | "decision" | "select" | "rank";
|
|
124
|
+
approvalOnDeny?: "fail" | "continue" | "skip";
|
|
125
|
+
approvalOptions?: ApprovalOption$1[];
|
|
126
|
+
approvalAllowedScopes?: string[];
|
|
127
|
+
approvalAllowedUsers?: string[];
|
|
128
|
+
approvalAutoApprove?: {
|
|
129
|
+
after?: number;
|
|
130
|
+
audit?: boolean;
|
|
131
|
+
conditionMet?: boolean;
|
|
132
|
+
revertOnMet?: boolean;
|
|
133
|
+
};
|
|
134
|
+
skipIf: boolean;
|
|
135
|
+
retries: number;
|
|
136
|
+
retryPolicy?: RetryPolicy$1;
|
|
137
|
+
timeoutMs: number | null;
|
|
138
|
+
heartbeatTimeoutMs: number | null;
|
|
139
|
+
continueOnFail: boolean;
|
|
140
|
+
cachePolicy?: CachePolicy$1;
|
|
141
|
+
agent?: AgentLike$1 | AgentLike$1[];
|
|
142
|
+
prompt?: string;
|
|
143
|
+
staticPayload?: unknown;
|
|
144
|
+
computeFn?: () => unknown | Promise<unknown>;
|
|
145
|
+
label?: string;
|
|
146
|
+
meta?: Record<string, unknown>;
|
|
147
|
+
scorers?: ScorersMap$1;
|
|
148
|
+
memoryConfig?: TaskMemoryConfig$1;
|
|
149
|
+
};
|
|
150
|
+
type WorkflowGraph$2 = {
|
|
151
|
+
readonly xml: XmlNode$1 | null;
|
|
152
|
+
readonly tasks: readonly TaskDescriptor$1[];
|
|
153
|
+
readonly mountedTaskIds: readonly string[];
|
|
154
|
+
};
|
|
155
|
+
type ExtractOptions$2 = {
|
|
156
|
+
readonly ralphIterations?: ReadonlyMap<string, number> | Record<string, number>;
|
|
157
|
+
readonly defaultIteration?: number;
|
|
158
|
+
readonly baseRootDir?: string;
|
|
159
|
+
readonly workflowPath?: string | null;
|
|
160
|
+
};
|
|
161
|
+
type ExtractGraph$1 = (root: HostNode$2 | null, opts?: ExtractOptions$2) => WorkflowGraph$2 | Promise<WorkflowGraph$2>;
|
|
162
|
+
|
|
163
|
+
type GraphSnapshot$1 = {
|
|
164
|
+
runId: string;
|
|
165
|
+
frameNo: number;
|
|
166
|
+
xml: XmlNode$1 | null;
|
|
167
|
+
tasks: TaskDescriptor$1[];
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {HostNode | null} root
|
|
172
|
+
* @param {ExtractOptions} [opts]
|
|
173
|
+
* @returns {WorkflowGraph}
|
|
174
|
+
*/
|
|
175
|
+
declare function extractGraph(root: HostNode$1 | null, opts?: ExtractOptions$1): WorkflowGraph$1;
|
|
176
|
+
/**
|
|
177
|
+
* @param {HostNode | null} root
|
|
178
|
+
* @param {ExtractOptions} [opts]
|
|
179
|
+
* @returns {WorkflowGraph}
|
|
180
|
+
*/
|
|
181
|
+
declare function extractFromHost(root: HostNode$1 | null, opts?: ExtractOptions$1): WorkflowGraph$1;
|
|
182
|
+
type ExtractOptions$1 = ExtractOptions$2;
|
|
183
|
+
type HostNode$1 = HostNode$2;
|
|
184
|
+
type WorkflowGraph$1 = WorkflowGraph$2;
|
|
185
|
+
|
|
186
|
+
type AgentLike = AgentLike$1;
|
|
187
|
+
type ApprovalOption = ApprovalOption$1;
|
|
188
|
+
type CachePolicy<Ctx = any> = CachePolicy$1<Ctx>;
|
|
189
|
+
type ExtractGraph = ExtractGraph$1;
|
|
190
|
+
type ExtractOptions = ExtractOptions$2;
|
|
191
|
+
type GraphSnapshot = GraphSnapshot$1;
|
|
192
|
+
type HostElement = HostElement$1;
|
|
193
|
+
type HostNode = HostNode$2;
|
|
194
|
+
type HostText = HostText$1;
|
|
195
|
+
type MemoryNamespace = MemoryNamespace$1;
|
|
196
|
+
type MemoryNamespaceKind = MemoryNamespaceKind$1;
|
|
197
|
+
type RetryPolicy = RetryPolicy$1;
|
|
198
|
+
type SamplingConfig = SamplingConfig$1;
|
|
199
|
+
type ScoreResult = ScoreResult$1;
|
|
200
|
+
type Scorer = Scorer$1;
|
|
201
|
+
type ScorerBinding = ScorerBinding$1;
|
|
202
|
+
type ScorerFn = ScorerFn$1;
|
|
203
|
+
type ScorerInput = ScorerInput$1;
|
|
204
|
+
type ScorersMap = ScorersMap$1;
|
|
205
|
+
type TaskDescriptor = TaskDescriptor$1;
|
|
206
|
+
type TaskMemoryConfig = TaskMemoryConfig$1;
|
|
207
|
+
type WorkflowGraph = WorkflowGraph$2;
|
|
208
|
+
type XmlElement = XmlElement$1;
|
|
209
|
+
type XmlNode = XmlNode$1;
|
|
210
|
+
type XmlText = XmlText$1;
|
|
211
|
+
|
|
212
|
+
export { type AgentLike, type ApprovalOption, type CachePolicy, type ExtractGraph, type ExtractOptions, type GraphSnapshot, type HostElement, type HostNode, type HostText, type MemoryNamespace, type MemoryNamespaceKind, type RetryPolicy, type SamplingConfig, type ScoreResult, type Scorer, type ScorerBinding, type ScorerFn, type ScorerInput, type ScorersMap, type TaskDescriptor, type TaskMemoryConfig, type WorkflowGraph, type XmlElement, type XmlNode, type XmlText, extractFromHost, extractGraph };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// @smithers-type-exports-begin
|
|
2
|
+
/** @typedef {import("./AgentLike.ts").AgentLike} AgentLike */
|
|
3
|
+
/** @typedef {import("./ApprovalOption.ts").ApprovalOption} ApprovalOption */
|
|
4
|
+
/**
|
|
5
|
+
* @template [Ctx=any]
|
|
6
|
+
* @typedef {import("./CachePolicy.ts").CachePolicy<Ctx>} CachePolicy
|
|
7
|
+
*/
|
|
8
|
+
/** @typedef {import("./ExtractGraph.ts").ExtractGraph} ExtractGraph */
|
|
9
|
+
/** @typedef {import("./ExtractOptions.ts").ExtractOptions} ExtractOptions */
|
|
10
|
+
/** @typedef {import("./GraphSnapshot.ts").GraphSnapshot} GraphSnapshot */
|
|
11
|
+
/** @typedef {import("./HostElement.ts").HostElement} HostElement */
|
|
12
|
+
/** @typedef {import("./HostNode.ts").HostNode} HostNode */
|
|
13
|
+
/** @typedef {import("./HostText.ts").HostText} HostText */
|
|
14
|
+
/** @typedef {import("./MemoryNamespace.ts").MemoryNamespace} MemoryNamespace */
|
|
15
|
+
/** @typedef {import("./MemoryNamespaceKind.ts").MemoryNamespaceKind} MemoryNamespaceKind */
|
|
16
|
+
/** @typedef {import("./RetryPolicy.ts").RetryPolicy} RetryPolicy */
|
|
17
|
+
/** @typedef {import("./SamplingConfig.ts").SamplingConfig} SamplingConfig */
|
|
18
|
+
/** @typedef {import("./ScoreResult.ts").ScoreResult} ScoreResult */
|
|
19
|
+
/** @typedef {import("./Scorer.ts").Scorer} Scorer */
|
|
20
|
+
/** @typedef {import("./ScorerBinding.ts").ScorerBinding} ScorerBinding */
|
|
21
|
+
/** @typedef {import("./ScorerFn.ts").ScorerFn} ScorerFn */
|
|
22
|
+
/** @typedef {import("./ScorerInput.ts").ScorerInput} ScorerInput */
|
|
23
|
+
/** @typedef {import("./ScorersMap.ts").ScorersMap} ScorersMap */
|
|
24
|
+
/** @typedef {import("./TaskDescriptor.ts").TaskDescriptor} TaskDescriptor */
|
|
25
|
+
/** @typedef {import("./TaskMemoryConfig.ts").TaskMemoryConfig} TaskMemoryConfig */
|
|
26
|
+
/** @typedef {import("./WorkflowGraph.ts").WorkflowGraph} WorkflowGraph */
|
|
27
|
+
/** @typedef {import("./XmlElement.ts").XmlElement} XmlElement */
|
|
28
|
+
/** @typedef {import("./XmlNode.ts").XmlNode} XmlNode */
|
|
29
|
+
/** @typedef {import("./XmlText.ts").XmlText} XmlText */
|
|
30
|
+
// @smithers-type-exports-end
|
|
31
|
+
|
|
32
|
+
export * from "./extract.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { AgentCapabilityRegistry } from "@smithers-orchestrator/agents/capability-registry";
|
|
3
|
+
|
|
4
|
+
export type XmlNode = XmlElement | XmlText;
|
|
5
|
+
|
|
6
|
+
export type XmlElement = {
|
|
7
|
+
readonly kind: "element";
|
|
8
|
+
readonly tag: string;
|
|
9
|
+
readonly props: Record<string, string>;
|
|
10
|
+
readonly children: readonly XmlNode[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type XmlText = {
|
|
14
|
+
readonly kind: "text";
|
|
15
|
+
readonly text: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type HostNode = HostElement | HostText;
|
|
19
|
+
|
|
20
|
+
export type HostElement = {
|
|
21
|
+
readonly kind: "element";
|
|
22
|
+
readonly tag: string;
|
|
23
|
+
readonly props: Record<string, string>;
|
|
24
|
+
readonly rawProps: Record<string, unknown>;
|
|
25
|
+
readonly children: readonly HostNode[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type HostText = {
|
|
29
|
+
readonly kind: "text";
|
|
30
|
+
readonly text: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type RetryPolicy = {
|
|
34
|
+
backoff?: "fixed" | "linear" | "exponential";
|
|
35
|
+
initialDelayMs?: number;
|
|
36
|
+
maxDelayMs?: number;
|
|
37
|
+
multiplier?: number;
|
|
38
|
+
jitter?: boolean;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CachePolicy<Ctx = unknown> = {
|
|
42
|
+
by?: (ctx: Ctx) => unknown;
|
|
43
|
+
version?: string;
|
|
44
|
+
key?: string;
|
|
45
|
+
ttlMs?: number;
|
|
46
|
+
scope?: "run" | "workflow" | "global";
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export type AgentLike = {
|
|
52
|
+
id?: string;
|
|
53
|
+
tools?: Record<string, unknown>;
|
|
54
|
+
capabilities?: AgentCapabilityRegistry;
|
|
55
|
+
generate: (args: unknown) => Promise<unknown>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type ScoreResult = {
|
|
59
|
+
score: number;
|
|
60
|
+
reason?: string;
|
|
61
|
+
meta?: Record<string, unknown>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type ScorerInput = {
|
|
65
|
+
input: unknown;
|
|
66
|
+
output: unknown;
|
|
67
|
+
groundTruth?: unknown;
|
|
68
|
+
context?: unknown;
|
|
69
|
+
latencyMs?: number;
|
|
70
|
+
outputSchema?: z.ZodObject;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type ScorerFn = (input: ScorerInput) => Promise<ScoreResult>;
|
|
74
|
+
|
|
75
|
+
export type Scorer = {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
score: ScorerFn;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type SamplingConfig =
|
|
83
|
+
| { type: "all" }
|
|
84
|
+
| { type: "ratio"; rate: number }
|
|
85
|
+
| { type: "none" };
|
|
86
|
+
|
|
87
|
+
export type ScorerBinding = {
|
|
88
|
+
scorer: Scorer;
|
|
89
|
+
sampling?: SamplingConfig;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type ScorersMap = Record<string, unknown>;
|
|
93
|
+
|
|
94
|
+
export type MemoryNamespaceKind = "workflow" | "agent" | "user" | "global";
|
|
95
|
+
|
|
96
|
+
export type MemoryNamespace = {
|
|
97
|
+
kind: MemoryNamespaceKind;
|
|
98
|
+
id: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type TaskMemoryConfig = {
|
|
102
|
+
recall?: {
|
|
103
|
+
namespace?: MemoryNamespace;
|
|
104
|
+
query?: string;
|
|
105
|
+
topK?: number;
|
|
106
|
+
};
|
|
107
|
+
remember?: {
|
|
108
|
+
namespace?: MemoryNamespace;
|
|
109
|
+
key?: string;
|
|
110
|
+
};
|
|
111
|
+
threadId?: string;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type ApprovalOption = {
|
|
115
|
+
key: string;
|
|
116
|
+
label: string;
|
|
117
|
+
summary?: string;
|
|
118
|
+
metadata?: Record<string, unknown>;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export type TaskDescriptor = {
|
|
122
|
+
nodeId: string;
|
|
123
|
+
ordinal: number;
|
|
124
|
+
iteration: number;
|
|
125
|
+
ralphId?: string;
|
|
126
|
+
dependsOn?: string[];
|
|
127
|
+
needs?: Record<string, string>;
|
|
128
|
+
worktreeId?: string;
|
|
129
|
+
worktreePath?: string;
|
|
130
|
+
worktreeBranch?: string;
|
|
131
|
+
worktreeBaseBranch?: string;
|
|
132
|
+
outputTable: unknown | null;
|
|
133
|
+
outputTableName: string;
|
|
134
|
+
outputRef?: z.ZodObject;
|
|
135
|
+
outputSchema?: z.ZodObject;
|
|
136
|
+
parallelGroupId?: string;
|
|
137
|
+
parallelMaxConcurrency?: number;
|
|
138
|
+
needsApproval: boolean;
|
|
139
|
+
waitAsync?: boolean;
|
|
140
|
+
approvalMode?: "gate" | "decision" | "select" | "rank";
|
|
141
|
+
approvalOnDeny?: "fail" | "continue" | "skip";
|
|
142
|
+
approvalOptions?: ApprovalOption[];
|
|
143
|
+
approvalAllowedScopes?: string[];
|
|
144
|
+
approvalAllowedUsers?: string[];
|
|
145
|
+
approvalAutoApprove?: {
|
|
146
|
+
after?: number;
|
|
147
|
+
audit?: boolean;
|
|
148
|
+
conditionMet?: boolean;
|
|
149
|
+
revertOnMet?: boolean;
|
|
150
|
+
};
|
|
151
|
+
skipIf: boolean;
|
|
152
|
+
retries: number;
|
|
153
|
+
retryPolicy?: RetryPolicy;
|
|
154
|
+
timeoutMs: number | null;
|
|
155
|
+
heartbeatTimeoutMs: number | null;
|
|
156
|
+
continueOnFail: boolean;
|
|
157
|
+
cachePolicy?: CachePolicy;
|
|
158
|
+
agent?: AgentLike | AgentLike[];
|
|
159
|
+
prompt?: string;
|
|
160
|
+
staticPayload?: unknown;
|
|
161
|
+
computeFn?: () => unknown | Promise<unknown>;
|
|
162
|
+
label?: string;
|
|
163
|
+
meta?: Record<string, unknown>;
|
|
164
|
+
scorers?: ScorersMap;
|
|
165
|
+
|
|
166
|
+
memoryConfig?: TaskMemoryConfig;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export type WorkflowGraph = {
|
|
170
|
+
readonly xml: XmlNode | null;
|
|
171
|
+
readonly tasks: readonly TaskDescriptor[];
|
|
172
|
+
readonly mountedTaskIds: readonly string[];
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type GraphSnapshot = {
|
|
176
|
+
readonly runId: string;
|
|
177
|
+
readonly frameNo: number;
|
|
178
|
+
readonly xml: XmlNode | null;
|
|
179
|
+
readonly tasks: readonly TaskDescriptor[];
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export type ExtractOptions = {
|
|
183
|
+
readonly ralphIterations?: ReadonlyMap<string, number> | Record<string, number>;
|
|
184
|
+
readonly defaultIteration?: number;
|
|
185
|
+
readonly baseRootDir?: string;
|
|
186
|
+
readonly workflowPath?: string | null;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type ExtractGraph = (
|
|
190
|
+
root: HostNode | null,
|
|
191
|
+
opts?: ExtractOptions,
|
|
192
|
+
) => WorkflowGraph | Promise<WorkflowGraph>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} prefix
|
|
3
|
+
* @param {number[]} path
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function stablePathId(prefix, path) {
|
|
7
|
+
if (path.length === 0)
|
|
8
|
+
return `${prefix}:root`;
|
|
9
|
+
return `${prefix}:${path.join(".")}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @param {unknown} explicitId
|
|
13
|
+
* @param {string} prefix
|
|
14
|
+
* @param {number[]} path
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function resolveStableId(explicitId, prefix, path) {
|
|
18
|
+
if (typeof explicitId === "string" && explicitId.trim().length > 0) {
|
|
19
|
+
return explicitId;
|
|
20
|
+
}
|
|
21
|
+
return stablePathId(prefix, path);
|
|
22
|
+
}
|
package/src/utils/xml.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
/** @typedef {import("../XmlNode.ts").XmlNode} XmlNode */
|
|
3
|
+
/**
|
|
4
|
+
* @param {Record<string, string>} props
|
|
5
|
+
* @returns {Record<string, string>}
|
|
6
|
+
*/
|
|
7
|
+
function sortProps(props) {
|
|
8
|
+
const entries = Object.entries(props).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
9
|
+
return Object.fromEntries(entries);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @param {XmlNode} node
|
|
13
|
+
* @returns {unknown}
|
|
14
|
+
*/
|
|
15
|
+
function canonicalizeNode(node) {
|
|
16
|
+
if (node.kind === "text") {
|
|
17
|
+
return { kind: "text", text: node.text };
|
|
18
|
+
}
|
|
19
|
+
const element = node;
|
|
20
|
+
return {
|
|
21
|
+
kind: "element",
|
|
22
|
+
tag: element.tag,
|
|
23
|
+
props: sortProps(element.props ?? {}),
|
|
24
|
+
children: element.children.map(canonicalizeNode),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @param {XmlNode | null} node
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function canonicalizeXml(node) {
|
|
32
|
+
if (!node)
|
|
33
|
+
return "null";
|
|
34
|
+
return JSON.stringify(canonicalizeNode(node));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} json
|
|
38
|
+
* @returns {XmlNode | null}
|
|
39
|
+
*/
|
|
40
|
+
export function parseXmlJson(json) {
|
|
41
|
+
return JSON.parse(json);
|
|
42
|
+
}
|