@aigne/core 1.22.0 → 1.23.1

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 (44) hide show
  1. package/CHANGELOG.md +33 -87
  2. package/lib/cjs/agents/agent.d.ts +15 -10
  3. package/lib/cjs/agents/agent.js +6 -10
  4. package/lib/cjs/agents/ai-agent.d.ts +1 -1
  5. package/lib/cjs/agents/mcp-agent.d.ts +1 -1
  6. package/lib/cjs/aigne/aigne.d.ts +4 -4
  7. package/lib/cjs/aigne/aigne.js +2 -0
  8. package/lib/cjs/aigne/context.d.ts +2 -2
  9. package/lib/cjs/loader/index.d.ts +2 -2
  10. package/lib/cjs/memory/memory.d.ts +5 -3
  11. package/lib/cjs/memory/memory.js +17 -3
  12. package/lib/cjs/memory/recorder.d.ts +14 -8
  13. package/lib/cjs/memory/recorder.js +13 -1
  14. package/lib/cjs/memory/retriever.d.ts +13 -7
  15. package/lib/cjs/memory/retriever.js +9 -1
  16. package/lib/cjs/utils/type-utils.d.ts +1 -0
  17. package/lib/cjs/utils/type-utils.js +5 -0
  18. package/lib/dts/agents/agent.d.ts +15 -10
  19. package/lib/dts/agents/ai-agent.d.ts +1 -1
  20. package/lib/dts/agents/mcp-agent.d.ts +1 -1
  21. package/lib/dts/aigne/aigne.d.ts +4 -4
  22. package/lib/dts/aigne/context.d.ts +2 -2
  23. package/lib/dts/loader/index.d.ts +2 -2
  24. package/lib/dts/memory/memory.d.ts +5 -3
  25. package/lib/dts/memory/recorder.d.ts +14 -8
  26. package/lib/dts/memory/retriever.d.ts +13 -7
  27. package/lib/dts/utils/type-utils.d.ts +1 -0
  28. package/lib/esm/agents/agent.d.ts +15 -10
  29. package/lib/esm/agents/agent.js +6 -10
  30. package/lib/esm/agents/ai-agent.d.ts +1 -1
  31. package/lib/esm/agents/mcp-agent.d.ts +1 -1
  32. package/lib/esm/aigne/aigne.d.ts +4 -4
  33. package/lib/esm/aigne/aigne.js +2 -0
  34. package/lib/esm/aigne/context.d.ts +2 -2
  35. package/lib/esm/loader/index.d.ts +2 -2
  36. package/lib/esm/memory/memory.d.ts +5 -3
  37. package/lib/esm/memory/memory.js +17 -3
  38. package/lib/esm/memory/recorder.d.ts +14 -8
  39. package/lib/esm/memory/recorder.js +14 -2
  40. package/lib/esm/memory/retriever.d.ts +13 -7
  41. package/lib/esm/memory/retriever.js +10 -2
  42. package/lib/esm/utils/type-utils.d.ts +1 -0
  43. package/lib/esm/utils/type-utils.js +4 -0
  44. package/package.json +2 -2
@@ -1,10 +1,14 @@
1
1
  import { z } from "zod";
2
- import { Agent } from "../agents/agent.js";
2
+ import { Agent, } from "../agents/agent.js";
3
3
  /**
4
4
  * @hidden
5
5
  */
6
6
  export const memoryRecorderInputSchema = z.object({
7
- content: z.array(z.unknown()),
7
+ content: z.array(z.object({
8
+ input: z.record(z.string(), z.unknown()).optional(),
9
+ output: z.record(z.string(), z.unknown()).optional(),
10
+ source: z.string().optional(),
11
+ })),
8
12
  });
9
13
  /**
10
14
  * @hidden
@@ -43,5 +47,13 @@ export class MemoryRecorder extends Agent {
43
47
  inputSchema: memoryRecorderInputSchema,
44
48
  outputSchema: memoryRecorderOutputSchema,
45
49
  });
50
+ this._process = options.process;
51
+ }
52
+ _process;
53
+ process(input, options) {
54
+ if (!this._process) {
55
+ throw new Error("MemoryRecorder process function is not defined.");
56
+ }
57
+ return this._process(input, options);
46
58
  }
47
59
  }
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
- import { Agent, type AgentOptions, type Message } from "../agents/agent.js";
2
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type FunctionAgentFn, type Message } from "../agents/agent.js";
3
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
4
  import type { Memory } from "./memory.js";
4
5
  /**
5
6
  * Input for memory retrieval operations.
@@ -17,7 +18,7 @@ export interface MemoryRetrieverInput extends Message {
17
18
  * Search term to filter memories by.
18
19
  * How the search is implemented depends on the specific retriever implementation.
19
20
  */
20
- search?: string;
21
+ search?: string | Message;
21
22
  }
