@cloudbase/agent-server 0.0.2 → 0.0.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 CHANGED
@@ -1,5 +1,74 @@
1
1
  # @cloudbase/agent-server
2
2
 
3
+ ## 0.0.11-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - alpha release 0.0.10-alpha.2
8
+ - Update all public packages to version 0.0.10-alpha.2
9
+ - Trigger automated alpha release workflow
10
+ - Includes latest features and improvements
11
+
12
+ - Updated dependencies
13
+ - @cloudbase/agent-shared@0.0.11-alpha.3
14
+
15
+ ## 0.0.11-alpha.2
16
+
17
+ ### Patch Changes
18
+
19
+ - alpha release 0.0.10-alpha.2
20
+ - Update all public packages to version 0.0.10-alpha.2
21
+ - Trigger automated alpha release workflow
22
+ - Includes latest features and improvements
23
+
24
+ - Updated dependencies
25
+ - @cloudbase/agent-agents@0.0.11-alpha.2
26
+ - @cloudbase/agent-shared@0.0.11-alpha.2
27
+
28
+ ## 0.0.11-alpha.1
29
+
30
+ ### Patch Changes
31
+
32
+ - alpha release 0.0.10-alpha.2
33
+ - Update all public packages to version 0.0.10-alpha.2
34
+ - Trigger automated alpha release workflow
35
+ - Includes latest features and improvements
36
+
37
+ - Updated dependencies
38
+ - @cloudbase/agent-agents@0.0.11-alpha.1
39
+ - @cloudbase/agent-shared@0.0.11-alpha.1
40
+
41
+ ## 0.0.11-alpha.0
42
+
43
+ ### Patch Changes
44
+
45
+ - 97b2740: alpha release 0.0.10-alpha.2
46
+ - Update all public packages to version 0.0.10-alpha.2
47
+ - Trigger automated alpha release workflow
48
+ - Includes latest features and improvements
49
+
50
+ - fd4c62a: alpha release 0.0.10-alpha.2
51
+ - Update all public packages to version 0.0.10-alpha.2
52
+ - Trigger automated alpha release workflow
53
+ - Includes latest features and improvements
54
+
55
+ - da3388c: alpha release 0.0.10-alpha.2
56
+ - Update all public packages to version 0.0.10-alpha.2
57
+ - Trigger automated alpha release workflow
58
+ - Includes latest features and improvements
59
+
60
+ - alpha release 0.0.10-alpha.2
61
+ - Update all public packages to version 0.0.10-alpha.2
62
+ - Trigger automated alpha release workflow
63
+ - Includes latest features and improvements
64
+
65
+ - Updated dependencies [97b2740]
66
+ - Updated dependencies [fd4c62a]
67
+ - Updated dependencies [da3388c]
68
+ - Updated dependencies
69
+ - @cloudbase/agent-agents@0.0.11-alpha.0
70
+ - @cloudbase/agent-shared@0.0.11-alpha.0
71
+
3
72
  ## 0.0.10
4
73
 
5
74
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { CreateCopilotRuntimeServerOptions } from '@copilotkit/runtime';
2
+ import { CopilotRuntimeOptions } from '@copilotkit/runtime/v2';
1
3
  import express, { Express } from 'express';
2
- import { AbstractAgent } from '@cloudbase/agent-agents/abstract';
4
+ import * as _ag_ui_client from '@ag-ui/client';
5
+ import { AbstractAgent, RunAgentInput } from '@ag-ui/client';
3
6
  import cors from 'cors';
4
- import { AbstractAgent as AbstractAgent$1 } from '@ag-ui/client';
5
7
  import { SendMessageInput } from '@cloudbase/agent-shared';
6
8
  import { Repeater } from '@repeaterjs/repeater';
7
9
  import * as _whatwg_node_server from '@whatwg-node/server';
@@ -21,14 +23,21 @@ interface ICreateServer {
21
23
  }
22
24
  declare function run(props: ICreateServer & {
23
25
  port?: number | string;
24
- }): void;
25
- declare function createExpressServer(props: ICreateServer): Express;
26
+ }): Promise<void>;
27
+ declare function createExpressServer(props: ICreateServer): Promise<Express>;
26
28
  interface ICreateExpressRoutes extends ICreateServer {
27
29
  express: Express;
30
+ useAGUI?: boolean;
31
+ aguiOptions?: AGUIOptions;
32
+ }
33
+ declare function createExpressRoutes({ createAgent, basePath: _basePath, express, useAGUI, aguiOptions, }: ICreateExpressRoutes): Promise<express.Express>;
34
+ interface AGUIOptions {
35
+ agentId?: string;
36
+ runtimeOptions?: Partial<CopilotRuntimeOptions>;
37
+ endpointOptions?: Partial<CreateCopilotRuntimeServerOptions>;
28
38
  }
