@aigne/core 1.0.9 → 1.0.11
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/agent.d.ts +70 -16
- package/lib/cjs/agent.js +68 -16
- package/lib/cjs/context.d.ts +1 -1
- package/lib/cjs/definitions/data-schema.d.ts +61 -0
- package/lib/cjs/definitions/memory.d.ts +18 -5
- package/lib/cjs/definitions/open-api.d.ts +3 -3
- package/lib/cjs/definitions/preload.d.ts +43 -0
- package/lib/cjs/definitions/preload.js +34 -0
- package/lib/cjs/function-agent.d.ts +15 -56
- package/lib/cjs/function-agent.js +9 -6
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/llm-agent.d.ts +17 -60
- package/lib/cjs/llm-agent.js +8 -5
- package/lib/cjs/llm-decision-agent.d.ts +31 -51
- package/lib/cjs/llm-decision-agent.js +30 -13
- package/lib/cjs/llm-model.d.ts +4 -4
- package/lib/cjs/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/cjs/llm-models/openai-llm-model.js +14 -14
- package/lib/cjs/memorable.d.ts +21 -13
- package/lib/cjs/memorable.js +2 -2
- package/lib/cjs/open-api-agent.d.ts +9 -38
- package/lib/cjs/open-api-agent.js +12 -6
- package/lib/cjs/pipeline-agent.d.ts +14 -37
- package/lib/cjs/pipeline-agent.js +10 -10
- package/lib/cjs/runnable.d.ts +7 -24
- package/lib/cjs/sandbox-function-agent.d.ts +10 -38
- package/lib/cjs/sandbox-function-agent.js +9 -5
- package/lib/cjs/sandbox-function-runner.d.ts +8 -17
- package/lib/cjs/sandbox-function-runner.js +1 -0
- package/lib/cjs/utils/index.d.ts +1 -0
- package/lib/cjs/utils/index.js +1 -0
- package/lib/cjs/utils/logger.d.ts +3 -0
- package/lib/cjs/utils/logger.js +17 -0
- package/lib/cjs/utils/message-utils.d.ts +1 -1
- package/lib/cjs/utils/message-utils.js +1 -4
- package/lib/cjs/utils/open-api-parameter.js +3 -6
- package/lib/cjs/utils/runnable-type.d.ts +5 -3
- package/lib/cjs/utils/structured-output-schema.d.ts +2 -2
- package/lib/cjs/utils/type-utils.d.ts +1 -0
- package/lib/cjs/{logger.js → utils/type-utils.js} +0 -2
- package/lib/dts/agent.d.ts +70 -16
- package/lib/dts/context.d.ts +1 -1
- package/lib/dts/definitions/data-schema.d.ts +61 -0
- package/lib/dts/definitions/memory.d.ts +18 -5
- package/lib/dts/definitions/open-api.d.ts +3 -3
- package/lib/dts/definitions/preload.d.ts +43 -0
- package/lib/dts/function-agent.d.ts +15 -56
- package/lib/dts/index.d.ts +1 -1
- package/lib/dts/llm-agent.d.ts +17 -60
- package/lib/dts/llm-decision-agent.d.ts +31 -51
- package/lib/dts/llm-model.d.ts +4 -4
- package/lib/dts/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/dts/memorable.d.ts +21 -13
- package/lib/dts/open-api-agent.d.ts +9 -38
- package/lib/dts/pipeline-agent.d.ts +14 -37
- package/lib/dts/runnable.d.ts +7 -24
- package/lib/dts/sandbox-function-agent.d.ts +10 -38
- package/lib/dts/sandbox-function-runner.d.ts +8 -17
- package/lib/dts/utils/index.d.ts +1 -0
- package/lib/dts/utils/logger.d.ts +3 -0
- package/lib/dts/utils/message-utils.d.ts +1 -1
- package/lib/dts/utils/runnable-type.d.ts +5 -3
- package/lib/dts/utils/structured-output-schema.d.ts +2 -2
- package/lib/dts/utils/type-utils.d.ts +1 -0
- package/lib/esm/agent.d.ts +70 -16
- package/lib/esm/agent.js +64 -9
- package/lib/esm/context.d.ts +1 -1
- package/lib/esm/definitions/data-schema.d.ts +61 -0
- package/lib/esm/definitions/memory.d.ts +18 -5
- package/lib/esm/definitions/open-api.d.ts +3 -3
- package/lib/esm/definitions/preload.d.ts +43 -0
- package/lib/esm/definitions/preload.js +31 -0
- package/lib/esm/function-agent.d.ts +15 -56
- package/lib/esm/function-agent.js +9 -6
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/llm-agent.d.ts +17 -60
- package/lib/esm/llm-agent.js +8 -5
- package/lib/esm/llm-decision-agent.d.ts +31 -51
- package/lib/esm/llm-decision-agent.js +32 -15
- package/lib/esm/llm-model.d.ts +4 -4
- package/lib/esm/llm-models/openai-llm-model.d.ts +4 -1
- package/lib/esm/llm-models/openai-llm-model.js +14 -14
- package/lib/esm/memorable.d.ts +21 -13
- package/lib/esm/memorable.js +2 -2
- package/lib/esm/open-api-agent.d.ts +9 -38
- package/lib/esm/open-api-agent.js +11 -5
- package/lib/esm/pipeline-agent.d.ts +14 -37
- package/lib/esm/pipeline-agent.js +9 -6
- package/lib/esm/runnable.d.ts +7 -24
- package/lib/esm/sandbox-function-agent.d.ts +10 -38
- package/lib/esm/sandbox-function-agent.js +9 -5
- package/lib/esm/sandbox-function-runner.d.ts +8 -17
- package/lib/esm/sandbox-function-runner.js +2 -1
- package/lib/esm/utils/index.d.ts +1 -0
- package/lib/esm/utils/index.js +1 -0
- package/lib/esm/utils/logger.d.ts +3 -0
- package/lib/esm/utils/logger.js +14 -0
- package/lib/esm/utils/message-utils.d.ts +1 -1
- package/lib/esm/utils/message-utils.js +1 -4
- package/lib/esm/utils/open-api-parameter.js +1 -1
- package/lib/esm/utils/runnable-type.d.ts +5 -3
- package/lib/esm/utils/structured-output-schema.d.ts +2 -2
- package/lib/esm/utils/type-utils.d.ts +1 -0
- package/lib/esm/utils/type-utils.js +1 -0
- package/package.json +4 -4
- package/lib/cjs/definitions/data-type-schema.d.ts +0 -42
- package/lib/cjs/logger.d.ts +0 -2
- package/lib/dts/definitions/data-type-schema.d.ts +0 -42
- package/lib/dts/logger.d.ts +0 -2
- package/lib/esm/definitions/data-type-schema.d.ts +0 -42
- package/lib/esm/logger.d.ts +0 -2
- package/lib/esm/logger.js +0 -2
- /package/lib/cjs/definitions/{data-type-schema.js → data-schema.js} +0 -0
- /package/lib/esm/definitions/{data-type-schema.js → data-schema.js} +0 -0
package/lib/esm/llm-model.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Agent } from "./agent";
|
|
2
2
|
import type { Context } from "./context";
|
|
3
3
|
export type Role = "system" | "user" | "assistant" | "tool";
|
|
4
|
-
export
|
|
4
|
+
export type LLMModelInputs = {
|
|
5
5
|
messages: LLMModelInputMessage[];
|
|
6
6
|
responseFormat?: {
|
|
7
7
|
type: "text";
|
|
@@ -23,7 +23,7 @@ export interface LLMModelInputs {
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
modelOptions?: LLMModelOptions;
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
27
|
export interface LLMModelInputMessage {
|
|
28
28
|
role: Role;
|
|
29
29
|
content: string | ({
|
|
@@ -60,7 +60,7 @@ export interface LLMModelOptions {
|
|
|
60
60
|
frequencyPenalty?: number;
|
|
61
61
|
presencePenalty?: number;
|
|
62
62
|
}
|
|
63
|
-
export
|
|
63
|
+
export type LLMModelOutputs = {
|
|
64
64
|
$text?: string | null;
|
|
65
65
|
toolCalls?: {
|
|
66
66
|
id?: string;
|
|
@@ -70,7 +70,7 @@ export interface LLMModelOutputs {
|
|
|
70
70
|
arguments?: string;
|
|
71
71
|
};
|
|
72
72
|
}[];
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
74
|
export declare abstract class LLMModel extends Agent<LLMModelInputs, LLMModelOutputs> {
|
|
75
75
|
constructor(context?: Context);
|
|
76
76
|
}
|
|
@@ -8,7 +8,9 @@ export declare class OpenaiLLMModel extends LLMModel {
|
|
|
8
8
|
private client;
|
|
9
9
|
setApiKey(apiKey: string): void;
|
|
10
10
|
process(input: LLMModelInputs): AsyncGenerator<{
|
|
11
|
-
$text: string
|
|
11
|
+
$text: string;
|
|
12
|
+
delta?: undefined;
|
|
13
|
+
} | {
|
|
12
14
|
delta: {
|
|
13
15
|
toolCalls: {
|
|
14
16
|
id?: string;
|
|
@@ -19,5 +21,6 @@ export declare class OpenaiLLMModel extends LLMModel {
|
|
|
19
21
|
};
|
|
20
22
|
}[];
|
|
21
23
|
};
|
|
24
|
+
$text?: undefined;
|
|
22
25
|
}, void, unknown>;
|
|
23
26
|
}
|
|
@@ -37,22 +37,22 @@ export class OpenaiLLMModel extends LLMModel {
|
|
|
37
37
|
const toolCalls = [];
|
|
38
38
|
for await (const chunk of res) {
|
|
39
39
|
const choice = chunk.choices?.[0];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
if (choice?.delta.tool_calls?.length) {
|
|
41
|
+
for (const call of choice.delta.tool_calls) {
|
|
42
|
+
const tool = toolCalls[call.index] ?? { id: call.id || nanoid() };
|
|
43
|
+
toolCalls[call.index] = tool;
|
|
44
|
+
if (call.type)
|
|
45
|
+
tool.type = call.type;
|
|
46
|
+
tool.function ??= {};
|
|
47
|
+
tool.function.name =
|
|
48
|
+
(tool.function.name || "") + (call.function?.name || "");
|
|
49
|
+
tool.function.arguments = (tool.function.arguments || "").concat(call.function?.arguments || "");
|
|
50
|
+
}
|
|
50
51
|
}
|
|
51
|
-
|
|
52
|
-
$text: choice
|
|
53
|
-
delta: { toolCalls },
|
|
54
|
-
};
|
|
52
|
+
if (choice?.delta.content)
|
|
53
|
+
yield { $text: choice.delta.content };
|
|
55
54
|
}
|
|
55
|
+
yield { delta: { toolCalls } };
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
async function contentsFromInputMessages(messages) {
|
package/lib/esm/memorable.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { Context } from "./context";
|
|
1
2
|
import type { LLMModelInputMessage } from "./llm-model";
|
|
2
3
|
import { Runnable } from "./runnable";
|
|
3
|
-
export
|
|
4
|
-
[key: string]: any;
|
|
5
|
-
}
|
|
4
|
+
export type MemoryMetadata = Record<string, unknown>;
|
|
6
5
|
export type MemoryActionItem<T> = {
|
|
7
6
|
event: "add";
|
|
8
7
|
id: string;
|
|
@@ -31,7 +30,7 @@ export interface MemoryItem<T> {
|
|
|
31
30
|
memory: T;
|
|
32
31
|
metadata: MemoryMetadata;
|
|
33
32
|
}
|
|
34
|
-
export interface MemoryItemWithScore<T =
|
|
33
|
+
export interface MemoryItemWithScore<T = unknown> extends MemoryItem<T> {
|
|
35
34
|
score: number;
|
|
36
35
|
}
|
|
37
36
|
export type MemoryMessage = LLMModelInputMessage;
|
|
@@ -110,13 +109,19 @@ export type MemoryActions<T> = {
|
|
|
110
109
|
} | {
|
|
111
110
|
action: "delete";
|
|
112
111
|
inputs: {
|
|
113
|
-
filter: string | string[] | Record<string,
|
|
112
|
+
filter: string | string[] | Record<string, unknown>;
|
|
113
|
+
};
|
|
114
|
+
outputs: {
|
|
115
|
+
[name: string]: never;
|
|
114
116
|
};
|
|
115
|
-
outputs: {};
|
|
116
117
|
} | {
|
|
117
118
|
action: "reset";
|
|
118
|
-
inputs: {
|
|
119
|
-
|
|
119
|
+
inputs: {
|
|
120
|
+
[name: string]: never;
|
|
121
|
+
};
|
|
122
|
+
outputs: {
|
|
123
|
+
[name: string]: never;
|
|
124
|
+
};
|
|
120
125
|
};
|
|
121
126
|
export interface SortItem {
|
|
122
127
|
field: string;
|
|
@@ -124,7 +129,7 @@ export interface SortItem {
|
|
|
124
129
|
}
|
|
125
130
|
export type MemorySortOptions = SortItem | SortItem[];
|
|
126
131
|
export declare abstract class Memorable<T, C = undefined> extends Runnable<MemoryActions<T>, MemoryActions<T>["outputs"]> {
|
|
127
|
-
constructor();
|
|
132
|
+
constructor(context?: Context);
|
|
128
133
|
abstract runner?: MemoryRunner<T, C>;
|
|
129
134
|
abstract add(messages: Extract<MemoryActions<T>, {
|
|
130
135
|
action: "add";
|
|
@@ -169,15 +174,18 @@ export declare abstract class Memorable<T, C = undefined> extends Runnable<Memor
|
|
|
169
174
|
}>["outputs"]>;
|
|
170
175
|
abstract reset(): Promise<void>;
|
|
171
176
|
}
|
|
172
|
-
export
|
|
177
|
+
export type MemoryRunnerInput<C = undefined> = {
|
|
173
178
|
messages: MemoryMessage[];
|
|
174
179
|
userId?: string;
|
|
175
180
|
sessionId?: string;
|
|
176
181
|
metadata?: MemoryMetadata;
|
|
177
182
|
filter?: MemoryMetadata;
|
|
178
183
|
customData: C;
|
|
179
|
-
}
|
|
180
|
-
export
|
|
184
|
+
};
|
|
185
|
+
export type MemoryRunnerOutput<T> = {
|
|
186
|
+
actions: MemoryActionItem<T>[];
|
|
187
|
+
};
|
|
188
|
+
export declare abstract class MemoryRunner<T, C = undefined> extends Runnable<MemoryRunnerInput<C>, MemoryRunnerOutput<T>> {
|
|
181
189
|
constructor(name: string);
|
|
182
190
|
}
|
|
183
|
-
export type MemorableSearchOutput<T extends Memorable<
|
|
191
|
+
export type MemorableSearchOutput<T extends Memorable<unknown>> = Awaited<ReturnType<T["search"]>>["results"];
|
package/lib/esm/memorable.js
CHANGED
|
@@ -2,14 +2,14 @@ import { camelCase, startCase } from "lodash";
|
|
|
2
2
|
import { Runnable } from "./runnable";
|
|
3
3
|
import { OrderedRecord } from "./utils";
|
|
4
4
|
export class Memorable extends Runnable {
|
|
5
|
-
constructor() {
|
|
5
|
+
constructor(context) {
|
|
6
6
|
super({
|
|
7
7
|
id: "memory",
|
|
8
8
|
type: "memory",
|
|
9
9
|
name: "Memory",
|
|
10
10
|
inputs: OrderedRecord.fromArray([]),
|
|
11
11
|
outputs: OrderedRecord.fromArray([]),
|
|
12
|
-
});
|
|
12
|
+
}, context);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export class MemoryRunner extends Runnable {
|
|
@@ -1,55 +1,26 @@
|
|
|
1
|
-
import { Agent } from "./agent";
|
|
1
|
+
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
7
|
-
import type { RunnableDefinition } from "./runnable";
|
|
3
|
+
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
+
import type { AuthConfig, FetchRequest, HTTPMethod, OpenAPIDataType } from "./definitions/open-api";
|
|
5
|
+
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
8
6
|
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> {
|
|
7
|
+
export declare class OpenAPIAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
|
|
16
8
|
definition: OpenAPIAgentDefinition;
|
|
17
9
|
static create: typeof create;
|
|
18
10
|
constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
|
|
19
|
-
process(input: I): Promise<O>;
|
|
11
|
+
process(input: AgentProcessInput<I, Preloads, Memories>): Promise<O>;
|
|
20
12
|
fetch<T>(request: FetchRequest): Promise<T>;
|
|
21
13
|
}
|
|
22
|
-
export interface OpenAPIAgentDefinition extends
|
|
14
|
+
export interface OpenAPIAgentDefinition extends AgentDefinition {
|
|
23
15
|
type: "open_api_agent";
|
|
24
16
|
inputs: OrderedRecord<OpenAPIDataType>;
|
|
25
17
|
url: string;
|
|
26
18
|
method?: HTTPMethod;
|
|
27
19
|
auth?: AuthConfig;
|
|
28
20
|
}
|
|
29
|
-
|
|
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;
|
|
21
|
+
declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
42
22
|
url: string;
|
|
43
23
|
method?: HTTPMethod;
|
|
44
24
|
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>;
|
|
25
|
+
}): OpenAPIAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
55
26
|
export {};
|
|
@@ -12,9 +12,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { nanoid } from "nanoid";
|
|
14
14
|
import { inject, injectable } from "tsyringe";
|
|
15
|
-
import { Agent } from "./agent";
|
|
15
|
+
import { Agent, } from "./agent";
|
|
16
16
|
import { TYPES } from "./constants";
|
|
17
|
-
import { schemaToDataType
|
|
17
|
+
import { schemaToDataType } from "./definitions/data-schema";
|
|
18
|
+
import { toRunnableMemories } from "./definitions/memory";
|
|
19
|
+
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
18
20
|
import { fetchOpenApi } from "./utils/fetch-open-api";
|
|
19
21
|
import { formatOpenAPIRequest } from "./utils/open-api-parameter";
|
|
20
22
|
let OpenAPIAgent = class OpenAPIAgent extends Agent {
|
|
@@ -42,18 +44,22 @@ OpenAPIAgent = __decorate([
|
|
|
42
44
|
__metadata("design:paramtypes", [Object, Object])
|
|
43
45
|
], OpenAPIAgent);
|
|
44
46
|
export { OpenAPIAgent };
|
|
45
|
-
function create(
|
|
46
|
-
const agentId = options.
|
|
47
|
+
function create(options) {
|
|
48
|
+
const agentId = options.name || nanoid();
|
|
47
49
|
const inputs = schemaToDataType(options.inputs);
|
|
48
50
|
const outputs = schemaToDataType(options.outputs);
|
|
51
|
+
const preloads = preloadCreatorsToPreloads(inputs, options.preloads);
|
|
52
|
+
const memories = toRunnableMemories(agentId, inputs, options.memories || {});
|
|
49
53
|
return new OpenAPIAgent({
|
|
50
54
|
id: agentId,
|
|
51
55
|
name: options.name,
|
|
52
56
|
type: "open_api_agent",
|
|
53
57
|
inputs,
|
|
58
|
+
preloads,
|
|
59
|
+
memories,
|
|
54
60
|
outputs,
|
|
55
61
|
url: options.url,
|
|
56
62
|
method: options.method,
|
|
57
63
|
auth: options.auth,
|
|
58
|
-
}, context);
|
|
64
|
+
}, options.context);
|
|
59
65
|
}
|
|
@@ -1,63 +1,40 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
1
|
+
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { Runnable, RunnableDefinition, RunnableOutput, RunnableResponseDelta } from "./runnable";
|
|
3
|
+
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
+
import type { Runnable, RunnableInput, RunnableOutput, RunnableOutputType, RunnableResponseDelta } from "./runnable";
|
|
7
5
|
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
8
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
9
7
|
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> {
|
|
8
|
+
export declare class PipelineAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, AgentPreloads, Memories> {
|
|
17
9
|
definition: PipelineAgentDefinition;
|
|
18
10
|
static create: typeof create;
|
|
19
11
|
constructor(definition: PipelineAgentDefinition, context?: Context<State>);
|
|
20
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
12
|
+
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
21
13
|
}
|
|
22
14
|
type VariableWithPropPath = {
|
|
23
15
|
fromVariable: string;
|
|
24
16
|
fromVariablePropPath?: (string | number)[];
|
|
25
17
|
};
|
|
26
|
-
export type PipelineAgentProcessParameter<R extends Runnable =
|
|
27
|
-
[name: string]: DataTypeSchema;
|
|
28
|
-
} = ExtractRunnableInputType<R>> = {
|
|
18
|
+
export type PipelineAgentProcessParameter<R extends Runnable = Runnable, RI extends RunnableInput = ExtractRunnableInputType<R>> = {
|
|
29
19
|
runnable: R;
|
|
30
20
|
input: MakeNullablePropertyOptional<{
|
|
31
21
|
[key in keyof RI]: VariableWithPropPath;
|
|
32
22
|
}>;
|
|
33
23
|
};
|
|
34
|
-
declare function create<I extends {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
fromVariable: string;
|
|
39
|
-
fromVariablePropPath?: string[];
|
|
40
|
-
};
|
|
41
|
-
}, Memories extends {
|
|
42
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
43
|
-
}, State extends ContextState, Processes extends {
|
|
24
|
+
declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema<{
|
|
25
|
+
fromVariable: string;
|
|
26
|
+
fromVariablePropPath?: string[];
|
|
27
|
+
}>, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>, Processes extends {
|
|
44
28
|
[name: string]: PipelineAgentProcessParameter;
|
|
45
|
-
}>(
|
|
46
|
-
context: Context<State>;
|
|
47
|
-
name?: string;
|
|
48
|
-
inputs: I;
|
|
49
|
-
outputs: O;
|
|
50
|
-
memories?: Memories;
|
|
29
|
+
}>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
51
30
|
processes: Processes;
|
|
52
|
-
}): PipelineAgent<
|
|
53
|
-
|
|
54
|
-
}, State>;
|
|
55
|
-
export interface PipelineAgentDefinition extends RunnableDefinition {
|
|
31
|
+
}): PipelineAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
32
|
+
export interface PipelineAgentDefinition extends AgentDefinition {
|
|
56
33
|
type: "pipeline_agent";
|
|
57
34
|
processes?: OrderedRecord<PipelineAgentProcess>;
|
|
58
35
|
outputs: OrderedRecord<PipelineAgentOutput>;
|
|
59
36
|
}
|
|
60
|
-
export type PipelineAgentOutput =
|
|
37
|
+
export type PipelineAgentOutput = RunnableOutputType & {
|
|
61
38
|
from: "variable";
|
|
62
39
|
fromVariableId?: string;
|
|
63
40
|
fromVariablePropPath?: (string | number)[];
|
|
@@ -13,12 +13,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
import { get, isNil } from "lodash";
|
|
14
14
|
import { nanoid } from "nanoid";
|
|
15
15
|
import { inject, injectable } from "tsyringe";
|
|
16
|
-
import { Agent } from "./agent";
|
|
16
|
+
import { Agent, } from "./agent";
|
|
17
17
|
import { StreamTextOutputName, TYPES } from "./constants";
|
|
18
|
-
import { schemaToDataType
|
|
19
|
-
import { toRunnableMemories
|
|
20
|
-
import
|
|
18
|
+
import { schemaToDataType } from "./definitions/data-schema";
|
|
19
|
+
import { toRunnableMemories } from "./definitions/memory";
|
|
20
|
+
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
21
21
|
import { isNonNullable } from "./utils/is-non-nullable";
|
|
22
|
+
import { logger } from "./utils/logger";
|
|
22
23
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
23
24
|
let PipelineAgent = class PipelineAgent extends Agent {
|
|
24
25
|
definition;
|
|
@@ -138,9 +139,10 @@ PipelineAgent = __decorate([
|
|
|
138
139
|
__metadata("design:paramtypes", [Object, Object])
|
|
139
140
|
], PipelineAgent);
|
|
140
141
|
export { PipelineAgent };
|
|
141
|
-
function create(
|
|
142
|
+
function create(options) {
|
|
142
143
|
const agentId = options.name || nanoid();
|
|
143
144
|
const inputs = schemaToDataType(options.inputs);
|
|
145
|
+
const preloads = preloadCreatorsToPreloads(inputs, options.preloads);
|
|
144
146
|
const memories = toRunnableMemories(agentId, inputs, options.memories || {});
|
|
145
147
|
const processes = OrderedRecord.fromArray([]);
|
|
146
148
|
for (const [name, p] of Object.entries(options.processes)) {
|
|
@@ -190,8 +192,9 @@ function create({ context, ...options }) {
|
|
|
190
192
|
name: options.name,
|
|
191
193
|
type: "pipeline_agent",
|
|
192
194
|
inputs,
|
|
195
|
+
preloads,
|
|
193
196
|
memories,
|
|
194
197
|
outputs,
|
|
195
198
|
processes,
|
|
196
|
-
}, context);
|
|
199
|
+
}, options.context);
|
|
197
200
|
}
|
package/lib/esm/runnable.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { Context, ContextState } from "./context";
|
|
2
2
|
import type { DataType } from "./definitions/data-type";
|
|
3
|
-
import type { Memorable } from "./memorable";
|
|
4
3
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
5
4
|
export interface RunOptions {
|
|
6
5
|
stream?: boolean;
|
|
7
6
|
}
|
|
8
7
|
export type RunnableResponse<T> = T | RunnableResponseStream<T>;
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
[name: string]: any;
|
|
13
|
-
} = {}, State extends ContextState = ContextState> {
|
|
8
|
+
export type RunnableInput = Record<string, any>;
|
|
9
|
+
export type RunnableOutput = Record<string, any>;
|
|
10
|
+
export declare abstract class Runnable<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState> {
|
|
14
11
|
definition: RunnableDefinition;
|
|
15
12
|
context?: Context<State> | undefined;
|
|
16
13
|
constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
|
|
@@ -35,25 +32,11 @@ export interface RunnableDefinition {
|
|
|
35
32
|
type: string;
|
|
36
33
|
name?: string;
|
|
37
34
|
description?: string;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
outputs: OrderedRecord<RunnableOutput>;
|
|
35
|
+
inputs: OrderedRecord<RunnableInputType>;
|
|
36
|
+
outputs: OrderedRecord<RunnableOutputType>;
|
|
41
37
|
}
|
|
42
|
-
export
|
|
43
|
-
|
|
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;
|
|
38
|
+
export type RunnableInputType = DataType;
|
|
39
|
+
export type RunnableOutputType = DataType;
|
|
57
40
|
export interface RunnableResponseDelta<T> {
|
|
58
41
|
$text?: string;
|
|
59
42
|
delta?: Partial<T>;
|
|
@@ -1,48 +1,20 @@
|
|
|
1
|
-
import { Agent, type AgentProcessOptions } from "./agent";
|
|
1
|
+
import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, type AgentProcessInput, type AgentProcessOptions, type CreateAgentInputSchema, type CreateAgentMemoriesSchema, type CreateAgentMemoriesType, type CreateAgentOptions, type CreateAgentOutputSchema, type CreateAgentPreloadsSchema, type CreateAgentPreloadsType } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore } from "./memorable";
|
|
6
|
-
import type { RunnableDefinition } from "./runnable";
|
|
3
|
+
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
+
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
7
5
|
import type { SandboxFunctionRunner } from "./sandbox-function-runner";
|
|
8
|
-
export declare class SandboxFunctionAgent<I extends {
|
|
9
|
-
[name: string]: any;
|
|
10
|
-
} = {}, O extends {
|
|
11
|
-
[name: string]: any;
|
|
12
|
-
} = {}, Memories extends {
|
|
13
|
-
[name: string]: MemoryItemWithScore[];
|
|
14
|
-
} = {}, State extends ContextState = ContextState> extends Agent<I, O, Memories, State> {
|
|
6
|
+
export declare class SandboxFunctionAgent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<I, O, State, Preloads, Memories> {
|
|
15
7
|
definition: SandboxFunctionAgentDefinition;
|
|
16
|
-
runner?: SandboxFunctionRunner<I, O,
|
|
8
|
+
runner?: SandboxFunctionRunner<I, O, State, Preloads, Memories> | undefined;
|
|
17
9
|
static create: typeof create;
|
|
18
|
-
constructor(definition: SandboxFunctionAgentDefinition, context?: Context<State>, runner?: SandboxFunctionRunner<I, O,
|
|
19
|
-
process(input: I, options: AgentProcessOptions<Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
|
|
10
|
+
constructor(definition: SandboxFunctionAgentDefinition, context?: Context<State>, runner?: SandboxFunctionRunner<I, O, State, Preloads, Memories> | undefined);
|
|
11
|
+
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("./runnable").RunnableResponseStream<O>>;
|
|
20
12
|
}
|
|
21
|
-
export
|
|
22
|
-
[name: string]: DataTypeSchema;
|
|
23
|
-
}, O extends {
|
|
24
|
-
[name: string]: DataTypeSchema;
|
|
25
|
-
}, Memories extends {
|
|
26
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
27
|
-
}, State extends ContextState> {
|
|
28
|
-
context?: Context<State>;
|
|
29
|
-
name?: string;
|
|
30
|
-
inputs: I;
|
|
31
|
-
outputs: O;
|
|
32
|
-
memories?: Memories;
|
|
13
|
+
export declare function create<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I>>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
33
14
|
language?: string;
|
|
34
15
|
code: string;
|
|
35
|
-
}
|
|
36
|
-
export
|
|
37
|
-
[name: string]: DataTypeSchema;
|
|
38
|
-
}, O extends {
|
|
39
|
-
[name: string]: DataTypeSchema;
|
|
40
|
-
}, Memories extends {
|
|
41
|
-
[name: string]: CreateRunnableMemory<I>;
|
|
42
|
-
}, State extends ContextState>({ context, ...options }: CreateSandboxFunctionAgentOptions<I, O, Memories, State>): SandboxFunctionAgent<SchemaMapType<I>, SchemaMapType<O>, {
|
|
43
|
-
[name in keyof Memories]: MemorableSearchOutput<Memories[name]["memory"]>;
|
|
44
|
-
}, State>;
|
|
45
|
-
export interface SandboxFunctionAgentDefinition extends RunnableDefinition {
|
|
16
|
+
}): SandboxFunctionAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
17
|
+
export interface SandboxFunctionAgentDefinition extends AgentDefinition {
|
|
46
18
|
type: "sandbox_function_agent";
|
|
47
19
|
language?: string;
|
|
48
20
|
code?: string;
|
|
@@ -12,10 +12,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
};
|
|
13
13
|
import { nanoid } from "nanoid";
|
|
14
14
|
import { inject, injectable } from "tsyringe";
|
|
15
|
-
import { Agent } from "./agent";
|
|
15
|
+
import { Agent, } from "./agent";
|
|
16
16
|
import { TYPES } from "./constants";
|
|
17
|
-
import { schemaToDataType
|
|
18
|
-
import { toRunnableMemories
|
|
17
|
+
import { schemaToDataType } from "./definitions/data-schema";
|
|
18
|
+
import { toRunnableMemories } from "./definitions/memory";
|
|
19
|
+
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
19
20
|
let SandboxFunctionAgent = class SandboxFunctionAgent extends Agent {
|
|
20
21
|
definition;
|
|
21
22
|
runner;
|
|
@@ -39,6 +40,7 @@ let SandboxFunctionAgent = class SandboxFunctionAgent extends Agent {
|
|
|
39
40
|
language,
|
|
40
41
|
code,
|
|
41
42
|
input,
|
|
43
|
+
preloads: options.preloads,
|
|
42
44
|
memories: options.memories,
|
|
43
45
|
context: { state: context.state },
|
|
44
46
|
}, { stream: true });
|
|
@@ -52,10 +54,11 @@ SandboxFunctionAgent = __decorate([
|
|
|
52
54
|
__metadata("design:paramtypes", [Object, Object, Function])
|
|
53
55
|
], SandboxFunctionAgent);
|
|
54
56
|
export { SandboxFunctionAgent };
|
|
55
|
-
export function create(
|
|
57
|
+
export function create(options) {
|
|
56
58
|
const agentId = options.name || nanoid();
|
|
57
59
|
const inputs = schemaToDataType(options.inputs);
|
|
58
60
|
const outputs = schemaToDataType(options.outputs);
|
|
61
|
+
const preloads = preloadCreatorsToPreloads(inputs, options.preloads);
|
|
59
62
|
const memories = toRunnableMemories(agentId, inputs, options.memories ?? {});
|
|
60
63
|
return new SandboxFunctionAgent({
|
|
61
64
|
id: agentId,
|
|
@@ -63,8 +66,9 @@ export function create({ context, ...options }) {
|
|
|
63
66
|
type: "sandbox_function_agent",
|
|
64
67
|
inputs,
|
|
65
68
|
outputs,
|
|
69
|
+
preloads,
|
|
66
70
|
memories,
|
|
67
71
|
language: options.language,
|
|
68
72
|
code: options.code,
|
|
69
|
-
}, context);
|
|
73
|
+
}, options.context);
|
|
70
74
|
}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import { Agent } from "./agent";
|
|
1
|
+
import { Agent, type AgentMemories, type AgentPreloads } from "./agent";
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
|
-
import type {
|
|
4
|
-
export
|
|
5
|
-
[name: string]: any;
|
|
6
|
-
} = {}, Memories extends {
|
|
7
|
-
[name: string]: MemoryItemWithScore[];
|
|
8
|
-
} = {}, State extends ContextState = ContextState> {
|
|
3
|
+
import type { RunnableInput, RunnableOutput } from "./runnable";
|
|
4
|
+
export type SandboxFunctionRunnerInput<Input extends RunnableInput = RunnableInput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> = {
|
|
9
5
|
name: string;
|
|
10
6
|
language?: string;
|
|
11
7
|
code: string;
|
|
12
|
-
input:
|
|
8
|
+
input: Input;
|
|
9
|
+
preloads: Preloads;
|
|
13
10
|
memories: Memories;
|
|
14
11
|
context: Pick<Context<State>, "state">;
|
|
15
|
-
}
|
|
16
|
-
export type SandboxFunctionRunnerOutput<
|
|
17
|
-
export declare abstract class SandboxFunctionRunner<I extends {
|
|
18
|
-
[name: string]: any;
|
|
19
|
-
} = {}, O extends {
|
|
20
|
-
[name: string]: any;
|
|
21
|
-
} = {}, Memories extends {
|
|
22
|
-
[name: string]: MemoryItemWithScore[];
|
|
23
|
-
} = {}, State extends ContextState = ContextState> extends Agent<SandboxFunctionRunnerInput<I, Memories, State>, SandboxFunctionRunnerOutput<O>> {
|
|
12
|
+
};
|
|
13
|
+
export type SandboxFunctionRunnerOutput<Output extends RunnableOutput> = Output;
|
|
14
|
+
export declare abstract class SandboxFunctionRunner<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Agent<SandboxFunctionRunnerInput<I, State, Preloads, Memories>, SandboxFunctionRunnerOutput<O>> {
|
|
24
15
|
constructor(context?: Context);
|
|
25
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Agent } from "./agent";
|
|
1
|
+
import { Agent, } from "./agent";
|
|
2
2
|
import { OrderedRecord } from "./utils";
|
|
3
3
|
export class SandboxFunctionRunner extends Agent {
|
|
4
4
|
constructor(context) {
|
|
@@ -12,6 +12,7 @@ export class SandboxFunctionRunner extends Agent {
|
|
|
12
12
|
{ id: "language", name: "language", type: "string" },
|
|
13
13
|
{ id: "code", name: "code", type: "string", required: true },
|
|
14
14
|
{ id: "input", name: "input", type: "object", required: true },
|
|
15
|
+
{ id: "preloads", name: "preloads", type: "object", required: true },
|
|
15
16
|
{ id: "memories", name: "memories", type: "object", required: true },
|
|
16
17
|
{ id: "context", name: "context", type: "object", required: true },
|
|
17
18
|
]),
|
package/lib/esm/utils/index.d.ts
CHANGED
package/lib/esm/utils/index.js
CHANGED