@axiom-lattice/client-sdk 4.3.1 → 4.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/runtime-client.test.d.ts +10 -0
- package/dist/__tests__/runtime-client.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-client.test.js +113 -0
- package/dist/__tests__/runtime-client.test.js.map +1 -0
- package/dist/index.d.ts +66 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -0
- package/dist/index.mjs.map +1 -1
- package/dist/runtime-client.d.ts +67 -0
- package/dist/runtime-client.d.ts.map +1 -0
- package/dist/runtime-client.js +122 -0
- package/dist/runtime-client.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4163,6 +4163,115 @@ var _Client = class extends AbstractClient {
|
|
|
4163
4163
|
var Client = _Client;
|
|
4164
4164
|
Client.globalWorkspaceHeaders = {};
|
|
4165
4165
|
|
|
4166
|
+
// src/runtime-client.ts
|
|
4167
|
+
var RuntimeAxiomClient = class extends Client {
|
|
4168
|
+
constructor(config) {
|
|
4169
|
+
super({
|
|
4170
|
+
...config,
|
|
4171
|
+
baseURL: `${config.gatewayUrl.replace(/\/$/, "")}/api/web-apps/${config.webAppId}/runtime`,
|
|
4172
|
+
apiKey: "runtime-bearer"
|
|
4173
|
+
});
|
|
4174
|
+
this.token = null;
|
|
4175
|
+
this.tokenPromise = null;
|
|
4176
|
+
this.gatewayUrl = config.gatewayUrl.replace(/\/$/, "");
|
|
4177
|
+
this.webAppId = config.webAppId;
|
|
4178
|
+
this.identity = config.identity;
|
|
4179
|
+
if (config.identity.mode === "unverified" && config.identity.userId.length === 0) {
|
|
4180
|
+
throw new Error("RuntimeAxiomClient requires a non-empty userId in unverified mode");
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
/**
|
|
4184
|
+
* Resolve (and cache) the current identity credential.
|
|
4185
|
+
*
|
|
4186
|
+
* - `verified`: resolves the bearer token from the provider (single-flight;
|
|
4187
|
+
* call again later to force a refresh, or pass through a fresh provider).
|
|
4188
|
+
* - `unverified`: no credential is needed; returns `""`.
|
|
4189
|
+
*
|
|
4190
|
+
* Transport methods resolve this lazily, so the chat stack needs no explicit
|
|
4191
|
+
* priming — the first request triggers the token provider.
|
|
4192
|
+
*/
|
|
4193
|
+
async primeToken() {
|
|
4194
|
+
if (this.identity.mode !== "verified")
|
|
4195
|
+
return "";
|
|
4196
|
+
if (!this.tokenPromise) {
|
|
4197
|
+
this.tokenPromise = this.identity.tokenProvider().then((token) => {
|
|
4198
|
+
this.token = token;
|
|
4199
|
+
return token;
|
|
4200
|
+
});
|
|
4201
|
+
}
|
|
4202
|
+
return this.tokenPromise;
|
|
4203
|
+
}
|
|
4204
|
+
identityHeaders() {
|
|
4205
|
+
if (this.identity.mode === "verified") {
|
|
4206
|
+
return { Authorization: `Bearer ${this.token ?? ""}` };
|
|
4207
|
+
}
|
|
4208
|
+
return { "X-Axiom-External-User-Id": this.identity.userId };
|
|
4209
|
+
}
|
|
4210
|
+
getAllHeaders() {
|
|
4211
|
+
const workspace = this.getWorkspaceHeaders();
|
|
4212
|
+
return {
|
|
4213
|
+
...this.identityHeaders(),
|
|
4214
|
+
...workspace
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
async makeRequest(url, options) {
|
|
4218
|
+
await this.primeToken();
|
|
4219
|
+
const method = options?.method ?? "GET";
|
|
4220
|
+
const headers = {
|
|
4221
|
+
"Content-Type": "application/json",
|
|
4222
|
+
...this.identityHeaders(),
|
|
4223
|
+
...options?.headers ?? {}
|
|
4224
|
+
};
|
|
4225
|
+
const requestOptions = { method, headers };
|
|
4226
|
+
if (options?.body !== void 0) {
|
|
4227
|
+
if (options.body instanceof FormData) {
|
|
4228
|
+
requestOptions.body = options.body;
|
|
4229
|
+
delete headers["Content-Type"];
|
|
4230
|
+
} else {
|
|
4231
|
+
requestOptions.body = JSON.stringify(options.body);
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
const response = await fetch(`${this.getBaseUrl()}${url}`, requestOptions);
|
|
4235
|
+
if (!response.ok) {
|
|
4236
|
+
let message = `HTTP ${response.status}`;
|
|
4237
|
+
try {
|
|
4238
|
+
const body = await response.json();
|
|
4239
|
+
message = body.error ?? body.message ?? message;
|
|
4240
|
+
} catch {
|
|
4241
|
+
}
|
|
4242
|
+
const error = new Error(message);
|
|
4243
|
+
error.status = response.status;
|
|
4244
|
+
throw error;
|
|
4245
|
+
}
|
|
4246
|
+
if (response.status === 204)
|
|
4247
|
+
return void 0;
|
|
4248
|
+
return await response.json();
|
|
4249
|
+
}
|
|
4250
|
+
getBaseUrl() {
|
|
4251
|
+
return this.config.baseURL;
|
|
4252
|
+
}
|
|
4253
|
+
/**
|
|
4254
|
+
* Clone into a real sibling instance sharing the runtime identity so the
|
|
4255
|
+
* `AxiomLatticeProvider` per-assistant `clone({ assistantId })` cache keeps
|
|
4256
|
+
* working (each clone carries its own resolved credential cache).
|
|
4257
|
+
*/
|
|
4258
|
+
createInstance(config) {
|
|
4259
|
+
return new RuntimeAxiomClient({
|
|
4260
|
+
gatewayUrl: this.gatewayUrl,
|
|
4261
|
+
webAppId: this.webAppId,
|
|
4262
|
+
identity: this.identity,
|
|
4263
|
+
assistantId: config.assistantId,
|
|
4264
|
+
transport: config.transport,
|
|
4265
|
+
...config.timeout !== void 0 ? { timeout: config.timeout } : {},
|
|
4266
|
+
...config.headers !== void 0 ? { headers: config.headers } : {},
|
|
4267
|
+
...config.retry !== void 0 ? { retry: config.retry } : {}
|
|
4268
|
+
});
|
|
4269
|
+
}
|
|
4270
|
+
streamRequest(_options, _onEvent, _onComplete, _onError) {
|
|
4271
|
+
throw new Error("RuntimeAxiomClient uses resumeStream; chat.stream is unsupported");
|
|
4272
|
+
}
|
|
4273
|
+
};
|
|
4274
|
+
|
|
4166
4275
|
// src/wechat-client.ts
|
|
4167
4276
|
var import_encoding = __toESM(require_encoding());
|
|
4168
4277
|
var WeChatClient = class extends AbstractClient {
|
|
@@ -4907,6 +5016,7 @@ export {
|
|
|
4907
5016
|
ProjectRoomClientError,
|
|
4908
5017
|
ProjectRoomsClient,
|
|
4909
5018
|
ResourcesClient,
|
|
5019
|
+
RuntimeAxiomClient,
|
|
4910
5020
|
ScheduleExecutionType,
|
|
4911
5021
|
ScheduledTaskStatus,
|
|
4912
5022
|
WeChatClient,
|