@aigne/core 1.0.15 → 1.0.17
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/llm-agent.d.ts +1 -1
- package/lib/cjs/llm-agent.js +5 -2
- package/lib/cjs/pipeline-agent.d.ts +1 -1
- package/lib/cjs/pipeline-agent.js +33 -30
- package/lib/cjs/runnable.d.ts +24 -1
- package/lib/cjs/runnable.js +7 -2
- package/lib/cjs/utils/stream-utils.js +1 -1
- package/lib/dts/llm-agent.d.ts +1 -1
- package/lib/dts/pipeline-agent.d.ts +1 -1
- package/lib/dts/runnable.d.ts +24 -1
- package/lib/esm/llm-agent.d.ts +1 -1
- package/lib/esm/llm-agent.js +5 -2
- package/lib/esm/pipeline-agent.d.ts +1 -1
- package/lib/esm/pipeline-agent.js +33 -30
- package/lib/esm/runnable.d.ts +24 -1
- package/lib/esm/runnable.js +6 -2
- package/lib/esm/utils/stream-utils.js +1 -1
- package/package.json +1 -1
package/lib/cjs/llm-agent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, ty
|
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
4
|
import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
|
|
5
|
-
import type
|
|
5
|
+
import { type RunnableInput, type RunnableOutput } from "./runnable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
export declare class LLMAgent<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
8
|
definition: LLMAgentDefinition;
|
package/lib/cjs/llm-agent.js
CHANGED
|
@@ -20,6 +20,7 @@ const constants_1 = require("./constants");
|
|
|
20
20
|
const data_schema_1 = require("./definitions/data-schema");
|
|
21
21
|
const memory_1 = require("./definitions/memory");
|
|
22
22
|
const preload_1 = require("./definitions/preload");
|
|
23
|
+
const runnable_1 = require("./runnable");
|
|
23
24
|
const message_utils_1 = require("./utils/message-utils");
|
|
24
25
|
const mustache_utils_1 = require("./utils/mustache-utils");
|
|
25
26
|
const ordered_map_1 = require("./utils/ordered-map");
|
|
@@ -47,8 +48,10 @@ let LLMAgent = class LLMAgent extends agent_1.Agent {
|
|
|
47
48
|
const hasTextOutput = ordered_map_1.OrderedRecord.find(definition.outputs, (i) => i.name === constants_1.StreamTextOutputName);
|
|
48
49
|
if (hasTextOutput) {
|
|
49
50
|
for await (const chunk of await this.runWithTextOutput(llmInputs)) {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if ((0, runnable_1.isRunnableResponseDelta)(chunk)) {
|
|
52
|
+
$text += chunk.$text || "";
|
|
53
|
+
yield { $text: chunk.$text };
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
const json = await this.runWithStructuredOutput(llmInputs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import type
|
|
4
|
+
import { type Runnable, type RunnableInput, type RunnableOutput, type RunnableOutputType, type RunnableResponseDelta } from "./runnable";
|
|
5
5
|
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
|
@@ -21,6 +21,7 @@ const constants_1 = require("./constants");
|
|
|
21
21
|
const data_schema_1 = require("./definitions/data-schema");
|
|
22
22
|
const memory_1 = require("./definitions/memory");
|
|
23
23
|
const preload_1 = require("./definitions/preload");
|
|
24
|
+
const runnable_1 = require("./runnable");
|
|
24
25
|
const is_non_nullable_1 = require("./utils/is-non-nullable");
|
|
25
26
|
const logger_1 = require("./utils/logger");
|
|
26
27
|
const ordered_map_1 = require("./utils/ordered-map");
|
|
@@ -90,37 +91,39 @@ let PipelineAgent = class PipelineAgent extends agent_1.Agent {
|
|
|
90
91
|
const processResult = {};
|
|
91
92
|
variables[process.id] = processResult;
|
|
92
93
|
for await (const chunk of stream) {
|
|
93
|
-
if (chunk
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
if (chunk.delta) {
|
|
102
|
-
Object.assign(processResult, chunk.delta);
|
|
103
|
-
// TODO: 这里需要考虑上层 agent 直接输出了 {$text: 'xxx'} 没有用 chunk 的方式返回的情况
|
|
104
|
-
// if (needRespondJsonStream) {
|
|
105
|
-
result = Object.fromEntries(ordered_map_1.OrderedRecord.map(definition.outputs, (output) => {
|
|
106
|
-
if (!output.name)
|
|
107
|
-
return null;
|
|
108
|
-
if (output.name === constants_1.StreamTextOutputName)
|
|
109
|
-
return null;
|
|
110
|
-
let value;
|
|
111
|
-
if (output.from === "variable") {
|
|
112
|
-
const v = variables[output.fromVariableId];
|
|
113
|
-
value = output.fromVariablePropPath?.length
|
|
114
|
-
? (0, lodash_1.get)(v, output.fromVariablePropPath)
|
|
115
|
-
: v;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
throw new Error(`Unsupported output source ${output.from}`);
|
|
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 });
|
|
119
101
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
+
}
|
|
124
127
|
}
|
|
125
128
|
}
|
|
126
129
|
}
|
package/lib/cjs/runnable.d.ts
CHANGED
|
@@ -41,13 +41,36 @@ export interface RunnableResponseDelta<T> {
|
|
|
41
41
|
$text?: string;
|
|
42
42
|
delta?: Partial<T>;
|
|
43
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
|
+
}
|
|
44
66
|
export interface RunnableResponseError {
|
|
45
67
|
error: {
|
|
46
68
|
message: string;
|
|
47
69
|
};
|
|
48
70
|
}
|
|
49
|
-
export type RunnableResponseChunk<T> = RunnableResponseDelta<T
|
|
71
|
+
export type RunnableResponseChunk<T> = RunnableResponseDelta<T> | RunnableResponseProgress;
|
|
50
72
|
export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
|
|
51
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;
|
|
52
75
|
export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
|
|
53
76
|
export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
|
package/lib/cjs/runnable.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Runnable = void 0;
|
|
4
4
|
exports.isRunnableResponseDelta = isRunnableResponseDelta;
|
|
5
|
+
exports.isRunnableResponseProgress = isRunnableResponseProgress;
|
|
5
6
|
exports.isRunnableResponseError = isRunnableResponseError;
|
|
6
7
|
const ordered_map_1 = require("./utils/ordered-map");
|
|
7
8
|
class Runnable {
|
|
@@ -25,8 +26,12 @@ class Runnable {
|
|
|
25
26
|
}
|
|
26
27
|
exports.Runnable = Runnable;
|
|
27
28
|
function isRunnableResponseDelta(chunk) {
|
|
28
|
-
return "$text" in chunk
|
|
29
|
+
return (("$text" in chunk && typeof chunk.$text === "string") ||
|
|
30
|
+
("delta" in chunk && typeof chunk.delta === "object"));
|
|
31
|
+
}
|
|
32
|
+
function isRunnableResponseProgress(chunk) {
|
|
33
|
+
return "progress" in chunk && typeof chunk.progress === "object";
|
|
29
34
|
}
|
|
30
35
|
function isRunnableResponseError(chunk) {
|
|
31
|
-
return "error" in chunk;
|
|
36
|
+
return "error" in chunk && typeof chunk.error === "object";
|
|
32
37
|
}
|
|
@@ -43,8 +43,8 @@ async function extractOutputsFromRunnableOutput(output, resolve) {
|
|
|
43
43
|
const result = {};
|
|
44
44
|
let $text = "";
|
|
45
45
|
for await (const value of output) {
|
|
46
|
+
controller.enqueue(value);
|
|
46
47
|
if ((0, runnable_1.isRunnableResponseDelta)(value)) {
|
|
47
|
-
controller.enqueue(value);
|
|
48
48
|
$text += value.$text || "";
|
|
49
49
|
Object.assign(result, value.delta);
|
|
50
50
|
}
|
package/lib/dts/llm-agent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, ty
|
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
4
|
import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
|
|
5
|
-
import type
|
|
5
|
+
import { type RunnableInput, type RunnableOutput } from "./runnable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
export declare class LLMAgent<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
8
|
definition: LLMAgentDefinition;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import type
|
|
4
|
+
import { type Runnable, type RunnableInput, type RunnableOutput, type RunnableOutputType, type RunnableResponseDelta } from "./runnable";
|
|
5
5
|
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
package/lib/dts/runnable.d.ts
CHANGED
|
@@ -41,13 +41,36 @@ export interface RunnableResponseDelta<T> {
|
|
|
41
41
|
$text?: string;
|
|
42
42
|
delta?: Partial<T>;
|
|
43
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
|
+
}
|
|
44
66
|
export interface RunnableResponseError {
|
|
45
67
|
error: {
|
|
46
68
|
message: string;
|
|
47
69
|
};
|
|
48
70
|
}
|
|
49
|
-
export type RunnableResponseChunk<T> = RunnableResponseDelta<T
|
|
71
|
+
export type RunnableResponseChunk<T> = RunnableResponseDelta<T> | RunnableResponseProgress;
|
|
50
72
|
export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
|
|
51
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;
|
|
52
75
|
export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
|
|
53
76
|
export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
|
package/lib/esm/llm-agent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Agent, type AgentDefinition, type AgentMemories, type AgentPreloads, ty
|
|
|
2
2
|
import type { Context, ContextState } from "./context";
|
|
3
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
4
|
import type { LLMModel, LLMModelInputMessage, LLMModelInputs } from "./llm-model";
|
|
5
|
-
import type
|
|
5
|
+
import { type RunnableInput, type RunnableOutput } from "./runnable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
export declare class LLMAgent<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
8
|
definition: LLMAgentDefinition;
|
package/lib/esm/llm-agent.js
CHANGED
|
@@ -17,6 +17,7 @@ import { StreamTextOutputName, TYPES } from "./constants";
|
|
|
17
17
|
import { schemaToDataType } from "./definitions/data-schema";
|
|
18
18
|
import { toRunnableMemories } from "./definitions/memory";
|
|
19
19
|
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
20
|
+
import { isRunnableResponseDelta, } from "./runnable";
|
|
20
21
|
import { prepareMessages } from "./utils/message-utils";
|
|
21
22
|
import { renderMessage } from "./utils/mustache-utils";
|
|
22
23
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
@@ -44,8 +45,10 @@ let LLMAgent = class LLMAgent extends Agent {
|
|
|
44
45
|
const hasTextOutput = OrderedRecord.find(definition.outputs, (i) => i.name === StreamTextOutputName);
|
|
45
46
|
if (hasTextOutput) {
|
|
46
47
|
for await (const chunk of await this.runWithTextOutput(llmInputs)) {
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
if (isRunnableResponseDelta(chunk)) {
|
|
49
|
+
$text += chunk.$text || "";
|
|
50
|
+
yield { $text: chunk.$text };
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
const json = await this.runWithStructuredOutput(llmInputs);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
3
|
import { type SchemaToType } from "./definitions/data-schema";
|
|
4
|
-
import type
|
|
4
|
+
import { type Runnable, type RunnableInput, type RunnableOutput, type RunnableOutputType, type RunnableResponseDelta } from "./runnable";
|
|
5
5
|
import type { MakeNullablePropertyOptional } from "./utils/nullable";
|
|
6
6
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
7
7
|
import type { ExtractRunnableInputType } from "./utils/runnable-type";
|
|
@@ -18,6 +18,7 @@ import { StreamTextOutputName, TYPES } from "./constants";
|
|
|
18
18
|
import { schemaToDataType } from "./definitions/data-schema";
|
|
19
19
|
import { toRunnableMemories } from "./definitions/memory";
|
|
20
20
|
import { preloadCreatorsToPreloads } from "./definitions/preload";
|
|
21
|
+
import { isRunnableResponseDelta, } from "./runnable";
|
|
21
22
|
import { isNonNullable } from "./utils/is-non-nullable";
|
|
22
23
|
import { logger } from "./utils/logger";
|
|
23
24
|
import { OrderedRecord } from "./utils/ordered-map";
|
|
@@ -87,37 +88,39 @@ let PipelineAgent = class PipelineAgent extends Agent {
|
|
|
87
88
|
const processResult = {};
|
|
88
89
|
variables[process.id] = processResult;
|
|
89
90
|
for await (const chunk of stream) {
|
|
90
|
-
if (chunk
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
if (chunk.delta) {
|
|
99
|
-
Object.assign(processResult, chunk.delta);
|
|
100
|
-
// TODO: 这里需要考虑上层 agent 直接输出了 {$text: 'xxx'} 没有用 chunk 的方式返回的情况
|
|
101
|
-
// if (needRespondJsonStream) {
|
|
102
|
-
result = Object.fromEntries(OrderedRecord.map(definition.outputs, (output) => {
|
|
103
|
-
if (!output.name)
|
|
104
|
-
return null;
|
|
105
|
-
if (output.name === StreamTextOutputName)
|
|
106
|
-
return null;
|
|
107
|
-
let value;
|
|
108
|
-
if (output.from === "variable") {
|
|
109
|
-
const v = variables[output.fromVariableId];
|
|
110
|
-
value = output.fromVariablePropPath?.length
|
|
111
|
-
? get(v, output.fromVariablePropPath)
|
|
112
|
-
: v;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
throw new Error(`Unsupported output source ${output.from}`);
|
|
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 });
|
|
116
98
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
}
|
|
121
124
|
}
|
|
122
125
|
}
|
|
123
126
|
}
|
package/lib/esm/runnable.d.ts
CHANGED
|
@@ -41,13 +41,36 @@ export interface RunnableResponseDelta<T> {
|
|
|
41
41
|
$text?: string;
|
|
42
42
|
delta?: Partial<T>;
|
|
43
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
|
+
}
|
|
44
66
|
export interface RunnableResponseError {
|
|
45
67
|
error: {
|
|
46
68
|
message: string;
|
|
47
69
|
};
|
|
48
70
|
}
|
|
49
|
-
export type RunnableResponseChunk<T> = RunnableResponseDelta<T
|
|
71
|
+
export type RunnableResponseChunk<T> = RunnableResponseDelta<T> | RunnableResponseProgress;
|
|
50
72
|
export type RunnableResponseChunkWithError<T> = RunnableResponseChunk<T> | RunnableResponseError;
|
|
51
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;
|
|
52
75
|
export declare function isRunnableResponseError<T>(chunk: RunnableResponseChunkWithError<T>): chunk is RunnableResponseError;
|
|
53
76
|
export type RunnableResponseStream<T> = ReadableStream<RunnableResponseChunk<T>>;
|
package/lib/esm/runnable.js
CHANGED
|
@@ -19,8 +19,12 @@ export class Runnable {
|
|
|
19
19
|
outputs;
|
|
20
20
|
}
|
|
21
21
|
export function isRunnableResponseDelta(chunk) {
|
|
22
|
-
return "$text" in chunk
|
|
22
|
+
return (("$text" in chunk && typeof chunk.$text === "string") ||
|
|
23
|
+
("delta" in chunk && typeof chunk.delta === "object"));
|
|
24
|
+
}
|
|
25
|
+
export function isRunnableResponseProgress(chunk) {
|
|
26
|
+
return "progress" in chunk && typeof chunk.progress === "object";
|
|
23
27
|
}
|
|
24
28
|
export function isRunnableResponseError(chunk) {
|
|
25
|
-
return "error" in chunk;
|
|
29
|
+
return "error" in chunk && typeof chunk.error === "object";
|
|
26
30
|
}
|
|
@@ -36,8 +36,8 @@ export async function extractOutputsFromRunnableOutput(output, resolve) {
|
|
|
36
36
|
const result = {};
|
|
37
37
|
let $text = "";
|
|
38
38
|
for await (const value of output) {
|
|
39
|
+
controller.enqueue(value);
|
|
39
40
|
if (isRunnableResponseDelta(value)) {
|
|
40
|
-
controller.enqueue(value);
|
|
41
41
|
$text += value.$text || "";
|
|
42
42
|
Object.assign(result, value.delta);
|
|
43
43
|
}
|