@runtypelabs/sdk 10.4.0 → 10.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +215 -1
- package/dist/index.d.cts +1783 -608
- package/dist/index.d.ts +1783 -608
- package/dist/index.mjs +212 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,10 @@ __export(index_exports, {
|
|
|
43
43
|
ClientBatchBuilder: () => ClientBatchBuilder,
|
|
44
44
|
ClientEvalBuilder: () => ClientEvalBuilder,
|
|
45
45
|
ClientFlowBuilder: () => ClientFlowBuilder,
|
|
46
|
+
ClientTokenDriftError: () => ClientTokenDriftError,
|
|
47
|
+
ClientTokenEnsureError: () => ClientTokenEnsureError,
|
|
46
48
|
ClientTokensEndpoint: () => ClientTokensEndpoint,
|
|
49
|
+
ClientTokensNamespace: () => ClientTokensNamespace,
|
|
47
50
|
CollectionsEndpoint: () => CollectionsEndpoint,
|
|
48
51
|
ContextTemplatesEndpoint: () => ContextTemplatesEndpoint,
|
|
49
52
|
ConversationsEndpoint: () => ConversationsEndpoint,
|
|
@@ -13415,6 +13418,196 @@ var SurfacesNamespace = class {
|
|
|
13415
13418
|
}
|
|
13416
13419
|
};
|
|
13417
13420
|
|
|
13421
|
+
// src/client-tokens-namespace.ts
|
|
13422
|
+
var ClientTokenEnsureError = class extends Error {
|
|
13423
|
+
constructor(message) {
|
|
13424
|
+
super(message);
|
|
13425
|
+
this.name = "ClientTokenEnsureError";
|
|
13426
|
+
}
|
|
13427
|
+
};
|
|
13428
|
+
var ClientTokenDriftError = class extends Error {
|
|
13429
|
+
constructor(name, plan) {
|
|
13430
|
+
super(
|
|
13431
|
+
`Client token "${name}" drifted: plan is '${plan.changes}' (changed: ${plan.changedKeys.join(", ") || "n/a"}). Re-run ensure to converge.`
|
|
13432
|
+
);
|
|
13433
|
+
this.name = "ClientTokenDriftError";
|
|
13434
|
+
this.plan = plan;
|
|
13435
|
+
}
|
|
13436
|
+
};
|
|
13437
|
+
function canonicalJson(value) {
|
|
13438
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
13439
|
+
if (value !== null && typeof value === "object") {
|
|
13440
|
+
const entries = Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
13441
|
+
return `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(",")}}`;
|
|
13442
|
+
}
|
|
13443
|
+
return JSON.stringify(value ?? null);
|
|
13444
|
+
}
|
|
13445
|
+
var sameSet = (a, b) => canonicalJson([...a].sort()) === canonicalJson([...b].sort());
|
|
13446
|
+
function planUpdate(definition, existing) {
|
|
13447
|
+
const environment = definition.environment ?? "live";
|
|
13448
|
+
if (environment !== existing.environment) {
|
|
13449
|
+
throw new ClientTokenEnsureError(
|
|
13450
|
+
`Client token "${definition.name}" is a ${existing.environment} token; the definition asks for ${environment}. A token environment cannot change. Rename the definition or delete the existing token.`
|
|
13451
|
+
);
|
|
13452
|
+
}
|
|
13453
|
+
const productSurfaceId = definition.productSurfaceId ?? null;
|
|
13454
|
+
if (productSurfaceId !== (existing.productSurfaceId ?? null)) {
|
|
13455
|
+
throw new ClientTokenEnsureError(
|
|
13456
|
+
`Client token "${definition.name}" belongs to surface ${existing.productSurfaceId ?? "(none)"}; the definition names ${productSurfaceId ?? "(none)"}. A token's surface cannot change.`
|
|
13457
|
+
);
|
|
13458
|
+
}
|
|
13459
|
+
const flowIds = definition.flowIds ?? [];
|
|
13460
|
+
if (flowIds.length === 0 && existing.flowIds.length > 0) {
|
|
13461
|
+
throw new ClientTokenEnsureError(
|
|
13462
|
+
`Client token "${definition.name}" carries flows (${existing.flowIds.join(", ")}); the API cannot remove every flow from a token. Delete the token and re-run ensure.`
|
|
13463
|
+
);
|
|
13464
|
+
}
|
|
13465
|
+
const patch = {};
|
|
13466
|
+
const agentIds = definition.agentIds ?? [];
|
|
13467
|
+
if (!sameSet(agentIds, existing.agentIds)) patch.agentIds = agentIds;
|
|
13468
|
+
if (flowIds.length > 0 && !sameSet(flowIds, existing.flowIds)) patch.flowIds = flowIds;
|
|
13469
|
+
if (definition.defaultFlowId !== void 0 && definition.defaultFlowId !== existing.defaultFlowId) {
|
|
13470
|
+
patch.defaultFlowId = definition.defaultFlowId;
|
|
13471
|
+
}
|
|
13472
|
+
if (!sameSet(definition.allowedOrigins, existing.allowedOrigins)) {
|
|
13473
|
+
patch.allowedOrigins = definition.allowedOrigins;
|
|
13474
|
+
}
|
|
13475
|
+
const targetAlias = definition.targetAlias ?? null;
|
|
13476
|
+
if (targetAlias !== (existing.targetAlias ?? null)) patch.targetAlias = targetAlias;
|
|
13477
|
+
const targetVersionId = definition.targetVersionId ?? null;
|
|
13478
|
+
if (targetVersionId !== (existing.targetVersionId ?? null)) {
|
|
13479
|
+
patch.targetVersionId = targetVersionId;
|
|
13480
|
+
}
|
|
13481
|
+
const optionalKeys = [
|
|
13482
|
+
"rateLimitPerMinute",
|
|
13483
|
+
"rateLimitPerHour",
|
|
13484
|
+
"maxMessagesPerSession",
|
|
13485
|
+
"sessionIdleTimeoutMinutes"
|
|
13486
|
+
];
|
|
13487
|
+
for (const key of optionalKeys) {
|
|
13488
|
+
const desired = definition[key];
|
|
13489
|
+
if (desired !== void 0 && desired !== existing[key]) patch[key] = desired;
|
|
13490
|
+
}
|
|
13491
|
+
if (definition.config !== void 0 && canonicalJson(definition.config) !== canonicalJson(existing.config ?? {})) {
|
|
13492
|
+
patch.config = definition.config;
|
|
13493
|
+
}
|
|
13494
|
+
return patch;
|
|
13495
|
+
}
|
|
13496
|
+
var ClientTokensNamespace = class {
|
|
13497
|
+
constructor(getClient) {
|
|
13498
|
+
this.getClient = getClient;
|
|
13499
|
+
}
|
|
13500
|
+
async list() {
|
|
13501
|
+
const response = await this.getClient().get("/client-tokens");
|
|
13502
|
+
return response.clientTokens;
|
|
13503
|
+
}
|
|
13504
|
+
async get(id) {
|
|
13505
|
+
const response = await this.getClient().get(
|
|
13506
|
+
`/client-tokens/${id}`
|
|
13507
|
+
);
|
|
13508
|
+
return response.clientToken;
|
|
13509
|
+
}
|
|
13510
|
+
/** The response's `token` is the publishable value. */
|
|
13511
|
+
async create(data) {
|
|
13512
|
+
return this.getClient().post("/client-tokens", data);
|
|
13513
|
+
}
|
|
13514
|
+
async update(id, data) {
|
|
13515
|
+
return this.getClient().put(
|
|
13516
|
+
`/client-tokens/${id}`,
|
|
13517
|
+
data
|
|
13518
|
+
);
|
|
13519
|
+
}
|
|
13520
|
+
async delete(id) {
|
|
13521
|
+
await this.getClient().delete(`/client-tokens/${id}`);
|
|
13522
|
+
}
|
|
13523
|
+
/** Issue a new value; the previous value stops working immediately. */
|
|
13524
|
+
async regenerate(id) {
|
|
13525
|
+
return this.getClient().post(`/client-tokens/${id}/regenerate`);
|
|
13526
|
+
}
|
|
13527
|
+
/** Read a stored token value. Fails for a reveal-once live token. */
|
|
13528
|
+
async getToken(id) {
|
|
13529
|
+
return this.getClient().get(`/client-tokens/${id}/token`);
|
|
13530
|
+
}
|
|
13531
|
+
async listConversations(id, params) {
|
|
13532
|
+
return this.getClient().get(
|
|
13533
|
+
`/client-tokens/${id}/conversations`,
|
|
13534
|
+
params
|
|
13535
|
+
);
|
|
13536
|
+
}
|
|
13537
|
+
/**
|
|
13538
|
+
* Find the token named `definition.name`, create it when missing, and update
|
|
13539
|
+
* it when it differs. Never deletes or regenerates. Throws when two tokens
|
|
13540
|
+
* share the name, or when the environment or surface differs.
|
|
13541
|
+
*
|
|
13542
|
+
* @example
|
|
13543
|
+
* ```typescript
|
|
13544
|
+
* const agent = await Runtype.agents.ensure(docsAgent, { deploy: { alias: 'live' } })
|
|
13545
|
+
* const { token } = await Runtype.clientTokens.ensure({
|
|
13546
|
+
* name: 'Docs site widget',
|
|
13547
|
+
* agentIds: [agent.agentId],
|
|
13548
|
+
* allowedOrigins: ['https://docs.example.com'],
|
|
13549
|
+
* })
|
|
13550
|
+
* ```
|
|
13551
|
+
*/
|
|
13552
|
+
async ensure(definition, options = {}) {
|
|
13553
|
+
if (typeof definition?.name !== "string" || definition.name.length === 0) {
|
|
13554
|
+
throw new ClientTokenEnsureError('clientTokens.ensure requires a non-empty string "name"');
|
|
13555
|
+
}
|
|
13556
|
+
const dryRun = options.dryRun === true || options.expectNoChanges === true;
|
|
13557
|
+
const matches = (await this.list()).filter((token) => token.name === definition.name);
|
|
13558
|
+
if (matches.length > 1) {
|
|
13559
|
+
throw new ClientTokenEnsureError(
|
|
13560
|
+
`${matches.length} client tokens are named "${definition.name}" (${matches.map((t) => t.id).join(", ")}). Rename or delete all but one so ensure has a single identity to converge.`
|
|
13561
|
+
);
|
|
13562
|
+
}
|
|
13563
|
+
const existing = matches[0];
|
|
13564
|
+
if (!existing) {
|
|
13565
|
+
const plan = { result: "plan", changes: "create", changedKeys: [] };
|
|
13566
|
+
if (options.expectNoChanges) throw new ClientTokenDriftError(definition.name, plan);
|
|
13567
|
+
if (dryRun) return plan;
|
|
13568
|
+
const created = await this.create({ ...definition });
|
|
13569
|
+
return {
|
|
13570
|
+
result: "created",
|
|
13571
|
+
clientToken: created.clientToken,
|
|
13572
|
+
token: created.token,
|
|
13573
|
+
changedKeys: [],
|
|
13574
|
+
warnings: created.warnings ?? []
|
|
13575
|
+
};
|
|
13576
|
+
}
|
|
13577
|
+
const patch = planUpdate(definition, existing);
|
|
13578
|
+
const changedKeys = Object.keys(patch);
|
|
13579
|
+
if (dryRun) {
|
|
13580
|
+
const plan = {
|
|
13581
|
+
result: "plan",
|
|
13582
|
+
changes: changedKeys.length > 0 ? "update" : "none",
|
|
13583
|
+
changedKeys,
|
|
13584
|
+
clientToken: existing
|
|
13585
|
+
};
|
|
13586
|
+
if (options.expectNoChanges && plan.changes !== "none") {
|
|
13587
|
+
throw new ClientTokenDriftError(definition.name, plan);
|
|
13588
|
+
}
|
|
13589
|
+
return plan;
|
|
13590
|
+
}
|
|
13591
|
+
if (changedKeys.length === 0) {
|
|
13592
|
+
return {
|
|
13593
|
+
result: "unchanged",
|
|
13594
|
+
clientToken: existing,
|
|
13595
|
+
token: existing.tokenValue,
|
|
13596
|
+
changedKeys,
|
|
13597
|
+
warnings: []
|
|
13598
|
+
};
|
|
13599
|
+
}
|
|
13600
|
+
const updated = await this.update(existing.id, patch);
|
|
13601
|
+
return {
|
|
13602
|
+
result: "updated",
|
|
13603
|
+
clientToken: updated.clientToken,
|
|
13604
|
+
token: updated.clientToken.tokenValue,
|
|
13605
|
+
changedKeys,
|
|
13606
|
+
warnings: updated.warnings ?? []
|
|
13607
|
+
};
|
|
13608
|
+
}
|
|
13609
|
+
};
|
|
13610
|
+
|
|
13418
13611
|
// src/runtype.ts
|
|
13419
13612
|
var globalConfig = {};
|
|
13420
13613
|
var globalClient = null;
|
|
@@ -13961,6 +14154,24 @@ var Runtype = class {
|
|
|
13961
14154
|
static get surfaces() {
|
|
13962
14155
|
return new SurfacesNamespace(() => this.getClient());
|
|
13963
14156
|
}
|
|
14157
|
+
/**
|
|
14158
|
+
* Client tokens — publishable credentials for widgets. `ensure` finds a token
|
|
14159
|
+
* by name, creates it when missing, and converges its agents, flows, origins,
|
|
14160
|
+
* and target; it returns the token value when the token stores one.
|
|
14161
|
+
*
|
|
14162
|
+
* @example
|
|
14163
|
+
* ```typescript
|
|
14164
|
+
* const agent = await Runtype.agents.ensure(docsAgent, { deploy: { alias: 'live' } })
|
|
14165
|
+
* const { token } = await Runtype.clientTokens.ensure({
|
|
14166
|
+
* name: 'Docs site widget',
|
|
14167
|
+
* agentIds: [agent.agentId],
|
|
14168
|
+
* allowedOrigins: ['https://docs.example.com'],
|
|
14169
|
+
* })
|
|
14170
|
+
* ```
|
|
14171
|
+
*/
|
|
14172
|
+
static get clientTokens() {
|
|
14173
|
+
return new ClientTokensNamespace(() => this.getClient());
|
|
14174
|
+
}
|
|
13964
14175
|
};
|
|
13965
14176
|
|
|
13966
14177
|
// src/agent-promotion.ts
|
|
@@ -14154,7 +14365,7 @@ function transformQueryParams(params) {
|
|
|
14154
14365
|
|
|
14155
14366
|
// src/version.ts
|
|
14156
14367
|
var FALLBACK_VERSION = "0.0.0";
|
|
14157
|
-
var SDK_VERSION = "10.
|
|
14368
|
+
var SDK_VERSION = "10.5.0".length > 0 ? "10.5.0" : FALLBACK_VERSION;
|
|
14158
14369
|
var RUNTYPE_CLIENT_KIND = "sdk";
|
|
14159
14370
|
var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
|
|
14160
14371
|
|
|
@@ -15446,7 +15657,10 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
15446
15657
|
ClientBatchBuilder,
|
|
15447
15658
|
ClientEvalBuilder,
|
|
15448
15659
|
ClientFlowBuilder,
|
|
15660
|
+
ClientTokenDriftError,
|
|
15661
|
+
ClientTokenEnsureError,
|
|
15449
15662
|
ClientTokensEndpoint,
|
|
15663
|
+
ClientTokensNamespace,
|
|
15450
15664
|
CollectionsEndpoint,
|
|
15451
15665
|
ContextTemplatesEndpoint,
|
|
15452
15666
|
ConversationsEndpoint,
|