@agnt-sdk/studio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +162 -0
  2. package/dist/AgntExecutor.d.ts +56 -0
  3. package/dist/AgntExecutor.d.ts.map +1 -0
  4. package/dist/AgntExecutor.js +117 -0
  5. package/dist/AgntExecutor.js.map +1 -0
  6. package/dist/BaseExecutor.d.ts +69 -0
  7. package/dist/BaseExecutor.d.ts.map +1 -0
  8. package/dist/BaseExecutor.js +528 -0
  9. package/dist/BaseExecutor.js.map +1 -0
  10. package/dist/ImageCache.d.ts +94 -0
  11. package/dist/ImageCache.d.ts.map +1 -0
  12. package/dist/ImageCache.js +232 -0
  13. package/dist/ImageCache.js.map +1 -0
  14. package/dist/cli/commands/init.d.ts +5 -0
  15. package/dist/cli/commands/init.d.ts.map +1 -0
  16. package/dist/cli/commands/init.js +47 -0
  17. package/dist/cli/commands/init.js.map +1 -0
  18. package/dist/cli/commands/pull.d.ts +10 -0
  19. package/dist/cli/commands/pull.d.ts.map +1 -0
  20. package/dist/cli/commands/pull.js +82 -0
  21. package/dist/cli/commands/pull.js.map +1 -0
  22. package/dist/cli/index.d.ts +6 -0
  23. package/dist/cli/index.d.ts.map +1 -0
  24. package/dist/cli/index.js +28 -0
  25. package/dist/cli/index.js.map +1 -0
  26. package/dist/cli/utils/api.d.ts +38 -0
  27. package/dist/cli/utils/api.d.ts.map +1 -0
  28. package/dist/cli/utils/api.js +44 -0
  29. package/dist/cli/utils/api.js.map +1 -0
  30. package/dist/cli/utils/config.d.ts +5 -0
  31. package/dist/cli/utils/config.d.ts.map +1 -0
  32. package/dist/cli/utils/config.js +5 -0
  33. package/dist/cli/utils/config.js.map +1 -0
  34. package/dist/conditions.d.ts +14 -0
  35. package/dist/conditions.d.ts.map +1 -0
  36. package/dist/conditions.js +59 -0
  37. package/dist/conditions.js.map +1 -0
  38. package/dist/executorFactory.d.ts +10 -0
  39. package/dist/executorFactory.d.ts.map +1 -0
  40. package/dist/executorFactory.js +45 -0
  41. package/dist/executorFactory.js.map +1 -0
  42. package/dist/index.d.ts +21 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +26 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/providers/anthropic.d.ts +22 -0
  47. package/dist/providers/anthropic.d.ts.map +1 -0
  48. package/dist/providers/anthropic.js +280 -0
  49. package/dist/providers/anthropic.js.map +1 -0
  50. package/dist/providers/bedrock.d.ts +23 -0
  51. package/dist/providers/bedrock.d.ts.map +1 -0
  52. package/dist/providers/bedrock.js +281 -0
  53. package/dist/providers/bedrock.js.map +1 -0
  54. package/dist/providers/deepseek.d.ts +22 -0
  55. package/dist/providers/deepseek.d.ts.map +1 -0
  56. package/dist/providers/deepseek.js +193 -0
  57. package/dist/providers/deepseek.js.map +1 -0
  58. package/dist/providers/google.d.ts +22 -0
  59. package/dist/providers/google.d.ts.map +1 -0
  60. package/dist/providers/google.js +357 -0
  61. package/dist/providers/google.js.map +1 -0
  62. package/dist/providers/openai.d.ts +22 -0
  63. package/dist/providers/openai.d.ts.map +1 -0
  64. package/dist/providers/openai.js +194 -0
  65. package/dist/providers/openai.js.map +1 -0
  66. package/dist/systemTools.d.ts +6 -0
  67. package/dist/systemTools.d.ts.map +1 -0
  68. package/dist/systemTools.js +15 -0
  69. package/dist/systemTools.js.map +1 -0
  70. package/dist/tracing.d.ts +32 -0
  71. package/dist/tracing.d.ts.map +1 -0
  72. package/dist/tracing.js +38 -0
  73. package/dist/tracing.js.map +1 -0
  74. package/dist/types.d.ts +280 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +5 -0
  77. package/dist/types.js.map +1 -0
  78. package/package.json +76 -0
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # @agnt-sdk/studio
2
+
3
+ V2 manifest-native LLM executor for [Agnt](https://agnt.ai) prompts, with a CLI for pulling and running agent manifests locally.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @agnt-sdk/studio
9
+ ```
10
+
11
+ For the CLI:
12
+
13
+ ```bash
14
+ npm install -g @agnt-sdk/studio
15
+ agnt --help
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ Create `agnt.config.js` at your project root. See [`@agnt-sdk/config`](../config) for the full reference.
21
+
22
+ ```js
23
+ // agnt.config.js
24
+ export default {
25
+ privateKey: `-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----`,
26
+ kid: 'your-key-id',
27
+ apiUrl: 'https://api.agnt.ai',
28
+ serviceKey: '',
29
+ outputDir: './agnt/prompts',
30
+ apiMode: true, // false = load from local files (after agnt pull)
31
+ };
32
+ ```
33
+
34
+ ## CLI
35
+
36
+ ### `agnt pull`
37
+
38
+ Pull one or all prompt manifests from the Agnt platform into your local `outputDir`:
39
+
40
+ ```bash
41
+ # Pull a specific prompt
42
+ agnt pull myaccount/flight-planner
43
+
44
+ # Pull all public prompts for an account
45
+ agnt pull myaccount/*
46
+ ```
47
+
48
+ Manifests are saved to `outputDir/accountSlug/promptSlug.json`. Set `apiMode: false` in your config to execute from these local files instead of fetching from the API on every run.
49
+
50
+ ### `agnt init`
51
+
52
+ Scaffold an `agnt.config.js` in the current directory:
53
+
54
+ ```bash
55
+ agnt init
56
+ ```
57
+
58
+ ## Programmatic use
59
+
60
+ ### `AgntExecutor`
61
+
62
+ Execute a prompt by address (`accountSlug/promptSlug`). Fetches the manifest from the API or a local file depending on `apiMode`.
63
+
64
+ ```ts
65
+ import { AgntExecutor } from '@agnt-sdk/studio';
66
+
67
+ const executor = await AgntExecutor.create({
68
+ credentials: {
69
+ anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
70
+ },
71
+ });
72
+
73
+ const result = await executor.execute(
74
+ 'myaccount/flight-planner',
75
+ { destination: 'New York', departDate: '2025-06-15' },
76
+ {
77
+ // optional tool implementations
78
+ get_flights: {
79
+ execute: async (args) => { /* ... */ }
80
+ }
81
+ }
82
+ );
83
+
84
+ console.log(result.result); // final output
85
+ console.log(result.messages); // full message history
86
+ console.log(result.usage); // token usage + cost
87
+ ```
88
+
89
+ ### `createExecutor`
90
+
91
+ Lower-level factory — takes a V2 `PromptManifestV2` object directly:
92
+
93
+ ```ts
94
+ import { createExecutor } from '@agnt-sdk/studio';
95
+
96
+ const executor = await createExecutor({
97
+ manifest,
98
+ credentials: {
99
+ anthropic: { apiKey: process.env.ANTHROPIC_API_KEY },
100
+ },
101
+ variables: { key: 'value' },
102
+ toolRouter: { /* tool implementations */ },
103
+ });
104
+
105
+ const result = await executor.execute();
106
+ ```
107
+
108
+ ## Logging
109
+
110
+ Pass `logLevel` to control output verbosity:
111
+
112
+ ```ts
113
+ const executor = await createExecutor({
114
+ manifest,
115
+ credentials,
116
+ logLevel: 'debug', // 'debug' | 'info' | 'silent' (default: 'info')
117
+ });
118
+ ```
119
+
120
+ - `'info'` — lifecycle events (model selection, tool calls)
121
+ - `'debug'` — full request/response payloads sent to the LLM
122
+ - `'silent'` — no output
123
+
124
+ ## V2 Manifest format
125
+
126
+ ```json
127
+ {
128
+ "$schema": "https://agnt.ai/schemas/manifest/v2.json",
129
+ "kind": "PromptManifest",
130
+ "apiVersion": "v2",
131
+ "metadata": {
132
+ "name": "flight-planner",
133
+ "title": "Flight Planner",
134
+ "description": "Books flights based on user preferences."
135
+ },
136
+ "spec": {
137
+ "routingStrategy": "fallback",
138
+ "enableToolCalls": true,
139
+ "variables": [],
140
+ "models": [
141
+ { "provider": "anthropic", "model": "claude-sonnet-4-5" }
142
+ ],
143
+ "tools": [],
144
+ "files": [],
145
+ "dependencies": []
146
+ }
147
+ }
148
+ ```
149
+
150
+ ## Supported providers
151
+
152
+ | Provider | Credentials key |
153
+ |---|---|
154
+ | Anthropic | `credentials.anthropic.apiKey` |
155
+ | OpenAI | `credentials.openai.apiKey` |
156
+ | AWS Bedrock | `credentials.bedrock.{ region, accessKeyId, secretAccessKey }` |
157
+ | DeepSeek | `credentials.deepseek.apiKey` |
158
+ | Google Gemini | `credentials.google.apiKey` |
159
+
160
+ ## License
161
+
162
+ MIT
@@ -0,0 +1,56 @@
1
+ /**
2
+ * AgntExecutor
3
+ *
4
+ * High-level executor that loads v2 PromptManifests by address
5
+ * (`accountSlug/promptSlug`) from the Agnt API or local files,
6
+ * then executes them via the appropriate provider adapter.
7
+ *
8
+ * Usage:
9
+ * const executor = await AgntExecutor.create({ credentials });
10
+ * const result = await executor.execute('skej/contact-collector', variables, toolRouter);
11
+ */
12
+ import { AgntApiClient } from './cli/utils/api.js';
13
+ import type { ProviderCredentials, ExecutionResult, ToolRouter, ToolCallCallback, TracingConfig, AgntConfig, Message } from './types.js';
14
+ export interface AgntExecutorConfig {
15
+ credentials: ProviderCredentials;
16
+ config?: AgntConfig;
17
+ }
18
+ export interface AgntExecuteOptions {
19
+ onToolCall?: ToolCallCallback;
20
+ tracing?: Pick<TracingConfig, 'enabled' | 'tags'>;
21
+ files?: Array<{
22
+ type: string;
23
+ image_url?: {
24
+ url: string;
25
+ };
26
+ input_audio?: {
27
+ data: string;
28
+ format: string;
29
+ };
30
+ }>;
31
+ apiMode?: boolean;
32
+ initialToolChoice?: string;
33
+ messages?: Message[];
34
+ }
35
+ export declare class AgntExecutor {
36
+ private credentials;
37
+ private config;
38
+ private client;
39
+ private constructor();
40
+ static create(options: AgntExecutorConfig): Promise<AgntExecutor>;
41
+ /**
42
+ * Execute a prompt by address.
43
+ *
44
+ * @param address `accountSlug/promptSlug`
45
+ * @param variables Runtime variables
46
+ * @param toolRouter Tool implementations
47
+ * @param options Optional execution options
48
+ */
49
+ execute(address: string, variables?: Record<string, any>, toolRouter?: ToolRouter, options?: AgntExecuteOptions): Promise<ExecutionResult>;
50
+ private parseAddress;
51
+ private loadFromApi;
52
+ private loadFromFile;
53
+ getConfig(): AgntConfig;
54
+ getClient(): AgntApiClient;
55
+ }
56
+ //# sourceMappingURL=AgntExecutor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgntExecutor.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3B,OAAO,CAAC,eAAe,CAAC;IAsC3B,OAAO,CAAC,YAAY;YAWN,WAAW;YAIX,YAAY;IA2B1B,SAAS,IAAI,UAAU;IAIvB,SAAS,IAAI,aAAa;CAG3B"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * AgntExecutor
3
+ *
4
+ * High-level executor that loads v2 PromptManifests by address
5
+ * (`accountSlug/promptSlug`) from the Agnt API or local files,
6
+ * then executes them via the appropriate provider adapter.
7
+ *
8
+ * Usage:
9
+ * const executor = await AgntExecutor.create({ credentials });
10
+ * const result = await executor.execute('skej/contact-collector', variables, toolRouter);
11
+ */
12
+ import { createExecutor } from './executorFactory.js';
13
+ import { AgntApiClient } from './cli/utils/api.js';
14
+ import { loadConfig } from './cli/utils/config.js';
15
+ export class AgntExecutor {
16
+ credentials;
17
+ config;
18
+ client;
19
+ constructor(credentials, config) {
20
+ this.credentials = credentials;
21
+ this.config = config;
22
+ this.client = new AgntApiClient({
23
+ apiUrl: config.apiUrl,
24
+ serviceKey: config.serviceKey
25
+ });
26
+ }
27
+ static async create(options) {
28
+ let config = options.config;
29
+ if (!config) {
30
+ const loaded = await loadConfig();
31
+ if (!loaded) {
32
+ throw new Error('No agnt.config.js found. Run: agnt init');
33
+ }
34
+ config = loaded;
35
+ }
36
+ return new AgntExecutor(options.credentials, config);
37
+ }
38
+ /**
39
+ * Execute a prompt by address.
40
+ *
41
+ * @param address `accountSlug/promptSlug`
42
+ * @param variables Runtime variables
43
+ * @param toolRouter Tool implementations
44
+ * @param options Optional execution options
45
+ */
46
+ async execute(address, variables = {}, toolRouter = {}, options) {
47
+ const { accountSlug, promptSlug } = this.parseAddress(address);
48
+ const useApi = options?.apiMode !== undefined ? options.apiMode : this.config.apiMode;
49
+ const manifest = useApi
50
+ ? await this.loadFromApi(accountSlug, promptSlug)
51
+ : await this.loadFromFile(accountSlug, promptSlug);
52
+ const tracingConfig = options?.tracing ? {
53
+ enabled: options.tracing.enabled,
54
+ apiUrl: this.config.apiUrl,
55
+ serviceKey: this.config.serviceKey,
56
+ promptName: address,
57
+ etag: manifest.metadata.etag,
58
+ tags: options.tracing.tags
59
+ } : undefined;
60
+ const executor = await createExecutor({
61
+ manifest,
62
+ credentials: this.credentials,
63
+ variables,
64
+ toolRouter,
65
+ maxMessages: this.config.maxMessages,
66
+ onToolCall: options?.onToolCall,
67
+ tracing: tracingConfig,
68
+ files: options?.files,
69
+ initialToolChoice: options?.initialToolChoice,
70
+ messages: options?.messages
71
+ });
72
+ return executor.execute();
73
+ }
74
+ // ─────────────────────────────────────────────────────────────────────────────
75
+ // Loading
76
+ // ─────────────────────────────────────────────────────────────────────────────
77
+ parseAddress(address) {
78
+ const parts = address.split('/');
79
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
80
+ throw new Error(`[AgntExecutor] Invalid prompt address: "${address}". ` +
81
+ 'Expected format: "accountSlug/promptSlug"');
82
+ }
83
+ return { accountSlug: parts[0], promptSlug: parts[1] };
84
+ }
85
+ async loadFromApi(accountSlug, promptSlug) {
86
+ return this.client.getManifest(accountSlug, promptSlug);
87
+ }
88
+ async loadFromFile(accountSlug, promptSlug) {
89
+ if (typeof process === 'undefined' || !process.versions?.node) {
90
+ throw new Error('File mode is only supported in Node.js. Use apiMode: true for browser.');
91
+ }
92
+ const { join, resolve } = await import('path');
93
+ const { readFile } = await import('fs/promises');
94
+ const outputDir = resolve(this.config.outputDir);
95
+ const filePath = join(outputDir, accountSlug, `${promptSlug}.json`);
96
+ try {
97
+ const content = await readFile(filePath, 'utf-8');
98
+ const parsed = JSON.parse(content);
99
+ // File format: { manifest: PromptManifestV2, pulledAt: ISO }
100
+ return parsed.manifest ?? parsed;
101
+ }
102
+ catch (err) {
103
+ if (err.code === 'ENOENT') {
104
+ throw new Error(`Prompt file not found: ${filePath}\n` +
105
+ `Run 'agnt pull ${accountSlug}/${promptSlug}' to download it.`);
106
+ }
107
+ throw err;
108
+ }
109
+ }
110
+ getConfig() {
111
+ return { ...this.config };
112
+ }
113
+ getClient() {
114
+ return this.client;
115
+ }
116
+ }
117
+ //# sourceMappingURL=AgntExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgntExecutor.js","sourceRoot":"","sources":["../src/AgntExecutor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AA0BnD,MAAM,OAAO,YAAY;IACf,WAAW,CAAsB;IACjC,MAAM,CAAa;IACnB,MAAM,CAAgB;IAE9B,YAAoB,WAAgC,EAAE,MAAkB;QACtE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA2B;QAC7C,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAC7D,CAAC;YACD,MAAM,GAAG,MAAM,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CACX,OAAe,EACf,YAAiC,EAAE,EACnC,aAAyB,EAAE,EAC3B,OAA4B;QAE5B,MAAM,EAAE,WAAW,EAAE,UAA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,CAAC;YACnC,6DAA6D;YAC7D,OAAO,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC;QACnC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,IAAI;oBACtC,kBAAkB,WAAW,IAAI,UAAU,mBAAmB,CAC/D,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAED,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * BaseExecutor — V2 PromptManifest native executor
3
+ *
4
+ * Operates directly on the v2 manifest spec:
5
+ * - Renders files/blocks from spec.files[] (no pre-compiled system/user strings)
6
+ * - Evaluates conditions on files, blocks, tools, and models at runtime
7
+ * - Respects enableToolCalls: false (skips tool loop, returns raw LLM text)
8
+ * - Routes models via routingStrategy (fallback | random | conditional)
9
+ */
10
+ import type { BaseExecutorConfig, PromptManifestV2, V2ModelConfig, PromptBlock, Message, ToolCall, ToolResult, ToolDefinition, InvokeOptions, InvokeResult, ExecutionResult, Usage, ToolRouter, ToolCallCallback, TracingConfig, ModelPricing } from './types.js';
11
+ export default class BaseExecutor {
12
+ protected manifest: PromptManifestV2;
13
+ protected variables: Record<string, any>;
14
+ protected toolRouter: ToolRouter;
15
+ protected credentials: any;
16
+ protected log: (message: string, ...args: any[]) => void;
17
+ protected debug: (message: string, ...args: any[]) => void;
18
+ protected messages: Message[];
19
+ protected onToolCall?: ToolCallCallback;
20
+ protected cancelled: boolean;
21
+ protected toolErrorCount: Record<string, number>;
22
+ protected forceNextTool?: string;
23
+ protected executorFactory?: (config: BaseExecutorConfig) => Promise<any>;
24
+ protected instructions: string;
25
+ protected primaryModelConfig: V2ModelConfig & {
26
+ name: string;
27
+ };
28
+ protected provider: string;
29
+ protected model: string;
30
+ protected allToolDefs: ToolDefinition[];
31
+ protected tracing?: TracingConfig;
32
+ protected files?: Array<any>;
33
+ protected maxMessages: number;
34
+ protected modelPricing?: ModelPricing;
35
+ protected initialToolChoice: 'auto' | 'required' | 'none' | string;
36
+ constructor({ manifest, variables, toolRouter, credentials, messages, onToolCall, log, logLevel, tracing, files, maxMessages, initialToolChoice, executorFactory }: BaseExecutorConfig);
37
+ protected validateManifest(): void;
38
+ protected selectPrimaryModel(): V2ModelConfig;
39
+ protected buildToolDefinitions(): ToolDefinition[];
40
+ /**
41
+ * Reorder tool schema properties so reasoning fields appear first.
42
+ * Ensures LLM generates reason before action when strict: true.
43
+ */
44
+ protected processToolDefinition(tool: ToolDefinition): ToolDefinition;
45
+ protected reorderReasoningFields(schema: any): any;
46
+ /**
47
+ * Render all files for a given section into a single string.
48
+ */
49
+ protected renderSection(section: 'system' | 'messages'): string;
50
+ protected renderBlocks(blocks: PromptBlock[]): string;
51
+ protected renderBlock(block: PromptBlock): string;
52
+ protected buildInstructions(): string;
53
+ protected populateTemplate(template: string, variables: Record<string, any>): string;
54
+ protected normalizeToolChoice(toolChoice: 'auto' | 'required' | 'none' | string): any;
55
+ cancel(): boolean;
56
+ protected validateVariables(): void;
57
+ protected buildInitialMessages(): Message[];
58
+ protected calculateCost(inputTokens: number, outputTokens: number): number;
59
+ execute(): Promise<ExecutionResult>;
60
+ protected runToolLoop(message: Message, usage: Usage): Promise<any>;
61
+ protected handleToolCalls(toolCalls: ToolCall[]): Promise<ToolResult[]>;
62
+ protected sendTurnTrace(turnUsage: {
63
+ input_tokens: number;
64
+ output_tokens: number;
65
+ }, turnDuration: number, cost: number): Promise<void>;
66
+ invoke(_messages: Message[], _options: InvokeOptions): Promise<InvokeResult>;
67
+ hasToolCalls(_message: Message): boolean;
68
+ }
69
+ //# sourceMappingURL=BaseExecutor.d.ts.map
@@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