supercompat 3.10.3 → 3.11.0
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/dist/index.cjs +2058 -307
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +2050 -311
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -379,6 +379,15 @@ __export(index_exports, {
|
|
|
379
379
|
anthropicClientAdapter: function() {
|
|
380
380
|
return anthropicClientAdapter;
|
|
381
381
|
},
|
|
382
|
+
azureAgentsRunAdapter: function() {
|
|
383
|
+
return azureAgentsRunAdapter;
|
|
384
|
+
},
|
|
385
|
+
azureAgentsStorageAdapter: function() {
|
|
386
|
+
return azureAgentsStorageAdapter;
|
|
387
|
+
},
|
|
388
|
+
azureAiProjectClientAdapter: function() {
|
|
389
|
+
return azureAiProjectClientAdapter;
|
|
390
|
+
},
|
|
382
391
|
azureOpenaiClientAdapter: function() {
|
|
383
392
|
return azureOpenaiClientAdapter;
|
|
384
393
|
},
|
|
@@ -911,11 +920,11 @@ var isOModel = function(param) {
|
|
|
911
920
|
};
|
|
912
921
|
// src/lib/messages/systemDeveloperMessages.ts
|
|
913
922
|
var systemDeveloperMessages = function(param) {
|
|
914
|
-
var
|
|
923
|
+
var messages5 = param.messages, model = param.model;
|
|
915
924
|
if (isOModel({
|
|
916
925
|
model: model
|
|
917
926
|
})) {
|
|
918
|
-
return
|
|
927
|
+
return messages5.map(function(message) {
|
|
919
928
|
if (message.role === "system") {
|
|
920
929
|
return _object_spread_props(_object_spread({}, message), {
|
|
921
930
|
// TODO: This should be 'developer' but we're using 'user' for now
|
|
@@ -926,7 +935,7 @@ var systemDeveloperMessages = function(param) {
|
|
|
926
935
|
return message;
|
|
927
936
|
});
|
|
928
937
|
}
|
|
929
|
-
return
|
|
938
|
+
return messages5;
|
|
930
939
|
};
|
|
931
940
|
// src/adapters/client/openaiClientAdapter/completions/post.ts
|
|
932
941
|
var omitKeys = function(param) {
|
|
@@ -944,17 +953,17 @@ var post2 = function(param) {
|
|
|
944
953
|
var openai = param.openai;
|
|
945
954
|
return function(_url, options) {
|
|
946
955
|
return _async_to_generator(function() {
|
|
947
|
-
var body,
|
|
956
|
+
var body, messages5, resultOptions, response, stream, data, error;
|
|
948
957
|
return _ts_generator(this, function(_state) {
|
|
949
958
|
switch(_state.label){
|
|
950
959
|
case 0:
|
|
951
960
|
body = JSON.parse(options.body);
|
|
952
|
-
|
|
961
|
+
messages5 = body.messages;
|
|
953
962
|
resultOptions = _object_spread_props(_object_spread({}, (0, import_radash2.omit)(body, omitKeys({
|
|
954
963
|
model: body.model
|
|
955
964
|
}))), {
|
|
956
965
|
messages: systemDeveloperMessages({
|
|
957
|
-
messages:
|
|
966
|
+
messages: messages5,
|
|
958
967
|
model: body.model
|
|
959
968
|
})
|
|
960
969
|
});
|
|
@@ -1154,6 +1163,15 @@ var azureOpenaiClientAdapter = function(param) {
|
|
|
1154
1163
|
}
|
|
1155
1164
|
};
|
|
1156
1165
|
};
|
|
1166
|
+
// src/adapters/client/azureAiProjectClientAdapter/index.ts
|
|
1167
|
+
var azureAiProjectClientAdapter = function(param) {
|
|
1168
|
+
var azureAiProject = param.azureAiProject;
|
|
1169
|
+
return {
|
|
1170
|
+
type: "AZURE_AI_PROJECT",
|
|
1171
|
+
client: azureAiProject,
|
|
1172
|
+
requestHandlers: {}
|
|
1173
|
+
};
|
|
1174
|
+
};
|
|
1157
1175
|
// src/adapters/client/mistralClientAdapter/models/get.ts
|
|
1158
1176
|
var get3 = function(param) {
|
|
1159
1177
|
var mistral = param.mistral;
|
|
@@ -1538,11 +1556,11 @@ var agentSideRoles = [
|
|
|
1538
1556
|
"system"
|
|
1539
1557
|
];
|
|
1540
1558
|
var alternatingMessages = function(param) {
|
|
1541
|
-
var
|
|
1559
|
+
var messages5 = param.messages;
|
|
1542
1560
|
var result = [];
|
|
1543
|
-
|
|
1561
|
+
messages5.forEach(function(message, index) {
|
|
1544
1562
|
result.push(message);
|
|
1545
|
-
var nextMessage =
|
|
1563
|
+
var nextMessage = messages5[index + 1];
|
|
1546
1564
|
if (!nextMessage) return;
|
|
1547
1565
|
if (message.role === "user" && nextMessage.role === "user") {
|
|
1548
1566
|
result.push({
|
|
@@ -1563,12 +1581,12 @@ var post4 = function(param) {
|
|
|
1563
1581
|
var perplexity = param.perplexity;
|
|
1564
1582
|
return function(_url, options) {
|
|
1565
1583
|
return _async_to_generator(function() {
|
|
1566
|
-
var body,
|
|
1584
|
+
var body, messages5, response, stream, data, error;
|
|
1567
1585
|
return _ts_generator(this, function(_state) {
|
|
1568
1586
|
switch(_state.label){
|
|
1569
1587
|
case 0:
|
|
1570
1588
|
body = JSON.parse(options.body);
|
|
1571
|
-
|
|
1589
|
+
messages5 = alternatingMessages({
|
|
1572
1590
|
messages: body.messages
|
|
1573
1591
|
});
|
|
1574
1592
|
if (!body.stream) return [
|
|
@@ -1578,7 +1596,7 @@ var post4 = function(param) {
|
|
|
1578
1596
|
return [
|
|
1579
1597
|
4,
|
|
1580
1598
|
perplexity.chat.completions.create(_object_spread_props(_object_spread({}, body), {
|
|
1581
|
-
messages:
|
|
1599
|
+
messages: messages5
|
|
1582
1600
|
}))
|
|
1583
1601
|
];
|
|
1584
1602
|
case 1:
|
|
@@ -1841,9 +1859,9 @@ var nonEmptyContent = function(param) {
|
|
|
1841
1859
|
return message.content;
|
|
1842
1860
|
};
|
|
1843
1861
|
var nonEmptyMessages = function(param) {
|
|
1844
|
-
var
|
|
1862
|
+
var messages5 = param.messages;
|
|
1845
1863
|
var result = [];
|
|
1846
|
-
|
|
1864
|
+
messages5.forEach(function(message) {
|
|
1847
1865
|
return result.push(_object_spread_props(_object_spread({}, message), {
|
|
1848
1866
|
content: nonEmptyContent({
|
|
1849
1867
|
message: message
|
|
@@ -1854,18 +1872,18 @@ var nonEmptyMessages = function(param) {
|
|
|
1854
1872
|
};
|
|
1855
1873
|
// src/lib/messages/firstUserMessages.ts
|
|
1856
1874
|
var firstUserMessages = function(param) {
|
|
1857
|
-
var
|
|
1858
|
-
var firstMessage =
|
|
1859
|
-
if (!firstMessage) return
|
|
1875
|
+
var messages5 = param.messages;
|
|
1876
|
+
var firstMessage = messages5[0];
|
|
1877
|
+
if (!firstMessage) return messages5;
|
|
1860
1878
|
if (firstMessage.role !== "user") {
|
|
1861
1879
|
return [
|
|
1862
1880
|
{
|
|
1863
1881
|
role: "user",
|
|
1864
1882
|
content: "-"
|
|
1865
1883
|
}
|
|
1866
|
-
].concat(_to_consumable_array(
|
|
1884
|
+
].concat(_to_consumable_array(messages5));
|
|
1867
1885
|
}
|
|
1868
|
-
return
|
|
1886
|
+
return messages5;
|
|
1869
1887
|
};
|
|
1870
1888
|
// src/adapters/client/anthropicClientAdapter/completions/serializeTools.ts
|
|
1871
1889
|
var serializeTools = function(param) {
|
|
@@ -1939,8 +1957,8 @@ var serializeMessage2 = function(param) {
|
|
|
1939
1957
|
};
|
|
1940
1958
|
// src/adapters/client/anthropicClientAdapter/completions/serializeMessages/index.ts
|
|
1941
1959
|
var serializeMessages = function(param) {
|
|
1942
|
-
var
|
|
1943
|
-
return
|
|
1960
|
+
var messages5 = param.messages;
|
|
1961
|
+
return messages5.map(function(message) {
|
|
1944
1962
|
return serializeMessage2({
|
|
1945
1963
|
message: message
|
|
1946
1964
|
});
|
|
@@ -2418,13 +2436,13 @@ var post5 = function(param) {
|
|
|
2418
2436
|
var anthropic = param.anthropic;
|
|
2419
2437
|
return function(_url, options) {
|
|
2420
2438
|
return _async_to_generator(function() {
|
|
2421
|
-
var body,
|
|
2439
|
+
var body, messages5, _ref, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, normalizedContent, normalizedData, error;
|
|
2422
2440
|
return _ts_generator(this, function(_state) {
|
|
2423
2441
|
switch(_state.label){
|
|
2424
2442
|
case 0:
|
|
2425
2443
|
body = JSON.parse(options.body);
|
|
2426
|
-
|
|
2427
|
-
_ref = _sliced_to_array((0, import_radash4.fork)(
|
|
2444
|
+
messages5 = body.messages;
|
|
2445
|
+
_ref = _sliced_to_array((0, import_radash4.fork)(messages5, function(message) {
|
|
2428
2446
|
return message.role === "system";
|
|
2429
2447
|
}), 2), systemMessages = _ref[0], otherMessages = _ref[1];
|
|
2430
2448
|
system = systemMessages.map(function(message) {
|
|
@@ -4047,11 +4065,11 @@ var serializeMessage3 = function(param) {
|
|
|
4047
4065
|
message: message
|
|
4048
4066
|
})
|
|
4049
4067
|
];
|
|
4050
|
-
var
|
|
4051
|
-
if (!
|
|
4068
|
+
var run4 = message.run;
|
|
4069
|
+
if (!run4) return result;
|
|
4052
4070
|
var messageToolCalls = ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) || [];
|
|
4053
4071
|
messageToolCalls.forEach(function(tc) {
|
|
4054
|
-
var runStep =
|
|
4072
|
+
var runStep = run4.runSteps.find(function(rs) {
|
|
4055
4073
|
if (rs.type !== "tool_calls") return false;
|
|
4056
4074
|
var stepDetails2 = rs.step_details;
|
|
4057
4075
|
if (!Array.isArray(stepDetails2.tool_calls)) return false;
|
|
@@ -4075,16 +4093,16 @@ var serializeMessage3 = function(param) {
|
|
|
4075
4093
|
};
|
|
4076
4094
|
// src/adapters/run/completionsRunAdapter/messages/index.ts
|
|
4077
4095
|
var messages = function(param) {
|
|
4078
|
-
var
|
|
4096
|
+
var run4 = param.run, getMessages2 = param.getMessages;
|
|
4079
4097
|
return _async_to_generator(function() {
|
|
4080
4098
|
var _, _1, _2;
|
|
4081
4099
|
return _ts_generator(this, function(_state) {
|
|
4082
4100
|
switch(_state.label){
|
|
4083
4101
|
case 0:
|
|
4084
|
-
_1 = (_ = _to_consumable_array(
|
|
4102
|
+
_1 = (_ = _to_consumable_array(run4.instructions ? [
|
|
4085
4103
|
{
|
|
4086
4104
|
role: "system",
|
|
4087
|
-
content:
|
|
4105
|
+
content: run4.instructions
|
|
4088
4106
|
}
|
|
4089
4107
|
] : [])).concat;
|
|
4090
4108
|
_2 = (0, import_radash6.flat);
|
|
@@ -4183,18 +4201,18 @@ var toolCallsData = function(param) {
|
|
|
4183
4201
|
var completionsRunAdapter = function() {
|
|
4184
4202
|
return {
|
|
4185
4203
|
handleRun: function(param) {
|
|
4186
|
-
var client = param.client,
|
|
4204
|
+
var client = param.client, run4 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
|
|
4187
4205
|
return _async_to_generator(function() {
|
|
4188
4206
|
var opts, _tmp, providerResponse, e, _e_cause, _e_message, _e_cause_message, message, toolCallsRunStep, currentContent, currentToolCalls, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, chunk, _chunk_choices, choices, choice, delta, _delta_content, err, _message_toolCalls, messageToolCalls, functionToolCalls, pendingFunctionToolCalls, requiredToolCalls;
|
|
4189
4207
|
return _ts_generator(this, function(_state) {
|
|
4190
4208
|
switch(_state.label){
|
|
4191
4209
|
case 0:
|
|
4192
|
-
if (
|
|
4210
|
+
if (run4.status !== "queued") return [
|
|
4193
4211
|
2
|
|
4194
4212
|
];
|
|
4195
4213
|
onEvent2({
|
|
4196
4214
|
event: "thread.run.in_progress",
|
|
4197
|
-
data: _object_spread_props(_object_spread({},
|
|
4215
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4198
4216
|
status: "in_progress"
|
|
4199
4217
|
})
|
|
4200
4218
|
});
|
|
@@ -4202,15 +4220,15 @@ var completionsRunAdapter = function() {
|
|
|
4202
4220
|
return [
|
|
4203
4221
|
4,
|
|
4204
4222
|
messages({
|
|
4205
|
-
run:
|
|
4223
|
+
run: run4,
|
|
4206
4224
|
getMessages: getMessages2
|
|
4207
4225
|
})
|
|
4208
4226
|
];
|
|
4209
4227
|
case 1:
|
|
4210
4228
|
opts = _object_spread.apply(void 0, [
|
|
4211
|
-
(_tmp.messages = _state.sent(), _tmp.model =
|
|
4212
|
-
(0, import_radash7.isEmpty)(
|
|
4213
|
-
tools:
|
|
4229
|
+
(_tmp.messages = _state.sent(), _tmp.model = run4.model, _tmp.stream = true, _tmp.response_format = run4.response_format, _tmp),
|
|
4230
|
+
(0, import_radash7.isEmpty)(run4.tools) ? {} : {
|
|
4231
|
+
tools: run4.tools
|
|
4214
4232
|
}
|
|
4215
4233
|
]);
|
|
4216
4234
|
_state.label = 2;
|
|
@@ -4238,7 +4256,7 @@ var completionsRunAdapter = function() {
|
|
|
4238
4256
|
2,
|
|
4239
4257
|
onEvent2({
|
|
4240
4258
|
event: "thread.run.failed",
|
|
4241
|
-
data: _object_spread_props(_object_spread({},
|
|
4259
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4242
4260
|
failed_at: (0, import_dayjs.default)().unix(),
|
|
4243
4261
|
status: "in_progress",
|
|
4244
4262
|
last_error: {
|
|
@@ -4257,14 +4275,14 @@ var completionsRunAdapter = function() {
|
|
|
4257
4275
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4258
4276
|
object: "thread.message",
|
|
4259
4277
|
completed_at: null,
|
|
4260
|
-
run_id:
|
|
4278
|
+
run_id: run4.id,
|
|
4261
4279
|
created_at: (0, import_dayjs.default)().unix(),
|
|
4262
|
-
assistant_id:
|
|
4280
|
+
assistant_id: run4.assistant_id,
|
|
4263
4281
|
incomplete_at: null,
|
|
4264
4282
|
incomplete_details: null,
|
|
4265
4283
|
metadata: {},
|
|
4266
4284
|
attachments: [],
|
|
4267
|
-
thread_id:
|
|
4285
|
+
thread_id: run4.thread_id,
|
|
4268
4286
|
content: [
|
|
4269
4287
|
{
|
|
4270
4288
|
text: {
|
|
@@ -4286,9 +4304,9 @@ var completionsRunAdapter = function() {
|
|
|
4286
4304
|
data: {
|
|
4287
4305
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4288
4306
|
object: "thread.run.step",
|
|
4289
|
-
run_id:
|
|
4290
|
-
assistant_id:
|
|
4291
|
-
thread_id:
|
|
4307
|
+
run_id: run4.id,
|
|
4308
|
+
assistant_id: run4.assistant_id,
|
|
4309
|
+
thread_id: run4.thread_id,
|
|
4292
4310
|
type: "message_creation",
|
|
4293
4311
|
status: "completed",
|
|
4294
4312
|
completed_at: (0, import_dayjs.default)().unix(),
|
|
@@ -4357,9 +4375,9 @@ var completionsRunAdapter = function() {
|
|
|
4357
4375
|
data: {
|
|
4358
4376
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4359
4377
|
object: "thread.run.step",
|
|
4360
|
-
run_id:
|
|
4361
|
-
assistant_id:
|
|
4362
|
-
thread_id:
|
|
4378
|
+
run_id: run4.id,
|
|
4379
|
+
assistant_id: run4.assistant_id,
|
|
4380
|
+
thread_id: run4.thread_id,
|
|
4363
4381
|
type: "tool_calls",
|
|
4364
4382
|
status: "in_progress",
|
|
4365
4383
|
completed_at: null,
|
|
@@ -4385,7 +4403,7 @@ var completionsRunAdapter = function() {
|
|
|
4385
4403
|
event: "thread.run.step.delta",
|
|
4386
4404
|
data: {
|
|
4387
4405
|
object: "thread.run.step.delta",
|
|
4388
|
-
run_id:
|
|
4406
|
+
run_id: run4.id,
|
|
4389
4407
|
id: toolCallsRunStep.id,
|
|
4390
4408
|
delta: {
|
|
4391
4409
|
step_details: {
|
|
@@ -4540,7 +4558,7 @@ var completionsRunAdapter = function() {
|
|
|
4540
4558
|
2,
|
|
4541
4559
|
onEvent2({
|
|
4542
4560
|
event: "thread.run.completed",
|
|
4543
|
-
data: _object_spread_props(_object_spread({},
|
|
4561
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4544
4562
|
status: "completed",
|
|
4545
4563
|
completed_at: (0, import_dayjs.default)().unix()
|
|
4546
4564
|
})
|
|
@@ -4583,7 +4601,7 @@ var completionsRunAdapter = function() {
|
|
|
4583
4601
|
2,
|
|
4584
4602
|
onEvent2({
|
|
4585
4603
|
event: "thread.run.requires_action",
|
|
4586
|
-
data: _object_spread_props(_object_spread({},
|
|
4604
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4587
4605
|
status: "requires_action",
|
|
4588
4606
|
required_action: {
|
|
4589
4607
|
type: "submit_tool_outputs",
|
|
@@ -4630,7 +4648,7 @@ var post10 = function(param) {
|
|
|
4630
4648
|
var prisma = param.prisma;
|
|
4631
4649
|
return function(_urlString, options) {
|
|
4632
4650
|
return _async_to_generator(function() {
|
|
4633
|
-
var body,
|
|
4651
|
+
var body, messages5, metadataRecord, assistantId, initialCreatedAt, messageData, threadData, thread;
|
|
4634
4652
|
return _ts_generator(this, function(_state) {
|
|
4635
4653
|
switch(_state.label){
|
|
4636
4654
|
case 0:
|
|
@@ -4638,14 +4656,14 @@ var post10 = function(param) {
|
|
|
4638
4656
|
throw new Error("No body provided");
|
|
4639
4657
|
}
|
|
4640
4658
|
body = JSON.parse(options.body);
|
|
4641
|
-
|
|
4659
|
+
messages5 = body.messages || [];
|
|
4642
4660
|
metadataRecord = body.metadata || {};
|
|
4643
4661
|
assistantId = typeof metadataRecord.assistantId === "string" ? metadataRecord.assistantId : void 0;
|
|
4644
4662
|
if (!assistantId) {
|
|
4645
4663
|
throw new Error("assistantId is required to create a thread");
|
|
4646
4664
|
}
|
|
4647
|
-
initialCreatedAt = (0, import_dayjs3.default)().subtract(
|
|
4648
|
-
messageData =
|
|
4665
|
+
initialCreatedAt = (0, import_dayjs3.default)().subtract(messages5.length, "seconds");
|
|
4666
|
+
messageData = messages5.map(function(message, index) {
|
|
4649
4667
|
var _message_attachments;
|
|
4650
4668
|
return {
|
|
4651
4669
|
role: message.role === "user" ? "USER" : "ASSISTANT",
|
|
@@ -4814,7 +4832,7 @@ var get10 = function(param) {
|
|
|
4814
4832
|
var prisma = param.prisma;
|
|
4815
4833
|
return function(urlString) {
|
|
4816
4834
|
return _async_to_generator(function() {
|
|
4817
|
-
var _this, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, messagesPlusOne,
|
|
4835
|
+
var _this, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, messagesPlusOne, messages5, _id;
|
|
4818
4836
|
return _ts_generator(this, function(_state) {
|
|
4819
4837
|
switch(_state.label){
|
|
4820
4838
|
case 0:
|
|
@@ -4844,17 +4862,17 @@ var get10 = function(param) {
|
|
|
4844
4862
|
];
|
|
4845
4863
|
case 1:
|
|
4846
4864
|
messagesPlusOne = _state.sent();
|
|
4847
|
-
|
|
4865
|
+
messages5 = messagesPlusOne.slice(0, pageSize);
|
|
4848
4866
|
return [
|
|
4849
4867
|
2,
|
|
4850
4868
|
new Response(JSON.stringify({
|
|
4851
|
-
data:
|
|
4869
|
+
data: messages5.map(function(message) {
|
|
4852
4870
|
return serializeMessage4({
|
|
4853
4871
|
message: message
|
|
4854
4872
|
});
|
|
4855
4873
|
}),
|
|
4856
4874
|
has_more: messagesPlusOne.length > pageSize,
|
|
4857
|
-
last_id: (_id = (_this = (0, import_radash10.last)(
|
|
4875
|
+
last_id: (_id = (_this = (0, import_radash10.last)(messages5)) === null || _this === void 0 ? void 0 : _this.id) !== null && _id !== void 0 ? _id : null
|
|
4858
4876
|
}), {
|
|
4859
4877
|
status: 200,
|
|
4860
4878
|
headers: {
|
|
@@ -4884,26 +4902,26 @@ var import_radash11 = require("radash");
|
|
|
4884
4902
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
|
|
4885
4903
|
var import_dayjs5 = __toESM(require("dayjs"), 1);
|
|
4886
4904
|
var serializeRun = function(param) {
|
|
4887
|
-
var
|
|
4905
|
+
var run4 = param.run;
|
|
4888
4906
|
return {
|
|
4889
|
-
id:
|
|
4907
|
+
id: run4.id,
|
|
4890
4908
|
object: "thread.run",
|
|
4891
|
-
created_at: (0, import_dayjs5.default)(
|
|
4892
|
-
thread_id:
|
|
4893
|
-
assistant_id:
|
|
4894
|
-
status:
|
|
4895
|
-
required_action:
|
|
4896
|
-
last_error:
|
|
4897
|
-
expires_at: (0, import_dayjs5.default)(
|
|
4898
|
-
started_at:
|
|
4899
|
-
cancelled_at:
|
|
4900
|
-
failed_at:
|
|
4901
|
-
completed_at:
|
|
4902
|
-
model:
|
|
4903
|
-
instructions:
|
|
4904
|
-
tools:
|
|
4905
|
-
metadata:
|
|
4906
|
-
usage:
|
|
4909
|
+
created_at: (0, import_dayjs5.default)(run4.createdAt).unix(),
|
|
4910
|
+
thread_id: run4.threadId,
|
|
4911
|
+
assistant_id: run4.assistantId,
|
|
4912
|
+
status: run4.status.toLowerCase(),
|
|
4913
|
+
required_action: run4.requiredAction,
|
|
4914
|
+
last_error: run4.lastError,
|
|
4915
|
+
expires_at: (0, import_dayjs5.default)(run4.expiresAt).unix(),
|
|
4916
|
+
started_at: run4.startedAt ? (0, import_dayjs5.default)(run4.startedAt).unix() : null,
|
|
4917
|
+
cancelled_at: run4.cancelledAt ? (0, import_dayjs5.default)(run4.cancelledAt).unix() : null,
|
|
4918
|
+
failed_at: run4.failedAt ? (0, import_dayjs5.default)(run4.failedAt).unix() : null,
|
|
4919
|
+
completed_at: run4.completedAt ? (0, import_dayjs5.default)(run4.completedAt).unix() : null,
|
|
4920
|
+
model: run4.model,
|
|
4921
|
+
instructions: run4.instructions,
|
|
4922
|
+
tools: run4.tools,
|
|
4923
|
+
metadata: run4.metadata,
|
|
4924
|
+
usage: run4.usage,
|
|
4907
4925
|
truncation_strategy: {
|
|
4908
4926
|
type: "auto"
|
|
4909
4927
|
},
|
|
@@ -4919,29 +4937,29 @@ var serializeRun = function(param) {
|
|
|
4919
4937
|
};
|
|
4920
4938
|
};
|
|
4921
4939
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/mapPrismaRun.ts
|
|
4922
|
-
var mapPrismaRun = function(
|
|
4923
|
-
var
|
|
4940
|
+
var mapPrismaRun = function(run4) {
|
|
4941
|
+
var _run4_startedAt, _run4_cancelledAt, _run4_failedAt, _run4_completedAt;
|
|
4924
4942
|
return {
|
|
4925
|
-
id:
|
|
4926
|
-
threadId:
|
|
4927
|
-
assistantId:
|
|
4928
|
-
status:
|
|
4929
|
-
requiredAction:
|
|
4930
|
-
lastError:
|
|
4931
|
-
expiresAt:
|
|
4932
|
-
startedAt: (
|
|
4933
|
-
cancelledAt: (
|
|
4934
|
-
failedAt: (
|
|
4935
|
-
completedAt: (
|
|
4936
|
-
model:
|
|
4937
|
-
instructions:
|
|
4938
|
-
tools:
|
|
4939
|
-
metadata:
|
|
4940
|
-
usage:
|
|
4941
|
-
truncationStrategy:
|
|
4942
|
-
responseFormat:
|
|
4943
|
-
createdAt:
|
|
4944
|
-
updatedAt:
|
|
4943
|
+
id: run4.id,
|
|
4944
|
+
threadId: run4.threadId,
|
|
4945
|
+
assistantId: run4.assistantId,
|
|
4946
|
+
status: run4.status,
|
|
4947
|
+
requiredAction: run4.requiredAction,
|
|
4948
|
+
lastError: run4.lastError,
|
|
4949
|
+
expiresAt: run4.expiresAt,
|
|
4950
|
+
startedAt: (_run4_startedAt = run4.startedAt) !== null && _run4_startedAt !== void 0 ? _run4_startedAt : null,
|
|
4951
|
+
cancelledAt: (_run4_cancelledAt = run4.cancelledAt) !== null && _run4_cancelledAt !== void 0 ? _run4_cancelledAt : null,
|
|
4952
|
+
failedAt: (_run4_failedAt = run4.failedAt) !== null && _run4_failedAt !== void 0 ? _run4_failedAt : null,
|
|
4953
|
+
completedAt: (_run4_completedAt = run4.completedAt) !== null && _run4_completedAt !== void 0 ? _run4_completedAt : null,
|
|
4954
|
+
model: run4.model,
|
|
4955
|
+
instructions: run4.instructions,
|
|
4956
|
+
tools: run4.tools,
|
|
4957
|
+
metadata: run4.metadata,
|
|
4958
|
+
usage: run4.usage,
|
|
4959
|
+
truncationStrategy: run4.truncationStrategy,
|
|
4960
|
+
responseFormat: run4.responseFormat,
|
|
4961
|
+
createdAt: run4.createdAt,
|
|
4962
|
+
updatedAt: run4.updatedAt
|
|
4945
4963
|
};
|
|
4946
4964
|
};
|
|
4947
4965
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
|
|
@@ -4949,7 +4967,7 @@ var get11 = function(param) {
|
|
|
4949
4967
|
var prisma = param.prisma;
|
|
4950
4968
|
return function(urlString) {
|
|
4951
4969
|
return _async_to_generator(function() {
|
|
4952
|
-
var
|
|
4970
|
+
var _runs4_at, url, _url_pathname_match, threadId, _ref, limit, order, after, pageSize, runsPlusOne, runs4, _runs4_at_id;
|
|
4953
4971
|
return _ts_generator(this, function(_state) {
|
|
4954
4972
|
switch(_state.label){
|
|
4955
4973
|
case 0:
|
|
@@ -4979,17 +4997,17 @@ var get11 = function(param) {
|
|
|
4979
4997
|
];
|
|
4980
4998
|
case 1:
|
|
4981
4999
|
runsPlusOne = _state.sent();
|
|
4982
|
-
|
|
5000
|
+
runs4 = runsPlusOne.slice(0, pageSize);
|
|
4983
5001
|
return [
|
|
4984
5002
|
2,
|
|
4985
5003
|
new Response(JSON.stringify({
|
|
4986
|
-
data:
|
|
5004
|
+
data: runs4.map(function(run4) {
|
|
4987
5005
|
return serializeRun({
|
|
4988
|
-
run: mapPrismaRun(
|
|
5006
|
+
run: mapPrismaRun(run4)
|
|
4989
5007
|
});
|
|
4990
5008
|
}),
|
|
4991
5009
|
has_more: runsPlusOne.length > pageSize,
|
|
4992
|
-
last_id: (
|
|
5010
|
+
last_id: (_runs4_at_id = (_runs4_at = runs4.at(-1)) === null || _runs4_at === void 0 ? void 0 : _runs4_at.id) !== null && _runs4_at_id !== void 0 ? _runs4_at_id : null
|
|
4993
5011
|
}), {
|
|
4994
5012
|
status: 200,
|
|
4995
5013
|
headers: {
|
|
@@ -5320,37 +5338,37 @@ var onEvent = function(param) {
|
|
|
5320
5338
|
};
|
|
5321
5339
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/getMessages.ts
|
|
5322
5340
|
var getTake = function(param) {
|
|
5323
|
-
var
|
|
5341
|
+
var run4 = param.run;
|
|
5324
5342
|
if ([
|
|
5325
5343
|
"auto",
|
|
5326
5344
|
"disabled"
|
|
5327
|
-
].includes(
|
|
5345
|
+
].includes(run4.truncationStrategy.type)) {
|
|
5328
5346
|
return null;
|
|
5329
5347
|
}
|
|
5330
|
-
if (
|
|
5331
|
-
if (!
|
|
5348
|
+
if (run4.truncationStrategy.type === "last_messages") {
|
|
5349
|
+
if (!run4.truncationStrategy.last_messages) {
|
|
5332
5350
|
throw new Error("Truncation strategy last_messages is required");
|
|
5333
5351
|
}
|
|
5334
|
-
return -
|
|
5352
|
+
return -run4.truncationStrategy.last_messages;
|
|
5335
5353
|
}
|
|
5336
|
-
throw new Error("Unsupported truncation strategy type: ".concat(
|
|
5354
|
+
throw new Error("Unsupported truncation strategy type: ".concat(run4.truncationStrategy.type));
|
|
5337
5355
|
};
|
|
5338
5356
|
var getMessages = function(param) {
|
|
5339
|
-
var prisma = param.prisma,
|
|
5357
|
+
var prisma = param.prisma, run4 = param.run;
|
|
5340
5358
|
return function() {
|
|
5341
5359
|
return _async_to_generator(function() {
|
|
5342
|
-
var take,
|
|
5360
|
+
var take, messages5;
|
|
5343
5361
|
return _ts_generator(this, function(_state) {
|
|
5344
5362
|
switch(_state.label){
|
|
5345
5363
|
case 0:
|
|
5346
5364
|
take = getTake({
|
|
5347
|
-
run:
|
|
5365
|
+
run: run4
|
|
5348
5366
|
});
|
|
5349
5367
|
return [
|
|
5350
5368
|
4,
|
|
5351
5369
|
prisma.message.findMany(_object_spread({
|
|
5352
5370
|
where: {
|
|
5353
|
-
threadId:
|
|
5371
|
+
threadId: run4.threadId
|
|
5354
5372
|
},
|
|
5355
5373
|
include: {
|
|
5356
5374
|
run: {
|
|
@@ -5367,10 +5385,10 @@ var getMessages = function(param) {
|
|
|
5367
5385
|
} : {}))
|
|
5368
5386
|
];
|
|
5369
5387
|
case 1:
|
|
5370
|
-
|
|
5388
|
+
messages5 = _state.sent();
|
|
5371
5389
|
return [
|
|
5372
5390
|
2,
|
|
5373
|
-
|
|
5391
|
+
messages5.map(function(message) {
|
|
5374
5392
|
return _object_spread_props(_object_spread({}, serializeMessage4({
|
|
5375
5393
|
message: message
|
|
5376
5394
|
})), {
|
|
@@ -5397,7 +5415,7 @@ var post12 = function(param) {
|
|
|
5397
5415
|
return function(urlString, options) {
|
|
5398
5416
|
return _async_to_generator(function() {
|
|
5399
5417
|
var url, _url_pathname_match, threadId, body, assistant_id, stream, assistant, _ref, model, instructions, // additional_instructions,
|
|
5400
|
-
tools, metadata, response_format, truncation_strategy,
|
|
5418
|
+
tools, metadata, response_format, truncation_strategy, run4, data, readableStream;
|
|
5401
5419
|
return _ts_generator(this, function(_state) {
|
|
5402
5420
|
switch(_state.label){
|
|
5403
5421
|
case 0:
|
|
@@ -5458,9 +5476,9 @@ var post12 = function(param) {
|
|
|
5458
5476
|
})
|
|
5459
5477
|
];
|
|
5460
5478
|
case 2:
|
|
5461
|
-
|
|
5479
|
+
run4 = _state.sent();
|
|
5462
5480
|
data = serializeRun({
|
|
5463
|
-
run:
|
|
5481
|
+
run: run4
|
|
5464
5482
|
});
|
|
5465
5483
|
readableStream = new ReadableStream({
|
|
5466
5484
|
start: function start(controller) {
|
|
@@ -5489,7 +5507,7 @@ var post12 = function(param) {
|
|
|
5489
5507
|
}),
|
|
5490
5508
|
getMessages: getMessages({
|
|
5491
5509
|
prisma: prisma,
|
|
5492
|
-
run:
|
|
5510
|
+
run: run4
|
|
5493
5511
|
})
|
|
5494
5512
|
})
|
|
5495
5513
|
];
|
|
@@ -5512,7 +5530,7 @@ var post12 = function(param) {
|
|
|
5512
5530
|
})({
|
|
5513
5531
|
event: "thread.run.failed",
|
|
5514
5532
|
data: {
|
|
5515
|
-
id:
|
|
5533
|
+
id: run4.id,
|
|
5516
5534
|
failed_at: (0, import_dayjs7.default)().unix(),
|
|
5517
5535
|
last_error: {
|
|
5518
5536
|
code: "server_error",
|
|
@@ -5580,7 +5598,7 @@ var get12 = function(param) {
|
|
|
5580
5598
|
var prisma = param.prisma;
|
|
5581
5599
|
return function(urlString) {
|
|
5582
5600
|
return _async_to_generator(function() {
|
|
5583
|
-
var url, _url_pathname_match, threadId, runId,
|
|
5601
|
+
var url, _url_pathname_match, threadId, runId, run4;
|
|
5584
5602
|
return _ts_generator(this, function(_state) {
|
|
5585
5603
|
switch(_state.label){
|
|
5586
5604
|
case 0:
|
|
@@ -5596,8 +5614,8 @@ var get12 = function(param) {
|
|
|
5596
5614
|
})
|
|
5597
5615
|
];
|
|
5598
5616
|
case 1:
|
|
5599
|
-
|
|
5600
|
-
if (!
|
|
5617
|
+
run4 = _state.sent();
|
|
5618
|
+
if (!run4) {
|
|
5601
5619
|
return [
|
|
5602
5620
|
2,
|
|
5603
5621
|
new Response(JSON.stringify({
|
|
@@ -5613,7 +5631,7 @@ var get12 = function(param) {
|
|
|
5613
5631
|
return [
|
|
5614
5632
|
2,
|
|
5615
5633
|
new Response(JSON.stringify(serializeRun({
|
|
5616
|
-
run: mapPrismaRun(
|
|
5634
|
+
run: mapPrismaRun(run4)
|
|
5617
5635
|
})), {
|
|
5618
5636
|
status: 200,
|
|
5619
5637
|
headers: {
|
|
@@ -5872,7 +5890,7 @@ var post13 = function(param) {
|
|
|
5872
5890
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
5873
5891
|
return function(urlString, options) {
|
|
5874
5892
|
return _async_to_generator(function() {
|
|
5875
|
-
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream,
|
|
5893
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream, run4;
|
|
5876
5894
|
return _ts_generator(this, function(_state) {
|
|
5877
5895
|
switch(_state.label){
|
|
5878
5896
|
case 0:
|
|
@@ -5887,7 +5905,7 @@ var post13 = function(param) {
|
|
|
5887
5905
|
readableStream = new ReadableStream({
|
|
5888
5906
|
start: function start(controller) {
|
|
5889
5907
|
return _async_to_generator(function() {
|
|
5890
|
-
var
|
|
5908
|
+
var run4;
|
|
5891
5909
|
return _ts_generator(this, function(_state) {
|
|
5892
5910
|
switch(_state.label){
|
|
5893
5911
|
case 0:
|
|
@@ -5917,12 +5935,12 @@ var post13 = function(param) {
|
|
|
5917
5935
|
})
|
|
5918
5936
|
];
|
|
5919
5937
|
case 1:
|
|
5920
|
-
|
|
5938
|
+
run4 = _state.sent();
|
|
5921
5939
|
return [
|
|
5922
5940
|
4,
|
|
5923
5941
|
runAdapter.handleRun({
|
|
5924
5942
|
run: serializeRun({
|
|
5925
|
-
run:
|
|
5943
|
+
run: run4
|
|
5926
5944
|
}),
|
|
5927
5945
|
onEvent: onEvent({
|
|
5928
5946
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5934,7 +5952,7 @@ var post13 = function(param) {
|
|
|
5934
5952
|
}),
|
|
5935
5953
|
getMessages: getMessages({
|
|
5936
5954
|
prisma: prisma,
|
|
5937
|
-
run:
|
|
5955
|
+
run: run4
|
|
5938
5956
|
})
|
|
5939
5957
|
})
|
|
5940
5958
|
];
|
|
@@ -5968,7 +5986,7 @@ var post13 = function(param) {
|
|
|
5968
5986
|
})
|
|
5969
5987
|
];
|
|
5970
5988
|
case 2:
|
|
5971
|
-
|
|
5989
|
+
run4 = _state.sent();
|
|
5972
5990
|
return [
|
|
5973
5991
|
4,
|
|
5974
5992
|
new Promise(function(resolve) {
|
|
@@ -5982,7 +6000,7 @@ var post13 = function(param) {
|
|
|
5982
6000
|
4,
|
|
5983
6001
|
runAdapter.handleRun({
|
|
5984
6002
|
run: serializeRun({
|
|
5985
|
-
run:
|
|
6003
|
+
run: run4
|
|
5986
6004
|
}),
|
|
5987
6005
|
onEvent: onEvent({
|
|
5988
6006
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5994,7 +6012,7 @@ var post13 = function(param) {
|
|
|
5994
6012
|
}),
|
|
5995
6013
|
getMessages: getMessages({
|
|
5996
6014
|
prisma: prisma,
|
|
5997
|
-
run:
|
|
6015
|
+
run: run4
|
|
5998
6016
|
})
|
|
5999
6017
|
})
|
|
6000
6018
|
];
|
|
@@ -6016,7 +6034,7 @@ var post13 = function(param) {
|
|
|
6016
6034
|
_state.sent();
|
|
6017
6035
|
return [
|
|
6018
6036
|
2,
|
|
6019
|
-
new Response(JSON.stringify(
|
|
6037
|
+
new Response(JSON.stringify(run4), {
|
|
6020
6038
|
status: 200,
|
|
6021
6039
|
headers: {
|
|
6022
6040
|
"Content-Type": "application/json"
|
|
@@ -6151,7 +6169,7 @@ var post15 = function(param) {
|
|
|
6151
6169
|
var client = param.client;
|
|
6152
6170
|
return function(_urlString, options) {
|
|
6153
6171
|
return _async_to_generator(function() {
|
|
6154
|
-
var body,
|
|
6172
|
+
var body, messages5, metadata, conversation;
|
|
6155
6173
|
return _ts_generator(this, function(_state) {
|
|
6156
6174
|
switch(_state.label){
|
|
6157
6175
|
case 0:
|
|
@@ -6159,13 +6177,13 @@ var post15 = function(param) {
|
|
|
6159
6177
|
throw new Error("Request body is required");
|
|
6160
6178
|
}
|
|
6161
6179
|
body = JSON.parse(options.body);
|
|
6162
|
-
|
|
6180
|
+
messages5 = body.messages || [];
|
|
6163
6181
|
metadata = body.metadata || {};
|
|
6164
6182
|
return [
|
|
6165
6183
|
4,
|
|
6166
6184
|
client.conversations.create({
|
|
6167
6185
|
metadata: metadata,
|
|
6168
|
-
items:
|
|
6186
|
+
items: messages5.map(function(message) {
|
|
6169
6187
|
return {
|
|
6170
6188
|
type: "message",
|
|
6171
6189
|
role: message.role === "user" ? "user" : "assistant",
|
|
@@ -8439,201 +8457,1573 @@ var responsesStorageAdapter = function() {
|
|
|
8439
8457
|
};
|
|
8440
8458
|
};
|
|
8441
8459
|
};
|
|
8442
|
-
// src/adapters/
|
|
8460
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/post.ts
|
|
8443
8461
|
var import_dayjs21 = __toESM(require("dayjs"), 1);
|
|
8444
|
-
var
|
|
8445
|
-
var
|
|
8446
|
-
|
|
8447
|
-
return toolCalls.map(function(toolCall) {
|
|
8448
|
-
if (toolCall.type === "function_call") {
|
|
8449
|
-
return {
|
|
8450
|
-
id: toolCall.call_id,
|
|
8451
|
-
type: "function",
|
|
8452
|
-
function: {
|
|
8453
|
-
name: toolCall.name,
|
|
8454
|
-
arguments: toolCall.arguments
|
|
8455
|
-
}
|
|
8456
|
-
};
|
|
8457
|
-
} else if (toolCall.type === "computer_call") {
|
|
8458
|
-
return {
|
|
8459
|
-
id: toolCall.call_id,
|
|
8460
|
-
type: "computer_call",
|
|
8461
|
-
computer_call: {
|
|
8462
|
-
action: toolCall.action,
|
|
8463
|
-
pending_safety_checks: toolCall.pending_safety_checks
|
|
8464
|
-
}
|
|
8465
|
-
};
|
|
8466
|
-
}
|
|
8467
|
-
});
|
|
8468
|
-
};
|
|
8469
|
-
var responsesRunAdapter = function(param) {
|
|
8470
|
-
var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
|
|
8471
|
-
return p.then(function() {});
|
|
8472
|
-
} : _param_waitUntil;
|
|
8473
|
-
var cachedOpenaiAssistant = null;
|
|
8474
|
-
var getOpenaiAssistant = function() {
|
|
8475
|
-
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, tmp = _ref.select, _ref1 = tmp === void 0 ? {} : tmp, _ref_id = _ref1.id, id = _ref_id === void 0 ? false : _ref_id;
|
|
8462
|
+
var post20 = function(param) {
|
|
8463
|
+
var azureAiProject = param.azureAiProject;
|
|
8464
|
+
return function(_urlString, options) {
|
|
8476
8465
|
return _async_to_generator(function() {
|
|
8477
|
-
var
|
|
8466
|
+
var body, metadata, thread, openaiThread;
|
|
8478
8467
|
return _ts_generator(this, function(_state) {
|
|
8479
8468
|
switch(_state.label){
|
|
8480
8469
|
case 0:
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
};
|
|
8486
|
-
if (!args.select.id) return [
|
|
8487
|
-
3,
|
|
8488
|
-
2
|
|
8489
|
-
];
|
|
8490
|
-
_tmp = {};
|
|
8470
|
+
if (typeof options.body !== "string") {
|
|
8471
|
+
throw new Error("Request body is required");
|
|
8472
|
+
}
|
|
8473
|
+
body = JSON.parse(options.body);
|
|
8474
|
+
metadata = body.metadata || {};
|
|
8491
8475
|
return [
|
|
8492
8476
|
4,
|
|
8493
|
-
|
|
8494
|
-
|
|
8495
|
-
id: true
|
|
8496
|
-
}
|
|
8477
|
+
azureAiProject.agents.threads.create({
|
|
8478
|
+
metadata: metadata
|
|
8497
8479
|
})
|
|
8498
8480
|
];
|
|
8499
8481
|
case 1:
|
|
8482
|
+
thread = _state.sent();
|
|
8483
|
+
openaiThread = {
|
|
8484
|
+
id: thread.id,
|
|
8485
|
+
object: "thread",
|
|
8486
|
+
created_at: (0, import_dayjs21.default)(thread.createdAt).unix(),
|
|
8487
|
+
metadata: thread.metadata || {},
|
|
8488
|
+
tool_resources: null
|
|
8489
|
+
};
|
|
8500
8490
|
return [
|
|
8501
8491
|
2,
|
|
8502
|
-
(
|
|
8492
|
+
new Response(JSON.stringify(openaiThread), {
|
|
8493
|
+
status: 200,
|
|
8494
|
+
headers: {
|
|
8495
|
+
"Content-Type": "application/json"
|
|
8496
|
+
}
|
|
8497
|
+
})
|
|
8503
8498
|
];
|
|
8504
|
-
|
|
8505
|
-
|
|
8506
|
-
|
|
8507
|
-
|
|
8499
|
+
}
|
|
8500
|
+
});
|
|
8501
|
+
})();
|
|
8502
|
+
};
|
|
8503
|
+
};
|
|
8504
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/index.ts
|
|
8505
|
+
var threads3 = function(param) {
|
|
8506
|
+
var azureAiProject = param.azureAiProject;
|
|
8507
|
+
return {
|
|
8508
|
+
post: post20({
|
|
8509
|
+
azureAiProject: azureAiProject
|
|
8510
|
+
})
|
|
8511
|
+
};
|
|
8512
|
+
};
|
|
8513
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/post.ts
|
|
8514
|
+
var import_dayjs22 = __toESM(require("dayjs"), 1);
|
|
8515
|
+
var post21 = function(param) {
|
|
8516
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8517
|
+
return function(urlString, options) {
|
|
8518
|
+
return _async_to_generator(function() {
|
|
8519
|
+
var url, _url_pathname_match, threadId, body, role, content, textContent, textItem, message, openaiAssistant, openaiMessage;
|
|
8520
|
+
return _ts_generator(this, function(_state) {
|
|
8521
|
+
switch(_state.label){
|
|
8522
|
+
case 0:
|
|
8523
|
+
url = new URL(urlString);
|
|
8524
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8525
|
+
if (typeof options.body !== "string") {
|
|
8526
|
+
throw new Error("Request body is required");
|
|
8527
|
+
}
|
|
8528
|
+
body = JSON.parse(options.body);
|
|
8529
|
+
role = body.role, content = body.content;
|
|
8530
|
+
textContent = "";
|
|
8531
|
+
if (typeof content === "string") {
|
|
8532
|
+
textContent = content;
|
|
8533
|
+
} else if (Array.isArray(content)) {
|
|
8534
|
+
textItem = content.find(function(item) {
|
|
8535
|
+
return item.type === "text";
|
|
8536
|
+
});
|
|
8537
|
+
if (textItem) {
|
|
8538
|
+
textContent = textItem.text;
|
|
8539
|
+
}
|
|
8540
|
+
}
|
|
8541
|
+
return [
|
|
8542
|
+
4,
|
|
8543
|
+
azureAiProject.agents.messages.create(threadId, role, textContent)
|
|
8508
8544
|
];
|
|
8545
|
+
case 1:
|
|
8546
|
+
message = _state.sent();
|
|
8509
8547
|
return [
|
|
8510
8548
|
4,
|
|
8511
|
-
|
|
8549
|
+
runAdapter.getOpenaiAssistant({
|
|
8550
|
+
select: {
|
|
8551
|
+
id: true
|
|
8552
|
+
}
|
|
8553
|
+
})
|
|
8512
8554
|
];
|
|
8513
|
-
case
|
|
8514
|
-
|
|
8555
|
+
case 2:
|
|
8556
|
+
openaiAssistant = _state.sent();
|
|
8557
|
+
openaiMessage = {
|
|
8558
|
+
id: message.id,
|
|
8559
|
+
object: "thread.message",
|
|
8560
|
+
created_at: (0, import_dayjs22.default)(message.createdAt).unix(),
|
|
8561
|
+
thread_id: message.threadId,
|
|
8562
|
+
role: message.role,
|
|
8563
|
+
content: message.content.map(function(c) {
|
|
8564
|
+
if (c.type === "text" && "text" in c) {
|
|
8565
|
+
return {
|
|
8566
|
+
type: "text",
|
|
8567
|
+
text: {
|
|
8568
|
+
value: c.text.value,
|
|
8569
|
+
annotations: []
|
|
8570
|
+
}
|
|
8571
|
+
};
|
|
8572
|
+
}
|
|
8573
|
+
return c;
|
|
8574
|
+
}),
|
|
8575
|
+
assistant_id: openaiAssistant.id,
|
|
8576
|
+
run_id: null,
|
|
8577
|
+
attachments: [],
|
|
8578
|
+
metadata: message.metadata || {},
|
|
8579
|
+
status: "completed",
|
|
8580
|
+
completed_at: (0, import_dayjs22.default)(message.createdAt).unix(),
|
|
8581
|
+
incomplete_at: null,
|
|
8582
|
+
incomplete_details: null
|
|
8583
|
+
};
|
|
8515
8584
|
return [
|
|
8516
8585
|
2,
|
|
8517
|
-
|
|
8586
|
+
new Response(JSON.stringify(openaiMessage), {
|
|
8587
|
+
status: 200,
|
|
8588
|
+
headers: {
|
|
8589
|
+
"Content-Type": "application/json"
|
|
8590
|
+
}
|
|
8591
|
+
})
|
|
8518
8592
|
];
|
|
8519
8593
|
}
|
|
8520
8594
|
});
|
|
8521
8595
|
})();
|
|
8522
8596
|
};
|
|
8523
|
-
|
|
8524
|
-
|
|
8597
|
+
};
|
|
8598
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/get.ts
|
|
8599
|
+
var import_dayjs23 = __toESM(require("dayjs"), 1);
|
|
8600
|
+
var get19 = function(param) {
|
|
8601
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8602
|
+
return function(urlString) {
|
|
8525
8603
|
return _async_to_generator(function() {
|
|
8526
|
-
var
|
|
8604
|
+
var _messagesList_, _messagesList_1, url, _url_pathname_match, threadId, order, messages5, openaiAssistant, messagesList, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, message, err, response;
|
|
8527
8605
|
return _ts_generator(this, function(_state) {
|
|
8528
8606
|
switch(_state.label){
|
|
8529
8607
|
case 0:
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8608
|
+
url = new URL(urlString);
|
|
8609
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8610
|
+
order = url.searchParams.get("order") || "desc";
|
|
8611
|
+
return [
|
|
8612
|
+
4,
|
|
8613
|
+
azureAiProject.agents.messages.list(threadId, {
|
|
8614
|
+
order: order
|
|
8615
|
+
})
|
|
8616
|
+
];
|
|
8537
8617
|
case 1:
|
|
8538
|
-
_state.
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8618
|
+
messages5 = _state.sent();
|
|
8619
|
+
return [
|
|
8620
|
+
4,
|
|
8621
|
+
runAdapter.getOpenaiAssistant({
|
|
8622
|
+
select: {
|
|
8623
|
+
id: true
|
|
8624
|
+
}
|
|
8625
|
+
})
|
|
8626
|
+
];
|
|
8546
8627
|
case 2:
|
|
8547
|
-
_state.
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
140,
|
|
8551
|
-
145
|
|
8552
|
-
]);
|
|
8553
|
-
_iterator = _async_iterator(response);
|
|
8628
|
+
openaiAssistant = _state.sent();
|
|
8629
|
+
messagesList = [];
|
|
8630
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
8554
8631
|
_state.label = 3;
|
|
8555
8632
|
case 3:
|
|
8633
|
+
_state.trys.push([
|
|
8634
|
+
3,
|
|
8635
|
+
8,
|
|
8636
|
+
9,
|
|
8637
|
+
14
|
|
8638
|
+
]);
|
|
8639
|
+
_iterator = _async_iterator(messages5);
|
|
8640
|
+
_state.label = 4;
|
|
8641
|
+
case 4:
|
|
8556
8642
|
return [
|
|
8557
8643
|
4,
|
|
8558
8644
|
_iterator.next()
|
|
8559
8645
|
];
|
|
8560
|
-
case
|
|
8646
|
+
case 5:
|
|
8561
8647
|
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
8562
8648
|
3,
|
|
8563
|
-
|
|
8649
|
+
7
|
|
8564
8650
|
];
|
|
8565
8651
|
_value = _step.value;
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
17
|
|
8598
|
-
];
|
|
8599
|
-
case "response.output_item.done":
|
|
8600
|
-
return [
|
|
8601
|
-
3,
|
|
8602
|
-
75
|
|
8603
|
-
];
|
|
8604
|
-
case "response.function_call_arguments.delta":
|
|
8605
|
-
return [
|
|
8606
|
-
3,
|
|
8607
|
-
126
|
|
8608
|
-
];
|
|
8609
|
-
case "response.mcp_call_arguments.delta":
|
|
8610
|
-
return [
|
|
8611
|
-
3,
|
|
8612
|
-
128
|
|
8613
|
-
];
|
|
8614
|
-
case "response.image_generation_call.in_progress":
|
|
8615
|
-
return [
|
|
8616
|
-
3,
|
|
8617
|
-
130
|
|
8618
|
-
];
|
|
8619
|
-
case "response.image_generation_call.generating":
|
|
8620
|
-
return [
|
|
8621
|
-
3,
|
|
8622
|
-
130
|
|
8623
|
-
];
|
|
8624
|
-
case "response.image_generation_call.partial_image":
|
|
8625
|
-
return [
|
|
8626
|
-
3,
|
|
8627
|
-
133
|
|
8628
|
-
];
|
|
8629
|
-
}
|
|
8652
|
+
message = _value;
|
|
8653
|
+
messagesList.push({
|
|
8654
|
+
id: message.id,
|
|
8655
|
+
object: "thread.message",
|
|
8656
|
+
created_at: (0, import_dayjs23.default)(message.createdAt).unix(),
|
|
8657
|
+
thread_id: message.threadId,
|
|
8658
|
+
role: message.role,
|
|
8659
|
+
content: message.content.map(function(c) {
|
|
8660
|
+
if (c.type === "text" && "text" in c) {
|
|
8661
|
+
return {
|
|
8662
|
+
type: "text",
|
|
8663
|
+
text: {
|
|
8664
|
+
value: c.text.value,
|
|
8665
|
+
annotations: []
|
|
8666
|
+
}
|
|
8667
|
+
};
|
|
8668
|
+
}
|
|
8669
|
+
return c;
|
|
8670
|
+
}),
|
|
8671
|
+
assistant_id: openaiAssistant.id,
|
|
8672
|
+
run_id: null,
|
|
8673
|
+
attachments: [],
|
|
8674
|
+
metadata: message.metadata || {},
|
|
8675
|
+
status: "completed",
|
|
8676
|
+
completed_at: (0, import_dayjs23.default)(message.createdAt).unix(),
|
|
8677
|
+
incomplete_at: null,
|
|
8678
|
+
incomplete_details: null
|
|
8679
|
+
});
|
|
8680
|
+
_state.label = 6;
|
|
8681
|
+
case 6:
|
|
8682
|
+
_iteratorAbruptCompletion = false;
|
|
8630
8683
|
return [
|
|
8631
8684
|
3,
|
|
8632
|
-
|
|
8685
|
+
4
|
|
8633
8686
|
];
|
|
8634
|
-
case
|
|
8635
|
-
|
|
8636
|
-
|
|
8687
|
+
case 7:
|
|
8688
|
+
return [
|
|
8689
|
+
3,
|
|
8690
|
+
14
|
|
8691
|
+
];
|
|
8692
|
+
case 8:
|
|
8693
|
+
err = _state.sent();
|
|
8694
|
+
_didIteratorError = true;
|
|
8695
|
+
_iteratorError = err;
|
|
8696
|
+
return [
|
|
8697
|
+
3,
|
|
8698
|
+
14
|
|
8699
|
+
];
|
|
8700
|
+
case 9:
|
|
8701
|
+
_state.trys.push([
|
|
8702
|
+
9,
|
|
8703
|
+
,
|
|
8704
|
+
12,
|
|
8705
|
+
13
|
|
8706
|
+
]);
|
|
8707
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
8708
|
+
3,
|
|
8709
|
+
11
|
|
8710
|
+
];
|
|
8711
|
+
return [
|
|
8712
|
+
4,
|
|
8713
|
+
_iterator.return()
|
|
8714
|
+
];
|
|
8715
|
+
case 10:
|
|
8716
|
+
_state.sent();
|
|
8717
|
+
_state.label = 11;
|
|
8718
|
+
case 11:
|
|
8719
|
+
return [
|
|
8720
|
+
3,
|
|
8721
|
+
13
|
|
8722
|
+
];
|
|
8723
|
+
case 12:
|
|
8724
|
+
if (_didIteratorError) {
|
|
8725
|
+
throw _iteratorError;
|
|
8726
|
+
}
|
|
8727
|
+
return [
|
|
8728
|
+
7
|
|
8729
|
+
];
|
|
8730
|
+
case 13:
|
|
8731
|
+
return [
|
|
8732
|
+
7
|
|
8733
|
+
];
|
|
8734
|
+
case 14:
|
|
8735
|
+
response = {
|
|
8736
|
+
data: messagesList,
|
|
8737
|
+
first_id: ((_messagesList_ = messagesList[0]) === null || _messagesList_ === void 0 ? void 0 : _messagesList_.id) || null,
|
|
8738
|
+
last_id: ((_messagesList_1 = messagesList[messagesList.length - 1]) === null || _messagesList_1 === void 0 ? void 0 : _messagesList_1.id) || null,
|
|
8739
|
+
has_more: false
|
|
8740
|
+
};
|
|
8741
|
+
return [
|
|
8742
|
+
2,
|
|
8743
|
+
new Response(JSON.stringify(response), {
|
|
8744
|
+
status: 200,
|
|
8745
|
+
headers: {
|
|
8746
|
+
"Content-Type": "application/json"
|
|
8747
|
+
}
|
|
8748
|
+
})
|
|
8749
|
+
];
|
|
8750
|
+
}
|
|
8751
|
+
});
|
|
8752
|
+
})();
|
|
8753
|
+
};
|
|
8754
|
+
};
|
|
8755
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/index.ts
|
|
8756
|
+
var messages4 = function(param) {
|
|
8757
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8758
|
+
return {
|
|
8759
|
+
post: post21({
|
|
8760
|
+
azureAiProject: azureAiProject,
|
|
8761
|
+
runAdapter: runAdapter
|
|
8762
|
+
}),
|
|
8763
|
+
get: get19({
|
|
8764
|
+
azureAiProject: azureAiProject,
|
|
8765
|
+
runAdapter: runAdapter
|
|
8766
|
+
})
|
|
8767
|
+
};
|
|
8768
|
+
};
|
|
8769
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/get.ts
|
|
8770
|
+
var get20 = function() {
|
|
8771
|
+
return function() {
|
|
8772
|
+
return _async_to_generator(function() {
|
|
8773
|
+
var response;
|
|
8774
|
+
return _ts_generator(this, function(_state) {
|
|
8775
|
+
response = {
|
|
8776
|
+
data: [],
|
|
8777
|
+
first_id: null,
|
|
8778
|
+
last_id: null,
|
|
8779
|
+
has_more: false
|
|
8780
|
+
};
|
|
8781
|
+
return [
|
|
8782
|
+
2,
|
|
8783
|
+
new Response(JSON.stringify(response), {
|
|
8784
|
+
status: 200,
|
|
8785
|
+
headers: {
|
|
8786
|
+
"Content-Type": "application/json"
|
|
8787
|
+
}
|
|
8788
|
+
})
|
|
8789
|
+
];
|
|
8790
|
+
});
|
|
8791
|
+
})();
|
|
8792
|
+
};
|
|
8793
|
+
};
|
|
8794
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/post.ts
|
|
8795
|
+
var import_radash23 = require("radash");
|
|
8796
|
+
var import_dayjs24 = __toESM(require("dayjs"), 1);
|
|
8797
|
+
var post22 = function(param) {
|
|
8798
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8799
|
+
return function(urlString, options) {
|
|
8800
|
+
return _async_to_generator(function() {
|
|
8801
|
+
var url, _url_pathname_match, threadId, body, assistant_id, stream, instructions, tools, azureAgentId, readableStream, azureRun, retries, maxRetries, createOptions, error, _error_cause, errorMessage, runIdMatch, activeRunId, activeRun, runData;
|
|
8802
|
+
return _ts_generator(this, function(_state) {
|
|
8803
|
+
switch(_state.label){
|
|
8804
|
+
case 0:
|
|
8805
|
+
url = new URL(urlString);
|
|
8806
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8807
|
+
if (typeof options.body !== "string") {
|
|
8808
|
+
throw new Error("Request body is required");
|
|
8809
|
+
}
|
|
8810
|
+
body = JSON.parse(options.body);
|
|
8811
|
+
assistant_id = body.assistant_id, stream = body.stream, instructions = body.instructions, tools = body.tools;
|
|
8812
|
+
if (!assistant_id) {
|
|
8813
|
+
throw new Error("assistant_id is required");
|
|
8814
|
+
}
|
|
8815
|
+
azureAgentId = assistant_id;
|
|
8816
|
+
if (!stream) return [
|
|
8817
|
+
3,
|
|
8818
|
+
1
|
|
8819
|
+
];
|
|
8820
|
+
readableStream = new ReadableStream({
|
|
8821
|
+
start: function start(controller) {
|
|
8822
|
+
return _async_to_generator(function() {
|
|
8823
|
+
var error, _error_cause, _error_message, _error_cause_message, event;
|
|
8824
|
+
return _ts_generator(this, function(_state) {
|
|
8825
|
+
switch(_state.label){
|
|
8826
|
+
case 0:
|
|
8827
|
+
_state.trys.push([
|
|
8828
|
+
0,
|
|
8829
|
+
2,
|
|
8830
|
+
,
|
|
8831
|
+
3
|
|
8832
|
+
]);
|
|
8833
|
+
return [
|
|
8834
|
+
4,
|
|
8835
|
+
runAdapter.handleRun({
|
|
8836
|
+
threadId: threadId,
|
|
8837
|
+
assistantId: azureAgentId,
|
|
8838
|
+
instructions: instructions,
|
|
8839
|
+
tools: tools,
|
|
8840
|
+
onEvent: function(event) {
|
|
8841
|
+
return _async_to_generator(function() {
|
|
8842
|
+
return _ts_generator(this, function(_state) {
|
|
8843
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
8844
|
+
return [
|
|
8845
|
+
2
|
|
8846
|
+
];
|
|
8847
|
+
});
|
|
8848
|
+
})();
|
|
8849
|
+
}
|
|
8850
|
+
})
|
|
8851
|
+
];
|
|
8852
|
+
case 1:
|
|
8853
|
+
_state.sent();
|
|
8854
|
+
return [
|
|
8855
|
+
3,
|
|
8856
|
+
3
|
|
8857
|
+
];
|
|
8858
|
+
case 2:
|
|
8859
|
+
error = _state.sent();
|
|
8860
|
+
console.error(error);
|
|
8861
|
+
event = {
|
|
8862
|
+
event: "thread.run.failed",
|
|
8863
|
+
data: {
|
|
8864
|
+
id: (0, import_radash23.uid)(24),
|
|
8865
|
+
failed_at: (0, import_dayjs24.default)().unix(),
|
|
8866
|
+
last_error: {
|
|
8867
|
+
code: "server_error",
|
|
8868
|
+
message: "".concat((_error_message = error === null || error === void 0 ? void 0 : error.message) !== null && _error_message !== void 0 ? _error_message : "", " ").concat((_error_cause_message = error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) !== null && _error_cause_message !== void 0 ? _error_cause_message : "")
|
|
8869
|
+
}
|
|
8870
|
+
}
|
|
8871
|
+
};
|
|
8872
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
8873
|
+
return [
|
|
8874
|
+
3,
|
|
8875
|
+
3
|
|
8876
|
+
];
|
|
8877
|
+
case 3:
|
|
8878
|
+
controller.close();
|
|
8879
|
+
return [
|
|
8880
|
+
2
|
|
8881
|
+
];
|
|
8882
|
+
}
|
|
8883
|
+
});
|
|
8884
|
+
})();
|
|
8885
|
+
}
|
|
8886
|
+
});
|
|
8887
|
+
return [
|
|
8888
|
+
2,
|
|
8889
|
+
new Response(readableStream, {
|
|
8890
|
+
headers: {
|
|
8891
|
+
"Content-Type": "text/event-stream"
|
|
8892
|
+
}
|
|
8893
|
+
})
|
|
8894
|
+
];
|
|
8895
|
+
case 1:
|
|
8896
|
+
retries = 0;
|
|
8897
|
+
maxRetries = 10;
|
|
8898
|
+
_state.label = 2;
|
|
8899
|
+
case 2:
|
|
8900
|
+
if (!(retries < maxRetries)) return [
|
|
8901
|
+
3,
|
|
8902
|
+
17
|
|
8903
|
+
];
|
|
8904
|
+
_state.label = 3;
|
|
8905
|
+
case 3:
|
|
8906
|
+
_state.trys.push([
|
|
8907
|
+
3,
|
|
8908
|
+
5,
|
|
8909
|
+
,
|
|
8910
|
+
16
|
|
8911
|
+
]);
|
|
8912
|
+
createOptions = {};
|
|
8913
|
+
if (instructions) {
|
|
8914
|
+
createOptions.instructions = instructions;
|
|
8915
|
+
}
|
|
8916
|
+
if (tools) {
|
|
8917
|
+
createOptions.tools = tools;
|
|
8918
|
+
}
|
|
8919
|
+
return [
|
|
8920
|
+
4,
|
|
8921
|
+
azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions)
|
|
8922
|
+
];
|
|
8923
|
+
case 4:
|
|
8924
|
+
azureRun = _state.sent();
|
|
8925
|
+
return [
|
|
8926
|
+
3,
|
|
8927
|
+
17
|
|
8928
|
+
];
|
|
8929
|
+
case 5:
|
|
8930
|
+
error = _state.sent();
|
|
8931
|
+
errorMessage = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) || "";
|
|
8932
|
+
if (!errorMessage.includes("already has an active run")) return [
|
|
8933
|
+
3,
|
|
8934
|
+
14
|
|
8935
|
+
];
|
|
8936
|
+
runIdMatch = errorMessage.match(/run_[a-zA-Z0-9]+/);
|
|
8937
|
+
if (!runIdMatch) return [
|
|
8938
|
+
3,
|
|
8939
|
+
11
|
|
8940
|
+
];
|
|
8941
|
+
activeRunId = runIdMatch[0];
|
|
8942
|
+
return [
|
|
8943
|
+
4,
|
|
8944
|
+
azureAiProject.agents.runs.get(threadId, activeRunId)
|
|
8945
|
+
];
|
|
8946
|
+
case 6:
|
|
8947
|
+
activeRun = _state.sent();
|
|
8948
|
+
_state.label = 7;
|
|
8949
|
+
case 7:
|
|
8950
|
+
if (!(activeRun.status === "queued" || activeRun.status === "in_progress")) return [
|
|
8951
|
+
3,
|
|
8952
|
+
10
|
|
8953
|
+
];
|
|
8954
|
+
return [
|
|
8955
|
+
4,
|
|
8956
|
+
new Promise(function(resolve) {
|
|
8957
|
+
return setTimeout(resolve, 500);
|
|
8958
|
+
})
|
|
8959
|
+
];
|
|
8960
|
+
case 8:
|
|
8961
|
+
_state.sent();
|
|
8962
|
+
return [
|
|
8963
|
+
4,
|
|
8964
|
+
azureAiProject.agents.runs.get(threadId, activeRunId)
|
|
8965
|
+
];
|
|
8966
|
+
case 9:
|
|
8967
|
+
activeRun = _state.sent();
|
|
8968
|
+
return [
|
|
8969
|
+
3,
|
|
8970
|
+
7
|
|
8971
|
+
];
|
|
8972
|
+
case 10:
|
|
8973
|
+
if (activeRun.status === "requires_action") {
|
|
8974
|
+
throw new Error("Thread ".concat(threadId, " has an active run ").concat(activeRunId, " that requires action (tool outputs must be submitted before creating a new run)"));
|
|
8975
|
+
}
|
|
8976
|
+
return [
|
|
8977
|
+
3,
|
|
8978
|
+
13
|
|
8979
|
+
];
|
|
8980
|
+
case 11:
|
|
8981
|
+
return [
|
|
8982
|
+
4,
|
|
8983
|
+
new Promise(function(resolve) {
|
|
8984
|
+
return setTimeout(resolve, 1e3 * Math.pow(2, retries));
|
|
8985
|
+
})
|
|
8986
|
+
];
|
|
8987
|
+
case 12:
|
|
8988
|
+
_state.sent();
|
|
8989
|
+
_state.label = 13;
|
|
8990
|
+
case 13:
|
|
8991
|
+
retries++;
|
|
8992
|
+
return [
|
|
8993
|
+
3,
|
|
8994
|
+
15
|
|
8995
|
+
];
|
|
8996
|
+
case 14:
|
|
8997
|
+
throw error;
|
|
8998
|
+
case 15:
|
|
8999
|
+
return [
|
|
9000
|
+
3,
|
|
9001
|
+
16
|
|
9002
|
+
];
|
|
9003
|
+
case 16:
|
|
9004
|
+
return [
|
|
9005
|
+
3,
|
|
9006
|
+
2
|
|
9007
|
+
];
|
|
9008
|
+
case 17:
|
|
9009
|
+
if (!azureRun) {
|
|
9010
|
+
throw new Error("Failed to create run after ".concat(maxRetries, " retries"));
|
|
9011
|
+
}
|
|
9012
|
+
runData = {
|
|
9013
|
+
id: azureRun.id,
|
|
9014
|
+
object: "thread.run",
|
|
9015
|
+
created_at: (0, import_dayjs24.default)(azureRun.createdAt).unix(),
|
|
9016
|
+
thread_id: azureRun.threadId,
|
|
9017
|
+
assistant_id: azureAgentId,
|
|
9018
|
+
status: azureRun.status,
|
|
9019
|
+
required_action: null,
|
|
9020
|
+
last_error: null,
|
|
9021
|
+
expires_at: null,
|
|
9022
|
+
started_at: azureRun.status === "in_progress" ? (0, import_dayjs24.default)(azureRun.createdAt).unix() : null,
|
|
9023
|
+
cancelled_at: null,
|
|
9024
|
+
failed_at: null,
|
|
9025
|
+
completed_at: null,
|
|
9026
|
+
incomplete_details: null,
|
|
9027
|
+
model: "",
|
|
9028
|
+
instructions: "",
|
|
9029
|
+
tools: [],
|
|
9030
|
+
metadata: azureRun.metadata || {},
|
|
9031
|
+
temperature: null,
|
|
9032
|
+
top_p: null,
|
|
9033
|
+
max_prompt_tokens: null,
|
|
9034
|
+
max_completion_tokens: null,
|
|
9035
|
+
truncation_strategy: {
|
|
9036
|
+
type: "auto",
|
|
9037
|
+
last_messages: null
|
|
9038
|
+
},
|
|
9039
|
+
response_format: "auto",
|
|
9040
|
+
tool_choice: "auto",
|
|
9041
|
+
parallel_tool_calls: true,
|
|
9042
|
+
usage: null
|
|
9043
|
+
};
|
|
9044
|
+
return [
|
|
9045
|
+
2,
|
|
9046
|
+
new Response(JSON.stringify(runData), {
|
|
9047
|
+
status: 200,
|
|
9048
|
+
headers: {
|
|
9049
|
+
"Content-Type": "application/json"
|
|
9050
|
+
}
|
|
9051
|
+
})
|
|
9052
|
+
];
|
|
9053
|
+
case 18:
|
|
9054
|
+
return [
|
|
9055
|
+
2
|
|
9056
|
+
];
|
|
9057
|
+
}
|
|
9058
|
+
});
|
|
9059
|
+
})();
|
|
9060
|
+
};
|
|
9061
|
+
};
|
|
9062
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/index.ts
|
|
9063
|
+
var runs3 = function(param) {
|
|
9064
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9065
|
+
return {
|
|
9066
|
+
get: get20(),
|
|
9067
|
+
post: post22({
|
|
9068
|
+
azureAiProject: azureAiProject,
|
|
9069
|
+
runAdapter: runAdapter
|
|
9070
|
+
})
|
|
9071
|
+
};
|
|
9072
|
+
};
|
|
9073
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/run/get.ts
|
|
9074
|
+
var import_dayjs25 = __toESM(require("dayjs"), 1);
|
|
9075
|
+
var get21 = function(param) {
|
|
9076
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9077
|
+
return function(urlString) {
|
|
9078
|
+
return _async_to_generator(function() {
|
|
9079
|
+
var url, _url_pathname_match, threadId, runId, azureRun, assistantId, openaiRun;
|
|
9080
|
+
return _ts_generator(this, function(_state) {
|
|
9081
|
+
switch(_state.label){
|
|
9082
|
+
case 0:
|
|
9083
|
+
url = new URL(urlString);
|
|
9084
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
9085
|
+
return [
|
|
9086
|
+
4,
|
|
9087
|
+
azureAiProject.agents.runs.get(threadId, runId)
|
|
9088
|
+
];
|
|
9089
|
+
case 1:
|
|
9090
|
+
azureRun = _state.sent();
|
|
9091
|
+
assistantId = azureRun.assistantId;
|
|
9092
|
+
openaiRun = {
|
|
9093
|
+
id: azureRun.id,
|
|
9094
|
+
object: "thread.run",
|
|
9095
|
+
created_at: (0, import_dayjs25.default)(azureRun.createdAt).unix(),
|
|
9096
|
+
thread_id: azureRun.threadId,
|
|
9097
|
+
assistant_id: assistantId,
|
|
9098
|
+
status: azureRun.status,
|
|
9099
|
+
required_action: azureRun.status === "requires_action" && azureRun.requiredAction ? {
|
|
9100
|
+
type: "submit_tool_outputs",
|
|
9101
|
+
submit_tool_outputs: {
|
|
9102
|
+
tool_calls: azureRun.requiredAction.submitToolOutputs.toolCalls.map(function(tc) {
|
|
9103
|
+
return {
|
|
9104
|
+
id: tc.id,
|
|
9105
|
+
type: "function",
|
|
9106
|
+
function: {
|
|
9107
|
+
name: tc.function.name,
|
|
9108
|
+
arguments: tc.function.arguments
|
|
9109
|
+
}
|
|
9110
|
+
};
|
|
9111
|
+
})
|
|
9112
|
+
}
|
|
9113
|
+
} : null,
|
|
9114
|
+
last_error: azureRun.lastError ? {
|
|
9115
|
+
code: "server_error",
|
|
9116
|
+
message: JSON.stringify(azureRun.lastError)
|
|
9117
|
+
} : null,
|
|
9118
|
+
expires_at: null,
|
|
9119
|
+
started_at: (0, import_dayjs25.default)(azureRun.createdAt).unix(),
|
|
9120
|
+
cancelled_at: null,
|
|
9121
|
+
failed_at: azureRun.status === "failed" ? (0, import_dayjs25.default)().unix() : null,
|
|
9122
|
+
completed_at: azureRun.status === "completed" ? (0, import_dayjs25.default)().unix() : null,
|
|
9123
|
+
incomplete_details: null,
|
|
9124
|
+
model: "",
|
|
9125
|
+
instructions: "",
|
|
9126
|
+
tools: [],
|
|
9127
|
+
metadata: azureRun.metadata || {},
|
|
9128
|
+
temperature: null,
|
|
9129
|
+
top_p: null,
|
|
9130
|
+
max_prompt_tokens: null,
|
|
9131
|
+
max_completion_tokens: null,
|
|
9132
|
+
truncation_strategy: {
|
|
9133
|
+
type: "auto",
|
|
9134
|
+
last_messages: null
|
|
9135
|
+
},
|
|
9136
|
+
response_format: "auto",
|
|
9137
|
+
tool_choice: "auto",
|
|
9138
|
+
parallel_tool_calls: true,
|
|
9139
|
+
usage: null
|
|
9140
|
+
};
|
|
9141
|
+
return [
|
|
9142
|
+
2,
|
|
9143
|
+
new Response(JSON.stringify(openaiRun), {
|
|
9144
|
+
status: 200,
|
|
9145
|
+
headers: {
|
|
9146
|
+
"Content-Type": "application/json"
|
|
9147
|
+
}
|
|
9148
|
+
})
|
|
9149
|
+
];
|
|
9150
|
+
}
|
|
9151
|
+
});
|
|
9152
|
+
})();
|
|
9153
|
+
};
|
|
9154
|
+
};
|
|
9155
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/run/index.ts
|
|
9156
|
+
var run3 = function(param) {
|
|
9157
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9158
|
+
return {
|
|
9159
|
+
get: get21({
|
|
9160
|
+
azureAiProject: azureAiProject,
|
|
9161
|
+
runAdapter: runAdapter
|
|
9162
|
+
})
|
|
9163
|
+
};
|
|
9164
|
+
};
|
|
9165
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/get.ts
|
|
9166
|
+
var import_dayjs26 = __toESM(require("dayjs"), 1);
|
|
9167
|
+
var get22 = function(param) {
|
|
9168
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9169
|
+
return function(urlString) {
|
|
9170
|
+
return _async_to_generator(function() {
|
|
9171
|
+
var _stepsList_, _stepsList_1, url, _url_pathname_match, threadId, runId, azureSteps, openaiAssistant, stepsList, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, step, _step_stepDetails_messageCreation, err, response;
|
|
9172
|
+
return _ts_generator(this, function(_state) {
|
|
9173
|
+
switch(_state.label){
|
|
9174
|
+
case 0:
|
|
9175
|
+
url = new URL(urlString);
|
|
9176
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
9177
|
+
return [
|
|
9178
|
+
4,
|
|
9179
|
+
azureAiProject.agents.runSteps.list(threadId, runId)
|
|
9180
|
+
];
|
|
9181
|
+
case 1:
|
|
9182
|
+
azureSteps = _state.sent();
|
|
9183
|
+
return [
|
|
9184
|
+
4,
|
|
9185
|
+
runAdapter.getOpenaiAssistant({
|
|
9186
|
+
select: {
|
|
9187
|
+
id: true
|
|
9188
|
+
}
|
|
9189
|
+
})
|
|
9190
|
+
];
|
|
9191
|
+
case 2:
|
|
9192
|
+
openaiAssistant = _state.sent();
|
|
9193
|
+
stepsList = [];
|
|
9194
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9195
|
+
_state.label = 3;
|
|
9196
|
+
case 3:
|
|
9197
|
+
_state.trys.push([
|
|
9198
|
+
3,
|
|
9199
|
+
8,
|
|
9200
|
+
9,
|
|
9201
|
+
14
|
|
9202
|
+
]);
|
|
9203
|
+
_iterator = _async_iterator(azureSteps);
|
|
9204
|
+
_state.label = 4;
|
|
9205
|
+
case 4:
|
|
9206
|
+
return [
|
|
9207
|
+
4,
|
|
9208
|
+
_iterator.next()
|
|
9209
|
+
];
|
|
9210
|
+
case 5:
|
|
9211
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9212
|
+
3,
|
|
9213
|
+
7
|
|
9214
|
+
];
|
|
9215
|
+
_value = _step.value;
|
|
9216
|
+
step = _value;
|
|
9217
|
+
stepsList.push({
|
|
9218
|
+
id: step.id,
|
|
9219
|
+
object: "thread.run.step",
|
|
9220
|
+
created_at: (0, import_dayjs26.default)(step.createdAt).unix(),
|
|
9221
|
+
assistant_id: openaiAssistant.id,
|
|
9222
|
+
thread_id: threadId,
|
|
9223
|
+
run_id: runId,
|
|
9224
|
+
type: step.type === "tool_calls" ? "tool_calls" : "message_creation",
|
|
9225
|
+
status: step.status,
|
|
9226
|
+
step_details: step.type === "tool_calls" ? {
|
|
9227
|
+
type: "tool_calls",
|
|
9228
|
+
tool_calls: step.stepDetails.toolCalls.map(function(tc) {
|
|
9229
|
+
return {
|
|
9230
|
+
id: tc.id,
|
|
9231
|
+
type: "function",
|
|
9232
|
+
function: {
|
|
9233
|
+
name: tc.function.name,
|
|
9234
|
+
arguments: tc.function.arguments,
|
|
9235
|
+
output: tc.function.output || null
|
|
9236
|
+
}
|
|
9237
|
+
};
|
|
9238
|
+
})
|
|
9239
|
+
} : {
|
|
9240
|
+
type: "message_creation",
|
|
9241
|
+
message_creation: {
|
|
9242
|
+
message_id: (_step_stepDetails_messageCreation = step.stepDetails.messageCreation) === null || _step_stepDetails_messageCreation === void 0 ? void 0 : _step_stepDetails_messageCreation.messageId
|
|
9243
|
+
}
|
|
9244
|
+
},
|
|
9245
|
+
last_error: null,
|
|
9246
|
+
expired_at: null,
|
|
9247
|
+
cancelled_at: null,
|
|
9248
|
+
failed_at: null,
|
|
9249
|
+
completed_at: step.completedAt ? (0, import_dayjs26.default)(step.completedAt).unix() : null,
|
|
9250
|
+
metadata: step.metadata || {},
|
|
9251
|
+
usage: null
|
|
9252
|
+
});
|
|
9253
|
+
_state.label = 6;
|
|
9254
|
+
case 6:
|
|
9255
|
+
_iteratorAbruptCompletion = false;
|
|
9256
|
+
return [
|
|
9257
|
+
3,
|
|
9258
|
+
4
|
|
9259
|
+
];
|
|
9260
|
+
case 7:
|
|
9261
|
+
return [
|
|
9262
|
+
3,
|
|
9263
|
+
14
|
|
9264
|
+
];
|
|
9265
|
+
case 8:
|
|
9266
|
+
err = _state.sent();
|
|
9267
|
+
_didIteratorError = true;
|
|
9268
|
+
_iteratorError = err;
|
|
9269
|
+
return [
|
|
9270
|
+
3,
|
|
9271
|
+
14
|
|
9272
|
+
];
|
|
9273
|
+
case 9:
|
|
9274
|
+
_state.trys.push([
|
|
9275
|
+
9,
|
|
9276
|
+
,
|
|
9277
|
+
12,
|
|
9278
|
+
13
|
|
9279
|
+
]);
|
|
9280
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
9281
|
+
3,
|
|
9282
|
+
11
|
|
9283
|
+
];
|
|
9284
|
+
return [
|
|
9285
|
+
4,
|
|
9286
|
+
_iterator.return()
|
|
9287
|
+
];
|
|
9288
|
+
case 10:
|
|
9289
|
+
_state.sent();
|
|
9290
|
+
_state.label = 11;
|
|
9291
|
+
case 11:
|
|
9292
|
+
return [
|
|
9293
|
+
3,
|
|
9294
|
+
13
|
|
9295
|
+
];
|
|
9296
|
+
case 12:
|
|
9297
|
+
if (_didIteratorError) {
|
|
9298
|
+
throw _iteratorError;
|
|
9299
|
+
}
|
|
9300
|
+
return [
|
|
9301
|
+
7
|
|
9302
|
+
];
|
|
9303
|
+
case 13:
|
|
9304
|
+
return [
|
|
9305
|
+
7
|
|
9306
|
+
];
|
|
9307
|
+
case 14:
|
|
9308
|
+
response = {
|
|
9309
|
+
data: stepsList,
|
|
9310
|
+
first_id: ((_stepsList_ = stepsList[0]) === null || _stepsList_ === void 0 ? void 0 : _stepsList_.id) || null,
|
|
9311
|
+
last_id: ((_stepsList_1 = stepsList[stepsList.length - 1]) === null || _stepsList_1 === void 0 ? void 0 : _stepsList_1.id) || null,
|
|
9312
|
+
has_more: false
|
|
9313
|
+
};
|
|
9314
|
+
return [
|
|
9315
|
+
2,
|
|
9316
|
+
new Response(JSON.stringify(response), {
|
|
9317
|
+
status: 200,
|
|
9318
|
+
headers: {
|
|
9319
|
+
"Content-Type": "application/json"
|
|
9320
|
+
}
|
|
9321
|
+
})
|
|
9322
|
+
];
|
|
9323
|
+
}
|
|
9324
|
+
});
|
|
9325
|
+
})();
|
|
9326
|
+
};
|
|
9327
|
+
};
|
|
9328
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/index.ts
|
|
9329
|
+
var steps3 = function(param) {
|
|
9330
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9331
|
+
return {
|
|
9332
|
+
get: get22({
|
|
9333
|
+
azureAiProject: azureAiProject,
|
|
9334
|
+
runAdapter: runAdapter
|
|
9335
|
+
})
|
|
9336
|
+
};
|
|
9337
|
+
};
|
|
9338
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
|
|
9339
|
+
var import_dayjs27 = __toESM(require("dayjs"), 1);
|
|
9340
|
+
function convertAzureEventToOpenAI(azureEvent, assistantId) {
|
|
9341
|
+
var event = azureEvent.event, data = azureEvent.data;
|
|
9342
|
+
var eventType = event;
|
|
9343
|
+
if (eventType.startsWith("thread.run.")) {
|
|
9344
|
+
var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
|
|
9345
|
+
var _data_temperature, _data_topP;
|
|
9346
|
+
return {
|
|
9347
|
+
event: eventType,
|
|
9348
|
+
data: {
|
|
9349
|
+
id: data.id,
|
|
9350
|
+
object: "thread.run",
|
|
9351
|
+
created_at: (0, import_dayjs27.default)(data.createdAt).unix(),
|
|
9352
|
+
thread_id: data.threadId,
|
|
9353
|
+
assistant_id: assistantId,
|
|
9354
|
+
status: data.status,
|
|
9355
|
+
required_action: data.requiredAction ? {
|
|
9356
|
+
type: "submit_tool_outputs",
|
|
9357
|
+
submit_tool_outputs: {
|
|
9358
|
+
tool_calls: ((_data_requiredAction_submitToolOutputs = data.requiredAction.submitToolOutputs) === null || _data_requiredAction_submitToolOutputs === void 0 ? void 0 : (_data_requiredAction_submitToolOutputs_toolCalls = _data_requiredAction_submitToolOutputs.toolCalls) === null || _data_requiredAction_submitToolOutputs_toolCalls === void 0 ? void 0 : _data_requiredAction_submitToolOutputs_toolCalls.map(function(tc) {
|
|
9359
|
+
return {
|
|
9360
|
+
id: tc.id,
|
|
9361
|
+
type: "function",
|
|
9362
|
+
function: {
|
|
9363
|
+
name: tc.function.name,
|
|
9364
|
+
arguments: tc.function.arguments
|
|
9365
|
+
}
|
|
9366
|
+
};
|
|
9367
|
+
})) || []
|
|
9368
|
+
}
|
|
9369
|
+
} : null,
|
|
9370
|
+
last_error: data.lastError ? {
|
|
9371
|
+
code: "server_error",
|
|
9372
|
+
message: JSON.stringify(data.lastError)
|
|
9373
|
+
} : null,
|
|
9374
|
+
expires_at: null,
|
|
9375
|
+
started_at: data.startedAt ? (0, import_dayjs27.default)(data.startedAt).unix() : null,
|
|
9376
|
+
cancelled_at: data.cancelledAt ? (0, import_dayjs27.default)(data.cancelledAt).unix() : null,
|
|
9377
|
+
failed_at: data.failedAt ? (0, import_dayjs27.default)(data.failedAt).unix() : null,
|
|
9378
|
+
completed_at: data.completedAt ? (0, import_dayjs27.default)(data.completedAt).unix() : null,
|
|
9379
|
+
incomplete_details: null,
|
|
9380
|
+
model: data.model || "",
|
|
9381
|
+
instructions: data.instructions || "",
|
|
9382
|
+
tools: data.tools || [],
|
|
9383
|
+
metadata: data.metadata || {},
|
|
9384
|
+
temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
|
|
9385
|
+
top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
|
|
9386
|
+
max_prompt_tokens: null,
|
|
9387
|
+
max_completion_tokens: null,
|
|
9388
|
+
truncation_strategy: {
|
|
9389
|
+
type: "auto",
|
|
9390
|
+
last_messages: null
|
|
9391
|
+
},
|
|
9392
|
+
response_format: "auto",
|
|
9393
|
+
tool_choice: "auto",
|
|
9394
|
+
parallel_tool_calls: true,
|
|
9395
|
+
usage: null
|
|
9396
|
+
}
|
|
9397
|
+
};
|
|
9398
|
+
}
|
|
9399
|
+
if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
|
|
9400
|
+
var _data_content;
|
|
9401
|
+
return {
|
|
9402
|
+
event: eventType,
|
|
9403
|
+
data: {
|
|
9404
|
+
id: data.id,
|
|
9405
|
+
object: "thread.message",
|
|
9406
|
+
created_at: (0, import_dayjs27.default)(data.createdAt).unix(),
|
|
9407
|
+
thread_id: data.threadId,
|
|
9408
|
+
role: data.role,
|
|
9409
|
+
content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
|
|
9410
|
+
if (c.type === "text") {
|
|
9411
|
+
var _c_text, _c_text1;
|
|
9412
|
+
return {
|
|
9413
|
+
type: "text",
|
|
9414
|
+
text: {
|
|
9415
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
9416
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
9417
|
+
}
|
|
9418
|
+
};
|
|
9419
|
+
}
|
|
9420
|
+
return c;
|
|
9421
|
+
})) || [],
|
|
9422
|
+
assistant_id: assistantId,
|
|
9423
|
+
run_id: data.runId || null,
|
|
9424
|
+
attachments: data.attachments || [],
|
|
9425
|
+
metadata: data.metadata || {},
|
|
9426
|
+
status: data.status || "completed",
|
|
9427
|
+
completed_at: data.completedAt ? (0, import_dayjs27.default)(data.completedAt).unix() : null,
|
|
9428
|
+
incomplete_at: null,
|
|
9429
|
+
incomplete_details: null
|
|
9430
|
+
}
|
|
9431
|
+
};
|
|
9432
|
+
}
|
|
9433
|
+
if (eventType === "thread.message.delta") {
|
|
9434
|
+
var _data_delta_content, _data_delta;
|
|
9435
|
+
return {
|
|
9436
|
+
event: "thread.message.delta",
|
|
9437
|
+
data: {
|
|
9438
|
+
id: data.id,
|
|
9439
|
+
object: "thread.message.delta",
|
|
9440
|
+
delta: {
|
|
9441
|
+
content: ((_data_delta = data.delta) === null || _data_delta === void 0 ? void 0 : (_data_delta_content = _data_delta.content) === null || _data_delta_content === void 0 ? void 0 : _data_delta_content.map(function(c) {
|
|
9442
|
+
if (c.type === "text") {
|
|
9443
|
+
var _c_text, _c_text1;
|
|
9444
|
+
return {
|
|
9445
|
+
index: c.index || 0,
|
|
9446
|
+
type: "text",
|
|
9447
|
+
text: {
|
|
9448
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
9449
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
9450
|
+
}
|
|
9451
|
+
};
|
|
9452
|
+
}
|
|
9453
|
+
return c;
|
|
9454
|
+
})) || []
|
|
9455
|
+
}
|
|
9456
|
+
}
|
|
9457
|
+
};
|
|
9458
|
+
}
|
|
9459
|
+
return null;
|
|
9460
|
+
}
|
|
9461
|
+
var post23 = function(param) {
|
|
9462
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9463
|
+
return function(urlString, options) {
|
|
9464
|
+
return _async_to_generator(function() {
|
|
9465
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, existingRun, assistantId, submitResponse, streamRun, readableStream, events, finalRun;
|
|
9466
|
+
return _ts_generator(this, function(_state) {
|
|
9467
|
+
switch(_state.label){
|
|
9468
|
+
case 0:
|
|
9469
|
+
url = new URL(urlString);
|
|
9470
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(submitToolOutputsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
9471
|
+
if (typeof options.body !== "string") {
|
|
9472
|
+
throw new Error("Request body is required");
|
|
9473
|
+
}
|
|
9474
|
+
body = JSON.parse(options.body);
|
|
9475
|
+
tool_outputs = body.tool_outputs, stream = body.stream;
|
|
9476
|
+
return [
|
|
9477
|
+
4,
|
|
9478
|
+
azureAiProject.agents.runs.get(threadId, runId)
|
|
9479
|
+
];
|
|
9480
|
+
case 1:
|
|
9481
|
+
existingRun = _state.sent();
|
|
9482
|
+
assistantId = existingRun.assistantId;
|
|
9483
|
+
submitResponse = azureAiProject.agents.runs.submitToolOutputs(threadId, runId, tool_outputs.map(function(to) {
|
|
9484
|
+
return {
|
|
9485
|
+
toolCallId: to.tool_call_id,
|
|
9486
|
+
output: to.output
|
|
9487
|
+
};
|
|
9488
|
+
}));
|
|
9489
|
+
streamRun = function(onEvent2) {
|
|
9490
|
+
return _async_to_generator(function() {
|
|
9491
|
+
var stream2, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, error, _error_cause, _error_message, _error_cause_message;
|
|
9492
|
+
return _ts_generator(this, function(_state) {
|
|
9493
|
+
switch(_state.label){
|
|
9494
|
+
case 0:
|
|
9495
|
+
_state.trys.push([
|
|
9496
|
+
0,
|
|
9497
|
+
15,
|
|
9498
|
+
,
|
|
9499
|
+
17
|
|
9500
|
+
]);
|
|
9501
|
+
return [
|
|
9502
|
+
4,
|
|
9503
|
+
submitResponse.stream()
|
|
9504
|
+
];
|
|
9505
|
+
case 1:
|
|
9506
|
+
stream2 = _state.sent();
|
|
9507
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9508
|
+
_state.label = 2;
|
|
9509
|
+
case 2:
|
|
9510
|
+
_state.trys.push([
|
|
9511
|
+
2,
|
|
9512
|
+
8,
|
|
9513
|
+
9,
|
|
9514
|
+
14
|
|
9515
|
+
]);
|
|
9516
|
+
_iterator = _async_iterator(stream2);
|
|
9517
|
+
_state.label = 3;
|
|
9518
|
+
case 3:
|
|
9519
|
+
return [
|
|
9520
|
+
4,
|
|
9521
|
+
_iterator.next()
|
|
9522
|
+
];
|
|
9523
|
+
case 4:
|
|
9524
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9525
|
+
3,
|
|
9526
|
+
7
|
|
9527
|
+
];
|
|
9528
|
+
_value = _step.value;
|
|
9529
|
+
azureEvent = _value;
|
|
9530
|
+
openaiEvent = convertAzureEventToOpenAI(azureEvent, assistantId);
|
|
9531
|
+
if (!openaiEvent) return [
|
|
9532
|
+
3,
|
|
9533
|
+
6
|
|
9534
|
+
];
|
|
9535
|
+
return [
|
|
9536
|
+
4,
|
|
9537
|
+
onEvent2(openaiEvent)
|
|
9538
|
+
];
|
|
9539
|
+
case 5:
|
|
9540
|
+
_state.sent();
|
|
9541
|
+
_state.label = 6;
|
|
9542
|
+
case 6:
|
|
9543
|
+
_iteratorAbruptCompletion = false;
|
|
9544
|
+
return [
|
|
9545
|
+
3,
|
|
9546
|
+
3
|
|
9547
|
+
];
|
|
9548
|
+
case 7:
|
|
9549
|
+
return [
|
|
9550
|
+
3,
|
|
9551
|
+
14
|
|
9552
|
+
];
|
|
9553
|
+
case 8:
|
|
9554
|
+
err = _state.sent();
|
|
9555
|
+
_didIteratorError = true;
|
|
9556
|
+
_iteratorError = err;
|
|
9557
|
+
return [
|
|
9558
|
+
3,
|
|
9559
|
+
14
|
|
9560
|
+
];
|
|
9561
|
+
case 9:
|
|
9562
|
+
_state.trys.push([
|
|
9563
|
+
9,
|
|
9564
|
+
,
|
|
9565
|
+
12,
|
|
9566
|
+
13
|
|
9567
|
+
]);
|
|
9568
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
9569
|
+
3,
|
|
9570
|
+
11
|
|
9571
|
+
];
|
|
9572
|
+
return [
|
|
9573
|
+
4,
|
|
9574
|
+
_iterator.return()
|
|
9575
|
+
];
|
|
9576
|
+
case 10:
|
|
9577
|
+
_state.sent();
|
|
9578
|
+
_state.label = 11;
|
|
9579
|
+
case 11:
|
|
9580
|
+
return [
|
|
9581
|
+
3,
|
|
9582
|
+
13
|
|
9583
|
+
];
|
|
9584
|
+
case 12:
|
|
9585
|
+
if (_didIteratorError) {
|
|
9586
|
+
throw _iteratorError;
|
|
9587
|
+
}
|
|
9588
|
+
return [
|
|
9589
|
+
7
|
|
9590
|
+
];
|
|
9591
|
+
case 13:
|
|
9592
|
+
return [
|
|
9593
|
+
7
|
|
9594
|
+
];
|
|
9595
|
+
case 14:
|
|
9596
|
+
return [
|
|
9597
|
+
3,
|
|
9598
|
+
17
|
|
9599
|
+
];
|
|
9600
|
+
case 15:
|
|
9601
|
+
error = _state.sent();
|
|
9602
|
+
return [
|
|
9603
|
+
4,
|
|
9604
|
+
onEvent2({
|
|
9605
|
+
event: "thread.run.failed",
|
|
9606
|
+
data: {
|
|
9607
|
+
id: runId,
|
|
9608
|
+
object: "thread.run",
|
|
9609
|
+
created_at: (0, import_dayjs27.default)().unix(),
|
|
9610
|
+
thread_id: threadId,
|
|
9611
|
+
assistant_id: assistantId,
|
|
9612
|
+
status: "failed",
|
|
9613
|
+
required_action: null,
|
|
9614
|
+
last_error: {
|
|
9615
|
+
code: "server_error",
|
|
9616
|
+
message: "".concat((_error_message = error === null || error === void 0 ? void 0 : error.message) !== null && _error_message !== void 0 ? _error_message : "", " ").concat((_error_cause_message = error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) !== null && _error_cause_message !== void 0 ? _error_cause_message : "")
|
|
9617
|
+
},
|
|
9618
|
+
expires_at: null,
|
|
9619
|
+
started_at: (0, import_dayjs27.default)().unix(),
|
|
9620
|
+
cancelled_at: null,
|
|
9621
|
+
failed_at: (0, import_dayjs27.default)().unix(),
|
|
9622
|
+
completed_at: null,
|
|
9623
|
+
incomplete_details: null,
|
|
9624
|
+
model: "",
|
|
9625
|
+
instructions: "",
|
|
9626
|
+
tools: [],
|
|
9627
|
+
metadata: {},
|
|
9628
|
+
temperature: null,
|
|
9629
|
+
top_p: null,
|
|
9630
|
+
max_prompt_tokens: null,
|
|
9631
|
+
max_completion_tokens: null,
|
|
9632
|
+
truncation_strategy: {
|
|
9633
|
+
type: "auto",
|
|
9634
|
+
last_messages: null
|
|
9635
|
+
},
|
|
9636
|
+
response_format: "auto",
|
|
9637
|
+
tool_choice: "auto",
|
|
9638
|
+
parallel_tool_calls: true,
|
|
9639
|
+
usage: null
|
|
9640
|
+
}
|
|
9641
|
+
})
|
|
9642
|
+
];
|
|
9643
|
+
case 16:
|
|
9644
|
+
_state.sent();
|
|
9645
|
+
return [
|
|
9646
|
+
3,
|
|
9647
|
+
17
|
|
9648
|
+
];
|
|
9649
|
+
case 17:
|
|
9650
|
+
return [
|
|
9651
|
+
2
|
|
9652
|
+
];
|
|
9653
|
+
}
|
|
9654
|
+
});
|
|
9655
|
+
})();
|
|
9656
|
+
};
|
|
9657
|
+
readableStream = new ReadableStream({
|
|
9658
|
+
start: function start(controller) {
|
|
9659
|
+
return _async_to_generator(function() {
|
|
9660
|
+
return _ts_generator(this, function(_state) {
|
|
9661
|
+
switch(_state.label){
|
|
9662
|
+
case 0:
|
|
9663
|
+
return [
|
|
9664
|
+
4,
|
|
9665
|
+
streamRun(function(event) {
|
|
9666
|
+
return _async_to_generator(function() {
|
|
9667
|
+
return _ts_generator(this, function(_state) {
|
|
9668
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
9669
|
+
return [
|
|
9670
|
+
2
|
|
9671
|
+
];
|
|
9672
|
+
});
|
|
9673
|
+
})();
|
|
9674
|
+
})
|
|
9675
|
+
];
|
|
9676
|
+
case 1:
|
|
9677
|
+
_state.sent();
|
|
9678
|
+
controller.close();
|
|
9679
|
+
return [
|
|
9680
|
+
2
|
|
9681
|
+
];
|
|
9682
|
+
}
|
|
9683
|
+
});
|
|
9684
|
+
})();
|
|
9685
|
+
}
|
|
9686
|
+
});
|
|
9687
|
+
if (!stream) return [
|
|
9688
|
+
3,
|
|
9689
|
+
2
|
|
9690
|
+
];
|
|
9691
|
+
return [
|
|
9692
|
+
2,
|
|
9693
|
+
new Response(readableStream, {
|
|
9694
|
+
headers: {
|
|
9695
|
+
"Content-Type": "text/event-stream"
|
|
9696
|
+
}
|
|
9697
|
+
})
|
|
9698
|
+
];
|
|
9699
|
+
case 2:
|
|
9700
|
+
events = [];
|
|
9701
|
+
finalRun = null;
|
|
9702
|
+
return [
|
|
9703
|
+
4,
|
|
9704
|
+
streamRun(function(event) {
|
|
9705
|
+
return _async_to_generator(function() {
|
|
9706
|
+
return _ts_generator(this, function(_state) {
|
|
9707
|
+
events.push(event);
|
|
9708
|
+
if (event.event === "thread.run.completed" || event.event === "thread.run.failed" || event.event === "thread.run.requires_action") {
|
|
9709
|
+
finalRun = event.data;
|
|
9710
|
+
}
|
|
9711
|
+
return [
|
|
9712
|
+
2
|
|
9713
|
+
];
|
|
9714
|
+
});
|
|
9715
|
+
})();
|
|
9716
|
+
})
|
|
9717
|
+
];
|
|
9718
|
+
case 3:
|
|
9719
|
+
_state.sent();
|
|
9720
|
+
if (!finalRun) {
|
|
9721
|
+
throw new Error("Run did not complete");
|
|
9722
|
+
}
|
|
9723
|
+
return [
|
|
9724
|
+
2,
|
|
9725
|
+
new Response(JSON.stringify(finalRun), {
|
|
9726
|
+
status: 200,
|
|
9727
|
+
headers: {
|
|
9728
|
+
"Content-Type": "application/json"
|
|
9729
|
+
}
|
|
9730
|
+
})
|
|
9731
|
+
];
|
|
9732
|
+
case 4:
|
|
9733
|
+
return [
|
|
9734
|
+
2
|
|
9735
|
+
];
|
|
9736
|
+
}
|
|
9737
|
+
});
|
|
9738
|
+
})();
|
|
9739
|
+
};
|
|
9740
|
+
};
|
|
9741
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/index.ts
|
|
9742
|
+
var submitToolOutputs3 = function(param) {
|
|
9743
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9744
|
+
return {
|
|
9745
|
+
post: post23({
|
|
9746
|
+
azureAiProject: azureAiProject,
|
|
9747
|
+
runAdapter: runAdapter
|
|
9748
|
+
})
|
|
9749
|
+
};
|
|
9750
|
+
};
|
|
9751
|
+
// src/adapters/storage/azureAgentsStorageAdapter/assistants/post.ts
|
|
9752
|
+
var post24 = function(param) {
|
|
9753
|
+
var runAdapter = param.runAdapter;
|
|
9754
|
+
return function(_urlString, options) {
|
|
9755
|
+
return _async_to_generator(function() {
|
|
9756
|
+
var body, _body_top_p, _body_temperature, openaiAssistant;
|
|
9757
|
+
return _ts_generator(this, function(_state) {
|
|
9758
|
+
if (typeof options.body !== "string") {
|
|
9759
|
+
throw new Error("Request body is required");
|
|
9760
|
+
}
|
|
9761
|
+
body = JSON.parse(options.body);
|
|
9762
|
+
openaiAssistant = {
|
|
9763
|
+
id: "placeholder",
|
|
9764
|
+
// This will be overridden by the assistant_id passed to createRun
|
|
9765
|
+
object: "assistant",
|
|
9766
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
9767
|
+
name: body.name || null,
|
|
9768
|
+
description: body.description || null,
|
|
9769
|
+
model: body.model,
|
|
9770
|
+
instructions: body.instructions || null,
|
|
9771
|
+
tools: body.tools || [],
|
|
9772
|
+
metadata: body.metadata || {},
|
|
9773
|
+
top_p: (_body_top_p = body.top_p) !== null && _body_top_p !== void 0 ? _body_top_p : null,
|
|
9774
|
+
temperature: (_body_temperature = body.temperature) !== null && _body_temperature !== void 0 ? _body_temperature : null,
|
|
9775
|
+
response_format: body.response_format || "auto"
|
|
9776
|
+
};
|
|
9777
|
+
return [
|
|
9778
|
+
2,
|
|
9779
|
+
new Response(JSON.stringify(openaiAssistant), {
|
|
9780
|
+
status: 200,
|
|
9781
|
+
headers: {
|
|
9782
|
+
"Content-Type": "application/json"
|
|
9783
|
+
}
|
|
9784
|
+
})
|
|
9785
|
+
];
|
|
9786
|
+
});
|
|
9787
|
+
})();
|
|
9788
|
+
};
|
|
9789
|
+
};
|
|
9790
|
+
// src/adapters/storage/azureAgentsStorageAdapter/assistants/index.ts
|
|
9791
|
+
var assistants3 = function(param) {
|
|
9792
|
+
var runAdapter = param.runAdapter;
|
|
9793
|
+
return {
|
|
9794
|
+
post: post24({
|
|
9795
|
+
runAdapter: runAdapter
|
|
9796
|
+
})
|
|
9797
|
+
};
|
|
9798
|
+
};
|
|
9799
|
+
// src/adapters/storage/azureAgentsStorageAdapter/index.ts
|
|
9800
|
+
var azureAgentsStorageAdapter = function(param) {
|
|
9801
|
+
var azureAiProject = param.azureAiProject;
|
|
9802
|
+
return function(param) {
|
|
9803
|
+
var runAdapter = param.runAdapter;
|
|
9804
|
+
var _obj;
|
|
9805
|
+
return {
|
|
9806
|
+
requestHandlers: (_obj = {
|
|
9807
|
+
"^/(?:v1|/?openai)/assistants$": assistants3({
|
|
9808
|
+
runAdapter: runAdapter
|
|
9809
|
+
}),
|
|
9810
|
+
"^/(?:v1|/?openai)/threads$": threads3({
|
|
9811
|
+
azureAiProject: azureAiProject
|
|
9812
|
+
})
|
|
9813
|
+
}, _define_property(_obj, messagesRegexp, messages4({
|
|
9814
|
+
azureAiProject: azureAiProject,
|
|
9815
|
+
runAdapter: runAdapter
|
|
9816
|
+
})), _define_property(_obj, runsRegexp, runs3({
|
|
9817
|
+
azureAiProject: azureAiProject,
|
|
9818
|
+
runAdapter: runAdapter
|
|
9819
|
+
})), _define_property(_obj, runRegexp, run3({
|
|
9820
|
+
azureAiProject: azureAiProject,
|
|
9821
|
+
runAdapter: runAdapter
|
|
9822
|
+
})), _define_property(_obj, stepsRegexp, steps3({
|
|
9823
|
+
azureAiProject: azureAiProject,
|
|
9824
|
+
runAdapter: runAdapter
|
|
9825
|
+
})), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs3({
|
|
9826
|
+
azureAiProject: azureAiProject,
|
|
9827
|
+
runAdapter: runAdapter
|
|
9828
|
+
})), _obj)
|
|
9829
|
+
};
|
|
9830
|
+
};
|
|
9831
|
+
};
|
|
9832
|
+
// src/adapters/run/responsesRunAdapter/index.ts
|
|
9833
|
+
var import_dayjs28 = __toESM(require("dayjs"), 1);
|
|
9834
|
+
var import_radash24 = require("radash");
|
|
9835
|
+
var serializeToolCalls2 = function(param) {
|
|
9836
|
+
var toolCalls = param.toolCalls;
|
|
9837
|
+
return toolCalls.map(function(toolCall) {
|
|
9838
|
+
if (toolCall.type === "function_call") {
|
|
9839
|
+
return {
|
|
9840
|
+
id: toolCall.call_id,
|
|
9841
|
+
type: "function",
|
|
9842
|
+
function: {
|
|
9843
|
+
name: toolCall.name,
|
|
9844
|
+
arguments: toolCall.arguments
|
|
9845
|
+
}
|
|
9846
|
+
};
|
|
9847
|
+
} else if (toolCall.type === "computer_call") {
|
|
9848
|
+
return {
|
|
9849
|
+
id: toolCall.call_id,
|
|
9850
|
+
type: "computer_call",
|
|
9851
|
+
computer_call: {
|
|
9852
|
+
action: toolCall.action,
|
|
9853
|
+
pending_safety_checks: toolCall.pending_safety_checks
|
|
9854
|
+
}
|
|
9855
|
+
};
|
|
9856
|
+
}
|
|
9857
|
+
});
|
|
9858
|
+
};
|
|
9859
|
+
var responsesRunAdapter = function(param) {
|
|
9860
|
+
var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
|
|
9861
|
+
return p.then(function() {});
|
|
9862
|
+
} : _param_waitUntil;
|
|
9863
|
+
var cachedOpenaiAssistant = null;
|
|
9864
|
+
var getOpenaiAssistant = function() {
|
|
9865
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, tmp = _ref.select, _ref1 = tmp === void 0 ? {} : tmp, _ref_id = _ref1.id, id = _ref_id === void 0 ? false : _ref_id;
|
|
9866
|
+
return _async_to_generator(function() {
|
|
9867
|
+
var args, _tmp;
|
|
9868
|
+
return _ts_generator(this, function(_state) {
|
|
9869
|
+
switch(_state.label){
|
|
9870
|
+
case 0:
|
|
9871
|
+
args = {
|
|
9872
|
+
select: {
|
|
9873
|
+
id: id
|
|
9874
|
+
}
|
|
9875
|
+
};
|
|
9876
|
+
if (!args.select.id) return [
|
|
9877
|
+
3,
|
|
9878
|
+
2
|
|
9879
|
+
];
|
|
9880
|
+
_tmp = {};
|
|
9881
|
+
return [
|
|
9882
|
+
4,
|
|
9883
|
+
getDirectOpenaiAssistant({
|
|
9884
|
+
select: {
|
|
9885
|
+
id: true
|
|
9886
|
+
}
|
|
9887
|
+
})
|
|
9888
|
+
];
|
|
9889
|
+
case 1:
|
|
9890
|
+
return [
|
|
9891
|
+
2,
|
|
9892
|
+
(_tmp.id = _state.sent().id, _tmp)
|
|
9893
|
+
];
|
|
9894
|
+
case 2:
|
|
9895
|
+
if (cachedOpenaiAssistant) return [
|
|
9896
|
+
2,
|
|
9897
|
+
cachedOpenaiAssistant
|
|
9898
|
+
];
|
|
9899
|
+
return [
|
|
9900
|
+
4,
|
|
9901
|
+
getDirectOpenaiAssistant()
|
|
9902
|
+
];
|
|
9903
|
+
case 3:
|
|
9904
|
+
cachedOpenaiAssistant = _state.sent();
|
|
9905
|
+
return [
|
|
9906
|
+
2,
|
|
9907
|
+
cachedOpenaiAssistant
|
|
9908
|
+
];
|
|
9909
|
+
}
|
|
9910
|
+
});
|
|
9911
|
+
})();
|
|
9912
|
+
};
|
|
9913
|
+
var handleRun = function(param) {
|
|
9914
|
+
var client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
|
|
9915
|
+
return _async_to_generator(function() {
|
|
9916
|
+
var responseCreatedResponse, responseCompletedResponse, toolCalls, mcpCalls, codeInterpreterCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, _tmp, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7, _tmp8, _tmp9, _tmp10, _tmp11, _tmp12, _tmp13, _tmp14, _tmp15, _tmp16, _tmp17, _tmp18, _tmp19, _tmp20, _tmp21, _tmp22, _tmp23, _tmp24, _tmp25, _tmp26, _tmp27, _tmp28, _tmp29, _tmp30, _tmp31, _tmp32, _tmp33, _tmp34, _tmp35, _tmp36, _tmp37, _tmp38, _tmp39, _tmp40, _tmp41, _tmp42, _tmp43, _tmp44, _tmp45, _tmp46, _tmp47, _tmp48, _tmp49, _tmp50, _tmp51, _tmp52, _tmp53, _tmp54, _tmp55, _tmp56, _tmp57, _tmp58, _tmp59, _tmp60, _tmp61, _tmp62, _tmp63, _tmp64, _tmp65, _tmp66, _tmp67, _tmp68, _tmp69, _tmp70, _tmp71, _tmp72, _tmp73, _tmp74, _tmp75, _tmp76, _tmp77, _tmp78, _tmp79, _tmp80, _tmp81, _tmp82, _tmp83, _tmp84, _tmp85, _tmp86, _tmp87, _tmp88, _tmp89, _tmp90, _tmp91, _tmp92, _tmp93, _tmp94, _tmp95, toolCall, mcpCall, _tmp96, _tmp97, _tmp98, _tmp99, err, _responseCompletedResponse_output, toolCalls2, serializedRun, _tmp100, e, _tmp101, _tmp102;
|
|
9917
|
+
return _ts_generator(this, function(_state) {
|
|
9918
|
+
switch(_state.label){
|
|
9919
|
+
case 0:
|
|
9920
|
+
responseCreatedResponse = null;
|
|
9921
|
+
responseCompletedResponse = null;
|
|
9922
|
+
toolCalls = {};
|
|
9923
|
+
mcpCalls = {};
|
|
9924
|
+
codeInterpreterCalls = {};
|
|
9925
|
+
itemIds = [];
|
|
9926
|
+
_state.label = 1;
|
|
9927
|
+
case 1:
|
|
9928
|
+
_state.trys.push([
|
|
9929
|
+
1,
|
|
9930
|
+
151,
|
|
9931
|
+
154,
|
|
9932
|
+
155
|
|
9933
|
+
]);
|
|
9934
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9935
|
+
_state.label = 2;
|
|
9936
|
+
case 2:
|
|
9937
|
+
_state.trys.push([
|
|
9938
|
+
2,
|
|
9939
|
+
139,
|
|
9940
|
+
140,
|
|
9941
|
+
145
|
|
9942
|
+
]);
|
|
9943
|
+
_iterator = _async_iterator(response);
|
|
9944
|
+
_state.label = 3;
|
|
9945
|
+
case 3:
|
|
9946
|
+
return [
|
|
9947
|
+
4,
|
|
9948
|
+
_iterator.next()
|
|
9949
|
+
];
|
|
9950
|
+
case 4:
|
|
9951
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9952
|
+
3,
|
|
9953
|
+
138
|
|
9954
|
+
];
|
|
9955
|
+
_value = _step.value;
|
|
9956
|
+
event = _value;
|
|
9957
|
+
_ = event.type;
|
|
9958
|
+
switch(_){
|
|
9959
|
+
case "response.created":
|
|
9960
|
+
return [
|
|
9961
|
+
3,
|
|
9962
|
+
5
|
|
9963
|
+
];
|
|
9964
|
+
case "response.in_progress":
|
|
9965
|
+
return [
|
|
9966
|
+
3,
|
|
9967
|
+
8
|
|
9968
|
+
];
|
|
9969
|
+
case "response.completed":
|
|
9970
|
+
return [
|
|
9971
|
+
3,
|
|
9972
|
+
11
|
|
9973
|
+
];
|
|
9974
|
+
case "response.failed":
|
|
9975
|
+
return [
|
|
9976
|
+
3,
|
|
9977
|
+
12
|
|
9978
|
+
];
|
|
9979
|
+
case "response.output_text.delta":
|
|
9980
|
+
return [
|
|
9981
|
+
3,
|
|
9982
|
+
15
|
|
9983
|
+
];
|
|
9984
|
+
case "response.output_item.added":
|
|
9985
|
+
return [
|
|
9986
|
+
3,
|
|
9987
|
+
17
|
|
9988
|
+
];
|
|
9989
|
+
case "response.output_item.done":
|
|
9990
|
+
return [
|
|
9991
|
+
3,
|
|
9992
|
+
75
|
|
9993
|
+
];
|
|
9994
|
+
case "response.function_call_arguments.delta":
|
|
9995
|
+
return [
|
|
9996
|
+
3,
|
|
9997
|
+
126
|
|
9998
|
+
];
|
|
9999
|
+
case "response.mcp_call_arguments.delta":
|
|
10000
|
+
return [
|
|
10001
|
+
3,
|
|
10002
|
+
128
|
|
10003
|
+
];
|
|
10004
|
+
case "response.image_generation_call.in_progress":
|
|
10005
|
+
return [
|
|
10006
|
+
3,
|
|
10007
|
+
130
|
|
10008
|
+
];
|
|
10009
|
+
case "response.image_generation_call.generating":
|
|
10010
|
+
return [
|
|
10011
|
+
3,
|
|
10012
|
+
130
|
|
10013
|
+
];
|
|
10014
|
+
case "response.image_generation_call.partial_image":
|
|
10015
|
+
return [
|
|
10016
|
+
3,
|
|
10017
|
+
133
|
|
10018
|
+
];
|
|
10019
|
+
}
|
|
10020
|
+
return [
|
|
10021
|
+
3,
|
|
10022
|
+
136
|
|
10023
|
+
];
|
|
10024
|
+
case 5:
|
|
10025
|
+
responseCreatedResponse = event.response;
|
|
10026
|
+
_tmp = {
|
|
8637
10027
|
event: "thread.run.created"
|
|
8638
10028
|
};
|
|
8639
10029
|
_tmp1 = {
|
|
@@ -8788,7 +10178,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8788
10178
|
4,
|
|
8789
10179
|
onEvent2.apply(void 0, [
|
|
8790
10180
|
(_tmp6.data = serializeItemAsMessage.apply(void 0, [
|
|
8791
|
-
(_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt = (0,
|
|
10181
|
+
(_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt = (0, import_dayjs28.default)().unix(), _tmp7.runId = responseCreatedResponse.id, _tmp7.status = "in_progress", _tmp7)
|
|
8792
10182
|
]), _tmp6)
|
|
8793
10183
|
])
|
|
8794
10184
|
];
|
|
@@ -8885,7 +10275,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8885
10275
|
4,
|
|
8886
10276
|
onEvent2.apply(void 0, [
|
|
8887
10277
|
(_tmp12.data = serializeItemAsMessage.apply(void 0, [
|
|
8888
|
-
(_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt = (0,
|
|
10278
|
+
(_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt = (0, import_dayjs28.default)().unix(), _tmp13.runId = responseCreatedResponse.id, _tmp13.status = "in_progress", _tmp13)
|
|
8889
10279
|
]), _tmp12)
|
|
8890
10280
|
])
|
|
8891
10281
|
];
|
|
@@ -8972,7 +10362,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8972
10362
|
4,
|
|
8973
10363
|
onEvent2.apply(void 0, [
|
|
8974
10364
|
(_tmp18.data = serializeItemAsMessage.apply(void 0, [
|
|
8975
|
-
(_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt = (0,
|
|
10365
|
+
(_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt = (0, import_dayjs28.default)().unix(), _tmp19.runId = responseCreatedResponse.id, _tmp19.status = "in_progress", _tmp19)
|
|
8976
10366
|
]), _tmp18)
|
|
8977
10367
|
])
|
|
8978
10368
|
];
|
|
@@ -9058,7 +10448,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9058
10448
|
4,
|
|
9059
10449
|
onEvent2.apply(void 0, [
|
|
9060
10450
|
(_tmp24.data = serializeItemAsMessage.apply(void 0, [
|
|
9061
|
-
(_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt = (0,
|
|
10451
|
+
(_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt = (0, import_dayjs28.default)().unix(), _tmp25.runId = responseCreatedResponse.id, _tmp25.status = "in_progress", _tmp25)
|
|
9062
10452
|
]), _tmp24)
|
|
9063
10453
|
])
|
|
9064
10454
|
];
|
|
@@ -9144,7 +10534,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9144
10534
|
4,
|
|
9145
10535
|
onEvent2.apply(void 0, [
|
|
9146
10536
|
(_tmp30.data = serializeItemAsMessage.apply(void 0, [
|
|
9147
|
-
(_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt = (0,
|
|
10537
|
+
(_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt = (0, import_dayjs28.default)().unix(), _tmp31.runId = responseCreatedResponse.id, _tmp31.status = "in_progress", _tmp31)
|
|
9148
10538
|
]), _tmp30)
|
|
9149
10539
|
])
|
|
9150
10540
|
];
|
|
@@ -9230,7 +10620,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9230
10620
|
4,
|
|
9231
10621
|
onEvent2.apply(void 0, [
|
|
9232
10622
|
(_tmp36.data = serializeItemAsMessage.apply(void 0, [
|
|
9233
|
-
(_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt = (0,
|
|
10623
|
+
(_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt = (0, import_dayjs28.default)().unix(), _tmp37.runId = responseCreatedResponse.id, _tmp37.status = "in_progress", _tmp37)
|
|
9234
10624
|
]), _tmp36)
|
|
9235
10625
|
])
|
|
9236
10626
|
];
|
|
@@ -9317,7 +10707,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9317
10707
|
4,
|
|
9318
10708
|
onEvent2.apply(void 0, [
|
|
9319
10709
|
(_tmp42.data = serializeItemAsMessage.apply(void 0, [
|
|
9320
|
-
(_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt = (0,
|
|
10710
|
+
(_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt = (0, import_dayjs28.default)().unix(), _tmp43.runId = responseCreatedResponse.id, _tmp43.status = "in_progress", _tmp43)
|
|
9321
10711
|
]), _tmp42)
|
|
9322
10712
|
])
|
|
9323
10713
|
];
|
|
@@ -9404,7 +10794,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9404
10794
|
4,
|
|
9405
10795
|
onEvent2.apply(void 0, [
|
|
9406
10796
|
(_tmp48.data = serializeItemAsMessage.apply(void 0, [
|
|
9407
|
-
(_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt = (0,
|
|
10797
|
+
(_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt = (0, import_dayjs28.default)().unix(), _tmp49.runId = responseCreatedResponse.id, _tmp49.status = "in_progress", _tmp49)
|
|
9408
10798
|
]), _tmp48)
|
|
9409
10799
|
])
|
|
9410
10800
|
];
|
|
@@ -9519,7 +10909,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9519
10909
|
4,
|
|
9520
10910
|
onEvent2.apply(void 0, [
|
|
9521
10911
|
(_tmp56.data = serializeItemAsMessage.apply(void 0, [
|
|
9522
|
-
(_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt = (0,
|
|
10912
|
+
(_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt = (0, import_dayjs28.default)().unix(), _tmp57.runId = responseCreatedResponse.id, _tmp57)
|
|
9523
10913
|
]), _tmp56)
|
|
9524
10914
|
])
|
|
9525
10915
|
];
|
|
@@ -9641,7 +11031,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9641
11031
|
4,
|
|
9642
11032
|
onEvent2.apply(void 0, [
|
|
9643
11033
|
(_tmp64.data = serializeItemAsMessage.apply(void 0, [
|
|
9644
|
-
(_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt = (0,
|
|
11034
|
+
(_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt = (0, import_dayjs28.default)().unix(), _tmp65.runId = responseCreatedResponse.id, _tmp65)
|
|
9645
11035
|
]), _tmp64)
|
|
9646
11036
|
])
|
|
9647
11037
|
];
|
|
@@ -9727,7 +11117,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9727
11117
|
4,
|
|
9728
11118
|
onEvent2.apply(void 0, [
|
|
9729
11119
|
(_tmp70.data = serializeItemAsMessage.apply(void 0, [
|
|
9730
|
-
(_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt = (0,
|
|
11120
|
+
(_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt = (0, import_dayjs28.default)().unix(), _tmp71.runId = responseCreatedResponse.id, _tmp71)
|
|
9731
11121
|
]), _tmp70)
|
|
9732
11122
|
])
|
|
9733
11123
|
];
|
|
@@ -9813,7 +11203,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9813
11203
|
4,
|
|
9814
11204
|
onEvent2.apply(void 0, [
|
|
9815
11205
|
(_tmp76.data = serializeItemAsMessage.apply(void 0, [
|
|
9816
|
-
(_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt = (0,
|
|
11206
|
+
(_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt = (0, import_dayjs28.default)().unix(), _tmp77.runId = responseCreatedResponse.id, _tmp77)
|
|
9817
11207
|
]), _tmp76)
|
|
9818
11208
|
])
|
|
9819
11209
|
];
|
|
@@ -9899,7 +11289,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9899
11289
|
4,
|
|
9900
11290
|
onEvent2.apply(void 0, [
|
|
9901
11291
|
(_tmp82.data = serializeItemAsMessage.apply(void 0, [
|
|
9902
|
-
(_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt = (0,
|
|
11292
|
+
(_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt = (0, import_dayjs28.default)().unix(), _tmp83.runId = responseCreatedResponse.id, _tmp83)
|
|
9903
11293
|
]), _tmp82)
|
|
9904
11294
|
])
|
|
9905
11295
|
];
|
|
@@ -9985,7 +11375,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9985
11375
|
4,
|
|
9986
11376
|
onEvent2.apply(void 0, [
|
|
9987
11377
|
(_tmp88.data = serializeItemAsMessage.apply(void 0, [
|
|
9988
|
-
(_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt = (0,
|
|
11378
|
+
(_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt = (0, import_dayjs28.default)().unix(), _tmp89.runId = responseCreatedResponse.id, _tmp89)
|
|
9989
11379
|
]), _tmp88)
|
|
9990
11380
|
])
|
|
9991
11381
|
];
|
|
@@ -10071,7 +11461,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10071
11461
|
4,
|
|
10072
11462
|
onEvent2.apply(void 0, [
|
|
10073
11463
|
(_tmp94.data = serializeItemAsMessage.apply(void 0, [
|
|
10074
|
-
(_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt = (0,
|
|
11464
|
+
(_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt = (0, import_dayjs28.default)().unix(), _tmp95.runId = responseCreatedResponse.id, _tmp95)
|
|
10075
11465
|
]), _tmp94)
|
|
10076
11466
|
])
|
|
10077
11467
|
];
|
|
@@ -10168,7 +11558,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10168
11558
|
_tmp97 = {
|
|
10169
11559
|
id: event.item_id,
|
|
10170
11560
|
object: "thread.message",
|
|
10171
|
-
created_at: (0,
|
|
11561
|
+
created_at: (0, import_dayjs28.default)().unix(),
|
|
10172
11562
|
thread_id: threadId,
|
|
10173
11563
|
completed_at: null,
|
|
10174
11564
|
incomplete_at: null,
|
|
@@ -10206,7 +11596,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10206
11596
|
_tmp99 = {
|
|
10207
11597
|
id: event.item_id,
|
|
10208
11598
|
object: "thread.message",
|
|
10209
|
-
created_at: (0,
|
|
11599
|
+
created_at: (0, import_dayjs28.default)().unix(),
|
|
10210
11600
|
thread_id: threadId,
|
|
10211
11601
|
completed_at: null,
|
|
10212
11602
|
incomplete_at: null,
|
|
@@ -10378,7 +11768,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10378
11768
|
event: "thread.run.failed"
|
|
10379
11769
|
};
|
|
10380
11770
|
_tmp102 = {
|
|
10381
|
-
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0,
|
|
11771
|
+
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash24.uid)(18)),
|
|
10382
11772
|
object: "thread.run",
|
|
10383
11773
|
thread_id: threadId
|
|
10384
11774
|
};
|
|
@@ -10394,7 +11784,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10394
11784
|
return [
|
|
10395
11785
|
4,
|
|
10396
11786
|
onEvent2.apply(void 0, [
|
|
10397
|
-
(_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at = (0,
|
|
11787
|
+
(_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at = (0, import_dayjs28.default)().unix(), _tmp102.last_error = {
|
|
10398
11788
|
code: "server_error",
|
|
10399
11789
|
message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
|
|
10400
11790
|
}, _tmp102), _tmp101)
|
|
@@ -10453,9 +11843,370 @@ var responsesRunAdapter = function(param) {
|
|
|
10453
11843
|
getOpenaiAssistant: getOpenaiAssistant
|
|
10454
11844
|
};
|
|
10455
11845
|
};
|
|
11846
|
+
// src/adapters/run/azureAgentsRunAdapter/index.ts
|
|
11847
|
+
var import_dayjs29 = __toESM(require("dayjs"), 1);
|
|
11848
|
+
var import_radash25 = require("radash");
|
|
11849
|
+
function convertAzureEventToOpenAI2(azureEvent, assistantId) {
|
|
11850
|
+
var event = azureEvent.event, data = azureEvent.data;
|
|
11851
|
+
var eventType = event;
|
|
11852
|
+
if (eventType.startsWith("thread.run.")) {
|
|
11853
|
+
var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
|
|
11854
|
+
var _data_temperature, _data_topP;
|
|
11855
|
+
return {
|
|
11856
|
+
event: eventType,
|
|
11857
|
+
data: {
|
|
11858
|
+
id: data.id,
|
|
11859
|
+
object: "thread.run",
|
|
11860
|
+
created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
|
|
11861
|
+
thread_id: data.threadId,
|
|
11862
|
+
assistant_id: assistantId,
|
|
11863
|
+
status: data.status,
|
|
11864
|
+
required_action: data.requiredAction ? {
|
|
11865
|
+
type: "submit_tool_outputs",
|
|
11866
|
+
submit_tool_outputs: {
|
|
11867
|
+
tool_calls: ((_data_requiredAction_submitToolOutputs = data.requiredAction.submitToolOutputs) === null || _data_requiredAction_submitToolOutputs === void 0 ? void 0 : (_data_requiredAction_submitToolOutputs_toolCalls = _data_requiredAction_submitToolOutputs.toolCalls) === null || _data_requiredAction_submitToolOutputs_toolCalls === void 0 ? void 0 : _data_requiredAction_submitToolOutputs_toolCalls.map(function(tc) {
|
|
11868
|
+
return {
|
|
11869
|
+
id: tc.id,
|
|
11870
|
+
type: "function",
|
|
11871
|
+
function: {
|
|
11872
|
+
name: tc.function.name,
|
|
11873
|
+
arguments: tc.function.arguments
|
|
11874
|
+
}
|
|
11875
|
+
};
|
|
11876
|
+
})) || []
|
|
11877
|
+
}
|
|
11878
|
+
} : null,
|
|
11879
|
+
last_error: data.lastError ? {
|
|
11880
|
+
code: "server_error",
|
|
11881
|
+
message: JSON.stringify(data.lastError)
|
|
11882
|
+
} : null,
|
|
11883
|
+
expires_at: null,
|
|
11884
|
+
started_at: data.startedAt ? (0, import_dayjs29.default)(data.startedAt).unix() : null,
|
|
11885
|
+
cancelled_at: data.cancelledAt ? (0, import_dayjs29.default)(data.cancelledAt).unix() : null,
|
|
11886
|
+
failed_at: data.failedAt ? (0, import_dayjs29.default)(data.failedAt).unix() : null,
|
|
11887
|
+
completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
|
|
11888
|
+
incomplete_details: null,
|
|
11889
|
+
model: data.model || "",
|
|
11890
|
+
instructions: data.instructions || "",
|
|
11891
|
+
tools: data.tools || [],
|
|
11892
|
+
metadata: data.metadata || {},
|
|
11893
|
+
temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
|
|
11894
|
+
top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
|
|
11895
|
+
max_prompt_tokens: null,
|
|
11896
|
+
max_completion_tokens: null,
|
|
11897
|
+
truncation_strategy: {
|
|
11898
|
+
type: "auto",
|
|
11899
|
+
last_messages: null
|
|
11900
|
+
},
|
|
11901
|
+
response_format: "auto",
|
|
11902
|
+
tool_choice: "auto",
|
|
11903
|
+
parallel_tool_calls: true,
|
|
11904
|
+
usage: null
|
|
11905
|
+
}
|
|
11906
|
+
};
|
|
11907
|
+
}
|
|
11908
|
+
if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
|
|
11909
|
+
var _data_content;
|
|
11910
|
+
return {
|
|
11911
|
+
event: eventType,
|
|
11912
|
+
data: {
|
|
11913
|
+
id: data.id,
|
|
11914
|
+
object: "thread.message",
|
|
11915
|
+
created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
|
|
11916
|
+
thread_id: data.threadId,
|
|
11917
|
+
role: data.role,
|
|
11918
|
+
content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
|
|
11919
|
+
if (c.type === "text") {
|
|
11920
|
+
var _c_text, _c_text1;
|
|
11921
|
+
return {
|
|
11922
|
+
type: "text",
|
|
11923
|
+
text: {
|
|
11924
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
11925
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
11926
|
+
}
|
|
11927
|
+
};
|
|
11928
|
+
}
|
|
11929
|
+
return c;
|
|
11930
|
+
})) || [],
|
|
11931
|
+
assistant_id: assistantId,
|
|
11932
|
+
run_id: data.runId || null,
|
|
11933
|
+
attachments: data.attachments || [],
|
|
11934
|
+
metadata: data.metadata || {},
|
|
11935
|
+
status: data.status || "completed",
|
|
11936
|
+
completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
|
|
11937
|
+
incomplete_at: null,
|
|
11938
|
+
incomplete_details: null
|
|
11939
|
+
}
|
|
11940
|
+
};
|
|
11941
|
+
}
|
|
11942
|
+
if (eventType === "thread.message.delta") {
|
|
11943
|
+
var _data_delta_content, _data_delta;
|
|
11944
|
+
return {
|
|
11945
|
+
event: "thread.message.delta",
|
|
11946
|
+
data: {
|
|
11947
|
+
id: data.id,
|
|
11948
|
+
object: "thread.message.delta",
|
|
11949
|
+
delta: {
|
|
11950
|
+
content: ((_data_delta = data.delta) === null || _data_delta === void 0 ? void 0 : (_data_delta_content = _data_delta.content) === null || _data_delta_content === void 0 ? void 0 : _data_delta_content.map(function(c) {
|
|
11951
|
+
if (c.type === "text") {
|
|
11952
|
+
var _c_text, _c_text1;
|
|
11953
|
+
return {
|
|
11954
|
+
index: c.index || 0,
|
|
11955
|
+
type: "text",
|
|
11956
|
+
text: {
|
|
11957
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
11958
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
11959
|
+
}
|
|
11960
|
+
};
|
|
11961
|
+
}
|
|
11962
|
+
return c;
|
|
11963
|
+
})) || []
|
|
11964
|
+
}
|
|
11965
|
+
}
|
|
11966
|
+
};
|
|
11967
|
+
}
|
|
11968
|
+
if (eventType.startsWith("thread.run.step.")) {
|
|
11969
|
+
return {
|
|
11970
|
+
event: eventType,
|
|
11971
|
+
data: {
|
|
11972
|
+
id: data.id,
|
|
11973
|
+
object: "thread.run.step",
|
|
11974
|
+
created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
|
|
11975
|
+
assistant_id: assistantId,
|
|
11976
|
+
thread_id: data.threadId,
|
|
11977
|
+
run_id: data.runId,
|
|
11978
|
+
type: data.type,
|
|
11979
|
+
status: data.status,
|
|
11980
|
+
step_details: data.stepDetails || {},
|
|
11981
|
+
last_error: data.lastError || null,
|
|
11982
|
+
expired_at: null,
|
|
11983
|
+
cancelled_at: data.cancelledAt ? (0, import_dayjs29.default)(data.cancelledAt).unix() : null,
|
|
11984
|
+
failed_at: data.failedAt ? (0, import_dayjs29.default)(data.failedAt).unix() : null,
|
|
11985
|
+
completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
|
|
11986
|
+
metadata: data.metadata || {},
|
|
11987
|
+
usage: null
|
|
11988
|
+
}
|
|
11989
|
+
};
|
|
11990
|
+
}
|
|
11991
|
+
if (eventType === "thread.created") {
|
|
11992
|
+
return {
|
|
11993
|
+
event: "thread.created",
|
|
11994
|
+
data: {
|
|
11995
|
+
id: data.id,
|
|
11996
|
+
object: "thread",
|
|
11997
|
+
created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
|
|
11998
|
+
metadata: data.metadata || {},
|
|
11999
|
+
tool_resources: data.toolResources || null
|
|
12000
|
+
}
|
|
12001
|
+
};
|
|
12002
|
+
}
|
|
12003
|
+
return null;
|
|
12004
|
+
}
|
|
12005
|
+
var azureAgentsRunAdapter = function(param) {
|
|
12006
|
+
var azureAiProject = param.azureAiProject;
|
|
12007
|
+
var getOpenaiAssistant = function(param) {
|
|
12008
|
+
var assistantId = param.assistantId;
|
|
12009
|
+
return _async_to_generator(function() {
|
|
12010
|
+
return _ts_generator(this, function(_state) {
|
|
12011
|
+
return [
|
|
12012
|
+
2,
|
|
12013
|
+
{
|
|
12014
|
+
id: assistantId
|
|
12015
|
+
}
|
|
12016
|
+
];
|
|
12017
|
+
});
|
|
12018
|
+
})();
|
|
12019
|
+
};
|
|
12020
|
+
var handleRun = function(param) {
|
|
12021
|
+
var threadId = param.threadId, assistantId = param.assistantId, instructions = param.instructions, tools = param.tools, onEvent2 = param.onEvent;
|
|
12022
|
+
return _async_to_generator(function() {
|
|
12023
|
+
var azureAgentId, createOptions, runResponse, stream, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, e, errorRunId;
|
|
12024
|
+
return _ts_generator(this, function(_state) {
|
|
12025
|
+
switch(_state.label){
|
|
12026
|
+
case 0:
|
|
12027
|
+
_state.trys.push([
|
|
12028
|
+
0,
|
|
12029
|
+
15,
|
|
12030
|
+
,
|
|
12031
|
+
17
|
|
12032
|
+
]);
|
|
12033
|
+
azureAgentId = assistantId;
|
|
12034
|
+
createOptions = {};
|
|
12035
|
+
if (instructions) {
|
|
12036
|
+
createOptions.instructions = instructions;
|
|
12037
|
+
}
|
|
12038
|
+
if (tools) {
|
|
12039
|
+
createOptions.tools = tools;
|
|
12040
|
+
}
|
|
12041
|
+
runResponse = azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions);
|
|
12042
|
+
return [
|
|
12043
|
+
4,
|
|
12044
|
+
runResponse.stream()
|
|
12045
|
+
];
|
|
12046
|
+
case 1:
|
|
12047
|
+
stream = _state.sent();
|
|
12048
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
12049
|
+
_state.label = 2;
|
|
12050
|
+
case 2:
|
|
12051
|
+
_state.trys.push([
|
|
12052
|
+
2,
|
|
12053
|
+
8,
|
|
12054
|
+
9,
|
|
12055
|
+
14
|
|
12056
|
+
]);
|
|
12057
|
+
_iterator = _async_iterator(stream);
|
|
12058
|
+
_state.label = 3;
|
|
12059
|
+
case 3:
|
|
12060
|
+
return [
|
|
12061
|
+
4,
|
|
12062
|
+
_iterator.next()
|
|
12063
|
+
];
|
|
12064
|
+
case 4:
|
|
12065
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
12066
|
+
3,
|
|
12067
|
+
7
|
|
12068
|
+
];
|
|
12069
|
+
_value = _step.value;
|
|
12070
|
+
azureEvent = _value;
|
|
12071
|
+
openaiEvent = convertAzureEventToOpenAI2(azureEvent, assistantId);
|
|
12072
|
+
if (!openaiEvent) return [
|
|
12073
|
+
3,
|
|
12074
|
+
6
|
|
12075
|
+
];
|
|
12076
|
+
return [
|
|
12077
|
+
4,
|
|
12078
|
+
onEvent2(openaiEvent)
|
|
12079
|
+
];
|
|
12080
|
+
case 5:
|
|
12081
|
+
_state.sent();
|
|
12082
|
+
_state.label = 6;
|
|
12083
|
+
case 6:
|
|
12084
|
+
_iteratorAbruptCompletion = false;
|
|
12085
|
+
return [
|
|
12086
|
+
3,
|
|
12087
|
+
3
|
|
12088
|
+
];
|
|
12089
|
+
case 7:
|
|
12090
|
+
return [
|
|
12091
|
+
3,
|
|
12092
|
+
14
|
|
12093
|
+
];
|
|
12094
|
+
case 8:
|
|
12095
|
+
err = _state.sent();
|
|
12096
|
+
_didIteratorError = true;
|
|
12097
|
+
_iteratorError = err;
|
|
12098
|
+
return [
|
|
12099
|
+
3,
|
|
12100
|
+
14
|
|
12101
|
+
];
|
|
12102
|
+
case 9:
|
|
12103
|
+
_state.trys.push([
|
|
12104
|
+
9,
|
|
12105
|
+
,
|
|
12106
|
+
12,
|
|
12107
|
+
13
|
|
12108
|
+
]);
|
|
12109
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
12110
|
+
3,
|
|
12111
|
+
11
|
|
12112
|
+
];
|
|
12113
|
+
return [
|
|
12114
|
+
4,
|
|
12115
|
+
_iterator.return()
|
|
12116
|
+
];
|
|
12117
|
+
case 10:
|
|
12118
|
+
_state.sent();
|
|
12119
|
+
_state.label = 11;
|
|
12120
|
+
case 11:
|
|
12121
|
+
return [
|
|
12122
|
+
3,
|
|
12123
|
+
13
|
|
12124
|
+
];
|
|
12125
|
+
case 12:
|
|
12126
|
+
if (_didIteratorError) {
|
|
12127
|
+
throw _iteratorError;
|
|
12128
|
+
}
|
|
12129
|
+
return [
|
|
12130
|
+
7
|
|
12131
|
+
];
|
|
12132
|
+
case 13:
|
|
12133
|
+
return [
|
|
12134
|
+
7
|
|
12135
|
+
];
|
|
12136
|
+
case 14:
|
|
12137
|
+
return [
|
|
12138
|
+
3,
|
|
12139
|
+
17
|
|
12140
|
+
];
|
|
12141
|
+
case 15:
|
|
12142
|
+
e = _state.sent();
|
|
12143
|
+
errorRunId = "run_".concat((0, import_radash25.uid)(18));
|
|
12144
|
+
return [
|
|
12145
|
+
4,
|
|
12146
|
+
onEvent2({
|
|
12147
|
+
event: "thread.run.failed",
|
|
12148
|
+
data: {
|
|
12149
|
+
id: errorRunId,
|
|
12150
|
+
object: "thread.run",
|
|
12151
|
+
created_at: (0, import_dayjs29.default)().unix(),
|
|
12152
|
+
thread_id: threadId,
|
|
12153
|
+
assistant_id: assistantId,
|
|
12154
|
+
status: "failed",
|
|
12155
|
+
required_action: null,
|
|
12156
|
+
last_error: {
|
|
12157
|
+
code: "server_error",
|
|
12158
|
+
message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
|
|
12159
|
+
},
|
|
12160
|
+
expires_at: null,
|
|
12161
|
+
started_at: (0, import_dayjs29.default)().unix(),
|
|
12162
|
+
cancelled_at: null,
|
|
12163
|
+
failed_at: (0, import_dayjs29.default)().unix(),
|
|
12164
|
+
completed_at: null,
|
|
12165
|
+
incomplete_details: null,
|
|
12166
|
+
model: "",
|
|
12167
|
+
instructions: "",
|
|
12168
|
+
tools: [],
|
|
12169
|
+
metadata: {},
|
|
12170
|
+
temperature: null,
|
|
12171
|
+
top_p: null,
|
|
12172
|
+
max_prompt_tokens: null,
|
|
12173
|
+
max_completion_tokens: null,
|
|
12174
|
+
truncation_strategy: {
|
|
12175
|
+
type: "auto",
|
|
12176
|
+
last_messages: null
|
|
12177
|
+
},
|
|
12178
|
+
response_format: "auto",
|
|
12179
|
+
tool_choice: "auto",
|
|
12180
|
+
parallel_tool_calls: true,
|
|
12181
|
+
usage: null
|
|
12182
|
+
}
|
|
12183
|
+
})
|
|
12184
|
+
];
|
|
12185
|
+
case 16:
|
|
12186
|
+
_state.sent();
|
|
12187
|
+
return [
|
|
12188
|
+
3,
|
|
12189
|
+
17
|
|
12190
|
+
];
|
|
12191
|
+
case 17:
|
|
12192
|
+
return [
|
|
12193
|
+
2
|
|
12194
|
+
];
|
|
12195
|
+
}
|
|
12196
|
+
});
|
|
12197
|
+
})();
|
|
12198
|
+
};
|
|
12199
|
+
return {
|
|
12200
|
+
handleRun: handleRun,
|
|
12201
|
+
getOpenaiAssistant: getOpenaiAssistant
|
|
12202
|
+
};
|
|
12203
|
+
};
|
|
10456
12204
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10457
12205
|
0 && (module.exports = {
|
|
10458
12206
|
anthropicClientAdapter: anthropicClientAdapter,
|
|
12207
|
+
azureAgentsRunAdapter: azureAgentsRunAdapter,
|
|
12208
|
+
azureAgentsStorageAdapter: azureAgentsStorageAdapter,
|
|
12209
|
+
azureAiProjectClientAdapter: azureAiProjectClientAdapter,
|
|
10459
12210
|
azureOpenaiClientAdapter: azureOpenaiClientAdapter,
|
|
10460
12211
|
completionsRunAdapter: completionsRunAdapter,
|
|
10461
12212
|
googleClientAdapter: googleClientAdapter,
|