@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/esm/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/esm/memorable.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { camelCase, startCase } from "lodash";
|
|
2
|
-
import { Agent } from "./agent";
|
|
3
|
-
import { Runnable } from "./runnable";
|
|
4
|
-
import { OrderedRecord } from "./utils";
|
|
5
|
-
export class Memorable extends Runnable {
|
|
6
|
-
constructor(context) {
|
|
7
|
-
super({
|
|
8
|
-
id: "memory",
|
|
9
|
-
type: "memory",
|
|
10
|
-
name: "Memory",
|
|
11
|
-
inputs: OrderedRecord.fromArray([]),
|
|
12
|
-
outputs: OrderedRecord.fromArray([]),
|
|
13
|
-
}, context);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class MemoryRunner extends Agent {
|
|
17
|
-
constructor(name) {
|
|
18
|
-
const id = `${camelCase(name)}_runner`;
|
|
19
|
-
super({
|
|
20
|
-
id,
|
|
21
|
-
type: id,
|
|
22
|
-
name: `${startCase(name)} Runner`,
|
|
23
|
-
description: `${startCase(name)} Runner`,
|
|
24
|
-
inputs: OrderedRecord.fromArray([]),
|
|
25
|
-
outputs: OrderedRecord.fromArray([]),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -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,65 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { nanoid } from "nanoid";
|
|
14
|
-
import { inject, injectable } from "tsyringe";
|
|
15
|
-
import { Agent, } from "./agent";
|
|
16
|
-
import { TYPES } from "./constants";
|
|
17
|
-
import { schemaToDataType } from "./definitions/data-schema";
|
|
18
|
-
import { toRunnableMemories } from "./definitions/memory";
|
|
19
|
-
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
20
|
-
import { fetchOpenApi } from "./utils/fetch-open-api";
|
|
21
|
-
import { formatOpenAPIRequest } from "./utils/open-api-parameter";
|
|
22
|
-
let OpenAPIAgent = class OpenAPIAgent extends Agent {
|
|
23
|
-
definition;
|
|
24
|
-
static create = create;
|
|
25
|
-
constructor(definition, context) {
|
|
26
|
-
super(definition, context);
|
|
27
|
-
this.definition = definition;
|
|
28
|
-
}
|
|
29
|
-
async process(input) {
|
|
30
|
-
const { url, method = "get", auth, inputs } = this.definition;
|
|
31
|
-
if (!url)
|
|
32
|
-
throw new Error("API url is required");
|
|
33
|
-
const request = await formatOpenAPIRequest({ url, method, auth }, inputs, input);
|
|
34
|
-
return this.fetch(request);
|
|
35
|
-
}
|
|
36
|
-
async fetch(request) {
|
|
37
|
-
return fetchOpenApi(request);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
OpenAPIAgent = __decorate([
|
|
41
|
-
injectable(),
|
|
42
|
-
__param(0, inject(TYPES.definition)),
|
|
43
|
-
__param(1, inject(TYPES.context)),
|
|
44
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
45
|
-
], OpenAPIAgent);
|
|
46
|
-
export { OpenAPIAgent };
|
|
47
|
-
function create(options) {
|
|
48
|
-
const agentId = options.name || nanoid();
|
|
49
|
-
const inputs = schemaToDataType(options.inputs);
|
|
50
|
-
const outputs = schemaToDataType(options.outputs);
|
|
51
|
-
const preloads = preloadCreatorsToPreloads(inputs, options.preloads);
|
|
52
|
-
const memories = toRunnableMemories(agentId, inputs, options.memories || {});
|
|
53
|
-
return new OpenAPIAgent({
|
|
54
|
-
id: agentId,
|
|
55
|
-
name: options.name,
|
|
56
|
-
type: "open_api_agent",
|
|
57
|
-
inputs,
|
|
58
|
-
preloads,
|
|
59
|
-
memories,
|
|
60
|
-
outputs,
|
|
61
|
-
url: options.url,
|
|
62
|
-
method: options.method,
|
|
63
|
-
auth: options.auth,
|
|
64
|
-
}, options.context);
|
|
65
|
-
}
|
|
@@ -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,203 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { get, isNil } from "lodash";
|
|
14
|
-
import { nanoid } from "nanoid";
|
|
15
|
-
import { inject, injectable } from "tsyringe";
|
|
16
|
-
import { Agent, } from "./agent";
|
|
17
|
-
import { StreamTextOutputName, TYPES } from "./constants";
|
|
18
|
-
import { schemaToDataType } from "./definitions/data-schema";
|
|
19
|
-
import { toRunnableMemories } from "./definitions/memory";
|
|
20
|
-
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
21
|
-
import { isRunnableResponseDelta, } from "./runnable";
|
|
22
|
-
import { isNonNullable } from "./utils/is-non-nullable";
|
|
23
|
-
import { logger } from "./utils/logger";
|
|
24
|
-
import { OrderedRecord } from "./utils/ordered-map";
|
|
25
|
-
let PipelineAgent = class PipelineAgent extends Agent {
|
|
26
|
-
definition;
|
|
27
|
-
static create = create;
|
|
28
|
-
constructor(definition, context) {
|
|
29
|
-
super(definition, context);
|
|
30
|
-
this.definition = definition;
|
|
31
|
-
}
|
|
32
|
-
async process(input, options) {
|
|
33
|
-
const { definition, context } = this;
|
|
34
|
-
if (!context)
|
|
35
|
-
throw new Error("Context is required");
|
|
36
|
-
const { processes } = definition;
|
|
37
|
-
if (!processes?.$indexes.length) {
|
|
38
|
-
throw new Error("No processes defined");
|
|
39
|
-
}
|
|
40
|
-
return new ReadableStream({
|
|
41
|
-
async start(controller) {
|
|
42
|
-
try {
|
|
43
|
-
// NOTE: 将 input 转换为 variables,其中 key 为 inputId,value 为 input 的值
|
|
44
|
-
const variables = {
|
|
45
|
-
...options.memories,
|
|
46
|
-
...Object.fromEntries(OrderedRecord.map(definition.inputs, (i) => {
|
|
47
|
-
const value = input[i.name || i.id];
|
|
48
|
-
if (isNil(value))
|
|
49
|
-
return null;
|
|
50
|
-
return [i.id, value];
|
|
51
|
-
}).filter(isNonNullable)),
|
|
52
|
-
};
|
|
53
|
-
const outputs = OrderedRecord.toArray(definition.outputs);
|
|
54
|
-
const textStreamOutput = outputs.find((i) => i.name === StreamTextOutputName);
|
|
55
|
-
let result = {};
|
|
56
|
-
for (const process of OrderedRecord.iterator(processes)) {
|
|
57
|
-
if (!process.runnable?.id) {
|
|
58
|
-
logger.warn("Runnable id is required for process", process);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const runnable = await context.resolve(process.runnable.id);
|
|
62
|
-
if (!runnable)
|
|
63
|
-
continue;
|
|
64
|
-
const inputValues = Object.fromEntries(Object.entries(process.input ?? {})
|
|
65
|
-
.map(([inputId, input]) => {
|
|
66
|
-
const targetInput = runnable.definition.inputs?.[inputId];
|
|
67
|
-
if (!targetInput?.name)
|
|
68
|
-
return null;
|
|
69
|
-
let value;
|
|
70
|
-
if (input.from === "variable") {
|
|
71
|
-
const v = variables[input.fromVariableId];
|
|
72
|
-
value = input.fromVariablePropPath?.length
|
|
73
|
-
? get(v, input.fromVariablePropPath)
|
|
74
|
-
: v;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
throw new Error("Unsupported input source");
|
|
78
|
-
}
|
|
79
|
-
return [targetInput.name, value];
|
|
80
|
-
})
|
|
81
|
-
.filter(isNonNullable));
|
|
82
|
-
const stream = await runnable.run(inputValues, { stream: true });
|
|
83
|
-
const needRespondTextStream = textStreamOutput?.from === "variable" &&
|
|
84
|
-
textStreamOutput.fromVariableId === process.id;
|
|
85
|
-
// const needRespondJsonStream = outputs.some(
|
|
86
|
-
// (i) => i.name !== StreamTextOutputName && i.from === 'variable' && i.fromVariableId === process.id
|
|
87
|
-
// );
|
|
88
|
-
const processResult = {};
|
|
89
|
-
variables[process.id] = processResult;
|
|
90
|
-
for await (const chunk of stream) {
|
|
91
|
-
if (isRunnableResponseDelta(chunk)) {
|
|
92
|
-
if (chunk.$text) {
|
|
93
|
-
Object.assign(processResult, {
|
|
94
|
-
$text: (processResult.$text || "") + chunk.$text,
|
|
95
|
-
});
|
|
96
|
-
if (needRespondTextStream) {
|
|
97
|
-
controller.enqueue({ $text: chunk.$text });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (chunk.delta) {
|
|
101
|
-
Object.assign(processResult, chunk.delta);
|
|
102
|
-
// TODO: 这里需要考虑上层 agent 直接输出了 {$text: 'xxx'} 没有用 chunk 的方式返回的情况
|
|
103
|
-
// if (needRespondJsonStream) {
|
|
104
|
-
result = Object.fromEntries(OrderedRecord.map(definition.outputs, (output) => {
|
|
105
|
-
if (!output.name)
|
|
106
|
-
return null;
|
|
107
|
-
if (output.name === StreamTextOutputName)
|
|
108
|
-
return null;
|
|
109
|
-
let value;
|
|
110
|
-
if (output.from === "variable") {
|
|
111
|
-
const v = variables[output.fromVariableId];
|
|
112
|
-
value = output.fromVariablePropPath?.length
|
|
113
|
-
? get(v, output.fromVariablePropPath)
|
|
114
|
-
: v;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw new Error(`Unsupported output source ${output.from}`);
|
|
118
|
-
}
|
|
119
|
-
return [output.name, value];
|
|
120
|
-
}).filter(isNonNullable));
|
|
121
|
-
controller.enqueue({ delta: result });
|
|
122
|
-
// }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
controller.error(error);
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
controller.close();
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
PipelineAgent = __decorate([
|
|
139
|
-
injectable(),
|
|
140
|
-
__param(0, inject(TYPES.definition)),
|
|
141
|
-
__param(1, inject(TYPES.context)),
|
|
142
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
143
|
-
], PipelineAgent);
|
|
144
|
-
export { PipelineAgent };
|
|
145
|
-
function create(options) {
|
|
146
|
-
const agentId = options.name || nanoid();
|
|
147
|
-
const inputs = schemaToDataType(options.inputs);
|
|
148
|
-
const preloads = preloadCreatorsToPreloads(inputs, options.preloads);
|
|
149
|
-
const memories = toRunnableMemories(agentId, inputs, options.memories || {});
|
|
150
|
-
const processes = OrderedRecord.fromArray([]);
|
|
151
|
-
for (const [name, p] of Object.entries(options.processes)) {
|
|
152
|
-
OrderedRecord.push(processes, {
|
|
153
|
-
id: nanoid(),
|
|
154
|
-
name: name || p.runnable?.name,
|
|
155
|
-
runnable: { id: p.runnable.id },
|
|
156
|
-
input: Object.fromEntries(OrderedRecord.map(p.runnable.definition.inputs, (inputOfProcess) => {
|
|
157
|
-
const i = p.input[inputOfProcess.name || inputOfProcess.id];
|
|
158
|
-
if (!i) {
|
|
159
|
-
if (inputOfProcess.required) {
|
|
160
|
-
throw new Error(`Input ${inputOfProcess.name || inputOfProcess.id} for case ${p.runnable.name || p.runnable.id} is required`);
|
|
161
|
-
}
|
|
162
|
-
// ignore optional input
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
const inputFromPipeline = OrderedRecord.find(inputs, (input) => input.name === i.fromVariable) ||
|
|
166
|
-
OrderedRecord.find(processes, (p) => p.name === i.fromVariable);
|
|
167
|
-
if (!inputFromPipeline)
|
|
168
|
-
throw new Error(`Input ${i.fromVariable.toString()} not found`);
|
|
169
|
-
return [
|
|
170
|
-
inputOfProcess.id,
|
|
171
|
-
{
|
|
172
|
-
from: "variable",
|
|
173
|
-
fromVariableId: inputFromPipeline.id,
|
|
174
|
-
fromVariablePropPath: i.fromVariablePropPath,
|
|
175
|
-
},
|
|
176
|
-
];
|
|
177
|
-
}).filter(isNonNullable)),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
const outputs = OrderedRecord.fromArray(OrderedRecord.map(schemaToDataType(options.outputs), (output) => {
|
|
181
|
-
const { fromVariable, fromVariablePropPath } = options.outputs[output.name];
|
|
182
|
-
const from = OrderedRecord.find(inputs, (i) => i.name === fromVariable) ||
|
|
183
|
-
OrderedRecord.find(processes, (p) => p.name === fromVariable);
|
|
184
|
-
if (!from)
|
|
185
|
-
throw new Error(`Output ${output.name} not found in inputs or processes`);
|
|
186
|
-
return {
|
|
187
|
-
...output,
|
|
188
|
-
from: "variable",
|
|
189
|
-
fromVariableId: from.id,
|
|
190
|
-
fromVariablePropPath,
|
|
191
|
-
};
|
|
192
|
-
}));
|
|
193
|
-
return new PipelineAgent({
|
|
194
|
-
id: agentId,
|
|
195
|
-
name: options.name,
|
|
196
|
-
type: "pipeline_agent",
|
|
197
|
-
inputs,
|
|
198
|
-
preloads,
|
|
199
|
-
memories,
|
|
200
|
-
outputs,
|
|
201
|
-
processes,
|
|
202
|
-
}, options.context);
|
|
203
|
-
}
|
package/lib/esm/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>>;
|