@aigne/core 1.0.17 → 1.1.0-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.
- package/lib/cjs/agents/agent.d.ts +49 -0
- package/lib/cjs/agents/agent.js +92 -0
- package/lib/cjs/agents/ai-agent.d.ts +21 -0
- package/lib/cjs/agents/ai-agent.js +84 -0
- package/lib/cjs/agents/mcp-agent.d.ts +26 -0
- package/lib/cjs/agents/mcp-agent.js +75 -0
- package/lib/cjs/agents/types.d.ts +9 -0
- package/lib/cjs/agents/types.js +16 -0
- package/lib/cjs/execution-engine/context.d.ts +10 -0
- package/lib/cjs/execution-engine/index.d.ts +45 -0
- package/lib/cjs/execution-engine/index.js +190 -0
- package/lib/cjs/execution-engine/message-queue.d.ts +5 -0
- package/lib/cjs/execution-engine/message-queue.js +9 -0
- package/lib/cjs/index.d.ts +10 -21
- package/lib/cjs/index.js +10 -21
- package/lib/cjs/models/chat-openai.d.ts +14 -0
- package/lib/cjs/{llm-models/openai-llm-model.js → models/chat-openai.js} +58 -26
- package/lib/cjs/models/chat.d.ts +78 -0
- package/lib/cjs/models/chat.js +91 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +25 -0
- package/lib/cjs/prompt/prompt-builder.js +126 -0
- package/lib/cjs/prompt/template.d.ts +70 -0
- package/lib/cjs/prompt/template.js +172 -0
- package/lib/cjs/prompt/templates/instructions.d.ts +1 -0
- package/lib/cjs/prompt/templates/instructions.js +10 -0
- package/lib/cjs/utils/logger.js +1 -3
- package/lib/cjs/utils/type-utils.d.ts +5 -1
- package/lib/cjs/utils/type-utils.js +23 -0
- package/lib/dts/agents/agent.d.ts +49 -0
- package/lib/dts/agents/ai-agent.d.ts +21 -0
- package/lib/dts/agents/mcp-agent.d.ts +26 -0
- package/lib/dts/agents/types.d.ts +9 -0
- package/lib/dts/execution-engine/context.d.ts +10 -0
- package/lib/dts/execution-engine/index.d.ts +45 -0
- package/lib/dts/execution-engine/message-queue.d.ts +5 -0
- package/lib/dts/index.d.ts +10 -21
- package/lib/dts/models/chat-openai.d.ts +14 -0
- package/lib/dts/models/chat.d.ts +78 -0
- package/lib/dts/prompt/prompt-builder.d.ts +25 -0
- package/lib/dts/prompt/template.d.ts +70 -0
- package/lib/dts/prompt/templates/instructions.d.ts +1 -0
- package/lib/dts/utils/type-utils.d.ts +5 -1
- package/lib/esm/agents/agent.d.ts +49 -0
- package/lib/esm/agents/agent.js +84 -0
- package/lib/esm/agents/ai-agent.d.ts +21 -0
- package/lib/esm/agents/ai-agent.js +80 -0
- package/lib/esm/agents/mcp-agent.d.ts +26 -0
- package/lib/esm/agents/mcp-agent.js +70 -0
- package/lib/esm/agents/types.d.ts +9 -0
- package/lib/esm/agents/types.js +11 -0
- package/lib/esm/execution-engine/context.d.ts +10 -0
- package/lib/esm/execution-engine/index.d.ts +45 -0
- package/lib/esm/execution-engine/index.js +182 -0
- package/lib/esm/execution-engine/message-queue.d.ts +5 -0
- package/lib/esm/execution-engine/message-queue.js +5 -0
- package/lib/esm/index.d.ts +10 -21
- package/lib/esm/index.js +10 -21
- package/lib/esm/models/chat-openai.d.ts +14 -0
- package/lib/esm/{llm-models/openai-llm-model.js → models/chat-openai.js} +55 -23
- package/lib/esm/models/chat.d.ts +78 -0
- package/lib/esm/models/chat.js +87 -0
- package/lib/esm/prompt/prompt-builder.d.ts +25 -0
- package/lib/esm/prompt/prompt-builder.js +117 -0
- package/lib/esm/prompt/template.d.ts +70 -0
- package/lib/esm/prompt/template.js +158 -0
- package/lib/esm/prompt/templates/instructions.d.ts +1 -0
- package/lib/esm/prompt/templates/instructions.js +7 -0
- package/lib/esm/utils/logger.js +1 -3
- package/lib/esm/utils/type-utils.d.ts +5 -1
- package/lib/esm/utils/type-utils.js +17 -1
- package/package.json +14 -14
- package/lib/cjs/agent.d.ts +0 -96
- package/lib/cjs/agent.js +0 -165
- package/lib/cjs/constants.d.ts +0 -7
- package/lib/cjs/constants.js +0 -10
- package/lib/cjs/context.d.ts +0 -23
- package/lib/cjs/definitions/data-schema.d.ts +0 -61
- package/lib/cjs/definitions/data-schema.js +0 -47
- package/lib/cjs/definitions/data-type.d.ts +0 -32
- package/lib/cjs/definitions/data-type.js +0 -2
- package/lib/cjs/definitions/memory.d.ts +0 -53
- package/lib/cjs/definitions/memory.js +0 -23
- package/lib/cjs/definitions/open-api.d.ts +0 -36
- package/lib/cjs/definitions/open-api.js +0 -2
- package/lib/cjs/definitions/preload.d.ts +0 -43
- package/lib/cjs/definitions/preload.js +0 -34
- package/lib/cjs/function-agent.d.ts +0 -23
- package/lib/cjs/function-agent.js +0 -62
- package/lib/cjs/llm-agent.d.ts +0 -53
- package/lib/cjs/llm-agent.js +0 -140
- package/lib/cjs/llm-decision-agent.d.ts +0 -53
- package/lib/cjs/llm-decision-agent.js +0 -144
- package/lib/cjs/llm-model.d.ts +0 -80
- package/lib/cjs/llm-model.js +0 -27
- package/lib/cjs/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/cjs/llm-models/gemini-llm-model.js +0 -199
- package/lib/cjs/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/cjs/memorable.d.ts +0 -198
- package/lib/cjs/memorable.js +0 -33
- package/lib/cjs/open-api-agent.d.ts +0 -26
- package/lib/cjs/open-api-agent.js +0 -68
- package/lib/cjs/pipeline-agent.d.ts +0 -56
- package/lib/cjs/pipeline-agent.js +0 -206
- package/lib/cjs/runnable.d.ts +0 -76
- package/lib/cjs/runnable.js +0 -37
- package/lib/cjs/runtime.d.ts +0 -64
- package/lib/cjs/runtime.js +0 -149
- package/lib/cjs/sandbox-function-agent.d.ts +0 -21
- package/lib/cjs/sandbox-function-agent.js +0 -78
- package/lib/cjs/sandbox-function-runner.d.ts +0 -16
- package/lib/cjs/sandbox-function-runner.js +0 -32
- package/lib/cjs/utils/constants.d.ts +0 -1
- package/lib/cjs/utils/constants.js +0 -4
- package/lib/cjs/utils/fetch-open-api.d.ts +0 -2
- package/lib/cjs/utils/fetch-open-api.js +0 -31
- package/lib/cjs/utils/fetch.d.ts +0 -1
- package/lib/cjs/utils/fetch.js +0 -21
- package/lib/cjs/utils/index.d.ts +0 -12
- package/lib/cjs/utils/index.js +0 -28
- package/lib/cjs/utils/is-non-nullable.d.ts +0 -2
- package/lib/cjs/utils/is-non-nullable.js +0 -20
- package/lib/cjs/utils/message-utils.d.ts +0 -20
- package/lib/cjs/utils/message-utils.js +0 -79
- package/lib/cjs/utils/mustache-utils.d.ts +0 -3
- package/lib/cjs/utils/mustache-utils.js +0 -14
- package/lib/cjs/utils/nullable.d.ts +0 -7
- package/lib/cjs/utils/nullable.js +0 -2
- package/lib/cjs/utils/omit.d.ts +0 -1
- package/lib/cjs/utils/omit.js +0 -2
- package/lib/cjs/utils/open-api-parameter.d.ts +0 -7
- package/lib/cjs/utils/open-api-parameter.js +0 -81
- package/lib/cjs/utils/ordered-map.d.ts +0 -37
- package/lib/cjs/utils/ordered-map.js +0 -103
- package/lib/cjs/utils/partial.d.ts +0 -3
- package/lib/cjs/utils/partial.js +0 -2
- package/lib/cjs/utils/runnable-type.d.ts +0 -5
- package/lib/cjs/utils/runnable-type.js +0 -2
- package/lib/cjs/utils/stream-utils.d.ts +0 -20
- package/lib/cjs/utils/stream-utils.js +0 -86
- package/lib/cjs/utils/structured-output-schema.d.ts +0 -3
- package/lib/cjs/utils/structured-output-schema.js +0 -43
- package/lib/cjs/utils/union.d.ts +0 -1
- package/lib/cjs/utils/union.js +0 -2
- package/lib/dts/agent.d.ts +0 -96
- package/lib/dts/constants.d.ts +0 -7
- package/lib/dts/context.d.ts +0 -23
- package/lib/dts/definitions/data-schema.d.ts +0 -61
- package/lib/dts/definitions/data-type.d.ts +0 -32
- package/lib/dts/definitions/memory.d.ts +0 -53
- package/lib/dts/definitions/open-api.d.ts +0 -36
- package/lib/dts/definitions/preload.d.ts +0 -43
- package/lib/dts/function-agent.d.ts +0 -23
- package/lib/dts/llm-agent.d.ts +0 -53
- package/lib/dts/llm-decision-agent.d.ts +0 -53
- package/lib/dts/llm-model.d.ts +0 -80
- package/lib/dts/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/dts/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/dts/memorable.d.ts +0 -198
- package/lib/dts/open-api-agent.d.ts +0 -26
- package/lib/dts/pipeline-agent.d.ts +0 -56
- package/lib/dts/runnable.d.ts +0 -76
- package/lib/dts/runtime.d.ts +0 -64
- package/lib/dts/sandbox-function-agent.d.ts +0 -21
- package/lib/dts/sandbox-function-runner.d.ts +0 -16
- package/lib/dts/utils/constants.d.ts +0 -1
- package/lib/dts/utils/fetch-open-api.d.ts +0 -2
- package/lib/dts/utils/fetch.d.ts +0 -1
- package/lib/dts/utils/index.d.ts +0 -12
- package/lib/dts/utils/is-non-nullable.d.ts +0 -2
- package/lib/dts/utils/message-utils.d.ts +0 -20
- package/lib/dts/utils/mustache-utils.d.ts +0 -3
- package/lib/dts/utils/nullable.d.ts +0 -7
- package/lib/dts/utils/omit.d.ts +0 -1
- package/lib/dts/utils/open-api-parameter.d.ts +0 -7
- package/lib/dts/utils/ordered-map.d.ts +0 -37
- package/lib/dts/utils/partial.d.ts +0 -3
- package/lib/dts/utils/runnable-type.d.ts +0 -5
- package/lib/dts/utils/stream-utils.d.ts +0 -20
- package/lib/dts/utils/structured-output-schema.d.ts +0 -3
- package/lib/dts/utils/union.d.ts +0 -1
- package/lib/esm/agent.d.ts +0 -96
- package/lib/esm/agent.js +0 -161
- package/lib/esm/constants.d.ts +0 -7
- package/lib/esm/constants.js +0 -7
- package/lib/esm/context.d.ts +0 -23
- package/lib/esm/definitions/data-schema.d.ts +0 -61
- package/lib/esm/definitions/data-schema.js +0 -44
- package/lib/esm/definitions/data-type.d.ts +0 -32
- package/lib/esm/definitions/data-type.js +0 -1
- package/lib/esm/definitions/memory.d.ts +0 -53
- package/lib/esm/definitions/memory.js +0 -20
- package/lib/esm/definitions/open-api.d.ts +0 -36
- package/lib/esm/definitions/open-api.js +0 -1
- package/lib/esm/definitions/preload.d.ts +0 -43
- package/lib/esm/definitions/preload.js +0 -31
- package/lib/esm/function-agent.d.ts +0 -23
- package/lib/esm/function-agent.js +0 -59
- package/lib/esm/llm-agent.d.ts +0 -53
- package/lib/esm/llm-agent.js +0 -137
- package/lib/esm/llm-decision-agent.d.ts +0 -53
- package/lib/esm/llm-decision-agent.js +0 -141
- package/lib/esm/llm-model.d.ts +0 -80
- package/lib/esm/llm-model.js +0 -23
- package/lib/esm/llm-models/gemini-llm-model.d.ts +0 -24
- package/lib/esm/llm-models/gemini-llm-model.js +0 -195
- package/lib/esm/llm-models/openai-llm-model.d.ts +0 -26
- package/lib/esm/memorable.d.ts +0 -198
- package/lib/esm/memorable.js +0 -28
- package/lib/esm/open-api-agent.d.ts +0 -26
- package/lib/esm/open-api-agent.js +0 -65
- package/lib/esm/pipeline-agent.d.ts +0 -56
- package/lib/esm/pipeline-agent.js +0 -203
- package/lib/esm/runnable.d.ts +0 -76
- package/lib/esm/runnable.js +0 -30
- package/lib/esm/runtime.d.ts +0 -64
- package/lib/esm/runtime.js +0 -146
- package/lib/esm/sandbox-function-agent.d.ts +0 -21
- package/lib/esm/sandbox-function-agent.js +0 -74
- package/lib/esm/sandbox-function-runner.d.ts +0 -16
- package/lib/esm/sandbox-function-runner.js +0 -28
- package/lib/esm/utils/constants.d.ts +0 -1
- package/lib/esm/utils/constants.js +0 -1
- package/lib/esm/utils/fetch-open-api.d.ts +0 -2
- package/lib/esm/utils/fetch-open-api.js +0 -28
- package/lib/esm/utils/fetch.d.ts +0 -1
- package/lib/esm/utils/fetch.js +0 -18
- package/lib/esm/utils/index.d.ts +0 -12
- package/lib/esm/utils/index.js +0 -12
- package/lib/esm/utils/is-non-nullable.d.ts +0 -2
- package/lib/esm/utils/is-non-nullable.js +0 -13
- package/lib/esm/utils/message-utils.d.ts +0 -20
- package/lib/esm/utils/message-utils.js +0 -71
- package/lib/esm/utils/mustache-utils.d.ts +0 -3
- package/lib/esm/utils/mustache-utils.js +0 -8
- package/lib/esm/utils/nullable.d.ts +0 -7
- package/lib/esm/utils/nullable.js +0 -1
- package/lib/esm/utils/omit.d.ts +0 -1
- package/lib/esm/utils/omit.js +0 -1
- package/lib/esm/utils/open-api-parameter.d.ts +0 -7
- package/lib/esm/utils/open-api-parameter.js +0 -78
- package/lib/esm/utils/ordered-map.d.ts +0 -37
- package/lib/esm/utils/ordered-map.js +0 -100
- package/lib/esm/utils/partial.d.ts +0 -3
- package/lib/esm/utils/partial.js +0 -1
- package/lib/esm/utils/runnable-type.d.ts +0 -5
- package/lib/esm/utils/runnable-type.js +0 -1
- package/lib/esm/utils/stream-utils.d.ts +0 -20
- package/lib/esm/utils/stream-utils.js +0 -79
- package/lib/esm/utils/structured-output-schema.d.ts +0 -3
- package/lib/esm/utils/structured-output-schema.js +0 -37
- package/lib/esm/utils/union.d.ts +0 -1
- package/lib/esm/utils/union.js +0 -1
- /package/lib/cjs/{context.js → execution-engine/context.js} +0 -0
- /package/lib/esm/{context.js → execution-engine/context.js} +0 -0
package/lib/cjs/memorable.d.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import { Agent } from "./agent";
|
|
2
|
-
import type { Context } from "./context";
|
|
3
|
-
import type { LLMModelInputMessage } from "./llm-model";
|
|
4
|
-
import { Runnable } from "./runnable";
|
|
5
|
-
export type MemoryMetadata = Record<string, unknown>;
|
|
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
|
-
agentId?: string;
|
|
30
|
-
createdAt: string;
|
|
31
|
-
updatedAt: string;
|
|
32
|
-
memory: T;
|
|
33
|
-
metadata: MemoryMetadata;
|
|
34
|
-
}
|
|
35
|
-
export interface MemoryItemWithScore<T = unknown> extends MemoryItem<T> {
|
|
36
|
-
score: number;
|
|
37
|
-
}
|
|
38
|
-
export type MemoryMessage = LLMModelInputMessage;
|
|
39
|
-
export type MemoryActions<T> = {
|
|
40
|
-
action: "add";
|
|
41
|
-
inputs: {
|
|
42
|
-
messages: MemoryMessage[];
|
|
43
|
-
options?: {
|
|
44
|
-
userId?: string;
|
|
45
|
-
sessionId?: string;
|
|
46
|
-
agentId?: 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
|
-
agentId?: string;
|
|
62
|
-
filter?: MemoryMetadata;
|
|
63
|
-
sort?: MemorySortOptions;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
outputs: {
|
|
67
|
-
results: MemoryItemWithScore<T>[];
|
|
68
|
-
};
|
|
69
|
-
} | {
|
|
70
|
-
action: "filter";
|
|
71
|
-
inputs: {
|
|
72
|
-
options?: {
|
|
73
|
-
k?: number;
|
|
74
|
-
userId?: string;
|
|
75
|
-
sessionId?: string;
|
|
76
|
-
agentId?: string;
|
|
77
|
-
filter?: MemoryMetadata;
|
|
78
|
-
sort?: MemorySortOptions;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
outputs: {
|
|
82
|
-
results: MemoryItem<T>[];
|
|
83
|
-
};
|
|
84
|
-
} | {
|
|
85
|
-
action: "get";
|
|
86
|
-
inputs: {
|
|
87
|
-
memoryId: string;
|
|
88
|
-
};
|
|
89
|
-
outputs: {
|
|
90
|
-
result: MemoryItem<T> | null;
|
|
91
|
-
};
|
|
92
|
-
} | {
|
|
93
|
-
action: "create";
|
|
94
|
-
inputs: {
|
|
95
|
-
memory: T;
|
|
96
|
-
options?: {
|
|
97
|
-
userId?: string;
|
|
98
|
-
sessionId?: string;
|
|
99
|
-
agentId?: string;
|
|
100
|
-
metadata?: MemoryMetadata;
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
outputs: {
|
|
104
|
-
result: MemoryItem<T>;
|
|
105
|
-
};
|
|
106
|
-
} | {
|
|
107
|
-
action: "update";
|
|
108
|
-
inputs: {
|
|
109
|
-
memoryId: string;
|
|
110
|
-
memory: T;
|
|
111
|
-
};
|
|
112
|
-
outputs: {
|
|
113
|
-
result: MemoryItem<T> | null;
|
|
114
|
-
};
|
|
115
|
-
} | {
|
|
116
|
-
action: "delete";
|
|
117
|
-
inputs: {
|
|
118
|
-
filter: string | string[] | Record<string, unknown>;
|
|
119
|
-
};
|
|
120
|
-
outputs: {
|
|
121
|
-
[name: string]: never;
|
|
122
|
-
};
|
|
123
|
-
} | {
|
|
124
|
-
action: "reset";
|
|
125
|
-
inputs: {
|
|
126
|
-
[name: string]: never;
|
|
127
|
-
};
|
|
128
|
-
outputs: {
|
|
129
|
-
[name: string]: never;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
export interface SortItem {
|
|
133
|
-
field: string;
|
|
134
|
-
direction: "asc" | "desc";
|
|
135
|
-
}
|
|
136
|
-
export type MemorySortOptions = SortItem | SortItem[];
|
|
137
|
-
export declare abstract class Memorable<T, C extends Record<string, any> = Record<string, any>> extends Runnable<MemoryActions<T>, MemoryActions<T>["outputs"]> {
|
|
138
|
-
constructor(context?: Context);
|
|
139
|
-
abstract runner?: MemoryRunner<T, C>;
|
|
140
|
-
abstract add(messages: Extract<MemoryActions<T>, {
|
|
141
|
-
action: "add";
|
|
142
|
-
}>["inputs"]["messages"], options?: Extract<MemoryActions<T>, {
|
|
143
|
-
action: "add";
|
|
144
|
-
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
145
|
-
action: "add";
|
|
146
|
-
}>["outputs"]>;
|
|
147
|
-
abstract search(query: Extract<MemoryActions<T>, {
|
|
148
|
-
action: "search";
|
|
149
|
-
}>["inputs"]["query"], options?: Extract<MemoryActions<T>, {
|
|
150
|
-
action: "search";
|
|
151
|
-
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
152
|
-
action: "search";
|
|
153
|
-
}>["outputs"]>;
|
|
154
|
-
abstract filter(options: Extract<MemoryActions<T>, {
|
|
155
|
-
action: "filter";
|
|
156
|
-
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
157
|
-
action: "filter";
|
|
158
|
-
}>["outputs"]>;
|
|
159
|
-
abstract get(memoryId: Extract<MemoryActions<T>, {
|
|
160
|
-
action: "get";
|
|
161
|
-
}>["inputs"]["memoryId"]): Promise<Extract<MemoryActions<T>, {
|
|
162
|
-
action: "get";
|
|
163
|
-
}>["outputs"]>;
|
|
164
|
-
abstract create(memory: Extract<MemoryActions<T>, {
|
|
165
|
-
action: "create";
|
|
166
|
-
}>["inputs"]["memory"], options?: Extract<MemoryActions<T>, {
|
|
167
|
-
action: "create";
|
|
168
|
-
}>["inputs"]["options"]): Promise<Extract<MemoryActions<T>, {
|
|
169
|
-
action: "create";
|
|
170
|
-
}>["outputs"]>;
|
|
171
|
-
abstract update(memoryId: Extract<MemoryActions<T>, {
|
|
172
|
-
action: "update";
|
|
173
|
-
}>["inputs"]["memoryId"], memory: T): Promise<Extract<MemoryActions<T>, {
|
|
174
|
-
action: "update";
|
|
175
|
-
}>["outputs"]>;
|
|
176
|
-
abstract delete(memoryId: Extract<MemoryActions<T>, {
|
|
177
|
-
action: "delete";
|
|
178
|
-
}>["inputs"]["filter"]): Promise<Extract<MemoryActions<T>, {
|
|
179
|
-
action: "delete";
|
|
180
|
-
}>["outputs"]>;
|
|
181
|
-
abstract reset(): Promise<void>;
|
|
182
|
-
}
|
|
183
|
-
export type MemoryRunnerInput<C extends Record<string, any> = Record<string, any>> = {
|
|
184
|
-
messages: MemoryMessage[];
|
|
185
|
-
userId?: string;
|
|
186
|
-
sessionId?: string;
|
|
187
|
-
agentId?: string;
|
|
188
|
-
metadata?: MemoryMetadata;
|
|
189
|
-
filter?: MemoryMetadata;
|
|
190
|
-
customData: C;
|
|
191
|
-
};
|
|
192
|
-
export type MemoryRunnerOutput<T> = {
|
|
193
|
-
actions: MemoryActionItem<T>[];
|
|
194
|
-
};
|
|
195
|
-
export declare abstract class MemoryRunner<T, C extends Record<string, any> = Record<string, any>> extends Agent<MemoryRunnerInput<C>, MemoryRunnerOutput<T>> {
|
|
196
|
-
constructor(name: string);
|
|
197
|
-
}
|
|
198
|
-
export type MemorableSearchOutput<T extends Memorable<unknown>> = Awaited<ReturnType<T["search"]>>["results"];
|
package/lib/cjs/memorable.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryRunner = exports.Memorable = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const agent_1 = require("./agent");
|
|
6
|
-
const runnable_1 = require("./runnable");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
class Memorable extends runnable_1.Runnable {
|
|
9
|
-
constructor(context) {
|
|
10
|
-
super({
|
|
11
|
-
id: "memory",
|
|
12
|
-
type: "memory",
|
|
13
|
-
name: "Memory",
|
|
14
|
-
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
15
|
-
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
16
|
-
}, context);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.Memorable = Memorable;
|
|
20
|
-
class MemoryRunner extends agent_1.Agent {
|
|
21
|
-
constructor(name) {
|
|
22
|
-
const id = `${(0, lodash_1.camelCase)(name)}_runner`;
|
|
23
|
-
super({
|
|
24
|
-
id,
|
|
25
|
-
type: id,
|
|
26
|
-
name: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
27
|
-
description: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
28
|
-
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
29
|
-
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.MemoryRunner = MemoryRunner;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
import type { Context, ContextState } from "./context";
|
|
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";
|
|
6
|
-
import type { OrderedRecord } from "./utils";
|
|
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> {
|
|
8
|
-
definition: OpenAPIAgentDefinition;
|
|
9
|
-
static create: typeof create;
|
|
10
|
-
constructor(definition: OpenAPIAgentDefinition, context?: Context<State>);
|
|
11
|
-
process(input: AgentProcessInput<I, Preloads, Memories>): Promise<O>;
|
|
12
|
-
fetch<T>(request: FetchRequest): Promise<T>;
|
|
13
|
-
}
|
|
14
|
-
export interface OpenAPIAgentDefinition extends AgentDefinition {
|
|
15
|
-
type: "open_api_agent";
|
|
16
|
-
inputs: OrderedRecord<OpenAPIDataType>;
|
|
17
|
-
url: string;
|
|
18
|
-
method?: HTTPMethod;
|
|
19
|
-
auth?: AuthConfig;
|
|
20
|
-
}
|
|
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> & {
|
|
22
|
-
url: string;
|
|
23
|
-
method?: HTTPMethod;
|
|
24
|
-
auth?: AuthConfig;
|
|
25
|
-
}): OpenAPIAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
26
|
-
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.OpenAPIAgent = void 0;
|
|
16
|
-
const nanoid_1 = require("nanoid");
|
|
17
|
-
const tsyringe_1 = require("tsyringe");
|
|
18
|
-
const agent_1 = require("./agent");
|
|
19
|
-
const constants_1 = require("./constants");
|
|
20
|
-
const data_schema_1 = require("./definitions/data-schema");
|
|
21
|
-
const memory_1 = require("./definitions/memory");
|
|
22
|
-
const preload_1 = require("./definitions/preload");
|
|
23
|
-
const fetch_open_api_1 = require("./utils/fetch-open-api");
|
|
24
|
-
const open_api_parameter_1 = require("./utils/open-api-parameter");
|
|
25
|
-
let OpenAPIAgent = class OpenAPIAgent extends agent_1.Agent {
|
|
26
|
-
definition;
|
|
27
|
-
static create = create;
|
|
28
|
-
constructor(definition, context) {
|
|
29
|
-
super(definition, context);
|
|
30
|
-
this.definition = definition;
|
|
31
|
-
}
|
|
32
|
-
async process(input) {
|
|
33
|
-
const { url, method = "get", auth, inputs } = this.definition;
|
|
34
|
-
if (!url)
|
|
35
|
-
throw new Error("API url is required");
|
|
36
|
-
const request = await (0, open_api_parameter_1.formatOpenAPIRequest)({ url, method, auth }, inputs, input);
|
|
37
|
-
return this.fetch(request);
|
|
38
|
-
}
|
|
39
|
-
async fetch(request) {
|
|
40
|
-
return (0, fetch_open_api_1.fetchOpenApi)(request);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.OpenAPIAgent = OpenAPIAgent;
|
|
44
|
-
exports.OpenAPIAgent = OpenAPIAgent = __decorate([
|
|
45
|
-
(0, tsyringe_1.injectable)(),
|
|
46
|
-
__param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
|
|
47
|
-
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
48
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
49
|
-
], OpenAPIAgent);
|
|
50
|
-
function create(options) {
|
|
51
|
-
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
52
|
-
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
53
|
-
const outputs = (0, data_schema_1.schemaToDataType)(options.outputs);
|
|
54
|
-
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
55
|
-
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
|
|
56
|
-
return new OpenAPIAgent({
|
|
57
|
-
id: agentId,
|
|
58
|
-
name: options.name,
|
|
59
|
-
type: "open_api_agent",
|
|
60
|
-
inputs,
|
|
61
|
-
preloads,
|
|
62
|
-
memories,
|
|
63
|
-
outputs,
|
|
64
|
-
url: options.url,
|
|
65
|
-
method: options.method,
|
|
66
|
-
auth: options.auth,
|
|
67
|
-
}, options.context);
|
|
68
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
-
import type { Context, ContextState } from "./context";
|
|
3
|
-
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import { type Runnable, type RunnableInput, type RunnableOutput, type RunnableOutputType, type RunnableResponseDelta } from "./runnable";
|
|
5
|
-
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
6
|
-
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
|
-
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
|
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> {
|
|
9
|
-
definition: PipelineAgentDefinition;
|
|
10
|
-
static create: typeof create;
|
|
11
|
-
constructor(definition: PipelineAgentDefinition, context?: Context<State>);
|
|
12
|
-
process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions<Preloads, Memories>): Promise<import("stream/web").ReadableStream<RunnableResponseDelta<O>>>;
|
|
13
|
-
}
|
|
14
|
-
type VariableWithPropPath = {
|
|
15
|
-
fromVariable: string;
|
|
16
|
-
fromVariablePropPath?: (string | number)[];
|
|
17
|
-
};
|
|
18
|
-
export type PipelineAgentProcessParameter<R extends Runnable = Runnable, RI extends RunnableInput = ExtractRunnableInputType<R>> = {
|
|
19
|
-
runnable: R;
|
|
20
|
-
input: MakeNullablePropertyOptional<{
|
|
21
|
-
[key in keyof RI]: VariableWithPropPath;
|
|
22
|
-
}>;
|
|
23
|
-
};
|
|
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 {
|
|
28
|
-
[name: string]: PipelineAgentProcessParameter;
|
|
29
|
-
}>(options: CreateAgentOptions<I, O, State, Preloads, Memories> & {
|
|
30
|
-
processes: Processes;
|
|
31
|
-
}): PipelineAgent<SchemaToType<I>, SchemaToType<O>, State, CreateAgentPreloadsType<I, Preloads>, CreateAgentMemoriesType<I, Memories>>;
|
|
32
|
-
export interface PipelineAgentDefinition extends AgentDefinition {
|
|
33
|
-
type: "pipeline_agent";
|
|
34
|
-
processes?: OrderedRecord<PipelineAgentProcess>;
|
|
35
|
-
outputs: OrderedRecord<PipelineAgentOutput>;
|
|
36
|
-
}
|
|
37
|
-
export type PipelineAgentOutput = RunnableOutputType & {
|
|
38
|
-
from: "variable";
|
|
39
|
-
fromVariableId?: string;
|
|
40
|
-
fromVariablePropPath?: (string | number)[];
|
|
41
|
-
};
|
|
42
|
-
export type PipelineAgentProcess = {
|
|
43
|
-
id: string;
|
|
44
|
-
name?: string;
|
|
45
|
-
runnable?: {
|
|
46
|
-
id?: string;
|
|
47
|
-
};
|
|
48
|
-
input?: {
|
|
49
|
-
[inputId: string]: {
|
|
50
|
-
from: "variable";
|
|
51
|
-
fromVariableId?: string;
|
|
52
|
-
fromVariablePropPath?: (string | number | symbol)[];
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
export {};
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.PipelineAgent = void 0;
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
17
|
-
const nanoid_1 = require("nanoid");
|
|
18
|
-
const tsyringe_1 = require("tsyringe");
|
|
19
|
-
const agent_1 = require("./agent");
|
|
20
|
-
const constants_1 = require("./constants");
|
|
21
|
-
const data_schema_1 = require("./definitions/data-schema");
|
|
22
|
-
const memory_1 = require("./definitions/memory");
|
|
23
|
-
const preload_1 = require("./definitions/preload");
|
|
24
|
-
const runnable_1 = require("./runnable");
|
|
25
|
-
const is_non_nullable_1 = require("./utils/is-non-nullable");
|
|
26
|
-
const logger_1 = require("./utils/logger");
|
|
27
|
-
const ordered_map_1 = require("./utils/ordered-map");
|
|
28
|
-
let PipelineAgent = class PipelineAgent extends agent_1.Agent {
|
|
29
|
-
definition;
|
|
30
|
-
static create = create;
|
|
31
|
-
constructor(definition, context) {
|
|
32
|
-
super(definition, context);
|
|
33
|
-
this.definition = definition;
|
|
34
|
-
}
|
|
35
|
-
async process(input, options) {
|
|
36
|
-
const { definition, context } = this;
|
|
37
|
-
if (!context)
|
|
38
|
-
throw new Error("Context is required");
|
|
39
|
-
const { processes } = definition;
|
|
40
|
-
if (!processes?.$indexes.length) {
|
|
41
|
-
throw new Error("No processes defined");
|
|
42
|
-
}
|
|
43
|
-
return new ReadableStream({
|
|
44
|
-
async start(controller) {
|
|
45
|
-
try {
|
|
46
|
-
// NOTE: 将 input 转换为 variables,其中 key 为 inputId,value 为 input 的值
|
|
47
|
-
const variables = {
|
|
48
|
-
...options.memories,
|
|
49
|
-
...Object.fromEntries(ordered_map_1.OrderedRecord.map(definition.inputs, (i) => {
|
|
50
|
-
const value = input[i.name || i.id];
|
|
51
|
-
if ((0, lodash_1.isNil)(value))
|
|
52
|
-
return null;
|
|
53
|
-
return [i.id, value];
|
|
54
|
-
}).filter(is_non_nullable_1.isNonNullable)),
|
|
55
|
-
};
|
|
56
|
-
const outputs = ordered_map_1.OrderedRecord.toArray(definition.outputs);
|
|
57
|
-
const textStreamOutput = outputs.find((i) => i.name === constants_1.StreamTextOutputName);
|
|
58
|
-
let result = {};
|
|
59
|
-
for (const process of ordered_map_1.OrderedRecord.iterator(processes)) {
|
|
60
|
-
if (!process.runnable?.id) {
|
|
61
|
-
logger_1.logger.warn("Runnable id is required for process", process);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const runnable = await context.resolve(process.runnable.id);
|
|
65
|
-
if (!runnable)
|
|
66
|
-
continue;
|
|
67
|
-
const inputValues = Object.fromEntries(Object.entries(process.input ?? {})
|
|
68
|
-
.map(([inputId, input]) => {
|
|
69
|
-
const targetInput = runnable.definition.inputs?.[inputId];
|
|
70
|
-
if (!targetInput?.name)
|
|
71
|
-
return null;
|
|
72
|
-
let value;
|
|
73
|
-
if (input.from === "variable") {
|
|
74
|
-
const v = variables[input.fromVariableId];
|
|
75
|
-
value = input.fromVariablePropPath?.length
|
|
76
|
-
? (0, lodash_1.get)(v, input.fromVariablePropPath)
|
|
77
|
-
: v;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
throw new Error("Unsupported input source");
|
|
81
|
-
}
|
|
82
|
-
return [targetInput.name, value];
|
|
83
|
-
})
|
|
84
|
-
.filter(is_non_nullable_1.isNonNullable));
|
|
85
|
-
const stream = await runnable.run(inputValues, { stream: true });
|
|
86
|
-
const needRespondTextStream = textStreamOutput?.from === "variable" &&
|
|
87
|
-
textStreamOutput.fromVariableId === process.id;
|
|
88
|
-
// const needRespondJsonStream = outputs.some(
|
|
89
|
-
// (i) => i.name !== StreamTextOutputName && i.from === 'variable' && i.fromVariableId === process.id
|
|
90
|
-
// );
|
|
91
|
-
const processResult = {};
|
|
92
|
-
variables[process.id] = processResult;
|
|
93
|
-
for await (const chunk of stream) {
|
|
94
|
-
if ((0, runnable_1.isRunnableResponseDelta)(chunk)) {
|
|
95
|
-
if (chunk.$text) {
|
|
96
|
-
Object.assign(processResult, {
|
|
97
|
-
$text: (processResult.$text || "") + chunk.$text,
|
|
98
|
-
});
|
|
99
|
-
if (needRespondTextStream) {
|
|
100
|
-
controller.enqueue({ $text: chunk.$text });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (chunk.delta) {
|
|
104
|
-
Object.assign(processResult, chunk.delta);
|
|
105
|
-
// TODO: 这里需要考虑上层 agent 直接输出了 {$text: 'xxx'} 没有用 chunk 的方式返回的情况
|
|
106
|
-
// if (needRespondJsonStream) {
|
|
107
|
-
result = Object.fromEntries(ordered_map_1.OrderedRecord.map(definition.outputs, (output) => {
|
|
108
|
-
if (!output.name)
|
|
109
|
-
return null;
|
|
110
|
-
if (output.name === constants_1.StreamTextOutputName)
|
|
111
|
-
return null;
|
|
112
|
-
let value;
|
|
113
|
-
if (output.from === "variable") {
|
|
114
|
-
const v = variables[output.fromVariableId];
|
|
115
|
-
value = output.fromVariablePropPath?.length
|
|
116
|
-
? (0, lodash_1.get)(v, output.fromVariablePropPath)
|
|
117
|
-
: v;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
throw new Error(`Unsupported output source ${output.from}`);
|
|
121
|
-
}
|
|
122
|
-
return [output.name, value];
|
|
123
|
-
}).filter(is_non_nullable_1.isNonNullable));
|
|
124
|
-
controller.enqueue({ delta: result });
|
|
125
|
-
// }
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
controller.error(error);
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
controller.close();
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
exports.PipelineAgent = PipelineAgent;
|
|
142
|
-
exports.PipelineAgent = PipelineAgent = __decorate([
|
|
143
|
-
(0, tsyringe_1.injectable)(),
|
|
144
|
-
__param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
|
|
145
|
-
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
146
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
147
|
-
], PipelineAgent);
|
|
148
|
-
function create(options) {
|
|
149
|
-
const agentId = options.name || (0, nanoid_1.nanoid)();
|
|
150
|
-
const inputs = (0, data_schema_1.schemaToDataType)(options.inputs);
|
|
151
|
-
const preloads = (0, preload_1.preloadCreatorsToPreloads)(inputs, options.preloads);
|
|
152
|
-
const memories = (0, memory_1.toRunnableMemories)(agentId, inputs, options.memories || {});
|
|
153
|
-
const processes = ordered_map_1.OrderedRecord.fromArray([]);
|
|
154
|
-
for (const [name, p] of Object.entries(options.processes)) {
|
|
155
|
-
ordered_map_1.OrderedRecord.push(processes, {
|
|
156
|
-
id: (0, nanoid_1.nanoid)(),
|
|
157
|
-
name: name || p.runnable?.name,
|
|
158
|
-
runnable: { id: p.runnable.id },
|
|
159
|
-
input: Object.fromEntries(ordered_map_1.OrderedRecord.map(p.runnable.definition.inputs, (inputOfProcess) => {
|
|
160
|
-
const i = p.input[inputOfProcess.name || inputOfProcess.id];
|
|
161
|
-
if (!i) {
|
|
162
|
-
if (inputOfProcess.required) {
|
|
163
|
-
throw new Error(`Input ${inputOfProcess.name || inputOfProcess.id} for case ${p.runnable.name || p.runnable.id} is required`);
|
|
164
|
-
}
|
|
165
|
-
// ignore optional input
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
const inputFromPipeline = ordered_map_1.OrderedRecord.find(inputs, (input) => input.name === i.fromVariable) ||
|
|
169
|
-
ordered_map_1.OrderedRecord.find(processes, (p) => p.name === i.fromVariable);
|
|
170
|
-
if (!inputFromPipeline)
|
|
171
|
-
throw new Error(`Input ${i.fromVariable.toString()} not found`);
|
|
172
|
-
return [
|
|
173
|
-
inputOfProcess.id,
|
|
174
|
-
{
|
|
175
|
-
from: "variable",
|
|
176
|
-
fromVariableId: inputFromPipeline.id,
|
|
177
|
-
fromVariablePropPath: i.fromVariablePropPath,
|
|
178
|
-
},
|
|
179
|
-
];
|
|
180
|
-
}).filter(is_non_nullable_1.isNonNullable)),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
const outputs = ordered_map_1.OrderedRecord.fromArray(ordered_map_1.OrderedRecord.map((0, data_schema_1.schemaToDataType)(options.outputs), (output) => {
|
|
184
|
-
const { fromVariable, fromVariablePropPath } = options.outputs[output.name];
|
|
185
|
-
const from = ordered_map_1.OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
|
|
186
|
-
ordered_map_1.OrderedRecord.find(processes, (p) => p.name === fromVariable);
|
|
187
|
-
if (!from)
|
|
188
|
-
throw new Error(`Output ${output.name} not found in inputs or processes`);
|
|
189
|
-
return {
|
|
190
|
-
...output,
|
|
191
|
-
from: "variable",
|
|
192
|
-
fromVariableId: from.id,
|
|
193
|
-
fromVariablePropPath,
|
|
194
|
-
};
|
|
195
|
-
}));
|
|
196
|
-
return new PipelineAgent({
|
|
197
|
-
id: agentId,
|
|
198
|
-
name: options.name,
|
|
199
|
-
type: "pipeline_agent",
|
|
200
|
-
inputs,
|
|
201
|
-
preloads,
|
|
202
|
-
memories,
|
|
203
|
-
outputs,
|
|
204
|
-
processes,
|
|
205
|
-
}, options.context);
|
|
206
|
-
}
|
package/lib/cjs/runnable.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { Context, ContextState } from "./context";
|
|
2
|
-
import type { DataType } from "./definitions/data-type";
|
|
3
|
-
import { OrderedRecord } from "./utils/ordered-map";
|
|
4
|
-
export interface RunOptions {
|
|
5
|
-
stream?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export type RunnableResponse<T> = T | RunnableResponseStream<T>;
|
|
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> {
|
|
11
|
-
definition: RunnableDefinition;
|
|
12
|
-
context?: Context<State> | undefined;
|
|
13
|
-
constructor(definition: RunnableDefinition, context?: Context<State> | undefined);
|
|
14
|
-
get id(): string;
|
|
15
|
-
get name(): string | undefined;
|
|
16
|
-
inputs: {
|
|
17
|
-
[key in keyof I]: DataType;
|
|
18
|
-
};
|
|
19
|
-
outputs: {
|
|
20
|
-
[key in keyof O]: DataType;
|
|
21
|
-
};
|
|
22
|
-
abstract run(input: I, options: RunOptions & {
|
|
23
|
-
stream: true;
|
|
24
|
-
}): Promise<RunnableResponseStream<O>>;
|
|
25
|
-
abstract run(input: I, options?: RunOptions & {
|
|
26
|
-
stream?: false;
|
|
27
|
-
}): Promise<O>;
|
|
28
|
-
abstract run(input: I, options?: RunOptions): Promise<RunnableResponse<O>>;
|
|
29
|
-
}
|
|
30
|
-
export interface RunnableDefinition {
|
|
31
|
-
id: string;
|
|
32
|
-
type: string;
|
|
33
|
-
name?: string;
|
|
34
|
-
description?: string;
|
|
35
|
-
inputs: OrderedRecord<RunnableInputType>;
|
|
36
|
-
outputs: OrderedRecord<RunnableOutputType>;
|
|
37
|
-
}
|
|
38
|
-
export type RunnableInputType = DataType;
|
|
39
|
-
export type RunnableOutputType = DataType;
|
|
40
|
-
export interface RunnableResponseDelta<T> {
|
|
41
|
-
$text?: string;
|
|
42
|
-
delta?: Partial<T>;
|
|
43
|
-
}
|
|
44
|
-
export interface RunnableResponseProgress {
|
|
45
|
-
progress: {
|
|
46
|
-
taskId: string;
|
|
47
|
-
time: string;
|
|
48
|
-
agent: {
|
|
49
|
-
id: string;
|
|
50
|
-
name?: string;
|
|
51
|
-
description?: string;
|
|
52
|
-
};
|
|
53
|
-
payload: {
|
|
54
|
-
type: "start";
|
|
55
|
-
input: {
|
|
56
|
-
[key: string]: any;
|
|
57
|
-
};
|
|
58
|
-
} | {
|
|
59
|
-
type: "end";
|
|
60
|
-
output: {
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export interface RunnableResponseError {
|
|
67
|
-
error: {
|
|
68
|
-
message: string;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
export type RunnableResponseChunk<T> = RunnableResponseDelta<T> | RunnableResponseProgress;
|
|
72
|
-
export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
|
|
73
|
-
export declare function isRunnableResponseDelta<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseDelta<T>;
|
|
74
|
-
export declare function isRunnableResponseProgress<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseProgress;
|
|
75
|
-
export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
|
|
76
|
-
export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
|