@aigne/core 1.29.0 → 1.31.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/lib/cjs/agents/agent.d.ts +0 -2
  3. package/lib/cjs/agents/agent.js +1 -9
  4. package/lib/cjs/agents/ai-agent.d.ts +74 -0
  5. package/lib/cjs/agents/ai-agent.js +43 -3
  6. package/lib/cjs/agents/user-agent.js +1 -1
  7. package/lib/cjs/aigne/context.d.ts +4 -0
  8. package/lib/cjs/aigne/index.d.ts +1 -1
  9. package/lib/cjs/aigne/index.js +1 -1
  10. package/lib/cjs/aigne/message-queue.js +6 -6
  11. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  12. package/lib/cjs/prompt/prompt-builder.js +37 -10
  13. package/lib/cjs/prompt/prompts/memory-message-template.d.ts +1 -1
  14. package/lib/cjs/prompt/prompts/memory-message-template.js +2 -4
  15. package/lib/cjs/prompt/prompts/structured-stream-instructions.d.ts +7 -0
  16. package/lib/cjs/prompt/prompts/structured-stream-instructions.js +27 -0
  17. package/lib/cjs/utils/mcp-utils.d.ts +1 -1
  18. package/lib/cjs/utils/structured-stream-extractor.d.ts +14 -0
  19. package/lib/cjs/utils/structured-stream-extractor.js +60 -0
  20. package/lib/cjs/utils/type-utils.d.ts +1 -1
  21. package/lib/cjs/utils/type-utils.js +3 -3
  22. package/lib/dts/agents/agent.d.ts +0 -2
  23. package/lib/dts/agents/ai-agent.d.ts +74 -0
  24. package/lib/dts/aigne/context.d.ts +4 -0
  25. package/lib/dts/aigne/index.d.ts +1 -1
  26. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  27. package/lib/dts/prompt/prompts/memory-message-template.d.ts +1 -1
  28. package/lib/dts/prompt/prompts/structured-stream-instructions.d.ts +7 -0
  29. package/lib/dts/utils/mcp-utils.d.ts +1 -1
  30. package/lib/dts/utils/structured-stream-extractor.d.ts +14 -0
  31. package/lib/dts/utils/type-utils.d.ts +1 -1
  32. package/lib/esm/agents/agent.d.ts +0 -2
  33. package/lib/esm/agents/agent.js +2 -10
  34. package/lib/esm/agents/ai-agent.d.ts +74 -0
  35. package/lib/esm/agents/ai-agent.js +43 -3
  36. package/lib/esm/agents/user-agent.js +2 -2
  37. package/lib/esm/aigne/context.d.ts +4 -0
  38. package/lib/esm/aigne/context.js +1 -1
  39. package/lib/esm/aigne/index.d.ts +1 -1
  40. package/lib/esm/aigne/index.js +1 -1
  41. package/lib/esm/aigne/message-queue.js +7 -7
  42. package/lib/esm/loader/agent-js.js +1 -1
  43. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  44. package/lib/esm/prompt/prompt-builder.js +38 -11
  45. package/lib/esm/prompt/prompts/memory-message-template.d.ts +1 -1
  46. package/lib/esm/prompt/prompts/memory-message-template.js +2 -4
  47. package/lib/esm/prompt/prompts/structured-stream-instructions.d.ts +7 -0
  48. package/lib/esm/prompt/prompts/structured-stream-instructions.js +24 -0
  49. package/lib/esm/utils/mcp-utils.d.ts +1 -1
  50. package/lib/esm/utils/structured-stream-extractor.d.ts +14 -0
  51. package/lib/esm/utils/structured-stream-extractor.js +56 -0
  52. package/lib/esm/utils/type-utils.d.ts +1 -1
  53. package/lib/esm/utils/type-utils.js +2 -2
  54. package/package.json +14 -14
