@aigne/core 1.63.0-beta.9 → 1.64.0-beta

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 (48) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/lib/cjs/agents/agent.js +1 -1
  3. package/lib/cjs/agents/ai-agent.js +35 -5
  4. package/lib/cjs/agents/chat-model.d.ts +4 -0
  5. package/lib/cjs/agents/chat-model.js +7 -2
  6. package/lib/cjs/agents/image-agent.d.ts +2 -0
  7. package/lib/cjs/agents/image-agent.js +14 -2
  8. package/lib/cjs/agents/team-agent.js +35 -2
  9. package/lib/cjs/aigne/aigne.d.ts +6 -1
  10. package/lib/cjs/aigne/aigne.js +6 -0
  11. package/lib/cjs/aigne/context.d.ts +4 -1
  12. package/lib/cjs/aigne/context.js +4 -0
  13. package/lib/cjs/aigne/type.d.ts +14 -0
  14. package/lib/cjs/loader/agent-yaml.d.ts +2 -0
  15. package/lib/cjs/loader/agent-yaml.js +1 -0
  16. package/lib/cjs/prompt/prompt-builder.d.ts +7 -1
  17. package/lib/cjs/prompt/prompt-builder.js +14 -2
  18. package/lib/cjs/utils/model-utils.js +1 -0
  19. package/lib/cjs/utils/queue.d.ts +57 -0
  20. package/lib/cjs/utils/queue.js +318 -0
  21. package/lib/dts/agents/chat-model.d.ts +4 -0
  22. package/lib/dts/agents/image-agent.d.ts +2 -0
  23. package/lib/dts/aigne/aigne.d.ts +6 -1
  24. package/lib/dts/aigne/context.d.ts +4 -1
  25. package/lib/dts/aigne/type.d.ts +14 -0
  26. package/lib/dts/loader/agent-yaml.d.ts +2 -0
  27. package/lib/dts/prompt/prompt-builder.d.ts +7 -1
  28. package/lib/dts/utils/queue.d.ts +57 -0
  29. package/lib/esm/agents/agent.js +1 -1
  30. package/lib/esm/agents/ai-agent.js +1 -1
  31. package/lib/esm/agents/chat-model.d.ts +4 -0
  32. package/lib/esm/agents/chat-model.js +7 -2
  33. package/lib/esm/agents/image-agent.d.ts +2 -0
  34. package/lib/esm/agents/image-agent.js +14 -2
  35. package/lib/esm/agents/team-agent.js +1 -1
  36. package/lib/esm/aigne/aigne.d.ts +6 -1
  37. package/lib/esm/aigne/aigne.js +6 -0
  38. package/lib/esm/aigne/context.d.ts +4 -1
  39. package/lib/esm/aigne/context.js +4 -0
  40. package/lib/esm/aigne/type.d.ts +14 -0
  41. package/lib/esm/loader/agent-yaml.d.ts +2 -0
  42. package/lib/esm/loader/agent-yaml.js +1 -0
  43. package/lib/esm/prompt/prompt-builder.d.ts +7 -1
  44. package/lib/esm/prompt/prompt-builder.js +14 -2
  45. package/lib/esm/utils/model-utils.js +1 -0
  46. package/lib/esm/utils/queue.d.ts +57 -0
  47. package/lib/esm/utils/queue.js +315 -0
  48. package/package.json +4 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.64.0-beta](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0...core-v1.64.0-beta) (2025-10-21)
