omnigateway 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/bin/omni.js +2118 -113
  2. package/gateway.js +2197 -196
  3. package/package.json +1 -1
  4. package/public/assets/{Chip-Did4Zhvj.js → Chip-BeKVtewW.js} +1 -1
  5. package/public/assets/{CopyValue-Cjg9QXrD.js → CopyValue-NTHhiCuT.js} +1 -1
  6. package/public/assets/{Rack-D0_N-xsd.js → Rack-sUGRoZUx.js} +1 -1
  7. package/public/assets/{RequestTable-i9paP_7e.js → RequestTable-C2RLARWy.js} +1 -1
  8. package/public/assets/{SummaryDeck-g4yLDeXB.js → SummaryDeck-BHXcb_Ji.js} +1 -1
  9. package/public/assets/{Toggle-D-NDlneh.js → Toggle-DwKz1aVq.js} +1 -1
  10. package/public/assets/{TokenBreakdown-D5ZIngM6.js → TokenBreakdown-DM-1HvOr.js} +1 -1
  11. package/public/assets/{_app.accounts-DFhyE62a.js → _app.accounts-DUYxItf0.js} +1 -1
  12. package/public/assets/{_app.console-BfHcfQMp.js → _app.console-BQJMLRv4.js} +1 -1
  13. package/public/assets/{_app.database-Cgw9z3rK.js → _app.database-BIiajZm6.js} +1 -1
  14. package/public/assets/{_app.index-Blw3S4-3.js → _app.index-DagK0Pqp.js} +1 -1
  15. package/public/assets/{_app.keys-DrdfnfIk.js → _app.keys-DLAG_bmt.js} +1 -1
  16. package/public/assets/{_app.logs-DUOqlJzB.js → _app.logs-AyVq3lLb.js} +1 -1
  17. package/public/assets/{_app.models-Dm83HRaM.js → _app.models-CwlkGPrx.js} +1 -1
  18. package/public/assets/{_app.plugins._pluginId-BmJGDYxw.js → _app.plugins._pluginId-BhvEnawY.js} +1 -1
  19. package/public/assets/{_app.settings-66rm4vHJ.js → _app.settings-BKA-1YLs.js} +1 -1
  20. package/public/assets/{_app.usage-BCufy5XR.js → _app.usage-C7JEWKZM.js} +1 -1
  21. package/public/assets/{chevron-right-BZ4QmUDM.js → chevron-right-S84SGCvk.js} +1 -1
  22. package/public/assets/{client-De1_cEH5.js → client-DCvpw0LS.js} +1 -1
  23. package/public/assets/{index-PP8vsvw3.js → index-pZbadEun.js} +3 -3
  24. package/public/assets/{login-CkZlwcdd.js → login-CitmheGz.js} +1 -1
  25. package/public/assets/plus-E7qLz9CF.js +1 -0
  26. package/public/assets/{trash-2-BLc5o7DN.js → trash-2-DmtElUHr.js} +1 -1
  27. package/public/index.html +2 -2
  28. package/public/shared/dashboard-sdk.js +1 -1
  29. package/public/assets/plus-D5AwIXj3.js +0 -1
