@aaac/runtime 0.1.5 → 0.1.8
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/adk-sdk.d.ts +2 -2
- package/dist/adapters/claude-agent-sdk.d.ts +2 -2
- package/dist/adapters/mock.d.ts +2 -1
- package/dist/adapters/openai-agents-sdk.d.ts +2 -2
- package/dist/generator/index.d.ts +91 -2
- package/dist/generator/index.js +131 -8
- package/dist/generator/index.js.map +1 -1
- package/dist/index.d.ts +5 -284
- package/dist/index.js +208 -8
- package/dist/index.js.map +1 -1
- package/dist/{task-runner-szDOYtJV.d.ts → task-runner-Dw8oWJD6.d.ts} +449 -46
- package/package.json +2 -1
- package/dist/guardrail-hooks-C8G5NGsj.d.ts +0 -83
package/dist/index.d.ts
CHANGED
|
@@ -1,227 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as AdapterSendOptions, a as AgentExecutionRequest,
|
|
1
|
+
import { T as TaskContext, b as TaskOutcome, c as AgentContractLike, d as TaskContractLike, P as PromptBuilderOptions, W as WorkflowResult, S as SdkAdapter, e as WorkflowRegistries, H as HandoffInput, f as StepCompleteEvent, g as StepResult, D as DelegateStep, h as GuardrailRuleData, i as MemoryStore, M as MemoryRef, L as LibraryToolRegistry, G as GuardrailHooks, R as ResolvedComponent, j as ArtifactBindingConfig, k as TaskRunResult, O as ObserverEmitFn, l as ResolvedToolchain, m as LibraryToolDefinition } from './task-runner-Dw8oWJD6.js';
|
|
2
|
+
export { n as AdapterOrFactory, A as AdapterSendOptions, a as AgentExecutionRequest, o as AgentProgressEvent, B as BoundResolveOptions, p as BoundResolver, C as CacheConfig, q as CandidateAgent, E as EnvelopeParams, r as GateStep, s as GuardrailCheckFunctions, t as GuardrailCheckResult, u as GuardrailRule, v as HookContext, w as HookResponse, I as InMemoryStore, x as ModelAwareSdkAdapterFactory, y as ModelClass, z as ModelMappingConfig, F as ModelResolver, J as ModelResolverOptions, K as ReceiveSpec, N as ResolvedModel, Q as RetryDecision, U as SdkAdapterFactory, V as SplitPrompt, X as TaskRunOptions, Y as WorkflowContractLike, Z as WorkflowInvocation, _ as WorkflowRunOptions, $ as WorkflowStep, a0 as buildCandidateAgents, a1 as buildGateEvaluationPrompt, a2 as buildPerAgentGuardrails, a3 as buildRetryFollowUp, a4 as buildSplitTaskPrompt, a5 as buildTaskPrompt, a6 as createExecutionEnvelope, a7 as createGuardrailHooks, a8 as createGuardrailHooksForAgent, a9 as createGuardrailHooksFromRules, aa as createLibraryToolRegistry, ab as createModelResolver, ac as deriveToolchainsForAgents, ad as emitSessionClose, ae as emitSessionOpen, af as emitSubagentClose, ag as emitSubagentOpen, ah as emitToolchainClose, ai as emitToolchainOpen, aj as extractStructuredResult, ak as getBlockingViolations, al as getEffectiveGuardrailIds, am as getGuardrailRulesForAgent, an as getWarnings, ao as guardrailContextToRuleData, ap as hasBlockingViolation, aq as parseGateEvaluationResponse, ar as renderAgentSystemPrompt, as as runTask, at as runWorkflow, au as zodSchemaToPromptDescription, av as zodSchemaToYamlExample } from './task-runner-Dw8oWJD6.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { a as GuardrailRuleData, G as GuardrailHooks } from './guardrail-hooks-C8G5NGsj.js';
|
|
5
|
-
export { b as GuardrailCheckFunctions, c as GuardrailCheckResult, d as GuardrailRule, H as HookContext, e as HookResponse, f as createGuardrailHooks, g as createGuardrailHooksForAgent, h as createGuardrailHooksFromRules, i as getBlockingViolations, j as getWarnings, k as hasBlockingViolation } from './guardrail-hooks-C8G5NGsj.js';
|
|
6
|
-
import { G as GuardrailContext } from './context-B_bekYiE.js';
|
|
7
4
|
import { OperationIR, ComponentIR } from '@aaac/contracts';
|
|
8
5
|
export { ExecutionEnvelope } from '@aaac/observability';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* ModelResolver — resolves a model_class to a concrete adapter + model pair.
|
|
12
|
-
*
|
|
13
|
-
* Resolution priority (highest wins):
|
|
14
|
-
* 1. AGENT_RUNTIME_MODEL_{FAST|STANDARD|THINKING} env var
|
|
15
|
-
* 2. AGENT_RUNTIME_MODEL env var (catch-all fallback)
|
|
16
|
-
* 3. agent-runtime.config.yaml model_mapping.<class>
|
|
17
|
-
* 4. CLI --adapter + adapter default model
|
|
18
|
-
*/
|
|
19
|
-
type ModelClass = "fast" | "standard" | "thinking";
|
|
20
|
-
interface ResolvedModel {
|
|
21
|
-
adapter: string;
|
|
22
|
-
model?: string;
|
|
23
|
-
}
|
|
24
|
-
interface ModelResolver {
|
|
25
|
-
resolve(modelClass: ModelClass | undefined): ResolvedModel;
|
|
26
|
-
}
|
|
27
|
-
interface ModelMappingConfig {
|
|
28
|
-
fast?: {
|
|
29
|
-
adapter: string;
|
|
30
|
-
model?: string;
|
|
31
|
-
};
|
|
32
|
-
standard?: {
|
|
33
|
-
adapter: string;
|
|
34
|
-
model?: string;
|
|
35
|
-
};
|
|
36
|
-
thinking?: {
|
|
37
|
-
adapter: string;
|
|
38
|
-
model?: string;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
interface ModelResolverOptions {
|
|
42
|
-
modelMapping?: ModelMappingConfig;
|
|
43
|
-
fallbackAdapter: string;
|
|
44
|
-
fallbackModel?: string;
|
|
45
|
-
env?: Record<string, string | undefined>;
|
|
46
|
-
}
|
|
47
|
-
declare function createModelResolver(options: ModelResolverOptions): ModelResolver;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Workflow Runner — orchestrates a DSL workflow as a sequence of task executions
|
|
51
|
-
*
|
|
52
|
-
* Programmatic control flow that replaces LLM-driven step interpretation:
|
|
53
|
-
*
|
|
54
|
-
* 1. Load workflow contract (ordered steps)
|
|
55
|
-
* 2. Run plugin beforeWorkflow hooks
|
|
56
|
-
* 3. For each step:
|
|
57
|
-
* - delegate → call task-runner with followUp/retry recovery
|
|
58
|
-
* - gate → pause and wait for user input
|
|
59
|
-
* 4. Validate each result against handoff schema
|
|
60
|
-
* 5. Accumulate context between steps
|
|
61
|
-
* 6. Run plugin afterWorkflow hooks
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* A factory that creates independent SdkAdapter instances.
|
|
66
|
-
* Used by runWorkflow to allocate one adapter per parallel step,
|
|
67
|
-
* avoiding session-level serialization in stateful SDK adapters.
|
|
68
|
-
*/
|
|
69
|
-
type SdkAdapterFactory = () => SdkAdapter;
|
|
70
|
-
/**
|
|
71
|
-
* Model-aware adapter factory. Accepts a model_class and returns an adapter
|
|
72
|
-
* configured for that capability level (possibly a different provider/model).
|
|
73
|
-
*/
|
|
74
|
-
type ModelAwareSdkAdapterFactory = (modelClass?: ModelClass) => SdkAdapter | Promise<SdkAdapter>;
|
|
75
|
-
/** Accepts either a single adapter (serial/shared) or a factory (parallel-safe). */
|
|
76
|
-
type AdapterOrFactory = SdkAdapter | SdkAdapterFactory | ModelAwareSdkAdapterFactory;
|
|
77
|
-
interface DelegateStep {
|
|
78
|
-
readonly type: "delegate";
|
|
79
|
-
readonly task: string;
|
|
80
|
-
readonly from_agent: string;
|
|
81
|
-
readonly description: string;
|
|
82
|
-
readonly optional: boolean;
|
|
83
|
-
readonly max_retries: number;
|
|
84
|
-
readonly max_follow_ups?: number;
|
|
85
|
-
readonly depends_on?: readonly string[];
|
|
86
|
-
readonly retry?: {
|
|
87
|
-
readonly condition: string;
|
|
88
|
-
readonly fix_task: string;
|
|
89
|
-
readonly revalidate_task?: string;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
interface GateStep {
|
|
93
|
-
readonly type: "gate";
|
|
94
|
-
readonly gate_kind: string;
|
|
95
|
-
readonly description: string;
|
|
96
|
-
readonly depends_on?: readonly string[];
|
|
97
|
-
}
|
|
98
|
-
type WorkflowStep = DelegateStep | GateStep;
|
|
99
|
-
interface WorkflowContractLike {
|
|
100
|
-
readonly id: string;
|
|
101
|
-
readonly description: string;
|
|
102
|
-
readonly steps: readonly WorkflowStep[];
|
|
103
|
-
}
|
|
104
|
-
interface WorkflowRunOptions {
|
|
105
|
-
user_request: string;
|
|
106
|
-
/** Override max follow-up attempts per step (lightweight output-format correction). Default: 2 */
|
|
107
|
-
maxFollowUps?: number;
|
|
108
|
-
/** Override max full retry attempts per step. Default: from DSL step.max_retries */
|
|
109
|
-
maxRetries?: number;
|
|
110
|
-
/** Variables propagated to every TaskContext in the workflow (from WorkflowInvocation.context). */
|
|
111
|
-
variables?: Record<string, unknown>;
|
|
112
|
-
onGate?: (gateKind: string, description: string, stepResults: StepResult[]) => Promise<boolean>;
|
|
113
|
-
onStepComplete?: (event: StepCompleteEvent) => void;
|
|
114
|
-
onOptionalStep?: (step: DelegateStep, context: TaskContext) => Promise<boolean>;
|
|
115
|
-
/**
|
|
116
|
-
* Writable stream for real-time progress output during agent execution.
|
|
117
|
-
* Intermediate events from adapters are formatted and written here.
|
|
118
|
-
* Typical value: process.stderr.
|
|
119
|
-
*/
|
|
120
|
-
progressOutput?: {
|
|
121
|
-
write(chunk: string): unknown;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Optional observer emit function for agent-axis spans (agent.session, agent.subagent).
|
|
125
|
-
* When undefined, no spans are emitted (observer is optional — no-op).
|
|
126
|
-
* Pass EventCollector.emit.bind(collector) to wire up the full observability pipeline.
|
|
127
|
-
*/
|
|
128
|
-
observer?: ObserverEmitFn;
|
|
129
|
-
}
|
|
130
|
-
/** Typed handoff envelope for workflow input. */
|
|
131
|
-
interface HandoffInput<TType extends string = string, TPayload = unknown> {
|
|
132
|
-
readonly type: TType;
|
|
133
|
-
readonly version?: number;
|
|
134
|
-
readonly payload: TPayload;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Standard runtime invocation envelope. SDK-specific options (openaiThreadId,
|
|
138
|
-
* sessionId, etc.) belong on the adapter constructor — not here.
|
|
139
|
-
*/
|
|
140
|
-
interface WorkflowInvocation<THandoffType extends string = string, TPayload = unknown> {
|
|
141
|
-
workflow: string;
|
|
142
|
-
/** Structured typed handoff input. Takes precedence over user_request if both are set. */
|
|
143
|
-
handoff?: HandoffInput<THandoffType, TPayload>;
|
|
144
|
-
/** Simple string input (convenience shorthand). */
|
|
145
|
-
user_request?: string;
|
|
146
|
-
runtime?: {
|
|
147
|
-
maxFollowUps?: number;
|
|
148
|
-
maxRetries?: number;
|
|
149
|
-
timeoutMs?: number;
|
|
150
|
-
readonly?: boolean;
|
|
151
|
-
dryRun?: boolean;
|
|
152
|
-
};
|
|
153
|
-
hooks?: {
|
|
154
|
-
onStepComplete?: (event: StepCompleteEvent) => void;
|
|
155
|
-
onGate?: (gateKind: string, description: string, stepResults: StepResult[]) => Promise<boolean>;
|
|
156
|
-
onOptionalStep?: (step: DelegateStep, context: TaskContext) => Promise<boolean>;
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Writable stream for real-time progress output during agent execution.
|
|
160
|
-
* Intermediate events from adapters are formatted and written here.
|
|
161
|
-
* Typical value: process.stderr.
|
|
162
|
-
*/
|
|
163
|
-
progressOutput?: {
|
|
164
|
-
write(chunk: string): unknown;
|
|
165
|
-
};
|
|
166
|
-
context?: {
|
|
167
|
-
cwd?: string;
|
|
168
|
-
environment?: "local" | "ci" | "remote";
|
|
169
|
-
artifacts?: Record<string, string>;
|
|
170
|
-
variables?: Record<string, unknown>;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Optional observer emit function for agent-axis spans (agent.session, agent.subagent).
|
|
174
|
-
* When undefined, no spans are emitted (observer is optional — no-op).
|
|
175
|
-
* Pass EventCollector.emit.bind(collector) to wire up the full observability pipeline.
|
|
176
|
-
*/
|
|
177
|
-
observer?: ObserverEmitFn;
|
|
178
|
-
}
|
|
179
|
-
interface StepResult {
|
|
180
|
-
step_index: number;
|
|
181
|
-
task_id?: string;
|
|
182
|
-
gate_kind?: string;
|
|
183
|
-
outcome: TaskOutcome | {
|
|
184
|
-
status: "gate_approved";
|
|
185
|
-
} | {
|
|
186
|
-
status: "gate_rejected";
|
|
187
|
-
} | {
|
|
188
|
-
status: "skipped";
|
|
189
|
-
};
|
|
190
|
-
follow_ups_used: number;
|
|
191
|
-
retries_used: number;
|
|
192
|
-
elapsed_ms: number;
|
|
193
|
-
}
|
|
194
|
-
interface StepCompleteEvent {
|
|
195
|
-
workflow_id: string;
|
|
196
|
-
step_index: number;
|
|
197
|
-
step_type: "delegate" | "gate";
|
|
198
|
-
task_id?: string;
|
|
199
|
-
gate_kind?: string;
|
|
200
|
-
outcome_status: string;
|
|
201
|
-
follow_ups_used: number;
|
|
202
|
-
retries_used: number;
|
|
203
|
-
elapsed_ms: number;
|
|
204
|
-
}
|
|
205
|
-
interface WorkflowResult {
|
|
206
|
-
workflow_id: string;
|
|
207
|
-
status: "completed" | "escalated" | "gate_rejected" | "error";
|
|
208
|
-
steps: StepResult[];
|
|
209
|
-
total_elapsed_ms: number;
|
|
210
|
-
escalation_reason?: string;
|
|
211
|
-
error_message?: string;
|
|
212
|
-
}
|
|
213
|
-
interface WorkflowRegistries {
|
|
214
|
-
workflowRegistry?: Record<string, WorkflowContractLike>;
|
|
215
|
-
taskRegistry?: Record<string, TaskContractLike>;
|
|
216
|
-
agentRegistry?: Record<string, AgentContractLike>;
|
|
217
|
-
handoffSchemas?: Record<string, z.ZodType>;
|
|
218
|
-
}
|
|
219
|
-
/** @deprecated Use the WorkflowInvocation overload for typed handoff input. */
|
|
220
|
-
declare function runWorkflow(adapter: AdapterOrFactory, workflowId: string, options: WorkflowRunOptions, registries?: WorkflowRegistries): Promise<WorkflowResult>;
|
|
221
|
-
/** Structured invocation with typed handoff envelope. */
|
|
222
|
-
declare function runWorkflow(adapter: AdapterOrFactory, invocation: WorkflowInvocation, registries?: WorkflowRegistries): Promise<WorkflowResult>;
|
|
223
|
-
declare function buildGateEvaluationPrompt(step: GateStep, priorContext: string): string;
|
|
224
|
-
declare function parseGateEvaluationResponse(response: string): boolean;
|
|
6
|
+
import './context-B_bekYiE.js';
|
|
225
7
|
|
|
226
8
|
/**
|
|
227
9
|
* Plugin Interface — extension points for user code injection
|
|
@@ -291,68 +73,6 @@ declare class PluginRegistry {
|
|
|
291
73
|
}
|
|
292
74
|
declare const pluginRegistry: PluginRegistry;
|
|
293
75
|
|
|
294
|
-
/**
|
|
295
|
-
* BoundResolver — runtime binding + policy resolution with per-agent isolation.
|
|
296
|
-
*
|
|
297
|
-
* Resolves artifact binding and guardrail/policy in one pass at runtime,
|
|
298
|
-
* producing a per-agent scoped ResolvedComponent. Reuses existing
|
|
299
|
-
* resolveBound(), buildGuardrailContext(), and agent scope resolution.
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
interface ArtifactBindingConfig {
|
|
303
|
-
source: string;
|
|
304
|
-
mappings?: Record<string, string>;
|
|
305
|
-
}
|
|
306
|
-
interface BoundResolveOptions {
|
|
307
|
-
/** Component identifier — used for cache keying. */
|
|
308
|
-
id: string;
|
|
309
|
-
/** Pre-resolved DSL (e.g. embedded from codegen). */
|
|
310
|
-
embeddedDsl?: Record<string, unknown>;
|
|
311
|
-
/** Path to DSL file — resolved via agent-contracts when no embeddedDsl. */
|
|
312
|
-
dslPath?: string;
|
|
313
|
-
/** Paths to software binding YAML files (guardrail_impl, etc.). */
|
|
314
|
-
bindingPaths?: string[];
|
|
315
|
-
/** Active guardrail policy name from DSL guardrail_policies. */
|
|
316
|
-
activeGuardrailPolicy?: string;
|
|
317
|
-
/** Artifact binding config — resolved via agent-contracts resolveBound(). */
|
|
318
|
-
artifactBinding?: ArtifactBindingConfig;
|
|
319
|
-
/** Path substitutions for artifact binding. */
|
|
320
|
-
paths?: Record<string, string>;
|
|
321
|
-
}
|
|
322
|
-
interface ResolvedComponent {
|
|
323
|
-
id: string;
|
|
324
|
-
dsl: Record<string, unknown>;
|
|
325
|
-
registries: WorkflowRegistries;
|
|
326
|
-
guardrails: {
|
|
327
|
-
perAgent: Map<string, GuardrailRuleData>;
|
|
328
|
-
};
|
|
329
|
-
diagnostics: Array<{
|
|
330
|
-
path?: string;
|
|
331
|
-
message: string;
|
|
332
|
-
severity?: string;
|
|
333
|
-
}>;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Effective guardrail IDs for an agent: entity-side bindings ∪ scope-side bindings.
|
|
337
|
-
*/
|
|
338
|
-
declare function getEffectiveGuardrailIds(dsl: Record<string, unknown>, agentId: string): Set<string>;
|
|
339
|
-
declare function guardrailContextToRuleData(ctx: GuardrailContext, effectiveIds?: Set<string>): GuardrailRuleData;
|
|
340
|
-
declare function buildPerAgentGuardrails(dsl: Record<string, unknown>, guardrailCtx: GuardrailContext): Map<string, GuardrailRuleData>;
|
|
341
|
-
declare class BoundResolver {
|
|
342
|
-
private readonly cache;
|
|
343
|
-
/**
|
|
344
|
-
* Resolve binding + policy in one pass. Results are cached by component id.
|
|
345
|
-
*/
|
|
346
|
-
resolve(opts: BoundResolveOptions): Promise<ResolvedComponent>;
|
|
347
|
-
/** Clear cached components (e.g. for testing). */
|
|
348
|
-
clearCache(): void;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Get guardrail rules for a specific agent from a ResolvedComponent.
|
|
352
|
-
* Falls back to embedded _guardrailRules when no per-agent rules exist.
|
|
353
|
-
*/
|
|
354
|
-
declare function getGuardrailRulesForAgent(component: ResolvedComponent, agentId: string, fallbackDsl?: Record<string, unknown>): GuardrailRuleData | undefined;
|
|
355
|
-
|
|
356
76
|
/**
|
|
357
77
|
* Fluent Builder API for workflow invocation.
|
|
358
78
|
*
|
|
@@ -761,6 +481,7 @@ interface ComponentScope {
|
|
|
761
481
|
toolsByAgent: Map<string, string[]>;
|
|
762
482
|
guardrailsByAgent: Map<string, unknown[]>;
|
|
763
483
|
libraryTools?: LibraryToolRegistry;
|
|
484
|
+
toolchainsByAgent?: Map<string, ResolvedToolchain[]>;
|
|
764
485
|
}
|
|
765
486
|
interface CreateComponentScopeOptions {
|
|
766
487
|
resolvedComponent?: ResolvedComponent;
|
|
@@ -815,4 +536,4 @@ declare function resolveArtifacts(options: ArtifactResolveOptions): Promise<Arti
|
|
|
815
536
|
/** Package version string. */
|
|
816
537
|
declare const version: string;
|
|
817
538
|
|
|
818
|
-
export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime,
|
|
539
|
+
export { type AaacInvocationContext, type AaacObserver, type AaacPolicy, type AaacRuntime, AgentContractLike, AgentLogWriter, type AgentLogWriterOptions, type AgentPlugin, ArtifactBindingConfig, type ArtifactResolveOptions, type ArtifactResolveResult, type ComponentScope, type CreateAdapterOptions, type CreateComponentScopeOptions, DelegateStep, type DslContext, DslValidationError, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, GuardrailHooks, type GuardrailResult, GuardrailRuleData, HandoffInput, LibraryToolDefinition, LibraryToolRegistry, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProgressSink, type ProgressSinkOptions, type PromptBuilderArgs, PromptBuilderOptions, type RequiredEntities, ResolvedComponent, ResolvedToolchain, type RunLogEvent, type Runtime, type RuntimeBinding, type RuntimeConfig, SdkAdapter, type SdkFunctionTool, StepCompleteEvent, StepResult, TaskContext, TaskContractLike, type TaskHookContext, TaskOutcome, TaskRunResult, WorkflowBuilder, type WorkflowHookContext, WorkflowRegistries, WorkflowResult, buildGuardrailRulesFromDsl, buildNavigationContext, buildRegistriesFromDsl, buildSdkFunctionTools, createAdapter, createComponentScope, createProgressSink, createRuntime, createRuntimeBinding, executeTask, executeWorkflow, jsonSchemaToZod, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, pluginRegistry, resolveArtifacts, version };
|
package/dist/index.js
CHANGED
|
@@ -71,12 +71,20 @@ function buildCandidateAgents(agentRegistry, opts) {
|
|
|
71
71
|
for (const [id, agent] of Object.entries(agentRegistry)) {
|
|
72
72
|
if (id === entryId) continue;
|
|
73
73
|
if (allowSet && !allowSet.has(id)) continue;
|
|
74
|
-
const
|
|
74
|
+
const agentTools = agent.can_execute_tools ? [...agent.can_execute_tools] : [];
|
|
75
|
+
const derivedToolchains = opts?.toolchainsByAgent?.get(id);
|
|
76
|
+
if (derivedToolchains) {
|
|
77
|
+
for (const tc of derivedToolchains) {
|
|
78
|
+
if (!agentTools.includes(tc.id)) {
|
|
79
|
+
agentTools.push(tc.id);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
75
83
|
candidates.push({
|
|
76
84
|
name: id,
|
|
77
85
|
description: deriveDescription(agent.purpose),
|
|
78
86
|
prompt: renderAgentSystemPrompt(agent),
|
|
79
|
-
...
|
|
87
|
+
...agentTools.length > 0 ? { tools: agentTools } : {}
|
|
80
88
|
});
|
|
81
89
|
}
|
|
82
90
|
return candidates;
|
|
@@ -205,6 +213,42 @@ function emitSubagentClose(observer, spanId, envelope, durationMs, status, agent
|
|
|
205
213
|
}
|
|
206
214
|
});
|
|
207
215
|
}
|
|
216
|
+
function emitToolchainOpen(observer, parentSpanId, toolchainId, operation, artifactIds, componentId) {
|
|
217
|
+
if (!observer) return void 0;
|
|
218
|
+
const spanId = generateId();
|
|
219
|
+
observer({
|
|
220
|
+
source: "aaac-runtime",
|
|
221
|
+
eventType: "toolchain.execution",
|
|
222
|
+
lifecycle: "open",
|
|
223
|
+
spanId,
|
|
224
|
+
parentSpanId,
|
|
225
|
+
attributes: attrs({
|
|
226
|
+
axis: "toolchain",
|
|
227
|
+
"toolchain.id": toolchainId,
|
|
228
|
+
"toolchain.operation": operation,
|
|
229
|
+
"toolchain.artifact_ids": artifactIds.join(","),
|
|
230
|
+
"agent.component_id": componentId
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
return spanId;
|
|
234
|
+
}
|
|
235
|
+
function emitToolchainClose(observer, spanId, toolchainId, operation, durationMs, status, errorMessage) {
|
|
236
|
+
if (!observer) return;
|
|
237
|
+
observer({
|
|
238
|
+
source: "aaac-runtime",
|
|
239
|
+
eventType: "toolchain.execution",
|
|
240
|
+
lifecycle: "close",
|
|
241
|
+
spanId,
|
|
242
|
+
attributes: attrs({
|
|
243
|
+
axis: "toolchain",
|
|
244
|
+
"toolchain.id": toolchainId,
|
|
245
|
+
"toolchain.operation": operation,
|
|
246
|
+
"toolchain.status": status,
|
|
247
|
+
"toolchain.duration_ms": durationMs,
|
|
248
|
+
...errorMessage ? { "toolchain.error": errorMessage } : {}
|
|
249
|
+
})
|
|
250
|
+
});
|
|
251
|
+
}
|
|
208
252
|
|
|
209
253
|
// src/lib/task-runner.ts
|
|
210
254
|
function getZodChecks(schema) {
|
|
@@ -920,7 +964,35 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
920
964
|
const completed = /* @__PURE__ */ new Set();
|
|
921
965
|
const stepResults = new Array(workflow.steps.length);
|
|
922
966
|
const stepContexts = new Array(workflow.steps.length).fill("");
|
|
967
|
+
const stepOutputs = new Array(workflow.steps.length).fill(void 0);
|
|
923
968
|
let abortResult;
|
|
969
|
+
function extractPath(obj, path) {
|
|
970
|
+
const cleanPath = path.startsWith("$.") ? path.slice(2) : path;
|
|
971
|
+
const segments = cleanPath.split(".");
|
|
972
|
+
let current = obj;
|
|
973
|
+
for (const seg of segments) {
|
|
974
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
975
|
+
current = current[seg];
|
|
976
|
+
}
|
|
977
|
+
return current;
|
|
978
|
+
}
|
|
979
|
+
function projectHandoffs(stepIndex, step) {
|
|
980
|
+
if (!step.receives) return void 0;
|
|
981
|
+
const projected = {};
|
|
982
|
+
for (const [alias, spec] of Object.entries(step.receives)) {
|
|
983
|
+
const fromTaskId = spec.from ?? alias;
|
|
984
|
+
const depIdx = workflow.steps.findIndex((s, j) => j < stepIndex && stepId(j) === fromTaskId);
|
|
985
|
+
if (depIdx === -1) continue;
|
|
986
|
+
const output = stepOutputs[depIdx];
|
|
987
|
+
if (output === void 0) continue;
|
|
988
|
+
if (spec.path) {
|
|
989
|
+
projected[alias] = extractPath(output, spec.path);
|
|
990
|
+
} else {
|
|
991
|
+
projected[alias] = output;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return Object.keys(projected).length > 0 ? projected : void 0;
|
|
995
|
+
}
|
|
924
996
|
function contextFor(stepIndex) {
|
|
925
997
|
const deps = depsByIndex[stepIndex];
|
|
926
998
|
if (deps.length === 0) return "";
|
|
@@ -932,8 +1004,10 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
932
1004
|
if (step.type === "gate") {
|
|
933
1005
|
return handleGateStep(step, Object.values(stepResults).filter(Boolean), options, i, stepAdapter);
|
|
934
1006
|
}
|
|
1007
|
+
const delegateStep = step;
|
|
935
1008
|
if (step.optional) {
|
|
936
|
-
const
|
|
1009
|
+
const stepUserRequest2 = delegateStep.instruction ?? options.user_request;
|
|
1010
|
+
const ctx = { user_request: stepUserRequest2, prior_context: contextFor(i), variables: options.variables };
|
|
937
1011
|
const shouldRun = options.onOptionalStep ? await options.onOptionalStep(step, ctx) : false;
|
|
938
1012
|
if (!shouldRun) {
|
|
939
1013
|
return {
|
|
@@ -946,11 +1020,23 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
946
1020
|
};
|
|
947
1021
|
}
|
|
948
1022
|
}
|
|
1023
|
+
const stepUserRequest = delegateStep.instruction ?? options.user_request;
|
|
1024
|
+
let handoffInput;
|
|
1025
|
+
const projected = projectHandoffs(i, delegateStep);
|
|
1026
|
+
if (projected) {
|
|
1027
|
+
handoffInput = {
|
|
1028
|
+
type: "step-projection",
|
|
1029
|
+
payload: projected
|
|
1030
|
+
};
|
|
1031
|
+
} else if (i === 0 && invocationHandoff) {
|
|
1032
|
+
handoffInput = invocationHandoff;
|
|
1033
|
+
}
|
|
1034
|
+
const useLegacyContext = !delegateStep.receives;
|
|
949
1035
|
const context = {
|
|
950
|
-
user_request:
|
|
951
|
-
prior_context: contextFor(i),
|
|
1036
|
+
user_request: stepUserRequest,
|
|
1037
|
+
...useLegacyContext ? { prior_context: contextFor(i) } : {},
|
|
952
1038
|
variables: options.variables,
|
|
953
|
-
...
|
|
1039
|
+
...handoffInput ? { handoff_input: handoffInput } : {}
|
|
954
1040
|
};
|
|
955
1041
|
const taskResult = await runTask(stepAdapter, step.task, context, {
|
|
956
1042
|
maxFollowUps: options.maxFollowUps ?? step.max_follow_ups ?? 2,
|
|
@@ -1017,6 +1103,7 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
1017
1103
|
emitStepEvent(options, workflow.id, i, step, result);
|
|
1018
1104
|
if (result.outcome.status === "success") {
|
|
1019
1105
|
const data = result.outcome.data;
|
|
1106
|
+
stepOutputs[i] = data;
|
|
1020
1107
|
stepContexts[i] = `
|
|
1021
1108
|
|
|
1022
1109
|
--- Step ${i + 1}: ${stepId(i)} ---
|
|
@@ -1423,6 +1510,71 @@ function buildPerAgentGuardrails(dsl, guardrailCtx) {
|
|
|
1423
1510
|
function hasGuardrailRules(rules) {
|
|
1424
1511
|
return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
|
|
1425
1512
|
}
|
|
1513
|
+
function mergeDerivedWithAgentTools(derivedTools, agentToolIds, allToolchains) {
|
|
1514
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1515
|
+
for (const tc of derivedTools) {
|
|
1516
|
+
merged.set(tc.id, tc);
|
|
1517
|
+
}
|
|
1518
|
+
for (const toolId of agentToolIds) {
|
|
1519
|
+
if (!merged.has(toolId)) {
|
|
1520
|
+
if (allToolchains[toolId]) {
|
|
1521
|
+
merged.set(toolId, { ...allToolchains[toolId], source: "merged" });
|
|
1522
|
+
}
|
|
1523
|
+
} else {
|
|
1524
|
+
const existing = merged.get(toolId);
|
|
1525
|
+
merged.set(toolId, { ...existing, source: "merged" });
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return Array.from(merged.values());
|
|
1529
|
+
}
|
|
1530
|
+
function deriveToolchainsForAgents(dsl, toolchains) {
|
|
1531
|
+
const result = /* @__PURE__ */ new Map();
|
|
1532
|
+
const agents = dsl.agents ?? {};
|
|
1533
|
+
for (const [agentId, agent] of Object.entries(agents)) {
|
|
1534
|
+
const derivedTools = [];
|
|
1535
|
+
const canReadArtifacts = agent.can_read_artifacts ?? [];
|
|
1536
|
+
const canWriteArtifacts = agent.can_write_artifacts ?? [];
|
|
1537
|
+
const agentArtifacts = agent.artifacts;
|
|
1538
|
+
const readArtifacts = /* @__PURE__ */ new Set([
|
|
1539
|
+
...canReadArtifacts,
|
|
1540
|
+
...agentArtifacts?.consumes ?? []
|
|
1541
|
+
]);
|
|
1542
|
+
const writeArtifacts = /* @__PURE__ */ new Set([
|
|
1543
|
+
...canWriteArtifacts,
|
|
1544
|
+
...agentArtifacts?.produces ?? []
|
|
1545
|
+
]);
|
|
1546
|
+
for (const tc of Object.values(toolchains)) {
|
|
1547
|
+
let matched = false;
|
|
1548
|
+
for (const artifactId of tc.artifacts.consumes) {
|
|
1549
|
+
if (readArtifacts.has(artifactId) || writeArtifacts.has(artifactId)) {
|
|
1550
|
+
matched = true;
|
|
1551
|
+
break;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
if (!matched) {
|
|
1555
|
+
for (const artifactId of tc.artifacts.produces) {
|
|
1556
|
+
if (writeArtifacts.has(artifactId)) {
|
|
1557
|
+
matched = true;
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
if (matched) {
|
|
1563
|
+
derivedTools.push(tc);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
if (derivedTools.length > 0) {
|
|
1567
|
+
const agentTools = agent.can_execute_tools ?? [];
|
|
1568
|
+
const mergedTools = mergeDerivedWithAgentTools(
|
|
1569
|
+
derivedTools,
|
|
1570
|
+
agentTools,
|
|
1571
|
+
toolchains
|
|
1572
|
+
);
|
|
1573
|
+
result.set(agentId, mergedTools);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return result;
|
|
1577
|
+
}
|
|
1426
1578
|
var BoundResolver = class {
|
|
1427
1579
|
cache = /* @__PURE__ */ new Map();
|
|
1428
1580
|
/**
|
|
@@ -1476,12 +1628,43 @@ var BoundResolver = class {
|
|
|
1476
1628
|
}
|
|
1477
1629
|
}
|
|
1478
1630
|
const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
|
|
1631
|
+
let toolchains;
|
|
1632
|
+
let toolchainsByAgent;
|
|
1633
|
+
if (opts.toolchainContractsPath) {
|
|
1634
|
+
const toolchainPkg = "@aaac/toolchain";
|
|
1635
|
+
const mod = await import(
|
|
1636
|
+
/* webpackIgnore: true */
|
|
1637
|
+
toolchainPkg
|
|
1638
|
+
);
|
|
1639
|
+
const tcDoc = await mod.loadToolchainContracts(opts.toolchainContractsPath);
|
|
1640
|
+
toolchains = {};
|
|
1641
|
+
for (const [id, tc] of Object.entries(tcDoc.toolchains)) {
|
|
1642
|
+
toolchains[id] = {
|
|
1643
|
+
id,
|
|
1644
|
+
kind: tc.kind,
|
|
1645
|
+
description: tc.description,
|
|
1646
|
+
module: tc.module,
|
|
1647
|
+
command: tc.command,
|
|
1648
|
+
cli_contract: tc.cli_contract,
|
|
1649
|
+
component_contract: tc.component_contract,
|
|
1650
|
+
artifacts: {
|
|
1651
|
+
consumes: [...tc.artifacts.consumes],
|
|
1652
|
+
produces: [...tc.artifacts.produces]
|
|
1653
|
+
},
|
|
1654
|
+
operations: tc.operations ? [...tc.operations] : void 0,
|
|
1655
|
+
source: "toolchain-contracts"
|
|
1656
|
+
};
|
|
1657
|
+
}
|
|
1658
|
+
toolchainsByAgent = deriveToolchainsForAgents(dsl, toolchains);
|
|
1659
|
+
}
|
|
1479
1660
|
const component = {
|
|
1480
1661
|
id: opts.id,
|
|
1481
1662
|
dsl,
|
|
1482
1663
|
registries: buildRegistriesFromDsl(dsl),
|
|
1483
1664
|
guardrails: { perAgent },
|
|
1484
|
-
diagnostics
|
|
1665
|
+
diagnostics,
|
|
1666
|
+
...toolchains ? { toolchains } : {},
|
|
1667
|
+
...toolchainsByAgent ? { toolchainsByAgent } : {}
|
|
1485
1668
|
};
|
|
1486
1669
|
this.cache.set(opts.id, component);
|
|
1487
1670
|
return component;
|
|
@@ -2285,6 +2468,19 @@ function buildToolsByAgent(componentIR, resolved) {
|
|
|
2285
2468
|
}
|
|
2286
2469
|
}
|
|
2287
2470
|
}
|
|
2471
|
+
if (resolved.toolchainsByAgent) {
|
|
2472
|
+
for (const [agentId, toolchains] of resolved.toolchainsByAgent) {
|
|
2473
|
+
for (const tc of toolchains) {
|
|
2474
|
+
if (tc.operations) {
|
|
2475
|
+
for (const op of tc.operations) {
|
|
2476
|
+
if (operationNames.has(op)) {
|
|
2477
|
+
appendToolForAgent(toolsByAgent, agentId, op);
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2288
2484
|
return toolsByAgent;
|
|
2289
2485
|
}
|
|
2290
2486
|
function appendToolForAgent(toolsByAgent, agentId, operationName) {
|
|
@@ -2322,7 +2518,8 @@ function createComponentScope(componentIR, binding, options) {
|
|
|
2322
2518
|
binding,
|
|
2323
2519
|
toolsByAgent: buildToolsByAgent(componentIR, resolved),
|
|
2324
2520
|
guardrailsByAgent: buildGuardrailsByAgent(resolved),
|
|
2325
|
-
libraryTools: buildLibraryTools(options?.libraryToolDefs)
|
|
2521
|
+
libraryTools: buildLibraryTools(options?.libraryToolDefs),
|
|
2522
|
+
...resolved?.toolchainsByAgent ? { toolchainsByAgent: resolved.toolchainsByAgent } : {}
|
|
2326
2523
|
};
|
|
2327
2524
|
}
|
|
2328
2525
|
|
|
@@ -2430,10 +2627,13 @@ export {
|
|
|
2430
2627
|
createProgressSink,
|
|
2431
2628
|
createRuntime,
|
|
2432
2629
|
createRuntimeBinding,
|
|
2630
|
+
deriveToolchainsForAgents,
|
|
2433
2631
|
emitSessionClose,
|
|
2434
2632
|
emitSessionOpen,
|
|
2435
2633
|
emitSubagentClose,
|
|
2436
2634
|
emitSubagentOpen,
|
|
2635
|
+
emitToolchainClose,
|
|
2636
|
+
emitToolchainOpen,
|
|
2437
2637
|
executeTask,
|
|
2438
2638
|
executeWorkflow,
|
|
2439
2639
|
extractStructuredResult,
|