@r-33/opencode 0.4.7-rc.21 → 0.4.7-rc.23

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.
@@ -593,64 +593,6 @@ var init_cli = __esm({
593
593
  }
594
594
  });
595
595
 
596
- // src/auth/auth-error/auth-error.ts
597
- var AuthError;
598
- var init_auth_error = __esm({
599
- "src/auth/auth-error/auth-error.ts"() {
600
- "use strict";
601
- AuthError = class extends Error {
602
- constructor(code, options) {
603
- super(
604
- "Route 33 authorization failed",
605
- options?.cause === void 0 ? void 0 : { cause: options.cause }
606
- );
607
- this.code = code;
608
- this.name = "AuthError";
609
- this.statusCode = options?.statusCode;
610
- }
611
- code;
612
- statusCode;
613
- };
614
- }
615
- });
616
-
617
- // src/auth/auth-error/index.ts
618
- var init_auth_error2 = __esm({
619
- "src/auth/auth-error/index.ts"() {
620
- "use strict";
621
- init_auth_error();
622
- }
623
- });
624
-
625
- // src/auth/build-authorize-url/build-authorize-url.ts
626
- var buildAuthorizeUrl;
627
- var init_build_authorize_url = __esm({
628
- "src/auth/build-authorize-url/build-authorize-url.ts"() {
629
- "use strict";
630
- buildAuthorizeUrl = (issuerUrl, request) => {
631
- const url = new URL("/authorize", issuerUrl);
632
- url.search = new URLSearchParams({
633
- client_id: request.clientId,
634
- code_challenge: request.codeChallenge,
635
- code_challenge_method: "S256",
636
- redirect_uri: request.redirectUri,
637
- response_type: "code",
638
- scope: request.scope,
639
- state: request.state
640
- }).toString();
641
- return url;
642
- };
643
- }
644
- });
645
-
646
- // src/auth/build-authorize-url/index.ts
647
- var init_build_authorize_url2 = __esm({
648
- "src/auth/build-authorize-url/index.ts"() {
649
- "use strict";
650
- init_build_authorize_url();
651
- }
652
- });
653
-
654
596
  // src/contract/adapters/contract-parse-error/contract-parse-error.ts
655
597
  var ContractParseError;
