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