supercompat 3.10.2 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs 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) {
@@ -2467,7 +2485,7 @@ var post5 = function(param) {
2467
2485
  stream = new ReadableStream({
2468
2486
  start: function start(controller) {
2469
2487
  return _async_to_generator(function() {
2470
- var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex, parseJson2, getOrCreateIndexForToolUseId, assignBlockToToolUse, markComputerToolUse, getToolUseIdFromBlock, emitNormalizedToolCall, getOrCreateIndexForBlock, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _ref, chunk, toolUseId, _toolUseIdArgumentBuffer_keys, firstKey, _toolUseIdArgumentBuffer_get, buffered, parsed, normalized, toolCallIndex, chunkIndex, _toolUseIdArgumentBuffer_get1, buffered1, toolCallIndex1, chunkIndex1, messageDelta, delta, toolUseId1, _toolUseIdArgumentBuffer_keys1, firstKey1, _toolUseIdArgumentBuffer_get2, existing, _chunk_delta_partial_json, updated, parsed1, normalized1, toolCallIndex2, chunkIndex2, _toolUseIdArgumentBuffer_get3, existing1, _chunk_delta_partial_json1, index, messageDelta1, delta1, toolName, normalizedToolName, index1, index2, _chunk_content_block_content, outputPayload, _getToolUseIdFromBlock, toolCallId, index3, _getToolUseIdFromBlock1, toolCallId1, _chunk_content_block, _toolUseId, _type, _id, rest, index4, _chunk_content_block_content1, outputPayload1, messageDelta2, messageDelta3, err;
2488
+ var blockIndexToToolUseId, toolUseIdToIndex, toolUseIdArgumentBuffer, computerToolUseIds, normalizedComputerCalls, nextToolCallIndex, parseJson2, getOrCreateIndexForToolUseId, assignBlockToToolUse, markComputerToolUse, getToolUseIdFromBlock, emitNormalizedToolCall, getOrCreateIndexForBlock, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _ref, chunk, toolUseId, _toolUseIdArgumentBuffer_get, buffered, parsed, normalized, toolCallIndex, chunkIndex, _toolUseIdArgumentBuffer_get1, buffered1, toolCallIndex1, chunkIndex1, messageDelta, delta, toolUseId1, _toolUseIdArgumentBuffer_get2, existing, _chunk_delta_partial_json, updated, parsed1, normalized1, toolCallIndex2, chunkIndex2, _toolUseIdArgumentBuffer_get3, existing1, _chunk_delta_partial_json1, index, messageDelta1, delta1, toolName, normalizedToolName, index1, index2, _chunk_content_block_content, outputPayload, _getToolUseIdFromBlock, toolCallId, index3, _getToolUseIdFromBlock1, toolCallId1, _chunk_content_block, _toolUseId, _type, _id, rest, index4, _chunk_content_block_content1, outputPayload1, messageDelta2, messageDelta3, err;
2471
2489
  return _ts_generator(this, function(_state) {
2472
2490
  switch(_state.label){
2473
2491
  case 0:
@@ -2572,10 +2590,6 @@ var post5 = function(param) {
2572
2590
  chunk = _ref;
2573
2591
  if (chunk.type === "content_block_stop") {
2574
2592
  toolUseId = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
2575
- if (!toolUseId && toolUseIdArgumentBuffer.size === 1) {
2576
- _toolUseIdArgumentBuffer_keys = _sliced_to_array(toolUseIdArgumentBuffer.keys(), 1), firstKey = _toolUseIdArgumentBuffer_keys[0];
2577
- toolUseId = firstKey;
2578
- }
2579
2593
  if (toolUseId && computerToolUseIds.has(toolUseId) && !normalizedComputerCalls.has(toolUseId)) {
2580
2594
  ;
2581
2595
  buffered = (_toolUseIdArgumentBuffer_get = toolUseIdArgumentBuffer.get(toolUseId)) !== null && _toolUseIdArgumentBuffer_get !== void 0 ? _toolUseIdArgumentBuffer_get : "";
@@ -2638,10 +2652,6 @@ var post5 = function(param) {
2638
2652
  delta = void 0;
2639
2653
  if (chunk.delta.type === "input_json_delta") {
2640
2654
  toolUseId1 = typeof chunk.index === "number" ? blockIndexToToolUseId.get(chunk.index) : void 0;
2641
- if (!toolUseId1 && toolUseIdArgumentBuffer.size === 1) {
2642
- _toolUseIdArgumentBuffer_keys1 = _sliced_to_array(toolUseIdArgumentBuffer.keys(), 1), firstKey1 = _toolUseIdArgumentBuffer_keys1[0];
2643
- toolUseId1 = firstKey1;
2644
- }
2645
2655
  if (toolUseId1 && computerToolUseIds.has(toolUseId1)) {
2646
2656
  ;
2647
2657
  existing = (_toolUseIdArgumentBuffer_get2 = toolUseIdArgumentBuffer.get(toolUseId1)) !== null && _toolUseIdArgumentBuffer_get2 !== void 0 ? _toolUseIdArgumentBuffer_get2 : "";
@@ -4055,11 +4065,11 @@ var serializeMessage3 = function(param) {
4055
4065
  message: message
4056
4066
  })
4057
4067
  ];
4058
- var run3 = message.run;
4059
- if (!run3) return result;
4068
+ var run4 = message.run;
4069
+ if (!run4) return result;
4060
4070
  var messageToolCalls = ((_message_metadata = message.metadata) === null || _message_metadata === void 0 ? void 0 : _message_metadata.toolCalls) || [];
4061
4071
  messageToolCalls.forEach(function(tc) {
4062
- var runStep = run3.runSteps.find(function(rs) {
4072
+ var runStep = run4.runSteps.find(function(rs) {
4063
4073
  if (rs.type !== "tool_calls") return false;
4064
4074
  var stepDetails2 = rs.step_details;
4065
4075
  if (!Array.isArray(stepDetails2.tool_calls)) return false;
@@ -4083,16 +4093,16 @@ var serializeMessage3 = function(param) {
4083
4093
  };
4084
4094
  // src/adapters/run/completionsRunAdapter/messages/index.ts
4085
4095
  var messages = function(param) {
4086
- var run3 = param.run, getMessages2 = param.getMessages;
4096
+ var run4 = param.run, getMessages2 = param.getMessages;
4087
4097
  return _async_to_generator(function() {
4088
4098
  var _, _1, _2;
4089
4099
  return _ts_generator(this, function(_state) {
4090
4100
  switch(_state.label){
4091
4101
  case 0:
4092
- _1 = (_ = _to_consumable_array(run3.instructions ? [
4102
+ _1 = (_ = _to_consumable_array(run4.instructions ? [
4093
4103
  {
4094
4104
  role: "system",
4095
- content: run3.instructions
4105
+ content: run4.instructions
4096
4106
  }
4097
4107
  ] : [])).concat;
4098
4108
  _2 = (0, import_radash6.flat);
@@ -4191,18 +4201,18 @@ var toolCallsData = function(param) {
4191
4201
  var completionsRunAdapter = function() {
4192
4202
  return {
4193
4203
  handleRun: function(param) {
4194
- 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;
4195
4205
  return _async_to_generator(function() {
4196
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;
4197
4207
  return _ts_generator(this, function(_state) {
4198
4208
  switch(_state.label){
4199
4209
  case 0:
4200
- if (run3.status !== "queued") return [
4210
+ if (run4.status !== "queued") return [
4201
4211
  2
4202
4212
  ];
4203
4213
  onEvent2({
4204
4214
  event: "thread.run.in_progress",
4205
- data: _object_spread_props(_object_spread({}, run3), {
4215
+ data: _object_spread_props(_object_spread({}, run4), {
4206
4216
  status: "in_progress"
4207
4217
  })
4208
4218
  });
@@ -4210,15 +4220,15 @@ var completionsRunAdapter = function() {
4210
4220
  return [
4211
4221
  4,
4212
4222
  messages({
4213
- run: run3,
4223
+ run: run4,
4214
4224
  getMessages: getMessages2
4215
4225
  })
4216
4226
  ];
4217
4227
  case 1:
4218
4228
  opts = _object_spread.apply(void 0, [
4219
- (_tmp.messages = _state.sent(), _tmp.model = run3.model, _tmp.stream = true, _tmp.response_format = run3.response_format, _tmp),
4220
- (0, import_radash7.isEmpty)(run3.tools) ? {} : {
4221
- 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
4222
4232
  }
4223
4233
  ]);
4224
4234
  _state.label = 2;
@@ -4246,7 +4256,7 @@ var completionsRunAdapter = function() {
4246
4256
  2,
4247
4257
  onEvent2({
4248
4258
  event: "thread.run.failed",
4249
- data: _object_spread_props(_object_spread({}, run3), {
4259
+ data: _object_spread_props(_object_spread({}, run4), {
4250
4260
  failed_at: (0, import_dayjs.default)().unix(),
4251
4261
  status: "in_progress",
4252
4262
  last_error: {
@@ -4265,14 +4275,14 @@ var completionsRunAdapter = function() {
4265
4275
  id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
4266
4276
  object: "thread.message",
4267
4277
  completed_at: null,
4268
- run_id: run3.id,
4278
+ run_id: run4.id,
4269
4279
  created_at: (0, import_dayjs.default)().unix(),
4270
- assistant_id: run3.assistant_id,
4280
+ assistant_id: run4.assistant_id,
4271
4281
  incomplete_at: null,
4272
4282
  incomplete_details: null,
4273
4283
  metadata: {},
4274
4284
  attachments: [],
4275
- thread_id: run3.thread_id,
4285
+ thread_id: run4.thread_id,
4276
4286
  content: [
4277
4287
  {
4278
4288
  text: {
@@ -4294,9 +4304,9 @@ var completionsRunAdapter = function() {
4294
4304
  data: {
4295
4305
  id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
4296
4306
  object: "thread.run.step",
4297
- run_id: run3.id,
4298
- assistant_id: run3.assistant_id,
4299
- thread_id: run3.thread_id,
4307
+ run_id: run4.id,
4308
+ assistant_id: run4.assistant_id,
4309
+ thread_id: run4.thread_id,
4300
4310
  type: "message_creation",
4301
4311
  status: "completed",
4302
4312
  completed_at: (0, import_dayjs.default)().unix(),
@@ -4365,9 +4375,9 @@ var completionsRunAdapter = function() {
4365
4375
  data: {
4366
4376
  id: "THERE_IS_A_BUG_IN_SUPERCOMPAT_IF_YOU_SEE_THIS_ID",
4367
4377
  object: "thread.run.step",
4368
- run_id: run3.id,
4369
- assistant_id: run3.assistant_id,
4370
- thread_id: run3.thread_id,
4378
+ run_id: run4.id,
4379
+ assistant_id: run4.assistant_id,
4380
+ thread_id: run4.thread_id,
4371
4381
  type: "tool_calls",
4372
4382
  status: "in_progress",
4373
4383
  completed_at: null,
@@ -4393,7 +4403,7 @@ var completionsRunAdapter = function() {
4393
4403
  event: "thread.run.step.delta",
4394
4404
  data: {
4395
4405
  object: "thread.run.step.delta",
4396
- run_id: run3.id,
4406
+ run_id: run4.id,
4397
4407
  id: toolCallsRunStep.id,
4398
4408
  delta: {
4399
4409
  step_details: {
@@ -4548,7 +4558,7 @@ var completionsRunAdapter = function() {
4548
4558
  2,
4549
4559
  onEvent2({
4550
4560
  event: "thread.run.completed",
4551
- data: _object_spread_props(_object_spread({}, run3), {
4561
+ data: _object_spread_props(_object_spread({}, run4), {
4552
4562
  status: "completed",
4553
4563
  completed_at: (0, import_dayjs.default)().unix()
4554
4564
  })
@@ -4591,7 +4601,7 @@ var completionsRunAdapter = function() {
4591
4601
  2,
4592
4602
  onEvent2({
4593
4603
  event: "thread.run.requires_action",
4594
- data: _object_spread_props(_object_spread({}, run3), {
4604
+ data: _object_spread_props(_object_spread({}, run4), {
4595
4605
  status: "requires_action",
4596
4606
  required_action: {
4597
4607
  type: "submit_tool_outputs",
@@ -4638,7 +4648,7 @@ var post10 = function(param) {
4638
4648
  var prisma = param.prisma;
4639
4649
  return function(_urlString, options) {
4640
4650
  return _async_to_generator(function() {
4641
- var body, messages4, metadataRecord, assistantId, initialCreatedAt, messageData, threadData, thread;
4651
+ var body, messages5, metadataRecord, assistantId, initialCreatedAt, messageData, threadData, thread;
4642
4652
  return _ts_generator(this, function(_state) {
4643
4653
  switch(_state.label){
4644
4654
  case 0:
@@ -4646,14 +4656,14 @@ var post10 = function(param) {
4646
4656
  throw new Error("No body provided");
4647
4657
  }
4648
4658
  body = JSON.parse(options.body);
4649
- messages4 = body.messages || [];
4659
+ messages5 = body.messages || [];
4650
4660
  metadataRecord = body.metadata || {};
4651
4661
  assistantId = typeof metadataRecord.assistantId === "string" ? metadataRecord.assistantId : void 0;
4652
4662
  if (!assistantId) {
4653
4663
  throw new Error("assistantId is required to create a thread");
4654
4664
  }
4655
- initialCreatedAt = (0, import_dayjs3.default)().subtract(messages4.length, "seconds");
4656
- messageData = messages4.map(function(message, index) {
4665
+ initialCreatedAt = (0, import_dayjs3.default)().subtract(messages5.length, "seconds");
4666
+ messageData = messages5.map(function(message, index) {
4657
4667
  var _message_attachments;
4658
4668
  return {
4659
4669
  role: message.role === "user" ? "USER" : "ASSISTANT",
@@ -4822,7 +4832,7 @@ var get10 = function(param) {
4822
4832
  var prisma = param.prisma;
4823
4833
  return function(urlString) {
4824
4834
  return _async_to_generator(function() {
4825
- 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;
4826
4836
  return _ts_generator(this, function(_state) {
4827
4837
  switch(_state.label){
4828
4838
  case 0:
@@ -4852,17 +4862,17 @@ var get10 = function(param) {
4852
4862
  ];
4853
4863
  case 1:
4854
4864
  messagesPlusOne = _state.sent();
4855
- messages4 = messagesPlusOne.slice(0, pageSize);
4865
+ messages5 = messagesPlusOne.slice(0, pageSize);
4856
4866
  return [
4857
4867
  2,
4858
4868
  new Response(JSON.stringify({
4859
- data: messages4.map(function(message) {
4869
+ data: messages5.map(function(message) {
4860
4870
  return serializeMessage4({
4861
4871
  message: message
4862
4872
  });
4863
4873
  }),
4864
4874
  has_more: messagesPlusOne.length > pageSize,
4865
- 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
4866
4876
  }), {
4867
4877
  status: 200,
4868
4878
  headers: {
@@ -4892,26 +4902,26 @@ var import_radash11 = require("radash");
4892
4902
  // src/adapters/storage/prismaStorageAdapter/threads/runs/serializeRun.ts
4893
4903
  var import_dayjs5 = __toESM(require("dayjs"), 1);
4894
4904
  var serializeRun = function(param) {
4895
- var run3 = param.run;
4905
+ var run4 = param.run;
4896
4906
  return {
4897
- id: run3.id,
4907
+ id: run4.id,
4898
4908
  object: "thread.run",
4899
- created_at: (0, import_dayjs5.default)(run3.createdAt).unix(),
4900
- thread_id: run3.threadId,
4901
- assistant_id: run3.assistantId,
4902
- status: run3.status.toLowerCase(),
4903
- required_action: run3.requiredAction,
4904
- last_error: run3.lastError,
4905
- expires_at: (0, import_dayjs5.default)(run3.expiresAt).unix(),
4906
- started_at: run3.startedAt ? (0, import_dayjs5.default)(run3.startedAt).unix() : null,
4907
- cancelled_at: run3.cancelledAt ? (0, import_dayjs5.default)(run3.cancelledAt).unix() : null,
4908
- failed_at: run3.failedAt ? (0, import_dayjs5.default)(run3.failedAt).unix() : null,
4909
- completed_at: run3.completedAt ? (0, import_dayjs5.default)(run3.completedAt).unix() : null,
4910
- model: run3.model,
4911
- instructions: run3.instructions,
4912
- tools: run3.tools,
4913
- metadata: run3.metadata,
4914
- 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,
4915
4925
  truncation_strategy: {
4916
4926
  type: "auto"
4917
4927
  },
@@ -4927,29 +4937,29 @@ var serializeRun = function(param) {
4927
4937
  };
4928
4938
  };
4929
4939
  // src/adapters/storage/prismaStorageAdapter/threads/runs/mapPrismaRun.ts
4930
- var mapPrismaRun = function(run3) {
4931
- var _run3_startedAt, _run3_cancelledAt, _run3_failedAt, _run3_completedAt;
4940
+ var mapPrismaRun = function(run4) {
4941
+ var _run4_startedAt, _run4_cancelledAt, _run4_failedAt, _run4_completedAt;
4932
4942
  return {
4933
- id: run3.id,
4934
- threadId: run3.threadId,
4935
- assistantId: run3.assistantId,
4936
- status: run3.status,
4937
- requiredAction: run3.requiredAction,
4938
- lastError: run3.lastError,
4939
- expiresAt: run3.expiresAt,
4940
- startedAt: (_run3_startedAt = run3.startedAt) !== null && _run3_startedAt !== void 0 ? _run3_startedAt : null,
4941
- cancelledAt: (_run3_cancelledAt = run3.cancelledAt) !== null && _run3_cancelledAt !== void 0 ? _run3_cancelledAt : null,
4942
- failedAt: (_run3_failedAt = run3.failedAt) !== null && _run3_failedAt !== void 0 ? _run3_failedAt : null,
4943
- completedAt: (_run3_completedAt = run3.completedAt) !== null && _run3_completedAt !== void 0 ? _run3_completedAt : null,
4944
- model: run3.model,
4945
- instructions: run3.instructions,
4946
- tools: run3.tools,
4947
- metadata: run3.metadata,
4948
- usage: run3.usage,
4949
- truncationStrategy: run3.truncationStrategy,
4950
- responseFormat: run3.responseFormat,
4951
- createdAt: run3.createdAt,
4952
- 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
4953
4963
  };
4954
4964
  };
4955
4965
  // src/adapters/storage/prismaStorageAdapter/threads/runs/get.ts
@@ -4957,7 +4967,7 @@ var get11 = function(param) {
4957
4967
  var prisma = param.prisma;
4958
4968
  return function(urlString) {
4959
4969
  return _async_to_generator(function() {
4960
- 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;
4961
4971
  return _ts_generator(this, function(_state) {
4962
4972
  switch(_state.label){
4963
4973
  case 0:
@@ -4987,17 +4997,17 @@ var get11 = function(param) {
4987
4997
  ];
4988
4998
  case 1:
4989
4999
  runsPlusOne = _state.sent();
4990
- runs3 = runsPlusOne.slice(0, pageSize);
5000
+ runs4 = runsPlusOne.slice(0, pageSize);
4991
5001
  return [
4992
5002
  2,
4993
5003
  new Response(JSON.stringify({
4994
- data: runs3.map(function(run3) {
5004
+ data: runs4.map(function(run4) {
4995
5005
  return serializeRun({
4996
- run: mapPrismaRun(run3)
5006
+ run: mapPrismaRun(run4)
4997
5007
  });
4998
5008
  }),
4999
5009
  has_more: runsPlusOne.length > pageSize,
5000
- 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
5001
5011
  }), {
5002
5012
  status: 200,
5003
5013
  headers: {
@@ -5328,37 +5338,37 @@ var onEvent = function(param) {
5328
5338
  };
5329
5339
  // src/adapters/storage/prismaStorageAdapter/threads/runs/getMessages.ts
5330
5340
  var getTake = function(param) {
5331
- var run3 = param.run;
5341
+ var run4 = param.run;
5332
5342
  if ([
5333
5343
  "auto",
5334
5344
  "disabled"
5335
- ].includes(run3.truncationStrategy.type)) {
5345
+ ].includes(run4.truncationStrategy.type)) {
5336
5346
  return null;
5337
5347
  }
5338
- if (run3.truncationStrategy.type === "last_messages") {
5339
- if (!run3.truncationStrategy.last_messages) {
5348
+ if (run4.truncationStrategy.type === "last_messages") {
5349
+ if (!run4.truncationStrategy.last_messages) {
5340
5350
  throw new Error("Truncation strategy last_messages is required");
5341
5351
  }
5342
- return -run3.truncationStrategy.last_messages;
5352
+ return -run4.truncationStrategy.last_messages;
5343
5353
  }
5344
- throw new Error("Unsupported truncation strategy type: ".concat(run3.truncationStrategy.type));
5354
+ throw new Error("Unsupported truncation strategy type: ".concat(run4.truncationStrategy.type));
5345
5355
  };
5346
5356
  var getMessages = function(param) {
5347
- var prisma = param.prisma, run3 = param.run;
5357
+ var prisma = param.prisma, run4 = param.run;
5348
5358
  return function() {
5349
5359
  return _async_to_generator(function() {
5350
- var take, messages4;
5360
+ var take, messages5;
5351
5361
  return _ts_generator(this, function(_state) {
5352
5362
  switch(_state.label){
5353
5363
  case 0:
5354
5364
  take = getTake({
5355
- run: run3
5365
+ run: run4
5356
5366
  });
5357
5367
  return [
5358
5368
  4,
5359
5369
  prisma.message.findMany(_object_spread({
5360
5370
  where: {
5361
- threadId: run3.threadId
5371
+ threadId: run4.threadId
5362
5372
  },
5363
5373
  include: {
5364
5374
  run: {
@@ -5375,10 +5385,10 @@ var getMessages = function(param) {
5375
5385
  } : {}))
5376
5386
  ];
5377
5387
  case 1:
5378
- messages4 = _state.sent();
5388
+ messages5 = _state.sent();
5379
5389
  return [
5380
5390
  2,
5381
- messages4.map(function(message) {
5391
+ messages5.map(function(message) {
5382
5392
  return _object_spread_props(_object_spread({}, serializeMessage4({
5383
5393
  message: message
5384
5394
  })), {
@@ -5405,7 +5415,7 @@ var post12 = function(param) {
5405
5415
  return function(urlString, options) {
5406
5416
  return _async_to_generator(function() {
5407
5417
  var url, _url_pathname_match, threadId, body, assistant_id, stream, assistant, _ref, model, instructions, // additional_instructions,
5408
- tools, metadata, response_format, truncation_strategy, run3, data, readableStream;
5418
+ tools, metadata, response_format, truncation_strategy, run4, data, readableStream;
5409
5419
  return _ts_generator(this, function(_state) {
5410
5420
  switch(_state.label){
5411
5421
  case 0:
@@ -5466,9 +5476,9 @@ var post12 = function(param) {
5466
5476
  })
5467
5477
  ];
5468
5478
  case 2:
5469
- run3 = _state.sent();
5479
+ run4 = _state.sent();
5470
5480
  data = serializeRun({
5471
- run: run3
5481
+ run: run4
5472
5482
  });
5473
5483
  readableStream = new ReadableStream({
5474
5484
  start: function start(controller) {
@@ -5497,7 +5507,7 @@ var post12 = function(param) {
5497
5507
  }),
5498
5508
  getMessages: getMessages({
5499
5509
  prisma: prisma,
5500
- run: run3
5510
+ run: run4
5501
5511
  })
5502
5512
  })
5503
5513
  ];
@@ -5520,7 +5530,7 @@ var post12 = function(param) {
5520
5530
  })({
5521
5531
  event: "thread.run.failed",
5522
5532
  data: {
5523
- id: run3.id,
5533
+ id: run4.id,
5524
5534
  failed_at: (0, import_dayjs7.default)().unix(),
5525
5535
  last_error: {
5526
5536
  code: "server_error",
@@ -5588,7 +5598,7 @@ var get12 = function(param) {
5588
5598
  var prisma = param.prisma;
5589
5599
  return function(urlString) {
5590
5600
  return _async_to_generator(function() {
5591
- var url, _url_pathname_match, threadId, runId, run3;
5601
+ var url, _url_pathname_match, threadId, runId, run4;
5592
5602
  return _ts_generator(this, function(_state) {
5593
5603
  switch(_state.label){
5594
5604
  case 0:
@@ -5604,8 +5614,8 @@ var get12 = function(param) {
5604
5614
  })
5605
5615
  ];
5606
5616
  case 1:
5607
- run3 = _state.sent();
5608
- if (!run3) {
5617
+ run4 = _state.sent();
5618
+ if (!run4) {
5609
5619
  return [
5610
5620
  2,
5611
5621
  new Response(JSON.stringify({
@@ -5621,7 +5631,7 @@ var get12 = function(param) {
5621
5631
  return [
5622
5632
  2,
5623
5633
  new Response(JSON.stringify(serializeRun({
5624
- run: mapPrismaRun(run3)
5634
+ run: mapPrismaRun(run4)
5625
5635
  })), {
5626
5636
  status: 200,
5627
5637
  headers: {
@@ -5880,7 +5890,7 @@ var post13 = function(param) {
5880
5890
  var prisma = param.prisma, runAdapter = param.runAdapter;
5881
5891
  return function(urlString, options) {
5882
5892
  return _async_to_generator(function() {
5883
- 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;
5884
5894
  return _ts_generator(this, function(_state) {
5885
5895
  switch(_state.label){
5886
5896
  case 0:
@@ -5895,7 +5905,7 @@ var post13 = function(param) {
5895
5905
  readableStream = new ReadableStream({
5896
5906
  start: function start(controller) {
5897
5907
  return _async_to_generator(function() {
5898
- var run3;
5908
+ var run4;
5899
5909
  return _ts_generator(this, function(_state) {
5900
5910
  switch(_state.label){
5901
5911
  case 0:
@@ -5925,12 +5935,12 @@ var post13 = function(param) {
5925
5935
  })
5926
5936
  ];
5927
5937
  case 1:
5928
- run3 = _state.sent();
5938
+ run4 = _state.sent();
5929
5939
  return [
5930
5940
  4,
5931
5941
  runAdapter.handleRun({
5932
5942
  run: serializeRun({
5933
- run: run3
5943
+ run: run4
5934
5944
  }),
5935
5945
  onEvent: onEvent({
5936
5946
  controller: _object_spread_props(_object_spread({}, controller), {
@@ -5942,7 +5952,7 @@ var post13 = function(param) {
5942
5952
  }),
5943
5953
  getMessages: getMessages({
5944
5954
  prisma: prisma,
5945
- run: run3
5955
+ run: run4
5946
5956
  })
5947
5957
  })
5948
5958
  ];
@@ -5976,7 +5986,7 @@ var post13 = function(param) {
5976
5986
  })
5977
5987
  ];
5978
5988
  case 2:
5979
- run3 = _state.sent();
5989
+ run4 = _state.sent();
5980
5990
  return [
5981
5991
  4,
5982
5992
  new Promise(function(resolve) {
@@ -5990,7 +6000,7 @@ var post13 = function(param) {
5990
6000
  4,
5991
6001
  runAdapter.handleRun({
5992
6002
  run: serializeRun({
5993
- run: run3
6003
+ run: run4
5994
6004
  }),
5995
6005
  onEvent: onEvent({
5996
6006
  controller: _object_spread_props(_object_spread({}, controller), {
@@ -6002,7 +6012,7 @@ var post13 = function(param) {
6002
6012
  }),
6003
6013
  getMessages: getMessages({
6004
6014
  prisma: prisma,
6005
- run: run3
6015
+ run: run4
6006
6016
  })
6007
6017
  })
6008
6018
  ];
@@ -6024,7 +6034,7 @@ var post13 = function(param) {
6024
6034
  _state.sent();
6025
6035
  return [
6026
6036
  2,
6027
- new Response(JSON.stringify(run3), {
6037
+ new Response(JSON.stringify(run4), {
6028
6038
  status: 200,
6029
6039
  headers: {
6030
6040
  "Content-Type": "application/json"
@@ -6159,7 +6169,7 @@ var post15 = function(param) {
6159
6169
  var client = param.client;
6160
6170
  return function(_urlString, options) {
6161
6171
  return _async_to_generator(function() {
6162
- var body, messages4, metadata, conversation;
6172
+ var body, messages5, metadata, conversation;
6163
6173
  return _ts_generator(this, function(_state) {
6164
6174
  switch(_state.label){
6165
6175
  case 0:
@@ -6167,13 +6177,13 @@ var post15 = function(param) {
6167
6177
  throw new Error("Request body is required");
6168
6178
  }
6169
6179
  body = JSON.parse(options.body);
6170
- messages4 = body.messages || [];
6180
+ messages5 = body.messages || [];
6171
6181
  metadata = body.metadata || {};
6172
6182
  return [
6173
6183
  4,
6174
6184
  client.conversations.create({
6175
6185
  metadata: metadata,
6176
- items: messages4.map(function(message) {
6186
+ items: messages5.map(function(message) {
6177
6187
  return {
6178
6188
  type: "message",
6179
6189
  role: message.role === "user" ? "user" : "assistant",
@@ -8447,199 +8457,1571 @@ var responsesStorageAdapter = function() {
8447
8457
  };
8448
8458
  };
8449
8459
  };
8450
- // src/adapters/run/responsesRunAdapter/index.ts
8460
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/post.ts
8451
8461
  var import_dayjs21 = __toESM(require("dayjs"), 1);
8452
- var import_radash23 = require("radash");
8453
- var serializeToolCalls2 = function(param) {
8454
- var toolCalls = param.toolCalls;
8455
- return toolCalls.map(function(toolCall) {
8456
- if (toolCall.type === "function_call") {
8457
- return {
8458
- id: toolCall.call_id,
8459
- type: "function",
8460
- function: {
8461
- name: toolCall.name,
8462
- arguments: toolCall.arguments
8463
- }
8464
- };
8465
- } else if (toolCall.type === "computer_call") {
8466
- return {
8467
- id: toolCall.call_id,
8468
- type: "computer_call",
8469
- computer_call: {
8470
- action: toolCall.action,
8471
- pending_safety_checks: toolCall.pending_safety_checks
8472
- }
8473
- };
8474
- }
8475
- });
8476
- };
8477
- var responsesRunAdapter = function(param) {
8478
- var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
8479
- return p.then(function() {});
8480
- } : _param_waitUntil;
8481
- var cachedOpenaiAssistant = null;
8482
- var getOpenaiAssistant = function() {
8483
- 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) {
8484
8465
  return _async_to_generator(function() {
8485
- var args, _tmp;
8466
+ var body, metadata, thread, openaiThread;
8486
8467
  return _ts_generator(this, function(_state) {
8487
8468
  switch(_state.label){
8488
8469
  case 0:
8489
- args = {
8490
- select: {
8491
- id: id
8492
- }
8493
- };
8494
- if (!args.select.id) return [
8495
- 3,
8496
- 2
8497
- ];
8498
- _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 || {};
8499
8475
  return [
8500
8476
  4,
8501
- getDirectOpenaiAssistant({
8502
- select: {
8503
- id: true
8504
- }
8477
+ azureAiProject.agents.threads.create({
8478
+ metadata: metadata
8505
8479
  })
8506
8480
  ];
8507
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
+ };
8508
8490
  return [
8509
8491
  2,
8510
- (_tmp.id = _state.sent().id, _tmp)
8492
+ new Response(JSON.stringify(openaiThread), {
8493
+ status: 200,
8494
+ headers: {
8495
+ "Content-Type": "application/json"
8496
+ }
8497
+ })
8511
8498
  ];
8512
- case 2:
8513
- if (cachedOpenaiAssistant) return [
8514
- 2,
8515
- 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)
8516
8544
  ];
8545
+ case 1:
8546
+ message = _state.sent();
8517
8547
  return [
8518
8548
  4,
8519
- getDirectOpenaiAssistant()
8549
+ runAdapter.getOpenaiAssistant({
8550
+ select: {
8551
+ id: true
8552
+ }
8553
+ })
8520
8554
  ];
8521
- case 3:
8522
- 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
+ };
8523
8584
  return [
8524
8585
  2,
8525
- cachedOpenaiAssistant
8586
+ new Response(JSON.stringify(openaiMessage), {
8587
+ status: 200,
8588
+ headers: {
8589
+ "Content-Type": "application/json"
8590
+ }
8591
+ })
8526
8592
  ];
8527
8593
  }
8528
8594
  });
8529
8595
  })();
8530
8596
  };
8531
- var handleRun = function(param) {
8532
- 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) {
8533
8603
  return _async_to_generator(function() {
8534
- 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;
8535
8605
  return _ts_generator(this, function(_state) {
8536
8606
  switch(_state.label){
8537
8607
  case 0:
8538
- responseCreatedResponse = null;
8539
- responseCompletedResponse = null;
8540
- toolCalls = {};
8541
- mcpCalls = {};
8542
- codeInterpreterCalls = {};
8543
- itemIds = [];
8544
- _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
+ ];
8545
8617
  case 1:
8546
- _state.trys.push([
8547
- 1,
8548
- 151,
8549
- 154,
8550
- 155
8551
- ]);
8552
- _iteratorAbruptCompletion = false, _didIteratorError = false;
8553
- _state.label = 2;
8618
+ messages5 = _state.sent();
8619
+ return [
8620
+ 4,
8621
+ runAdapter.getOpenaiAssistant({
8622
+ select: {
8623
+ id: true
8624
+ }
8625
+ })
8626
+ ];
8554
8627
  case 2:
8555
- _state.trys.push([
8556
- 2,
8557
- 139,
8558
- 140,
8559
- 145
8560
- ]);
8561
- _iterator = _async_iterator(response);
8628
+ openaiAssistant = _state.sent();
8629
+ messagesList = [];
8630
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
8562
8631
  _state.label = 3;
8563
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:
8564
8642
  return [
8565
8643
  4,
8566
8644
  _iterator.next()
8567
8645
  ];
8568
- case 4:
8646
+ case 5:
8569
8647
  if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
8570
8648
  3,
8571
- 138
8649
+ 7
8572
8650
  ];
8573
8651
  _value = _step.value;
8574
- event = _value;
8575
- _ = event.type;
8576
- switch(_){
8577
- case "response.created":
8578
- return [
8579
- 3,
8580
- 5
8581
- ];
8582
- case "response.in_progress":
8583
- return [
8584
- 3,
8585
- 8
8586
- ];
8587
- case "response.completed":
8588
- return [
8589
- 3,
8590
- 11
8591
- ];
8592
- case "response.failed":
8593
- return [
8594
- 3,
8595
- 12
8596
- ];
8597
- case "response.output_text.delta":
8598
- return [
8599
- 3,
8600
- 15
8601
- ];
8602
- case "response.output_item.added":
8603
- return [
8604
- 3,
8605
- 17
8606
- ];
8607
- case "response.output_item.done":
8608
- return [
8609
- 3,
8610
- 75
8611
- ];
8612
- case "response.function_call_arguments.delta":
8613
- return [
8614
- 3,
8615
- 126
8616
- ];
8617
- case "response.mcp_call_arguments.delta":
8618
- return [
8619
- 3,
8620
- 128
8621
- ];
8622
- case "response.image_generation_call.in_progress":
8623
- return [
8624
- 3,
8625
- 130
8626
- ];
8627
- case "response.image_generation_call.generating":
8628
- return [
8629
- 3,
8630
- 130
8631
- ];
8632
- case "response.image_generation_call.partial_image":
8633
- return [
8634
- 3,
8635
- 133
8636
- ];
8637
- }
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;
8638
8683
  return [
8639
8684
  3,
8640
- 136
8685
+ 4
8641
8686
  ];
8642
- case 5:
8687
+ case 7:
8688
+ return [
8689
+ 3,
8690
+ 14
8691
+ ];
8692
+ case 8:
8693
+ err = _state.sent();
8694
+ _didIteratorError = true;
8695
+ _iteratorError = err;
8696
+ return [
8697
+ 3,
8698
+ 14
8699
+ ];
8700
+ case 9:
8701
+ _state.trys.push([
8702
+ 9,
8703
+ ,
8704
+ 12,
8705
+ 13
8706
+ ]);
8707
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
8708
+ 3,
8709
+ 11
8710
+ ];
8711
+ return [
8712
+ 4,
8713
+ _iterator.return()
8714
+ ];
8715
+ case 10:
8716
+ _state.sent();
8717
+ _state.label = 11;
8718
+ case 11:
8719
+ return [
8720
+ 3,
8721
+ 13
8722
+ ];
8723
+ case 12:
8724
+ if (_didIteratorError) {
8725
+ throw _iteratorError;
8726
+ }
8727
+ return [
8728
+ 7
8729
+ ];
8730
+ case 13:
8731
+ return [
8732
+ 7
8733
+ ];
8734
+ case 14:
8735
+ response = {
8736
+ data: messagesList,
8737
+ first_id: ((_messagesList_ = messagesList[0]) === null || _messagesList_ === void 0 ? void 0 : _messagesList_.id) || null,
8738
+ last_id: ((_messagesList_1 = messagesList[messagesList.length - 1]) === null || _messagesList_1 === void 0 ? void 0 : _messagesList_1.id) || null,
8739
+ has_more: false
8740
+ };
8741
+ return [
8742
+ 2,
8743
+ new Response(JSON.stringify(response), {
8744
+ status: 200,
8745
+ headers: {
8746
+ "Content-Type": "application/json"
8747
+ }
8748
+ })
8749
+ ];
8750
+ }
8751
+ });
8752
+ })();
8753
+ };
8754
+ };
8755
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/messages/index.ts
8756
+ var messages4 = function(param) {
8757
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
8758
+ return {
8759
+ post: post21({
8760
+ azureAiProject: azureAiProject,
8761
+ runAdapter: runAdapter
8762
+ }),
8763
+ get: get19({
8764
+ azureAiProject: azureAiProject,
8765
+ runAdapter: runAdapter
8766
+ })
8767
+ };
8768
+ };
8769
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/get.ts
8770
+ var get20 = function() {
8771
+ return function() {
8772
+ return _async_to_generator(function() {
8773
+ var response;
8774
+ return _ts_generator(this, function(_state) {
8775
+ response = {
8776
+ data: [],
8777
+ first_id: null,
8778
+ last_id: null,
8779
+ has_more: false
8780
+ };
8781
+ return [
8782
+ 2,
8783
+ new Response(JSON.stringify(response), {
8784
+ status: 200,
8785
+ headers: {
8786
+ "Content-Type": "application/json"
8787
+ }
8788
+ })
8789
+ ];
8790
+ });
8791
+ })();
8792
+ };
8793
+ };
8794
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/post.ts
8795
+ var import_radash23 = require("radash");
8796
+ var import_dayjs24 = __toESM(require("dayjs"), 1);
8797
+ var post22 = function(param) {
8798
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
8799
+ return function(urlString, options) {
8800
+ return _async_to_generator(function() {
8801
+ var url, _url_pathname_match, threadId, body, assistant_id, stream, instructions, tools, azureAgentId, readableStream, azureRun, retries, maxRetries, createOptions, error, _error_cause, errorMessage, runIdMatch, activeRunId, activeRun, runData;
8802
+ return _ts_generator(this, function(_state) {
8803
+ switch(_state.label){
8804
+ case 0:
8805
+ url = new URL(urlString);
8806
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runsRegexp)), 2), threadId = _url_pathname_match[1];
8807
+ if (typeof options.body !== "string") {
8808
+ throw new Error("Request body is required");
8809
+ }
8810
+ body = JSON.parse(options.body);
8811
+ assistant_id = body.assistant_id, stream = body.stream, instructions = body.instructions, tools = body.tools;
8812
+ if (!assistant_id) {
8813
+ throw new Error("assistant_id is required");
8814
+ }
8815
+ azureAgentId = assistant_id;
8816
+ if (!stream) return [
8817
+ 3,
8818
+ 1
8819
+ ];
8820
+ readableStream = new ReadableStream({
8821
+ start: function start(controller) {
8822
+ return _async_to_generator(function() {
8823
+ var error, _error_cause, _error_message, _error_cause_message, event;
8824
+ return _ts_generator(this, function(_state) {
8825
+ switch(_state.label){
8826
+ case 0:
8827
+ _state.trys.push([
8828
+ 0,
8829
+ 2,
8830
+ ,
8831
+ 3
8832
+ ]);
8833
+ return [
8834
+ 4,
8835
+ runAdapter.handleRun({
8836
+ threadId: threadId,
8837
+ assistantId: azureAgentId,
8838
+ instructions: instructions,
8839
+ tools: tools,
8840
+ onEvent: function(event) {
8841
+ return _async_to_generator(function() {
8842
+ return _ts_generator(this, function(_state) {
8843
+ controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
8844
+ return [
8845
+ 2
8846
+ ];
8847
+ });
8848
+ })();
8849
+ }
8850
+ })
8851
+ ];
8852
+ case 1:
8853
+ _state.sent();
8854
+ return [
8855
+ 3,
8856
+ 3
8857
+ ];
8858
+ case 2:
8859
+ error = _state.sent();
8860
+ console.error(error);
8861
+ event = {
8862
+ event: "thread.run.failed",
8863
+ data: {
8864
+ id: (0, import_radash23.uid)(24),
8865
+ failed_at: (0, import_dayjs24.default)().unix(),
8866
+ last_error: {
8867
+ code: "server_error",
8868
+ message: "".concat((_error_message = error === null || error === void 0 ? void 0 : error.message) !== null && _error_message !== void 0 ? _error_message : "", " ").concat((_error_cause_message = error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) !== null && _error_cause_message !== void 0 ? _error_cause_message : "")
8869
+ }
8870
+ }
8871
+ };
8872
+ controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
8873
+ return [
8874
+ 3,
8875
+ 3
8876
+ ];
8877
+ case 3:
8878
+ controller.close();
8879
+ return [
8880
+ 2
8881
+ ];
8882
+ }
8883
+ });
8884
+ })();
8885
+ }
8886
+ });
8887
+ return [
8888
+ 2,
8889
+ new Response(readableStream, {
8890
+ headers: {
8891
+ "Content-Type": "text/event-stream"
8892
+ }
8893
+ })
8894
+ ];
8895
+ case 1:
8896
+ retries = 0;
8897
+ maxRetries = 10;
8898
+ _state.label = 2;
8899
+ case 2:
8900
+ if (!(retries < maxRetries)) return [
8901
+ 3,
8902
+ 17
8903
+ ];
8904
+ _state.label = 3;
8905
+ case 3:
8906
+ _state.trys.push([
8907
+ 3,
8908
+ 5,
8909
+ ,
8910
+ 16
8911
+ ]);
8912
+ createOptions = {};
8913
+ if (instructions) {
8914
+ createOptions.instructions = instructions;
8915
+ }
8916
+ if (tools) {
8917
+ createOptions.tools = tools;
8918
+ }
8919
+ return [
8920
+ 4,
8921
+ azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions)
8922
+ ];
8923
+ case 4:
8924
+ azureRun = _state.sent();
8925
+ return [
8926
+ 3,
8927
+ 17
8928
+ ];
8929
+ case 5:
8930
+ error = _state.sent();
8931
+ errorMessage = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) || "";
8932
+ if (!errorMessage.includes("already has an active run")) return [
8933
+ 3,
8934
+ 14
8935
+ ];
8936
+ runIdMatch = errorMessage.match(/run_[a-zA-Z0-9]+/);
8937
+ if (!runIdMatch) return [
8938
+ 3,
8939
+ 11
8940
+ ];
8941
+ activeRunId = runIdMatch[0];
8942
+ return [
8943
+ 4,
8944
+ azureAiProject.agents.runs.get(threadId, activeRunId)
8945
+ ];
8946
+ case 6:
8947
+ activeRun = _state.sent();
8948
+ _state.label = 7;
8949
+ case 7:
8950
+ if (!(activeRun.status === "queued" || activeRun.status === "in_progress")) return [
8951
+ 3,
8952
+ 10
8953
+ ];
8954
+ return [
8955
+ 4,
8956
+ new Promise(function(resolve) {
8957
+ return setTimeout(resolve, 500);
8958
+ })
8959
+ ];
8960
+ case 8:
8961
+ _state.sent();
8962
+ return [
8963
+ 4,
8964
+ azureAiProject.agents.runs.get(threadId, activeRunId)
8965
+ ];
8966
+ case 9:
8967
+ activeRun = _state.sent();
8968
+ return [
8969
+ 3,
8970
+ 7
8971
+ ];
8972
+ case 10:
8973
+ if (activeRun.status === "requires_action") {
8974
+ throw new Error("Thread ".concat(threadId, " has an active run ").concat(activeRunId, " that requires action (tool outputs must be submitted before creating a new run)"));
8975
+ }
8976
+ return [
8977
+ 3,
8978
+ 13
8979
+ ];
8980
+ case 11:
8981
+ return [
8982
+ 4,
8983
+ new Promise(function(resolve) {
8984
+ return setTimeout(resolve, 1e3 * Math.pow(2, retries));
8985
+ })
8986
+ ];
8987
+ case 12:
8988
+ _state.sent();
8989
+ _state.label = 13;
8990
+ case 13:
8991
+ retries++;
8992
+ return [
8993
+ 3,
8994
+ 15
8995
+ ];
8996
+ case 14:
8997
+ throw error;
8998
+ case 15:
8999
+ return [
9000
+ 3,
9001
+ 16
9002
+ ];
9003
+ case 16:
9004
+ return [
9005
+ 3,
9006
+ 2
9007
+ ];
9008
+ case 17:
9009
+ if (!azureRun) {
9010
+ throw new Error("Failed to create run after ".concat(maxRetries, " retries"));
9011
+ }
9012
+ runData = {
9013
+ id: azureRun.id,
9014
+ object: "thread.run",
9015
+ created_at: (0, import_dayjs24.default)(azureRun.createdAt).unix(),
9016
+ thread_id: azureRun.threadId,
9017
+ assistant_id: azureAgentId,
9018
+ status: azureRun.status,
9019
+ required_action: null,
9020
+ last_error: null,
9021
+ expires_at: null,
9022
+ started_at: azureRun.status === "in_progress" ? (0, import_dayjs24.default)(azureRun.createdAt).unix() : null,
9023
+ cancelled_at: null,
9024
+ failed_at: null,
9025
+ completed_at: null,
9026
+ incomplete_details: null,
9027
+ model: "",
9028
+ instructions: "",
9029
+ tools: [],
9030
+ metadata: azureRun.metadata || {},
9031
+ temperature: null,
9032
+ top_p: null,
9033
+ max_prompt_tokens: null,
9034
+ max_completion_tokens: null,
9035
+ truncation_strategy: {
9036
+ type: "auto",
9037
+ last_messages: null
9038
+ },
9039
+ response_format: "auto",
9040
+ tool_choice: "auto",
9041
+ parallel_tool_calls: true,
9042
+ usage: null
9043
+ };
9044
+ return [
9045
+ 2,
9046
+ new Response(JSON.stringify(runData), {
9047
+ status: 200,
9048
+ headers: {
9049
+ "Content-Type": "application/json"
9050
+ }
9051
+ })
9052
+ ];
9053
+ case 18:
9054
+ return [
9055
+ 2
9056
+ ];
9057
+ }
9058
+ });
9059
+ })();
9060
+ };
9061
+ };
9062
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/index.ts
9063
+ var runs3 = function(param) {
9064
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9065
+ return {
9066
+ get: get20(),
9067
+ post: post22({
9068
+ azureAiProject: azureAiProject,
9069
+ runAdapter: runAdapter
9070
+ })
9071
+ };
9072
+ };
9073
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/run/get.ts
9074
+ var import_dayjs25 = __toESM(require("dayjs"), 1);
9075
+ var get21 = function(param) {
9076
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9077
+ return function(urlString) {
9078
+ return _async_to_generator(function() {
9079
+ var url, _url_pathname_match, threadId, runId, azureRun, assistantId, openaiRun;
9080
+ return _ts_generator(this, function(_state) {
9081
+ switch(_state.label){
9082
+ case 0:
9083
+ url = new URL(urlString);
9084
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(runRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
9085
+ return [
9086
+ 4,
9087
+ azureAiProject.agents.runs.get(threadId, runId)
9088
+ ];
9089
+ case 1:
9090
+ azureRun = _state.sent();
9091
+ assistantId = azureRun.assistantId;
9092
+ openaiRun = {
9093
+ id: azureRun.id,
9094
+ object: "thread.run",
9095
+ created_at: (0, import_dayjs25.default)(azureRun.createdAt).unix(),
9096
+ thread_id: azureRun.threadId,
9097
+ assistant_id: assistantId,
9098
+ status: azureRun.status,
9099
+ required_action: azureRun.status === "requires_action" && azureRun.requiredAction ? {
9100
+ type: "submit_tool_outputs",
9101
+ submit_tool_outputs: {
9102
+ tool_calls: azureRun.requiredAction.submitToolOutputs.toolCalls.map(function(tc) {
9103
+ return {
9104
+ id: tc.id,
9105
+ type: "function",
9106
+ function: {
9107
+ name: tc.function.name,
9108
+ arguments: tc.function.arguments
9109
+ }
9110
+ };
9111
+ })
9112
+ }
9113
+ } : null,
9114
+ last_error: azureRun.lastError ? {
9115
+ code: "server_error",
9116
+ message: JSON.stringify(azureRun.lastError)
9117
+ } : null,
9118
+ expires_at: null,
9119
+ started_at: (0, import_dayjs25.default)(azureRun.createdAt).unix(),
9120
+ cancelled_at: null,
9121
+ failed_at: azureRun.status === "failed" ? (0, import_dayjs25.default)().unix() : null,
9122
+ completed_at: azureRun.status === "completed" ? (0, import_dayjs25.default)().unix() : null,
9123
+ incomplete_details: null,
9124
+ model: "",
9125
+ instructions: "",
9126
+ tools: [],
9127
+ metadata: azureRun.metadata || {},
9128
+ temperature: null,
9129
+ top_p: null,
9130
+ max_prompt_tokens: null,
9131
+ max_completion_tokens: null,
9132
+ truncation_strategy: {
9133
+ type: "auto",
9134
+ last_messages: null
9135
+ },
9136
+ response_format: "auto",
9137
+ tool_choice: "auto",
9138
+ parallel_tool_calls: true,
9139
+ usage: null
9140
+ };
9141
+ return [
9142
+ 2,
9143
+ new Response(JSON.stringify(openaiRun), {
9144
+ status: 200,
9145
+ headers: {
9146
+ "Content-Type": "application/json"
9147
+ }
9148
+ })
9149
+ ];
9150
+ }
9151
+ });
9152
+ })();
9153
+ };
9154
+ };
9155
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/run/index.ts
9156
+ var run3 = function(param) {
9157
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9158
+ return {
9159
+ get: get21({
9160
+ azureAiProject: azureAiProject,
9161
+ runAdapter: runAdapter
9162
+ })
9163
+ };
9164
+ };
9165
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/get.ts
9166
+ var import_dayjs26 = __toESM(require("dayjs"), 1);
9167
+ var get22 = function(param) {
9168
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9169
+ return function(urlString) {
9170
+ return _async_to_generator(function() {
9171
+ var _stepsList_, _stepsList_1, url, _url_pathname_match, threadId, runId, azureSteps, openaiAssistant, stepsList, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, step, _step_stepDetails_messageCreation, err, response;
9172
+ return _ts_generator(this, function(_state) {
9173
+ switch(_state.label){
9174
+ case 0:
9175
+ url = new URL(urlString);
9176
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(stepsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
9177
+ return [
9178
+ 4,
9179
+ azureAiProject.agents.runSteps.list(threadId, runId)
9180
+ ];
9181
+ case 1:
9182
+ azureSteps = _state.sent();
9183
+ return [
9184
+ 4,
9185
+ runAdapter.getOpenaiAssistant({
9186
+ select: {
9187
+ id: true
9188
+ }
9189
+ })
9190
+ ];
9191
+ case 2:
9192
+ openaiAssistant = _state.sent();
9193
+ stepsList = [];
9194
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
9195
+ _state.label = 3;
9196
+ case 3:
9197
+ _state.trys.push([
9198
+ 3,
9199
+ 8,
9200
+ 9,
9201
+ 14
9202
+ ]);
9203
+ _iterator = _async_iterator(azureSteps);
9204
+ _state.label = 4;
9205
+ case 4:
9206
+ return [
9207
+ 4,
9208
+ _iterator.next()
9209
+ ];
9210
+ case 5:
9211
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
9212
+ 3,
9213
+ 7
9214
+ ];
9215
+ _value = _step.value;
9216
+ step = _value;
9217
+ stepsList.push({
9218
+ id: step.id,
9219
+ object: "thread.run.step",
9220
+ created_at: (0, import_dayjs26.default)(step.createdAt).unix(),
9221
+ assistant_id: openaiAssistant.id,
9222
+ thread_id: threadId,
9223
+ run_id: runId,
9224
+ type: step.type === "tool_calls" ? "tool_calls" : "message_creation",
9225
+ status: step.status,
9226
+ step_details: step.type === "tool_calls" ? {
9227
+ type: "tool_calls",
9228
+ tool_calls: step.stepDetails.toolCalls.map(function(tc) {
9229
+ return {
9230
+ id: tc.id,
9231
+ type: "function",
9232
+ function: {
9233
+ name: tc.function.name,
9234
+ arguments: tc.function.arguments,
9235
+ output: tc.function.output || null
9236
+ }
9237
+ };
9238
+ })
9239
+ } : {
9240
+ type: "message_creation",
9241
+ message_creation: {
9242
+ message_id: (_step_stepDetails_messageCreation = step.stepDetails.messageCreation) === null || _step_stepDetails_messageCreation === void 0 ? void 0 : _step_stepDetails_messageCreation.messageId
9243
+ }
9244
+ },
9245
+ last_error: null,
9246
+ expired_at: null,
9247
+ cancelled_at: null,
9248
+ failed_at: null,
9249
+ completed_at: step.completedAt ? (0, import_dayjs26.default)(step.completedAt).unix() : null,
9250
+ metadata: step.metadata || {},
9251
+ usage: null
9252
+ });
9253
+ _state.label = 6;
9254
+ case 6:
9255
+ _iteratorAbruptCompletion = false;
9256
+ return [
9257
+ 3,
9258
+ 4
9259
+ ];
9260
+ case 7:
9261
+ return [
9262
+ 3,
9263
+ 14
9264
+ ];
9265
+ case 8:
9266
+ err = _state.sent();
9267
+ _didIteratorError = true;
9268
+ _iteratorError = err;
9269
+ return [
9270
+ 3,
9271
+ 14
9272
+ ];
9273
+ case 9:
9274
+ _state.trys.push([
9275
+ 9,
9276
+ ,
9277
+ 12,
9278
+ 13
9279
+ ]);
9280
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
9281
+ 3,
9282
+ 11
9283
+ ];
9284
+ return [
9285
+ 4,
9286
+ _iterator.return()
9287
+ ];
9288
+ case 10:
9289
+ _state.sent();
9290
+ _state.label = 11;
9291
+ case 11:
9292
+ return [
9293
+ 3,
9294
+ 13
9295
+ ];
9296
+ case 12:
9297
+ if (_didIteratorError) {
9298
+ throw _iteratorError;
9299
+ }
9300
+ return [
9301
+ 7
9302
+ ];
9303
+ case 13:
9304
+ return [
9305
+ 7
9306
+ ];
9307
+ case 14:
9308
+ response = {
9309
+ data: stepsList,
9310
+ first_id: ((_stepsList_ = stepsList[0]) === null || _stepsList_ === void 0 ? void 0 : _stepsList_.id) || null,
9311
+ last_id: ((_stepsList_1 = stepsList[stepsList.length - 1]) === null || _stepsList_1 === void 0 ? void 0 : _stepsList_1.id) || null,
9312
+ has_more: false
9313
+ };
9314
+ return [
9315
+ 2,
9316
+ new Response(JSON.stringify(response), {
9317
+ status: 200,
9318
+ headers: {
9319
+ "Content-Type": "application/json"
9320
+ }
9321
+ })
9322
+ ];
9323
+ }
9324
+ });
9325
+ })();
9326
+ };
9327
+ };
9328
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/steps/index.ts
9329
+ var steps3 = function(param) {
9330
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9331
+ return {
9332
+ get: get22({
9333
+ azureAiProject: azureAiProject,
9334
+ runAdapter: runAdapter
9335
+ })
9336
+ };
9337
+ };
9338
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/post/index.ts
9339
+ var import_dayjs27 = __toESM(require("dayjs"), 1);
9340
+ function convertAzureEventToOpenAI(azureEvent, assistantId) {
9341
+ var event = azureEvent.event, data = azureEvent.data;
9342
+ var eventType = event;
9343
+ if (eventType.startsWith("thread.run.")) {
9344
+ var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
9345
+ var _data_temperature, _data_topP;
9346
+ return {
9347
+ event: eventType,
9348
+ data: {
9349
+ id: data.id,
9350
+ object: "thread.run",
9351
+ created_at: (0, import_dayjs27.default)(data.createdAt).unix(),
9352
+ thread_id: data.threadId,
9353
+ assistant_id: assistantId,
9354
+ status: data.status,
9355
+ required_action: data.requiredAction ? {
9356
+ type: "submit_tool_outputs",
9357
+ submit_tool_outputs: {
9358
+ tool_calls: ((_data_requiredAction_submitToolOutputs = data.requiredAction.submitToolOutputs) === null || _data_requiredAction_submitToolOutputs === void 0 ? void 0 : (_data_requiredAction_submitToolOutputs_toolCalls = _data_requiredAction_submitToolOutputs.toolCalls) === null || _data_requiredAction_submitToolOutputs_toolCalls === void 0 ? void 0 : _data_requiredAction_submitToolOutputs_toolCalls.map(function(tc) {
9359
+ return {
9360
+ id: tc.id,
9361
+ type: "function",
9362
+ function: {
9363
+ name: tc.function.name,
9364
+ arguments: tc.function.arguments
9365
+ }
9366
+ };
9367
+ })) || []
9368
+ }
9369
+ } : null,
9370
+ last_error: data.lastError ? {
9371
+ code: "server_error",
9372
+ message: JSON.stringify(data.lastError)
9373
+ } : null,
9374
+ expires_at: null,
9375
+ started_at: data.startedAt ? (0, import_dayjs27.default)(data.startedAt).unix() : null,
9376
+ cancelled_at: data.cancelledAt ? (0, import_dayjs27.default)(data.cancelledAt).unix() : null,
9377
+ failed_at: data.failedAt ? (0, import_dayjs27.default)(data.failedAt).unix() : null,
9378
+ completed_at: data.completedAt ? (0, import_dayjs27.default)(data.completedAt).unix() : null,
9379
+ incomplete_details: null,
9380
+ model: data.model || "",
9381
+ instructions: data.instructions || "",
9382
+ tools: data.tools || [],
9383
+ metadata: data.metadata || {},
9384
+ temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
9385
+ top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
9386
+ max_prompt_tokens: null,
9387
+ max_completion_tokens: null,
9388
+ truncation_strategy: {
9389
+ type: "auto",
9390
+ last_messages: null
9391
+ },
9392
+ response_format: "auto",
9393
+ tool_choice: "auto",
9394
+ parallel_tool_calls: true,
9395
+ usage: null
9396
+ }
9397
+ };
9398
+ }
9399
+ if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
9400
+ var _data_content;
9401
+ return {
9402
+ event: eventType,
9403
+ data: {
9404
+ id: data.id,
9405
+ object: "thread.message",
9406
+ created_at: (0, import_dayjs27.default)(data.createdAt).unix(),
9407
+ thread_id: data.threadId,
9408
+ role: data.role,
9409
+ content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
9410
+ if (c.type === "text") {
9411
+ var _c_text, _c_text1;
9412
+ return {
9413
+ type: "text",
9414
+ text: {
9415
+ value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
9416
+ annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
9417
+ }
9418
+ };
9419
+ }
9420
+ return c;
9421
+ })) || [],
9422
+ assistant_id: assistantId,
9423
+ run_id: data.runId || null,
9424
+ attachments: data.attachments || [],
9425
+ metadata: data.metadata || {},
9426
+ status: data.status || "completed",
9427
+ completed_at: data.completedAt ? (0, import_dayjs27.default)(data.completedAt).unix() : null,
9428
+ incomplete_at: null,
9429
+ incomplete_details: null
9430
+ }
9431
+ };
9432
+ }
9433
+ if (eventType === "thread.message.delta") {
9434
+ var _data_delta_content, _data_delta;
9435
+ return {
9436
+ event: "thread.message.delta",
9437
+ data: {
9438
+ id: data.id,
9439
+ object: "thread.message.delta",
9440
+ delta: {
9441
+ content: ((_data_delta = data.delta) === null || _data_delta === void 0 ? void 0 : (_data_delta_content = _data_delta.content) === null || _data_delta_content === void 0 ? void 0 : _data_delta_content.map(function(c) {
9442
+ if (c.type === "text") {
9443
+ var _c_text, _c_text1;
9444
+ return {
9445
+ index: c.index || 0,
9446
+ type: "text",
9447
+ text: {
9448
+ value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
9449
+ annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
9450
+ }
9451
+ };
9452
+ }
9453
+ return c;
9454
+ })) || []
9455
+ }
9456
+ }
9457
+ };
9458
+ }
9459
+ return null;
9460
+ }
9461
+ var post23 = function(param) {
9462
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9463
+ return function(urlString, options) {
9464
+ return _async_to_generator(function() {
9465
+ var url, _url_pathname_match, threadId, runId, body, tool_outputs, stream, existingRun, assistantId, submitResponse, streamRun, readableStream, events, finalRun;
9466
+ return _ts_generator(this, function(_state) {
9467
+ switch(_state.label){
9468
+ case 0:
9469
+ url = new URL(urlString);
9470
+ _url_pathname_match = _sliced_to_array(url.pathname.match(new RegExp(submitToolOutputsRegexp)), 3), threadId = _url_pathname_match[1], runId = _url_pathname_match[2];
9471
+ if (typeof options.body !== "string") {
9472
+ throw new Error("Request body is required");
9473
+ }
9474
+ body = JSON.parse(options.body);
9475
+ tool_outputs = body.tool_outputs, stream = body.stream;
9476
+ return [
9477
+ 4,
9478
+ azureAiProject.agents.runs.get(threadId, runId)
9479
+ ];
9480
+ case 1:
9481
+ existingRun = _state.sent();
9482
+ assistantId = existingRun.assistantId;
9483
+ submitResponse = azureAiProject.agents.runs.submitToolOutputs(threadId, runId, tool_outputs.map(function(to) {
9484
+ return {
9485
+ toolCallId: to.tool_call_id,
9486
+ output: to.output
9487
+ };
9488
+ }));
9489
+ streamRun = function(onEvent2) {
9490
+ return _async_to_generator(function() {
9491
+ var stream2, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, error, _error_cause, _error_message, _error_cause_message;
9492
+ return _ts_generator(this, function(_state) {
9493
+ switch(_state.label){
9494
+ case 0:
9495
+ _state.trys.push([
9496
+ 0,
9497
+ 15,
9498
+ ,
9499
+ 17
9500
+ ]);
9501
+ return [
9502
+ 4,
9503
+ submitResponse.stream()
9504
+ ];
9505
+ case 1:
9506
+ stream2 = _state.sent();
9507
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
9508
+ _state.label = 2;
9509
+ case 2:
9510
+ _state.trys.push([
9511
+ 2,
9512
+ 8,
9513
+ 9,
9514
+ 14
9515
+ ]);
9516
+ _iterator = _async_iterator(stream2);
9517
+ _state.label = 3;
9518
+ case 3:
9519
+ return [
9520
+ 4,
9521
+ _iterator.next()
9522
+ ];
9523
+ case 4:
9524
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
9525
+ 3,
9526
+ 7
9527
+ ];
9528
+ _value = _step.value;
9529
+ azureEvent = _value;
9530
+ openaiEvent = convertAzureEventToOpenAI(azureEvent, assistantId);
9531
+ if (!openaiEvent) return [
9532
+ 3,
9533
+ 6
9534
+ ];
9535
+ return [
9536
+ 4,
9537
+ onEvent2(openaiEvent)
9538
+ ];
9539
+ case 5:
9540
+ _state.sent();
9541
+ _state.label = 6;
9542
+ case 6:
9543
+ _iteratorAbruptCompletion = false;
9544
+ return [
9545
+ 3,
9546
+ 3
9547
+ ];
9548
+ case 7:
9549
+ return [
9550
+ 3,
9551
+ 14
9552
+ ];
9553
+ case 8:
9554
+ err = _state.sent();
9555
+ _didIteratorError = true;
9556
+ _iteratorError = err;
9557
+ return [
9558
+ 3,
9559
+ 14
9560
+ ];
9561
+ case 9:
9562
+ _state.trys.push([
9563
+ 9,
9564
+ ,
9565
+ 12,
9566
+ 13
9567
+ ]);
9568
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
9569
+ 3,
9570
+ 11
9571
+ ];
9572
+ return [
9573
+ 4,
9574
+ _iterator.return()
9575
+ ];
9576
+ case 10:
9577
+ _state.sent();
9578
+ _state.label = 11;
9579
+ case 11:
9580
+ return [
9581
+ 3,
9582
+ 13
9583
+ ];
9584
+ case 12:
9585
+ if (_didIteratorError) {
9586
+ throw _iteratorError;
9587
+ }
9588
+ return [
9589
+ 7
9590
+ ];
9591
+ case 13:
9592
+ return [
9593
+ 7
9594
+ ];
9595
+ case 14:
9596
+ return [
9597
+ 3,
9598
+ 17
9599
+ ];
9600
+ case 15:
9601
+ error = _state.sent();
9602
+ return [
9603
+ 4,
9604
+ onEvent2({
9605
+ event: "thread.run.failed",
9606
+ data: {
9607
+ id: runId,
9608
+ object: "thread.run",
9609
+ created_at: (0, import_dayjs27.default)().unix(),
9610
+ thread_id: threadId,
9611
+ assistant_id: assistantId,
9612
+ status: "failed",
9613
+ required_action: null,
9614
+ last_error: {
9615
+ code: "server_error",
9616
+ message: "".concat((_error_message = error === null || error === void 0 ? void 0 : error.message) !== null && _error_message !== void 0 ? _error_message : "", " ").concat((_error_cause_message = error === null || error === void 0 ? void 0 : (_error_cause = error.cause) === null || _error_cause === void 0 ? void 0 : _error_cause.message) !== null && _error_cause_message !== void 0 ? _error_cause_message : "")
9617
+ },
9618
+ expires_at: null,
9619
+ started_at: (0, import_dayjs27.default)().unix(),
9620
+ cancelled_at: null,
9621
+ failed_at: (0, import_dayjs27.default)().unix(),
9622
+ completed_at: null,
9623
+ incomplete_details: null,
9624
+ model: "",
9625
+ instructions: "",
9626
+ tools: [],
9627
+ metadata: {},
9628
+ temperature: null,
9629
+ top_p: null,
9630
+ max_prompt_tokens: null,
9631
+ max_completion_tokens: null,
9632
+ truncation_strategy: {
9633
+ type: "auto",
9634
+ last_messages: null
9635
+ },
9636
+ response_format: "auto",
9637
+ tool_choice: "auto",
9638
+ parallel_tool_calls: true,
9639
+ usage: null
9640
+ }
9641
+ })
9642
+ ];
9643
+ case 16:
9644
+ _state.sent();
9645
+ return [
9646
+ 3,
9647
+ 17
9648
+ ];
9649
+ case 17:
9650
+ return [
9651
+ 2
9652
+ ];
9653
+ }
9654
+ });
9655
+ })();
9656
+ };
9657
+ readableStream = new ReadableStream({
9658
+ start: function start(controller) {
9659
+ return _async_to_generator(function() {
9660
+ return _ts_generator(this, function(_state) {
9661
+ switch(_state.label){
9662
+ case 0:
9663
+ return [
9664
+ 4,
9665
+ streamRun(function(event) {
9666
+ return _async_to_generator(function() {
9667
+ return _ts_generator(this, function(_state) {
9668
+ controller.enqueue("data: ".concat(JSON.stringify(event), "\n\n"));
9669
+ return [
9670
+ 2
9671
+ ];
9672
+ });
9673
+ })();
9674
+ })
9675
+ ];
9676
+ case 1:
9677
+ _state.sent();
9678
+ controller.close();
9679
+ return [
9680
+ 2
9681
+ ];
9682
+ }
9683
+ });
9684
+ })();
9685
+ }
9686
+ });
9687
+ if (!stream) return [
9688
+ 3,
9689
+ 2
9690
+ ];
9691
+ return [
9692
+ 2,
9693
+ new Response(readableStream, {
9694
+ headers: {
9695
+ "Content-Type": "text/event-stream"
9696
+ }
9697
+ })
9698
+ ];
9699
+ case 2:
9700
+ events = [];
9701
+ finalRun = null;
9702
+ return [
9703
+ 4,
9704
+ streamRun(function(event) {
9705
+ return _async_to_generator(function() {
9706
+ return _ts_generator(this, function(_state) {
9707
+ events.push(event);
9708
+ if (event.event === "thread.run.completed" || event.event === "thread.run.failed" || event.event === "thread.run.requires_action") {
9709
+ finalRun = event.data;
9710
+ }
9711
+ return [
9712
+ 2
9713
+ ];
9714
+ });
9715
+ })();
9716
+ })
9717
+ ];
9718
+ case 3:
9719
+ _state.sent();
9720
+ if (!finalRun) {
9721
+ throw new Error("Run did not complete");
9722
+ }
9723
+ return [
9724
+ 2,
9725
+ new Response(JSON.stringify(finalRun), {
9726
+ status: 200,
9727
+ headers: {
9728
+ "Content-Type": "application/json"
9729
+ }
9730
+ })
9731
+ ];
9732
+ case 4:
9733
+ return [
9734
+ 2
9735
+ ];
9736
+ }
9737
+ });
9738
+ })();
9739
+ };
9740
+ };
9741
+ // src/adapters/storage/azureAgentsStorageAdapter/threads/runs/submitToolOutputs/index.ts
9742
+ var submitToolOutputs3 = function(param) {
9743
+ var azureAiProject = param.azureAiProject, runAdapter = param.runAdapter;
9744
+ return {
9745
+ post: post23({
9746
+ azureAiProject: azureAiProject,
9747
+ runAdapter: runAdapter
9748
+ })
9749
+ };
9750
+ };
9751
+ // src/adapters/storage/azureAgentsStorageAdapter/assistants/post.ts
9752
+ var post24 = function(param) {
9753
+ var runAdapter = param.runAdapter;
9754
+ return function(_urlString, options) {
9755
+ return _async_to_generator(function() {
9756
+ var body, _body_top_p, _body_temperature, openaiAssistant;
9757
+ return _ts_generator(this, function(_state) {
9758
+ if (typeof options.body !== "string") {
9759
+ throw new Error("Request body is required");
9760
+ }
9761
+ body = JSON.parse(options.body);
9762
+ openaiAssistant = {
9763
+ id: "placeholder",
9764
+ // This will be overridden by the assistant_id passed to createRun
9765
+ object: "assistant",
9766
+ created_at: Math.floor(Date.now() / 1e3),
9767
+ name: body.name || null,
9768
+ description: body.description || null,
9769
+ model: body.model,
9770
+ instructions: body.instructions || null,
9771
+ tools: body.tools || [],
9772
+ metadata: body.metadata || {},
9773
+ top_p: (_body_top_p = body.top_p) !== null && _body_top_p !== void 0 ? _body_top_p : null,
9774
+ temperature: (_body_temperature = body.temperature) !== null && _body_temperature !== void 0 ? _body_temperature : null,
9775
+ response_format: body.response_format || "auto"
9776
+ };
9777
+ return [
9778
+ 2,
9779
+ new Response(JSON.stringify(openaiAssistant), {
9780
+ status: 200,
9781
+ headers: {
9782
+ "Content-Type": "application/json"
9783
+ }
9784
+ })
9785
+ ];
9786
+ });
9787
+ })();
9788
+ };
9789
+ };
9790
+ // src/adapters/storage/azureAgentsStorageAdapter/assistants/index.ts
9791
+ var assistants3 = function(param) {
9792
+ var runAdapter = param.runAdapter;
9793
+ return {
9794
+ post: post24({
9795
+ runAdapter: runAdapter
9796
+ })
9797
+ };
9798
+ };
9799
+ // src/adapters/storage/azureAgentsStorageAdapter/index.ts
9800
+ var azureAgentsStorageAdapter = function(param) {
9801
+ var azureAiProject = param.azureAiProject;
9802
+ return function(param) {
9803
+ var runAdapter = param.runAdapter;
9804
+ var _obj;
9805
+ return {
9806
+ requestHandlers: (_obj = {
9807
+ "^/(?:v1|/?openai)/assistants$": assistants3({
9808
+ runAdapter: runAdapter
9809
+ }),
9810
+ "^/(?:v1|/?openai)/threads$": threads3({
9811
+ azureAiProject: azureAiProject
9812
+ })
9813
+ }, _define_property(_obj, messagesRegexp, messages4({
9814
+ azureAiProject: azureAiProject,
9815
+ runAdapter: runAdapter
9816
+ })), _define_property(_obj, runsRegexp, runs3({
9817
+ azureAiProject: azureAiProject,
9818
+ runAdapter: runAdapter
9819
+ })), _define_property(_obj, runRegexp, run3({
9820
+ azureAiProject: azureAiProject,
9821
+ runAdapter: runAdapter
9822
+ })), _define_property(_obj, stepsRegexp, steps3({
9823
+ azureAiProject: azureAiProject,
9824
+ runAdapter: runAdapter
9825
+ })), _define_property(_obj, submitToolOutputsRegexp, submitToolOutputs3({
9826
+ azureAiProject: azureAiProject,
9827
+ runAdapter: runAdapter
9828
+ })), _obj)
9829
+ };
9830
+ };
9831
+ };
9832
+ // src/adapters/run/responsesRunAdapter/index.ts
9833
+ var import_dayjs28 = __toESM(require("dayjs"), 1);
9834
+ var import_radash24 = require("radash");
9835
+ var serializeToolCalls2 = function(param) {
9836
+ var toolCalls = param.toolCalls;
9837
+ return toolCalls.map(function(toolCall) {
9838
+ if (toolCall.type === "function_call") {
9839
+ return {
9840
+ id: toolCall.call_id,
9841
+ type: "function",
9842
+ function: {
9843
+ name: toolCall.name,
9844
+ arguments: toolCall.arguments
9845
+ }
9846
+ };
9847
+ } else if (toolCall.type === "computer_call") {
9848
+ return {
9849
+ id: toolCall.call_id,
9850
+ type: "computer_call",
9851
+ computer_call: {
9852
+ action: toolCall.action,
9853
+ pending_safety_checks: toolCall.pending_safety_checks
9854
+ }
9855
+ };
9856
+ }
9857
+ });
9858
+ };
9859
+ var responsesRunAdapter = function(param) {
9860
+ var getDirectOpenaiAssistant = param.getOpenaiAssistant, _param_waitUntil = param.waitUntil, waitUntil = _param_waitUntil === void 0 ? function(p) {
9861
+ return p.then(function() {});
9862
+ } : _param_waitUntil;
9863
+ var cachedOpenaiAssistant = null;
9864
+ var getOpenaiAssistant = function() {
9865
+ var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, tmp = _ref.select, _ref1 = tmp === void 0 ? {} : tmp, _ref_id = _ref1.id, id = _ref_id === void 0 ? false : _ref_id;
9866
+ return _async_to_generator(function() {
9867
+ var args, _tmp;
9868
+ return _ts_generator(this, function(_state) {
9869
+ switch(_state.label){
9870
+ case 0:
9871
+ args = {
9872
+ select: {
9873
+ id: id
9874
+ }
9875
+ };
9876
+ if (!args.select.id) return [
9877
+ 3,
9878
+ 2
9879
+ ];
9880
+ _tmp = {};
9881
+ return [
9882
+ 4,
9883
+ getDirectOpenaiAssistant({
9884
+ select: {
9885
+ id: true
9886
+ }
9887
+ })
9888
+ ];
9889
+ case 1:
9890
+ return [
9891
+ 2,
9892
+ (_tmp.id = _state.sent().id, _tmp)
9893
+ ];
9894
+ case 2:
9895
+ if (cachedOpenaiAssistant) return [
9896
+ 2,
9897
+ cachedOpenaiAssistant
9898
+ ];
9899
+ return [
9900
+ 4,
9901
+ getDirectOpenaiAssistant()
9902
+ ];
9903
+ case 3:
9904
+ cachedOpenaiAssistant = _state.sent();
9905
+ return [
9906
+ 2,
9907
+ cachedOpenaiAssistant
9908
+ ];
9909
+ }
9910
+ });
9911
+ })();
9912
+ };
9913
+ var handleRun = function(param) {
9914
+ var client = param.client, threadId = param.threadId, response = param.response, onEvent2 = param.onEvent;
9915
+ return _async_to_generator(function() {
9916
+ var responseCreatedResponse, responseCompletedResponse, toolCalls, mcpCalls, codeInterpreterCalls, itemIds, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, event, _, _tmp, _tmp1, _tmp2, _tmp3, _tmp4, _tmp5, _tmp6, _tmp7, _tmp8, _tmp9, _tmp10, _tmp11, _tmp12, _tmp13, _tmp14, _tmp15, _tmp16, _tmp17, _tmp18, _tmp19, _tmp20, _tmp21, _tmp22, _tmp23, _tmp24, _tmp25, _tmp26, _tmp27, _tmp28, _tmp29, _tmp30, _tmp31, _tmp32, _tmp33, _tmp34, _tmp35, _tmp36, _tmp37, _tmp38, _tmp39, _tmp40, _tmp41, _tmp42, _tmp43, _tmp44, _tmp45, _tmp46, _tmp47, _tmp48, _tmp49, _tmp50, _tmp51, _tmp52, _tmp53, _tmp54, _tmp55, _tmp56, _tmp57, _tmp58, _tmp59, _tmp60, _tmp61, _tmp62, _tmp63, _tmp64, _tmp65, _tmp66, _tmp67, _tmp68, _tmp69, _tmp70, _tmp71, _tmp72, _tmp73, _tmp74, _tmp75, _tmp76, _tmp77, _tmp78, _tmp79, _tmp80, _tmp81, _tmp82, _tmp83, _tmp84, _tmp85, _tmp86, _tmp87, _tmp88, _tmp89, _tmp90, _tmp91, _tmp92, _tmp93, _tmp94, _tmp95, toolCall, mcpCall, _tmp96, _tmp97, _tmp98, _tmp99, err, _responseCompletedResponse_output, toolCalls2, serializedRun, _tmp100, e, _tmp101, _tmp102;
9917
+ return _ts_generator(this, function(_state) {
9918
+ switch(_state.label){
9919
+ case 0:
9920
+ responseCreatedResponse = null;
9921
+ responseCompletedResponse = null;
9922
+ toolCalls = {};
9923
+ mcpCalls = {};
9924
+ codeInterpreterCalls = {};
9925
+ itemIds = [];
9926
+ _state.label = 1;
9927
+ case 1:
9928
+ _state.trys.push([
9929
+ 1,
9930
+ 151,
9931
+ 154,
9932
+ 155
9933
+ ]);
9934
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
9935
+ _state.label = 2;
9936
+ case 2:
9937
+ _state.trys.push([
9938
+ 2,
9939
+ 139,
9940
+ 140,
9941
+ 145
9942
+ ]);
9943
+ _iterator = _async_iterator(response);
9944
+ _state.label = 3;
9945
+ case 3:
9946
+ return [
9947
+ 4,
9948
+ _iterator.next()
9949
+ ];
9950
+ case 4:
9951
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
9952
+ 3,
9953
+ 138
9954
+ ];
9955
+ _value = _step.value;
9956
+ event = _value;
9957
+ _ = event.type;
9958
+ switch(_){
9959
+ case "response.created":
9960
+ return [
9961
+ 3,
9962
+ 5
9963
+ ];
9964
+ case "response.in_progress":
9965
+ return [
9966
+ 3,
9967
+ 8
9968
+ ];
9969
+ case "response.completed":
9970
+ return [
9971
+ 3,
9972
+ 11
9973
+ ];
9974
+ case "response.failed":
9975
+ return [
9976
+ 3,
9977
+ 12
9978
+ ];
9979
+ case "response.output_text.delta":
9980
+ return [
9981
+ 3,
9982
+ 15
9983
+ ];
9984
+ case "response.output_item.added":
9985
+ return [
9986
+ 3,
9987
+ 17
9988
+ ];
9989
+ case "response.output_item.done":
9990
+ return [
9991
+ 3,
9992
+ 75
9993
+ ];
9994
+ case "response.function_call_arguments.delta":
9995
+ return [
9996
+ 3,
9997
+ 126
9998
+ ];
9999
+ case "response.mcp_call_arguments.delta":
10000
+ return [
10001
+ 3,
10002
+ 128
10003
+ ];
10004
+ case "response.image_generation_call.in_progress":
10005
+ return [
10006
+ 3,
10007
+ 130
10008
+ ];
10009
+ case "response.image_generation_call.generating":
10010
+ return [
10011
+ 3,
10012
+ 130
10013
+ ];
10014
+ case "response.image_generation_call.partial_image":
10015
+ return [
10016
+ 3,
10017
+ 133
10018
+ ];
10019
+ }
10020
+ return [
10021
+ 3,
10022
+ 136
10023
+ ];
10024
+ case 5:
8643
10025
  responseCreatedResponse = event.response;
8644
10026
  _tmp = {
8645
10027
  event: "thread.run.created"
@@ -8796,7 +10178,7 @@ var responsesRunAdapter = function(param) {
8796
10178
  4,
8797
10179
  onEvent2.apply(void 0, [
8798
10180
  (_tmp6.data = serializeItemAsMessage.apply(void 0, [
8799
- (_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt = (0, import_dayjs21.default)().unix(), _tmp7.runId = responseCreatedResponse.id, _tmp7.status = "in_progress", _tmp7)
10181
+ (_tmp7.openaiAssistant = _state.sent(), _tmp7.createdAt = (0, import_dayjs28.default)().unix(), _tmp7.runId = responseCreatedResponse.id, _tmp7.status = "in_progress", _tmp7)
8800
10182
  ]), _tmp6)
8801
10183
  ])
8802
10184
  ];
@@ -8893,7 +10275,7 @@ var responsesRunAdapter = function(param) {
8893
10275
  4,
8894
10276
  onEvent2.apply(void 0, [
8895
10277
  (_tmp12.data = serializeItemAsMessage.apply(void 0, [
8896
- (_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt = (0, import_dayjs21.default)().unix(), _tmp13.runId = responseCreatedResponse.id, _tmp13.status = "in_progress", _tmp13)
10278
+ (_tmp13.openaiAssistant = _state.sent(), _tmp13.createdAt = (0, import_dayjs28.default)().unix(), _tmp13.runId = responseCreatedResponse.id, _tmp13.status = "in_progress", _tmp13)
8897
10279
  ]), _tmp12)
8898
10280
  ])
8899
10281
  ];
@@ -8980,7 +10362,7 @@ var responsesRunAdapter = function(param) {
8980
10362
  4,
8981
10363
  onEvent2.apply(void 0, [
8982
10364
  (_tmp18.data = serializeItemAsMessage.apply(void 0, [
8983
- (_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt = (0, import_dayjs21.default)().unix(), _tmp19.runId = responseCreatedResponse.id, _tmp19.status = "in_progress", _tmp19)
10365
+ (_tmp19.openaiAssistant = _state.sent(), _tmp19.createdAt = (0, import_dayjs28.default)().unix(), _tmp19.runId = responseCreatedResponse.id, _tmp19.status = "in_progress", _tmp19)
8984
10366
  ]), _tmp18)
8985
10367
  ])
8986
10368
  ];
@@ -9066,7 +10448,7 @@ var responsesRunAdapter = function(param) {
9066
10448
  4,
9067
10449
  onEvent2.apply(void 0, [
9068
10450
  (_tmp24.data = serializeItemAsMessage.apply(void 0, [
9069
- (_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt = (0, import_dayjs21.default)().unix(), _tmp25.runId = responseCreatedResponse.id, _tmp25.status = "in_progress", _tmp25)
10451
+ (_tmp25.openaiAssistant = _state.sent(), _tmp25.createdAt = (0, import_dayjs28.default)().unix(), _tmp25.runId = responseCreatedResponse.id, _tmp25.status = "in_progress", _tmp25)
9070
10452
  ]), _tmp24)
9071
10453
  ])
9072
10454
  ];
@@ -9152,7 +10534,7 @@ var responsesRunAdapter = function(param) {
9152
10534
  4,
9153
10535
  onEvent2.apply(void 0, [
9154
10536
  (_tmp30.data = serializeItemAsMessage.apply(void 0, [
9155
- (_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt = (0, import_dayjs21.default)().unix(), _tmp31.runId = responseCreatedResponse.id, _tmp31.status = "in_progress", _tmp31)
10537
+ (_tmp31.openaiAssistant = _state.sent(), _tmp31.createdAt = (0, import_dayjs28.default)().unix(), _tmp31.runId = responseCreatedResponse.id, _tmp31.status = "in_progress", _tmp31)
9156
10538
  ]), _tmp30)
9157
10539
  ])
9158
10540
  ];
@@ -9238,7 +10620,7 @@ var responsesRunAdapter = function(param) {
9238
10620
  4,
9239
10621
  onEvent2.apply(void 0, [
9240
10622
  (_tmp36.data = serializeItemAsMessage.apply(void 0, [
9241
- (_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt = (0, import_dayjs21.default)().unix(), _tmp37.runId = responseCreatedResponse.id, _tmp37.status = "in_progress", _tmp37)
10623
+ (_tmp37.openaiAssistant = _state.sent(), _tmp37.createdAt = (0, import_dayjs28.default)().unix(), _tmp37.runId = responseCreatedResponse.id, _tmp37.status = "in_progress", _tmp37)
9242
10624
  ]), _tmp36)
9243
10625
  ])
9244
10626
  ];
@@ -9325,7 +10707,7 @@ var responsesRunAdapter = function(param) {
9325
10707
  4,
9326
10708
  onEvent2.apply(void 0, [
9327
10709
  (_tmp42.data = serializeItemAsMessage.apply(void 0, [
9328
- (_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt = (0, import_dayjs21.default)().unix(), _tmp43.runId = responseCreatedResponse.id, _tmp43.status = "in_progress", _tmp43)
10710
+ (_tmp43.openaiAssistant = _state.sent(), _tmp43.createdAt = (0, import_dayjs28.default)().unix(), _tmp43.runId = responseCreatedResponse.id, _tmp43.status = "in_progress", _tmp43)
9329
10711
  ]), _tmp42)
9330
10712
  ])
9331
10713
  ];
@@ -9412,7 +10794,7 @@ var responsesRunAdapter = function(param) {
9412
10794
  4,
9413
10795
  onEvent2.apply(void 0, [
9414
10796
  (_tmp48.data = serializeItemAsMessage.apply(void 0, [
9415
- (_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt = (0, import_dayjs21.default)().unix(), _tmp49.runId = responseCreatedResponse.id, _tmp49.status = "in_progress", _tmp49)
10797
+ (_tmp49.openaiAssistant = _state.sent(), _tmp49.createdAt = (0, import_dayjs28.default)().unix(), _tmp49.runId = responseCreatedResponse.id, _tmp49.status = "in_progress", _tmp49)
9416
10798
  ]), _tmp48)
9417
10799
  ])
9418
10800
  ];
@@ -9527,7 +10909,7 @@ var responsesRunAdapter = function(param) {
9527
10909
  4,
9528
10910
  onEvent2.apply(void 0, [
9529
10911
  (_tmp56.data = serializeItemAsMessage.apply(void 0, [
9530
- (_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt = (0, import_dayjs21.default)().unix(), _tmp57.runId = responseCreatedResponse.id, _tmp57)
10912
+ (_tmp57.openaiAssistant = _state.sent(), _tmp57.createdAt = (0, import_dayjs28.default)().unix(), _tmp57.runId = responseCreatedResponse.id, _tmp57)
9531
10913
  ]), _tmp56)
9532
10914
  ])
9533
10915
  ];
@@ -9649,7 +11031,7 @@ var responsesRunAdapter = function(param) {
9649
11031
  4,
9650
11032
  onEvent2.apply(void 0, [
9651
11033
  (_tmp64.data = serializeItemAsMessage.apply(void 0, [
9652
- (_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt = (0, import_dayjs21.default)().unix(), _tmp65.runId = responseCreatedResponse.id, _tmp65)
11034
+ (_tmp65.openaiAssistant = _state.sent(), _tmp65.createdAt = (0, import_dayjs28.default)().unix(), _tmp65.runId = responseCreatedResponse.id, _tmp65)
9653
11035
  ]), _tmp64)
9654
11036
  ])
9655
11037
  ];
@@ -9735,7 +11117,7 @@ var responsesRunAdapter = function(param) {
9735
11117
  4,
9736
11118
  onEvent2.apply(void 0, [
9737
11119
  (_tmp70.data = serializeItemAsMessage.apply(void 0, [
9738
- (_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt = (0, import_dayjs21.default)().unix(), _tmp71.runId = responseCreatedResponse.id, _tmp71)
11120
+ (_tmp71.openaiAssistant = _state.sent(), _tmp71.createdAt = (0, import_dayjs28.default)().unix(), _tmp71.runId = responseCreatedResponse.id, _tmp71)
9739
11121
  ]), _tmp70)
9740
11122
  ])
9741
11123
  ];
@@ -9821,7 +11203,7 @@ var responsesRunAdapter = function(param) {
9821
11203
  4,
9822
11204
  onEvent2.apply(void 0, [
9823
11205
  (_tmp76.data = serializeItemAsMessage.apply(void 0, [
9824
- (_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt = (0, import_dayjs21.default)().unix(), _tmp77.runId = responseCreatedResponse.id, _tmp77)
11206
+ (_tmp77.openaiAssistant = _state.sent(), _tmp77.createdAt = (0, import_dayjs28.default)().unix(), _tmp77.runId = responseCreatedResponse.id, _tmp77)
9825
11207
  ]), _tmp76)
9826
11208
  ])
9827
11209
  ];
@@ -9907,7 +11289,7 @@ var responsesRunAdapter = function(param) {
9907
11289
  4,
9908
11290
  onEvent2.apply(void 0, [
9909
11291
  (_tmp82.data = serializeItemAsMessage.apply(void 0, [
9910
- (_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt = (0, import_dayjs21.default)().unix(), _tmp83.runId = responseCreatedResponse.id, _tmp83)
11292
+ (_tmp83.openaiAssistant = _state.sent(), _tmp83.createdAt = (0, import_dayjs28.default)().unix(), _tmp83.runId = responseCreatedResponse.id, _tmp83)
9911
11293
  ]), _tmp82)
9912
11294
  ])
9913
11295
  ];
@@ -9993,7 +11375,7 @@ var responsesRunAdapter = function(param) {
9993
11375
  4,
9994
11376
  onEvent2.apply(void 0, [
9995
11377
  (_tmp88.data = serializeItemAsMessage.apply(void 0, [
9996
- (_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt = (0, import_dayjs21.default)().unix(), _tmp89.runId = responseCreatedResponse.id, _tmp89)
11378
+ (_tmp89.openaiAssistant = _state.sent(), _tmp89.createdAt = (0, import_dayjs28.default)().unix(), _tmp89.runId = responseCreatedResponse.id, _tmp89)
9997
11379
  ]), _tmp88)
9998
11380
  ])
9999
11381
  ];
@@ -10079,7 +11461,7 @@ var responsesRunAdapter = function(param) {
10079
11461
  4,
10080
11462
  onEvent2.apply(void 0, [
10081
11463
  (_tmp94.data = serializeItemAsMessage.apply(void 0, [
10082
- (_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt = (0, import_dayjs21.default)().unix(), _tmp95.runId = responseCreatedResponse.id, _tmp95)
11464
+ (_tmp95.openaiAssistant = _state.sent(), _tmp95.createdAt = (0, import_dayjs28.default)().unix(), _tmp95.runId = responseCreatedResponse.id, _tmp95)
10083
11465
  ]), _tmp94)
10084
11466
  ])
10085
11467
  ];
@@ -10176,7 +11558,7 @@ var responsesRunAdapter = function(param) {
10176
11558
  _tmp97 = {
10177
11559
  id: event.item_id,
10178
11560
  object: "thread.message",
10179
- created_at: (0, import_dayjs21.default)().unix(),
11561
+ created_at: (0, import_dayjs28.default)().unix(),
10180
11562
  thread_id: threadId,
10181
11563
  completed_at: null,
10182
11564
  incomplete_at: null,
@@ -10214,7 +11596,7 @@ var responsesRunAdapter = function(param) {
10214
11596
  _tmp99 = {
10215
11597
  id: event.item_id,
10216
11598
  object: "thread.message",
10217
- created_at: (0, import_dayjs21.default)().unix(),
11599
+ created_at: (0, import_dayjs28.default)().unix(),
10218
11600
  thread_id: threadId,
10219
11601
  completed_at: null,
10220
11602
  incomplete_at: null,
@@ -10386,7 +11768,7 @@ var responsesRunAdapter = function(param) {
10386
11768
  event: "thread.run.failed"
10387
11769
  };
10388
11770
  _tmp102 = {
10389
- id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash23.uid)(18)),
11771
+ id: (responseCreatedResponse === null || responseCreatedResponse === void 0 ? void 0 : responseCreatedResponse.id) || "run_".concat((0, import_radash24.uid)(18)),
10390
11772
  object: "thread.run",
10391
11773
  thread_id: threadId
10392
11774
  };
@@ -10402,7 +11784,7 @@ var responsesRunAdapter = function(param) {
10402
11784
  return [
10403
11785
  4,
10404
11786
  onEvent2.apply(void 0, [
10405
- (_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at = (0, import_dayjs21.default)().unix(), _tmp102.last_error = {
11787
+ (_tmp101.data = (_tmp102.assistant_id = _state.sent().id, _tmp102.status = "failed", _tmp102.failed_at = (0, import_dayjs28.default)().unix(), _tmp102.last_error = {
10406
11788
  code: "server_error",
10407
11789
  message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
10408
11790
  }, _tmp102), _tmp101)
@@ -10461,9 +11843,370 @@ var responsesRunAdapter = function(param) {
10461
11843
  getOpenaiAssistant: getOpenaiAssistant
10462
11844
  };
10463
11845
  };
11846
+ // src/adapters/run/azureAgentsRunAdapter/index.ts
11847
+ var import_dayjs29 = __toESM(require("dayjs"), 1);
11848
+ var import_radash25 = require("radash");
11849
+ function convertAzureEventToOpenAI2(azureEvent, assistantId) {
11850
+ var event = azureEvent.event, data = azureEvent.data;
11851
+ var eventType = event;
11852
+ if (eventType.startsWith("thread.run.")) {
11853
+ var _data_requiredAction_submitToolOutputs_toolCalls, _data_requiredAction_submitToolOutputs;
11854
+ var _data_temperature, _data_topP;
11855
+ return {
11856
+ event: eventType,
11857
+ data: {
11858
+ id: data.id,
11859
+ object: "thread.run",
11860
+ created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
11861
+ thread_id: data.threadId,
11862
+ assistant_id: assistantId,
11863
+ status: data.status,
11864
+ required_action: data.requiredAction ? {
11865
+ type: "submit_tool_outputs",
11866
+ submit_tool_outputs: {
11867
+ tool_calls: ((_data_requiredAction_submitToolOutputs = data.requiredAction.submitToolOutputs) === null || _data_requiredAction_submitToolOutputs === void 0 ? void 0 : (_data_requiredAction_submitToolOutputs_toolCalls = _data_requiredAction_submitToolOutputs.toolCalls) === null || _data_requiredAction_submitToolOutputs_toolCalls === void 0 ? void 0 : _data_requiredAction_submitToolOutputs_toolCalls.map(function(tc) {
11868
+ return {
11869
+ id: tc.id,
11870
+ type: "function",
11871
+ function: {
11872
+ name: tc.function.name,
11873
+ arguments: tc.function.arguments
11874
+ }
11875
+ };
11876
+ })) || []
11877
+ }
11878
+ } : null,
11879
+ last_error: data.lastError ? {
11880
+ code: "server_error",
11881
+ message: JSON.stringify(data.lastError)
11882
+ } : null,
11883
+ expires_at: null,
11884
+ started_at: data.startedAt ? (0, import_dayjs29.default)(data.startedAt).unix() : null,
11885
+ cancelled_at: data.cancelledAt ? (0, import_dayjs29.default)(data.cancelledAt).unix() : null,
11886
+ failed_at: data.failedAt ? (0, import_dayjs29.default)(data.failedAt).unix() : null,
11887
+ completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
11888
+ incomplete_details: null,
11889
+ model: data.model || "",
11890
+ instructions: data.instructions || "",
11891
+ tools: data.tools || [],
11892
+ metadata: data.metadata || {},
11893
+ temperature: (_data_temperature = data.temperature) !== null && _data_temperature !== void 0 ? _data_temperature : null,
11894
+ top_p: (_data_topP = data.topP) !== null && _data_topP !== void 0 ? _data_topP : null,
11895
+ max_prompt_tokens: null,
11896
+ max_completion_tokens: null,
11897
+ truncation_strategy: {
11898
+ type: "auto",
11899
+ last_messages: null
11900
+ },
11901
+ response_format: "auto",
11902
+ tool_choice: "auto",
11903
+ parallel_tool_calls: true,
11904
+ usage: null
11905
+ }
11906
+ };
11907
+ }
11908
+ if (eventType.startsWith("thread.message.") && eventType !== "thread.message.delta") {
11909
+ var _data_content;
11910
+ return {
11911
+ event: eventType,
11912
+ data: {
11913
+ id: data.id,
11914
+ object: "thread.message",
11915
+ created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
11916
+ thread_id: data.threadId,
11917
+ role: data.role,
11918
+ content: ((_data_content = data.content) === null || _data_content === void 0 ? void 0 : _data_content.map(function(c) {
11919
+ if (c.type === "text") {
11920
+ var _c_text, _c_text1;
11921
+ return {
11922
+ type: "text",
11923
+ text: {
11924
+ value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
11925
+ annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
11926
+ }
11927
+ };
11928
+ }
11929
+ return c;
11930
+ })) || [],
11931
+ assistant_id: assistantId,
11932
+ run_id: data.runId || null,
11933
+ attachments: data.attachments || [],
11934
+ metadata: data.metadata || {},
11935
+ status: data.status || "completed",
11936
+ completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
11937
+ incomplete_at: null,
11938
+ incomplete_details: null
11939
+ }
11940
+ };
11941
+ }
11942
+ if (eventType === "thread.message.delta") {
11943
+ var _data_delta_content, _data_delta;
11944
+ return {
11945
+ event: "thread.message.delta",
11946
+ data: {
11947
+ id: data.id,
11948
+ object: "thread.message.delta",
11949
+ delta: {
11950
+ content: ((_data_delta = data.delta) === null || _data_delta === void 0 ? void 0 : (_data_delta_content = _data_delta.content) === null || _data_delta_content === void 0 ? void 0 : _data_delta_content.map(function(c) {
11951
+ if (c.type === "text") {
11952
+ var _c_text, _c_text1;
11953
+ return {
11954
+ index: c.index || 0,
11955
+ type: "text",
11956
+ text: {
11957
+ value: ((_c_text = c.text) === null || _c_text === void 0 ? void 0 : _c_text.value) || "",
11958
+ annotations: ((_c_text1 = c.text) === null || _c_text1 === void 0 ? void 0 : _c_text1.annotations) || []
11959
+ }
11960
+ };
11961
+ }
11962
+ return c;
11963
+ })) || []
11964
+ }
11965
+ }
11966
+ };
11967
+ }
11968
+ if (eventType.startsWith("thread.run.step.")) {
11969
+ return {
11970
+ event: eventType,
11971
+ data: {
11972
+ id: data.id,
11973
+ object: "thread.run.step",
11974
+ created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
11975
+ assistant_id: assistantId,
11976
+ thread_id: data.threadId,
11977
+ run_id: data.runId,
11978
+ type: data.type,
11979
+ status: data.status,
11980
+ step_details: data.stepDetails || {},
11981
+ last_error: data.lastError || null,
11982
+ expired_at: null,
11983
+ cancelled_at: data.cancelledAt ? (0, import_dayjs29.default)(data.cancelledAt).unix() : null,
11984
+ failed_at: data.failedAt ? (0, import_dayjs29.default)(data.failedAt).unix() : null,
11985
+ completed_at: data.completedAt ? (0, import_dayjs29.default)(data.completedAt).unix() : null,
11986
+ metadata: data.metadata || {},
11987
+ usage: null
11988
+ }
11989
+ };
11990
+ }
11991
+ if (eventType === "thread.created") {
11992
+ return {
11993
+ event: "thread.created",
11994
+ data: {
11995
+ id: data.id,
11996
+ object: "thread",
11997
+ created_at: (0, import_dayjs29.default)(data.createdAt).unix(),
11998
+ metadata: data.metadata || {},
11999
+ tool_resources: data.toolResources || null
12000
+ }
12001
+ };
12002
+ }
12003
+ return null;
12004
+ }
12005
+ var azureAgentsRunAdapter = function(param) {
12006
+ var azureAiProject = param.azureAiProject;
12007
+ var getOpenaiAssistant = function(param) {
12008
+ var assistantId = param.assistantId;
12009
+ return _async_to_generator(function() {
12010
+ return _ts_generator(this, function(_state) {
12011
+ return [
12012
+ 2,
12013
+ {
12014
+ id: assistantId
12015
+ }
12016
+ ];
12017
+ });
12018
+ })();
12019
+ };
12020
+ var handleRun = function(param) {
12021
+ var threadId = param.threadId, assistantId = param.assistantId, instructions = param.instructions, tools = param.tools, onEvent2 = param.onEvent;
12022
+ return _async_to_generator(function() {
12023
+ var azureAgentId, createOptions, runResponse, stream, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, azureEvent, openaiEvent, err, e, errorRunId;
12024
+ return _ts_generator(this, function(_state) {
12025
+ switch(_state.label){
12026
+ case 0:
12027
+ _state.trys.push([
12028
+ 0,
12029
+ 15,
12030
+ ,
12031
+ 17
12032
+ ]);
12033
+ azureAgentId = assistantId;
12034
+ createOptions = {};
12035
+ if (instructions) {
12036
+ createOptions.instructions = instructions;
12037
+ }
12038
+ if (tools) {
12039
+ createOptions.tools = tools;
12040
+ }
12041
+ runResponse = azureAiProject.agents.runs.create(threadId, azureAgentId, createOptions);
12042
+ return [
12043
+ 4,
12044
+ runResponse.stream()
12045
+ ];
12046
+ case 1:
12047
+ stream = _state.sent();
12048
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
12049
+ _state.label = 2;
12050
+ case 2:
12051
+ _state.trys.push([
12052
+ 2,
12053
+ 8,
12054
+ 9,
12055
+ 14
12056
+ ]);
12057
+ _iterator = _async_iterator(stream);
12058
+ _state.label = 3;
12059
+ case 3:
12060
+ return [
12061
+ 4,
12062
+ _iterator.next()
12063
+ ];
12064
+ case 4:
12065
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
12066
+ 3,
12067
+ 7
12068
+ ];
12069
+ _value = _step.value;
12070
+ azureEvent = _value;
12071
+ openaiEvent = convertAzureEventToOpenAI2(azureEvent, assistantId);
12072
+ if (!openaiEvent) return [
12073
+ 3,
12074
+ 6
12075
+ ];
12076
+ return [
12077
+ 4,
12078
+ onEvent2(openaiEvent)
12079
+ ];
12080
+ case 5:
12081
+ _state.sent();
12082
+ _state.label = 6;
12083
+ case 6:
12084
+ _iteratorAbruptCompletion = false;
12085
+ return [
12086
+ 3,
12087
+ 3
12088
+ ];
12089
+ case 7:
12090
+ return [
12091
+ 3,
12092
+ 14
12093
+ ];
12094
+ case 8:
12095
+ err = _state.sent();
12096
+ _didIteratorError = true;
12097
+ _iteratorError = err;
12098
+ return [
12099
+ 3,
12100
+ 14
12101
+ ];
12102
+ case 9:
12103
+ _state.trys.push([
12104
+ 9,
12105
+ ,
12106
+ 12,
12107
+ 13
12108
+ ]);
12109
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
12110
+ 3,
12111
+ 11
12112
+ ];
12113
+ return [
12114
+ 4,
12115
+ _iterator.return()
12116
+ ];
12117
+ case 10:
12118
+ _state.sent();
12119
+ _state.label = 11;
12120
+ case 11:
12121
+ return [
12122
+ 3,
12123
+ 13
12124
+ ];
12125
+ case 12:
12126
+ if (_didIteratorError) {
12127
+ throw _iteratorError;
12128
+ }
12129
+ return [
12130
+ 7
12131
+ ];
12132
+ case 13:
12133
+ return [
12134
+ 7
12135
+ ];
12136
+ case 14:
12137
+ return [
12138
+ 3,
12139
+ 17
12140
+ ];
12141
+ case 15:
12142
+ e = _state.sent();
12143
+ errorRunId = "run_".concat((0, import_radash25.uid)(18));
12144
+ return [
12145
+ 4,
12146
+ onEvent2({
12147
+ event: "thread.run.failed",
12148
+ data: {
12149
+ id: errorRunId,
12150
+ object: "thread.run",
12151
+ created_at: (0, import_dayjs29.default)().unix(),
12152
+ thread_id: threadId,
12153
+ assistant_id: assistantId,
12154
+ status: "failed",
12155
+ required_action: null,
12156
+ last_error: {
12157
+ code: "server_error",
12158
+ message: String((e === null || e === void 0 ? void 0 : e.message) || e || "Unknown error")
12159
+ },
12160
+ expires_at: null,
12161
+ started_at: (0, import_dayjs29.default)().unix(),
12162
+ cancelled_at: null,
12163
+ failed_at: (0, import_dayjs29.default)().unix(),
12164
+ completed_at: null,
12165
+ incomplete_details: null,
12166
+ model: "",
12167
+ instructions: "",
12168
+ tools: [],
12169
+ metadata: {},
12170
+ temperature: null,
12171
+ top_p: null,
12172
+ max_prompt_tokens: null,
12173
+ max_completion_tokens: null,
12174
+ truncation_strategy: {
12175
+ type: "auto",
12176
+ last_messages: null
12177
+ },
12178
+ response_format: "auto",
12179
+ tool_choice: "auto",
12180
+ parallel_tool_calls: true,
12181
+ usage: null
12182
+ }
12183
+ })
12184
+ ];
12185
+ case 16:
12186
+ _state.sent();
12187
+ return [
12188
+ 3,
12189
+ 17
12190
+ ];
12191
+ case 17:
12192
+ return [
12193
+ 2
12194
+ ];
12195
+ }
12196
+ });
12197
+ })();
12198
+ };
12199
+ return {
12200
+ handleRun: handleRun,
12201
+ getOpenaiAssistant: getOpenaiAssistant
12202
+ };
12203
+ };
10464
12204
  // Annotate the CommonJS export names for ESM import in node:
10465
12205
  0 && (module.exports = {
10466
12206
  anthropicClientAdapter: anthropicClientAdapter,
12207
+ azureAgentsRunAdapter: azureAgentsRunAdapter,
12208
+ azureAgentsStorageAdapter: azureAgentsStorageAdapter,
12209
+ azureAiProjectClientAdapter: azureAiProjectClientAdapter,
10467
12210
  azureOpenaiClientAdapter: azureOpenaiClientAdapter,
10468
12211
  completionsRunAdapter: completionsRunAdapter,
10469
12212
  googleClientAdapter: googleClientAdapter,