@aigne/core 0.4.209 → 0.4.211-beta.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 (56) hide show
  1. package/lib/cjs/api-agent.js +70 -0
  2. package/lib/cjs/data-type-schema.js +46 -0
  3. package/lib/cjs/data-type.js +2 -0
  4. package/lib/cjs/definitions/api-parameter.js +10 -0
  5. package/lib/cjs/definitions/data-type-schema.js +3 -3
  6. package/lib/cjs/definitions/open-api.js +2 -0
  7. package/lib/cjs/index.js +3 -0
  8. package/lib/cjs/memory.js +32 -0
  9. package/lib/cjs/open-api-agent.js +62 -0
  10. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  11. package/lib/cjs/utils/constants.js +4 -0
  12. package/lib/cjs/utils/fetch-api.js +35 -0
  13. package/lib/cjs/utils/fetch-open-api.js +30 -0
  14. package/lib/cjs/utils/fetch.js +20 -0
  15. package/lib/cjs/utils/flatten-openapi.js +14 -0
  16. package/lib/cjs/utils/format-parameter.js +126 -0
  17. package/lib/cjs/utils/index.js +3 -0
  18. package/lib/cjs/utils/open-api-parameter.js +84 -0
  19. package/lib/esm/api-agent.js +67 -0
  20. package/lib/esm/data-type-schema.js +43 -0
  21. package/lib/esm/data-type.js +1 -0
  22. package/lib/esm/definitions/api-parameter.js +7 -0
  23. package/lib/esm/definitions/data-type-schema.js +1 -1
  24. package/lib/esm/definitions/open-api.js +1 -0
  25. package/lib/esm/index.js +3 -0
  26. package/lib/esm/memory.js +27 -0
  27. package/lib/esm/open-api-agent.js +59 -0
  28. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  29. package/lib/esm/utils/constants.js +1 -0
  30. package/lib/esm/utils/fetch-api.js +31 -0
  31. package/lib/esm/utils/fetch-open-api.js +26 -0
  32. package/lib/esm/utils/fetch.js +17 -0
  33. package/lib/esm/utils/flatten-openapi.js +11 -0
  34. package/lib/esm/utils/format-parameter.js +116 -0
  35. package/lib/esm/utils/index.js +3 -0
  36. package/lib/esm/utils/open-api-parameter.js +78 -0
  37. package/lib/types/api-agent.d.ts +53 -0
  38. package/lib/types/context.d.ts +1 -0
  39. package/lib/types/data-type-schema.d.ts +46 -0
  40. package/lib/types/data-type.d.ts +32 -0
  41. package/lib/types/definitions/api-parameter.d.ts +55 -0
  42. package/lib/types/definitions/data-type-schema.d.ts +1 -1
  43. package/lib/types/definitions/open-api.d.ts +36 -0
  44. package/lib/types/index.d.ts +3 -0
  45. package/lib/types/memory.d.ts +184 -0
  46. package/lib/types/open-api-agent.d.ts +55 -0
  47. package/lib/types/tsconfig.tsbuildinfo +1 -1
  48. package/lib/types/utils/constants.d.ts +1 -0
  49. package/lib/types/utils/fetch-api.d.ts +3 -0
  50. package/lib/types/utils/fetch-open-api.d.ts +2 -0
  51. package/lib/types/utils/fetch.d.ts +1 -0
  52. package/lib/types/utils/flatten-openapi.d.ts +25 -0
  53. package/lib/types/utils/format-parameter.d.ts +6 -0
  54. package/lib/types/utils/index.d.ts +3 -0
  55. package/lib/types/utils/open-api-parameter.d.ts +7 -0
  56. package/package.json +2 -20
@@ -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
+ }
@@ -0,0 +1,55 @@
1
+ import { Agent } from './agent';
2
+ import type { Context, ContextState } from './context';
3
+ import { DataTypeSchema, SchemaMapType } from './definitions/data-type-schema';
4
+ import { CreateRunnableMemory } from './definitions/memory';
5
+ import { AuthConfig, FetchRequest, HTTPMethod, OpenAPIDataType, OpenAPIDataTypeSchema } from './definitions/open-api';
6
+ import { MemorableSearchOutput, MemoryItemWithScore } from './memorable';
7
+ import { RunnableDefinition } from './runnable';
8
+ import { OrderedRecord } from './utils';
9
+ export declare class OpenAPIAgent<I extends {
10
+ [name: string]: any;
11
+ } = {}, O extends {
12
+ [name: string]: any;
13
+ } = {}, Memories extends {
14
+ [name: string]: MemoryItemWithScore[];
15
+ } = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
16
+ definition: OpenAPIAgentDefinition;
17
+ static create: typeof create;
18
+ constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
19
+ process(input: I): Promise<any>;
20
+ fetch(request: FetchRequest): Promise<any>;
21
+ }
22
+ export interface OpenAPIAgentDefinition extends RunnableDefinition {
23
+ type: 'open_api_agent';
24
+ inputs: OrderedRecord<OpenAPIDataType>;
25
+ url: string;
26
+ method?: HTTPMethod;
27
+ auth?: AuthConfig;
28
+ }
29
+ export interface CreateOpenAPIAgentOptions<I extends {
30
+ [name: string]: OpenAPIDataTypeSchema;
31
+ }, O extends {
32
+ [name: string]: DataTypeSchema;
33
+ }, Memories extends {
34
+ [name: string]: CreateRunnableMemory<I>;
35
+ }, State extends ContextState> {
36
+ context?: Context<State>;
37
+ id?: string;
38
+ name?: string;
39
+ inputs: I;
40
+ outputs: O;
41
+ memories?: Memories;
42
+ url: string;
43
+ method?: HTTPMethod;
44
+ auth?: AuthConfig;
45
+ }
46
+ declare function create<I extends {
47
+ [name: string]: OpenAPIDataTypeSchema;
48
+ }, O extends {
49
+ [name: string]: DataTypeSchema;
50
+ }, Memories extends {
51
+ [name: string]: CreateRunnableMemory<I>;
52
+ }, State extends ContextState>({ context, ...options }: CreateOpenAPIAgentOptions<I, O, Memories, State>): OpenAPIAgent<SchemaMapType<I>, SchemaMapType<O>, {
53
+ [name in keyof Memories]: MemorableSearchOutput<Memories[name]['memory']>;
54
+ }, State>;
55
+ export {};