@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.
Files changed (252) hide show
  1. package/lib/cjs/agents/agent.d.ts +55 -0
  2. package/lib/cjs/agents/agent.js +91 -0
  3. package/lib/cjs/agents/ai-agent.d.ts +20 -0
  4. package/lib/cjs/agents/ai-agent.js +86 -0
  5. package/lib/cjs/agents/mcp-agent.d.ts +27 -0
  6. package/lib/cjs/agents/mcp-agent.js +95 -0
  7. package/lib/cjs/agents/types.d.ts +9 -0
  8. package/lib/cjs/agents/types.js +16 -0
  9. package/lib/cjs/execution-engine/context.d.ts +10 -0
  10. package/lib/cjs/execution-engine/index.d.ts +45 -0
  11. package/lib/cjs/execution-engine/index.js +190 -0
  12. package/lib/cjs/execution-engine/message-queue.d.ts +5 -0
  13. package/lib/cjs/execution-engine/message-queue.js +9 -0
  14. package/lib/cjs/index.d.ts +10 -21
  15. package/lib/cjs/index.js +10 -21
  16. package/lib/cjs/models/chat-openai.d.ts +14 -0
  17. package/lib/cjs/{llm-models/openai-llm-model.js → models/chat-openai.js} +62 -27
  18. package/lib/cjs/models/chat.d.ts +78 -0
  19. package/lib/cjs/models/chat.js +91 -0
  20. package/lib/cjs/prompt/prompt-builder.d.ts +34 -0
  21. package/lib/cjs/prompt/prompt-builder.js +140 -0
  22. package/lib/cjs/prompt/template.d.ts +70 -0
  23. package/lib/cjs/prompt/template.js +172 -0
  24. package/lib/cjs/utils/logger.d.ts +6 -3
  25. package/lib/cjs/utils/logger.js +9 -14
  26. package/lib/cjs/utils/type-utils.d.ts +5 -1
  27. package/lib/cjs/utils/type-utils.js +23 -0
  28. package/lib/dts/agents/agent.d.ts +55 -0
  29. package/lib/dts/agents/ai-agent.d.ts +20 -0
  30. package/lib/dts/agents/mcp-agent.d.ts +27 -0
  31. package/lib/dts/agents/types.d.ts +9 -0
  32. package/lib/dts/execution-engine/context.d.ts +10 -0
  33. package/lib/dts/execution-engine/index.d.ts +45 -0
  34. package/lib/dts/execution-engine/message-queue.d.ts +5 -0
  35. package/lib/dts/index.d.ts +10 -21
  36. package/lib/dts/models/chat-openai.d.ts +14 -0
  37. package/lib/dts/models/chat.d.ts +78 -0
  38. package/lib/dts/prompt/prompt-builder.d.ts +34 -0
  39. package/lib/dts/prompt/template.d.ts +70 -0
  40. package/lib/dts/utils/logger.d.ts +6 -3
  41. package/lib/dts/utils/type-utils.d.ts +5 -1
  42. package/lib/esm/agents/agent.d.ts +55 -0
  43. package/lib/esm/agents/agent.js +83 -0
  44. package/lib/esm/agents/ai-agent.d.ts +20 -0
  45. package/lib/esm/agents/ai-agent.js +82 -0
  46. package/lib/esm/agents/mcp-agent.d.ts +27 -0
  47. package/lib/esm/agents/mcp-agent.js +90 -0
  48. package/lib/esm/agents/types.d.ts +9 -0
  49. package/lib/esm/agents/types.js +11 -0
  50. package/lib/esm/execution-engine/context.d.ts +10 -0
  51. package/lib/esm/execution-engine/index.d.ts +45 -0
  52. package/lib/esm/execution-engine/index.js +182 -0
  53. package/lib/esm/execution-engine/message-queue.d.ts +5 -0
  54. package/lib/esm/execution-engine/message-queue.js +5 -0
  55. package/lib/esm/index.d.ts +10 -21
  56. package/lib/esm/index.js +10 -21
  57. package/lib/esm/models/chat-openai.d.ts +14 -0
  58. package/lib/esm/{llm-models/openai-llm-model.js → models/chat-openai.js} +59 -24
  59. package/lib/esm/models/chat.d.ts +78 -0
  60. package/lib/esm/models/chat.js +87 -0
  61. package/lib/esm/prompt/prompt-builder.d.ts +34 -0
  62. package/lib/esm/prompt/prompt-builder.js +131 -0
  63. package/lib/esm/prompt/template.d.ts +70 -0
  64. package/lib/esm/prompt/template.js +158 -0
  65. package/lib/esm/utils/logger.d.ts +6 -3
  66. package/lib/esm/utils/logger.js +6 -14
  67. package/lib/esm/utils/type-utils.d.ts +5 -1
  68. package/lib/esm/utils/type-utils.js +17 -1
  69. package/package.json +18 -14
  70. package/lib/cjs/agent.d.ts +0 -96
  71. package/lib/cjs/agent.js +0 -165
  72. package/lib/cjs/constants.d.ts +0 -7
  73. package/lib/cjs/constants.js +0 -10
  74. package/lib/cjs/context.d.ts +0 -23
  75. package/lib/cjs/definitions/data-schema.d.ts +0 -61
  76. package/lib/cjs/definitions/data-schema.js +0 -47
  77. package/lib/cjs/definitions/data-type.d.ts +0 -32
  78. package/lib/cjs/definitions/data-type.js +0 -2
  79. package/lib/cjs/definitions/memory.d.ts +0 -53
  80. package/lib/cjs/definitions/memory.js +0 -23
  81. package/lib/cjs/definitions/open-api.d.ts +0 -36
  82. package/lib/cjs/definitions/open-api.js +0 -2
  83. package/lib/cjs/definitions/preload.d.ts +0 -43
  84. package/lib/cjs/definitions/preload.js +0 -34
  85. package/lib/cjs/function-agent.d.ts +0 -23
  86. package/lib/cjs/function-agent.js +0 -62
  87. package/lib/cjs/llm-agent.d.ts +0 -53
  88. package/lib/cjs/llm-agent.js +0 -140
  89. package/lib/cjs/llm-decision-agent.d.ts +0 -53
  90. package/lib/cjs/llm-decision-agent.js +0 -144
  91. package/lib/cjs/llm-model.d.ts +0 -80
  92. package/lib/cjs/llm-model.js +0 -27
  93. package/lib/cjs/llm-models/gemini-llm-model.d.ts +0 -24
  94. package/lib/cjs/llm-models/gemini-llm-model.js +0 -199
  95. package/lib/cjs/llm-models/openai-llm-model.d.ts +0 -26
  96. package/lib/cjs/memorable.d.ts +0 -198
  97. package/lib/cjs/memorable.js +0 -33
  98. package/lib/cjs/open-api-agent.d.ts +0 -26
  99. package/lib/cjs/open-api-agent.js +0 -68
  100. package/lib/cjs/pipeline-agent.d.ts +0 -56
  101. package/lib/cjs/pipeline-agent.js +0 -206
  102. package/lib/cjs/runnable.d.ts +0 -76
  103. package/lib/cjs/runnable.js +0 -37
  104. package/lib/cjs/runtime.d.ts +0 -64
  105. package/lib/cjs/runtime.js +0 -149
  106. package/lib/cjs/sandbox-function-agent.d.ts +0 -21
  107. package/lib/cjs/sandbox-function-agent.js +0 -78
  108. package/lib/cjs/sandbox-function-runner.d.ts +0 -16
  109. package/lib/cjs/sandbox-function-runner.js +0 -32
  110. package/lib/cjs/utils/constants.d.ts +0 -1
  111. package/lib/cjs/utils/constants.js +0 -4
  112. package/lib/cjs/utils/fetch-open-api.d.ts +0 -2
  113. package/lib/cjs/utils/fetch-open-api.js +0 -31
  114. package/lib/cjs/utils/fetch.d.ts +0 -1
  115. package/lib/cjs/utils/fetch.js +0 -21
  116. package/lib/cjs/utils/index.d.ts +0 -12
  117. package/lib/cjs/utils/index.js +0 -28
  118. package/lib/cjs/utils/is-non-nullable.d.ts +0 -2
  119. package/lib/cjs/utils/is-non-nullable.js +0 -20
  120. package/lib/cjs/utils/message-utils.d.ts +0 -20
  121. package/lib/cjs/utils/message-utils.js +0 -79
  122. package/lib/cjs/utils/mustache-utils.d.ts +0 -3
  123. package/lib/cjs/utils/mustache-utils.js +0 -14
  124. package/lib/cjs/utils/nullable.d.ts +0 -7
  125. package/lib/cjs/utils/nullable.js +0 -2
  126. package/lib/cjs/utils/omit.d.ts +0 -1
  127. package/lib/cjs/utils/omit.js +0 -2
  128. package/lib/cjs/utils/open-api-parameter.d.ts +0 -7
  129. package/lib/cjs/utils/open-api-parameter.js +0 -81
  130. package/lib/cjs/utils/ordered-map.d.ts +0 -37
  131. package/lib/cjs/utils/ordered-map.js +0 -103
  132. package/lib/cjs/utils/partial.d.ts +0 -3
  133. package/lib/cjs/utils/partial.js +0 -2
  134. package/lib/cjs/utils/runnable-type.d.ts +0 -5
  135. package/lib/cjs/utils/runnable-type.js +0 -2
  136. package/lib/cjs/utils/stream-utils.d.ts +0 -20
  137. package/lib/cjs/utils/stream-utils.js +0 -86
  138. package/lib/cjs/utils/structured-output-schema.d.ts +0 -3
  139. package/lib/cjs/utils/structured-output-schema.js +0 -43
  140. package/lib/cjs/utils/union.d.ts +0 -1
  141. package/lib/cjs/utils/union.js +0 -2
  142. package/lib/dts/agent.d.ts +0 -96
  143. package/lib/dts/constants.d.ts +0 -7
  144. package/lib/dts/context.d.ts +0 -23
  145. package/lib/dts/definitions/data-schema.d.ts +0 -61
  146. package/lib/dts/definitions/data-type.d.ts +0 -32
  147. package/lib/dts/definitions/memory.d.ts +0 -53
  148. package/lib/dts/definitions/open-api.d.ts +0 -36
  149. package/lib/dts/definitions/preload.d.ts +0 -43
  150. package/lib/dts/function-agent.d.ts +0 -23
  151. package/lib/dts/llm-agent.d.ts +0 -53
  152. package/lib/dts/llm-decision-agent.d.ts +0 -53
  153. package/lib/dts/llm-model.d.ts +0 -80
  154. package/lib/dts/llm-models/gemini-llm-model.d.ts +0 -24
  155. package/lib/dts/llm-models/openai-llm-model.d.ts +0 -26
  156. package/lib/dts/memorable.d.ts +0 -198
  157. package/lib/dts/open-api-agent.d.ts +0 -26
  158. package/lib/dts/pipeline-agent.d.ts +0 -56
  159. package/lib/dts/runnable.d.ts +0 -76
  160. package/lib/dts/runtime.d.ts +0 -64
  161. package/lib/dts/sandbox-function-agent.d.ts +0 -21
  162. package/lib/dts/sandbox-function-runner.d.ts +0 -16
  163. package/lib/dts/utils/constants.d.ts +0 -1
  164. package/lib/dts/utils/fetch-open-api.d.ts +0 -2
  165. package/lib/dts/utils/fetch.d.ts +0 -1
  166. package/lib/dts/utils/index.d.ts +0 -12
  167. package/lib/dts/utils/is-non-nullable.d.ts +0 -2
  168. package/lib/dts/utils/message-utils.d.ts +0 -20
  169. package/lib/dts/utils/mustache-utils.d.ts +0 -3
  170. package/lib/dts/utils/nullable.d.ts +0 -7
  171. package/lib/dts/utils/omit.d.ts +0 -1
  172. package/lib/dts/utils/open-api-parameter.d.ts +0 -7
  173. package/lib/dts/utils/ordered-map.d.ts +0 -37
  174. package/lib/dts/utils/partial.d.ts +0 -3
  175. package/lib/dts/utils/runnable-type.d.ts +0 -5
  176. package/lib/dts/utils/stream-utils.d.ts +0 -20
  177. package/lib/dts/utils/structured-output-schema.d.ts +0 -3
  178. package/lib/dts/utils/union.d.ts +0 -1
  179. package/lib/esm/agent.d.ts +0 -96
  180. package/lib/esm/agent.js +0 -161
  181. package/lib/esm/constants.d.ts +0 -7
  182. package/lib/esm/constants.js +0 -7
  183. package/lib/esm/context.d.ts +0 -23
  184. package/lib/esm/definitions/data-schema.d.ts +0 -61
  185. package/lib/esm/definitions/data-schema.js +0 -44
  186. package/lib/esm/definitions/data-type.d.ts +0 -32
  187. package/lib/esm/definitions/data-type.js +0 -1
  188. package/lib/esm/definitions/memory.d.ts +0 -53
  189. package/lib/esm/definitions/memory.js +0 -20
  190. package/lib/esm/definitions/open-api.d.ts +0 -36
  191. package/lib/esm/definitions/open-api.js +0 -1
  192. package/lib/esm/definitions/preload.d.ts +0 -43
  193. package/lib/esm/definitions/preload.js +0 -31
  194. package/lib/esm/function-agent.d.ts +0 -23
  195. package/lib/esm/function-agent.js +0 -59
  196. package/lib/esm/llm-agent.d.ts +0 -53
  197. package/lib/esm/llm-agent.js +0 -137
  198. package/lib/esm/llm-decision-agent.d.ts +0 -53
  199. package/lib/esm/llm-decision-agent.js +0 -141
  200. package/lib/esm/llm-model.d.ts +0 -80
  201. package/lib/esm/llm-model.js +0 -23
  202. package/lib/esm/llm-models/gemini-llm-model.d.ts +0 -24
  203. package/lib/esm/llm-models/gemini-llm-model.js +0 -195
  204. package/lib/esm/llm-models/openai-llm-model.d.ts +0 -26
  205. package/lib/esm/memorable.d.ts +0 -198
  206. package/lib/esm/memorable.js +0 -28
  207. package/lib/esm/open-api-agent.d.ts +0 -26
  208. package/lib/esm/open-api-agent.js +0 -65
  209. package/lib/esm/pipeline-agent.d.ts +0 -56
  210. package/lib/esm/pipeline-agent.js +0 -203
  211. package/lib/esm/runnable.d.ts +0 -76
  212. package/lib/esm/runnable.js +0 -30
  213. package/lib/esm/runtime.d.ts +0 -64
  214. package/lib/esm/runtime.js +0 -146
  215. package/lib/esm/sandbox-function-agent.d.ts +0 -21
  216. package/lib/esm/sandbox-function-agent.js +0 -74
  217. package/lib/esm/sandbox-function-runner.d.ts +0 -16
  218. package/lib/esm/sandbox-function-runner.js +0 -28
  219. package/lib/esm/utils/constants.d.ts +0 -1
  220. package/lib/esm/utils/constants.js +0 -1
  221. package/lib/esm/utils/fetch-open-api.d.ts +0 -2
  222. package/lib/esm/utils/fetch-open-api.js +0 -28
  223. package/lib/esm/utils/fetch.d.ts +0 -1
  224. package/lib/esm/utils/fetch.js +0 -18
  225. package/lib/esm/utils/index.d.ts +0 -12
  226. package/lib/esm/utils/index.js +0 -12
  227. package/lib/esm/utils/is-non-nullable.d.ts +0 -2
  228. package/lib/esm/utils/is-non-nullable.js +0 -13
  229. package/lib/esm/utils/message-utils.d.ts +0 -20
  230. package/lib/esm/utils/message-utils.js +0 -71
  231. package/lib/esm/utils/mustache-utils.d.ts +0 -3
  232. package/lib/esm/utils/mustache-utils.js +0 -8
  233. package/lib/esm/utils/nullable.d.ts +0 -7
  234. package/lib/esm/utils/nullable.js +0 -1
  235. package/lib/esm/utils/omit.d.ts +0 -1
  236. package/lib/esm/utils/omit.js +0 -1
  237. package/lib/esm/utils/open-api-parameter.d.ts +0 -7
  238. package/lib/esm/utils/open-api-parameter.js +0 -78
  239. package/lib/esm/utils/ordered-map.d.ts +0 -37
  240. package/lib/esm/utils/ordered-map.js +0 -100
  241. package/lib/esm/utils/partial.d.ts +0 -3
  242. package/lib/esm/utils/partial.js +0 -1
  243. package/lib/esm/utils/runnable-type.d.ts +0 -5
  244. package/lib/esm/utils/runnable-type.js +0 -1
  245. package/lib/esm/utils/stream-utils.d.ts +0 -20
  246. package/lib/esm/utils/stream-utils.js +0 -79
  247. package/lib/esm/utils/structured-output-schema.d.ts +0 -3
  248. package/lib/esm/utils/structured-output-schema.js +0 -37
  249. package/lib/esm/utils/union.d.ts +0 -1
  250. package/lib/esm/utils/union.js +0 -1
  251. /package/lib/cjs/{context.js → execution-engine/context.js} +0 -0
  252. /package/lib/esm/{context.js → execution-engine/context.js} +0 -0