656
598
  var init_contract_parse_error = __esm({
@@ -891,577 +833,6 @@ var init_adapters = __esm({
891
833
  }
892
834
  });
893
835
 
894
- // src/contract/auth-session/auth-session.ts
895
- var init_auth_session = __esm({
896
- "src/contract/auth-session/auth-session.ts"() {
897
- "use strict";
898
- }
899
- });
900
-
901
- // src/contract/auth-session/parse-token-set/parse-token-set.ts
902
- var parseTokenSet;
903
- var init_parse_token_set = __esm({
904
- "src/contract/auth-session/parse-token-set/parse-token-set.ts"() {
905
- "use strict";
906
- init_adapters();
907
- init_predicates();
908
- parseTokenSet = (value) => {
909
- if (!isRecord(value)) {
910
- throw new ContractParseError("invalid token response");
911
- }
912
- if (typeof value["access_token"] !== "string" || typeof value["expires_in"] !== "number" || value["token_type"] !== "Bearer") {
913
- throw new ContractParseError("invalid token response");
914
- }
915
- return {
916
- access_token: value["access_token"],
917
- expires_in: value["expires_in"],
918
- token_type: "Bearer",
919
- ...typeof value["id_token"] === "string" ? { id_token: value["id_token"] } : {},
920
- ...typeof value["refresh_token"] === "string" ? { refresh_token: value["refresh_token"] } : {},
921
- ...typeof value["scope"] === "string" ? { scope: value["scope"] } : {}
922
- };
923
- };
924
- }
925
- });
926
-
927
- // src/contract/auth-session/parse-token-set/index.ts
928
- var init_parse_token_set2 = __esm({
929
- "src/contract/auth-session/parse-token-set/index.ts"() {
930
- "use strict";
931
- init_parse_token_set();
932
- }
933
- });
934
-
935
- // src/contract/auth-session/index.ts
936
- var init_auth_session2 = __esm({
937
- "src/contract/auth-session/index.ts"() {
938
- "use strict";
939
- init_auth_session();
940
- init_parse_token_set2();
941
- }
942
- });
943
-
944
- // src/auth/exchange-code-and-parse/exchange-code-and-parse.ts
945
- var exchangeCodeAndParse;
946
- var init_exchange_code_and_parse = __esm({
947
- "src/auth/exchange-code-and-parse/exchange-code-and-parse.ts"() {
948
- "use strict";
949
- init_adapters();
950
- init_auth_session2();
951
- init_auth_error2();
952
- exchangeCodeAndParse = async (options) => {
953
- const body = new URLSearchParams({
954
- client_id: options.clientId,
955
- code: options.input.code,
956
- code_verifier: options.input.codeVerifier,
957
- grant_type: "authorization_code",
958
- redirect_uri: options.input.redirectUri
959
- });
960
- let response;
961
- try {
962
- response = await (options.fetchImpl ?? fetch)(options.tokenUrl, {
963
- body,
964
- headers: { "content-type": "application/x-www-form-urlencoded" },
965
- method: "POST"
966
- });
967
- } catch (cause) {
968
- throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
969
- }
970
- if (!response.ok) {
971
- throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", {
972
- statusCode: response.status
973
- });
974
- }
975
- let payload;
976
- try {
977
- payload = await response.json();
978
- } catch (cause) {
979
- throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
980
- }
981
- try {
982
- return parseTokenSet(payload);
983
- } catch (cause) {
984
- if (cause instanceof ContractParseError) {
985
- throw new AuthError("AUTH_CODE_EXCHANGE_FAILED", { cause });
986
- }
987
- throw cause;
988
- }
989
- };
990
- }
991
- });
992
-
993
- // src/auth/exchange-code-and-parse/index.ts
994
- var init_exchange_code_and_parse2 = __esm({
995
- "src/auth/exchange-code-and-parse/index.ts"() {
996
- "use strict";
997
- init_exchange_code_and_parse();
998
- }
999
- });
1000
-
1001
- // src/auth/refresh-session/refresh-session.ts
1002
- var refreshSession;
1003
- var init_refresh_session = __esm({
1004
- "src/auth/refresh-session/refresh-session.ts"() {
1005
- "use strict";
1006
- init_adapters();
1007
- init_auth_session2();
1008
- init_auth_error2();
1009
- refreshSession = async (options) => {
1010
- const body = new URLSearchParams({
1011
- client_id: options.clientId,
1012
- grant_type: "refresh_token",
1013
- refresh_token: options.refreshToken
1014
- });
1015
- let response;
1016
- try {
1017
- response = await (options.fetchImpl ?? fetch)(options.tokenUrl, {
1018
- body,
1019
- headers: { "content-type": "application/x-www-form-urlencoded" },
1020
- method: "POST"
1021
- });
1022
- } catch (cause) {
1023
- throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
1024
- }
1025
- if (!response.ok) {
1026
- throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", {
1027
- statusCode: response.status
1028
- });
1029
- }
1030
- let payload;
1031
- try {
1032
- payload = await response.json();
1033
- } catch (cause) {
1034
- throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
1035
- }
1036
- try {
1037
- return parseTokenSet(payload);
1038
- } catch (cause) {
1039
- if (cause instanceof ContractParseError) {
1040
- throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED", { cause });
1041
- }
1042
- throw cause;
1043
- }
1044
- };
1045
- }
1046
- });
1047
-
1048
- // src/auth/refresh-session/index.ts
1049
- var init_refresh_session2 = __esm({
1050
- "src/auth/refresh-session/index.ts"() {
1051
- "use strict";
1052
- init_refresh_session();
1053
- }
1054
- });
1055
-
1056
- // src/auth/create-auth-session/create-auth-session.ts
1057
- var createAuthSession;
1058
- var init_create_auth_session = __esm({
1059
- "src/auth/create-auth-session/create-auth-session.ts"() {
1060
- "use strict";
1061
- init_build_authorize_url2();
1062
- init_exchange_code_and_parse2();
1063
- init_refresh_session2();
1064
- createAuthSession = (options) => {
1065
- const tokenUrl = new URL("/oauth/token", options.issuerUrl);
1066
- return {
1067
- authorizationUrl: (request) => buildAuthorizeUrl(options.issuerUrl, request),
1068
- exchangeCode: (input) => exchangeCodeAndParse({
1069
- clientId: options.clientId,
1070
- ...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl },
1071
- input,
1072
- tokenUrl
1073
- }),
1074
- refresh: (refreshToken) => refreshSession({
1075
- clientId: options.clientId,
1076
- ...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl },
1077
- refreshToken,
1078
- tokenUrl
1079
- })
1080
- };
1081
- };
1082
- }
1083
- });
1084
-
1085
- // src/auth/create-auth-session/index.ts
1086
- var init_create_auth_session2 = __esm({
1087
- "src/auth/create-auth-session/index.ts"() {
1088
- "use strict";
1089
- init_create_auth_session();
1090
- }
1091
- });
1092
-
1093
- // src/auth/loopback-callback/callback-page/callback-page.ts
1094
- var MARK_PATHS, BRAND_MARK, PAGE_STYLE, buildCallbackPage;
1095
- var init_callback_page = __esm({
1096
- "src/auth/loopback-callback/callback-page/callback-page.ts"() {
1097
- "use strict";
1098
- MARK_PATHS = [
1099
- "M310.6,175.8c0-6.1-2.7-11.8-7.2-15.9l-127.6-114.4V7h-43.5v48.3c0,6.2,2.6,12.1,7.2,16.2l92.5,82.9H0v43.5h234.7l-95.6,91.4c-4.3,4.1-6.7,9.8-6.7,15.7v48.3h43.5v-39l128.1-122.4c4.4-4.2,6.8-10,6.7-16.1h0Z",
1100
- "M457.2,175.9v-2.6c18.4-4.9,33-14.1,44-27.7,11-13.6,16.5-30.3,16.5-50.3s-4.5-32.9-13.4-47.5c-9-14.5-21.6-26.1-38-34.9-16.4-8.7-35.8-13.1-58.3-13.1s-41.1,4-58.8,12.1-31.8,19.3-42.4,33.7-16.1,31-16.6,50h51.1c.3-10.8,3.6-20,9.8-27.7,6.2-7.6,14.2-13.5,24.1-17.5,9.9-4.1,20.6-6.1,32-6.1s22.3,2.2,31.1,6.7c8.8,4.5,15.6,10.8,20.5,18.8,4.9,8.1,7.3,17.5,7.3,28.4s-2.8,21.1-8.4,29.4-13.3,14.8-23.2,19.5-21.3,7.1-34.2,7.1h-29.9v43.3h29.9c16.2,0,30,2.5,41.5,7.5,11.5,5,20.2,12,26.1,21.1,6,9,9,19.4,9,31.2s-3,21.2-9.1,29.8-14.4,15.3-25.1,20.1c-10.7,4.9-22.9,7.3-36.7,7.3s-24.2-2.1-34.5-6.2-18.6-10-24.8-17.5c-6.3-7.5-9.8-16.5-10.6-26.8h-53.2c.6,19,6.3,35.7,17,50.2,10.7,14.5,25.2,25.7,43.6,33.8,18.4,8.1,39.4,12.1,63.1,12.1s45.1-4.4,63.7-13.2c18.6-8.8,33.3-20.8,44-36,10.8-15.2,16.1-32.5,16.1-51.8s-6.4-40.7-19.2-55.6c-12.8-14.9-30.8-24.2-54-27.8h0Z",
1101
- "M763,203.7c-12.8-14.9-30.8-24.2-54-27.8v-2.6c18.4-4.9,33-14.1,44-27.7,11-13.6,16.5-30.3,16.5-50.3s-4.5-32.9-13.4-47.5c-8.9-14.5-21.6-26.1-38-34.9-16.4-8.7-35.8-13.1-58.3-13.1s-41.1,4-58.8,12.1-31.8,19.3-42.4,33.7-16.1,31-16.6,50h51.1c.3-10.8,3.6-20,9.8-27.7,6.2-7.6,14.2-13.5,24.1-17.5,9.9-4.1,20.6-6.1,32-6.1s22.3,2.2,31.1,6.7c8.8,4.5,15.6,10.8,20.5,18.8,4.9,8.1,7.3,17.5,7.3,28.4s-2.8,21.1-8.4,29.4c-5.6,8.3-13.3,14.8-23.2,19.5s-21.3,7.1-34.2,7.1h-29.9v43.3h29.9c16.2,0,30,2.5,41.5,7.5,11.5,5,20.2,12,26.1,21.1,6,9,8.9,19.4,8.9,31.2s-3,21.2-9.1,29.8c-6.1,8.6-14.4,15.3-25.1,20.1-10.7,4.9-22.9,7.3-36.7,7.3s-24.2-2.1-34.5-6.2-18.6-10-24.8-17.5c-6.3-7.5-9.8-16.5-10.6-26.8h-53.2c.6,19,6.3,35.7,17,50.2,10.7,14.5,25.2,25.7,43.6,33.8,18.4,8.1,39.4,12.1,63.1,12.1s45.1-4.4,63.7-13.2,33.3-20.8,44-36c10.8-15.2,16.1-32.5,16.1-51.8s-6.4-40.7-19.2-55.6h0Z"
1102
- ];
1103
- BRAND_MARK = `<svg class="r33-mark" viewBox="0 0 782.2 360.3" fill="currentColor" role="img" aria-label="route33.ai" xmlns="http://www.w3.org/2000/svg"><path d="${MARK_PATHS[0]}"/><path d="${MARK_PATHS[1]}"/><path d="${MARK_PATHS[2]}"/></svg>`;
1104
- PAGE_STYLE = `:root{color-scheme:dark;--r33-euro-blue:#0000FF;--r33-off-white:#F1F1F1;--r33-off-black:#121212;--r33-grey-300:#C9CBCF;--r33-radius-fillet:4px;--r33-space-2:8px;--r33-space-3:16px;--r33-space-4:24px;--r33-space-6:64px;--r33-font-body:"Geist","Helvetica Neue",Arial,sans-serif;--r33-font-mono:"Geist Mono","SFMono-Regular",Menlo,monospace;--r33-surface:var(--r33-off-black);--r33-text-primary:var(--r33-off-white);--r33-text-secondary:var(--r33-grey-300);--r33-fill-accent:var(--r33-euro-blue);--r33-on-fill-accent:var(--r33-off-white)}
1105
- *{box-sizing:border-box}
1106
- html,body{margin:0}
1107
- .r33-page{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:var(--r33-space-6);background:var(--r33-surface);color:var(--r33-text-primary);font-family:var(--r33-font-body);-webkit-font-smoothing:antialiased}
1108
- .r33-panel{display:grid;gap:var(--r33-space-4);max-width:460px;width:100%}
1109
- .r33-mark{height:40px;width:auto;color:var(--r33-text-primary)}
1110
- .r33-status{display:inline-flex;align-items:center;gap:var(--r33-space-2);font-size:11px;letter-spacing:0.08em;text-transform:uppercase;color:var(--r33-text-secondary)}
1111
- .r33-status__dot{width:8px;height:8px;background:var(--r33-fill-accent)}
1112
- .r33-status__dot--error{background:transparent;border:1px solid var(--r33-text-primary);border-radius:50%}
1113
- .r33-headline{margin:0;font-size:48px;line-height:0.85;letter-spacing:-0.02em;font-weight:600;color:var(--r33-text-primary);text-wrap:balance}
1114
- .r33-subline{margin:0;font-size:16px;line-height:1.45;color:var(--r33-text-secondary);max-width:40ch;text-wrap:pretty}
1115
- .r33-code{margin:0;font-size:13px;letter-spacing:0.04em;color:var(--r33-text-secondary)}
1116
- .r33-code__value{font-family:var(--r33-font-mono);text-transform:uppercase;color:var(--r33-text-primary)}
1117
- @media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}`;
1118
- buildCallbackPage = (state, errorCode) => {
1119
- const isError = state === "error";
1120
- const safeCode = (errorCode ?? "").replace(/[^a-z0-9_-]/gi, "");
1121
- const title = isError ? "Sign-in failed" : "Signed in";
1122
- const headline = isError ? "Sign-in failed" : "Signed in to route33";
1123
- const subline = isError ? "Return to OpenCode and retry." : "Return to OpenCode \u2014 one more step may wait there: if it asks which budget covers usage, pick a project. This window can be closed.";
1124
- const statusLabel = isError ? "Authentication error" : "Authenticated";
1125
- const dotClass = isError ? "r33-status__dot r33-status__dot--error" : "r33-status__dot";
1126
- const codeLine = isError && safeCode.length > 0 ? `<p class="r33-code">Error code: <span class="r33-code__value">${safeCode}</span></p>` : "";
1127
- return `<!doctype html>
1128
- <html lang="en" data-theme="dark">
1129
- <head>
1130
- <meta charset="utf-8">
1131
- <meta name="viewport" content="width=device-width, initial-scale=1">
1132
- <title>${title} \xB7 route33.ai</title>
1133
- <style>${PAGE_STYLE}</style>
1134
- </head>
1135
- <body>
1136
- <main class="r33-page">
1137
- <div class="r33-panel">
1138
- ${BRAND_MARK}
1139
- <span class="r33-status"><span class="${dotClass}"></span>${statusLabel}</span>
1140
- <h1 class="r33-headline">${headline}</h1>
1141
- <p class="r33-subline">${subline}</p>
1142
- ${codeLine}
1143
- </div>
1144
- </main>
1145
- </body>
1146
- </html>`;
1147
- };
1148
- }
1149
- });
1150
-
1151
- // src/auth/loopback-callback/callback-page/index.ts
1152
- var init_callback_page2 = __esm({
1153
- "src/auth/loopback-callback/callback-page/index.ts"() {
1154
- "use strict";
1155
- init_callback_page();
1156
- }
1157
- });
1158
-
1159
- // src/auth/loopback-callback/loopback-callback.ts
1160
- import { createServer } from "node:http";
1161
- var createAuthLoopbackCallback;
1162
- var init_loopback_callback = __esm({
1163
- "src/auth/loopback-callback/loopback-callback.ts"() {
1164
- "use strict";
1165
- init_auth_error2();
1166
- init_callback_page2();
1167
- createAuthLoopbackCallback = async () => {
1168
- let redirectUri = "http://127.0.0.1/callback";
1169
- let resolveCapture;
1170
- const captured = new Promise((resolve2) => {
1171
- resolveCapture = resolve2;
1172
- });
1173
- const server = createServer((request, response) => {
1174
- const url = new URL(request.url ?? "/", redirectUri);
1175
- if (request.method !== "GET" || url.pathname !== "/callback") {
1176
- response.writeHead(404).end();
1177
- return;
1178
- }
1179
- const resolve2 = resolveCapture;
1180
- resolveCapture = void 0;
1181
- resolve2?.(url);
1182
- const error = url.searchParams.get("error");
1183
- const page = error === null || error.length === 0 ? buildCallbackPage("success") : buildCallbackPage("error", error);
1184
- response.writeHead(200, { "content-type": "text/html; charset=utf-8" });
1185
- response.end(page);
1186
- });
1187
- await new Promise((resolve2, reject) => {
1188
- const onError = (cause) => {
1189
- reject(new AuthError("AUTH_CALLBACK_LISTEN_FAILED", { cause }));
1190
- };
1191
- server.once("error", onError);
1192
- server.listen(0, "127.0.0.1", () => {
1193
- server.off("error", onError);
1194
- resolve2();
1195
- });
1196
- });
1197
- const address = server.address();
1198
- if (address === null || typeof address === "string") {
1199
- server.close();
1200
- throw new AuthError("AUTH_CALLBACK_LISTEN_FAILED");
1201
- }
1202
- redirectUri = `http://127.0.0.1:${String(address.port)}/callback`;
1203
- return {
1204
- redirectUri,
1205
- close: () => {
1206
- if (!server.listening) {
1207
- return Promise.resolve();
1208
- }
1209
- return new Promise((resolve2, reject) => {
1210
- server.close((cause) => {
1211
- if (cause === void 0) {
1212
- resolve2();
1213
- return;
1214
- }
1215
- reject(new AuthError("AUTH_CALLBACK_CLEANUP_FAILED", { cause }));
1216
- });
1217
- });
1218
- },
1219
- wait: () => captured
1220
- };
1221
- };
1222
- }
1223
- });
1224
-
1225
- // src/auth/loopback-callback/index.ts
1226
- var init_loopback_callback2 = __esm({
1227
- "src/auth/loopback-callback/index.ts"() {
1228
- "use strict";
1229
- init_loopback_callback();
1230
- }
1231
- });
1232
-
1233
- // src/auth/open-system-browser/open-system-browser.ts
1234
- import { spawn } from "node:child_process";
1235
- var openSystemBrowser;
1236
- var init_open_system_browser = __esm({
1237
- "src/auth/open-system-browser/open-system-browser.ts"() {
1238
- "use strict";
1239
- openSystemBrowser = async (url, options = {}) => new Promise((resolve2, reject) => {
1240
- let command = "xdg-open";
1241
- let args = [url.href];
1242
- if (process.platform === "darwin") {
1243
- command = "open";
1244
- } else if (process.platform === "win32") {
1245
- command = "cmd";
1246
- args = ["/c", "start", "", url.href];
1247
- }
1248
- if (options.spawnUrl !== void 0) {
1249
- options.spawnUrl(command, args, { detached: true, stdio: "ignore" });
1250
- resolve2();
1251
- return;
1252
- }
1253
- const child = spawn(command, args, {
1254
- detached: true,
1255
- stdio: "ignore"
1256
- });
1257
- child.once("error", reject);
1258
- child.once("spawn", () => {
1259
- child.unref();
1260
- resolve2();
1261
- });
1262
- });
1263
- }
1264
- });
1265
-
1266
- // src/auth/open-system-browser/index.ts
1267
- var init_open_system_browser2 = __esm({
1268
- "src/auth/open-system-browser/index.ts"() {
1269
- "use strict";
1270
- init_open_system_browser();
1271
- }
1272
- });
1273
-
1274
- // src/auth/open-browser-and-capture/open-browser-and-capture.ts
1275
- import { timingSafeEqual } from "node:crypto";
1276
- var openBrowserAndCapture;
1277
- var init_open_browser_and_capture = __esm({
1278
- "src/auth/open-browser-and-capture/open-browser-and-capture.ts"() {
1279
- "use strict";
1280
- init_auth_error2();
1281
- init_loopback_callback2();
1282
- init_open_system_browser2();
1283
- openBrowserAndCapture = async (options) => {
1284
- const callback = await createAuthLoopbackCallback();
1285
- const authorizationUrl = options.authorizationUrl(callback.redirectUri);
1286
- const browserRunner = options.browserRunner ?? ((url) => openSystemBrowser(url));
1287
- let timer;
1288
- const timeout = new Promise((_resolve, reject) => {
1289
- timer = setTimeout(() => {
1290
- reject(new AuthError("AUTH_CALLBACK_TIMEOUT"));
1291
- }, options.timeoutMs ?? 12e4);
1292
- });
1293
- const launch = browserRunner(authorizationUrl).catch((cause) => {
1294
- throw new AuthError("AUTH_BROWSER_LAUNCH_FAILED", { cause });
1295
- });
1296
- try {
1297
- const completed = await Promise.race([
1298
- Promise.all([launch, callback.wait()]),
1299
- timeout
1300
- ]);
1301
- const callbackUrl = completed[1];
1302
- const actualState = callbackUrl.searchParams.get("state");
1303
- if (actualState === null) {
1304
- throw new AuthError("AUTH_CALLBACK_RESPONSE_INVALID");
1305
- }
1306
- const expectedState = Buffer.from(options.expectedState);
1307
- const receivedState = Buffer.from(actualState);
1308
- if (expectedState.length !== receivedState.length || !timingSafeEqual(expectedState, receivedState)) {
1309
- throw new AuthError("AUTH_CALLBACK_STATE_MISMATCH");
1310
- }
1311
- const code = callbackUrl.searchParams.get("code");
1312
- if (code === null || code.length === 0) {
1313
- throw new AuthError("AUTH_CALLBACK_RESPONSE_INVALID");
1314
- }
1315
- return { code, redirectUri: callback.redirectUri };
1316
- } finally {
1317
- if (timer !== void 0) {
1318
- clearTimeout(timer);
1319
- }
1320
- await callback.close();
1321
- }
1322
- };
1323
- }
1324
- });
1325
-
1326
- // src/auth/open-browser-and-capture/index.ts
1327
- var init_open_browser_and_capture2 = __esm({
1328
- "src/auth/open-browser-and-capture/index.ts"() {
1329
- "use strict";
1330
- init_open_browser_and_capture();
1331
- }
1332
- });
1333
-
1334
- // src/auth/pkce-challenge/pkce-challenge.ts
1335
- import { createHash } from "node:crypto";
1336
- var pkceChallenge;
1337
- var init_pkce_challenge = __esm({
1338
- "src/auth/pkce-challenge/pkce-challenge.ts"() {
1339
- "use strict";
1340
- pkceChallenge = (verifier) => createHash("sha256").update(verifier).digest("base64url");
1341
- }
1342
- });
1343
-
1344
- // src/auth/pkce-challenge/index.ts
1345
- var init_pkce_challenge2 = __esm({
1346
- "src/auth/pkce-challenge/index.ts"() {
1347
- "use strict";
1348
- init_pkce_challenge();
1349
- }
1350
- });
1351
-
1352
- // src/auth/pkce-verifier-and-challenge/pkce-verifier-and-challenge.ts
1353
- import { randomBytes } from "node:crypto";
1354
- var createPkceVerifierAndChallenge;
1355
- var init_pkce_verifier_and_challenge = __esm({
1356
- "src/auth/pkce-verifier-and-challenge/pkce-verifier-and-challenge.ts"() {
1357
- "use strict";
1358
- init_pkce_challenge2();
1359
- createPkceVerifierAndChallenge = () => {
1360
- const codeVerifier = randomBytes(32).toString("base64url");
1361
- return {
1362
- codeChallenge: pkceChallenge(codeVerifier),
1363
- codeVerifier,
1364
- state: randomBytes(32).toString("base64url")
1365
- };
1366
- };
1367
- }
1368
- });
1369
-
1370
- // src/auth/pkce-verifier-and-challenge/index.ts
1371
- var init_pkce_verifier_and_challenge2 = __esm({
1372
- "src/auth/pkce-verifier-and-challenge/index.ts"() {
1373
- "use strict";
1374
- init_pkce_verifier_and_challenge();
1375
- }
1376
- });
1377
-
1378
- // src/auth/requested-scopes/requested-scopes.ts
1379
- var REQUESTED_OAUTH_SCOPES;
1380
- var init_requested_scopes = __esm({
1381
- "src/auth/requested-scopes/requested-scopes.ts"() {
1382
- "use strict";
1383
- REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read keys:read keys:write";
1384
- }
1385
- });
1386
-
1387
- // src/auth/requested-scopes/index.ts
1388
- var init_requested_scopes2 = __esm({
1389
- "src/auth/requested-scopes/index.ts"() {
1390
- "use strict";
1391
- init_requested_scopes();
1392
- }
1393
- });
1394
-
1395
- // src/auth/login-flow/login-flow.ts
1396
- var loginFlow;
1397
- var init_login_flow = __esm({
1398
- "src/auth/login-flow/login-flow.ts"() {
1399
- "use strict";
1400
- init_adapters();
1401
- init_shared();
1402
- init_auth_error2();
1403
- init_open_browser_and_capture2();
1404
- init_pkce_verifier_and_challenge2();
1405
- init_requested_scopes2();
1406
- loginFlow = async (options) => {
1407
- const log = options.logger ?? logger;
1408
- log.info("auth.login.started");
1409
- const pkce = createPkceVerifierAndChallenge();
1410
- const captured = await openBrowserAndCapture({
1411
- authorizationUrl: (redirectUri) => options.session.authorizationUrl({
1412
- clientId: options.clientId,
1413
- codeChallenge: pkce.codeChallenge,
1414
- redirectUri,
1415
- scope: REQUESTED_OAUTH_SCOPES,
1416
- state: pkce.state
1417
- }),
1418
- ...options.browserRunner === void 0 ? {} : { browserRunner: options.browserRunner },
1419
- expectedState: pkce.state,
1420
- ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
1421
- });
1422
- const tokenSet = await options.session.exchangeCode({
1423
- code: captured.code,
1424
- codeVerifier: pkce.codeVerifier,
1425
- redirectUri: captured.redirectUri
1426
- });
1427
- let credential;
1428
- try {
1429
- credential = parseManagementJwt(tokenSet.access_token);
1430
- } catch (cause) {
1431
- throw new AuthError("AUTH_TOKEN_RESPONSE_INVALID", { cause });
1432
- }
1433
- log.info("auth.login.completed");
1434
- return { credential, tokenSet };
1435
- };
1436
- }
1437
- });
1438
-
1439
- // src/auth/login-flow/index.ts
1440
- var init_login_flow2 = __esm({
1441
- "src/auth/login-flow/index.ts"() {
1442
- "use strict";
1443
- init_login_flow();
1444
- }
1445
- });
1446
-
1447
- // src/auth/index.ts
1448
- var init_auth = __esm({
1449
- "src/auth/index.ts"() {
1450
- "use strict";
1451
- init_auth_error2();
1452
- init_build_authorize_url2();
1453
- init_create_auth_session2();
1454
- init_exchange_code_and_parse2();
1455
- init_login_flow2();
1456
- init_loopback_callback2();
1457
- init_open_browser_and_capture2();
1458
- init_pkce_challenge2();
1459
- init_pkce_verifier_and_challenge2();
1460
- init_refresh_session2();
1461
- init_requested_scopes2();
1462
- }
1463
- });
1464
-
1465
836
  // src/requested-client-id/requested-client-id.ts
