@aigne/core 0.0.3 → 0.0.4
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/index.js +1 -1
- package/lib/cjs/types/index.js +2 -4
- package/lib/esm/index.js +1 -1
- package/lib/esm/types/index.js +2 -4
- package/lib/types/index.d.ts +1 -1
- package/lib/types/types/agent.d.ts +5 -0
- package/lib/types/types/index.d.ts +2 -4
- package/lib/types/types/runnable.d.ts +20 -0
- package/package.json +3 -4
- package/lib/cjs/assistant/generate-output.js +0 -101
- package/lib/cjs/assistant/select-agent.js +0 -76
- package/lib/cjs/assistant/type.js +0 -11
- package/lib/cjs/common/aid.js +0 -42
- package/lib/cjs/common/index.js +0 -238
- package/lib/cjs/common/resource-manager.js +0 -199
- package/lib/cjs/constants.js +0 -9
- package/lib/cjs/executor/agent.js +0 -10
- package/lib/cjs/executor/aigc.js +0 -28
- package/lib/cjs/executor/api.js +0 -64
- package/lib/cjs/executor/base.js +0 -676
- package/lib/cjs/executor/blocklet.js +0 -25
- package/lib/cjs/executor/call-agent.js +0 -105
- package/lib/cjs/executor/decision.js +0 -478
- package/lib/cjs/executor/image-blender.js +0 -32
- package/lib/cjs/executor/index.js +0 -81
- package/lib/cjs/executor/llm.js +0 -379
- package/lib/cjs/executor/logic.js +0 -167
- package/lib/cjs/libs/blocklet/vc.js +0 -92
- package/lib/cjs/libs/openapi/request/index.js +0 -24
- package/lib/cjs/libs/openapi/request/util.js +0 -146
- package/lib/cjs/libs/openapi/types/index.js +0 -17
- package/lib/cjs/libs/openapi/util/call.js +0 -15
- package/lib/cjs/libs/openapi/util/check-schema.js +0 -67
- package/lib/cjs/libs/openapi/util/convert-schema.js +0 -44
- package/lib/cjs/libs/openapi/util/flatten-open-api.js +0 -21
- package/lib/cjs/libs/openapi/util/get-open-api-i18n-text.js +0 -7
- package/lib/cjs/runtime/resource-blocklet.js +0 -5
- package/lib/cjs/runtime/runtime.js +0 -143
- package/lib/cjs/types/assistant/index.js +0 -31
- package/lib/cjs/types/assistant/mustache/ReadableMustache.js +0 -69
- package/lib/cjs/types/assistant/mustache/directive.js +0 -35
- package/lib/cjs/types/assistant/mustache/mustache.js +0 -688
- package/lib/cjs/types/resource/index.js +0 -47
- package/lib/cjs/types/resource/project.js +0 -35
- package/lib/cjs/types/runtime/error.js +0 -18
- package/lib/cjs/types/runtime/index.js +0 -37
- package/lib/cjs/types/runtime/runtime-resource-blocklet-state.js +0 -4
- package/lib/cjs/types/runtime/schema.js +0 -259
- package/lib/cjs/utils/cron-job.js +0 -48
- package/lib/cjs/utils/extract-metadata-transform.js +0 -58
- package/lib/cjs/utils/extract-metadata-transform.test.js +0 -61
- package/lib/cjs/utils/fs.js +0 -49
- package/lib/cjs/utils/get-blocklet-agent.js +0 -351
- package/lib/cjs/utils/geti.js +0 -37
- package/lib/cjs/utils/is-non-nullable.js +0 -20
- package/lib/cjs/utils/render-message.js +0 -23
- package/lib/cjs/utils/resolve-secret-inputs.js +0 -49
- package/lib/cjs/utils/retry.js +0 -19
- package/lib/cjs/utils/task-id.js +0 -7
- package/lib/cjs/utils/tool-calls-transform.js +0 -18
- package/lib/esm/assistant/generate-output.js +0 -91
- package/lib/esm/assistant/select-agent.js +0 -71
- package/lib/esm/assistant/type.js +0 -7
- package/lib/esm/common/aid.js +0 -38
- package/lib/esm/common/index.js +0 -232
- package/lib/esm/common/resource-manager.js +0 -192
- package/lib/esm/constants.js +0 -6
- package/lib/esm/executor/agent.js +0 -6
- package/lib/esm/executor/aigc.js +0 -24
- package/lib/esm/executor/api.js +0 -34
- package/lib/esm/executor/base.js +0 -668
- package/lib/esm/executor/blocklet.js +0 -21
- package/lib/esm/executor/call-agent.js +0 -98
- package/lib/esm/executor/decision.js +0 -471
- package/lib/esm/executor/image-blender.js +0 -25
- package/lib/esm/executor/index.js +0 -74
- package/lib/esm/executor/llm.js +0 -372
- package/lib/esm/executor/logic.js +0 -160
- package/lib/esm/libs/blocklet/vc.js +0 -85
- package/lib/esm/libs/openapi/request/index.js +0 -20
- package/lib/esm/libs/openapi/request/util.js +0 -136
- package/lib/esm/libs/openapi/types/index.js +0 -1
- package/lib/esm/libs/openapi/util/call.js +0 -8
- package/lib/esm/libs/openapi/util/check-schema.js +0 -62
- package/lib/esm/libs/openapi/util/convert-schema.js +0 -42
- package/lib/esm/libs/openapi/util/flatten-open-api.js +0 -19
- package/lib/esm/libs/openapi/util/get-open-api-i18n-text.js +0 -5
- package/lib/esm/runtime/resource-blocklet.js +0 -2
- package/lib/esm/runtime/runtime.js +0 -136
- package/lib/esm/types/assistant/index.js +0 -9
- package/lib/esm/types/assistant/mustache/ReadableMustache.js +0 -63
- package/lib/esm/types/assistant/mustache/directive.js +0 -29
- package/lib/esm/types/assistant/mustache/mustache.js +0 -686
- package/lib/esm/types/resource/index.js +0 -26
- package/lib/esm/types/resource/project.js +0 -29
- package/lib/esm/types/runtime/error.js +0 -14
- package/lib/esm/types/runtime/index.js +0 -20
- package/lib/esm/types/runtime/runtime-resource-blocklet-state.js +0 -1
- package/lib/esm/types/runtime/schema.js +0 -249
- package/lib/esm/utils/cron-job.js +0 -44
- package/lib/esm/utils/extract-metadata-transform.js +0 -54
- package/lib/esm/utils/extract-metadata-transform.test.js +0 -59
- package/lib/esm/utils/fs.js +0 -41
- package/lib/esm/utils/get-blocklet-agent.js +0 -344
- package/lib/esm/utils/geti.js +0 -30
- package/lib/esm/utils/is-non-nullable.js +0 -13
- package/lib/esm/utils/render-message.js +0 -20
- package/lib/esm/utils/resolve-secret-inputs.js +0 -46
- package/lib/esm/utils/retry.js +0 -16
- package/lib/esm/utils/task-id.js +0 -3
- package/lib/esm/utils/tool-calls-transform.js +0 -15
- package/lib/types/assistant/generate-output.d.ts +0 -29
- package/lib/types/assistant/select-agent.d.ts +0 -14
- package/lib/types/assistant/type.d.ts +0 -61
- package/lib/types/common/aid.d.ts +0 -18
- package/lib/types/common/index.d.ts +0 -7
- package/lib/types/common/resource-manager.d.ts +0 -88
- package/lib/types/constants.d.ts +0 -6
- package/lib/types/executor/agent.d.ts +0 -5
- package/lib/types/executor/aigc.d.ts +0 -9
- package/lib/types/executor/api.d.ts +0 -9
- package/lib/types/executor/base.d.ts +0 -209
- package/lib/types/executor/blocklet.d.ts +0 -9
- package/lib/types/executor/call-agent.d.ts +0 -12
- package/lib/types/executor/decision.d.ts +0 -20
- package/lib/types/executor/image-blender.d.ts +0 -9
- package/lib/types/executor/index.d.ts +0 -8
- package/lib/types/executor/llm.d.ts +0 -38
- package/lib/types/executor/logic.d.ts +0 -9
- package/lib/types/libs/blocklet/vc.d.ts +0 -17
- package/lib/types/libs/openapi/request/index.d.ts +0 -17
- package/lib/types/libs/openapi/request/util.d.ts +0 -40
- package/lib/types/libs/openapi/types/index.d.ts +0 -20
- package/lib/types/libs/openapi/util/call.d.ts +0 -2
- package/lib/types/libs/openapi/util/check-schema.d.ts +0 -3
- package/lib/types/libs/openapi/util/convert-schema.d.ts +0 -8
- package/lib/types/libs/openapi/util/flatten-open-api.d.ts +0 -3
- package/lib/types/libs/openapi/util/get-open-api-i18n-text.d.ts +0 -2
- package/lib/types/runtime/resource-blocklet.d.ts +0 -2
- package/lib/types/runtime/runtime.d.ts +0 -20
- package/lib/types/types/assistant/index.d.ts +0 -405
- package/lib/types/types/assistant/mustache/ReadableMustache.d.ts +0 -2
- package/lib/types/types/assistant/mustache/directive.d.ts +0 -6
- package/lib/types/types/assistant/mustache/mustache.d.ts +0 -2
- package/lib/types/types/common/index.d.ts +0 -45
- package/lib/types/types/resource/index.d.ts +0 -17
- package/lib/types/types/resource/project.d.ts +0 -41
- package/lib/types/types/runtime/agent.d.ts +0 -33
- package/lib/types/types/runtime/error.d.ts +0 -10
- package/lib/types/types/runtime/index.d.ts +0 -116
- package/lib/types/types/runtime/runtime-resource-blocklet-state.d.ts +0 -5
- package/lib/types/types/runtime/schema.d.ts +0 -110
- package/lib/types/utils/cron-job.d.ts +0 -22
- package/lib/types/utils/extract-metadata-transform.d.ts +0 -16
- package/lib/types/utils/extract-metadata-transform.test.d.ts +0 -1
- package/lib/types/utils/fs.d.ts +0 -9
- package/lib/types/utils/get-blocklet-agent.d.ts +0 -219
- package/lib/types/utils/geti.d.ts +0 -1
- package/lib/types/utils/is-non-nullable.d.ts +0 -2
- package/lib/types/utils/render-message.d.ts +0 -6
- package/lib/types/utils/resolve-secret-inputs.d.ts +0 -11
- package/lib/types/utils/retry.d.ts +0 -1
- package/lib/types/utils/task-id.d.ts +0 -1
- package/lib/types/utils/tool-calls-transform.d.ts +0 -2
- /package/lib/cjs/types/{runtime/agent.js → agent.js} +0 -0
- /package/lib/cjs/types/{common/index.js → runnable.js} +0 -0
- /package/lib/esm/types/{runtime/agent.js → agent.js} +0 -0
- /package/lib/esm/types/{common/index.js → runnable.js} +0 -0
package/lib/cjs/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./types"), exports);
|
package/lib/cjs/types/index.js
CHANGED
|
@@ -14,7 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./common"), exports);
|
|
20
|
-
__exportStar(require("./resource"), exports);
|
|
17
|
+
__exportStar(require("./runnable"), exports);
|
|
18
|
+
__exportStar(require("./agent"), exports);
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './types';
|
package/lib/esm/types/index.js
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface RunOptions {
|
|
2
|
+
stream?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export interface StreamingResponseDelta {
|
|
5
|
+
delta: {
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export type StreamingResponse<T> = ReadableStream<Partial<T> | StreamingResponseDelta>;
|
|
10
|
+
export interface Runnable<I extends {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
} = object, O = object> {
|
|
13
|
+
run(input: I, options: RunOptions & {
|
|
14
|
+
stream: true;
|
|
15
|
+
}): Promise<StreamingResponse<O>>;
|
|
16
|
+
run(input: I, options?: RunOptions & {
|
|
17
|
+
stream?: false;
|
|
18
|
+
}): Promise<O>;
|
|
19
|
+
run(input: I, options?: RunOptions): Promise<O | StreamingResponse<O>>;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aigne/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "AIGNE core library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
|
|
9
9
|
"homepage": "https://github.com/blocklet/ai-studio#readme",
|
|
10
10
|
"license": "ISC",
|
|
11
|
-
"type": "module",
|
|
12
11
|
"main": "./lib/cjs/index.js",
|
|
13
12
|
"module": "./lib/esm/index.js",
|
|
14
13
|
"types": "./lib/types/index.d.js",
|
|
@@ -44,7 +43,7 @@
|
|
|
44
43
|
"snowflake-uuid": "^1.0.0",
|
|
45
44
|
"ufo": "^1.5.4",
|
|
46
45
|
"yaml": "^2.5.0",
|
|
47
|
-
"@blocklet/quickjs": "^0.4.
|
|
46
|
+
"@blocklet/quickjs": "^0.4.172"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@tsconfig/recommended": "^1.0.8",
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
"build:cjs": "tsc -p tsconfig.json --module commonjs --outDir lib/cjs",
|
|
61
60
|
"build:esm": "tsc -p tsconfig.json --module es2022 --outDir lib/esm",
|
|
62
61
|
"build:types": "tsc -p tsconfig.json --declaration --emitDeclarationOnly --outDir lib/types",
|
|
63
|
-
"clean": "rimraf
|
|
62
|
+
"clean": "rimraf lib",
|
|
64
63
|
"test": "jest src/"
|
|
65
64
|
}
|
|
66
65
|
}
|
|
@@ -1,101 +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.metadataStreamOutputFormatPrompt = exports.metadataOutputFormatPrompt = exports.metadataSuffix = exports.metadataPrefix = void 0;
|
|
7
|
-
exports.generateOutput = generateOutput;
|
|
8
|
-
exports.extractMetadataFromStream = extractMetadataFromStream;
|
|
9
|
-
const web_1 = require("stream/web");
|
|
10
|
-
const chat_1 = require("@blocklet/ai-kit/api/types/chat");
|
|
11
|
-
const schema_1 = require("../types/runtime/schema");
|
|
12
|
-
const extract_metadata_transform_1 = require("../utils/extract-metadata-transform");
|
|
13
|
-
const retry_1 = __importDefault(require("../utils/retry"));
|
|
14
|
-
exports.metadataPrefix = '```metadata';
|
|
15
|
-
exports.metadataSuffix = '```';
|
|
16
|
-
const metadataOutputFormatPrompt = (schema) => `\
|
|
17
|
-
## Metadata Schema
|
|
18
|
-
Here is the metadata json schema, inside the <metadata-schema></metadata-schema> XML tags:
|
|
19
|
-
<metadata-schema>
|
|
20
|
-
${schema}
|
|
21
|
-
</metadata-schema>
|
|
22
|
-
|
|
23
|
-
## Output Rules
|
|
24
|
-
- You have to generate a json metadata base on the metadata schema above, inside the <metadata-schema></metadata-schema> XML tags
|
|
25
|
-
- Don't make any explanation
|
|
26
|
-
|
|
27
|
-
## Output Format
|
|
28
|
-
[Generate a json data based on the above metadata schema, put the json string into the following code block]
|
|
29
|
-
${exports.metadataPrefix}
|
|
30
|
-
${exports.metadataSuffix}
|
|
31
|
-
|
|
32
|
-
## Output Example
|
|
33
|
-
${exports.metadataPrefix}
|
|
34
|
-
{"key": "value"}
|
|
35
|
-
${exports.metadataSuffix}
|
|
36
|
-
`;
|
|
37
|
-
exports.metadataOutputFormatPrompt = metadataOutputFormatPrompt;
|
|
38
|
-
const metadataStreamOutputFormatPrompt = (schema) => `\
|
|
39
|
-
## Metadata Schema
|
|
40
|
-
Here is the metadata json schema, inside the <metadata-schema></metadata-schema> XML tags:
|
|
41
|
-
<metadata-schema>
|
|
42
|
-
${schema}
|
|
43
|
-
</metadata-schema>
|
|
44
|
-
|
|
45
|
-
## Output Rules
|
|
46
|
-
- You have to generate a text content and a json metadata base on the metadata schema above, inside the <metadata-schema></metadata-schema> XML tags
|
|
47
|
-
- Don't make any explanation
|
|
48
|
-
|
|
49
|
-
## Output Format
|
|
50
|
-
[Your text content here]
|
|
51
|
-
[Generate a json data based on the above metadata schema, put the json string into the following code block]
|
|
52
|
-
${exports.metadataPrefix}
|
|
53
|
-
${exports.metadataSuffix}
|
|
54
|
-
|
|
55
|
-
## Output Example
|
|
56
|
-
[Here is your answer to the the user's question]
|
|
57
|
-
${exports.metadataPrefix}
|
|
58
|
-
{"key": "value"}
|
|
59
|
-
${exports.metadataSuffix}
|
|
60
|
-
`;
|
|
61
|
-
exports.metadataStreamOutputFormatPrompt = metadataStreamOutputFormatPrompt;
|
|
62
|
-
async function generateOutput({ assistant, messages, callAI, maxRetries = 0, datastoreVariables, }) {
|
|
63
|
-
const jsonSchema = (0, schema_1.outputVariablesToJsonSchema)(assistant, { variables: datastoreVariables });
|
|
64
|
-
const joiSchema = (0, schema_1.outputVariablesToJoiSchema)(assistant, { variables: datastoreVariables });
|
|
65
|
-
const outputSchema = JSON.stringify(jsonSchema, null, 2);
|
|
66
|
-
messages.push({
|
|
67
|
-
role: 'system',
|
|
68
|
-
content: (0, exports.metadataOutputFormatPrompt)(outputSchema),
|
|
69
|
-
});
|
|
70
|
-
return (0, retry_1.default)(async () => {
|
|
71
|
-
const result = await callAI({
|
|
72
|
-
assistant,
|
|
73
|
-
input: {
|
|
74
|
-
stream: true,
|
|
75
|
-
messages,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
let text = '';
|
|
79
|
-
for await (const chunk of extractMetadataFromStream(result, true)) {
|
|
80
|
-
if (chunk.type === 'match')
|
|
81
|
-
text += chunk.text;
|
|
82
|
-
}
|
|
83
|
-
const json = JSON.parse(text);
|
|
84
|
-
return await joiSchema.validateAsync(json);
|
|
85
|
-
}, maxRetries);
|
|
86
|
-
}
|
|
87
|
-
function extractMetadataFromStream(input, extract = true) {
|
|
88
|
-
return input
|
|
89
|
-
.pipeThrough(new web_1.TransformStream({
|
|
90
|
-
transform: (chunk, controller) => {
|
|
91
|
-
if ((0, chat_1.isChatCompletionChunk)(chunk))
|
|
92
|
-
if (chunk.delta.content)
|
|
93
|
-
controller.enqueue(chunk.delta.content);
|
|
94
|
-
},
|
|
95
|
-
}))
|
|
96
|
-
.pipeThrough(new extract_metadata_transform_1.ExtractMetadataTransform({
|
|
97
|
-
// Pass empty string to disable extractor
|
|
98
|
-
start: extract ? exports.metadataPrefix : '',
|
|
99
|
-
end: extract ? exports.metadataSuffix : '',
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
@@ -1,76 +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
|
-
const chat_1 = require("@blocklet/ai-kit/api/types/chat");
|
|
7
|
-
const retry_1 = __importDefault(require("../utils/retry"));
|
|
8
|
-
const selectAgentSystemPrompt = () => `\
|
|
9
|
-
### Job Description
|
|
10
|
-
You are a text classification engine that analyzes text data and assigns categories based on user input or automatically determined categories.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Task
|
|
14
|
-
Your task is to assign one categories ONLY to the input text and only one category may be assigned returned in the output.
|
|
15
|
-
Additionally, you need to extract the key words from the text that are related to the classification.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
### Format
|
|
19
|
-
- "input_text" is in the variable text_field.
|
|
20
|
-
- "categories" are specified as a category list in the variable categories or left empty for automatic determination.
|
|
21
|
-
- "classification_instructions" may be included to improve the classification accuracy.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Constraint
|
|
25
|
-
- DO NOT include anything other than the JSON array in your response.
|
|
26
|
-
- The output results must be within the scope of categories, not content outside the scope
|
|
27
|
-
`;
|
|
28
|
-
async function generateSelectAgentName({ assistant, message, callAI, maxRetries = 0, categories, }) {
|
|
29
|
-
return (0, retry_1.default)(async () => {
|
|
30
|
-
const selectAgentIdResponseByPrompt = await callAI({
|
|
31
|
-
assistant,
|
|
32
|
-
input: {
|
|
33
|
-
messages: [
|
|
34
|
-
{
|
|
35
|
-
role: 'system',
|
|
36
|
-
content: `${selectAgentSystemPrompt()}`,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
role: 'user',
|
|
40
|
-
content: '\n { "input_text": ["I recently had a great experience with your company. The service was prompt and the staff was very friendly."],\n "categories": [{,"category_name": "Customer Service"}, {"category_name": "Satisfaction"}, {"category_name": "Sales"}, {"category_name": "Product"}],\n "classification_instructions": []}\n',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
role: 'assistant',
|
|
44
|
-
content: '{"category_name": "Customer Service"}',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
role: 'user',
|
|
48
|
-
content: '\n {"input_text": ["bad service, slow to bring the food"],\n "categories": [{"category_name": "Food Quality"}, {"category_name": "Experience"}, {"category_name": "Price"}],\n "classification_instructions": []}\n',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
role: 'assistant',
|
|
52
|
-
content: '{"category_name": "Experience"}',
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
role: 'user',
|
|
56
|
-
content: `\n {"input_text": [${message}],\n "categories": [${categories}],\n "classification_instructions": []}\n`,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
model: assistant?.model,
|
|
60
|
-
temperature: assistant?.temperature,
|
|
61
|
-
topP: assistant?.topP,
|
|
62
|
-
presencePenalty: assistant?.presencePenalty,
|
|
63
|
-
frequencyPenalty: assistant?.frequencyPenalty,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
let text = '';
|
|
67
|
-
for await (const chunk of selectAgentIdResponseByPrompt) {
|
|
68
|
-
if ((0, chat_1.isChatCompletionChunk)(chunk) && chunk.delta.content) {
|
|
69
|
-
text += chunk.delta.content;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const json = JSON.parse(text);
|
|
73
|
-
return json;
|
|
74
|
-
}, maxRetries);
|
|
75
|
-
}
|
|
76
|
-
exports.default = generateSelectAgentName;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToolCompletionDirective = void 0;
|
|
4
|
-
class ToolCompletionDirective extends Error {
|
|
5
|
-
type;
|
|
6
|
-
constructor(message, type) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.type = type;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.ToolCompletionDirective = ToolCompletionDirective;
|
package/lib/cjs/common/aid.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseIdentity = parseIdentity;
|
|
4
|
-
exports.stringifyIdentity = stringifyIdentity;
|
|
5
|
-
const js_base64_1 = require("js-base64");
|
|
6
|
-
function parseIdentity(aid, options) {
|
|
7
|
-
let blockletDid;
|
|
8
|
-
let projectId;
|
|
9
|
-
let projectRef;
|
|
10
|
-
let agentId;
|
|
11
|
-
try {
|
|
12
|
-
const s = js_base64_1.Base64.decode(aid).split('/');
|
|
13
|
-
if (s.length === 4) {
|
|
14
|
-
[blockletDid, projectId, projectRef, agentId] = s;
|
|
15
|
-
}
|
|
16
|
-
else if (s.length === 3) {
|
|
17
|
-
[projectId, projectRef, agentId] = s;
|
|
18
|
-
}
|
|
19
|
-
else if (s.length === 2) {
|
|
20
|
-
[projectId, agentId] = s;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error('parse assistantId error', { error });
|
|
25
|
-
}
|
|
26
|
-
if (projectId && agentId)
|
|
27
|
-
return {
|
|
28
|
-
blockletDid: blockletDid || undefined,
|
|
29
|
-
projectId,
|
|
30
|
-
projectRef: projectRef || undefined,
|
|
31
|
-
agentId,
|
|
32
|
-
};
|
|
33
|
-
if (options?.rejectWhenError)
|
|
34
|
-
throw new Error(`Invalid assistant identity ${aid}`);
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
function stringifyIdentity({ blockletDid, projectId, projectRef, agentId, }) {
|
|
38
|
-
if (typeof projectId !== 'string' || typeof agentId !== 'string') {
|
|
39
|
-
throw new Error('Invalid aid fragments');
|
|
40
|
-
}
|
|
41
|
-
return js_base64_1.Base64.encodeURI([blockletDid || '', projectId, projectRef || '', agentId].join('/'));
|
|
42
|
-
}
|
package/lib/cjs/common/index.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultImageModel = exports.supportJsonSchemaModels = exports.defaultTextModel = void 0;
|
|
4
|
-
exports.getSupportedModels = getSupportedModels;
|
|
5
|
-
exports.getSupportedImagesModels = getSupportedImagesModels;
|
|
6
|
-
exports.getServiceModePermissionMap = getServiceModePermissionMap;
|
|
7
|
-
exports.defaultTextModel = 'gpt-4o-mini';
|
|
8
|
-
exports.supportJsonSchemaModels = ['gpt-4o', 'gpt-4o-mini'];
|
|
9
|
-
async function getSupportedModels() {
|
|
10
|
-
return [
|
|
11
|
-
{
|
|
12
|
-
brand: 'OpenAI',
|
|
13
|
-
model: 'gpt-4o',
|
|
14
|
-
name: 'GPT4o',
|
|
15
|
-
temperatureMin: 0,
|
|
16
|
-
temperatureMax: 2,
|
|
17
|
-
temperatureDefault: 1,
|
|
18
|
-
topPMin: 0,
|
|
19
|
-
topPMax: 1,
|
|
20
|
-
topPDefault: 1,
|
|
21
|
-
presencePenaltyMin: -2,
|
|
22
|
-
presencePenaltyMax: 2,
|
|
23
|
-
presencePenaltyDefault: 0,
|
|
24
|
-
frequencyPenaltyMin: -2,
|
|
25
|
-
frequencyPenaltyMax: 2,
|
|
26
|
-
frequencyPenaltyDefault: 0,
|
|
27
|
-
maxTokensMin: 1,
|
|
28
|
-
maxTokensMax: 128000,
|
|
29
|
-
maxTokensDefault: 128000,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
brand: 'OpenAI',
|
|
33
|
-
model: 'gpt-4o-mini',
|
|
34
|
-
name: 'GPT4o mini',
|
|
35
|
-
temperatureMin: 0,
|
|
36
|
-
temperatureMax: 2,
|
|
37
|
-
temperatureDefault: 1,
|
|
38
|
-
topPMin: 0,
|
|
39
|
-
topPMax: 1,
|
|
40
|
-
topPDefault: 1,
|
|
41
|
-
presencePenaltyMin: -2,
|
|
42
|
-
presencePenaltyMax: 2,
|
|
43
|
-
presencePenaltyDefault: 0,
|
|
44
|
-
frequencyPenaltyMin: -2,
|
|
45
|
-
frequencyPenaltyMax: 2,
|
|
46
|
-
frequencyPenaltyDefault: 0,
|
|
47
|
-
maxTokensMin: 1,
|
|
48
|
-
maxTokensMax: 128000,
|
|
49
|
-
maxTokensDefault: 128000,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
brand: 'OpenAI',
|
|
53
|
-
model: 'gpt-3.5-turbo',
|
|
54
|
-
name: 'GPT3.5 turbo',
|
|
55
|
-
temperatureMin: 0,
|
|
56
|
-
temperatureMax: 2,
|
|
57
|
-
temperatureDefault: 1,
|
|
58
|
-
topPMin: 0,
|
|
59
|
-
topPMax: 1,
|
|
60
|
-
topPDefault: 1,
|
|
61
|
-
presencePenaltyMin: -2,
|
|
62
|
-
presencePenaltyMax: 2,
|
|
63
|
-
presencePenaltyDefault: 0,
|
|
64
|
-
frequencyPenaltyMin: -2,
|
|
65
|
-
frequencyPenaltyMax: 2,
|
|
66
|
-
frequencyPenaltyDefault: 0,
|
|
67
|
-
maxTokensMin: 1,
|
|
68
|
-
maxTokensMax: 4096,
|
|
69
|
-
maxTokensDefault: 4096,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
brand: 'OpenAI',
|
|
73
|
-
model: 'gpt-3.5-turbo-16k',
|
|
74
|
-
name: 'GPT3.5 turbo 16k',
|
|
75
|
-
temperatureMin: 0,
|
|
76
|
-
temperatureMax: 2,
|
|
77
|
-
temperatureDefault: 1,
|
|
78
|
-
topPMin: 0,
|
|
79
|
-
topPMax: 1,
|
|
80
|
-
topPDefault: 1,
|
|
81
|
-
presencePenaltyMin: -2,
|
|
82
|
-
presencePenaltyMax: 2,
|
|
83
|
-
presencePenaltyDefault: 0,
|
|
84
|
-
frequencyPenaltyMin: -2,
|
|
85
|
-
frequencyPenaltyMax: 2,
|
|
86
|
-
frequencyPenaltyDefault: 0,
|
|
87
|
-
maxTokensMin: 1,
|
|
88
|
-
maxTokensMax: 16385,
|
|
89
|
-
maxTokensDefault: 16385,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
brand: 'OpenAI',
|
|
93
|
-
model: 'gpt-4',
|
|
94
|
-
name: 'GPT4',
|
|
95
|
-
temperatureMin: 0,
|
|
96
|
-
temperatureMax: 2,
|
|
97
|
-
temperatureDefault: 1,
|
|
98
|
-
topPMin: 0,
|
|
99
|
-
topPMax: 1,
|
|
100
|
-
topPDefault: 1,
|
|
101
|
-
presencePenaltyMin: -2,
|
|
102
|
-
presencePenaltyMax: 2,
|
|
103
|
-
presencePenaltyDefault: 0,
|
|
104
|
-
frequencyPenaltyMin: -2,
|
|
105
|
-
frequencyPenaltyMax: 2,
|
|
106
|
-
frequencyPenaltyDefault: 0,
|
|
107
|
-
maxTokensMin: 1,
|
|
108
|
-
maxTokensMax: 8192,
|
|
109
|
-
maxTokensDefault: 8192,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
brand: 'OpenAI',
|
|
113
|
-
model: 'gpt-4-32k',
|
|
114
|
-
name: 'GPT4 32k',
|
|
115
|
-
temperatureMin: 0,
|
|
116
|
-
temperatureMax: 2,
|
|
117
|
-
temperatureDefault: 1,
|
|
118
|
-
topPMin: 0,
|
|
119
|
-
topPMax: 1,
|
|
120
|
-
topPDefault: 1,
|
|
121
|
-
presencePenaltyMin: -2,
|
|
122
|
-
presencePenaltyMax: 2,
|
|
123
|
-
presencePenaltyDefault: 0,
|
|
124
|
-
frequencyPenaltyMin: -2,
|
|
125
|
-
frequencyPenaltyMax: 2,
|
|
126
|
-
frequencyPenaltyDefault: 0,
|
|
127
|
-
maxTokensMin: 1,
|
|
128
|
-
maxTokensMax: 32768,
|
|
129
|
-
maxTokensDefault: 32768,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
brand: 'Google',
|
|
133
|
-
model: 'gemini-pro',
|
|
134
|
-
name: 'Gemini Pro',
|
|
135
|
-
temperatureMin: 0,
|
|
136
|
-
temperatureMax: 2,
|
|
137
|
-
temperatureDefault: 1,
|
|
138
|
-
topPMin: 0.1,
|
|
139
|
-
topPMax: 1,
|
|
140
|
-
topPDefault: 1,
|
|
141
|
-
maxTokensMin: 1,
|
|
142
|
-
maxTokensMax: 2048,
|
|
143
|
-
maxTokensDefault: 2048,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
brand: 'Mistral AI',
|
|
147
|
-
model: 'openRouter/mistralai/mistral-7b-instruct',
|
|
148
|
-
name: 'Mistral 7B Instruct',
|
|
149
|
-
temperatureMin: 0,
|
|
150
|
-
temperatureMax: 2,
|
|
151
|
-
temperatureDefault: 1,
|
|
152
|
-
topPMin: 0,
|
|
153
|
-
topPMax: 1,
|
|
154
|
-
topPDefault: 1,
|
|
155
|
-
maxTokensMin: 1,
|
|
156
|
-
maxTokensMax: 8192,
|
|
157
|
-
maxTokensDefault: 8192,
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
brand: 'Mistral AI',
|
|
161
|
-
model: 'openRouter/mistralai/mixtral-8x7b-instruct',
|
|
162
|
-
name: 'Mixtral 8x7B Instruct (beta)',
|
|
163
|
-
temperatureMin: 0,
|
|
164
|
-
temperatureMax: 2,
|
|
165
|
-
temperatureDefault: 1,
|
|
166
|
-
topPMin: 0,
|
|
167
|
-
topPMax: 1,
|
|
168
|
-
topPDefault: 1,
|
|
169
|
-
maxTokensMin: 1,
|
|
170
|
-
maxTokensMax: 32768,
|
|
171
|
-
maxTokensDefault: 32768,
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
brand: 'Hugging Face',
|
|
175
|
-
model: 'Hugging Face',
|
|
176
|
-
disabled: true,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
brand: 'Azure OpenAI',
|
|
180
|
-
model: 'Azure OpenAI',
|
|
181
|
-
disabled: true,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
brand: 'Replicate',
|
|
185
|
-
model: 'Replicate',
|
|
186
|
-
disabled: true,
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
brand: 'Vertex AI',
|
|
190
|
-
model: 'Vertex AI',
|
|
191
|
-
disabled: true,
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
exports.defaultImageModel = 'dall-e-2';
|
|
196
|
-
async function getSupportedImagesModels() {
|
|
197
|
-
return [
|
|
198
|
-
{
|
|
199
|
-
brand: 'OpenAI',
|
|
200
|
-
model: 'dall-e-2',
|
|
201
|
-
nMin: 1,
|
|
202
|
-
nMax: 10,
|
|
203
|
-
nDefault: 1,
|
|
204
|
-
size: ['256x256', '512x512', '1024x1024'],
|
|
205
|
-
sizeDefault: '256x256',
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
brand: 'OpenAI',
|
|
209
|
-
model: 'dall-e-3',
|
|
210
|
-
nMin: 1,
|
|
211
|
-
nMax: 1,
|
|
212
|
-
nDefault: 1,
|
|
213
|
-
quality: ['standard', 'hd'],
|
|
214
|
-
qualityDefault: 'standard',
|
|
215
|
-
size: ['1024x1024', '1792x1024', '1024x1792'],
|
|
216
|
-
sizeDefault: '1024x1024',
|
|
217
|
-
style: ['vivid', 'natural'],
|
|
218
|
-
styleDefault: 'vivid',
|
|
219
|
-
},
|
|
220
|
-
];
|
|
221
|
-
}
|
|
222
|
-
function getServiceModePermissionMap(serviceMode) {
|
|
223
|
-
const permissionMap = {
|
|
224
|
-
single: {
|
|
225
|
-
ensureViewAllProjectsRoles: ['owner', 'admin', 'promptsEditor'],
|
|
226
|
-
ensurePromptsEditorRoles: ['owner', 'admin', 'promptsEditor'],
|
|
227
|
-
ensurePromptsAdminRoles: ['owner', 'admin', 'promptsEditor'],
|
|
228
|
-
},
|
|
229
|
-
multiple: {
|
|
230
|
-
ensureViewAllProjectsRoles: [],
|
|
231
|
-
// no need to check, everyone can do it, will check author permission in the backend
|
|
232
|
-
ensurePromptsEditorRoles: undefined,
|
|
233
|
-
ensurePromptsAdminRoles: ['owner', 'admin', 'promptsEditor'],
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
// try to fallback to 'single-tenant'
|
|
237
|
-
return permissionMap[serviceMode] || permissionMap.single;
|
|
238
|
-
}
|