@aigne/core 0.4.207 → 0.4.208-beta.2
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/lib/cjs/constants.js +0 -1
- package/lib/cjs/data-type-schema.js +46 -0
- package/lib/cjs/data-type.js +2 -0
- package/lib/cjs/llm-decision-agent.js +1 -1
- package/lib/cjs/memory.js +32 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/constants.js +0 -1
- package/lib/esm/data-type-schema.js +43 -0
- package/lib/esm/data-type.js +1 -0
- package/lib/esm/llm-decision-agent.js +1 -1
- package/lib/esm/memory.js +27 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/constants.d.ts +0 -1
- package/lib/types/context.d.ts +6 -1
- package/lib/types/data-type-schema.d.ts +46 -0
- package/lib/types/data-type.d.ts +32 -0
- package/lib/types/memory.d.ts +184 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/types/constants.d.ts
CHANGED
package/lib/types/context.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { LLMModelConfiguration } from './llm-model';
|
|
1
2
|
import { Runnable, RunnableDefinition } from './runnable';
|
|
2
3
|
export interface ContextState {
|
|
3
4
|
userId?: string;
|
|
4
5
|
sessionId?: string;
|
|
5
6
|
}
|
|
6
|
-
export interface
|
|
7
|
+
export interface ContextConfig {
|
|
8
|
+
llmModel?: LLMModelConfiguration;
|
|
9
|
+
}
|
|
10
|
+
export interface Context<State extends ContextState = ContextState, Config extends ContextConfig = ContextConfig> {
|
|
7
11
|
state: State;
|
|
12
|
+
config: Config;
|
|
8
13
|
resolve<T extends Runnable>(id: string | RunnableDefinition): Promise<T>;
|
|
9
14
|
register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
|
|
10
15
|
resolveDependency<T>(token: string | symbol): T;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DataType } from './data-type';
|
|
2
|
+
import { OrderedRecord } from './utils';
|
|
3
|
+
export declare function schemaToDataType(dataType: {
|
|
4
|
+
[name: string]: DataTypeSchema;
|
|
5
|
+
}): OrderedRecord<DataType>;
|
|
6
|
+
export type DataTypeSchema = DataTypeSchemaString | DataTypeSchemaNumber | DataTypeSchemaBoolean | DataTypeSchemaObject | DataTypeSchemaArray;
|
|
7
|
+
export interface DataTypeSchemaBase {
|
|
8
|
+
description?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface DataTypeSchemaString extends DataTypeSchemaBase {
|
|
12
|
+
type: 'string';
|
|
13
|
+
}
|
|
14
|
+
export interface DataTypeSchemaNumber extends DataTypeSchemaBase {
|
|
15
|
+
type: 'number';
|
|
16
|
+
}
|
|
17
|
+
export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
|
|
18
|
+
type: 'boolean';
|
|
19
|
+
}
|
|
20
|
+
export interface DataTypeSchemaObject extends DataTypeSchemaBase {
|
|
21
|
+
type: 'object';
|
|
22
|
+
properties: {
|
|
23
|
+
[key: string]: DataTypeSchema;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface DataTypeSchemaArray extends DataTypeSchemaBase {
|
|
27
|
+
type: 'array';
|
|
28
|
+
items: DataTypeSchema;
|
|
29
|
+
}
|
|
30
|
+
type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
|
|
31
|
+
[K in keyof T['properties']]: SchemaType<T['properties'][K]>;
|
|
32
|
+
}> : T extends DataTypeSchemaArray ? SchemaType<T['items']>[] : never;
|
|
33
|
+
export type SchemaType<T extends DataTypeSchema> = T['required'] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
|
|
34
|
+
export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
|
|
35
|
+
type: 'object';
|
|
36
|
+
required: true;
|
|
37
|
+
properties: T;
|
|
38
|
+
}>;
|
|
39
|
+
type MakeNullablePropertyOptional<T extends {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}> = {
|
|
42
|
+
[K in keyof T as Extract<T[K], null | undefined> extends never ? K : never]: T[K];
|
|
43
|
+
} & {
|
|
44
|
+
[K in keyof T as Extract<T[K], null | undefined> extends never ? never : K]?: T[K];
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -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,184 @@
|
|
|
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
|
+
filter: string | string[] | Record<string, any>;
|
|
116
|
+
};
|
|
117
|
+
outputs: {};
|
|
118
|
+
} | {
|
|
119
|
+
action: 'reset';
|
|
120
|
+
inputs: {};
|
|
121
|
+
outputs: {};
|
|
122
|
+
};
|
|
123
|
+
export interface SortItem {
|
|
124
|
+
field: string;
|
|
125
|
+
direction: 'asc' | 'desc';
|
|
126
|
+
}
|
|
127
|
+
export type MemorySortOptions = SortItem | SortItem[];
|
|
128
|
+
export declare abstract class Memory<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>['outputs']> {
|
|
129
|
+
constructor();
|
|
130
|
+
abstract runner?: MemoryRunner<T, C>;
|
|
131
|
+
abstract add(messages: Extract<MemoryActions<T>, {
|
|
132
|
+
action: 'add';
|
|
133
|
+
}>['inputs']['messages'], options?: Extract<MemoryActions<T>, {
|
|
134
|
+
action: 'add';
|
|
135
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
136
|
+
action: 'add';
|
|
137
|
+
}>['outputs']>;
|
|
138
|
+
abstract search(query: Extract<MemoryActions<T>, {
|
|
139
|
+
action: 'search';
|
|
140
|
+
}>['inputs']['query'], options?: Extract<MemoryActions<T>, {
|
|
141
|
+
action: 'search';
|
|
142
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
143
|
+
action: 'search';
|
|
144
|
+
}>['outputs']>;
|
|
145
|
+
abstract filter(options: Extract<MemoryActions<T>, {
|
|
146
|
+
action: 'filter';
|
|
147
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
148
|
+
action: 'filter';
|
|
149
|
+
}>['outputs']>;
|
|
150
|
+
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
151
|
+
action: 'get';
|
|
152
|
+
}>['inputs']['memoryId']): Promise<Extract<MemoryActions<T>, {
|
|
153
|
+
action: 'get';
|
|
154
|
+
}>['outputs']>;
|
|
155
|
+
abstract create(memory: Extract<MemoryActions<T>, {
|
|
156
|
+
action: 'create';
|
|
157
|
+
}>['inputs']['memory'], options?: Extract<MemoryActions<T>, {
|
|
158
|
+
action: 'create';
|
|
159
|
+
}>['inputs']['options']): Promise<Extract<MemoryActions<T>, {
|
|
160
|
+
action: 'create';
|
|
161
|
+
}>['outputs']>;
|
|
162
|
+
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
163
|
+
action: 'update';
|
|
164
|
+
}>['inputs']['memoryId'], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
165
|
+
action: 'update';
|
|
166
|
+
}>['outputs']>;
|
|
167
|
+
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
168
|
+
action: 'delete';
|
|
169
|
+
}>['inputs']['filter']): Promise<Extract<MemoryActions<T>, {
|
|
170
|
+
action: 'delete';
|
|
171
|
+
}>['outputs']>;
|
|
172
|
+
abstract reset(): Promise<void>;
|
|
173
|
+
}
|
|
174
|
+
export interface MemoryRunnerInput<C = undefined> {
|
|
175
|
+
messages: MemoryMessage[];
|
|
176
|
+
userId?: string;
|
|
177
|
+
sessionId?: string;
|
|
178
|
+
metadata?: MemoryMetadata;
|
|
179
|
+
filter?: MemoryMetadata;
|
|
180
|
+
customData: C;
|
|
181
|
+
}
|
|
182
|
+
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
|
|
183
|
+
constructor(name: string);
|
|
184
|
+
}
|