@aigne/core 1.0.1 → 1.0.2-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/dts/agent.d.ts +41 -0
- package/lib/dts/constants.d.ts +7 -0
- package/lib/dts/context.d.ts +17 -0
- package/lib/dts/definitions/data-type-schema.d.ts +42 -0
- package/lib/dts/definitions/data-type.d.ts +32 -0
- package/lib/dts/definitions/memory.d.ts +40 -0
- package/lib/dts/definitions/open-api.d.ts +36 -0
- package/lib/dts/function-agent.d.ts +49 -0
- package/lib/dts/function-runner.d.ts +25 -0
- package/lib/dts/index.d.ts +18 -0
- package/lib/dts/llm-agent.d.ts +96 -0
- package/lib/dts/llm-decision-agent.d.ts +73 -0
- package/lib/dts/llm-model.d.ts +80 -0
- package/lib/dts/local-function-agent.d.ts +64 -0
- package/lib/dts/logger.d.ts +2 -0
- package/lib/dts/memorable.d.ts +183 -0
- package/lib/dts/open-api-agent.d.ts +55 -0
- package/lib/dts/pipeline-agent.d.ts +79 -0
- package/lib/dts/runnable.d.ts +70 -0
- package/lib/dts/utils/constants.d.ts +1 -0
- package/lib/dts/utils/fetch-open-api.d.ts +2 -0
- package/lib/dts/utils/fetch.d.ts +1 -0
- package/lib/dts/utils/index.d.ts +10 -0
- package/lib/dts/utils/is-non-nullable.d.ts +2 -0
- package/lib/dts/utils/message-utils.d.ts +20 -0
- package/lib/dts/utils/mustache-utils.d.ts +3 -0
- package/lib/dts/utils/nullable.d.ts +7 -0
- package/lib/dts/utils/omit.d.ts +1 -0
- package/lib/dts/utils/open-api-parameter.d.ts +7 -0
- package/lib/dts/utils/ordered-map.d.ts +37 -0
- package/lib/dts/utils/runnable-type.d.ts +3 -0
- package/lib/dts/utils/stream-utils.d.ts +20 -0
- package/lib/dts/utils/structured-output-schema.d.ts +3 -0
- package/lib/dts/utils/union.d.ts +1 -0
- package/lib/esm/agent.d.ts +41 -0
- package/lib/esm/constants.d.ts +7 -0
- package/lib/esm/context.d.ts +17 -0
- package/lib/esm/definitions/data-type-schema.d.ts +42 -0
- package/lib/esm/definitions/data-type.d.ts +32 -0
- package/lib/esm/definitions/memory.d.ts +40 -0
- package/lib/esm/definitions/open-api.d.ts +36 -0
- package/lib/esm/function-agent.d.ts +49 -0
- package/lib/esm/function-runner.d.ts +25 -0
- package/lib/esm/index.d.ts +18 -0
- package/lib/esm/llm-agent.d.ts +96 -0
- package/lib/esm/llm-decision-agent.d.ts +73 -0
- package/lib/esm/llm-model.d.ts +80 -0
- package/lib/esm/local-function-agent.d.ts +64 -0
- package/lib/esm/logger.d.ts +2 -0
- package/lib/esm/memorable.d.ts +183 -0
- package/lib/esm/open-api-agent.d.ts +55 -0
- package/lib/esm/pipeline-agent.d.ts +79 -0
- package/lib/esm/runnable.d.ts +70 -0
- package/lib/esm/utils/constants.d.ts +1 -0
- package/lib/esm/utils/fetch-open-api.d.ts +2 -0
- package/lib/esm/utils/fetch.d.ts +1 -0
- package/lib/esm/utils/index.d.ts +10 -0
- package/lib/esm/utils/is-non-nullable.d.ts +2 -0
- package/lib/esm/utils/message-utils.d.ts +20 -0
- package/lib/esm/utils/mustache-utils.d.ts +3 -0
- package/lib/esm/utils/nullable.d.ts +7 -0
- package/lib/esm/utils/omit.d.ts +1 -0
- package/lib/esm/utils/open-api-parameter.d.ts +7 -0
- package/lib/esm/utils/ordered-map.d.ts +37 -0
- package/lib/esm/utils/runnable-type.d.ts +3 -0
- package/lib/esm/utils/stream-utils.d.ts +20 -0
- package/lib/esm/utils/structured-output-schema.d.ts +3 -0
- package/lib/esm/utils/union.d.ts +1 -0
- package/lib/tsconfig.build.cjs.tsbuildinfo +1 -0
- package/lib/tsconfig.build.dts.tsbuildinfo +1 -0
- package/lib/tsconfig.build.esm.tsbuildinfo +1 -0
- package/package.json +4 -8
- package/tsconfig.json +0 -10
- /package/lib/{types → cjs}/agent.d.ts +0 -0
- /package/lib/{types → cjs}/constants.d.ts +0 -0
- /package/lib/{types → cjs}/context.d.ts +0 -0
- /package/lib/{types → cjs}/definitions/data-type-schema.d.ts +0 -0
- /package/lib/{types → cjs}/definitions/data-type.d.ts +0 -0
- /package/lib/{types → cjs}/definitions/memory.d.ts +0 -0
- /package/lib/{types → cjs}/definitions/open-api.d.ts +0 -0
- /package/lib/{types → cjs}/function-agent.d.ts +0 -0
- /package/lib/{types → cjs}/function-runner.d.ts +0 -0
- /package/lib/{types → cjs}/index.d.ts +0 -0
- /package/lib/{types → cjs}/llm-agent.d.ts +0 -0
- /package/lib/{types → cjs}/llm-decision-agent.d.ts +0 -0
- /package/lib/{types → cjs}/llm-model.d.ts +0 -0
- /package/lib/{types → cjs}/local-function-agent.d.ts +0 -0
- /package/lib/{types → cjs}/logger.d.ts +0 -0
- /package/lib/{types → cjs}/memorable.d.ts +0 -0
- /package/lib/{types → cjs}/open-api-agent.d.ts +0 -0
- /package/lib/{types → cjs}/pipeline-agent.d.ts +0 -0
- /package/lib/{types → cjs}/runnable.d.ts +0 -0
- /package/lib/{types → cjs}/utils/constants.d.ts +0 -0
- /package/lib/{types → cjs}/utils/fetch-open-api.d.ts +0 -0
- /package/lib/{types → cjs}/utils/fetch.d.ts +0 -0
- /package/lib/{types → cjs}/utils/index.d.ts +0 -0
- /package/lib/{types → cjs}/utils/is-non-nullable.d.ts +0 -0
- /package/lib/{types → cjs}/utils/message-utils.d.ts +0 -0
- /package/lib/{types → cjs}/utils/mustache-utils.d.ts +0 -0
- /package/lib/{types → cjs}/utils/nullable.d.ts +0 -0
- /package/lib/{types → cjs}/utils/omit.d.ts +0 -0
- /package/lib/{types → cjs}/utils/open-api-parameter.d.ts +0 -0
- /package/lib/{types → cjs}/utils/ordered-map.d.ts +0 -0
- /package/lib/{types → cjs}/utils/runnable-type.d.ts +0 -0
- /package/lib/{types → cjs}/utils/stream-utils.d.ts +0 -0
- /package/lib/{types → cjs}/utils/structured-output-schema.d.ts +0 -0
- /package/lib/{types → cjs}/utils/union.d.ts +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { LLMModelInputMessage } from "./llm-model";
|
|
2
|
+
import { Runnable } from "./runnable";
|
|
3
|
+
export interface MemoryMetadata {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export type MemoryActionItem<T> = {
|
|
7
|
+
event: "add";
|
|
8
|
+
id: string;
|
|
9
|
+
memory: T;
|
|
10
|
+
metadata?: MemoryMetadata;
|
|
11
|
+
} | {
|
|
12
|
+
event: "update";
|
|
13
|
+
id: string;
|
|
14
|
+
memory: T;
|
|
15
|
+
oldMemory: T;
|
|
16
|
+
metadata?: MemoryMetadata;
|
|
17
|
+
} | {
|
|
18
|
+
event: "delete";
|
|
19
|
+
id: string;
|
|
20
|
+
memory: T;
|
|
21
|
+
} | {
|
|
22
|
+
event: "none";
|
|
23
|
+
memory: T;
|
|
24
|
+
};
|
|
25
|
+
export interface MemoryItem<T> {
|
|
26
|
+
id: string;
|
|
27
|
+
userId?: string;
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
memory: T;
|
|
32
|
+
metadata: MemoryMetadata;
|
|
33
|
+
}
|
|
34
|
+
export interface MemoryItemWithScore<T = any> extends MemoryItem<T> {
|
|
35
|
+
score: number;
|
|
36
|
+
}
|
|
37
|
+
export type MemoryMessage = LLMModelInputMessage;
|
|
38
|
+
export type MemoryActions<T> = {
|
|
39
|
+
action: "add";
|
|
40
|
+
inputs: {
|
|
41
|
+
messages: MemoryMessage[];
|
|
42
|
+
options?: {
|
|
43
|
+
userId?: string;
|
|
44
|
+
sessionId?: string;
|
|
45
|
+
metadata?: MemoryMetadata;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
outputs: {
|
|
49
|
+
results: MemoryActionItem<T>[];
|
|
50
|
+
};
|
|
51
|
+
} | {
|
|
52
|
+
action: "search";
|
|
53
|
+
inputs: {
|
|
54
|
+
query: string;
|
|
55
|
+
options?: {
|
|
56
|
+
k?: number;
|
|
57
|
+
userId?: string;
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
filter?: MemoryMetadata;
|
|
60
|
+
sort?: MemorySortOptions;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
outputs: {
|
|
64
|
+
results: MemoryItemWithScore<T>[];
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
action: "filter";
|
|
68
|
+
inputs: {
|
|
69
|
+
options?: {
|
|
70
|
+
k?: number;
|
|
71
|
+
userId?: string;
|
|
72
|
+
sessionId?: string;
|
|
73
|
+
filter?: MemoryMetadata;
|
|
74
|
+
sort?: MemorySortOptions;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
outputs: {
|
|
78
|
+
results: MemoryItem<T>[];
|
|
79
|
+
};
|
|
80
|
+
} | {
|
|
81
|
+
action: "get";
|
|
82
|
+
inputs: {
|
|
83
|
+
memoryId: string;
|
|
84
|
+
};
|
|
85
|
+
outputs: {
|
|
86
|
+
result: MemoryItem<T> | null;
|
|
87
|
+
};
|
|
88
|
+
} | {
|
|
89
|
+
action: "create";
|
|
90
|
+
inputs: {
|
|
91
|
+
memory: T;
|
|
92
|
+
options?: {
|
|
93
|
+
userId?: string;
|
|
94
|
+
sessionId?: string;
|
|
95
|
+
metadata?: MemoryMetadata;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
outputs: {
|
|
99
|
+
result: MemoryItem<T>;
|
|
100
|
+
};
|
|
101
|
+
} | {
|
|
102
|
+
action: "update";
|
|
103
|
+
inputs: {
|
|
104
|
+
memoryId: string;
|
|
105
|
+
memory: T;
|
|
106
|
+
};
|
|
107
|
+
outputs: {
|
|
108
|
+
result: MemoryItem<T> | null;
|
|
109
|
+
};
|
|
110
|
+
} | {
|
|
111
|
+
action: "delete";
|
|
112
|
+
inputs: {
|
|
113
|
+
filter: string | string[] | Record<string, any>;
|
|
114
|
+
};
|
|
115
|
+
outputs: {};
|
|
116
|
+
} | {
|
|
117
|
+
action: "reset";
|
|
118
|
+
inputs: {};
|
|
119
|
+
outputs: {};
|
|
120
|
+
};
|
|
121
|
+
export interface SortItem {
|
|
122
|
+
field: string;
|
|
123
|
+
direction: "asc" | "desc";
|
|
124
|
+
}
|
|
125
|
+
export type MemorySortOptions = SortItem | SortItem[];
|
|
126
|
+
export declare abstract class Memorable<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>["outputs"]> {
|
|
127
|
+
constructor();
|
|
128
|
+
abstract runner?: MemoryRunner<T, C>;
|
|
129
|
+
abstract add(messages: Extract<MemoryActions<T>, {
|
|
130
|
+
action: "add";
|
|
131
|
+
}>["inputs"]["messages"], options?: Extract<MemoryActions<T>, {
|
|
132
|
+
action: "add";
|
|
133
|
+
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
134
|
+
action: "add";
|
|
135
|
+
}>["outputs"]>;
|
|
136
|
+
abstract search(query: Extract<MemoryActions<T>, {
|
|
137
|
+
action: "search";
|
|
138
|
+
}>["inputs"]["query"], options?: Extract<MemoryActions<T>, {
|
|
139
|
+
action: "search";
|
|
140
|
+
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
141
|
+
action: "search";
|
|
142
|
+
}>["outputs"]>;
|
|
143
|
+
abstract filter(options: Extract<MemoryActions<T>, {
|
|
144
|
+
action: "filter";
|
|
145
|
+
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
146
|
+
action: "filter";
|
|
147
|
+
}>["outputs"]>;
|
|
148
|
+
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
149
|
+
action: "get";
|
|
150
|
+
}>["inputs"]["memoryId"]): Promise<Extract<MemoryActions<T>, {
|
|
151
|
+
action: "get";
|
|
152
|
+
}>["outputs"]>;
|
|
153
|
+
abstract create(memory: Extract<MemoryActions<T>, {
|
|
154
|
+
action: "create";
|
|
155
|
+
}>["inputs"]["memory"], options?: Extract<MemoryActions<T>, {
|
|
156
|
+
action: "create";
|
|
157
|
+
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
158
|
+
action: "create";
|
|
159
|
+
}>["outputs"]>;
|
|
160
|
+
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
161
|
+
action: "update";
|
|
162
|
+
}>["inputs"]["memoryId"], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
163
|
+
action: "update";
|
|
164
|
+
}>["outputs"]>;
|
|
165
|
+
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
166
|
+
action: "delete";
|
|
167
|
+
}>["inputs"]["filter"]): Promise<Extract<MemoryActions<T>, {
|
|
168
|
+
action: "delete";
|
|
169
|
+
}>["outputs"]>;
|
|
170
|
+
abstract reset(): Promise<void>;
|
|
171
|
+
}
|
|
172
|
+
export interface MemoryRunnerInput<C = undefined> {
|
|
173
|
+
messages: MemoryMessage[];
|
|
174
|
+
userId?: string;
|
|
175
|
+
sessionId?: string;
|
|
176
|
+
metadata?: MemoryMetadata;
|
|
177
|
+
filter?: MemoryMetadata;
|
|
178
|
+
customData: C;
|
|
179
|
+
}
|
|
180
|
+
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryActionItem<T>[]> {
|
|
181
|
+
constructor(name: string);
|
|
182
|
+
}
|
|
183
|
+
export type MemorableSearchOutput<T extends Memorable<any>> = Awaited<ReturnType<T["search"]>>["results"];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Agent } from "./agent";
|
|
2
|
+
import type { Context, ContextState } from "./context";
|
|
3
|
+
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
|
+
import type { CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
+
import type { AuthConfig, FetchRequest, HTTPMethod, OpenAPIDataType, OpenAPIDataTypeSchema } from "./definitions/open-api";
|
|
6
|
+
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
7
|
+
import type { RunnableDefinition } from "./runnable";
|
|
8
|
+
import type { 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<O>;
|
|
20
|
+
fetch<T>(request: FetchRequest): Promise<T>;
|
|
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 {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Agent, type AgentProcessOptions } from "./agent";
|
|
2
|
+
import type { Context, ContextState } from "./context";
|
|
3
|
+
import { type DataTypeSchema, type SchemaMapType } from "./definitions/data-type-schema";
|
|
4
|
+
import { type CreateRunnableMemory } from "./definitions/memory";
|
|
5
|
+
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
+
import type { Runnable, RunnableDefinition, RunnableOutput, RunnableResponseDelta } from "./runnable";
|
|
7
|
+
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
8
|
+
import { OrderedRecord } from "./utils/ordered-map";
|
|
9
|
+
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
|
10
|
+
export declare class PipelineAgent<I extends {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
} = {}, O extends {
|
|
13
|
+
[name: string]: any;
|
|
14
|
+
} = {}, Memories extends {
|
|
15
|
+
[name: string]: MemoryItemWithScore[];
|
|
16
|
+
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
17
|
+
definition: PipelineAgentDefinition;
|
|
18
|
+
static create: typeof create;
|
|
19
|
+
constructor(definition: PipelineAgentDefinition, context?: Context<State>);
|
|
20
|
+
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
21
|
+
}
|
|
22
|
+
type VariableWithPropPath = {
|
|
23
|
+
fromVariable: string;
|
|
24
|
+
fromVariablePropPath?: (string | number)[];
|
|
25
|
+
};
|
|
26
|
+
export type PipelineAgentProcessParameter<R extends Runnable = any, RI extends {
|
|
27
|
+
[name: string]: DataTypeSchema;
|
|
28
|
+
} = ExtractRunnableInputType<R>> = {
|
|
29
|
+
runnable: R;
|
|
30
|
+
input: MakeNullablePropertyOptional<{
|
|
31
|
+
[key in keyof RI]: VariableWithPropPath;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
declare function create<I extends {
|
|
35
|
+
[name: string]: DataTypeSchema;
|
|
36
|
+
}, O extends {
|
|
37
|
+
[name: string]: DataTypeSchema & {
|
|
38
|
+
fromVariable: string;
|
|
39
|
+
fromVariablePropPath?: string[];
|
|
40
|
+
};
|
|
41
|
+
}, Memories extends {
|
|
42
|
+
[name: string]: CreateRunnableMemory<I>;
|
|
43
|
+
}, State extends ContextState, Processes extends {
|
|
44
|
+
[name: string]: PipelineAgentProcessParameter;
|
|
45
|
+
}>({ context, ...options }: {
|
|
46
|
+
context: Context<State>;
|
|
47
|
+
name?: string;
|
|
48
|
+
inputs: I;
|
|
49
|
+
outputs: O;
|
|
50
|
+
memories?: Memories;
|
|
51
|
+
processes: Processes;
|
|
52
|
+
}): PipelineAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
53
|
+
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
54
|
+
}, State>;
|
|
55
|
+
export interface PipelineAgentDefinition extends RunnableDefinition {
|
|
56
|
+
type: "pipeline_agent";
|
|
57
|
+
processes?: OrderedRecord<PipelineAgentProcess>;
|
|
58
|
+
outputs: OrderedRecord<PipelineAgentOutput>;
|
|
59
|
+
}
|
|
60
|
+
export type PipelineAgentOutput = RunnableOutput & {
|
|
61
|
+
from: "variable";
|
|
62
|
+
fromVariableId?: string;
|
|
63
|
+
fromVariablePropPath?: (string | number)[];
|
|
64
|
+
};
|
|
65
|
+
export type PipelineAgentProcess = {
|
|
66
|
+
id: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
runnable?: {
|
|
69
|
+
id?: string;
|
|
70
|
+
};
|
|
71
|
+
input?: {
|
|
72
|
+
[inputId: string]: {
|
|
73
|
+
from: "variable";
|
|
74
|
+
fromVariableId?: string;
|
|
75
|
+
fromVariablePropPath?: (string | number | symbol)[];
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Context, ContextState } from "./context";
|
|
2
|
+
import type { DataType } from "./definitions/data-type";
|
|
3
|
+
import type { Memorable } from "./memorable";
|
|
4
|
+
import { OrderedRecord } from "./utils/ordered-map";
|
|
5
|
+
export interface RunOptions {
|
|
6
|
+
stream?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type RunnableResponse<T> = T | RunnableResponseStream<T>;
|
|
9
|
+
export declare abstract class Runnable<I extends {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
} = {}, O extends {
|
|
12
|
+
[name: string]: any;
|
|
13
|
+
} = {}, State extends ContextState = ContextState> {
|
|
14
|
+
definition: RunnableDefinition;
|
|
15
|
+
context?: Context<State> | undefined;
|
|
16
|
+
constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
|
|
17
|
+
get id(): string;
|
|
18
|
+
get name(): string | undefined;
|
|
19
|
+
inputs: {
|
|
20
|
+
[key in keyof I]: DataType;
|
|
21
|
+
};
|
|
22
|
+
outputs: {
|
|
23
|
+
[key in keyof O]: DataType;
|
|
24
|
+
};
|
|
25
|
+
abstract run(input: I, options: RunOptions & {
|
|
26
|
+
stream: true;
|
|
27
|
+
}): Promise<RunnableResponseStream<O>>;
|
|
28
|
+
abstract run(input: I, options?: RunOptions & {
|
|
29
|
+
stream?: false;
|
|
30
|
+
}): Promise<O>;
|
|
31
|
+
abstract run(input: I, options?: RunOptions): Promise<RunnableResponse<O>>;
|
|
32
|
+
}
|
|
33
|
+
export interface RunnableDefinition {
|
|
34
|
+
id: string;
|
|
35
|
+
type: string;
|
|
36
|
+
name?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
memories?: OrderedRecord<RunnableMemory>;
|
|
39
|
+
inputs: OrderedRecord<RunnableInput>;
|
|
40
|
+
outputs: OrderedRecord<RunnableOutput>;
|
|
41
|
+
}
|
|
42
|
+
export interface RunnableMemory {
|
|
43
|
+
id: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
memory?: Memorable<any>;
|
|
46
|
+
query?: {
|
|
47
|
+
from: "variable";
|
|
48
|
+
fromVariableId?: string;
|
|
49
|
+
fromVariablePropPath?: string[];
|
|
50
|
+
};
|
|
51
|
+
options?: {
|
|
52
|
+
k?: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export type RunnableInput = DataType;
|
|
56
|
+
export type RunnableOutput = DataType;
|
|
57
|
+
export interface RunnableResponseDelta<T> {
|
|
58
|
+
$text?: string;
|
|
59
|
+
delta?: Partial<T>;
|
|
60
|
+
}
|
|
61
|
+
export interface RunnableResponseError {
|
|
62
|
+
error: {
|
|
63
|
+
message: string;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export type RunnableResponseChunk<T> = RunnableResponseDelta<T>;
|
|
67
|
+
export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
|
|
68
|
+
export declare function isRunnableResponseDelta<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseDelta<T>;
|
|
69
|
+
export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
|
|
70
|
+
export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FETCH_TIMEOUT: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkFetchResponse(result: Response): Promise<Response>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./fetch";
|
|
2
|
+
export * from "./fetch-open-api";
|
|
3
|
+
export * from "./is-non-nullable";
|
|
4
|
+
export * from "./mustache-utils";
|
|
5
|
+
export * from "./nullable";
|
|
6
|
+
export * from "./omit";
|
|
7
|
+
export * from "./open-api-parameter";
|
|
8
|
+
export * from "./ordered-map";
|
|
9
|
+
export * from "./stream-utils";
|
|
10
|
+
export * from "./union";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LLMAgentDefinition } from "../llm-agent";
|
|
2
|
+
import type { LLMModelInputMessage } from "../llm-model";
|
|
3
|
+
import type { MemoryItemWithScore } from "../memorable";
|
|
4
|
+
export declare function mergeHistoryMessages(messages: LLMModelInputMessage[], history: LLMModelInputMessage[]): LLMModelInputMessage[];
|
|
5
|
+
export declare function memoriesToMessages(memories: {
|
|
6
|
+
[name: string]: MemoryItemWithScore[];
|
|
7
|
+
}, { primaryMemoryName }?: {
|
|
8
|
+
primaryMemoryName?: string;
|
|
9
|
+
}): {
|
|
10
|
+
primaryMemory: LLMModelInputMessage[];
|
|
11
|
+
memory: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function prepareMessages(definition: Pick<LLMAgentDefinition, "messages" | "memories" | "primaryMemoryId">, input: {
|
|
14
|
+
[name: string]: any;
|
|
15
|
+
}, memories: {
|
|
16
|
+
[name: string]: MemoryItemWithScore[];
|
|
17
|
+
}): {
|
|
18
|
+
originalMessages: LLMModelInputMessage[];
|
|
19
|
+
messagesWithMemory: LLMModelInputMessage[];
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type OmitPropsFromUnion<T, K extends string | number | symbol> = T extends any ? Omit<T, K> : never;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AuthConfig, FetchRequest, HTTPMethod } from "../definitions/open-api";
|
|
2
|
+
import type { OpenAPIAgentDefinition } from "../open-api-agent";
|
|
3
|
+
export declare function formatOpenAPIRequest(api: {
|
|
4
|
+
url: string;
|
|
5
|
+
method: HTTPMethod;
|
|
6
|
+
auth?: AuthConfig;
|
|
7
|
+
}, inputs: OpenAPIAgentDefinition["inputs"], input: Record<string, any>): Promise<FetchRequest>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type OrderedRecord<T extends {
|
|
2
|
+
id: string;
|
|
3
|
+
}> = Record<string, T> & {
|
|
4
|
+
$indexes: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare namespace OrderedRecord {
|
|
7
|
+
function iterator<T extends {
|
|
8
|
+
id: string;
|
|
9
|
+
}>(record?: OrderedRecord<T>): IterableIterator<T>;
|
|
10
|
+
function map<O, T extends {
|
|
11
|
+
id: string;
|
|
12
|
+
}>(record: OrderedRecord<T> | undefined, fn: (value: T, index: number) => O): O[];
|
|
13
|
+
function toArray<T extends {
|
|
14
|
+
id: string;
|
|
15
|
+
}>(record: OrderedRecord<T> | undefined): T[];
|
|
16
|
+
function fromArray<T extends {
|
|
17
|
+
id: string;
|
|
18
|
+
}>(array?: T[]): OrderedRecord<T>;
|
|
19
|
+
function find<T extends {
|
|
20
|
+
id: string;
|
|
21
|
+
}>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T | undefined;
|
|
22
|
+
function filter<T extends {
|
|
23
|
+
id: string;
|
|
24
|
+
}>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T[];
|
|
25
|
+
function at<T extends {
|
|
26
|
+
id: string;
|
|
27
|
+
}>(record: OrderedRecord<T> | undefined, index: number): T | undefined;
|
|
28
|
+
function push<T extends {
|
|
29
|
+
id: string;
|
|
30
|
+
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
31
|
+
function merge<T extends {
|
|
32
|
+
id: string;
|
|
33
|
+
}>(...records: OrderedRecord<T>[]): OrderedRecord<T>;
|
|
34
|
+
function pushOrUpdate<T extends {
|
|
35
|
+
id: string;
|
|
36
|
+
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Runnable, RunnableResponseStream } from "../runnable";
|
|
2
|
+
export type ExtractRunnableInputType<T> = T extends Runnable<infer I, any> ? I : never;
|
|
3
|
+
export type ExtractRunnableOutputType<T> = T extends Runnable<any, infer O> ? Exclude<O, RunnableResponseStream<any>> : never;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "../runnable";
|
|
2
|
+
export declare function objectToRunnableResponseStream<T extends {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}>(obj: T): RunnableResponseStream<T>;
|
|
5
|
+
export declare function runnableResponseStreamToObject<T extends {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}>(stream: RunnableResponseStream<T> | AsyncGenerator<RunnableResponseChunk<T>>): Promise<T>;
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the outputs from a runnable output stream and run the
|
|
10
|
+
* resolve function on the result before the stream closes. It can be
|
|
11
|
+
* used to update the memories of an agent.
|
|
12
|
+
* @param output The runnable output stream or object
|
|
13
|
+
* @param resolve The function to run on the result
|
|
14
|
+
* @returns The runnable output stream or object
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractOutputsFromRunnableOutput<T extends {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}>(output: RunnableResponse<T> | AsyncGenerator<RunnableResponseChunk<T>>, resolve: (result: T) => Promise<void> | void): Promise<RunnableResponse<T>>;
|
|
19
|
+
export declare function asyncGeneratorToReadableStream<T>(generator: AsyncGenerator<T>): ReadableStream<T>;
|
|
20
|
+
export declare function isAsyncGenerator<T extends AsyncGenerator>(value: any): value is T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UnionToIntersection<U, O = any> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I extends O ? I : never : never;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Context, ContextState } from "./context";
|
|
2
|
+
import type { MemoryItemWithScore, MemoryMessage } from "./memorable";
|
|
3
|
+
import { type RunOptions, Runnable, type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "./runnable";
|
|
4
|
+
export interface AgentProcessOptions<Memories extends {
|
|
5
|
+
[name: string]: MemoryItemWithScore[];
|
|
6
|
+
}> {
|
|
7
|
+
memories: Memories;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class Agent<I extends {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
} = {}, O extends {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
} = {}, Memories extends {
|
|
14
|
+
[name: string]: MemoryItemWithScore[];
|
|
15
|
+
} = {}, State extends ContextState = ContextState> extends Runnable<I, O, State> {
|
|
16
|
+
private getMemoryQuery;
|
|
17
|
+
/**
|
|
18
|
+
* Load memories that are defined in the agent definition.
|
|
19
|
+
* @param input The agent input.
|
|
20
|
+
* @param context The AIGNE context.
|
|
21
|
+
* @returns A dictionary of memories, where the key is the memory id or name and the value is an array of memory items.
|
|
22
|
+
*/
|
|
23
|
+
protected loadMemories(input: I, context?: Context): Promise<Memories>;
|
|
24
|
+
/**
|
|
25
|
+
* Update memories by user messages and assistant responses.
|
|
26
|
+
* @param messages Messages to be added to memories.
|
|
27
|
+
*/
|
|
28
|
+
protected updateMemories(messages: MemoryMessage[]): Promise<void>;
|
|
29
|
+
run(input: I, options: RunOptions & {
|
|
30
|
+
stream: true;
|
|
31
|
+
}): Promise<RunnableResponseStream<O>>;
|
|
32
|
+
run(input: I, options?: RunOptions & {
|
|
33
|
+
stream?: false;
|
|
34
|
+
}): Promise<O>;
|
|
35
|
+
/**
|
|
36
|
+
* Hook that is called before the agent result is returned.
|
|
37
|
+
* @param _result The agent result.
|
|
38
|
+
*/
|
|
39
|
+
protected onResult(_result: O): Promise<void>;
|
|
40
|
+
abstract process(input: I, options: AgentProcessOptions<Memories>): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LLMModelConfiguration } from "./llm-model";
|
|
2
|
+
import type { Runnable, RunnableDefinition } from "./runnable";
|
|
3
|
+
export interface ContextState {
|
|
4
|
+
userId?: string;
|
|
5
|
+
sessionId?: string;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export interface ContextConfig {
|
|
9
|
+
llmModel?: LLMModelConfiguration;
|
|
10
|
+
}
|
|
11
|
+
export interface Context<State extends ContextState = ContextState, Config extends ContextConfig = ContextConfig> {
|
|
12
|
+
state: State;
|
|
13
|
+
config: Config;
|
|
14
|
+
resolve<T extends Runnable>(id: string | RunnableDefinition | T): Promise<T>;
|
|
15
|
+
register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
|
|
16
|
+
resolveDependency<T>(token: string | symbol): T;
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MakeNullablePropertyOptional } from "../utils/nullable";
|
|
2
|
+
import { OrderedRecord } from "../utils/ordered-map";
|
|
3
|
+
import type { DataType } from "./data-type";
|
|
4
|
+
export declare function schemaToDataType(dataType: {
|
|
5
|
+
[name: string]: DataTypeSchema;
|
|
6
|
+
}): OrderedRecord<DataType>;
|
|
7
|
+
export type DataTypeSchema = DataTypeSchemaString | DataTypeSchemaNumber | DataTypeSchemaBoolean | DataTypeSchemaObject | DataTypeSchemaArray;
|
|
8
|
+
export interface DataTypeSchemaBase {
|
|
9
|
+
description?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DataTypeSchemaString extends DataTypeSchemaBase {
|
|
13
|
+
type: "string";
|
|
14
|
+
}
|
|
15
|
+
export interface DataTypeSchemaNumber extends DataTypeSchemaBase {
|
|
16
|
+
type: "number";
|
|
17
|
+
}
|
|
18
|
+
export interface DataTypeSchemaBoolean extends DataTypeSchemaBase {
|
|
19
|
+
type: "boolean";
|
|
20
|
+
}
|
|
21
|
+
export interface DataTypeSchemaObject extends DataTypeSchemaBase {
|
|
22
|
+
type: "object";
|
|
23
|
+
properties?: {
|
|
24
|
+
[key: string]: DataTypeSchema;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface DataTypeSchemaArray extends DataTypeSchemaBase {
|
|
28
|
+
type: "array";
|
|
29
|
+
items?: DataTypeSchema;
|
|
30
|
+
}
|
|
31
|
+
type SchemaTypeInner<T extends DataTypeSchema> = T extends DataTypeSchemaString ? string : T extends DataTypeSchemaNumber ? number : T extends DataTypeSchemaBoolean ? boolean : T extends DataTypeSchemaObject ? MakeNullablePropertyOptional<{
|
|
32
|
+
[K in keyof T["properties"]]: SchemaType<NonNullable<T["properties"]>[K]>;
|
|
33
|
+
}> : T extends DataTypeSchemaArray ? T["items"] extends null | undefined ? SchemaType<{
|
|
34
|
+
type: "object";
|
|
35
|
+
}>[] : SchemaType<NonNullable<T["items"]>>[] : never;
|
|
36
|
+
export type SchemaType<T extends DataTypeSchema> = T["required"] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
|
|
37
|
+
export type SchemaMapType<T extends Record<string, DataTypeSchema>> = SchemaType<{
|
|
38
|
+
type: "object";
|
|
39
|
+
required: true;
|
|
40
|
+
properties: T;
|
|
41
|
+
}>;
|
|
42
|
+
export {};
|