@aigne/core 1.65.1-beta.2 → 1.66.0-beta.3
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/CHANGELOG.md +27 -0
- package/lib/cjs/agents/agent.d.ts +2 -6
- package/lib/cjs/agents/agent.js +5 -1
- package/lib/cjs/agents/ai-agent.js +1 -0
- package/lib/cjs/agents/chat-model.d.ts +6 -4
- package/lib/cjs/agents/chat-model.js +30 -11
- package/lib/cjs/agents/image-model.d.ts +2 -1
- package/lib/cjs/agents/types.d.ts +14 -1
- package/lib/cjs/agents/types.js +14 -0
- package/lib/cjs/agents/video-model.d.ts +2 -1
- package/lib/cjs/aigne/context.js +4 -1
- package/lib/cjs/loader/agent-js.js +2 -1
- package/lib/cjs/loader/error.d.ts +2 -0
- package/lib/cjs/loader/error.js +6 -0
- package/lib/cjs/loader/index.d.ts +140 -28
- package/lib/cjs/loader/index.js +8 -4
- package/lib/cjs/loader/schema.d.ts +107 -23
- package/lib/cjs/loader/schema.js +9 -14
- package/lib/dts/agents/agent.d.ts +2 -6
- package/lib/dts/agents/chat-model.d.ts +6 -4
- package/lib/dts/agents/image-model.d.ts +2 -1
- package/lib/dts/agents/types.d.ts +14 -1
- package/lib/dts/agents/video-model.d.ts +2 -1
- package/lib/dts/loader/error.d.ts +2 -0
- package/lib/dts/loader/index.d.ts +140 -28
- package/lib/dts/loader/schema.d.ts +107 -23
- package/lib/esm/agents/agent.d.ts +2 -6
- package/lib/esm/agents/agent.js +5 -1
- package/lib/esm/agents/ai-agent.js +1 -0
- package/lib/esm/agents/chat-model.d.ts +6 -4
- package/lib/esm/agents/chat-model.js +31 -12
- package/lib/esm/agents/image-model.d.ts +2 -1
- package/lib/esm/agents/types.d.ts +14 -1
- package/lib/esm/agents/types.js +10 -0
- package/lib/esm/agents/video-model.d.ts +2 -1
- package/lib/esm/aigne/context.js +4 -1
- package/lib/esm/loader/agent-js.js +2 -1
- package/lib/esm/loader/error.d.ts +2 -0
- package/lib/esm/loader/error.js +2 -0
- package/lib/esm/loader/index.d.ts +140 -28
- package/lib/esm/loader/index.js +8 -4
- package/lib/esm/loader/schema.d.ts +107 -23
- package/lib/esm/loader/schema.js +10 -15
- package/package.json +3 -3
|
@@ -22,42 +22,126 @@ export declare const inputOutputSchema: ({ path }: {
|
|
|
22
22
|
required?: string[] | undefined;
|
|
23
23
|
additionalProperties?: boolean | undefined;
|
|
24
24
|
}>]>;
|
|
25
|
-
export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
25
|
+
export declare const defaultInputSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnknown, z.ZodObject<{
|
|
26
26
|
$get: z.ZodString;
|
|
27
27
|
}, "strip", z.ZodTypeAny, {
|
|
28
28
|
$get: string;
|
|
29
29
|
}, {
|
|
30
30
|
$get: string;
|
|
31
|
-
}
|
|
31
|
+
}>]>>;
|
|
32
32
|
declare const chatModelObjectSchema: z.ZodObject<{
|
|
33
|
-
model: ZodType<string |
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
model: ZodType<string | {
|
|
34
|
+
$get: string;
|
|
35
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
36
|
+
$get: string;
|
|
37
|
+
} | undefined>;
|
|
38
|
+
temperature: ZodType<number | {
|
|
39
|
+
$get: string;
|
|
40
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
41
|
+
$get: string;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
topP: ZodType<number | {
|
|
44
|
+
$get: string;
|
|
45
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
46
|
+
$get: string;
|
|
47
|
+
} | undefined>;
|
|
48
|
+
frequencyPenalty: ZodType<number | {
|
|
49
|
+
$get: string;
|
|
50
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
51
|
+
$get: string;
|
|
52
|
+
} | undefined>;
|
|
53
|
+
presencePenalty: ZodType<number | {
|
|
54
|
+
$get: string;
|
|
55
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
56
|
+
$get: string;
|
|
57
|
+
} | undefined>;
|
|
58
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
59
|
+
$get: string;
|
|
60
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
61
|
+
$get: string;
|
|
62
|
+
} | undefined>;
|
|
39
63
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
40
|
-
model: ZodType<string |
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
model: ZodType<string | {
|
|
65
|
+
$get: string;
|
|
66
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
67
|
+
$get: string;
|
|
68
|
+
} | undefined>;
|
|
69
|
+
temperature: ZodType<number | {
|
|
70
|
+
$get: string;
|
|
71
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
72
|
+
$get: string;
|
|
73
|
+
} | undefined>;
|
|
74
|
+
topP: ZodType<number | {
|
|
75
|
+
$get: string;
|
|
76
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
77
|
+
$get: string;
|
|
78
|
+
} | undefined>;
|
|
79
|
+
frequencyPenalty: ZodType<number | {
|
|
80
|
+
$get: string;
|
|
81
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
82
|
+
$get: string;
|
|
83
|
+
} | undefined>;
|
|
84
|
+
presencePenalty: ZodType<number | {
|
|
85
|
+
$get: string;
|
|
86
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
87
|
+
$get: string;
|
|
88
|
+
} | undefined>;
|
|
89
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
90
|
+
$get: string;
|
|
91
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
92
|
+
$get: string;
|
|
93
|
+
} | undefined>;
|
|
46
94
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
47
|
-
model: ZodType<string |
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
model: ZodType<string | {
|
|
96
|
+
$get: string;
|
|
97
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
98
|
+
$get: string;
|
|
99
|
+
} | undefined>;
|
|
100
|
+
temperature: ZodType<number | {
|
|
101
|
+
$get: string;
|
|
102
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
103
|
+
$get: string;
|
|
104
|
+
} | undefined>;
|
|
105
|
+
topP: ZodType<number | {
|
|
106
|
+
$get: string;
|
|
107
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
108
|
+
$get: string;
|
|
109
|
+
} | undefined>;
|
|
110
|
+
frequencyPenalty: ZodType<number | {
|
|
111
|
+
$get: string;
|
|
112
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
113
|
+
$get: string;
|
|
114
|
+
} | undefined>;
|
|
115
|
+
presencePenalty: ZodType<number | {
|
|
116
|
+
$get: string;
|
|
117
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
118
|
+
$get: string;
|
|
119
|
+
} | undefined>;
|
|
120
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
121
|
+
$get: string;
|
|
122
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
123
|
+
$get: string;
|
|
124
|
+
} | undefined>;
|
|
53
125
|
}, z.ZodTypeAny, "passthrough">>;
|
|
54
126
|
export declare const chatModelSchema: typeof chatModelObjectSchema;
|
|
55
127
|
declare const imageModelObjectSchema: z.ZodObject<{
|
|
56
|
-
model: ZodType<string |
|
|
128
|
+
model: ZodType<string | {
|
|
129
|
+
$get: string;
|
|
130
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
131
|
+
$get: string;
|
|
132
|
+
} | undefined>;
|
|
57
133
|
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
58
|
-
model: ZodType<string |
|
|
134
|
+
model: ZodType<string | {
|
|
135
|
+
$get: string;
|
|
136
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
137
|
+
$get: string;
|
|
138
|
+
} | undefined>;
|
|
59
139
|
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
60
|
-
model: ZodType<string |
|
|
140
|
+
model: ZodType<string | {
|
|
141
|
+
$get: string;
|
|
142
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
143
|
+
$get: string;
|
|
144
|
+
} | undefined>;
|
|
61
145
|
}, z.ZodTypeAny, "passthrough">>;
|
|
62
146
|
export declare const imageModelSchema: typeof imageModelObjectSchema;
|
|
63
147
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
@@ -12,7 +12,7 @@ import { type Nullish, type PromiseOrValue, type XOr } from "../utils/type-utils
|
|
|
12
12
|
import type { ChatModel } from "./chat-model.js";
|
|
13
13
|
import type { GuideRailAgent, GuideRailAgentOutput } from "./guide-rail-agent.js";
|
|
14
14
|
import type { ImageModel } from "./image-model.js";
|
|
15
|
-
import { type TransferAgentOutput } from "./types.js";
|
|
15
|
+
import { type GetterSchema, type TransferAgentOutput } from "./types.js";
|
|
16
16
|
export * from "./types.js";
|
|
17
17
|
export declare const DEFAULT_INPUT_ACTION_GET = "$get";
|
|
18
18
|
/**
|
|
@@ -293,11 +293,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
|
|
|
293
293
|
renderTaskTitle(input: I): Promise<string | undefined>;
|
|
294
294
|
taskRenderMode?: TaskRenderMode;
|
|
295
295
|
private readonly _inputSchema?;
|
|
296
|
-
defaultInput?:
|
|
297
|
-
[key in keyof I]: {
|
|
298
|
-
[DEFAULT_INPUT_ACTION_GET]: string;
|
|
299
|
-
} | I[key];
|
|
300
|
-
}>;
|
|
296
|
+
defaultInput?: GetterSchema<I>;
|
|
301
297
|
private readonly _outputSchema?;
|
|
302
298
|
/**
|
|
303
299
|
* Get the input data schema for this agent
|
package/lib/esm/agents/agent.js
CHANGED
|
@@ -363,7 +363,11 @@ export class Agent {
|
|
|
363
363
|
input = this.mergeDefaultInput(input);
|
|
364
364
|
logger.debug("Invoke agent %s started with input: %O", this.name, input);
|
|
365
365
|
if (!this.disableEvents)
|
|
366
|
-
opts.context.emit("agentStarted", {
|
|
366
|
+
opts.context.emit("agentStarted", {
|
|
367
|
+
agent: this,
|
|
368
|
+
input,
|
|
369
|
+
taskTitle: await this.renderTaskTitle(input),
|
|
370
|
+
});
|
|
367
371
|
try {
|
|
368
372
|
const s = await this.callHooks("onStart", { input }, opts);
|
|
369
373
|
if (s?.input)
|
|
@@ -273,6 +273,7 @@ export class AIAgent extends Agent {
|
|
|
273
273
|
input,
|
|
274
274
|
model,
|
|
275
275
|
});
|
|
276
|
+
modelInput.modelOptions = await model.getModelOptions(input, options);
|
|
276
277
|
const toolsMap = new Map(toolAgents?.map((i) => [i.name, i]));
|
|
277
278
|
if (this.toolChoice === "router") {
|
|
278
279
|
return yield* this._processRouter(input, model, modelInput, options, toolsMap);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import { type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type Message } from "./agent.js";
|
|
3
|
+
import { type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type AgentResponse, type AgentResponseStream, type GetterSchema, type Message } from "./agent.js";
|
|
4
4
|
import { type FileType, type FileUnionContent, Model } from "./model.js";
|
|
5
5
|
export declare class StructuredOutputError extends Error {
|
|
6
6
|
}
|
|
7
7
|
export interface ChatModelOptions extends Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "model" | "inputSchema" | "outputSchema"> {
|
|
8
8
|
model?: string;
|
|
9
|
-
modelOptions?:
|
|
9
|
+
modelOptions?: ChatModelInputOptionsWithGetter;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
|
|
@@ -40,6 +40,7 @@ export declare abstract class ChatModel extends Model<ChatModelInput, ChatModelO
|
|
|
40
40
|
apiKey?: string;
|
|
41
41
|
model?: string;
|
|
42
42
|
}>;
|
|
43
|
+
getModelOptions(input: Message, options: AgentInvokeOptions): Promise<ChatModelInputOptions>;
|
|
43
44
|
/**
|
|
44
45
|
* Indicates whether the model supports parallel tool calls
|
|
45
46
|
*
|
|
@@ -156,7 +157,7 @@ export interface ChatModelInput extends Message {
|
|
|
156
157
|
/**
|
|
157
158
|
* Model-specific configuration options
|
|
158
159
|
*/
|
|
159
|
-
modelOptions?:
|
|
160
|
+
modelOptions?: ChatModelInputOptionsWithGetter;
|
|
160
161
|
}
|
|
161
162
|
/**
|
|
162
163
|
* Message role types
|
|
@@ -361,7 +362,7 @@ export type Modality = "text" | "image" | "audio";
|
|
|
361
362
|
*
|
|
362
363
|
* Contains various parameters for controlling model behavior, such as model name, temperature, etc.
|
|
363
364
|
*/
|
|
364
|
-
export interface ChatModelInputOptions {
|
|
365
|
+
export interface ChatModelInputOptions extends Record<string, unknown> {
|
|
365
366
|
/**
|
|
366
367
|
* Model name or version
|
|
367
368
|
*/
|
|
@@ -390,6 +391,7 @@ export interface ChatModelInputOptions {
|
|
|
390
391
|
preferInputFileType?: "file" | "url";
|
|
391
392
|
reasoningEffort?: number | "minimal" | "low" | "medium" | "high";
|
|
392
393
|
}
|
|
394
|
+
export type ChatModelInputOptionsWithGetter = GetterSchema<ChatModelInputOptions>;
|
|
393
395
|
/**
|
|
394
396
|
* Output message format for ChatModel
|
|
395
397
|
*
|
|
@@ -4,7 +4,7 @@ import { convertJsonSchemaToZod } from "zod-from-json-schema";
|
|
|
4
4
|
import { wrapAutoParseJsonSchema } from "../utils/json-schema.js";
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
6
|
import { checkArguments, isNil, omitByDeep } from "../utils/type-utils.js";
|
|
7
|
-
import { agentOptionsSchema, } from "./agent.js";
|
|
7
|
+
import { agentOptionsSchema, DEFAULT_INPUT_ACTION_GET, getterSchema, } from "./agent.js";
|
|
8
8
|
import { fileContentSchema, fileUnionContentSchema, localContentSchema, Model, urlContentSchema, } from "./model.js";
|
|
9
9
|
const CHAT_MODEL_DEFAULT_RETRY_OPTIONS = {
|
|
10
10
|
retries: 3,
|
|
@@ -61,6 +61,27 @@ export class ChatModel extends Model {
|
|
|
61
61
|
get credential() {
|
|
62
62
|
return {};
|
|
63
63
|
}
|
|
64
|
+
async getModelOptions(input, options) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const [key, val] of Object.entries({
|
|
67
|
+
...this.options?.modelOptions,
|
|
68
|
+
...("modelOptions" in input ? input.modelOptions : {}),
|
|
69
|
+
})) {
|
|
70
|
+
if (val &&
|
|
71
|
+
typeof val === "object" &&
|
|
72
|
+
DEFAULT_INPUT_ACTION_GET in val &&
|
|
73
|
+
typeof val[DEFAULT_INPUT_ACTION_GET] === "string") {
|
|
74
|
+
const getterPath = val[DEFAULT_INPUT_ACTION_GET];
|
|
75
|
+
const value = input[getterPath] ?? options.context.userContext[getterPath];
|
|
76
|
+
if (!isNil(value))
|
|
77
|
+
Object.assign(result, { [key]: value });
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
Object.assign(result, { [key]: val });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
64
85
|
/**
|
|
65
86
|
* Indicates whether the model supports parallel tool calls
|
|
66
87
|
*
|
|
@@ -292,22 +313,20 @@ const chatModelInputToolChoiceSchema = z.union([
|
|
|
292
313
|
chatModelInputToolSchema,
|
|
293
314
|
]);
|
|
294
315
|
const modelOptionsSchema = z.object({
|
|
295
|
-
model: z.string().optional(),
|
|
296
|
-
temperature: z.number().optional(),
|
|
297
|
-
topP: z.number().optional(),
|
|
298
|
-
frequencyPenalty: z.number().optional(),
|
|
299
|
-
presencePenalty: z.number().optional(),
|
|
300
|
-
parallelToolCalls: z.boolean().optional().default(true),
|
|
301
|
-
modalities: z.array(z.enum(["text", "image", "audio"])).optional(),
|
|
302
|
-
reasoningEffort: z
|
|
303
|
-
.union([
|
|
316
|
+
model: getterSchema(z.string()).optional(),
|
|
317
|
+
temperature: getterSchema(z.number()).optional(),
|
|
318
|
+
topP: getterSchema(z.number()).optional(),
|
|
319
|
+
frequencyPenalty: getterSchema(z.number()).optional(),
|
|
320
|
+
presencePenalty: getterSchema(z.number()).optional(),
|
|
321
|
+
parallelToolCalls: getterSchema(z.boolean()).optional().default(true),
|
|
322
|
+
modalities: getterSchema(z.array(z.enum(["text", "image", "audio"]))).optional(),
|
|
323
|
+
reasoningEffort: getterSchema(z.union([
|
|
304
324
|
z.number(),
|
|
305
325
|
z.literal("minimal"),
|
|
306
326
|
z.literal("low"),
|
|
307
327
|
z.literal("medium"),
|
|
308
328
|
z.literal("high"),
|
|
309
|
-
])
|
|
310
|
-
.optional(),
|
|
329
|
+
])).optional(),
|
|
311
330
|
});
|
|
312
331
|
const chatModelOptionsSchema = agentOptionsSchema.extend({
|
|
313
332
|
model: z.string().optional(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
2
|
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
|
|
3
|
+
import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, GetterSchema, Message } from "./agent.js";
|
|
4
4
|
import { type ChatModelOutputUsage } from "./chat-model.js";
|
|
5
5
|
import { type FileType, type FileUnionContent, Model } from "./model.js";
|
|
6
6
|
export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
|
|
@@ -33,6 +33,7 @@ export interface ImageModelInputOptions extends Record<string, unknown> {
|
|
|
33
33
|
model?: string;
|
|
34
34
|
preferInputFileType?: "file" | "url";
|
|
35
35
|
}
|
|
36
|
+
export type ImageModelInputOptionsWithGetter = GetterSchema<ImageModelInputOptions>;
|
|
36
37
|
export declare const imageModelInputSchema: z.ZodObject<{
|
|
37
38
|
prompt: z.ZodString;
|
|
38
39
|
image: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import z, { type ZodType } from "zod";
|
|
2
|
+
import { type Agent, DEFAULT_INPUT_ACTION_GET, type Message } from "./agent.js";
|
|
2
3
|
export declare const transferAgentOutputKey = "$transferAgentTo";
|
|
3
4
|
export interface TransferAgentOutput extends Message {
|
|
4
5
|
[transferAgentOutputKey]: {
|
|
@@ -8,3 +9,15 @@ export interface TransferAgentOutput extends Message {
|
|
|
8
9
|
export declare function transferToAgentOutput(agent: Agent): TransferAgentOutput;
|
|
9
10
|
export declare function isTransferAgentOutput(output: Message): output is TransferAgentOutput;
|
|
10
11
|
export declare function replaceTransferAgentToName(output: Message): Message;
|
|
12
|
+
export type GetterSchema<I extends Record<string, unknown>> = Partial<{
|
|
13
|
+
[key in keyof I]: {
|
|
14
|
+
[DEFAULT_INPUT_ACTION_GET]: string;
|
|
15
|
+
} | I[key];
|
|
16
|
+
}>;
|
|
17
|
+
export declare function getterSchema<T extends ZodType>(schema: T): z.ZodUnion<[T, z.ZodObject<{
|
|
18
|
+
$get: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
$get: string;
|
|
21
|
+
}, {
|
|
22
|
+
$get: string;
|
|
23
|
+
}>]>;
|
package/lib/esm/agents/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { DEFAULT_INPUT_ACTION_GET } from "./agent.js";
|
|
1
3
|
export const transferAgentOutputKey = "$transferAgentTo";
|
|
2
4
|
export function transferToAgentOutput(agent) {
|
|
3
5
|
return {
|
|
@@ -18,3 +20,11 @@ export function replaceTransferAgentToName(output) {
|
|
|
18
20
|
}
|
|
19
21
|
return output;
|
|
20
22
|
}
|
|
23
|
+
export function getterSchema(schema) {
|
|
24
|
+
return z.union([
|
|
25
|
+
schema,
|
|
26
|
+
z.object({
|
|
27
|
+
[DEFAULT_INPUT_ACTION_GET]: z.string(),
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
2
|
import type { PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
-
import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, Message } from "./agent.js";
|
|
3
|
+
import type { AgentInvokeOptions, AgentOptions, AgentProcessResult, AgentResponse, AgentResponseStream, GetterSchema, Message } from "./agent.js";
|
|
4
4
|
import { type ChatModelOutputUsage } from "./chat-model.js";
|
|
5
5
|
import { type FileType, type FileUnionContent, Model } from "./model.js";
|
|
6
6
|
export interface VideoModelOptions<I extends VideoModelInput = VideoModelInput, O extends VideoModelOutput = VideoModelOutput> extends Omit<AgentOptions<I, O>, "model"> {
|
|
@@ -33,6 +33,7 @@ export interface VideoModelInput extends Message {
|
|
|
33
33
|
export interface VideoModelInputOptions extends Record<string, unknown> {
|
|
34
34
|
model?: string;
|
|
35
35
|
}
|
|
36
|
+
export type VideoModelInputOptionsWithGetter = GetterSchema<VideoModelInputOptions>;
|
|
36
37
|
export declare const videoModelInputSchema: z.ZodObject<{
|
|
37
38
|
prompt: z.ZodString;
|
|
38
39
|
model: z.ZodOptional<z.ZodString>;
|
package/lib/esm/aigne/context.js
CHANGED
|
@@ -204,7 +204,7 @@ export class AIGNEContext {
|
|
|
204
204
|
try {
|
|
205
205
|
switch (eventName) {
|
|
206
206
|
case "agentStarted": {
|
|
207
|
-
const { agent, input } = args[0];
|
|
207
|
+
const { agent, input, taskTitle } = args[0];
|
|
208
208
|
span.updateName(agent.name);
|
|
209
209
|
span.setAttribute("custom.trace_id", this.rootId);
|
|
210
210
|
span.setAttribute("custom.span_id", this.id);
|
|
@@ -215,6 +215,9 @@ export class AIGNEContext {
|
|
|
215
215
|
span.setAttribute("custom.started_at", b.timestamp);
|
|
216
216
|
span.setAttribute("input", JSON.stringify(input));
|
|
217
217
|
span.setAttribute("agentTag", agent.tag ?? "UnknownAgent");
|
|
218
|
+
if (taskTitle) {
|
|
219
|
+
span.setAttribute("taskTitle", taskTitle);
|
|
220
|
+
}
|
|
218
221
|
try {
|
|
219
222
|
span.setAttribute("userContext", JSON.stringify(this.userContext));
|
|
220
223
|
}
|
|
@@ -2,11 +2,12 @@ import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
|
2
2
|
import { Agent } from "../agents/agent.js";
|
|
3
3
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
4
4
|
import { parseAgentFile } from "./agent-yaml.js";
|
|
5
|
+
import { LoadJsAgentError } from "./error.js";
|
|
5
6
|
const importFn = new Function("path", "return import(path)");
|
|
6
7
|
export async function loadAgentFromJsFile(path) {
|
|
7
8
|
if (nodejs.path.isAbsolute(path))
|
|
8
9
|
path = nodejs.url.pathToFileURL(path).toString();
|
|
9
|
-
const { default: agent } = await tryOrThrow(() => importFn(path), (error) => new
|
|
10
|
+
const { default: agent } = await tryOrThrow(() => importFn(path), (error) => new LoadJsAgentError(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
10
11
|
if (agent instanceof Agent)
|
|
11
12
|
return agent;
|
|
12
13
|
if (typeof agent !== "function") {
|
|
@@ -33,24 +33,80 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
33
33
|
name: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
34
34
|
description: ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
|
|
35
35
|
model: ZodType<z.objectInputType<{
|
|
36
|
-
model: ZodType<string |
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
model: ZodType<string | {
|
|
37
|
+
$get: string;
|
|
38
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
39
|
+
$get: string;
|
|
40
|
+
} | undefined>;
|
|
41
|
+
temperature: ZodType<number | {
|
|
42
|
+
$get: string;
|
|
43
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
44
|
+
$get: string;
|
|
45
|
+
} | undefined>;
|
|
46
|
+
topP: ZodType<number | {
|
|
47
|
+
$get: string;
|
|
48
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
49
|
+
$get: string;
|
|
50
|
+
} | undefined>;
|
|
51
|
+
frequencyPenalty: ZodType<number | {
|
|
52
|
+
$get: string;
|
|
53
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
54
|
+
$get: string;
|
|
55
|
+
} | undefined>;
|
|
56
|
+
presencePenalty: ZodType<number | {
|
|
57
|
+
$get: string;
|
|
58
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
59
|
+
$get: string;
|
|
60
|
+
} | undefined>;
|
|
61
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
62
|
+
$get: string;
|
|
63
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
64
|
+
$get: string;
|
|
65
|
+
} | undefined>;
|
|
42
66
|
}, z.ZodTypeAny, "passthrough"> | undefined, z.ZodTypeDef, z.objectInputType<{
|
|
43
|
-
model: ZodType<string |
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
model: ZodType<string | {
|
|
68
|
+
$get: string;
|
|
69
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
70
|
+
$get: string;
|
|
71
|
+
} | undefined>;
|
|
72
|
+
temperature: ZodType<number | {
|
|
73
|
+
$get: string;
|
|
74
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
75
|
+
$get: string;
|
|
76
|
+
} | undefined>;
|
|
77
|
+
topP: ZodType<number | {
|
|
78
|
+
$get: string;
|
|
79
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
80
|
+
$get: string;
|
|
81
|
+
} | undefined>;
|
|
82
|
+
frequencyPenalty: ZodType<number | {
|
|
83
|
+
$get: string;
|
|
84
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
85
|
+
$get: string;
|
|
86
|
+
} | undefined>;
|
|
87
|
+
presencePenalty: ZodType<number | {
|
|
88
|
+
$get: string;
|
|
89
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
90
|
+
$get: string;
|
|
91
|
+
} | undefined>;
|
|
92
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
93
|
+
$get: string;
|
|
94
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
95
|
+
$get: string;
|
|
96
|
+
} | undefined>;
|
|
49
97
|
}, z.ZodTypeAny, "passthrough"> | undefined>;
|
|
50
98
|
imageModel: ZodType<z.objectInputType<{
|
|
51
|
-
model: ZodType<string |
|
|
99
|
+
model: ZodType<string | {
|
|
100
|
+
$get: string;
|
|
101
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
102
|
+
$get: string;
|
|
103
|
+
} | undefined>;
|
|
52
104
|
}, z.ZodTypeAny, "passthrough"> | undefined, z.ZodTypeDef, z.objectInputType<{
|
|
53
|
-
model: ZodType<string |
|
|
105
|
+
model: ZodType<string | {
|
|
106
|
+
$get: string;
|
|
107
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
108
|
+
$get: string;
|
|
109
|
+
} | undefined>;
|
|
54
110
|
}, z.ZodTypeAny, "passthrough"> | undefined>;
|
|
55
111
|
agents: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
56
112
|
skills: ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
|
|
@@ -68,17 +124,45 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
68
124
|
} | undefined>;
|
|
69
125
|
}, "strip", z.ZodTypeAny, {
|
|
70
126
|
model?: z.objectInputType<{
|
|
71
|
-
model: ZodType<string |
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
127
|
+
model: ZodType<string | {
|
|
128
|
+
$get: string;
|
|
129
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
130
|
+
$get: string;
|
|
131
|
+
} | undefined>;
|
|
132
|
+
temperature: ZodType<number | {
|
|
133
|
+
$get: string;
|
|
134
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
135
|
+
$get: string;
|
|
136
|
+
} | undefined>;
|
|
137
|
+
topP: ZodType<number | {
|
|
138
|
+
$get: string;
|
|
139
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
140
|
+
$get: string;
|
|
141
|
+
} | undefined>;
|
|
142
|
+
frequencyPenalty: ZodType<number | {
|
|
143
|
+
$get: string;
|
|
144
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
145
|
+
$get: string;
|
|
146
|
+
} | undefined>;
|
|
147
|
+
presencePenalty: ZodType<number | {
|
|
148
|
+
$get: string;
|
|
149
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
150
|
+
$get: string;
|
|
151
|
+
} | undefined>;
|
|
152
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
153
|
+
$get: string;
|
|
154
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
155
|
+
$get: string;
|
|
156
|
+
} | undefined>;
|
|
77
157
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
78
158
|
name?: string | undefined;
|
|
79
159
|
description?: string | undefined;
|
|
80
160
|
imageModel?: z.objectInputType<{
|
|
81
|
-
model: ZodType<string |
|
|
161
|
+
model: ZodType<string | {
|
|
162
|
+
$get: string;
|
|
163
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
164
|
+
$get: string;
|
|
165
|
+
} | undefined>;
|
|
82
166
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
83
167
|
skills?: string[] | undefined;
|
|
84
168
|
agents?: string[] | undefined;
|
|
@@ -91,17 +175,45 @@ declare const aigneFileSchema: z.ZodObject<{
|
|
|
91
175
|
} | undefined;
|
|
92
176
|
}, {
|
|
93
177
|
model?: z.objectInputType<{
|
|
94
|
-
model: ZodType<string |
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
178
|
+
model: ZodType<string | {
|
|
179
|
+
$get: string;
|
|
180
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
181
|
+
$get: string;
|
|
182
|
+
} | undefined>;
|
|
183
|
+
temperature: ZodType<number | {
|
|
184
|
+
$get: string;
|
|
185
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
186
|
+
$get: string;
|
|
187
|
+
} | undefined>;
|
|
188
|
+
topP: ZodType<number | {
|
|
189
|
+
$get: string;
|
|
190
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
191
|
+
$get: string;
|
|
192
|
+
} | undefined>;
|
|
193
|
+
frequencyPenalty: ZodType<number | {
|
|
194
|
+
$get: string;
|
|
195
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
196
|
+
$get: string;
|
|
197
|
+
} | undefined>;
|
|
198
|
+
presencePenalty: ZodType<number | {
|
|
199
|
+
$get: string;
|
|
200
|
+
} | undefined, z.ZodTypeDef, number | {
|
|
201
|
+
$get: string;
|
|
202
|
+
} | undefined>;
|
|
203
|
+
thinkingEffort: ZodType<number | "high" | "medium" | "low" | "minimal" | {
|
|
204
|
+
$get: string;
|
|
205
|
+
} | undefined, z.ZodTypeDef, number | "high" | "medium" | "low" | "minimal" | {
|
|
206
|
+
$get: string;
|
|
207
|
+
} | undefined>;
|
|
100
208
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
101
209
|
name?: string | undefined;
|
|
102
210
|
description?: string | undefined;
|
|
103
211
|
imageModel?: z.objectInputType<{
|
|
104
|
-
model: ZodType<string |
|
|
212
|
+
model: ZodType<string | {
|
|
213
|
+
$get: string;
|
|
214
|
+
} | undefined, z.ZodTypeDef, string | {
|
|
215
|
+
$get: string;
|
|
216
|
+
} | undefined>;
|
|
105
217
|
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
106
218
|
skills?: string[] | undefined;
|
|
107
219
|
agents?: string[] | undefined;
|
package/lib/esm/loader/index.js
CHANGED
|
@@ -100,11 +100,15 @@ async function parseHooks(path, hooks, options) {
|
|
|
100
100
|
onHandoff: hook.onHandoff ? await loadNestAgent(path, hook.onHandoff, options) : undefined,
|
|
101
101
|
})));
|
|
102
102
|
}
|
|
103
|
+
async function loadSkills(path, skills, options) {
|
|
104
|
+
const loadedSkills = [];
|
|
105
|
+
for (const skill of skills) {
|
|
106
|
+
loadedSkills.push(await loadNestAgent(path, skill, options));
|
|
107
|
+
}
|
|
108
|
+
return loadedSkills;
|
|
109
|
+
}
|
|
103
110
|
async function parseAgent(path, agent, options, agentOptions) {
|
|
104
|
-
const skills = "skills" in agent
|
|
105
|
-
? agent.skills &&
|
|
106
|
-
(await Promise.all(agent.skills.map((skill) => loadNestAgent(path, skill, options))))
|
|
107
|
-
: undefined;
|
|
111
|
+
const skills = "skills" in agent && agent.skills ? await loadSkills(path, agent.skills, options) : undefined;
|
|
108
112
|
const memory = "memory" in agent && options?.memories?.length
|
|
109
113
|
? await loadMemory(options.memories, typeof agent.memory === "object" ? agent.memory.provider : undefined, typeof agent.memory === "object" ? agent.memory : {})
|
|
110
114
|
: undefined;
|