supercompat 3.10.3 → 3.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2244 -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 +2236 -311
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -802,11 +802,11 @@ var isOModel = function(param) {
|
|
|
802
802
|
};
|
|
803
803
|
// src/lib/messages/systemDeveloperMessages.ts
|
|
804
804
|
var systemDeveloperMessages = function(param) {
|
|
805
|
-
var
|
|
805
|
+
var messages5 = param.messages, model = param.model;
|
|
806
806
|
if (isOModel({
|
|
807
807
|
model: model
|
|
808
808
|
})) {
|
|
809
|
-
return
|
|
809
|
+
return messages5.map(function(message) {
|
|
810
810
|
if (message.role === "system") {
|
|
811
811
|
return _object_spread_props(_object_spread({}, message), {
|
|
812
812
|
// TODO: This should be 'developer' but we're using 'user' for now
|
|
@@ -817,7 +817,7 @@ var systemDeveloperMessages = function(param) {
|
|
|
817
817
|
return message;
|
|
818
818
|
});
|
|
819
819
|
}
|
|
820
|
-
return
|
|
820
|
+
return messages5;
|
|
821
821
|
};
|
|
822
822
|
// src/adapters/client/openaiClientAdapter/completions/post.ts
|
|
823
823
|
var omitKeys = function(param) {
|
|
@@ -835,17 +835,17 @@ var post2 = function(param) {
|
|
|
835
835
|
var openai = param.openai;
|
|
836
836
|
return function(_url, options) {
|
|
837
837
|
return _async_to_generator(function() {
|
|
838
|
-
var body,
|
|
838
|
+
var body, messages5, resultOptions, response, stream, data, error;
|
|
839
839
|
return _ts_generator(this, function(_state) {
|
|
840
840
|
switch(_state.label){
|
|
841
841
|
case 0:
|
|
842
842
|
body = JSON.parse(options.body);
|
|
843
|
-
|
|
843
|
+
messages5 = body.messages;
|
|
844
844
|
resultOptions = _object_spread_props(_object_spread({}, omit(body, omitKeys({
|
|
845
845
|
model: body.model
|
|
846
846
|
}))), {
|
|
847
847
|
messages: systemDeveloperMessages({
|
|
848
|
-
messages:
|
|
848
|
+
messages: messages5,
|
|
849
849
|
model: body.model
|
|
850
850
|
})
|
|
851
851
|
});
|
|
@@ -1045,6 +1045,15 @@ var azureOpenaiClientAdapter = function(param) {
|
|
|
1045
1045
|
}
|
|
1046
1046
|
};
|
|
1047
1047
|
};
|
|
1048
|
+
// src/adapters/client/azureAiProjectClientAdapter/index.ts
|
|
1049
|
+
var azureAiProjectClientAdapter = function(param) {
|
|
1050
|
+
var azureAiProject = param.azureAiProject;
|
|
1051
|
+
return {
|
|
1052
|
+
type: "AZURE_AI_PROJECT",
|
|
1053
|
+
client: azureAiProject,
|
|
1054
|
+
requestHandlers: {}
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1048
1057
|
// src/adapters/client/mistralClientAdapter/models/get.ts
|
|
1049
1058
|
var get3 = function(param) {
|
|
1050
1059
|
var mistral = param.mistral;
|
|
@@ -1429,11 +1438,11 @@ var agentSideRoles = [
|
|
|
1429
1438
|
"system"
|
|
1430
1439
|
];
|
|
1431
1440
|
var alternatingMessages = function(param) {
|
|
1432
|
-
var
|
|
1441
|
+
var messages5 = param.messages;
|
|
1433
1442
|
var result = [];
|
|
1434
|
-
|
|
1443
|
+
messages5.forEach(function(message, index) {
|
|
1435
1444
|
result.push(message);
|
|
1436
|
-
var nextMessage =
|
|
1445
|
+
var nextMessage = messages5[index + 1];
|
|
1437
1446
|
if (!nextMessage) return;
|
|
1438
1447
|
if (message.role === "user" && nextMessage.role === "user") {
|
|
1439
1448
|
result.push({
|
|
@@ -1454,12 +1463,12 @@ var post4 = function(param) {
|
|
|
1454
1463
|
var perplexity = param.perplexity;
|
|
1455
1464
|
return function(_url, options) {
|
|
1456
1465
|
return _async_to_generator(function() {
|
|
1457
|
-
var body,
|
|
1466
|
+
var body, messages5, response, stream, data, error;
|
|
1458
1467
|
return _ts_generator(this, function(_state) {
|
|
1459
1468
|
switch(_state.label){
|
|
1460
1469
|
case 0:
|
|
1461
1470
|
body = JSON.parse(options.body);
|
|
1462
|
-
|
|
1471
|
+
messages5 = alternatingMessages({
|
|
1463
1472
|
messages: body.messages
|
|
1464
1473
|
});
|
|
1465
1474
|
if (!body.stream) return [
|
|
@@ -1469,7 +1478,7 @@ var post4 = function(param) {
|
|
|
1469
1478
|
return [
|
|
1470
1479
|
4,
|
|
1471
1480
|
perplexity.chat.completions.create(_object_spread_props(_object_spread({}, body), {
|
|
1472
|
-
messages:
|
|
1481
|
+
messages: messages5
|
|
1473
1482
|
}))
|
|
1474
1483
|
];
|
|
1475
1484
|
case 1:
|
|
@@ -1732,9 +1741,9 @@ var nonEmptyContent = function(param) {
|
|
|
1732
1741
|
return message.content;
|
|
1733
1742
|
};
|
|
1734
1743
|
var nonEmptyMessages = function(param) {
|
|
1735
|
-
var
|
|
1744
|
+
var messages5 = param.messages;
|
|
1736
1745
|
var result = [];
|
|
1737
|
-
|
|
1746
|
+
messages5.forEach(function(message) {
|
|
1738
1747
|
return result.push(_object_spread_props(_object_spread({}, message), {
|
|
1739
1748
|
content: nonEmptyContent({
|
|
1740
1749
|
message: message
|
|
@@ -1745,18 +1754,18 @@ var nonEmptyMessages = function(param) {
|
|
|
1745
1754
|
};
|
|
1746
1755
|
// src/lib/messages/firstUserMessages.ts
|
|
1747
1756
|
var firstUserMessages = function(param) {
|
|
1748
|
-
var
|
|
1749
|
-
var firstMessage =
|
|
1750
|
-
if (!firstMessage) return
|
|
1757
|
+
var messages5 = param.messages;
|
|
1758
|
+
var firstMessage = messages5[0];
|
|
1759
|
+
if (!firstMessage) return messages5;
|
|
1751
1760
|
if (firstMessage.role !== "user") {
|
|
1752
1761
|
return [
|
|
1753
1762
|
{
|
|
1754
1763
|
role: "user",
|
|
1755
1764
|
content: "-"
|
|
1756
1765
|
}
|
|
1757
|
-
].concat(_to_consumable_array(
|
|
1766
|
+
].concat(_to_consumable_array(messages5));
|
|
1758
1767
|
}
|
|
1759
|
-
return
|
|
1768
|
+
return messages5;
|
|
1760
1769
|
};
|
|
1761
1770
|
// src/adapters/client/anthropicClientAdapter/completions/serializeTools.ts
|
|
1762
1771
|
var serializeTools = function(param) {
|
|
@@ -1830,8 +1839,8 @@ var serializeMessage2 = function(param) {
|
|
|
1830
1839
|
};
|
|
1831
1840
|
// src/adapters/client/anthropicClientAdapter/completions/serializeMessages/index.ts
|
|
1832
1841
|
var serializeMessages = function(param) {
|
|
1833
|
-
var
|
|
1834
|
-
return
|
|
1842
|
+
var messages5 = param.messages;
|
|
1843
|
+
return messages5.map(function(message) {
|
|
1835
1844
|
return serializeMessage2({
|
|
1836
1845
|
message: message
|
|
1837
1846
|
});
|
|
@@ -2309,13 +2318,13 @@ var post5 = function(param) {
|
|
|
2309
2318
|
var anthropic = param.anthropic;
|
|
2310
2319
|
return function(_url, options) {
|
|
2311
2320
|
return _async_to_generator(function() {
|
|
2312
|
-
var body,
|
|
2321
|
+
var body, messages5, _fork, systemMessages, otherMessages, system, chatMessages, resultOptions, response, stream, data, normalizedContent, normalizedData, error;
|
|
2313
2322
|
return _ts_generator(this, function(_state) {
|
|
2314
2323
|
switch(_state.label){
|
|
2315
2324
|
case 0:
|
|
2316
2325
|
body = JSON.parse(options.body);
|
|
2317
|
-
|
|
2318
|
-
_fork = _sliced_to_array(fork(
|
|
2326
|
+
messages5 = body.messages;
|
|
2327
|
+
_fork = _sliced_to_array(fork(messages5, function(message) {
|
|
2319
2328
|
return message.role === "system";
|
|
2320
2329
|
}), 2), systemMessages = _fork[0], otherMessages = _fork[1];
|
|
2321
2330
|
system = systemMessages.map(function(message) {
|
|
@@ -3938,11 +3947,11 @@ var serializeMessage3 = function(param) {
|
|
|
3938
3947
|
message: message
|
|
3939
3948
|
})
|
|
3940
3949
|
];
|
|
3941
|
-
var
|
|
3942
|
-
if (!
|
|
3950
|
+
var run4 = message.run;
|
|
3951
|
+
if (!run4) return result;
|
|
3943
3952
|
var messageToolCalls = ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) || [];
|
|
3944
3953
|
messageToolCalls.forEach(function(tc) {
|
|
3945
|
-
var runStep =
|
|
3954
|
+
var runStep = run4.runSteps.find(function(rs) {
|
|
3946
3955
|
if (rs.type !== "tool_calls") return false;
|
|
3947
3956
|
var stepDetails2 = rs.step_details;
|
|
3948
3957
|
if (!Array.isArray(stepDetails2.tool_calls)) return false;
|
|
@@ -3966,16 +3975,16 @@ var serializeMessage3 = function(param) {
|
|
|
3966
3975
|
};
|
|
3967
3976
|
// src/adapters/run/completionsRunAdapter/messages/index.ts
|
|
3968
3977
|
var messages = function(param) {
|
|
3969
|
-
var
|
|
3978
|
+
var run4 = param.run, getMessages2 = param.getMessages;
|
|
3970
3979
|
return _async_to_generator(function() {
|
|
3971
3980
|
var _, _1;
|
|
3972
3981
|
return _ts_generator(this, function(_state) {
|
|
3973
3982
|
switch(_state.label){
|
|
3974
3983
|
case 0:
|
|
3975
|
-
_1 = (_ = _to_consumable_array(
|
|
3984
|
+
_1 = (_ = _to_consumable_array(run4.instructions ? [
|
|
3976
3985
|
{
|
|
3977
3986
|
role: "system",
|
|
3978
|
-
content:
|
|
3987
|
+
content: run4.instructions
|
|
3979
3988
|
}
|
|
3980
3989
|
] : [])).concat;
|
|
3981
3990
|
return [
|
|
@@ -4073,18 +4082,18 @@ var toolCallsData = function(param) {
|
|
|
4073
4082
|
var completionsRunAdapter = function() {
|
|
4074
4083
|
return {
|
|
4075
4084
|
handleRun: function(param) {
|
|
4076
|
-
var client = param.client,
|
|
4085
|
+
var client = param.client, run4 = param.run, onEvent2 = param.onEvent, getMessages2 = param.getMessages;
|
|
4077
4086
|
return _async_to_generator(function() {
|
|
4078
4087
|
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;
|
|
4079
4088
|
return _ts_generator(this, function(_state) {
|
|
4080
4089
|
switch(_state.label){
|
|
4081
4090
|
case 0:
|
|
4082
|
-
if (
|
|
4091
|
+
if (run4.status !== "queued") return [
|
|
4083
4092
|
2
|
|
4084
4093
|
];
|
|
4085
4094
|
onEvent2({
|
|
4086
4095
|
event: "thread.run.in_progress",
|
|
4087
|
-
data: _object_spread_props(_object_spread({},
|
|
4096
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4088
4097
|
status: "in_progress"
|
|
4089
4098
|
})
|
|
4090
4099
|
});
|
|
@@ -4092,15 +4101,15 @@ var completionsRunAdapter = function() {
|
|
|
4092
4101
|
return [
|
|
4093
4102
|
4,
|
|
4094
4103
|
messages({
|
|
4095
|
-
run:
|
|
4104
|
+
run: run4,
|
|
4096
4105
|
getMessages: getMessages2
|
|
4097
4106
|
})
|
|
4098
4107
|
];
|
|
4099
4108
|
case 1:
|
|
4100
4109
|
opts = _object_spread.apply(void 0, [
|
|
4101
|
-
(_tmp.messages = _state.sent(), _tmp.model =
|
|
4102
|
-
isEmpty2(
|
|
4103
|
-
tools:
|
|
4110
|
+
(_tmp.messages = _state.sent(), _tmp.model = run4.model, _tmp.stream = true, _tmp.response_format = run4.response_format, _tmp),
|
|
4111
|
+
isEmpty2(run4.tools) ? {} : {
|
|
4112
|
+
tools: run4.tools
|
|
4104
4113
|
}
|
|
4105
4114
|
]);
|
|
4106
4115
|
_state.label = 2;
|
|
@@ -4128,7 +4137,7 @@ var completionsRunAdapter = function() {
|
|
|
4128
4137
|
2,
|
|
4129
4138
|
onEvent2({
|
|
4130
4139
|
event: "thread.run.failed",
|
|
4131
|
-
data: _object_spread_props(_object_spread({},
|
|
4140
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4132
4141
|
failed_at: dayjs().unix(),
|
|
4133
4142
|
status: "in_progress",
|
|
4134
4143
|
last_error: {
|
|
@@ -4147,14 +4156,14 @@ var completionsRunAdapter = function() {
|
|
|
4147
4156
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4148
4157
|
object: "thread.message",
|
|
4149
4158
|
completed_at: null,
|
|
4150
|
-
run_id:
|
|
4159
|
+
run_id: run4.id,
|
|
4151
4160
|
created_at: dayjs().unix(),
|
|
4152
|
-
assistant_id:
|
|
4161
|
+
assistant_id: run4.assistant_id,
|
|
4153
4162
|
incomplete_at: null,
|
|
4154
4163
|
incomplete_details: null,
|
|
4155
4164
|
metadata: {},
|
|
4156
4165
|
attachments: [],
|
|
4157
|
-
thread_id:
|
|
4166
|
+
thread_id: run4.thread_id,
|
|
4158
4167
|
content: [
|
|
4159
4168
|
{
|
|
4160
4169
|
text: {
|
|
@@ -4176,9 +4185,9 @@ var completionsRunAdapter = function() {
|
|
|
4176
4185
|
data: {
|
|
4177
4186
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4178
4187
|
object: "thread.run.step",
|
|
4179
|
-
run_id:
|
|
4180
|
-
assistant_id:
|
|
4181
|
-
thread_id:
|
|
4188
|
+
run_id: run4.id,
|
|
4189
|
+
assistant_id: run4.assistant_id,
|
|
4190
|
+
thread_id: run4.thread_id,
|
|
4182
4191
|
type: "message_creation",
|
|
4183
4192
|
status: "completed",
|
|
4184
4193
|
completed_at: dayjs().unix(),
|
|
@@ -4247,9 +4256,9 @@ var completionsRunAdapter = function() {
|
|
|
4247
4256
|
data: {
|
|
4248
4257
|
id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
|
|
4249
4258
|
object: "thread.run.step",
|
|
4250
|
-
run_id:
|
|
4251
|
-
assistant_id:
|
|
4252
|
-
thread_id:
|
|
4259
|
+
run_id: run4.id,
|
|
4260
|
+
assistant_id: run4.assistant_id,
|
|
4261
|
+
thread_id: run4.thread_id,
|
|
4253
4262
|
type: "tool_calls",
|
|
4254
4263
|
status: "in_progress",
|
|
4255
4264
|
completed_at: null,
|
|
@@ -4275,7 +4284,7 @@ var completionsRunAdapter = function() {
|
|
|
4275
4284
|
event: "thread.run.step.delta",
|
|
4276
4285
|
data: {
|
|
4277
4286
|
object: "thread.run.step.delta",
|
|
4278
|
-
run_id:
|
|
4287
|
+
run_id: run4.id,
|
|
4279
4288
|
id: toolCallsRunStep.id,
|
|
4280
4289
|
delta: {
|
|
4281
4290
|
step_details: {
|
|
@@ -4430,7 +4439,7 @@ var completionsRunAdapter = function() {
|
|
|
4430
4439
|
2,
|
|
4431
4440
|
onEvent2({
|
|
4432
4441
|
event: "thread.run.completed",
|
|
4433
|
-
data: _object_spread_props(_object_spread({},
|
|
4442
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4434
4443
|
status: "completed",
|
|
4435
4444
|
completed_at: dayjs().unix()
|
|
4436
4445
|
})
|
|
@@ -4473,7 +4482,7 @@ var completionsRunAdapter = function() {
|
|
|
4473
4482
|
2,
|
|
4474
4483
|
onEvent2({
|
|
4475
4484
|
event: "thread.run.requires_action",
|
|
4476
|
-
data: _object_spread_props(_object_spread({},
|
|
4485
|
+
data: _object_spread_props(_object_spread({}, run4), {
|
|
4477
4486
|
status: "requires_action",
|
|
4478
4487
|
required_action: {
|
|
4479
4488
|
type: "submit_tool_outputs",
|
|
@@ -4520,7 +4529,7 @@ var post10 = function(param) {
|
|
|
4520
4529
|
var prisma = param.prisma;
|
|
4521
4530
|
return function(_urlString, options) {
|
|
4522
4531
|
return _async_to_generator(function() {
|
|
4523
|
-
var body,
|
|
4532
|
+
var body, messages5, metadataRecord, assistantId, initialCreatedAt, messageData, threadData, thread;
|
|
4524
4533
|
return _ts_generator(this, function(_state) {
|
|
4525
4534
|
switch(_state.label){
|
|
4526
4535
|
case 0:
|
|
@@ -4528,14 +4537,14 @@ var post10 = function(param) {
|
|
|
4528
4537
|
throw new Error("No body provided");
|
|
4529
4538
|
}
|
|
4530
4539
|
body = JSON.parse(options.body);
|
|
4531
|
-
|
|
4540
|
+
messages5 = body.messages || [];
|
|
4532
4541
|
metadataRecord = body.metadata || {};
|
|
4533
4542
|
assistantId = typeof metadataRecord.assistantId === "string" ? metadataRecord.assistantId : void 0;
|
|
4534
4543
|
if (!assistantId) {
|
|
4535
4544
|
throw new Error("assistantId is required to create a thread");
|
|
4536
4545
|
}
|
|
4537
|
-
initialCreatedAt = dayjs3().subtract(
|
|
4538
|
-
messageData =
|
|
4546
|
+
initialCreatedAt = dayjs3().subtract(messages5.length, "seconds");
|
|
4547
|
+
messageData = messages5.map(function(message, index) {
|
|
4539
4548
|
var _message_attachments;
|
|
4540
4549
|
return {
|
|
4541
4550
|
role: message.role === "user" ? "USER" : "ASSISTANT",
|
|
@@ -4704,7 +4713,7 @@ var get10 = function(param) {
|
|
|
4704
4713
|
var prisma = param.prisma;
|
|
4705
4714
|
return function(urlString) {
|
|
4706
4715
|
return _async_to_generator(function() {
|
|
4707
|
-
var _last, url, _url_pathname_match, threadId, _assign3, limit, order, after, pageSize, messagesPlusOne,
|
|
4716
|
+
var _last, url, _url_pathname_match, threadId, _assign3, limit, order, after, pageSize, messagesPlusOne, messages5, _last_id;
|
|
4708
4717
|
return _ts_generator(this, function(_state) {
|
|
4709
4718
|
switch(_state.label){
|
|
4710
4719
|
case 0:
|
|
@@ -4734,17 +4743,17 @@ var get10 = function(param) {
|
|
|
4734
4743
|
];
|
|
4735
4744
|
case 1:
|
|
4736
4745
|
messagesPlusOne = _state.sent();
|
|
4737
|
-
|
|
4746
|
+
messages5 = messagesPlusOne.slice(0, pageSize);
|
|
4738
4747
|
return [
|
|
4739
4748
|
2,
|
|
4740
4749
|
new Response(JSON.stringify({
|
|
4741
|
-
data:
|
|
4750
|
+
data: messages5.map(function(message) {
|
|
4742
4751
|
return serializeMessage4({
|
|
4743
4752
|
message: message
|
|
4744
4753
|
});
|
|
4745
4754
|
}),
|
|
4746
4755
|
has_more: messagesPlusOne.length > pageSize,
|
|
4747
|
-
last_id: (_last_id = (_last = last(
|
|
4756
|
+
last_id: (_last_id = (_last = last(messages5)) === null || _last === void 0 ? void 0 : _last.id) !== null && _last_id !== void 0 ? _last_id : null
|
|
4748
4757
|
}), {
|
|
4749
4758
|
status: 200,
|
|
4750
4759
|
headers: {
|
|
@@ -4774,26 +4783,26 @@ import { assign as assign4 } from "radash";
|
|
|
4774
4783
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
|
|
4775
4784
|
import dayjs5 from "dayjs";
|
|
4776
4785
|
var serializeRun = function(param) {
|
|
4777
|
-
var
|
|
4786
|
+
var run4 = param.run;
|
|
4778
4787
|
return {
|
|
4779
|
-
id:
|
|
4788
|
+
id: run4.id,
|
|
4780
4789
|
object: "thread.run",
|
|
4781
|
-
created_at: dayjs5(
|
|
4782
|
-
thread_id:
|
|
4783
|
-
assistant_id:
|
|
4784
|
-
status:
|
|
4785
|
-
required_action:
|
|
4786
|
-
last_error:
|
|
4787
|
-
expires_at: dayjs5(
|
|
4788
|
-
started_at:
|
|
4789
|
-
cancelled_at:
|
|
4790
|
-
failed_at:
|
|
4791
|
-
completed_at:
|
|
4792
|
-
model:
|
|
4793
|
-
instructions:
|
|
4794
|
-
tools:
|
|
4795
|
-
metadata:
|
|
4796
|
-
usage:
|
|
4790
|
+
created_at: dayjs5(run4.createdAt).unix(),
|
|
4791
|
+
thread_id: run4.threadId,
|
|
4792
|
+
assistant_id: run4.assistantId,
|
|
4793
|
+
status: run4.status.toLowerCase(),
|
|
4794
|
+
required_action: run4.requiredAction,
|
|
4795
|
+
last_error: run4.lastError,
|
|
4796
|
+
expires_at: dayjs5(run4.expiresAt).unix(),
|
|
4797
|
+
started_at: run4.startedAt ? dayjs5(run4.startedAt).unix() : null,
|
|
4798
|
+
cancelled_at: run4.cancelledAt ? dayjs5(run4.cancelledAt).unix() : null,
|
|
4799
|
+
failed_at: run4.failedAt ? dayjs5(run4.failedAt).unix() : null,
|
|
4800
|
+
completed_at: run4.completedAt ? dayjs5(run4.completedAt).unix() : null,
|
|
4801
|
+
model: run4.model,
|
|
4802
|
+
instructions: run4.instructions,
|
|
4803
|
+
tools: run4.tools,
|
|
4804
|
+
metadata: run4.metadata,
|
|
4805
|
+
usage: run4.usage,
|
|
4797
4806
|
truncation_strategy: {
|
|
4798
4807
|
type: "auto"
|
|
4799
4808
|
},
|
|
@@ -4809,29 +4818,29 @@ var serializeRun = function(param) {
|
|
|
4809
4818
|
};
|
|
4810
4819
|
};
|
|
4811
4820
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/mapPrismaRun.ts
|
|
4812
|
-
var mapPrismaRun = function(
|
|
4813
|
-
var
|
|
4821
|
+
var mapPrismaRun = function(run4) {
|
|
4822
|
+
var _run4_startedAt, _run4_cancelledAt, _run4_failedAt, _run4_completedAt;
|
|
4814
4823
|
return {
|
|
4815
|
-
id:
|
|
4816
|
-
threadId:
|
|
4817
|
-
assistantId:
|
|
4818
|
-
status:
|
|
4819
|
-
requiredAction:
|
|
4820
|
-
lastError:
|
|
4821
|
-
expiresAt:
|
|
4822
|
-
startedAt: (
|
|
4823
|
-
cancelledAt: (
|
|
4824
|
-
failedAt: (
|
|
4825
|
-
completedAt: (
|
|
4826
|
-
model:
|
|
4827
|
-
instructions:
|
|
4828
|
-
tools:
|
|
4829
|
-
metadata:
|
|
4830
|
-
usage:
|
|
4831
|
-
truncationStrategy:
|
|
4832
|
-
responseFormat:
|
|
4833
|
-
createdAt:
|
|
4834
|
-
updatedAt:
|
|
4824
|
+
id: run4.id,
|
|
4825
|
+
threadId: run4.threadId,
|
|
4826
|
+
assistantId: run4.assistantId,
|
|
4827
|
+
status: run4.status,
|
|
4828
|
+
requiredAction: run4.requiredAction,
|
|
4829
|
+
lastError: run4.lastError,
|
|
4830
|
+
expiresAt: run4.expiresAt,
|
|
4831
|
+
startedAt: (_run4_startedAt = run4.startedAt) !== null && _run4_startedAt !== void 0 ? _run4_startedAt : null,
|
|
4832
|
+
cancelledAt: (_run4_cancelledAt = run4.cancelledAt) !== null && _run4_cancelledAt !== void 0 ? _run4_cancelledAt : null,
|
|
4833
|
+
failedAt: (_run4_failedAt = run4.failedAt) !== null && _run4_failedAt !== void 0 ? _run4_failedAt : null,
|
|
4834
|
+
completedAt: (_run4_completedAt = run4.completedAt) !== null && _run4_completedAt !== void 0 ? _run4_completedAt : null,
|
|
4835
|
+
model: run4.model,
|
|
4836
|
+
instructions: run4.instructions,
|
|
4837
|
+
tools: run4.tools,
|
|
4838
|
+
metadata: run4.metadata,
|
|
4839
|
+
usage: run4.usage,
|
|
4840
|
+
truncationStrategy: run4.truncationStrategy,
|
|
4841
|
+
responseFormat: run4.responseFormat,
|
|
4842
|
+
createdAt: run4.createdAt,
|
|
4843
|
+
updatedAt: run4.updatedAt
|
|
4835
4844
|
};
|
|
4836
4845
|
};
|
|
4837
4846
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
|
|
@@ -4839,7 +4848,7 @@ var get11 = function(param) {
|
|
|
4839
4848
|
var prisma = param.prisma;
|
|
4840
4849
|
return function(urlString) {
|
|
4841
4850
|
return _async_to_generator(function() {
|
|
4842
|
-
var
|
|
4851
|
+
var _runs4_at, url, _url_pathname_match, threadId, _assign4, limit, order, after, pageSize, runsPlusOne, runs4, _runs4_at_id;
|
|
4843
4852
|
return _ts_generator(this, function(_state) {
|
|
4844
4853
|
switch(_state.label){
|
|
4845
4854
|
case 0:
|
|
@@ -4869,17 +4878,17 @@ var get11 = function(param) {
|
|
|
4869
4878
|
];
|
|
4870
4879
|
case 1:
|
|
4871
4880
|
runsPlusOne = _state.sent();
|
|
4872
|
-
|
|
4881
|
+
runs4 = runsPlusOne.slice(0, pageSize);
|
|
4873
4882
|
return [
|
|
4874
4883
|
2,
|
|
4875
4884
|
new Response(JSON.stringify({
|
|
4876
|
-
data:
|
|
4885
|
+
data: runs4.map(function(run4) {
|
|
4877
4886
|
return serializeRun({
|
|
4878
|
-
run: mapPrismaRun(
|
|
4887
|
+
run: mapPrismaRun(run4)
|
|
4879
4888
|
});
|
|
4880
4889
|
}),
|
|
4881
4890
|
has_more: runsPlusOne.length > pageSize,
|
|
4882
|
-
last_id: (
|
|
4891
|
+
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
|
|
4883
4892
|
}), {
|
|
4884
4893
|
status: 200,
|
|
4885
4894
|
headers: {
|
|
@@ -5210,37 +5219,37 @@ var onEvent = function(param) {
|
|
|
5210
5219
|
};
|
|
5211
5220
|
// src/adapters/storage/prismaStorageAdapter/threads/runs/getMessages.ts
|
|
5212
5221
|
var getTake = function(param) {
|
|
5213
|
-
var
|
|
5222
|
+
var run4 = param.run;
|
|
5214
5223
|
if ([
|
|
5215
5224
|
"auto",
|
|
5216
5225
|
"disabled"
|
|
5217
|
-
].includes(
|
|
5226
|
+
].includes(run4.truncationStrategy.type)) {
|
|
5218
5227
|
return null;
|
|
5219
5228
|
}
|
|
5220
|
-
if (
|
|
5221
|
-
if (!
|
|
5229
|
+
if (run4.truncationStrategy.type === "last_messages") {
|
|
5230
|
+
if (!run4.truncationStrategy.last_messages) {
|
|
5222
5231
|
throw new Error("Truncation strategy last_messages is required");
|
|
5223
5232
|
}
|
|
5224
|
-
return -
|
|
5233
|
+
return -run4.truncationStrategy.last_messages;
|
|
5225
5234
|
}
|
|
5226
|
-
throw new Error("Unsupported truncation strategy type: ".concat(
|
|
5235
|
+
throw new Error("Unsupported truncation strategy type: ".concat(run4.truncationStrategy.type));
|
|
5227
5236
|
};
|
|
5228
5237
|
var getMessages = function(param) {
|
|
5229
|
-
var prisma = param.prisma,
|
|
5238
|
+
var prisma = param.prisma, run4 = param.run;
|
|
5230
5239
|
return function() {
|
|
5231
5240
|
return _async_to_generator(function() {
|
|
5232
|
-
var take,
|
|
5241
|
+
var take, messages5;
|
|
5233
5242
|
return _ts_generator(this, function(_state) {
|
|
5234
5243
|
switch(_state.label){
|
|
5235
5244
|
case 0:
|
|
5236
5245
|
take = getTake({
|
|
5237
|
-
run:
|
|
5246
|
+
run: run4
|
|
5238
5247
|
});
|
|
5239
5248
|
return [
|
|
5240
5249
|
4,
|
|
5241
5250
|
prisma.message.findMany(_object_spread({
|
|
5242
5251
|
where: {
|
|
5243
|
-
threadId:
|
|
5252
|
+
threadId: run4.threadId
|
|
5244
5253
|
},
|
|
5245
5254
|
include: {
|
|
5246
5255
|
run: {
|
|
@@ -5257,10 +5266,10 @@ var getMessages = function(param) {
|
|
|
5257
5266
|
} : {}))
|
|
5258
5267
|
];
|
|
5259
5268
|
case 1:
|
|
5260
|
-
|
|
5269
|
+
messages5 = _state.sent();
|
|
5261
5270
|
return [
|
|
5262
5271
|
2,
|
|
5263
|
-
|
|
5272
|
+
messages5.map(function(message) {
|
|
5264
5273
|
return _object_spread_props(_object_spread({}, serializeMessage4({
|
|
5265
5274
|
message: message
|
|
5266
5275
|
})), {
|
|
@@ -5287,7 +5296,7 @@ var post12 = function(param) {
|
|
|
5287
5296
|
return function(urlString, options) {
|
|
5288
5297
|
return _async_to_generator(function() {
|
|
5289
5298
|
var url, _url_pathname_match, threadId, body, assistant_id, stream, assistant, _assign5, model, instructions, // additional_instructions,
|
|
5290
|
-
tools, metadata, response_format, truncation_strategy,
|
|
5299
|
+
tools, metadata, response_format, truncation_strategy, run4, data, readableStream;
|
|
5291
5300
|
return _ts_generator(this, function(_state) {
|
|
5292
5301
|
switch(_state.label){
|
|
5293
5302
|
case 0:
|
|
@@ -5348,9 +5357,9 @@ var post12 = function(param) {
|
|
|
5348
5357
|
})
|
|
5349
5358
|
];
|
|
5350
5359
|
case 2:
|
|
5351
|
-
|
|
5360
|
+
run4 = _state.sent();
|
|
5352
5361
|
data = serializeRun({
|
|
5353
|
-
run:
|
|
5362
|
+
run: run4
|
|
5354
5363
|
});
|
|
5355
5364
|
readableStream = new ReadableStream({
|
|
5356
5365
|
start: function start(controller) {
|
|
@@ -5379,7 +5388,7 @@ var post12 = function(param) {
|
|
|
5379
5388
|
}),
|
|
5380
5389
|
getMessages: getMessages({
|
|
5381
5390
|
prisma: prisma,
|
|
5382
|
-
run:
|
|
5391
|
+
run: run4
|
|
5383
5392
|
})
|
|
5384
5393
|
})
|
|
5385
5394
|
];
|
|
@@ -5402,7 +5411,7 @@ var post12 = function(param) {
|
|
|
5402
5411
|
})({
|
|
5403
5412
|
event: "thread.run.failed",
|
|
5404
5413
|
data: {
|
|
5405
|
-
id:
|
|
5414
|
+
id: run4.id,
|
|
5406
5415
|
failed_at: dayjs7().unix(),
|
|
5407
5416
|
last_error: {
|
|
5408
5417
|
code: "server_error",
|
|
@@ -5470,7 +5479,7 @@ var get12 = function(param) {
|
|
|
5470
5479
|
var prisma = param.prisma;
|
|
5471
5480
|
return function(urlString) {
|
|
5472
5481
|
return _async_to_generator(function() {
|
|
5473
|
-
var url, _url_pathname_match, threadId, runId,
|
|
5482
|
+
var url, _url_pathname_match, threadId, runId, run4;
|
|
5474
5483
|
return _ts_generator(this, function(_state) {
|
|
5475
5484
|
switch(_state.label){
|
|
5476
5485
|
case 0:
|
|
@@ -5486,8 +5495,8 @@ var get12 = function(param) {
|
|
|
5486
5495
|
})
|
|
5487
5496
|
];
|
|
5488
5497
|
case 1:
|
|
5489
|
-
|
|
5490
|
-
if (!
|
|
5498
|
+
run4 = _state.sent();
|
|
5499
|
+
if (!run4) {
|
|
5491
5500
|
return [
|
|
5492
5501
|
2,
|
|
5493
5502
|
new Response(JSON.stringify({
|
|
@@ -5503,7 +5512,7 @@ var get12 = function(param) {
|
|
|
5503
5512
|
return [
|
|
5504
5513
|
2,
|
|
5505
5514
|
new Response(JSON.stringify(serializeRun({
|
|
5506
|
-
run: mapPrismaRun(
|
|
5515
|
+
run: mapPrismaRun(run4)
|
|
5507
5516
|
})), {
|
|
5508
5517
|
status: 200,
|
|
5509
5518
|
headers: {
|
|
@@ -5762,7 +5771,7 @@ var post13 = function(param) {
|
|
|
5762
5771
|
var prisma = param.prisma, runAdapter = param.runAdapter;
|
|
5763
5772
|
return function(urlString, options) {
|
|
5764
5773
|
return _async_to_generator(function() {
|
|
5765
|
-
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream,
|
|
5774
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, readableStream, run4;
|
|
5766
5775
|
return _ts_generator(this, function(_state) {
|
|
5767
5776
|
switch(_state.label){
|
|
5768
5777
|
case 0:
|
|
@@ -5777,7 +5786,7 @@ var post13 = function(param) {
|
|
|
5777
5786
|
readableStream = new ReadableStream({
|
|
5778
5787
|
start: function start(controller) {
|
|
5779
5788
|
return _async_to_generator(function() {
|
|
5780
|
-
var
|
|
5789
|
+
var run4;
|
|
5781
5790
|
return _ts_generator(this, function(_state) {
|
|
5782
5791
|
switch(_state.label){
|
|
5783
5792
|
case 0:
|
|
@@ -5807,12 +5816,12 @@ var post13 = function(param) {
|
|
|
5807
5816
|
})
|
|
5808
5817
|
];
|
|
5809
5818
|
case 1:
|
|
5810
|
-
|
|
5819
|
+
run4 = _state.sent();
|
|
5811
5820
|
return [
|
|
5812
5821
|
4,
|
|
5813
5822
|
runAdapter.handleRun({
|
|
5814
5823
|
run: serializeRun({
|
|
5815
|
-
run:
|
|
5824
|
+
run: run4
|
|
5816
5825
|
}),
|
|
5817
5826
|
onEvent: onEvent({
|
|
5818
5827
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5824,7 +5833,7 @@ var post13 = function(param) {
|
|
|
5824
5833
|
}),
|
|
5825
5834
|
getMessages: getMessages({
|
|
5826
5835
|
prisma: prisma,
|
|
5827
|
-
run:
|
|
5836
|
+
run: run4
|
|
5828
5837
|
})
|
|
5829
5838
|
})
|
|
5830
5839
|
];
|
|
@@ -5858,7 +5867,7 @@ var post13 = function(param) {
|
|
|
5858
5867
|
})
|
|
5859
5868
|
];
|
|
5860
5869
|
case 2:
|
|
5861
|
-
|
|
5870
|
+
run4 = _state.sent();
|
|
5862
5871
|
return [
|
|
5863
5872
|
4,
|
|
5864
5873
|
new Promise(function(resolve) {
|
|
@@ -5872,7 +5881,7 @@ var post13 = function(param) {
|
|
|
5872
5881
|
4,
|
|
5873
5882
|
runAdapter.handleRun({
|
|
5874
5883
|
run: serializeRun({
|
|
5875
|
-
run:
|
|
5884
|
+
run: run4
|
|
5876
5885
|
}),
|
|
5877
5886
|
onEvent: onEvent({
|
|
5878
5887
|
controller: _object_spread_props(_object_spread({}, controller), {
|
|
@@ -5884,7 +5893,7 @@ var post13 = function(param) {
|
|
|
5884
5893
|
}),
|
|
5885
5894
|
getMessages: getMessages({
|
|
5886
5895
|
prisma: prisma,
|
|
5887
|
-
run:
|
|
5896
|
+
run: run4
|
|
5888
5897
|
})
|
|
5889
5898
|
})
|
|
5890
5899
|
];
|
|
@@ -5906,7 +5915,7 @@ var post13 = function(param) {
|
|
|
5906
5915
|
_state.sent();
|
|
5907
5916
|
return [
|
|
5908
5917
|
2,
|
|
5909
|
-
new Response(JSON.stringify(
|
|
5918
|
+
new Response(JSON.stringify(run4), {
|
|
5910
5919
|
status: 200,
|
|
5911
5920
|
headers: {
|
|
5912
5921
|
"Content-Type": "application/json"
|
|
@@ -6041,7 +6050,7 @@ var post15 = function(param) {
|
|
|
6041
6050
|
var client = param.client;
|
|
6042
6051
|
return function(_urlString, options) {
|
|
6043
6052
|
return _async_to_generator(function() {
|
|
6044
|
-
var body,
|
|
6053
|
+
var body, messages5, metadata, conversation;
|
|
6045
6054
|
return _ts_generator(this, function(_state) {
|
|
6046
6055
|
switch(_state.label){
|
|
6047
6056
|
case 0:
|
|
@@ -6049,13 +6058,13 @@ var post15 = function(param) {
|
|
|
6049
6058
|
throw new Error("Request body is required");
|
|
6050
6059
|
}
|
|
6051
6060
|
body = JSON.parse(options.body);
|
|
6052
|
-
|
|
6061
|
+
messages5 = body.messages || [];
|
|
6053
6062
|
metadata = body.metadata || {};
|
|
6054
6063
|
return [
|
|
6055
6064
|
4,
|
|
6056
6065
|
client.conversations.create({
|
|
6057
6066
|
metadata: metadata,
|
|
6058
|
-
items:
|
|
6067
|
+
items: messages5.map(function(message) {
|
|
6059
6068
|
return {
|
|
6060
6069
|
type: "message",
|
|
6061
6070
|
role: message.role === "user" ? "user" : "assistant",
|
|
@@ -8328,204 +8337,1612 @@ var responsesStorageAdapter = function() {
|
|
|
8328
8337
|
};
|
|
8329
8338
|
};
|
|
8330
8339
|
};
|
|
8331
|
-
// src/adapters/
|
|
8340
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/post.ts
|
|
8332
8341
|
import dayjs21 from "dayjs";
|
|
8333
|
-
|
|
8334
|
-
var
|
|
8335
|
-
|
|
8336
|
-
return toolCalls.map(function(toolCall) {
|
|
8337
|
-
if (toolCall.type === "function_call") {
|
|
8338
|
-
return {
|
|
8339
|
-
id: toolCall.call_id,
|
|
8340
|
-
type: "function",
|
|
8341
|
-
function: {
|
|
8342
|
-
name: toolCall.name,
|
|
8343
|
-
arguments: toolCall.arguments
|
|
8344
|
-
}
|
|
8345
|
-
};
|
|
8346
|
-
} else if (toolCall.type === "computer_call") {
|
|
8347
|
-
return {
|
|
8348
|
-
id: toolCall.call_id,
|
|
8349
|
-
type: "computer_call",
|
|
8350
|
-
computer_call: {
|
|
8351
|
-
action: toolCall.action,
|
|
8352
|
-
pending_safety_checks: toolCall.pending_safety_checks
|
|
8353
|
-
}
|
|
8354
|
-
};
|
|
8355
|
-
}
|
|
8356
|
-
});
|
|
8357
|
-
};
|
|
8358
|
-
var responsesRunAdapter = function(param) {
|
|
8359
|
-
var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
|
|
8360
|
-
return p.then(function() {});
|
|
8361
|
-
} : _param_waitUntil;
|
|
8362
|
-
var cachedOpenaiAssistant = null;
|
|
8363
|
-
var getOpenaiAssistant = function() {
|
|
8364
|
-
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;
|
|
8342
|
+
var post20 = function(param) {
|
|
8343
|
+
var azureAiProject = param.azureAiProject;
|
|
8344
|
+
return function(_urlString, options) {
|
|
8365
8345
|
return _async_to_generator(function() {
|
|
8366
|
-
var
|
|
8346
|
+
var body, metadata, thread, openaiThread;
|
|
8367
8347
|
return _ts_generator(this, function(_state) {
|
|
8368
8348
|
switch(_state.label){
|
|
8369
8349
|
case 0:
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
|
|
8374
|
-
};
|
|
8375
|
-
if (!args.select.id) return [
|
|
8376
|
-
3,
|
|
8377
|
-
2
|
|
8378
|
-
];
|
|
8379
|
-
_tmp = {};
|
|
8350
|
+
if (typeof options.body !== "string") {
|
|
8351
|
+
throw new Error("Request body is required");
|
|
8352
|
+
}
|
|
8353
|
+
body = JSON.parse(options.body);
|
|
8354
|
+
metadata = body.metadata || {};
|
|
8380
8355
|
return [
|
|
8381
8356
|
4,
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
id: true
|
|
8385
|
-
}
|
|
8357
|
+
azureAiProject.agents.threads.create({
|
|
8358
|
+
metadata: metadata
|
|
8386
8359
|
})
|
|
8387
8360
|
];
|
|
8388
8361
|
case 1:
|
|
8362
|
+
thread = _state.sent();
|
|
8363
|
+
openaiThread = {
|
|
8364
|
+
id: thread.id,
|
|
8365
|
+
object: "thread",
|
|
8366
|
+
created_at: dayjs21(thread.createdAt).unix(),
|
|
8367
|
+
metadata: thread.metadata || {},
|
|
8368
|
+
tool_resources: null
|
|
8369
|
+
};
|
|
8389
8370
|
return [
|
|
8390
8371
|
2,
|
|
8391
|
-
(
|
|
8372
|
+
new Response(JSON.stringify(openaiThread), {
|
|
8373
|
+
status: 200,
|
|
8374
|
+
headers: {
|
|
8375
|
+
"Content-Type": "application/json"
|
|
8376
|
+
}
|
|
8377
|
+
})
|
|
8392
8378
|
];
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8379
|
+
}
|
|
8380
|
+
});
|
|
8381
|
+
})();
|
|
8382
|
+
};
|
|
8383
|
+
};
|
|
8384
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/index.ts
|
|
8385
|
+
var threads3 = function(param) {
|
|
8386
|
+
var azureAiProject = param.azureAiProject;
|
|
8387
|
+
return {
|
|
8388
|
+
post: post20({
|
|
8389
|
+
azureAiProject: azureAiProject
|
|
8390
|
+
})
|
|
8391
|
+
};
|
|
8392
|
+
};
|
|
8393
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/post.ts
|
|
8394
|
+
import dayjs22 from "dayjs";
|
|
8395
|
+
var post21 = function(param) {
|
|
8396
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8397
|
+
return function(urlString, options) {
|
|
8398
|
+
return _async_to_generator(function() {
|
|
8399
|
+
var url, _url_pathname_match, threadId, body, role, content, textContent, textItem, message, openaiAssistant, openaiMessage;
|
|
8400
|
+
return _ts_generator(this, function(_state) {
|
|
8401
|
+
switch(_state.label){
|
|
8402
|
+
case 0:
|
|
8403
|
+
url = new URL(urlString);
|
|
8404
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8405
|
+
if (typeof options.body !== "string") {
|
|
8406
|
+
throw new Error("Request body is required");
|
|
8407
|
+
}
|
|
8408
|
+
body = JSON.parse(options.body);
|
|
8409
|
+
role = body.role, content = body.content;
|
|
8410
|
+
textContent = "";
|
|
8411
|
+
if (typeof content === "string") {
|
|
8412
|
+
textContent = content;
|
|
8413
|
+
} else if (Array.isArray(content)) {
|
|
8414
|
+
textItem = content.find(function(item) {
|
|
8415
|
+
return item.type === "text";
|
|
8416
|
+
});
|
|
8417
|
+
if (textItem) {
|
|
8418
|
+
textContent = textItem.text;
|
|
8419
|
+
}
|
|
8420
|
+
}
|
|
8421
|
+
return [
|
|
8422
|
+
4,
|
|
8423
|
+
azureAiProject.agents.messages.create(threadId, role, textContent)
|
|
8397
8424
|
];
|
|
8425
|
+
case 1:
|
|
8426
|
+
message = _state.sent();
|
|
8398
8427
|
return [
|
|
8399
8428
|
4,
|
|
8400
|
-
|
|
8429
|
+
runAdapter.getOpenaiAssistant({
|
|
8430
|
+
select: {
|
|
8431
|
+
id: true
|
|
8432
|
+
}
|
|
8433
|
+
})
|
|
8401
8434
|
];
|
|
8402
|
-
case
|
|
8403
|
-
|
|
8435
|
+
case 2:
|
|
8436
|
+
openaiAssistant = _state.sent();
|
|
8437
|
+
openaiMessage = {
|
|
8438
|
+
id: message.id,
|
|
8439
|
+
object: "thread.message",
|
|
8440
|
+
created_at: dayjs22(message.createdAt).unix(),
|
|
8441
|
+
thread_id: message.threadId,
|
|
8442
|
+
role: message.role,
|
|
8443
|
+
content: message.content.map(function(c) {
|
|
8444
|
+
if (c.type === "text" && "text" in c) {
|
|
8445
|
+
return {
|
|
8446
|
+
type: "text",
|
|
8447
|
+
text: {
|
|
8448
|
+
value: c.text.value,
|
|
8449
|
+
annotations: []
|
|
8450
|
+
}
|
|
8451
|
+
};
|
|
8452
|
+
}
|
|
8453
|
+
return c;
|
|
8454
|
+
}),
|
|
8455
|
+
assistant_id: openaiAssistant.id,
|
|
8456
|
+
run_id: null,
|
|
8457
|
+
attachments: [],
|
|
8458
|
+
metadata: message.metadata || {},
|
|
8459
|
+
status: "completed",
|
|
8460
|
+
completed_at: dayjs22(message.createdAt).unix(),
|
|
8461
|
+
incomplete_at: null,
|
|
8462
|
+
incomplete_details: null
|
|
8463
|
+
};
|
|
8404
8464
|
return [
|
|
8405
8465
|
2,
|
|
8406
|
-
|
|
8466
|
+
new Response(JSON.stringify(openaiMessage), {
|
|
8467
|
+
status: 200,
|
|
8468
|
+
headers: {
|
|
8469
|
+
"Content-Type": "application/json"
|
|
8470
|
+
}
|
|
8471
|
+
})
|
|
8407
8472
|
];
|
|
8408
8473
|
}
|
|
8409
8474
|
});
|
|
8410
8475
|
})();
|
|
8411
8476
|
};
|
|
8412
|
-
|
|
8413
|
-
|
|
8477
|
+
};
|
|
8478
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/get.ts
|
|
8479
|
+
import dayjs23 from "dayjs";
|
|
8480
|
+
var get19 = function(param) {
|
|
8481
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8482
|
+
return function(urlString) {
|
|
8414
8483
|
return _async_to_generator(function() {
|
|
8415
|
-
var
|
|
8484
|
+
var _messagesList_, _messagesList_1, url, _url_pathname_match, threadId, order, messages5, openaiAssistant, messagesList, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, message, err, response;
|
|
8416
8485
|
return _ts_generator(this, function(_state) {
|
|
8417
8486
|
switch(_state.label){
|
|
8418
8487
|
case 0:
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8488
|
+
url = new URL(urlString);
|
|
8489
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(messagesRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8490
|
+
order = url.searchParams.get("order") || "desc";
|
|
8491
|
+
return [
|
|
8492
|
+
4,
|
|
8493
|
+
azureAiProject.agents.messages.list(threadId, {
|
|
8494
|
+
order: order
|
|
8495
|
+
})
|
|
8496
|
+
];
|
|
8426
8497
|
case 1:
|
|
8427
|
-
_state.
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8498
|
+
messages5 = _state.sent();
|
|
8499
|
+
return [
|
|
8500
|
+
4,
|
|
8501
|
+
runAdapter.getOpenaiAssistant({
|
|
8502
|
+
select: {
|
|
8503
|
+
id: true
|
|
8504
|
+
}
|
|
8505
|
+
})
|
|
8506
|
+
];
|
|
8435
8507
|
case 2:
|
|
8436
|
-
_state.
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
140,
|
|
8440
|
-
145
|
|
8441
|
-
]);
|
|
8442
|
-
_iterator = _async_iterator(response);
|
|
8508
|
+
openaiAssistant = _state.sent();
|
|
8509
|
+
messagesList = [];
|
|
8510
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
8443
8511
|
_state.label = 3;
|
|
8444
8512
|
case 3:
|
|
8513
|
+
_state.trys.push([
|
|
8514
|
+
3,
|
|
8515
|
+
8,
|
|
8516
|
+
9,
|
|
8517
|
+
14
|
|
8518
|
+
]);
|
|
8519
|
+
_iterator = _async_iterator(messages5);
|
|
8520
|
+
_state.label = 4;
|
|
8521
|
+
case 4:
|
|
8445
8522
|
return [
|
|
8446
8523
|
4,
|
|
8447
8524
|
_iterator.next()
|
|
8448
8525
|
];
|
|
8449
|
-
case
|
|
8526
|
+
case 5:
|
|
8450
8527
|
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
8451
8528
|
3,
|
|
8452
|
-
|
|
8529
|
+
7
|
|
8453
8530
|
];
|
|
8454
8531
|
_value = _step.value;
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
17
|
|
8487
|
-
];
|
|
8488
|
-
case "response.output_item.done":
|
|
8489
|
-
return [
|
|
8490
|
-
3,
|
|
8491
|
-
75
|
|
8492
|
-
];
|
|
8493
|
-
case "response.function_call_arguments.delta":
|
|
8494
|
-
return [
|
|
8495
|
-
3,
|
|
8496
|
-
126
|
|
8497
|
-
];
|
|
8498
|
-
case "response.mcp_call_arguments.delta":
|
|
8499
|
-
return [
|
|
8500
|
-
3,
|
|
8501
|
-
128
|
|
8502
|
-
];
|
|
8503
|
-
case "response.image_generation_call.in_progress":
|
|
8504
|
-
return [
|
|
8505
|
-
3,
|
|
8506
|
-
130
|
|
8507
|
-
];
|
|
8508
|
-
case "response.image_generation_call.generating":
|
|
8509
|
-
return [
|
|
8510
|
-
3,
|
|
8511
|
-
130
|
|
8512
|
-
];
|
|
8513
|
-
case "response.image_generation_call.partial_image":
|
|
8514
|
-
return [
|
|
8515
|
-
3,
|
|
8516
|
-
133
|
|
8517
|
-
];
|
|
8518
|
-
}
|
|
8532
|
+
message = _value;
|
|
8533
|
+
messagesList.push({
|
|
8534
|
+
id: message.id,
|
|
8535
|
+
object: "thread.message",
|
|
8536
|
+
created_at: dayjs23(message.createdAt).unix(),
|
|
8537
|
+
thread_id: message.threadId,
|
|
8538
|
+
role: message.role,
|
|
8539
|
+
content: message.content.map(function(c) {
|
|
8540
|
+
if (c.type === "text" && "text" in c) {
|
|
8541
|
+
return {
|
|
8542
|
+
type: "text",
|
|
8543
|
+
text: {
|
|
8544
|
+
value: c.text.value,
|
|
8545
|
+
annotations: []
|
|
8546
|
+
}
|
|
8547
|
+
};
|
|
8548
|
+
}
|
|
8549
|
+
return c;
|
|
8550
|
+
}),
|
|
8551
|
+
assistant_id: openaiAssistant.id,
|
|
8552
|
+
run_id: null,
|
|
8553
|
+
attachments: [],
|
|
8554
|
+
metadata: message.metadata || {},
|
|
8555
|
+
status: "completed",
|
|
8556
|
+
completed_at: dayjs23(message.createdAt).unix(),
|
|
8557
|
+
incomplete_at: null,
|
|
8558
|
+
incomplete_details: null
|
|
8559
|
+
});
|
|
8560
|
+
_state.label = 6;
|
|
8561
|
+
case 6:
|
|
8562
|
+
_iteratorAbruptCompletion = false;
|
|
8519
8563
|
return [
|
|
8520
8564
|
3,
|
|
8521
|
-
|
|
8565
|
+
4
|
|
8522
8566
|
];
|
|
8523
|
-
case
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8567
|
+
case 7:
|
|
8568
|
+
return [
|
|
8569
|
+
3,
|
|
8570
|
+
14
|
|
8571
|
+
];
|
|
8572
|
+
case 8:
|
|
8573
|
+
err = _state.sent();
|
|
8574
|
+
_didIteratorError = true;
|
|
8575
|
+
_iteratorError = err;
|
|
8576
|
+
return [
|
|
8577
|
+
3,
|
|
8578
|
+
14
|
|
8579
|
+
];
|
|
8580
|
+
case 9:
|
|
8581
|
+
_state.trys.push([
|
|
8582
|
+
9,
|
|
8583
|
+
,
|
|
8584
|
+
12,
|
|
8585
|
+
13
|
|
8586
|
+
]);
|
|
8587
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
8588
|
+
3,
|
|
8589
|
+
11
|
|
8590
|
+
];
|
|
8591
|
+
return [
|
|
8592
|
+
4,
|
|
8593
|
+
_iterator.return()
|
|
8594
|
+
];
|
|
8595
|
+
case 10:
|
|
8596
|
+
_state.sent();
|
|
8597
|
+
_state.label = 11;
|
|
8598
|
+
case 11:
|
|
8599
|
+
return [
|
|
8600
|
+
3,
|
|
8601
|
+
13
|
|
8602
|
+
];
|
|
8603
|
+
case 12:
|
|
8604
|
+
if (_didIteratorError) {
|
|
8605
|
+
throw _iteratorError;
|
|
8606
|
+
}
|
|
8607
|
+
return [
|
|
8608
|
+
7
|
|
8609
|
+
];
|
|
8610
|
+
case 13:
|
|
8611
|
+
return [
|
|
8612
|
+
7
|
|
8613
|
+
];
|
|
8614
|
+
case 14:
|
|
8615
|
+
response = {
|
|
8616
|
+
data: messagesList,
|
|
8617
|
+
first_id: ((_messagesList_ = messagesList[0]) === null || _messagesList_ === void 0 ? void 0 : _messagesList_.id) || null,
|
|
8618
|
+
last_id: ((_messagesList_1 = messagesList[messagesList.length - 1]) === null || _messagesList_1 === void 0 ? void 0 : _messagesList_1.id) || null,
|
|
8619
|
+
has_more: false
|
|
8620
|
+
};
|
|
8621
|
+
return [
|
|
8622
|
+
2,
|
|
8623
|
+
new Response(JSON.stringify(response), {
|
|
8624
|
+
status: 200,
|
|
8625
|
+
headers: {
|
|
8626
|
+
"Content-Type": "application/json"
|
|
8627
|
+
}
|
|
8628
|
+
})
|
|
8629
|
+
];
|
|
8630
|
+
}
|
|
8631
|
+
});
|
|
8632
|
+
})();
|
|
8633
|
+
};
|
|
8634
|
+
};
|
|
8635
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/messages/index.ts
|
|
8636
|
+
var messages4 = function(param) {
|
|
8637
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8638
|
+
return {
|
|
8639
|
+
post: post21({
|
|
8640
|
+
azureAiProject: azureAiProject,
|
|
8641
|
+
runAdapter: runAdapter
|
|
8642
|
+
}),
|
|
8643
|
+
get: get19({
|
|
8644
|
+
azureAiProject: azureAiProject,
|
|
8645
|
+
runAdapter: runAdapter
|
|
8646
|
+
})
|
|
8647
|
+
};
|
|
8648
|
+
};
|
|
8649
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/get.ts
|
|
8650
|
+
var get20 = function() {
|
|
8651
|
+
return function() {
|
|
8652
|
+
return _async_to_generator(function() {
|
|
8653
|
+
var response;
|
|
8654
|
+
return _ts_generator(this, function(_state) {
|
|
8655
|
+
response = {
|
|
8656
|
+
data: [],
|
|
8657
|
+
first_id: null,
|
|
8658
|
+
last_id: null,
|
|
8659
|
+
has_more: false
|
|
8660
|
+
};
|
|
8661
|
+
return [
|
|
8662
|
+
2,
|
|
8663
|
+
new Response(JSON.stringify(response), {
|
|
8664
|
+
status: 200,
|
|
8665
|
+
headers: {
|
|
8666
|
+
"Content-Type": "application/json"
|
|
8667
|
+
}
|
|
8668
|
+
})
|
|
8669
|
+
];
|
|
8670
|
+
});
|
|
8671
|
+
})();
|
|
8672
|
+
};
|
|
8673
|
+
};
|
|
8674
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/post.ts
|
|
8675
|
+
import { uid as uid8 } from "radash";
|
|
8676
|
+
import dayjs24 from "dayjs";
|
|
8677
|
+
var post22 = function(param) {
|
|
8678
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8679
|
+
return function(urlString, options) {
|
|
8680
|
+
return _async_to_generator(function() {
|
|
8681
|
+
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;
|
|
8682
|
+
return _ts_generator(this, function(_state) {
|
|
8683
|
+
switch(_state.label){
|
|
8684
|
+
case 0:
|
|
8685
|
+
url = new URL(urlString);
|
|
8686
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
|
|
8687
|
+
if (typeof options.body !== "string") {
|
|
8688
|
+
throw new Error("Request body is required");
|
|
8689
|
+
}
|
|
8690
|
+
body = JSON.parse(options.body);
|
|
8691
|
+
assistant_id = body.assistant_id, stream = body.stream, instructions = body.instructions, tools = body.tools;
|
|
8692
|
+
if (!assistant_id) {
|
|
8693
|
+
throw new Error("assistant_id is required");
|
|
8694
|
+
}
|
|
8695
|
+
azureAgentId = assistant_id;
|
|
8696
|
+
if (!stream) return [
|
|
8697
|
+
3,
|
|
8698
|
+
1
|
|
8699
|
+
];
|
|
8700
|
+
readableStream = new ReadableStream({
|
|
8701
|
+
start: function start(controller) {
|
|
8702
|
+
return _async_to_generator(function() {
|
|
8703
|
+
var error, _error_cause, _error_message, _error_cause_message, event;
|
|
8704
|
+
return _ts_generator(this, function(_state) {
|
|
8705
|
+
switch(_state.label){
|
|
8706
|
+
case 0:
|
|
8707
|
+
_state.trys.push([
|
|
8708
|
+
0,
|
|
8709
|
+
2,
|
|
8710
|
+
,
|
|
8711
|
+
3
|
|
8712
|
+
]);
|
|
8713
|
+
return [
|
|
8714
|
+
4,
|
|
8715
|
+
runAdapter.handleRun({
|
|
8716
|
+
threadId: threadId,
|
|
8717
|
+
assistantId: azureAgentId,
|
|
8718
|
+
instructions: instructions,
|
|
8719
|
+
tools: tools,
|
|
8720
|
+
onEvent: function(event) {
|
|
8721
|
+
return _async_to_generator(function() {
|
|
8722
|
+
return _ts_generator(this, function(_state) {
|
|
8723
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
8724
|
+
return [
|
|
8725
|
+
2
|
|
8726
|
+
];
|
|
8727
|
+
});
|
|
8728
|
+
})();
|
|
8729
|
+
}
|
|
8730
|
+
})
|
|
8731
|
+
];
|
|
8732
|
+
case 1:
|
|
8733
|
+
_state.sent();
|
|
8734
|
+
return [
|
|
8735
|
+
3,
|
|
8736
|
+
3
|
|
8737
|
+
];
|
|
8738
|
+
case 2:
|
|
8739
|
+
error = _state.sent();
|
|
8740
|
+
console.error(error);
|
|
8741
|
+
event = {
|
|
8742
|
+
event: "thread.run.failed",
|
|
8743
|
+
data: {
|
|
8744
|
+
id: uid8(24),
|
|
8745
|
+
failed_at: dayjs24().unix(),
|
|
8746
|
+
last_error: {
|
|
8747
|
+
code: "server_error",
|
|
8748
|
+
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 : "")
|
|
8749
|
+
}
|
|
8750
|
+
}
|
|
8751
|
+
};
|
|
8752
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
8753
|
+
return [
|
|
8754
|
+
3,
|
|
8755
|
+
3
|
|
8756
|
+
];
|
|
8757
|
+
case 3:
|
|
8758
|
+
controller.close();
|
|
8759
|
+
return [
|
|
8760
|
+
2
|
|
8761
|
+
];
|
|
8762
|
+
}
|
|
8763
|
+
});
|
|
8764
|
+
})();
|
|
8765
|
+
}
|
|
8766
|
+
});
|
|
8767
|
+
return [
|
|
8768
|
+
2,
|
|
8769
|
+
new Response(readableStream, {
|
|
8770
|
+
headers: {
|
|
8771
|
+
"Content-Type": "text/event-stream"
|
|
8772
|
+
}
|
|
8773
|
+
})
|
|
8774
|
+
];
|
|
8775
|
+
case 1:
|
|
8776
|
+
retries = 0;
|
|
8777
|
+
maxRetries = 10;
|
|
8778
|
+
_state.label = 2;
|
|
8779
|
+
case 2:
|
|
8780
|
+
if (!(retries < maxRetries)) return [
|
|
8781
|
+
3,
|
|
8782
|
+
17
|
|
8783
|
+
];
|
|
8784
|
+
_state.label = 3;
|
|
8785
|
+
case 3:
|
|
8786
|
+
_state.trys.push([
|
|
8787
|
+
3,
|
|
8788
|
+
5,
|
|
8789
|
+
,
|
|
8790
|
+
16
|
|
8791
|
+
]);
|
|
8792
|
+
createOptions = {};
|
|
8793
|
+
if (instructions) {
|
|
8794
|
+
createOptions.instructions = instructions;
|
|
8795
|
+
}
|
|
8796
|
+
if (tools) {
|
|
8797
|
+
createOptions.tools = tools;
|
|
8798
|
+
}
|
|
8799
|
+
return [
|
|
8800
|
+
4,
|
|
8801
|
+
azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions)
|
|
8802
|
+
];
|
|
8803
|
+
case 4:
|
|
8804
|
+
azureRun = _state.sent();
|
|
8805
|
+
return [
|
|
8806
|
+
3,
|
|
8807
|
+
17
|
|
8808
|
+
];
|
|
8809
|
+
case 5:
|
|
8810
|
+
error = _state.sent();
|
|
8811
|
+
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) || "";
|
|
8812
|
+
if (!errorMessage.includes("already has an active run")) return [
|
|
8813
|
+
3,
|
|
8814
|
+
14
|
|
8815
|
+
];
|
|
8816
|
+
runIdMatch = errorMessage.match(/run_[a-zA-Z0-9]+/);
|
|
8817
|
+
if (!runIdMatch) return [
|
|
8818
|
+
3,
|
|
8819
|
+
11
|
|
8820
|
+
];
|
|
8821
|
+
activeRunId = runIdMatch[0];
|
|
8822
|
+
return [
|
|
8823
|
+
4,
|
|
8824
|
+
azureAiProject.agents.runs.get(threadId, activeRunId)
|
|
8825
|
+
];
|
|
8826
|
+
case 6:
|
|
8827
|
+
activeRun = _state.sent();
|
|
8828
|
+
_state.label = 7;
|
|
8829
|
+
case 7:
|
|
8830
|
+
if (!(activeRun.status === "queued" || activeRun.status === "in_progress")) return [
|
|
8831
|
+
3,
|
|
8832
|
+
10
|
|
8833
|
+
];
|
|
8834
|
+
return [
|
|
8835
|
+
4,
|
|
8836
|
+
new Promise(function(resolve) {
|
|
8837
|
+
return setTimeout(resolve, 500);
|
|
8838
|
+
})
|
|
8839
|
+
];
|
|
8840
|
+
case 8:
|
|
8841
|
+
_state.sent();
|
|
8842
|
+
return [
|
|
8843
|
+
4,
|
|
8844
|
+
azureAiProject.agents.runs.get(threadId, activeRunId)
|
|
8845
|
+
];
|
|
8846
|
+
case 9:
|
|
8847
|
+
activeRun = _state.sent();
|
|
8848
|
+
return [
|
|
8849
|
+
3,
|
|
8850
|
+
7
|
|
8851
|
+
];
|
|
8852
|
+
case 10:
|
|
8853
|
+
if (activeRun.status === "requires_action") {
|
|
8854
|
+
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)"));
|
|
8855
|
+
}
|
|
8856
|
+
return [
|
|
8857
|
+
3,
|
|
8858
|
+
13
|
|
8859
|
+
];
|
|
8860
|
+
case 11:
|
|
8861
|
+
return [
|
|
8862
|
+
4,
|
|
8863
|
+
new Promise(function(resolve) {
|
|
8864
|
+
return setTimeout(resolve, 1e3 * Math.pow(2, retries));
|
|
8865
|
+
})
|
|
8866
|
+
];
|
|
8867
|
+
case 12:
|
|
8868
|
+
_state.sent();
|
|
8869
|
+
_state.label = 13;
|
|
8870
|
+
case 13:
|
|
8871
|
+
retries++;
|
|
8872
|
+
return [
|
|
8873
|
+
3,
|
|
8874
|
+
15
|
|
8875
|
+
];
|
|
8876
|
+
case 14:
|
|
8877
|
+
throw error;
|
|
8878
|
+
case 15:
|
|
8879
|
+
return [
|
|
8880
|
+
3,
|
|
8881
|
+
16
|
|
8882
|
+
];
|
|
8883
|
+
case 16:
|
|
8884
|
+
return [
|
|
8885
|
+
3,
|
|
8886
|
+
2
|
|
8887
|
+
];
|
|
8888
|
+
case 17:
|
|
8889
|
+
if (!azureRun) {
|
|
8890
|
+
throw new Error("Failed to create run after ".concat(maxRetries, " retries"));
|
|
8891
|
+
}
|
|
8892
|
+
runData = {
|
|
8893
|
+
id: azureRun.id,
|
|
8894
|
+
object: "thread.run",
|
|
8895
|
+
created_at: dayjs24(azureRun.createdAt).unix(),
|
|
8896
|
+
thread_id: azureRun.threadId,
|
|
8897
|
+
assistant_id: azureAgentId,
|
|
8898
|
+
status: azureRun.status,
|
|
8899
|
+
required_action: null,
|
|
8900
|
+
last_error: null,
|
|
8901
|
+
expires_at: null,
|
|
8902
|
+
started_at: azureRun.status === "in_progress" ? dayjs24(azureRun.createdAt).unix() : null,
|
|
8903
|
+
cancelled_at: null,
|
|
8904
|
+
failed_at: null,
|
|
8905
|
+
completed_at: null,
|
|
8906
|
+
incomplete_details: null,
|
|
8907
|
+
model: "",
|
|
8908
|
+
instructions: "",
|
|
8909
|
+
tools: [],
|
|
8910
|
+
metadata: azureRun.metadata || {},
|
|
8911
|
+
temperature: null,
|
|
8912
|
+
top_p: null,
|
|
8913
|
+
max_prompt_tokens: null,
|
|
8914
|
+
max_completion_tokens: null,
|
|
8915
|
+
truncation_strategy: {
|
|
8916
|
+
type: "auto",
|
|
8917
|
+
last_messages: null
|
|
8918
|
+
},
|
|
8919
|
+
response_format: "auto",
|
|
8920
|
+
tool_choice: "auto",
|
|
8921
|
+
parallel_tool_calls: true,
|
|
8922
|
+
usage: null
|
|
8923
|
+
};
|
|
8924
|
+
return [
|
|
8925
|
+
2,
|
|
8926
|
+
new Response(JSON.stringify(runData), {
|
|
8927
|
+
status: 200,
|
|
8928
|
+
headers: {
|
|
8929
|
+
"Content-Type": "application/json"
|
|
8930
|
+
}
|
|
8931
|
+
})
|
|
8932
|
+
];
|
|
8933
|
+
case 18:
|
|
8934
|
+
return [
|
|
8935
|
+
2
|
|
8936
|
+
];
|
|
8937
|
+
}
|
|
8938
|
+
});
|
|
8939
|
+
})();
|
|
8940
|
+
};
|
|
8941
|
+
};
|
|
8942
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/index.ts
|
|
8943
|
+
var runs3 = function(param) {
|
|
8944
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8945
|
+
return {
|
|
8946
|
+
get: get20(),
|
|
8947
|
+
post: post22({
|
|
8948
|
+
azureAiProject: azureAiProject,
|
|
8949
|
+
runAdapter: runAdapter
|
|
8950
|
+
})
|
|
8951
|
+
};
|
|
8952
|
+
};
|
|
8953
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/run/get.ts
|
|
8954
|
+
import dayjs25 from "dayjs";
|
|
8955
|
+
var get21 = function(param) {
|
|
8956
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
8957
|
+
return function(urlString) {
|
|
8958
|
+
return _async_to_generator(function() {
|
|
8959
|
+
var url, _url_pathname_match, threadId, runId, azureRun, assistantId, openaiRun;
|
|
8960
|
+
return _ts_generator(this, function(_state) {
|
|
8961
|
+
switch(_state.label){
|
|
8962
|
+
case 0:
|
|
8963
|
+
url = new URL(urlString);
|
|
8964
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
8965
|
+
return [
|
|
8966
|
+
4,
|
|
8967
|
+
azureAiProject.agents.runs.get(threadId, runId)
|
|
8968
|
+
];
|
|
8969
|
+
case 1:
|
|
8970
|
+
azureRun = _state.sent();
|
|
8971
|
+
assistantId = azureRun.assistantId;
|
|
8972
|
+
openaiRun = {
|
|
8973
|
+
id: azureRun.id,
|
|
8974
|
+
object: "thread.run",
|
|
8975
|
+
created_at: dayjs25(azureRun.createdAt).unix(),
|
|
8976
|
+
thread_id: azureRun.threadId,
|
|
8977
|
+
assistant_id: assistantId,
|
|
8978
|
+
status: azureRun.status,
|
|
8979
|
+
required_action: azureRun.status === "requires_action" && azureRun.requiredAction ? {
|
|
8980
|
+
type: "submit_tool_outputs",
|
|
8981
|
+
submit_tool_outputs: {
|
|
8982
|
+
tool_calls: azureRun.requiredAction.submitToolOutputs.toolCalls.map(function(tc) {
|
|
8983
|
+
return {
|
|
8984
|
+
id: tc.id,
|
|
8985
|
+
type: "function",
|
|
8986
|
+
function: {
|
|
8987
|
+
name: tc.function.name,
|
|
8988
|
+
arguments: tc.function.arguments
|
|
8989
|
+
}
|
|
8990
|
+
};
|
|
8991
|
+
})
|
|
8992
|
+
}
|
|
8993
|
+
} : null,
|
|
8994
|
+
last_error: azureRun.lastError ? {
|
|
8995
|
+
code: "server_error",
|
|
8996
|
+
message: JSON.stringify(azureRun.lastError)
|
|
8997
|
+
} : null,
|
|
8998
|
+
expires_at: null,
|
|
8999
|
+
started_at: dayjs25(azureRun.createdAt).unix(),
|
|
9000
|
+
cancelled_at: null,
|
|
9001
|
+
failed_at: azureRun.status === "failed" ? dayjs25().unix() : null,
|
|
9002
|
+
completed_at: azureRun.status === "completed" ? dayjs25().unix() : null,
|
|
9003
|
+
incomplete_details: null,
|
|
9004
|
+
model: "",
|
|
9005
|
+
instructions: "",
|
|
9006
|
+
tools: [],
|
|
9007
|
+
metadata: azureRun.metadata || {},
|
|
9008
|
+
temperature: null,
|
|
9009
|
+
top_p: null,
|
|
9010
|
+
max_prompt_tokens: null,
|
|
9011
|
+
max_completion_tokens: null,
|
|
9012
|
+
truncation_strategy: {
|
|
9013
|
+
type: "auto",
|
|
9014
|
+
last_messages: null
|
|
9015
|
+
},
|
|
9016
|
+
response_format: "auto",
|
|
9017
|
+
tool_choice: "auto",
|
|
9018
|
+
parallel_tool_calls: true,
|
|
9019
|
+
usage: null
|
|
9020
|
+
};
|
|
9021
|
+
return [
|
|
9022
|
+
2,
|
|
9023
|
+
new Response(JSON.stringify(openaiRun), {
|
|
9024
|
+
status: 200,
|
|
9025
|
+
headers: {
|
|
9026
|
+
"Content-Type": "application/json"
|
|
9027
|
+
}
|
|
9028
|
+
})
|
|
9029
|
+
];
|
|
9030
|
+
}
|
|
9031
|
+
});
|
|
9032
|
+
})();
|
|
9033
|
+
};
|
|
9034
|
+
};
|
|
9035
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/run/index.ts
|
|
9036
|
+
var run3 = function(param) {
|
|
9037
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9038
|
+
return {
|
|
9039
|
+
get: get21({
|
|
9040
|
+
azureAiProject: azureAiProject,
|
|
9041
|
+
runAdapter: runAdapter
|
|
9042
|
+
})
|
|
9043
|
+
};
|
|
9044
|
+
};
|
|
9045
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/get.ts
|
|
9046
|
+
import dayjs26 from "dayjs";
|
|
9047
|
+
var get22 = function(param) {
|
|
9048
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9049
|
+
return function(urlString) {
|
|
9050
|
+
return _async_to_generator(function() {
|
|
9051
|
+
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;
|
|
9052
|
+
return _ts_generator(this, function(_state) {
|
|
9053
|
+
switch(_state.label){
|
|
9054
|
+
case 0:
|
|
9055
|
+
url = new URL(urlString);
|
|
9056
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
9057
|
+
return [
|
|
9058
|
+
4,
|
|
9059
|
+
azureAiProject.agents.runSteps.list(threadId, runId)
|
|
9060
|
+
];
|
|
9061
|
+
case 1:
|
|
9062
|
+
azureSteps = _state.sent();
|
|
9063
|
+
return [
|
|
9064
|
+
4,
|
|
9065
|
+
runAdapter.getOpenaiAssistant({
|
|
9066
|
+
select: {
|
|
9067
|
+
id: true
|
|
9068
|
+
}
|
|
9069
|
+
})
|
|
9070
|
+
];
|
|
9071
|
+
case 2:
|
|
9072
|
+
openaiAssistant = _state.sent();
|
|
9073
|
+
stepsList = [];
|
|
9074
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9075
|
+
_state.label = 3;
|
|
9076
|
+
case 3:
|
|
9077
|
+
_state.trys.push([
|
|
9078
|
+
3,
|
|
9079
|
+
8,
|
|
9080
|
+
9,
|
|
9081
|
+
14
|
|
9082
|
+
]);
|
|
9083
|
+
_iterator = _async_iterator(azureSteps);
|
|
9084
|
+
_state.label = 4;
|
|
9085
|
+
case 4:
|
|
9086
|
+
return [
|
|
9087
|
+
4,
|
|
9088
|
+
_iterator.next()
|
|
9089
|
+
];
|
|
9090
|
+
case 5:
|
|
9091
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9092
|
+
3,
|
|
9093
|
+
7
|
|
9094
|
+
];
|
|
9095
|
+
_value = _step.value;
|
|
9096
|
+
step = _value;
|
|
9097
|
+
stepsList.push({
|
|
9098
|
+
id: step.id,
|
|
9099
|
+
object: "thread.run.step",
|
|
9100
|
+
created_at: dayjs26(step.createdAt).unix(),
|
|
9101
|
+
assistant_id: openaiAssistant.id,
|
|
9102
|
+
thread_id: threadId,
|
|
9103
|
+
run_id: runId,
|
|
9104
|
+
type: step.type === "tool_calls" ? "tool_calls" : "message_creation",
|
|
9105
|
+
status: step.status,
|
|
9106
|
+
step_details: step.type === "tool_calls" ? {
|
|
9107
|
+
type: "tool_calls",
|
|
9108
|
+
tool_calls: step.stepDetails.toolCalls.map(function(tc) {
|
|
9109
|
+
if (tc.type === "code_interpreter") {
|
|
9110
|
+
var _tc_codeInterpreter, _tc_codeInterpreter_outputs, _tc_codeInterpreter1;
|
|
9111
|
+
return {
|
|
9112
|
+
id: tc.id,
|
|
9113
|
+
type: "code_interpreter",
|
|
9114
|
+
code_interpreter: {
|
|
9115
|
+
input: ((_tc_codeInterpreter = tc.codeInterpreter) === null || _tc_codeInterpreter === void 0 ? void 0 : _tc_codeInterpreter.input) || "",
|
|
9116
|
+
outputs: ((_tc_codeInterpreter1 = tc.codeInterpreter) === null || _tc_codeInterpreter1 === void 0 ? void 0 : (_tc_codeInterpreter_outputs = _tc_codeInterpreter1.outputs) === null || _tc_codeInterpreter_outputs === void 0 ? void 0 : _tc_codeInterpreter_outputs.map(function(output) {
|
|
9117
|
+
if (output.type === "logs") {
|
|
9118
|
+
return {
|
|
9119
|
+
type: "logs",
|
|
9120
|
+
logs: output.logs || ""
|
|
9121
|
+
};
|
|
9122
|
+
}
|
|
9123
|
+
if (output.type === "image") {
|
|
9124
|
+
var _output_image;
|
|
9125
|
+
return {
|
|
9126
|
+
type: "image",
|
|
9127
|
+
image: {
|
|
9128
|
+
file_id: ((_output_image = output.image) === null || _output_image === void 0 ? void 0 : _output_image.fileId) || ""
|
|
9129
|
+
}
|
|
9130
|
+
};
|
|
9131
|
+
}
|
|
9132
|
+
return output;
|
|
9133
|
+
})) || []
|
|
9134
|
+
}
|
|
9135
|
+
};
|
|
9136
|
+
} else if (tc.type === "file_search") {
|
|
9137
|
+
return {
|
|
9138
|
+
id: tc.id,
|
|
9139
|
+
type: "file_search",
|
|
9140
|
+
file_search: tc.fileSearch || {}
|
|
9141
|
+
};
|
|
9142
|
+
} else if (tc.type === "function") {
|
|
9143
|
+
return {
|
|
9144
|
+
id: tc.id,
|
|
9145
|
+
type: "function",
|
|
9146
|
+
function: {
|
|
9147
|
+
name: tc.function.name,
|
|
9148
|
+
arguments: tc.function.arguments,
|
|
9149
|
+
output: tc.function.output || null
|
|
9150
|
+
}
|
|
9151
|
+
};
|
|
9152
|
+
}
|
|
9153
|
+
return tc;
|
|
9154
|
+
})
|
|
9155
|
+
} : {
|
|
9156
|
+
type: "message_creation",
|
|
9157
|
+
message_creation: {
|
|
9158
|
+
message_id: (_step_stepDetails_messageCreation = step.stepDetails.messageCreation) === null || _step_stepDetails_messageCreation === void 0 ? void 0 : _step_stepDetails_messageCreation.messageId
|
|
9159
|
+
}
|
|
9160
|
+
},
|
|
9161
|
+
last_error: null,
|
|
9162
|
+
expired_at: null,
|
|
9163
|
+
cancelled_at: null,
|
|
9164
|
+
failed_at: null,
|
|
9165
|
+
completed_at: step.completedAt ? dayjs26(step.completedAt).unix() : null,
|
|
9166
|
+
metadata: step.metadata || {},
|
|
9167
|
+
usage: null
|
|
9168
|
+
});
|
|
9169
|
+
_state.label = 6;
|
|
9170
|
+
case 6:
|
|
9171
|
+
_iteratorAbruptCompletion = false;
|
|
9172
|
+
return [
|
|
9173
|
+
3,
|
|
9174
|
+
4
|
|
9175
|
+
];
|
|
9176
|
+
case 7:
|
|
9177
|
+
return [
|
|
9178
|
+
3,
|
|
9179
|
+
14
|
|
9180
|
+
];
|
|
9181
|
+
case 8:
|
|
9182
|
+
err = _state.sent();
|
|
9183
|
+
_didIteratorError = true;
|
|
9184
|
+
_iteratorError = err;
|
|
9185
|
+
return [
|
|
9186
|
+
3,
|
|
9187
|
+
14
|
|
9188
|
+
];
|
|
9189
|
+
case 9:
|
|
9190
|
+
_state.trys.push([
|
|
9191
|
+
9,
|
|
9192
|
+
,
|
|
9193
|
+
12,
|
|
9194
|
+
13
|
|
9195
|
+
]);
|
|
9196
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
9197
|
+
3,
|
|
9198
|
+
11
|
|
9199
|
+
];
|
|
9200
|
+
return [
|
|
9201
|
+
4,
|
|
9202
|
+
_iterator.return()
|
|
9203
|
+
];
|
|
9204
|
+
case 10:
|
|
9205
|
+
_state.sent();
|
|
9206
|
+
_state.label = 11;
|
|
9207
|
+
case 11:
|
|
9208
|
+
return [
|
|
9209
|
+
3,
|
|
9210
|
+
13
|
|
9211
|
+
];
|
|
9212
|
+
case 12:
|
|
9213
|
+
if (_didIteratorError) {
|
|
9214
|
+
throw _iteratorError;
|
|
9215
|
+
}
|
|
9216
|
+
return [
|
|
9217
|
+
7
|
|
9218
|
+
];
|
|
9219
|
+
case 13:
|
|
9220
|
+
return [
|
|
9221
|
+
7
|
|
9222
|
+
];
|
|
9223
|
+
case 14:
|
|
9224
|
+
response = {
|
|
9225
|
+
data: stepsList,
|
|
9226
|
+
first_id: ((_stepsList_ = stepsList[0]) === null || _stepsList_ === void 0 ? void 0 : _stepsList_.id) || null,
|
|
9227
|
+
last_id: ((_stepsList_1 = stepsList[stepsList.length - 1]) === null || _stepsList_1 === void 0 ? void 0 : _stepsList_1.id) || null,
|
|
9228
|
+
has_more: false
|
|
9229
|
+
};
|
|
9230
|
+
return [
|
|
9231
|
+
2,
|
|
9232
|
+
new Response(JSON.stringify(response), {
|
|
9233
|
+
status: 200,
|
|
9234
|
+
headers: {
|
|
9235
|
+
"Content-Type": "application/json"
|
|
9236
|
+
}
|
|
9237
|
+
})
|
|
9238
|
+
];
|
|
9239
|
+
}
|
|
9240
|
+
});
|
|
9241
|
+
})();
|
|
9242
|
+
};
|
|
9243
|
+
};
|
|
9244
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/index.ts
|
|
9245
|
+
var steps3 = function(param) {
|
|
9246
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9247
|
+
return {
|
|
9248
|
+
get: get22({
|
|
9249
|
+
azureAiProject: azureAiProject,
|
|
9250
|
+
runAdapter: runAdapter
|
|
9251
|
+
})
|
|
9252
|
+
};
|
|
9253
|
+
};
|
|
9254
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
|
|
9255
|
+
import dayjs27 from "dayjs";
|
|
9256
|
+
function convertAzureEventToOpenAI(azureEvent, assistantId) {
|
|
9257
|
+
var event = azureEvent.event, data = azureEvent.data;
|
|
9258
|
+
var eventType = event;
|
|
9259
|
+
if (eventType.startsWith("thread.run.")) {
|
|
9260
|
+
var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
|
|
9261
|
+
var _data_temperature, _data_topP;
|
|
9262
|
+
return {
|
|
9263
|
+
event: eventType,
|
|
9264
|
+
data: {
|
|
9265
|
+
id: data.id,
|
|
9266
|
+
object: "thread.run",
|
|
9267
|
+
created_at: dayjs27(data.createdAt).unix(),
|
|
9268
|
+
thread_id: data.threadId,
|
|
9269
|
+
assistant_id: assistantId,
|
|
9270
|
+
status: data.status,
|
|
9271
|
+
required_action: data.requiredAction ? {
|
|
9272
|
+
type: "submit_tool_outputs",
|
|
9273
|
+
submit_tool_outputs: {
|
|
9274
|
+
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) {
|
|
9275
|
+
return {
|
|
9276
|
+
id: tc.id,
|
|
9277
|
+
type: "function",
|
|
9278
|
+
function: {
|
|
9279
|
+
name: tc.function.name,
|
|
9280
|
+
arguments: tc.function.arguments
|
|
9281
|
+
}
|
|
9282
|
+
};
|
|
9283
|
+
})) || []
|
|
9284
|
+
}
|
|
9285
|
+
} : null,
|
|
9286
|
+
last_error: data.lastError ? {
|
|
9287
|
+
code: "server_error",
|
|
9288
|
+
message: JSON.stringify(data.lastError)
|
|
9289
|
+
} : null,
|
|
9290
|
+
expires_at: null,
|
|
9291
|
+
started_at: data.startedAt ? dayjs27(data.startedAt).unix() : null,
|
|
9292
|
+
cancelled_at: data.cancelledAt ? dayjs27(data.cancelledAt).unix() : null,
|
|
9293
|
+
failed_at: data.failedAt ? dayjs27(data.failedAt).unix() : null,
|
|
9294
|
+
completed_at: data.completedAt ? dayjs27(data.completedAt).unix() : null,
|
|
9295
|
+
incomplete_details: null,
|
|
9296
|
+
model: data.model || "",
|
|
9297
|
+
instructions: data.instructions || "",
|
|
9298
|
+
tools: data.tools || [],
|
|
9299
|
+
metadata: data.metadata || {},
|
|
9300
|
+
temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
|
|
9301
|
+
top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
|
|
9302
|
+
max_prompt_tokens: null,
|
|
9303
|
+
max_completion_tokens: null,
|
|
9304
|
+
truncation_strategy: {
|
|
9305
|
+
type: "auto",
|
|
9306
|
+
last_messages: null
|
|
9307
|
+
},
|
|
9308
|
+
response_format: "auto",
|
|
9309
|
+
tool_choice: "auto",
|
|
9310
|
+
parallel_tool_calls: true,
|
|
9311
|
+
usage: null
|
|
9312
|
+
}
|
|
9313
|
+
};
|
|
9314
|
+
}
|
|
9315
|
+
if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
|
|
9316
|
+
var _data_content;
|
|
9317
|
+
return {
|
|
9318
|
+
event: eventType,
|
|
9319
|
+
data: {
|
|
9320
|
+
id: data.id,
|
|
9321
|
+
object: "thread.message",
|
|
9322
|
+
created_at: dayjs27(data.createdAt).unix(),
|
|
9323
|
+
thread_id: data.threadId,
|
|
9324
|
+
role: data.role,
|
|
9325
|
+
content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
|
|
9326
|
+
if (c.type === "text") {
|
|
9327
|
+
var _c_text, _c_text1;
|
|
9328
|
+
return {
|
|
9329
|
+
type: "text",
|
|
9330
|
+
text: {
|
|
9331
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
9332
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
9333
|
+
}
|
|
9334
|
+
};
|
|
9335
|
+
}
|
|
9336
|
+
return c;
|
|
9337
|
+
})) || [],
|
|
9338
|
+
assistant_id: assistantId,
|
|
9339
|
+
run_id: data.runId || null,
|
|
9340
|
+
attachments: data.attachments || [],
|
|
9341
|
+
metadata: data.metadata || {},
|
|
9342
|
+
status: data.status || "completed",
|
|
9343
|
+
completed_at: data.completedAt ? dayjs27(data.completedAt).unix() : null,
|
|
9344
|
+
incomplete_at: null,
|
|
9345
|
+
incomplete_details: null
|
|
9346
|
+
}
|
|
9347
|
+
};
|
|
9348
|
+
}
|
|
9349
|
+
if (eventType === "thread.message.delta") {
|
|
9350
|
+
var _data_delta_content, _data_delta;
|
|
9351
|
+
return {
|
|
9352
|
+
event: "thread.message.delta",
|
|
9353
|
+
data: {
|
|
9354
|
+
id: data.id,
|
|
9355
|
+
object: "thread.message.delta",
|
|
9356
|
+
delta: {
|
|
9357
|
+
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) {
|
|
9358
|
+
if (c.type === "text") {
|
|
9359
|
+
var _c_text, _c_text1;
|
|
9360
|
+
return {
|
|
9361
|
+
index: c.index || 0,
|
|
9362
|
+
type: "text",
|
|
9363
|
+
text: {
|
|
9364
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
9365
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
9366
|
+
}
|
|
9367
|
+
};
|
|
9368
|
+
}
|
|
9369
|
+
return c;
|
|
9370
|
+
})) || []
|
|
9371
|
+
}
|
|
9372
|
+
}
|
|
9373
|
+
};
|
|
9374
|
+
}
|
|
9375
|
+
return null;
|
|
9376
|
+
}
|
|
9377
|
+
var post23 = function(param) {
|
|
9378
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9379
|
+
return function(urlString, options) {
|
|
9380
|
+
return _async_to_generator(function() {
|
|
9381
|
+
var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, existingRun, assistantId, submitResponse, streamRun, readableStream, events, finalRun;
|
|
9382
|
+
return _ts_generator(this, function(_state) {
|
|
9383
|
+
switch(_state.label){
|
|
9384
|
+
case 0:
|
|
9385
|
+
url = new URL(urlString);
|
|
9386
|
+
_url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(submitToolOutputsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
|
|
9387
|
+
if (typeof options.body !== "string") {
|
|
9388
|
+
throw new Error("Request body is required");
|
|
9389
|
+
}
|
|
9390
|
+
body = JSON.parse(options.body);
|
|
9391
|
+
tool_outputs = body.tool_outputs, stream = body.stream;
|
|
9392
|
+
return [
|
|
9393
|
+
4,
|
|
9394
|
+
azureAiProject.agents.runs.get(threadId, runId)
|
|
9395
|
+
];
|
|
9396
|
+
case 1:
|
|
9397
|
+
existingRun = _state.sent();
|
|
9398
|
+
assistantId = existingRun.assistantId;
|
|
9399
|
+
submitResponse = azureAiProject.agents.runs.submitToolOutputs(threadId, runId, tool_outputs.map(function(to) {
|
|
9400
|
+
return {
|
|
9401
|
+
toolCallId: to.tool_call_id,
|
|
9402
|
+
output: to.output
|
|
9403
|
+
};
|
|
9404
|
+
}));
|
|
9405
|
+
streamRun = function(onEvent2) {
|
|
9406
|
+
return _async_to_generator(function() {
|
|
9407
|
+
var stream2, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, error, _error_cause, _error_message, _error_cause_message;
|
|
9408
|
+
return _ts_generator(this, function(_state) {
|
|
9409
|
+
switch(_state.label){
|
|
9410
|
+
case 0:
|
|
9411
|
+
_state.trys.push([
|
|
9412
|
+
0,
|
|
9413
|
+
15,
|
|
9414
|
+
,
|
|
9415
|
+
17
|
|
9416
|
+
]);
|
|
9417
|
+
return [
|
|
9418
|
+
4,
|
|
9419
|
+
submitResponse.stream()
|
|
9420
|
+
];
|
|
9421
|
+
case 1:
|
|
9422
|
+
stream2 = _state.sent();
|
|
9423
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9424
|
+
_state.label = 2;
|
|
9425
|
+
case 2:
|
|
9426
|
+
_state.trys.push([
|
|
9427
|
+
2,
|
|
9428
|
+
8,
|
|
9429
|
+
9,
|
|
9430
|
+
14
|
|
9431
|
+
]);
|
|
9432
|
+
_iterator = _async_iterator(stream2);
|
|
9433
|
+
_state.label = 3;
|
|
9434
|
+
case 3:
|
|
9435
|
+
return [
|
|
9436
|
+
4,
|
|
9437
|
+
_iterator.next()
|
|
9438
|
+
];
|
|
9439
|
+
case 4:
|
|
9440
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9441
|
+
3,
|
|
9442
|
+
7
|
|
9443
|
+
];
|
|
9444
|
+
_value = _step.value;
|
|
9445
|
+
azureEvent = _value;
|
|
9446
|
+
openaiEvent = convertAzureEventToOpenAI(azureEvent, assistantId);
|
|
9447
|
+
if (!openaiEvent) return [
|
|
9448
|
+
3,
|
|
9449
|
+
6
|
|
9450
|
+
];
|
|
9451
|
+
return [
|
|
9452
|
+
4,
|
|
9453
|
+
onEvent2(openaiEvent)
|
|
9454
|
+
];
|
|
9455
|
+
case 5:
|
|
9456
|
+
_state.sent();
|
|
9457
|
+
_state.label = 6;
|
|
9458
|
+
case 6:
|
|
9459
|
+
_iteratorAbruptCompletion = false;
|
|
9460
|
+
return [
|
|
9461
|
+
3,
|
|
9462
|
+
3
|
|
9463
|
+
];
|
|
9464
|
+
case 7:
|
|
9465
|
+
return [
|
|
9466
|
+
3,
|
|
9467
|
+
14
|
|
9468
|
+
];
|
|
9469
|
+
case 8:
|
|
9470
|
+
err = _state.sent();
|
|
9471
|
+
_didIteratorError = true;
|
|
9472
|
+
_iteratorError = err;
|
|
9473
|
+
return [
|
|
9474
|
+
3,
|
|
9475
|
+
14
|
|
9476
|
+
];
|
|
9477
|
+
case 9:
|
|
9478
|
+
_state.trys.push([
|
|
9479
|
+
9,
|
|
9480
|
+
,
|
|
9481
|
+
12,
|
|
9482
|
+
13
|
|
9483
|
+
]);
|
|
9484
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
9485
|
+
3,
|
|
9486
|
+
11
|
|
9487
|
+
];
|
|
9488
|
+
return [
|
|
9489
|
+
4,
|
|
9490
|
+
_iterator.return()
|
|
9491
|
+
];
|
|
9492
|
+
case 10:
|
|
9493
|
+
_state.sent();
|
|
9494
|
+
_state.label = 11;
|
|
9495
|
+
case 11:
|
|
9496
|
+
return [
|
|
9497
|
+
3,
|
|
9498
|
+
13
|
|
9499
|
+
];
|
|
9500
|
+
case 12:
|
|
9501
|
+
if (_didIteratorError) {
|
|
9502
|
+
throw _iteratorError;
|
|
9503
|
+
}
|
|
9504
|
+
return [
|
|
9505
|
+
7
|
|
9506
|
+
];
|
|
9507
|
+
case 13:
|
|
9508
|
+
return [
|
|
9509
|
+
7
|
|
9510
|
+
];
|
|
9511
|
+
case 14:
|
|
9512
|
+
return [
|
|
9513
|
+
3,
|
|
9514
|
+
17
|
|
9515
|
+
];
|
|
9516
|
+
case 15:
|
|
9517
|
+
error = _state.sent();
|
|
9518
|
+
return [
|
|
9519
|
+
4,
|
|
9520
|
+
onEvent2({
|
|
9521
|
+
event: "thread.run.failed",
|
|
9522
|
+
data: {
|
|
9523
|
+
id: runId,
|
|
9524
|
+
object: "thread.run",
|
|
9525
|
+
created_at: dayjs27().unix(),
|
|
9526
|
+
thread_id: threadId,
|
|
9527
|
+
assistant_id: assistantId,
|
|
9528
|
+
status: "failed",
|
|
9529
|
+
required_action: null,
|
|
9530
|
+
last_error: {
|
|
9531
|
+
code: "server_error",
|
|
9532
|
+
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 : "")
|
|
9533
|
+
},
|
|
9534
|
+
expires_at: null,
|
|
9535
|
+
started_at: dayjs27().unix(),
|
|
9536
|
+
cancelled_at: null,
|
|
9537
|
+
failed_at: dayjs27().unix(),
|
|
9538
|
+
completed_at: null,
|
|
9539
|
+
incomplete_details: null,
|
|
9540
|
+
model: "",
|
|
9541
|
+
instructions: "",
|
|
9542
|
+
tools: [],
|
|
9543
|
+
metadata: {},
|
|
9544
|
+
temperature: null,
|
|
9545
|
+
top_p: null,
|
|
9546
|
+
max_prompt_tokens: null,
|
|
9547
|
+
max_completion_tokens: null,
|
|
9548
|
+
truncation_strategy: {
|
|
9549
|
+
type: "auto",
|
|
9550
|
+
last_messages: null
|
|
9551
|
+
},
|
|
9552
|
+
response_format: "auto",
|
|
9553
|
+
tool_choice: "auto",
|
|
9554
|
+
parallel_tool_calls: true,
|
|
9555
|
+
usage: null
|
|
9556
|
+
}
|
|
9557
|
+
})
|
|
9558
|
+
];
|
|
9559
|
+
case 16:
|
|
9560
|
+
_state.sent();
|
|
9561
|
+
return [
|
|
9562
|
+
3,
|
|
9563
|
+
17
|
|
9564
|
+
];
|
|
9565
|
+
case 17:
|
|
9566
|
+
return [
|
|
9567
|
+
2
|
|
9568
|
+
];
|
|
9569
|
+
}
|
|
9570
|
+
});
|
|
9571
|
+
})();
|
|
9572
|
+
};
|
|
9573
|
+
readableStream = new ReadableStream({
|
|
9574
|
+
start: function start(controller) {
|
|
9575
|
+
return _async_to_generator(function() {
|
|
9576
|
+
return _ts_generator(this, function(_state) {
|
|
9577
|
+
switch(_state.label){
|
|
9578
|
+
case 0:
|
|
9579
|
+
return [
|
|
9580
|
+
4,
|
|
9581
|
+
streamRun(function(event) {
|
|
9582
|
+
return _async_to_generator(function() {
|
|
9583
|
+
return _ts_generator(this, function(_state) {
|
|
9584
|
+
controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
|
|
9585
|
+
return [
|
|
9586
|
+
2
|
|
9587
|
+
];
|
|
9588
|
+
});
|
|
9589
|
+
})();
|
|
9590
|
+
})
|
|
9591
|
+
];
|
|
9592
|
+
case 1:
|
|
9593
|
+
_state.sent();
|
|
9594
|
+
controller.close();
|
|
9595
|
+
return [
|
|
9596
|
+
2
|
|
9597
|
+
];
|
|
9598
|
+
}
|
|
9599
|
+
});
|
|
9600
|
+
})();
|
|
9601
|
+
}
|
|
9602
|
+
});
|
|
9603
|
+
if (!stream) return [
|
|
9604
|
+
3,
|
|
9605
|
+
2
|
|
9606
|
+
];
|
|
9607
|
+
return [
|
|
9608
|
+
2,
|
|
9609
|
+
new Response(readableStream, {
|
|
9610
|
+
headers: {
|
|
9611
|
+
"Content-Type": "text/event-stream"
|
|
9612
|
+
}
|
|
9613
|
+
})
|
|
9614
|
+
];
|
|
9615
|
+
case 2:
|
|
9616
|
+
events = [];
|
|
9617
|
+
finalRun = null;
|
|
9618
|
+
return [
|
|
9619
|
+
4,
|
|
9620
|
+
streamRun(function(event) {
|
|
9621
|
+
return _async_to_generator(function() {
|
|
9622
|
+
return _ts_generator(this, function(_state) {
|
|
9623
|
+
events.push(event);
|
|
9624
|
+
if (event.event === "thread.run.completed" || event.event === "thread.run.failed" || event.event === "thread.run.requires_action") {
|
|
9625
|
+
finalRun = event.data;
|
|
9626
|
+
}
|
|
9627
|
+
return [
|
|
9628
|
+
2
|
|
9629
|
+
];
|
|
9630
|
+
});
|
|
9631
|
+
})();
|
|
9632
|
+
})
|
|
9633
|
+
];
|
|
9634
|
+
case 3:
|
|
9635
|
+
_state.sent();
|
|
9636
|
+
if (!finalRun) {
|
|
9637
|
+
throw new Error("Run did not complete");
|
|
9638
|
+
}
|
|
9639
|
+
return [
|
|
9640
|
+
2,
|
|
9641
|
+
new Response(JSON.stringify(finalRun), {
|
|
9642
|
+
status: 200,
|
|
9643
|
+
headers: {
|
|
9644
|
+
"Content-Type": "application/json"
|
|
9645
|
+
}
|
|
9646
|
+
})
|
|
9647
|
+
];
|
|
9648
|
+
case 4:
|
|
9649
|
+
return [
|
|
9650
|
+
2
|
|
9651
|
+
];
|
|
9652
|
+
}
|
|
9653
|
+
});
|
|
9654
|
+
})();
|
|
9655
|
+
};
|
|
9656
|
+
};
|
|
9657
|
+
// src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/index.ts
|
|
9658
|
+
var submitToolOutputs3 = function(param) {
|
|
9659
|
+
var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
|
|
9660
|
+
return {
|
|
9661
|
+
post: post23({
|
|
9662
|
+
azureAiProject: azureAiProject,
|
|
9663
|
+
runAdapter: runAdapter
|
|
9664
|
+
})
|
|
9665
|
+
};
|
|
9666
|
+
};
|
|
9667
|
+
// src/adapters/storage/azureAgentsStorageAdapter/assistants/post.ts
|
|
9668
|
+
var post24 = function(param) {
|
|
9669
|
+
var runAdapter = param.runAdapter;
|
|
9670
|
+
return function(_urlString, options) {
|
|
9671
|
+
return _async_to_generator(function() {
|
|
9672
|
+
var body, _body_top_p, _body_temperature, openaiAssistant;
|
|
9673
|
+
return _ts_generator(this, function(_state) {
|
|
9674
|
+
if (typeof options.body !== "string") {
|
|
9675
|
+
throw new Error("Request body is required");
|
|
9676
|
+
}
|
|
9677
|
+
body = JSON.parse(options.body);
|
|
9678
|
+
openaiAssistant = {
|
|
9679
|
+
id: "placeholder",
|
|
9680
|
+
// This will be overridden by the assistant_id passed to createRun
|
|
9681
|
+
object: "assistant",
|
|
9682
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
9683
|
+
name: body.name || null,
|
|
9684
|
+
description: body.description || null,
|
|
9685
|
+
model: body.model,
|
|
9686
|
+
instructions: body.instructions || null,
|
|
9687
|
+
tools: body.tools || [],
|
|
9688
|
+
metadata: body.metadata || {},
|
|
9689
|
+
top_p: (_body_top_p = body.top_p) !== null && _body_top_p !== void 0 ? _body_top_p : null,
|
|
9690
|
+
temperature: (_body_temperature = body.temperature) !== null && _body_temperature !== void 0 ? _body_temperature : null,
|
|
9691
|
+
response_format: body.response_format || "auto"
|
|
9692
|
+
};
|
|
9693
|
+
return [
|
|
9694
|
+
2,
|
|
9695
|
+
new Response(JSON.stringify(openaiAssistant), {
|
|
9696
|
+
status: 200,
|
|
9697
|
+
headers: {
|
|
9698
|
+
"Content-Type": "application/json"
|
|
9699
|
+
}
|
|
9700
|
+
})
|
|
9701
|
+
];
|
|
9702
|
+
});
|
|
9703
|
+
})();
|
|
9704
|
+
};
|
|
9705
|
+
};
|
|
9706
|
+
// src/adapters/storage/azureAgentsStorageAdapter/assistants/index.ts
|
|
9707
|
+
var assistants3 = function(param) {
|
|
9708
|
+
var runAdapter = param.runAdapter;
|
|
9709
|
+
return {
|
|
9710
|
+
post: post24({
|
|
9711
|
+
runAdapter: runAdapter
|
|
9712
|
+
})
|
|
9713
|
+
};
|
|
9714
|
+
};
|
|
9715
|
+
// src/adapters/storage/azureAgentsStorageAdapter/index.ts
|
|
9716
|
+
var azureAgentsStorageAdapter = function(param) {
|
|
9717
|
+
var azureAiProject = param.azureAiProject;
|
|
9718
|
+
return function(param) {
|
|
9719
|
+
var runAdapter = param.runAdapter;
|
|
9720
|
+
var _obj;
|
|
9721
|
+
return {
|
|
9722
|
+
requestHandlers: (_obj = {
|
|
9723
|
+
"^/(?:v1|/?openai)/assistants$": assistants3({
|
|
9724
|
+
runAdapter: runAdapter
|
|
9725
|
+
}),
|
|
9726
|
+
"^/(?:v1|/?openai)/threads$": threads3({
|
|
9727
|
+
azureAiProject: azureAiProject
|
|
9728
|
+
})
|
|
9729
|
+
}, _define_property(_obj, messagesRegexp, messages4({
|
|
9730
|
+
azureAiProject: azureAiProject,
|
|
9731
|
+
runAdapter: runAdapter
|
|
9732
|
+
})), _define_property(_obj, runsRegexp, runs3({
|
|
9733
|
+
azureAiProject: azureAiProject,
|
|
9734
|
+
runAdapter: runAdapter
|
|
9735
|
+
})), _define_property(_obj, runRegexp, run3({
|
|
9736
|
+
azureAiProject: azureAiProject,
|
|
9737
|
+
runAdapter: runAdapter
|
|
9738
|
+
})), _define_property(_obj, stepsRegexp, steps3({
|
|
9739
|
+
azureAiProject: azureAiProject,
|
|
9740
|
+
runAdapter: runAdapter
|
|
9741
|
+
})), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs3({
|
|
9742
|
+
azureAiProject: azureAiProject,
|
|
9743
|
+
runAdapter: runAdapter
|
|
9744
|
+
})), _obj)
|
|
9745
|
+
};
|
|
9746
|
+
};
|
|
9747
|
+
};
|
|
9748
|
+
// src/adapters/run/responsesRunAdapter/index.ts
|
|
9749
|
+
import dayjs28 from "dayjs";
|
|
9750
|
+
import { uid as uid9 } from "radash";
|
|
9751
|
+
var serializeToolCalls2 = function(param) {
|
|
9752
|
+
var toolCalls = param.toolCalls;
|
|
9753
|
+
return toolCalls.map(function(toolCall) {
|
|
9754
|
+
if (toolCall.type === "function_call") {
|
|
9755
|
+
return {
|
|
9756
|
+
id: toolCall.call_id,
|
|
9757
|
+
type: "function",
|
|
9758
|
+
function: {
|
|
9759
|
+
name: toolCall.name,
|
|
9760
|
+
arguments: toolCall.arguments
|
|
9761
|
+
}
|
|
9762
|
+
};
|
|
9763
|
+
} else if (toolCall.type === "computer_call") {
|
|
9764
|
+
return {
|
|
9765
|
+
id: toolCall.call_id,
|
|
9766
|
+
type: "computer_call",
|
|
9767
|
+
computer_call: {
|
|
9768
|
+
action: toolCall.action,
|
|
9769
|
+
pending_safety_checks: toolCall.pending_safety_checks
|
|
9770
|
+
}
|
|
9771
|
+
};
|
|
9772
|
+
}
|
|
9773
|
+
});
|
|
9774
|
+
};
|
|
9775
|
+
var responsesRunAdapter = function(param) {
|
|
9776
|
+
var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
|
|
9777
|
+
return p.then(function() {});
|
|
9778
|
+
} : _param_waitUntil;
|
|
9779
|
+
var cachedOpenaiAssistant = null;
|
|
9780
|
+
var getOpenaiAssistant = function() {
|
|
9781
|
+
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;
|
|
9782
|
+
return _async_to_generator(function() {
|
|
9783
|
+
var args, _tmp;
|
|
9784
|
+
return _ts_generator(this, function(_state) {
|
|
9785
|
+
switch(_state.label){
|
|
9786
|
+
case 0:
|
|
9787
|
+
args = {
|
|
9788
|
+
select: {
|
|
9789
|
+
id: id
|
|
9790
|
+
}
|
|
9791
|
+
};
|
|
9792
|
+
if (!args.select.id) return [
|
|
9793
|
+
3,
|
|
9794
|
+
2
|
|
9795
|
+
];
|
|
9796
|
+
_tmp = {};
|
|
9797
|
+
return [
|
|
9798
|
+
4,
|
|
9799
|
+
getDirectOpenaiAssistant({
|
|
9800
|
+
select: {
|
|
9801
|
+
id: true
|
|
9802
|
+
}
|
|
9803
|
+
})
|
|
9804
|
+
];
|
|
9805
|
+
case 1:
|
|
9806
|
+
return [
|
|
9807
|
+
2,
|
|
9808
|
+
(_tmp.id = _state.sent().id, _tmp)
|
|
9809
|
+
];
|
|
9810
|
+
case 2:
|
|
9811
|
+
if (cachedOpenaiAssistant) return [
|
|
9812
|
+
2,
|
|
9813
|
+
cachedOpenaiAssistant
|
|
9814
|
+
];
|
|
9815
|
+
return [
|
|
9816
|
+
4,
|
|
9817
|
+
getDirectOpenaiAssistant()
|
|
9818
|
+
];
|
|
9819
|
+
case 3:
|
|
9820
|
+
cachedOpenaiAssistant = _state.sent();
|
|
9821
|
+
return [
|
|
9822
|
+
2,
|
|
9823
|
+
cachedOpenaiAssistant
|
|
9824
|
+
];
|
|
9825
|
+
}
|
|
9826
|
+
});
|
|
9827
|
+
})();
|
|
9828
|
+
};
|
|
9829
|
+
var handleRun = function(param) {
|
|
9830
|
+
var client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
|
|
9831
|
+
return _async_to_generator(function() {
|
|
9832
|
+
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;
|
|
9833
|
+
return _ts_generator(this, function(_state) {
|
|
9834
|
+
switch(_state.label){
|
|
9835
|
+
case 0:
|
|
9836
|
+
responseCreatedResponse = null;
|
|
9837
|
+
responseCompletedResponse = null;
|
|
9838
|
+
toolCalls = {};
|
|
9839
|
+
mcpCalls = {};
|
|
9840
|
+
codeInterpreterCalls = {};
|
|
9841
|
+
itemIds = [];
|
|
9842
|
+
_state.label = 1;
|
|
9843
|
+
case 1:
|
|
9844
|
+
_state.trys.push([
|
|
9845
|
+
1,
|
|
9846
|
+
151,
|
|
9847
|
+
154,
|
|
9848
|
+
155
|
|
9849
|
+
]);
|
|
9850
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
9851
|
+
_state.label = 2;
|
|
9852
|
+
case 2:
|
|
9853
|
+
_state.trys.push([
|
|
9854
|
+
2,
|
|
9855
|
+
139,
|
|
9856
|
+
140,
|
|
9857
|
+
145
|
|
9858
|
+
]);
|
|
9859
|
+
_iterator = _async_iterator(response);
|
|
9860
|
+
_state.label = 3;
|
|
9861
|
+
case 3:
|
|
9862
|
+
return [
|
|
9863
|
+
4,
|
|
9864
|
+
_iterator.next()
|
|
9865
|
+
];
|
|
9866
|
+
case 4:
|
|
9867
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
9868
|
+
3,
|
|
9869
|
+
138
|
|
9870
|
+
];
|
|
9871
|
+
_value = _step.value;
|
|
9872
|
+
event = _value;
|
|
9873
|
+
_ = event.type;
|
|
9874
|
+
switch(_){
|
|
9875
|
+
case "response.created":
|
|
9876
|
+
return [
|
|
9877
|
+
3,
|
|
9878
|
+
5
|
|
9879
|
+
];
|
|
9880
|
+
case "response.in_progress":
|
|
9881
|
+
return [
|
|
9882
|
+
3,
|
|
9883
|
+
8
|
|
9884
|
+
];
|
|
9885
|
+
case "response.completed":
|
|
9886
|
+
return [
|
|
9887
|
+
3,
|
|
9888
|
+
11
|
|
9889
|
+
];
|
|
9890
|
+
case "response.failed":
|
|
9891
|
+
return [
|
|
9892
|
+
3,
|
|
9893
|
+
12
|
|
9894
|
+
];
|
|
9895
|
+
case "response.output_text.delta":
|
|
9896
|
+
return [
|
|
9897
|
+
3,
|
|
9898
|
+
15
|
|
9899
|
+
];
|
|
9900
|
+
case "response.output_item.added":
|
|
9901
|
+
return [
|
|
9902
|
+
3,
|
|
9903
|
+
17
|
|
9904
|
+
];
|
|
9905
|
+
case "response.output_item.done":
|
|
9906
|
+
return [
|
|
9907
|
+
3,
|
|
9908
|
+
75
|
|
9909
|
+
];
|
|
9910
|
+
case "response.function_call_arguments.delta":
|
|
9911
|
+
return [
|
|
9912
|
+
3,
|
|
9913
|
+
126
|
|
9914
|
+
];
|
|
9915
|
+
case "response.mcp_call_arguments.delta":
|
|
9916
|
+
return [
|
|
9917
|
+
3,
|
|
9918
|
+
128
|
|
9919
|
+
];
|
|
9920
|
+
case "response.image_generation_call.in_progress":
|
|
9921
|
+
return [
|
|
9922
|
+
3,
|
|
9923
|
+
130
|
|
9924
|
+
];
|
|
9925
|
+
case "response.image_generation_call.generating":
|
|
9926
|
+
return [
|
|
9927
|
+
3,
|
|
9928
|
+
130
|
|
9929
|
+
];
|
|
9930
|
+
case "response.image_generation_call.partial_image":
|
|
9931
|
+
return [
|
|
9932
|
+
3,
|
|
9933
|
+
133
|
|
9934
|
+
];
|
|
9935
|
+
}
|
|
9936
|
+
return [
|
|
9937
|
+
3,
|
|
9938
|
+
136
|
|
9939
|
+
];
|
|
9940
|
+
case 5:
|
|
9941
|
+
responseCreatedResponse = event.response;
|
|
9942
|
+
_tmp = {
|
|
9943
|
+
event: "thread.run.created"
|
|
9944
|
+
};
|
|
9945
|
+
_tmp1 = {
|
|
8529
9946
|
response: event.response
|
|
8530
9947
|
};
|
|
8531
9948
|
return [
|
|
@@ -8677,7 +10094,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8677
10094
|
4,
|
|
8678
10095
|
onEvent2.apply(void 0, [
|
|
8679
10096
|
(_tmp6.data = serializeItemAsMessage.apply(void 0, [
|
|
8680
|
-
(_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt =
|
|
10097
|
+
(_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt = dayjs28().unix(), _tmp7.runId = responseCreatedResponse.id, _tmp7.status = "in_progress", _tmp7)
|
|
8681
10098
|
]), _tmp6)
|
|
8682
10099
|
])
|
|
8683
10100
|
];
|
|
@@ -8774,7 +10191,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8774
10191
|
4,
|
|
8775
10192
|
onEvent2.apply(void 0, [
|
|
8776
10193
|
(_tmp12.data = serializeItemAsMessage.apply(void 0, [
|
|
8777
|
-
(_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt =
|
|
10194
|
+
(_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt = dayjs28().unix(), _tmp13.runId = responseCreatedResponse.id, _tmp13.status = "in_progress", _tmp13)
|
|
8778
10195
|
]), _tmp12)
|
|
8779
10196
|
])
|
|
8780
10197
|
];
|
|
@@ -8861,7 +10278,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8861
10278
|
4,
|
|
8862
10279
|
onEvent2.apply(void 0, [
|
|
8863
10280
|
(_tmp18.data = serializeItemAsMessage.apply(void 0, [
|
|
8864
|
-
(_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt =
|
|
10281
|
+
(_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt = dayjs28().unix(), _tmp19.runId = responseCreatedResponse.id, _tmp19.status = "in_progress", _tmp19)
|
|
8865
10282
|
]), _tmp18)
|
|
8866
10283
|
])
|
|
8867
10284
|
];
|
|
@@ -8947,7 +10364,7 @@ var responsesRunAdapter = function(param) {
|
|
|
8947
10364
|
4,
|
|
8948
10365
|
onEvent2.apply(void 0, [
|
|
8949
10366
|
(_tmp24.data = serializeItemAsMessage.apply(void 0, [
|
|
8950
|
-
(_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt =
|
|
10367
|
+
(_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt = dayjs28().unix(), _tmp25.runId = responseCreatedResponse.id, _tmp25.status = "in_progress", _tmp25)
|
|
8951
10368
|
]), _tmp24)
|
|
8952
10369
|
])
|
|
8953
10370
|
];
|
|
@@ -9033,7 +10450,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9033
10450
|
4,
|
|
9034
10451
|
onEvent2.apply(void 0, [
|
|
9035
10452
|
(_tmp30.data = serializeItemAsMessage.apply(void 0, [
|
|
9036
|
-
(_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt =
|
|
10453
|
+
(_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt = dayjs28().unix(), _tmp31.runId = responseCreatedResponse.id, _tmp31.status = "in_progress", _tmp31)
|
|
9037
10454
|
]), _tmp30)
|
|
9038
10455
|
])
|
|
9039
10456
|
];
|
|
@@ -9119,7 +10536,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9119
10536
|
4,
|
|
9120
10537
|
onEvent2.apply(void 0, [
|
|
9121
10538
|
(_tmp36.data = serializeItemAsMessage.apply(void 0, [
|
|
9122
|
-
(_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt =
|
|
10539
|
+
(_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt = dayjs28().unix(), _tmp37.runId = responseCreatedResponse.id, _tmp37.status = "in_progress", _tmp37)
|
|
9123
10540
|
]), _tmp36)
|
|
9124
10541
|
])
|
|
9125
10542
|
];
|
|
@@ -9206,7 +10623,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9206
10623
|
4,
|
|
9207
10624
|
onEvent2.apply(void 0, [
|
|
9208
10625
|
(_tmp42.data = serializeItemAsMessage.apply(void 0, [
|
|
9209
|
-
(_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt =
|
|
10626
|
+
(_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt = dayjs28().unix(), _tmp43.runId = responseCreatedResponse.id, _tmp43.status = "in_progress", _tmp43)
|
|
9210
10627
|
]), _tmp42)
|
|
9211
10628
|
])
|
|
9212
10629
|
];
|
|
@@ -9293,7 +10710,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9293
10710
|
4,
|
|
9294
10711
|
onEvent2.apply(void 0, [
|
|
9295
10712
|
(_tmp48.data = serializeItemAsMessage.apply(void 0, [
|
|
9296
|
-
(_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt =
|
|
10713
|
+
(_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt = dayjs28().unix(), _tmp49.runId = responseCreatedResponse.id, _tmp49.status = "in_progress", _tmp49)
|
|
9297
10714
|
]), _tmp48)
|
|
9298
10715
|
])
|
|
9299
10716
|
];
|
|
@@ -9408,7 +10825,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9408
10825
|
4,
|
|
9409
10826
|
onEvent2.apply(void 0, [
|
|
9410
10827
|
(_tmp56.data = serializeItemAsMessage.apply(void 0, [
|
|
9411
|
-
(_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt =
|
|
10828
|
+
(_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt = dayjs28().unix(), _tmp57.runId = responseCreatedResponse.id, _tmp57)
|
|
9412
10829
|
]), _tmp56)
|
|
9413
10830
|
])
|
|
9414
10831
|
];
|
|
@@ -9530,7 +10947,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9530
10947
|
4,
|
|
9531
10948
|
onEvent2.apply(void 0, [
|
|
9532
10949
|
(_tmp64.data = serializeItemAsMessage.apply(void 0, [
|
|
9533
|
-
(_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt =
|
|
10950
|
+
(_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt = dayjs28().unix(), _tmp65.runId = responseCreatedResponse.id, _tmp65)
|
|
9534
10951
|
]), _tmp64)
|
|
9535
10952
|
])
|
|
9536
10953
|
];
|
|
@@ -9616,7 +11033,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9616
11033
|
4,
|
|
9617
11034
|
onEvent2.apply(void 0, [
|
|
9618
11035
|
(_tmp70.data = serializeItemAsMessage.apply(void 0, [
|
|
9619
|
-
(_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt =
|
|
11036
|
+
(_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt = dayjs28().unix(), _tmp71.runId = responseCreatedResponse.id, _tmp71)
|
|
9620
11037
|
]), _tmp70)
|
|
9621
11038
|
])
|
|
9622
11039
|
];
|
|
@@ -9702,7 +11119,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9702
11119
|
4,
|
|
9703
11120
|
onEvent2.apply(void 0, [
|
|
9704
11121
|
(_tmp76.data = serializeItemAsMessage.apply(void 0, [
|
|
9705
|
-
(_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt =
|
|
11122
|
+
(_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt = dayjs28().unix(), _tmp77.runId = responseCreatedResponse.id, _tmp77)
|
|
9706
11123
|
]), _tmp76)
|
|
9707
11124
|
])
|
|
9708
11125
|
];
|
|
@@ -9788,7 +11205,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9788
11205
|
4,
|
|
9789
11206
|
onEvent2.apply(void 0, [
|
|
9790
11207
|
(_tmp82.data = serializeItemAsMessage.apply(void 0, [
|
|
9791
|
-
(_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt =
|
|
11208
|
+
(_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt = dayjs28().unix(), _tmp83.runId = responseCreatedResponse.id, _tmp83)
|
|
9792
11209
|
]), _tmp82)
|
|
9793
11210
|
])
|
|
9794
11211
|
];
|
|
@@ -9874,7 +11291,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9874
11291
|
4,
|
|
9875
11292
|
onEvent2.apply(void 0, [
|
|
9876
11293
|
(_tmp88.data = serializeItemAsMessage.apply(void 0, [
|
|
9877
|
-
(_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt =
|
|
11294
|
+
(_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt = dayjs28().unix(), _tmp89.runId = responseCreatedResponse.id, _tmp89)
|
|
9878
11295
|
]), _tmp88)
|
|
9879
11296
|
])
|
|
9880
11297
|
];
|
|
@@ -9960,7 +11377,7 @@ var responsesRunAdapter = function(param) {
|
|
|
9960
11377
|
4,
|
|
9961
11378
|
onEvent2.apply(void 0, [
|
|
9962
11379
|
(_tmp94.data = serializeItemAsMessage.apply(void 0, [
|
|
9963
|
-
(_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt =
|
|
11380
|
+
(_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt = dayjs28().unix(), _tmp95.runId = responseCreatedResponse.id, _tmp95)
|
|
9964
11381
|
]), _tmp94)
|
|
9965
11382
|
])
|
|
9966
11383
|
];
|
|
@@ -10057,7 +11474,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10057
11474
|
_tmp97 = {
|
|
10058
11475
|
id: event.item_id,
|
|
10059
11476
|
object: "thread.message",
|
|
10060
|
-
created_at:
|
|
11477
|
+
created_at: dayjs28().unix(),
|
|
10061
11478
|
thread_id: threadId,
|
|
10062
11479
|
completed_at: null,
|
|
10063
11480
|
incomplete_at: null,
|
|
@@ -10095,7 +11512,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10095
11512
|
_tmp99 = {
|
|
10096
11513
|
id: event.item_id,
|
|
10097
11514
|
object: "thread.message",
|
|
10098
|
-
created_at:
|
|
11515
|
+
created_at: dayjs28().unix(),
|
|
10099
11516
|
thread_id: threadId,
|
|
10100
11517
|
completed_at: null,
|
|
10101
11518
|
incomplete_at: null,
|
|
@@ -10267,7 +11684,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10267
11684
|
event: "thread.run.failed"
|
|
10268
11685
|
};
|
|
10269
11686
|
_tmp102 = {
|
|
10270
|
-
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat(
|
|
11687
|
+
id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat(uid9(18)),
|
|
10271
11688
|
object: "thread.run",
|
|
10272
11689
|
thread_id: threadId
|
|
10273
11690
|
};
|
|
@@ -10283,7 +11700,7 @@ var responsesRunAdapter = function(param) {
|
|
|
10283
11700
|
return [
|
|
10284
11701
|
4,
|
|
10285
11702
|
onEvent2.apply(void 0, [
|
|
10286
|
-
(_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at =
|
|
11703
|
+
(_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at = dayjs28().unix(), _tmp102.last_error = {
|
|
10287
11704
|
code: "server_error",
|
|
10288
11705
|
message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
|
|
10289
11706
|
}, _tmp102), _tmp101)
|
|
@@ -10342,5 +11759,513 @@ var responsesRunAdapter = function(param) {
|
|
|
10342
11759
|
getOpenaiAssistant: getOpenaiAssistant
|
|
10343
11760
|
};
|
|
10344
11761
|
};
|
|
10345
|
-
|
|
11762
|
+
// src/adapters/run/azureAgentsRunAdapter/index.ts
|
|
11763
|
+
import dayjs29 from "dayjs";
|
|
11764
|
+
import { uid as uid10 } from "radash";
|
|
11765
|
+
function convertAzureEventToOpenAI2(azureEvent, assistantId) {
|
|
11766
|
+
var event = azureEvent.event, data = azureEvent.data;
|
|
11767
|
+
var eventType = event;
|
|
11768
|
+
if (eventType.startsWith("thread.run.")) {
|
|
11769
|
+
var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
|
|
11770
|
+
var _data_temperature, _data_topP;
|
|
11771
|
+
return {
|
|
11772
|
+
event: eventType,
|
|
11773
|
+
data: {
|
|
11774
|
+
id: data.id,
|
|
11775
|
+
object: "thread.run",
|
|
11776
|
+
created_at: dayjs29(data.createdAt).unix(),
|
|
11777
|
+
thread_id: data.threadId,
|
|
11778
|
+
assistant_id: assistantId,
|
|
11779
|
+
status: data.status,
|
|
11780
|
+
required_action: data.requiredAction ? {
|
|
11781
|
+
type: "submit_tool_outputs",
|
|
11782
|
+
submit_tool_outputs: {
|
|
11783
|
+
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) {
|
|
11784
|
+
return {
|
|
11785
|
+
id: tc.id,
|
|
11786
|
+
type: "function",
|
|
11787
|
+
function: {
|
|
11788
|
+
name: tc.function.name,
|
|
11789
|
+
arguments: tc.function.arguments
|
|
11790
|
+
}
|
|
11791
|
+
};
|
|
11792
|
+
})) || []
|
|
11793
|
+
}
|
|
11794
|
+
} : null,
|
|
11795
|
+
last_error: data.lastError ? {
|
|
11796
|
+
code: "server_error",
|
|
11797
|
+
message: JSON.stringify(data.lastError)
|
|
11798
|
+
} : null,
|
|
11799
|
+
expires_at: null,
|
|
11800
|
+
started_at: data.startedAt ? dayjs29(data.startedAt).unix() : null,
|
|
11801
|
+
cancelled_at: data.cancelledAt ? dayjs29(data.cancelledAt).unix() : null,
|
|
11802
|
+
failed_at: data.failedAt ? dayjs29(data.failedAt).unix() : null,
|
|
11803
|
+
completed_at: data.completedAt ? dayjs29(data.completedAt).unix() : null,
|
|
11804
|
+
incomplete_details: null,
|
|
11805
|
+
model: data.model || "",
|
|
11806
|
+
instructions: data.instructions || "",
|
|
11807
|
+
tools: data.tools || [],
|
|
11808
|
+
metadata: data.metadata || {},
|
|
11809
|
+
temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
|
|
11810
|
+
top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
|
|
11811
|
+
max_prompt_tokens: null,
|
|
11812
|
+
max_completion_tokens: null,
|
|
11813
|
+
truncation_strategy: {
|
|
11814
|
+
type: "auto",
|
|
11815
|
+
last_messages: null
|
|
11816
|
+
},
|
|
11817
|
+
response_format: "auto",
|
|
11818
|
+
tool_choice: "auto",
|
|
11819
|
+
parallel_tool_calls: true,
|
|
11820
|
+
usage: null
|
|
11821
|
+
}
|
|
11822
|
+
};
|
|
11823
|
+
}
|
|
11824
|
+
if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
|
|
11825
|
+
var _data_content;
|
|
11826
|
+
return {
|
|
11827
|
+
event: eventType,
|
|
11828
|
+
data: {
|
|
11829
|
+
id: data.id,
|
|
11830
|
+
object: "thread.message",
|
|
11831
|
+
created_at: dayjs29(data.createdAt).unix(),
|
|
11832
|
+
thread_id: data.threadId,
|
|
11833
|
+
role: data.role,
|
|
11834
|
+
content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
|
|
11835
|
+
if (c.type === "text") {
|
|
11836
|
+
var _c_text, _c_text1;
|
|
11837
|
+
return {
|
|
11838
|
+
type: "text",
|
|
11839
|
+
text: {
|
|
11840
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
11841
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
11842
|
+
}
|
|
11843
|
+
};
|
|
11844
|
+
}
|
|
11845
|
+
return c;
|
|
11846
|
+
})) || [],
|
|
11847
|
+
assistant_id: assistantId,
|
|
11848
|
+
run_id: data.runId || null,
|
|
11849
|
+
attachments: data.attachments || [],
|
|
11850
|
+
metadata: data.metadata || {},
|
|
11851
|
+
status: data.status || "completed",
|
|
11852
|
+
completed_at: data.completedAt ? dayjs29(data.completedAt).unix() : null,
|
|
11853
|
+
incomplete_at: null,
|
|
11854
|
+
incomplete_details: null
|
|
11855
|
+
}
|
|
11856
|
+
};
|
|
11857
|
+
}
|
|
11858
|
+
if (eventType === "thread.message.delta") {
|
|
11859
|
+
var _data_delta_content, _data_delta;
|
|
11860
|
+
return {
|
|
11861
|
+
event: "thread.message.delta",
|
|
11862
|
+
data: {
|
|
11863
|
+
id: data.id,
|
|
11864
|
+
object: "thread.message.delta",
|
|
11865
|
+
delta: {
|
|
11866
|
+
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) {
|
|
11867
|
+
if (c.type === "text") {
|
|
11868
|
+
var _c_text, _c_text1;
|
|
11869
|
+
return {
|
|
11870
|
+
index: c.index || 0,
|
|
11871
|
+
type: "text",
|
|
11872
|
+
text: {
|
|
11873
|
+
value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
|
|
11874
|
+
annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
|
|
11875
|
+
}
|
|
11876
|
+
};
|
|
11877
|
+
}
|
|
11878
|
+
return c;
|
|
11879
|
+
})) || []
|
|
11880
|
+
}
|
|
11881
|
+
}
|
|
11882
|
+
};
|
|
11883
|
+
}
|
|
11884
|
+
if (eventType === "thread.run.step.delta") {
|
|
11885
|
+
var _data_delta1;
|
|
11886
|
+
var stepDetailsDelta = {};
|
|
11887
|
+
if ((_data_delta1 = data.delta) === null || _data_delta1 === void 0 ? void 0 : _data_delta1.stepDetails) {
|
|
11888
|
+
var details = data.delta.stepDetails;
|
|
11889
|
+
if (details.type === "tool_calls") {
|
|
11890
|
+
var _details_toolCalls;
|
|
11891
|
+
stepDetailsDelta = {
|
|
11892
|
+
type: "tool_calls",
|
|
11893
|
+
tool_calls: ((_details_toolCalls = details.toolCalls) === null || _details_toolCalls === void 0 ? void 0 : _details_toolCalls.map(function(tc) {
|
|
11894
|
+
if (tc.type === "code_interpreter") {
|
|
11895
|
+
var _tc_codeInterpreter, _tc_codeInterpreter_outputs, _tc_codeInterpreter1;
|
|
11896
|
+
var _tc_index;
|
|
11897
|
+
return {
|
|
11898
|
+
index: (_tc_index = tc.index) !== null && _tc_index !== void 0 ? _tc_index : 0,
|
|
11899
|
+
id: tc.id,
|
|
11900
|
+
type: "code_interpreter",
|
|
11901
|
+
code_interpreter: {
|
|
11902
|
+
input: ((_tc_codeInterpreter = tc.codeInterpreter) === null || _tc_codeInterpreter === void 0 ? void 0 : _tc_codeInterpreter.input) || "",
|
|
11903
|
+
outputs: ((_tc_codeInterpreter1 = tc.codeInterpreter) === null || _tc_codeInterpreter1 === void 0 ? void 0 : (_tc_codeInterpreter_outputs = _tc_codeInterpreter1.outputs) === null || _tc_codeInterpreter_outputs === void 0 ? void 0 : _tc_codeInterpreter_outputs.map(function(output) {
|
|
11904
|
+
if (output.type === "logs") {
|
|
11905
|
+
var _output_index;
|
|
11906
|
+
return {
|
|
11907
|
+
index: (_output_index = output.index) !== null && _output_index !== void 0 ? _output_index : 0,
|
|
11908
|
+
type: "logs",
|
|
11909
|
+
logs: output.logs || ""
|
|
11910
|
+
};
|
|
11911
|
+
}
|
|
11912
|
+
if (output.type === "image") {
|
|
11913
|
+
var _output_image;
|
|
11914
|
+
var _output_index1;
|
|
11915
|
+
return {
|
|
11916
|
+
index: (_output_index1 = output.index) !== null && _output_index1 !== void 0 ? _output_index1 : 0,
|
|
11917
|
+
type: "image",
|
|
11918
|
+
image: {
|
|
11919
|
+
file_id: ((_output_image = output.image) === null || _output_image === void 0 ? void 0 : _output_image.fileId) || ""
|
|
11920
|
+
}
|
|
11921
|
+
};
|
|
11922
|
+
}
|
|
11923
|
+
return output;
|
|
11924
|
+
})) || []
|
|
11925
|
+
}
|
|
11926
|
+
};
|
|
11927
|
+
} else if (tc.type === "file_search") {
|
|
11928
|
+
var _tc_index1;
|
|
11929
|
+
return {
|
|
11930
|
+
index: (_tc_index1 = tc.index) !== null && _tc_index1 !== void 0 ? _tc_index1 : 0,
|
|
11931
|
+
id: tc.id,
|
|
11932
|
+
type: "file_search",
|
|
11933
|
+
file_search: tc.fileSearch || {}
|
|
11934
|
+
};
|
|
11935
|
+
} else if (tc.type === "function") {
|
|
11936
|
+
var _tc_function, _tc_function1, _tc_function2;
|
|
11937
|
+
var _tc_index2;
|
|
11938
|
+
return {
|
|
11939
|
+
index: (_tc_index2 = tc.index) !== null && _tc_index2 !== void 0 ? _tc_index2 : 0,
|
|
11940
|
+
id: tc.id,
|
|
11941
|
+
type: "function",
|
|
11942
|
+
function: {
|
|
11943
|
+
name: ((_tc_function = tc.function) === null || _tc_function === void 0 ? void 0 : _tc_function.name) || "",
|
|
11944
|
+
arguments: ((_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) || "",
|
|
11945
|
+
output: ((_tc_function2 = tc.function) === null || _tc_function2 === void 0 ? void 0 : _tc_function2.output) || null
|
|
11946
|
+
}
|
|
11947
|
+
};
|
|
11948
|
+
}
|
|
11949
|
+
return tc;
|
|
11950
|
+
})) || []
|
|
11951
|
+
};
|
|
11952
|
+
} else {
|
|
11953
|
+
stepDetailsDelta = details;
|
|
11954
|
+
}
|
|
11955
|
+
}
|
|
11956
|
+
return {
|
|
11957
|
+
event: "thread.run.step.delta",
|
|
11958
|
+
data: {
|
|
11959
|
+
id: data.id,
|
|
11960
|
+
object: "thread.run.step.delta",
|
|
11961
|
+
delta: {
|
|
11962
|
+
step_details: stepDetailsDelta
|
|
11963
|
+
}
|
|
11964
|
+
}
|
|
11965
|
+
};
|
|
11966
|
+
}
|
|
11967
|
+
if (eventType.startsWith("thread.run.step.")) {
|
|
11968
|
+
var stepDetails = {};
|
|
11969
|
+
if (data.stepDetails) {
|
|
11970
|
+
if (data.stepDetails.type === "message_creation") {
|
|
11971
|
+
var _data_stepDetails_messageCreation;
|
|
11972
|
+
stepDetails = {
|
|
11973
|
+
type: "message_creation",
|
|
11974
|
+
message_creation: {
|
|
11975
|
+
message_id: ((_data_stepDetails_messageCreation = data.stepDetails.messageCreation) === null || _data_stepDetails_messageCreation === void 0 ? void 0 : _data_stepDetails_messageCreation.messageId) || ""
|
|
11976
|
+
}
|
|
11977
|
+
};
|
|
11978
|
+
} else if (data.stepDetails.type === "tool_calls") {
|
|
11979
|
+
var _data_stepDetails_toolCalls;
|
|
11980
|
+
stepDetails = {
|
|
11981
|
+
type: "tool_calls",
|
|
11982
|
+
tool_calls: ((_data_stepDetails_toolCalls = data.stepDetails.toolCalls) === null || _data_stepDetails_toolCalls === void 0 ? void 0 : _data_stepDetails_toolCalls.map(function(tc) {
|
|
11983
|
+
if (tc.type === "code_interpreter") {
|
|
11984
|
+
var _tc_codeInterpreter, _tc_codeInterpreter_outputs, _tc_codeInterpreter1;
|
|
11985
|
+
return {
|
|
11986
|
+
id: tc.id,
|
|
11987
|
+
type: "code_interpreter",
|
|
11988
|
+
code_interpreter: {
|
|
11989
|
+
input: ((_tc_codeInterpreter = tc.codeInterpreter) === null || _tc_codeInterpreter === void 0 ? void 0 : _tc_codeInterpreter.input) || "",
|
|
11990
|
+
outputs: ((_tc_codeInterpreter1 = tc.codeInterpreter) === null || _tc_codeInterpreter1 === void 0 ? void 0 : (_tc_codeInterpreter_outputs = _tc_codeInterpreter1.outputs) === null || _tc_codeInterpreter_outputs === void 0 ? void 0 : _tc_codeInterpreter_outputs.map(function(output) {
|
|
11991
|
+
if (output.type === "logs") {
|
|
11992
|
+
return {
|
|
11993
|
+
type: "logs",
|
|
11994
|
+
logs: output.logs || ""
|
|
11995
|
+
};
|
|
11996
|
+
}
|
|
11997
|
+
if (output.type === "image") {
|
|
11998
|
+
var _output_image;
|
|
11999
|
+
return {
|
|
12000
|
+
type: "image",
|
|
12001
|
+
image: {
|
|
12002
|
+
file_id: ((_output_image = output.image) === null || _output_image === void 0 ? void 0 : _output_image.fileId) || ""
|
|
12003
|
+
}
|
|
12004
|
+
};
|
|
12005
|
+
}
|
|
12006
|
+
return output;
|
|
12007
|
+
})) || []
|
|
12008
|
+
}
|
|
12009
|
+
};
|
|
12010
|
+
} else if (tc.type === "file_search") {
|
|
12011
|
+
return {
|
|
12012
|
+
id: tc.id,
|
|
12013
|
+
type: "file_search",
|
|
12014
|
+
file_search: tc.fileSearch || {}
|
|
12015
|
+
};
|
|
12016
|
+
} else if (tc.type === "function") {
|
|
12017
|
+
var _tc_function, _tc_function1, _tc_function2;
|
|
12018
|
+
return {
|
|
12019
|
+
id: tc.id,
|
|
12020
|
+
type: "function",
|
|
12021
|
+
function: {
|
|
12022
|
+
name: ((_tc_function = tc.function) === null || _tc_function === void 0 ? void 0 : _tc_function.name) || "",
|
|
12023
|
+
arguments: ((_tc_function1 = tc.function) === null || _tc_function1 === void 0 ? void 0 : _tc_function1.arguments) || "",
|
|
12024
|
+
output: ((_tc_function2 = tc.function) === null || _tc_function2 === void 0 ? void 0 : _tc_function2.output) || null
|
|
12025
|
+
}
|
|
12026
|
+
};
|
|
12027
|
+
}
|
|
12028
|
+
return tc;
|
|
12029
|
+
})) || []
|
|
12030
|
+
};
|
|
12031
|
+
} else {
|
|
12032
|
+
stepDetails = data.stepDetails;
|
|
12033
|
+
}
|
|
12034
|
+
}
|
|
12035
|
+
return {
|
|
12036
|
+
event: eventType,
|
|
12037
|
+
data: {
|
|
12038
|
+
id: data.id,
|
|
12039
|
+
object: "thread.run.step",
|
|
12040
|
+
created_at: dayjs29(data.createdAt).unix(),
|
|
12041
|
+
assistant_id: assistantId,
|
|
12042
|
+
thread_id: data.threadId,
|
|
12043
|
+
run_id: data.runId,
|
|
12044
|
+
type: data.type,
|
|
12045
|
+
status: data.status,
|
|
12046
|
+
step_details: stepDetails,
|
|
12047
|
+
last_error: data.lastError || null,
|
|
12048
|
+
expired_at: null,
|
|
12049
|
+
cancelled_at: data.cancelledAt ? dayjs29(data.cancelledAt).unix() : null,
|
|
12050
|
+
failed_at: data.failedAt ? dayjs29(data.failedAt).unix() : null,
|
|
12051
|
+
completed_at: data.completedAt ? dayjs29(data.completedAt).unix() : null,
|
|
12052
|
+
metadata: data.metadata || {},
|
|
12053
|
+
usage: null
|
|
12054
|
+
}
|
|
12055
|
+
};
|
|
12056
|
+
}
|
|
12057
|
+
if (eventType === "thread.created") {
|
|
12058
|
+
return {
|
|
12059
|
+
event: "thread.created",
|
|
12060
|
+
data: {
|
|
12061
|
+
id: data.id,
|
|
12062
|
+
object: "thread",
|
|
12063
|
+
created_at: dayjs29(data.createdAt).unix(),
|
|
12064
|
+
metadata: data.metadata || {},
|
|
12065
|
+
tool_resources: data.toolResources || null
|
|
12066
|
+
}
|
|
12067
|
+
};
|
|
12068
|
+
}
|
|
12069
|
+
return null;
|
|
12070
|
+
}
|
|
12071
|
+
var azureAgentsRunAdapter = function(param) {
|
|
12072
|
+
var azureAiProject = param.azureAiProject;
|
|
12073
|
+
var getOpenaiAssistant = function(param) {
|
|
12074
|
+
var assistantId = param.assistantId;
|
|
12075
|
+
return _async_to_generator(function() {
|
|
12076
|
+
return _ts_generator(this, function(_state) {
|
|
12077
|
+
return [
|
|
12078
|
+
2,
|
|
12079
|
+
{
|
|
12080
|
+
id: assistantId
|
|
12081
|
+
}
|
|
12082
|
+
];
|
|
12083
|
+
});
|
|
12084
|
+
})();
|
|
12085
|
+
};
|
|
12086
|
+
var handleRun = function(param) {
|
|
12087
|
+
var threadId = param.threadId, assistantId = param.assistantId, instructions = param.instructions, tools = param.tools, onEvent2 = param.onEvent;
|
|
12088
|
+
return _async_to_generator(function() {
|
|
12089
|
+
var azureAgentId, createOptions, runResponse, stream, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, e, errorRunId;
|
|
12090
|
+
return _ts_generator(this, function(_state) {
|
|
12091
|
+
switch(_state.label){
|
|
12092
|
+
case 0:
|
|
12093
|
+
_state.trys.push([
|
|
12094
|
+
0,
|
|
12095
|
+
15,
|
|
12096
|
+
,
|
|
12097
|
+
17
|
|
12098
|
+
]);
|
|
12099
|
+
azureAgentId = assistantId;
|
|
12100
|
+
createOptions = {};
|
|
12101
|
+
if (instructions) {
|
|
12102
|
+
createOptions.instructions = instructions;
|
|
12103
|
+
}
|
|
12104
|
+
if (tools) {
|
|
12105
|
+
createOptions.tools = tools;
|
|
12106
|
+
}
|
|
12107
|
+
runResponse = azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions);
|
|
12108
|
+
return [
|
|
12109
|
+
4,
|
|
12110
|
+
runResponse.stream()
|
|
12111
|
+
];
|
|
12112
|
+
case 1:
|
|
12113
|
+
stream = _state.sent();
|
|
12114
|
+
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
12115
|
+
_state.label = 2;
|
|
12116
|
+
case 2:
|
|
12117
|
+
_state.trys.push([
|
|
12118
|
+
2,
|
|
12119
|
+
8,
|
|
12120
|
+
9,
|
|
12121
|
+
14
|
|
12122
|
+
]);
|
|
12123
|
+
_iterator = _async_iterator(stream);
|
|
12124
|
+
_state.label = 3;
|
|
12125
|
+
case 3:
|
|
12126
|
+
return [
|
|
12127
|
+
4,
|
|
12128
|
+
_iterator.next()
|
|
12129
|
+
];
|
|
12130
|
+
case 4:
|
|
12131
|
+
if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
|
|
12132
|
+
3,
|
|
12133
|
+
7
|
|
12134
|
+
];
|
|
12135
|
+
_value = _step.value;
|
|
12136
|
+
azureEvent = _value;
|
|
12137
|
+
openaiEvent = convertAzureEventToOpenAI2(azureEvent, assistantId);
|
|
12138
|
+
if (!openaiEvent) return [
|
|
12139
|
+
3,
|
|
12140
|
+
6
|
|
12141
|
+
];
|
|
12142
|
+
return [
|
|
12143
|
+
4,
|
|
12144
|
+
onEvent2(openaiEvent)
|
|
12145
|
+
];
|
|
12146
|
+
case 5:
|
|
12147
|
+
_state.sent();
|
|
12148
|
+
_state.label = 6;
|
|
12149
|
+
case 6:
|
|
12150
|
+
_iteratorAbruptCompletion = false;
|
|
12151
|
+
return [
|
|
12152
|
+
3,
|
|
12153
|
+
3
|
|
12154
|
+
];
|
|
12155
|
+
case 7:
|
|
12156
|
+
return [
|
|
12157
|
+
3,
|
|
12158
|
+
14
|
|
12159
|
+
];
|
|
12160
|
+
case 8:
|
|
12161
|
+
err = _state.sent();
|
|
12162
|
+
_didIteratorError = true;
|
|
12163
|
+
_iteratorError = err;
|
|
12164
|
+
return [
|
|
12165
|
+
3,
|
|
12166
|
+
14
|
|
12167
|
+
];
|
|
12168
|
+
case 9:
|
|
12169
|
+
_state.trys.push([
|
|
12170
|
+
9,
|
|
12171
|
+
,
|
|
12172
|
+
12,
|
|
12173
|
+
13
|
|
12174
|
+
]);
|
|
12175
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
12176
|
+
3,
|
|
12177
|
+
11
|
|
12178
|
+
];
|
|
12179
|
+
return [
|
|
12180
|
+
4,
|
|
12181
|
+
_iterator.return()
|
|
12182
|
+
];
|
|
12183
|
+
case 10:
|
|
12184
|
+
_state.sent();
|
|
12185
|
+
_state.label = 11;
|
|
12186
|
+
case 11:
|
|
12187
|
+
return [
|
|
12188
|
+
3,
|
|
12189
|
+
13
|
|
12190
|
+
];
|
|
12191
|
+
case 12:
|
|
12192
|
+
if (_didIteratorError) {
|
|
12193
|
+
throw _iteratorError;
|
|
12194
|
+
}
|
|
12195
|
+
return [
|
|
12196
|
+
7
|
|
12197
|
+
];
|
|
12198
|
+
case 13:
|
|
12199
|
+
return [
|
|
12200
|
+
7
|
|
12201
|
+
];
|
|
12202
|
+
case 14:
|
|
12203
|
+
return [
|
|
12204
|
+
3,
|
|
12205
|
+
17
|
|
12206
|
+
];
|
|
12207
|
+
case 15:
|
|
12208
|
+
e = _state.sent();
|
|
12209
|
+
errorRunId = "run_".concat(uid10(18));
|
|
12210
|
+
return [
|
|
12211
|
+
4,
|
|
12212
|
+
onEvent2({
|
|
12213
|
+
event: "thread.run.failed",
|
|
12214
|
+
data: {
|
|
12215
|
+
id: errorRunId,
|
|
12216
|
+
object: "thread.run",
|
|
12217
|
+
created_at: dayjs29().unix(),
|
|
12218
|
+
thread_id: threadId,
|
|
12219
|
+
assistant_id: assistantId,
|
|
12220
|
+
status: "failed",
|
|
12221
|
+
required_action: null,
|
|
12222
|
+
last_error: {
|
|
12223
|
+
code: "server_error",
|
|
12224
|
+
message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
|
|
12225
|
+
},
|
|
12226
|
+
expires_at: null,
|
|
12227
|
+
started_at: dayjs29().unix(),
|
|
12228
|
+
cancelled_at: null,
|
|
12229
|
+
failed_at: dayjs29().unix(),
|
|
12230
|
+
completed_at: null,
|
|
12231
|
+
incomplete_details: null,
|
|
12232
|
+
model: "",
|
|
12233
|
+
instructions: "",
|
|
12234
|
+
tools: [],
|
|
12235
|
+
metadata: {},
|
|
12236
|
+
temperature: null,
|
|
12237
|
+
top_p: null,
|
|
12238
|
+
max_prompt_tokens: null,
|
|
12239
|
+
max_completion_tokens: null,
|
|
12240
|
+
truncation_strategy: {
|
|
12241
|
+
type: "auto",
|
|
12242
|
+
last_messages: null
|
|
12243
|
+
},
|
|
12244
|
+
response_format: "auto",
|
|
12245
|
+
tool_choice: "auto",
|
|
12246
|
+
parallel_tool_calls: true,
|
|
12247
|
+
usage: null
|
|
12248
|
+
}
|
|
12249
|
+
})
|
|
12250
|
+
];
|
|
12251
|
+
case 16:
|
|
12252
|
+
_state.sent();
|
|
12253
|
+
return [
|
|
12254
|
+
3,
|
|
12255
|
+
17
|
|
12256
|
+
];
|
|
12257
|
+
case 17:
|
|
12258
|
+
return [
|
|
12259
|
+
2
|
|
12260
|
+
];
|
|
12261
|
+
}
|
|
12262
|
+
});
|
|
12263
|
+
})();
|
|
12264
|
+
};
|
|
12265
|
+
return {
|
|
12266
|
+
handleRun: handleRun,
|
|
12267
|
+
getOpenaiAssistant: getOpenaiAssistant
|
|
12268
|
+
};
|
|
12269
|
+
};
|
|
12270
|
+
export { anthropicClientAdapter, azureAgentsRunAdapter, azureAgentsStorageAdapter, azureAiProjectClientAdapter, azureOpenaiClientAdapter, completionsRunAdapter, googleClientAdapter, groqClientAdapter, humirisClientAdapter, mistralClientAdapter, ollamaClientAdapter, openaiClientAdapter, perplexityClientAdapter, prismaStorageAdapter, responsesRunAdapter, responsesStorageAdapter, supercompat, togetherClientAdapter };
|
|
10346
12271
|
//# sourceMappingURL=index.js.map
|