4
+
5
+
6
+ ### Features
7
+
8
+ * add thinking support to Gemini chat models ([#650](https://github.com/AIGNE-io/aigne-framework/issues/650)) ([09b828b](https://github.com/AIGNE-io/aigne-framework/commit/09b828ba668d90cc6aac68a5e8190adb146b5e45))
9
+ * add user context support to prompt template variables ([#649](https://github.com/AIGNE-io/aigne-framework/issues/649)) ([a02d9b4](https://github.com/AIGNE-io/aigne-framework/commit/a02d9b412878050b8c1e32127b505c0346f19bba))
10
+ * **cli:** add metadata traces including CLI version, app name, and version ([#646](https://github.com/AIGNE-io/aigne-framework/issues/646)) ([c64bd76](https://github.com/AIGNE-io/aigne-framework/commit/c64bd761ba4c9f3854be5feee208c711bff7a170))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **gemini:** handle empty responses when files are present ([#648](https://github.com/AIGNE-io/aigne-framework/issues/648)) ([f4e259c](https://github.com/AIGNE-io/aigne-framework/commit/f4e259c5e5c687c347bb5cf29cbb0b5bf4d0d4a1))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @aigne/observability-api bumped to 0.11.3-beta
23
+
24
+ ## [1.63.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.12...core-v1.63.0) (2025-10-19)
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @aigne/afs bumped to 1.1.0
32
+ * @aigne/observability-api bumped to 0.11.2
33
+
34
+ ## [1.63.0-beta.12](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.11...core-v1.63.0-beta.12) (2025-10-17)
35
+
36
+
37
+ ### Bug Fixes
38
+
39
+ * custom queue instead of fastq to compatible with browser ([#640](https://github.com/AIGNE-io/aigne-framework/issues/640)) ([51e0f8f](https://github.com/AIGNE-io/aigne-framework/commit/51e0f8fdeaf26f2765f392218f04a2af4c0d2e1a))
40
+
41
+ ## [1.63.0-beta.11](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.10...core-v1.63.0-beta.11) (2025-10-17)
42
+
43
+
44
+ ### Bug Fixes
45
+
46
+ * **gemini:** implement retry mechanism for empty responses with structured output fallback ([#638](https://github.com/AIGNE-io/aigne-framework/issues/638)) ([d33c8bb](https://github.com/AIGNE-io/aigne-framework/commit/d33c8bb9711aadddef9687d6cf472a179cd8ed9c))
47
+
48
+ ## [1.63.0-beta.10](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.9...core-v1.63.0-beta.10) (2025-10-16)
49
+
50
+
51
+ ### Dependencies
52
+
53
+ * The following workspace dependencies were updated
54
+ * dependencies
55
+ * @aigne/observability-api bumped to 0.11.2-beta.5
56
+
3
57
  ## [1.63.0-beta.9](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.63.0-beta.8...core-v1.63.0-beta.9) (2025-10-16)
4
58
 
5
59
 
@@ -476,7 +476,7 @@ class Agent {
476
476
  if (!res.retry) {
477
477
  const e = res.error ?? error;
478
478
  if (attempt > 0)
479
- e.message += ` (after ${attempt} retries)`;
479
+ e.message += ` (after ${attempt + 1} retries)`;
480
480
  throw e;
481
481
  }
482
482
  }
@@ -1,14 +1,44 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
5
35
  Object.defineProperty(exports, "__esModule", { value: true });
6
36
  exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = exports.AIAgentToolChoice = exports.DEFAULT_OUTPUT_FILE_KEY = exports.DEFAULT_OUTPUT_KEY = void 0;
7
- const fastq_1 = __importDefault(require("fastq"));
8
37
  const zod_1 = require("zod");
9
38
  const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
10
39
  const structured_stream_instructions_js_1 = require("../prompt/prompts/structured-stream-instructions.js");
11
40
  const template_js_1 = require("../prompt/template.js");
41
+ const fastq = __importStar(require("../utils/queue.js"));
12
42
  const structured_stream_extractor_js_1 = require("../utils/structured-stream-extractor.js");
13
43
  const type_utils_js_1 = require("../utils/type-utils.js");
14
44
  const agent_js_1 = require("./agent.js");
@@ -319,7 +349,7 @@ class AIAgent extends agent_js_1.Agent {
319
349
  }
320
350
  const executedToolCalls = [];
321
351
  let error;
322
- const queue = fastq_1.default.promise(async ({ tool, call }) => {
352
+ const queue = fastq.promise(async ({ tool, call }) => {
323
353
  try {
324
354
  // NOTE: should pass both arguments (model generated) and input (user provided) to the tool
325
355
  const output = await this.invokeSkill(tool, { ...input, ...call.function.arguments }, options).catch((error) => {
@@ -407,6 +407,10 @@ export interface ChatModelOutput extends Message {
407
407
  * Text format response content
408
408
  */
409
409
  text?: string;
410
+ /**
411
+ * Model's internal thoughts (if supported)
412
+ */
413
+ thoughts?: string;
410
414
  /**
411
415
  * JSON format response content
412
416
  */
@@ -38,11 +38,12 @@ const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
38
38
  const zod_1 = require("zod");
39
39
  const zod_from_json_schema_1 = require("zod-from-json-schema");
40
40
  const json_schema_js_1 = require("../utils/json-schema.js");
41
+ const logger_js_1 = require("../utils/logger.js");
41
42
  const type_utils_js_1 = require("../utils/type-utils.js");
42
43
  const agent_js_1 = require("./agent.js");
43
44
  const model_js_1 = require("./model.js");
44
45
  const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
45
- retries: 10,
46
+ retries: 3,
46
47
  shouldRetry: async (error) => error instanceof StructuredOutputError || (await Promise.resolve().then(() => __importStar(require("is-network-error")))).default(error),
47
48
  };
48
49
  class StructuredOutputError extends Error {
@@ -215,7 +216,10 @@ class ChatModel extends model_js_1.Model {
215
216
  */
216
217
  async postprocess(input, output, options) {
217
218
  super.postprocess(input, output, options);
218
- const { usage } = output;
219
+ const { usage, thoughts, model } = output;
220
+ if (thoughts) {
221
+ logger_js_1.logger.info(`Model Thoughts (${model}): ${thoughts}`);
222
+ }
219
223
  if (usage) {
220
224
  options.context.usage.outputTokens += usage.outputTokens;
221
225
  options.context.usage.inputTokens += usage.inputTokens;
@@ -360,6 +364,7 @@ exports.chatModelOutputUsageSchema = zod_1.z.object({
360
364
  });
361
365
  const chatModelOutputSchema = zod_1.z.object({
362
366
  text: zod_1.z.string().optional(),
367
+ thoughts: zod_1.z.string().optional(),
363
368
  json: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
364
369
  toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
365
370
  usage: exports.chatModelOutputUsageSchema.optional(),
@@ -5,6 +5,7 @@ import { type ImageModelOutput } from "./image-model.js";
5
5
  import { type FileType } from "./model.js";
6
6
  export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
7
7
  instructions: string | PromptBuilder;
8
+ inputFileKey?: string;
8
9
  modelOptions?: Record<string, any>;
9
10
  outputFileType?: FileType;
10
11
  }
@@ -16,6 +17,7 @@ export declare class ImageAgent<I extends Message = any, O extends ImageModelOut
16
17
  static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
17
18
  constructor(options: ImageAgentOptions<I, O>);
18
19
  instructions: PromptBuilder;
20
+ inputFileKey?: string;
19
21
  modelOptions?: Record<string, any>;
20
22
  outputFileType?: FileType;
21
23
  process(input: I, options: AgentInvokeOptions): Promise<O>;
@@ -27,18 +27,30 @@ class ImageAgent extends agent_js_1.Agent {
27
27
  typeof options.instructions === "string"
28
28
  ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
29
29
  : options.instructions;
30
+ this.inputFileKey = options.inputFileKey;
30
31
  this.modelOptions = options.modelOptions;
31
32
  this.outputFileType = options.outputFileType;
32
33
  }
33
34
  instructions;
35
+ inputFileKey;
34
36
  modelOptions;
35
37
  outputFileType;
36
38
  async process(input, options) {
37
39
  const imageModel = this.imageModel || options.imageModel || options.context.imageModel;
38
40
  if (!imageModel)
39
41
  throw new Error("image model is required to run ImageAgent");
40
- const { prompt } = await this.instructions.buildImagePrompt({ input });
41
- return (await this.invokeChildAgent(imageModel, { ...input, modelOptions: this.modelOptions, prompt, outputFileType: this.outputFileType }, { ...options, streaming: false }));
42
+ const { prompt, image } = await this.instructions.buildImagePrompt({
43
+ ...options,
44
+ input,
45
+ agent: this,
46
+ });
47
+ return (await this.invokeChildAgent(imageModel, {
48
+ ...input,
49
+ modelOptions: this.modelOptions,
50
+ prompt,
51
+ image,
52
+ outputFileType: this.outputFileType,
53
+ }, { ...options, streaming: false }));
42
54
  }
43
55
  }
44
56
  exports.ImageAgent = ImageAgent;
@@ -1,12 +1,45 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
37
  };
5
38
  Object.defineProperty(exports, "__esModule", { value: true });
6
39
  exports.TeamAgent = exports.DEFAULT_REFLECTION_MAX_ITERATIONS = exports.ProcessMode = void 0;
7
40
  const node_assert_1 = __importDefault(require("node:assert"));
8
- const fastq_1 = __importDefault(require("fastq"));
9
41
  const immer_1 = require("immer");
42
+ const fastq = __importStar(require("../utils/queue.js"));
10
43
  const stream_utils_js_1 = require("../utils/stream-utils.js");
11
44
  const type_utils_js_1 = require("../utils/type-utils.js");
12
45
  const agent_js_1 = require("./agent.js");
@@ -201,7 +234,7 @@ class TeamAgent extends agent_js_1.Agent {
201
234
  arr = Array.isArray(arr) ? [...arr] : (0, type_utils_js_1.isNil)(arr) ? [arr] : [];
202
235
  const results = new Array(arr.length);
203
236
  let error;
204
- const queue = fastq_1.default.promise(async ({ item, index }) => {
237
+ const queue = fastq.promise(async ({ item, index }) => {
205
238
  try {
206
239
  if (!(0, type_utils_js_1.isRecord)(item))
207
240
  throw new TypeError(`Expected ${String(key)} to be an object, got ${typeof item}`);
@@ -6,7 +6,7 @@ import type { UserAgent } from "../agents/user-agent.js";
6
6
  import { type LoadOptions } from "../loader/index.js";
7
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
8
8
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
9
- import type { AIGNECLIAgents } from "./type.js";
9
+ import type { AIGNECLIAgents, AIGNEMetadata } from "./type.js";
10
10
  import type { ContextLimits } from "./usage.js";
11
11
  /**
12
12
  * Options for the AIGNE class.
@@ -53,6 +53,7 @@ export interface AIGNEOptions {
53
53
  * Observer for the AIGNE instance.
54
54
  */
55
55
  observer?: AIGNEObserver;
56
+ metadata?: AIGNEMetadata;
56
57
  }
57
58
  /**
58
59
  * AIGNE is a class that orchestrates multiple agents to build complex AI applications.
@@ -136,6 +137,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
136
137
  * Observer for the AIGNE instance.
137
138
  */
138
139
  readonly observer?: AIGNEObserver;
140
+ /**
141
+ * Metadata for the AIGNE instance.
142
+ */
143
+ readonly metadata: AIGNEMetadata;
139
144
  /**
140
145
  * Adds one or more agents to this AIGNE instance.
141
146
  * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
@@ -37,6 +37,7 @@ class AIGNE {
37
37
  imageModel,
38
38
  agents: agents.concat(options?.agents ?? []),
39
39
  skills: skills.concat(options?.skills ?? []),
40
+ metadata: options?.metadata,
40
41
  });
41
42
  }
42
43
  /**
@@ -66,6 +67,7 @@ class AIGNE {
66
67
  this.cli = options?.cli ?? {};
67
68
  this.observer?.serve();
68
69
  this.initProcessExitHandler();
70
+ this.metadata = options?.metadata ?? {};
69
71
  }
70
72
  /**
71
73
  * Optional root directory for this AIGNE instance.
@@ -115,6 +117,10 @@ class AIGNE {
115
117
  * Observer for the AIGNE instance.
116
118
  */
117
119
  observer;
120
+ /**
121
+ * Metadata for the AIGNE instance.
122
+ */
123
+ metadata = {};
118
124
  /**
119
125
  * Adds one or more agents to this AIGNE instance.
120
126
  * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
@@ -9,6 +9,7 @@ import type { Memory } from "../memory/memory.js";
9
9
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
10
10
  import type { Args, Listener, TypedEventEmitter } from "../utils/typed-event-emitter.js";
11
11
  import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
12
+ import type { AIGNEMetadata } from "./type.js";
12
13
  import { type ContextLimits, type ContextUsage } from "./usage.js";
13
14
  /**
14
15
  * @hidden
@@ -78,6 +79,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
78
79
  skills?: Agent[];
79
80
  agents: Agent[];
80
81
  observer?: AIGNEObserver;
82
+ metadata?: AIGNEMetadata;
81
83
  span?: Span;
82
84
  usage: ContextUsage;
83
85
  limits?: ContextLimits;
@@ -187,7 +189,7 @@ export declare class AIGNEContext implements Context {
187
189
  }
188
190
  declare class AIGNEContextShared {
189
191
  private readonly parent?;
190
- constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
192
+ constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer" | "metadata"> & {
191
193
  messageQueue?: MessageQueue;
192
194
  events?: Emitter<any>;
193
195
  }) | undefined);
@@ -198,6 +200,7 @@ declare class AIGNEContextShared {
198
200
  get skills(): Agent<any, any>[] | undefined;
199
201
  get agents(): Agent<any, any>[];
200
202
  get observer(): AIGNEObserver | undefined;
203
+ get metadata(): AIGNEMetadata | undefined;
201
204
  get limits(): ContextLimits | undefined;
202
205
  usage: ContextUsage;
203
206
  userContext: Context["userContext"];
@@ -217,6 +217,7 @@ class AIGNEContext {
217
217
  if (this.parentId) {
218
218
  span.setAttribute("custom.parent_id", this.parentId);
219
219
  }
220
+ span.setAttribute("metadata", JSON.stringify(this.internal.metadata ?? {}));
220
221
  span.setAttribute("custom.started_at", b.timestamp);
221
222
  span.setAttribute("input", JSON.stringify(input));
222
223
  span.setAttribute("agentTag", agent.tag ?? "UnknownAgent");
@@ -300,6 +301,9 @@ class AIGNEContextShared {
300
301
  get observer() {
301
302
  return this.parent?.observer;
302
303
  }
304
+ get metadata() {
305
+ return this.parent?.metadata;
306
+ }
303
307
  get limits() {
304
308
  return this.parent?.limits;
305
309
  }
@@ -10,3 +10,17 @@ export interface AIGNECLIAgent {
10
10
  description?: string;
11
11
  agents?: AIGNECLIAgent[];
12
12
  }
13
+ export interface AIGNEMetadata {
14
+ /**
15
+ * CLI version (e.g., "1.51.0")
16
+ */
17
+ cliVersion?: string;
18
+ /**
19
+ * Application name (e.g., "docsmith", "websmith")
20
+ */
21
+ appName?: string;
22
+ /**
23
+ * Application version (e.g., "2.3.4")
24
+ */
25
+ appVersion?: string;
26
+ }
@@ -59,6 +59,7 @@ export interface AIAgentSchema extends BaseAgentSchema {
59
59
  inputKey?: string;
60
60
  inputFileKey?: string;
61
61
  outputKey?: string;
62
+ outputFileKey?: string;
62
63
  toolChoice?: AIAgentToolChoice;
63
64
  toolCallsConcurrency?: number;
64
65
  keepTextInToolUses?: boolean;
@@ -66,6 +67,7 @@ export interface AIAgentSchema extends BaseAgentSchema {
66
67
  export interface ImageAgentSchema extends BaseAgentSchema {
67
68
  type: "image";
68
69
  instructions: Instructions;
70
+ inputFileKey?: string;
69
71
  modelOptions?: Record<string, any>;
70
72
  }
71
73
  export interface MCPAgentSchema extends BaseAgentSchema {
@@ -128,6 +128,7 @@ async function parseAgentFile(path, data) {
128
128
  .object({
129
129
  type: zod_1.z.literal("image"),
130
130
  instructions: instructionsSchema,
131
+ inputFileKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
131
132
  modelOptions: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.record(zod_1.z.any()))),
132
133
  })
133
134
  .extend(baseAgentSchema.shape),
@@ -2,6 +2,8 @@ import type { GetPromptResult } from "@modelcontextprotocol/sdk/types.js";
2
2
  import { Agent, type AgentInvokeOptions, type Message } from "../agents/agent.js";
3
3
  import { type AIAgent } from "../agents/ai-agent.js";
4
4
  import type { ChatModel, ChatModelInput } from "../agents/chat-model.js";
5
+ import type { ImageAgent } from "../agents/image-agent.js";
6
+ import { type FileUnionContent } from "../agents/model.js";
5
7
  import { ChatMessagesTemplate } from "./template.js";
6
8
  export interface PromptBuilderOptions {
7
9
  instructions?: string | ChatMessagesTemplate;
@@ -27,9 +29,13 @@ export declare class PromptBuilder {
27
29
  build(options: PromptBuildOptions): Promise<ChatModelInput & {
28
30
  toolAgents?: Agent[];
29
31
  }>;
30
- buildImagePrompt(options: Pick<PromptBuildOptions, "input">): Promise<{
32
+ buildImagePrompt(options: Pick<PromptBuildOptions, "input" | "context"> & {
33
+ agent: ImageAgent;
34
+ }): Promise<{
31
35
  prompt: string;
36
+ image?: FileUnionContent[];
32
37
  }>;
38
+ private getTemplateVariables;
33
39
  private buildMessages;
34
40
  private refineMessages;
35
41
  private convertMemoriesToMessages;
@@ -78,9 +78,21 @@ class PromptBuilder {
78
78
  async buildImagePrompt(options) {
79
79
  const messages = (await (typeof this.instructions === "string"
80
80
  ? template_js_1.ChatMessagesTemplate.from([template_js_1.SystemMessageTemplate.from(this.instructions)])
81
- : this.instructions)?.format(options.input, { workingDir: this.workingDir })) ?? [];
81
+ : this.instructions)?.format(this.getTemplateVariables(options), { workingDir: this.workingDir })) ?? [];
82
+ const inputFileKey = options.agent?.inputFileKey;
83
+ const files = (0, type_utils_js_1.flat)(inputFileKey
84
+ ? (0, type_utils_js_1.checkArguments)("Check input files", (0, schema_js_1.optionalize)(model_js_1.fileUnionContentsSchema), options.input?.[inputFileKey])
85
+ : null);
82
86
  return {
83
87
  prompt: messages.map((i) => i.content).join("\n"),
88
+ image: files.length ? files : undefined,
89
+ };
90
+ }
91
+ getTemplateVariables(options) {
92
+ return {
93
+ userContext: options.context?.userContext,
94
+ ...options.context?.userContext,
95
+ ...options.input,
84
96
  };
85
97
  }
86
98
  async buildMessages(options) {
@@ -89,7 +101,7 @@ class PromptBuilder {
89
101
  const message = inputKey && typeof input?.[inputKey] === "string" ? input[inputKey] : undefined;
90
102
  const [messages, otherCustomMessages] = (0, type_utils_js_1.partition)((await (typeof this.instructions === "string"
91
103
  ? template_js_1.ChatMessagesTemplate.from([template_js_1.SystemMessageTemplate.from(this.instructions)])
92
- : this.instructions)?.format(options.input, { workingDir: this.workingDir })) ?? [], (i) => i.role === "system");
104
+ : this.instructions)?.format(this.getTemplateVariables(options), { workingDir: this.workingDir })) ?? [], (i) => i.role === "system");
93
105
  const inputFileKey = options.agent?.inputFileKey;
94
106
  const files = (0, type_utils_js_1.flat)(inputFileKey
95
107
  ? (0, type_utils_js_1.checkArguments)("Check input files", (0, schema_js_1.optionalize)(model_js_1.fileUnionContentsSchema), input?.[inputFileKey])
@@ -5,5 +5,6 @@ function mergeUsage(...usages) {
5
5
  return {
6
6
  inputTokens: usages.reduce((acc, usage) => (usage ? acc + usage.inputTokens : acc), 0),
7
7
  outputTokens: usages.reduce((acc, usage) => (usage ? acc + usage.outputTokens : acc), 0),
8
+ aigneHubCredits: usages.reduce((acc, usage) => (usage?.aigneHubCredits ? acc + usage.aigneHubCredits : acc), 0),
8
9
  };
9
10
  }
@@ -0,0 +1,57 @@
1
+ /** biome-ignore-all lint/style/noNonNullAssertion lint/complexity/useOptionalChain: <!> */
2
+ declare namespace fastq {
3
+ type worker<C, T = any, R = any> = (this: C, task: T, cb: fastq.done<R>) => void;
4
+ type asyncWorker<C, T = any, R = any> = (this: C, task: T) => Promise<R>;
5
+ type done<R = any> = (err: Error | null, result?: R) => void;
6
+ type errorHandler<T = any> = (err: Error, task: T) => void;
7
+ interface queue<T = any, R = any> {
8
+ /** Add a task at the end of the queue. `done(err, result)` will be called when the task was processed. */
9
+ push(task: T, done?: done<R>): void;
10
+ /** Add a task at the beginning of the queue. `done(err, result)` will be called when the task was processed. */
11
+ unshift(task: T, done?: done<R>): void;
12
+ /** Pause the processing of tasks. Currently worked tasks are not stopped. */
13
+ pause(): any;
14
+ /** Resume the processing of tasks. */
15
+ resume(): any;
16
+ running(): number;
17
+ /** Returns `false` if there are tasks being processed or waiting to be processed. `true` otherwise. */
18
+ idle(): boolean;
19
+ /** Returns the number of tasks waiting to be processed (in the queue). */
20
+ length(): number;
21
+ /** Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks */
22
+ getQueue(): T[];
23
+ /** Removes all tasks waiting to be processed, and reset `drain` to an empty function. */
24
+ kill(): any;
25
+ /** Same than `kill` but the `drain` function will be called before reset to empty. */
26
+ killAndDrain(): any;
27
+ /** Set a global error handler. `handler(err, task)` will be called each time a task is completed, `err` will be not null if the task has thrown an error. */
28
+ error(handler: errorHandler<T>): void;
29
+ /** Property that returns the number of concurrent tasks that could be executed in parallel. It can be altered at runtime. */
30
+ concurrency: number;
31
+ /** Property that returns `true` when the queue is in a paused state. */
32
+ paused: boolean;
33
+ /** Function that will be called when the last item from the queue has been processed by a worker. It can be altered at runtime. */
34
+ drain(): any;
35
+ /** Function that will be called when the last item from the queue has been assigned to a worker. It can be altered at runtime. */
36
+ empty: () => void;
37
+ /** Function that will be called when the queue hits the concurrency limit. It can be altered at runtime. */
38
+ saturated: () => void;
39
+ }
40
+ interface queueAsPromised<T = any, R = any> extends queue<T, R> {
41
+ /** Add a task at the end of the queue. The returned `Promise` will be fulfilled (rejected) when the task is completed successfully (unsuccessfully). */
42
+ push(task: T): Promise<R>;
43
+ /** Add a task at the beginning of the queue. The returned `Promise` will be fulfilled (rejected) when the task is completed successfully (unsuccessfully). */
44
+ unshift(task: T): Promise<R>;
45
+ /** Wait for the queue to be drained. The returned `Promise` will be resolved when all tasks in the queue have been processed by a worker. */
46
+ drained(): Promise<void>;
47
+ }
48
+ }
49
+ declare function fastq<C, T = any, R = any>(context: C, worker: fastq.worker<C, T, R>, _concurrency: number): fastq.queue<T, R>;
50
+ declare function fastq<C, T = any, R = any>(worker: fastq.worker<C, T, R>, _concurrency: number): fastq.queue<T, R>;
51
+ declare namespace fastq {
52
+ var promise: typeof queueAsPromised;
53
+ }
54
+ declare function queueAsPromised<C, T = any, R = any>(context: C, worker: fastq.asyncWorker<C, T, R>, _concurrency: number): fastq.queueAsPromised<T, R>;
55
+ declare function queueAsPromised<C, T = any, R = any>(worker: fastq.asyncWorker<C, T, R>, _concurrency: number): fastq.queueAsPromised<T, R>;
56
+ export default fastq;
57
+ export declare const promise: typeof queueAsPromised;