@huaweidevtools/aishell-dsh-client-credentials 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/lib/client.js +878 -239
- package/lib/index.js +1452 -109
- package/lib/types/auth-tool.d.ts +108 -0
- package/lib/types/client/AishellAccountHint.d.ts +1 -1
- package/lib/types/client/CredentialFormInteraction.d.ts +2 -19
- package/lib/types/client/CredentialRequestForm.d.ts +59 -30
- package/lib/types/client/credential-form-visibility.d.ts +25 -58
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/locales.d.ts +26 -8
- package/lib/types/client/login-flow.d.ts +98 -0
- package/lib/types/client/permission-mode.d.ts +3 -3
- package/lib/types/client/spinner.d.ts +32 -0
- package/lib/types/client/start-page.d.ts +61 -0
- package/lib/types/form-request.d.ts +118 -0
- package/lib/types/index.d.ts +28 -50
- package/lib/types/login-status.d.ts +62 -0
- package/lib/types/out-of-band/contract.d.ts +199 -0
- package/lib/types/out-of-band/flow.d.ts +82 -0
- package/lib/types/out-of-band/listener.d.ts +156 -0
- package/lib/types/out-of-band/login.d.ts +144 -0
- package/lib/types/out-of-band/routes.d.ts +108 -0
- package/lib/types/prefill.d.ts +78 -0
- package/lib/types/reconcile.d.ts +3 -11
- package/package.json +5 -3
package/lib/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createCredentialsStore } from "@huaweidevtools/aishell-dsh-credentials-store";
|
|
2
|
-
import {
|
|
2
|
+
import { clearCredentials, hasStoredPair, readStoredPair, writeHuaweiCloud } from "@huaweidevtools/aishell-dsh-credentials-store/accounts";
|
|
3
|
+
import { verifyCredentials } from "@huaweidevtools/aishell-dsh-credentials-store/verify";
|
|
4
|
+
import { createServer } from "node:http";
|
|
3
5
|
|
|
4
6
|
//#region ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.5/node_modules/@deepseek-ai/cosmokit/lib/index.js
|
|
5
7
|
/** Return true when a value is `null` or `undefined`. */
|
|
@@ -893,6 +895,1196 @@ defineMethod("transform", [
|
|
|
893
895
|
"preserve"
|
|
894
896
|
], ({ inner }, isInner) => inner.toString(isInner));
|
|
895
897
|
|
|
898
|
+
//#endregion
|
|
899
|
+
//#region src/auth-tool.ts
|
|
900
|
+
/** Model-facing name. Prefixed so it cannot collide with another cloud plugin. */
|
|
901
|
+
const AUTH_TOOL_NAME = "aishell__auth";
|
|
902
|
+
/** Region used to route the verification call; IAM is global, see the module note. */
|
|
903
|
+
const VERIFY_REGION$1 = "cn-north-4";
|
|
904
|
+
/**
|
|
905
|
+
* The JSON Schema for `auth`'s parameters: none.
|
|
906
|
+
*
|
|
907
|
+
* Declared as an empty object rather than omitted so the model reads "takes no
|
|
908
|
+
* arguments" explicitly, instead of inferring it from a missing field.
|
|
909
|
+
*/
|
|
910
|
+
const AUTH_PARAMETERS = {
|
|
911
|
+
type: "object",
|
|
912
|
+
properties: {},
|
|
913
|
+
additionalProperties: false
|
|
914
|
+
};
|
|
915
|
+
/**
|
|
916
|
+
* Register the `auth` tool on the host's tool registry.
|
|
917
|
+
*
|
|
918
|
+
* @param ctx - host context.
|
|
919
|
+
* @param store - the credential store this package owns.
|
|
920
|
+
*/
|
|
921
|
+
function registerAuthTool(ctx, store, deps) {
|
|
922
|
+
ctx.inject(["tools"], (scope) => {
|
|
923
|
+
const dispose = scope.tools.register({
|
|
924
|
+
name: AUTH_TOOL_NAME,
|
|
925
|
+
description: "Authenticate with Huawei Cloud IAM, then report the account: its id and name, and every project visible to it (a project's name is a region; its id is what a region-scoped API needs). Opens the credential form and waits for the user to finish — it does not return until they have authenticated or cancelled.",
|
|
926
|
+
parameters: AUTH_PARAMETERS,
|
|
927
|
+
output: {
|
|
928
|
+
schema: {
|
|
929
|
+
type: "object",
|
|
930
|
+
properties: {
|
|
931
|
+
authenticated: { type: "boolean" },
|
|
932
|
+
account: {
|
|
933
|
+
type: "object",
|
|
934
|
+
properties: {
|
|
935
|
+
accountId: { type: "string" },
|
|
936
|
+
name: { type: "string" }
|
|
937
|
+
},
|
|
938
|
+
required: ["accountId", "name"]
|
|
939
|
+
},
|
|
940
|
+
projects: {
|
|
941
|
+
type: "array",
|
|
942
|
+
items: {
|
|
943
|
+
type: "object",
|
|
944
|
+
properties: {
|
|
945
|
+
id: { type: "string" },
|
|
946
|
+
name: { type: "string" },
|
|
947
|
+
description: { type: "string" }
|
|
948
|
+
},
|
|
949
|
+
required: ["id", "name"]
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
sts: { type: "boolean" }
|
|
953
|
+
},
|
|
954
|
+
required: [
|
|
955
|
+
"authenticated",
|
|
956
|
+
"account",
|
|
957
|
+
"projects",
|
|
958
|
+
"sts"
|
|
959
|
+
]
|
|
960
|
+
},
|
|
961
|
+
render: (_args, value) => renderAuth(value)
|
|
962
|
+
},
|
|
963
|
+
async execute(_args, exec) {
|
|
964
|
+
return await runAuth(store, deps, sessionOf(exec), exec.signal);
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
return dispose;
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
/** The session a tool call runs under, from its execution context. */
|
|
971
|
+
function sessionOf(exec) {
|
|
972
|
+
return exec.agent?.session?.id;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Verify and describe the stored account.
|
|
976
|
+
*
|
|
977
|
+
* Four outcomes, and each one is a different instruction to the model:
|
|
978
|
+
*
|
|
979
|
+
* - **Verified.** The account and its projects.
|
|
980
|
+
* - **The person cancelled.** Terminal: stop, and say what the credential was
|
|
981
|
+
* needed for. Without this the model's only signal is the same failure it
|
|
982
|
+
* got before, and it retries until the turn ends — while the person has
|
|
983
|
+
* already said no.
|
|
984
|
+
* - **Nothing stored, or the stored pair was rejected.** Open the form and
|
|
985
|
+
* fail with the reason. The model calls again once the person is done.
|
|
986
|
+
*
|
|
987
|
+
* The last two both open the form, which is deliberate: a rejected credential is
|
|
988
|
+
* the case where the person most needs to see the form again, and Huawei's own
|
|
989
|
+
* reason is what tells them what to correct.
|
|
990
|
+
*
|
|
991
|
+
* @param store - the credential store to read.
|
|
992
|
+
* @param deps - host controls: open the form and wait for its answer.
|
|
993
|
+
* @param sessionId - the conversation to open the form in; `undefined` when the
|
|
994
|
+
* call carries no agent, in which case no form can be shown.
|
|
995
|
+
* @param signal - the call's cancellation; the way out of a form nobody answers.
|
|
996
|
+
* @returns the account, its projects, and whether the credentials are temporary.
|
|
997
|
+
* @throws when the person cancels, or when no form can be shown at all.
|
|
998
|
+
*/
|
|
999
|
+
async function runAuth(store, deps, sessionId, signal) {
|
|
1000
|
+
const stored = readStoredPair(store);
|
|
1001
|
+
if (stored !== void 0) {
|
|
1002
|
+
const verified = await verifyCredentials(stored, { region: VERIFY_REGION$1 });
|
|
1003
|
+
if (verified.ok) return describeAccount(verified);
|
|
1004
|
+
}
|
|
1005
|
+
if (sessionId === void 0 || sessionId === "") throw new Error("Not authenticated with Huawei Cloud IAM, and this call is not attached to a conversation, so the credential form cannot be shown. Ask the user to open the credential form themselves, then call auth again.");
|
|
1006
|
+
for (let round = 0; round < MAX_FORM_ROUNDS; round += 1) {
|
|
1007
|
+
const pending = deps.requestForm(sessionId);
|
|
1008
|
+
if (pending === void 0) break;
|
|
1009
|
+
let outcome;
|
|
1010
|
+
try {
|
|
1011
|
+
outcome = await raceCancellation(pending, signal);
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
deps.releaseForm();
|
|
1014
|
+
throw error;
|
|
1015
|
+
}
|
|
1016
|
+
if (outcome.kind === "cancelled" || outcome.kind === "aborted") {
|
|
1017
|
+
deps.releaseForm();
|
|
1018
|
+
throw new CredentialEntryCancelled();
|
|
1019
|
+
}
|
|
1020
|
+
const pair = readStoredPair(store);
|
|
1021
|
+
if (pair === void 0) continue;
|
|
1022
|
+
const result = await verifyCredentials(pair, { region: VERIFY_REGION$1 });
|
|
1023
|
+
if (result.ok) return describeAccount(result);
|
|
1024
|
+
}
|
|
1025
|
+
throw new Error("Not authenticated with Huawei Cloud IAM. The credential form was shown but no usable credential was stored. Ask the user to authenticate, then call auth again.");
|
|
1026
|
+
}
|
|
1027
|
+
/** How many form rounds one call will wait through before giving up. */
|
|
1028
|
+
const MAX_FORM_ROUNDS = 10;
|
|
1029
|
+
/**
|
|
1030
|
+
* Credential entry ended without a credential.
|
|
1031
|
+
*
|
|
1032
|
+
* One message for both ways it ends — the person pressed cancel, or the turn
|
|
1033
|
+
* was stopped while the form was up. From the call's side they are the same
|
|
1034
|
+
* outcome: nothing was entered, so the call cannot continue.
|
|
1035
|
+
*
|
|
1036
|
+
* Bilingual, and stating only the fact. That is the shape `aishell-e2b` uses
|
|
1037
|
+
* for its blocked-call error: the reader is whichever language the session
|
|
1038
|
+
* runs in, and the message says what happened rather than what to do about it.
|
|
1039
|
+
*
|
|
1040
|
+
* ## Why no instruction follows
|
|
1041
|
+
*
|
|
1042
|
+
* An earlier version ended with "Do not call auth again until they say to."
|
|
1043
|
+
* The intent was to stop a model retrying in a loop, but what it produced was
|
|
1044
|
+
* a model that treated every later sentence from the person as a question
|
|
1045
|
+
* about permission — asked to look again, it narrated its uncertainty about
|
|
1046
|
+
* whether that counted as consent, and stalled instead of either retrying or
|
|
1047
|
+
* explaining. The fact is enough; what follows it is the model's judgement.
|
|
1048
|
+
*/
|
|
1049
|
+
var CredentialEntryCancelled = class extends Error {
|
|
1050
|
+
constructor() {
|
|
1051
|
+
super("用户取消了认证流程。 / The user cancelled the authentication flow.");
|
|
1052
|
+
this.name = "CredentialEntryCancelled";
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
/**
|
|
1056
|
+
* Wait for the form's answer, or for the call to be cancelled.
|
|
1057
|
+
*
|
|
1058
|
+
* An abandoned call must not keep a promise alive: the turn is over, and nobody
|
|
1059
|
+
* is going to answer a prompt for it. `aborted` is a separate outcome from
|
|
1060
|
+
* `cancelled` in shape, and treated the same in effect — either way the person
|
|
1061
|
+
* did not supply a credential and asking again would be wrong.
|
|
1062
|
+
*
|
|
1063
|
+
* @param pending - the open form request.
|
|
1064
|
+
* @param signal - the call's cancellation, if any.
|
|
1065
|
+
*/
|
|
1066
|
+
async function raceCancellation(pending, signal) {
|
|
1067
|
+
if (signal === void 0) return pending;
|
|
1068
|
+
if (signal.aborted) return { kind: "aborted" };
|
|
1069
|
+
return await new Promise((resolve) => {
|
|
1070
|
+
const onAbort = () => {
|
|
1071
|
+
resolve({ kind: "aborted" });
|
|
1072
|
+
};
|
|
1073
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1074
|
+
pending.then((outcome) => {
|
|
1075
|
+
signal.removeEventListener("abort", onAbort);
|
|
1076
|
+
resolve(outcome);
|
|
1077
|
+
});
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
/** Project a successful verification into the tool's canonical value. */
|
|
1081
|
+
function describeAccount(result) {
|
|
1082
|
+
return {
|
|
1083
|
+
authenticated: true,
|
|
1084
|
+
account: {
|
|
1085
|
+
accountId: result.account.accountId,
|
|
1086
|
+
name: result.account.name
|
|
1087
|
+
},
|
|
1088
|
+
projects: result.account.projects.map((project) => ({
|
|
1089
|
+
id: project.id,
|
|
1090
|
+
name: project.name,
|
|
1091
|
+
...project.description === void 0 ? {} : { description: project.description }
|
|
1092
|
+
})),
|
|
1093
|
+
sts: result.sts
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* The text the model reads.
|
|
1098
|
+
*
|
|
1099
|
+
* A short summary then the project table: the summary answers the question the
|
|
1100
|
+
* tool was called with, and the table is what the next call needs. The region
|
|
1101
|
+
* is deliberately absent — IAM does not verify it, so printing it would suggest
|
|
1102
|
+
* it had been checked.
|
|
1103
|
+
*
|
|
1104
|
+
* @param value - the verified account.
|
|
1105
|
+
*/
|
|
1106
|
+
function renderAuth(value) {
|
|
1107
|
+
const projects = value.projects.length === 0 ? "No projects are visible to these credentials." : ["Project id region description", ...value.projects.map((project) => `${project.id.padEnd(36)} ${project.name.padEnd(14)} ${project.description ?? ""}`.trimEnd())].join("\n");
|
|
1108
|
+
const kind = value.sts ? "temporary (STS)" : "stored";
|
|
1109
|
+
return [{
|
|
1110
|
+
type: "text",
|
|
1111
|
+
text: `Authenticated with Huawei Cloud as ${value.account.name} (account id ${value.account.accountId}); using ${kind} credentials.\n\n` + projects
|
|
1112
|
+
}];
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
//#endregion
|
|
1116
|
+
//#region src/form-request.ts
|
|
1117
|
+
/**
|
|
1118
|
+
* The credential form's Host-side control.
|
|
1119
|
+
*
|
|
1120
|
+
* ## What this is for
|
|
1121
|
+
*
|
|
1122
|
+
* `aishell__auth` needs credentials that are not there. It cannot collect them
|
|
1123
|
+
* — a credential a tool returns is a credential in the transcript — so it asks
|
|
1124
|
+
* for the form to be put on screen, the person fills it, and the model calls
|
|
1125
|
+
* `auth` again.
|
|
1126
|
+
*
|
|
1127
|
+
* ## Why the settings document carries the request
|
|
1128
|
+
*
|
|
1129
|
+
* The two halves live apart: the tool runs on the host, the form is browser
|
|
1130
|
+
* code. The host cannot reach the browser over the fetch channel — that channel
|
|
1131
|
+
* is browser→host only — so the request has to ride something the browser
|
|
1132
|
+
* already watches. The settings document is exactly that: the browser half
|
|
1133
|
+
* subscribes to this entry's config through `configForms`, and a volatile field
|
|
1134
|
+
* written by the host shows up there.
|
|
1135
|
+
*
|
|
1136
|
+
* The document carries **only** a request token and a session id. Never a
|
|
1137
|
+
* credential, never a verdict — those travel the other way, over the
|
|
1138
|
+
* credential route, and the browser never receives a stored secret at all.
|
|
1139
|
+
*
|
|
1140
|
+
* ## Why the token, not a boolean
|
|
1141
|
+
*
|
|
1142
|
+
* The browser has to tell "a new request" from "the request it already opened".
|
|
1143
|
+
* With a boolean, a second `auth` failure while the form is up would look
|
|
1144
|
+
* identical to the first and the form would not re-open after the person
|
|
1145
|
+
* cancelled it. The token changes on every request, and the browser compares it
|
|
1146
|
+
* to the last one it acted on.
|
|
1147
|
+
*
|
|
1148
|
+
* ## Why nothing is awaited
|
|
1149
|
+
*
|
|
1150
|
+
* The tool cannot wait for the person — a tool call has no way to be paused for
|
|
1151
|
+
* a human. So `auth` fails, the form appears, and the model calls again. That
|
|
1152
|
+
* round trip is the whole protocol, and it is why the failure message and the
|
|
1153
|
+
* form are worded as a pair.
|
|
1154
|
+
*
|
|
1155
|
+
* @module @huaweidevtools/aishell-dsh-client-credentials/form-request
|
|
1156
|
+
*/
|
|
1157
|
+
/** Field of this entry's config that carries one pending request. */
|
|
1158
|
+
const FORM_REQUEST_FIELD = "credentialFormRequest";
|
|
1159
|
+
/**
|
|
1160
|
+
* Build a request for one session, minting its token.
|
|
1161
|
+
*
|
|
1162
|
+
* The token is minted here rather than by the caller so a request cannot be
|
|
1163
|
+
* recorded without one — the browser's "is this new?" test would then be
|
|
1164
|
+
* comparing against nothing, and the form would not reopen after a cancel.
|
|
1165
|
+
*
|
|
1166
|
+
* @param sessionId - the conversation the form should render in.
|
|
1167
|
+
* @returns the request, and its encoded form for the settings document.
|
|
1168
|
+
*/
|
|
1169
|
+
function formRequest(sessionId) {
|
|
1170
|
+
nextToken += 1;
|
|
1171
|
+
const request = {
|
|
1172
|
+
token: `${Date.now().toString(36)}-${String(nextToken)}`,
|
|
1173
|
+
sessionId
|
|
1174
|
+
};
|
|
1175
|
+
const completion = Promise.withResolvers();
|
|
1176
|
+
return {
|
|
1177
|
+
request,
|
|
1178
|
+
encoded: encodeRequest(request),
|
|
1179
|
+
outcome: completion.promise,
|
|
1180
|
+
settle: (outcome) => {
|
|
1181
|
+
completion.resolve(outcome);
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
/** Source of tokens; module-scoped so it is per-host-process. */
|
|
1186
|
+
let nextToken = 0;
|
|
1187
|
+
/**
|
|
1188
|
+
* Serialize a request for the settings document.
|
|
1189
|
+
*
|
|
1190
|
+
* The document holds strings — a volatile `string` field is what the browser
|
|
1191
|
+
* half reads through `configForms` — so the request is JSON. Encoding rather
|
|
1192
|
+
* than reshaping the config into several fields keeps the request atomic: the
|
|
1193
|
+
* browser cannot observe a new token with an old session.
|
|
1194
|
+
*
|
|
1195
|
+
* @param request - the request to encode.
|
|
1196
|
+
*/
|
|
1197
|
+
function encodeRequest(request) {
|
|
1198
|
+
return JSON.stringify(request);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region src/login-status.ts
|
|
1203
|
+
/**
|
|
1204
|
+
* The vocabulary the two halves share about a browser login in progress.
|
|
1205
|
+
*
|
|
1206
|
+
* ## Why it is its own module
|
|
1207
|
+
*
|
|
1208
|
+
* Both halves need these names and neither owns them: the host writes the
|
|
1209
|
+
* outcome into the settings document, the browser half reads it and drives the
|
|
1210
|
+
* form the login opens in. A module the two import is the only place the
|
|
1211
|
+
* contract can live without one half depending on the other's internals —
|
|
1212
|
+
* the same reasoning `../form-request.ts` follows for the credential form.
|
|
1213
|
+
*
|
|
1214
|
+
* ## What travels, and what does not
|
|
1215
|
+
*
|
|
1216
|
+
* A login's outcome is a kind and, at most, an account name or a message. No
|
|
1217
|
+
* credential ever crosses this channel in either direction: the credential
|
|
1218
|
+
* arrives at a loopback socket the host owns, is verified there, and is stored
|
|
1219
|
+
* there. The browser half learns only that it worked, and as whom.
|
|
1220
|
+
*
|
|
1221
|
+
* @module @huaweidevtools/aishell-dsh-client-credentials/login-status
|
|
1222
|
+
*/
|
|
1223
|
+
/** Field of this entry's config carrying the last login's outcome. */
|
|
1224
|
+
const LOGIN_OUTCOME_FIELD = "loginOutcome";
|
|
1225
|
+
/**
|
|
1226
|
+
* Header the reachability probe sends, to force a CORS preflight.
|
|
1227
|
+
*
|
|
1228
|
+
* Any non-safelisted header would do it; this one names why. Declared here
|
|
1229
|
+
* because both halves need the same string and neither owns it: the browser
|
|
1230
|
+
* half sends it, the host's listener must allow it in its preflight answer,
|
|
1231
|
+
* and a mismatch between the two is a probe that fails on a deployment that
|
|
1232
|
+
* would actually work — the entry hidden for no reason.
|
|
1233
|
+
*/
|
|
1234
|
+
const PROBE_HEADER = "x-aishell-probe";
|
|
1235
|
+
/**
|
|
1236
|
+
* Serialize an outcome for the settings document.
|
|
1237
|
+
*
|
|
1238
|
+
* @param outcome - the outcome, or `undefined` to clear the field.
|
|
1239
|
+
* @returns the encoded value, or `''` to clear it.
|
|
1240
|
+
*/
|
|
1241
|
+
function encodeOutcome(outcome) {
|
|
1242
|
+
return outcome === void 0 ? "" : JSON.stringify(outcome);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
//#endregion
|
|
1246
|
+
//#region src/out-of-band/contract.ts
|
|
1247
|
+
/**
|
|
1248
|
+
* The aishell-auth contract, as this plugin consumes it.
|
|
1249
|
+
*
|
|
1250
|
+
* ## What this module is
|
|
1251
|
+
*
|
|
1252
|
+
* A client for one stateless service that answers a single question: *where
|
|
1253
|
+
* should the browser go to sign in, and how does the credential come back?*
|
|
1254
|
+
* It stores nothing, holds no credential, and has no user system — the cloud
|
|
1255
|
+
* posts the credential straight to the caller.
|
|
1256
|
+
*
|
|
1257
|
+
* ## Why the contract is read, not hardcoded
|
|
1258
|
+
*
|
|
1259
|
+
* Every quirk of the cloud's callback is in the response: the listen path, the
|
|
1260
|
+
* accepted origins, whether a correlation string exists, what to do with the
|
|
1261
|
+
* payload. The service's own README says the point is that the caller "does
|
|
1262
|
+
* not need to hardcode anything provider-specific" — so this module hardcodes
|
|
1263
|
+
* none of it either. That is what makes a second provider a config change here
|
|
1264
|
+
* rather than a rewrite, and it is why the types below mirror the wire exactly
|
|
1265
|
+
* instead of modelling what Huawei happens to do today.
|
|
1266
|
+
*
|
|
1267
|
+
* ## Why field mapping is schema-driven
|
|
1268
|
+
*
|
|
1269
|
+
* `credential_schema` names the payload fields per provider. Mapping by those
|
|
1270
|
+
* names rather than by literal keys means a provider that calls its fields
|
|
1271
|
+
* something else still lands in the right store slots, and a provider that
|
|
1272
|
+
* renames one is a server-side change the caller follows for free.
|
|
1273
|
+
*
|
|
1274
|
+
* ## No exception, after all
|
|
1275
|
+
*
|
|
1276
|
+
* Private Network Access is in the contract as
|
|
1277
|
+
* `requires_private_network_access`: a browser on a public origin reaching
|
|
1278
|
+
* loopback sends a preflight carrying `Access-Control-Request-Private-Network`,
|
|
1279
|
+
* and a response without the matching allow header makes it drop the real
|
|
1280
|
+
* request — invisibly, in production only, with no error anywhere. The
|
|
1281
|
+
* contract carries that fact now, so this module hardcodes nothing about it.
|
|
1282
|
+
* See `./listener.ts` for how the flag and the browser's own request header
|
|
1283
|
+
* are combined.
|
|
1284
|
+
*
|
|
1285
|
+
* @module @huaweidevtools/aishell-dsh-client-credentials/out-of-band/contract
|
|
1286
|
+
*/
|
|
1287
|
+
/**
|
|
1288
|
+
* Base URL of the login-dispatch service.
|
|
1289
|
+
*
|
|
1290
|
+
* A constant rather than a setting: it identifies one deployment of a shared
|
|
1291
|
+
* service, the same way a cloud endpoint would, and every caller of this
|
|
1292
|
+
* plugin in an organisation points at the same one. A deployment that needs a
|
|
1293
|
+
* different address is a code change here, which is the honest representation
|
|
1294
|
+
* — this is not something an end user picks.
|
|
1295
|
+
*/
|
|
1296
|
+
const AUTH_SERVICE_BASE = "https://public.aishell.openbuildlab.com";
|
|
1297
|
+
/**
|
|
1298
|
+
* A response this client could not use.
|
|
1299
|
+
*
|
|
1300
|
+
* Its own type so a caller can tell "the service said no" from "the network
|
|
1301
|
+
* failed": both mean the browser-login entry is unavailable, but only the
|
|
1302
|
+
* first is worth logging with the service's own words.
|
|
1303
|
+
*/
|
|
1304
|
+
var AuthContractError = class extends Error {
|
|
1305
|
+
constructor(..._args) {
|
|
1306
|
+
super(..._args);
|
|
1307
|
+
this.name = "AuthContractError";
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
/**
|
|
1311
|
+
* Read one JSON response, failing with the service's own message.
|
|
1312
|
+
*
|
|
1313
|
+
* The service answers errors as `{ error_code, error_msg }` — a shape shared
|
|
1314
|
+
* across this family of services — and the message is worth surfacing: it
|
|
1315
|
+
* distinguishes "this provider does not exist" from "this redirect_uri is not
|
|
1316
|
+
* acceptable", which are different problems with the same status class.
|
|
1317
|
+
*
|
|
1318
|
+
* @param response - the response to read.
|
|
1319
|
+
* @param what - what was being requested, for the fallback message.
|
|
1320
|
+
* @throws {AuthContractError} on a non-2xx status or an unreadable body.
|
|
1321
|
+
*/
|
|
1322
|
+
async function readJson(response, what) {
|
|
1323
|
+
if (!response.ok) {
|
|
1324
|
+
let detail = `HTTP ${String(response.status)}`;
|
|
1325
|
+
try {
|
|
1326
|
+
const body = await response.json();
|
|
1327
|
+
const message = typeof body.error_msg === "string" && body.error_msg !== "" ? body.error_msg : void 0;
|
|
1328
|
+
const code = typeof body.error_code === "string" ? body.error_code : void 0;
|
|
1329
|
+
if (message !== void 0) detail = code === void 0 ? message : `${message} (${code})`;
|
|
1330
|
+
} catch {}
|
|
1331
|
+
throw new AuthContractError(`${what} failed: ${detail}`);
|
|
1332
|
+
}
|
|
1333
|
+
try {
|
|
1334
|
+
return await response.json();
|
|
1335
|
+
} catch {
|
|
1336
|
+
throw new AuthContractError(`${what} returned a body that is not JSON.`);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
/** Narrow the service's answer to the shape this client is willing to act on. */
|
|
1340
|
+
function assertLoginTarget(value) {
|
|
1341
|
+
const callback = value.callback;
|
|
1342
|
+
if (typeof value.login_url !== "string" || value.login_url === "") throw new AuthContractError("The login service returned no login_url.");
|
|
1343
|
+
if (callback === null || typeof callback !== "object") throw new AuthContractError("The login service returned no callback plan.");
|
|
1344
|
+
if (typeof callback.address !== "string" || typeof callback.path !== "string") throw new AuthContractError("The login service returned an incomplete callback plan.");
|
|
1345
|
+
if (value.delivery !== "out_of_band") throw new AuthContractError(`The login service offered delivery "${value.delivery}", which this plugin cannot complete.`);
|
|
1346
|
+
return value;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* List the providers the service can dispatch for.
|
|
1350
|
+
*
|
|
1351
|
+
* @param deps - transport overrides.
|
|
1352
|
+
* @returns every provider, in the service's order.
|
|
1353
|
+
* @throws {AuthContractError} when the service is unreachable or answers unusably.
|
|
1354
|
+
*/
|
|
1355
|
+
async function listProviders(deps = {}) {
|
|
1356
|
+
const doFetch = deps.fetch ?? fetch;
|
|
1357
|
+
const base = deps.base ?? AUTH_SERVICE_BASE;
|
|
1358
|
+
let response;
|
|
1359
|
+
try {
|
|
1360
|
+
response = await doFetch(`${base}/v1/providers`);
|
|
1361
|
+
} catch (error) {
|
|
1362
|
+
throw new AuthContractError(`Could not reach the login service at ${base}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1363
|
+
}
|
|
1364
|
+
const body = await readJson(response, "Listing login providers");
|
|
1365
|
+
return body.providers ?? [];
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Find one provider by id.
|
|
1369
|
+
*
|
|
1370
|
+
* @param providerId - the provider to look for.
|
|
1371
|
+
* @param deps - transport overrides.
|
|
1372
|
+
* @returns the provider, or `undefined` when the service does not offer it.
|
|
1373
|
+
* @throws {AuthContractError} when the service is unreachable or answers unusably.
|
|
1374
|
+
*/
|
|
1375
|
+
async function findProvider(providerId, deps = {}) {
|
|
1376
|
+
const providers = await listProviders(deps);
|
|
1377
|
+
return providers.find((provider) => provider.id === providerId);
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Ask where the browser should go for one provider.
|
|
1381
|
+
*
|
|
1382
|
+
* @param providerId - the provider to sign in with.
|
|
1383
|
+
* @param redirectUri - the address the caller will listen on. Its host must be
|
|
1384
|
+
* loopback and its port explicit; a provider may reject anything else, and
|
|
1385
|
+
* the service reports that as a `400` rather than silently adjusting it.
|
|
1386
|
+
* @param deps - transport overrides.
|
|
1387
|
+
* @returns the browser URL and the callback plan to honour.
|
|
1388
|
+
* @throws {AuthContractError} when the service is unreachable, rejects the
|
|
1389
|
+
* redirect URI, or answers unusably.
|
|
1390
|
+
*/
|
|
1391
|
+
async function requestLogin(providerId, redirectUri, deps = {}) {
|
|
1392
|
+
const doFetch = deps.fetch ?? fetch;
|
|
1393
|
+
const base = deps.base ?? AUTH_SERVICE_BASE;
|
|
1394
|
+
const url = `${base}/v1/login?provider=${encodeURIComponent(providerId)}&redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
1395
|
+
let response;
|
|
1396
|
+
try {
|
|
1397
|
+
response = await doFetch(url);
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
throw new AuthContractError(`Could not reach the login service at ${base}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1400
|
+
}
|
|
1401
|
+
return assertLoginTarget(await readJson(response, `Starting a ${providerId} login`));
|
|
1402
|
+
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Apply a provider's `credential_schema` to a callback payload.
|
|
1405
|
+
*
|
|
1406
|
+
* The schema maps a payload key to a type; this pulls the string values out
|
|
1407
|
+
* under the names the store uses. A payload missing a field the schema
|
|
1408
|
+
* promises is a malformed callback, not a credential — returning `undefined`
|
|
1409
|
+
* lets the caller treat it as "nothing arrived" instead of storing half a
|
|
1410
|
+
* pair, which is the failure the store's single-record design exists to
|
|
1411
|
+
* prevent.
|
|
1412
|
+
*
|
|
1413
|
+
* A `securitytoken` absent from both the schema and the payload is ordinary —
|
|
1414
|
+
* a permanent key has none — so it is optional even though the schema lists
|
|
1415
|
+
* it.
|
|
1416
|
+
*
|
|
1417
|
+
* @param schema - the provider's `credential_schema`.
|
|
1418
|
+
* @param payload - the decoded callback body.
|
|
1419
|
+
* @returns the credential under this plugin's names, or `undefined` when the
|
|
1420
|
+
* payload does not satisfy the schema.
|
|
1421
|
+
*/
|
|
1422
|
+
function mapCredential(schema, payload) {
|
|
1423
|
+
/** The schema key whose name marks it as each slot; providers differ, the roles do not. */
|
|
1424
|
+
const keyFor = (candidates) => Object.keys(schema).find((key) => candidates.includes(key.replace(/[_-]/g, "").toLowerCase()));
|
|
1425
|
+
const accessKey = keyFor([
|
|
1426
|
+
"access",
|
|
1427
|
+
"accesskey",
|
|
1428
|
+
"accesskeyid",
|
|
1429
|
+
"ak"
|
|
1430
|
+
]);
|
|
1431
|
+
const secretKey = keyFor([
|
|
1432
|
+
"secret",
|
|
1433
|
+
"secretkey",
|
|
1434
|
+
"secretaccesskey",
|
|
1435
|
+
"sk"
|
|
1436
|
+
]);
|
|
1437
|
+
const token = keyFor([
|
|
1438
|
+
"securitytoken",
|
|
1439
|
+
"token",
|
|
1440
|
+
"sessiontoken"
|
|
1441
|
+
]);
|
|
1442
|
+
if (accessKey === void 0 || secretKey === void 0) return void 0;
|
|
1443
|
+
const ak = payload[accessKey];
|
|
1444
|
+
const sk = payload[secretKey];
|
|
1445
|
+
if (typeof ak !== "string" || ak === "" || typeof sk !== "string" || sk === "") return void 0;
|
|
1446
|
+
const rawToken = token === void 0 ? void 0 : payload[token];
|
|
1447
|
+
return {
|
|
1448
|
+
accessKeyId: ak,
|
|
1449
|
+
secretAccessKey: sk,
|
|
1450
|
+
...typeof rawToken === "string" && rawToken !== "" ? { securityToken: rawToken } : {}
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
//#endregion
|
|
1455
|
+
//#region src/out-of-band/listener.ts
|
|
1456
|
+
/** Largest callback body accepted. A credential is a few fields; 64 KiB is generous. */
|
|
1457
|
+
const MAX_CALLBACK_BYTES = 64 * 1024;
|
|
1458
|
+
/** Header a browser sends on the preflight that precedes a loopback request. */
|
|
1459
|
+
const PNA_REQUEST_HEADER = "access-control-request-private-network";
|
|
1460
|
+
/** Query parameter carrying the probe nonce. */
|
|
1461
|
+
const PROBE_NONCE_PARAM = "n";
|
|
1462
|
+
/**
|
|
1463
|
+
* Whether an `Origin` matches an allowed origin exactly.
|
|
1464
|
+
*
|
|
1465
|
+
* Exact comparison, deliberately: a suffix or prefix rule would admit
|
|
1466
|
+
* `https://<allowed>.evil.com` and `https://evil-<allowed>`, and a
|
|
1467
|
+
* case-insensitive rule would admit a spelling the browser never sends. The
|
|
1468
|
+
* service's reference client makes the same choice for the same reason.
|
|
1469
|
+
*
|
|
1470
|
+
* @param allowed - the plan's list.
|
|
1471
|
+
* @param origin - the request's `Origin`, if any.
|
|
1472
|
+
* @returns the matched origin to echo, or `undefined` when nothing matched.
|
|
1473
|
+
*/
|
|
1474
|
+
function matchOrigin(allowed, origin) {
|
|
1475
|
+
if (origin === void 0) return void 0;
|
|
1476
|
+
return allowed.find((candidate) => candidate === origin);
|
|
1477
|
+
}
|
|
1478
|
+
/**
|
|
1479
|
+
* Read a request's single header value.
|
|
1480
|
+
*
|
|
1481
|
+
* Node delivers a repeated header as an array; a preflight never legitimately
|
|
1482
|
+
* repeats these, so an array is treated as absent rather than joined into
|
|
1483
|
+
* something that would not match.
|
|
1484
|
+
*
|
|
1485
|
+
* @param request - the incoming request.
|
|
1486
|
+
* @param name - lowercase header name.
|
|
1487
|
+
*/
|
|
1488
|
+
function header(request, name$1) {
|
|
1489
|
+
const value = request.headers[name$1];
|
|
1490
|
+
return typeof value === "string" ? value : void 0;
|
|
1491
|
+
}
|
|
1492
|
+
/** The path portion of a request target, without its query. */
|
|
1493
|
+
function pathOf(request) {
|
|
1494
|
+
return (request.url ?? "").split("?")[0] ?? "";
|
|
1495
|
+
}
|
|
1496
|
+
/** The value of one query parameter in a request target. */
|
|
1497
|
+
function queryParam(request, name$1) {
|
|
1498
|
+
const query = (request.url ?? "").split("?")[1];
|
|
1499
|
+
if (query === void 0) return void 0;
|
|
1500
|
+
for (const pair of query.split("&")) {
|
|
1501
|
+
const [key, value] = pair.split("=");
|
|
1502
|
+
if (key === name$1) return value === void 0 ? void 0 : decodeURIComponent(value);
|
|
1503
|
+
}
|
|
1504
|
+
return void 0;
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Write a CORS preflight answer.
|
|
1508
|
+
*
|
|
1509
|
+
* @param response - the response to write.
|
|
1510
|
+
* @param origin - the matched origin to echo.
|
|
1511
|
+
* @param allowMethods - methods to advertise.
|
|
1512
|
+
* @param allowHeaders - request headers to advertise, when any.
|
|
1513
|
+
* @param allowPrivateNetwork - whether the plan says the cloud's post is a
|
|
1514
|
+
* private-network request. Both this and the browser's own request header
|
|
1515
|
+
* must hold before the allow header is written.
|
|
1516
|
+
* @param request - the preflight, for its PNA request header.
|
|
1517
|
+
*/
|
|
1518
|
+
function writePreflight(response, origin, allowMethods, allowHeaders, allowPrivateNetwork, request) {
|
|
1519
|
+
const headers = {
|
|
1520
|
+
"access-control-allow-origin": origin,
|
|
1521
|
+
vary: "Origin",
|
|
1522
|
+
"access-control-allow-methods": allowMethods
|
|
1523
|
+
};
|
|
1524
|
+
if (allowHeaders !== void 0) headers["access-control-allow-headers"] = allowHeaders;
|
|
1525
|
+
if (allowPrivateNetwork && header(request, PNA_REQUEST_HEADER) === "true") headers["access-control-allow-private-network"] = "true";
|
|
1526
|
+
response.writeHead(204, headers);
|
|
1527
|
+
response.end();
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Read a request body up to {@link MAX_CALLBACK_BYTES}.
|
|
1531
|
+
*
|
|
1532
|
+
* @param request - the request to drain.
|
|
1533
|
+
* @returns the decoded JSON object.
|
|
1534
|
+
* @throws when the body exceeds the bound, is not JSON, or is not an object.
|
|
1535
|
+
*/
|
|
1536
|
+
function readPayload(request) {
|
|
1537
|
+
return new Promise((resolve, reject) => {
|
|
1538
|
+
const chunks = [];
|
|
1539
|
+
let size = 0;
|
|
1540
|
+
let settled = false;
|
|
1541
|
+
const fail = (error) => {
|
|
1542
|
+
if (settled) return;
|
|
1543
|
+
settled = true;
|
|
1544
|
+
reject(error);
|
|
1545
|
+
};
|
|
1546
|
+
request.on("error", fail);
|
|
1547
|
+
request.on("data", (chunk) => {
|
|
1548
|
+
if (settled) return;
|
|
1549
|
+
size += chunk.length;
|
|
1550
|
+
if (size > MAX_CALLBACK_BYTES) {
|
|
1551
|
+
fail(new Error("Callback body exceeded the accepted size."));
|
|
1552
|
+
request.pause();
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
chunks.push(chunk.toString("utf8"));
|
|
1556
|
+
});
|
|
1557
|
+
request.on("end", () => {
|
|
1558
|
+
if (settled) return;
|
|
1559
|
+
settled = true;
|
|
1560
|
+
try {
|
|
1561
|
+
const parsed = JSON.parse(chunks.join(""));
|
|
1562
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1563
|
+
reject(new Error("Callback body is not a JSON object."));
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
resolve(parsed);
|
|
1567
|
+
} catch {
|
|
1568
|
+
reject(new Error("Callback body is not valid JSON."));
|
|
1569
|
+
}
|
|
1570
|
+
});
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Bind a loopback port, without yet honouring any plan.
|
|
1575
|
+
*
|
|
1576
|
+
* Binds before anything else happens, deliberately: the port appears in the
|
|
1577
|
+
* redirect URI and is therefore not a secret, so a local process could take it
|
|
1578
|
+
* first. Binding early and handing the actual port back is what makes the
|
|
1579
|
+
* ordering correct by construction rather than by care.
|
|
1580
|
+
*
|
|
1581
|
+
* @returns the bound socket.
|
|
1582
|
+
* @throws when the port cannot be bound.
|
|
1583
|
+
*/
|
|
1584
|
+
async function bindLoopback() {
|
|
1585
|
+
let handler;
|
|
1586
|
+
const server = createServer((request, response) => {
|
|
1587
|
+
if (handler === void 0) {
|
|
1588
|
+
response.writeHead(503);
|
|
1589
|
+
response.end();
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
handler(request, response);
|
|
1593
|
+
});
|
|
1594
|
+
await new Promise((resolve, reject) => {
|
|
1595
|
+
server.on("listening", () => {
|
|
1596
|
+
resolve();
|
|
1597
|
+
});
|
|
1598
|
+
server.on("error", (error) => {
|
|
1599
|
+
reject(error);
|
|
1600
|
+
});
|
|
1601
|
+
server.listen(0, "127.0.0.1");
|
|
1602
|
+
});
|
|
1603
|
+
const address = server.address();
|
|
1604
|
+
if (address === null || typeof address === "string") {
|
|
1605
|
+
server.close();
|
|
1606
|
+
throw new Error("The callback listener bound without an address.");
|
|
1607
|
+
}
|
|
1608
|
+
const bound = `127.0.0.1:${String(address.port)}`;
|
|
1609
|
+
let closed = false;
|
|
1610
|
+
return {
|
|
1611
|
+
host: "127.0.0.1",
|
|
1612
|
+
port: address.port,
|
|
1613
|
+
address: bound,
|
|
1614
|
+
close: () => {
|
|
1615
|
+
if (closed) return;
|
|
1616
|
+
closed = true;
|
|
1617
|
+
server.close();
|
|
1618
|
+
},
|
|
1619
|
+
serve: (plan, probe) => {
|
|
1620
|
+
const allowed = plan.allow_origins ?? [];
|
|
1621
|
+
const allowPrivateNetwork = plan.requires_private_network_access === true;
|
|
1622
|
+
let settleAccepted;
|
|
1623
|
+
let failAccepted;
|
|
1624
|
+
const accepted = new Promise((resolve, reject) => {
|
|
1625
|
+
settleAccepted = resolve;
|
|
1626
|
+
failAccepted = reject;
|
|
1627
|
+
});
|
|
1628
|
+
accepted.catch(() => {});
|
|
1629
|
+
let received = false;
|
|
1630
|
+
server.on("error", (error) => {
|
|
1631
|
+
failAccepted(error);
|
|
1632
|
+
});
|
|
1633
|
+
const close = () => {
|
|
1634
|
+
if (closed) return;
|
|
1635
|
+
closed = true;
|
|
1636
|
+
server.close();
|
|
1637
|
+
};
|
|
1638
|
+
/** Whether this request is the probe: right path, and the nonce it was given. */
|
|
1639
|
+
const isProbe = (request) => probe !== void 0 && pathOf(request) === probe.path && queryParam(request, PROBE_NONCE_PARAM) === probe.nonce;
|
|
1640
|
+
handler = (request, response) => {
|
|
1641
|
+
const method = request.method ?? "";
|
|
1642
|
+
if (probe !== void 0 && pathOf(request) === probe.path) {
|
|
1643
|
+
if (method === "OPTIONS") {
|
|
1644
|
+
const origin$2 = header(request, "origin");
|
|
1645
|
+
if (origin$2 === void 0 || !isProbe(request)) {
|
|
1646
|
+
response.writeHead(204);
|
|
1647
|
+
response.end();
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
writePreflight(response, origin$2, "GET, OPTIONS", PROBE_HEADER, allowPrivateNetwork, request);
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
if (method !== "GET" || !isProbe(request)) {
|
|
1654
|
+
response.writeHead(404);
|
|
1655
|
+
response.end();
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
const origin$1 = header(request, "origin");
|
|
1659
|
+
response.writeHead(204, origin$1 === void 0 ? {} : {
|
|
1660
|
+
"access-control-allow-origin": origin$1,
|
|
1661
|
+
vary: "Origin"
|
|
1662
|
+
});
|
|
1663
|
+
response.end();
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
if (method === "OPTIONS") {
|
|
1667
|
+
const origin$1 = matchOrigin(allowed, header(request, "origin"));
|
|
1668
|
+
if (origin$1 === void 0) {
|
|
1669
|
+
response.writeHead(204);
|
|
1670
|
+
response.end();
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
writePreflight(response, origin$1, `${plan.method}, OPTIONS`, plan.content_type === void 0 || plan.content_type === "" ? void 0 : "Content-Type", allowPrivateNetwork, request);
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
if (method !== plan.method) {
|
|
1677
|
+
response.writeHead(405);
|
|
1678
|
+
response.end();
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
if (pathOf(request) !== plan.path) {
|
|
1682
|
+
response.writeHead(404);
|
|
1683
|
+
response.end();
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
if (received) {
|
|
1687
|
+
response.writeHead(409);
|
|
1688
|
+
response.end();
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
const origin = matchOrigin(allowed, header(request, "origin"));
|
|
1692
|
+
if (allowed.length > 0 && origin === void 0) {
|
|
1693
|
+
response.writeHead(403);
|
|
1694
|
+
response.end();
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
readPayload(request).then((payload) => {
|
|
1698
|
+
if (closed || received) {
|
|
1699
|
+
response.writeHead(409);
|
|
1700
|
+
response.end();
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
received = true;
|
|
1704
|
+
const headers = {};
|
|
1705
|
+
if (origin !== void 0) {
|
|
1706
|
+
headers["access-control-allow-origin"] = origin;
|
|
1707
|
+
headers.vary = "Origin";
|
|
1708
|
+
}
|
|
1709
|
+
response.writeHead(200, headers);
|
|
1710
|
+
response.end();
|
|
1711
|
+
settleAccepted(payload);
|
|
1712
|
+
close();
|
|
1713
|
+
}, (error) => {
|
|
1714
|
+
if (closed) return;
|
|
1715
|
+
response.writeHead(400);
|
|
1716
|
+
response.end();
|
|
1717
|
+
failAccepted(error instanceof Error ? error : new Error(String(error)));
|
|
1718
|
+
});
|
|
1719
|
+
};
|
|
1720
|
+
return {
|
|
1721
|
+
address: bound,
|
|
1722
|
+
accepted,
|
|
1723
|
+
close
|
|
1724
|
+
};
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
//#endregion
|
|
1730
|
+
//#region src/out-of-band/login.ts
|
|
1731
|
+
/** A value that cannot be guessed from the port alone. */
|
|
1732
|
+
function randomNonce() {
|
|
1733
|
+
const bytes = new Uint8Array(16);
|
|
1734
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1735
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* How long to wait when the service does not say.
|
|
1739
|
+
*
|
|
1740
|
+
* The service's own contract states ten minutes; this matches it rather than
|
|
1741
|
+
* inventing a different number, so a response omitting the field behaves the
|
|
1742
|
+
* same as one carrying the documented value.
|
|
1743
|
+
*/
|
|
1744
|
+
const DEFAULT_EXPIRES_SECONDS = 600;
|
|
1745
|
+
/**
|
|
1746
|
+
* Detach a timer from the event loop, when the runtime has that notion.
|
|
1747
|
+
*
|
|
1748
|
+
* Node's timer objects carry `unref`; a browser's are numbers. This package's
|
|
1749
|
+
* tsconfig compiles against the DOM signature (the browser half is most of
|
|
1750
|
+
* it), so the method is reached through a narrow cast rather than declared.
|
|
1751
|
+
*
|
|
1752
|
+
* @param timer - the timer handle, of whichever shape this runtime uses.
|
|
1753
|
+
*/
|
|
1754
|
+
function unrefIfPossible(timer) {
|
|
1755
|
+
const candidate = timer;
|
|
1756
|
+
if (typeof candidate?.unref === "function") candidate.unref();
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Begin a browser login.
|
|
1760
|
+
*
|
|
1761
|
+
* Everything it returns is settled by the time it returns except `credential`,
|
|
1762
|
+
* which resolves when the person finishes signing in. The bind, the plan fetch
|
|
1763
|
+
* and the plan check all happen first, so a caller that gets a login back
|
|
1764
|
+
* knows there is a listener and somewhere to send the browser — a failure in
|
|
1765
|
+
* any of those throws instead.
|
|
1766
|
+
*
|
|
1767
|
+
* @param options - provider, verifier, and the probe path.
|
|
1768
|
+
* @returns the running login.
|
|
1769
|
+
* @throws {AuthContractError} when the port cannot be bound, the service
|
|
1770
|
+
* cannot be reached, or the plan names an address this machine is not on.
|
|
1771
|
+
*/
|
|
1772
|
+
async function startBrowserLogin(options) {
|
|
1773
|
+
const { provider, verify, probePath, contract } = options;
|
|
1774
|
+
const bound = await bindLoopback();
|
|
1775
|
+
let cancelled = false;
|
|
1776
|
+
try {
|
|
1777
|
+
const target = await requestLogin(provider.id, `http://${bound.address}/`, contract);
|
|
1778
|
+
if (target.callback.address !== "" && target.callback.address !== bound.address) throw new AuthContractError(`The login service expects the callback at ${target.callback.address}, but this machine is listening on ${bound.address}. Refusing to wait for a callback that cannot arrive.`);
|
|
1779
|
+
const nonce = randomNonce();
|
|
1780
|
+
const listener = bound.serve(target.callback, {
|
|
1781
|
+
path: probePath,
|
|
1782
|
+
nonce
|
|
1783
|
+
});
|
|
1784
|
+
const probeUrl = `http://${bound.address}${probePath}?n=${nonce}`;
|
|
1785
|
+
const expiresInSeconds = target.expires_in > 0 ? target.expires_in : DEFAULT_EXPIRES_SECONDS;
|
|
1786
|
+
let settleCredential;
|
|
1787
|
+
let failCredential;
|
|
1788
|
+
const completion = Promise.withResolvers();
|
|
1789
|
+
settleCredential = completion.resolve;
|
|
1790
|
+
failCredential = completion.reject;
|
|
1791
|
+
const credential = completion.promise;
|
|
1792
|
+
credential.catch(() => {});
|
|
1793
|
+
(async () => {
|
|
1794
|
+
const expirySeconds = expiresInSeconds;
|
|
1795
|
+
let expiry;
|
|
1796
|
+
const expired = new Promise((resolve) => {
|
|
1797
|
+
expiry = setTimeout(() => {
|
|
1798
|
+
resolve("expired");
|
|
1799
|
+
}, expirySeconds * 1e3);
|
|
1800
|
+
unrefIfPossible(expiry);
|
|
1801
|
+
});
|
|
1802
|
+
let payload;
|
|
1803
|
+
try {
|
|
1804
|
+
const outcome = await Promise.race([listener.accepted.then((value) => ({
|
|
1805
|
+
kind: "accepted",
|
|
1806
|
+
value
|
|
1807
|
+
})), expired.then(() => ({ kind: "expired" }))]);
|
|
1808
|
+
if (outcome.kind === "expired") {
|
|
1809
|
+
bound.close();
|
|
1810
|
+
failCredential(new AuthContractError(`The browser sign-in was not completed within ${String(Math.round(expirySeconds / 60))} minutes. Open the credential form again to retry.`));
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
payload = outcome.value;
|
|
1814
|
+
} catch (error) {
|
|
1815
|
+
if (cancelled) return;
|
|
1816
|
+
failCredential(error instanceof Error ? error : new Error(String(error)));
|
|
1817
|
+
return;
|
|
1818
|
+
} finally {
|
|
1819
|
+
if (expiry !== void 0) clearTimeout(expiry);
|
|
1820
|
+
}
|
|
1821
|
+
if (cancelled) return;
|
|
1822
|
+
const mapped = mapCredential(provider.credential_schema, payload);
|
|
1823
|
+
if (mapped === void 0) {
|
|
1824
|
+
failCredential(new AuthContractError("The callback arrived but did not carry the fields the provider declared."));
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
let accountName;
|
|
1828
|
+
try {
|
|
1829
|
+
accountName = await verify(mapped);
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
failCredential(error instanceof Error ? error : new Error(String(error)));
|
|
1832
|
+
return;
|
|
1833
|
+
}
|
|
1834
|
+
if (cancelled) return;
|
|
1835
|
+
settleCredential({
|
|
1836
|
+
credential: mapped,
|
|
1837
|
+
accountName: typeof accountName === "string" ? accountName : ""
|
|
1838
|
+
});
|
|
1839
|
+
})();
|
|
1840
|
+
return {
|
|
1841
|
+
address: bound.address,
|
|
1842
|
+
probeUrl,
|
|
1843
|
+
loginUrl: target.login_url,
|
|
1844
|
+
expiresInSeconds,
|
|
1845
|
+
credential,
|
|
1846
|
+
cancel: () => {
|
|
1847
|
+
if (cancelled) return;
|
|
1848
|
+
cancelled = true;
|
|
1849
|
+
bound.close();
|
|
1850
|
+
failCredential(new AuthContractError("The browser login was cancelled."));
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
} catch (error) {
|
|
1854
|
+
bound.close();
|
|
1855
|
+
throw error;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
//#endregion
|
|
1860
|
+
//#region src/out-of-band/routes.ts
|
|
1861
|
+
/** Path the browser half posts to, to begin a login. */
|
|
1862
|
+
const LOGIN_START_PATH = "/api/aishell/credentials/login/start";
|
|
1863
|
+
/** Path the browser half posts to, to abandon a login. */
|
|
1864
|
+
const LOGIN_CANCEL_PATH = "/api/aishell/credentials/login/cancel";
|
|
1865
|
+
/**
|
|
1866
|
+
* Path the probe is served on, on the callback listener.
|
|
1867
|
+
*
|
|
1868
|
+
* On the listener rather than the host's `/api` route deliberately: the
|
|
1869
|
+
* question is whether the browser can reach *that* socket, so the probe has to
|
|
1870
|
+
* be answered there. Under a name no provider will use as a callback path —
|
|
1871
|
+
* the shipped provider posts to the root, so anything else is free.
|
|
1872
|
+
*/
|
|
1873
|
+
const LOGIN_PROBE_PATH = "/__aishell_probe";
|
|
1874
|
+
/** One JSON response the browser half reads. */
|
|
1875
|
+
function json(body, status = 200) {
|
|
1876
|
+
return Response.json(body, {
|
|
1877
|
+
status,
|
|
1878
|
+
headers: { "cache-control": "no-store" }
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
/** Read a JSON object body, or `{}` when it is absent or unreadable. */
|
|
1882
|
+
async function readBody(request) {
|
|
1883
|
+
try {
|
|
1884
|
+
const parsed = JSON.parse(await request.text());
|
|
1885
|
+
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
1886
|
+
} catch {
|
|
1887
|
+
return {};
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
/** The login routes, bound to their collaborators. */
|
|
1891
|
+
function createLoginRoutes(deps) {
|
|
1892
|
+
const { findProvider: findProvider$1, begin, cancel, inProgress } = deps;
|
|
1893
|
+
return {
|
|
1894
|
+
start: async (request) => {
|
|
1895
|
+
if (inProgress()) return json({
|
|
1896
|
+
ok: false,
|
|
1897
|
+
error: "A browser login is already in progress."
|
|
1898
|
+
}, 409);
|
|
1899
|
+
const body = await readBody(request);
|
|
1900
|
+
const providerId = typeof body.provider === "string" && body.provider !== "" ? body.provider : "huaweicloud";
|
|
1901
|
+
let provider;
|
|
1902
|
+
try {
|
|
1903
|
+
provider = await findProvider$1(providerId);
|
|
1904
|
+
} catch (error) {
|
|
1905
|
+
return json({
|
|
1906
|
+
ok: false,
|
|
1907
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1908
|
+
}, 503);
|
|
1909
|
+
}
|
|
1910
|
+
if (provider === void 0) return json({
|
|
1911
|
+
ok: false,
|
|
1912
|
+
error: `No login provider named ${providerId}.`
|
|
1913
|
+
}, 404);
|
|
1914
|
+
if (provider.delivery !== "out_of_band") return json({
|
|
1915
|
+
ok: false,
|
|
1916
|
+
error: `Provider ${providerId} uses "${provider.delivery}", which this plugin cannot complete.`
|
|
1917
|
+
}, 501);
|
|
1918
|
+
try {
|
|
1919
|
+
return json(await begin(provider));
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
return json({
|
|
1922
|
+
ok: false,
|
|
1923
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1924
|
+
}, 502);
|
|
1925
|
+
}
|
|
1926
|
+
},
|
|
1927
|
+
cancel: () => {
|
|
1928
|
+
cancel();
|
|
1929
|
+
return Promise.resolve(json({ ok: true }));
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
//#endregion
|
|
1935
|
+
//#region src/out-of-band/flow.ts
|
|
1936
|
+
/**
|
|
1937
|
+
* Build the flow.
|
|
1938
|
+
*
|
|
1939
|
+
* @param deps - the collaborators above.
|
|
1940
|
+
*/
|
|
1941
|
+
function createLoginFlow(deps) {
|
|
1942
|
+
const { verify, store, recordError, recordOutcome, contract } = deps;
|
|
1943
|
+
/** The login in progress, if any. */
|
|
1944
|
+
let active;
|
|
1945
|
+
const finish = () => {
|
|
1946
|
+
active = void 0;
|
|
1947
|
+
};
|
|
1948
|
+
return {
|
|
1949
|
+
findProvider: (providerId) => findProvider(providerId, contract),
|
|
1950
|
+
inProgress: () => active !== void 0,
|
|
1951
|
+
cancel: () => {
|
|
1952
|
+
const login = active;
|
|
1953
|
+
finish();
|
|
1954
|
+
login?.cancel();
|
|
1955
|
+
recordOutcome(void 0);
|
|
1956
|
+
},
|
|
1957
|
+
begin: async (provider) => {
|
|
1958
|
+
if (active !== void 0) throw new AuthContractError("A browser login is already in progress.");
|
|
1959
|
+
const login = await startBrowserLogin({
|
|
1960
|
+
provider,
|
|
1961
|
+
probePath: LOGIN_PROBE_PATH,
|
|
1962
|
+
contract,
|
|
1963
|
+
verify
|
|
1964
|
+
});
|
|
1965
|
+
active = login;
|
|
1966
|
+
login.credential.then(async (result) => {
|
|
1967
|
+
if (active !== login) return;
|
|
1968
|
+
try {
|
|
1969
|
+
await store(result.credential);
|
|
1970
|
+
if (active !== login) return;
|
|
1971
|
+
finish();
|
|
1972
|
+
recordError("");
|
|
1973
|
+
recordOutcome({
|
|
1974
|
+
kind: "succeeded",
|
|
1975
|
+
accountName: result.accountName
|
|
1976
|
+
});
|
|
1977
|
+
} catch (error) {
|
|
1978
|
+
if (active !== login) return;
|
|
1979
|
+
finish();
|
|
1980
|
+
const message = `The credential verified, but storing it failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1981
|
+
recordError(message);
|
|
1982
|
+
recordOutcome({
|
|
1983
|
+
kind: "failed",
|
|
1984
|
+
error: message
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}, (error) => {
|
|
1988
|
+
if (active !== login) return;
|
|
1989
|
+
finish();
|
|
1990
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1991
|
+
recordError(message);
|
|
1992
|
+
recordOutcome({
|
|
1993
|
+
kind: "failed",
|
|
1994
|
+
error: message
|
|
1995
|
+
});
|
|
1996
|
+
});
|
|
1997
|
+
return {
|
|
1998
|
+
ok: true,
|
|
1999
|
+
loginUrl: login.loginUrl,
|
|
2000
|
+
probeUrl: login.probeUrl,
|
|
2001
|
+
providerName: provider.display_name,
|
|
2002
|
+
expiresInSeconds: login.expiresInSeconds
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
//#endregion
|
|
2009
|
+
//#region src/prefill.ts
|
|
2010
|
+
/**
|
|
2011
|
+
* Credential prefill from the environment.
|
|
2012
|
+
*
|
|
2013
|
+
* ## What this is for
|
|
2014
|
+
*
|
|
2015
|
+
* A machine that already carries `HW_ACCESS_KEY`, `HW_SECRET_KEY` and
|
|
2016
|
+
* `HW_SECURITY_TOKEN` in its environment has the credentials; the person just
|
|
2017
|
+
* has to move them into the store. Typing three values that are already on the
|
|
2018
|
+
* machine is work nobody should do, so the form opens with them filled in.
|
|
2019
|
+
*
|
|
2020
|
+
* ## Why the values come from the host
|
|
2021
|
+
*
|
|
2022
|
+
* The browser half cannot read `process.env` — it is browser code, and the
|
|
2023
|
+
* environment it would see is not the host's. So the host reads the variables
|
|
2024
|
+
* and serves them over a route the form calls before it renders its fields.
|
|
2025
|
+
*
|
|
2026
|
+
* ## Why that is acceptable here
|
|
2027
|
+
*
|
|
2028
|
+
* The values travel from the host to the page it is serving, over the same
|
|
2029
|
+
* authenticated channel and the same origin as the credential route the form
|
|
2030
|
+
* already posts to. Nothing new is exposed: a page that could read this route
|
|
2031
|
+
* could also submit that form.
|
|
2032
|
+
*
|
|
2033
|
+
* They are **not** written to the settings document, the session, or a log —
|
|
2034
|
+
* the route is the whole journey, and it is called once per form open.
|
|
2035
|
+
*
|
|
2036
|
+
* ## Why it returns nothing rather than a partial set
|
|
2037
|
+
*
|
|
2038
|
+
* A form filled with an access key and no secret key looks broken. Either the
|
|
2039
|
+
* environment carries a usable pair, or the form starts empty and the person
|
|
2040
|
+
* enters what they have. The token is separate: it is optional, and a lone
|
|
2041
|
+
* token with no pair is dropped for the same reason.
|
|
2042
|
+
*
|
|
2043
|
+
* ## Why the form says so
|
|
2044
|
+
*
|
|
2045
|
+
* The person did not type these values. Saying where they came from is what
|
|
2046
|
+
* lets them decide whether to trust them — a credential silently appearing in
|
|
2047
|
+
* a field is worse than an empty one.
|
|
2048
|
+
*
|
|
2049
|
+
* @module @huaweidevtools/aishell-dsh-client-credentials/prefill
|
|
2050
|
+
*/
|
|
2051
|
+
/** Route the form reads prefills from. */
|
|
2052
|
+
const PREFILL_PATH = "/api/aishell/credentials/prefill";
|
|
2053
|
+
/** Variables read, in the order the form's fields appear. */
|
|
2054
|
+
const ACCESS_KEY_ENV = "HW_ACCESS_KEY";
|
|
2055
|
+
const SECRET_KEY_ENV = "HW_SECRET_KEY";
|
|
2056
|
+
const SECURITY_TOKEN_ENV = "HW_SECURITY_TOKEN";
|
|
2057
|
+
/**
|
|
2058
|
+
* Read an environment for a usable credential set.
|
|
2059
|
+
*
|
|
2060
|
+
* Pure, and the environment is a parameter: this package compiles without Node
|
|
2061
|
+
* type definitions (the browser half is most of it), so `process` is not in
|
|
2062
|
+
* scope and the caller supplies what to read.
|
|
2063
|
+
*
|
|
2064
|
+
* ## What these values do, and do not, do
|
|
2065
|
+
*
|
|
2066
|
+
* They fill the form's fields. The form still opens, every field is still
|
|
2067
|
+
* editable, and submitting or cancelling still works the way it always did —
|
|
2068
|
+
* the person saves the step of copying three values out of their shell, and
|
|
2069
|
+
* nothing else. In particular nothing is stored on their behalf: a prefill is a
|
|
2070
|
+
* starting point, not a credential.
|
|
2071
|
+
*
|
|
2072
|
+
* @param env - the environment to read.
|
|
2073
|
+
* @returns the pair (and token, when present), or `undefined` when either half
|
|
2074
|
+
* of the pair is missing.
|
|
2075
|
+
*/
|
|
2076
|
+
function readEnvPrefill(env) {
|
|
2077
|
+
const ak = env[ACCESS_KEY_ENV];
|
|
2078
|
+
const sk = env[SECRET_KEY_ENV];
|
|
2079
|
+
if (ak === void 0 || ak === "" || sk === void 0 || sk === "") return void 0;
|
|
2080
|
+
const token = env[SECURITY_TOKEN_ENV];
|
|
2081
|
+
return {
|
|
2082
|
+
accessKeyId: ak,
|
|
2083
|
+
secretAccessKey: sk,
|
|
2084
|
+
...token === void 0 || token === "" ? {} : { securityToken: token }
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
|
|
896
2088
|
//#endregion
|
|
897
2089
|
//#region src/reconcile.ts
|
|
898
2090
|
/**
|
|
@@ -915,14 +2107,13 @@ defineMethod("transform", [
|
|
|
915
2107
|
* mirror so reconcile never depends on config flow-back timing.
|
|
916
2108
|
*/
|
|
917
2109
|
function createCredentialReconciler(deps) {
|
|
918
|
-
const {
|
|
2110
|
+
const { verify, recordStatus, readStored, readHint, readPair } = deps;
|
|
919
2111
|
let lastVerifyFingerprint = "";
|
|
920
2112
|
const materialFingerprint = (ak, sk, token) => `${ak}\n${sk}\n${token ?? ""}`;
|
|
921
2113
|
return {
|
|
922
2114
|
reconcile: () => {
|
|
923
|
-
const
|
|
924
|
-
const
|
|
925
|
-
const haveKeys = Boolean(ak && sk);
|
|
2115
|
+
const pair = readPair();
|
|
2116
|
+
const haveKeys = pair !== void 0;
|
|
926
2117
|
const stored = readStored();
|
|
927
2118
|
const hint = readHint();
|
|
928
2119
|
if (!haveKeys && (stored || hint !== null)) recordStatus([{
|
|
@@ -939,14 +2130,12 @@ function createCredentialReconciler(deps) {
|
|
|
939
2130
|
value: true
|
|
940
2131
|
}]);
|
|
941
2132
|
if (!haveKeys) return;
|
|
942
|
-
const
|
|
943
|
-
const fingerprint = materialFingerprint(ak, sk, token);
|
|
2133
|
+
const fingerprint = materialFingerprint(pair.ak, pair.sk, pair.securityToken);
|
|
944
2134
|
const materialChanged = fingerprint !== lastVerifyFingerprint;
|
|
945
2135
|
if (!materialChanged) return;
|
|
946
2136
|
lastVerifyFingerprint = fingerprint;
|
|
947
|
-
verify(ak, sk,
|
|
948
|
-
if (
|
|
949
|
-
if (store.get(accounts.secretKey) !== sk) return;
|
|
2137
|
+
verify(pair.ak, pair.sk, pair.securityToken).then((accountName) => {
|
|
2138
|
+
if (readPair()?.ak !== pair.ak) return;
|
|
950
2139
|
recordStatus([{
|
|
951
2140
|
op: "set",
|
|
952
2141
|
path: ["accessKeyIdHint"],
|
|
@@ -963,6 +2152,39 @@ function createCredentialReconciler(deps) {
|
|
|
963
2152
|
//#endregion
|
|
964
2153
|
//#region src/index.ts
|
|
965
2154
|
/**
|
|
2155
|
+
* Read the request token out of a save body.
|
|
2156
|
+
*
|
|
2157
|
+
* Parsed leniently: the route validates the body itself and answers 400 for a
|
|
2158
|
+
* malformed one, so this only has to avoid throwing on the way past. A missing
|
|
2159
|
+
* or unreadable token means "not an answer to a request", which is the right
|
|
2160
|
+
* behaviour for a chip-opened form.
|
|
2161
|
+
*
|
|
2162
|
+
* @param body - the raw request body.
|
|
2163
|
+
*/
|
|
2164
|
+
function readRequestToken(body) {
|
|
2165
|
+
try {
|
|
2166
|
+
const parsed = JSON.parse(body);
|
|
2167
|
+
const token = parsed?.requestToken;
|
|
2168
|
+
return typeof token === "string" && token !== "" ? token : void 0;
|
|
2169
|
+
} catch {
|
|
2170
|
+
return void 0;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* The host process's environment.
|
|
2175
|
+
*
|
|
2176
|
+
* Reached through a narrow cast rather than a typed `process`: this package
|
|
2177
|
+
* compiles without Node type definitions, so `process` is not in scope. The
|
|
2178
|
+
* host always has it; `{}` is the shape a build without one falls back to, and
|
|
2179
|
+
* an empty environment simply yields no prefill.
|
|
2180
|
+
*
|
|
2181
|
+
* @returns the environment, or an empty object when there is none.
|
|
2182
|
+
*/
|
|
2183
|
+
function runtimeEnv() {
|
|
2184
|
+
const holder = globalThis;
|
|
2185
|
+
return holder.process?.env ?? {};
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
966
2188
|
* Settings schema for this entry. Secrets are deliberately absent: they travel
|
|
967
2189
|
* over the credential route into the credential store, never through a
|
|
968
2190
|
* settings document.
|
|
@@ -971,57 +2193,69 @@ const Config = Schema.object({
|
|
|
971
2193
|
credentialsStored: Schema.boolean().default(false).volatile(),
|
|
972
2194
|
accessKeyIdHint: Schema.string().default("").volatile(),
|
|
973
2195
|
lastError: Schema.string().default("").volatile(),
|
|
974
|
-
|
|
2196
|
+
credentialFormRequest: Schema.string().default("").volatile(),
|
|
2197
|
+
loginOutcome: Schema.string().default("").volatile()
|
|
975
2198
|
});
|
|
976
|
-
/** Credential store account names for Huawei Cloud credentials. */
|
|
977
|
-
const AK_ACCOUNT = "HW_ACCESS_KEY";
|
|
978
|
-
const SK_ACCOUNT = "HW_SECRET_KEY";
|
|
979
|
-
const TOKEN_ACCOUNT = "HW_SECURITY_TOKEN";
|
|
980
|
-
/** IAM endpoint host. */
|
|
981
|
-
const IAM_HOST = "iam.myhuaweicloud.com";
|
|
982
2199
|
/** Route the browser half reads status from and saves credentials to. */
|
|
983
2200
|
const CREDENTIALS_PATH = "/api/aishell/credentials";
|
|
984
2201
|
/** Route the browser half clears credentials through (fetch routes have no DELETE). */
|
|
985
2202
|
const CLEAR_PATH = "/api/aishell/credentials/clear";
|
|
986
2203
|
/**
|
|
987
|
-
* Route the browser calls
|
|
2204
|
+
* Route the browser calls when the person cancels the credential form.
|
|
988
2205
|
*
|
|
989
|
-
* Separate from `clear`:
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
* say "not now" without wiping anything.
|
|
2206
|
+
* Separate from `clear`: cancelling says "not now" without touching the store.
|
|
2207
|
+
* What it does record is the cancel itself, so the next `auth` call can tell an
|
|
2208
|
+
* unanswered request from a refused one and stop asking.
|
|
993
2209
|
*/
|
|
994
|
-
const
|
|
2210
|
+
const CANCEL_PATH = "/api/aishell/credentials/cancel";
|
|
995
2211
|
/** Largest credential body accepted; a real payload is well under 1 KiB. */
|
|
996
2212
|
const MAX_BODY_BYTES = 8 * 1024;
|
|
997
2213
|
/**
|
|
998
2214
|
* Verify credentials against Huawei Cloud IAM and return the account name.
|
|
999
2215
|
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
2216
|
+
* Delegates to the shared `verify` module, so the form, the ops `auth` tool
|
|
2217
|
+
* and anything else that asks "are these credentials valid?" get the same
|
|
2218
|
+
* answer from the same endpoint (profile: `GET /v3/projects`, with the account
|
|
2219
|
+
* name read best-effort from `/v3/auth/domains`).
|
|
2220
|
+
*
|
|
2221
|
+
* ## Why not a local domains-only call
|
|
1005
2222
|
*
|
|
1006
|
-
*
|
|
2223
|
+
* This used to call `/v3/auth/domains` directly, because the only fact this
|
|
2224
|
+
* route needed was the account name shown in the composer chip. That made it a
|
|
2225
|
+
* second, narrower notion of validity: `/v3/projects` rejects a credential with
|
|
2226
|
+
* no visible project, while `/v3/auth/domains` accepts it — so the form said
|
|
2227
|
+
* "saved" for credentials the tools would then refuse. One verifier removes
|
|
2228
|
+
* that gap, and the project list it returns is exactly what a caller needs
|
|
2229
|
+
* before planning a deployment.
|
|
2230
|
+
*
|
|
2231
|
+
* ## The region
|
|
2232
|
+
*
|
|
2233
|
+
* IAM is global: the region only routes to a regional replica and does not
|
|
2234
|
+
* scope the result. The chip's copy is fixed at `cn-north-4` for routing
|
|
2235
|
+
* purposes rather than configured, because verification must succeed even
|
|
2236
|
+
* before a person has chosen a region — and because a wrong region here would
|
|
2237
|
+
* report "invalid credentials" for what is really a typo'd region setting
|
|
2238
|
+
* elsewhere.
|
|
2239
|
+
*
|
|
2240
|
+
* @returns the account name (domain name), falling back to the account id.
|
|
1007
2241
|
* @throws Error with a user-readable message when verification fails.
|
|
1008
2242
|
*/
|
|
1009
|
-
async function verifyCredentials(ak, sk, securityToken) {
|
|
1010
|
-
const
|
|
1011
|
-
const signed = sign("GET", IAM_HOST, path, {}, "", {
|
|
2243
|
+
async function verifyCredentials$1(ak, sk, securityToken) {
|
|
2244
|
+
const result = await verifyCredentials({
|
|
1012
2245
|
ak,
|
|
1013
2246
|
sk,
|
|
1014
|
-
...securityToken ? {
|
|
1015
|
-
});
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
if (resp.status === 403) throw new Error("Credential verification failed: this credential cannot read IAM (403).");
|
|
1019
|
-
if (!resp.ok) throw new Error(`Credential verification failed: Huawei Cloud returned ${resp.status}.`);
|
|
1020
|
-
const body = await resp.json();
|
|
1021
|
-
const name$1 = body.domains?.[0]?.name;
|
|
1022
|
-
if (!name$1) throw new Error("Credential verified, but Huawei Cloud returned no account name.");
|
|
1023
|
-
return name$1;
|
|
2247
|
+
...securityToken === void 0 ? {} : { securityToken }
|
|
2248
|
+
}, { region: VERIFY_REGION });
|
|
2249
|
+
if (!result.ok) throw new Error(result.message);
|
|
2250
|
+
return result.account.name;
|
|
1024
2251
|
}
|
|
2252
|
+
/**
|
|
2253
|
+
* Region used to route the verification call.
|
|
2254
|
+
*
|
|
2255
|
+
* Not a setting: see {@link verifyCredentials}. Any region replica answers the
|
|
2256
|
+
* same question.
|
|
2257
|
+
*/
|
|
2258
|
+
const VERIFY_REGION = "cn-north-4";
|
|
1025
2259
|
/** One JSON error response the browser half renders verbatim. */
|
|
1026
2260
|
function jsonError(status, message) {
|
|
1027
2261
|
return Response.json({
|
|
@@ -1058,7 +2292,7 @@ function createCredentialRoutes(deps) {
|
|
|
1058
2292
|
const { store, verify, recordStatus, hint, notifyChanged } = deps;
|
|
1059
2293
|
return {
|
|
1060
2294
|
get: () => Promise.resolve(Response.json({
|
|
1061
|
-
configured:
|
|
2295
|
+
configured: hasStoredPair(store),
|
|
1062
2296
|
accountName: hint()
|
|
1063
2297
|
}, { headers: { "cache-control": "no-store" } })),
|
|
1064
2298
|
save: async (request) => {
|
|
@@ -1088,12 +2322,11 @@ function createCredentialRoutes(deps) {
|
|
|
1088
2322
|
}, { status: 422 });
|
|
1089
2323
|
}
|
|
1090
2324
|
try {
|
|
1091
|
-
store
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if (token) store.set(TOKEN_ACCOUNT, token);
|
|
2325
|
+
writeHuaweiCloud(store, {
|
|
2326
|
+
ak,
|
|
2327
|
+
sk,
|
|
2328
|
+
...token === void 0 ? {} : { securityToken: token }
|
|
2329
|
+
});
|
|
1097
2330
|
} catch (error) {
|
|
1098
2331
|
const message = `Credential verified, but storing it failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1099
2332
|
recordStatus([{
|
|
@@ -1126,9 +2359,7 @@ function createCredentialRoutes(deps) {
|
|
|
1126
2359
|
});
|
|
1127
2360
|
},
|
|
1128
2361
|
clear: () => {
|
|
1129
|
-
store
|
|
1130
|
-
store.delete(SK_ACCOUNT);
|
|
1131
|
-
store.delete(TOKEN_ACCOUNT);
|
|
2362
|
+
clearCredentials(store);
|
|
1132
2363
|
recordStatus([
|
|
1133
2364
|
{
|
|
1134
2365
|
op: "set",
|
|
@@ -1156,6 +2387,14 @@ function apply(ctx, config) {
|
|
|
1156
2387
|
const ns = ctx.fiber.entry?.options.id;
|
|
1157
2388
|
let recordedStored = config.credentialsStored.get() === true;
|
|
1158
2389
|
let recordedHint = config.accessKeyIdHint.get() || null;
|
|
2390
|
+
/**
|
|
2391
|
+
* The form request a tool call is currently blocked on.
|
|
2392
|
+
*
|
|
2393
|
+
* Held here rather than read from the document: the answer arrives over the
|
|
2394
|
+
* credential and cancel routes, and those need the same object the tool is
|
|
2395
|
+
* awaiting.
|
|
2396
|
+
*/
|
|
2397
|
+
let pendingForm;
|
|
1159
2398
|
/** Apply one batch of ops to the mirror. */
|
|
1160
2399
|
const mirrorOps = (ops) => {
|
|
1161
2400
|
for (const op of ops) if (op.path[0] === "credentialsStored") recordedStored = op.op === "set" && op.value === true;
|
|
@@ -1186,7 +2425,7 @@ function apply(ctx, config) {
|
|
|
1186
2425
|
};
|
|
1187
2426
|
const routes = createCredentialRoutes({
|
|
1188
2427
|
store,
|
|
1189
|
-
verify: verifyCredentials,
|
|
2428
|
+
verify: verifyCredentials$1,
|
|
1190
2429
|
recordStatus,
|
|
1191
2430
|
hint: () => recordedHint ?? "",
|
|
1192
2431
|
notifyChanged: () => {
|
|
@@ -1194,83 +2433,187 @@ function apply(ctx, config) {
|
|
|
1194
2433
|
}
|
|
1195
2434
|
});
|
|
1196
2435
|
const reconciler = createCredentialReconciler({
|
|
1197
|
-
|
|
1198
|
-
verify: verifyCredentials,
|
|
2436
|
+
verify: verifyCredentials$1,
|
|
1199
2437
|
recordStatus,
|
|
1200
2438
|
readStored: () => recordedStored,
|
|
1201
2439
|
readHint: () => recordedHint,
|
|
1202
|
-
|
|
1203
|
-
accessKey: AK_ACCOUNT,
|
|
1204
|
-
secretKey: SK_ACCOUNT,
|
|
1205
|
-
securityToken: TOKEN_ACCOUNT
|
|
1206
|
-
}
|
|
2440
|
+
readPair: () => readStoredPair(store)
|
|
1207
2441
|
});
|
|
1208
|
-
let settlePrompt;
|
|
1209
|
-
/**
|
|
1210
|
-
* End the open form, if any: clear the flag the browser renders from and
|
|
1211
|
-
* hand the credential back to the waiting call.
|
|
1212
|
-
*/
|
|
1213
|
-
const settleCredentialForm = (credentials) => {
|
|
1214
|
-
const settle = settlePrompt;
|
|
1215
|
-
settlePrompt = void 0;
|
|
1216
|
-
recordStatus([{
|
|
1217
|
-
op: "set",
|
|
1218
|
-
path: ["credentialRequestSession"],
|
|
1219
|
-
value: ""
|
|
1220
|
-
}]);
|
|
1221
|
-
settle?.(credentials);
|
|
1222
|
-
};
|
|
1223
|
-
ctx.effect(() => ctx.on("aishell/credential-request", (request) => {
|
|
1224
|
-
settlePrompt?.(void 0);
|
|
1225
|
-
settlePrompt = request.settle;
|
|
1226
|
-
recordStatus([{
|
|
1227
|
-
op: "set",
|
|
1228
|
-
path: ["credentialRequestSession"],
|
|
1229
|
-
value: request.sessionId ?? ""
|
|
1230
|
-
}]);
|
|
1231
|
-
request.signal?.addEventListener("abort", () => {
|
|
1232
|
-
if (settlePrompt === request.settle) settleCredentialForm(void 0);
|
|
1233
|
-
}, { once: true });
|
|
1234
|
-
}), "aishell-credentials: credential form requests");
|
|
1235
|
-
ctx.effect(() => ctx.on("aishell/credentials-updated", () => {
|
|
1236
|
-
if (settlePrompt === void 0) return;
|
|
1237
|
-
const ak = store.get(AK_ACCOUNT);
|
|
1238
|
-
const sk = store.get(SK_ACCOUNT);
|
|
1239
|
-
if (!ak || !sk) return;
|
|
1240
|
-
const securityToken = store.get(TOKEN_ACCOUNT);
|
|
1241
|
-
settleCredentialForm({
|
|
1242
|
-
ak,
|
|
1243
|
-
sk,
|
|
1244
|
-
...securityToken === void 0 ? {} : { securityToken }
|
|
1245
|
-
});
|
|
1246
|
-
}), "aishell-credentials: resume the waiting call");
|
|
1247
2442
|
ctx.effect(() => ctx.connection.fetch.register({
|
|
1248
2443
|
path: CREDENTIALS_PATH,
|
|
1249
2444
|
methods: ["GET", "POST"],
|
|
1250
2445
|
requestBody: "buffered",
|
|
1251
|
-
fetch: (request) =>
|
|
2446
|
+
fetch: async (request) => {
|
|
2447
|
+
if (request.method === "GET") return reconciler.reconcile(), routes.get();
|
|
2448
|
+
const body = await request.text();
|
|
2449
|
+
const requestToken = readRequestToken(body);
|
|
2450
|
+
const response = await routes.save(new Request(request.url, {
|
|
2451
|
+
method: "POST",
|
|
2452
|
+
headers: request.headers,
|
|
2453
|
+
body
|
|
2454
|
+
}));
|
|
2455
|
+
if (response.ok && requestToken !== void 0 && pendingForm !== void 0 && pendingForm.request.token === requestToken) {
|
|
2456
|
+
const pending = pendingForm;
|
|
2457
|
+
pendingForm = void 0;
|
|
2458
|
+
pending.settle({ kind: "submitted" });
|
|
2459
|
+
}
|
|
2460
|
+
return response;
|
|
2461
|
+
}
|
|
1252
2462
|
}), "aishell-credentials: credentials route");
|
|
1253
2463
|
ctx.effect(() => ctx.connection.fetch.register({
|
|
1254
|
-
path:
|
|
2464
|
+
path: CANCEL_PATH,
|
|
1255
2465
|
methods: ["POST"],
|
|
1256
2466
|
requestBody: "buffered",
|
|
1257
|
-
fetch: () => {
|
|
1258
|
-
|
|
1259
|
-
|
|
2467
|
+
fetch: async (request) => {
|
|
2468
|
+
let body;
|
|
2469
|
+
try {
|
|
2470
|
+
body = await request.json();
|
|
2471
|
+
} catch {
|
|
2472
|
+
return Response.json({
|
|
2473
|
+
ok: false,
|
|
2474
|
+
error: "Request body is not valid JSON."
|
|
2475
|
+
}, { status: 400 });
|
|
2476
|
+
}
|
|
2477
|
+
const token = body?.token;
|
|
2478
|
+
if (typeof token !== "string" || token === "") return Response.json({
|
|
2479
|
+
ok: false,
|
|
2480
|
+
error: "token is required."
|
|
2481
|
+
}, { status: 400 });
|
|
2482
|
+
if (pendingForm !== void 0 && pendingForm.request.token === token) {
|
|
2483
|
+
const pending = pendingForm;
|
|
2484
|
+
pendingForm = void 0;
|
|
2485
|
+
pending.settle({ kind: "cancelled" });
|
|
2486
|
+
}
|
|
2487
|
+
return Response.json({ ok: true });
|
|
1260
2488
|
}
|
|
1261
|
-
}), "aishell-credentials:
|
|
2489
|
+
}), "aishell-credentials: cancel route");
|
|
2490
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
2491
|
+
path: PREFILL_PATH,
|
|
2492
|
+
methods: ["GET"],
|
|
2493
|
+
requestBody: "buffered",
|
|
2494
|
+
fetch: () => Promise.resolve(Response.json(readEnvPrefill(runtimeEnv()) ?? {}, { headers: { "cache-control": "no-store" } }))
|
|
2495
|
+
}), "aishell-credentials: prefill route");
|
|
2496
|
+
/**
|
|
2497
|
+
* Announces that the stored credentials changed, so consumers that cached
|
|
2498
|
+
* something derived from them drop it.
|
|
2499
|
+
*
|
|
2500
|
+
* Declared before the flow because `recordOutcome` is where a successful
|
|
2501
|
+
* login is known, and that is the point at which the store has just changed.
|
|
2502
|
+
*/
|
|
2503
|
+
const announceCredentialsChanged = () => {
|
|
2504
|
+
ctx.emit("aishell/credentials-updated");
|
|
2505
|
+
};
|
|
2506
|
+
const loginFlow = createLoginFlow({
|
|
2507
|
+
verify: async (credential) => {
|
|
2508
|
+
return await verifyCredentials$1(credential.accessKeyId, credential.secretAccessKey, credential.securityToken);
|
|
2509
|
+
},
|
|
2510
|
+
store: (credential) => {
|
|
2511
|
+
writeHuaweiCloud(store, {
|
|
2512
|
+
ak: credential.accessKeyId,
|
|
2513
|
+
sk: credential.secretAccessKey,
|
|
2514
|
+
...credential.securityToken === void 0 ? {} : { securityToken: credential.securityToken }
|
|
2515
|
+
});
|
|
2516
|
+
return Promise.resolve();
|
|
2517
|
+
},
|
|
2518
|
+
recordError: (error) => {
|
|
2519
|
+
recordStatus([{
|
|
2520
|
+
op: "set",
|
|
2521
|
+
path: ["lastError"],
|
|
2522
|
+
value: error
|
|
2523
|
+
}]);
|
|
2524
|
+
},
|
|
2525
|
+
recordOutcome: (outcome) => {
|
|
2526
|
+
recordStatus([{
|
|
2527
|
+
op: "set",
|
|
2528
|
+
path: [LOGIN_OUTCOME_FIELD],
|
|
2529
|
+
value: encodeOutcome(outcome)
|
|
2530
|
+
}]);
|
|
2531
|
+
if (outcome?.kind !== "succeeded") return;
|
|
2532
|
+
recordStatus([
|
|
2533
|
+
{
|
|
2534
|
+
op: "set",
|
|
2535
|
+
path: ["credentialsStored"],
|
|
2536
|
+
value: true
|
|
2537
|
+
},
|
|
2538
|
+
{
|
|
2539
|
+
op: "set",
|
|
2540
|
+
path: ["accessKeyIdHint"],
|
|
2541
|
+
value: outcome.accountName
|
|
2542
|
+
},
|
|
2543
|
+
{
|
|
2544
|
+
op: "unset",
|
|
2545
|
+
path: ["lastError"]
|
|
2546
|
+
}
|
|
2547
|
+
]);
|
|
2548
|
+
announceCredentialsChanged();
|
|
2549
|
+
const pending = pendingForm;
|
|
2550
|
+
if (pending !== void 0) {
|
|
2551
|
+
pendingForm = void 0;
|
|
2552
|
+
pending.settle({ kind: "submitted" });
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
const loginRoutes = createLoginRoutes({
|
|
2557
|
+
findProvider: loginFlow.findProvider,
|
|
2558
|
+
begin: loginFlow.begin,
|
|
2559
|
+
cancel: loginFlow.cancel,
|
|
2560
|
+
inProgress: loginFlow.inProgress
|
|
2561
|
+
});
|
|
2562
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
2563
|
+
path: LOGIN_START_PATH,
|
|
2564
|
+
methods: ["POST"],
|
|
2565
|
+
requestBody: "buffered",
|
|
2566
|
+
fetch: loginRoutes.start
|
|
2567
|
+
}), "aishell-credentials: browser login start route");
|
|
2568
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
2569
|
+
path: LOGIN_CANCEL_PATH,
|
|
2570
|
+
methods: ["POST"],
|
|
2571
|
+
requestBody: "buffered",
|
|
2572
|
+
fetch: loginRoutes.cancel
|
|
2573
|
+
}), "aishell-credentials: browser login cancel route");
|
|
2574
|
+
ctx.effect(() => () => {
|
|
2575
|
+
loginFlow.cancel();
|
|
2576
|
+
}, "aishell-credentials: browser login teardown");
|
|
1262
2577
|
ctx.effect(() => ctx.connection.fetch.register({
|
|
1263
|
-
path:
|
|
2578
|
+
path: CLEAR_PATH,
|
|
1264
2579
|
methods: ["POST"],
|
|
1265
2580
|
requestBody: "buffered",
|
|
1266
2581
|
fetch: () => {
|
|
1267
|
-
|
|
1268
|
-
return
|
|
2582
|
+
reconciler.resetVerifyBaseline();
|
|
2583
|
+
return routes.clear();
|
|
1269
2584
|
}
|
|
1270
|
-
}), "aishell-credentials:
|
|
2585
|
+
}), "aishell-credentials: clear route");
|
|
1271
2586
|
reconciler.reconcile();
|
|
1272
2587
|
const reconcileTimer = setInterval(reconciler.reconcile, 3e4);
|
|
1273
2588
|
ctx.effect(() => () => clearInterval(reconcileTimer), "aishell-credentials: status reconcile timer");
|
|
2589
|
+
registerAuthTool(ctx, store, {
|
|
2590
|
+
requestForm: (sessionId) => {
|
|
2591
|
+
if (ns === void 0) return void 0;
|
|
2592
|
+
if (pendingForm !== void 0) return pendingForm.outcome;
|
|
2593
|
+
const pending = formRequest(sessionId);
|
|
2594
|
+
pendingForm = pending;
|
|
2595
|
+
ctx.settings.mutate(ns, [{
|
|
2596
|
+
op: "set",
|
|
2597
|
+
path: [FORM_REQUEST_FIELD],
|
|
2598
|
+
value: pending.encoded
|
|
2599
|
+
}]).catch((error) => {
|
|
2600
|
+
ctx.logger.warn(error);
|
|
2601
|
+
if (pendingForm === pending) {
|
|
2602
|
+
pendingForm = void 0;
|
|
2603
|
+
pending.settle({ kind: "cancelled" });
|
|
2604
|
+
}
|
|
2605
|
+
});
|
|
2606
|
+
return pending.outcome;
|
|
2607
|
+
},
|
|
2608
|
+
releaseForm: () => {
|
|
2609
|
+
const pending = pendingForm;
|
|
2610
|
+
if (pending !== void 0) {
|
|
2611
|
+
pendingForm = void 0;
|
|
2612
|
+
pending.settle({ kind: "cancelled" });
|
|
2613
|
+
}
|
|
2614
|
+
loginFlow.cancel();
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
1274
2617
|
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber));
|
|
1275
2618
|
}
|
|
1276
2619
|
|