omnigateway 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/bin/omni.js +1754 -113
  2. package/gateway.js +1831 -194
  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,144 @@ 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 FREE = { input: 0, output: 0, cacheRead: 0, cacheWrite5m: 0, cacheWrite1h: 0 };
28977
+ var FLASH_LIMITS = { contextWindow: 1048576, maxOutputTokens: MAX_OUTPUT_TOKENS };
28978
+ var PRO_LIMITS = { contextWindow: 1048576, maxOutputTokens: PRO_MAX_OUTPUT_TOKENS };
28979
+ var ANTIGRAVITY_MODELS = {
28980
+ defaultModel: "gemini-3.8-flash-high",
28981
+ authTypes: ["oauth"],
28982
+ models: [
28983
+ {
28984
+ id: "gemini-3.8-flash-high",
28985
+ label: "Gemini 3.8 Flash (High)",
28986
+ pricing: FREE,
28987
+ limits: FLASH_LIMITS
28988
+ },
28989
+ {
28990
+ id: "gemini-3.8-flash-medium",
28991
+ label: "Gemini 3.8 Flash (Medium)",
28992
+ pricing: FREE,
28993
+ limits: FLASH_LIMITS
28994
+ },
28995
+ {
28996
+ id: "gemini-3.8-flash-low",
28997
+ label: "Gemini 3.8 Flash (Low)",
28998
+ pricing: FREE,
28999
+ limits: FLASH_LIMITS
29000
+ },
29001
+ {
29002
+ id: "gemini-3.7-flash-high",
29003
+ label: "Gemini 3.7 Flash (High)",
29004
+ pricing: FREE,
29005
+ limits: FLASH_LIMITS
29006
+ },
29007
+ {
29008
+ id: "gemini-3.7-flash-medium",
29009
+ label: "Gemini 3.7 Flash (Medium)",
29010
+ pricing: FREE,
29011
+ limits: FLASH_LIMITS
29012
+ },
29013
+ {
29014
+ id: "gemini-3.7-flash-low",
29015
+ label: "Gemini 3.7 Flash (Low)",
29016
+ pricing: FREE,
29017
+ limits: FLASH_LIMITS
29018
+ },
29019
+ {
29020
+ id: "gemini-3.6-flash-high",
29021
+ label: "Gemini 3.6 Flash (High)",
29022
+ pricing: FREE,
29023
+ limits: FLASH_LIMITS
29024
+ },
29025
+ {
29026
+ id: "gemini-3.6-flash-medium",
29027
+ label: "Gemini 3.6 Flash (Medium)",
29028
+ pricing: FREE,
29029
+ limits: FLASH_LIMITS
29030
+ },
29031
+ {
29032
+ id: "gemini-3.6-flash-low",
29033
+ label: "Gemini 3.6 Flash (Low)",
29034
+ pricing: FREE,
29035
+ limits: FLASH_LIMITS
29036
+ },
29037
+ {
29038
+ id: "gemini-3-flash-agent",
29039
+ label: "Gemini 3.5 Flash (High)",
29040
+ pricing: FREE,
29041
+ limits: FLASH_LIMITS
29042
+ },
29043
+ {
29044
+ id: "gemini-3.5-flash-low",
29045
+ label: "Gemini 3.5 Flash (Medium)",
29046
+ pricing: FREE,
29047
+ limits: FLASH_LIMITS
29048
+ },
29049
+ {
29050
+ id: "gemini-3.5-flash-extra-low",
29051
+ label: "Gemini 3.5 Flash (Low)",
29052
+ pricing: FREE,
29053
+ limits: FLASH_LIMITS
29054
+ },
29055
+ {
29056
+ id: "gemini-3-flash",
29057
+ label: "Gemini 3 Flash",
29058
+ pricing: FREE,
29059
+ limits: FLASH_LIMITS
29060
+ },
29061
+ {
29062
+ id: "gemini-3.5-flash-lite",
29063
+ label: "Gemini 3.5 Flash Lite",
29064
+ pricing: FREE,
29065
+ limits: PRO_LIMITS
29066
+ },
29067
+ {
29068
+ id: "gemini-3.1-pro-high",
29069
+ label: "Gemini 3.1 Pro (High)",
29070
+ pricing: FREE,
29071
+ limits: PRO_LIMITS
29072
+ },
29073
+ {
29074
+ id: "gemini-3.1-pro-low",
29075
+ label: "Gemini 3.1 Pro (Low)",
29076
+ pricing: FREE,
29077
+ limits: PRO_LIMITS
29078
+ },
29079
+ {
29080
+ id: "gemini-3.1-flash-lite",
29081
+ label: "Gemini 3.1 Flash Lite",
29082
+ pricing: FREE,
29083
+ limits: PRO_LIMITS
29084
+ },
29085
+ {
29086
+ id: "gemini-2.5-pro",
29087
+ label: "Gemini 2.5 Pro",
29088
+ pricing: FREE,
29089
+ limits: PRO_LIMITS
29090
+ }
29091
+ ]
29092
+ };
29093
+
29094
+ // packages/providers/src/antigravity/descriptor.ts
29095
+ var antigravityDescriptor = {
29096
+ id: "antigravity",
29097
+ capabilities: { tools: true, images: true, reasoning: true },
29098
+ writeOverInput: { fiveMinute: 0, oneHour: 0 },
29099
+ catalog: ANTIGRAVITY_MODELS,
29100
+ modelPrefixes: ["gemini-"],
29101
+ callback: { uri: "http://127.0.0.1:51121/callback", label: "Antigravity" },
29102
+ presentation: {
29103
+ label: "Antigravity",
29104
+ order: 6,
29105
+ tone: "violet",
29106
+ colour: { light: "oklch(0.52 0.14 277)", dark: "oklch(0.74 0.14 277)" },
29107
+ 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."
29108
+ }
29109
+ };
29110
+
28967
29111
  // packages/providers/src/custom/models.ts