22
23
  /**
23
24
  * Output from memory retrieval operations.
@@ -37,13 +38,13 @@ export interface MemoryRetrieverOutput extends Message {
37
38
  */
38
39
  export declare const memoryRetrieverInputSchema: z.ZodObject<{
39
40
  limit: z.ZodOptional<z.ZodNumber>;
40
- search: z.ZodOptional<z.ZodString>;
41
+ search: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>]>>;
41
42
  }, "strip", z.ZodTypeAny, {
43
+ search?: string | Record<string, unknown> | undefined;
42
44
  limit?: number | undefined;
43
- search?: string | undefined;
44
45
  }, {
46
+ search?: string | Record<string, unknown> | undefined;
45
47
  limit?: number | undefined;
46
- search?: string | undefined;
47
48
  }>;
48
49
  /**
49
50
  * @hidden
@@ -75,6 +76,9 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
75
76
  createdAt: string;
76
77
  }[];
77
78
  }>;
79
+ export interface MemoryRetrieverOptions extends Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema"> {
80
+ process?: FunctionAgentFn<MemoryRetrieverInput, MemoryRetrieverOutput>;
81
+ }
78
82
  /**
79
83
  * Abstract base class for agents that retrieve memories from storage.
80
84
  *
@@ -89,12 +93,14 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
89
93
  * Custom implementations should extend this class and provide concrete
90
94
  * implementations of the process method to handle the actual retrieval logic.
91
95
  */
92
- export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
96
+ export declare class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
97
  tag: string;
94
98
  /**
95
99
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
96
100
  *
97
101
  * @param options - Configuration options for the memory retriever agent
98
102
  */
99
- constructor(options: Omit<AgentOptions<MemoryRetrieverInput, MemoryRetrieverOutput>, "inputSchema" | "outputSchema">);
103
+ constructor(options: MemoryRetrieverOptions);
104
+ private _process?;
105
+ process(input: MemoryRetrieverInput, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<MemoryRetrieverOutput>>;
100
106
  }
@@ -1,11 +1,11 @@
1
1
  import { z } from "zod";
2
- import { Agent } from "../agents/agent.js";
2
+ import { Agent, } from "../agents/agent.js";
3
3
  /**
4
4
  * @hidden
5
5
  */
6
6
  export const memoryRetrieverInputSchema = z.object({
7
7
  limit: z.number().optional(),
8
- search: z.string().optional(),
8
+ search: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
9
9
  });
10
10
  /**
11
11
  * @hidden
@@ -44,5 +44,13 @@ export class MemoryRetriever extends Agent {
44
44
  inputSchema: memoryRetrieverInputSchema,
45
45
  outputSchema: memoryRetrieverOutputSchema,
46
46
  });
47
+ this._process = options.process;
48
+ }
49
+ _process;
50
+ process(input, options) {
51
+ if (!this._process) {
52
+ throw new Error("MemoryRetriever process function is not implemented.");
53
+ }
54
+ return this._process(input, options);
47
55
  }
48
56
  }
@@ -15,6 +15,7 @@ export declare function isNotEmpty<T>(arr: T[]): arr is [T, ...T[]];
15
15
  export declare function duplicates<T>(arr: T[], key?: (item: T) => unknown): T[];
16
16
  export declare function remove<T>(arr: T[], remove: T[] | ((item: T) => boolean)): T[];
17
17
  export declare function unique<T>(arr: T[], key?: (item: T) => unknown): T[];
18
+ export declare function pick<T extends Record<string, unknown>, K extends keyof T | string>(obj: T, ...keys: (K | K[])[]): Pick<T, Extract<K, keyof T>> & Partial<Record<Exclude<K, keyof T>, unknown>>;
18
19
  export declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
19
20
  export declare function omitDeep<T, K>(obj: T, ...keys: (K | K[])[]): unknown;
20
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>;
@@ -58,6 +58,10 @@ export function unique(arr, key = (item) => item) {
58
58
  return true;
59
59
  });
60
60
  }
61
+ export function pick(obj, ...keys) {
62
+ const flattenedKeys = new Set(keys.flat());
63
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => flattenedKeys.has(key)));
64
+ }
61
65
  export function omit(obj, ...keys) {
62
66
  const flattenedKeys = new Set(keys.flat());
63
67
  return Object.fromEntries(Object.entries(obj).filter(([key]) => !flattenedKeys.has(key)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.22.0",
3
+ "version": "1.23.1",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -81,7 +81,7 @@
81
81
  "yaml": "^2.7.1",
82
82
  "zod": "^3.24.4",
83
83
  "zod-to-json-schema": "^3.24.5",
84
- "@aigne/observability": "^0.1.0",
84
+ "@aigne/observability": "^0.1.1",
85
85
  "@aigne/platform-helpers": "^0.1.2"
86
86
  },
87
87
  "devDependencies": {