@aigne/transport 0.3.5 → 0.4.0
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 +29 -0
- package/lib/cjs/http-client/client-agent.js +7 -5
- package/lib/cjs/http-client/client.d.ts +1 -0
- package/lib/cjs/http-client/client.js +2 -0
- package/lib/cjs/http-server/server.d.ts +12 -5
- package/lib/cjs/http-server/server.js +13 -8
- package/lib/dts/http-client/client.d.ts +1 -0
- package/lib/dts/http-server/server.d.ts +12 -5
- package/lib/esm/http-client/client-agent.js +7 -5
- package/lib/esm/http-client/client.d.ts +1 -0
- package/lib/esm/http-client/client.js +2 -0
- package/lib/esm/http-server/server.d.ts +12 -5
- package/lib/esm/http-server/server.js +13 -8
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/AIGNE-io/aigne-framework/compare/transport-v0.3.6...transport-v0.4.0) (2025-06-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* support respond progressing chunks by enable `returnProgressChunks` option for aigne.invoke ([cf4c313](https://github.com/AIGNE-io/aigne-framework/commit/cf4c313ee69f255be799ac196da675b79f69bf76))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @aigne/openai bumped to 0.3.0
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @aigne/core bumped to 1.19.0
|
|
18
|
+
* @aigne/test-utils bumped to 0.4.0
|
|
19
|
+
|
|
20
|
+
## [0.3.6](https://github.com/AIGNE-io/aigne-framework/compare/transport-v0.3.5...transport-v0.3.6) (2025-06-11)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Dependencies
|
|
24
|
+
|
|
25
|
+
* The following workspace dependencies were updated
|
|
26
|
+
* dependencies
|
|
27
|
+
* @aigne/openai bumped to 0.2.7
|
|
28
|
+
* devDependencies
|
|
29
|
+
* @aigne/core bumped to 1.18.6
|
|
30
|
+
* @aigne/test-utils bumped to 0.3.8
|
|
31
|
+
|
|
3
32
|
## [0.3.5](https://github.com/AIGNE-io/aigne-framework/compare/transport-v0.3.4...transport-v0.3.5) (2025-06-06)
|
|
4
33
|
|
|
5
34
|
|
|
@@ -23,11 +23,13 @@ class ClientAgent extends core_1.Agent {
|
|
|
23
23
|
});
|
|
24
24
|
return result;
|
|
25
25
|
}
|
|
26
|
-
return (0, stream_utils_js_1.onAgentResponseStreamEnd)(result,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
return (0, stream_utils_js_1.onAgentResponseStreamEnd)(result, {
|
|
27
|
+
onResult: async (result) => {
|
|
28
|
+
await this.postprocess((0, core_1.createMessage)(input), result, {
|
|
29
|
+
...options,
|
|
30
|
+
context: this.client,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
process(_input, _options) {
|
|
@@ -43,6 +43,7 @@ export declare class AIGNEHTTPClient<U extends UserContext = UserContext> implem
|
|
|
43
43
|
* @param options - Configuration options for connecting to the AIGNE server
|
|
44
44
|
*/
|
|
45
45
|
constructor(options: AIGNEHTTPClientOptions);
|
|
46
|
+
id: string;
|
|
46
47
|
usage: ContextUsage;
|
|
47
48
|
userContext: U;
|
|
48
49
|
memories: Context["memories"];
|
|
@@ -4,6 +4,7 @@ exports.AIGNEHTTPClient = void 0;
|
|
|
4
4
|
const core_1 = require("@aigne/core");
|
|
5
5
|
const event_stream_js_1 = require("@aigne/core/utils/event-stream.js");
|
|
6
6
|
const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
7
8
|
const client_agent_js_1 = require("./client-agent.js");
|
|
8
9
|
/**
|
|
9
10
|
* Http client for interacting with a remote AIGNE server.
|
|
@@ -28,6 +29,7 @@ class AIGNEHTTPClient {
|
|
|
28
29
|
constructor(options) {
|
|
29
30
|
this.options = options;
|
|
30
31
|
}
|
|
32
|
+
id = (0, uuid_1.v7)();
|
|
31
33
|
usage = (0, core_1.newEmptyContextUsage)();
|
|
32
34
|
userContext = {};
|
|
33
35
|
memories = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { AIGNE, AgentInvokeOptions, UserContext } from "@aigne/core";
|
|
2
|
+
import type { AIGNE, AgentInvokeOptions, InvokeOptions, UserContext } from "@aigne/core";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/**
|
|
5
5
|
* Schema for validating agent invocation payloads.
|
|
@@ -12,6 +12,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
12
12
|
input: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
13
13
|
options: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
14
14
|
streaming: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
|
+
returnProgressChunks: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
16
|
userContext: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>, Record<string, unknown> | undefined, Record<string, unknown> | null | undefined>;
|
|
16
17
|
memories: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
17
18
|
content: z.ZodType<object, z.ZodTypeDef, object>;
|
|
@@ -30,24 +31,28 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
30
31
|
memories?: {
|
|
31
32
|
content: object;
|
|
32
33
|
}[] | undefined;
|
|
34
|
+
returnProgressChunks?: boolean | undefined;
|
|
33
35
|
}, {
|
|
34
36
|
streaming?: boolean | null | undefined;
|
|
35
37
|
userContext?: Record<string, unknown> | null | undefined;
|
|
36
38
|
memories?: {
|
|
37
39
|
content: object;
|
|
38
40
|
}[] | null | undefined;
|
|
41
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
39
42
|
}>>>, {
|
|
40
43
|
streaming?: boolean | undefined;
|
|
41
44
|
userContext?: Record<string, unknown> | undefined;
|
|
42
45
|
memories?: {
|
|
43
46
|
content: object;
|
|
44
47
|
}[] | undefined;
|
|
48
|
+
returnProgressChunks?: boolean | undefined;
|
|
45
49
|
} | undefined, {
|
|
46
50
|
streaming?: boolean | null | undefined;
|
|
47
51
|
userContext?: Record<string, unknown> | null | undefined;
|
|
48
52
|
memories?: {
|
|
49
53
|
content: object;
|
|
50
54
|
}[] | null | undefined;
|
|
55
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
51
56
|
} | null | undefined>;
|
|
52
57
|
}, "strip", z.ZodTypeAny, {
|
|
53
58
|
agent: string;
|
|
@@ -58,6 +63,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
58
63
|
memories?: {
|
|
59
64
|
content: object;
|
|
60
65
|
}[] | undefined;
|
|
66
|
+
returnProgressChunks?: boolean | undefined;
|
|
61
67
|
} | undefined;
|
|
62
68
|
}, {
|
|
63
69
|
agent: string;
|
|
@@ -68,6 +74,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
68
74
|
memories?: {
|
|
69
75
|
content: object;
|
|
70
76
|
}[] | null | undefined;
|
|
77
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
71
78
|
} | null | undefined;
|
|
72
79
|
}>;
|
|
73
80
|
/**
|
|
@@ -86,7 +93,7 @@ export interface AIGNEHTTPServerOptions {
|
|
|
86
93
|
*/
|
|
87
94
|
maximumBodySize?: string;
|
|
88
95
|
}
|
|
89
|
-
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories"> {
|
|
96
|
+
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories">, Pick<InvokeOptions, "returnProgressChunks"> {
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* AIGNEHTTPServer provides HTTP API access to AIGNE capabilities.
|
|
@@ -103,15 +110,15 @@ export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContex
|
|
|
103
110
|
* {@includeCode ../../test/http-server/http-server.test.ts#example-aigne-server-hono}
|
|
104
111
|
*/
|
|
105
112
|
export declare class AIGNEHTTPServer {
|
|
106
|
-
|
|
113
|
+
aigne: AIGNE;
|
|
107
114
|
options?: AIGNEHTTPServerOptions | undefined;
|
|
108
115
|
/**
|
|
109
116
|
* Creates a new AIGNEServer instance.
|
|
110
117
|
*
|
|
111
|
-
* @param
|
|
118
|
+
* @param aigne - The AIGNE instance that will process agent invocations
|
|
112
119
|
* @param options - Configuration options for the server
|
|
113
120
|
*/
|
|
114
|
-
constructor(
|
|
121
|
+
constructor(aigne: AIGNE, options?: AIGNEHTTPServerOptions | undefined);
|
|
115
122
|
/**
|
|
116
123
|
* Invokes an agent with the provided input and returns a standard web Response.
|
|
117
124
|
* This method serves as the primary API endpoint for agent invocation.
|
|
@@ -33,6 +33,10 @@ exports.invokePayloadSchema = zod_1.z.object({
|
|
|
33
33
|
.boolean()
|
|
34
34
|
.nullish()
|
|
35
35
|
.transform((v) => v ?? undefined),
|
|
36
|
+
returnProgressChunks: zod_1.z
|
|
37
|
+
.boolean()
|
|
38
|
+
.nullish()
|
|
39
|
+
.transform((v) => v ?? undefined),
|
|
36
40
|
userContext: zod_1.z
|
|
37
41
|
.record(zod_1.z.string(), zod_1.z.unknown())
|
|
38
42
|
.nullish()
|
|
@@ -60,16 +64,16 @@ exports.invokePayloadSchema = zod_1.z.object({
|
|
|
60
64
|
* {@includeCode ../../test/http-server/http-server.test.ts#example-aigne-server-hono}
|
|
61
65
|
*/
|
|
62
66
|
class AIGNEHTTPServer {
|
|
63
|
-
|
|
67
|
+
aigne;
|
|
64
68
|
options;
|
|
65
69
|
/**
|
|
66
70
|
* Creates a new AIGNEServer instance.
|
|
67
71
|
*
|
|
68
|
-
* @param
|
|
72
|
+
* @param aigne - The AIGNE instance that will process agent invocations
|
|
69
73
|
* @param options - Configuration options for the server
|
|
70
74
|
*/
|
|
71
|
-
constructor(
|
|
72
|
-
this.
|
|
75
|
+
constructor(aigne, options) {
|
|
76
|
+
this.aigne = aigne;
|
|
73
77
|
this.options = options;
|
|
74
78
|
}
|
|
75
79
|
async invoke(request, response, options) {
|
|
@@ -95,24 +99,25 @@ class AIGNEHTTPServer {
|
|
|
95
99
|
* @private
|
|
96
100
|
*/
|
|
97
101
|
async _invoke(request, options = {}) {
|
|
98
|
-
const {
|
|
102
|
+
const { aigne } = this;
|
|
99
103
|
try {
|
|
100
104
|
const payload = await this._prepareInput(request);
|
|
101
105
|
const { agent: agentName, input, options: { streaming, ...opts } = {}, } = (0, type_utils_js_1.tryOrThrow)(() => (0, type_utils_js_1.checkArguments)(`Invoke agent ${payload.agent}`, exports.invokePayloadSchema, payload), (error) => new error_js_1.ServerError(400, error.message));
|
|
102
|
-
const agent =
|
|
106
|
+
const agent = aigne.agents[agentName];
|
|
103
107
|
if (!agent)
|
|
104
108
|
throw new error_js_1.ServerError(404, `Agent ${agentName} not found`);
|
|
105
109
|
const mergedOptions = {
|
|
110
|
+
returnProgressChunks: opts.returnProgressChunks,
|
|
106
111
|
userContext: { ...opts.userContext, ...options.userContext },
|
|
107
112
|
memories: [...(opts.memories ?? []), ...(options.memories ?? [])],
|
|
108
113
|
};
|
|
109
114
|
if (!streaming) {
|
|
110
|
-
const result = await
|
|
115
|
+
const result = await aigne.invoke(agent, input, mergedOptions);
|
|
111
116
|
return new Response(JSON.stringify(result), {
|
|
112
117
|
headers: { "Content-Type": "application/json" },
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
|
-
const stream = await
|
|
120
|
+
const stream = await aigne.invoke(agent, input, {
|
|
116
121
|
...mergedOptions,
|
|
117
122
|
returnActiveAgent: false,
|
|
118
123
|
streaming: true,
|
|
@@ -43,6 +43,7 @@ export declare class AIGNEHTTPClient<U extends UserContext = UserContext> implem
|
|
|
43
43
|
* @param options - Configuration options for connecting to the AIGNE server
|
|
44
44
|
*/
|
|
45
45
|
constructor(options: AIGNEHTTPClientOptions);
|
|
46
|
+
id: string;
|
|
46
47
|
usage: ContextUsage;
|
|
47
48
|
userContext: U;
|
|
48
49
|
memories: Context["memories"];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { AIGNE, AgentInvokeOptions, UserContext } from "@aigne/core";
|
|
2
|
+
import type { AIGNE, AgentInvokeOptions, InvokeOptions, UserContext } from "@aigne/core";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/**
|
|
5
5
|
* Schema for validating agent invocation payloads.
|
|
@@ -12,6 +12,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
12
12
|
input: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
13
13
|
options: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
14
14
|
streaming: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
|
+
returnProgressChunks: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
16
|
userContext: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>, Record<string, unknown> | undefined, Record<string, unknown> | null | undefined>;
|
|
16
17
|
memories: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
17
18
|
content: z.ZodType<object, z.ZodTypeDef, object>;
|
|
@@ -30,24 +31,28 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
30
31
|
memories?: {
|
|
31
32
|
content: object;
|
|
32
33
|
}[] | undefined;
|
|
34
|
+
returnProgressChunks?: boolean | undefined;
|
|
33
35
|
}, {
|
|
34
36
|
streaming?: boolean | null | undefined;
|
|
35
37
|
userContext?: Record<string, unknown> | null | undefined;
|
|
36
38
|
memories?: {
|
|
37
39
|
content: object;
|
|
38
40
|
}[] | null | undefined;
|
|
41
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
39
42
|
}>>>, {
|
|
40
43
|
streaming?: boolean | undefined;
|
|
41
44
|
userContext?: Record<string, unknown> | undefined;
|
|
42
45
|
memories?: {
|
|
43
46
|
content: object;
|
|
44
47
|
}[] | undefined;
|
|
48
|
+
returnProgressChunks?: boolean | undefined;
|
|
45
49
|
} | undefined, {
|
|
46
50
|
streaming?: boolean | null | undefined;
|
|
47
51
|
userContext?: Record<string, unknown> | null | undefined;
|
|
48
52
|
memories?: {
|
|
49
53
|
content: object;
|
|
50
54
|
}[] | null | undefined;
|
|
55
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
51
56
|
} | null | undefined>;
|
|
52
57
|
}, "strip", z.ZodTypeAny, {
|
|
53
58
|
agent: string;
|
|
@@ -58,6 +63,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
58
63
|
memories?: {
|
|
59
64
|
content: object;
|
|
60
65
|
}[] | undefined;
|
|
66
|
+
returnProgressChunks?: boolean | undefined;
|
|
61
67
|
} | undefined;
|
|
62
68
|
}, {
|
|
63
69
|
agent: string;
|
|
@@ -68,6 +74,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
68
74
|
memories?: {
|
|
69
75
|
content: object;
|
|
70
76
|
}[] | null | undefined;
|
|
77
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
71
78
|
} | null | undefined;
|
|
72
79
|
}>;
|
|
73
80
|
/**
|
|
@@ -86,7 +93,7 @@ export interface AIGNEHTTPServerOptions {
|
|
|
86
93
|
*/
|
|
87
94
|
maximumBodySize?: string;
|
|
88
95
|
}
|
|
89
|
-
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories"> {
|
|
96
|
+
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories">, Pick<InvokeOptions, "returnProgressChunks"> {
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* AIGNEHTTPServer provides HTTP API access to AIGNE capabilities.
|
|
@@ -103,15 +110,15 @@ export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContex
|
|
|
103
110
|
* {@includeCode ../../test/http-server/http-server.test.ts#example-aigne-server-hono}
|
|
104
111
|
*/
|
|
105
112
|
export declare class AIGNEHTTPServer {
|
|
106
|
-
|
|
113
|
+
aigne: AIGNE;
|
|
107
114
|
options?: AIGNEHTTPServerOptions | undefined;
|
|
108
115
|
/**
|
|
109
116
|
* Creates a new AIGNEServer instance.
|
|
110
117
|
*
|
|
111
|
-
* @param
|
|
118
|
+
* @param aigne - The AIGNE instance that will process agent invocations
|
|
112
119
|
* @param options - Configuration options for the server
|
|
113
120
|
*/
|
|
114
|
-
constructor(
|
|
121
|
+
constructor(aigne: AIGNE, options?: AIGNEHTTPServerOptions | undefined);
|
|
115
122
|
/**
|
|
116
123
|
* Invokes an agent with the provided input and returns a standard web Response.
|
|
117
124
|
* This method serves as the primary API endpoint for agent invocation.
|
|
@@ -20,11 +20,13 @@ export class ClientAgent extends Agent {
|
|
|
20
20
|
});
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
-
return onAgentResponseStreamEnd(result,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return onAgentResponseStreamEnd(result, {
|
|
24
|
+
onResult: async (result) => {
|
|
25
|
+
await this.postprocess(createMessage(input), result, {
|
|
26
|
+
...options,
|
|
27
|
+
context: this.client,
|
|
28
|
+
});
|
|
29
|
+
},
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
process(_input, _options) {
|
|
@@ -43,6 +43,7 @@ export declare class AIGNEHTTPClient<U extends UserContext = UserContext> implem
|
|
|
43
43
|
* @param options - Configuration options for connecting to the AIGNE server
|
|
44
44
|
*/
|
|
45
45
|
constructor(options: AIGNEHTTPClientOptions);
|
|
46
|
+
id: string;
|
|
46
47
|
usage: ContextUsage;
|
|
47
48
|
userContext: U;
|
|
48
49
|
memories: Context["memories"];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { newEmptyContextUsage, } from "@aigne/core";
|
|
2
2
|
import { AgentResponseStreamParser, EventStreamParser } from "@aigne/core/utils/event-stream.js";
|
|
3
3
|
import { tryOrThrow } from "@aigne/core/utils/type-utils.js";
|
|
4
|
+
import { v7 } from "uuid";
|
|
4
5
|
import { ClientAgent } from "./client-agent.js";
|
|
5
6
|
/**
|
|
6
7
|
* Http client for interacting with a remote AIGNE server.
|
|
@@ -25,6 +26,7 @@ export class AIGNEHTTPClient {
|
|
|
25
26
|
constructor(options) {
|
|
26
27
|
this.options = options;
|
|
27
28
|
}
|
|
29
|
+
id = v7();
|
|
28
30
|
usage = newEmptyContextUsage();
|
|
29
31
|
userContext = {};
|
|
30
32
|
memories = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { AIGNE, AgentInvokeOptions, UserContext } from "@aigne/core";
|
|
2
|
+
import type { AIGNE, AgentInvokeOptions, InvokeOptions, UserContext } from "@aigne/core";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/**
|
|
5
5
|
* Schema for validating agent invocation payloads.
|
|
@@ -12,6 +12,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
12
12
|
input: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>;
|
|
13
13
|
options: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
14
14
|
streaming: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
|
+
returnProgressChunks: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, boolean | undefined, boolean | null | undefined>;
|
|
15
16
|
userContext: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>, Record<string, unknown> | undefined, Record<string, unknown> | null | undefined>;
|
|
16
17
|
memories: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
17
18
|
content: z.ZodType<object, z.ZodTypeDef, object>;
|
|
@@ -30,24 +31,28 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
30
31
|
memories?: {
|
|
31
32
|
content: object;
|
|
32
33
|
}[] | undefined;
|
|
34
|
+
returnProgressChunks?: boolean | undefined;
|
|
33
35
|
}, {
|
|
34
36
|
streaming?: boolean | null | undefined;
|
|
35
37
|
userContext?: Record<string, unknown> | null | undefined;
|
|
36
38
|
memories?: {
|
|
37
39
|
content: object;
|
|
38
40
|
}[] | null | undefined;
|
|
41
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
39
42
|
}>>>, {
|
|
40
43
|
streaming?: boolean | undefined;
|
|
41
44
|
userContext?: Record<string, unknown> | undefined;
|
|
42
45
|
memories?: {
|
|
43
46
|
content: object;
|
|
44
47
|
}[] | undefined;
|
|
48
|
+
returnProgressChunks?: boolean | undefined;
|
|
45
49
|
} | undefined, {
|
|
46
50
|
streaming?: boolean | null | undefined;
|
|
47
51
|
userContext?: Record<string, unknown> | null | undefined;
|
|
48
52
|
memories?: {
|
|
49
53
|
content: object;
|
|
50
54
|
}[] | null | undefined;
|
|
55
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
51
56
|
} | null | undefined>;
|
|
52
57
|
}, "strip", z.ZodTypeAny, {
|
|
53
58
|
agent: string;
|
|
@@ -58,6 +63,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
58
63
|
memories?: {
|
|
59
64
|
content: object;
|
|
60
65
|
}[] | undefined;
|
|
66
|
+
returnProgressChunks?: boolean | undefined;
|
|
61
67
|
} | undefined;
|
|
62
68
|
}, {
|
|
63
69
|
agent: string;
|
|
@@ -68,6 +74,7 @@ export declare const invokePayloadSchema: z.ZodObject<{
|
|
|
68
74
|
memories?: {
|
|
69
75
|
content: object;
|
|
70
76
|
}[] | null | undefined;
|
|
77
|
+
returnProgressChunks?: boolean | null | undefined;
|
|
71
78
|
} | null | undefined;
|
|
72
79
|
}>;
|
|
73
80
|
/**
|
|
@@ -86,7 +93,7 @@ export interface AIGNEHTTPServerOptions {
|
|
|
86
93
|
*/
|
|
87
94
|
maximumBodySize?: string;
|
|
88
95
|
}
|
|
89
|
-
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories"> {
|
|
96
|
+
export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContext> extends Pick<AgentInvokeOptions<U>, "userContext" | "memories">, Pick<InvokeOptions, "returnProgressChunks"> {
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* AIGNEHTTPServer provides HTTP API access to AIGNE capabilities.
|
|
@@ -103,15 +110,15 @@ export interface AIGNEHTTPServerInvokeOptions<U extends UserContext = UserContex
|
|
|
103
110
|
* {@includeCode ../../test/http-server/http-server.test.ts#example-aigne-server-hono}
|
|
104
111
|
*/
|
|
105
112
|
export declare class AIGNEHTTPServer {
|
|
106
|
-
|
|
113
|
+
aigne: AIGNE;
|
|
107
114
|
options?: AIGNEHTTPServerOptions | undefined;
|
|
108
115
|
/**
|
|
109
116
|
* Creates a new AIGNEServer instance.
|
|
110
117
|
*
|
|
111
|
-
* @param
|
|
118
|
+
* @param aigne - The AIGNE instance that will process agent invocations
|
|
112
119
|
* @param options - Configuration options for the server
|
|
113
120
|
*/
|
|
114
|
-
constructor(
|
|
121
|
+
constructor(aigne: AIGNE, options?: AIGNEHTTPServerOptions | undefined);
|
|
115
122
|
/**
|
|
116
123
|
* Invokes an agent with the provided input and returns a standard web Response.
|
|
117
124
|
* This method serves as the primary API endpoint for agent invocation.
|
|
@@ -27,6 +27,10 @@ export const invokePayloadSchema = z.object({
|
|
|
27
27
|
.boolean()
|
|
28
28
|
.nullish()
|
|
29
29
|
.transform((v) => v ?? undefined),
|
|
30
|
+
returnProgressChunks: z
|
|
31
|
+
.boolean()
|
|
32
|
+
.nullish()
|
|
33
|
+
.transform((v) => v ?? undefined),
|
|
30
34
|
userContext: z
|
|
31
35
|
.record(z.string(), z.unknown())
|
|
32
36
|
.nullish()
|
|
@@ -54,16 +58,16 @@ export const invokePayloadSchema = z.object({
|
|
|
54
58
|
* {@includeCode ../../test/http-server/http-server.test.ts#example-aigne-server-hono}
|
|
55
59
|
*/
|
|
56
60
|
export class AIGNEHTTPServer {
|
|
57
|
-
|
|
61
|
+
aigne;
|
|
58
62
|
options;
|
|
59
63
|
/**
|
|
60
64
|
* Creates a new AIGNEServer instance.
|
|
61
65
|
*
|
|
62
|
-
* @param
|
|
66
|
+
* @param aigne - The AIGNE instance that will process agent invocations
|
|
63
67
|
* @param options - Configuration options for the server
|
|
64
68
|
*/
|
|
65
|
-
constructor(
|
|
66
|
-
this.
|
|
69
|
+
constructor(aigne, options) {
|
|
70
|
+
this.aigne = aigne;
|
|
67
71
|
this.options = options;
|
|
68
72
|
}
|
|
69
73
|
async invoke(request, response, options) {
|
|
@@ -89,24 +93,25 @@ export class AIGNEHTTPServer {
|
|
|
89
93
|
* @private
|
|
90
94
|
*/
|
|
91
95
|
async _invoke(request, options = {}) {
|
|
92
|
-
const {
|
|
96
|
+
const { aigne } = this;
|
|
93
97
|
try {
|
|
94
98
|
const payload = await this._prepareInput(request);
|
|
95
99
|
const { agent: agentName, input, options: { streaming, ...opts } = {}, } = tryOrThrow(() => checkArguments(`Invoke agent ${payload.agent}`, invokePayloadSchema, payload), (error) => new ServerError(400, error.message));
|
|
96
|
-
const agent =
|
|
100
|
+
const agent = aigne.agents[agentName];
|
|
97
101
|
if (!agent)
|
|
98
102
|
throw new ServerError(404, `Agent ${agentName} not found`);
|
|
99
103
|
const mergedOptions = {
|
|
104
|
+
returnProgressChunks: opts.returnProgressChunks,
|
|
100
105
|
userContext: { ...opts.userContext, ...options.userContext },
|
|
101
106
|
memories: [...(opts.memories ?? []), ...(options.memories ?? [])],
|
|
102
107
|
};
|
|
103
108
|
if (!streaming) {
|
|
104
|
-
const result = await
|
|
109
|
+
const result = await aigne.invoke(agent, input, mergedOptions);
|
|
105
110
|
return new Response(JSON.stringify(result), {
|
|
106
111
|
headers: { "Content-Type": "application/json" },
|
|
107
112
|
});
|
|
108
113
|
}
|
|
109
|
-
const stream = await
|
|
114
|
+
const stream = await aigne.invoke(agent, input, {
|
|
110
115
|
...mergedOptions,
|
|
111
116
|
returnActiveAgent: false,
|
|
112
117
|
streaming: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/transport",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "AIGNE Transport SDK providing HTTP client and server implementations for communication between AIGNE components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@aigne/openai": "^0.
|
|
42
|
+
"@aigne/openai": "^0.3.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/bun": "^1.2.12",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"rimraf": "^6.0.1",
|
|
55
55
|
"typescript": "^5.8.3",
|
|
56
56
|
"uuid": "^11.1.0",
|
|
57
|
-
"@aigne/core": "^1.
|
|
58
|
-
"@aigne/test-utils": "^0.
|
|
57
|
+
"@aigne/core": "^1.19.0",
|
|
58
|
+
"@aigne/test-utils": "^0.4.0"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"lint": "tsc --noEmit",
|