28968
29112
  var CUSTOM_MODELS = {
28969
29113
  defaultModel: "",
@@ -28980,7 +29124,7 @@ var customDescriptor = {
28980
29124
  modelPrefixes: [],
28981
29125
  presentation: {
28982
29126
  label: "OpenAI Compatible",
28983
- order: 6,
29127
+ order: 8,
28984
29128
  tone: "cyan",
28985
29129
  colour: { light: "oklch(0.5 0.03 258)", dark: "oklch(0.72 0.03 258)" },
28986
29130
  pasteHint: "Enter endpoint metadata and API key."
@@ -29305,35 +29449,90 @@ var kimiDescriptor = {
29305
29449
  }
29306
29450
  };
29307
29451
 
29452
+ // packages/providers/src/muse/models.ts
29453
+ var MUSE_MODELS = {
29454
+ defaultModel: "muse-spark-1.3",
29455
+ authTypes: ["oauth", "apiKey"],
29456
+ models: [
29457
+ {
29458
+ id: "muse-spark-1.3",
29459
+ label: "Muse Spark 1.3",
29460
+ pricing: { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite5m: 0, cacheWrite1h: 0 },
29461
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29462
+ },
29463
+ {
29464
+ id: "muse-spark-1.3-contributor",
29465
+ label: "Muse Spark 1.3 \u2014 Meta trains on this traffic",
29466
+ pricing: { input: 0.1, output: 0.2, cacheRead: 0.002, cacheWrite5m: 0, cacheWrite1h: 0 },
29467
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29468
+ },
29469
+ {
29470
+ id: "muse-spark-1.2",
29471
+ label: "Muse Spark 1.2",
29472
+ pricing: { input: 1.25, output: 4.25, cacheRead: 0.15, cacheWrite5m: 0, cacheWrite1h: 0 },
29473
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29474
+ },
29475
+ {
29476
+ id: "muse-spark-1.2-contributor",
29477
+ label: "Muse Spark 1.2 \u2014 Meta trains on this traffic",
29478
+ pricing: { input: 0.1, output: 0.2, cacheRead: 0.002, cacheWrite5m: 0, cacheWrite1h: 0 },
29479
+ limits: { contextWindow: 1048576, maxOutputTokens: 943718 }
29480
+ }
29481
+ ]
29482
+ };
29483
+
29484
+ // packages/providers/src/muse/descriptor.ts
29485
+ var museDescriptor = {
29486
+ id: "muse",
29487
+ capabilities: { tools: true, images: true, reasoning: true },
29488
+ writeOverInput: { fiveMinute: 0, oneHour: 0 },
29489
+ catalog: MUSE_MODELS,
29490
+ modelPrefixes: ["muse-", "muse-spark"],
29491
+ presentation: {
29492
+ label: "Muse",
29493
+ order: 7,
29494
+ tone: "azure",
29495
+ colour: { light: "oklch(0.55 0.23 262)", dark: "oklch(0.72 0.17 262)" },
29496
+ pasteHint: "Enter the code on Meta's device page. This dialog finishes on its own."
29497
+ }
29498
+ };
29499
+
29308
29500
  // packages/providers/src/openai/models.ts
29309
29501
  var OPENAI_MODELS = {
29310
29502
  defaultModel: "gpt-5.6",
29311
29503
  authTypes: ["oauth", "apiKey"],
29312
29504
  models: [
29505
+ {
29506
+ id: "gpt-6-astra",
29507
+ label: "GPT-6 Astra",
29508
+ pricing: { input: 10, output: 50, cacheRead: 1, cacheWrite5m: 0, cacheWrite1h: 0 },
29509
+ limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29510
+ oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29511
+ },
29313
29512
  {
29314
29513
  id: "gpt-5.6",
29315
29514
  label: "GPT-5.6 \u2014 routes to Sol",
29316
- pricing: { input: 5, output: 30, cacheRead: 0.5, cacheWrite5m: 0, cacheWrite1h: 0 },
29515
+ pricing: { input: 4, output: 20, cacheRead: 0.4, cacheWrite5m: 0, cacheWrite1h: 0 },
29317
29516
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29318
29517
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29319
29518
  },
29320
29519
  {
29321
29520
  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 },
29521
+ label: "GPT-5.6 Sol",
29522
+ pricing: { input: 4, output: 20, cacheRead: 0.4, cacheWrite5m: 0, cacheWrite1h: 0 },
29324
29523
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29325
29524
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29326
29525
  },
29327
29526
  {
29328
29527
  id: "gpt-5.6-terra",
29329
- label: "GPT-5.6 Terra \u2014 balanced",
29528
+ label: "GPT-5.6 Terra",
29330
29529
  pricing: { input: 2, output: 12, cacheRead: 0.2, cacheWrite5m: 0, cacheWrite1h: 0 },
29331
29530
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29332
29531
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
29333
29532
  },
29334
29533
  {
29335
29534
  id: "gpt-5.6-luna",
29336
- label: "GPT-5.6 Luna \u2014 fastest",
29535
+ label: "GPT-5.6 Luna",
29337
29536
  pricing: { input: 0.2, output: 1.2, cacheRead: 0.02, cacheWrite5m: 0, cacheWrite1h: 0 },
29338
29537
  limits: { contextWindow: 922000, maxOutputTokens: 128000 },
29339
29538
  oauthLimits: { contextWindow: 272000, maxOutputTokens: 128000 }
@@ -29371,6 +29570,8 @@ var PROVIDER_DESCRIPTORS = {
29371
29570
  kimi: kimiDescriptor,
29372
29571
  kilo: kiloDescriptor,
29373
29572
  grok: grokDescriptor,
29573
+ antigravity: antigravityDescriptor,
29574
+ muse: museDescriptor,
29374
29575
  custom: customDescriptor
29375
29576
  };
29376
29577
  Object.setPrototypeOf(PROVIDER_DESCRIPTORS, null);
@@ -29909,6 +30110,38 @@ var anthropicBodyOrder = [
29909
30110
  "stream"
29910
30111
  ];
29911
30112
 
30113
+ // packages/providers/src/antigravity/profile.ts
30114
+ var ANTIGRAVITY_IDE_VERSION = env("OMNI_ANTIGRAVITY_IDE_VERSION", "2.12.2");
30115
+ var PLATFORM = "darwin/arm64";
30116
+ var antigravityProfile = {
30117
+ headers: [
30118
+ [
30119
+ "User-Agent",
30120
+ env("OMNI_UA_ANTIGRAVITY", `antigravity/ide/${ANTIGRAVITY_IDE_VERSION} ${PLATFORM}`)
30121
+ ],
30122
+ ["Content-Type", "application/json"],
30123
+ ["Accept", "text/event-stream"]
30124
+ ],
30125
+ order: envOrder("OMNI_ORDER_ANTIGRAVITY", [
30126
+ "Host",
30127
+ "Content-Type",
30128
+ "Authorization",
30129
+ "User-Agent",
30130
+ "X-Goog-Api-Client",
30131
+ "Accept",
30132
+ "Accept-Encoding",
30133
+ "Content-Length"
30134
+ ])
30135
+ };
30136
+ var antigravityBodyOrder = [
30137
+ "project",
30138
+ "requestId",
30139
+ "model",
30140
+ "userAgent",
30141
+ "requestType",
30142
+ "request"
30143
+ ];
30144
+
29912
30145
  // packages/providers/src/custom/profile.ts
29913
30146
  var customProfile = { headers: [], order: [] };
29914
30147
  var customBodyOrder = [];
@@ -30030,6 +30263,43 @@ var kimiBodyOrder = [
30030
30263
  "stream"
30031
30264
  ];
30032
30265
 
30266
+ // packages/providers/src/muse/profile.ts
30267
+ var MUSE_CLI_VERSION = env("OMNI_MUSE_CLI_VERSION", "1.0.3");
30268
+ var museProfile = {
30269
+ headers: [
30270
+ ["User-Agent", env("OMNI_UA_MUSE", `muse-code/${MUSE_CLI_VERSION}`)],
30271
+ ["x-api-version", env("OMNI_MUSE_API_VERSION", "1.0.0")],
30272
+ ["Accept", "text/event-stream"]
30273
+ ],
30274
+ order: envOrder("OMNI_ORDER_MUSE", [
30275
+ "Host",
30276
+ "Content-Type",
30277
+ "Authorization",
30278
+ "x-meta-ai-gateway-session-id",
30279
+ "x-api-version",
30280
+ "Accept",
30281
+ "User-Agent",
30282
+ "Accept-Encoding",
30283
+ "Content-Length"
30284
+ ])
30285
+ };
30286
+ var museBodyOrder = [
30287
+ "model",
30288
+ "stream",
30289
+ "input",
30290
+ "instructions",
30291
+ "store",
30292
+ "reasoning",
30293
+ "prompt_cache_key",
30294
+ "max_output_tokens",
30295
+ "temperature",
30296
+ "tools",
30297
+ "tool_choice",
30298
+ "include",
30299
+ "parallel_tool_calls",
30300
+ "metadata"
30301
+ ];
30302
+
30033
30303
  // packages/providers/src/openai/profile.ts
30034
30304
  var OPENAI_CLI_VERSION = env("OMNI_OPENAI_CLI_VERSION", "0.144.1");
30035
30305
  var OPENAI_UA_PLATFORM = env("OMNI_OPENAI_UA_PLATFORM", "Windows 10.0.26200");
@@ -30086,6 +30356,8 @@ var BODY_ORDER = {
30086
30356
  kimi: kimiBodyOrder,
30087
30357
  kilo: kiloBodyOrder,
30088
30358
  grok: grokBodyOrder,
30359
+ antigravity: antigravityBodyOrder,
30360
+ muse: museBodyOrder,
30089
30361
  custom: customBodyOrder
30090
30362
  };
30091
30363
  Object.setPrototypeOf(BODY_ORDER, null);
@@ -30179,6 +30451,8 @@ var PROVIDER_MODEL_CATALOG = {
30179
30451
  kimi: KIMI_MODELS,
30180
30452
  kilo: KILO_MODELS,
30181
30453
  grok: GROK_MODELS,
30454
+ antigravity: ANTIGRAVITY_MODELS,
30455
+ muse: MUSE_MODELS,
30182
30456
  custom: CUSTOM_MODELS
30183
30457
  };
30184
30458
  Object.setPrototypeOf(PROVIDER_MODEL_CATALOG, null);
@@ -30209,6 +30483,8 @@ var PROFILES = {
30209
30483
  kimi: kimiProfile,
30210
30484
  kilo: kiloProfile,
30211
30485
  grok: grokProfile,
30486
+ antigravity: antigravityProfile,
30487
+ muse: museProfile,
30212
30488
  custom: customProfile
30213
30489
  };
30214
30490
  Object.setPrototypeOf(PROFILES, null);
@@ -31493,6 +31769,751 @@ var anthropicOAuthFlow = {
31493
31769
  return parseAnthropicUsage(parsed(res.body), now());
31494
31770
  }
31495
31771
  };
31772
+ // packages/providers/src/antigravity/codec.ts
31773
+ import { createHash as createHash2 } from "crypto";
31774
+
31775
+ // packages/providers/src/antigravity/decode.ts
31776
+ var STOP_REASON2 = {
31777
+ STOP: "endTurn",
31778
+ MAX_TOKENS: "maxTokens",
31779
+ SAFETY: "contentFilter",
31780
+ PROHIBITED_CONTENT: "contentFilter",
31781
+ SPII: "contentFilter",
31782
+ BLOCKLIST: "contentFilter",
31783
+ RECITATION: "contentFilter"
31784
+ };
31785
+ var ERROR_CODE = {
31786
+ RESOURCE_EXHAUSTED: "RATE_LIMIT",
31787
+ UNAUTHENTICATED: "AUTH",
31788
+ PERMISSION_DENIED: "AUTH",
31789
+ INVALID_ARGUMENT: "BAD_REQUEST",
31790
+ FAILED_PRECONDITION: "BAD_REQUEST",
31791
+ UNAVAILABLE: "UPSTREAM",
31792
+ INTERNAL: "UPSTREAM",
31793
+ DEADLINE_EXCEEDED: "TIMEOUT"
31794
+ };
31795
+ function json3(data) {
31796
+ try {
31797
+ const value = JSON.parse(data);
31798
+ return typeof value === "object" && value !== null ? value : null;
31799
+ } catch {
31800
+ return null;
31801
+ }
31802
+ }
31803
+ function count(value) {
31804
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
31805
+ }
31806
+ function usageOf(meta3) {
31807
+ return usageFromPromptTotal(count(meta3?.promptTokenCount), count(meta3?.candidatesTokenCount) + count(meta3?.thoughtsTokenCount), count(meta3?.cachedContentTokenCount));
31808
+ }
31809
+ async function* decodeAntigravityStream(messages) {
31810
+ let started = false;
31811
+ let terminal = false;
31812
+ let nextIndex = 0;
31813
+ let toolCalls = 0;
31814
+ let open2 = null;
31815
+ const closeOpen = function* () {
31816
+ if (open2 === null)
31817
+ return;
31818
+ yield { type: "blockEnd", index: open2.index };
31819
+ open2 = null;
31820
+ };
31821
+ for await (const message of messages) {
31822
+ if (message.data === "[DONE]")
31823
+ continue;
31824
+ const frame = json3(message.data);
31825
+ if (frame === null)
31826
+ continue;
31827
+ const failure = frame.error ?? frame.response?.error;
31828
+ if (failure !== undefined) {
31829
+ terminal = true;
31830
+ yield* closeOpen();
31831
+ const status = String(failure.status ?? "");
31832
+ const code = (Object.hasOwn(ERROR_CODE, status) ? ERROR_CODE[status] : undefined) ?? "UPSTREAM";
31833
+ yield {
31834
+ type: "error",
31835
+ code,
31836
+ message: String(failure.message ?? "upstream error"),
31837
+ retryable: RETRYABLE[code]
31838
+ };
31839
+ return;
31840
+ }
31841
+ const response = frame.response;
31842
+ if (response === undefined)
31843
+ continue;
31844
+ const blocked = response.promptFeedback?.blockReason;
31845
+ if (blocked !== undefined && (response.candidates ?? []).length === 0) {
31846
+ terminal = true;
31847
+ if (!started)
31848
+ yield { type: "start", id: "", model: "" };
31849
+ yield* closeOpen();
31850
+ yield { type: "end", stopReason: "contentFilter", usage: usageOf(response.usageMetadata) };
31851
+ return;
31852
+ }
31853
+ if (!started) {
31854
+ started = true;
31855
+ yield {
31856
+ type: "start",
31857
+ id: String(response.responseId ?? ""),
31858
+ model: String(response.modelVersion ?? "")
31859
+ };
31860
+ }
31861
+ const candidates = response.candidates ?? [];
31862
+ if (candidates.length > 1) {
31863
+ terminal = true;
31864
+ yield* closeOpen();
31865
+ yield {
31866
+ type: "error",
31867
+ code: "UPSTREAM",
31868
+ message: `Antigravity returned ${candidates.length} candidates, which cannot be represented`,
31869
+ retryable: false
31870
+ };
31871
+ return;
31872
+ }
31873
+ const candidate = candidates[0];
31874
+ for (const part of candidate?.content?.parts ?? []) {
31875
+ const call = part.functionCall;
31876
+ if (call !== undefined && typeof call.name === "string") {
31877
+ yield* closeOpen();
31878
+ const index = nextIndex++;
31879
+ yield {
31880
+ type: "blockStart",
31881
+ index,
31882
+ block: {
31883
+ type: "toolUse",
31884
+ id: typeof call.id === "string" && call.id.length > 0 ? call.id : `fc_${toolCalls}`,
31885
+ name: call.name
31886
+ }
31887
+ };
31888
+ yield {
31889
+ type: "blockDelta",
31890
+ index,
31891
+ delta: { type: "toolJson", partial: JSON.stringify(call.args ?? {}) }
31892
+ };
31893
+ yield { type: "blockEnd", index };
31894
+ toolCalls++;
31895
+ continue;
31896
+ }
31897
+ if (typeof part.text !== "string")
31898
+ continue;
31899
+ const kind = part.thought === true ? "thinking" : "text";
31900
+ if (open2 === null || open2.kind !== kind) {
31901
+ yield* closeOpen();
31902
+ open2 = { kind, index: nextIndex++ };
31903
+ yield { type: "blockStart", index: open2.index, block: { type: kind } };
31904
+ }
31905
+ yield {
31906
+ type: "blockDelta",
31907
+ index: open2.index,
31908
+ delta: kind === "thinking" ? { type: "thinking", text: part.text } : { type: "text", text: part.text }
31909
+ };
31910
+ }
31911
+ const finish = candidate?.finishReason;
31912
+ if (finish === undefined || finish === null)
31913
+ continue;
31914
+ terminal = true;
31915
+ yield* closeOpen();
31916
+ const raw = String(finish);
31917
+ if (raw === "MALFORMED_FUNCTION_CALL") {
31918
+ yield {
31919
+ type: "error",
31920
+ code: "BAD_REQUEST",
31921
+ message: "the model emitted a malformed function call",
31922
+ retryable: false
31923
+ };
31924
+ return;
31925
+ }
31926
+ const mapped = Object.hasOwn(STOP_REASON2, raw) ? STOP_REASON2[raw] : undefined;
31927
+ if (mapped === undefined) {
31928
+ yield {
31929
+ type: "error",
31930
+ code: "UPSTREAM",
31931
+ message: `unrecognized Antigravity finish reason "${raw}"`,
31932
+ retryable: false
31933
+ };
31934
+ return;
31935
+ }
31936
+ yield {
31937
+ type: "end",
31938
+ stopReason: toolCalls > 0 ? "toolUse" : mapped,
31939
+ usage: usageOf(response.usageMetadata)
31940
+ };
31941
+ return;
31942
+ }
31943
+ if (!terminal) {
31944
+ yield* closeOpen();
31945
+ yield {
31946
+ type: "error",
31947
+ code: "UPSTREAM",
31948
+ message: "upstream stream ended before the response finished",
31949
+ retryable: RETRYABLE.UPSTREAM
31950
+ };
31951
+ }
31952
+ }
31953
+
31954
+ // packages/providers/src/antigravity/wire.ts
31955
+ var SIGNATURE_BYPASS = "skip_thought_signature_validator";
31956
+ function toolNamesById(req) {
31957
+ const names = new Map;
31958
+ for (const message of req.messages) {
31959
+ for (const block of message.content) {
31960
+ if (block.type === "toolUse")
31961
+ names.set(block.id, block.name);
31962
+ }
31963
+ }
31964
+ return names;
31965
+ }
31966
+ function mergeSameRole(contents) {
31967
+ const merged = [];
31968
+ for (const entry of contents) {
31969
+ const last = merged[merged.length - 1];
31970
+ if (last !== undefined && last.role === entry.role)
31971
+ last.parts.push(...entry.parts);
31972
+ else
31973
+ merged.push({ role: entry.role, parts: [...entry.parts] });
31974
+ }
31975
+ return merged;
31976
+ }
31977
+ var hasCacheControl = (block) => ("cacheControl" in block) && block.cacheControl !== undefined;
31978
+ function encodeToolChoice2(choice) {
31979
+ switch (choice.type) {
31980
+ case "auto":
31981
+ return { functionCallingConfig: { mode: "AUTO" } };
31982
+ case "any":
31983
+ return { functionCallingConfig: { mode: "ANY" } };
31984
+ case "none":
31985
+ return { functionCallingConfig: { mode: "NONE" } };
31986
+ case "tool":
31987
+ return { functionCallingConfig: { mode: "ANY", allowedFunctionNames: [choice.name] } };
31988
+ }
31989
+ }
31990
+ function toAntigravityWire(req, model, identity) {
31991
+ const degradations = [];
31992
+ const note = (d) => {
31993
+ if (!degradations.includes(d))
31994
+ degradations.push(d);
31995
+ };
31996
+ const names = toolNamesById(req);
31997
+ const contents = [];
31998
+ for (const message of req.messages) {
31999
+ const parts = [];
32000
+ if (message.role === "system")
32001
+ note("antigravity:system-turn-as-user");
32002
+ let role = message.role === "assistant" ? "model" : "user";
32003
+ for (const block of message.content) {
32004
+ if (hasCacheControl(block))
32005
+ note("antigravity:cache-control-dropped");
32006
+ switch (block.type) {
32007
+ case "text":
32008
+ parts.push({ text: block.text });
32009
+ break;
32010
+ case "image":
32011
+ parts.push({ inlineData: { mimeType: block.mediaType, data: block.data } });
32012
+ break;
32013
+ case "thinking":
32014
+ note("antigravity:thinking-dropped");
32015
+ break;
32016
+ case "toolUse":
32017
+ parts.push({
32018
+ thoughtSignature: SIGNATURE_BYPASS,
32019
+ functionCall: { name: block.name, args: block.input }
32020
+ });
32021
+ break;
32022
+ case "toolResult": {
32023
+ const name = names.get(block.toolUseId);
32024
+ if (name === undefined)
32025
+ note("antigravity:tool-result-unmatched");
32026
+ if (block.isError === true)
32027
+ note("antigravity:tool-result-error-flag-dropped");
32028
+ parts.push({
32029
+ functionResponse: {
32030
+ name: name ?? block.toolUseId,
32031
+ response: { output: block.content }
32032
+ }
32033
+ });
32034
+ role = "user";
32035
+ break;
32036
+ }
32037
+ case "providerNative":
32038
+ note("antigravity:provider-native-block-dropped");
32039
+ break;
32040
+ }
32041
+ }
32042
+ if (parts.length > 0)
32043
+ contents.push({ role, parts });
32044
+ }
32045
+ const request2 = { contents: mergeSameRole(contents) };
32046
+ const system = systemText(req.system, "antigravity", note);
32047
+ if (system !== undefined && system.length > 0) {
32048
+ request2.systemInstruction = { parts: [{ text: system }] };
32049
+ }
32050
+ const generationConfig = {};
32051
+ if (req.maxTokens !== undefined)
32052
+ generationConfig.maxOutputTokens = req.maxTokens;
32053
+ if (req.temperature !== undefined)
32054
+ generationConfig.temperature = req.temperature;
32055
+ if (req.stopSequences !== undefined)
32056
+ generationConfig.stopSequences = req.stopSequences;
32057
+ if (req.reasoning !== undefined) {
32058
+ switch (req.reasoning.mode) {
32059
+ case "off":
32060
+ generationConfig.thinkingConfig = { thinkingBudget: 0, includeThoughts: false };
32061
+ break;
32062
+ case "budget":
32063
+ generationConfig.thinkingConfig = {
32064
+ thinkingBudget: req.reasoning.budgetTokens,
32065
+ includeThoughts: req.reasoning.budgetTokens !== 0
32066
+ };
32067
+ break;
32068
+ case "adaptive":
32069
+ generationConfig.thinkingConfig = {
32070
+ includeThoughts: req.reasoning.display !== "omitted"
32071
+ };
32072
+ if (req.reasoning.effort !== undefined)
32073
+ note("antigravity:reasoning-effort-dropped");
32074
+ break;
32075
+ }
32076
+ }
32077
+ const max = generationConfig.maxOutputTokens;
32078
+ if (max !== undefined && max > MAX_OUTPUT_TOKENS) {
32079
+ generationConfig.maxOutputTokens = MAX_OUTPUT_TOKENS;
32080
+ note("antigravity:max-tokens-clamped");
32081
+ }
32082
+ const budget = generationConfig.thinkingConfig?.thinkingBudget;
32083
+ if (budget !== undefined && budget > 0) {
32084
+ const ceiling = generationConfig.maxOutputTokens;
32085
+ if (ceiling === undefined || ceiling <= budget) {
32086
+ generationConfig.maxOutputTokens = Math.min(budget + 1, MAX_OUTPUT_TOKENS);
32087
+ }
32088
+ }
32089
+ if (Object.keys(generationConfig).length > 0)
32090
+ request2.generationConfig = generationConfig;
32091
+ if (req.tools !== undefined) {
32092
+ const portable = req.tools.filter((t) => t.kind === "portable");
32093
+ if (portable.length !== req.tools.length)
32094
+ note("antigravity:provider-tool-dropped");
32095
+ if (portable.length > 0) {
32096
+ request2.tools = [
32097
+ {
32098
+ functionDeclarations: portable.map((t) => ({
32099
+ name: t.name,
32100
+ description: t.description,
32101
+ parameters: t.inputSchema
32102
+ }))
32103
+ }
32104
+ ];
32105
+ }
32106
+ }
32107
+ if (req.toolChoice !== undefined)
32108
+ request2.toolConfig = encodeToolChoice2(req.toolChoice);
32109
+ Object.assign(request2, req.vendor?.antigravity ?? {});
32110
+ return {
32111
+ body: {
32112
+ project: identity.project,
32113
+ requestId: identity.requestId,
32114
+ model,
32115
+ userAgent: "antigravity",
32116
+ requestType: "agent",
32117
+ request: request2
32118
+ },
32119
+ degradations
32120
+ };
32121
+ }
32122
+
32123
+ // packages/providers/src/antigravity/codec.ts
32124
+ var URL2 = "https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse";
32125
+ var REQUEST_NAMESPACE = "omni-antigravity-req";
32126
+ function derivedRequestId(seed) {
32127
+ const h = createHash2("sha256").update(`${REQUEST_NAMESPACE}:${seed}`).digest("hex");
32128
+ const variant = (Number.parseInt(h[16], 16) & 3 | 8).toString(16);
32129
+ return [
32130
+ h.slice(0, 8),
32131
+ h.slice(8, 12),
32132
+ `4${h.slice(13, 16)}`,
32133
+ `${variant}${h.slice(17, 20)}`,
32134
+ h.slice(20, 32)
32135
+ ].join("-");
32136
+ }
32137
+ function projectOf(input2) {
32138
+ const stored = input2.credentials.providerData.projectId;
32139
+ const project = typeof stored === "string" ? stored.trim() : "";
32140
+ if (project.length === 0) {
32141
+ throw input2.fail("AUTH", "antigravity credential has no Cloud Code project; reconnect the account");
32142
+ }
32143
+ return project;
32144
+ }
32145
+ var antigravityCodec = {
32146
+ buildRequest(input2) {
32147
+ const accessToken = input2.credentials.accessToken;
32148
+ if (accessToken === null || accessToken.length === 0) {
32149
+ throw input2.fail("AUTH", "antigravity credential has no access token");
32150
+ }
32151
+ const project = projectOf(input2);
32152
+ const requestId = input2.requestId !== undefined && input2.requestId.length > 0 ? input2.requestId : derivedRequestId(`${input2.model}:${project}`);
32153
+ const { body, degradations } = toAntigravityWire(input2.request, input2.model, {
32154
+ project,
32155
+ requestId
32156
+ });
32157
+ const protocol = [["Authorization", `Bearer ${accessToken}`]];
32158
+ const headers = orderHeaders(mergeHeaders(antigravityProfile.headers, protocol), antigravityProfile.order);
32159
+ return {
32160
+ request: {
32161
+ url: URL2,
32162
+ method: "POST",
32163
+ headers,
32164
+ body: JSON.stringify(body)
32165
+ },
32166
+ degradations
32167
+ };
32168
+ },
32169
+ decode({ body }) {
32170
+ return decodeAntigravityStream(parseSse(body));
32171
+ }
32172
+ };
32173
+
32174
+ // packages/providers/src/antigravity/index.ts
32175
+ var antigravityAdapter = codecAdapter("antigravity", antigravityDescriptor.capabilities, antigravityCodec);
32176
+ // packages/providers/src/antigravity/oauth.ts
32177
+ var MASK = "omnigateway-public-v1";
32178
+ function unmask(bytes) {
32179
+ let out = "";
32180
+ for (let i = 0;i < bytes.length; i++) {
32181
+ out += String.fromCharCode(bytes[i] ^ MASK.charCodeAt(i % MASK.length));
32182
+ }
32183
+ return out;
32184
+ }
32185
+ var ANTIGRAVITY_CLIENT_ID = unmask([
32186
+ 94,
32187
+ 93,
32188
+ 89,
32189
+ 88,
32190
+ 87,
32191
+ 81,
32192
+ 66,
32193
+ 85,
32194
+ 65,
32195
+ 81,
32196
+ 76,
32197
+ 20,
32198
+ 65,
32199
+ 88,
32200
+ 22,
32201
+ 1,
32202
+ 1,
32203
+ 16,
32204
+ 94,
32205
+ 31,
32206
+ 95,
32207
+ 93,
32208
+ 5,
32209
+ 92,
32210
+ 88,
32211
+ 11,
32212
+ 2,
32213
+ 6,
32214
+ 0,
32215
+ 69,
32216
+ 82,
32217
+ 76,
32218
+ 91,
32219
+ 4,
32220
+ 26,
32221
+ 14,
32222
+ 3,
32223
+ 3,
32224
+ 11,
32225
+ 25,
32226
+ 17,
32227
+ 5,
32228
+ 95,
32229
+ 94,
32230
+ 11,
32231
+ 25,
32232
+ 73,
32233
+ 0,
32234
+ 4,
32235
+ 21,
32236
+ 4,
32237
+ 79,
32238
+ 30,
32239
+ 66,
32240
+ 31,
32241
+ 18,
32242
+ 14,
32243
+ 9,
32244
+ 28,
32245
+ 16,
32246
+ 72,
32247
+ 4,
32248
+ 82,
32249
+ 0,
32250
+ 3,
32251
+ 26,
32252
+ 12,
32253
+ 9,
32254
+ 21,
32255
+ 90,
32256
+ 6,
32257
+ 24,
32258
+ 12
32259
+ ]);
32260
+ var CLIENT_ID2 = ANTIGRAVITY_CLIENT_ID;
32261
+ var CLIENT_SECRET = unmask([
32262
+ 40,
32263
+ 34,
32264
+ 45,
32265
+ 58,
32266
+ 55,
32267
+ 57,
32268
+ 89,
32269
+ 46,
32270
+ 66,
32271
+ 89,
32272
+ 63,
32273
+ 122,
32274
+ 34,
32275
+ 65,
32276
+ 90,
32277
+ 90,
32278
+ 37,
32279
+ 7,
32280
+ 97,
32281
+ 60,
32282
+ 0,
32283
+ 2,
32284
+ 33,
32285
+ 44,
32286
+ 81,
32287
+ 20,
32288
+ 57,
32289
+ 55,
32290
+ 81,
32291
+ 13,
32292
+ 87,
32293
+ 8,
32294
+ 105,
32295
+ 49,
32296
+ 19
32297
+ ]);
32298
+ var AUTHORIZE_URL2 = "https://accounts.google.com/o/oauth2/v2/auth";
32299
+ var TOKEN_URL2 = "https://oauth2.googleapis.com/token";
32300
+ var USERINFO_URL = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json";
32301
+ var CODE_ASSIST = "https://cloudcode-pa.googleapis.com/v1internal";
32302
+ var LOAD_CODE_ASSIST_URL = `${CODE_ASSIST}:loadCodeAssist`;
32303
+ var ONBOARD_USER_URL = `${CODE_ASSIST}:onboardUser`;
32304
+ var QUOTA_SUMMARY_URL = `${CODE_ASSIST}:retrieveUserQuotaSummary`;
32305
+ var SCOPES2 = [
32306
+ "https://www.googleapis.com/auth/cloud-platform",
32307
+ "https://www.googleapis.com/auth/userinfo.email",
32308
+ "https://www.googleapis.com/auth/userinfo.profile",
32309
+ "https://www.googleapis.com/auth/cclog",
32310
+ "https://www.googleapis.com/auth/experimentsandconfigs"
32311
+ ].join(" ");
32312
+ var IDE_METADATA = { ideType: "ANTIGRAVITY" };
32313
+ var DEFAULT_TIER = "legacy-tier";
32314
+ function parseTokenResponse(value) {
32315
+ const record2 = recordOf(value);
32316
+ if (record2 === null || typeof record2.access_token !== "string")
32317
+ return null;
32318
+ return {
32319
+ accessToken: record2.access_token,
32320
+ refreshToken: typeof record2.refresh_token === "string" ? record2.refresh_token : null,
32321
+ expiresIn: typeof record2.expires_in === "number" ? record2.expires_in : null
32322
+ };
32323
+ }
32324
+ async function* postToken2(body, fail) {
32325
+ const res = yield postJsonRequest(TOKEN_URL2, antigravityProfile, {
32326
+ contentType: "application/x-www-form-urlencoded",
32327
+ body: new URLSearchParams(body).toString()
32328
+ });
32329
+ const parsed2 = parsed(res.body);
32330
+ if (res.status < 200 || res.status >= 300) {
32331
+ throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
32332
+ }
32333
+ const token = parseTokenResponse(parsed2);
32334
+ if (token === null)
32335
+ throw fail("AUTH", "token endpoint returned no access_token");
32336
+ return token;
32337
+ }
32338
+ function projectFrom(value) {
32339
+ const record2 = recordOf(value);
32340
+ if (record2 === null)
32341
+ return "";
32342
+ const project = record2.cloudaicompanionProject;
32343
+ if (typeof project === "string")
32344
+ return project.trim();
32345
+ const nested = recordOf(project);
32346
+ const id = nested?.id;
32347
+ return typeof id === "string" ? id.trim() : "";
32348
+ }
32349
+ function tierFrom(value) {
32350
+ const record2 = recordOf(value);
32351
+ const tiers = record2?.allowedTiers;
32352
+ if (Array.isArray(tiers)) {
32353
+ for (const entry of tiers) {
32354
+ const tier = recordOf(entry);
32355
+ if (tier?.isDefault === true && typeof tier.id === "string")
32356
+ return tier.id;
32357
+ }
32358
+ }
32359
+ const current = recordOf(record2?.currentTier);
32360
+ return typeof current?.id === "string" ? current.id : DEFAULT_TIER;
32361
+ }
32362
+ function codeAssistRequest(url2, accessToken, body) {
32363
+ return postJsonRequest(url2, antigravityProfile, {
32364
+ contentType: "application/json",
32365
+ body: JSON.stringify(body),
32366
+ extraHeaders: [["Authorization", `Bearer ${accessToken}`]]
32367
+ });
32368
+ }
32369
+ async function* bootstrapProject(accessToken) {
32370
+ const loaded = yield codeAssistRequest(LOAD_CODE_ASSIST_URL, accessToken, {
32371
+ metadata: IDE_METADATA
32372
+ });
32373
+ const body = loaded.status >= 200 && loaded.status < 300 ? parsed(loaded.body) : null;
32374
+ const tier = tierFrom(body);
32375
+ const existing = projectFrom(body);
32376
+ if (existing.length > 0)
32377
+ return { projectId: existing, tier };
32378
+ const onboarded = yield codeAssistRequest(ONBOARD_USER_URL, accessToken, {
32379
+ tier_id: tier,
32380
+ metadata: IDE_METADATA
32381
+ });
32382
+ if (onboarded.status < 200 || onboarded.status >= 300)
32383
+ return { projectId: "", tier };
32384
+ const operation = recordOf(parsed(onboarded.body));
32385
+ return { projectId: projectFrom(operation?.response), tier };
32386
+ }
32387
+ async function* readEmail(accessToken) {
32388
+ const res = yield getJsonRequest(USERINFO_URL, antigravityProfile, { accessToken });
32389
+ if (res.status < 200 || res.status >= 300)
32390
+ return null;
32391
+ const record2 = recordOf(parsed(res.body));
32392
+ const email3 = record2?.email;
32393
+ return typeof email3 === "string" && email3.trim().length > 0 ? email3 : null;
32394
+ }
32395
+ function toResult2(token, fallbackRefresh, accountEmail, providerData, now) {
32396
+ return {
32397
+ secrets: {
32398
+ accessToken: token.accessToken,
32399
+ refreshToken: token.refreshToken ?? fallbackRefresh,
32400
+ apiKey: null,
32401
+ idToken: null
32402
+ },
32403
+ expiresAt: token.expiresIn === null ? null : now() + token.expiresIn * 1000,
32404
+ accountEmail,
32405
+ providerData
32406
+ };
32407
+ }
32408
+ var GEMINI_GROUP = /\bgemini\b/;
32409
+ function windowOf(bucket) {
32410
+ const text = `${String(bucket.bucketId ?? "")} ${String(bucket.displayName ?? "")}`.toLowerCase();
32411
+ if (/\bweekly\b|\bweek\b/.test(text))
32412
+ return "weekly";
32413
+ if (/\b5\s*-?\s*hour|\b5h\b|\bfive\s*hour/.test(text))
32414
+ return "fiveHour";
32415
+ return null;
32416
+ }
32417
+ function groupsOf(value) {
32418
+ const root = recordOf(value);
32419
+ if (root === null)
32420
+ return [];
32421
+ if (Array.isArray(root.groups))
32422
+ return root.groups;
32423
+ const nested = recordOf(root.quotaSummary)?.groups;
32424
+ return Array.isArray(nested) ? nested : [];
32425
+ }
32426
+ function parseAntigravityQuota(value, now) {
32427
+ const windows = [];
32428
+ for (const groupValue of groupsOf(value)) {
32429
+ const group = recordOf(groupValue);
32430
+ if (group === null)
32431
+ continue;
32432
+ if (!GEMINI_GROUP.test(String(group.displayName ?? "").toLowerCase()))
32433
+ continue;
32434
+ const buckets = Array.isArray(group.buckets) ? group.buckets : [];
32435
+ for (const bucketValue of buckets) {
32436
+ const bucket = recordOf(bucketValue);
32437
+ if (bucket === null || bucket.disabled === true)
32438
+ continue;
32439
+ const windowType = windowOf(bucket);
32440
+ if (windowType === null)
32441
+ continue;
32442
+ const fraction = numberOf(bucket, ["remainingFraction"]);
32443
+ if (fraction === null)
32444
+ continue;
32445
+ const remaining = Math.max(0, Math.min(1, fraction));
32446
+ windows.push({
32447
+ windowType,
32448
+ used: Math.round((1 - remaining) * 100),
32449
+ limit: 100,
32450
+ resetsAt: resetAtOf(bucket, { absolute: ["resetTime"] }, now),
32451
+ windowMs: null
32452
+ });
32453
+ }
32454
+ }
32455
+ return reportFrom(windows);
32456
+ }
32457
+ var antigravityOAuthFlow = {
32458
+ kind: "pkce",
32459
+ supportsManualPaste: true,
32460
+ async* start({ redirectUri, randomState }) {
32461
+ const state = randomState();
32462
+ const url2 = new URL(AUTHORIZE_URL2);
32463
+ url2.searchParams.set("client_id", CLIENT_ID2);
32464
+ url2.searchParams.set("response_type", "code");
32465
+ url2.searchParams.set("redirect_uri", redirectUri);
32466
+ url2.searchParams.set("scope", SCOPES2);
32467
+ url2.searchParams.set("state", state);
32468
+ url2.searchParams.set("access_type", "offline");
32469
+ url2.searchParams.set("prompt", "consent");
32470
+ return {
32471
+ authorizeUrl: url2.toString(),
32472
+ pending: { verifier: "", challenge: "", state, redirectUri }
32473
+ };
32474
+ },
32475
+ async* exchange({ code, pending, fail, now }) {
32476
+ const [rawCode, pastedState] = code.split("#");
32477
+ if (pastedState !== undefined && pastedState !== pending.state) {
32478
+ throw fail("AUTH", "authorization state mismatch");
32479
+ }
32480
+ const token = yield* postToken2({
32481
+ grant_type: "authorization_code",
32482
+ client_id: CLIENT_ID2,
32483
+ client_secret: CLIENT_SECRET,
32484
+ code: (rawCode ?? "").trim(),
32485
+ redirect_uri: pending.redirectUri
32486
+ }, fail);
32487
+ const email3 = yield* readEmail(token.accessToken);
32488
+ const { projectId, tier } = yield* bootstrapProject(token.accessToken);
32489
+ return toResult2(token, null, email3, { projectId, tier }, now);
32490
+ },
32491
+ async* refresh({ refreshToken, providerData, fail, now }) {
32492
+ const token = yield* postToken2({
32493
+ grant_type: "refresh_token",
32494
+ client_id: CLIENT_ID2,
32495
+ client_secret: CLIENT_SECRET,
32496
+ refresh_token: refreshToken
32497
+ }, fail);
32498
+ return toResult2(token, refreshToken, null, providerData, now);
32499
+ },
32500
+ async* usage({ secrets, providerData, now }) {
32501
+ const project = typeof providerData.projectId === "string" ? providerData.projectId : "";
32502
+ if (project.trim().length === 0)
32503
+ return null;
32504
+ const res = yield {
32505
+ ...postJsonRequest(QUOTA_SUMMARY_URL, antigravityProfile, {
32506
+ contentType: "application/json",
32507
+ body: JSON.stringify({ project }),
32508
+ extraHeaders: [["Authorization", `Bearer ${secrets.accessToken}`]]
32509
+ }),
32510
+ timeoutMs: SHORT_TIMEOUT_MS
32511
+ };
32512
+ if (!usageReadable(res.status, "antigravity"))
32513
+ return null;
32514
+ return parseAntigravityQuota(parsed(res.body), now());
32515
+ }
32516
+ };
31496
32517
  // packages/providers/src/grok/device.ts
31497
32518
  import { randomUUID } from "crypto";
31498
32519
  function mintGrokDevice() {
@@ -31506,10 +32527,10 @@ function grokDeviceHeaders(providerData) {
31506
32527
  }
31507
32528
 
31508
32529
  // packages/providers/src/grok/oauth.ts
31509
- var CLIENT_ID2 = "b1a00492-073a-47ea-816f-4c329264a828";
32530
+ var CLIENT_ID3 = "b1a00492-073a-47ea-816f-4c329264a828";
31510
32531
  var ISSUER = "https://auth.x.ai";
31511
32532
  var DISCOVERY_URL = `${ISSUER}/.well-known/openid-configuration`;
31512
- var SCOPES2 = [
32533
+ var SCOPES3 = [
31513
32534
  "openid",
31514
32535
  "profile",
31515
32536
  "email",
@@ -31555,7 +32576,7 @@ async function* discover(fail) {
31555
32576
  tokenUrl: trustedEndpoint(parsed2.token_endpoint, "token_endpoint", fail)
31556
32577
  };
31557
32578
  }
31558
- function parseTokenResponse(value) {
32579
+ function parseTokenResponse2(value) {
31559
32580
  if (!isRecord2(value) || typeof value.access_token !== "string")
31560
32581
  return null;
31561
32582
  return {
@@ -31571,15 +32592,15 @@ function emailFromIdToken(idToken) {
31571
32592
  if (parts.length !== 3 || payload === undefined || payload.length === 0)
31572
32593
  return null;
31573
32594
  try {
31574
- const json3 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
31575
- if (!isRecord2(json3))
32595
+ const json4 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
32596
+ if (!isRecord2(json4))
31576
32597
  return null;
31577
- return typeof json3.email === "string" && json3.email.trim().length > 0 ? json3.email : null;
32598
+ return typeof json4.email === "string" && json4.email.trim().length > 0 ? json4.email : null;
31578
32599
  } catch {
31579
32600
  return null;
31580
32601
  }
31581
32602
  }
31582
- async function* postToken2(tokenUrl, body, fail) {
32603
+ async function* postToken3(tokenUrl, body, fail) {
31583
32604
  const res = yield postJsonRequest(tokenUrl, grokProfile, {
31584
32605
  contentType: "application/x-www-form-urlencoded",
31585
32606
  body: new URLSearchParams(body).toString()
@@ -31588,7 +32609,7 @@ async function* postToken2(tokenUrl, body, fail) {
31588
32609
  if (res.status < 200 || res.status >= 300) {
31589
32610
  throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
31590
32611
  }
31591
- const token = parseTokenResponse(parsed2);
32612
+ const token = parseTokenResponse2(parsed2);
31592
32613
  if (token === null) {
31593
32614
  throw fail("AUTH", "token endpoint returned no access_token");
31594
32615
  }
@@ -31598,7 +32619,7 @@ function agentIdFrom(providerData) {
31598
32619
  const stored = providerData.agentId;
31599
32620
  return typeof stored === "string" && stored.trim().length > 0 ? stored : mintGrokDevice().agentId;
31600
32621
  }
31601
- function toResult2(token, fallbackRefresh, agentId, now) {
32622
+ function toResult3(token, fallbackRefresh, agentId, now) {
31602
32623
  return {
31603
32624
  secrets: {
31604
32625
  accessToken: token.accessToken,
@@ -31620,9 +32641,9 @@ var grokOAuthFlow = {
31620
32641
  const state = randomState();
31621
32642
  const url2 = new URL(authorizeUrl);
31622
32643
  url2.searchParams.set("response_type", "code");
31623
- url2.searchParams.set("client_id", CLIENT_ID2);
32644
+ url2.searchParams.set("client_id", CLIENT_ID3);
31624
32645
  url2.searchParams.set("redirect_uri", redirectUri);
31625
- url2.searchParams.set("scope", SCOPES2);
32646
+ url2.searchParams.set("scope", SCOPES3);
31626
32647
  url2.searchParams.set("code_challenge", challenge);
31627
32648
  url2.searchParams.set("code_challenge_method", "S256");
31628
32649
  url2.searchParams.set("state", state);
@@ -31636,19 +32657,19 @@ var grokOAuthFlow = {
31636
32657
  throw fail("AUTH", "authorization state mismatch");
31637
32658
  }
31638
32659
  const { tokenUrl } = yield* discover(fail);
31639
- const token = yield* postToken2(tokenUrl, {
32660
+ const token = yield* postToken3(tokenUrl, {
31640
32661
  grant_type: "authorization_code",
31641
32662
  code: (rawCode ?? "").trim(),
31642
32663
  redirect_uri: pending.redirectUri,
31643
- client_id: CLIENT_ID2,
32664
+ client_id: CLIENT_ID3,
31644
32665
  code_verifier: pending.verifier
31645
32666
  }, fail);
31646
- return toResult2(token, null, mintGrokDevice().agentId, now);
32667
+ return toResult3(token, null, mintGrokDevice().agentId, now);
31647
32668
  },
31648
32669
  async* refresh({ refreshToken, providerData, fail, now }) {
31649
32670
  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);
32671
+ const token = yield* postToken3(tokenUrl, { grant_type: "refresh_token", client_id: CLIENT_ID3, refresh_token: refreshToken }, fail);
32672
+ return toResult3(token, refreshToken, agentIdFrom(providerData), now);
31652
32673
  }
31653
32674
  };
31654
32675
 
@@ -31808,9 +32829,9 @@ function kimiDeviceHeaders(providerData) {
31808
32829
  }
31809
32830
 
31810
32831
  // packages/providers/src/kimi/oauth.ts
31811
- var CLIENT_ID3 = "17e5f671-d194-4dfb-9706-5516cb48c098";
32832
+ var CLIENT_ID4 = "17e5f671-d194-4dfb-9706-5516cb48c098";
31812
32833
  var DEVICE_CODE_URL = "https://auth.kimi.com/api/oauth/device_authorization";
31813
- var TOKEN_URL2 = "https://auth.kimi.com/api/oauth/token";
32834
+ var TOKEN_URL3 = "https://auth.kimi.com/api/oauth/token";
31814
32835
  var USAGE_URL2 = "https://api.kimi.com/coding/v1/usages";
31815
32836
  var DEFAULT_INTERVAL_SECONDS = 5;
31816
32837
  var PENDING_ERRORS = new Set(["authorization_pending", "slow_down"]);
@@ -31864,7 +32885,7 @@ function deviceCodeFrom2(value, fail) {
31864
32885
  async function* post(url2, body, device, fail, keepPolling) {
31865
32886
  const res = yield postJsonRequest(url2, kimiProfile, {
31866
32887
  contentType: "application/x-www-form-urlencoded",
31867
- body: new URLSearchParams({ ...body, client_id: CLIENT_ID3 }).toString(),
32888
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID4 }).toString(),
31868
32889
  extraHeaders: kimiDeviceHeaders(device)
31869
32890
  });
31870
32891
  const parsed2 = parsed(res.body);
@@ -31895,7 +32916,7 @@ function deviceFrom(source) {
31895
32916
  function deviceForBegin(deviceId) {
31896
32917
  return { ...mintKimiDevice(), deviceId };
31897
32918
  }
31898
- function toResult3(token, device, fallbackRefresh, now) {
32919
+ function toResult4(token, device, fallbackRefresh, now) {
31899
32920
  return {
31900
32921
  secrets: {
31901
32922
  accessToken: token.accessToken,
@@ -31950,17 +32971,17 @@ var kimiOAuthFlow = {
31950
32971
  throw fail("INTERNAL", "kimi exchange requires a pending flow produced by begin()");
31951
32972
  }
31952
32973
  const device = deviceFrom(pending.extra);
31953
- const token = tokenFrom(yield* post(TOKEN_URL2, {
32974
+ const token = tokenFrom(yield* post(TOKEN_URL3, {
31954
32975
  grant_type: "urn:ietf:params:oauth:grant-type:device_code",
31955
32976
  device_code: pending.deviceCode,
31956
32977
  device_id: device.deviceId
31957
32978
  }, device, fail, keepPolling), fail);
31958
- return toResult3(token, device, null, now);
32979
+ return toResult4(token, device, null, now);
31959
32980
  },
31960
32981
  async* refresh({ refreshToken, providerData, fail, keepPolling, now }) {
31961
32982
  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);
32983
+ const token = tokenFrom(yield* post(TOKEN_URL3, { grant_type: "refresh_token", refresh_token: refreshToken, device_id: device.deviceId }, device, fail, keepPolling), fail);
32984
+ return toResult4(token, device, refreshToken, now);
31964
32985
  },
31965
32986
  async* usage({ secrets, providerData, now }) {
31966
32987
  if (secrets.accessToken === null)
@@ -31976,13 +32997,225 @@ var kimiOAuthFlow = {
31976
32997
  }
31977
32998
  };
31978
32999
 
33000
+ // packages/providers/src/muse/endpoint.ts
33001
+ var TRUSTED_HOST2 = "meta.ai";
33002
+ var MUSE_DEFAULT_BASE_URL = "https://api.meta.ai/v1";
33003
+ function trustedBaseUrl(value) {
33004
+ if (typeof value !== "string" || value.length === 0)
33005
+ return null;
33006
+ let url2;
33007
+ try {
33008
+ url2 = new URL(value);
33009
+ } catch {
33010
+ return null;
33011
+ }
33012
+ if (url2.protocol !== "https:")
33013
+ return null;
33014
+ const host2 = url2.hostname;
33015
+ if (host2 !== TRUSTED_HOST2 && !host2.endsWith(`.${TRUSTED_HOST2}`))
33016
+ return null;
33017
+ return `${url2.origin}${url2.pathname}`.replace(/\/$/, "");
33018
+ }
33019
+ function museResponsesUrl(providerData) {
33020
+ return `${trustedBaseUrl(providerData.baseUrl) ?? MUSE_DEFAULT_BASE_URL}/responses`;
33021
+ }
33022
+
33023
+ // packages/providers/src/muse/oauth.ts
33024
+ var AUTH_BASE = "https://auth.meta.com";
33025
+ var DEVICE_CODE_URL2 = `${AUTH_BASE}/oidc/device/authorization/`;
33026
+ var TOKEN_URL4 = `${AUTH_BASE}/oidc/device/token/`;
33027
+ var MINT_URL = "https://api.meta.ai/muse-code/key";
33028
+ var CLIENT_ID5 = "1031625952748946";
33029
+ var DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
33030
+ var FALLBACK_VERIFICATION_URL2 = "https://auth.meta.com/oauth/device/";
33031
+ var DEFAULT_INTERVAL_SECONDS2 = 5;
33032
+ var PENDING_ERRORS2 = new Set(["authorization_pending", "slow_down"]);
33033
+ function isRecord5(value) {
33034
+ return typeof value === "object" && value !== null;
33035
+ }
33036
+ function recordFrom3(value) {
33037
+ return isRecord5(value) ? value : null;
33038
+ }
33039
+ function stringFrom3(value, field) {
33040
+ const candidate = value[field];
33041
+ return typeof candidate === "string" && candidate.trim().length > 0 ? candidate : null;
33042
+ }
33043
+ function positiveNumberFrom3(value, field) {
33044
+ const candidate = value[field];
33045
+ return typeof candidate === "number" && Number.isFinite(candidate) && candidate > 0 ? candidate : null;
33046
+ }
33047
+ function tokenFrom2(value, fail) {
33048
+ const record2 = recordFrom3(value);
33049
+ const accessToken = record2 === null ? null : stringFrom3(record2, "access_token");
33050
+ if (record2 === null || accessToken === null) {
33051
+ throw fail("AUTH", "token endpoint returned no access_token");
33052
+ }
33053
+ return {
33054
+ accessToken,
33055
+ refreshToken: stringFrom3(record2, "refresh_token"),
33056
+ expiresIn: positiveNumberFrom3(record2, "expires_in")
33057
+ };
33058
+ }
33059
+ function deviceCodeFrom3(value, fail) {
33060
+ const record2 = recordFrom3(value);
33061
+ const deviceCode = record2 === null ? null : stringFrom3(record2, "device_code");
33062
+ const userCode = record2 === null ? null : stringFrom3(record2, "user_code");
33063
+ if (record2 === null || deviceCode === null || userCode === null) {
33064
+ throw fail("AUTH", "device authorization response missing user_code or verification_uri");
33065
+ }
33066
+ return {
33067
+ deviceCode,
33068
+ userCode,
33069
+ verificationUri: stringFrom3(record2, "verification_uri_complete") ?? stringFrom3(record2, "verification_uri") ?? FALLBACK_VERIFICATION_URL2,
33070
+ interval: positiveNumberFrom3(record2, "interval") ?? DEFAULT_INTERVAL_SECONDS2
33071
+ };
33072
+ }
33073
+ async function* postForm(url2, body, fail, keepPolling) {
33074
+ const res = yield postJsonRequest(url2, museProfile, {
33075
+ contentType: "application/x-www-form-urlencoded",
33076
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID5 }).toString(),
33077
+ extraHeaders: [["Accept", "application/json"]]
33078
+ });
33079
+ const parsed2 = parsed(res.body);
33080
+ if (res.status >= 200 && res.status < 300)
33081
+ return parsed2;
33082
+ const record2 = recordFrom3(parsed2);
33083
+ const code = record2 === null ? `http_${res.status}` : stringFrom3(record2, "error") ?? `http_${res.status}`;
33084
+ if (PENDING_ERRORS2.has(code))
33085
+ throw keepPolling(code);
33086
+ if (code === "expired_token") {
33087
+ throw fail("AUTH", "muse device code expired; start the authorization again");
33088
+ }
33089
+ throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
33090
+ }
33091
+ async function* mint(accessToken, fail) {
33092
+ const res = yield postJsonRequest(MINT_URL, museProfile, {
33093
+ contentType: "application/json",
33094
+ body: "{}",
33095
+ extraHeaders: [
33096
+ ["Authorization", `Bearer ${accessToken}`],
33097
+ ["Accept", "application/json"]
33098
+ ]
33099
+ });
33100
+ const parsed2 = parsed(res.body);
33101
+ if (res.status < 200 || res.status >= 300) {
33102
+ if (res.status === 401 || res.status === 403) {
33103
+ throw fail("AUTH", "muse rejected the saved login; reconnect the account or use a different one");
33104
+ }
33105
+ if (res.status === 429) {
33106
+ throw fail("RATE_LIMIT", `muse rate limited the key mint: http_${res.status}`);
33107
+ }
33108
+ throw fail("UPSTREAM", `muse key mint failed: http_${res.status}`);
33109
+ }
33110
+ const record2 = recordFrom3(parsed2);
33111
+ if (record2 === null) {
33112
+ throw fail("UPSTREAM", "muse key mint returned an unusable response");
33113
+ }
33114
+ if (record2.require_payment === true) {
33115
+ throw fail("AUTH", "muse requires a payment method on the Meta account; add one at https://dev.meta.ai and reconnect");
33116
+ }
33117
+ const apiKey = stringFrom3(record2, "api_key");
33118
+ if (apiKey === null) {
33119
+ throw fail("AUTH", "muse key mint returned an empty api key; finish onboarding at https://dev.meta.ai and reconnect");
33120
+ }
33121
+ return {
33122
+ apiKey,
33123
+ email: stringFrom3(record2, "user_email"),
33124
+ tierName: stringFrom3(record2, "subs_tier_name"),
33125
+ subscriptionActive: record2.is_subs_active === true,
33126
+ baseUrl: trustedBaseUrl(record2.base_url),
33127
+ usage: record2.subs_usage
33128
+ };
33129
+ }
33130
+ function toResult5(token, key, fallbackRefresh, now) {
33131
+ return {
33132
+ secrets: {
33133
+ accessToken: token.accessToken,
33134
+ refreshToken: token.refreshToken ?? fallbackRefresh,
33135
+ apiKey: key.apiKey,
33136
+ idToken: null
33137
+ },
33138
+ expiresAt: token.expiresIn === null ? null : now() + token.expiresIn * 1000,
33139
+ accountEmail: key.email,
33140
+ providerData: {
33141
+ ...key.tierName === null ? {} : { subscriptionTier: key.tierName },
33142
+ subscriptionActive: key.subscriptionActive,
33143
+ ...key.baseUrl === null ? {} : { baseUrl: key.baseUrl }
33144
+ }
33145
+ };
33146
+ }
33147
+ var museOAuthFlow = {
33148
+ kind: "device",
33149
+ supportsManualPaste: false,
33150
+ needsDeviceId: false,
33151
+ async* start() {
33152
+ return {
33153
+ authorizeUrl: FALLBACK_VERIFICATION_URL2,
33154
+ pending: { verifier: "", challenge: "", state: "", redirectUri: "" }
33155
+ };
33156
+ },
33157
+ async* begin({ fail, keepPolling }) {
33158
+ const response = deviceCodeFrom3(yield* postForm(DEVICE_CODE_URL2, {}, fail, keepPolling), fail);
33159
+ return {
33160
+ authorizeUrl: response.verificationUri,
33161
+ userCode: response.userCode,
33162
+ pending: {
33163
+ verifier: "",
33164
+ challenge: "",
33165
+ state: "",
33166
+ redirectUri: "",
33167
+ deviceCode: response.deviceCode,
33168
+ interval: response.interval
33169
+ }
33170
+ };
33171
+ },
33172
+ async* exchange({ pending, fail, keepPolling, now }) {
33173
+ if (pending.deviceCode === undefined) {
33174
+ throw fail("INTERNAL", "muse exchange requires a pending flow produced by begin()");
33175
+ }
33176
+ const token = tokenFrom2(yield* postForm(TOKEN_URL4, { grant_type: DEVICE_CODE_GRANT, device_code: pending.deviceCode }, fail, keepPolling), fail);
33177
+ return toResult5(token, yield* mint(token.accessToken, fail), null, now);
33178
+ },
33179
+ async* refresh({ refreshToken, fail, keepPolling, now }) {
33180
+ const token = tokenFrom2(yield* postForm(TOKEN_URL4, { grant_type: "refresh_token", refresh_token: refreshToken }, fail, keepPolling), fail);
33181
+ return toResult5(token, yield* mint(token.accessToken, fail), refreshToken, now);
33182
+ },
33183
+ async* usage({ secrets, now }) {
33184
+ if (secrets.accessToken === null)
33185
+ return null;
33186
+ const res = yield postJsonRequest(MINT_URL, museProfile, {
33187
+ contentType: "application/json",
33188
+ body: "{}",
33189
+ extraHeaders: [
33190
+ ["Authorization", `Bearer ${secrets.accessToken}`],
33191
+ ["Accept", "application/json"]
33192
+ ]
33193
+ });
33194
+ if (!usageReadable(res.status, "muse"))
33195
+ return null;
33196
+ const record2 = recordOf(parsed(res.body));
33197
+ return record2 === null ? null : parseMuseUsage(record2.subs_usage, now());
33198
+ }
33199
+ };
33200
+ function parseMuseUsage(value, now) {
33201
+ const root = recordOf(value);
33202
+ if (root === null)
33203
+ return null;
33204
+ const window2 = recordOf(root.window);
33205
+ const mins = window2 === null ? null : numberOf(window2, ["window_duration_mins"]);
33206
+ return reportFrom([
33207
+ windowFrom(root.window, "fiveHour", now, mins === null ? null : mins * 60000),
33208
+ windowFrom(root.weekly, "weekly", now)
33209
+ ]);
33210
+ }
33211
+
31979
33212
  // 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";
33213
+ var CLIENT_ID6 = "app_EMoamEEZ73f0CkXaXp7hrann";
33214
+ var AUTHORIZE_URL3 = "https://auth.openai.com/oauth/authorize";
33215
+ var TOKEN_URL5 = "https://auth.openai.com/oauth/token";
33216
+ var SCOPES4 = "openid profile email offline_access";
31984
33217
  var USAGE_URL3 = "https://chatgpt.com/backend-api/wham/usage";
31985
- function isRecord5(value) {
33218
+ function isRecord6(value) {
31986
33219
  return typeof value === "object" && value !== null;
31987
33220
  }
31988
33221
  function nonBlankStringOrNull(value) {
@@ -31998,20 +33231,20 @@ function decodeClaims(idToken) {
31998
33231
  return { email: null, accountId: null };
31999
33232
  }
32000
33233
  try {
32001
- const json3 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
32002
- if (!isRecord5(json3))
33234
+ const json4 = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
33235
+ if (!isRecord6(json4))
32003
33236
  return { email: null, accountId: null };
32004
- const auth = json3["https://api.openai.com/auth"];
33237
+ const auth = json4["https://api.openai.com/auth"];
32005
33238
  return {
32006
- email: typeof json3.email === "string" ? json3.email : null,
32007
- accountId: isRecord5(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
33239
+ email: typeof json4.email === "string" ? json4.email : null,
33240
+ accountId: isRecord6(auth) ? nonBlankStringOrNull(auth.chatgpt_account_id) : null
32008
33241
  };
32009
33242
  } catch {
32010
33243
  return { email: null, accountId: null };
32011
33244
  }
32012
33245
  }
32013
- function parseTokenResponse2(value) {
32014
- if (!isRecord5(value) || typeof value.access_token !== "string")
33246
+ function parseTokenResponse3(value) {
33247
+ if (!isRecord6(value) || typeof value.access_token !== "string")
32015
33248
  return null;
32016
33249
  return {
32017
33250
  accessToken: value.access_token,
@@ -32020,22 +33253,22 @@ function parseTokenResponse2(value) {
32020
33253
  idToken: typeof value.id_token === "string" ? value.id_token : null
32021
33254
  };
32022
33255
  }
32023
- async function* postToken3(body, fail) {
32024
- const res = yield postJsonRequest(TOKEN_URL3, openaiProfile, {
33256
+ async function* postToken4(body, fail) {
33257
+ const res = yield postJsonRequest(TOKEN_URL5, openaiProfile, {
32025
33258
  contentType: "application/x-www-form-urlencoded",
32026
- body: new URLSearchParams({ ...body, client_id: CLIENT_ID4 }).toString()
33259
+ body: new URLSearchParams({ ...body, client_id: CLIENT_ID6 }).toString()
32027
33260
  });
32028
33261
  const parsed2 = parsed(res.body);
32029
33262
  if (res.status < 200 || res.status >= 300) {
32030
33263
  throw fail(tokenErrorCode(res.status), tokenErrorMessage(res.status, parsed2));
32031
33264
  }
32032
- const token = parseTokenResponse2(parsed2);
33265
+ const token = parseTokenResponse3(parsed2);
32033
33266
  if (token === null) {
32034
33267
  throw fail("AUTH", "token endpoint returned no access_token");
32035
33268
  }
32036
33269
  return token;
32037
33270
  }
32038
- function toResult4(token, fallbackRefresh, now, fallbackAccountId = null) {
33271
+ function toResult6(token, fallbackRefresh, now, fallbackAccountId = null) {
32039
33272
  const claims = decodeClaims(token.idToken);
32040
33273
  return {
32041
33274
  secrets: {
@@ -32093,11 +33326,11 @@ var openaiOAuthFlow = {
32093
33326
  async* start({ redirectUri, pkce, randomState }) {
32094
33327
  const { verifier, challenge } = pkce();
32095
33328
  const state = randomState();
32096
- const url2 = new URL(AUTHORIZE_URL2);
32097
- url2.searchParams.set("client_id", CLIENT_ID4);
33329
+ const url2 = new URL(AUTHORIZE_URL3);
33330
+ url2.searchParams.set("client_id", CLIENT_ID6);
32098
33331
  url2.searchParams.set("response_type", "code");
32099
33332
  url2.searchParams.set("redirect_uri", redirectUri);
32100
- url2.searchParams.set("scope", SCOPES3);
33333
+ url2.searchParams.set("scope", SCOPES4);
32101
33334
  url2.searchParams.set("code_challenge", challenge);
32102
33335
  url2.searchParams.set("code_challenge_method", "S256");
32103
33336
  url2.searchParams.set("id_token_add_organizations", "true");
@@ -32112,17 +33345,17 @@ var openaiOAuthFlow = {
32112
33345
  if (pastedState !== undefined && pastedState !== pending.state) {
32113
33346
  throw fail("AUTH", "authorization state mismatch");
32114
33347
  }
32115
- const token = yield* postToken3({
33348
+ const token = yield* postToken4({
32116
33349
  grant_type: "authorization_code",
32117
33350
  code: (rawCode ?? "").trim(),
32118
33351
  redirect_uri: pending.redirectUri,
32119
33352
  code_verifier: pending.verifier
32120
33353
  }, fail);
32121
- return toResult4(token, null, now);
33354
+ return toResult6(token, null, now);
32122
33355
  },
32123
33356
  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));
33357
+ const token = yield* postToken4({ grant_type: "refresh_token", refresh_token: refreshToken, scope: SCOPES4 }, fail);
33358
+ return toResult6(token, refreshToken, now, accountIdFromProviderData(providerData));
32126
33359
  },
32127
33360
  async* usage({ secrets, providerData, now }) {
32128
33361
  if (secrets.accessToken === null)
@@ -32145,7 +33378,9 @@ function builtinOAuthFlows() {
32145
33378
  ["openai", openaiOAuthFlow],
32146
33379
  ["kimi", kimiOAuthFlow],
32147
33380
  ["kilo", kiloOAuthFlow],
32148
- ["grok", grokOAuthFlow]
33381
+ ["grok", grokOAuthFlow],
33382
+ ["antigravity", antigravityOAuthFlow],
33383
+ ["muse", museOAuthFlow]
32149
33384
  ];
32150
33385
  }
32151
33386
  // packages/providers/src/custom/decode.ts
@@ -32173,7 +33408,7 @@ function reasoningText(delta) {
32173
33408
  return [];
32174
33409
  }).join("");
32175
33410
  }
32176
- function json3(data) {
33411
+ function json4(data) {
32177
33412
  try {
32178
33413
  const v = JSON.parse(data);
32179
33414
  return typeof v === "object" && v !== null ? v : null;
@@ -32195,7 +33430,7 @@ async function* decodeCustomChat(messages) {
32195
33430
  done = true;
32196
33431
  break;
32197
33432
  }
32198
- const d = json3(msg.data);
33433
+ const d = json4(msg.data);
32199
33434
  if (d === null)
32200
33435
  continue;
32201
33436
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -32353,7 +33588,7 @@ async function* decodeCustomResponses(messages) {
32353
33588
  };
32354
33589
  return;
32355
33590
  }
32356
- const d = json3(msg.data);
33591
+ const d = json4(msg.data);
32357
33592
  if (d === null)
32358
33593
  continue;
32359
33594
  switch (msg.event) {
@@ -32741,10 +33976,10 @@ var customCodec = {
32741
33976
  // packages/providers/src/custom/index.ts
32742
33977
  var customAdapter = codecAdapter("custom", customDescriptor.capabilities, customCodec);
32743
33978
  // packages/providers/src/grok/codec.ts
32744
- import { createHash as createHash3 } from "crypto";
33979
+ import { createHash as createHash4 } from "crypto";
32745
33980
 
32746
33981
  // packages/providers/src/grok/decode.ts
32747
- var ERROR_CODE = {
33982
+ var ERROR_CODE2 = {
32748
33983
  rate_limit_exceeded: "RATE_LIMIT",
32749
33984
  insufficient_quota: "QUOTA_EXHAUSTED",
32750
33985
  invalid_api_key: "AUTH",
@@ -32778,7 +34013,7 @@ var KNOWN_EVENTS2 = new Set([
32778
34013
  "response.failed",
32779
34014
  "error"
32780
34015
  ]);
32781
- function json4(data) {
34016
+ function json5(data) {
32782
34017
  try {
32783
34018
  const v = JSON.parse(data);
32784
34019
  return typeof v === "object" && v !== null ? v : null;
@@ -32813,7 +34048,7 @@ async function* decodeGrokResponses(messages) {
32813
34048
  };
32814
34049
  return;
32815
34050
  }
32816
- const d = json4(msg.data);
34051
+ const d = json5(msg.data);
32817
34052
  if (d === null)
32818
34053
  continue;
32819
34054
  switch (msg.event) {
@@ -32916,7 +34151,7 @@ async function* decodeGrokResponses(messages) {
32916
34151
  terminal = true;
32917
34152
  const err = d.response?.error ?? d.error ?? {};
32918
34153
  const raw = String(err.code ?? err.type);
32919
- const code = (Object.hasOwn(ERROR_CODE, raw) ? ERROR_CODE[raw] : undefined) ?? "UPSTREAM";
34154
+ const code = (Object.hasOwn(ERROR_CODE2, raw) ? ERROR_CODE2[raw] : undefined) ?? "UPSTREAM";
32920
34155
  yield {
32921
34156
  type: "error",
32922
34157
  code,
@@ -32940,9 +34175,9 @@ async function* decodeGrokResponses(messages) {
32940
34175
  }
32941
34176
 
32942
34177
  // packages/providers/src/grok/wire.ts
32943
- import { createHash as createHash2 } from "crypto";
34178
+ import { createHash as createHash3 } from "crypto";
32944
34179
  var MAX_TOOLS = 200;
32945
- function encodeToolChoice2(c) {
34180
+ function encodeToolChoice3(c) {
32946
34181
  switch (c.type) {
32947
34182
  case "auto":
32948
34183
  return "auto";
@@ -32956,7 +34191,7 @@ function encodeToolChoice2(c) {
32956
34191
  }
32957
34192
  function promptCacheKey(instructions, firstInput) {
32958
34193
  const stable = JSON.stringify({ instructions, firstInput });
32959
- return createHash2("sha256").update(stable).digest("hex").slice(0, 32);
34194
+ return createHash3("sha256").update(stable).digest("hex").slice(0, 32);
32960
34195
  }
32961
34196
  function toGrokWire(req, model) {
32962
34197
  const degradations = [];
@@ -33049,7 +34284,7 @@ function toGrokWire(req, model) {
33049
34284
  }));
33050
34285
  }
33051
34286
  if (req.toolChoice !== undefined)
33052
- body.tool_choice = encodeToolChoice2(req.toolChoice);
34287
+ body.tool_choice = encodeToolChoice3(req.toolChoice);
33053
34288
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
33054
34289
  if (req.reasoning.mode === "budget") {
33055
34290
  note("grok:reasoning-budget-dropped");
@@ -33067,7 +34302,7 @@ var PROXY_URL = "https://cli-chat-proxy.grok.com/v1/responses";
33067
34302
  var API_URL = "https://api.x.ai/v1/responses";
33068
34303
  var CONV_NAMESPACE = "omni-grok-conv";
33069
34304
  function derivedUuid(value) {
33070
- const h = createHash3("sha256").update(`${CONV_NAMESPACE}:${value}`).digest("hex");
34305
+ const h = createHash4("sha256").update(`${CONV_NAMESPACE}:${value}`).digest("hex");
33071
34306
  const variant = (Number.parseInt(h[16], 16) & 3 | 8).toString(16);
33072
34307
  return [
33073
34308
  h.slice(0, 8),
@@ -33250,7 +34485,7 @@ function reasoningText2(delta) {
33250
34485
  return [];
33251
34486
  }).join("");
33252
34487
  }
33253
- function json5(data) {
34488
+ function json6(data) {
33254
34489
  try {
33255
34490
  const v = JSON.parse(data);
33256
34491
  return typeof v === "object" && v !== null ? v : null;
@@ -33272,7 +34507,7 @@ async function* decodeKiloChat(messages) {
33272
34507
  done = true;
33273
34508
  break;
33274
34509
  }
33275
- const d = json5(msg.data);
34510
+ const d = json6(msg.data);
33276
34511
  if (d === null)
33277
34512
  continue;
33278
34513
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -33372,7 +34607,7 @@ async function* decodeKiloChat(messages) {
33372
34607
  }
33373
34608
 
33374
34609
  // packages/providers/src/kilo/wire.ts
33375
- function encodeToolChoice3(c) {
34610
+ function encodeToolChoice4(c) {
33376
34611
  switch (c.type) {
33377
34612
  case "auto":
33378
34613
  return "auto";
@@ -33483,7 +34718,7 @@ function toKiloWire(req, model) {
33483
34718
  }));
33484
34719
  }
33485
34720
  if (req.toolChoice !== undefined)
33486
- body.tool_choice = encodeToolChoice3(req.toolChoice);
34721
+ body.tool_choice = encodeToolChoice4(req.toolChoice);
33487
34722
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
33488
34723
  if (req.reasoning.mode === "budget") {
33489
34724
  body.reasoning = { max_tokens: req.reasoning.budgetTokens };
@@ -33542,7 +34777,7 @@ var FINISH2 = {
33542
34777
  tool_calls: "toolUse",
33543
34778
  content_filter: "contentFilter"
33544
34779
  };
33545
- function json6(data) {
34780
+ function json7(data) {
33546
34781
  try {
33547
34782
  const v = JSON.parse(data);
33548
34783
  return typeof v === "object" && v !== null ? v : null;
@@ -33564,7 +34799,7 @@ async function* decodeChat(messages) {
33564
34799
  done = true;
33565
34800
  break;
33566
34801
  }
33567
- const d = json6(msg.data);
34802
+ const d = json7(msg.data);
33568
34803
  if (d === null)
33569
34804
  continue;
33570
34805
  if (!started && (d.id !== undefined || d.model !== undefined)) {
@@ -33648,7 +34883,7 @@ async function* decodeChat(messages) {
33648
34883
  }
33649
34884
 
33650
34885
  // packages/providers/src/kimi/wire.ts
33651
- function encodeToolChoice4(c) {
34886
+ function encodeToolChoice5(c) {
33652
34887
  switch (c.type) {
33653
34888
  case "auto":
33654
34889
  return "auto";
@@ -33739,7 +34974,7 @@ function toChatWire(req, model, vendor = "kimi") {
33739
34974
  }));
33740
34975
  }
33741
34976
  if (req.toolChoice !== undefined)
33742
- body.tool_choice = encodeToolChoice4(req.toolChoice);
34977
+ body.tool_choice = encodeToolChoice5(req.toolChoice);
33743
34978
  if (req.reasoning !== undefined)
33744
34979
  note("kimi:reasoning-dropped");
33745
34980
  Object.assign(body, req.vendor?.[vendor] ?? {});
@@ -33779,8 +35014,8 @@ var kimiCodec = {
33779
35014
 
33780
35015
  // packages/providers/src/kimi/index.ts
33781
35016
  var kimiAdapter = codecAdapter("kimi", kimiDescriptor.capabilities, kimiCodec);
33782
- // packages/providers/src/openai/decode.ts
33783
- var ERROR_CODE2 = {
35017
+ // packages/providers/src/muse/decode.ts
35018
+ var ERROR_CODE3 = {
33784
35019
  rate_limit_exceeded: "RATE_LIMIT",
33785
35020
  insufficient_quota: "QUOTA_EXHAUSTED",
33786
35021
  invalid_api_key: "AUTH",
@@ -33815,7 +35050,7 @@ var KNOWN_EVENTS3 = new Set([
33815
35050
  "response.failed",
33816
35051
  "error"
33817
35052
  ]);
33818
- function json7(data) {
35053
+ function json8(data) {
33819
35054
  try {
33820
35055
  const v = JSON.parse(data);
33821
35056
  return typeof v === "object" && v !== null ? v : null;
@@ -33823,7 +35058,7 @@ function json7(data) {
33823
35058
  return null;
33824
35059
  }
33825
35060
  }
33826
- async function* decodeResponses(messages, options = {}) {
35061
+ async function* decodeMuseResponses(messages, options = {}) {
33827
35062
  const nativeReasoning = options.nativeReasoning === true;
33828
35063
  const indices = new Map;
33829
35064
  let next = 0;
@@ -33846,12 +35081,12 @@ async function* decodeResponses(messages, options = {}) {
33846
35081
  yield {
33847
35082
  type: "error",
33848
35083
  code: "UPSTREAM",
33849
- message: `unrecognized OpenAI stream event "${msg.event}"`,
35084
+ message: `unrecognized muse stream event "${msg.event}"`,
33850
35085
  retryable: false
33851
35086
  };
33852
35087
  return;
33853
35088
  }
33854
- const d = json7(msg.data);
35089
+ const d = json8(msg.data);
33855
35090
  if (d === null)
33856
35091
  continue;
33857
35092
  switch (msg.event) {
@@ -33869,7 +35104,7 @@ async function* decodeResponses(messages, options = {}) {
33869
35104
  yield {
33870
35105
  type: "blockStart",
33871
35106
  index: irIndex(d.output_index ?? 0),
33872
- block: nativeReasoning ? { type: "providerNative", provider: "openai", blockType: "reasoning", data: {} } : { type: "thinking" }
35107
+ block: nativeReasoning ? { type: "providerNative", provider: "muse", blockType: "reasoning", data: {} } : { type: "thinking" }
33873
35108
  };
33874
35109
  } else if (item.type === "function_call") {
33875
35110
  sawToolCall = true;
@@ -33904,7 +35139,7 @@ async function* decodeResponses(messages, options = {}) {
33904
35139
  index: irIndex(d.output_index ?? 0),
33905
35140
  delta: nativeReasoning ? {
33906
35141
  type: "providerNative",
33907
- provider: "openai",
35142
+ provider: "muse",
33908
35143
  deltaType: "reasoning_summary_text.delta",
33909
35144
  data: { text: String(d.delta ?? "") }
33910
35145
  } : { type: "thinking", text: String(d.delta ?? "") }
@@ -33930,7 +35165,7 @@ async function* decodeResponses(messages, options = {}) {
33930
35165
  index: irIndex(outputIndex),
33931
35166
  delta: {
33932
35167
  type: "providerNative",
33933
- provider: "openai",
35168
+ provider: "muse",
33934
35169
  deltaType: "response.output_item.done",
33935
35170
  fold: "merge",
33936
35171
  data: item
@@ -33955,7 +35190,7 @@ async function* decodeResponses(messages, options = {}) {
33955
35190
  yield {
33956
35191
  type: "error",
33957
35192
  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",
35193
+ 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
35194
  retryable: false
33960
35195
  };
33961
35196
  break;
@@ -33972,7 +35207,7 @@ async function* decodeResponses(messages, options = {}) {
33972
35207
  terminal = true;
33973
35208
  const err = d.response?.error ?? d.error ?? {};
33974
35209
  const raw = String(err.code ?? err.type);
33975
- const code = (Object.hasOwn(ERROR_CODE2, raw) ? ERROR_CODE2[raw] : undefined) ?? "UPSTREAM";
35210
+ const code = (Object.hasOwn(ERROR_CODE3, raw) ? ERROR_CODE3[raw] : undefined) ?? "UPSTREAM";
33976
35211
  yield {
33977
35212
  type: "error",
33978
35213
  code,
@@ -33995,8 +35230,8 @@ async function* decodeResponses(messages, options = {}) {
33995
35230
  }
33996
35231
  }
33997
35232
 
33998
- // packages/providers/src/openai/wire.ts
33999
- import { createHash as createHash4 } from "crypto";
35233
+ // packages/providers/src/muse/wire.ts
35234
+ import { createHash as createHash5 } from "crypto";
34000
35235
  function suppliedKey(req) {
34001
35236
  const vendor = req.vendor?.openai;
34002
35237
  for (const name of ["prompt_cache_key", "session_id"]) {
@@ -34008,7 +35243,7 @@ function suppliedKey(req) {
34008
35243
  }
34009
35244
  function cacheKey(req, instructions, firstInput) {
34010
35245
  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);
35246
+ return createHash5("sha256").update(stable).digest("hex").slice(0, 32);
34012
35247
  }
34013
35248
  function repairOrphanedCalls(input2) {
34014
35249
  const answered = new Set;
@@ -34027,7 +35262,407 @@ function repairOrphanedCalls(input2) {
34027
35262
  input2.splice(i + 1, 0, { type: "function_call_output", call_id: record2.call_id, output: "" });
34028
35263
  }
34029
35264
  }
34030
- function encodeToolChoice5(c) {
35265
+ function encodeToolChoice6(c) {
35266
+ switch (c.type) {
35267
+ case "auto":
35268
+ return "auto";
35269
+ case "any":
35270
+ return "required";
35271
+ case "none":
35272
+ return "none";
35273
+ case "tool":
35274
+ return { type: "function", name: c.name };
35275
+ }
35276
+ }
35277
+ function toMuseWire(req, model) {
35278
+ const degradations = [];
35279
+ const input2 = [];
35280
+ const note = (d) => {
35281
+ if (!degradations.includes(d))
35282
+ degradations.push(d);
35283
+ };
35284
+ if (req.betas?.includes(CONTEXT_1M_BETA))
35285
+ note("muse:context-1m-dropped");
35286
+ for (const message of req.messages) {
35287
+ const parts = [];
35288
+ const asDeveloper = message.role === "system";
35289
+ if (asDeveloper)
35290
+ note("muse:system-turn-as-developer");
35291
+ const role = asDeveloper ? "developer" : message.role;
35292
+ const flush = () => {
35293
+ if (parts.length === 0)
35294
+ return;
35295
+ input2.push({ type: "message", role, content: [...parts] });
35296
+ parts.length = 0;
35297
+ };
35298
+ for (const block of message.content) {
35299
+ switch (block.type) {
35300
+ case "text":
35301
+ parts.push({
35302
+ type: role === "assistant" ? "output_text" : "input_text",
35303
+ text: block.text
35304
+ });
35305
+ break;
35306
+ case "image":
35307
+ parts.push({
35308
+ type: "input_image",
35309
+ image_url: `data:${block.mediaType};base64,${block.data}`
35310
+ });
35311
+ break;
35312
+ case "thinking":
35313
+ note("muse:thinking-dropped");
35314
+ break;
35315
+ case "toolUse":
35316
+ flush();
35317
+ input2.push({
35318
+ type: "function_call",
35319
+ call_id: block.id,
35320
+ name: block.name,
35321
+ arguments: JSON.stringify(block.input)
35322
+ });
35323
+ break;
35324
+ case "toolResult":
35325
+ flush();
35326
+ input2.push({
35327
+ type: "function_call_output",
35328
+ call_id: block.toolUseId,
35329
+ output: block.content
35330
+ });
35331
+ break;
35332
+ case "providerNative":
35333
+ if (block.provider === "muse") {
35334
+ flush();
35335
+ const { id: _id, ...rest } = block.data;
35336
+ input2.push({ type: block.blockType, ...rest });
35337
+ break;
35338
+ }
35339
+ note("muse:foreign-native-block-dropped");
35340
+ break;
35341
+ }
35342
+ }
35343
+ flush();
35344
+ }
35345
+ repairOrphanedCalls(input2);
35346
+ const body = { model, input: input2, stream: req.stream, store: false };
35347
+ const instructions = systemText(req.system, "muse", note);
35348
+ if (instructions !== undefined && instructions.length > 0)
35349
+ body.instructions = instructions;
35350
+ if (req.maxTokens !== undefined)
35351
+ body.max_output_tokens = req.maxTokens;
35352
+ if (req.temperature !== undefined)
35353
+ body.temperature = req.temperature;
35354
+ if (req.tools !== undefined) {
35355
+ const portable = req.tools.filter((t) => t.kind === "portable");
35356
+ if (portable.length !== req.tools.length)
35357
+ note("muse:provider-tool-dropped");
35358
+ body.tools = portable.map((t) => ({
35359
+ type: "function",
35360
+ name: t.name,
35361
+ description: t.description,
35362
+ parameters: t.inputSchema
35363
+ }));
35364
+ }
35365
+ if (req.toolChoice !== undefined)
35366
+ body.tool_choice = encodeToolChoice6(req.toolChoice);
35367
+ if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
35368
+ if (req.reasoning.mode === "budget") {
35369
+ note("muse:reasoning-budget-dropped");
35370
+ } else {
35371
+ const effort = req.reasoning.effort ?? "medium";
35372
+ body.reasoning = { effort, summary: "auto" };
35373
+ }
35374
+ }
35375
+ const key = suppliedKey(req) ?? cacheKey(req, instructions ?? "", input2[0]);
35376
+ Object.assign(body, req.vendor?.openai ?? {});
35377
+ body.prompt_cache_key = key;
35378
+ return { body, degradations, cacheKey: key };
35379
+ }
35380
+
35381
+ // packages/providers/src/muse/codec.ts
35382
+ var museCodec = {
35383
+ buildRequest(input2) {
35384
+ const { body, degradations, cacheKey: cacheKey2 } = toMuseWire(input2.request, input2.model);
35385
+ if (input2.credentials.apiKey === null) {
35386
+ throw input2.fail("AUTH", "muse credential has no model api key");
35387
+ }
35388
+ const protocol = [
35389
+ ["Content-Type", "application/json"],
35390
+ ["Authorization", `Bearer ${input2.credentials.apiKey}`],
35391
+ ["x-meta-ai-gateway-session-id", cacheKey2]
35392
+ ];
35393
+ const headers = orderHeaders(mergeHeaders(museProfile.headers, protocol), museProfile.order);
35394
+ const include = body.include;
35395
+ const nativeReasoning = Array.isArray(include) && include.includes("reasoning.encrypted_content");
35396
+ return {
35397
+ decodeState: { nativeReasoning },
35398
+ request: {
35399
+ url: museResponsesUrl(input2.credentials.providerData),
35400
+ method: "POST",
35401
+ headers,
35402
+ body: JSON.stringify(orderFields({ ...body, stream: true }, museBodyOrder))
35403
+ },
35404
+ degradations
35405
+ };
35406
+ },
35407
+ decode({ body, decodeState }) {
35408
+ const state = decodeState;
35409
+ return decodeMuseResponses(parseSse(body), {
35410
+ nativeReasoning: state?.nativeReasoning === true
35411
+ });
35412
+ }
35413
+ };
35414
+
35415
+ // packages/providers/src/muse/index.ts
35416
+ var museAdapter = codecAdapter("muse", museDescriptor.capabilities, museCodec);
35417
+ // packages/providers/src/openai/decode.ts
35418
+ var ERROR_CODE4 = {
35419
+ rate_limit_exceeded: "RATE_LIMIT",
35420
+ insufficient_quota: "QUOTA_EXHAUSTED",
35421
+ invalid_api_key: "AUTH",
35422
+ server_error: "UPSTREAM",
35423
+ context_length_exceeded: "BAD_REQUEST",
35424
+ content_policy_violation: "CONTENT_FILTER"
35425
+ };
35426
+ var KNOWN_EVENTS4 = new Set([
35427
+ "keepalive",
35428
+ "response.created",
35429
+ "response.queued",
35430
+ "response.in_progress",
35431
+ "response.output_item.added",
35432
+ "response.output_item.done",
35433
+ "response.content_part.added",
35434
+ "response.content_part.done",
35435
+ "response.output_text.delta",
35436
+ "response.output_text.done",
35437
+ "response.output_text.annotation.added",
35438
+ "response.refusal.delta",
35439
+ "response.refusal.done",
35440
+ "response.reasoning_summary_part.added",
35441
+ "response.reasoning_summary_part.done",
35442
+ "response.reasoning_summary_text.delta",
35443
+ "response.reasoning_summary_text.done",
35444
+ "response.reasoning_text.delta",
35445
+ "response.reasoning_text.done",
35446
+ "response.function_call_arguments.delta",
35447
+ "response.function_call_arguments.done",
35448
+ "response.completed",
35449
+ "response.incomplete",
35450
+ "response.failed",
35451
+ "error"
35452
+ ]);
35453
+ function json9(data) {
35454
+ try {
35455
+ const v = JSON.parse(data);
35456
+ return typeof v === "object" && v !== null ? v : null;
35457
+ } catch {
35458
+ return null;
35459
+ }
35460
+ }
35461
+ async function* decodeResponses(messages, options = {}) {
35462
+ const nativeReasoning = options.nativeReasoning === true;
35463
+ const indices = new Map;
35464
+ let next = 0;
35465
+ const irIndex = (outputIndex, contentIndex = 0) => {
35466
+ const key = `${outputIndex}:${contentIndex}`;
35467
+ const existing = indices.get(key);
35468
+ if (existing !== undefined)
35469
+ return existing;
35470
+ const assigned = next++;
35471
+ indices.set(key, assigned);
35472
+ return assigned;
35473
+ };
35474
+ let sawToolCall = false;
35475
+ let terminal = false;
35476
+ const ownsBlock = new Set;
35477
+ for await (const msg of messages) {
35478
+ if (msg.data === "[DONE]")
35479
+ continue;
35480
+ if (!KNOWN_EVENTS4.has(msg.event)) {
35481
+ yield {
35482
+ type: "error",
35483
+ code: "UPSTREAM",
35484
+ message: `unrecognized OpenAI stream event "${msg.event}"`,
35485
+ retryable: false
35486
+ };
35487
+ return;
35488
+ }
35489
+ const d = json9(msg.data);
35490
+ if (d === null)
35491
+ continue;
35492
+ switch (msg.event) {
35493
+ case "response.created":
35494
+ yield {
35495
+ type: "start",
35496
+ id: String(d.response?.id ?? ""),
35497
+ model: String(d.response?.model ?? "")
35498
+ };
35499
+ break;
35500
+ case "response.output_item.added": {
35501
+ const item = d.item ?? {};
35502
+ if (item.type === "reasoning") {
35503
+ ownsBlock.add(d.output_index ?? 0);
35504
+ yield {
35505
+ type: "blockStart",
35506
+ index: irIndex(d.output_index ?? 0),
35507
+ block: nativeReasoning ? { type: "providerNative", provider: "openai", blockType: "reasoning", data: {} } : { type: "thinking" }
35508
+ };
35509
+ } else if (item.type === "function_call") {
35510
+ sawToolCall = true;
35511
+ ownsBlock.add(d.output_index ?? 0);
35512
+ yield {
35513
+ type: "blockStart",
35514
+ index: irIndex(d.output_index ?? 0),
35515
+ block: { type: "toolUse", id: String(item.call_id), name: String(item.name) }
35516
+ };
35517
+ }
35518
+ break;
35519
+ }
35520
+ case "response.content_part.added":
35521
+ if (d.part?.type === "output_text") {
35522
+ yield {
35523
+ type: "blockStart",
35524
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
35525
+ block: { type: "text" }
35526
+ };
35527
+ }
35528
+ break;
35529
+ case "response.output_text.delta":
35530
+ yield {
35531
+ type: "blockDelta",
35532
+ index: irIndex(d.output_index ?? 0, d.content_index ?? 0),
35533
+ delta: { type: "text", text: String(d.delta ?? "") }
35534
+ };
35535
+ break;
35536
+ case "response.reasoning_summary_text.delta":
35537
+ yield {
35538
+ type: "blockDelta",
35539
+ index: irIndex(d.output_index ?? 0),
35540
+ delta: nativeReasoning ? {
35541
+ type: "providerNative",
35542
+ provider: "openai",
35543
+ deltaType: "reasoning_summary_text.delta",
35544
+ data: { text: String(d.delta ?? "") }
35545
+ } : { type: "thinking", text: String(d.delta ?? "") }
35546
+ };
35547
+ break;
35548
+ case "response.function_call_arguments.delta":
35549
+ yield {
35550
+ type: "blockDelta",
35551
+ index: irIndex(d.output_index ?? 0),
35552
+ delta: { type: "toolJson", partial: String(d.delta ?? "") }
35553
+ };
35554
+ break;
35555
+ case "response.content_part.done":
35556
+ yield { type: "blockEnd", index: irIndex(d.output_index ?? 0, d.content_index ?? 0) };
35557
+ break;
35558
+ case "response.output_item.done": {
35559
+ const outputIndex = d.output_index ?? 0;
35560
+ if (ownsBlock.delete(outputIndex)) {
35561
+ const item = d.item ?? {};
35562
+ if (nativeReasoning && item.type === "reasoning") {
35563
+ yield {
35564
+ type: "blockDelta",
35565
+ index: irIndex(outputIndex),
35566
+ delta: {
35567
+ type: "providerNative",
35568
+ provider: "openai",
35569
+ deltaType: "response.output_item.done",
35570
+ fold: "merge",
35571
+ data: item
35572
+ }
35573
+ };
35574
+ }
35575
+ yield { type: "blockEnd", index: irIndex(outputIndex) };
35576
+ }
35577
+ break;
35578
+ }
35579
+ case "response.completed":
35580
+ case "response.incomplete": {
35581
+ terminal = true;
35582
+ const r = d.response ?? {};
35583
+ const reason = r.incomplete_details?.reason;
35584
+ let stopReason = sawToolCall ? "toolUse" : "endTurn";
35585
+ if (reason === "max_output_tokens")
35586
+ stopReason = "maxTokens";
35587
+ else if (reason === "content_filter")
35588
+ stopReason = "contentFilter";
35589
+ else if (reason !== undefined || msg.event === "response.incomplete" || r.status !== undefined && r.status !== "completed") {
35590
+ yield {
35591
+ type: "error",
35592
+ code: "UPSTREAM",
35593
+ 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",
35594
+ retryable: false
35595
+ };
35596
+ break;
35597
+ }
35598
+ yield {
35599
+ type: "end",
35600
+ stopReason,
35601
+ 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)
35602
+ };
35603
+ break;
35604
+ }
35605
+ case "response.failed":
35606
+ case "error": {
35607
+ terminal = true;
35608
+ const err = d.response?.error ?? d.error ?? {};
35609
+ const raw = String(err.code ?? err.type);
35610
+ const code = (Object.hasOwn(ERROR_CODE4, raw) ? ERROR_CODE4[raw] : undefined) ?? "UPSTREAM";
35611
+ yield {
35612
+ type: "error",
35613
+ code,
35614
+ message: String(err.message ?? "upstream error"),
35615
+ retryable: RETRYABLE[code]
35616
+ };
35617
+ break;
35618
+ }
35619
+ default:
35620
+ break;
35621
+ }
35622
+ }
35623
+ if (!terminal) {
35624
+ yield {
35625
+ type: "error",
35626
+ code: "UPSTREAM",
35627
+ message: "upstream stream ended before response completion",
35628
+ retryable: RETRYABLE.UPSTREAM
35629
+ };
35630
+ }
35631
+ }
35632
+
35633
+ // packages/providers/src/openai/wire.ts
35634
+ import { createHash as createHash6 } from "crypto";
35635
+ function suppliedKey2(req) {
35636
+ const vendor = req.vendor?.openai;
35637
+ for (const name of ["prompt_cache_key", "session_id"]) {
35638
+ const value = vendor?.[name];
35639
+ if (typeof value === "string" && value.length > 0)
35640
+ return value;
35641
+ }
35642
+ return;
35643
+ }
35644
+ function cacheKey2(req, instructions, firstInput) {
35645
+ const stable = req.conversationId !== undefined && req.conversationId.length > 0 ? JSON.stringify({ conversation: req.conversationId }) : JSON.stringify({ instructions, firstInput: firstInput ?? null });
35646
+ return createHash6("sha256").update(stable).digest("hex").slice(0, 32);
35647
+ }
35648
+ function repairOrphanedCalls2(input2) {
35649
+ const answered = new Set;
35650
+ for (const item of input2) {
35651
+ const record2 = item;
35652
+ if (record2.type === "function_call_output" && typeof record2.call_id === "string") {
35653
+ answered.add(record2.call_id);
35654
+ }
35655
+ }
35656
+ for (let i = input2.length - 1;i >= 0; i--) {
35657
+ const record2 = input2[i];
35658
+ if (record2.type !== "function_call" || typeof record2.call_id !== "string")
35659
+ continue;
35660
+ if (answered.has(record2.call_id))
35661
+ continue;
35662
+ input2.splice(i + 1, 0, { type: "function_call_output", call_id: record2.call_id, output: "" });
35663
+ }
35664
+ }
35665
+ function encodeToolChoice7(c) {
34031
35666
  switch (c.type) {
34032
35667
  case "auto":
34033
35668
  return "auto";
@@ -34109,7 +35744,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34109
35744
  }
34110
35745
  flush();
34111
35746
  }
34112
- repairOrphanedCalls(input2);
35747
+ repairOrphanedCalls2(input2);
34113
35748
  const body = { model, input: input2, stream: req.stream, store: false };
34114
35749
  const instructions = systemText(req.system, "openai", note);
34115
35750
  if (instructions !== undefined && instructions.length > 0)
@@ -34138,7 +35773,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34138
35773
  }));
34139
35774
  }
34140
35775
  if (req.toolChoice !== undefined)
34141
- body.tool_choice = encodeToolChoice5(req.toolChoice);
35776
+ body.tool_choice = encodeToolChoice7(req.toolChoice);
34142
35777
  if (req.reasoning !== undefined && req.reasoning.mode !== "off") {
34143
35778
  if (req.reasoning.mode === "budget") {
34144
35779
  degradations.push("openai:reasoning-budget-dropped");
@@ -34147,7 +35782,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
34147
35782
  body.reasoning = { effort, summary: "auto" };
34148
35783
  }
34149
35784
  }
34150
- const key = suppliedKey(req) ?? cacheKey(req, instructions ?? "", input2[0]);
35785
+ const key = suppliedKey2(req) ?? cacheKey2(req, instructions ?? "", input2[0]);
34151
35786
  Object.assign(body, req.vendor?.openai ?? {});
34152
35787
  body.prompt_cache_key = key;
34153
35788
  return { body, degradations, cacheKey: key };
@@ -34159,14 +35794,14 @@ var API_URL3 = "https://api.openai.com/v1/responses";
34159
35794
  var openaiCodec = {
34160
35795
  buildRequest(input2) {
34161
35796
  const oauth = input2.credentials.accessToken !== null;
34162
- const { body, degradations, cacheKey: cacheKey2 } = toResponsesWire(input2.request, input2.model, { oauth });
35797
+ const { body, degradations, cacheKey: cacheKey3 } = toResponsesWire(input2.request, input2.model, { oauth });
34163
35798
  const protocol = [["Content-Type", "application/json"]];
34164
35799
  if (oauth) {
34165
35800
  protocol.push(["Authorization", `Bearer ${input2.credentials.accessToken}`]);
34166
35801
  const accountId = input2.credentials.providerData.accountId;
34167
35802
  if (typeof accountId === "string")
34168
35803
  protocol.push(["chatgpt-account-id", accountId]);
34169
- protocol.push(["session_id", cacheKey2]);
35804
+ protocol.push(["session_id", cacheKey3]);
34170
35805
  } else if (input2.credentials.apiKey !== null) {
34171
35806
  protocol.push(["Authorization", `Bearer ${input2.credentials.apiKey}`]);
34172
35807
  } else {
@@ -34201,6 +35836,8 @@ var ADAPTERS = {
34201
35836
  kimi: kimiAdapter,
34202
35837
  kilo: kiloAdapter,
34203
35838
  grok: grokAdapter,
35839
+ antigravity: antigravityAdapter,
35840
+ muse: museAdapter,
34204
35841
  custom: customAdapter
34205
35842
  };
34206
35843
  Object.setPrototypeOf(ADAPTERS, null);
@@ -35812,7 +37449,7 @@ import { join as join3 } from "path";
35812
37449
 
35813
37450
  // packages/plugin-api/src/version.ts
35814
37451
  var PLUGIN_API_VERSION = 3;
35815
- var DASHBOARD_SDK_VERSION = "0.1.6";
37452
+ var DASHBOARD_SDK_VERSION = "0.1.8";
35816
37453
  // packages/plugin-api/src/manifest.ts
35817
37454
  var CAPABILITIES = [
35818
37455
  "storage",
@@ -36250,7 +37887,7 @@ function createRefresher(deps) {
36250
37887
  };
36251
37888
  }
36252
37889
  // packages/control/src/pluginProviders.ts
36253
- function isRecord6(value) {
37890
+ function isRecord7(value) {
36254
37891
  return typeof value === "object" && value !== null && !Array.isArray(value);
36255
37892
  }
36256
37893
  function isNumber(value) {
@@ -36261,7 +37898,7 @@ function checkAt(ok, id, path, expected) {
36261
37898
  throw new Error(`provider ${id} descriptor: ${path} must be ${expected}`);
36262
37899
  }
36263
37900
  function checkLimits(id, path, value) {
36264
- checkAt(isRecord6(value), id, path, "an object");
37901
+ checkAt(isRecord7(value), id, path, "an object");
36265
37902
  const limits = value;
36266
37903
  checkAt(isNumber(limits.contextWindow), id, `${path}.contextWindow`, "a finite number");
36267
37904
  checkAt(isNumber(limits.maxOutputTokens), id, `${path}.maxOutputTokens`, "a finite number");
@@ -36279,19 +37916,19 @@ function checkDescriptor(id, record2) {
36279
37916
  }
36280
37917
  }
36281
37918
  const capabilities2 = record2.capabilities;
36282
- checkAt(isRecord6(capabilities2), id, "capabilities", "an object");
37919
+ checkAt(isRecord7(capabilities2), id, "capabilities", "an object");
36283
37920
  for (const flag of ["tools", "images", "reasoning"]) {
36284
37921
  const value = capabilities2[flag];
36285
37922
  checkAt(typeof value === "boolean", id, `capabilities.${flag}`, "a boolean");
36286
37923
  }
36287
37924
  const write = record2.writeOverInput;
36288
- checkAt(isRecord6(write), id, "writeOverInput", "an object");
37925
+ checkAt(isRecord7(write), id, "writeOverInput", "an object");
36289
37926
  for (const ttl of ["fiveMinute", "oneHour"]) {
36290
37927
  const value = write[ttl];
36291
37928
  checkAt(isNumber(value), id, `writeOverInput.${ttl}`, "a finite number");
36292
37929
  }
36293
37930
  const catalog2 = record2.catalog;
36294
- checkAt(isRecord6(catalog2), id, "catalog", "an object");
37931
+ checkAt(isRecord7(catalog2), id, "catalog", "an object");
36295
37932
  const entry = catalog2;
36296
37933
  checkAt(typeof entry.defaultModel === "string", id, "catalog.defaultModel", "a string");
36297
37934
  checkAt(Array.isArray(entry.authTypes), id, "catalog.authTypes", "an array");
@@ -36302,11 +37939,11 @@ function checkDescriptor(id, record2) {
36302
37939
  checkAt(Array.isArray(entry.models), id, "catalog.models", "an array");
36303
37940
  for (const [index, model] of entry.models.entries()) {
36304
37941
  const at = `catalog.models[${index}]`;
36305
- checkAt(isRecord6(model), id, at, "an object");
37942
+ checkAt(isRecord7(model), id, at, "an object");
36306
37943
  const choice = model;
36307
37944
  checkAt(typeof choice.id === "string", id, `${at}.id`, "a string");
36308
37945
  checkAt(typeof choice.label === "string", id, `${at}.label`, "a string");
36309
- checkAt(isRecord6(choice.pricing), id, `${at}.pricing`, "an object");
37946
+ checkAt(isRecord7(choice.pricing), id, `${at}.pricing`, "an object");
36310
37947
  const pricing = choice.pricing;
36311
37948
  for (const field of ["input", "output", "cacheRead", "cacheWrite5m", "cacheWrite1h"]) {
36312
37949
  checkAt(isNumber(pricing[field]), id, `${at}.pricing.${field}`, "a finite number");
@@ -36322,13 +37959,13 @@ function checkDescriptor(id, record2) {
36322
37959
  checkAt(typeof prefix === "string", id, `modelPrefixes[${index}]`, "a string");
36323
37960
  }
36324
37961
  const presentation = record2.presentation;
36325
- checkAt(isRecord6(presentation), id, "presentation", "an object");
37962
+ checkAt(isRecord7(presentation), id, "presentation", "an object");
36326
37963
  const shown = presentation;
36327
37964
  for (const field of ["label", "tone"]) {
36328
37965
  checkAt(typeof shown[field] === "string", id, `presentation.${field}`, "a string");
36329
37966
  }
36330
37967
  checkAt(isNumber(shown.order), id, "presentation.order", "a finite number");
36331
- checkAt(isRecord6(shown.colour), id, "presentation.colour", "an object");
37968
+ checkAt(isRecord7(shown.colour), id, "presentation.colour", "an object");
36332
37969
  for (const scheme of ["light", "dark"]) {
36333
37970
  const value = shown.colour[scheme];
36334
37971
  checkAt(typeof value === "string", id, `presentation.colour.${scheme}`, "a string");
@@ -36340,7 +37977,7 @@ function checkDescriptor(id, record2) {
36340
37977
  function validateOAuthFlow(id, value) {
36341
37978
  if (value === undefined)
36342
37979
  return;
36343
- if (!isRecord6(value))
37980
+ if (!isRecord7(value))
36344
37981
  throw new Error(`provider ${id} oauth must be an object`);
36345
37982
  const kind = value.kind;
36346
37983
  if (kind !== "pkce" && kind !== "device") {
@@ -37972,13 +39609,13 @@ function IsSeparator(pattern, index) {
37972
39609
  function IsGroup(pattern) {
37973
39610
  if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
37974
39611
  return false;
37975
- let count = 0;
39612
+ let count2 = 0;
37976
39613
  for (let index = 0;index < pattern.length; index++) {
37977
39614
  if (IsOpenParen(pattern, index))
37978
- count += 1;
39615
+ count2 += 1;
37979
39616
  if (IsCloseParen(pattern, index))
37980
- count -= 1;
37981
- if (count === 0 && index !== pattern.length - 1)
39617
+ count2 -= 1;
39618
+ if (count2 === 0 && index !== pattern.length - 1)
37982
39619
  return false;
37983
39620
  }
37984
39621
  return true;
@@ -37987,13 +39624,13 @@ function InGroup(pattern) {
37987
39624
  return pattern.slice(1, pattern.length - 1);
37988
39625
  }
37989
39626
  function IsPrecedenceOr(pattern) {
37990
- let count = 0;
39627
+ let count2 = 0;
37991
39628
  for (let index = 0;index < pattern.length; index++) {
37992
39629
  if (IsOpenParen(pattern, index))
37993
- count += 1;
39630
+ count2 += 1;
37994
39631
  if (IsCloseParen(pattern, index))
37995
- count -= 1;
37996
- if (IsSeparator(pattern, index) && count === 0)
39632
+ count2 -= 1;
39633
+ if (IsSeparator(pattern, index) && count2 === 0)
37997
39634
  return true;
37998
39635
  }
37999
39636
  return false;
@@ -38006,14 +39643,14 @@ function IsPrecedenceAnd(pattern) {
38006
39643
  return false;
38007
39644
  }
38008
39645
  function Or(pattern) {
38009
- let [count, start] = [0, 0];
39646
+ let [count2, start] = [0, 0];
38010
39647
  const expressions = [];
38011
39648
  for (let index = 0;index < pattern.length; index++) {
38012
39649
  if (IsOpenParen(pattern, index))
38013
- count += 1;
39650
+ count2 += 1;
38014
39651
  if (IsCloseParen(pattern, index))
38015
- count -= 1;
38016
- if (IsSeparator(pattern, index) && count === 0) {
39652
+ count2 -= 1;
39653
+ if (IsSeparator(pattern, index) && count2 === 0) {
38017
39654
  const range2 = pattern.slice(start, index);
38018
39655
  if (range2.length > 0)
38019
39656
  expressions.push(TemplateLiteralParse(range2));
@@ -38033,13 +39670,13 @@ function And(pattern) {
38033
39670
  function Group(value, index) {
38034
39671
  if (!IsOpenParen(value, index))
38035
39672
  throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
38036
- let count = 0;
39673
+ let count2 = 0;
38037
39674
  for (let scan = index;scan < value.length; scan++) {
38038
39675
  if (IsOpenParen(value, scan))
38039
- count += 1;
39676
+ count2 += 1;
38040
39677
  if (IsCloseParen(value, scan))
38041
- count -= 1;
38042
- if (count === 0)
39678
+ count2 -= 1;
39679
+ if (count2 === 0)
38043
39680
  return [index, scan];
38044
39681
  }
38045
39682
  throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
@@ -38809,8 +40446,8 @@ function FromNumberRight(left, right) {
38809
40446
  function FromNumber(left, right) {
38810
40447
  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
40448
  }
38812
- function IsObjectPropertyCount(schema, count) {
38813
- return Object.getOwnPropertyNames(schema.properties).length === count;
40449
+ function IsObjectPropertyCount(schema, count2) {
40450
+ return Object.getOwnPropertyNames(schema.properties).length === count2;
38814
40451
  }
38815
40452
  function IsObjectStringLike(schema) {
38816
40453
  return IsObjectArrayLike(schema);
@@ -44279,7 +45916,7 @@ var emptySchema = {
44279
45916
 
44280
45917
  // node_modules/.bun/elysia@1.4.30+7c910760591f72db/node_modules/elysia/dist/error.mjs
44281
45918
  var env2 = typeof Bun < "u" ? Bun.env : typeof process < "u" ? process?.env : undefined;
44282
- var ERROR_CODE3 = Symbol("ElysiaErrorCode");
45919
+ var ERROR_CODE5 = Symbol("ElysiaErrorCode");
44283
45920
  var isProduction = (env2?.NODE_ENV ?? env2?.ENV) === "production";
44284
45921
  var emptyHttpStatus = {
44285
45922
  101: undefined,
@@ -48852,7 +50489,7 @@ c.defs=definitions
48852
50489
  schema: app.router.history,
48853
50490
  definitions: app.definitions.type,
48854
50491
  tee,
48855
- ERROR_CODE: ERROR_CODE3,
50492
+ ERROR_CODE: ERROR_CODE5,
48856
50493
  parseCookie: hasCookie ? parseCookie : undefined,
48857
50494
  signCookie: hasCookie ? signCookie : undefined,
48858
50495
  Cookie: hasCookie ? Cookie : undefined,
@@ -49125,7 +50762,7 @@ return mapResponse(${saveResponse}error,set${adapter.mapResponseContext})}`;
49125
50762
  return Function("inject", `"use strict";
49126
50763
  ` + fnLiteral)({
49127
50764
  mapResponse: app["~adapter"].handler.mapResponse,
49128
- ERROR_CODE: ERROR_CODE3,
50765
+ ERROR_CODE: ERROR_CODE5,
49129
50766
  ElysiaCustomStatusResponse,
49130
50767
  ValidationError,
49131
50768
  TransformDecodeError,
@@ -50608,12 +52245,12 @@ var _Elysia = class _Elysia2 {
50608
52245
  error(name, error61) {
50609
52246
  switch (typeof name) {
50610
52247
  case "string":
50611
- return error61.prototype[ERROR_CODE3] = name, this.definitions.error[name] = error61, this;
52248
+ return error61.prototype[ERROR_CODE5] = name, this.definitions.error[name] = error61, this;
50612
52249
  case "function":
50613
52250
  return this.definitions.error = name(this.definitions.error), this;
50614
52251
  }
50615
52252
  for (const [code, error210] of Object.entries(name))
50616
- error210.prototype[ERROR_CODE3] = code, this.definitions.error[code] = error210;
52253
+ error210.prototype[ERROR_CODE5] = code, this.definitions.error[code] = error210;
50617
52254
  return this;
50618
52255
  }
50619
52256
  onError(options, handler) {
@@ -51575,9 +53212,9 @@ function createLoadRegistry(coord = memoryCoord()) {
51575
53212
  },
51576
53213
  counts() {
51577
53214
  const out = new Map(local);
51578
- for (const [key, count] of remote) {
51579
- if (count > (out.get(key) ?? 0))
51580
- out.set(key, count);
53215
+ for (const [key, count2] of remote) {
53216
+ if (count2 > (out.get(key) ?? 0))
53217
+ out.set(key, count2);
51581
53218
  }
51582
53219
  return out;
51583
53220
  },
@@ -51587,8 +53224,8 @@ function createLoadRegistry(coord = memoryCoord()) {
51587
53224
  async refresh() {
51588
53225
  const held = await coord.gauge.snapshot(PREFIX6);
51589
53226
  const sample = new Map;
51590
- for (const [key, count] of held)
51591
- sample.set(key.slice(PREFIX6.length), count);
53227
+ for (const [key, count2] of held)
53228
+ sample.set(key.slice(PREFIX6.length), count2);
51592
53229
  remote = sample;
51593
53230
  }
51594
53231
  };
@@ -51664,7 +53301,7 @@ function createRoutingSnapshotCache(store, logger2 = noopLogger) {
51664
53301
  }
51665
53302
 
51666
53303
  // apps/gateway/src/egress/anthropic.ts
51667
- var STOP_REASON2 = {
53304
+ var STOP_REASON3 = {
51668
53305
  endTurn: "end_turn",
51669
53306
  maxTokens: "max_tokens",
51670
53307
  stopSequence: "stop_sequence",
@@ -51761,7 +53398,7 @@ async function* anthropicStream(events, requestId) {
51761
53398
  case "end":
51762
53399
  yield frame("message_delta", {
51763
53400
  type: "message_delta",
51764
- delta: { stop_reason: STOP_REASON2[event.stopReason], stop_sequence: null },
53401
+ delta: { stop_reason: STOP_REASON3[event.stopReason], stop_sequence: null },
51765
53402
  usage: {
51766
53403
  input_tokens: event.usage.inputTokens,
51767
53404
  output_tokens: event.usage.outputTokens,
@@ -51804,7 +53441,7 @@ function anthropicResponse(collected, requestId) {
51804
53441
  return { type: "text", text: "" };
51805
53442
  }
51806
53443
  }),
51807
- stop_reason: STOP_REASON2[collected.stopReason],
53444
+ stop_reason: STOP_REASON3[collected.stopReason],
51808
53445
  stop_sequence: null,
51809
53446
  usage: {
51810
53447
  input_tokens: collected.usage.inputTokens,
@@ -52432,7 +54069,7 @@ function zodDetail(issue2) {
52432
54069
  }
52433
54070
  return issue2.message;
52434
54071
  }
52435
- function isRecord7(value) {
54072
+ function isRecord8(value) {
52436
54073
  return typeof value === "object" && value !== null;
52437
54074
  }
52438
54075
  function extraFields(body2, known) {
@@ -52567,7 +54204,7 @@ async function readJson(request2) {
52567
54204
  }
52568
54205
  async function readJsonRecord(request2) {
52569
54206
  const body2 = await readJson(request2);
52570
- return isRecord7(body2) ? body2 : null;
54207
+ return isRecord8(body2) ? body2 : null;
52571
54208
  }
52572
54209
  function apiErrorResponse(error61) {
52573
54210
  const gatewayError = error61 instanceof GatewayError ? error61 : new GatewayError("INTERNAL", "internal error");
@@ -53807,10 +55444,10 @@ function classifyGrep(executable, args) {
53807
55444
  else if (argument === "-n" || argument === "--line-number")
53808
55445
  lineNumber = true;
53809
55446
  else if (["-C", "-A", "-B", "--context", "--after-context", "--before-context"].includes(argument)) {
53810
- const count = args[++index];
53811
- if (count === undefined || !/^\d+$/.test(count))
55447
+ const count2 = args[++index];
55448
+ if (count2 === undefined || !/^\d+$/.test(count2))
53812
55449
  return;
53813
- const value = Number(count);
55450
+ const value = Number(count2);
53814
55451
  if (argument === "-C" || argument === "--context") {
53815
55452
  beforeContext = value;
53816
55453
  afterContext = value;
@@ -54032,12 +55669,12 @@ class ParserBudget {
54032
55669
  constructor(inputCodeUnits) {
54033
55670
  this.inputCodeUnits = inputCodeUnits;
54034
55671
  }
54035
- chargeRecords(count) {
54036
- this.records += count;
55672
+ chargeRecords(count2) {
55673
+ this.records += count2;
54037
55674
  return this.records <= 1e5;
54038
55675
  }
54039
- chargeCodeUnits(count) {
54040
- this.codeUnits += count;
55676
+ chargeCodeUnits(count2) {
55677
+ this.codeUnits += count2;
54041
55678
  return this.codeUnits <= this.inputCodeUnits * 3;
54042
55679
  }
54043
55680
  }
@@ -54096,8 +55733,8 @@ function renderSelection(input2, selected, unit = "lines") {
54096
55733
  return renderGaps(input2, selected, (start, end) => `... ${end - start + 1} ${unit} omitted ...`);
54097
55734
  }
54098
55735
  function selectBlock(input2, selected, block) {
54099
- const count = block.end - block.start + 1;
54100
- if (!input2.budget.chargeRecords(count))
55736
+ const count2 = block.end - block.start + 1;
55737
+ if (!input2.budget.chargeRecords(count2))
54101
55738
  return false;
54102
55739
  for (let index = block.start;index <= block.end; index++)
54103
55740
  selected.add(index);
@@ -54421,8 +56058,8 @@ function renderGroups(input2, groups) {
54421
56058
  return;
54422
56059
  }
54423
56060
  if (group.entryCount > 12) {
54424
- const count = group.entryCount - 12;
54425
- if (!append(`... ${count} ${count === 1 ? "entry" : "entries"} omitted from ${group.key} ...`))
56061
+ const count2 = group.entryCount - 12;
56062
+ if (!append(`... ${count2} ${count2 === 1 ? "entry" : "entries"} omitted from ${group.key} ...`))
54426
56063
  return;
54427
56064
  }
54428
56065
  }
@@ -54445,12 +56082,12 @@ function subtreeCounts(input2, node2, classified) {
54445
56082
  let entries = 0;
54446
56083
  let ambiguous = false;
54447
56084
  for (const child of node2.children) {
54448
- const count = subtreeCounts(input2, child, classified);
54449
- if (count === undefined)
56085
+ const count2 = subtreeCounts(input2, child, classified);
56086
+ if (count2 === undefined)
54450
56087
  return;
54451
- directories += count.directories;
54452
- entries += count.entries;
54453
- ambiguous ||= count.ambiguous;
56088
+ directories += count2.directories;
56089
+ entries += count2.entries;
56090
+ ambiguous ||= count2.ambiguous;
54454
56091
  }
54455
56092
  return { directories, entries, ambiguous };
54456
56093
  }
@@ -54470,12 +56107,12 @@ function appendSubtree(input2, output2, node2, classified) {
54470
56107
  let entries = 0;
54471
56108
  let ambiguous = false;
54472
56109
  for (const child of omitted) {
54473
- const count = subtreeCounts(input2, child, classified);
54474
- if (count === undefined)
56110
+ const count2 = subtreeCounts(input2, child, classified);
56111
+ if (count2 === undefined)
54475
56112
  return false;
54476
- directories += count.directories;
54477
- entries += count.entries;
54478
- ambiguous ||= count.ambiguous;
56113
+ directories += count2.directories;
56114
+ entries += count2.entries;
56115
+ ambiguous ||= count2.ambiguous;
54479
56116
  }
54480
56117
  if (ambiguous)
54481
56118
  return false;
@@ -55153,8 +56790,8 @@ function compressTests(input2, executable = "unknown") {
55153
56790
  break;
55154
56791
  end++;
55155
56792
  }
55156
- const count = end - start + 1;
55157
- if (!input2.budget.chargeRecords(count))
56793
+ const count2 = end - start + 1;
56794
+ if (!input2.budget.chargeRecords(count2))
55158
56795
  return text;
55159
56796
  for (let index = start;index <= end; index++)
55160
56797
  selected.add(index);
@@ -56807,10 +58444,10 @@ function toIrToolChoice(c) {
56807
58444
  }
56808
58445
  var EFFORTS = REASONING_EFFORTS;
56809
58446
  function readEffort(body2) {
56810
- if (!isRecord7(body2))
58447
+ if (!isRecord8(body2))
56811
58448
  return;
56812
58449
  const outputConfig = body2.output_config;
56813
- if (!isRecord7(outputConfig))
58450
+ if (!isRecord8(outputConfig))
56814
58451
  return;
56815
58452
  const effort = outputConfig.effort;
56816
58453
  return EFFORTS.find((level) => level === effort);
@@ -57105,7 +58742,7 @@ function parseOpenAIRequest(body2, headers) {
57105
58742
  }
57106
58743
 
57107
58744
  // apps/gateway/src/ingress/responses.ts
57108
- import { createHash as createHash5 } from "crypto";
58745
+ import { createHash as createHash7 } from "crypto";
57109
58746
  var reasoning = exports_external.object({
57110
58747
  effort: exports_external.enum(REASONING_EFFORTS).optional(),
57111
58748
  summary: exports_external.string().optional()
@@ -57171,7 +58808,7 @@ function toIrReasoning2(r) {
57171
58808
  };
57172
58809
  }
57173
58810
  function clampCallId(raw) {
57174
- return raw.length <= 64 ? raw : createHash5("sha256").update(raw).digest("hex");
58811
+ return raw.length <= 64 ? raw : createHash7("sha256").update(raw).digest("hex");
57175
58812
  }
57176
58813
  function roleOf(raw) {
57177
58814
  if (raw === "assistant")
@@ -57181,7 +58818,7 @@ function roleOf(raw) {
57181
58818
  return "user";
57182
58819
  }
57183
58820
  function contentPart(part2) {
57184
- if (!isRecord7(part2))
58821
+ if (!isRecord8(part2))
57185
58822
  throw new GatewayError("BAD_REQUEST", "input: content part must be an object");
57186
58823
  const type = part2.type;
57187
58824
  if (type === "input_text" || type === "output_text") {
@@ -57221,7 +58858,7 @@ function readInputItems(items) {
57221
58858
  messages.push({ role, content });
57222
58859
  };
57223
58860
  for (const raw of items) {
57224
- if (!isRecord7(raw))
58861
+ if (!isRecord8(raw))
57225
58862
  throw new GatewayError("BAD_REQUEST", "input: item must be an object");
57226
58863
  const type = raw.type ?? (raw.role === undefined ? undefined : "message");
57227
58864
  switch (type) {
@@ -57277,7 +58914,7 @@ function jsonArguments(raw, callId) {
57277
58914
  const text = typeof raw === "string" ? raw : "";
57278
58915
  try {
57279
58916
  const parsed2 = text === "" ? {} : JSON.parse(text);
57280
- return isRecord7(parsed2) ? parsed2 : { value: parsed2 };
58917
+ return isRecord8(parsed2) ? parsed2 : { value: parsed2 };
57281
58918
  } catch {
57282
58919
  throw new GatewayError("BAD_REQUEST", `input: arguments for call ${safeToken(callId)} are not valid JSON`);
57283
58920
  }
@@ -57286,7 +58923,7 @@ var TOOL_NAME = /^[A-Za-z0-9_-]{1,128}$/;
57286
58923
  function readTools(raw) {
57287
58924
  const tools2 = [];
57288
58925
  for (const entry of raw) {
57289
- if (!isRecord7(entry))
58926
+ if (!isRecord8(entry))
57290
58927
  throw new GatewayError("BAD_REQUEST", "tools: each tool must be an object");
57291
58928
  const type = typeof entry.type === "string" ? entry.type : "";
57292
58929
  const declared = typeof entry.name === "string" ? entry.name : "";
@@ -57299,7 +58936,7 @@ function readTools(raw) {
57299
58936
  kind: "portable",
57300
58937
  name: declared,
57301
58938
  ...description === undefined ? {} : { description },
57302
- inputSchema: type === "custom" ? { type: "object", properties: { input: { type: "string" } }, required: ["input"] } : isRecord7(entry.parameters) ? entry.parameters : { type: "object" }
58939
+ inputSchema: type === "custom" ? { type: "object", properties: { input: { type: "string" } }, required: ["input"] } : isRecord8(entry.parameters) ? entry.parameters : { type: "object" }
57303
58940
  });
57304
58941
  continue;
57305
58942
  }
@@ -57314,10 +58951,10 @@ function readTools(raw) {
57314
58951
  }
57315
58952
  function customToolNames(body2) {
57316
58953
  const names = new Set;
57317
- if (!isRecord7(body2) || !Array.isArray(body2.tools))
58954
+ if (!isRecord8(body2) || !Array.isArray(body2.tools))
57318
58955
  return names;
57319
58956
  for (const entry of body2.tools) {
57320
- if (isRecord7(entry) && entry.type === "custom" && typeof entry.name === "string") {
58957
+ if (isRecord8(entry) && entry.type === "custom" && typeof entry.name === "string") {
57321
58958
  names.add(entry.name);
57322
58959
  }
57323
58960
  }
@@ -57956,11 +59593,11 @@ function topicClass(topic) {
57956
59593
  return null;
57957
59594
  }
57958
59595
  var MAX_TOPIC = 128;
57959
- function isRecord8(value) {
59596
+ function isRecord9(value) {
57960
59597
  return typeof value === "object" && value !== null && !Array.isArray(value);
57961
59598
  }
57962
59599
  function parseClientFrame(raw) {
57963
- if (!isRecord8(raw))
59600
+ if (!isRecord9(raw))
57964
59601
  return null;
57965
59602
  const { id, type, topic } = raw;
57966
59603
  if (id !== undefined && typeof id !== "string")
@@ -58166,16 +59803,16 @@ function createChannelRegistry(deps) {
58166
59803
  cancelReport = undefined;
58167
59804
  if (!live)
58168
59805
  return;
58169
- for (const [pluginId, count] of dropsSinceReport) {
58170
- logger2.warn("plugin channel broadcast dropped", { plugin: pluginId, count });
59806
+ for (const [pluginId, count2] of dropsSinceReport) {
59807
+ logger2.warn("plugin channel broadcast dropped", { plugin: pluginId, count: count2 });
58171
59808
  }
58172
59809
  dropsSinceReport.clear();
58173
- for (const [pluginId, count] of unencodableSinceReport) {
58174
- logger2.warn("plugin channel payload could not be serialised", { plugin: pluginId, count });
59810
+ for (const [pluginId, count2] of unencodableSinceReport) {
59811
+ logger2.warn("plugin channel payload could not be serialised", { plugin: pluginId, count: count2 });
58175
59812
  }
58176
59813
  unencodableSinceReport.clear();
58177
- for (const [pluginId, count] of errorsSinceReport) {
58178
- logger2.warn("plugin channel handler failed", { plugin: pluginId, count });
59814
+ for (const [pluginId, count2] of errorsSinceReport) {
59815
+ logger2.warn("plugin channel handler failed", { plugin: pluginId, count: count2 });
58179
59816
  }
58180
59817
  errorsSinceReport.clear();
58181
59818
  };
@@ -58643,7 +60280,7 @@ function createRing(limits) {
58643
60280
  }
58644
60281
 
58645
60282
  // apps/gateway/src/version.ts
58646
- var VERSION = "0.9.2";
60283
+ var VERSION = "0.10.0";
58647
60284
 
58648
60285
  // apps/gateway/src/app.ts
58649
60286
  var ADMIN_SESSION_TTL_MS = 12 * 60 * 60 * 1000;
@@ -59397,9 +61034,9 @@ function startMaintenance(deps) {
59397
61034
  });
59398
61035
  }, SWEEP_INTERVAL_MS2);
59399
61036
  const prune = async () => {
59400
- await deps.store.usage.sweepPending(deps.now()).then((count) => {
59401
- if (count > 0)
59402
- logger2.info("retired interrupted requests", { count });
61037
+ await deps.store.usage.sweepPending(deps.now()).then((count2) => {
61038
+ if (count2 > 0)
61039
+ logger2.info("retired interrupted requests", { count: count2 });
59403
61040
  }).catch((error61) => {
59404
61041
  logger2.error("pending sweep failed", { reason: describeError(error61, "unknown") });
59405
61042
  });
@@ -59524,8 +61161,8 @@ function createPluginEventBus(opts) {
59524
61161
  }
59525
61162
  }
59526
61163
  }
59527
- for (const [pluginId, count] of errorsSinceReport) {
59528
- logger2.warn("plugin event handler failed", { plugin: pluginId, count });
61164
+ for (const [pluginId, count2] of errorsSinceReport) {
61165
+ logger2.warn("plugin event handler failed", { plugin: pluginId, count: count2 });
59529
61166
  }
59530
61167
  errorsSinceReport.clear();
59531
61168
  if (droppedSinceReport > 0) {
@@ -60367,9 +62004,9 @@ function createTelemetry(opts) {
60367
62004
  breaker(provider, before, after) {
60368
62005
  if (!opts.metricsEnabled || before === after)
60369
62006
  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);
62007
+ const count2 = Math.max(0, (openBreakers.get(provider) ?? 0) + (after === "open" ? 1 : before === "open" ? -1 : 0));
62008
+ openBreakers.set(provider, count2);
62009
+ registry2.set("omni_breaker_open", { provider }, count2);
60373
62010
  },
60374
62011
  rateLimit(dimension, window2) {
60375
62012
  if (opts.metricsEnabled)