@aigne/core 0.4.194 → 0.4.196

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 (66) hide show
  1. package/lib/cjs/constants.js +11 -0
  2. package/lib/cjs/function-agent.js +81 -0
  3. package/lib/cjs/function-runner.js +29 -0
  4. package/lib/cjs/index.js +13 -1
  5. package/lib/cjs/llm-agent.js +166 -0
  6. package/lib/cjs/llm-decision-agent.js +169 -0
  7. package/lib/cjs/llm-model.js +27 -0
  8. package/lib/cjs/local-function-agent.js +80 -0
  9. package/lib/cjs/memory.js +32 -0
  10. package/lib/cjs/pipeline-agent.js +199 -0
  11. package/lib/cjs/runnable.js +29 -0
  12. package/lib/cjs/tsconfig.tsbuildinfo +1 -0
  13. package/lib/cjs/{types → utils}/index.js +4 -2
  14. package/lib/cjs/utils/is-non-nullable.js +20 -0
  15. package/lib/cjs/utils/mustache-utils.js +14 -0
  16. package/lib/cjs/utils/omit.js +2 -0
  17. package/lib/cjs/utils/ordered-map.js +71 -0
  18. package/lib/cjs/utils/stream-utils.js +25 -0
  19. package/lib/esm/constants.js +8 -0
  20. package/lib/esm/function-agent.js +77 -0
  21. package/lib/esm/function-runner.js +25 -0
  22. package/lib/esm/index.js +13 -1
  23. package/lib/esm/llm-agent.js +162 -0
  24. package/lib/esm/llm-decision-agent.js +165 -0
  25. package/lib/esm/llm-model.js +23 -0
  26. package/lib/esm/local-function-agent.js +76 -0
  27. package/lib/esm/memory.js +27 -0
  28. package/lib/esm/pipeline-agent.js +192 -0
  29. package/lib/esm/runnable.js +23 -0
  30. package/lib/esm/tsconfig.tsbuildinfo +1 -0
  31. package/lib/esm/utils/index.js +4 -0
  32. package/lib/esm/utils/is-non-nullable.js +13 -0
  33. package/lib/esm/utils/mustache-utils.js +8 -0
  34. package/lib/esm/utils/omit.js +1 -0
  35. package/lib/esm/utils/ordered-map.js +68 -0
  36. package/lib/esm/utils/stream-utils.js +21 -0
  37. package/lib/types/constants.d.ts +8 -0
  38. package/lib/types/context.d.ts +5 -0
  39. package/lib/types/data-type.d.ts +32 -0
  40. package/lib/types/function-agent.d.ts +36 -0
  41. package/lib/types/function-runner.d.ts +11 -0
  42. package/lib/types/index.d.ts +13 -1
  43. package/lib/types/llm-agent.d.ts +37 -0
  44. package/lib/types/llm-decision-agent.d.ts +66 -0
  45. package/lib/types/llm-model.d.ts +79 -0
  46. package/lib/types/local-function-agent.d.ts +38 -0
  47. package/lib/types/memory.d.ts +186 -0
  48. package/lib/types/pipeline-agent.d.ts +69 -0
  49. package/lib/types/runnable.d.ts +49 -0
  50. package/lib/types/tsconfig.tsbuildinfo +1 -0
  51. package/lib/types/utils/index.d.ts +4 -0
  52. package/lib/types/utils/is-non-nullable.d.ts +2 -0
  53. package/lib/types/utils/mustache-utils.d.ts +3 -0
  54. package/lib/types/utils/omit.d.ts +1 -0
  55. package/lib/types/utils/ordered-map.d.ts +28 -0
  56. package/lib/types/utils/stream-utils.d.ts +7 -0
  57. package/package.json +6 -4
  58. package/tsconfig.json +3 -7
  59. package/lib/esm/types/index.js +0 -2
  60. package/lib/types/types/agent.d.ts +0 -5
  61. package/lib/types/types/index.d.ts +0 -2
  62. package/lib/types/types/runnable.d.ts +0 -20
  63. /package/lib/cjs/{types/agent.js → context.js} +0 -0
  64. /package/lib/cjs/{types/runnable.js → data-type.js} +0 -0
  65. /package/lib/esm/{types/agent.js → context.js} +0 -0
  66. /package/lib/esm/{types/runnable.js → data-type.js} +0 -0