@@ -0,0 +1,14 @@
1
+ import { type AgentResponseChunk } from "../agents/agent.js";
2
+ import type { ChatModelOutput } from "../agents/chat-model.js";
3
+ export declare class ExtractMetadataTransform extends TransformStream<AgentResponseChunk<ChatModelOutput>, AgentResponseChunk<ChatModelOutput & {
4
+ metadata?: string;
5
+ }>> {
6
+ private buffer;
7
+ private cursor;
8
+ private state;
9
+ constructor({ start, end, parse, }: {
10
+ start: string;
11
+ end: string;
12
+ parse: (raw: string) => object;
13
+ });
14
+ }
@@ -0,0 +1,56 @@
1
+ import { isAgentResponseDelta } from "../agents/agent.js";
2
+ export class ExtractMetadataTransform extends TransformStream {
3
+ buffer = "";
4
+ cursor = 0;
5
+ state = "none";
6
+ constructor({ start, end, parse, }) {
7
+ super({
8
+ transform: async (chunk, controller) => {
9
+ if (isAgentResponseDelta(chunk) && chunk.delta.text?.text) {
10
+ const text = chunk.delta.text.text;
11
+ this.buffer += text;
12
+ for (;;) {
13
+ if (this.state === "none") {
14
+ const found = findMatchIndex(this.buffer, this.cursor, start);
15
+ if (found.start > this.cursor) {
16
+ const text = this.buffer.slice(this.cursor, found.start);
17
+ this.cursor = found.start;
18
+ controller.enqueue({ delta: { text: { text } } });
19
+ }
20
+ if (found.end) {
21
+ this.state = "start";
22
+ this.cursor = found.end;
23
+ }
24
+ }
25
+ if (this.state === "start") {
26
+ const found = findMatchIndex(this.buffer, this.cursor, end);
27
+ if (found.end) {
28
+ const metadata = this.buffer.slice(this.cursor, found.start);
29
+ const json = parse(metadata);
30
+ controller.enqueue({ delta: { json: { json } } });
31
+ this.state = "none";
32
+ this.cursor = found.end;
33
+ continue;
34
+ }
35
+ }
36
+ break;
37
+ }
38
+ return;
39
+ }
40
+ controller.enqueue(chunk);
41
+ },
42
+ });
43
+ }
44
+ }
45
+ function findMatchIndex(str, position, match) {
46
+ const i = str.indexOf(match, position);
47
+ if (i >= 0)
48
+ return { start: i, end: i + match.length };
49
+ for (let i = match.length - 1; i > 0; i--) {
50
+ const m = match.slice(0, i);
51
+ if (str.endsWith(m)) {
52
+ return { start: str.length - m.length };
53
+ }
54
+ }
55
+ return { start: str.length };
56
+ }
@@ -19,7 +19,7 @@ export declare function pick<T extends object, K extends keyof T>(obj: T, ...key
19
19
  export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
20
20
  export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
21
21
  export declare function omitBy<T extends Record<string, unknown>, K extends keyof T>(obj: T, predicate: (value: T[K], key: K) => boolean): Partial<T>;
22
- export declare function orArrayToArray<T>(value?: T | T[]): T[];
22
+ export declare function flat<T>(value?: T | T[]): T[];
23
23
  export declare function createAccessorArray<T>(array: T[], accessor: (array: T[], name: string) => T | undefined): T[] & {
24
24
  [key: string]: T;
25
25
  };
@@ -37,7 +37,7 @@ export function duplicates(arr, key = (item) => item) {
37
37
  export function remove(arr, remove) {
38
38
  const removed = [];
39
39
  for (let i = 0; i < arr.length; i++) {
40
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
40
+ // biome-ignore lint/style/noNonNullAssertion: false positive
41
41
  const item = arr[i];
42
42
  if ((Array.isArray(remove) && remove.includes(item)) ||
43
43
  (typeof remove === "function" && remove(item))) {
@@ -84,7 +84,7 @@ export function omitBy(obj, predicate) {
84
84
  return !predicate(value, k);
85
85
  }));
86
86
  }
87
- export function orArrayToArray(value) {
87
+ export function flat(value) {
88
88
  if (isNil(value))
89
89
  return [];
90
90
  return Array.isArray(value) ? value : [value];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.29.0",
3
+ "version": "1.31.0",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -63,12 +63,12 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@aigne/json-schema-to-zod": "^1.3.3",
66
- "@modelcontextprotocol/sdk": "^1.11.0",
66
+ "@modelcontextprotocol/sdk": "^1.13.3",
67
67
  "@types/debug": "^4.1.12",
68
68
  "camelize-ts": "^3.0.0",
69
69
  "content-type": "^1.0.5",
70
- "debug": "^4.4.0",
71
- "eventsource-parser": "^3.0.1",
70
+ "debug": "^4.4.1",
71
+ "eventsource-parser": "^3.0.3",
72
72
  "fast-deep-equal": "^3.1.3",
73
73
  "immer": "^10.1.1",
74
74
  "jsonata": "^2.0.6",
@@ -79,19 +79,19 @@
79
79
  "strict-event-emitter": "^0.5.1",
80
80
  "ufo": "^1.6.1",
81
81
  "uuid": "^11.1.0",
82
- "yaml": "^2.7.1",
83
- "zod": "^3.24.4",
84
- "zod-to-json-schema": "^3.24.5",
85
- "@aigne/platform-helpers": "^0.1.2",
86
- "@aigne/observability-api": "^0.3.2"
82
+ "yaml": "^2.8.0",
83
+ "zod": "^3.25.67",
84
+ "zod-to-json-schema": "^3.24.6",
85
+ "@aigne/observability-api": "^0.5.0",
86
+ "@aigne/platform-helpers": "^0.3.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@types/bun": "^1.2.12",
90
- "@types/compression": "^1.7.5",
91
- "@types/content-type": "^1.1.8",
92
- "@types/express": "^5.0.1",
89
+ "@types/bun": "^1.2.17",
90
+ "@types/compression": "^1.8.1",
91
+ "@types/content-type": "^1.1.9",
92
+ "@types/express": "^5.0.3",
93
93
  "@types/mustache": "^4.2.6",
94
- "@types/node": "^22.15.15",
94
+ "@types/node": "^24.0.10",
95
95
  "compression": "^1.8.0",
96
96
  "detect-port": "^2.1.0",
97
97
  "express": "^5.1.0",