@aigne/core 1.0.17 → 1.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agents/agent.d.ts +55 -0
- package/lib/cjs/agents/agent.js +91 -0
- package/lib/cjs/agents/ai-agent.d.ts +20 -0
- package/lib/cjs/agents/ai-agent.js +86 -0
- package/lib/cjs/agents/mcp-agent.d.ts +27 -0
- package/lib/cjs/agents/mcp-agent.js +95 -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} +62 -27
- 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 +34 -0
- package/lib/cjs/prompt/prompt-builder.js +140 -0
- package/lib/cjs/prompt/template.d.ts +70 -0
- package/lib/cjs/prompt/template.js +172 -0
- package/lib/cjs/utils/logger.d.ts +6 -3
- package/lib/cjs/utils/logger.js +9 -14
- 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 +55 -0
- package/lib/dts/agents/ai-agent.d.ts +20 -0
- package/lib/dts/agents/mcp-agent.d.ts +27 -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 +34 -0
- package/lib/dts/prompt/template.d.ts +70 -0
- package/lib/dts/utils/logger.d.ts +6 -3
- package/lib/dts/utils/type-utils.d.ts +5 -1
- package/lib/esm/agents/agent.d.ts +55 -0
- package/lib/esm/agents/agent.js +83 -0
- package/lib/esm/agents/ai-agent.d.ts +20 -0
- package/lib/esm/agents/ai-agent.js +82 -0
- package/lib/esm/agents/mcp-agent.d.ts +27 -0
- package/lib/esm/agents/mcp-agent.js +90 -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} +59 -24
- 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 +34 -0
- package/lib/esm/prompt/prompt-builder.js +131 -0
- package/lib/esm/prompt/template.d.ts +70 -0
- package/lib/esm/prompt/template.js +158 -0
- package/lib/esm/utils/logger.d.ts +6 -3
- package/lib/esm/utils/logger.js +6 -14
- package/lib/esm/utils/type-utils.d.ts +5 -1
- package/lib/esm/utils/type-utils.js +17 -1
- package/package.json +18 -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
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { isEmpty, omitBy } from "lodash";
|
|
2
|
-
import { logger } from "./logger";
|
|
3
|
-
import { OrderedRecord } from "./ordered-map";
|
|
4
|
-
export async function formatOpenAPIRequest(api, inputs, input) {
|
|
5
|
-
const { url, method, ...inputParams } = processParameters(api, inputs, input);
|
|
6
|
-
logger.debug("inputParams", inputParams);
|
|
7
|
-
const authParams = await getAuthParams(api.auth);
|
|
8
|
-
logger.debug("authParams", authParams);
|
|
9
|
-
return {
|
|
10
|
-
url,
|
|
11
|
-
method,
|
|
12
|
-
...omitBy({
|
|
13
|
-
...inputParams,
|
|
14
|
-
query: { ...inputParams.query, ...authParams.query },
|
|
15
|
-
cookies: { ...inputParams.cookies, ...authParams.cookies },
|
|
16
|
-
headers: { ...inputParams.headers, ...authParams.headers },
|
|
17
|
-
}, (i) => isEmpty(i)),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
async function getAuthParams(auth) {
|
|
21
|
-
if (!auth)
|
|
22
|
-
return {};
|
|
23
|
-
if (auth.type === "custom") {
|
|
24
|
-
return await auth.auth();
|
|
25
|
-
}
|
|
26
|
-
const { type, key, token } = auth;
|
|
27
|
-
switch (auth.in) {
|
|
28
|
-
case "query":
|
|
29
|
-
return { query: { [key || "token"]: token } };
|
|
30
|
-
case "cookie":
|
|
31
|
-
return { cookies: { [key || "token"]: token } };
|
|
32
|
-
default: {
|
|
33
|
-
const prefix = type === "bearer" ? "Bearer " : type === "basic" ? "Basic " : "";
|
|
34
|
-
return { headers: { [key || "Authorization"]: `${prefix}${token}` } };
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function processParameters(api, inputs, input) {
|
|
39
|
-
const result = {
|
|
40
|
-
url: api.url,
|
|
41
|
-
method: api.method,
|
|
42
|
-
headers: {},
|
|
43
|
-
query: {},
|
|
44
|
-
cookies: {},
|
|
45
|
-
body: {},
|
|
46
|
-
};
|
|
47
|
-
for (const [key, value] of Object.entries(input)) {
|
|
48
|
-
const schema = OrderedRecord.find(inputs, (x) => x.name === key);
|
|
49
|
-
if (!schema)
|
|
50
|
-
continue;
|
|
51
|
-
switch (schema.in) {
|
|
52
|
-
case "query":
|
|
53
|
-
result.query[key] = value;
|
|
54
|
-
break;
|
|
55
|
-
case "header":
|
|
56
|
-
result.headers[key] = value;
|
|
57
|
-
break;
|
|
58
|
-
case "cookie":
|
|
59
|
-
result.cookies[key] = value;
|
|
60
|
-
break;
|
|
61
|
-
case "body":
|
|
62
|
-
result.body[key] = value;
|
|
63
|
-
break;
|
|
64
|
-
case "path":
|
|
65
|
-
result.url = result.url.replace(`{${key}}`, String(value));
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
// 没有指定 in 的情况
|
|
69
|
-
if (result.method.toLowerCase() === "get") {
|
|
70
|
-
result.query[key] = value;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
result.body[key] = value;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export type OrderedRecord<T extends {
|
|
2
|
-
id: string;
|
|
3
|
-
}> = Record<string, T> & {
|
|
4
|
-
$indexes: string[];
|
|
5
|
-
};
|
|
6
|
-
export declare namespace OrderedRecord {
|
|
7
|
-
function iterator<T extends {
|
|
8
|
-
id: string;
|
|
9
|
-
}>(record?: OrderedRecord<T>): IterableIterator<T>;
|
|
10
|
-
function map<O, T extends {
|
|
11
|
-
id: string;
|
|
12
|
-
}>(record: OrderedRecord<T> | undefined, fn: (value: T, index: number) => O): O[];
|
|
13
|
-
function toArray<T extends {
|
|
14
|
-
id: string;
|
|
15
|
-
}>(record: OrderedRecord<T> | undefined): T[];
|
|
16
|
-
function fromArray<T extends {
|
|
17
|
-
id: string;
|
|
18
|
-
}>(array?: T[]): OrderedRecord<T>;
|
|
19
|
-
function find<T extends {
|
|
20
|
-
id: string;
|
|
21
|
-
}>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T | undefined;
|
|
22
|
-
function filter<T extends {
|
|
23
|
-
id: string;
|
|
24
|
-
}>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T[];
|
|
25
|
-
function at<T extends {
|
|
26
|
-
id: string;
|
|
27
|
-
}>(record: OrderedRecord<T> | undefined, index: number): T | undefined;
|
|
28
|
-
function push<T extends {
|
|
29
|
-
id: string;
|
|
30
|
-
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
31
|
-
function merge<T extends {
|
|
32
|
-
id: string;
|
|
33
|
-
}>(...records: OrderedRecord<T>[]): OrderedRecord<T>;
|
|
34
|
-
function pushOrUpdate<T extends {
|
|
35
|
-
id: string;
|
|
36
|
-
}>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
|
|
37
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
export var OrderedRecord;
|
|
2
|
-
(function (OrderedRecord) {
|
|
3
|
-
function iterator(record) {
|
|
4
|
-
return (function* () {
|
|
5
|
-
if (!record)
|
|
6
|
-
return;
|
|
7
|
-
for (const id of record.$indexes) {
|
|
8
|
-
yield record[id];
|
|
9
|
-
}
|
|
10
|
-
})();
|
|
11
|
-
}
|
|
12
|
-
OrderedRecord.iterator = iterator;
|
|
13
|
-
function map(record, fn) {
|
|
14
|
-
if (!record)
|
|
15
|
-
return [];
|
|
16
|
-
const result = new Array(record.$indexes.length);
|
|
17
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
18
|
-
result[i] = fn(record[record.$indexes[i]], i);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
OrderedRecord.map = map;
|
|
23
|
-
function toArray(record) {
|
|
24
|
-
return OrderedRecord.map(record, (value) => value);
|
|
25
|
-
}
|
|
26
|
-
OrderedRecord.toArray = toArray;
|
|
27
|
-
function fromArray(array) {
|
|
28
|
-
const record = { $indexes: [] };
|
|
29
|
-
for (const value of array ?? []) {
|
|
30
|
-
record[value.id] = value;
|
|
31
|
-
record.$indexes.push(value.id);
|
|
32
|
-
}
|
|
33
|
-
return record;
|
|
34
|
-
}
|
|
35
|
-
OrderedRecord.fromArray = fromArray;
|
|
36
|
-
function find(record, predicate) {
|
|
37
|
-
if (!record)
|
|
38
|
-
return undefined;
|
|
39
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
40
|
-
const id = record.$indexes[i];
|
|
41
|
-
const value = record[id];
|
|
42
|
-
if (predicate(value, i))
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
OrderedRecord.find = find;
|
|
48
|
-
function filter(record, predicate) {
|
|
49
|
-
if (!record)
|
|
50
|
-
return [];
|
|
51
|
-
const result = [];
|
|
52
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
53
|
-
const id = record.$indexes[i];
|
|
54
|
-
const value = record[id];
|
|
55
|
-
if (predicate(value, i))
|
|
56
|
-
result.push(value);
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
OrderedRecord.filter = filter;
|
|
61
|
-
function at(record, index) {
|
|
62
|
-
if (!record?.$indexes.length)
|
|
63
|
-
return undefined;
|
|
64
|
-
const id = record.$indexes.at(index);
|
|
65
|
-
return record[id];
|
|
66
|
-
}
|
|
67
|
-
OrderedRecord.at = at;
|
|
68
|
-
function push(record, ...items) {
|
|
69
|
-
for (const item of items) {
|
|
70
|
-
if (record[item.id])
|
|
71
|
-
throw new Error(`Item with id ${item.id} already exists`);
|
|
72
|
-
record.$indexes.push(item.id);
|
|
73
|
-
record[item.id] = item;
|
|
74
|
-
}
|
|
75
|
-
return record;
|
|
76
|
-
}
|
|
77
|
-
OrderedRecord.push = push;
|
|
78
|
-
function merge(...records) {
|
|
79
|
-
const result = { $indexes: [] };
|
|
80
|
-
for (const record of records) {
|
|
81
|
-
for (const id of record.$indexes) {
|
|
82
|
-
if (!result[id])
|
|
83
|
-
result.$indexes.push(id);
|
|
84
|
-
result[id] = record[id];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
OrderedRecord.merge = merge;
|
|
90
|
-
function pushOrUpdate(record, ...items) {
|
|
91
|
-
for (const item of items) {
|
|
92
|
-
if (!record[item.id]) {
|
|
93
|
-
record.$indexes.push(item.id);
|
|
94
|
-
}
|
|
95
|
-
record[item.id] = item;
|
|
96
|
-
}
|
|
97
|
-
return record;
|
|
98
|
-
}
|
|
99
|
-
OrderedRecord.pushOrUpdate = pushOrUpdate;
|
|
100
|
-
})(OrderedRecord || (OrderedRecord = {}));
|
package/lib/esm/utils/partial.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Runnable, RunnableInput, RunnableOutput, RunnableResponseStream } from "../runnable";
|
|
2
|
-
import type { UnionToIntersection } from "./union";
|
|
3
|
-
export type ExtractRunnableInputType<T> = T extends Runnable<infer I, RunnableOutput> ? I : never;
|
|
4
|
-
export type ExtractRunnableOutputType<T> = T extends Runnable<RunnableInput, infer O> ? Exclude<O, RunnableResponseStream<unknown>> : never;
|
|
5
|
-
export type ExtractRunnableInputTypeIntersection<T> = UnionToIntersection<ExtractRunnableInputType<T>, Record<string, unknown>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "../runnable";
|
|
2
|
-
export declare function objectToRunnableResponseStream<T extends {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}>(obj: T): RunnableResponseStream<T>;
|
|
5
|
-
export declare function runnableResponseStreamToObject<T extends {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}>(stream: RunnableResponseStream<T> | AsyncGenerator<RunnableResponseChunk<T>>): Promise<T>;
|
|
8
|
-
/**
|
|
9
|
-
* Extracts the outputs from a runnable output stream and run the
|
|
10
|
-
* resolve function on the result before the stream closes. It can be
|
|
11
|
-
* used to update the memories of an agent.
|
|
12
|
-
* @param output The runnable output stream or object
|
|
13
|
-
* @param resolve The function to run on the result
|
|
14
|
-
* @returns The runnable output stream or object
|
|
15
|
-
*/
|
|
16
|
-
export declare function extractOutputsFromRunnableOutput<T extends {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
}>(output: RunnableResponse<T> | AsyncGenerator<RunnableResponseChunk<T>>, resolve: (result: T) => Promise<void> | void): Promise<RunnableResponse<T>>;
|
|
19
|
-
export declare function asyncGeneratorToReadableStream<T>(generator: AsyncGenerator<T>): ReadableStream<T>;
|
|
20
|
-
export declare function isAsyncGenerator<T extends AsyncGenerator>(value: any): value is T;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { isRunnableResponseDelta, } from "../runnable";
|
|
2
|
-
export function objectToRunnableResponseStream(obj) {
|
|
3
|
-
return new ReadableStream({
|
|
4
|
-
start(controller) {
|
|
5
|
-
controller.enqueue({ $text: obj.$text || undefined, delta: obj });
|
|
6
|
-
controller.close();
|
|
7
|
-
},
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export async function runnableResponseStreamToObject(stream) {
|
|
11
|
-
let $text = "";
|
|
12
|
-
const result = {};
|
|
13
|
-
for await (const value of stream) {
|
|
14
|
-
if (isRunnableResponseDelta(value)) {
|
|
15
|
-
$text += value.$text || "";
|
|
16
|
-
Object.assign(result, value.delta);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
Object.assign(result, { $text: result.$text || $text || undefined });
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Extracts the outputs from a runnable output stream and run the
|
|
24
|
-
* resolve function on the result before the stream closes. It can be
|
|
25
|
-
* used to update the memories of an agent.
|
|
26
|
-
* @param output The runnable output stream or object
|
|
27
|
-
* @param resolve The function to run on the result
|
|
28
|
-
* @returns The runnable output stream or object
|
|
29
|
-
*/
|
|
30
|
-
export async function extractOutputsFromRunnableOutput(output, resolve) {
|
|
31
|
-
if (output instanceof ReadableStream ||
|
|
32
|
-
isAsyncGenerator(output)) {
|
|
33
|
-
return new ReadableStream({
|
|
34
|
-
async start(controller) {
|
|
35
|
-
try {
|
|
36
|
-
const result = {};
|
|
37
|
-
let $text = "";
|
|
38
|
-
for await (const value of output) {
|
|
39
|
-
controller.enqueue(value);
|
|
40
|
-
if (isRunnableResponseDelta(value)) {
|
|
41
|
-
$text += value.$text || "";
|
|
42
|
-
Object.assign(result, value.delta);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
Object.assign(result, { $text: result.$text || $text || undefined });
|
|
46
|
-
await resolve(result);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
controller.error(error);
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
controller.close();
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
await resolve(output);
|
|
58
|
-
return output;
|
|
59
|
-
}
|
|
60
|
-
export function asyncGeneratorToReadableStream(generator) {
|
|
61
|
-
return new ReadableStream({
|
|
62
|
-
async start(controller) {
|
|
63
|
-
try {
|
|
64
|
-
for await (const value of generator) {
|
|
65
|
-
controller.enqueue(value);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
controller.error(error);
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
controller.close();
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export function isAsyncGenerator(value) {
|
|
78
|
-
return Symbol.asyncIterator in value;
|
|
79
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import omitBy from "lodash/omitBy";
|
|
2
|
-
import { isNonNullable } from "./is-non-nullable";
|
|
3
|
-
import { OrderedRecord } from "./ordered-map";
|
|
4
|
-
export function outputsToJsonSchema(outputs) {
|
|
5
|
-
const outputToSchema = (output) => {
|
|
6
|
-
const properties = output.type === "object" && output.properties?.$indexes.length
|
|
7
|
-
? OrderedRecord.map(output.properties, (property) => {
|
|
8
|
-
if (!property.name)
|
|
9
|
-
return null;
|
|
10
|
-
const schema = outputToSchema(property);
|
|
11
|
-
if (!schema)
|
|
12
|
-
return null;
|
|
13
|
-
return { schema, property };
|
|
14
|
-
}).filter(isNonNullable)
|
|
15
|
-
: undefined;
|
|
16
|
-
return omitBy({
|
|
17
|
-
type: output.type,
|
|
18
|
-
description: output.description,
|
|
19
|
-
properties: properties?.length
|
|
20
|
-
? Object.fromEntries(properties.map((p) => [p.property.name, p.schema]))
|
|
21
|
-
: undefined,
|
|
22
|
-
items: output.type === "array" && output.items
|
|
23
|
-
? outputToSchema(output.items)
|
|
24
|
-
: undefined,
|
|
25
|
-
additionalProperties: output.type === "object" ? false : undefined,
|
|
26
|
-
required: properties?.length
|
|
27
|
-
? properties
|
|
28
|
-
.filter((i) => i.property.required)
|
|
29
|
-
.map((i) => i.property.name)
|
|
30
|
-
: undefined,
|
|
31
|
-
}, (v) => v === undefined);
|
|
32
|
-
};
|
|
33
|
-
return outputToSchema({
|
|
34
|
-
type: "object",
|
|
35
|
-
properties: outputs,
|
|
36
|
-
});
|
|
37
|
-
}
|
package/lib/esm/utils/union.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type UnionToIntersection<U, O = any> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I extends O ? I : never : never;
|
package/lib/esm/utils/union.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|