1466
837
  var DEFAULT_ROUTE33_CLIENT_ID;
1467
838
  var init_requested_client_id = __esm({
@@ -2091,12 +1462,12 @@ var init_clear_catalog_memory2 = __esm({
2091
1462
  });
2092
1463
 
2093
1464
  // src/catalog/catalog-cache/hash-key/hash-key.ts
2094
- import { createHash as createHash2 } from "node:crypto";
1465
+ import { createHash } from "node:crypto";
2095
1466
  var hashKey;
2096
1467
  var init_hash_key = __esm({
2097
1468
  "src/catalog/catalog-cache/hash-key/hash-key.ts"() {
2098
1469
  "use strict";
2099
- hashKey = (baseURL, gatewayKey) => createHash2("sha256").update(`${baseURL}
1470
+ hashKey = (baseURL, gatewayKey) => createHash("sha256").update(`${baseURL}
2100
1471
  ${gatewayKey.value}`).digest("hex").slice(0, 12);
2101
1472
  }
2102
1473
  });
@@ -5938,7 +5309,7 @@ var init_lease_installation_factory2 = __esm({
5938
5309
  });
5939
5310
 
5940
5311
  // src/key-lease/scope-id/scope-id.ts
5941
- import { createHash as createHash3 } from "node:crypto";
5312
+ import { createHash as createHash2 } from "node:crypto";
5942
5313
  var deriveScopeId;
5943
5314
  var init_scope_id = __esm({
5944
5315
  "src/key-lease/scope-id/scope-id.ts"() {
@@ -5965,7 +5336,7 @@ var init_scope_id = __esm({
5965
5336
  throw new TypeError(`Unexpected attribution: ${String(unexpected)}`);
5966
5337
  }
5967
5338
  }
5968
- return createHash3("sha256").update(JSON.stringify(identity)).digest("hex");
5339
+ return createHash2("sha256").update(JSON.stringify(identity)).digest("hex");
5969
5340
  };
5970
5341
  }
5971
5342
  });
@@ -6252,6 +5623,28 @@ var init_trusted_party_copy2 = __esm({
6252
5623
  }
6253
5624
  });
6254
5625
 
5626
+ // src/ux/callback-page-copy/callback-page-copy.ts
5627
+ var CALLBACK_PAGE_COPY;
5628
+ var init_callback_page_copy = __esm({
5629
+ "src/ux/callback-page-copy/callback-page-copy.ts"() {
5630
+ "use strict";
5631
+ CALLBACK_PAGE_COPY = {
5632
+ errorHeadline: "Sign-in failed",
5633
+ errorSubline: "Return to OpenCode and retry.",
5634
+ successHeadline: "Signed in to route33",
5635
+ successSubline: "Return to OpenCode \u2014 one more step may wait there: if it asks which budget covers usage, pick a project. This window can be closed."
5636
+ };
5637
+ }
5638
+ });
5639
+
5640
+ // src/ux/callback-page-copy/index.ts
5641
+ var init_callback_page_copy2 = __esm({
5642
+ "src/ux/callback-page-copy/index.ts"() {
5643
+ "use strict";
5644
+ init_callback_page_copy();
5645
+ }
5646
+ });
5647
+
6255
5648
  // src/ux/index.ts
6256
5649
  var init_ux = __esm({
6257
5650
  "src/ux/index.ts"() {
@@ -6260,16 +5653,78 @@ var init_ux = __esm({
6260
5653
  init_attribution_prompt_error2();
6261
5654
  init_prompt_flow2();
6262
5655
  init_trusted_party_copy2();
5656
+ init_callback_page_copy2();
5657
+ }
5658
+ });
5659
+
5660
+ // src/requested-scopes/requested-scopes.ts
5661
+ var REQUESTED_OAUTH_SCOPES;
5662
+ var init_requested_scopes = __esm({
5663
+ "src/requested-scopes/requested-scopes.ts"() {
5664
+ "use strict";
5665
+ REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read keys:read keys:write";
5666
+ }
5667
+ });
5668
+
5669
+ // src/requested-scopes/index.ts
5670
+ var init_requested_scopes2 = __esm({
5671
+ "src/requested-scopes/index.ts"() {
5672
+ "use strict";
5673
+ init_requested_scopes();
5674
+ }
5675
+ });
5676
+
5677
+ // src/route33-login/route33-login.ts
5678
+ import {
5679
+ AuthError,
5680
+ loginFlow
5681
+ } from "@r-33/auth-browser";
5682
+ var route33Login;
5683
+ var init_route33_login = __esm({
5684
+ "src/route33-login/route33-login.ts"() {
5685
+ "use strict";
5686
+ init_adapters();
5687
+ init_requested_scopes2();
5688
+ init_shared();
5689
+ init_callback_page_copy2();
5690
+ route33Login = async (options) => {
5691
+ const log = options.logger ?? logger;
5692
+ const tokenSet = await loginFlow({
5693
+ ...options.browserRunner === void 0 ? {} : { browserRunner: options.browserRunner },
5694
+ clientId: options.clientId,
5695
+ logger: log,
5696
+ pageCopy: CALLBACK_PAGE_COPY,
5697
+ scope: REQUESTED_OAUTH_SCOPES,
5698
+ session: options.session,
5699
+ ...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
5700
+ });
5701
+ let credential;
5702
+ try {
5703
+ credential = parseManagementJwt(tokenSet.access_token);
5704
+ } catch (cause) {
5705
+ throw new AuthError("AUTH_TOKEN_RESPONSE_INVALID", { cause });
5706
+ }
5707
+ return { credential, tokenSet };
5708
+ };
5709
+ }
5710
+ });
5711
+
5712
+ // src/route33-login/index.ts
5713
+ var init_route33_login2 = __esm({
5714
+ "src/route33-login/index.ts"() {
5715
+ "use strict";
5716
+ init_route33_login();
6263
5717
  }
6264
5718
  });
6265
5719
 
6266
5720
  // src/route33-runtime/login-session/login-session.ts
5721
+ import { AuthError as AuthError2 } from "@r-33/auth-browser";
6267
5722
  var EXPIRY_SKEW_MS, LoginSession;
6268
5723
  var init_login_session = __esm({
6269
5724
  "src/route33-runtime/login-session/login-session.ts"() {
6270
5725
  "use strict";
6271
- init_auth();
6272
5726
  init_adapters();
5727
+ init_route33_login2();
6273
5728
  init_shared();
6274
5729
  init_ux();
6275
5730
  EXPIRY_SKEW_MS = 6e4;
@@ -6280,15 +5735,11 @@ var init_login_session = __esm({
6280
5735
  constructor(options) {
6281
5736
  this.#options = options;
6282
5737
  }
6283
- /**
6284
- * Resolves the login once per process, sharing in-flight attempts.
6285
- * @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
6286
- * @returns The token set plus its typed management credential.
6287
- */
6288
5738
  /**
6289
5739
  * Clears the session: the cached login result and the stored refresh
6290
5740
  * token. The next login starts from scratch — /r33 logout and the
6291
5741
  * auto-reconnect path both land here.
5742
+ * @returns Resolved once the session and the stored refresh token are gone.
6292
5743
  */
6293
5744
  async clear() {
6294
5745
  this.#result = void 0;
@@ -6296,8 +5747,9 @@ var init_login_session = __esm({
6296
5747
  await this.#options.tokenStore?.set(void 0);
6297
5748
  }
6298
5749
  /**
6299
- *
6300
- * @param policy
5750
+ * Resolves the login once per process, sharing in-flight attempts.
5751
+ * @param policy - Whether this attempt may start a browser login; an in-flight attempt is always shared.
5752
+ * @returns The token set plus its typed management credential.
6301
5753
  */
6302
5754
  result(policy = {}) {
6303
5755
  if (this.#result !== void 0 && this.#expiresAt !== void 0 && Date.now() >= this.#expiresAt - EXPIRY_SKEW_MS) {
@@ -6323,10 +5775,10 @@ var init_login_session = __esm({
6323
5775
  return viaRefresh;
6324
5776
  }
6325
5777
  if (policy.allowBrowser === false) {
6326
- throw new AuthError("AUTH_REAUTHENTICATION_REQUIRED");
5778
+ throw new AuthError2("AUTH_REAUTHENTICATION_REQUIRED");
6327
5779
  }
6328
5780
  await this.#options.presenter?.present(TRUSTED_PARTY_COPY);
6329
- const result = await loginFlow(this.#options.auth);
5781
+ const result = await route33Login(this.#options.auth);
6330
5782
  this.#trackExpiry(result.tokenSet.expires_in);
6331
5783
  await this.#persist(result.tokenSet.refresh_token);
6332
5784
  return result;
@@ -6340,23 +5792,29 @@ var init_login_session = __esm({
6340
5792
  if (stored === void 0 || stored === "") {
6341
5793
  return void 0;
6342
5794
  }
6343
- let tokenSet;
6344
- try {
6345
- tokenSet = await this.#options.auth.session.refresh(stored);
6346
- } catch {
6347
- logger.info("auth.refresh.fell-back-to-browser");
5795
+ const tokenSet = await this.#tryRefreshToken(stored);
5796
+ if (tokenSet === void 0) {
6348
5797
  return void 0;
6349
5798
  }
6350
5799
  let credential;
6351
5800
  try {
6352
5801
  credential = parseManagementJwt(tokenSet.access_token);
6353
5802
  } catch (cause) {
6354
- throw new AuthError("AUTH_TOKEN_RESPONSE_INVALID", { cause });
5803
+ throw new AuthError2("AUTH_TOKEN_RESPONSE_INVALID", { cause });
6355
5804
  }
6356
5805
  this.#trackExpiry(tokenSet.expires_in);
6357
5806
  await this.#persist(tokenSet.refresh_token);
6358
5807
  return { credential, tokenSet };
6359
5808
  }
5809
+ async #tryRefreshToken(stored) {
5810
+ const session = this.#options.auth.session;
5811
+ try {
5812
+ return await session.refresh(stored);
5813
+ } catch {
5814
+ logger.info("auth.refresh.fell-back-to-browser");
5815
+ return void 0;
5816
+ }
5817
+ }
6360
5818
  #trackExpiry(expiresIn) {
6361
5819
  this.#expiresAt = Date.now() + expiresIn * 1e3;
6362
5820
  }
@@ -6897,10 +6355,14 @@ init_cli();
6897
6355
  init_cli();
6898
6356
 
6899
6357
  // src/production-runtime-options/production-runtime-options.ts
6900
- init_auth();
6358
+ import { createAuthSession } from "@r-33/auth-browser";
6901
6359
 
6902
- // src/management/http-management-keys/http-management-keys.ts
6360
+ // src/management/sdk-management-keys/sdk-management-keys.ts
6903
6361
  init_adapters();
6362
+ import {
6363
+ createRoute33Client,
6364
+ Route33SdkError
6365
+ } from "@r-33/sdk";
6904
6366
 
6905
6367
  // src/contract/management-keys/parse-api-key/parse-api-key.ts
6906
6368
  init_adapters();
@@ -7113,252 +6575,145 @@ var ManagementError = class extends Error {
7113
6575
  statusCode;
7114
6576
  };
7115
6577
 
7116
- // src/management/management-http-transport/management-http-transport.ts
7117
- init_adapters();
7118
- var ManagementHttpTransport = class {
7119
- #baseUrl;
7120
- #credential;
7121
- #fetchImpl;
7122
- #onUnauthorized;
7123
- #timeoutMs;
7124
- constructor(options) {
7125
- const baseUrl = options.baseUrl ?? "https://api.route33.ai/v1";
7126
- this.#baseUrl = new URL(baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`);
7127
- this.#credential = options.credential;
7128
- this.#fetchImpl = options.fetchImpl ?? fetch;
7129
- this.#onUnauthorized = options.onUnauthorized;
7130
- this.#timeoutMs = options.timeoutMs ?? 1e4;
7131
- }
7132
- /** Sends a request and reads one JSON value under the request timeout.
7133
- * @param request - Management path, method, and optional JSON body.
7134
- * @returns The untrusted response value.
7135
- */
7136
- json(request) {
7137
- return this.#perform(request, async (response) => {
7138
- try {
7139
- return await response.json();
7140
- } catch (cause) {
7141
- throw new ContractParseError("invalid management response", { cause });
7142
- }
7143
- });
7144
- }
7145
- /** Sends a request whose successful response has no body.
7146
- * @param request - Management path and method.
7147
- */
7148
- empty(request) {
7149
- return this.#perform(request, () => Promise.resolve());
7150
- }
7151
- async #perform(request, consume) {
7152
- const controller = new AbortController();
7153
- const timer = setTimeout(() => {
7154
- controller.abort();
7155
- }, this.#timeoutMs);
7156
- const headers = new Headers({
7157
- accept: "application/json",
7158
- authorization: `Bearer ${this.#credential.value}`
6578
+ // src/management/sdk-management-keys/sdk-management-keys.ts
6579
+ var API_PREFIX_PATTERN = /\/api\/v1\/?$/;
6580
+ var sdkManagementKeys = (options) => {
6581
+ const baseUrl = options.apiBaseUrl.replace(API_PREFIX_PATTERN, "");
6582
+ const timeoutMs = options.timeoutMs ?? 1e4;
6583
+ const fetchImpl = options.fetchImpl;
6584
+ const observingFetch = (status) => fetchImpl === void 0 ? void 0 : async (input, init) => {
6585
+ const response = await fetchImpl(input, init);
6586
+ status.code = response.status;
6587
+ return response;
6588
+ };
6589
+ const callClient = (accessToken, status) => {
6590
+ const provider = {
6591
+ getToken: () => Promise.resolve(accessToken.value),
6592
+ onUnauthorized: () => Promise.resolve(accessToken.value)
6593
+ };
6594
+ const observedFetch = observingFetch(status);
6595
+ return createRoute33Client({
6596
+ baseUrl,
6597
+ provider,
6598
+ timeoutMs,
6599
+ ...observedFetch === void 0 ? {} : { fetch: observedFetch }
7159
6600
  });
7160
- if (request.body !== void 0) {
7161
- headers.set("content-type", "application/json");
6601
+ };
6602
+ const mapFailure = (cause) => {
6603
+ if (cause instanceof ManagementError || cause instanceof ContractParseError) {
6604
+ return cause;
6605
+ }
6606
+ if (cause instanceof Route33SdkError) {
6607
+ const code = cause.code === "SDK_TIMEOUT" ? "MANAGEMENT_TIMEOUT" : "MANAGEMENT_NETWORK_ERROR";
6608
+ return new ManagementError(code, { cause });
6609
+ }
6610
+ if (cause instanceof SyntaxError) {
6611
+ return new ContractParseError("invalid management response", { cause });
7162
6612
  }
6613
+ return new ManagementError("MANAGEMENT_NETWORK_ERROR", { cause });
6614
+ };
6615
+ const call = async (accessToken, run) => {
6616
+ const status = { code: void 0 };
7163
6617
  try {
7164
- const send = () => this.#fetchImpl(new URL(request.path, this.#baseUrl), {
7165
- ...request.body === void 0 ? {} : { body: JSON.stringify(request.body) },
7166
- headers,
7167
- method: request.method,
7168
- signal: controller.signal
7169
- });
7170
- let response = await send();
7171
- if (response.status === 401 && this.#onUnauthorized !== void 0) {
7172
- await this.#onUnauthorized();
7173
- response = await send();
7174
- }
7175
- if (!response.ok) {
6618
+ const outcome = await run(callClient(accessToken, status));
6619
+ const code = status.code;
6620
+ if (code === void 0 || code < 200 || code >= 300) {
7176
6621
  throw new ManagementError(
7177
- response.status === 401 ? "MANAGEMENT_UNAUTHORIZED" : "MANAGEMENT_HTTP_ERROR",
7178
- { statusCode: response.status }
6622
+ code === 401 ? "MANAGEMENT_UNAUTHORIZED" : "MANAGEMENT_HTTP_ERROR",
6623
+ { statusCode: code }
7179
6624
  );
7180
6625
  }
7181
- return await consume(response);
6626
+ return outcome.data;
7182
6627
  } catch (cause) {
7183
- if (cause instanceof ManagementError) {
7184
- throw cause;
7185
- }
7186
- if (controller.signal.aborted) {
7187
- throw new ManagementError("MANAGEMENT_TIMEOUT", { cause });
7188
- }
7189
- if (cause instanceof ContractParseError) {
7190
- throw cause;
7191
- }
7192
- throw new ManagementError("MANAGEMENT_NETWORK_ERROR", { cause });
7193
- } finally {
7194
- clearTimeout(timer);
6628
+ throw mapFailure(cause);
7195
6629
  }
7196
- }
7197
- };
7198
-
7199
- // src/management/http-management-keys/http-management-keys.ts
7200
- var HttpManagementKeys = class {
7201
- #credential;
7202
- #transport;
7203
- constructor(options) {
7204
- this.#credential = options.credential;
7205
- this.#transport = new ManagementHttpTransport(options);
7206
- }
7207
- /** Creates a future-expiring ownership-scoped key.
7208
- * @param accessToken - Credential required by the frozen contract.
7209
- * @param input - Key name, expiry, and ownership.
7210
- * @returns One-time key material.
7211
- */
7212
- async create(accessToken, input) {
7213
- this.#authorize(accessToken);
7214
- return parseKeyMaterial(
7215
- await this.#transport.json({
7216
- body: {
7217
- ...input.allowedModels === void 0 ? {} : { allowed_models: input.allowedModels },
7218
- ...input.description === void 0 ? {} : { description: input.description },
7219
- expires_at: input.expiresAt,
7220
- ...input.maxBudgetAmount === void 0 ? {} : { max_budget_amount: input.maxBudgetAmount },
7221
- name: input.name,
7222
- ...input.ownerId === null ? {} : { owner_user_id: input.ownerId },
7223
- owner_type: input.ownerType,
7224
- ...input.projectId === null ? {} : { project_id: input.projectId }
7225
- },
7226
- method: "POST",
7227
- path: "api-keys"
7228
- })
7229
- );
7230
- }
7231
- /** Treats a successful empty response as confirmation of permanent removal.
7232
- * @param accessToken - Credential required by the frozen contract.
7233
- * @param id - Key identifier.
7234
- */
7235
- async delete(accessToken, id) {
7236
- this.#authorize(accessToken);
7237
- await this.#transport.empty({
7238
- method: "DELETE",
7239
- path: `api-keys/${encodeURIComponent(id)}`
7240
- });
7241
- }
7242
- /** Gets a safe key DTO.
7243
- * @param accessToken - Credential required by the frozen contract.
7244
- * @param id - Key identifier.
7245
- * @returns The secret-free key DTO.
7246
- */
7247
- async get(accessToken, id) {
7248
- this.#authorize(accessToken);
7249
- return parseApiKey(
7250
- await this.#transport.json({
7251
- method: "GET",
7252
- path: `api-keys/${encodeURIComponent(id)}`
7253
- })
7254
- );
7255
- }
7256
- /** Lists safe key DTOs.
7257
- * @param accessToken - Credential required by the frozen contract.
7258
- * @returns The parsed key collection.
7259
- */
7260
- async list(accessToken) {
7261
- this.#authorize(accessToken);
7262
- return parseCollection(
7263
- await this.#transport.json({ method: "GET", path: "api-keys" }),
6630
+ };
6631
+ return {
6632
+ create: async (accessToken, input) => parseKeyMaterial(
6633
+ await call(
6634
+ accessToken,
6635
+ (client) => client.POST("/api/v1/api-keys", {
6636
+ body: {
6637
+ ...input.allowedModels === void 0 ? {} : { allowed_models: [...input.allowedModels] },
6638
+ budget_currency: "EUR",
6639
+ ...input.description === void 0 ? {} : { description: input.description },
6640
+ expires_at: input.expiresAt,
6641
+ ...input.maxBudgetAmount === void 0 ? {} : { max_budget_amount: input.maxBudgetAmount },
6642
+ name: input.name,
6643
+ ...input.ownerId === null ? {} : { owner_user_id: input.ownerId },
6644
+ owner_type: input.ownerType,
6645
+ ...input.projectId === null ? {} : { project_id: input.projectId }
6646
+ }
6647
+ })
6648
+ )
6649
+ ),
6650
+ delete: async (accessToken, id) => {
6651
+ await call(
6652
+ accessToken,
6653
+ (client) => client.DELETE("/api/v1/api-keys/{api_key_id}", {
6654
+ params: { path: { api_key_id: id } }
6655
+ })
6656
+ );
6657
+ },
6658
+ get: async (accessToken, id) => parseApiKey(
6659
+ await call(
6660
+ accessToken,
6661
+ (client) => client.GET("/api/v1/api-keys/{api_key_id}", {
6662
+ params: { path: { api_key_id: id } }
6663
+ })
6664
+ )
6665
+ ),
6666
+ list: async (accessToken) => parseCollection(
6667
+ await call(accessToken, (client) => client.GET("/api/v1/api-keys", {})),
7264
6668
  parseApiKey
7265
- );
7266
- }
7267
- /** Lists organizations visible to the authenticated management subject.
7268
- * @param accessToken - Credential required by the frozen contract.
7269
- * @returns The parsed organization collection.
7270
- */
7271
- async listOrganizations(accessToken) {
7272
- this.#authorize(accessToken);
7273
- return parseCollection(
7274
- await this.#transport.json({ method: "GET", path: "orgs" }),
6669
+ ),
6670
+ listOrganizations: async (accessToken) => parseCollection(
6671
+ await call(accessToken, (client) => client.GET("/api/v1/orgs", {})),
7275
6672
  parseOrganization
7276
- );
7277
- }
7278
- /** Lists projects visible within an organisation filter.
7279
- * @param accessToken - Credential required by the frozen contract.
7280
- * @param organisationId - Required backend organisation filter.
7281
- * @returns The parsed project collection.
7282
- */
7283
- async listProjects(accessToken, organisationId) {
7284
- this.#authorize(accessToken);
7285
- if (organisationId.trim().length === 0) {
7286
- throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
7287
- statusCode: 400
7288
- });
7289
- }
7290
- const query = new URLSearchParams({
7291
- member_user_id: parseManagementSubject(accessToken),
7292
- org_id: organisationId
7293
- });
7294
- return parseCollection(
7295
- await this.#transport.json({
7296
- method: "GET",
7297
- path: `projects?${query.toString()}`
7298
- }),
7299
- parseProject
7300
- );
7301
- }
7302
- /** Regenerates one-time key material while preserving expiry when omitted.
7303
- * @param accessToken - Credential required by the frozen contract.
7304
- * @param id - Key identifier.
7305
- * @param expiresAt - Optional replacement expiry.
7306
- * @returns Regenerated one-time key material.
7307
- */
7308
- async regenerate(accessToken, id, expiresAt) {
7309
- this.#authorize(accessToken);
7310
- return parseKeyMaterial(
7311
- await this.#transport.json({
7312
- body: expiresAt === void 0 ? {} : { expires_at: expiresAt },
7313
- method: "POST",
7314
- path: `api-keys/${encodeURIComponent(id)}/secrets`
7315
- })
7316
- );
7317
- }
7318
- /** Updates mutable key metadata.
7319
- * @param accessToken - Credential required by the frozen contract.
7320
- * @param id - Key identifier.
7321
- * @param input - Optional name and expiry replacements.
7322
- * @returns The updated safe key DTO.
7323
- */
7324
- async update(accessToken, id, input) {
7325
- this.#authorize(accessToken);
7326
- return parseApiKey(
7327
- await this.#transport.json({
7328
- body: {
7329
- ...input.expiresAt === void 0 ? {} : { expires_at: input.expiresAt },
7330
- ...input.name === void 0 ? {} : { name: input.name }
7331
- },
7332
- method: "PATCH",
7333
- path: `api-keys/${encodeURIComponent(id)}`
7334
- })
7335
- );
7336
- }
7337
- #authorize(accessToken) {
7338
- if (accessToken.value !== this.#credential.value) {
7339
- throw new ManagementError("MANAGEMENT_UNAUTHORIZED", {
7340
- statusCode: 401
7341
- });
7342
- }
7343
- }
7344
- };
7345
-
7346
- // src/lazy-management-keys/lazy-management-keys.ts
7347
- var lazyManagementKeys = (options) => {
7348
- const client = (accessToken) => new HttpManagementKeys({
7349
- baseUrl: options.apiBaseUrl,
7350
- credential: accessToken,
7351
- ...options.fetchImpl === void 0 ? {} : { fetchImpl: options.fetchImpl }
7352
- });
7353
- return {
7354
- create: async (accessToken, input) => client(accessToken).create(accessToken, input),
7355
- delete: async (accessToken, id) => client(accessToken).delete(accessToken, id),
7356
- get: async (accessToken, id) => client(accessToken).get(accessToken, id),
7357
- list: async (accessToken) => client(accessToken).list(accessToken),
7358
- listOrganizations: async (accessToken) => client(accessToken).listOrganizations(accessToken),
7359
- listProjects: async (accessToken, organisationId) => client(accessToken).listProjects(accessToken, organisationId),
7360
- regenerate: async (accessToken, id, expiresAt) => client(accessToken).regenerate(accessToken, id, expiresAt),
7361
- update: async (accessToken, id, input) => client(accessToken).update(accessToken, id, input)
6673
+ ),
6674
+ listProjects: async (accessToken, organisationId) => {
6675
+ if (organisationId.trim().length === 0) {
6676
+ throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
6677
+ statusCode: 400
6678
+ });
6679
+ }
6680
+ return parseCollection(
6681
+ await call(
6682
+ accessToken,
6683
+ (client) => client.GET("/api/v1/projects", {
6684
+ params: {
6685
+ query: {
6686
+ member_user_id: parseManagementSubject(accessToken),
6687
+ org_id: organisationId
6688
+ }
6689
+ }
6690
+ })
6691
+ ),
6692
+ parseProject
6693
+ );
6694
+ },
6695
+ regenerate: async (accessToken, id, expiresAt) => parseKeyMaterial(
6696
+ await call(
6697
+ accessToken,
6698
+ (client) => client.POST("/api/v1/api-keys/{api_key_id}/secrets", {
6699
+ body: expiresAt === void 0 ? {} : { expires_at: expiresAt },
6700
+ params: { path: { api_key_id: id } }
6701
+ })
6702
+ )
6703
+ ),
6704
+ update: async (accessToken, id, input) => parseApiKey(
6705
+ await call(
6706
+ accessToken,
6707
+ (client) => client.PATCH("/api/v1/api-keys/{api_key_id}", {
6708
+ body: {
6709
+ budget_currency: "EUR",
6710
+ ...input.expiresAt === void 0 ? {} : { expires_at: input.expiresAt },
6711
+ ...input.name === void 0 ? {} : { name: input.name }
6712
+ },
6713
+ params: { path: { api_key_id: id } }
6714
+ })
6715
+ )
6716
+ )
7362
6717
  };
7363
6718
  };
7364
6719
 
@@ -7374,7 +6729,7 @@ var buildProductionRuntimeOptions = (input) => ({
7374
6729
  timeoutMs: LOGIN_BUDGET_MS
7375
6730
  },
7376
6731
  management: {
7377
- client: () => lazyManagementKeys({ apiBaseUrl: input.apiBaseUrl })
6732
+ client: () => sdkManagementKeys({ apiBaseUrl: input.apiBaseUrl })
7378
6733
  },
7379
6734
  ...input.tokenStore === void 0 ? {} : { tokenStore: input.tokenStore }
7380
6735
  });