29
- declare function createExpressRoutes({ createAgent, basePath: _basePath, express, }: ICreateExpressRoutes): express.Express;
30
39
 
31
- declare function handler$1(input: SendMessageInput, agent: AbstractAgent$1): Repeater<{
40
+ declare function handler$2(input: SendMessageInput, agent: AbstractAgent): Repeater<{
32
41
  type: "text";
33
42
  content: string;
34
43
  } | {
@@ -53,6 +62,18 @@ declare function handler$1(input: SendMessageInput, agent: AbstractAgent$1): Rep
53
62
  payload: any;
54
63
  }, any, unknown>;
55
64
 
65
+ declare function createServerAdapter$2(createAgent: AgentCreator): _whatwg_node_server.ServerAdapter<{}, _whatwg_node_server.ServerAdapterBaseObject<{}, (request: Request) => Promise<Response>>>;
66
+
67
+ declare namespace index$4 {
68
+ export { createServerAdapter$2 as createServerAdapter, handler$2 as handler };
69
+ }
70
+
71
+ declare function handler$1(input: RunAgentInput, agent: AbstractAgent): Repeater<{
72
+ type: _ag_ui_client.EventType;
73
+ timestamp?: number | undefined;
74
+ rawEvent?: any;
75
+ }, any, unknown>;
76
+
56
77
  declare function createServerAdapter$1(createAgent: AgentCreator): _whatwg_node_server.ServerAdapter<{}, _whatwg_node_server.ServerAdapterBaseObject<{}, (request: Request) => Promise<Response>>>;
57
78
 
58
79
  declare namespace index$3 {
@@ -72,7 +93,7 @@ type ChatCompletionsInput = {
72
93
  messages: Array<OpenAIMessage>;
73
94
  tools?: Array<OpenAITool>;
74
95
  };
75
- declare function handler(input: ChatCompletionsInput, agent: AbstractAgent$1): Repeater<OpenAI.Chat.Completions.ChatCompletionChunk, any, unknown>;
96
+ declare function handler(input: ChatCompletionsInput, agent: AbstractAgent): Repeater<OpenAI.Chat.Completions.ChatCompletionChunk, any, unknown>;
76
97
 
77
98
  declare function createServerAdapter(createAgent: AgentCreator): _whatwg_node_server.ServerAdapter<{}, _whatwg_node_server.ServerAdapterBaseObject<{}, (request: Request) => Promise<Response>>>;
78
99
 
@@ -83,7 +104,7 @@ declare namespace index$1 {
83
104
  }
84
105
 
85
106
  declare namespace index {
86
- export { index$2 as healthz, index$1 as openai, index$3 as sendMessage };
107
+ export { index$2 as healthz, index$1 as openai, index$4 as sendMessage, index$3 as sendMessageAGUI };
87
108
  }
88
109
 
89
110
  export { type AgentCreator, index as agui, createExpressRoutes, createExpressServer, run };
package/dist/index.js CHANGED
@@ -41,7 +41,8 @@ var agui_exports = {};
41
41
  __export(agui_exports, {
42
42
  healthz: () => healthz_exports,
43
43
  openai: () => openai_exports,
44
- sendMessage: () => sendMessage_exports
44
+ sendMessage: () => sendMessage_exports,
45
+ sendMessageAGUI: () => sendMessageAGUI_exports
45
46
  });
46
47
 
47
48
  // src/agui/sendMessage/index.ts
@@ -73,12 +74,20 @@ function handler(input, agent) {
73
74
  onTextMessageContentEvent: ({ event }) => {
74
75
  push({
75
76
  type: "text",
76
- content: event.delta
77
+ content: event.delta,
78
+ rawEvent: event.rawEvent
77
79
  });
78
80
  },
79
81
  onRunFinishedEvent: () => {
80
82
  stop();
81
83
  },
84
+ onRunErrorEvent: ({ event }) => {
85
+ push({
86
+ type: "error",
87
+ error: event.message,
88
+ code: event.code
89
+ });
90
+ },
82
91
  onToolCallStartEvent: ({ event }) => {
83
92
  push({
84
93
  type: "tool-call-start",
@@ -194,25 +203,90 @@ function createServerAdapter(createAgent) {
194
203
  });
195
204
  }
196
205
 
206
+ // src/agui/sendMessageAGUI/index.ts
207
+ var sendMessageAGUI_exports = {};
208
+ __export(sendMessageAGUI_exports, {
209
+ createServerAdapter: () => createServerAdapter2,
210
+ handler: () => handler2
211
+ });
212
+
213
+ // src/agui/sendMessageAGUI/handler.ts
214
+ var import_repeater2 = require("@repeaterjs/repeater");
215
+ function handler2(input, agent) {
216
+ return new import_repeater2.Repeater(async (push, stop) => {
217
+ agent.setMessages(input.messages);
218
+ agent.setState(input.state);
219
+ agent.threadId = input.threadId;
220
+ await agent.runAgent(input, {
221
+ onEvent: ({ event }) => {
222
+ push(event);
223
+ }
224
+ });
225
+ stop();
226
+ });
227
+ }
228
+
229
+ // src/agui/sendMessageAGUI/server.ts
230
+ var import_server3 = require("@whatwg-node/server");
231
+ var import_client2 = require("@ag-ui/client");
232
+ function createServerAdapter2(createAgent) {
233
+ return (0, import_server3.createServerAdapter)(async (request) => {
234
+ const input = import_client2.RunAgentInputSchema.parse(await request.json());
235
+ const { agent: unknownAgent, cleanup } = await Promise.resolve(createAgent());
236
+ const agent = "toAGUIAgent" in unknownAgent ? unknownAgent.toAGUIAgent() : unknownAgent;
237
+ const events = handler2(input, agent);
238
+ let heartbeat;
239
+ const stream = new ReadableStream({
240
+ async start(controller) {
241
+ const encoder = new TextEncoder();
242
+ heartbeat = setInterval(() => {
243
+ controller.enqueue(encoder.encode(":ping\n\n"));
244
+ }, 15 * 1e3);
245
+ try {
246
+ for await (const event of events) {
247
+ const sseChunk = `data: ${JSON.stringify(event)}
248
+
249
+ `;
250
+ controller.enqueue(encoder.encode(sseChunk));
251
+ }
252
+ } finally {
253
+ if (heartbeat) clearInterval(heartbeat);
254
+ controller.close();
255
+ cleanup == null ? void 0 : cleanup();
256
+ }
257
+ },
258
+ cancel() {
259
+ if (heartbeat) clearInterval(heartbeat);
260
+ }
261
+ });
262
+ const headers = new Headers({
263
+ "Content-Type": "text/event-stream",
264
+ "Cache-Control": "no-cache, no-transform",
265
+ Connection: "keep-alive"
266
+ });
267
+ return new Response(stream, { status: 200, headers });
268
+ });
269
+ }
270
+
197
271
  // src/agui/healthz/index.ts
198
272
  var healthz_exports = {};
199
273
  __export(healthz_exports, {
200
274
  serverAdapter: () => serverAdapter
201
275
  });
202
- var import_server3 = require("@whatwg-node/server");
203
- var serverAdapter = (0, import_server3.createServerAdapter)(() => new Response("OK"));
276
+ var import_server5 = require("@whatwg-node/server");
277
+ var serverAdapter = (0, import_server5.createServerAdapter)(() => new Response("OK"));
204
278
 
205
279
  // src/agui/openai/index.ts
206
280
  var openai_exports = {};
207
281
  __export(openai_exports, {
208
- createServerAdapter: () => createServerAdapter2,
209
- handler: () => handler2
282
+ createServerAdapter: () => createServerAdapter3,
283
+ handler: () => handler3
210
284
  });
211
285
 
212
286
  // src/agui/openai/handler.ts
213
287
  var import_uuid2 = require("uuid");
214
- var import_repeater2 = require("@repeaterjs/repeater");
215
- function handler2(input, agent) {
288
+ var import_repeater3 = require("@repeaterjs/repeater");
289
+ function handler3(input, agent) {
216
290
  var _a;
217
291
  const res = handler(
218
292
  {
@@ -226,7 +300,7 @@ function handler2(input, agent) {
226
300
  },
227
301
  agent
228
302
  );
229
- return new import_repeater2.Repeater(async (push, stop) => {
303
+ return new import_repeater3.Repeater(async (push, stop) => {
230
304
  const id = (0, import_uuid2.v4)();
231
305
  let tools = [];
232
306
  let lastWithToolCall = false;
@@ -352,13 +426,13 @@ function openAIMessageToClientMessage(message) {
352
426
  }
353
427
 
354
428
  // src/agui/openai/server.ts
355
- var import_server4 = require("@whatwg-node/server");
356
- function createServerAdapter2(createAgent) {
357
- return (0, import_server4.createServerAdapter)(async (request) => {
429
+ var import_server6 = require("@whatwg-node/server");
430
+ function createServerAdapter3(createAgent) {
431
+ return (0, import_server6.createServerAdapter)(async (request) => {
358
432
  const input = await request.json();
359
433
  const { agent: unknownAgent, cleanup } = await Promise.resolve(createAgent());
360
434
  const agent = "toAGUIAgent" in unknownAgent ? unknownAgent.toAGUIAgent() : unknownAgent;
361
- const events = handler2(input, agent);
435
+ const events = handler3(input, agent);
362
436
  const stream = new ReadableStream({
363
437
  async start(controller) {
364
438
  const encoder = new TextEncoder();
@@ -383,34 +457,45 @@ function createServerAdapter2(createAgent) {
383
457
  }
384
458
 
385
459
  // src/express.ts
460
+ var import_runtime = require("@copilotkit/runtime");
386
461
  var import_express = __toESM(require("express"));
387
462
  var import_cors = __toESM(require("cors"));
388
- function run(props) {
463
+ async function run(props) {
389
464
  const { port, ...rest } = props;
390
- createExpressServer(rest).listen(
465
+ (await createExpressServer(rest)).listen(
391
466
  typeof port === "number" ? port : parseInt(port)
392
467
  );
393
468
  }
394
- function createExpressServer(props) {
469
+ async function createExpressServer(props) {
395
470
  const { cors: corsOption = true } = props;
396
471
  const app = (0, import_express.default)();
397
472
  if (corsOption) {
398
473
  app.use(isCorsOptions(corsOption) ? (0, import_cors.default)(corsOption) : (0, import_cors.default)());
399
474
  }
400
- createExpressRoutes({
475
+ await createExpressRoutes({
401
476
  ...props,
402
477
  express: app,
403
478
  basePath: props.basePath ?? process.env.TENCENTCLOUD_RUNENV === "SCF" ? "/v1/aibot/bots/:agentId/" : void 0
404
479
  });
405
480
  return app;
406
481
  }
407
- function createExpressRoutes({
482
+ async function createExpressRoutes({
408
483
  createAgent,
409
484
  basePath: _basePath,
410
- express: express2
485
+ express: express2,
486
+ useAGUI,
487
+ aguiOptions
411
488
  }) {
412
489
  const basePath = _basePath ?? "/";
413
- const sendMessageServerAdapter = sendMessage_exports.createServerAdapter(createAgent);
490
+ const sendMessageServerAdapter = useAGUI ? sendMessageAGUI_exports.createServerAdapter(createAgent) : sendMessage_exports.createServerAdapter(createAgent);
491
+ if (useAGUI) {
492
+ await createAGUIRoute({
493
+ basePath,
494
+ express: express2,
495
+ createAgent,
496
+ ...aguiOptions || {}
497
+ });
498
+ }
414
499
  const openaiServerAdapter = openai_exports.createServerAdapter(createAgent);
415
500
  const healthzServerAdapter = healthz_exports.serverAdapter;
416
501
  express2.use(`${basePath}send-message`, sendMessageServerAdapter);
@@ -418,6 +503,30 @@ function createExpressRoutes({
418
503
  express2.use(`${basePath}chat/completions`, openaiServerAdapter);
419
504
  return express2;
420
505
  }
506
+ async function createAGUIRoute({
507
+ createAgent,
508
+ express: express2,
509
+ agentId,
510
+ basePath,
511
+ runtimeOptions,
512
+ endpointOptions
513
+ }) {
514
+ const agent = (await createAgent()).agent;
515
+ const aguiAgent = "toAGUIAgent" in agent ? agent.toAGUIAgent() : agent;
516
+ const runtime = new import_runtime.CopilotRuntime({
517
+ agents: {
518
+ [agentId || "default"]: aguiAgent
519
+ },
520
+ ...runtimeOptions || {}
521
+ });
522
+ const rpcHandler = (0, import_runtime.copilotRuntimeNodeExpressEndpoint)({
523
+ endpoint: `${basePath}agui`,
524
+ runtime,
525
+ serviceAdapter: new import_runtime.EmptyAdapter(),
526
+ ...endpointOptions || {}
527
+ });
528
+ express2.post(`${basePath}agui`, rpcHandler);
529
+ }
421
530
  function isCorsOptions(cors2) {
422
531
  return typeof cors2 === "boolean";
423
532
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/agent-server",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist/",
@@ -11,7 +11,8 @@
11
11
  "license": "ISC",
12
12
  "description": "",
13
13
  "dependencies": {
14
- "@ag-ui/client": "^0.0.38",
14
+ "@ag-ui/client": "0.0.42",
15
+ "@copilotkit/runtime": "^1.50.1",
15
16
  "@repeaterjs/repeater": "^3.0.6",
16
17
  "@whatwg-node/server": "^0.10.12",
17
18
  "cors": "^2.8.5",
@@ -19,8 +20,7 @@
19
20
  "openai": "6.3.0",
20
21
  "uuid": "^10.0.0",
21
22
  "zod": "^4.1.12",
22
- "@cloudbase/agent-agents": "0.0.2",
23
- "@cloudbase/agent-shared": "^0.0.2"
23
+ "@cloudbase/agent-shared": "^0.0.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/cors": "^2.8.19",