@@ -1,78 +0,0 @@
1
- import { isEmpty, omitBy } from "lodash";
2
- import { logger } from "./logger";
3
- import { OrderedRecord } from "./ordered-map";
4
- export async function formatOpenAPIRequest(api, inputs, input) {
5
- const { url, method, ...inputParams } = processParameters(api, inputs, input);
6
- logger.debug("inputParams", inputParams);
7
- const authParams = await getAuthParams(api.auth);
8
- logger.debug("authParams", authParams);
9
- return {
10
- url,
11
- method,
12
- ...omitBy({
13
- ...inputParams,
14
- query: { ...inputParams.query, ...authParams.query },
15
- cookies: { ...inputParams.cookies, ...authParams.cookies },
16
- headers: { ...inputParams.headers, ...authParams.headers },
17
- }, (i) => isEmpty(i)),
18
- };
19
- }
20
- async function getAuthParams(auth) {
21
- if (!auth)
22
- return {};
23
- if (auth.type === "custom") {
24
- return await auth.auth();
25
- }
26
- const { type, key, token } = auth;
27
- switch (auth.in) {
28
- case "query":
29
- return { query: { [key || "token"]: token } };
30
- case "cookie":
31
- return { cookies: { [key || "token"]: token } };
32
- default: {
33
- const prefix = type === "bearer" ? "Bearer " : type === "basic" ? "Basic " : "";
34
- return { headers: { [key || "Authorization"]: `${prefix}${token}` } };
35
- }
36
- }
37
- }
38
- function processParameters(api, inputs, input) {
39
- const result = {
40
- url: api.url,
41
- method: api.method,
42
- headers: {},
43
- query: {},
44
- cookies: {},
45
- body: {},
46
- };
47
- for (const [key, value] of Object.entries(input)) {
48
- const schema = OrderedRecord.find(inputs, (x) => x.name === key);
49
- if (!schema)
50
- continue;
51
- switch (schema.in) {
52
- case "query":
53
- result.query[key] = value;
54
- break;
55
- case "header":
56
- result.headers[key] = value;
57
- break;
58
- case "cookie":
59
- result.cookies[key] = value;
60
- break;
61
- case "body":
62
- result.body[key] = value;
63
- break;
64
- case "path":
65
- result.url = result.url.replace(`{${key}}`, String(value));
66
- break;
67
- default:
68
- // 没有指定 in 的情况
69
- if (result.method.toLowerCase() === "get") {
70
- result.query[key] = value;
71
- }
72
- else {
73
- result.body[key] = value;
74
- }
75
- }
76
- }
77
- return result;
78
- }
@@ -1,37 +0,0 @@
1
- export type OrderedRecord<T extends {
2
- id: string;
3
- }> = Record<string, T> & {
4
- $indexes: string[];
5
- };
6
- export declare namespace OrderedRecord {
7
- function iterator<T extends {
8
- id: string;
9
- }>(record?: OrderedRecord<T>): IterableIterator<T>;
10
- function map<O, T extends {
11
- id: string;
12
- }>(record: OrderedRecord<T> | undefined, fn: (value: T, index: number) => O): O[];
13
- function toArray<T extends {
14
- id: string;
15
- }>(record: OrderedRecord<T> | undefined): T[];
16
- function fromArray<T extends {
17
- id: string;
18
- }>(array?: T[]): OrderedRecord<T>;
19
- function find<T extends {
20
- id: string;
21
- }>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T | undefined;
22
- function filter<T extends {
23
- id: string;
24
- }>(record: OrderedRecord<T> | undefined, predicate: (value: T, index: number) => boolean): T[];
25
- function at<T extends {
26
- id: string;
27
- }>(record: OrderedRecord<T> | undefined, index: number): T | undefined;
28
- function push<T extends {
29
- id: string;
30
- }>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
31
- function merge<T extends {
32
- id: string;
33
- }>(...records: OrderedRecord<T>[]): OrderedRecord<T>;
34
- function pushOrUpdate<T extends {
35
- id: string;
36
- }>(record: OrderedRecord<T>, ...items: T[]): OrderedRecord<T>;
37
- }
@@ -1,100 +0,0 @@
1
- export var OrderedRecord;
2
- (function (OrderedRecord) {
3
- function iterator(record) {
4
- return (function* () {
5
- if (!record)
6
- return;
7
- for (const id of record.$indexes) {
8
- yield record[id];
9
- }
10
- })();
11
- }
12
- OrderedRecord.iterator = iterator;
13
- function map(record, fn) {
14
- if (!record)
15
- return [];
16
- const result = new Array(record.$indexes.length);
17
- for (let i = 0; i < record.$indexes.length; i++) {
18
- result[i] = fn(record[record.$indexes[i]], i);
19
- }
20
- return result;
21
- }
22
- OrderedRecord.map = map;
23
- function toArray(record) {
24
- return OrderedRecord.map(record, (value) => value);
25
- }
26
- OrderedRecord.toArray = toArray;
27
- function fromArray(array) {
28
- const record = { $indexes: [] };
29
- for (const value of array ?? []) {
30
- record[value.id] = value;
31
- record.$indexes.push(value.id);
32
- }
33
- return record;
34
- }
35
- OrderedRecord.fromArray = fromArray;
36
- function find(record, predicate) {
37
- if (!record)
38
- return undefined;
39
- for (let i = 0; i < record.$indexes.length; i++) {
40
- const id = record.$indexes[i];
41
- const value = record[id];
42
- if (predicate(value, i))
43
- return value;
44
- }
45
- return undefined;
46
- }
47
- OrderedRecord.find = find;
48
- function filter(record, predicate) {
49
- if (!record)
50
- return [];
51
- const result = [];
52
- for (let i = 0; i < record.$indexes.length; i++) {
53
- const id = record.$indexes[i];
54
- const value = record[id];
55
- if (predicate(value, i))
56
- result.push(value);
57
- }
58
- return result;
59
- }
60
- OrderedRecord.filter = filter;
61
- function at(record, index) {
62
- if (!record?.$indexes.length)
63
- return undefined;
64
- const id = record.$indexes.at(index);
65
- return record[id];
66
- }
67
- OrderedRecord.at = at;
68
- function push(record, ...items) {
69
- for (const item of items) {
70
- if (record[item.id])
71
- throw new Error(`Item with id ${item.id} already exists`);
72
- record.$indexes.push(item.id);
73
- record[item.id] = item;
74
- }
75
- return record;
76
- }
77
- OrderedRecord.push = push;
78
- function merge(...records) {
79
- const result = { $indexes: [] };
80
- for (const record of records) {
81
- for (const id of record.$indexes) {
82
- if (!result[id])
83
- result.$indexes.push(id);
84
- result[id] = record[id];
85
- }
86
- }
87
- return result;
88
- }
89
- OrderedRecord.merge = merge;
90
- function pushOrUpdate(record, ...items) {
91
- for (const item of items) {
92
- if (!record[item.id]) {
93
- record.$indexes.push(item.id);
94
- }
95
- record[item.id] = item;
96
- }
97
- return record;
98
- }
99
- OrderedRecord.pushOrUpdate = pushOrUpdate;
100
- })(OrderedRecord || (OrderedRecord = {}));
@@ -1,3 +0,0 @@
1
- export type DeepPartial<T> = T extends object ? {
2
- [P in keyof T]?: DeepPartial<T[P]>;
3
- } : T;
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import type { Runnable, RunnableInput, RunnableOutput, RunnableResponseStream } from "../runnable";
2
- import type { UnionToIntersection } from "./union";
3
- export type ExtractRunnableInputType<T> = T extends Runnable<infer I, RunnableOutput> ? I : never;
4
- export type ExtractRunnableOutputType<T> = T extends Runnable<RunnableInput, infer O> ? Exclude<O, RunnableResponseStream<unknown>> : never;
5
- export type ExtractRunnableInputTypeIntersection<T> = UnionToIntersection<ExtractRunnableInputType<T>, Record<string, unknown>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import { type RunnableResponse, type RunnableResponseChunk, type RunnableResponseStream } from "../runnable";
2
- export declare function objectToRunnableResponseStream<T extends {
3
- [key: string]: any;
4
- }>(obj: T): RunnableResponseStream<T>;
5
- export declare function runnableResponseStreamToObject<T extends {
6
- [key: string]: any;
7
- }>(stream: RunnableResponseStream<T> | AsyncGenerator<RunnableResponseChunk<T>>): Promise<T>;
8
- /**
9
- * Extracts the outputs from a runnable output stream and run the
10
- * resolve function on the result before the stream closes. It can be
11
- * used to update the memories of an agent.
12
- * @param output The runnable output stream or object
13
- * @param resolve The function to run on the result
14
- * @returns The runnable output stream or object
15
- */
16
- export declare function extractOutputsFromRunnableOutput<T extends {
17
- [key: string]: any;
18
- }>(output: RunnableResponse<T> | AsyncGenerator<RunnableResponseChunk<T>>, resolve: (result: T) => Promise<void> | void): Promise<RunnableResponse<T>>;
19
- export declare function asyncGeneratorToReadableStream<T>(generator: AsyncGenerator<T>): ReadableStream<T>;
20
- export declare function isAsyncGenerator<T extends AsyncGenerator>(value: any): value is T;
@@ -1,79 +0,0 @@
1
- import { isRunnableResponseDelta, } from "../runnable";
2
- export function objectToRunnableResponseStream(obj) {
3
- return new ReadableStream({
4
- start(controller) {
5
- controller.enqueue({ $text: obj.$text || undefined, delta: obj });
6
- controller.close();
7
- },
8
- });
9
- }
10
- export async function runnableResponseStreamToObject(stream) {
11
- let $text = "";
12
- const result = {};
13
- for await (const value of stream) {
14
- if (isRunnableResponseDelta(value)) {
15
- $text += value.$text || "";
16
- Object.assign(result, value.delta);
17
- }
18
- }
19
- Object.assign(result, { $text: result.$text || $text || undefined });
20
- return result;
21
- }
22
- /**
23
- * Extracts the outputs from a runnable output stream and run the
24
- * resolve function on the result before the stream closes. It can be
25
- * used to update the memories of an agent.
26
- * @param output The runnable output stream or object
27
- * @param resolve The function to run on the result
28
- * @returns The runnable output stream or object
29
- */
30
- export async function extractOutputsFromRunnableOutput(output, resolve) {
31
- if (output instanceof ReadableStream ||
32
- isAsyncGenerator(output)) {
33
- return new ReadableStream({
34
- async start(controller) {
35
- try {
36
- const result = {};
37
- let $text = "";
38
- for await (const value of output) {
39
- controller.enqueue(value);
40
- if (isRunnableResponseDelta(value)) {
41
- $text += value.$text || "";
42
- Object.assign(result, value.delta);
43
- }
44
- }
45
- Object.assign(result, { $text: result.$text || $text || undefined });
46
- await resolve(result);
47
- }
48
- catch (error) {
49
- controller.error(error);
50
- }
51
- finally {
52
- controller.close();
53
- }
54
- },
55
- });
56
- }
57
- await resolve(output);
58
- return output;
59
- }
60
- export function asyncGeneratorToReadableStream(generator) {
61
- return new ReadableStream({
62
- async start(controller) {
63
- try {
64
- for await (const value of generator) {
65
- controller.enqueue(value);
66
- }
67
- }
68
- catch (error) {
69
- controller.error(error);
70
- }
71
- finally {
72
- controller.close();
73
- }
74
- },
75
- });
76
- }
77
- export function isAsyncGenerator(value) {
78
- return Symbol.asyncIterator in value;
79
- }
@@ -1,3 +0,0 @@
1
- import type { RunnableOutputType } from "../runnable";
2
- import { OrderedRecord } from "./ordered-map";
3
- export declare function outputsToJsonSchema(outputs: OrderedRecord<RunnableOutputType>): object;
@@ -1,37 +0,0 @@
1
- import omitBy from "lodash/omitBy";
2
- import { isNonNullable } from "./is-non-nullable";
3
- import { OrderedRecord } from "./ordered-map";
4
- export function outputsToJsonSchema(outputs) {
5
- const outputToSchema = (output) => {
6
- const properties = output.type === "object" && output.properties?.$indexes.length
7
- ? OrderedRecord.map(output.properties, (property) => {
8
- if (!property.name)
9
- return null;
10
- const schema = outputToSchema(property);
11
- if (!schema)
12
- return null;
13
- return { schema, property };
14
- }).filter(isNonNullable)
15
- : undefined;
16
- return omitBy({
17
- type: output.type,
18
- description: output.description,
19
- properties: properties?.length
20
- ? Object.fromEntries(properties.map((p) => [p.property.name, p.schema]))
21
- : undefined,
22
- items: output.type === "array" && output.items
23
- ? outputToSchema(output.items)
24
- : undefined,
25
- additionalProperties: output.type === "object" ? false : undefined,
26
- required: properties?.length
27
- ? properties
28
- .filter((i) => i.property.required)
29
- .map((i) => i.property.name)
30
- : undefined,
31
- }, (v) => v === undefined);
32
- };
33
- return outputToSchema({
34
- type: "object",
35
- properties: outputs,
36
- });
37
- }
@@ -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;
@@ -1 +0,0 @@
1
- export {};