@@ -0,0 +1,4 @@
1
+ export * from './ordered-map';
2
+ export * from './is-non-nullable';
3
+ export * from './stream-utils';
4
+ export * from './mustache-utils';
@@ -0,0 +1,13 @@
1
+ import isNil from 'lodash/isNil';
2
+ export function isNonNullable(value) {
3
+ return !isNil(value);
4
+ }
5
+ export function isPropsNonNullable(...props) {
6
+ return (value) => {
7
+ for (const prop of props.flat()) {
8
+ if (isNil(value?.[prop]))
9
+ return false;
10
+ }
11
+ return true;
12
+ };
13
+ }
@@ -0,0 +1,8 @@
1
+ import Mustache from 'mustache';
2
+ export function renderMessage(template, variables) {
3
+ return Mustache.render(template, variables, undefined, {
4
+ escape: (v) => {
5
+ return typeof v === 'object' ? JSON.stringify(v) : v;
6
+ },
7
+ });
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,68 @@
1
+ export var OrderedRecord;
2
+ (function (OrderedRecord) {
3
+ function iterator(record) {
4
+ return (function* () {
5
+ if (!record)
6
+ return;
7
+ for (const id of record.$indexes) {
8
+ yield record[id];
9
+ }
10
+ })();
11
+ }
12
+ OrderedRecord.iterator = iterator;
13
+ function map(record, fn) {
14
+ if (!record)
15
+ return [];
16
+ const result = new Array(record.$indexes.length);
17
+ for (let i = 0; i < record.$indexes.length; i++) {
18
+ result[i] = fn(record[record.$indexes[i]], i);
19
+ }
20
+ return result;
21
+ }
22
+ OrderedRecord.map = map;
23
+ function toArray(record) {
24
+ return OrderedRecord.map(record, (value) => value);
25
+ }
26
+ OrderedRecord.toArray = toArray;
27
+ function fromArray(array) {
28
+ const record = { $indexes: [] };
29
+ for (const value of array ?? []) {
30
+ record[value.id] = value;
31
+ record.$indexes.push(value.id);
32
+ }
33
+ return record;
34
+ }
35
+ OrderedRecord.fromArray = fromArray;
36
+ function find(record, predicate) {
37
+ if (!record)
38
+ return undefined;
39
+ for (let i = 0; i < record.$indexes.length; i++) {
40
+ const id = record.$indexes[i];
41
+ const value = record[id];
42
+ if (predicate(value, i))
43
+ return value;
44
+ }
45
+ return undefined;
46
+ }
47
+ OrderedRecord.find = find;
48
+ function push(record, ...items) {
49
+ for (const item of items) {
50
+ if (record[item.id])
51
+ throw new Error(`Item with id ${item.id} already exists`);
52
+ record.$indexes.push(item.id);
53
+ record[item.id] = item;
54
+ }
55
+ return record;
56
+ }
57
+ OrderedRecord.push = push;
58
+ function pushOrUpdate(record, ...items) {
59
+ for (const item of items) {
60
+ if (!record[item.id]) {
61
+ record.$indexes.push(item.id);
62
+ }
63
+ record[item.id] = item;
64
+ }
65
+ return record;
66
+ }
67
+ OrderedRecord.pushOrUpdate = pushOrUpdate;
68
+ })(OrderedRecord || (OrderedRecord = {}));
@@ -0,0 +1,21 @@
1
+ import { isRunnableResponseDelta } from '../runnable';
2
+ export function objectToRunnableResponseStream(obj) {
3
+ return new ReadableStream({
4
+ start(controller) {
5
+ controller.enqueue({ delta: obj });
6
+ controller.close();
7
+ },
8
+ });
9
+ }
10
+ export async function runnableResponseStreamToObject(stream) {
11
+ let $text = '';
12
+ const lastValue = {};
13
+ for await (const value of stream) {
14
+ if (isRunnableResponseDelta(value)) {
15
+ $text += value.$text || '';
16
+ Object.assign(lastValue, value.delta);
17
+ }
18
+ }
19
+ Object.assign(lastValue, { $text: lastValue.$text || $text || undefined });
20
+ return lastValue;
21
+ }
@@ -0,0 +1,8 @@
1
+ export declare const TYPES: {
2
+ context: symbol;
3
+ definition: symbol;
4
+ llmModel: symbol;
5
+ llmModelConfiguration: symbol;
6
+ functionRunner: symbol;
7
+ };
8
+ export declare const StreamTextOutputName = "$text";
@@ -0,0 +1,5 @@
1
+ import { Runnable, RunnableDefinition } from './runnable';
2
+ export interface Context<State = {}> {
3
+ state: State;
4
+ resolve<T extends Runnable>(id: string | RunnableDefinition): Promise<T>;
5
+ }
@@ -0,0 +1,32 @@
1
+ import { OmitPropsFromUnion } from './utils/omit';
2
+ import { OrderedRecord } from './utils/ordered-map';
3
+ export type DataType = DataTypeString | DataTypeNumber | DataTypeBoolean | DataTypeObject | DataTypeArray;
4
+ export interface DataTypeBase {
5
+ id: string;
6
+ name?: string;
7
+ description?: string;
8
+ required?: boolean;
9
+ }
10
+ export interface DataTypeString extends DataTypeBase {
11
+ type: 'string';
12
+ defaultValue?: string;
13
+ multiline?: boolean;
14
+ }
15
+ export interface DataTypeNumber extends DataTypeBase {
16
+ type: 'number';
17
+ defaultValue?: number;
18
+ }
19
+ export interface DataTypeBoolean extends DataTypeBase {
20
+ type: 'boolean';
21
+ defaultValue?: boolean;
22
+ }
23
+ export interface DataTypeObject extends DataTypeBase {
24
+ type: 'object';
25
+ defaultValue?: object;
26
+ properties?: OrderedRecord<DataType>;
27
+ }
28
+ export interface DataTypeArray extends DataTypeBase {
29
+ type: 'array';
30
+ defaultValue?: object[];
31
+ items?: OmitPropsFromUnion<DataType, 'id'>;
32
+ }
@@ -0,0 +1,36 @@
1
+ import { DataType } from './data-type';
2
+ import { FunctionRunner } from './function-runner';
3
+ import { RunOptions, Runnable, RunnableDefinition, RunnableResponseStream } from './runnable';
4
+ export declare class FunctionAgent<I extends {} = {}, O extends {} = {}> extends Runnable<I, O> {
5
+ definition: FunctionAgentDefinition;
6
+ runner?: FunctionRunner | undefined;
7
+ static create<I extends {} = {}, O extends {} = {}>(options: Parameters<typeof createFunctionAgentDefinition>[0]): FunctionAgent<I, O>;
8
+ constructor(definition: FunctionAgentDefinition, runner?: FunctionRunner | undefined);
9
+ run(input: I, options: RunOptions & {
10
+ stream: true;
11
+ }): Promise<RunnableResponseStream<O>>;
12
+ run(input: I, options?: RunOptions & {
13
+ stream?: false;
14
+ }): Promise<O>;
15
+ }
16
+ export declare function createFunctionAgentDefinition(options: {
17
+ id?: string;
18
+ name?: string;
19
+ inputs?: {
20
+ name: string;
21
+ type: DataType['type'];
22
+ required?: boolean;
23
+ }[];
24
+ outputs?: {
25
+ name: string;
26
+ type: DataType['type'];
27
+ required?: boolean;
28
+ }[];
29
+ language: string;
30
+ code: string;
31
+ }): FunctionAgentDefinition;
32
+ export interface FunctionAgentDefinition extends RunnableDefinition {
33
+ type: 'function_agent';
34
+ language?: string;
35
+ code?: string;
36
+ }
@@ -0,0 +1,11 @@
1
+ import { Runnable } from './runnable';
2
+ export interface FunctionRunnerInputs {
3
+ name: string;
4
+ language: string;
5
+ code: string;
6
+ arguments?: object;
7
+ }
8
+ export type FunctionRunnerOutputs = object;
9
+ export declare abstract class FunctionRunner extends Runnable<FunctionRunnerInputs, FunctionRunnerOutputs> {
10
+ constructor();
11
+ }
@@ -1 +1,13 @@
1
- export * from './types';
1
+ export * from './utils';
2
+ export * from './constants';
3
+ export * from './data-type';
4
+ export * from './context';
5
+ export * from './runnable';
6
+ export * from './pipeline-agent';
7
+ export * from './llm-agent';
8
+ export * from './llm-model';
9
+ export * from './function-agent';
10
+ export * from './function-runner';
11
+ export * from './llm-decision-agent';
12
+ export * from './local-function-agent';
13
+ export * from './memory';
@@ -0,0 +1,37 @@
1
+ import { DataType } from './data-type';
2
+ import { LLMModel, LLMModelInputs, Role } from './llm-model';
3
+ import { RunOptions, Runnable, RunnableDefinition, RunnableResponseStream } from './runnable';
4
+ import { OmitPropsFromUnion } from './utils/omit';
5
+ import { OrderedRecord } from './utils/ordered-map';
6
+ export declare class LLMAgent<I extends {} = {}, O extends {} = {}> extends Runnable<I, O> {
7
+ definition: LLMAgentDefinition;
8
+ model?: LLMModel | undefined;
9
+ static create<I extends {} = {}, O extends {} = {}>(options: Parameters<typeof createLLMAgentDefinition>[0]): LLMAgent<I, O>;
10
+ constructor(definition: LLMAgentDefinition, model?: LLMModel | undefined);
11
+ run(input: I, options: RunOptions & {
12
+ stream: true;
13
+ }): Promise<RunnableResponseStream<O>>;
14
+ run(input: I, options?: RunOptions & {
15
+ stream?: false;
16
+ }): Promise<O>;
17
+ }
18
+ export declare function createLLMAgentDefinition(options: {
19
+ id?: string;
20
+ name?: string;
21
+ messages?: {
22
+ role: Role;
23
+ content: string;
24
+ }[];
25
+ modelOptions?: LLMModelInputs['modelOptions'];
26
+ inputs?: OmitPropsFromUnion<DataType, 'id'>[];
27
+ outputs?: OmitPropsFromUnion<DataType, 'id'>[];
28
+ }): LLMAgentDefinition;
29
+ export interface LLMAgentDefinition extends RunnableDefinition {
30
+ type: 'llm_agent';
31
+ messages?: OrderedRecord<{
32
+ id: string;
33
+ role: Role;
34
+ content: string;
35
+ }>;
36
+ modelOptions?: LLMModelInputs['modelOptions'];
37
+ }
@@ -0,0 +1,66 @@
1
+ import type { Context } from './context';
2
+ import { DataType } from './data-type';
3
+ import { LLMModel, LLMModelInputMessage, LLMModelInputs, LLMModelOptions } from './llm-model';
4
+ import { RunOptions, Runnable, RunnableDefinition, RunnableResponseStream } from './runnable';
5
+ import { OrderedRecord } from './utils';
6
+ export declare class LLMDecisionAgent<I extends {
7
+ [key: string]: any;
8
+ } = {}, O extends {} = {}> extends Runnable<I, O> {
9
+ definition: LLMDecisionAgentDefinition;
10
+ model?: LLMModel | undefined;
11
+ context?: Context | undefined;
12
+ static create<I extends {} = {}, O extends {} = {}>(options: Parameters<typeof createLLMDecisionAgentDefinition>[0]): LLMDecisionAgent<I, O>;
13
+ constructor(definition: LLMDecisionAgentDefinition, model?: LLMModel | undefined, context?: Context | undefined);
14
+ run(input: I, options: RunOptions & {
15
+ stream: true;
16
+ }): Promise<RunnableResponseStream<O>>;
17
+ run(input: I, options?: RunOptions & {
18
+ stream?: false;
19
+ }): Promise<O>;
20
+ }
21
+ export interface DecisionAgentCaseParameter<I extends {} = {}, O extends {} = {}, R = Runnable<I, O>> {
22
+ name?: string;
23
+ description?: string;
24
+ runnable: R;
25
+ input?: {
26
+ [key: string]: {
27
+ fromVariable: string;
28
+ fromVariablePropPath?: string[];
29
+ } | undefined;
30
+ };
31
+ }
32
+ export declare function createLLMDecisionAgentDefinition(options: {
33
+ id?: string;
34
+ name?: string;
35
+ inputs?: {
36
+ name: string;
37
+ type: DataType['type'];
38
+ required?: boolean;
39
+ }[];
40
+ messages: string;
41
+ modelOptions?: LLMModelOptions;
42
+ cases: DecisionAgentCaseParameter[];
43
+ }): LLMDecisionAgentDefinition;
44
+ export interface LLMDecisionAgentDefinition extends RunnableDefinition {
45
+ type: 'llm_decision_agent';
46
+ messages?: OrderedRecord<LLMModelInputMessage & {
47
+ id: string;
48
+ }>;
49
+ modelOptions?: LLMModelInputs['modelOptions'];
50
+ cases?: OrderedRecord<LLMDecisionCase>;
51
+ }
52
+ export interface LLMDecisionCase {
53
+ id: string;
54
+ name?: string;
55
+ description?: string;
56
+ runnable?: {
57
+ id?: string;
58
+ };
59
+ input?: {
60
+ [inputId: string]: {
61
+ from: 'variable';
62
+ fromVariableId?: string;
63
+ fromVariablePropPath?: (string | number)[];
64
+ };
65
+ };
66
+ }
@@ -0,0 +1,79 @@
1
+ import { Runnable } from './runnable';
2
+ export type Role = 'system' | 'user' | 'assistant' | 'tool';
3
+ export interface LLMModelInputs {
4
+ messages: LLMModelInputMessage[];
5
+ responseFormat?: {
6
+ type: 'text';
7
+ } | {
8
+ type: 'json_schema';
9
+ jsonSchema: {
10
+ name: string;
11
+ description?: string;
12
+ schema: object;
13
+ strict?: boolean;
14
+ };
15
+ };
16
+ tools?: LLMModelInputTool[];
17
+ toolChoice?: 'auto' | 'none' | 'required' | {
18
+ type: 'function';
19
+ function: {
20
+ name: string;
21
+ description?: string;
22
+ };
23
+ };
24
+ modelOptions?: LLMModelOptions;
25
+ }
26
+ export interface LLMModelInputMessage {
27
+ role: Role;
28
+ content: string | ({
29
+ type: 'text';
30
+ text: string;
31
+ } | {
32
+ type: 'image_url';
33
+ imageUrl: {
34
+ url: string;
35
+ };
36
+ })[];
37
+ toolCalls?: {
38
+ id: string;
39
+ type: 'function';
40
+ function: {
41
+ name: string;
42
+ arguments: string;
43
+ };
44
+ }[];
45
+ toolCallId?: string;
46
+ }
47
+ export interface LLMModelInputTool {
48
+ type: 'function';
49
+ function: {
50
+ name: string;
51
+ description?: string;
52
+ parameters: object;
53
+ };
54
+ }
55
+ export interface LLMModelOptions {
56
+ model?: string;
57
+ temperature?: number;
58
+ topP?: number;
59
+ frequencyPenalty?: number;
60
+ presencePenalty?: number;
61
+ }
62
+ export interface LLMModelOutputs {
63
+ $text?: string | null;
64
+ toolCalls?: {
65
+ id?: string;
66
+ type?: 'function';
67
+ function?: {
68
+ name?: string;
69
+ arguments?: string;
70
+ };
71
+ }[];
72
+ }
73
+ export declare abstract class LLMModel extends Runnable<LLMModelInputs, LLMModelOutputs> {
74
+ constructor();
75
+ }
76
+ export interface LLMModelConfiguration {
77
+ default?: Partial<LLMModelOptions>;
78
+ override?: Partial<LLMModelOptions>;
79
+ }
@@ -0,0 +1,38 @@
1
+ import type { Context } from './context';
2
+ import { DataType } from './data-type';
3
+ import { RunOptions, Runnable, RunnableDefinition, RunnableResponse, RunnableResponseStream } from './runnable';
4
+ export declare class LocalFunctionAgent<I extends {} = {}, O extends {} = {}, State = {}> extends Runnable<I, O> {
5
+ definition: LocalFunctionAgentDefinition<I, O, State>;
6
+ context?: Context<State> | undefined;
7
+ static create<I extends {} = {}, O extends {} = {}, State = {}>(options: Parameters<typeof createLocalFunctionAgentDefinition<I, O, State>>[0]): LocalFunctionAgent<I, O, State>;
8
+ constructor(definition: LocalFunctionAgentDefinition<I, O, State>, context?: Context<State> | undefined);
9
+ run(input: I, options: RunOptions & {
10
+ stream: true;
11
+ }): Promise<RunnableResponseStream<O>>;
12
+ run(input: I, options?: RunOptions & {
13
+ stream?: false;
14
+ }): Promise<O>;
15
+ }
16
+ export declare function createLocalFunctionAgentDefinition<I extends {} = {}, O extends {} = {}, State = {}>(options: {
17
+ id?: string;
18
+ name?: string;
19
+ inputs?: {
20
+ name: string;
21
+ type: DataType['type'];
22
+ required?: boolean;
23
+ }[];
24
+ outputs?: {
25
+ name: string;
26
+ type: DataType['type'];
27
+ required?: boolean;
28
+ }[];
29
+ function?: (input: I, options: {
30
+ context: Context<State>;
31
+ }) => Promise<RunnableResponse<O>>;
32
+ }): LocalFunctionAgentDefinition<I, O, State>;
33
+ export interface LocalFunctionAgentDefinition<I extends {} = {}, O extends {} = {}, State = {}> extends RunnableDefinition {
34
+ type: 'local_function_agent';
35
+ function?: (input: I, options: {
36
+ context: Context<State>;
37
+ }) => Promise<RunnableResponse<O>>;
38
+ }
@@ -0,0 +1,186 @@
1
+ import { Runnable } from './runnable';
2
+ export interface MemoryMetadata {
3
+ [key: string]: any;
4
+ }
5
+ export type MemoryActionItem<T> = {
6
+ event: 'add';
7
+ id: string;
8
+ memory: T;
9
+ metadata?: MemoryMetadata;
10
+ } | {
11
+ event: 'update';
12
+ id: string;
13
+ memory: T;
14
+ oldMemory: T;
15
+ metadata?: MemoryMetadata;
16
+ } | {
17
+ event: 'delete';
18
+ id: string;
19
+ memory: T;
20
+ } | {
21
+ event: 'none';
22
+ memory: T;
23
+ };
24
+ export interface MemoryItem<T> {
25
+ id: string;
26
+ userId?: string;
27
+ sessionId?: string;
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ memory: T;
31
+ metadata: MemoryMetadata;
32
+ }
33
+ export interface MemoryItemWithScore<T> extends MemoryItem<T> {
34
+ score: number;
35
+ }
36
+ export interface MemoryMessage {
37
+ role: string;
38
+ content: string;
39
+ }
40
+ export type MemoryActions<T> = {
41
+ action: 'add';
42
+ inputs: {
43
+ messages: MemoryMessage[];
44
+ options?: {
45
+ userId?: string;
46
+ sessionId?: string;
47
+ metadata?: MemoryMetadata;
48
+ };
49
+ };
50
+ outputs: {
51
+ results: MemoryActionItem<T>[];
52
+ };
53
+ } | {
54
+ action: 'search';
55
+ inputs: {
56
+ query: string;
57
+ options?: {
58
+ k?: number;
59
+ userId?: string;
60
+ sessionId?: string;
61
+ filter?: MemoryMetadata;
62
+ sort?: MemorySortOptions;
63
+ };
64
+ };
65
+ outputs: {
66
+ results: MemoryItemWithScore<T>[];
67
+ };
68
+ } | {
69
+ action: 'filter';
70
+ inputs: {
71
+ options?: {
72
+ k?: number;
73
+ userId?: string;
74
+ sessionId?: string;
75
+ filter?: MemoryMetadata;
76
+ sort?: MemorySortOptions;
77
+ };
78
+ };
79
+ outputs: {
80
+ results: MemoryItem<T>[];
81
+ };
82
+ } | {
83
+ action: 'get';
84
+ inputs: {
85
+ memoryId: string;
86
+ };
87
+ outputs: {
88
+ result: MemoryItem<T> | null;
89
+ };
90
+ } | {
91
+ action: 'create';
92
+ inputs: {
93
+ memory: T;
94
+ options?: {
95
+ userId?: string;
96
+ sessionId?: string;
97
+ metadata?: MemoryMetadata;
98
+ };
99
+ };
100
+ outputs: {
101
+ result: MemoryItem<T>;
102
+ };
103
+ } | {
104
+ action: 'update';
105
+ inputs: {
106
+ memoryId: string;
107
+ memory: T;
108
+ };
109
+ outputs: {
110
+ result: MemoryItem<T> | null;
111
+ };
112
+ } | {
113
+ action: 'delete';
114
+ inputs: {
115
+ memoryId: string;
116
+ };
117
+ outputs: {
118
+ result: MemoryItem<T> | null;
119
+ };
120
+ } | {
121
+ action: 'reset';
122
+ inputs: {};
123
+ outputs: {};
124
+ };
125
+ export interface SortItem {
126
+ field: string;
127
+ direction: 'asc' | 'desc';
128
+ }
129
+ export type MemorySortOptions = SortItem | SortItem[];
130
+ export declare abstract class Memory<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>['outputs']> {
131
+ constructor();
132
+ abstract runner?: MemoryRunner<T, C>;
133
+ abstract add(messages: Extract<MemoryActions<T>, {
134
+ action: 'add';
135
+ }>['inputs']['messages'], options?: Extract<MemoryActions<T>, {
136
+ action: 'add';
137
+ }>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
138
+ action: 'add';
139
+ }>['outputs']>;
140
+ abstract search(query: Extract<MemoryActions<T>, {
141
+ action: 'search';
142
+ }>['inputs']['query'], options?: Extract<MemoryActions<T>, {
143
+ action: 'search';
144
+ }>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
145
+ action: 'search';
146
+ }>['outputs']>;
147
+ abstract filter(options: Extract<MemoryActions<T>, {
148
+ action: 'filter';
149
+ }>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
150
+ action: 'filter';
151
+ }>['outputs']>;
152
+ abstract get(memoryId: Extract<MemoryActions<T>, {
153
+ action: 'get';
154
+ }>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
155
+ action: 'get';
156
+ }>['outputs']>;
157
+ abstract create(memory: Extract<MemoryActions<T>, {
158
+ action: 'create';
159
+ }>['inputs']['memory'], options?: Extract<MemoryActions<T>, {
160
+ action: 'create';
161
+ }>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
162
+ action: 'create';
163
+ }>['outputs']>;
164
+ abstract update(memoryId: Extract<MemoryActions<T>, {
165
+ action: 'update';
166
+ }>['inputs']['memoryId'], memory: T): Promise<Extract<MemoryActions<T>, {
167
+ action: 'update';
168
+ }>['outputs']>;
169
+ abstract delete(memoryId: Extract<MemoryActions<T>, {
170
+ action: 'delete';
171
+ }>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
172
+ action: 'delete';
173
+ }>['outputs']>;
174
+ abstract reset(): Promise<void>;
175
+ }
176
+ export interface MemoryRunnerInput<C = undefined> {
177
+ messages: MemoryMessage[];
178
+ userId?: string;
179
+ sessionId?: string;
180
+ metadata?: MemoryMetadata;
181
+ filter?: MemoryMetadata;
182
+ customData: C;
183
+ }
184
+ export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
185
+ constructor(name: string);
186
+ }