@d34dman/flowdrop 0.0.56 → 0.0.57
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/adapters/agentspec/AgentSpecAdapter.d.ts +92 -0
- package/dist/adapters/agentspec/AgentSpecAdapter.js +658 -0
- package/dist/adapters/agentspec/agentAdapter.d.ts +59 -0
- package/dist/adapters/agentspec/agentAdapter.js +91 -0
- package/dist/adapters/agentspec/autoLayout.d.ts +34 -0
- package/dist/adapters/agentspec/autoLayout.js +127 -0
- package/dist/adapters/agentspec/index.d.ts +35 -0
- package/dist/adapters/agentspec/index.js +37 -0
- package/dist/adapters/agentspec/nodeTypeRegistry.d.ts +62 -0
- package/dist/adapters/agentspec/nodeTypeRegistry.js +589 -0
- package/dist/adapters/agentspec/validator.d.ts +34 -0
- package/dist/adapters/agentspec/validator.js +169 -0
- package/dist/components/ConfigForm.svelte +46 -12
- package/dist/components/ConfigForm.svelte.d.ts +8 -0
- package/dist/components/SchemaForm.svelte +34 -12
- package/dist/components/SchemaForm.svelte.d.ts +8 -0
- package/dist/components/form/FormFieldset.svelte +142 -0
- package/dist/components/form/FormFieldset.svelte.d.ts +11 -0
- package/dist/components/form/FormUISchemaRenderer.svelte +140 -0
- package/dist/components/form/FormUISchemaRenderer.svelte.d.ts +32 -0
- package/dist/components/form/index.d.ts +2 -0
- package/dist/components/form/index.js +3 -0
- package/dist/config/agentSpecEndpoints.d.ts +70 -0
- package/dist/config/agentSpecEndpoints.js +65 -0
- package/dist/config/endpoints.d.ts +6 -0
- package/dist/core/index.d.ts +17 -1
- package/dist/core/index.js +17 -0
- package/dist/form/index.d.ts +2 -0
- package/dist/form/index.js +3 -0
- package/dist/helpers/workflowEditorHelper.d.ts +24 -0
- package/dist/helpers/workflowEditorHelper.js +55 -0
- package/dist/services/agentSpecExecutionService.d.ts +106 -0
- package/dist/services/agentSpecExecutionService.js +333 -0
- package/dist/types/agentspec.d.ts +318 -0
- package/dist/types/agentspec.js +48 -0
- package/dist/types/events.d.ts +28 -1
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.js +1 -0
- package/dist/types/uischema.d.ts +144 -0
- package/dist/types/uischema.js +51 -0
- package/dist/utils/uischema.d.ts +52 -0
- package/dist/utils/uischema.js +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Spec Execution Service
|
|
3
|
+
*
|
|
4
|
+
* Connects FlowDrop to Agent Spec runtimes (WayFlow/PyAgentSpec) for
|
|
5
|
+
* workflow execution, status tracking, and result retrieval.
|
|
6
|
+
*
|
|
7
|
+
* Follows the same singleton pattern as NodeExecutionService.
|
|
8
|
+
*/
|
|
9
|
+
import { buildAgentSpecUrl, getAgentSpecAuthHeaders } from '../config/agentSpecEndpoints.js';
|
|
10
|
+
import { AgentSpecAdapter } from '../adapters/agentspec/AgentSpecAdapter.js';
|
|
11
|
+
/**
|
|
12
|
+
* Service for executing FlowDrop workflows on Agent Spec runtimes.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const service = AgentSpecExecutionService.getInstance();
|
|
17
|
+
* service.configure(myRuntimeConfig);
|
|
18
|
+
*
|
|
19
|
+
* // Check runtime availability
|
|
20
|
+
* const healthy = await service.checkHealth();
|
|
21
|
+
*
|
|
22
|
+
* // Execute a workflow
|
|
23
|
+
* const handle = await service.executeWorkflow(workflow, inputs, {
|
|
24
|
+
* onNodeUpdate: (nodeId, info) => updateNodeVisual(nodeId, info),
|
|
25
|
+
* onComplete: (results) => showResults(results),
|
|
26
|
+
* onError: (error) => showError(error)
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Cancel if needed
|
|
30
|
+
* await service.cancelExecution(handle.executionId);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export class AgentSpecExecutionService {
|
|
34
|
+
static instance;
|
|
35
|
+
config = null;
|
|
36
|
+
adapter;
|
|
37
|
+
activeExecutions = new Map();
|
|
38
|
+
constructor() {
|
|
39
|
+
this.adapter = new AgentSpecAdapter();
|
|
40
|
+
}
|
|
41
|
+
static getInstance() {
|
|
42
|
+
if (!AgentSpecExecutionService.instance) {
|
|
43
|
+
AgentSpecExecutionService.instance = new AgentSpecExecutionService();
|
|
44
|
+
}
|
|
45
|
+
return AgentSpecExecutionService.instance;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Configure the runtime connection.
|
|
49
|
+
*/
|
|
50
|
+
configure(config) {
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if the service has been configured with a runtime.
|
|
55
|
+
*/
|
|
56
|
+
isConfigured() {
|
|
57
|
+
return this.config !== null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check runtime health.
|
|
61
|
+
*/
|
|
62
|
+
async checkHealth() {
|
|
63
|
+
if (!this.config)
|
|
64
|
+
return false;
|
|
65
|
+
try {
|
|
66
|
+
const url = buildAgentSpecUrl(this.config, this.config.endpoints.health);
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
headers: getAgentSpecAuthHeaders(this.config),
|
|
69
|
+
signal: AbortSignal.timeout(5000)
|
|
70
|
+
});
|
|
71
|
+
return response.ok;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Execute a FlowDrop workflow on the Agent Spec runtime.
|
|
79
|
+
*
|
|
80
|
+
* 1. Converts StandardWorkflow → AgentSpecFlow using the adapter
|
|
81
|
+
* 2. POSTs the flow JSON to the runtime
|
|
82
|
+
* 3. Starts polling for execution status
|
|
83
|
+
* 4. Maps runtime node statuses to FlowDrop's NodeExecutionInfo
|
|
84
|
+
*/
|
|
85
|
+
async executeWorkflow(workflow, inputs, callbacks, pollingIntervalMs = 2000) {
|
|
86
|
+
this.ensureConfigured();
|
|
87
|
+
// Convert to Agent Spec format
|
|
88
|
+
const agentSpecFlow = this.adapter.toAgentSpec(workflow);
|
|
89
|
+
// POST to runtime
|
|
90
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.execute);
|
|
91
|
+
const response = await fetch(url, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: getAgentSpecAuthHeaders(this.getConfig()),
|
|
94
|
+
body: JSON.stringify({
|
|
95
|
+
flow: agentSpecFlow,
|
|
96
|
+
inputs: inputs || {}
|
|
97
|
+
}),
|
|
98
|
+
signal: AbortSignal.timeout(this.getConfig().timeout || 60000)
|
|
99
|
+
});
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
102
|
+
throw new Error(`Agent Spec runtime error (${response.status}): ${errorText}`);
|
|
103
|
+
}
|
|
104
|
+
const result = await response.json();
|
|
105
|
+
const executionId = result.execution_id || result.id;
|
|
106
|
+
if (!executionId) {
|
|
107
|
+
throw new Error('Runtime did not return an execution ID');
|
|
108
|
+
}
|
|
109
|
+
// Track execution
|
|
110
|
+
const state = {
|
|
111
|
+
id: executionId,
|
|
112
|
+
status: 'running',
|
|
113
|
+
startedAt: new Date().toISOString(),
|
|
114
|
+
nodeStatuses: {}
|
|
115
|
+
};
|
|
116
|
+
this.activeExecutions.set(executionId, state);
|
|
117
|
+
// Build node name → FlowDrop node ID mapping for status updates
|
|
118
|
+
const nameToNodeId = new Map();
|
|
119
|
+
for (const node of workflow.nodes) {
|
|
120
|
+
const label = node.data.label || node.id;
|
|
121
|
+
nameToNodeId.set(label, node.id);
|
|
122
|
+
}
|
|
123
|
+
// Start polling
|
|
124
|
+
const stop = () => this.stopPolling(executionId);
|
|
125
|
+
if (callbacks) {
|
|
126
|
+
this.startPolling(executionId, nameToNodeId, callbacks.onNodeUpdate, callbacks.onComplete, callbacks.onError, pollingIntervalMs);
|
|
127
|
+
}
|
|
128
|
+
return { executionId, stop };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get current execution status.
|
|
132
|
+
*/
|
|
133
|
+
async getExecutionStatus(executionId) {
|
|
134
|
+
this.ensureConfigured();
|
|
135
|
+
try {
|
|
136
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.status, {
|
|
137
|
+
id: executionId
|
|
138
|
+
});
|
|
139
|
+
const response = await fetch(url, {
|
|
140
|
+
headers: getAgentSpecAuthHeaders(this.getConfig())
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok)
|
|
143
|
+
return null;
|
|
144
|
+
const data = await response.json();
|
|
145
|
+
return this.mapRuntimeStatusToNodeInfo(data);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Cancel a running execution.
|
|
153
|
+
*/
|
|
154
|
+
async cancelExecution(executionId) {
|
|
155
|
+
this.ensureConfigured();
|
|
156
|
+
this.stopPolling(executionId);
|
|
157
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.cancel, {
|
|
158
|
+
id: executionId
|
|
159
|
+
});
|
|
160
|
+
await fetch(url, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: getAgentSpecAuthHeaders(this.getConfig())
|
|
163
|
+
});
|
|
164
|
+
const state = this.activeExecutions.get(executionId);
|
|
165
|
+
if (state) {
|
|
166
|
+
state.status = 'cancelled';
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get execution results.
|
|
171
|
+
*/
|
|
172
|
+
async getResults(executionId) {
|
|
173
|
+
this.ensureConfigured();
|
|
174
|
+
try {
|
|
175
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.results, {
|
|
176
|
+
id: executionId
|
|
177
|
+
});
|
|
178
|
+
const response = await fetch(url, {
|
|
179
|
+
headers: getAgentSpecAuthHeaders(this.getConfig())
|
|
180
|
+
});
|
|
181
|
+
if (!response.ok)
|
|
182
|
+
return null;
|
|
183
|
+
return await response.json();
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Validate a workflow against the runtime.
|
|
191
|
+
*/
|
|
192
|
+
async validateOnRuntime(workflow) {
|
|
193
|
+
this.ensureConfigured();
|
|
194
|
+
const agentSpecFlow = this.adapter.toAgentSpec(workflow);
|
|
195
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.validate);
|
|
196
|
+
const response = await fetch(url, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers: getAgentSpecAuthHeaders(this.getConfig()),
|
|
199
|
+
body: JSON.stringify(agentSpecFlow)
|
|
200
|
+
});
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
return { valid: false, errors: [`Runtime validation failed: ${response.status}`] };
|
|
203
|
+
}
|
|
204
|
+
return await response.json();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Clean up all active executions.
|
|
208
|
+
*/
|
|
209
|
+
destroy() {
|
|
210
|
+
for (const [id] of this.activeExecutions) {
|
|
211
|
+
this.stopPolling(id);
|
|
212
|
+
}
|
|
213
|
+
this.activeExecutions.clear();
|
|
214
|
+
}
|
|
215
|
+
// ========================================================================
|
|
216
|
+
// Private
|
|
217
|
+
// ========================================================================
|
|
218
|
+
ensureConfigured() {
|
|
219
|
+
if (!this.config) {
|
|
220
|
+
throw new Error('AgentSpecExecutionService not configured. Call configure() with runtime endpoint config first.');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Get the config, throwing if not configured */
|
|
224
|
+
getConfig() {
|
|
225
|
+
this.ensureConfigured();
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
227
|
+
return this.config;
|
|
228
|
+
}
|
|
229
|
+
startPolling(executionId, nameToNodeId, onNodeUpdate, onComplete, onError, intervalMs = 2000) {
|
|
230
|
+
const state = this.activeExecutions.get(executionId);
|
|
231
|
+
if (!state)
|
|
232
|
+
return;
|
|
233
|
+
const poll = async () => {
|
|
234
|
+
try {
|
|
235
|
+
const url = buildAgentSpecUrl(this.getConfig(), this.getConfig().endpoints.status, {
|
|
236
|
+
id: executionId
|
|
237
|
+
});
|
|
238
|
+
const response = await fetch(url, {
|
|
239
|
+
headers: getAgentSpecAuthHeaders(this.getConfig())
|
|
240
|
+
});
|
|
241
|
+
if (!response.ok) {
|
|
242
|
+
throw new Error(`Status check failed: ${response.status}`);
|
|
243
|
+
}
|
|
244
|
+
const data = await response.json();
|
|
245
|
+
const executionStatus = data.status || data.execution_status;
|
|
246
|
+
// Map node statuses
|
|
247
|
+
const nodeStatuses = data.node_statuses || data.nodes || {};
|
|
248
|
+
for (const [nodeName, status] of Object.entries(nodeStatuses)) {
|
|
249
|
+
const nodeId = nameToNodeId.get(nodeName) || nodeName;
|
|
250
|
+
const info = this.mapSingleNodeStatus(status);
|
|
251
|
+
state.nodeStatuses[nodeId] = info;
|
|
252
|
+
onNodeUpdate?.(nodeId, info);
|
|
253
|
+
}
|
|
254
|
+
// Check if execution is done
|
|
255
|
+
if (executionStatus === 'completed' || executionStatus === 'success') {
|
|
256
|
+
state.status = 'completed';
|
|
257
|
+
this.stopPolling(executionId);
|
|
258
|
+
const results = await this.getResults(executionId);
|
|
259
|
+
onComplete?.(results || {});
|
|
260
|
+
}
|
|
261
|
+
else if (executionStatus === 'failed' || executionStatus === 'error') {
|
|
262
|
+
state.status = 'failed';
|
|
263
|
+
this.stopPolling(executionId);
|
|
264
|
+
const errorMsg = data.error || data.message || 'Execution failed';
|
|
265
|
+
onError?.(new Error(errorMsg));
|
|
266
|
+
}
|
|
267
|
+
else if (executionStatus === 'cancelled') {
|
|
268
|
+
state.status = 'cancelled';
|
|
269
|
+
this.stopPolling(executionId);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
// Don't stop polling on transient errors — let it retry
|
|
274
|
+
console.error('[AgentSpecExecution] Polling error:', error);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
// Initial poll immediately, then at interval
|
|
278
|
+
poll();
|
|
279
|
+
state.pollingInterval = setInterval(poll, intervalMs);
|
|
280
|
+
}
|
|
281
|
+
stopPolling(executionId) {
|
|
282
|
+
const state = this.activeExecutions.get(executionId);
|
|
283
|
+
if (state?.pollingInterval) {
|
|
284
|
+
clearInterval(state.pollingInterval);
|
|
285
|
+
state.pollingInterval = undefined;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
mapRuntimeStatusToNodeInfo(data) {
|
|
289
|
+
const result = {};
|
|
290
|
+
const nodeStatuses = (data.node_statuses || data.nodes || {});
|
|
291
|
+
for (const [nodeName, status] of Object.entries(nodeStatuses)) {
|
|
292
|
+
result[nodeName] = this.mapSingleNodeStatus(status);
|
|
293
|
+
}
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
mapSingleNodeStatus(status) {
|
|
297
|
+
const runtimeStatus = (status.status || status.state || 'idle');
|
|
298
|
+
return {
|
|
299
|
+
status: this.mapToFlowDropStatus(runtimeStatus),
|
|
300
|
+
executionCount: status.execution_count || 0,
|
|
301
|
+
isExecuting: runtimeStatus === 'running' || runtimeStatus === 'executing',
|
|
302
|
+
lastExecuted: status.started_at,
|
|
303
|
+
lastExecutionDuration: status.duration_ms,
|
|
304
|
+
lastError: status.error
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
mapToFlowDropStatus(runtimeStatus) {
|
|
308
|
+
switch (runtimeStatus) {
|
|
309
|
+
case 'running':
|
|
310
|
+
case 'executing':
|
|
311
|
+
return 'running';
|
|
312
|
+
case 'completed':
|
|
313
|
+
case 'success':
|
|
314
|
+
case 'done':
|
|
315
|
+
return 'completed';
|
|
316
|
+
case 'failed':
|
|
317
|
+
case 'error':
|
|
318
|
+
return 'failed';
|
|
319
|
+
case 'cancelled':
|
|
320
|
+
case 'canceled':
|
|
321
|
+
return 'cancelled';
|
|
322
|
+
case 'pending':
|
|
323
|
+
case 'queued':
|
|
324
|
+
return 'pending';
|
|
325
|
+
case 'skipped':
|
|
326
|
+
return 'skipped';
|
|
327
|
+
default:
|
|
328
|
+
return 'idle';
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/** Singleton instance */
|
|
333
|
+
export const agentSpecExecutionService = AgentSpecExecutionService.getInstance();
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open Agent Specification (Agent Spec) TypeScript Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions mirroring Oracle's Open Agent Spec format.
|
|
5
|
+
* Used for bidirectional conversion between FlowDrop and Agent Spec.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/oracle/agent-spec
|
|
8
|
+
* @see https://oracle.github.io/agent-spec/
|
|
9
|
+
*/
|
|
10
|
+
/** Agent Spec node component_type discriminator values */
|
|
11
|
+
export type AgentSpecNodeComponentType = 'start_node' | 'end_node' | 'llm_node' | 'api_node' | 'agent_node' | 'flow_node' | 'map_node' | 'branching_node' | 'tool_node';
|
|
12
|
+
/** Agent Spec tool component_type discriminator values */
|
|
13
|
+
export type AgentSpecToolComponentType = 'server_tool' | 'client_tool' | 'remote_tool';
|
|
14
|
+
/** All Agent Spec component_type values */
|
|
15
|
+
export type AgentSpecComponentType = 'agent' | 'flow' | AgentSpecNodeComponentType | AgentSpecToolComponentType | 'llm_config';
|
|
16
|
+
/**
|
|
17
|
+
* Agent Spec Property — JSON Schema-based input/output definition.
|
|
18
|
+
*
|
|
19
|
+
* Uses JSON Schema types and structure for describing data shape.
|
|
20
|
+
* Placeholder syntax `{{variable_name}}` generates implicit input properties.
|
|
21
|
+
*/
|
|
22
|
+
export interface AgentSpecProperty {
|
|
23
|
+
/** Property name (used as identifier in edges and templates) */
|
|
24
|
+
title: string;
|
|
25
|
+
/** JSON Schema type */
|
|
26
|
+
type: string;
|
|
27
|
+
/** Human-readable description */
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Default value */
|
|
30
|
+
default?: unknown;
|
|
31
|
+
/** Allowed values (JSON Schema enum) */
|
|
32
|
+
enum?: unknown[];
|
|
33
|
+
/** Array item schema */
|
|
34
|
+
items?: AgentSpecProperty;
|
|
35
|
+
/** Object property schemas */
|
|
36
|
+
properties?: Record<string, AgentSpecProperty>;
|
|
37
|
+
/** Required properties (for object types) */
|
|
38
|
+
required?: string[];
|
|
39
|
+
/** Additional JSON Schema fields */
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** Base interface for all Agent Spec nodes */
|
|
43
|
+
export interface AgentSpecNodeBase {
|
|
44
|
+
/** Discriminator for node type */
|
|
45
|
+
component_type: AgentSpecNodeComponentType;
|
|
46
|
+
/** Node name (used as identifier in edges) */
|
|
47
|
+
name: string;
|
|
48
|
+
/** Human-readable description */
|
|
49
|
+
description?: string;
|
|
50
|
+
/** Input properties */
|
|
51
|
+
inputs?: AgentSpecProperty[];
|
|
52
|
+
/** Output properties */
|
|
53
|
+
outputs?: AgentSpecProperty[];
|
|
54
|
+
/** Extension metadata (includes FlowDrop-specific data for round-trip) */
|
|
55
|
+
metadata?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/** Graph entry point */
|
|
58
|
+
export interface AgentSpecStartNode extends AgentSpecNodeBase {
|
|
59
|
+
component_type: 'start_node';
|
|
60
|
+
}
|
|
61
|
+
/** Graph exit point */
|
|
62
|
+
export interface AgentSpecEndNode extends AgentSpecNodeBase {
|
|
63
|
+
component_type: 'end_node';
|
|
64
|
+
}
|
|
65
|
+
/** LLM text generation node */
|
|
66
|
+
export interface AgentSpecLLMNode extends AgentSpecNodeBase {
|
|
67
|
+
component_type: 'llm_node';
|
|
68
|
+
/** LLM configuration (inline or $component_ref string) */
|
|
69
|
+
llm_config?: AgentSpecLLMConfig | string;
|
|
70
|
+
/** System prompt template (supports {{variable}} syntax) */
|
|
71
|
+
system_prompt?: string;
|
|
72
|
+
/** User prompt template (supports {{variable}} syntax) */
|
|
73
|
+
prompt_template?: string;
|
|
74
|
+
/** Output JSON Schema for structured output */
|
|
75
|
+
output_schema?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
/** API call node */
|
|
78
|
+
export interface AgentSpecAPINode extends AgentSpecNodeBase {
|
|
79
|
+
component_type: 'api_node';
|
|
80
|
+
/** API endpoint URL */
|
|
81
|
+
endpoint?: string;
|
|
82
|
+
/** HTTP method */
|
|
83
|
+
method?: string;
|
|
84
|
+
/** Request headers */
|
|
85
|
+
headers?: Record<string, string>;
|
|
86
|
+
/** Request body template */
|
|
87
|
+
body?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/** Multi-round agent conversation node */
|
|
90
|
+
export interface AgentSpecAgentNode extends AgentSpecNodeBase {
|
|
91
|
+
component_type: 'agent_node';
|
|
92
|
+
/** Agent reference ($component_ref or inline) */
|
|
93
|
+
agent?: AgentSpecAgent | string;
|
|
94
|
+
}
|
|
95
|
+
/** Nested flow execution node */
|
|
96
|
+
export interface AgentSpecFlowNode extends AgentSpecNodeBase {
|
|
97
|
+
component_type: 'flow_node';
|
|
98
|
+
/** Flow reference ($component_ref or inline) */
|
|
99
|
+
flow?: AgentSpecFlow | string;
|
|
100
|
+
}
|
|
101
|
+
/** Map-reduce operation node */
|
|
102
|
+
export interface AgentSpecMapNode extends AgentSpecNodeBase {
|
|
103
|
+
component_type: 'map_node';
|
|
104
|
+
/** Input collection property name */
|
|
105
|
+
input_collection?: string;
|
|
106
|
+
/** Output collection property name */
|
|
107
|
+
output_collection?: string;
|
|
108
|
+
/** Flow or node to execute per item ($component_ref or inline) */
|
|
109
|
+
map_flow?: AgentSpecFlow | string;
|
|
110
|
+
}
|
|
111
|
+
/** Conditional routing node */
|
|
112
|
+
export interface AgentSpecBranchingNode extends AgentSpecNodeBase {
|
|
113
|
+
component_type: 'branching_node';
|
|
114
|
+
/** Branch definitions with conditions */
|
|
115
|
+
branches: AgentSpecBranch[];
|
|
116
|
+
}
|
|
117
|
+
/** Tool execution node */
|
|
118
|
+
export interface AgentSpecToolNode extends AgentSpecNodeBase {
|
|
119
|
+
component_type: 'tool_node';
|
|
120
|
+
/** Tool reference ($component_ref or inline) */
|
|
121
|
+
tool?: AgentSpecTool | string;
|
|
122
|
+
}
|
|
123
|
+
/** Union of all Agent Spec node types */
|
|
124
|
+
export type AgentSpecNode = AgentSpecStartNode | AgentSpecEndNode | AgentSpecLLMNode | AgentSpecAPINode | AgentSpecAgentNode | AgentSpecFlowNode | AgentSpecMapNode | AgentSpecBranchingNode | AgentSpecToolNode;
|
|
125
|
+
/** Branch definition for BranchingNode */
|
|
126
|
+
export interface AgentSpecBranch {
|
|
127
|
+
/** Branch name (used as from_branch in ControlFlowEdge) */
|
|
128
|
+
name: string;
|
|
129
|
+
/** Condition expression for this branch */
|
|
130
|
+
condition?: string;
|
|
131
|
+
/** Human-readable description */
|
|
132
|
+
description?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Control Flow Edge — defines execution order between nodes.
|
|
136
|
+
*
|
|
137
|
+
* Multiple control flow connections from the same branch are prohibited.
|
|
138
|
+
*/
|
|
139
|
+
export interface AgentSpecControlFlowEdge {
|
|
140
|
+
/** Edge name (identifier) */
|
|
141
|
+
name: string;
|
|
142
|
+
/** Source node name */
|
|
143
|
+
from_node: string;
|
|
144
|
+
/** Target node name */
|
|
145
|
+
to_node: string;
|
|
146
|
+
/** Source branch name (null/undefined = default "next" branch) */
|
|
147
|
+
from_branch?: string | null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Data Flow Edge — routes data between node outputs and inputs.
|
|
151
|
+
*
|
|
152
|
+
* Maps a specific output property of a source node to a specific
|
|
153
|
+
* input property of a destination node.
|
|
154
|
+
*/
|
|
155
|
+
export interface AgentSpecDataFlowEdge {
|
|
156
|
+
/** Edge name (identifier) */
|
|
157
|
+
name: string;
|
|
158
|
+
/** Source node name */
|
|
159
|
+
source_node: string;
|
|
160
|
+
/** Source output property title */
|
|
161
|
+
source_output: string;
|
|
162
|
+
/** Destination node name */
|
|
163
|
+
destination_node: string;
|
|
164
|
+
/** Destination input property title */
|
|
165
|
+
destination_input: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Agent Spec Flow — a directed, potentially cyclic graph of nodes.
|
|
169
|
+
*
|
|
170
|
+
* Flows function as "subroutines" encapsulating repeatable processes.
|
|
171
|
+
* They separate control-flow (execution order) from data-flow (data routing).
|
|
172
|
+
*/
|
|
173
|
+
export interface AgentSpecFlow {
|
|
174
|
+
component_type: 'flow';
|
|
175
|
+
/** Flow name */
|
|
176
|
+
name: string;
|
|
177
|
+
/** Human-readable description */
|
|
178
|
+
description?: string;
|
|
179
|
+
/** Reference to the StartNode name */
|
|
180
|
+
start_node: string;
|
|
181
|
+
/** All nodes in the flow */
|
|
182
|
+
nodes: AgentSpecNode[];
|
|
183
|
+
/** Execution order edges */
|
|
184
|
+
control_flow_connections: AgentSpecControlFlowEdge[];
|
|
185
|
+
/**
|
|
186
|
+
* Data routing edges.
|
|
187
|
+
* When null, data flows by matching input/output property names
|
|
188
|
+
* across connected nodes (name-based variable access).
|
|
189
|
+
*/
|
|
190
|
+
data_flow_connections?: AgentSpecDataFlowEdge[] | null;
|
|
191
|
+
/** Extension metadata */
|
|
192
|
+
metadata?: Record<string, unknown>;
|
|
193
|
+
}
|
|
194
|
+
/** Base interface for Agent Spec tools */
|
|
195
|
+
export interface AgentSpecToolBase {
|
|
196
|
+
component_type: AgentSpecToolComponentType;
|
|
197
|
+
/** Tool name */
|
|
198
|
+
name: string;
|
|
199
|
+
/** Human-readable description */
|
|
200
|
+
description?: string;
|
|
201
|
+
/** Input parameters */
|
|
202
|
+
inputs?: AgentSpecProperty[];
|
|
203
|
+
/** Output parameters */
|
|
204
|
+
outputs?: AgentSpecProperty[];
|
|
205
|
+
/** Extension metadata */
|
|
206
|
+
metadata?: Record<string, unknown>;
|
|
207
|
+
}
|
|
208
|
+
/** Tool executed in the same runtime environment */
|
|
209
|
+
export interface AgentSpecServerTool extends AgentSpecToolBase {
|
|
210
|
+
component_type: 'server_tool';
|
|
211
|
+
/** Function name or module path */
|
|
212
|
+
function_name?: string;
|
|
213
|
+
}
|
|
214
|
+
/** Tool executed by the client, results returned to runtime */
|
|
215
|
+
export interface AgentSpecClientTool extends AgentSpecToolBase {
|
|
216
|
+
component_type: 'client_tool';
|
|
217
|
+
}
|
|
218
|
+
/** Tool triggered via RPC/REST calls */
|
|
219
|
+
export interface AgentSpecRemoteTool extends AgentSpecToolBase {
|
|
220
|
+
component_type: 'remote_tool';
|
|
221
|
+
/** Remote endpoint URL */
|
|
222
|
+
endpoint?: string;
|
|
223
|
+
/** HTTP method */
|
|
224
|
+
method?: string;
|
|
225
|
+
/** Request headers */
|
|
226
|
+
headers?: Record<string, string>;
|
|
227
|
+
}
|
|
228
|
+
/** Union of all Agent Spec tool types */
|
|
229
|
+
export type AgentSpecTool = AgentSpecServerTool | AgentSpecClientTool | AgentSpecRemoteTool;
|
|
230
|
+
/** LLM model configuration */
|
|
231
|
+
export interface AgentSpecLLMConfig {
|
|
232
|
+
component_type: 'llm_config';
|
|
233
|
+
/** Configuration name */
|
|
234
|
+
name: string;
|
|
235
|
+
/** Model identifier (e.g., "gpt-4o", "claude-sonnet-4-5-20250929") */
|
|
236
|
+
model_id: string;
|
|
237
|
+
/** Provider name (e.g., "openai", "anthropic") */
|
|
238
|
+
provider?: string;
|
|
239
|
+
/** API endpoint URL */
|
|
240
|
+
url?: string;
|
|
241
|
+
/** Generation parameters (temperature, max_tokens, etc.) */
|
|
242
|
+
parameters?: Record<string, unknown>;
|
|
243
|
+
/** Extension metadata */
|
|
244
|
+
metadata?: Record<string, unknown>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Agent Spec Agent — top-level conversational AI system.
|
|
248
|
+
*
|
|
249
|
+
* Serves as the entry point and holds shared resources like
|
|
250
|
+
* tools, memory, and LLM configuration.
|
|
251
|
+
*/
|
|
252
|
+
export interface AgentSpecAgent {
|
|
253
|
+
component_type: 'agent';
|
|
254
|
+
/** Agent name */
|
|
255
|
+
name: string;
|
|
256
|
+
/** Human-readable description */
|
|
257
|
+
description?: string;
|
|
258
|
+
/** Agent inputs */
|
|
259
|
+
inputs?: AgentSpecProperty[];
|
|
260
|
+
/** Agent outputs */
|
|
261
|
+
outputs?: AgentSpecProperty[];
|
|
262
|
+
/** Available tools (inline or $component_ref strings) */
|
|
263
|
+
tools?: (AgentSpecTool | string)[];
|
|
264
|
+
/** LLM configuration (inline or $component_ref string) */
|
|
265
|
+
llm_config?: AgentSpecLLMConfig | string;
|
|
266
|
+
/** System prompt template */
|
|
267
|
+
system_prompt?: string;
|
|
268
|
+
/** Extension metadata */
|
|
269
|
+
metadata?: Record<string, unknown>;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Top-level Agent Spec document.
|
|
273
|
+
*
|
|
274
|
+
* Contains a flow and/or agent definition along with shared
|
|
275
|
+
* tool and LLM configuration declarations.
|
|
276
|
+
*/
|
|
277
|
+
export interface AgentSpecDocument {
|
|
278
|
+
/** Agent definition */
|
|
279
|
+
agent?: AgentSpecAgent;
|
|
280
|
+
/** Flow definition */
|
|
281
|
+
flow?: AgentSpecFlow;
|
|
282
|
+
/** Shared tool declarations */
|
|
283
|
+
tools?: AgentSpecTool[];
|
|
284
|
+
/** Shared LLM configurations */
|
|
285
|
+
llm_configs?: AgentSpecLLMConfig[];
|
|
286
|
+
/** Document-level metadata */
|
|
287
|
+
metadata?: Record<string, unknown>;
|
|
288
|
+
}
|
|
289
|
+
/** Prefix for component references in Agent Spec */
|
|
290
|
+
export declare const COMPONENT_REF_PREFIX = "$component_ref:";
|
|
291
|
+
/**
|
|
292
|
+
* Check if a value is a component reference string.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* isComponentRef("$component_ref:my_tool") // true
|
|
297
|
+
* isComponentRef("just a string") // false
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
export declare function isComponentRef(value: unknown): value is string;
|
|
301
|
+
/**
|
|
302
|
+
* Extract the component ID from a component reference string.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* extractComponentRefId("$component_ref:my_tool") // "my_tool"
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export declare function extractComponentRefId(ref: string): string;
|
|
310
|
+
/**
|
|
311
|
+
* Create a component reference string.
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* createComponentRef("my_tool") // "$component_ref:my_tool"
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export declare function createComponentRef(componentId: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open Agent Specification (Agent Spec) TypeScript Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions mirroring Oracle's Open Agent Spec format.
|
|
5
|
+
* Used for bidirectional conversion between FlowDrop and Agent Spec.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/oracle/agent-spec
|
|
8
|
+
* @see https://oracle.github.io/agent-spec/
|
|
9
|
+
*/
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Component Reference
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/** Prefix for component references in Agent Spec */
|
|
14
|
+
export const COMPONENT_REF_PREFIX = '$component_ref:';
|
|
15
|
+
/**
|
|
16
|
+
* Check if a value is a component reference string.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* isComponentRef("$component_ref:my_tool") // true
|
|
21
|
+
* isComponentRef("just a string") // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function isComponentRef(value) {
|
|
25
|
+
return typeof value === 'string' && value.startsWith(COMPONENT_REF_PREFIX);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract the component ID from a component reference string.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* extractComponentRefId("$component_ref:my_tool") // "my_tool"
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function extractComponentRefId(ref) {
|
|
36
|
+
return ref.slice(COMPONENT_REF_PREFIX.length);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a component reference string.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* createComponentRef("my_tool") // "$component_ref:my_tool"
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function createComponentRef(componentId) {
|
|
47
|
+
return `${COMPONENT_REF_PREFIX}${componentId}`;
|
|
48
|
+
}
|