package/gateway.js CHANGED
@@ -4687,8 +4687,8 @@ class FileTypeParser {
4687
4687
  if (jsonSize > 12 && this.buffer.length >= jsonSize + 16) {
4688
4688
  try {
4689
4689
  const header = new TextDecoder().decode(this.buffer.subarray(16, jsonSize + 16));
4690
- const json8 = JSON.parse(header);
4691
- if (json8.files) {
4690
+ const json10 = JSON.parse(header);
4691
+ if (json10.files) {
4692
4692
  return {
4693
4693
  ext: "asar",
4694
4694
  mime: "application/x-asar"
@@ -28911,6 +28911,12 @@ var ANTHROPIC_MODELS = {
28911
28911
  defaultModel: "claude-opus-5",
28912
28912
  authTypes: ["oauth", "apiKey"],
28913
28913
  models: [
28914
+ {
28915
+ id: "claude-fable-5-1",
28916
+ label: "Claude Fable 5.1",
28917
+ pricing: { input: 10, output: 50, cacheRead: 0.25, cacheWrite5m: 12.5, cacheWrite1h: 20 },
28918
+ limits: { contextWindow: 1e6, maxOutputTokens: 128000 }
28919
+ },
28914
28920
  {
28915
28921
  id: "claude-fable-5",
28916
28922
  label: "Claude Fable 5",
@@ -28926,7 +28932,7 @@ var ANTHROPIC_MODELS = {
28926
28932
  {
28927
28933
  id: "claude-sonnet-5",
28928
28934
  label: "Claude Sonnet 5",
28929
- pricing: { input: 3, output: 15, cacheRead: 0.3, cacheWrite5m: 3.75, cacheWrite1h: 6 },
28935
+ pricing: { input: 2, output: 10, cacheRead: 0.2, cacheWrite5m: 2.5, cacheWrite1h: 4 },
28930
28936
  limits: { contextWindow: 1e6, maxOutputTokens: 128000 }
28931
28937
  },
28932
28938
  {
@@ -28964,6 +28970,145 @@ var anthropicDescriptor = {
28964
28970
  }
28965
28971
  };
28966
28972
 
28973
+ // packages/providers/src/antigravity/models.ts
28974
+ var MAX_OUTPUT_TOKENS = 65536;
28975
+ var PRO_MAX_OUTPUT_TOKENS = 65535;
28976
+ var NO_CACHE_WRITE = { cacheWrite5m: 0, cacheWrite1h: 0 };
28977
+ var FREE = { input: 0, output: 0, cacheRead: 0, ...NO_CACHE_WRITE };
28978
+ var FLASH_LIMITS = { contextWindow: 1048576, maxOutputTokens: MAX_OUTPUT_TOKENS };
28979
+ var PRO_LIMITS = { contextWindow: 1048576, maxOutputTokens: PRO_MAX_OUTPUT_TOKENS };
28980
+ var ANTIGRAVITY_MODELS = {
28981
+ defaultModel: "gemini-3.8-flash-high",
28982
+ authTypes: ["oauth"],
28983
+ models: [
28984
+ {
28985
+ id: "gemini-3.8-flash-high",
28986
+ label: "Gemini 3.8 Flash (High)",
28987
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
28988
+ limits: FLASH_LIMITS
28989
+ },
28990
+ {
28991
+ id: "gemini-3.8-flash-medium",
28992
+ label: "Gemini 3.8 Flash (Medium)",
28993
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
28994
+ limits: FLASH_LIMITS
28995
+ },
28996
+ {
28997
+ id: "gemini-3.8-flash-low",
28998
+ label: "Gemini 3.8 Flash (Low)",
28999
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29000
+ limits: FLASH_LIMITS
29001
+ },
29002
+ {
29003
+ id: "gemini-3.7-flash-high",
29004
+ label: "Gemini 3.7 Flash (High)",
29005
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29006
+ limits: FLASH_LIMITS
29007
+ },
29008
+ {
29009
+ id: "gemini-3.7-flash-medium",
29010
+ label: "Gemini 3.7 Flash (Medium)",
29011
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29012
+ limits: FLASH_LIMITS
29013
+ },
29014
+ {
29015
+ id: "gemini-3.7-flash-low",
29016
+ label: "Gemini 3.7 Flash (Low)",
29017
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29018
+ limits: FLASH_LIMITS
29019
+ },
29020
+ {
29021
+ id: "gemini-3.6-flash-high",
29022
+ label: "Gemini 3.6 Flash (High)",
29023
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29024
+ limits: FLASH_LIMITS
29025
+ },
29026
+ {
29027
+ id: "gemini-3.6-flash-medium",
29028
+ label: "Gemini 3.6 Flash (Medium)",
29029
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29030
+ limits: FLASH_LIMITS
29031
+ },
29032
+ {
29033
+ id: "gemini-3.6-flash-low",
29034
+ label: "Gemini 3.6 Flash (Low)",
29035
+ pricing: { input: 1.5, output: 7.5, cacheRead: 0.15, ...NO_CACHE_WRITE },
29036
+ limits: FLASH_LIMITS
29037
+ },
29038
+ {
29039
+ id: "gemini-3-flash-agent",
29040
+ label: "Gemini 3.5 Flash (High)",
29041
+ pricing: { input: 1.5, output: 9, cacheRead: 0.15, ...NO_CACHE_WRITE },
29042
+ limits: FLASH_LIMITS
29043
+ },
29044
+ {
29045
+ id: "gemini-3.5-flash-low",
29046
+ label: "Gemini 3.5 Flash (Medium)",
29047
+ pricing: { input: 1.5, output: 9, cacheRead: 0.15, ...NO_CACHE_WRITE },
29048
+ limits: FLASH_LIMITS
29049
+ },
29050
+ {
29051
+ id: "gemini-3.5-flash-extra-low",
29052
+ label: "Gemini 3.5 Flash (Low)",
29053
+ pricing: { input: 1.5, output: 9, cacheRead: 0.15, ...NO_CACHE_WRITE },
29054
+ limits: FLASH_LIMITS
29055
+ },
29056
+ {
29057
+ id: "gemini-3-flash",
29058
+ label: "Gemini 3 Flash",
29059
+ pricing: FREE,
29060
+ limits: FLASH_LIMITS
29061
+ },
29062
+ {
29063
+ id: "gemini-3.5-flash-lite",
29064
+ label: "Gemini 3.5 Flash Lite",
29065
+ pricing: { input: 0.3, output: 2.5, cacheRead: 0.03, ...NO_CACHE_WRITE },
29066
+ limits: PRO_LIMITS
29067
+ },
29068
+ {
29069
+ id: "gemini-pro-agent",
29070
+ label: "Gemini 3.1 Pro (High)",
29071
+ pricing: { input: 2, output: 12, cacheRead: 0.2, ...NO_CACHE_WRITE },
29072
+ limits: PRO_LIMITS
29073
+ },
29074
+ {
29075
+ id: "gemini-3.1-pro-low",
29076
+ label: "Gemini 3.1 Pro (Low)",
29077
+ pricing: { input: 2, output: 12, cacheRead: 0.2, ...NO_CACHE_WRITE },
29078
+ limits: PRO_LIMITS
29079
+ },
29080
+ {
29081
+ id: "gemini-3.1-flash-lite",
29082
+ label: "Gemini 3.1 Flash Lite",
29083
+ pricing: { input: 0.25, output: 1.5, cacheRead: 0.025, ...NO_CACHE_WRITE },
29084
+ limits: PRO_LIMITS
29085
+ },
29086
+ {
29087
+ id: "gemini-2.5-pro",
29088
+ label: "Gemini 2.5 Pro",
29089
+ pricing: { input: 1.25, output: 10, cacheRead: 0.125, ...NO_CACHE_WRITE },
29090
+ limits: PRO_LIMITS
29091
+ }
29092
+ ]
29093
+ };
29094
+
29095
+ // packages/providers/src/antigravity/descriptor.ts
29096
+ var antigravityDescriptor = {
29097
+ id: "antigravity",
29098
+ capabilities: { tools: true, images: true, reasoning: true },
29099
+ writeOverInput: { fiveMinute: 0, oneHour: 0 },
29100
+ catalog: ANTIGRAVITY_MODELS,
29101
+ modelPrefixes: ["gemini-"],
29102
+ callback: { uri: "http://127.0.0.1:51121/callback", label: "Antigravity" },
29103
+ presentation: {
29104
+ label: "Antigravity",
29105
+ order: 6,
29106
+ tone: "violet",
29107
+ colour: { light: "oklch(0.52 0.14 277)", dark: "oklch(0.74 0.14 277)" },
29108
+ pasteHint: "Approve in a browser on the gateway's own machine \u2014 or SSH-forward port 51121 first. When it redirects to 127.0.0.1, paste the whole URL."
29109
+ }
29110
+ };
29111
+
28967
29112
  // packages/providers/src/custom/models.ts
28968
29113
  var CUSTOM_MODELS = {
28969
29114
  defaultModel: "",
@@ -28980,7 +29125,7 @@ var customDescriptor = {
28980
29125
  modelPrefixes: [],
28981
29126
  presentation: {
28982
29127
  label: "OpenAI Compatible",
28983
- order: 6,
29128
+ order: 8,
28984
29129
  tone: "cyan",
28985
29130
  colour: { light: "oklch(0.5 0.03 258)", dark: "oklch(0.72 0.03 258)" },
28986
29131
  pasteHint: "Enter endpoint metadata and API key."
@@ -29305,35 +29450,90 @@ var kimiDescriptor = {
29305
29450
  }
29306
29451
  };
29307
29452
 
29453
+ // packages/providers/src/muse/models.ts
29454
+ var MUSE_MODELS = {
29455
+ defaultModel: "muse-spark-1.3",
29456
+ authTypes: ["oauth", "apiKey"],
29457
+ models: [
29458
+ {
29459
+ id: "muse-spark-1.3",
29460
+ label: "Muse Spark 1.3",
29461
+ pricing: { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite5m: 0, cacheWrite1h: 0 },
29462
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29463
+ },
29464
+ {
29465
+ id: "muse-spark-1.3-contributor",
29466
+ label: "Muse Spark 1.3 \u2014 Meta trains on this traffic",
29467
+ pricing: { input: 0.1, output: 0.2, cacheRead: 0.002, cacheWrite5m: 0, cacheWrite1h: 0 },
29468
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29469
+ },
29470
+ {
29471
+ id: "muse-spark-1.2",
29472
+ label: "Muse Spark 1.2",
29473
+ pricing: { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite5m: 0, cacheWrite1h: 0 },
29474
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29475
+ },
29476
+ {
29477
+ id: "muse-spark-1.2-contributor",
29478
+ label: "Muse Spark 1.2 \u2014 Meta trains on this traffic",
29479
+ pricing: { input: 0.1, output: 0.2, cacheRead: 0.002, cacheWrite5m: 0, cacheWrite1h: 0 },
29480
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29481
+ }
29482
+ ]
29483
+ };
29484
+
29485
+ // packages/providers/src/muse/descriptor.ts
29486
+ var museDescriptor = {
29487
+ id: "muse",
29488
+ capabilities: { tools: true, images: true, reasoning: true },
29489
+ writeOverInput: { fiveMinute: 0, oneHour: 0 },
29490
+ catalog: MUSE_MODELS,
29491
+ modelPrefixes: ["muse-", "muse-spark"],
29492
+ presentation: {
29493
+ label: "Muse",
29494
+ order: 7,
29495
+ tone: "azure",
29496
+ colour: { light: "oklch(0.55 0.23 262)", dark: "oklch(0.72 0.17 262)" },
29497
+ pasteHint: "Enter the code on Meta's device page. This dialog finishes on its own."
29498
+ }
29499
+ };
29500
+
29308
29501
  // packages/providers/src/openai/models.ts
29309
29502
  var OPENAI_MODELS = {
29310
29503
  defaultModel: "gpt-5.6",
29311
29504
  authTypes: ["oauth", "apiKey"],
29312
29505
  models: [
29506
+ {
29507
+ id: "gpt-6-astra",
29508
+ label: "GPT-6 Astra",
29509
+ pricing: { input: 10, output: 50, cacheRead: 1, cacheWrite5m: 0, cacheWrite1h: 0 },
29510
+ limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29511
+ oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29512
+ },
29313
29513
  {
29314
29514
  id: "gpt-5.6",
29315
29515
  label: "GPT-5.6 \u2014 routes to Sol",
29316
- pricing: { input: 5, output: 30, cacheRead: 0.5, cacheWrite5m: 0, cacheWrite1h: 0 },
29516
+ pricing: { input: 4, output: 20, cacheRead: 0.4, cacheWrite5m: 0, cacheWrite1h: 0 },
29317
29517
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29318
29518
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29319
29519
  },
29320
29520
  {
29321
29521
  id: "gpt-5.6-sol",
29322
- label: "GPT-5.6 Sol \u2014 deepest reasoning",
29323
- pricing: { input: 5, output: 30, cacheRead: 0.5, cacheWrite5m: 0, cacheWrite1h: 0 },
29522
+ label: "GPT-5.6 Sol",
29523
+ pricing: { input: 4, output: 20, cacheRead: 0.4, cacheWrite5m: 0, cacheWrite1h: 0 },
29324
29524
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29325
29525
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29326
29526
  },
29327
29527
  {
29328
29528
  id: "gpt-5.6-terra",
29329
- label: "GPT-5.6 Terra \u2014 balanced",
29529
+ label: "GPT-5.6 Terra",
29330
29530
  pricing: { input: 2, output: 12, cacheRead: 0.2, cacheWrite5m: 0, cacheWrite1h: 0 },
29331
29531
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29332
29532
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29333
29533
  },
29334
29534
  {
29335
29535
  id: "gpt-5.6-luna",
29336
- label: "GPT-5.6 Luna \u2014 fastest",
29536
+ label: "GPT-5.6 Luna",
29337
29537
  pricing: { input: 0.2, output: 1.2, cacheRead: 0.02, cacheWrite5m: 0, cacheWrite1h: 0 },
29338
29538
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29339
29539
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
@@ -29371,6 +29571,8 @@ var PROVIDER_DESCRIPTORS = {
29371
29571
  kimi: kimiDescriptor,
29372
29572
  kilo: kiloDescriptor,
29373
29573
  grok: grokDescriptor,
29574
+ antigravity: antigravityDescriptor,
29575
+ muse: museDescriptor,
29374
29576
  custom: customDescriptor
29375
29577
  };
29376
29578
  Object.setPrototypeOf(PROVIDER_DESCRIPTORS, null);
@@ -29909,6 +30111,38 @@ var anthropicBodyOrder = [
29909
30111
  "stream"
29910
30112
  ];
29911
30113
 
30114
+ // packages/providers/src/antigravity/profile.ts
30115
+ var ANTIGRAVITY_IDE_VERSION = env("OMNI_ANTIGRAVITY_IDE_VERSION", "2.12.2");
30116
+ var PLATFORM = "darwin/arm64";
30117
+ var antigravityProfile = {
30118
+ headers: [
30119
+ [
30120
+ "User-Agent",
30121
+ env("OMNI_UA_ANTIGRAVITY", `antigravity/ide/${ANTIGRAVITY_IDE_VERSION} ${PLATFORM}`)
30122
+ ],
30123
+ ["Content-Type", "application/json"],
30124
+ ["Accept", "text/event-stream"]
30125
+ ],
30126
+ order: envOrder("OMNI_ORDER_ANTIGRAVITY", [
30127
+ "Host",
30128
+ "Content-Type",
30129
+ "Authorization",
30130
+ "User-Agent",
30131
+ "X-Goog-Api-Client",
30132
+ "Accept",
30133
+ "Accept-Encoding",
30134
+ "Content-Length"
30135
+ ])
30136
+ };
30137
+ var antigravityBodyOrder = [
30138
+ "project",
30139
+ "requestId",
30140
+ "model",
30141
+ "userAgent",
30142
+ "requestType",
30143
+ "request"
30144
+ ];
30145
+
29912
30146
  // packages/providers/src/custom/profile.ts
29913
30147
  var customProfile = { headers: [], order: [] };
29914
30148
  var customBodyOrder = [];
@@ -30030,6 +30264,43 @@ var kimiBodyOrder = [
30030
30264
  "stream"
30031
30265
  ];
30032
30266
 
30267
+ // packages/providers/src/muse/profile.ts
30268
+ var MUSE_CLI_VERSION = env("OMNI_MUSE_CLI_VERSION", "1.0.3");
30269
+ var museProfile = {
30270
+ headers: [
30271
+ ["User-Agent", env("OMNI_UA_MUSE", `muse-code/${MUSE_CLI_VERSION}`)],
30272
+ ["x-api-version", env("OMNI_MUSE_API_VERSION", "1.0.0")],
30273
+ ["Accept", "text/event-stream"]
30274
+ ],
30275
+ order: envOrder("OMNI_ORDER_MUSE", [
30276
+ "Host",
30277
+ "Content-Type",
30278
+ "Authorization",
30279
+ "x-meta-ai-gateway-session-id",
30280
+ "x-api-version",
30281
+ "Accept",
30282
+ "User-Agent",
30283
+ "Accept-Encoding",
30284
+ "Content-Length"
30285
+ ])
30286
+ };
30287
+ var museBodyOrder = [
30288
+ "model",
30289
+ "stream",
30290
+ "input",
30291
+ "instructions",
30292
+ "store",
30293
+ "reasoning",
30294
+ "prompt_cache_key",
30295
+ "max_output_tokens",
30296
+ "temperature",
30297
+ "tools",
30298
+ "tool_choice",
30299
+ "include",
30300
+ "parallel_tool_calls",
30301
+ "metadata"
30302
+ ];
30303
+
30033
30304
  // packages/providers/src/openai/profile.ts
30034
30305
  var OPENAI_CLI_VERSION = env("OMNI_OPENAI_CLI_VERSION", "0.144.1");
30035
30306
  var OPENAI_UA_PLATFORM = env("OMNI_OPENAI_UA_PLATFORM", "Windows 10.0.26200");
@@ -30086,6 +30357,8 @@ var BODY_ORDER = {
30086
30357
  kimi: kimiBodyOrder,
30087
30358
  kilo: kiloBodyOrder,
30088
30359
  grok: grokBodyOrder,
30360
+ antigravity: antigravityBodyOrder,
30361
+ muse: museBodyOrder,
30089
30362
  custom: customBodyOrder
30090
30363
  };
30091
30364
  Object.setPrototypeOf(BODY_ORDER, null);
@@ -30179,6 +30452,8 @@ var PROVIDER_MODEL_CATALOG = {
30179
30452
  kimi: KIMI_MODELS,
30180
30453
  kilo: KILO_MODELS,
30181
30454
  grok: GROK_MODELS,
30455
+ antigravity: ANTIGRAVITY_MODELS,
30456
+ muse: MUSE_MODELS,
30182
30457
  custom: CUSTOM_MODELS
30183
30458
  };
30184
30459
  Object.setPrototypeOf(PROVIDER_MODEL_CATALOG, null);
@@ -30209,6 +30484,8 @@ var PROFILES = {
30209
30484
  kimi: kimiProfile,
30210
30485
  kilo: kiloProfile,
30211
30486
  grok: grokProfile,
30487
+ antigravity: antigravityProfile,
30488
+ muse: museProfile,
30212
30489
  custom: customProfile
30213
30490
  };
30214
30491
  Object.setPrototypeOf(PROFILES, null);
@@ -31493,6 +31770,1114 @@ var anthropicOAuthFlow = {
31493
31770
  return parseAnthropicUsage(parsed(res.body), now());
31494
31771
  }
31495
31772
  };
31773
+ // packages/providers/src/antigravity/codec.ts
31774
+ import { createHash as createHash2 } from "crypto";
31775
+
31776
+ // packages/providers/src/antigravity/cloak.ts
31777
+ var FUNCTION_NAME = /^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/;
31778
+ var MAX_NAME = 128;
31779
+ var SUFFIX_LENGTH2 = 6;
31780
+ function aliasFor2(name) {
31781
+ let base = name.replace(/[^A-Za-z0-9_.-]+/g, "_");
31782
+ if (!/^[A-Za-z_]/.test(base))
31783
+ base = `_${base}`;
31784
+ if (base === "_")
31785
+ return { base: "_tool", forced: true };
31786
+ if (base.length > MAX_NAME) {
31787
+ return { base: base.slice(0, MAX_NAME - SUFFIX_LENGTH2), forced: true };
31788
+ }
31789
+ return { base, forced: false };
31790
+ }
31791
+ function clientToolNames2(request2) {
31792
+ const renamable = new Set;
31793
+ const reserved = new Set;
31794
+ const add = (name) => {
31795
+ (FUNCTION_NAME.test(name) ? reserved : renamable).add(name);
31796
+ };
31797
+ const called = new Set;
31798
+ for (const message of request2.messages) {
31799
+ for (const block of message.content) {
31800
+ if (block.type === "toolUse")
31801
+ called.add(block.id);
31802
+ }
31803
+ }
31804
+ for (const tool of request2.tools ?? []) {
31805
+ if (tool.kind === "portable")
31806
+ add(tool.name);
31807
+ }
31808
+ for (const message of request2.messages) {
31809
+ for (const block of message.content) {
31810
+ if (block.type === "toolUse")
31811
+ add(block.name);
31812
+ if (block.type === "toolResult" && !called.has(block.toolUseId))
31813
+ add(block.toolUseId);
31814
+ }
31815
+ }
31816
+ if (request2.toolChoice?.type === "tool")
31817
+ add(request2.toolChoice.name);
31818
+ return { renamable: [...renamable], reserved: [...reserved] };
31819
+ }
31820
+ function suffixFor2(name) {
31821
+ const digest = Bun.hash.xxHash64(Buffer.from(name, "utf8")) & 0xffffffn;
31822
+ return digest.toString(16).padStart(SUFFIX_LENGTH2, "0");
31823
+ }
31824
+ function buildToolCloak2(request2) {
31825
+ const { renamable, reserved } = clientToolNames2(request2);
31826
+ const claims = new Map;
31827
+ const claim2 = (name) => {
31828
+ claims.set(name, (claims.get(name) ?? 0) + 1);
31829
+ };
31830
+ for (const name of reserved)
31831
+ claim2(name);
31832
+ const bases = new Map;
31833
+ for (const name of renamable) {
31834
+ const derived = aliasFor2(name);
31835
+ bases.set(name, derived);
31836
+ claim2(derived.base);
31837
+ }
31838
+ const toWire2 = new Map;
31839
+ const fromWire = new Map;
31840
+ for (const [name, { base, forced }] of bases) {
31841
+ const alias = forced || (claims.get(base) ?? 0) > 1 ? base + suffixFor2(name) : base;
31842
+ toWire2.set(name, alias);
31843
+ fromWire.set(alias, name);
31844
+ }
31845
+ return toWire2.size === 0 ? null : { toWire: toWire2, fromWire };
31846
+ }
31847
+ function cloakName2(cloak, name) {
31848
+ return cloak?.toWire.get(name) ?? name;
31849
+ }
31850
+ function uncloakName2(cloak, name) {
31851
+ return cloak?.fromWire.get(name) ?? name;
31852
+ }
31853
+
31854
+ // packages/providers/src/antigravity/decode.ts
31855
+ var STOP_REASON2 = {
31856
+ STOP: "endTurn",
31857
+ MAX_TOKENS: "maxTokens",
31858
+ SAFETY: "contentFilter",
31859
+ PROHIBITED_CONTENT: "contentFilter",
31860
+ SPII: "contentFilter",
31861
+ BLOCKLIST: "contentFilter",
31862
+ RECITATION: "contentFilter"
31863
+ };
31864
+ var ERROR_CODE = {
31865
+ RESOURCE_EXHAUSTED: "RATE_LIMIT",
31866
+ UNAUTHENTICATED: "AUTH",
31867
+ PERMISSION_DENIED: "AUTH",
31868
+ INVALID_ARGUMENT: "BAD_REQUEST",
31869
+ FAILED_PRECONDITION: "BAD_REQUEST",
31870
+ UNAVAILABLE: "UPSTREAM",
31871
+ INTERNAL: "UPSTREAM",
31872
+ DEADLINE_EXCEEDED: "TIMEOUT"
31873
+ };
31874
+ function json3(data) {
31875
+ try {
31876
+ const value = JSON.parse(data);
31877
+ return typeof value === "object" && value !== null ? value : null;
31878
+ } catch {
31879
+ return null;
31880
+ }
31881
+ }
31882
+ function count(value) {
31883
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
31884
+ }
31885
+ function usageOf(meta3) {
31886
+ return usageFromPromptTotal(count(meta3?.promptTokenCount), count(meta3?.candidatesTokenCount) + count(meta3?.thoughtsTokenCount), count(meta3?.cachedContentTokenCount));
31887
+ }
31888
+ async function* decodeAntigravityStream(messages, opts = {}) {
31889
+ const cloak = opts.cloak ?? null;
31890
+ let started = false;
31891
+ let terminal = false;
31892
+ let nextIndex = 0;
31893
+ let toolCalls = 0;
31894
+ let open2 = null;
31895
+ const closeOpen = function* () {
31896
+ if (open2 === null)
31897
+ return;
31898
+ yield { type: "blockEnd", index: open2.index };
31899
+ open2 = null;
31900
+ };
31901
+ for await (const message of messages) {
31902
+ if (message.data === "[DONE]")
31903
+ continue;
31904
+ const frame = json3(message.data);
31905
+ if (frame === null)
31906
+ continue;
31907
+ const failure = frame.error ?? frame.response?.error;
31908
+ if (failure !== undefined) {
31909
+ terminal = true;
31910
+ yield* closeOpen();
31911
+ const status = String(failure.status ?? "");
31912
+ const code = (Object.hasOwn(ERROR_CODE, status) ? ERROR_CODE[status] : undefined) ?? "UPSTREAM";
31913
+ yield {
31914
+ type: "error",
31915
+ code,
31916
+ message: String(failure.message ?? "upstream error"),
31917
+ retryable: RETRYABLE[code]
31918
+ };
31919
+ return;
31920
+ }
31921
+ const response = frame.response;
31922
+ if (response === undefined)
31923
+ continue;
31924
+ const blocked = response.promptFeedback?.blockReason;
31925
+ if (blocked !== undefined && (response.candidates ?? []).length === 0) {
31926
+ terminal = true;
31927
+ if (!started)
31928
+ yield { type: "start", id: "", model: "" };
31929
+ yield* closeOpen();
31930
+ yield { type: "end", stopReason: "contentFilter", usage: usageOf(response.usageMetadata) };
31931
+ return;
31932
+ }
31933
+ if (!started) {
31934
+ started = true;
31935
+ yield {
31936
+ type: "start",
31937
+ id: String(response.responseId ?? ""),
31938
+ model: String(response.modelVersion ?? "")
31939
+ };
31940
+ }
31941
+ const candidates = response.candidates ?? [];
31942
+ if (candidates.length > 1) {
31943
+ terminal = true;
31944
+ yield* closeOpen();
31945
+ yield {
31946
+ type: "error",
31947
+ code: "UPSTREAM",
31948
+ message: `Antigravity returned ${candidates.length} candidates, which cannot be represented`,
31949
+ retryable: false
31950
+ };
31951
+ return;
31952
+ }
31953
+ const candidate = candidates[0];
31954
+ for (const part of candidate?.content?.parts ?? []) {
31955
+ const call = part.functionCall;
31956
+ if (call !== undefined && typeof call.name === "string") {
31957
+ yield* closeOpen();
31958
+ const index = nextIndex++;
31959
+ yield {
31960
+ type: "blockStart",
31961
+ index,
31962
+ block: {
31963
+ type: "toolUse",
31964
+ id: typeof call.id === "string" && call.id.length > 0 ? call.id : `fc_${toolCalls}`,
31965
+ name: uncloakName2(cloak, call.name)
31966
+ }
31967
+ };
31968
+ yield {
31969
+ type: "blockDelta",
31970
+ index,
31971
+ delta: { type: "toolJson", partial: JSON.stringify(call.args ?? {}) }
31972
+ };
31973
+ yield { type: "blockEnd", index };
31974
+ toolCalls++;
31975
+ continue;
31976
+ }
31977
+ if (typeof part.text !== "string")
31978
+ continue;
31979
+ const kind = part.thought === true ? "thinking" : "text";
31980
+ if (open2 === null || open2.kind !== kind) {
31981
+ yield* closeOpen();
31982
+ open2 = { kind, index: nextIndex++ };
31983
+ yield { type: "blockStart", index: open2.index, block: { type: kind } };
31984
+ }
31985
+ yield {
31986
+ type: "blockDelta",
31987
+ index: open2.index,
31988
+ delta: kind === "thinking" ? { type: "thinking", text: part.text } : { type: "text", text: part.text }
31989
+ };
31990
+ }
31991
+ const finish = candidate?.finishReason;
31992
+ if (finish === undefined || finish === null)
31993
+ continue;
31994
+ terminal = true;
31995
+ yield* closeOpen();
31996
+ const raw = String(finish);
31997
+ if (raw === "MALFORMED_FUNCTION_CALL") {
31998
+ yield {
31999
+ type: "error",
32000
+ code: "BAD_REQUEST",
32001
+ message: "the model emitted a malformed function call",
32002
+ retryable: false
32003
+ };
32004
+ return;
32005
+ }
32006
+ const mapped = Object.hasOwn(STOP_REASON2, raw) ? STOP_REASON2[raw] : undefined;
32007
+ if (mapped === undefined) {
32008
+ yield {
32009
+ type: "error",
32010
+ code: "UPSTREAM",
32011
+ message: `unrecognized Antigravity finish reason "${raw}"`,
32012
+ retryable: false
32013
+ };
32014
+ return;
32015
+ }
32016
+ yield {
32017
+ type: "end",
32018
+ stopReason: toolCalls > 0 ? "toolUse" : mapped,
32019
+ usage: usageOf(response.usageMetadata)
32020
+ };
32021
+ return;
32022
+ }
32023
+ if (!terminal) {
32024
+ yield* closeOpen();
32025
+ yield {
32026
+ type: "error",
32027
+ code: "UPSTREAM",
32028
+ message: "upstream stream ended before the response finished",
32029
+ retryable: RETRYABLE.UPSTREAM
32030
+ };
32031
+ }
32032
+ }
32033
+
32034
+ // packages/providers/src/antigravity/wire.ts
32035
+ var SIGNATURE_BYPASS = "skip_thought_signature_validator";
32036
+ function toolNamesById(req) {
32037
+ const names = new Map;
32038
+ for (const message of req.messages) {
32039
+ for (const block of message.content) {
32040
+ if (block.type === "toolUse")
32041
+ names.set(block.id, block.name);
32042
+ }
32043
+ }
32044
+ return names;
32045
+ }
32046
+ function mergeSameRole(contents) {
32047
+ const merged = [];
32048
+ for (const entry of contents) {
32049
+ const last = merged[merged.length - 1];
32050
+ if (last !== undefined && last.role === entry.role)
32051
+ last.parts.push(...entry.parts);
32052
+ else
32053
+ merged.push({ role: entry.role, parts: [...entry.parts] });
32054
+ }
32055
+ return merged;
32056
+ }
32057
+ function openingTurn(contents, note) {
32058
+ const first = contents[0];
32059
+ if (first === undefined)
32060
+ return contents;
32061
+ const opensOnTool = first.role === "model" || first.parts[0] !== undefined && "functionResponse" in first.parts[0];
32062
+ if (!opensOnTool)
32063
+ return contents;
32064
+ note("antigravity:opening-turn-added");
32065
+ return [{ role: "user", parts: [{ text: "" }] }, ...contents];
32066
+ }
32067
+ function closingTurn(contents, note) {
32068
+ if (contents[contents.length - 1]?.role !== "model")
32069
+ return contents;
32070
+ note("antigravity:closing-turn-added");
32071
+ return [...contents, { role: "user", parts: [{ text: " " }] }];
32072
+ }
32073
+ var hasCacheControl = (block) => ("cacheControl" in block) && block.cacheControl !== undefined;
32074
+ var PRUNED = "antigravity:tool-schema-pruned";
32075
+ var MAX_STOP_SEQUENCES = 5;
32076
+ var MAX_THINKING_BUDGET = 65535;
32077
+ function scalarValue(kind, value) {
32078
+ const numeric = (v, whole) => {
32079
+ if (typeof v === "number")
32080
+ return Number.isFinite(v) && (!whole || Number.isInteger(v));
32081
+ if (typeof v !== "string")
32082
+ return false;
32083
+ if (whole)
32084
+ return /^-?\d+$/.test(v);
32085
+ return v.trim().length > 0 && Number.isFinite(Number(v));
32086
+ };
32087
+ switch (kind) {
32088
+ case "free":
32089
+ return value;
32090
+ case "text":
32091
+ return typeof value === "string" ? value : undefined;
32092
+ case "texts": {
32093
+ if (typeof value === "string")
32094
+ return value;
32095
+ if (!Array.isArray(value))
32096
+ return;
32097
+ const members2 = value.filter((m) => typeof m === "string");
32098
+ return members2.length === 0 ? undefined : members2;
32099
+ }
32100
+ case "int":
32101
+ return numeric(value, true) ? value : undefined;
32102
+ case "double":
32103
+ return numeric(value, false) ? value : undefined;
32104
+ case "walked":
32105
+ return value;
32106
+ }
32107
+ }
32108
+ var SCHEMA_FIELDS = new Map([
32109
+ ["type", "walked"],
32110
+ ["items", "walked"],
32111
+ ["properties", "walked"],
32112
+ ["anyOf", "walked"],
32113
+ ["allOf", "walked"],
32114
+ ["additionalProperties", "walked"],
32115
+ ["format", "text"],
32116
+ ["title", "text"],
32117
+ ["description", "text"],
32118
+ ["pattern", "text"],
32119
+ ["enum", "texts"],
32120
+ ["required", "texts"],
32121
+ ["propertyOrdering", "texts"],
32122
+ ["minItems", "int"],
32123
+ ["maxItems", "int"],
32124
+ ["minLength", "int"],
32125
+ ["maxLength", "int"],
32126
+ ["minProperties", "int"],
32127
+ ["maxProperties", "int"],
32128
+ ["minimum", "double"],
32129
+ ["maximum", "double"],
32130
+ ["default", "free"],
32131
+ ["example", "free"],
32132
+ ["nullable", "free"]
32133
+ ]);
32134
+ var SCHEMA_TYPES = new Set([
32135
+ "string",
32136
+ "number",
32137
+ "integer",
32138
+ "boolean",
32139
+ "array",
32140
+ "object",
32141
+ "null",
32142
+ "type_unspecified"
32143
+ ]);
32144
+ var MAX_SCHEMA_DEPTH = 24;
32145
+ var isSchema = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
32146
+ function pruneSchema(node2, note, depth = 0) {
32147
+ const out = {};
32148
+ const drop = () => note(PRUNED);
32149
+ const sub = (v) => {
32150
+ if (!isSchema(v) || depth >= MAX_SCHEMA_DEPTH) {
32151
+ drop();
32152
+ return;
32153
+ }
32154
+ return pruneSchema(v, note, depth + 1);
32155
+ };
32156
+ for (const [key, value] of Object.entries(node2)) {
32157
+ if (key === "const") {
32158
+ drop();
32159
+ if (typeof value === "string" && !Object.hasOwn(node2, "enum"))
32160
+ out.enum = [value];
32161
+ continue;
32162
+ }
32163
+ const kind = SCHEMA_FIELDS.get(key);
32164
+ if (kind === undefined) {
32165
+ drop();
32166
+ continue;
32167
+ }
32168
+ switch (key) {
32169
+ case "type": {
32170
+ if (typeof value === "string") {
32171
+ if (SCHEMA_TYPES.has(value.toLowerCase()))
32172
+ out.type = value;
32173
+ else
32174
+ drop();
32175
+ break;
32176
+ }
32177
+ const named = Array.isArray(value) ? value.filter((t) => typeof t === "string" && SCHEMA_TYPES.has(t.toLowerCase())) : [];
32178
+ const real = named.filter((t) => t.toLowerCase() !== "null");
32179
+ if (!Array.isArray(value) || named.length !== value.length || real.length !== 1)
32180
+ drop();
32181
+ if (real[0] !== undefined)
32182
+ out.type = real[0];
32183
+ if (named.length !== real.length)
32184
+ out.nullable = true;
32185
+ break;
32186
+ }
32187
+ case "properties": {
32188
+ if (!isSchema(value)) {
32189
+ drop();
32190
+ break;
32191
+ }
32192
+ const entries = [];
32193
+ for (const [name, member] of Object.entries(value)) {
32194
+ if (name.length === 0) {
32195
+ drop();
32196
+ continue;
32197
+ }
32198
+ const pruned = sub(member);
32199
+ if (pruned !== undefined)
32200
+ entries.push([name, pruned]);
32201
+ }
32202
+ out.properties = Object.fromEntries(entries);
32203
+ break;
32204
+ }
32205
+ case "items": {
32206
+ if (Array.isArray(value)) {
32207
+ drop();
32208
+ const first = sub(value[0]);
32209
+ if (first !== undefined)
32210
+ out.items = first;
32211
+ break;
32212
+ }
32213
+ const pruned = sub(value);
32214
+ if (pruned !== undefined)
32215
+ out.items = pruned;
32216
+ break;
32217
+ }
32218
+ case "anyOf":
32219
+ case "allOf": {
32220
+ if (!Array.isArray(value)) {
32221
+ drop();
32222
+ break;
32223
+ }
32224
+ const arms = [];
32225
+ for (const arm of value) {
32226
+ const pruned = sub(arm);
32227
+ if (pruned !== undefined)
32228
+ arms.push(pruned);
32229
+ }
32230
+ out[key] = arms;
32231
+ break;
32232
+ }
32233
+ case "additionalProperties": {
32234
+ if (typeof value === "boolean") {
32235
+ out[key] = value;
32236
+ break;
32237
+ }
32238
+ const pruned = sub(value);
32239
+ if (pruned !== undefined)
32240
+ out[key] = pruned;
32241
+ break;
32242
+ }
32243
+ default: {
32244
+ const kept = scalarValue(kind, value);
32245
+ if (kept === undefined)
32246
+ drop();
32247
+ else {
32248
+ if (Array.isArray(kept) && Array.isArray(value) && kept.length !== value.length)
32249
+ drop();
32250
+ out[key] = kept;
32251
+ }
32252
+ }
32253
+ }
32254
+ }
32255
+ const declared = typeof out.type === "string" ? out.type.toLowerCase() : undefined;
32256
+ const agree = (want, fields) => {
32257
+ if (!fields.some((f) => out[f] !== undefined))
32258
+ return;
32259
+ if (declared === want)
32260
+ return;
32261
+ if (declared === undefined) {
32262
+ out.type = want;
32263
+ return;
32264
+ }
32265
+ drop();
32266
+ for (const f of fields)
32267
+ delete out[f];
32268
+ };
32269
+ agree("object", ["properties", "required", "propertyOrdering"]);
32270
+ agree("array", ["items"]);
32271
+ for (const key of ["required", "propertyOrdering"]) {
32272
+ const names = out[key];
32273
+ if (!Array.isArray(names))
32274
+ continue;
32275
+ const known = isSchema(out.properties) ? out.properties : {};
32276
+ const kept = names.filter((n) => typeof n === "string" && Object.hasOwn(known, n));
32277
+ if (kept.length === names.length)
32278
+ continue;
32279
+ drop();
32280
+ if (kept.length === 0)
32281
+ delete out[key];
32282
+ else
32283
+ out[key] = kept;
32284
+ }
32285
+ if (out.type === "array" && out.items === undefined) {
32286
+ drop();
32287
+ delete out.type;
32288
+ }
32289
+ return out;
32290
+ }
32291
+ function encodeToolChoice2(choice, cloak) {
32292
+ switch (choice.type) {
32293
+ case "auto":
32294
+ return { functionCallingConfig: { mode: "AUTO" } };
32295
+ case "any":
32296
+ return { functionCallingConfig: { mode: "ANY" } };
32297
+ case "none":
32298
+ return { functionCallingConfig: { mode: "NONE" } };
32299
+ case "tool":
32300
+ return {
32301
+ functionCallingConfig: {
32302
+ mode: "ANY",
32303
+ allowedFunctionNames: [cloakName2(cloak, choice.name)]
32304
+ }
32305
+ };
32306
+ }
32307
+ }
32308
+ function toAntigravityWire(req, model, identity) {
32309
+ const cloak = identity.cloak ?? null;
32310
+ const degradations = [];
32311
+ const note = (d) => {
32312
+ if (!degradations.includes(d))
32313
+ degradations.push(d);
32314
+ };
32315
+ const names = toolNamesById(req);
32316
+ const contents = [];
32317
+ for (const message of req.messages) {
32318
+ const parts = [];
32319
+ if (message.role === "system")
32320
+ note("antigravity:system-turn-as-user");
32321
+ let role = message.role === "assistant" ? "model" : "user";
32322
+ for (const block of message.content) {
32323
+ if (hasCacheControl(block))
32324
+ note("antigravity:cache-control-dropped");
32325
+ switch (block.type) {
32326
+ case "text":
32327
+ parts.push({ text: block.text });
32328
+ break;
32329
+ case "image":
32330
+ parts.push({ inlineData: { mimeType: block.mediaType, data: block.data } });
32331
+ break;
32332
+ case "thinking":
32333
+ note("antigravity:thinking-dropped");
32334
+ break;
32335
+ case "toolUse":
32336
+ parts.push({
32337
+ thoughtSignature: SIGNATURE_BYPASS,
32338
+ functionCall: { name: cloakName2(cloak, block.name), args: block.input }
32339
+ });
32340
+ break;
32341
+ case "toolResult": {
32342
+ const name = names.get(block.toolUseId);
32343
+ if (name === undefined)
32344
+ note("antigravity:tool-result-unmatched");
32345
+ if (block.isError === true)
32346
+ note("antigravity:tool-result-error-flag-dropped");
32347
+ parts.push({
32348
+ functionResponse: {
32349
+ name: cloakName2(cloak, name ?? block.toolUseId),
32350
+ response: { output: block.content }
32351
+ }
32352
+ });
32353
+ role = "user";
32354
+ break;
32355
+ }
32356
+ case "providerNative":
32357
+ note("antigravity:provider-native-block-dropped");
32358
+ break;
32359
+ }
32360
+ }
32361
+ if (parts.length > 0)
32362
+ contents.push({ role, parts });
32363
+ }
32364
+ const request2 = {
32365
+ contents: closingTurn(openingTurn(mergeSameRole(contents), note), note)
32366
+ };
32367
+ const system = systemText(req.system, "antigravity", note);
32368
+ if (system !== undefined && system.length > 0) {
32369
+ request2.systemInstruction = { parts: [{ text: system }] };
32370
+ }
32371
+ const generationConfig = {};
32372
+ if (req.maxTokens !== undefined) {
32373
+ if (req.maxTokens > 0)
32374
+ generationConfig.maxOutputTokens = req.maxTokens;
32375
+ else
32376
+ note("antigravity:max-tokens-dropped");
32377
+ }
32378
+ if (req.temperature !== undefined) {
32379
+ const clamped = Math.min(Math.max(req.temperature, 0), 2);
32380
+ if (clamped !== req.temperature)
32381
+ note("antigravity:temperature-clamped");
32382
+ generationConfig.temperature = clamped;
32383
+ }
32384
+ if (req.stopSequences !== undefined) {
32385
+ generationConfig.stopSequences = req.stopSequences.slice(0, MAX_STOP_SEQUENCES);
32386
+ if (req.stopSequences.length > MAX_STOP_SEQUENCES)
32387
+ note("antigravity:stop-sequences-dropped");
32388
+ }
32389
+ if (req.reasoning !== undefined) {
32390
+ switch (req.reasoning.mode) {
32391
+ case "off":
32392
+ generationConfig.thinkingConfig = { thinkingBudget: 0, includeThoughts: false };
32393
+ break;
32394
+ case "budget":
32395
+ {
32396
+ const asked = req.reasoning.budgetTokens;
32397
+ const budget2 = Math.min(Math.max(asked, -1), MAX_THINKING_BUDGET);
32398
+ if (budget2 !== asked)
32399
+ note("antigravity:thinking-budget-clamped");
32400
+ generationConfig.thinkingConfig = {
32401
+ thinkingBudget: budget2,
32402
+ includeThoughts: budget2 !== 0
32403
+ };
32404
+ }
32405
+ break;
32406
+ case "adaptive":
32407
+ generationConfig.thinkingConfig = {
32408
+ includeThoughts: req.reasoning.display !== "omitted"
32409
+ };
32410
+ if (req.reasoning.effort !== undefined)
32411
+ note("antigravity:reasoning-effort-dropped");
32412
+ break;
32413
+ }
32414
+ }
32415
+ const max = generationConfig.maxOutputTokens;
32416
+ if (max !== undefined && max > MAX_OUTPUT_TOKENS) {
32417
+ generationConfig.maxOutputTokens = MAX_OUTPUT_TOKENS;
32418
+ note("antigravity:max-tokens-clamped");
32419
+ }
32420
+ const budget = generationConfig.thinkingConfig?.thinkingBudget;
32421
+ if (budget !== undefined && budget > 0) {
32422
+ const ceiling = generationConfig.maxOutputTokens;
32423
+ if (ceiling === undefined || ceiling <= budget) {
32424
+ generationConfig.maxOutputTokens = Math.min(budget + 1, MAX_OUTPUT_TOKENS);
32425
+ }
32426
+ }
32427
+ if (Object.keys(generationConfig).length > 0)
32428
+ request2.generationConfig = generationConfig;
32429
+ if (req.tools !== undefined) {
32430
+ const portable = req.tools.filter((t) => t.kind === "portable");
32431
+ if (portable.length !== req.tools.length)
32432
+ note("antigravity:provider-tool-dropped");
32433
+ const seen = new Set;
32434
+ const named = [];
32435
+ for (const tool of portable) {
32436
+ const name = cloakName2(cloak, tool.name);
32437
+ if (seen.has(name)) {
32438
+ note("antigravity:duplicate-tool-dropped");
32439
+ continue;
32440
+ }
32441
+ seen.add(name);
32442
+ named.push({ name, description: tool.description, inputSchema: tool.inputSchema });
32443
+ }
32444
+ if (cloak !== null && cloak.toWire.size > 0)
32445
+ note("antigravity:tool-name-renamed");
32446
+ if (named.length > 0) {
32447
+ request2.tools = [
32448
+ {
32449
+ functionDeclarations: named.map((t) => ({
32450
+ name: t.name,
32451
+ description: t.description,
32452
+ parameters: pruneSchema(t.inputSchema, note)
32453
+ }))
32454
+ }
32455
+ ];
32456
+ }
32457
+ }
32458
+ if (req.toolChoice !== undefined)
32459
+ request2.toolConfig = encodeToolChoice2(req.toolChoice, cloak);
32460
+ Object.assign(request2, req.vendor?.antigravity ?? {});
32461
+ return {
32462
+ body: {
32463
+ project: identity.project,
32464
+ requestId: identity.requestId,
32465
+ model,
32466
+ userAgent: "antigravity",
32467
+ requestType: "agent",
32468
+ request: request2
32469
+ },
32470
+ degradations
32471
+ };
32472
+ }
32473
+
32474
+ // packages/providers/src/antigravity/codec.ts
32475
+ var URL2 = "https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse";
32476
+ var REQUEST_NAMESPACE = "omni-antigravity-req";
32477
+ function derivedRequestId(seed) {
32478
+ const h = createHash2("sha256").update(`${REQUEST_NAMESPACE}:${seed}`).digest("hex");
32479
+ const variant = (Number.parseInt(h[16], 16) & 3 | 8).toString(16);
32480
+ return [
32481
+ h.slice(0, 8),
32482
+ h.slice(8, 12),
32483
+ `4${h.slice(13, 16)}`,
32484
+ `${variant}${h.slice(17, 20)}`,
32485
+ h.slice(20, 32)
32486
+ ].join("-");
32487
+ }
32488
+ function projectOf(input2) {
32489
+ const stored = input2.credentials.providerData.projectId;
32490
+ const project = typeof stored === "string" ? stored.trim() : "";
32491
+ if (project.length === 0) {
32492
+ throw input2.fail("AUTH", "antigravity credential has no Cloud Code project; reconnect the account");
32493
+ }
32494
+ return project;
32495
+ }
32496
+ function cloakOf2(state) {
32497
+ if (state === null || typeof state !== "object")
32498
+ return null;
32499
+ const cloak = state.cloak;
32500
+ if (cloak === null || cloak === undefined || typeof cloak !== "object")
32501
+ return null;
32502
+ const { toWire: toWire2, fromWire } = cloak;
32503
+ return toWire2 instanceof Map && fromWire instanceof Map ? cloak : null;
32504
+ }
32505
+ var antigravityCodec = {
32506
+ buildRequest(input2) {
32507
+ const accessToken = input2.credentials.accessToken;
32508
+ if (accessToken === null || accessToken.length === 0) {
32509
+ throw input2.fail("AUTH", "antigravity credential has no access token");
32510
+ }
32511
+ const project = projectOf(input2);
32512
+ const requestId = input2.requestId !== undefined && input2.requestId.length > 0 ? input2.requestId : derivedRequestId(`${input2.model}:${project}`);
32513
+ const cloak = buildToolCloak2(input2.request);
32514
+ const { body, degradations } = toAntigravityWire(input2.request, input2.model, {
32515
+ project,
32516
+ requestId,
32517
+ cloak
32518
+ });
32519
+ const protocol = [["Authorization", `Bearer ${accessToken}`]];
32520
+ const headers = orderHeaders(mergeHeaders(antigravityProfile.headers, protocol), antigravityProfile.order);
32521
+ return {
32522
+ request: {
32523
+ url: URL2,
32524
+ method: "POST",
32525
+ headers,
32526
+ body: JSON.stringify(body)
32527
+ },
32528
+ decodeState: { cloak },
32529
+ degradations,
32530
+ ...cloak === null ? {} : { cloakedTools: cloak.toWire.size }
32531
+ };
32532
+ },
32533
+ decode({ body, decodeState }) {
32534
+ return decodeAntigravityStream(parseSse(body), { cloak: cloakOf2(decodeState) });
32535
+ }
32536
+ };
32537
+
32538
+ // packages/providers/src/antigravity/index.ts
32539
+ var antigravityAdapter = codecAdapter("antigravity", antigravityDescriptor.capabilities, antigravityCodec);
32540
+ // packages/providers/src/antigravity/oauth.ts
32541
+ var MASK = "omnigateway-public-v1";
32542
+ function unmask(bytes) {
32543
+ let out = "";
32544
+ for (let i = 0;i < bytes.length; i++) {
32545
+ out += String.fromCharCode(bytes[i] ^ MASK.charCodeAt(i % MASK.length));
32546
+ }
32547
+ return out;
32548
+ }
32549
+ var ANTIGRAVITY_CLIENT_ID = unmask([
32550
+ 94,
32551
+ 93,
32552
+ 89,
32553
+ 88,
32554
+ 87,
32555
+ 81,
32556
+ 66,
32557
+ 85,
32558
+ 65,
32559
+ 81,
32560
+ 76,
32561
+ 20,
32562
+ 65,
32563
+ 88,
32564
+ 22,
32565
+ 1,
32566
+ 1,
32567
+ 16,
32568
+ 94,
32569
+ 31,
32570
+ 95,
32571
+ 93,
32572
+ 5,
32573
+ 92,
32574
+ 88,
32575
+ 11,
32576
+ 2,
32577
+ 6,
32578
+ 0,
32579
+ 69,
32580
+ 82,
32581
+ 76,
32582
+ 91,
32583
+ 4,
32584
+ 26,
32585
+ 14,
32586
+ 3,
32587
+ 3,
32588
+ 11,
32589
+ 25,
32590
+ 17,
32591
+ 5,
32592
+ 95,
32593
+ 94,
32594
+ 11,
32595
+ 25,
32596
+ 73,
32597
+ 0,
32598
+ 4,
32599
+ 21,
32600
+ 4,
32601
+ 79,
32602
+ 30,
32603
+ 66,
32604
+ 31,
32605
+ 18,
32606
+ 14,
32607
+ 9,
32608
+ 28,
32609
+ 16,
32610
+ 72,
32611
+ 4,
32612
+ 82,
32613
+ 0,
32614
+ 3,
32615
+ 26,
32616
+ 12,
32617
+ 9,
32618
+ 21,
32619
+ 90,
32620
+ 6,
32621
+ 24,
32622
+ 12
32623
+ ]);
32624
+ var CLIENT_ID2 = ANTIGRAVITY_CLIENT_ID;
32625
+ var CLIENT_SECRET = unmask([
32626
+ 40,
32627
+ 34,
32628
+ 45,
32629
+ 58,
32630
+ 55,
32631
+ 57,
32632
+ 89,
32633
+ 46,
32634
+ 66,
32635
+ 89,
32636
+ 63,
32637
+ 122,
32638
+ 34,
32639
+ 65,
32640
+ 90,
32641
+ 90,
32642
+ 37,
32643
+ 7,
32644
+ 97,
32645
+ 60,
32646
+ 0,
32647
+ 2,
32648
+ 33,
32649
+ 44,
32650
+ 81,
32651
+ 20,
32652
+ 57,
32653
+ 55,
32654
+ 81,
32655
+ 13,
32656
+ 87,
32657
+ 8,
32658
+ 105,
32659
+ 49,
32660
+ 19
32661
+ ]);
32662
+ var AUTHORIZE_URL2 = "https://accounts.google.com/o/oauth2/v2/auth";
32663
+ var TOKEN_URL2 = "https://oauth2.googleapis.com/token";
32664
+ var USERINFO_URL = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
32665
+ var CODE_ASSIST = "https://cloudcode-pa.googleapis.com/v1internal";
32666
+ var LOAD_CODE_ASSIST_URL = `${CODE_ASSIST}:loadCodeAssist`;
32667
+ var ONBOARD_USER_URL = `${CODE_ASSIST}:onboardUser`;
32668
+ var QUOTA_SUMMARY_URL = `${CODE_ASSIST}:retrieveUserQuotaSummary`;
32669
+ var SCOPES2 = [
32670
+ "https://www.googleapis.com/auth/cloud-platform",
32671
+ "https://www.googleapis.com/auth/userinfo.email",
32672
+ "https://www.googleapis.com/auth/userinfo.profile",
32673
+ "https://www.googleapis.com/auth/cclog",
32674
+ "https://www.googleapis.com/auth/experimentsandconfigs"
32675
+ ].join(" ");
32676
+ var IDE_METADATA = { ideType: "ANTIGRAVITY" };
32677
+ var DEFAULT_TIER = "legacy-tier";
32678
+ function parseTokenResponse(value) {
32679
+ const record2 = recordOf(value);
32680
+ if (record2 === null || typeof record2.access_token !== "string")
32681
+ return null;
32682
+ return {
32683
+ accessToken: record2.access_token,
32684
+ refreshToken: typeof record2.refresh_token === "string" ? record2.refresh_token : null,
32685
+ expiresIn: typeof record2.expires_in === "number" ? record2.expires_in : null
32686
+ };
32687
+ }
32688
+ async function* postToken2(body, fail) {
32689
+ const res = yield postJsonRequest(TOKEN_URL2, antigravityProfile, {
32690
+ contentType: "application/x-www-form-urlencoded",
32691
+ body: new URLSearchParams(body).toString()
32692
+ });
32693
+ const parsed2 = parsed(res.body);
32694
+ if (res.status < 200 || res.status >= 300) {
32695
+ throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
32696
+ }
32697
+ const token = parseTokenResponse(parsed2);
32698
+ if (token === null)
32699
+ throw fail("AUTH", "token endpoint returned no access_token");
32700
+ return token;
32701
+ }
32702
+ function projectFrom(value) {
32703
+ const record2 = recordOf(value);
32704
+ if (record2 === null)
32705
+ return "";
32706
+ const project = record2.cloudaicompanionProject;
32707
+ if (typeof project === "string")
32708
+ return project.trim();
32709
+ const nested = recordOf(project);
32710
+ const id = nested?.id;
32711
+ return typeof id === "string" ? id.trim() : "";
32712
+ }
32713
+ function tierFrom(value) {
32714
+ const record2 = recordOf(value);
32715
+ const tiers = record2?.allowedTiers;
32716
+ if (Array.isArray(tiers)) {
32717
+ for (const entry of tiers) {
32718
+ const tier = recordOf(entry);
32719
+ if (tier?.isDefault === true && typeof tier.id === "string")
32720
+ return tier.id;
32721
+ }
32722
+ }
32723
+ const current = recordOf(record2?.currentTier);
32724
+ return typeof current?.id === "string" ? current.id : DEFAULT_TIER;
32725
+ }
32726
+ function codeAssistRequest(url2, accessToken, body) {
32727
+ return postJsonRequest(url2, antigravityProfile, {
32728
+ contentType: "application/json",
32729
+ body: JSON.stringify(body),
32730
+ extraHeaders: [["Authorization", `Bearer ${accessToken}`]]
32731
+ });
32732
+ }
32733
+ async function* bootstrapProject(accessToken) {
32734
+ const loaded = yield codeAssistRequest(LOAD_CODE_ASSIST_URL, accessToken, {
32735
+ metadata: IDE_METADATA
32736
+ });
32737
+ const body = loaded.status >= 200 && loaded.status < 300 ? parsed(loaded.body) : null;
32738
+ const tier = tierFrom(body);
32739
+ const existing = projectFrom(body);
32740
+ if (existing.length > 0)
32741
+ return { projectId: existing, tier };
32742
+ const onboarded = yield codeAssistRequest(ONBOARD_USER_URL, accessToken, {
32743
+ tier_id: tier,
32744
+ metadata: IDE_METADATA
32745
+ });
32746
+ if (onboarded.status < 200 || onboarded.status >= 300)
32747
+ return { projectId: "", tier };
32748
+ const operation = recordOf(parsed(onboarded.body));
32749
+ return { projectId: projectFrom(operation?.response), tier };
32750
+ }
32751
+ async function* readEmail(accessToken) {
32752
+ const res = yield getJsonRequest(USERINFO_URL, antigravityProfile, { accessToken });
32753
+ if (res.status < 200 || res.status >= 300)
32754
+ return null;
32755
+ const record2 = recordOf(parsed(res.body));
32756
+ const email3 = record2?.email;
32757
+ return typeof email3 === "string" && email3.trim().length > 0 ? email3 : null;
32758
+ }
32759
+ function toResult2(token, fallbackRefresh, accountEmail, providerData, now) {
32760
+ return {
32761
+ secrets: {
32762
+ accessToken: token.accessToken,
32763
+ refreshToken: token.refreshToken ?? fallbackRefresh,
32764
+ apiKey: null,
32765
+ idToken: null
32766
+ },
32767
+ expiresAt: token.expiresIn === null ? null : now() + token.expiresIn * 1000,
32768
+ accountEmail,
32769
+ providerData
32770
+ };
32771
+ }
32772
+ var GEMINI_GROUP = /\bgemini\b/;
32773
+ function windowOf(bucket) {
32774
+ const text = `${String(bucket.bucketId ?? "")} ${String(bucket.displayName ?? "")}`.toLowerCase();
32775
+ if (/\bweekly\b|\bweek\b/.test(text))
32776
+ return "weekly";
32777
+ if (/\b5\s*-?\s*hour|\b5h\b|\bfive\s*hour/.test(text))
32778
+ return "fiveHour";
32779
+ return null;
32780
+ }
32781
+ function groupsOf(value) {
32782
+ const root = recordOf(value);
32783
+ if (root === null)
32784
+ return [];
32785
+ if (Array.isArray(root.groups))
32786
+ return root.groups;
32787
+ const nested = recordOf(root.quotaSummary)?.groups;
32788
+ return Array.isArray(nested) ? nested : [];
32789
+ }
32790
+ function parseAntigravityQuota(value, now) {
32791
+ const windows = [];
32792
+ for (const groupValue of groupsOf(value)) {
32793
+ const group = recordOf(groupValue);
32794
+ if (group === null)
32795
+ continue;
32796
+ if (!GEMINI_GROUP.test(String(group.displayName ?? "").toLowerCase()))
32797
+ continue;
32798
+ const buckets = Array.isArray(group.buckets) ? group.buckets : [];
32799
+ for (const bucketValue of buckets) {
32800
+ const bucket = recordOf(bucketValue);
32801
+ if (bucket === null || bucket.disabled === true)
32802
+ continue;
32803
+ const windowType = windowOf(bucket);
32804
+ if (windowType === null)
32805
+ continue;
32806
+ const fraction = numberOf(bucket, ["remainingFraction"]);
32807
+ if (fraction === null)
32808
+ continue;
32809
+ const remaining = Math.max(0, Math.min(1, fraction));
32810
+ windows.push({
32811
+ windowType,
32812
+ used: Math.round((1 - remaining) * 100),
32813
+ limit: 100,
32814
+ resetsAt: resetAtOf(bucket, { absolute: ["resetTime"] }, now),
32815
+ windowMs: null
32816
+ });
32817
+ }
32818
+ }
32819
+ return reportFrom(windows);
32820
+ }
32821
+ var antigravityOAuthFlow = {
32822
+ kind: "pkce",
32823
+ supportsManualPaste: true,
32824
+ async* start({ redirectUri, randomState }) {
32825
+ const state = randomState();
32826
+ const url2 = new URL(AUTHORIZE_URL2);
32827
+ url2.searchParams.set("client_id", CLIENT_ID2);
32828
+ url2.searchParams.set("response_type", "code");
32829
+ url2.searchParams.set("redirect_uri", redirectUri);
32830
+ url2.searchParams.set("scope", SCOPES2);
32831
+ url2.searchParams.set("state", state);
32832
+ url2.searchParams.set("access_type", "offline");
32833
+ url2.searchParams.set("prompt", "consent");
32834
+ return {
32835
+ authorizeUrl: url2.toString(),
32836
+ pending: { verifier: "", challenge: "", state, redirectUri }
32837
+ };
32838
+ },
32839
+ async* exchange({ code, pending, fail, now }) {
32840
+ const [rawCode, pastedState] = code.split("#");
32841
+ if (pastedState !== undefined && pastedState !== pending.state) {
32842
+ throw fail("AUTH", "authorization state mismatch");
32843
+ }
32844
+ const token = yield* postToken2({
32845
+ grant_type: "authorization_code",
32846
+ client_id: CLIENT_ID2,
32847
+ client_secret: CLIENT_SECRET,
32848
+ code: (rawCode ?? "").trim(),
32849
+ redirect_uri: pending.redirectUri
32850
+ }, fail);
32851
+ const email3 = yield* readEmail(token.accessToken);
32852
+ const { projectId, tier } = yield* bootstrapProject(token.accessToken);
32853
+ return toResult2(token, null, email3, { projectId, tier }, now);
32854
+ },
32855
+ async* refresh({ refreshToken, providerData, fail, now }) {
32856
+ const token = yield* postToken2({
32857
+ grant_type: "refresh_token",
32858
+ client_id: CLIENT_ID2,
32859
+ client_secret: CLIENT_SECRET,
32860
+ refresh_token: refreshToken
32861
+ }, fail);
32862
+ return toResult2(token, refreshToken, null, providerData, now);
32863
+ },
32864
+ async* usage({ secrets, providerData, now }) {
32865
+ const project = typeof providerData.projectId === "string" ? providerData.projectId : "";
32866
+ if (project.trim().length === 0)
32867
+ return null;
32868
+ const res = yield {
32869
+ ...postJsonRequest(QUOTA_SUMMARY_URL, antigravityProfile, {
32870
+ contentType: "application/json",
32871
+ body: JSON.stringify({ project }),
32872
+ extraHeaders: [["Authorization", `Bearer ${secrets.accessToken}`]]
32873
+ }),
32874
+ timeoutMs: SHORT_TIMEOUT_MS
32875
+ };
32876
+ if (!usageReadable(res.status, "antigravity"))
32877
+ return null;
32878
+ return parseAntigravityQuota(parsed(res.body), now());
32879
+ }
32880
+ };
31496
32881
  // packages/providers/src/grok/device.ts
31497
32882
  import { randomUUID } from "crypto";
31498
32883
  function mintGrokDevice() {
@@ -31506,10 +32891,10 @@ function grokDeviceHeaders(providerData) {
31506
32891
  }
31507
32892
 
31508
32893
  // packages/providers/src/grok/oauth.ts
31509
- var CLIENT_ID2 = "b1a00492-073a-47ea-816f-4c329264a828";
32894
+ var CLIENT_ID3 = "b1a00492-073a-47ea-816f-4c329264a828";
31510
32895
  var ISSUER = "https://auth.x.ai";
31511
32896
  var DISCOVERY_URL = `${ISSUER}/.well-known/openid-configuration`;
31512
- var SCOPES2 = [
32897
+ var SCOPES3 = [
31513
32898
  "openid",
31514
32899
  "profile",
31515
32900
  "email",
@@ -31555,7 +32940,7 @@ async function* discover(fail) {
31555
32940
  tokenUrl: trustedEndpoint(parsed2.token_endpoint, "token_endpoint", fail)
31556
32941
  };
31557
32942
  }
31558
- function parseTokenResponse(value) {
32943
+ function parseTokenResponse2(value) {
31559
32944
  if (!isRecord2(value) || typeof value.access_token !== "string")
31560
32945
  return null;
31561
32946
  return {
@@ -31571,15 +32956,15 @@ function emailFromIdToken(idToken) {
31571
32956
  if (parts.length !== 3 || payload === undefined || payload.length === 0)
31572
32957
  return null;
31573
32958
  try {
31574
- const json3 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
31575
- if (!isRecord2(json3))
32959
+ const json4 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
32960
+ if (!isRecord2(json4))
31576
32961
  return null;
31577
- return typeof json3.email === "string" && json3.email.trim().length > 0 ? json3.email : null;
32962
+ return typeof json4.email === "string" && json4.email.trim().length > 0 ? json4.email : null;
31578
32963
  } catch {
31579
32964
  return null;
31580
32965
  }
31581
32966
  }
31582
- async function* postToken2(tokenUrl, body, fail) {
32967
+ async function* postToken3(tokenUrl, body, fail) {
31583
32968
  const res = yield postJsonRequest(tokenUrl, grokProfile, {
31584
32969
  contentType: "application/x-www-form-urlencoded",
31585
32970
  body: new URLSearchParams(body).toString()
@@ -31588,7 +32973,7 @@ async function* postToken2(tokenUrl, body, fail) {
31588
32973
  if (res.status < 200 || res.status >= 300) {
31589
32974
  throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
31590
32975
  }
31591
- const token = parseTokenResponse(parsed2);
32976
+ const token = parseTokenResponse2(parsed2);
31592
32977
  if (token === null) {
31593
32978
  throw fail("AUTH", "token endpoint returned no access_token");
31594
32979
  }
@@ -31598,7 +32983,7 @@ function agentIdFrom(providerData) {
31598
32983
  const stored = providerData.agentId;
31599
32984
  return typeof stored === "string" && stored.trim().length > 0 ? stored : mintGrokDevice().agentId;
31600
32985
  }
31601
- function toResult2(token, fallbackRefresh, agentId, now) {
32986
+ function toResult3(token, fallbackRefresh, agentId, now) {
31602
32987
  return {
31603
32988
  secrets: {
31604
32989
  accessToken: token.accessToken,
@@ -31620,9 +33005,9 @@ var grokOAuthFlow = {
31620
33005
  const state = randomState();
31621
33006
  const url2 = new URL(authorizeUrl);
31622
33007
  url2.searchParams.set("response_type", "code");
31623
- url2.searchParams.set("client_id", CLIENT_ID2);
33008
+ url2.searchParams.set("client_id", CLIENT_ID3);
31624
33009
  url2.searchParams.set("redirect_uri", redirectUri);
31625
- url2.searchParams.set("scope", SCOPES2);
33010
+ url2.searchParams.set("scope", SCOPES3);
31626
33011
  url2.searchParams.set("code_challenge", challenge);
31627
33012
  url2.searchParams.set("code_challenge_method", "S256");
31628
33013
  url2.searchParams.set("state", state);
@@ -31636,19 +33021,19 @@ var grokOAuthFlow = {
31636
33021
  throw fail("AUTH", "authorization state mismatch");
31637
33022
  }
31638
33023
  const { tokenUrl } = yield* discover(fail);
31639
- const token = yield* postToken2(tokenUrl, {
33024
+ const token = yield* postToken3(tokenUrl, {
31640
33025
  grant_type: "authorization_code",
31641
33026
  code: (rawCode ?? "").trim(),
31642
33027
  redirect_uri: pending.redirectUri,
31643
- client_id: CLIENT_ID2,
33028
+ client_id: CLIENT_ID3,
31644
33029
  code_verifier: pending.verifier
31645
33030
  }, fail);
31646
- return toResult2(token, null, mintGrokDevice().agentId, now);
33031
+ return toResult3(token, null, mintGrokDevice().agentId, now);
31647
33032
  },
31648
33033
  async* refresh({ refreshToken, providerData, fail, now }) {
31649
33034
  const { tokenUrl } = yield* discover(fail);
31650
- const token = yield* postToken2(tokenUrl, { grant_type: "refresh_token", client_id: CLIENT_ID2, refresh_token: refreshToken }, fail);
31651
- return toResult2(token, refreshToken, agentIdFrom(providerData), now);
33035
+ const token = yield* postToken3(tokenUrl, { grant_type: "refresh_token", client_id: CLIENT_ID3, refresh_token: refreshToken }, fail);
33036
+ return toResult3(token, refreshToken, agentIdFrom(providerData), now);
31652
33037
  }
31653
33038
  };
31654
33039
 
@@ -31808,9 +33193,9 @@ function kimiDeviceHeaders(providerData) {
31808
33193
  }
31809
33194
 
31810
33195
  // packages/providers/src/kimi/oauth.ts
31811
- var CLIENT_ID3 = "17e5f671-d194-4dfb-9706-5516cb48c098";
33196
+ var CLIENT_ID4 = "17e5f671-d194-4dfb-9706-5516cb48c098";
31812
33197
  var DEVICE_CODE_URL = "https://auth.kimi.com/api/oauth/device_authorization";
31813
- var TOKEN_URL2 = "https://auth.kimi.com/api/oauth/token";
33198
+ var TOKEN_URL3 = "https://auth.kimi.com/api/oauth/token";
31814
33199
  var USAGE_URL2 = "https://api.kimi.com/coding/v1/usages";
31815
33200
  var DEFAULT_INTERVAL_SECONDS = 5;
31816
33201
  var PENDING_ERRORS = new Set(["authorization_pending", "slow_down"]);
@@ -31864,7 +33249,7 @@ function deviceCodeFrom2(value, fail) {
31864
33249
  async function* post(url2, body, device, fail, keepPolling) {
31865
33250
  const res = yield postJsonRequest(url2, kimiProfile, {
31866
33251
  contentType: "application/x-www-form-urlencoded",
31867
- body: new URLSearchParams({ ...body, client_id: CLIENT_ID3 }).toString(),
33252
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID4 }).toString(),
31868
33253
  extraHeaders: kimiDeviceHeaders(device)
31869
33254
  });
31870
33255
  const parsed2 = parsed(res.body);
@@ -31895,7 +33280,7 @@ function deviceFrom(source) {
31895
33280
  function deviceForBegin(deviceId) {
31896
33281
  return { ...mintKimiDevice(), deviceId };
31897
33282
  }
31898
- function toResult3(token, device, fallbackRefresh, now) {
33283
+ function toResult4(token, device, fallbackRefresh, now) {
31899
33284
  return {
31900
33285
  secrets: {
31901
33286
  accessToken: token.accessToken,
@@ -31950,17 +33335,17 @@ var kimiOAuthFlow = {
31950
33335
  throw fail("INTERNAL", "kimi exchange requires a pending flow produced by begin()");
31951
33336
  }
31952
33337
  const device = deviceFrom(pending.extra);
31953
- const token = tokenFrom(yield* post(TOKEN_URL2, {
33338
+ const token = tokenFrom(yield* post(TOKEN_URL3, {
31954
33339
  grant_type: "urn:ietf:params:oauth:grant-type:device_code",
31955
33340
  device_code: pending.deviceCode,
31956
33341
  device_id: device.deviceId
31957
33342
  }, device, fail, keepPolling), fail);
31958
- return toResult3(token, device, null, now);
33343
+ return toResult4(token, device, null, now);
31959
33344
  },
31960
33345
  async* refresh({ refreshToken, providerData, fail, keepPolling, now }) {
31961
33346
  const device = deviceFrom(providerData);
31962
- const token = tokenFrom(yield* post(TOKEN_URL2, { grant_type: "refresh_token", refresh_token: refreshToken, device_id: device.deviceId }, device, fail, keepPolling), fail);
31963
- return toResult3(token, device, refreshToken, now);
33347
+ const token = tokenFrom(yield* post(TOKEN_URL3, { grant_type: "refresh_token", refresh_token: refreshToken, device_id: device.deviceId }, device, fail, keepPolling), fail);
33348
+ return toResult4(token, device, refreshToken, now);
31964
33349
  },
31965
33350
  async* usage({ secrets, providerData, now }) {
31966
33351
  if (secrets.accessToken === null)
@@ -31976,13 +33361,225 @@ var kimiOAuthFlow = {
31976
33361
  }
31977
33362
  };
31978
33363
 
33364
+ // packages/providers/src/muse/endpoint.ts
33365
+ var TRUSTED_HOST2 = "meta.ai";
33366
+ var MUSE_DEFAULT_BASE_URL = "https://api.meta.ai/v1";
33367
+ function trustedBaseUrl(value) {
33368
+ if (typeof value !== "string" || value.length === 0)
33369
+ return null;
33370
+ let url2;
33371
+ try {
33372
+ url2 = new URL(value);
33373
+ } catch {
33374
+ return null;
33375
+ }
33376
+ if (url2.protocol !== "https:")
33377
+ return null;
33378
+ const host2 = url2.hostname;
33379
+ if (host2 !== TRUSTED_HOST2 && !host2.endsWith(`.${TRUSTED_HOST2}`))
33380
+ return null;
33381
+ return `${url2.origin}${url2.pathname}`.replace(/\/$/, "");
33382
+ }
33383
+ function museResponsesUrl(providerData) {
33384
+ return `${trustedBaseUrl(providerData.baseUrl) ?? MUSE_DEFAULT_BASE_URL}/responses`;
33385
+ }
33386
+
33387
+ // packages/providers/src/muse/oauth.ts
33388
+ var AUTH_BASE = "https://auth.meta.com";
33389
+ var DEVICE_CODE_URL2 = `${AUTH_BASE}/oidc/device/authorization/`;
33390
+ var TOKEN_URL4 = `${AUTH_BASE}/oidc/device/token/`;
33391
+ var MINT_URL = "https://api.meta.ai/muse-code/key";
33392
+ var CLIENT_ID5 = "1031625952748946";
33393
+ var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
33394
+ var FALLBACK_VERIFICATION_URL2 = "https://auth.meta.com/oauth/device/";
33395
+ var DEFAULT_INTERVAL_SECONDS2 = 5;
33396
+ var PENDING_ERRORS2 = new Set(["authorization_pending", "slow_down"]);
33397
+ function isRecord5(value) {
33398
+ return typeof value === "object" && value !== null;
33399
+ }
33400
+ function recordFrom3(value) {
33401
+ return isRecord5(value) ? value : null;
33402
+ }
33403
+ function stringFrom3(value, field) {
33404
+ const candidate = value[field];
33405
+ return typeof candidate === "string" && candidate.trim().length > 0 ? candidate : null;
33406
+ }
33407
+ function positiveNumberFrom3(value, field) {
33408
+ const candidate = value[field];
33409
+ return typeof candidate === "number" && Number.isFinite(candidate) && candidate > 0 ? candidate : null;
33410
+ }
33411
+ function tokenFrom2(value, fail) {
33412
+ const record2 = recordFrom3(value);
33413
+ const accessToken = record2 === null ? null : stringFrom3(record2, "access_token");
33414
+ if (record2 === null || accessToken === null) {
33415
+ throw fail("AUTH", "token endpoint returned no access_token");
33416
+ }
33417
+ return {
33418
+ accessToken,
33419
+ refreshToken: stringFrom3(record2, "refresh_token"),
33420
+ expiresIn: positiveNumberFrom3(record2, "expires_in")
33421
+ };
33422
+ }
33423
+ function deviceCodeFrom3(value, fail) {
33424
+ const record2 = recordFrom3(value);
33425
+ const deviceCode = record2 === null ? null : stringFrom3(record2, "device_code");
33426
+ const userCode = record2 === null ? null : stringFrom3(record2, "user_code");
33427
+ if (record2 === null || deviceCode === null || userCode === null) {
33428
+ throw fail("AUTH", "device authorization response missing user_code or verification_uri");
33429
+ }
33430
+ return {
33431
+ deviceCode,
33432
+ userCode,
33433
+ verificationUri: stringFrom3(record2, "verification_uri_complete") ?? stringFrom3(record2, "verification_uri") ?? FALLBACK_VERIFICATION_URL2,
33434
+ interval: positiveNumberFrom3(record2, "interval") ?? DEFAULT_INTERVAL_SECONDS2
33435
+ };
33436
+ }
33437
+ async function* postForm(url2, body, fail, keepPolling) {
33438
+ const res = yield postJsonRequest(url2, museProfile, {
33439
+ contentType: "application/x-www-form-urlencoded",
33440
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID5 }).toString(),
33441
+ extraHeaders: [["Accept", "application/json"]]
33442
+ });
33443
+ const parsed2 = parsed(res.body);
33444
+ if (res.status >= 200 && res.status < 300)
33445
+ return parsed2;
33446
+ const record2 = recordFrom3(parsed2);
33447
+ const code = record2 === null ? `http_${res.status}` : stringFrom3(record2, "error") ?? `http_${res.status}`;
33448
+ if (PENDING_ERRORS2.has(code))
33449
+ throw keepPolling(code);
33450
+ if (code === "expired_token") {
33451
+ throw fail("AUTH", "muse device code expired; start the authorization again");
33452
+ }
33453
+ throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
33454
+ }
33455
+ async function* mint(accessToken, fail) {
33456
+ const res = yield postJsonRequest(MINT_URL, museProfile, {
33457
+ contentType: "application/json",
33458
+ body: "{}",
33459
+ extraHeaders: [
33460
+ ["Authorization", `Bearer ${accessToken}`],
33461
+ ["Accept", "application/json"]
33462
+ ]
33463
+ });
33464
+ const parsed2 = parsed(res.body);
33465
+ if (res.status < 200 || res.status >= 300) {
33466
+ if (res.status === 401 || res.status === 403) {
33467
+ throw fail("AUTH", "muse rejected the saved login; reconnect the account or use a different one");
33468
+ }
33469
+ if (res.status === 429) {
33470
+ throw fail("RATE_LIMIT", `muse rate limited the key mint: http_${res.status}`);
33471
+ }
33472
+ throw fail("UPSTREAM", `muse key mint failed: http_${res.status}`);
33473
+ }
33474
+ const record2 = recordFrom3(parsed2);
33475
+ if (record2 === null) {
33476
+ throw fail("UPSTREAM", "muse key mint returned an unusable response");
33477
+ }
33478
+ if (record2.require_payment === true) {
33479
+ throw fail("AUTH", "muse requires a payment method on the Meta account; add one at https://dev.meta.ai and reconnect");
33480
+ }
33481
+ const apiKey = stringFrom3(record2, "api_key");
33482
+ if (apiKey === null) {
33483
+ throw fail("AUTH", "muse key mint returned an empty api key; finish onboarding at https://dev.meta.ai and reconnect");
33484
+ }
33485
+ return {
33486
+ apiKey,
33487
+ email: stringFrom3(record2, "user_email"),
33488
+ tierName: stringFrom3(record2, "subs_tier_name"),
33489
+ subscriptionActive: record2.is_subs_active === true,
33490
+ baseUrl: trustedBaseUrl(record2.base_url),
33491
+ usage: record2.subs_usage
33492
+ };
33493
+ }
33494
+ function toResult5(token, key, fallbackRefresh, now) {
33495
+ return {
33496
+ secrets: {
33497
+ accessToken: token.accessToken,
33498
+ refreshToken: token.refreshToken ?? fallbackRefresh,
33499
+ apiKey: key.apiKey,
33500
+ idToken: null
33501
+ },
33502
+ expiresAt: token.expiresIn === null ? null : now() + token.expiresIn * 1000,
33503
+ accountEmail: key.email,
33504
+ providerData: {
33505
+ ...key.tierName === null ? {} : { subscriptionTier: key.tierName },
33506
+ subscriptionActive: key.subscriptionActive,
33507
+ ...key.baseUrl === null ? {} : { baseUrl: key.baseUrl }
33508
+ }
33509
+ };
33510
+ }
33511
+ var museOAuthFlow = {
33512
+ kind: "device",
33513
+ supportsManualPaste: false,
33514
+ needsDeviceId: false,
33515
+ async* start() {
33516
+ return {
33517
+ authorizeUrl: FALLBACK_VERIFICATION_URL2,
33518
+ pending: { verifier: "", challenge: "", state: "", redirectUri: "" }
33519
+ };
33520
+ },
33521
+ async* begin({ fail, keepPolling }) {
33522
+ const response = deviceCodeFrom3(yield* postForm(DEVICE_CODE_URL2, {}, fail, keepPolling), fail);
33523
+ return {
33524
+ authorizeUrl: response.verificationUri,
33525
+ userCode: response.userCode,
33526
+ pending: {
33527
+ verifier: "",
33528
+ challenge: "",
33529
+ state: "",
33530
+ redirectUri: "",
33531
+ deviceCode: response.deviceCode,
33532
+ interval: response.interval
33533
+ }
33534
+ };
33535
+ },
33536
+ async* exchange({ pending, fail, keepPolling, now }) {
33537
+ if (pending.deviceCode === undefined) {
33538
+ throw fail("INTERNAL", "muse exchange requires a pending flow produced by begin()");
33539
+ }
33540
+ const token = tokenFrom2(yield* postForm(TOKEN_URL4, { grant_type: DEVICE_CODE_GRANT, device_code: pending.deviceCode }, fail, keepPolling), fail);
33541
+ return toResult5(token, yield* mint(token.accessToken, fail), null, now);
33542
+ },
33543
+ async* refresh({ refreshToken, fail, keepPolling, now }) {
33544
+ const token = tokenFrom2(yield* postForm(TOKEN_URL4, { grant_type: "refresh_token", refresh_token: refreshToken }, fail, keepPolling), fail);
33545
+ return toResult5(token, yield* mint(token.accessToken, fail), refreshToken, now);
33546
+ },
33547
+ async* usage({ secrets, now }) {
33548
+ if (secrets.accessToken === null)
33549
+ return null;
33550
+ const res = yield postJsonRequest(MINT_URL, museProfile, {
33551
+ contentType: "application/json",
33552
+ body: "{}",
33553
+ extraHeaders: [
33554
+ ["Authorization", `Bearer ${secrets.accessToken}`],
33555
+ ["Accept", "application/json"]
33556
+ ]
33557
+ });
33558
+ if (!usageReadable(res.status, "muse"))
33559
+ return null;
33560
+ const record2 = recordOf(parsed(res.body));
33561
+ return record2 === null ? null : parseMuseUsage(record2.subs_usage, now());
33562
+ }
33563
+ };
33564
+ function parseMuseUsage(value, now) {
33565
+ const root = recordOf(value);
33566
+ if (root === null)
33567
+ return null;
33568
+ const window2 = recordOf(root.window);
33569
+ const mins = window2 === null ? null : numberOf(window2, ["window_duration_mins"]);
33570
+ return reportFrom([
33571
+ windowFrom(root.window, "fiveHour", now, mins === null ? null : mins * 60000),
33572
+ windowFrom(root.weekly, "weekly", now)
33573
+ ]);
33574
+ }
33575
+
31979
33576
  // packages/providers/src/openai/oauth.ts
31980
- var CLIENT_ID4 = "app_EMoamEEZ73f0CkXaXp7hrann";
31981
- var AUTHORIZE_URL2 = "https://auth.openai.com/oauth/authorize";
31982
- var TOKEN_URL3 = "https://auth.openai.com/oauth/token";
31983
- var SCOPES3 = "openid profile email offline_access";
33577
+ var CLIENT_ID6 = "app_EMoamEEZ73f0CkXaXp7hrann";
33578
+ var AUTHORIZE_URL3 = "https://auth.openai.com/oauth/authorize";
33579
+ var TOKEN_URL5 = "https://auth.openai.com/oauth/token";
33580
+ var SCOPES4 = "openid profile email offline_access";
31984
33581
  var USAGE_URL3 = "https://chatgpt.com/backend-api/wham/usage";
31985
- function isRecord5(value) {
33582
+ function isRecord6(value) {
31986
33583
  return typeof value === "object" && value !== null;
31987
33584
  }
31988
33585
  function nonBlankStringOrNull(value) {
@@ -31998,20 +33595,20 @@ function decodeClaims(idToken) {
31998
33595
  return { email: null, accountId: null };
31999
33596
  }
32000
33597
  try {
32001
- const json3 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
32002
- if (!isRecord5(json3))
33598
+ const json4 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
33599
+ if (!isRecord6(json4))
32003
33600
  return { email: null, accountId: null };
32004
- const auth = json3["https://api.openai.com/auth"];
33601
+ const auth = json4["https://api.openai.com/auth"];
32005
33602
  return {
32006
- email: typeof json3.email === "string" ? json3.email : null,
32007
- accountId: isRecord5(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
33603
+ email: typeof json4.email === "string" ? json4.email : null,
33604
+ accountId: isRecord6(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
32008
33605
  };
32009
33606
  } catch {
32010
33607
  return { email: null, accountId: null };
32011
33608
  }
32012
33609
  }
32013
- function parseTokenResponse2(value) {
32014
- if (!isRecord5(value) || typeof value.access_token !== "string")
33610
+ function parseTokenResponse3(value) {
33611
+ if (!isRecord6(value) || typeof value.access_token !== "string")
32015
33612
  return null;
32016
33613
  return {
32017
33614
  accessToken: value.access_token,
@@ -32020,22 +33617,22 @@ function parseTokenResponse2(value) {
32020
33617
  idToken: typeof value.id_token === "string" ? value.id_token : null
32021
33618
  };
32022
33619
  }
32023
- async function* postToken3(body, fail) {
32024
- const res = yield postJsonRequest(TOKEN_URL3, openaiProfile, {
33620
+ async function* postToken4(body, fail) {
33621
+ const res = yield postJsonRequest(TOKEN_URL5, openaiProfile, {
32025
33622
  contentType: "application/x-www-form-urlencoded",
32026
- body: new URLSearchParams({ ...body, client_id: CLIENT_ID4 }).toString()
33623
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID6 }).toString()
32027
33624
  });
32028
33625
  const parsed2 = parsed(res.body);
32029
33626
  if (res.status < 200 || res.status >= 300) {
32030
33627
  throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
32031
33628
  }
32032
- const token = parseTokenResponse2(parsed2);
33629
+ const token = parseTokenResponse3(parsed2);
32033
33630
  if (token === null) {
32034
33631
  throw fail("AUTH", "token endpoint returned no access_token");
32035
33632
  }
32036
33633
  return token;
32037
33634
  }
32038
- function toResult4(token, fallbackRefresh, now, fallbackAccountId = null) {
33635
+ function toResult6(token, fallbackRefresh, now, fallbackAccountId = null) {
32039
33636
  const claims = decodeClaims(token.idToken);
32040
33637
  return {
32041
33638
  secrets: {
@@ -32093,11 +33690,11 @@ var openaiOAuthFlow = {
32093
33690
  async* start({ redirectUri, pkce, randomState }) {
32094
33691
  const { verifier, challenge } = pkce();
32095
33692
  const state = randomState();
32096
- const url2 = new URL(AUTHORIZE_URL2);
32097
- url2.searchParams.set("client_id", CLIENT_ID4);
33693
+ const url2 = new URL(AUTHORIZE_URL3);
33694
+ url2.searchParams.set("client_id", CLIENT_ID6);
32098
33695
  url2.searchParams.set("response_type", "code");
32099
33696
  url2.searchParams.set("redirect_uri", redirectUri);
32100
- url2.searchParams.set("scope", SCOPES3);
33697
+ url2.searchParams.set("scope", SCOPES4);
32101
33698
  url2.searchParams.set("code_challenge", challenge);
32102
33699
  url2.searchParams.set("code_challenge_method", "S256");
32103
33700
  url2.searchParams.set("id_token_add_organizations", "true");
@@ -32112,17 +33709,17 @@ var openaiOAuthFlow = {
32112
33709
  if (pastedState !== undefined && pastedState !== pending.state) {
32113
33710
  throw fail("AUTH", "authorization state mismatch");
32114
33711
  }
32115
- const token = yield* postToken3({
33712
+ const token = yield* postToken4({
32116
33713
  grant_type: "authorization_code",
32117
33714
  code: (rawCode ?? "").trim(),
32118
33715
  redirect_uri: pending.redirectUri,
32119
33716
  code_verifier: pending.verifier
32120
33717
  }, fail);
32121
- return toResult4(token, null, now);
33718
+ return toResult6(token, null, now);
32122
33719
  },
32123
33720
  async* refresh({ refreshToken, providerData, fail, now }) {
32124
- const token = yield* postToken3({ grant_type: "refresh_token", refresh_token: refreshToken, scope: SCOPES3 }, fail);
32125
- return toResult4(token, refreshToken, now, accountIdFromProviderData(providerData));
33721
+ const token = yield* postToken4({ grant_type: "refresh_token", refresh_token: refreshToken, scope: SCOPES4 }, fail);
33722
+ return toResult6(token, refreshToken, now, accountIdFromProviderData(providerData));
32126
33723
  },
32127
33724
  async* usage({ secrets, providerData, now }) {
32128
33725
  if (secrets.accessToken === null)
@@ -32145,7 +33742,9 @@ function builtinOAuthFlows() {
32145
33742
  ["openai", openaiOAuthFlow],
32146
33743
  ["kimi", kimiOAuthFlow],
32147
33744
  ["kilo", kiloOAuthFlow],
32148
- ["grok", grokOAuthFlow]
33745
+ ["grok", grokOAuthFlow],
33746
+ ["antigravity", antigravityOAuthFlow],
33747
+ ["muse", museOAuthFlow]
32149
33748
  ];
32150
33749
  }
32151
33750
  // packages/providers/src/custom/decode.ts
@@ -32173,7 +33772,7 @@ function reasoningText(delta) {
32173
33772
  return [];
32174
33773
  }).join("");
32175
33774
  }
32176
- function json3(data) {
33775
+ function json4(data) {
32177
33776
  try {
32178
33777
  const v = JSON.parse(data);
32179
33778
  return typeof v === "object" && v !== null ? v : null;
@@ -32195,7 +33794,7 @@ async function* decodeCustomChat(messages) {
32195
33794
  done = true;
32196
33795
  break;
32197
33796
  }
32198
- const d = json3(msg.data);
33797
+ const d = json4(msg.data);
32199
33798
  if (d === null)
32200
33799
  continue;
32201
33800
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -32353,7 +33952,7 @@ async function* decodeCustomResponses(messages) {
32353
33952
  };
32354
33953
  return;
32355
33954
  }
32356
- const d = json3(msg.data);
33955
+ const d = json4(msg.data);
32357
33956
  if (d === null)
32358
33957
  continue;
32359
33958
  switch (msg.event) {
@@ -32741,10 +34340,10 @@ var customCodec = {
32741
34340
  // packages/providers/src/custom/index.ts
32742
34341
  var customAdapter = codecAdapter("custom", customDescriptor.capabilities, customCodec);
32743
34342
  // packages/providers/src/grok/codec.ts
32744
- import { createHash as createHash3 } from "crypto";
34343
+ import { createHash as createHash4 } from "crypto";
32745
34344
 
32746
34345
  // packages/providers/src/grok/decode.ts
32747
- var ERROR_CODE = {
34346
+ var ERROR_CODE2 = {
32748
34347
  rate_limit_exceeded: "RATE_LIMIT",
32749
34348
  insufficient_quota: "QUOTA_EXHAUSTED",
32750
34349
  invalid_api_key: "AUTH",
@@ -32778,7 +34377,7 @@ var KNOWN_EVENTS2 = new Set([
32778
34377
  "response.failed",
32779
34378
  "error"
32780
34379
  ]);
32781
- function json4(data) {
34380
+ function json5(data) {
32782
34381
  try {
32783
34382
  const v = JSON.parse(data);
32784
34383
  return typeof v === "object" && v !== null ? v : null;
@@ -32813,7 +34412,7 @@ async function* decodeGrokResponses(messages) {
32813
34412
  };
32814
34413
  return;
32815
34414
  }
32816
- const d = json4(msg.data);
34415
+ const d = json5(msg.data);
32817
34416
  if (d === null)
32818
34417
  continue;
32819
34418
  switch (msg.event) {
@@ -32916,7 +34515,7 @@ async function* decodeGrokResponses(messages) {
32916
34515
  terminal = true;
32917
34516
  const err = d.response?.error ?? d.error ?? {};
32918
34517
  const raw = String(err.code ?? err.type);
32919
- const code = (Object.hasOwn(ERROR_CODE, raw) ? ERROR_CODE[raw] : undefined) ?? "UPSTREAM";
34518
+ const code = (Object.hasOwn(ERROR_CODE2, raw) ? ERROR_CODE2[raw] : undefined) ?? "UPSTREAM";
32920
34519
  yield {
32921
34520
  type: "error",
32922
34521
  code,
@@ -32940,9 +34539,9 @@ async function* decodeGrokResponses(messages) {
32940
34539
  }
32941
34540
 
32942
34541
  // packages/providers/src/grok/wire.ts
32943
- import { createHash as createHash2 } from "crypto";
34542
+ import { createHash as createHash3 } from "crypto";
32944
34543
  var MAX_TOOLS = 200;
32945
- function encodeToolChoice2(c) {
34544
+ function encodeToolChoice3(c) {
32946
34545
  switch (c.type) {
32947
34546
  case "auto":
32948
34547
  return "auto";
@@ -32956,7 +34555,7 @@ function encodeToolChoice2(c) {
32956
34555
  }
32957
34556
  function promptCacheKey(instructions, firstInput) {
32958
34557
  const stable = JSON.stringify({ instructions, firstInput });
32959
- return createHash2("sha256").update(stable).digest("hex").slice(0, 32);
34558
+ return createHash3("sha256").update(stable).digest("hex").slice(0, 32);
32960
34559
  }
32961
34560
  function toGrokWire(req, model) {
32962
34561
  const degradations = [];
@@ -33049,7 +34648,7 @@ function toGrokWire(req, model) {
33049
34648
  }));
33050
34649
  }
33051
34650
  if (req.toolChoice !== undefined)
33052
- body.tool_choice = encodeToolChoice2(req.toolChoice);
34651
+ body.tool_choice = encodeToolChoice3(req.toolChoice);
33053
34652
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
33054
34653
  if (req.reasoning.mode === "budget") {
33055
34654
  note("grok:reasoning-budget-dropped");
@@ -33067,7 +34666,7 @@ var PROXY_URL = "https://cli-chat-proxy.grok.com/v1/responses";
33067
34666
  var API_URL = "https://api.x.ai/v1/responses";
33068
34667
  var CONV_NAMESPACE = "omni-grok-conv";
33069
34668
  function derivedUuid(value) {
33070
- const h = createHash3("sha256").update(`${CONV_NAMESPACE}:${value}`).digest("hex");
34669
+ const h = createHash4("sha256").update(`${CONV_NAMESPACE}:${value}`).digest("hex");
33071
34670
  const variant = (Number.parseInt(h[16], 16) & 3 | 8).toString(16);
33072
34671
  return [
33073
34672
  h.slice(0, 8),
@@ -33250,7 +34849,7 @@ function reasoningText2(delta) {
33250
34849
  return [];
33251
34850
  }).join("");
33252
34851
  }
33253
- function json5(data) {
34852
+ function json6(data) {
33254
34853
  try {
33255
34854
  const v = JSON.parse(data);
33256
34855
  return typeof v === "object" && v !== null ? v : null;
@@ -33272,7 +34871,7 @@ async function* decodeKiloChat(messages) {
33272
34871
  done = true;
33273
34872
  break;
33274
34873
  }
33275
- const d = json5(msg.data);
34874
+ const d = json6(msg.data);
33276
34875
  if (d === null)
33277
34876
  continue;
33278
34877
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -33372,7 +34971,7 @@ async function* decodeKiloChat(messages) {
33372
34971
  }
33373
34972
 
33374
34973
  // packages/providers/src/kilo/wire.ts
33375
- function encodeToolChoice3(c) {
34974
+ function encodeToolChoice4(c) {
33376
34975
  switch (c.type) {
33377
34976
  case "auto":
33378
34977
  return "auto";
@@ -33483,7 +35082,7 @@ function toKiloWire(req, model) {
33483
35082
  }));
33484
35083
  }
33485
35084
  if (req.toolChoice !== undefined)
33486
- body.tool_choice = encodeToolChoice3(req.toolChoice);
35085
+ body.tool_choice = encodeToolChoice4(req.toolChoice);
33487
35086
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
33488
35087
  if (req.reasoning.mode === "budget") {
33489
35088
  body.reasoning = { max_tokens: req.reasoning.budgetTokens };
@@ -33542,7 +35141,7 @@ var FINISH2 = {
33542
35141
  tool_calls: "toolUse",
33543
35142
  content_filter: "contentFilter"
33544
35143
  };
33545
- function json6(data) {
35144
+ function json7(data) {
33546
35145
  try {
33547
35146
  const v = JSON.parse(data);
33548
35147
  return typeof v === "object" && v !== null ? v : null;
@@ -33564,7 +35163,7 @@ async function* decodeChat(messages) {
33564
35163
  done = true;
33565
35164
  break;
33566
35165
  }
33567
- const d = json6(msg.data);
35166
+ const d = json7(msg.data);
33568
35167
  if (d === null)
33569
35168
  continue;
33570
35169
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -33648,7 +35247,7 @@ async function* decodeChat(messages) {
33648
35247
  }
33649
35248
 
33650
35249
  // packages/providers/src/kimi/wire.ts
33651
- function encodeToolChoice4(c) {
35250
+ function encodeToolChoice5(c) {
33652
35251
  switch (c.type) {
33653
35252
  case "auto":
33654
35253
  return "auto";
@@ -33739,7 +35338,7 @@ function toChatWire(req, model, vendor = "kimi") {
33739
35338
  }));
33740
35339
  }
33741
35340
  if (req.toolChoice !== undefined)
33742
- body.tool_choice = encodeToolChoice4(req.toolChoice);
35341
+ body.tool_choice = encodeToolChoice5(req.toolChoice);
33743
35342
  if (req.reasoning !== undefined)
33744
35343
  note("kimi:reasoning-dropped");
33745
35344
  Object.assign(body, req.vendor?.[vendor] ?? {});
@@ -33779,8 +35378,8 @@ var kimiCodec = {
33779
35378
 
33780
35379
  // packages/providers/src/kimi/index.ts
33781
35380
  var kimiAdapter = codecAdapter("kimi", kimiDescriptor.capabilities, kimiCodec);
33782
- // packages/providers/src/openai/decode.ts
33783
- var ERROR_CODE2 = {
35381
+ // packages/providers/src/muse/decode.ts
35382
+ var ERROR_CODE3 = {
33784
35383
  rate_limit_exceeded: "RATE_LIMIT",
33785
35384
  insufficient_quota: "QUOTA_EXHAUSTED",
33786
35385
  invalid_api_key: "AUTH",
@@ -33815,7 +35414,7 @@ var KNOWN_EVENTS3 = new Set([
33815
35414
  "response.failed",
33816
35415
  "error"
33817
35416
  ]);
33818
- function json7(data) {
35417
+ function json8(data) {
33819
35418
  try {
33820
35419
  const v = JSON.parse(data);
33821
35420
  return typeof v === "object" && v !== null ? v : null;
@@ -33823,7 +35422,7 @@ function json7(data) {
33823
35422
  return null;
33824
35423
  }
33825
35424
  }
33826
- async function* decodeResponses(messages, options = {}) {
35425
+ async function* decodeMuseResponses(messages, options = {}) {
33827
35426
  const nativeReasoning = options.nativeReasoning === true;
33828
35427
  const indices = new Map;
33829
35428
  let next = 0;
@@ -33846,12 +35445,12 @@ async function* decodeResponses(messages, options = {}) {
33846
35445
  yield {
33847
35446
  type: "error",
33848
35447
  code: "UPSTREAM",
33849
- message: `unrecognized OpenAI stream event "${msg.event}"`,
35448
+ message: `unrecognized muse stream event "${msg.event}"`,
33850
35449
  retryable: false
33851
35450
  };
33852
35451
  return;
33853
35452
  }
33854
- const d = json7(msg.data);
35453
+ const d = json8(msg.data);
33855
35454
  if (d === null)
33856
35455
  continue;
33857
35456
  switch (msg.event) {
@@ -33869,7 +35468,7 @@ async function* decodeResponses(messages, options = {}) {
33869
35468
  yield {
33870
35469
  type: "blockStart",
33871
35470
  index: irIndex(d.output_index ?? 0),
33872
- block: nativeReasoning ? { type: "providerNative", provider: "openai", blockType: "reasoning", data: {} } : { type: "thinking" }
35471
+ block: nativeReasoning ? { type: "providerNative", provider: "muse", blockType: "reasoning", data: {} } : { type: "thinking" }
33873
35472
  };
33874
35473
  } else if (item.type === "function_call") {
33875
35474
  sawToolCall = true;
@@ -33904,7 +35503,7 @@ async function* decodeResponses(messages, options = {}) {
33904
35503
  index: irIndex(d.output_index ?? 0),
33905
35504
  delta: nativeReasoning ? {
33906
35505
  type: "providerNative",
33907
- provider: "openai",
35506
+ provider: "muse",
33908
35507
  deltaType: "reasoning_summary_text.delta",
33909
35508
  data: { text: String(d.delta ?? "") }
33910
35509
  } : { type: "thinking", text: String(d.delta ?? "") }
@@ -33930,7 +35529,7 @@ async function* decodeResponses(messages, options = {}) {
33930
35529
  index: irIndex(outputIndex),
33931
35530
  delta: {
33932
35531
  type: "providerNative",
33933
- provider: "openai",
35532
+ provider: "muse",
33934
35533
  deltaType: "response.output_item.done",
33935
35534
  fold: "merge",
33936
35535
  data: item
@@ -33955,7 +35554,7 @@ async function* decodeResponses(messages, options = {}) {
33955
35554
  yield {
33956
35555
  type: "error",
33957
35556
  code: "UPSTREAM",
33958
- message: reason !== undefined ? `unrecognized OpenAI incomplete reason "${String(reason)}"` : r.status !== undefined && r.status !== "incomplete" ? `OpenAI reported terminal response status "${String(r.status)}"` : "OpenAI reported the response incomplete without a reason",
35557
+ message: reason !== undefined ? `unrecognized muse incomplete reason "${String(reason)}"` : r.status !== undefined && r.status !== "incomplete" ? `muse reported terminal response status "${String(r.status)}"` : "muse reported the response incomplete without a reason",
33959
35558
  retryable: false
33960
35559
  };
33961
35560
  break;
@@ -33972,7 +35571,7 @@ async function* decodeResponses(messages, options = {}) {
33972
35571
  terminal = true;
33973
35572
  const err = d.response?.error ?? d.error ?? {};
33974
35573
  const raw = String(err.code ?? err.type);
33975
- const code = (Object.hasOwn(ERROR_CODE2, raw) ? ERROR_CODE2[raw] : undefined) ?? "UPSTREAM";
35574
+ const code = (Object.hasOwn(ERROR_CODE3, raw) ? ERROR_CODE3[raw] : undefined) ?? "UPSTREAM";
33976
35575
  yield {
33977
35576
  type: "error",
33978
35577
  code,
@@ -33995,8 +35594,8 @@ async function* decodeResponses(messages, options = {}) {
33995
35594
  }
33996
35595
  }
33997
35596
 
33998
- // packages/providers/src/openai/wire.ts
33999
- import { createHash as createHash4 } from "crypto";
35597
+ // packages/providers/src/muse/wire.ts
35598
+ import { createHash as createHash5 } from "crypto";
34000
35599
  function suppliedKey(req) {
34001
35600
  const vendor = req.vendor?.openai;
34002
35601
  for (const name of ["prompt_cache_key", "session_id"]) {
@@ -34008,7 +35607,7 @@ function suppliedKey(req) {
34008
35607
  }
34009
35608
  function cacheKey(req, instructions, firstInput) {
34010
35609
  const stable = req.conversationId !== undefined && req.conversationId.length > 0 ? JSON.stringify({ conversation: req.conversationId }) : JSON.stringify({ instructions, firstInput: firstInput ?? null });
34011
- return createHash4("sha256").update(stable).digest("hex").slice(0, 32);
35610
+ return createHash5("sha256").update(stable).digest("hex").slice(0, 32);
34012
35611
  }
34013
35612
  function repairOrphanedCalls(input2) {
34014
35613
  const answered = new Set;
@@ -34027,7 +35626,407 @@ function repairOrphanedCalls(input2) {
34027
35626
  input2.splice(i + 1, 0, { type: "function_call_output", call_id: record2.call_id, output: "" });
34028
35627
  }
34029
35628
  }
34030
- function encodeToolChoice5(c) {
35629
+ function encodeToolChoice6(c) {
35630
+ switch (c.type) {
35631
+ case "auto":
35632
+ return "auto";
35633
+ case "any":
35634
+ return "required";
35635
+ case "none":
35636
+ return "none";
35637
+ case "tool":
35638
+ return { type: "function", name: c.name };
35639
+ }
35640
+ }
35641
+ function toMuseWire(req, model) {
35642
+ const degradations = [];
35643
+ const input2 = [];
35644
+ const note = (d) => {
35645
+ if (!degradations.includes(d))
35646
+ degradations.push(d);
35647
+ };
35648
+ if (req.betas?.includes(CONTEXT_1M_BETA))
35649
+ note("muse:context-1m-dropped");
35650
+ for (const message of req.messages) {
35651
+ const parts = [];
35652
+ const asDeveloper = message.role === "system";
35653
+ if (asDeveloper)
35654
+ note("muse:system-turn-as-developer");
35655
+ const role = asDeveloper ? "developer" : message.role;
35656
+ const flush = () => {
35657
+ if (parts.length === 0)
35658
+ return;
35659
+ input2.push({ type: "message", role, content: [...parts] });
35660
+ parts.length = 0;
35661
+ };
35662
+ for (const block of message.content) {
35663
+ switch (block.type) {
35664
+ case "text":
35665
+ parts.push({
35666
+ type: role === "assistant" ? "output_text" : "input_text",
35667
+ text: block.text
35668
+ });
35669
+ break;
35670
+ case "image":
35671
+ parts.push({
35672
+ type: "input_image",
35673
+ image_url: `data:${block.mediaType};base64,${block.data}`
35674
+ });
35675
+ break;
35676
+ case "thinking":
35677
+ note("muse:thinking-dropped");
35678
+ break;
35679
+ case "toolUse":
35680
+ flush();
35681
+ input2.push({
35682
+ type: "function_call",
35683
+ call_id: block.id,
35684
+ name: block.name,
35685
+ arguments: JSON.stringify(block.input)
35686
+ });
35687
+ break;
35688
+ case "toolResult":
35689
+ flush();
35690
+ input2.push({
35691
+ type: "function_call_output",
35692
+ call_id: block.toolUseId,
35693
+ output: block.content
35694
+ });
35695
+ break;
35696
+ case "providerNative":
35697
+ if (block.provider === "muse") {
35698
+ flush();
35699
+ const { id: _id, ...rest } = block.data;
35700
+ input2.push({ type: block.blockType, ...rest });
35701
+ break;
35702
+ }
35703
+ note("muse:foreign-native-block-dropped");
35704
+ break;
35705
+ }
35706
+ }
35707
+ flush();
35708
+ }
35709
+ repairOrphanedCalls(input2);
35710
+ const body = { model, input: input2, stream: req.stream, store: false };
35711
+ const instructions = systemText(req.system, "muse", note);
35712
+ if (instructions !== undefined && instructions.length > 0)
35713
+ body.instructions = instructions;
35714
+ if (req.maxTokens !== undefined)
35715
+ body.max_output_tokens = req.maxTokens;
35716
+ if (req.temperature !== undefined)
35717
+ body.temperature = req.temperature;
35718
+ if (req.tools !== undefined) {
35719
+ const portable = req.tools.filter((t) => t.kind === "portable");
35720
+ if (portable.length !== req.tools.length)
35721
+ note("muse:provider-tool-dropped");
35722
+ body.tools = portable.map((t) => ({
35723
+ type: "function",
35724
+ name: t.name,
35725
+ description: t.description,
35726
+ parameters: t.inputSchema
35727
+ }));
35728
+ }
35729
+ if (req.toolChoice !== undefined)
35730
+ body.tool_choice = encodeToolChoice6(req.toolChoice);
35731
+ if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
35732
+ if (req.reasoning.mode === "budget") {
35733
+ note("muse:reasoning-budget-dropped");
35734
+ } else {
35735
+ const effort = req.reasoning.effort ?? "medium";
35736
+ body.reasoning = { effort, summary: "auto" };
35737
+ }
35738
+ }
35739
+ const key = suppliedKey(req) ?? cacheKey(req, instructions ?? "", input2[0]);
35740
+ Object.assign(body, req.vendor?.openai ?? {});
35741
+ body.prompt_cache_key = key;
35742
+ return { body, degradations, cacheKey: key };
35743
+ }
35744
+
35745
+ // packages/providers/src/muse/codec.ts
35746
+ var museCodec = {
35747
+ buildRequest(input2) {
35748
+ const { body, degradations, cacheKey: cacheKey2 } = toMuseWire(input2.request, input2.model);
35749
+ if (input2.credentials.apiKey === null) {
35750
+ throw input2.fail("AUTH", "muse credential has no model api key");
35751
+ }
35752
+ const protocol = [
35753
+ ["Content-Type", "application/json"],
35754
+ ["Authorization", `Bearer ${input2.credentials.apiKey}`],
35755
+ ["x-meta-ai-gateway-session-id", cacheKey2]
35756
+ ];
35757
+ const headers = orderHeaders(mergeHeaders(museProfile.headers, protocol), museProfile.order);
35758
+ const include = body.include;
35759
+ const nativeReasoning = Array.isArray(include) && include.includes("reasoning.encrypted_content");
35760
+ return {
35761
+ decodeState: { nativeReasoning },
35762
+ request: {
35763
+ url: museResponsesUrl(input2.credentials.providerData),
35764
+ method: "POST",
35765
+ headers,
35766
+ body: JSON.stringify(orderFields({ ...body, stream: true }, museBodyOrder))
35767
+ },
35768
+ degradations
35769
+ };
35770
+ },
35771
+ decode({ body, decodeState }) {
35772
+ const state = decodeState;
35773
+ return decodeMuseResponses(parseSse(body), {
35774
+ nativeReasoning: state?.nativeReasoning === true
35775
+ });
35776
+ }
35777
+ };
35778
+
35779
+ // packages/providers/src/muse/index.ts
35780
+ var museAdapter = codecAdapter("muse", museDescriptor.capabilities, museCodec);
35781
+ // packages/providers/src/openai/decode.ts
35782
+ var ERROR_CODE4 = {
35783
+ rate_limit_exceeded: "RATE_LIMIT",
35784
+ insufficient_quota: "QUOTA_EXHAUSTED",
35785
+ invalid_api_key: "AUTH",
35786
+ server_error: "UPSTREAM",
35787
+ context_length_exceeded: "BAD_REQUEST",
35788
+ content_policy_violation: "CONTENT_FILTER"
35789
+ };
35790
+ var KNOWN_EVENTS4 = new Set([
35791
+ "keepalive",
35792
+ "response.created",
35793
+ "response.queued",
35794
+ "response.in_progress",
35795
+ "response.output_item.added",
35796
+ "response.output_item.done",
35797
+ "response.content_part.added",
35798
+ "response.content_part.done",
35799
+ "response.output_text.delta",
35800
+ "response.output_text.done",
35801
+ "response.output_text.annotation.added",
35802
+ "response.refusal.delta",
35803
+ "response.refusal.done",
35804
+ "response.reasoning_summary_part.added",
35805
+ "response.reasoning_summary_part.done",
35806
+ "response.reasoning_summary_text.delta",
35807
+ "response.reasoning_summary_text.done",
35808
+ "response.reasoning_text.delta",
35809
+ "response.reasoning_text.done",
35810
+ "response.function_call_arguments.delta",
35811
+ "response.function_call_arguments.done",
35812
+ "response.completed",
35813
+ "response.incomplete",
35814
+ "response.failed",
35815
+ "error"
35816
+ ]);
35817
+ function json9(data) {
35818
+ try {
35819
+ const v = JSON.parse(data);
35820
+ return typeof v === "object" && v !== null ? v : null;
35821
+ } catch {
35822
+ return null;
35823
+ }
35824
+ }
35825
+ async function* decodeResponses(messages, options = {}) {
35826
+ const nativeReasoning = options.nativeReasoning === true;
35827
+ const indices = new Map;
35828
+ let next = 0;
35829
+ const irIndex = (outputIndex, contentIndex = 0) => {
35830
+ const key = `${outputIndex}:${contentIndex}`;
35831
+ const existing = indices.get(key);
35832
+ if (existing !== undefined)
35833
+ return existing;
35834
+ const assigned = next++;
35835
+ indices.set(key, assigned);
35836
+ return assigned;
35837
+ };
35838
+ let sawToolCall = false;
35839
+ let terminal = false;
35840
+ const ownsBlock = new Set;
35841
+ for await (const msg of messages) {
35842
+ if (msg.data === "[DONE]")
35843
+ continue;
35844
+ if (!KNOWN_EVENTS4.has(msg.event)) {
35845
+ yield {
35846
+ type: "error",
35847
+ code: "UPSTREAM",
35848
+ message: `unrecognized OpenAI stream event "${msg.event}"`,
35849
+ retryable: false
35850
+ };
35851
+ return;
35852
+ }
35853
+ const d = json9(msg.data);
35854
+ if (d === null)
35855
+ continue;
35856
+ switch (msg.event) {
35857
+ case "response.created":
35858
+ yield {
35859
+ type: "start",
35860
+ id: String(d.response?.id ?? ""),
35861
+ model: String(d.response?.model ?? "")
35862
+ };
35863
+ break;
35864
+ case "response.output_item.added": {
35865
+ const item = d.item ?? {};
35866
+ if (item.type === "reasoning") {
35867
+ ownsBlock.add(d.output_index ?? 0);
35868
+ yield {
35869
+ type: "blockStart",
35870
+ index: irIndex(d.output_index ?? 0),
35871
+ block: nativeReasoning ? { type: "providerNative", provider: "openai", blockType: "reasoning", data: {} } : { type: "thinking" }
35872
+ };
35873
+ } else if (item.type === "function_call") {
35874
+ sawToolCall = true;
35875
+ ownsBlock.add(d.output_index ?? 0);
35876
+ yield {
35877
+ type: "blockStart",
35878
+ index: irIndex(d.output_index ?? 0),
35879
+ block: { type: "toolUse", id: String(item.call_id), name: String(item.name) }
35880
+ };
35881
+ }
35882
+ break;
35883
+ }
35884
+ case "response.content_part.added":
35885
+ if (d.part?.type === "output_text") {
35886
+ yield {
35887
+ type: "blockStart",
35888
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
35889
+ block: { type: "text" }
35890
+ };
35891
+ }
35892
+ break;
35893
+ case "response.output_text.delta":
35894
+ yield {
35895
+ type: "blockDelta",
35896
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
35897
+ delta: { type: "text", text: String(d.delta ?? "") }
35898
+ };
35899
+ break;
35900
+ case "response.reasoning_summary_text.delta":
35901
+ yield {
35902
+ type: "blockDelta",
35903
+ index: irIndex(d.output_index ?? 0),
35904
+ delta: nativeReasoning ? {
35905
+ type: "providerNative",
35906
+ provider: "openai",
35907
+ deltaType: "reasoning_summary_text.delta",
35908
+ data: { text: String(d.delta ?? "") }
35909
+ } : { type: "thinking", text: String(d.delta ?? "") }
35910
+ };
35911
+ break;
35912
+ case "response.function_call_arguments.delta":
35913
+ yield {
35914
+ type: "blockDelta",
35915
+ index: irIndex(d.output_index ?? 0),
35916
+ delta: { type: "toolJson", partial: String(d.delta ?? "") }
35917
+ };
35918
+ break;
35919
+ case "response.content_part.done":
35920
+ yield { type: "blockEnd", index: irIndex(d.output_index ?? 0, d.content_index ?? 0) };
35921
+ break;
35922
+ case "response.output_item.done": {
35923
+ const outputIndex = d.output_index ?? 0;
35924
+ if (ownsBlock.delete(outputIndex)) {
35925
+ const item = d.item ?? {};
35926
+ if (nativeReasoning && item.type === "reasoning") {
35927
+ yield {
35928
+ type: "blockDelta",
35929
+ index: irIndex(outputIndex),
35930
+ delta: {
35931
+ type: "providerNative",
35932
+ provider: "openai",
35933
+ deltaType: "response.output_item.done",
35934
+ fold: "merge",
35935
+ data: item
35936
+ }
35937
+ };
35938
+ }
35939
+ yield { type: "blockEnd", index: irIndex(outputIndex) };
35940
+ }
35941
+ break;
35942
+ }
35943
+ case "response.completed":
35944
+ case "response.incomplete": {
35945
+ terminal = true;
35946
+ const r = d.response ?? {};
35947
+ const reason = r.incomplete_details?.reason;
35948
+ let stopReason = sawToolCall ? "toolUse" : "endTurn";
35949
+ if (reason === "max_output_tokens")
35950
+ stopReason = "maxTokens";
35951
+ else if (reason === "content_filter")
35952
+ stopReason = "contentFilter";
35953
+ else if (reason !== undefined || msg.event === "response.incomplete" || r.status !== undefined && r.status !== "completed") {
35954
+ yield {
35955
+ type: "error",
35956
+ code: "UPSTREAM",
35957
+ message: reason !== undefined ? `unrecognized OpenAI incomplete reason "${String(reason)}"` : r.status !== undefined && r.status !== "incomplete" ? `OpenAI reported terminal response status "${String(r.status)}"` : "OpenAI reported the response incomplete without a reason",
35958
+ retryable: false
35959
+ };
35960
+ break;
35961
+ }
35962
+ yield {
35963
+ type: "end",
35964
+ stopReason,
35965
+ usage: usageFromPromptTotal(r.usage?.input_tokens ?? 0, r.usage?.output_tokens ?? 0, r.usage?.input_tokens_details?.cached_tokens ?? r.usage?.prompt_tokens_details?.cached_tokens ?? 0)
35966
+ };
35967
+ break;
35968
+ }
35969
+ case "response.failed":
35970
+ case "error": {
35971
+ terminal = true;
35972
+ const err = d.response?.error ?? d.error ?? {};
35973
+ const raw = String(err.code ?? err.type);
35974
+ const code = (Object.hasOwn(ERROR_CODE4, raw) ? ERROR_CODE4[raw] : undefined) ?? "UPSTREAM";
35975
+ yield {
35976
+ type: "error",
35977
+ code,
35978
+ message: String(err.message ?? "upstream error"),
35979
+ retryable: RETRYABLE[code]
35980
+ };
35981
+ break;
35982
+ }
35983
+ default:
35984
+ break;
35985
+ }
35986
+ }
35987
+ if (!terminal) {
35988
+ yield {
35989
+ type: "error",
35990
+ code: "UPSTREAM",
35991
+ message: "upstream stream ended before response completion",
35992
+ retryable: RETRYABLE.UPSTREAM
35993
+ };
35994
+ }
35995
+ }
35996
+
35997
+ // packages/providers/src/openai/wire.ts
35998
+ import { createHash as createHash6 } from "crypto";
35999
+ function suppliedKey2(req) {
36000
+ const vendor = req.vendor?.openai;
36001
+ for (const name of ["prompt_cache_key", "session_id"]) {
36002
+ const value = vendor?.[name];
36003
+ if (typeof value === "string" && value.length > 0)
36004
+ return value;
36005
+ }
36006
+ return;
36007
+ }
36008
+ function cacheKey2(req, instructions, firstInput) {
36009
+ const stable = req.conversationId !== undefined && req.conversationId.length > 0 ? JSON.stringify({ conversation: req.conversationId }) : JSON.stringify({ instructions, firstInput: firstInput ?? null });
36010
+ return createHash6("sha256").update(stable).digest("hex").slice(0, 32);
36011
+ }
36012
+ function repairOrphanedCalls2(input2) {
36013
+ const answered = new Set;
36014
+ for (const item of input2) {
36015
+ const record2 = item;
36016
+ if (record2.type === "function_call_output" && typeof record2.call_id === "string") {
36017
+ answered.add(record2.call_id);
36018
+ }
36019
+ }
36020
+ for (let i = input2.length - 1;i >= 0; i--) {
36021
+ const record2 = input2[i];
36022
+ if (record2.type !== "function_call" || typeof record2.call_id !== "string")
36023
+ continue;
36024
+ if (answered.has(record2.call_id))
36025
+ continue;
36026
+ input2.splice(i + 1, 0, { type: "function_call_output", call_id: record2.call_id, output: "" });
36027
+ }
36028
+ }
36029
+ function encodeToolChoice7(c) {
34031
36030
  switch (c.type) {
34032
36031
  case "auto":
34033
36032
  return "auto";
@@ -34109,7 +36108,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34109
36108
  }
34110
36109
  flush();
34111
36110
  }
34112
- repairOrphanedCalls(input2);
36111
+ repairOrphanedCalls2(input2);
34113
36112
  const body = { model, input: input2, stream: req.stream, store: false };
34114
36113
  const instructions = systemText(req.system, "openai", note);
34115
36114
  if (instructions !== undefined && instructions.length > 0)
@@ -34138,7 +36137,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34138
36137
  }));
34139
36138
  }
34140
36139
  if (req.toolChoice !== undefined)
34141
- body.tool_choice = encodeToolChoice5(req.toolChoice);
36140
+ body.tool_choice = encodeToolChoice7(req.toolChoice);
34142
36141
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
34143
36142
  if (req.reasoning.mode === "budget") {
34144
36143
  degradations.push("openai:reasoning-budget-dropped");
@@ -34147,7 +36146,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34147
36146
  body.reasoning = { effort, summary: "auto" };
34148
36147
  }
34149
36148
  }
34150
- const key = suppliedKey(req) ?? cacheKey(req, instructions ?? "", input2[0]);
36149
+ const key = suppliedKey2(req) ?? cacheKey2(req, instructions ?? "", input2[0]);
34151
36150
  Object.assign(body, req.vendor?.openai ?? {});
34152
36151
  body.prompt_cache_key = key;
34153
36152
  return { body, degradations, cacheKey: key };
@@ -34159,14 +36158,14 @@ var API_URL3 = "https://api.openai.com/v1/responses";
34159
36158
  var openaiCodec = {
34160
36159
  buildRequest(input2) {
34161
36160
  const oauth = input2.credentials.accessToken !== null;
34162
- const { body, degradations, cacheKey: cacheKey2 } = toResponsesWire(input2.request, input2.model, { oauth });
36161
+ const { body, degradations, cacheKey: cacheKey3 } = toResponsesWire(input2.request, input2.model, { oauth });
34163
36162
  const protocol = [["Content-Type", "application/json"]];
34164
36163
  if (oauth) {
34165
36164
  protocol.push(["Authorization", `Bearer ${input2.credentials.accessToken}`]);
34166
36165
  const accountId = input2.credentials.providerData.accountId;
34167
36166
  if (typeof accountId === "string")
34168
36167
  protocol.push(["chatgpt-account-id", accountId]);
34169
- protocol.push(["session_id", cacheKey2]);
36168
+ protocol.push(["session_id", cacheKey3]);
34170
36169
  } else if (input2.credentials.apiKey !== null) {
34171
36170
  protocol.push(["Authorization", `Bearer ${input2.credentials.apiKey}`]);
34172
36171
  } else {
@@ -34201,6 +36200,8 @@ var ADAPTERS = {
34201
36200
  kimi: kimiAdapter,
34202
36201
  kilo: kiloAdapter,
34203
36202
  grok: grokAdapter,
36203
+ antigravity: antigravityAdapter,
36204
+ muse: museAdapter,
34204
36205
  custom: customAdapter
34205
36206
  };
34206
36207
  Object.setPrototypeOf(ADAPTERS, null);
@@ -35812,7 +37813,7 @@ import { join as join3 } from "path";
35812
37813
 
35813
37814
  // packages/plugin-api/src/version.ts
35814
37815
  var PLUGIN_API_VERSION = 3;
35815
- var DASHBOARD_SDK_VERSION = "0.1.6";
37816
+ var DASHBOARD_SDK_VERSION = "0.1.8";
35816
37817
  // packages/plugin-api/src/manifest.ts
35817
37818
  var CAPABILITIES = [
35818
37819
  "storage",
@@ -36250,7 +38251,7 @@ function createRefresher(deps) {
36250
38251
  };
36251
38252
  }
36252
38253
  // packages/control/src/pluginProviders.ts
36253
- function isRecord6(value) {
38254
+ function isRecord7(value) {
36254
38255
  return typeof value === "object" && value !== null && !Array.isArray(value);
36255
38256
  }
36256
38257
  function isNumber(value) {
@@ -36261,7 +38262,7 @@ function checkAt(ok, id, path, expected) {
36261
38262
  throw new Error(`provider ${id} descriptor: ${path} must be ${expected}`);
36262
38263
  }
36263
38264
  function checkLimits(id, path, value) {
36264
- checkAt(isRecord6(value), id, path, "an object");
38265
+ checkAt(isRecord7(value), id, path, "an object");
36265
38266
  const limits = value;
36266
38267
  checkAt(isNumber(limits.contextWindow), id, `${path}.contextWindow`, "a finite number");
36267
38268
  checkAt(isNumber(limits.maxOutputTokens), id, `${path}.maxOutputTokens`, "a finite number");
@@ -36279,19 +38280,19 @@ function checkDescriptor(id, record2) {
36279
38280
  }
36280
38281
  }
36281
38282
  const capabilities2 = record2.capabilities;
36282
- checkAt(isRecord6(capabilities2), id, "capabilities", "an object");
38283
+ checkAt(isRecord7(capabilities2), id, "capabilities", "an object");
36283
38284
  for (const flag of ["tools", "images", "reasoning"]) {
36284
38285
  const value = capabilities2[flag];
36285
38286
  checkAt(typeof value === "boolean", id, `capabilities.${flag}`, "a boolean");
36286
38287
  }
36287
38288
  const write = record2.writeOverInput;
36288
- checkAt(isRecord6(write), id, "writeOverInput", "an object");
38289
+ checkAt(isRecord7(write), id, "writeOverInput", "an object");
36289
38290
  for (const ttl of ["fiveMinute", "oneHour"]) {
36290
38291
  const value = write[ttl];
36291
38292
  checkAt(isNumber(value), id, `writeOverInput.${ttl}`, "a finite number");
36292
38293
  }
36293
38294
  const catalog2 = record2.catalog;
36294
- checkAt(isRecord6(catalog2), id, "catalog", "an object");
38295
+ checkAt(isRecord7(catalog2), id, "catalog", "an object");
36295
38296
  const entry = catalog2;
36296
38297
  checkAt(typeof entry.defaultModel === "string", id, "catalog.defaultModel", "a string");
36297
38298
  checkAt(Array.isArray(entry.authTypes), id, "catalog.authTypes", "an array");
@@ -36302,11 +38303,11 @@ function checkDescriptor(id, record2) {
36302
38303
  checkAt(Array.isArray(entry.models), id, "catalog.models", "an array");
36303
38304
  for (const [index, model] of entry.models.entries()) {
36304
38305
  const at = `catalog.models[${index}]`;
36305
- checkAt(isRecord6(model), id, at, "an object");
38306
+ checkAt(isRecord7(model), id, at, "an object");
36306
38307
  const choice = model;
36307
38308
  checkAt(typeof choice.id === "string", id, `${at}.id`, "a string");
36308
38309
  checkAt(typeof choice.label === "string", id, `${at}.label`, "a string");
36309
- checkAt(isRecord6(choice.pricing), id, `${at}.pricing`, "an object");
38310
+ checkAt(isRecord7(choice.pricing), id, `${at}.pricing`, "an object");
36310
38311
  const pricing = choice.pricing;
36311
38312
  for (const field of ["input", "output", "cacheRead", "cacheWrite5m", "cacheWrite1h"]) {
36312
38313
  checkAt(isNumber(pricing[field]), id, `${at}.pricing.${field}`, "a finite number");
@@ -36322,13 +38323,13 @@ function checkDescriptor(id, record2) {
36322
38323
  checkAt(typeof prefix === "string", id, `modelPrefixes[${index}]`, "a string");
36323
38324
  }
36324
38325
  const presentation = record2.presentation;
36325
- checkAt(isRecord6(presentation), id, "presentation", "an object");
38326
+ checkAt(isRecord7(presentation), id, "presentation", "an object");
36326
38327
  const shown = presentation;
36327
38328
  for (const field of ["label", "tone"]) {
36328
38329
  checkAt(typeof shown[field] === "string", id, `presentation.${field}`, "a string");
36329
38330
  }
36330
38331
  checkAt(isNumber(shown.order), id, "presentation.order", "a finite number");
36331
- checkAt(isRecord6(shown.colour), id, "presentation.colour", "an object");
38332
+ checkAt(isRecord7(shown.colour), id, "presentation.colour", "an object");
36332
38333
  for (const scheme of ["light", "dark"]) {
36333
38334
  const value = shown.colour[scheme];
36334
38335
  checkAt(typeof value === "string", id, `presentation.colour.${scheme}`, "a string");
@@ -36340,7 +38341,7 @@ function checkDescriptor(id, record2) {
36340
38341
  function validateOAuthFlow(id, value) {
36341
38342
  if (value === undefined)
36342
38343
  return;
36343
- if (!isRecord6(value))
38344
+ if (!isRecord7(value))
36344
38345
  throw new Error(`provider ${id} oauth must be an object`);
36345
38346
  const kind = value.kind;
36346
38347
  if (kind !== "pkce" && kind !== "device") {
@@ -37972,13 +39973,13 @@ function IsSeparator(pattern, index) {
37972
39973
  function IsGroup(pattern) {
37973
39974
  if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
37974
39975
  return false;
37975
- let count = 0;
39976
+ let count2 = 0;
37976
39977
  for (let index = 0;index < pattern.length; index++) {
37977
39978
  if (IsOpenParen(pattern, index))
37978
- count += 1;
39979
+ count2 += 1;
37979
39980
  if (IsCloseParen(pattern, index))
37980
- count -= 1;
37981
- if (count === 0 && index !== pattern.length - 1)
39981
+ count2 -= 1;
39982
+ if (count2 === 0 && index !== pattern.length - 1)
37982
39983
  return false;
37983
39984
  }
37984
39985
  return true;
@@ -37987,13 +39988,13 @@ function InGroup(pattern) {
37987
39988
  return pattern.slice(1, pattern.length - 1);
37988
39989
  }
37989
39990
  function IsPrecedenceOr(pattern) {
37990
- let count = 0;
39991
+ let count2 = 0;
37991
39992
  for (let index = 0;index < pattern.length; index++) {
37992
39993
  if (IsOpenParen(pattern, index))
37993
- count += 1;
39994
+ count2 += 1;
37994
39995
  if (IsCloseParen(pattern, index))
37995
- count -= 1;
37996
- if (IsSeparator(pattern, index) && count === 0)
39996
+ count2 -= 1;
39997
+ if (IsSeparator(pattern, index) && count2 === 0)
37997
39998
  return true;
37998
39999
  }
37999
40000
  return false;
@@ -38006,14 +40007,14 @@ function IsPrecedenceAnd(pattern) {
38006
40007
  return false;
38007
40008
  }
38008
40009
  function Or(pattern) {
38009
- let [count, start] = [0, 0];
40010
+ let [count2, start] = [0, 0];
38010
40011
  const expressions = [];
38011
40012
  for (let index = 0;index < pattern.length; index++) {
38012
40013
  if (IsOpenParen(pattern, index))
38013
- count += 1;
40014
+ count2 += 1;
38014
40015
  if (IsCloseParen(pattern, index))
38015
- count -= 1;
38016
- if (IsSeparator(pattern, index) && count === 0) {
40016
+ count2 -= 1;
40017
+ if (IsSeparator(pattern, index) && count2 === 0) {
38017
40018
  const range2 = pattern.slice(start, index);
38018
40019
  if (range2.length > 0)
38019
40020
  expressions.push(TemplateLiteralParse(range2));
@@ -38033,13 +40034,13 @@ function And(pattern) {
38033
40034
  function Group(value, index) {
38034
40035
  if (!IsOpenParen(value, index))
38035
40036
  throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
38036
- let count = 0;
40037
+ let count2 = 0;
38037
40038
  for (let scan = index;scan < value.length; scan++) {
38038
40039
  if (IsOpenParen(value, scan))
38039
- count += 1;
40040
+ count2 += 1;
38040
40041
  if (IsCloseParen(value, scan))
38041
- count -= 1;
38042
- if (count === 0)
40042
+ count2 -= 1;
40043
+ if (count2 === 0)
38043
40044
  return [index, scan];
38044
40045
  }
38045
40046
  throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
@@ -38809,8 +40810,8 @@ function FromNumberRight(left, right) {
38809
40810
  function FromNumber(left, right) {
38810
40811
  return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type.IsObject(right) ? FromObjectRight(left, right) : exports_type.IsRecord(right) ? FromRecordRight(left, right) : exports_type.IsInteger(right) || exports_type.IsNumber(right) ? ExtendsResult.True : ExtendsResult.False;
38811
40812
  }
38812
- function IsObjectPropertyCount(schema, count) {
38813
- return Object.getOwnPropertyNames(schema.properties).length === count;
40813
+ function IsObjectPropertyCount(schema, count2) {
40814
+ return Object.getOwnPropertyNames(schema.properties).length === count2;
38814
40815
  }
38815
40816
  function IsObjectStringLike(schema) {
38816
40817
  return IsObjectArrayLike(schema);
@@ -44279,7 +46280,7 @@ var emptySchema = {
44279
46280
 
44280
46281
  // node_modules/.bun/elysia@1.4.30+7c910760591f72db/node_modules/elysia/dist/error.mjs
44281
46282
  var env2 = typeof Bun < "u" ? Bun.env : typeof process < "u" ? process?.env : undefined;
44282
- var ERROR_CODE3 = Symbol("ElysiaErrorCode");
46283
+ var ERROR_CODE5 = Symbol("ElysiaErrorCode");
44283
46284
  var isProduction = (env2?.NODE_ENV ?? env2?.ENV) === "production";
44284
46285
  var emptyHttpStatus = {
44285
46286
  101: undefined,
@@ -48852,7 +50853,7 @@ c.defs=definitions
48852
50853
  schema: app.router.history,
48853
50854
  definitions: app.definitions.type,
48854
50855
  tee,
48855
- ERROR_CODE: ERROR_CODE3,
50856
+ ERROR_CODE: ERROR_CODE5,
48856
50857
  parseCookie: hasCookie ? parseCookie : undefined,
48857
50858
  signCookie: hasCookie ? signCookie : undefined,
48858
50859
  Cookie: hasCookie ? Cookie : undefined,
@@ -49125,7 +51126,7 @@ return mapResponse(${saveResponse}error,set${adapter.mapResponseContext})}`;
49125
51126
  return Function("inject", `"use strict";
49126
51127
  ` + fnLiteral)({
49127
51128
  mapResponse: app["~adapter"].handler.mapResponse,
49128
- ERROR_CODE: ERROR_CODE3,
51129
+ ERROR_CODE: ERROR_CODE5,
49129
51130
  ElysiaCustomStatusResponse,
49130
51131
  ValidationError,
49131
51132
  TransformDecodeError,
@@ -50608,12 +52609,12 @@ var _Elysia = class _Elysia2 {
50608
52609
  error(name, error61) {
50609
52610
  switch (typeof name) {
50610
52611
  case "string":
50611
- return error61.prototype[ERROR_CODE3] = name, this.definitions.error[name] = error61, this;
52612
+ return error61.prototype[ERROR_CODE5] = name, this.definitions.error[name] = error61, this;
50612
52613
  case "function":
50613
52614
  return this.definitions.error = name(this.definitions.error), this;
50614
52615
  }
50615
52616
  for (const [code, error210] of Object.entries(name))
50616
- error210.prototype[ERROR_CODE3] = code, this.definitions.error[code] = error210;
52617
+ error210.prototype[ERROR_CODE5] = code, this.definitions.error[code] = error210;
50617
52618
  return this;
50618
52619
  }
50619
52620
  onError(options, handler) {
@@ -50702,7 +52703,7 @@ var _Elysia = class _Elysia2 {
50702
52703
  scoped: [...this.standaloneValidator.scoped ?? []],
50703
52704
  global: [...this.standaloneValidator.global ?? []]
50704
52705
  };
50705
- const isSchema = typeof schemaOrRun == "object", sandbox = (isSchema ? run : schemaOrRun)(instance);
52706
+ const isSchema2 = typeof schemaOrRun == "object", sandbox = (isSchema2 ? run : schemaOrRun)(instance);
50706
52707
  return this.singleton = mergeDeep(this.singleton, instance.singleton), this.definitions = mergeDeep(this.definitions, instance.definitions), sandbox.event.request?.length && (this.event.request = [
50707
52708
  ...this.event.request || [],
50708
52709
  ...sandbox.event.request || []
@@ -50710,7 +52711,7 @@ var _Elysia = class _Elysia2 {
50710
52711
  ...this.event.mapResponse || [],
50711
52712
  ...sandbox.event.mapResponse || []
50712
52713
  ]), this.model(sandbox.definitions.type), Object.values(instance.router.history).forEach(({ method, path, handler, hooks }) => {
50713
- if (path = (isSchema ? "" : this.config.prefix ?? "") + prefix + path, isSchema) {
52714
+ if (path = (isSchema2 ? "" : this.config.prefix ?? "") + prefix + path, isSchema2) {
50714
52715
  const {
50715
52716
  body: body2,
50716
52717
  headers,
@@ -51575,9 +53576,9 @@ function createLoadRegistry(coord = memoryCoord()) {
51575
53576
  },
51576
53577
  counts() {
51577
53578
  const out = new Map(local);
51578
- for (const [key, count] of remote) {
51579
- if (count > (out.get(key) ?? 0))
51580
- out.set(key, count);
53579
+ for (const [key, count2] of remote) {
53580
+ if (count2 > (out.get(key) ?? 0))
53581
+ out.set(key, count2);
51581
53582
  }
51582
53583
  return out;
51583
53584
  },
@@ -51587,8 +53588,8 @@ function createLoadRegistry(coord = memoryCoord()) {
51587
53588
  async refresh() {
51588
53589
  const held = await coord.gauge.snapshot(PREFIX6);
51589
53590
  const sample = new Map;
51590
- for (const [key, count] of held)
51591
- sample.set(key.slice(PREFIX6.length), count);
53591
+ for (const [key, count2] of held)
53592
+ sample.set(key.slice(PREFIX6.length), count2);
51592
53593
  remote = sample;
51593
53594
  }
51594
53595
  };
@@ -51664,7 +53665,7 @@ function createRoutingSnapshotCache(store, logger2 = noopLogger) {
51664
53665
  }
51665
53666
 
51666
53667
  // apps/gateway/src/egress/anthropic.ts
51667
- var STOP_REASON2 = {
53668
+ var STOP_REASON3 = {
51668
53669
  endTurn: "end_turn",
51669
53670
  maxTokens: "max_tokens",
51670
53671
  stopSequence: "stop_sequence",
@@ -51761,7 +53762,7 @@ async function* anthropicStream(events, requestId) {
51761
53762
  case "end":
51762
53763
  yield frame("message_delta", {
51763
53764
  type: "message_delta",
51764
- delta: { stop_reason: STOP_REASON2[event.stopReason], stop_sequence: null },
53765
+ delta: { stop_reason: STOP_REASON3[event.stopReason], stop_sequence: null },
51765
53766
  usage: {
51766
53767
  input_tokens: event.usage.inputTokens,
51767
53768
  output_tokens: event.usage.outputTokens,
@@ -51804,7 +53805,7 @@ function anthropicResponse(collected, requestId) {
51804
53805
  return { type: "text", text: "" };
51805
53806
  }
51806
53807
  }),
51807
- stop_reason: STOP_REASON2[collected.stopReason],
53808
+ stop_reason: STOP_REASON3[collected.stopReason],
51808
53809
  stop_sequence: null,
51809
53810
  usage: {
51810
53811
  input_tokens: collected.usage.inputTokens,
@@ -52432,7 +54433,7 @@ function zodDetail(issue2) {
52432
54433
  }
52433
54434
  return issue2.message;
52434
54435
  }
52435
- function isRecord7(value) {
54436
+ function isRecord8(value) {
52436
54437
  return typeof value === "object" && value !== null;
52437
54438
  }
52438
54439
  function extraFields(body2, known) {
@@ -52567,7 +54568,7 @@ async function readJson(request2) {
52567
54568
  }
52568
54569
  async function readJsonRecord(request2) {
52569
54570
  const body2 = await readJson(request2);
52570
- return isRecord7(body2) ? body2 : null;
54571
+ return isRecord8(body2) ? body2 : null;
52571
54572
  }
52572
54573
  function apiErrorResponse(error61) {
52573
54574
  const gatewayError = error61 instanceof GatewayError ? error61 : new GatewayError("INTERNAL", "internal error");
@@ -53807,10 +55808,10 @@ function classifyGrep(executable, args) {
53807
55808
  else if (argument === "-n" || argument === "--line-number")
53808
55809
  lineNumber = true;
53809
55810
  else if (["-C", "-A", "-B", "--context", "--after-context", "--before-context"].includes(argument)) {
53810
- const count = args[++index];
53811
- if (count === undefined || !/^\d+$/.test(count))
55811
+ const count2 = args[++index];
55812
+ if (count2 === undefined || !/^\d+$/.test(count2))
53812
55813
  return;
53813
- const value = Number(count);
55814
+ const value = Number(count2);
53814
55815
  if (argument === "-C" || argument === "--context") {
53815
55816
  beforeContext = value;
53816
55817
  afterContext = value;
@@ -54032,12 +56033,12 @@ class ParserBudget {
54032
56033
  constructor(inputCodeUnits) {
54033
56034
  this.inputCodeUnits = inputCodeUnits;
54034
56035
  }
54035
- chargeRecords(count) {
54036
- this.records += count;
56036
+ chargeRecords(count2) {
56037
+ this.records += count2;
54037
56038
  return this.records <= 1e5;
54038
56039
  }
54039
- chargeCodeUnits(count) {
54040
- this.codeUnits += count;
56040
+ chargeCodeUnits(count2) {
56041
+ this.codeUnits += count2;
54041
56042
  return this.codeUnits <= this.inputCodeUnits * 3;
54042
56043
  }
54043
56044
  }
@@ -54096,8 +56097,8 @@ function renderSelection(input2, selected, unit = "lines") {
54096
56097
  return renderGaps(input2, selected, (start, end) => `... ${end - start + 1} ${unit} omitted ...`);
54097
56098
  }
54098
56099
  function selectBlock(input2, selected, block) {
54099
- const count = block.end - block.start + 1;
54100
- if (!input2.budget.chargeRecords(count))
56100
+ const count2 = block.end - block.start + 1;
56101
+ if (!input2.budget.chargeRecords(count2))
54101
56102
  return false;
54102
56103
  for (let index = block.start;index <= block.end; index++)
54103
56104
  selected.add(index);
@@ -54421,8 +56422,8 @@ function renderGroups(input2, groups) {
54421
56422
  return;
54422
56423
  }
54423
56424
  if (group.entryCount > 12) {
54424
- const count = group.entryCount - 12;
54425
- if (!append(`... ${count} ${count === 1 ? "entry" : "entries"} omitted from ${group.key} ...`))
56425
+ const count2 = group.entryCount - 12;
56426
+ if (!append(`... ${count2} ${count2 === 1 ? "entry" : "entries"} omitted from ${group.key} ...`))
54426
56427
  return;
54427
56428
  }
54428
56429
  }
@@ -54445,12 +56446,12 @@ function subtreeCounts(input2, node2, classified) {
54445
56446
  let entries = 0;
54446
56447
  let ambiguous = false;
54447
56448
  for (const child of node2.children) {
54448
- const count = subtreeCounts(input2, child, classified);
54449
- if (count === undefined)
56449
+ const count2 = subtreeCounts(input2, child, classified);
56450
+ if (count2 === undefined)
54450
56451
  return;
54451
- directories += count.directories;
54452
- entries += count.entries;
54453
- ambiguous ||= count.ambiguous;
56452
+ directories += count2.directories;
56453
+ entries += count2.entries;
56454
+ ambiguous ||= count2.ambiguous;
54454
56455
  }
54455
56456
  return { directories, entries, ambiguous };
54456
56457
  }
@@ -54470,12 +56471,12 @@ function appendSubtree(input2, output2, node2, classified) {
54470
56471
  let entries = 0;
54471
56472
  let ambiguous = false;
54472
56473
  for (const child of omitted) {
54473
- const count = subtreeCounts(input2, child, classified);
54474
- if (count === undefined)
56474
+ const count2 = subtreeCounts(input2, child, classified);
56475
+ if (count2 === undefined)
54475
56476
  return false;
54476
- directories += count.directories;
54477
- entries += count.entries;
54478
- ambiguous ||= count.ambiguous;
56477
+ directories += count2.directories;
56478
+ entries += count2.entries;
56479
+ ambiguous ||= count2.ambiguous;
54479
56480
  }
54480
56481
  if (ambiguous)
54481
56482
  return false;
@@ -55153,8 +57154,8 @@ function compressTests(input2, executable = "unknown") {
55153
57154
  break;
55154
57155
  end++;
55155
57156
  }
55156
- const count = end - start + 1;
55157
- if (!input2.budget.chargeRecords(count))
57157
+ const count2 = end - start + 1;
57158
+ if (!input2.budget.chargeRecords(count2))
55158
57159
  return text;
55159
57160
  for (let index = start;index <= end; index++)
55160
57161
  selected.add(index);
@@ -56807,10 +58808,10 @@ function toIrToolChoice(c) {
56807
58808
  }
56808
58809
  var EFFORTS = REASONING_EFFORTS;
56809
58810
  function readEffort(body2) {
56810
- if (!isRecord7(body2))
58811
+ if (!isRecord8(body2))
56811
58812
  return;
56812
58813
  const outputConfig = body2.output_config;
56813
- if (!isRecord7(outputConfig))
58814
+ if (!isRecord8(outputConfig))
56814
58815
  return;
56815
58816
  const effort = outputConfig.effort;
56816
58817
  return EFFORTS.find((level) => level === effort);
@@ -57105,7 +59106,7 @@ function parseOpenAIRequest(body2, headers) {
57105
59106
  }
57106
59107
 
57107
59108
  // apps/gateway/src/ingress/responses.ts
57108
- import { createHash as createHash5 } from "crypto";
59109
+ import { createHash as createHash7 } from "crypto";
57109
59110
  var reasoning = exports_external.object({
57110
59111
  effort: exports_external.enum(REASONING_EFFORTS).optional(),
57111
59112
  summary: exports_external.string().optional()
@@ -57171,7 +59172,7 @@ function toIrReasoning2(r) {
57171
59172
  };
57172
59173
  }
57173
59174
  function clampCallId(raw) {
57174
- return raw.length <= 64 ? raw : createHash5("sha256").update(raw).digest("hex");
59175
+ return raw.length <= 64 ? raw : createHash7("sha256").update(raw).digest("hex");
57175
59176
  }
57176
59177
  function roleOf(raw) {
57177
59178
  if (raw === "assistant")
@@ -57181,7 +59182,7 @@ function roleOf(raw) {
57181
59182
  return "user";
57182
59183
  }
57183
59184
  function contentPart(part2) {
57184
- if (!isRecord7(part2))
59185
+ if (!isRecord8(part2))
57185
59186
  throw new GatewayError("BAD_REQUEST", "input: content part must be an object");
57186
59187
  const type = part2.type;
57187
59188
  if (type === "input_text" || type === "output_text") {
@@ -57221,7 +59222,7 @@ function readInputItems(items) {
57221
59222
  messages.push({ role, content });
57222
59223
  };
57223
59224
  for (const raw of items) {
57224
- if (!isRecord7(raw))
59225
+ if (!isRecord8(raw))
57225
59226
  throw new GatewayError("BAD_REQUEST", "input: item must be an object");
57226
59227
  const type = raw.type ?? (raw.role === undefined ? undefined : "message");
57227
59228
  switch (type) {
@@ -57277,7 +59278,7 @@ function jsonArguments(raw, callId) {
57277
59278
  const text = typeof raw === "string" ? raw : "";
57278
59279
  try {
57279
59280
  const parsed2 = text === "" ? {} : JSON.parse(text);
57280
- return isRecord7(parsed2) ? parsed2 : { value: parsed2 };
59281
+ return isRecord8(parsed2) ? parsed2 : { value: parsed2 };
57281
59282
  } catch {
57282
59283
  throw new GatewayError("BAD_REQUEST", `input: arguments for call ${safeToken(callId)} are not valid JSON`);
57283
59284
  }
@@ -57286,7 +59287,7 @@ var TOOL_NAME = /^[A-Za-z0-9_-]{1,128}$/;
57286
59287
  function readTools(raw) {
57287
59288
  const tools2 = [];
57288
59289
  for (const entry of raw) {
57289
- if (!isRecord7(entry))
59290
+ if (!isRecord8(entry))
57290
59291
  throw new GatewayError("BAD_REQUEST", "tools: each tool must be an object");
57291
59292
  const type = typeof entry.type === "string" ? entry.type : "";
57292
59293
  const declared = typeof entry.name === "string" ? entry.name : "";
@@ -57299,7 +59300,7 @@ function readTools(raw) {
57299
59300
  kind: "portable",
57300
59301
  name: declared,
57301
59302
  ...description === undefined ? {} : { description },
57302
- inputSchema: type === "custom" ? { type: "object", properties: { input: { type: "string" } }, required: ["input"] } : isRecord7(entry.parameters) ? entry.parameters : { type: "object" }
59303
+ inputSchema: type === "custom" ? { type: "object", properties: { input: { type: "string" } }, required: ["input"] } : isRecord8(entry.parameters) ? entry.parameters : { type: "object" }
57303
59304
  });
57304
59305
  continue;
57305
59306
  }
@@ -57314,10 +59315,10 @@ function readTools(raw) {
57314
59315
  }
57315
59316
  function customToolNames(body2) {
57316
59317
  const names = new Set;
57317
- if (!isRecord7(body2) || !Array.isArray(body2.tools))
59318
+ if (!isRecord8(body2) || !Array.isArray(body2.tools))
57318
59319
  return names;
57319
59320
  for (const entry of body2.tools) {
57320
- if (isRecord7(entry) && entry.type === "custom" && typeof entry.name === "string") {
59321
+ if (isRecord8(entry) && entry.type === "custom" && typeof entry.name === "string") {
57321
59322
  names.add(entry.name);
57322
59323
  }
57323
59324
  }
@@ -57956,11 +59957,11 @@ function topicClass(topic) {
57956
59957
  return null;
57957
59958
  }
57958
59959
  var MAX_TOPIC = 128;
57959
- function isRecord8(value) {
59960
+ function isRecord9(value) {
57960
59961
  return typeof value === "object" && value !== null && !Array.isArray(value);
57961
59962
  }
57962
59963
  function parseClientFrame(raw) {
57963
- if (!isRecord8(raw))
59964
+ if (!isRecord9(raw))
57964
59965
  return null;
57965
59966
  const { id, type, topic } = raw;
57966
59967
  if (id !== undefined && typeof id !== "string")
@@ -58166,16 +60167,16 @@ function createChannelRegistry(deps) {
58166
60167
  cancelReport = undefined;
58167
60168
  if (!live)
58168
60169
  return;
58169
- for (const [pluginId, count] of dropsSinceReport) {
58170
- logger2.warn("plugin channel broadcast dropped", { plugin: pluginId, count });
60170
+ for (const [pluginId, count2] of dropsSinceReport) {
60171
+ logger2.warn("plugin channel broadcast dropped", { plugin: pluginId, count: count2 });
58171
60172
  }
58172
60173
  dropsSinceReport.clear();
58173
- for (const [pluginId, count] of unencodableSinceReport) {
58174
- logger2.warn("plugin channel payload could not be serialised", { plugin: pluginId, count });
60174
+ for (const [pluginId, count2] of unencodableSinceReport) {
60175
+ logger2.warn("plugin channel payload could not be serialised", { plugin: pluginId, count: count2 });
58175
60176
  }
58176
60177
  unencodableSinceReport.clear();
58177
- for (const [pluginId, count] of errorsSinceReport) {
58178
- logger2.warn("plugin channel handler failed", { plugin: pluginId, count });
60178
+ for (const [pluginId, count2] of errorsSinceReport) {
60179
+ logger2.warn("plugin channel handler failed", { plugin: pluginId, count: count2 });
58179
60180
  }
58180
60181
  errorsSinceReport.clear();
58181
60182
  };
@@ -58643,7 +60644,7 @@ function createRing(limits) {
58643
60644
  }
58644
60645
 
58645
60646
  // apps/gateway/src/version.ts
58646
- var VERSION = "0.9.2";
60647
+ var VERSION = "0.10.1";
58647
60648
 
58648
60649
  // apps/gateway/src/app.ts
58649
60650
  var ADMIN_SESSION_TTL_MS = 12 * 60 * 60 * 1000;
@@ -59397,9 +61398,9 @@ function startMaintenance(deps) {
59397
61398
  });
59398
61399
  }, SWEEP_INTERVAL_MS2);
59399
61400
  const prune = async () => {
59400
- await deps.store.usage.sweepPending(deps.now()).then((count) => {
59401
- if (count > 0)
59402
- logger2.info("retired interrupted requests", { count });
61401
+ await deps.store.usage.sweepPending(deps.now()).then((count2) => {
61402
+ if (count2 > 0)
61403
+ logger2.info("retired interrupted requests", { count: count2 });
59403
61404
  }).catch((error61) => {
59404
61405
  logger2.error("pending sweep failed", { reason: describeError(error61, "unknown") });
59405
61406
  });
@@ -59524,8 +61525,8 @@ function createPluginEventBus(opts) {
59524
61525
  }
59525
61526
  }
59526
61527
  }
59527
- for (const [pluginId, count] of errorsSinceReport) {
59528
- logger2.warn("plugin event handler failed", { plugin: pluginId, count });
61528
+ for (const [pluginId, count2] of errorsSinceReport) {
61529
+ logger2.warn("plugin event handler failed", { plugin: pluginId, count: count2 });
59529
61530
  }
59530
61531
  errorsSinceReport.clear();
59531
61532
  if (droppedSinceReport > 0) {
@@ -60367,9 +62368,9 @@ function createTelemetry(opts) {
60367
62368
  breaker(provider, before, after) {
60368
62369
  if (!opts.metricsEnabled || before === after)
60369
62370
  return;
60370
- const count = Math.max(0, (openBreakers.get(provider) ?? 0) + (after === "open" ? 1 : before === "open" ? -1 : 0));
60371
- openBreakers.set(provider, count);
60372
- registry2.set("omni_breaker_open", { provider }, count);
62371
+ const count2 = Math.max(0, (openBreakers.get(provider) ?? 0) + (after === "open" ? 1 : before === "open" ? -1 : 0));
62372
+ openBreakers.set(provider, count2);
62373
+ registry2.set("omni_breaker_open", { provider }, count2);
60373
62374
  },
60374
62375
  rateLimit(dimension, window2) {
60375
62376
  if (opts.metricsEnabled)