@aigne/core 0.0.2 → 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.
Files changed (168) hide show
  1. package/lib/cjs/index.js +1 -1
  2. package/lib/cjs/types/index.js +2 -4
  3. package/lib/esm/index.js +1 -1
  4. package/lib/esm/types/index.js +2 -4
  5. package/lib/types/index.d.ts +1 -1
  6. package/lib/types/types/agent.d.ts +5 -0
  7. package/lib/types/types/index.d.ts +2 -4
  8. package/lib/types/types/runnable.d.ts +20 -0
  9. package/package.json +6 -7
  10. package/lib/cjs/assistant/generate-output.js +0 -101
  11. package/lib/cjs/assistant/select-agent.js +0 -76
  12. package/lib/cjs/assistant/type.js +0 -11
  13. package/lib/cjs/common/aid.js +0 -42
  14. package/lib/cjs/common/index.js +0 -238
  15. package/lib/cjs/common/resource-manager.js +0 -199
  16. package/lib/cjs/constants.js +0 -9
  17. package/lib/cjs/executor/agent.js +0 -10
  18. package/lib/cjs/executor/aigc.js +0 -28
  19. package/lib/cjs/executor/api.js +0 -64
  20. package/lib/cjs/executor/base.js +0 -676
  21. package/lib/cjs/executor/blocklet.js +0 -25
  22. package/lib/cjs/executor/call-agent.js +0 -105
  23. package/lib/cjs/executor/decision.js +0 -478
  24. package/lib/cjs/executor/image-blender.js +0 -32
  25. package/lib/cjs/executor/index.js +0 -81
  26. package/lib/cjs/executor/llm.js +0 -379
  27. package/lib/cjs/executor/logic.js +0 -167
  28. package/lib/cjs/libs/blocklet/vc.js +0 -92
  29. package/lib/cjs/libs/openapi/request/index.js +0 -24
  30. package/lib/cjs/libs/openapi/request/util.js +0 -146
  31. package/lib/cjs/libs/openapi/types/index.js +0 -17
  32. package/lib/cjs/libs/openapi/util/call.js +0 -15
  33. package/lib/cjs/libs/openapi/util/check-schema.js +0 -67
  34. package/lib/cjs/libs/openapi/util/convert-schema.js +0 -44
  35. package/lib/cjs/libs/openapi/util/flatten-open-api.js +0 -21
  36. package/lib/cjs/libs/openapi/util/get-open-api-i18n-text.js +0 -7
  37. package/lib/cjs/runtime/resource-blocklet.js +0 -5
  38. package/lib/cjs/runtime/runtime.js +0 -143
  39. package/lib/cjs/types/assistant/index.js +0 -31
  40. package/lib/cjs/types/assistant/mustache/ReadableMustache.js +0 -69
  41. package/lib/cjs/types/assistant/mustache/directive.js +0 -35
  42. package/lib/cjs/types/assistant/mustache/mustache.js +0 -688
  43. package/lib/cjs/types/resource/index.js +0 -47
  44. package/lib/cjs/types/resource/project.js +0 -35
  45. package/lib/cjs/types/runtime/error.js +0 -18
  46. package/lib/cjs/types/runtime/index.js +0 -37
  47. package/lib/cjs/types/runtime/runtime-resource-blocklet-state.js +0 -4
  48. package/lib/cjs/types/runtime/schema.js +0 -259
  49. package/lib/cjs/utils/cron-job.js +0 -48
  50. package/lib/cjs/utils/extract-metadata-transform.js +0 -58
  51. package/lib/cjs/utils/extract-metadata-transform.test.js +0 -61
  52. package/lib/cjs/utils/fs.js +0 -49
  53. package/lib/cjs/utils/get-blocklet-agent.js +0 -351
  54. package/lib/cjs/utils/geti.js +0 -37
  55. package/lib/cjs/utils/is-non-nullable.js +0 -20
  56. package/lib/cjs/utils/render-message.js +0 -23
  57. package/lib/cjs/utils/resolve-secret-inputs.js +0 -49
  58. package/lib/cjs/utils/retry.js +0 -19
  59. package/lib/cjs/utils/task-id.js +0 -7
  60. package/lib/cjs/utils/tool-calls-transform.js +0 -18
  61. package/lib/esm/assistant/generate-output.js +0 -91
  62. package/lib/esm/assistant/select-agent.js +0 -71
  63. package/lib/esm/assistant/type.js +0 -7
  64. package/lib/esm/common/aid.js +0 -38
  65. package/lib/esm/common/index.js +0 -232
  66. package/lib/esm/common/resource-manager.js +0 -192
  67. package/lib/esm/constants.js +0 -6
  68. package/lib/esm/executor/agent.js +0 -6
  69. package/lib/esm/executor/aigc.js +0 -24
  70. package/lib/esm/executor/api.js +0 -34
  71. package/lib/esm/executor/base.js +0 -668
  72. package/lib/esm/executor/blocklet.js +0 -21
  73. package/lib/esm/executor/call-agent.js +0 -98
  74. package/lib/esm/executor/decision.js +0 -471
  75. package/lib/esm/executor/image-blender.js +0 -25
  76. package/lib/esm/executor/index.js +0 -74
  77. package/lib/esm/executor/llm.js +0 -372
  78. package/lib/esm/executor/logic.js +0 -160
  79. package/lib/esm/libs/blocklet/vc.js +0 -85
  80. package/lib/esm/libs/openapi/request/index.js +0 -20
  81. package/lib/esm/libs/openapi/request/util.js +0 -136
  82. package/lib/esm/libs/openapi/types/index.js +0 -1
  83. package/lib/esm/libs/openapi/util/call.js +0 -8
  84. package/lib/esm/libs/openapi/util/check-schema.js +0 -62
  85. package/lib/esm/libs/openapi/util/convert-schema.js +0 -42
  86. package/lib/esm/libs/openapi/util/flatten-open-api.js +0 -19
  87. package/lib/esm/libs/openapi/util/get-open-api-i18n-text.js +0 -5
  88. package/lib/esm/runtime/resource-blocklet.js +0 -2
  89. package/lib/esm/runtime/runtime.js +0 -136
  90. package/lib/esm/types/assistant/index.js +0 -9
  91. package/lib/esm/types/assistant/mustache/ReadableMustache.js +0 -63
  92. package/lib/esm/types/assistant/mustache/directive.js +0 -29
  93. package/lib/esm/types/assistant/mustache/mustache.js +0 -686
  94. package/lib/esm/types/resource/index.js +0 -26
  95. package/lib/esm/types/resource/project.js +0 -29
  96. package/lib/esm/types/runtime/error.js +0 -14
  97. package/lib/esm/types/runtime/index.js +0 -20
  98. package/lib/esm/types/runtime/runtime-resource-blocklet-state.js +0 -1
  99. package/lib/esm/types/runtime/schema.js +0 -249
  100. package/lib/esm/utils/cron-job.js +0 -44
  101. package/lib/esm/utils/extract-metadata-transform.js +0 -54
  102. package/lib/esm/utils/extract-metadata-transform.test.js +0 -59
  103. package/lib/esm/utils/fs.js +0 -41
  104. package/lib/esm/utils/get-blocklet-agent.js +0 -344
  105. package/lib/esm/utils/geti.js +0 -30
  106. package/lib/esm/utils/is-non-nullable.js +0 -13
  107. package/lib/esm/utils/render-message.js +0 -20
  108. package/lib/esm/utils/resolve-secret-inputs.js +0 -46
  109. package/lib/esm/utils/retry.js +0 -16
  110. package/lib/esm/utils/task-id.js +0 -3
  111. package/lib/esm/utils/tool-calls-transform.js +0 -15
  112. package/lib/types/assistant/generate-output.d.ts +0 -29
  113. package/lib/types/assistant/select-agent.d.ts +0 -14
  114. package/lib/types/assistant/type.d.ts +0 -61
  115. package/lib/types/common/aid.d.ts +0 -18
  116. package/lib/types/common/index.d.ts +0 -7
  117. package/lib/types/common/resource-manager.d.ts +0 -88
  118. package/lib/types/constants.d.ts +0 -6
  119. package/lib/types/executor/agent.d.ts +0 -5
  120. package/lib/types/executor/aigc.d.ts +0 -9
  121. package/lib/types/executor/api.d.ts +0 -9
  122. package/lib/types/executor/base.d.ts +0 -209
  123. package/lib/types/executor/blocklet.d.ts +0 -9
  124. package/lib/types/executor/call-agent.d.ts +0 -12
  125. package/lib/types/executor/decision.d.ts +0 -20
  126. package/lib/types/executor/image-blender.d.ts +0 -9
  127. package/lib/types/executor/index.d.ts +0 -8
  128. package/lib/types/executor/llm.d.ts +0 -38
  129. package/lib/types/executor/logic.d.ts +0 -9
  130. package/lib/types/libs/blocklet/vc.d.ts +0 -17
  131. package/lib/types/libs/openapi/request/index.d.ts +0 -17
  132. package/lib/types/libs/openapi/request/util.d.ts +0 -40
  133. package/lib/types/libs/openapi/types/index.d.ts +0 -20
  134. package/lib/types/libs/openapi/util/call.d.ts +0 -2
  135. package/lib/types/libs/openapi/util/check-schema.d.ts +0 -3
  136. package/lib/types/libs/openapi/util/convert-schema.d.ts +0 -8
  137. package/lib/types/libs/openapi/util/flatten-open-api.d.ts +0 -3
  138. package/lib/types/libs/openapi/util/get-open-api-i18n-text.d.ts +0 -2
  139. package/lib/types/runtime/resource-blocklet.d.ts +0 -2
  140. package/lib/types/runtime/runtime.d.ts +0 -20
  141. package/lib/types/types/assistant/index.d.ts +0 -405
  142. package/lib/types/types/assistant/mustache/ReadableMustache.d.ts +0 -2
  143. package/lib/types/types/assistant/mustache/directive.d.ts +0 -6
  144. package/lib/types/types/assistant/mustache/mustache.d.ts +0 -2
  145. package/lib/types/types/common/index.d.ts +0 -45
  146. package/lib/types/types/resource/index.d.ts +0 -17
  147. package/lib/types/types/resource/project.d.ts +0 -41
  148. package/lib/types/types/runtime/agent.d.ts +0 -33
  149. package/lib/types/types/runtime/error.d.ts +0 -10
  150. package/lib/types/types/runtime/index.d.ts +0 -116
  151. package/lib/types/types/runtime/runtime-resource-blocklet-state.d.ts +0 -5
  152. package/lib/types/types/runtime/schema.d.ts +0 -110
  153. package/lib/types/utils/cron-job.d.ts +0 -22
  154. package/lib/types/utils/extract-metadata-transform.d.ts +0 -16
  155. package/lib/types/utils/extract-metadata-transform.test.d.ts +0 -1
  156. package/lib/types/utils/fs.d.ts +0 -9
  157. package/lib/types/utils/get-blocklet-agent.d.ts +0 -219
  158. package/lib/types/utils/geti.d.ts +0 -1
  159. package/lib/types/utils/is-non-nullable.d.ts +0 -2
  160. package/lib/types/utils/render-message.d.ts +0 -6
  161. package/lib/types/utils/resolve-secret-inputs.d.ts +0 -11
  162. package/lib/types/utils/retry.d.ts +0 -1
  163. package/lib/types/utils/task-id.d.ts +0 -1
  164. package/lib/types/utils/tool-calls-transform.d.ts +0 -2
  165. /package/lib/cjs/types/{runtime/agent.js → agent.js} +0 -0
  166. /package/lib/cjs/types/{common/index.js → runnable.js} +0 -0
  167. /package/lib/esm/types/{runtime/agent.js → agent.js} +0 -0
  168. /package/lib/esm/types/{common/index.js → runnable.js} +0 -0
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ResourceTypes = void 0;
21
- exports.validateResourceProject = validateResourceProject;
22
- const joi_1 = __importDefault(require("joi"));
23
- const project_1 = require("./project");
24
- __exportStar(require("./project"), exports);
25
- exports.ResourceTypes = [
26
- 'application',
27
- 'tool',
28
- 'llm-adapter',
29
- 'aigc-adapter',
30
- 'knowledge',
31
- 'template',
32
- 'example',
33
- ];
34
- const resourceProjectSchema = joi_1.default.object({
35
- project: project_1.projectSettingsSchema.required(),
36
- agents: joi_1.default.array().items(joi_1.default.object()).required(),
37
- config: joi_1.default.object().default({}),
38
- cron: joi_1.default.object().default({}),
39
- memory: joi_1.default.object().default({}),
40
- }).options({ stripUnknown: true });
41
- async function validateResourceProject(value) {
42
- return resourceProjectSchema.validateAsync({
43
- ...value,
44
- agents: value.agents || value.assistants,
45
- cron: value.cron || value.cronConfig,
46
- });
47
- }
@@ -1,35 +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.projectSettingsSchema = void 0;
7
- const joi_1 = __importDefault(require("joi"));
8
- exports.projectSettingsSchema = joi_1.default.object({
9
- id: joi_1.default.string().required(),
10
- name: joi_1.default.string().empty(['', null]),
11
- description: joi_1.default.string().empty(['', null]),
12
- model: joi_1.default.string().empty(['', null]),
13
- temperature: joi_1.default.number().empty(['', null]),
14
- topP: joi_1.default.number().empty(['', null]),
15
- presencePenalty: joi_1.default.number().empty(['', null]),
16
- frequencyPenalty: joi_1.default.number().empty(['', null]),
17
- maxTokens: joi_1.default.number().empty(['', null]),
18
- createdAt: joi_1.default.alternatives(joi_1.default.string().isoDate(), joi_1.default.date().cast('string')).empty(['', null]),
19
- updatedAt: joi_1.default.alternatives(joi_1.default.string().isoDate(), joi_1.default.date().cast('string')).empty(['', null]),
20
- createdBy: joi_1.default.string().empty(['', null]),
21
- updatedBy: joi_1.default.string().empty(['', null]),
22
- appearance: joi_1.default.object({
23
- primaryColor: joi_1.default.string().empty(['', null]),
24
- typography: joi_1.default.object({
25
- fontFamily: joi_1.default.string().empty(['', null]),
26
- heading: joi_1.default.object({
27
- fontFamily: joi_1.default.string().empty(['', null]),
28
- }).empty(['', null]),
29
- }).empty(['', null]),
30
- }).empty(['', null]),
31
- readme: joi_1.default.string().empty(['', null]).optional(),
32
- executor: joi_1.default.object().empty(['', null]).optional(),
33
- })
34
- .rename('_id', 'id', { override: true, ignoreUndefined: true })
35
- .options({ stripUnknown: true });
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RuntimeError = exports.RuntimeErrorType = void 0;
4
- var RuntimeErrorType;
5
- (function (RuntimeErrorType) {
6
- RuntimeErrorType["MissingSecretError"] = "MissingSecretError";
7
- RuntimeErrorType["RequestExceededError"] = "RequestExceededError";
8
- RuntimeErrorType["ProjectOwnerRequestExceededError"] = "ProjectOwnerRequestExceededError";
9
- RuntimeErrorType["ProjectLimitExceededError"] = "ProjectLimitExceededError";
10
- })(RuntimeErrorType || (exports.RuntimeErrorType = RuntimeErrorType = {}));
11
- class RuntimeError extends Error {
12
- type;
13
- constructor(type, message) {
14
- super(message);
15
- this.type = type;
16
- }
17
- }
18
- exports.RuntimeError = RuntimeError;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AssistantResponseType = exports.ExecutionPhase = void 0;
18
- __exportStar(require("./schema"), exports);
19
- __exportStar(require("./error"), exports);
20
- var ExecutionPhase;
21
- (function (ExecutionPhase) {
22
- ExecutionPhase["EXECUTE_BLOCK_START"] = "EXECUTE_BLOCK_START";
23
- ExecutionPhase["EXECUTE_SELECT_STOP"] = "EXECUTE_SELECT_STOP";
24
- ExecutionPhase["EXECUTE_ASSISTANT_START"] = "EXECUTE_ASSISTANT_START";
25
- ExecutionPhase["EXECUTE_ASSISTANT_RUNNING"] = "EXECUTE_BLOCK_RUNNING";
26
- ExecutionPhase["EXECUTE_ASSISTANT_END"] = "EXECUTE_ASSISTANT_END";
27
- })(ExecutionPhase || (exports.ExecutionPhase = ExecutionPhase = {}));
28
- var AssistantResponseType;
29
- (function (AssistantResponseType) {
30
- AssistantResponseType["ERROR"] = "ERROR";
31
- AssistantResponseType["LOG"] = "LOG";
32
- AssistantResponseType["INPUT"] = "INPUT";
33
- AssistantResponseType["CHUNK"] = "CHUNK";
34
- AssistantResponseType["USAGE"] = "USAGE";
35
- AssistantResponseType["EXECUTE"] = "EXECUTE";
36
- AssistantResponseType["INPUT_PARAMETER"] = "INPUT_PARAMETER";
37
- })(AssistantResponseType || (exports.AssistantResponseType = AssistantResponseType = {}));
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RUNTIME_RESOURCE_BLOCKLET_STATE_GLOBAL_VARIABLE = void 0;
4
- exports.RUNTIME_RESOURCE_BLOCKLET_STATE_GLOBAL_VARIABLE = '__AI_RUNTIME_RESOURCE_BLOCKLET_STATE__';
@@ -1,259 +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.RuntimeOutputVariable = exports.runtimeVariablesSchema = exports.variableBlockListForAgent = void 0;
7
- exports.outputVariablesToJsonSchema = outputVariablesToJsonSchema;
8
- exports.outputVariablesToJoiSchema = outputVariablesToJoiSchema;
9
- exports.isRuntimeOutputVariable = isRuntimeOutputVariable;
10
- exports.jsonSchemaToOpenAIJsonSchema = jsonSchemaToOpenAIJsonSchema;
11
- const joi_1 = __importDefault(require("joi"));
12
- const omitBy_1 = __importDefault(require("lodash/omitBy"));
13
- const toLower_1 = __importDefault(require("lodash/toLower"));
14
- exports.variableBlockListForAgent = {
15
- prompt: {
16
- // block: new Set(['$images']),
17
- },
18
- image: {
19
- // allow: new Set(['$images']),
20
- },
21
- };
22
- exports.runtimeVariablesSchema = {
23
- $text: {
24
- type: 'string',
25
- description: 'Text Stream',
26
- faker: 'lorem.paragraph',
27
- },
28
- $images: {
29
- type: 'array',
30
- description: 'Generated Images',
31
- element: {
32
- id: '',
33
- type: 'object',
34
- properties: [
35
- {
36
- id: '',
37
- type: 'string',
38
- name: 'url',
39
- description: 'Image Url',
40
- required: true,
41
- faker: 'image.url',
42
- },
43
- ],
44
- },
45
- },
46
- '$suggested.questions': {
47
- type: 'array',
48
- description: 'Generate 3 questions for users to ask you based on answers and context',
49
- element: {
50
- id: '',
51
- type: 'object',
52
- properties: [
53
- {
54
- id: '',
55
- type: 'string',
56
- name: 'question',
57
- required: true,
58
- faker: 'lorem.sentence',
59
- },
60
- ],
61
- },
62
- required: true,
63
- },
64
- '$reference.links': {
65
- type: 'array',
66
- description: 'List all referenced links in the generated text',
67
- element: {
68
- id: '',
69
- type: 'object',
70
- properties: [
71
- {
72
- id: '',
73
- type: 'string',
74
- name: 'title',
75
- required: true,
76
- faker: 'lorem.sentence',
77
- },
78
- {
79
- id: '',
80
- type: 'string',
81
- name: 'url',
82
- required: true,
83
- faker: 'internet.url',
84
- },
85
- ],
86
- },
87
- required: true,
88
- },
89
- };
90
- function outputVariablesToJsonSchema(assistant, { variables, includeRuntimeOutputVariables, includeFaker, }) {
91
- const variableToSchema = (variable) => {
92
- if (variable.from?.type === 'input')
93
- return undefined;
94
- if (!includeRuntimeOutputVariables && ignoreJsonSchemaOutputs.has(variable.name))
95
- return undefined;
96
- if (variable.name && isRuntimeOutputVariable(variable.name)) {
97
- const runtimeVariable = exports.runtimeVariablesSchema[variable.name];
98
- if (!runtimeVariable)
99
- return undefined;
100
- return variableToSchema({
101
- ...runtimeVariable,
102
- description: [runtimeVariable.description, variable.description].filter((i) => !!i).join('\n'),
103
- });
104
- }
105
- if (variable.variable) {
106
- const { key, scope } = variable.variable;
107
- const v = variables.find((i) => (0, toLower_1.default)(i.key) === (0, toLower_1.default)(key) && i.scope === scope);
108
- if (!v?.type)
109
- throw new Error(`Variable ${key} not found from ${scope}`);
110
- return variableToSchema(v.type);
111
- }
112
- return (0, omitBy_1.default)({
113
- type: variable.type || 'string',
114
- description: variable.description,
115
- properties: variable.type === 'object' && variable.properties
116
- ? Object.fromEntries(variable.properties
117
- .map((property) => [property.name, variableToSchema(property)])
118
- .filter((i) => i[0] && i[1]))
119
- : undefined,
120
- items: variable.type === 'array' && variable.element ? variableToSchema(variable.element) : undefined,
121
- additionalProperties: variable.type === 'object' ? false : undefined,
122
- required: variable.type === 'object' && variable.properties?.length
123
- ? variable.properties
124
- .filter((i) => i.name &&
125
- (i.required ||
126
- (runtimeOutputVariableSet.has(i.name) &&
127
- exports.runtimeVariablesSchema[i.name] &&
128
- !ignoreJsonSchemaOutputs.has(i.name))))
129
- .map((i) => i.name)
130
- : undefined,
131
- faker: includeFaker ? variable.faker : undefined,
132
- }, (v) => v === undefined);
133
- };
134
- const outputVariables = (assistant.outputVariables ?? []).filter((i) => !i.hidden && i.from?.type !== 'callAgent' && !i.valueTemplate?.trim());
135
- return variableToSchema({ type: 'object', properties: outputVariables });
136
- }
137
- function outputVariablesToJoiSchema(assistant, { partial, variables }) {
138
- const variableToSchema = (variable) => {
139
- let schema;
140
- if (variable.from?.type === 'input') {
141
- const fromId = variable.from.id;
142
- const input = assistant.parameters?.find((i) => i.id === fromId && !i.hidden);
143
- if (input) {
144
- return joi_1.default.any();
145
- }
146
- return undefined;
147
- }
148
- if (variable.from?.type === 'output') {
149
- return joi_1.default.any();
150
- }
151
- if (variable.name && isRuntimeOutputVariable(variable.name)) {
152
- if (variable.name === RuntimeOutputVariable.llmResponseStream) {
153
- schema = joi_1.default.any();
154
- }
155
- else {
156
- const runtimeVariable = exports.runtimeVariablesSchema[variable.name];
157
- if (!runtimeVariable)
158
- return undefined;
159
- schema = variableToSchema({ ...runtimeVariable });
160
- if (schema) {
161
- schema = joi_1.default.alternatives().try(schema, joi_1.default.any().empty(joi_1.default.any()));
162
- }
163
- }
164
- return schema;
165
- }
166
- if (variable.variable) {
167
- const { key, scope } = variable.variable;
168
- const v = variables.find((i) => (0, toLower_1.default)(i.key) === (0, toLower_1.default)(key) && i.scope === scope);
169
- if (!v?.type)
170
- return undefined;
171
- schema = variableToSchema(v.type);
172
- }
173
- else if (!variable.type || variable.type === 'string') {
174
- schema = joi_1.default.string().empty(['', null]);
175
- }
176
- else if (variable.type === 'number') {
177
- schema = joi_1.default.number().empty([null, '']);
178
- }
179
- else if (variable.type === 'boolean') {
180
- schema = joi_1.default.boolean().empty([null, '']);
181
- }
182
- else if (variable.type === 'object') {
183
- if (variable.properties?.length) {
184
- schema = joi_1.default.object(Object.fromEntries((variable.properties ?? [])
185
- .map((property) => [property.name, variableToSchema(property)])
186
- .filter((i) => i[0] && i[1])))
187
- .empty([null, ''])
188
- .options({ stripUnknown: true });
189
- }
190
- else {
191
- schema = joi_1.default.any().empty(['', null]);
192
- }
193
- }
194
- else if (variable.type === 'array') {
195
- schema = joi_1.default.array()
196
- .empty([null, ''])
197
- .items((variable.element && variableToSchema(variable.element)) || joi_1.default.string().empty([null, '']));
198
- }
199
- if (!schema)
200
- return undefined;
201
- if ('defaultValue' in variable) {
202
- schema = schema.default(variable.defaultValue);
203
- }
204
- if (variable.required) {
205
- schema = schema.required();
206
- }
207
- return schema;
208
- };
209
- const outputVariables = (assistant.outputVariables ?? []).filter((i) => !i.hidden && i.from?.type !== 'callAgent' && !i.valueTemplate);
210
- return variableToSchema({
211
- type: 'object',
212
- properties: partial ? outputVariables.map((i) => ({ ...i, required: false })) : outputVariables,
213
- });
214
- }
215
- var RuntimeOutputVariable;
216
- (function (RuntimeOutputVariable) {
217
- RuntimeOutputVariable["llmResponseStream"] = "$llmResponseStream";
218
- RuntimeOutputVariable["text"] = "$text";
219
- RuntimeOutputVariable["images"] = "$images";
220
- RuntimeOutputVariable["suggestedQuestions"] = "$suggested.questions";
221
- RuntimeOutputVariable["referenceLinks"] = "$reference.links";
222
- RuntimeOutputVariable["appearancePage"] = "$appearance.page";
223
- RuntimeOutputVariable["appearanceInput"] = "$appearance.input";
224
- RuntimeOutputVariable["appearanceOutput"] = "$appearance.output";
225
- RuntimeOutputVariable["children"] = "$children";
226
- RuntimeOutputVariable["share"] = "$share";
227
- RuntimeOutputVariable["openingQuestions"] = "$openingQuestions";
228
- RuntimeOutputVariable["openingMessage"] = "$openingMessage";
229
- RuntimeOutputVariable["profile"] = "$profile";
230
- })(RuntimeOutputVariable || (exports.RuntimeOutputVariable = RuntimeOutputVariable = {}));
231
- const runtimeOutputVariableSet = new Set(Object.values(RuntimeOutputVariable));
232
- const ignoreJsonSchemaOutputs = new Set([
233
- RuntimeOutputVariable.text,
234
- RuntimeOutputVariable.images,
235
- ]);
236
- function isRuntimeOutputVariable(variable) {
237
- return Object.values(RuntimeOutputVariable).includes(variable);
238
- }
239
- function jsonSchemaToOpenAIJsonSchema(schema) {
240
- if (schema?.type === 'object') {
241
- const { required, properties } = schema;
242
- return {
243
- ...schema,
244
- properties: Object.fromEntries(Object.entries(properties).map(([key, value]) => {
245
- const valueSchema = jsonSchemaToOpenAIJsonSchema(value);
246
- // NOTE: All fields must be required https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required
247
- return [key, required?.includes(key) ? valueSchema : { anyOf: [valueSchema, { type: ['null'] }] }];
248
- })),
249
- required: Object.keys(properties),
250
- };
251
- }
252
- if (schema?.type === 'array') {
253
- return {
254
- ...schema,
255
- items: jsonSchemaToOpenAIJsonSchema(schema.items),
256
- };
257
- }
258
- return schema;
259
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CronJobManager = exports.CronJobDefaultGroup = void 0;
4
- const cron_1 = require("cron");
5
- exports.CronJobDefaultGroup = 'default';
6
- class CronJobManager {
7
- groups = {};
8
- resetJobs(jobs, { groupId = exports.CronJobDefaultGroup } = {}) {
9
- this.destroyGroup({ groupId });
10
- for (const job of jobs) {
11
- this.resetJob(job, { groupId });
12
- }
13
- }
14
- resetJob(job, { groupId = exports.CronJobDefaultGroup } = {}) {
15
- if (!job.cronTime)
16
- throw new Error('cronTime is required');
17
- this.groups[groupId] ??= { jobs: {} };
18
- const group = this.groups[groupId];
19
- this.stopJob(job.id, { groupId });
20
- const cronJob = cron_1.CronJob.from({ cronTime: job.cronTime, onTick: job.onTick, utcOffset: 0, start: true });
21
- group.jobs[job.id] = { cronJob, job };
22
- }
23
- stopJob(jobId, { groupId = exports.CronJobDefaultGroup } = {}) {
24
- const group = this.groups[groupId];
25
- if (!group)
26
- return;
27
- const item = group.jobs[jobId];
28
- if (!item)
29
- return;
30
- item.cronJob.stop();
31
- delete group.jobs[jobId];
32
- }
33
- destroyGroup({ groupId }) {
34
- const group = this.groups[groupId];
35
- if (!group)
36
- return;
37
- for (const item of Object.values(group.jobs)) {
38
- this.stopJob(item.job.id, { groupId });
39
- }
40
- delete this.groups[groupId];
41
- }
42
- destroy() {
43
- for (const groupId of Object.keys(this.groups)) {
44
- this.destroyGroup({ groupId });
45
- }
46
- }
47
- }
48
- exports.CronJobManager = CronJobManager;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtractMetadataTransform = void 0;
4
- const web_1 = require("stream/web");
5
- class ExtractMetadataTransform extends web_1.TransformStream {
6
- buffer = '';
7
- cursor = 0;
8
- state = 'none';
9
- constructor({ start, end }) {
10
- super({
11
- transform: async (chunk, controller) => {
12
- if (!start || !end) {
13
- controller.enqueue({ type: 'text', text: chunk });
14
- return;
15
- }
16
- this.buffer += chunk;
17
- for (;;) {
18
- if (this.state === 'none') {
19
- const found = findMatchIndex(this.buffer, this.cursor, start);
20
- if (found.start > this.cursor) {
21
- const text = this.buffer.slice(this.cursor, found.start);
22
- this.cursor = found.start;
23
- controller.enqueue({ type: 'text', text });
24
- }
25
- if (found.end) {
26
- this.state = 'start';
27
- this.cursor = found.end;
28
- }
29
- }
30
- if (this.state === 'start') {
31
- const found = findMatchIndex(this.buffer, this.cursor, end);
32
- if (found.end) {
33
- const match = this.buffer.slice(this.cursor, found.start);
34
- controller.enqueue({ type: 'match', text: match });
35
- this.state = 'none';
36
- this.cursor = found.end;
37
- continue;
38
- }
39
- }
40
- break;
41
- }
42
- },
43
- });
44
- }
45
- }
46
- exports.ExtractMetadataTransform = ExtractMetadataTransform;
47
- function findMatchIndex(str, position, match) {
48
- const i = str.indexOf(match, position);
49
- if (i >= 0)
50
- return { start: i, end: i + match.length };
51
- for (let i = match.length - 1; i > 0; i--) {
52
- const m = match.slice(0, i);
53
- if (str.endsWith(m)) {
54
- return { start: str.length - m.length };
55
- }
56
- }
57
- return { start: str.length };
58
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const web_1 = require("stream/web");
4
- const globals_1 = require("@jest/globals");
5
- const extract_metadata_transform_1 = require("./extract-metadata-transform");
6
- (0, globals_1.describe)('ExtractMetadataTransform', () => {
7
- async function run(str, start, end, step = 1) {
8
- const s = new web_1.ReadableStream({
9
- start(controller) {
10
- let t = '';
11
- for (const i of str) {
12
- t += i;
13
- if (t.length === step) {
14
- controller.enqueue(t);
15
- t = '';
16
- }
17
- }
18
- controller.enqueue(t);
19
- controller.close();
20
- },
21
- }).pipeThrough(new extract_metadata_transform_1.ExtractMetadataTransform({ start, end }));
22
- let text = '';
23
- const matched = [];
24
- for await (const i of s) {
25
- if (i.type === 'text') {
26
- text += i.text;
27
- }
28
- else if (i.type === 'match') {
29
- matched.push(i.text);
30
- }
31
- }
32
- return { text, matched };
33
- }
34
- const cases = [
35
- {
36
- input: 'hello<metadata>{"name":"foo","age":120}</metadata>world how<metadata>{"name":"bar","age":130}</metadata> to',
37
- start: '<metadata>',
38
- end: '</metadata>',
39
- expected: { text: 'helloworld how to', matched: ['{"name":"foo","age":120}', '{"name":"bar","age":130}'] },
40
- },
41
- {
42
- input: '```metadata{"name":"foo","age":120}```',
43
- start: '```metadata',
44
- end: '```',
45
- expected: { text: '', matched: ['{"name":"foo","age":120}'] },
46
- },
47
- {
48
- input: '```metadata{"name":"foo","age":120}``````metadata{"name":"bar","age":130}```',
49
- start: '```metadata',
50
- end: '```',
51
- expected: { text: '', matched: ['{"name":"foo","age":120}', '{"name":"bar","age":130}'] },
52
- },
53
- ];
54
- (0, globals_1.test)('extract metadata transform', async () => {
55
- for (const c of cases) {
56
- for (let i = 1; i < c.input.length; i++) {
57
- (0, globals_1.expect)([await run(c.input, c.start, c.end, i), i]).toEqual([c.expected, i]);
58
- }
59
- }
60
- });
61
- });
@@ -1,49 +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.copyFile = copyFile;
7
- exports.copyDirectory = copyDirectory;
8
- exports.copyRecursive = copyRecursive;
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- async function copyFile(src, dest, { skip } = {}) {
12
- if (skip?.(src))
13
- return;
14
- await new Promise((resolve, reject) => {
15
- const readStream = fs_1.default.createReadStream(src);
16
- const writeStream = fs_1.default.createWriteStream(dest);
17
- readStream.on('error', reject);
18
- writeStream.on('error', reject);
19
- writeStream.on('finish', resolve);
20
- readStream.pipe(writeStream);
21
- });
22
- }
23
- async function copyDirectory(src, dest, { skip } = {}) {
24
- if (skip?.(src))
25
- return;
26
- await fs_1.default.promises.mkdir(dest, { recursive: true });
27
- const entries = await fs_1.default.promises.readdir(src, { withFileTypes: true });
28
- for (const entry of entries) {
29
- const srcPath = path_1.default.join(src, entry.name);
30
- const destPath = path_1.default.join(dest, entry.name);
31
- if (entry.isDirectory()) {
32
- await copyDirectory(srcPath, destPath, { skip });
33
- }
34
- else {
35
- await copyFile(srcPath, destPath, { skip });
36
- }
37
- }
38
- }
39
- async function copyRecursive(src, dest, { skip } = {}) {
40
- if (skip?.(src))
41
- return;
42
- const srcStats = await fs_1.default.promises.stat(src);
43
- if (srcStats.isDirectory()) {
44
- await copyDirectory(src, dest, { skip });
45
- }
46
- else {
47
- await copyFile(src, dest, { skip });
48
- }
49
- }