@aaac/runtime 0.1.16 → 0.1.17
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/index.d.ts +43 -1
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -745,6 +745,48 @@ interface GuardStatusResult {
|
|
|
745
745
|
*/
|
|
746
746
|
declare function guardStatus(opts?: GuardStatusOptions): Promise<GuardStatusResult>;
|
|
747
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Prompt Executor — natural language routing via LLM tool selection.
|
|
750
|
+
*
|
|
751
|
+
* Converts component operations into tool descriptions, sends them to an LLM
|
|
752
|
+
* for routing, and dispatches the selected operation through the existing
|
|
753
|
+
* component binding.
|
|
754
|
+
*/
|
|
755
|
+
|
|
756
|
+
interface OperationToolDef {
|
|
757
|
+
name: string;
|
|
758
|
+
description: string;
|
|
759
|
+
inputSchema: Record<string, unknown>;
|
|
760
|
+
}
|
|
761
|
+
interface PromptResult {
|
|
762
|
+
selectedOperation: string;
|
|
763
|
+
mappedInput: Record<string, unknown>;
|
|
764
|
+
output?: unknown;
|
|
765
|
+
dryRun?: boolean;
|
|
766
|
+
model?: string;
|
|
767
|
+
}
|
|
768
|
+
interface PromptExecuteOptions {
|
|
769
|
+
dryRun?: boolean;
|
|
770
|
+
adapter: string;
|
|
771
|
+
model?: string;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Convert non-handler, non-prompt operations from ComponentIR into tool definitions
|
|
775
|
+
* for LLM routing.
|
|
776
|
+
*/
|
|
777
|
+
declare function operationsToTools(ir: ComponentIR): OperationToolDef[];
|
|
778
|
+
/**
|
|
779
|
+
* Parse the LLM router response to extract selected operation and mapped input.
|
|
780
|
+
*/
|
|
781
|
+
declare function parseRouterResponse(response: string, validNames: string[]): {
|
|
782
|
+
selectedOperation: string;
|
|
783
|
+
mappedInput: Record<string, unknown>;
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* Execute a natural language prompt by routing to the appropriate operation.
|
|
787
|
+
*/
|
|
788
|
+
declare function executePrompt(message: string, ir: ComponentIR, binding: RuntimeBinding, ctx: AaacInvocationContext, opts: PromptExecuteOptions): Promise<PromptResult>;
|
|
789
|
+
|
|
748
790
|
/**
|
|
749
791
|
* @aaac/runtime — public API
|
|
750
792
|
*
|
|
@@ -753,4 +795,4 @@ declare function guardStatus(opts?: GuardStatusOptions): Promise<GuardStatusResu
|
|
|
753
795
|
/** Package version string. */
|
|
754
796
|
declare const version: string;
|
|
755
797
|
|
|
756
|
-
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, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type EvaluateGuardrailOptions, type EvaluateGuardrailResult, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, type GuardStatusOptions, type GuardStatusResult, GuardrailCheckResult, GuardrailHooks, type GuardrailListEntry, type GuardrailResult, GuardrailRuleData, HandoffInput, HookResponse, LibraryToolDefinition, LibraryToolRegistry, type ListGuardrailsOptions, type ListGuardrailsResult, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type RequiredEntities, type ResolvedAdapterSelection, 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, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, evaluateGuardrail, executeTask, executeWorkflow, findProjectConfig, guardStatus, jsonSchemaToZod, listGuardrails, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, pluginRegistry, resolveArtifacts, version };
|
|
798
|
+
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, type CreateProjectRuntimeOptions, DelegateStep, type DslContext, DslValidationError, type EvaluateGuardrailOptions, type EvaluateGuardrailResult, type ExecuteOptions, type ExecuteTaskOptions, type ExecuteWorkflowOptions, FileMemoryStore, type GuardStatusOptions, type GuardStatusResult, GuardrailCheckResult, GuardrailHooks, type GuardrailListEntry, type GuardrailResult, GuardrailRuleData, HandoffInput, HookResponse, LibraryToolDefinition, LibraryToolRegistry, type ListGuardrailsOptions, type ListGuardrailsResult, type LoadDslOptions, MemoryRef, MemoryStore, type MemoryStoreEntry, type NavigationContext, type NavigationContextOptions, ObserverEmitFn, type OperationHandler, type OperationMemoryRefConfig, type OperationToolDef, PROJECT_CONFIG_FILENAME, type PermissionMode, type PluginLoadResult, PluginRegistry, type ProcessEditOptions, type ProcessTaskOptions, type ProcessWorkflowOptions, type ProgressSink, type ProgressSinkOptions, type ProjectRuntime, type PromptBuilderArgs, PromptBuilderOptions, type PromptExecuteOptions, type PromptResult, type RequiredEntities, type ResolvedAdapterSelection, 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, createProjectRuntime, createRuntime, createRuntimeBinding, emitProcessEdit, emitProcessTaskClose, emitProcessTaskOpen, emitProcessWorkflowClose, emitProcessWorkflowOpen, evaluateGuardrail, executePrompt, executeTask, executeWorkflow, findProjectConfig, guardStatus, jsonSchemaToZod, listGuardrails, loadDslContext, loadPlugins, loadPluginsFromDirectory, loadPluginsFromPaths, operationsToTools, parseRouterResponse, pluginRegistry, resolveArtifacts, version };
|
package/dist/index.js
CHANGED
|
@@ -3154,6 +3154,119 @@ async function guardStatus(opts = {}) {
|
|
|
3154
3154
|
};
|
|
3155
3155
|
}
|
|
3156
3156
|
|
|
3157
|
+
// src/lib/prompt-executor.ts
|
|
3158
|
+
import * as YAML5 from "yaml";
|
|
3159
|
+
function unwrapInputSchema(input) {
|
|
3160
|
+
if (!input) {
|
|
3161
|
+
return { type: "object", properties: {} };
|
|
3162
|
+
}
|
|
3163
|
+
if ("schema" in input && input.schema && typeof input.schema === "object") {
|
|
3164
|
+
return input.schema;
|
|
3165
|
+
}
|
|
3166
|
+
if ("$ref" in input) {
|
|
3167
|
+
return { type: "object", properties: {} };
|
|
3168
|
+
}
|
|
3169
|
+
return input;
|
|
3170
|
+
}
|
|
3171
|
+
function operationsToTools(ir) {
|
|
3172
|
+
return Object.entries(ir.operations).filter(([name, op]) => name !== "prompt" && !op.handler).map(([name, op]) => ({
|
|
3173
|
+
name,
|
|
3174
|
+
description: op.description,
|
|
3175
|
+
inputSchema: unwrapInputSchema(op.input)
|
|
3176
|
+
}));
|
|
3177
|
+
}
|
|
3178
|
+
function buildRouterPrompt(componentId, tools, message) {
|
|
3179
|
+
const toolDescriptions = tools.map((t) => {
|
|
3180
|
+
const schema = JSON.stringify(t.inputSchema, null, 2);
|
|
3181
|
+
return `### ${t.name}
|
|
3182
|
+
${t.description}
|
|
3183
|
+
Input schema:
|
|
3184
|
+
\`\`\`json
|
|
3185
|
+
${schema}
|
|
3186
|
+
\`\`\``;
|
|
3187
|
+
}).join("\n\n");
|
|
3188
|
+
return [
|
|
3189
|
+
`You are an operation router for the "${componentId}" CLI.`,
|
|
3190
|
+
`Understand the user request and call the appropriate operation.`,
|
|
3191
|
+
`Always select exactly one operation. Extract parameters from the user message.`,
|
|
3192
|
+
``,
|
|
3193
|
+
`## Available Operations`,
|
|
3194
|
+
``,
|
|
3195
|
+
toolDescriptions,
|
|
3196
|
+
``,
|
|
3197
|
+
`## Response Format`,
|
|
3198
|
+
``,
|
|
3199
|
+
`Respond with ONLY the following YAML:`,
|
|
3200
|
+
``,
|
|
3201
|
+
"```yaml",
|
|
3202
|
+
`operation: <operation_name>`,
|
|
3203
|
+
`input:`,
|
|
3204
|
+
` <key>: <value>`,
|
|
3205
|
+
"```",
|
|
3206
|
+
``,
|
|
3207
|
+
`## User Request`,
|
|
3208
|
+
``,
|
|
3209
|
+
message
|
|
3210
|
+
].join("\n");
|
|
3211
|
+
}
|
|
3212
|
+
function parseRouterResponse(response, validNames) {
|
|
3213
|
+
const yamlMatch = response.match(/```(?:yaml)?\n([\s\S]*?)```/);
|
|
3214
|
+
const content = yamlMatch ? yamlMatch[1].trim() : response.trim();
|
|
3215
|
+
let parsed;
|
|
3216
|
+
try {
|
|
3217
|
+
parsed = YAML5.parse(content);
|
|
3218
|
+
} catch {
|
|
3219
|
+
const jsonMatch = response.match(/\{[\s\S]*"operation"[\s\S]*\}/);
|
|
3220
|
+
if (jsonMatch) {
|
|
3221
|
+
try {
|
|
3222
|
+
parsed = JSON.parse(jsonMatch[0]);
|
|
3223
|
+
} catch {
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
if (parsed?.operation && typeof parsed.operation === "string") {
|
|
3228
|
+
if (!validNames.includes(parsed.operation)) {
|
|
3229
|
+
throw new Error(
|
|
3230
|
+
`Router selected unknown operation "${parsed.operation}". Available: ${validNames.join(", ")}`
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3233
|
+
return {
|
|
3234
|
+
selectedOperation: parsed.operation,
|
|
3235
|
+
mappedInput: parsed.input ?? {}
|
|
3236
|
+
};
|
|
3237
|
+
}
|
|
3238
|
+
throw new Error(
|
|
3239
|
+
`Could not parse operation routing from LLM response. Expected YAML with "operation" and "input" fields.
|
|
3240
|
+
Response:
|
|
3241
|
+
${response.slice(0, 500)}`
|
|
3242
|
+
);
|
|
3243
|
+
}
|
|
3244
|
+
async function executePrompt(message, ir, binding, ctx, opts) {
|
|
3245
|
+
const tools = operationsToTools(ir);
|
|
3246
|
+
if (tools.length < 2) {
|
|
3247
|
+
throw new Error(
|
|
3248
|
+
`prompt command requires at least 2 routable operations, found ${tools.length}`
|
|
3249
|
+
);
|
|
3250
|
+
}
|
|
3251
|
+
const prompt = buildRouterPrompt(ir.info.id, tools, message);
|
|
3252
|
+
const adapter = await createAdapter(opts.adapter, { model: opts.model });
|
|
3253
|
+
const response = await adapter.send(prompt, { readonly: true });
|
|
3254
|
+
const { selectedOperation, mappedInput } = parseRouterResponse(
|
|
3255
|
+
response,
|
|
3256
|
+
tools.map((t) => t.name)
|
|
3257
|
+
);
|
|
3258
|
+
if (opts.dryRun) {
|
|
3259
|
+
return {
|
|
3260
|
+
selectedOperation,
|
|
3261
|
+
mappedInput,
|
|
3262
|
+
dryRun: true,
|
|
3263
|
+
model: opts.model
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
const output = await binding.execute(selectedOperation, {}, mappedInput, ctx);
|
|
3267
|
+
return { selectedOperation, mappedInput, output };
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3157
3270
|
// src/index.ts
|
|
3158
3271
|
var require2 = createRequire(import.meta.url);
|
|
3159
3272
|
var pkg = require2("../package.json");
|
|
@@ -3205,6 +3318,7 @@ export {
|
|
|
3205
3318
|
emitToolchainClose,
|
|
3206
3319
|
emitToolchainOpen,
|
|
3207
3320
|
evaluateGuardrail,
|
|
3321
|
+
executePrompt,
|
|
3208
3322
|
executeTask,
|
|
3209
3323
|
executeWorkflow,
|
|
3210
3324
|
extractStructuredResult,
|
|
@@ -3222,7 +3336,9 @@ export {
|
|
|
3222
3336
|
loadPlugins,
|
|
3223
3337
|
loadPluginsFromDirectory,
|
|
3224
3338
|
loadPluginsFromPaths,
|
|
3339
|
+
operationsToTools,
|
|
3225
3340
|
parseGateEvaluationResponse,
|
|
3341
|
+
parseRouterResponse,
|
|
3226
3342
|
pluginRegistry,
|
|
3227
3343
|
renderAgentSystemPrompt,
|
|
3228
3344
|
resolveArtifacts,
|