@aigne/test-utils 0.5.55 → 0.5.56-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.
- package/CHANGELOG.md +9 -0
- package/lib/run-example-test.d.ts +7 -0
- package/lib/run-example-test.js +12 -0
- package/lib/utils/agent-response.d.ts +7 -0
- package/lib/utils/agent-response.js +14 -0
- package/lib/utils/event-stream.d.ts +5 -0
- package/lib/utils/event-stream.js +13 -0
- package/lib/utils/openai-like-utils.d.ts +7 -0
- package/lib/utils/openai-like-utils.js +76 -0
- package/lib/utils/with-env.d.ts +3 -0
- package/lib/utils/with-env.js +9 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.56-beta](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.5.55...test-utils-v0.5.56-beta) (2025-10-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Dependencies
|
|
7
|
+
|
|
8
|
+
* The following workspace dependencies were updated
|
|
9
|
+
* dependencies
|
|
10
|
+
* @aigne/core bumped to 1.64.0-beta
|
|
11
|
+
|
|
3
12
|
## [0.5.55](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.5.55-beta.12...test-utils-v0.5.55) (2025-10-19)
|
|
4
13
|
|
|
5
14
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
export async function runExampleTest(config) {
|
|
4
|
+
const scriptPath = config?.scriptPath ?? join(process.cwd(), "index.ts");
|
|
5
|
+
return spawnSync("bun", [scriptPath], {
|
|
6
|
+
stdio: ["inherit", "inherit", "inherit"],
|
|
7
|
+
env: {
|
|
8
|
+
...process.env,
|
|
9
|
+
INITIAL_CALL: config?.initialCall ?? process.env.INITIAL_CALL,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AgentResponseChunk, type AgentResponseStream, type Message } from "@aigne/core";
|
|
2
|
+
export declare function agentResponseStreamToArraySnapshot<T extends Message>(stream: AgentResponseStream<T>, options?: {
|
|
3
|
+
catchError?: false;
|
|
4
|
+
}): Promise<AgentResponseChunk<T>[]>;
|
|
5
|
+
export declare function agentResponseStreamToArraySnapshot<T extends Message>(stream: AgentResponseStream<T>, options?: {
|
|
6
|
+
catchError?: boolean;
|
|
7
|
+
}): Promise<(AgentResponseChunk<T> | Error)[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isAgentResponseProgress, } from "@aigne/core";
|
|
2
|
+
import { readableStreamToArray } from "@aigne/core/utils/stream-utils.js";
|
|
3
|
+
export async function agentResponseStreamToArraySnapshot(stream, options) {
|
|
4
|
+
return (await readableStreamToArray(stream, options)).map((i) => !(i instanceof Error) && isAgentResponseProgress(i)
|
|
5
|
+
? {
|
|
6
|
+
progress: {
|
|
7
|
+
...i.progress,
|
|
8
|
+
contextId: "TEST_CONTEXT_ID",
|
|
9
|
+
parentContextId: "TEST_PARENT_CONTEXT_ID",
|
|
10
|
+
timestamp: 123456,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
: i);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
export function createMockEventStream(data) {
|
|
3
|
+
return new ReadableStream({
|
|
4
|
+
async start(controller) {
|
|
5
|
+
const file = "path" in data ? await readFile(data.path) : data.raw;
|
|
6
|
+
for (const line of file.toString().split("\n")) {
|
|
7
|
+
if (line)
|
|
8
|
+
controller.enqueue(JSON.parse(line.replace("data:", "")));
|
|
9
|
+
}
|
|
10
|
+
controller.close();
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ChatModelInputResponseFormat, type ChatModelInputTool, type ChatModelOutputToolCall, type Message } from "@aigne/core";
|
|
2
|
+
export declare const COMMON_TOOLS: ChatModelInputTool[];
|
|
3
|
+
export declare const COMMON_RESPONSE_FORMAT: ChatModelInputResponseFormat;
|
|
4
|
+
export declare const createWeatherToolMessages: () => Promise<import("@aigne/core").ChatModelInputMessage[]>;
|
|
5
|
+
export declare const createWeatherToolExpected: () => any;
|
|
6
|
+
export declare const createWeatherToolCallMessages: () => Promise<import("@aigne/core").ChatModelInputMessage[]>;
|
|
7
|
+
export declare function createToolCallResponse(functionName: string, args: Message): ChatModelOutputToolCall;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect } from "bun:test";
|
|
2
|
+
import { AgentMessageTemplate, ChatMessagesTemplate, SystemMessageTemplate, ToolMessageTemplate, UserMessageTemplate, } from "@aigne/core";
|
|
3
|
+
export const COMMON_TOOLS = [
|
|
4
|
+
{
|
|
5
|
+
type: "function",
|
|
6
|
+
function: {
|
|
7
|
+
name: "get_weather",
|
|
8
|
+
parameters: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
city: {
|
|
12
|
+
type: "string",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
required: ["city"],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
export const COMMON_RESPONSE_FORMAT = {
|
|
21
|
+
type: "json_schema",
|
|
22
|
+
jsonSchema: {
|
|
23
|
+
name: "output",
|
|
24
|
+
schema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
text: {
|
|
28
|
+
type: "string",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
required: ["text"],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
strict: true,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const createBaseMessages = () => [
|
|
38
|
+
SystemMessageTemplate.from("You are a chatbot"),
|
|
39
|
+
UserMessageTemplate.from([{ type: "text", text: "What is the weather in New York?" }]),
|
|
40
|
+
];
|
|
41
|
+
export const createWeatherToolMessages = () => ChatMessagesTemplate.from(createBaseMessages()).format();
|
|
42
|
+
export const createWeatherToolExpected = () => expect.objectContaining({
|
|
43
|
+
toolCalls: [
|
|
44
|
+
{
|
|
45
|
+
function: {
|
|
46
|
+
arguments: {
|
|
47
|
+
city: "New York",
|
|
48
|
+
},
|
|
49
|
+
name: "get_weather",
|
|
50
|
+
},
|
|
51
|
+
id: expect.any(String),
|
|
52
|
+
type: "function",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
export const createWeatherToolCallMessages = () => ChatMessagesTemplate.from([
|
|
57
|
+
...createBaseMessages(),
|
|
58
|
+
AgentMessageTemplate.from(undefined, [
|
|
59
|
+
{
|
|
60
|
+
id: "get_weather",
|
|
61
|
+
type: "function",
|
|
62
|
+
function: { name: "get_weather", arguments: { city: "New York" } },
|
|
63
|
+
},
|
|
64
|
+
]),
|
|
65
|
+
ToolMessageTemplate.from({ temperature: 20 }, "get_weather"),
|
|
66
|
+
]).format();
|
|
67
|
+
export function createToolCallResponse(functionName, args) {
|
|
68
|
+
return {
|
|
69
|
+
id: functionName,
|
|
70
|
+
type: "function",
|
|
71
|
+
function: {
|
|
72
|
+
name: functionName,
|
|
73
|
+
arguments: args,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/test-utils",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.56-beta",
|
|
4
4
|
"description": "Test utils for AIGNE framework",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@aigne/core": "^1.
|
|
30
|
+
"@aigne/core": "^1.64.0-beta"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/bun": "^1.2.22",
|