@aigne/core 0.4.210 → 0.4.211-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/api-agent.js +70 -0
- package/lib/cjs/data-type-schema.js +46 -0
- package/lib/cjs/data-type.js +2 -0
- package/lib/cjs/definitions/api-parameter.js +10 -0
- package/lib/cjs/memory.js +32 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/fetch-api.js +35 -0
- package/lib/cjs/utils/flatten-openapi.js +14 -0
- package/lib/cjs/utils/format-parameter.js +126 -0
- package/lib/esm/api-agent.js +67 -0
- package/lib/esm/data-type-schema.js +43 -0
- package/lib/esm/data-type.js +1 -0
- package/lib/esm/definitions/api-parameter.js +7 -0
- package/lib/esm/memory.js +27 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/fetch-api.js +31 -0
- package/lib/esm/utils/flatten-openapi.js +11 -0
- package/lib/esm/utils/format-parameter.js +116 -0
- package/lib/types/api-agent.d.ts +53 -0
- package/lib/types/data-type-schema.d.ts +46 -0
- package/lib/types/data-type.d.ts +32 -0
- package/lib/types/definitions/api-parameter.d.ts +55 -0
- package/lib/types/memory.d.ts +184 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/fetch-api.d.ts +3 -0
- package/lib/types/utils/flatten-openapi.d.ts +25 -0
- package/lib/types/utils/format-parameter.d.ts +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OpenAPIAgent = void 0;
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
17
|
+
const nanoid_1 = require("nanoid");
|
|
18
|
+
const tsyringe_1 = require("tsyringe");
|
|
19
|
+
const agent_1 = require("./agent");
|
|
20
|
+
const constants_1 = require("./constants");
|
|
21
|
+
const data_type_schema_1 = require("./definitions/data-type-schema");
|
|
22
|
+
const fetch_api_1 = require("./utils/fetch-api");
|
|
23
|
+
const format_parameter_1 = require("./utils/format-parameter");
|
|
24
|
+
let OpenAPIAgent = class OpenAPIAgent extends agent_1.Agent {
|
|
25
|
+
definition;
|
|
26
|
+
static create = create;
|
|
27
|
+
constructor(definition, context) {
|
|
28
|
+
super(definition, context);
|
|
29
|
+
this.definition = definition;
|
|
30
|
+
}
|
|
31
|
+
async process(input) {
|
|
32
|
+
const { definition: { url, method, auth, inputs }, context, } = this;
|
|
33
|
+
if (!url)
|
|
34
|
+
throw new Error('API url is required');
|
|
35
|
+
const api = {
|
|
36
|
+
url,
|
|
37
|
+
method,
|
|
38
|
+
auth,
|
|
39
|
+
};
|
|
40
|
+
const request = (0, format_parameter_1.formatRequest)(api, inputs, input);
|
|
41
|
+
const contextState = (0, lodash_1.pick)(context?.state, ['userId', 'sessionId']);
|
|
42
|
+
request.query = { ...contextState, ...(request.query || {}) };
|
|
43
|
+
return this.fetch(request);
|
|
44
|
+
}
|
|
45
|
+
fetch(request) {
|
|
46
|
+
return (0, fetch_api_1.fetchApi)(request);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.OpenAPIAgent = OpenAPIAgent;
|
|
50
|
+
exports.OpenAPIAgent = OpenAPIAgent = __decorate([
|
|
51
|
+
(0, tsyringe_1.injectable)(),
|
|
52
|
+
__param(0, (0, tsyringe_1.inject)(constants_1.TYPES.definition)),
|
|
53
|
+
__param(1, (0, tsyringe_1.inject)(constants_1.TYPES.context)),
|
|
54
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
55
|
+
], OpenAPIAgent);
|
|
56
|
+
function create({ context, ...options }) {
|
|
57
|
+
const agentId = options.id || options.name || (0, nanoid_1.nanoid)();
|
|
58
|
+
const inputs = (0, data_type_schema_1.schemaToDataType)(options.inputs);
|
|
59
|
+
const outputs = (0, data_type_schema_1.schemaToDataType)(options.outputs);
|
|
60
|
+
return new OpenAPIAgent({
|
|
61
|
+
id: agentId,
|
|
62
|
+
name: options.name,
|
|
63
|
+
type: 'api_agent',
|
|
64
|
+
inputs,
|
|
65
|
+
outputs,
|
|
66
|
+
url: options.url,
|
|
67
|
+
method: options.method,
|
|
68
|
+
auth: options.auth,
|
|
69
|
+
}, context);
|
|
70
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schemaToDataType = schemaToDataType;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function schemaToDataType(dataType) {
|
|
7
|
+
return utils_1.OrderedRecord.fromArray(Object.entries(dataType).map(([name, schema]) => {
|
|
8
|
+
const base = {
|
|
9
|
+
...schema,
|
|
10
|
+
id: (0, nanoid_1.nanoid)(),
|
|
11
|
+
name,
|
|
12
|
+
};
|
|
13
|
+
switch (schema.type) {
|
|
14
|
+
case 'string':
|
|
15
|
+
return {
|
|
16
|
+
...base,
|
|
17
|
+
type: 'string',
|
|
18
|
+
};
|
|
19
|
+
case 'number':
|
|
20
|
+
return {
|
|
21
|
+
...base,
|
|
22
|
+
type: 'number',
|
|
23
|
+
};
|
|
24
|
+
case 'boolean':
|
|
25
|
+
return {
|
|
26
|
+
...base,
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
};
|
|
29
|
+
case 'object':
|
|
30
|
+
return {
|
|
31
|
+
...base,
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: schemaToDataType(schema.properties),
|
|
34
|
+
};
|
|
35
|
+
case 'array':
|
|
36
|
+
return {
|
|
37
|
+
...base,
|
|
38
|
+
type: 'array',
|
|
39
|
+
items: utils_1.OrderedRecord.find(schemaToDataType({ items: schema.items }), (i) => i.name === 'items'),
|
|
40
|
+
};
|
|
41
|
+
default: {
|
|
42
|
+
throw new Error(`Unknown data type: ${schema.type}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTPMethod = void 0;
|
|
4
|
+
var HTTPMethod;
|
|
5
|
+
(function (HTTPMethod) {
|
|
6
|
+
HTTPMethod["GET"] = "GET";
|
|
7
|
+
HTTPMethod["POST"] = "POST";
|
|
8
|
+
HTTPMethod["PUT"] = "PUT";
|
|
9
|
+
HTTPMethod["DELETE"] = "DELETE";
|
|
10
|
+
})(HTTPMethod || (exports.HTTPMethod = HTTPMethod = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryRunner = exports.Memory = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const runnable_1 = require("./runnable");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
class Memory extends runnable_1.Runnable {
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
id: 'memory',
|
|
11
|
+
type: 'memory',
|
|
12
|
+
name: 'Memory',
|
|
13
|
+
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
14
|
+
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Memory = Memory;
|
|
19
|
+
class MemoryRunner extends runnable_1.Runnable {
|
|
20
|
+
constructor(name) {
|
|
21
|
+
const id = `${(0, lodash_1.camelCase)(name)}_runner`;
|
|
22
|
+
super({
|
|
23
|
+
id,
|
|
24
|
+
type: id,
|
|
25
|
+
name: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
26
|
+
description: `${(0, lodash_1.startCase)(name)} Runner`,
|
|
27
|
+
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
28
|
+
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.MemoryRunner = MemoryRunner;
|