@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,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.renderMessage = renderMessage;
|
|
7
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
8
|
-
function renderMessage(template, variables) {
|
|
9
|
-
return mustache_1.default.render(template, variables, undefined, {
|
|
10
|
-
escape: (v) => {
|
|
11
|
-
return typeof v === "object" ? JSON.stringify(v) : v;
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
}
|
package/lib/cjs/utils/omit.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type OmitPropsFromUnion<T, K extends string | number | symbol> = T extends any ? Omit<T, K> : never;
|
package/lib/cjs/utils/omit.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AuthConfig, FetchRequest, HTTPMethod } from "../definitions/open-api";
|
|
2
|
-
import type { OpenAPIAgentDefinition } from "../open-api-agent";
|
|
3
|
-
export declare function formatOpenAPIRequest(api: {
|
|
4
|
-
url: string;
|
|
5
|
-
method: HTTPMethod;
|
|
6
|
-
auth?: AuthConfig;
|
|
7
|
-
}, inputs: OpenAPIAgentDefinition["inputs"], input: Record<string, any>): Promise<FetchRequest>;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatOpenAPIRequest = formatOpenAPIRequest;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const logger_1 = require("./logger");
|
|
6
|
-
const ordered_map_1 = require("./ordered-map");
|
|
7
|
-
async function formatOpenAPIRequest(api, inputs, input) {
|
|
8
|
-
const { url, method, ...inputParams } = processParameters(api, inputs, input);
|
|
9
|
-
logger_1.logger.debug("inputParams", inputParams);
|
|
10
|
-
const authParams = await getAuthParams(api.auth);
|
|
11
|
-
logger_1.logger.debug("authParams", authParams);
|
|
12
|
-
return {
|
|
13
|
-
url,
|
|
14
|
-
method,
|
|
15
|
-
...(0, lodash_1.omitBy)({
|
|
16
|
-
...inputParams,
|
|
17
|
-
query: { ...inputParams.query, ...authParams.query },
|
|
18
|
-
cookies: { ...inputParams.cookies, ...authParams.cookies },
|
|
19
|
-
headers: { ...inputParams.headers, ...authParams.headers },
|
|
20
|
-
}, (i) => (0, lodash_1.isEmpty)(i)),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async function getAuthParams(auth) {
|
|
24
|
-
if (!auth)
|
|
25
|
-
return {};
|
|
26
|
-
if (auth.type === "custom") {
|
|
27
|
-
return await auth.auth();
|
|
28
|
-
}
|
|
29
|
-
const { type, key, token } = auth;
|
|
30
|
-
switch (auth.in) {
|
|
31
|
-
case "query":
|
|
32
|
-
return { query: { [key || "token"]: token } };
|
|
33
|
-
case "cookie":
|
|
34
|
-
return { cookies: { [key || "token"]: token } };
|
|
35
|
-
default: {
|
|
36
|
-
const prefix = type === "bearer" ? "Bearer " : type === "basic" ? "Basic " : "";
|
|
37
|
-
return { headers: { [key || "Authorization"]: `${prefix}${token}` } };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function processParameters(api, inputs, input) {
|
|
42
|
-
const result = {
|
|
43
|
-
url: api.url,
|
|
44
|
-
method: api.method,
|
|
45
|
-
headers: {},
|
|
46
|
-
query: {},
|
|
47
|
-
cookies: {},
|
|
48
|
-
body: {},
|
|
49
|
-
};
|
|
50
|
-
for (const [key, value] of Object.entries(input)) {
|
|
51
|
-
const schema = ordered_map_1.OrderedRecord.find(inputs, (x) => x.name === key);
|
|
52
|
-
if (!schema)
|
|
53
|
-
continue;
|
|
54
|
-
switch (schema.in) {
|
|
55
|
-
case "query":
|
|
56
|
-
result.query[key] = value;
|
|
57
|
-
break;
|
|
58
|
-
case "header":
|
|
59
|
-
result.headers[key] = value;
|
|
60
|
-
break;
|
|
61
|
-
case "cookie":
|
|
62
|
-
result.cookies[key] = value;
|
|
63
|
-
break;
|
|
64
|
-
case "body":
|
|
65
|
-
result.body[key] = value;
|
|
66
|
-
break;
|
|
67
|
-
case "path":
|
|
68
|
-
result.url = result.url.replace(`{${key}}`, String(value));
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
// 没有指定 in 的情况
|
|
72
|
-
if (result.method.toLowerCase() === "get") {
|
|
73
|
-
result.query[key] = value;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
result.body[key] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
@@ -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,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderedRecord = void 0;
|
|
4
|
-
var OrderedRecord;
|
|
5
|
-
(function (OrderedRecord) {
|
|
6
|
-
function iterator(record) {
|
|
7
|
-
return (function* () {
|
|
8
|
-
if (!record)
|
|
9
|
-
return;
|
|
10
|
-
for (const id of record.$indexes) {
|
|
11
|
-
yield record[id];
|
|
12
|
-
}
|
|
13
|
-
})();
|
|
14
|
-
}
|
|
15
|
-
OrderedRecord.iterator = iterator;
|
|
16
|
-
function map(record, fn) {
|
|
17
|
-
if (!record)
|
|
18
|
-
return [];
|
|
19
|
-
const result = new Array(record.$indexes.length);
|
|
20
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
21
|
-
result[i] = fn(record[record.$indexes[i]], i);
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
OrderedRecord.map = map;
|
|
26
|
-
function toArray(record) {
|
|
27
|
-
return OrderedRecord.map(record, (value) => value);
|
|
28
|
-
}
|
|
29
|
-
OrderedRecord.toArray = toArray;
|
|
30
|
-
function fromArray(array) {
|
|
31
|
-
const record = { $indexes: [] };
|
|
32
|
-
for (const value of array ?? []) {
|
|
33
|
-
record[value.id] = value;
|
|
34
|
-
record.$indexes.push(value.id);
|
|
35
|
-
}
|
|
36
|
-
return record;
|
|
37
|
-
}
|
|
38
|
-
OrderedRecord.fromArray = fromArray;
|
|
39
|
-
function find(record, predicate) {
|
|
40
|
-
if (!record)
|
|
41
|
-
return undefined;
|
|
42
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
43
|
-
const id = record.$indexes[i];
|
|
44
|
-
const value = record[id];
|
|
45
|
-
if (predicate(value, i))
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
OrderedRecord.find = find;
|
|
51
|
-
function filter(record, predicate) {
|
|
52
|
-
if (!record)
|
|
53
|
-
return [];
|
|
54
|
-
const result = [];
|
|
55
|
-
for (let i = 0; i < record.$indexes.length; i++) {
|
|
56
|
-
const id = record.$indexes[i];
|
|
57
|
-
const value = record[id];
|
|
58
|
-
if (predicate(value, i))
|
|
59
|
-
result.push(value);
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
OrderedRecord.filter = filter;
|
|
64
|
-
function at(record, index) {
|
|
65
|
-
if (!record?.$indexes.length)
|
|
66
|
-
return undefined;
|
|
67
|
-
const id = record.$indexes.at(index);
|
|
68
|
-
return record[id];
|
|
69
|
-
}
|
|
70
|
-
OrderedRecord.at = at;
|
|
71
|
-
function push(record, ...items) {
|
|
72
|
-
for (const item of items) {
|
|
73
|
-
if (record[item.id])
|
|
74
|
-
throw new Error(`Item with id ${item.id} already exists`);
|
|
75
|
-
record.$indexes.push(item.id);
|
|
76
|
-
record[item.id] = item;
|
|
77
|
-
}
|
|
78
|
-
return record;
|
|
79
|
-
}
|
|
80
|
-
OrderedRecord.push = push;
|
|
81
|
-
function merge(...records) {
|
|
82
|
-
const result = { $indexes: [] };
|
|
83
|
-
for (const record of records) {
|
|
84
|
-
for (const id of record.$indexes) {
|
|
85
|
-
if (!result[id])
|
|
86
|
-
result.$indexes.push(id);
|
|
87
|
-
result[id] = record[id];
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
OrderedRecord.merge = merge;
|
|
93
|
-
function pushOrUpdate(record, ...items) {
|
|
94
|
-
for (const item of items) {
|
|
95
|
-
if (!record[item.id]) {
|
|
96
|
-
record.$indexes.push(item.id);
|
|
97
|
-
}
|
|
98
|
-
record[item.id] = item;
|
|
99
|
-
}
|
|
100
|
-
return record;
|
|
101
|
-
}
|
|
102
|
-
OrderedRecord.pushOrUpdate = pushOrUpdate;
|
|
103
|
-
})(OrderedRecord || (exports.OrderedRecord = OrderedRecord = {}));
|
package/lib/cjs/utils/partial.js
DELETED
|
@@ -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,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,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objectToRunnableResponseStream = objectToRunnableResponseStream;
|
|
4
|
-
exports.runnableResponseStreamToObject = runnableResponseStreamToObject;
|
|
5
|
-
exports.extractOutputsFromRunnableOutput = extractOutputsFromRunnableOutput;
|
|
6
|
-
exports.asyncGeneratorToReadableStream = asyncGeneratorToReadableStream;
|
|
7
|
-
exports.isAsyncGenerator = isAsyncGenerator;
|
|
8
|
-
const runnable_1 = require("../runnable");
|
|
9
|
-
function objectToRunnableResponseStream(obj) {
|
|
10
|
-
return new ReadableStream({
|
|
11
|
-
start(controller) {
|
|
12
|
-
controller.enqueue({ $text: obj.$text || undefined, delta: obj });
|
|
13
|
-
controller.close();
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async function runnableResponseStreamToObject(stream) {
|
|
18
|
-
let $text = "";
|
|
19
|
-
const result = {};
|
|
20
|
-
for await (const value of stream) {
|
|
21
|
-
if ((0, runnable_1.isRunnableResponseDelta)(value)) {
|
|
22
|
-
$text += value.$text || "";
|
|
23
|
-
Object.assign(result, value.delta);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
Object.assign(result, { $text: result.$text || $text || undefined });
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Extracts the outputs from a runnable output stream and run the
|
|
31
|
-
* resolve function on the result before the stream closes. It can be
|
|
32
|
-
* used to update the memories of an agent.
|
|
33
|
-
* @param output The runnable output stream or object
|
|
34
|
-
* @param resolve The function to run on the result
|
|
35
|
-
* @returns The runnable output stream or object
|
|
36
|
-
*/
|
|
37
|
-
async function extractOutputsFromRunnableOutput(output, resolve) {
|
|
38
|
-
if (output instanceof ReadableStream ||
|
|
39
|
-
isAsyncGenerator(output)) {
|
|
40
|
-
return new ReadableStream({
|
|
41
|
-
async start(controller) {
|
|
42
|
-
try {
|
|
43
|
-
const result = {};
|
|
44
|
-
let $text = "";
|
|
45
|
-
for await (const value of output) {
|
|
46
|
-
controller.enqueue(value);
|
|
47
|
-
if ((0, runnable_1.isRunnableResponseDelta)(value)) {
|
|
48
|
-
$text += value.$text || "";
|
|
49
|
-
Object.assign(result, value.delta);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
Object.assign(result, { $text: result.$text || $text || undefined });
|
|
53
|
-
await resolve(result);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
controller.error(error);
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
controller.close();
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
await resolve(output);
|
|
65
|
-
return output;
|
|
66
|
-
}
|
|
67
|
-
function asyncGeneratorToReadableStream(generator) {
|
|
68
|
-
return new ReadableStream({
|
|
69
|
-
async start(controller) {
|
|
70
|
-
try {
|
|
71
|
-
for await (const value of generator) {
|
|
72
|
-
controller.enqueue(value);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
controller.error(error);
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
controller.close();
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function isAsyncGenerator(value) {
|
|
85
|
-
return Symbol.asyncIterator in value;
|
|
86
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.outputsToJsonSchema = outputsToJsonSchema;
|
|
7
|
-
const omitBy_1 = __importDefault(require("lodash/omitBy"));
|
|
8
|
-
const is_non_nullable_1 = require("./is-non-nullable");
|
|
9
|
-
const ordered_map_1 = require("./ordered-map");
|
|
10
|
-
function outputsToJsonSchema(outputs) {
|
|
11
|
-
const outputToSchema = (output) => {
|
|
12
|
-
const properties = output.type === "object" && output.properties?.$indexes.length
|
|
13
|
-
? ordered_map_1.OrderedRecord.map(output.properties, (property) => {
|
|
14
|
-
if (!property.name)
|
|
15
|
-
return null;
|
|
16
|
-
const schema = outputToSchema(property);
|
|
17
|
-
if (!schema)
|
|
18
|
-
return null;
|
|
19
|
-
return { schema, property };
|
|
20
|
-
}).filter(is_non_nullable_1.isNonNullable)
|
|
21
|
-
: undefined;
|
|
22
|
-
return (0, omitBy_1.default)({
|
|
23
|
-
type: output.type,
|
|
24
|
-
description: output.description,
|
|
25
|
-
properties: properties?.length
|
|
26
|
-
? Object.fromEntries(properties.map((p) => [p.property.name, p.schema]))
|
|
27
|
-
: undefined,
|
|
28
|
-
items: output.type === "array" && output.items
|
|
29
|
-
? outputToSchema(output.items)
|
|
30
|
-
: undefined,
|
|
31
|
-
additionalProperties: output.type === "object" ? false : undefined,
|
|
32
|
-
required: properties?.length
|
|
33
|
-
? properties
|
|
34
|
-
.filter((i) => i.property.required)
|
|
35
|
-
.map((i) => i.property.name)
|
|
36
|
-
: undefined,
|
|
37
|
-
}, (v) => v === undefined);
|
|
38
|
-
};
|
|
39
|
-
return outputToSchema({
|
|
40
|
-
type: "object",
|
|
41
|
-
properties: outputs,
|
|
42
|
-
});
|
|
43
|
-
}
|
package/lib/cjs/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/cjs/utils/union.js
DELETED
package/lib/dts/agent.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { Context, ContextState } from "./context";
|
|
2
|
-
import type { DataSchema } from "./definitions/data-schema";
|
|
3
|
-
import type { AgentMemory, CreateRunnableMemory } from "./definitions/memory";
|
|
4
|
-
import type { AgentPreload, BindAgentInputs, BoundAgent, PreloadCreator } from "./definitions/preload";
|
|
5
|
-
import type { MemorableSearchOutput, MemoryItemWithScore, MemoryMessage } from "./memorable";
|
|
6
|
-
import { type RunOptions, Runnable, type RunnableDefinition, type RunnableInput, type RunnableOutput, type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "./runnable";
|
|
7
|
-
import { OrderedRecord } from "./utils";
|
|
8
|
-
import type { ExtractRunnableOutputType } from "./utils/runnable-type";
|
|
9
|
-
export type AgentPreloads = Record<string, unknown>;
|
|
10
|
-
export type AgentMemories = Record<string, MemoryItemWithScore[]>;
|
|
11
|
-
export declare abstract class Agent<I extends RunnableInput = RunnableInput, O extends RunnableOutput = RunnableOutput, State extends ContextState = ContextState, Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> extends Runnable<I, O, State> {
|
|
12
|
-
definition: AgentDefinition;
|
|
13
|
-
context?: Context<State> | undefined;
|
|
14
|
-
constructor(definition: AgentDefinition, context?: Context<State> | undefined);
|
|
15
|
-
private getMemoryQuery;
|
|
16
|
-
/**
|
|
17
|
-
* Load memories that are defined in the agent definition.
|
|
18
|
-
* @param input The agent input.
|
|
19
|
-
* @param context The AIGNE context.
|
|
20
|
-
* @returns A dictionary of memories, where the key is the memory id or name and the value is an array of memory items.
|
|
21
|
-
*/
|
|
22
|
-
protected loadMemories(input: I): Promise<Memories>;
|
|
23
|
-
/**
|
|
24
|
-
* Update memories by user messages and assistant responses.
|
|
25
|
-
* @param messages Messages to be added to memories.
|
|
26
|
-
*/
|
|
27
|
-
protected updateMemories(messages: MemoryMessage[]): Promise<void>;
|
|
28
|
-
protected loadPreloads(input: I): Promise<Preloads>;
|
|
29
|
-
run(input: I, options: RunOptions & {
|
|
30
|
-
stream: true;
|
|
31
|
-
}): Promise<RunnableResponseStream<O>>;
|
|
32
|
-
run(input: I, options?: RunOptions & {
|
|
33
|
-
stream?: false;
|
|
34
|
-
}): Promise<O>;
|
|
35
|
-
private addHistory;
|
|
36
|
-
/**
|
|
37
|
-
* Hook that is called before the agent result is returned.
|
|
38
|
-
* @param _result The agent result.
|
|
39
|
-
*/
|
|
40
|
-
protected onResult(_result: O): Promise<void>;
|
|
41
|
-
abstract process(input: AgentProcessInput<I, Preloads, Memories>, options: AgentProcessOptions): Promise<RunnableResponse<O> | AsyncGenerator<RunnableResponseChunk<O>, void>> | AsyncGenerator<RunnableResponseChunk<O>, void>;
|
|
42
|
-
/**
|
|
43
|
-
* Bind some inputs to the agent, used for process of `PipelineAgent` or case of `LLMDecisionAgent`.
|
|
44
|
-
* @param options The bind options.
|
|
45
|
-
* @returns The bound agent.
|
|
46
|
-
*/
|
|
47
|
-
bind<Input extends BindAgentInputs<Record<string, never>, typeof this>>(options: {
|
|
48
|
-
description?: string;
|
|
49
|
-
input?: Input;
|
|
50
|
-
}): BoundAgent<Record<string, never>, typeof this, Readonly<Input>>;
|
|
51
|
-
}
|
|
52
|
-
export type AgentProcessOptions<Preloads extends AgentPreloads = AgentPreloads, Memories extends AgentMemories = AgentMemories> = {
|
|
53
|
-
preloads: Preloads;
|
|
54
|
-
memories: Memories;
|
|
55
|
-
};
|
|
56
|
-
export type AgentProcessInput<I extends RunnableInput, Preloads extends AgentPreloads, Memories extends AgentMemories> = I & Preloads & Memories;
|
|
57
|
-
export interface AgentDefinition extends RunnableDefinition {
|
|
58
|
-
preloads?: OrderedRecord<AgentPreload>;
|
|
59
|
-
memories?: OrderedRecord<AgentMemory>;
|
|
60
|
-
}
|
|
61
|
-
export type CreateAgentInputSchema = Record<string, DataSchema>;
|
|
62
|
-
export type CreateAgentOutputSchema<Extra extends Record<string, unknown> = Record<string, unknown>> = Record<string, DataSchema & Extra>;
|
|
63
|
-
export type CreateAgentPreloadsSchema<I extends CreateAgentInputSchema> = Record<string, PreloadCreator<I>>;
|
|
64
|
-
export type CreateAgentPreloadsType<I extends CreateAgentInputSchema, Preloads extends CreateAgentPreloadsSchema<I>> = {
|
|
65
|
-
[name in keyof Preloads]: ExtractRunnableOutputType<ReturnType<Preloads[name]>["runnable"]>;
|
|
66
|
-
};
|
|
67
|
-
export type CreateAgentMemoriesSchema<I extends CreateAgentInputSchema, Extras extends Record<string, unknown> = Record<string, unknown>> = Record<string, CreateRunnableMemory<I> & Extras>;
|
|
68
|
-
export type CreateAgentMemoriesType<I extends CreateAgentInputSchema, Memories extends CreateAgentMemoriesSchema<I, Record<string, unknown>>> = {
|
|
69
|
-
[key in keyof Memories]: MemorableSearchOutput<Memories[key]["memory"]>;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Common options to create Agent.
|
|
73
|
-
*/
|
|
74
|
-
export interface CreateAgentOptions<I extends CreateAgentInputSchema, O extends CreateAgentOutputSchema, State extends ContextState, Preloads extends CreateAgentPreloadsSchema<I>, Memories extends CreateAgentMemoriesSchema<I, Record<string, unknown>>> {
|
|
75
|
-
context?: Context<State>;
|
|
76
|
-
/**
|
|
77
|
-
* Agent name, used to identify the agent.
|
|
78
|
-
*/
|
|
79
|
-
name?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Input variables for this agent.
|
|
82
|
-
*/
|
|
83
|
-
inputs: I;
|
|
84
|
-
/**
|
|
85
|
-
* Output variables for this agent.
|
|
86
|
-
*/
|
|
87
|
-
outputs: O;
|
|
88
|
-
/**
|
|
89
|
-
* Preload runnables before running this agent. the preloaded data are available in the agent as input variables.
|
|
90
|
-
*/
|
|
91
|
-
preloads?: Preloads;
|
|
92
|
-
/**
|
|
93
|
-
* Memories to be used in this agent.
|
|
94
|
-
*/
|
|
95
|
-
memories?: Memories;
|
|
96
|
-
}
|
package/lib/dts/constants.d.ts
DELETED
package/lib/dts/context.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { LLMModelConfiguration } from "./llm-model";
|
|
2
|
-
import type { Memorable } from "./memorable";
|
|
3
|
-
import type { Runnable, RunnableDefinition } from "./runnable";
|
|
4
|
-
export interface ContextState {
|
|
5
|
-
userId?: string;
|
|
6
|
-
sessionId?: string;
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
}
|
|
9
|
-
export interface ContextConfig {
|
|
10
|
-
llmModel?: LLMModelConfiguration;
|
|
11
|
-
}
|
|
12
|
-
export interface Context<State extends ContextState = ContextState, Config extends ContextConfig = ContextConfig> {
|
|
13
|
-
id: string;
|
|
14
|
-
state: State;
|
|
15
|
-
config: Config;
|
|
16
|
-
historyManager?: Memorable<{
|
|
17
|
-
input: object;
|
|
18
|
-
output: object;
|
|
19
|
-
}>;
|
|
20
|
-
resolve<T extends Runnable>(id: string | RunnableDefinition | T): Promise<T>;
|
|
21
|
-
register<R extends Array<RunnableDefinition | Runnable> = []>(...definition: R): void;
|
|
22
|
-
resolveDependency<T>(token: string | symbol): T;
|
|
23
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { MakeNullablePropertyOptional } from "../utils/nullable";
|
|
2
|
-
import { OrderedRecord } from "../utils/ordered-map";
|
|
3
|
-
import type { ArrayElement } from "../utils/type-utils";
|
|
4
|
-
import type { DataType } from "./data-type";
|
|
5
|
-
export declare function schemaToDataType(dataType: {
|
|
6
|
-
[name: string]: DataSchema;
|
|
7
|
-
}): OrderedRecord<DataType>;
|
|
8
|
-
export type DataSchema = DataSchemaString | DataSchemaNumber | DataSchemaBoolean | DataSchemaObject | DataSchemaArray;
|
|
9
|
-
export interface DataSchemaBase {
|
|
10
|
-
description?: string;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface DataSchemaString extends DataSchemaBase {
|
|
14
|
-
type: "string";
|
|
15
|
-
}
|
|
16
|
-
export interface DataSchemaNumber extends DataSchemaBase {
|
|
17
|
-
type: "number";
|
|
18
|
-
}
|
|
19
|
-
export interface DataSchemaBoolean extends DataSchemaBase {
|
|
20
|
-
type: "boolean";
|
|
21
|
-
}
|
|
22
|
-
export interface DataSchemaObject extends DataSchemaBase {
|
|
23
|
-
type: "object";
|
|
24
|
-
properties?: {
|
|
25
|
-
[key: string]: DataSchema;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export interface DataSchemaArray extends DataSchemaBase {
|
|
29
|
-
type: "array";
|
|
30
|
-
items?: DataSchema;
|
|
31
|
-
}
|
|
32
|
-
type SchemaTypeInner<T extends DataSchema> = T extends DataSchemaString ? string : T extends DataSchemaNumber ? number : T extends DataSchemaBoolean ? boolean : T extends DataSchemaObject ? MakeNullablePropertyOptional<{
|
|
33
|
-
[K in keyof T["properties"]]: SchemaType<NonNullable<T["properties"]>[K]>;
|
|
34
|
-
}> : T extends DataSchemaArray ? Extract<T["items"], null | undefined> extends never ? SchemaType<NonNullable<T["items"]>>[] : SchemaType<{
|
|
35
|
-
type: "object";
|
|
36
|
-
}>[] : never;
|
|
37
|
-
type SchemaType<T extends DataSchema> = T["required"] extends true ? SchemaTypeInner<T> : SchemaTypeInner<T> | undefined | null;
|
|
38
|
-
export type SchemaToType<T extends Record<string, DataSchema>> = SchemaType<{
|
|
39
|
-
type: "object";
|
|
40
|
-
required: true;
|
|
41
|
-
properties: T;
|
|
42
|
-
}>;
|
|
43
|
-
type TypeToSchemaInner<T> = Extract<T, string | undefined> extends string | undefined ? DataSchemaString & {
|
|
44
|
-
required: Extract<T, undefined> extends undefined ? false : true;
|
|
45
|
-
} : Extract<T, number | undefined> extends number | undefined ? DataSchemaNumber & {
|
|
46
|
-
required: Extract<T, undefined> extends undefined ? false : true;
|
|
47
|
-
} : Extract<T, boolean | undefined> extends boolean | undefined ? DataSchemaBoolean & {
|
|
48
|
-
required: Extract<T, undefined> extends undefined ? false : true;
|
|
49
|
-
} : Extract<T, object | undefined> extends object | undefined ? DataSchemaObject & {
|
|
50
|
-
properties: {
|
|
51
|
-
[K in keyof T]: TypeToSchemaInner<NonNullable<T[K]>>;
|
|
52
|
-
};
|
|
53
|
-
required: Extract<T, undefined> extends undefined ? false : true;
|
|
54
|
-
} : Extract<T, [] | undefined> extends [] | undefined ? DataSchemaArray & {
|
|
55
|
-
items: Extract<T, undefined> extends undefined ? undefined : TypeToSchemaInner<NonNullable<ArrayElement<T>>>;
|
|
56
|
-
required: Extract<T, undefined> extends undefined ? false : true;
|
|
57
|
-
} : never;
|
|
58
|
-
export type TypeToSchema<T extends Record<string, unknown>> = {
|
|
59
|
-
[K in keyof T]: TypeToSchemaInner<T[K]>;
|
|
60
|
-
};
|
|
61
|
-
export {};
|