langwatch 2.2.0 → 2.3.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/agent/index.js +1 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +1 -1
- package/dist/agent/index.mjs.map +1 -1
- package/dist/{types-RkiBQZ9j.d.mts → braid-baggage-span-processor-CBNdRYKr.d.mts} +28 -1
- package/dist/{types-RkiBQZ9j.d.ts → braid-baggage-span-processor-CBNdRYKr.d.ts} +28 -1
- package/dist/{chunk-OAAGWSLX.mjs → chunk-5TNHAT3S.mjs} +101 -4
- package/dist/chunk-5TNHAT3S.mjs.map +1 -0
- package/dist/{chunk-TQJS5H5P.js → chunk-FQJHCT5Y.js} +111 -14
- package/dist/chunk-FQJHCT5Y.js.map +1 -0
- package/dist/{chunk-PDTYQM5C.js → chunk-HWKTHOMP.js} +58 -3
- package/dist/chunk-HWKTHOMP.js.map +1 -0
- package/dist/{chunk-P65KWWFU.mjs → chunk-IMUFSW7Z.mjs} +58 -3
- package/dist/chunk-IMUFSW7Z.mjs.map +1 -0
- package/dist/{chunk-XQ4CP2JK.mjs → chunk-MCWJ3AWF.mjs} +1 -1
- package/dist/{chunk-WDUUAIG3.js → chunk-PDYPOYVZ.js} +1 -1
- package/dist/{chunk-WDUUAIG3.js.map → chunk-PDYPOYVZ.js.map} +1 -1
- package/dist/cli/bundle.js +691 -421
- package/dist/{implementation-CaKFOMnp.d.ts → implementation-BparHh-q.d.ts} +1 -1
- package/dist/{implementation-CMJfitMa.d.mts → implementation-CrBgn1V6.d.mts} +1 -1
- package/dist/index.d.mts +47 -4
- package/dist/index.d.ts +47 -4
- package/dist/index.js +168 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -8
- package/dist/index.mjs.map +1 -1
- package/dist/observability-sdk/index.d.mts +27 -6
- package/dist/observability-sdk/index.d.ts +27 -6
- package/dist/observability-sdk/index.js +13 -3
- package/dist/observability-sdk/index.js.map +1 -1
- package/dist/observability-sdk/index.mjs +12 -2
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +1 -1
- package/dist/observability-sdk/setup/node/index.d.mts +39 -3
- package/dist/observability-sdk/setup/node/index.d.ts +39 -3
- package/dist/observability-sdk/setup/node/index.js +9 -3
- package/dist/observability-sdk/setup/node/index.js.map +1 -1
- package/dist/observability-sdk/setup/node/index.mjs +10 -4
- package/dist/{types-0leNdzy4.d.ts → types-BXcB5Uov.d.ts} +255 -12
- package/dist/{types-DNjiOkpS.d.mts → types-D_MsVA5r.d.mts} +255 -12
- package/package.json +1 -1
- package/dist/chunk-OAAGWSLX.mjs.map +0 -1
- package/dist/chunk-P65KWWFU.mjs.map +0 -1
- package/dist/chunk-PDTYQM5C.js.map +0 -1
- package/dist/chunk-TQJS5H5P.js.map +0 -1
- /package/dist/{chunk-XQ4CP2JK.mjs.map → chunk-MCWJ3AWF.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FilterableBatchSpanProcessor
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MCWJ3AWF.mjs";
|
|
4
4
|
import {
|
|
5
5
|
createLangWatchSpan,
|
|
6
6
|
external_exports,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
ensureSetup,
|
|
11
11
|
resolveEndpoint
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-5TNHAT3S.mjs";
|
|
13
13
|
import {
|
|
14
14
|
API_VERSION_HEADER,
|
|
15
15
|
LANGWATCH_API_VERSION,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
LangWatchTraceExporter,
|
|
22
22
|
buildAuthHeaders,
|
|
23
23
|
getLangWatchLogger
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-IMUFSW7Z.mjs";
|
|
25
25
|
import "./chunk-C7IWJ2GJ.mjs";
|
|
26
26
|
import {
|
|
27
27
|
ConsoleLogger,
|
|
@@ -5985,9 +5985,10 @@ var DatasetApiError = class extends DatasetError {
|
|
|
5985
5985
|
}
|
|
5986
5986
|
};
|
|
5987
5987
|
var DatasetValidationError = class extends DatasetError {
|
|
5988
|
-
constructor(message) {
|
|
5988
|
+
constructor(message, code) {
|
|
5989
5989
|
super(message);
|
|
5990
5990
|
this.name = "DatasetValidationError";
|
|
5991
|
+
this.code = code;
|
|
5991
5992
|
}
|
|
5992
5993
|
};
|
|
5993
5994
|
var DatasetPlanLimitError = class extends DatasetError {
|
|
@@ -6087,6 +6088,36 @@ var tracer2 = getLangWatchTracer(
|
|
|
6087
6088
|
LANGWATCH_SDK_VERSION
|
|
6088
6089
|
);
|
|
6089
6090
|
|
|
6091
|
+
// src/client-sdk/services/datasets/upsert-keys.ts
|
|
6092
|
+
function stableJson(value) {
|
|
6093
|
+
return JSON.stringify(
|
|
6094
|
+
value,
|
|
6095
|
+
(_key, inner) => inner && typeof inner === "object" && !Array.isArray(inner) ? Object.fromEntries(Object.entries(inner).toSorted(([a], [b]) => a.localeCompare(b))) : inner
|
|
6096
|
+
);
|
|
6097
|
+
}
|
|
6098
|
+
function keyOf(value) {
|
|
6099
|
+
return stableJson(value);
|
|
6100
|
+
}
|
|
6101
|
+
function assertUpsertableKeys(entries, key) {
|
|
6102
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6103
|
+
for (const entry of entries) {
|
|
6104
|
+
const value = Object.hasOwn(entry, key) ? keyOf(entry[key]) : void 0;
|
|
6105
|
+
if (value === void 0) {
|
|
6106
|
+
throw new DatasetValidationError(
|
|
6107
|
+
`Every entry must hold a JSON value in the key column "${key}"`,
|
|
6108
|
+
"missing_upsert_key"
|
|
6109
|
+
);
|
|
6110
|
+
}
|
|
6111
|
+
if (seen.has(value)) {
|
|
6112
|
+
throw new DatasetValidationError(
|
|
6113
|
+
`Two entries share the key ${key} = ${value}`,
|
|
6114
|
+
"duplicate_upsert_key"
|
|
6115
|
+
);
|
|
6116
|
+
}
|
|
6117
|
+
seen.add(value);
|
|
6118
|
+
}
|
|
6119
|
+
}
|
|
6120
|
+
|
|
6090
6121
|
// src/client-sdk/services/datasets/dataset.service.ts
|
|
6091
6122
|
var API_COLUMN_TYPES = {
|
|
6092
6123
|
string: "string",
|
|
@@ -6115,6 +6146,10 @@ function toApiColumnTypes(columnTypes) {
|
|
|
6115
6146
|
return { name, type: parsed.data };
|
|
6116
6147
|
});
|
|
6117
6148
|
}
|
|
6149
|
+
var CREATE_BATCH_SIZE = 1e3;
|
|
6150
|
+
function sameEntry(a, b) {
|
|
6151
|
+
return stableJson(a) === stableJson(b);
|
|
6152
|
+
}
|
|
6118
6153
|
var DatasetService = class {
|
|
6119
6154
|
constructor(config) {
|
|
6120
6155
|
this.config = __spreadProps(__spreadValues({}, config), { endpoint: resolveEndpoint(config.endpoint) });
|
|
@@ -6333,10 +6368,10 @@ var DatasetService = class {
|
|
|
6333
6368
|
this.config.logger.debug(`Creating dataset: ${options.name}`);
|
|
6334
6369
|
const response = await this.asResponseEnvelope(
|
|
6335
6370
|
this.config.langwatchApiClient.POST("/api/v1/dataset", {
|
|
6336
|
-
body: {
|
|
6371
|
+
body: __spreadValues({
|
|
6337
6372
|
name: options.name,
|
|
6338
6373
|
columnTypes: toApiColumnTypes((_a = options.columnTypes) != null ? _a : [])
|
|
6339
|
-
}
|
|
6374
|
+
}, options.entries && options.entries.length > 0 ? { entries: options.entries } : {})
|
|
6340
6375
|
})
|
|
6341
6376
|
);
|
|
6342
6377
|
return this.unwrapResponse(response, `create dataset "${options.name}"`);
|
|
@@ -6411,6 +6446,54 @@ var DatasetService = class {
|
|
|
6411
6446
|
slugOrId
|
|
6412
6447
|
);
|
|
6413
6448
|
}
|
|
6449
|
+
/**
|
|
6450
|
+
* Updates the rows whose `key` column matches an entry, adds the entries whose key is new, and
|
|
6451
|
+
* leaves alone the rows an entry would not change. Columns an entry leaves out keep their
|
|
6452
|
+
* values. Refuses, before writing anything, a key that more than one existing row holds.
|
|
6453
|
+
*/
|
|
6454
|
+
async upsertRecords(slugOrId, entries, { key }) {
|
|
6455
|
+
var _a, _b;
|
|
6456
|
+
const result = { created: [], updated: [], unchanged: 0 };
|
|
6457
|
+
if (entries.length === 0) {
|
|
6458
|
+
await this.listRecords(slugOrId, { page: 1, limit: 1 });
|
|
6459
|
+
return result;
|
|
6460
|
+
}
|
|
6461
|
+
const existing = /* @__PURE__ */ new Map();
|
|
6462
|
+
for (const row of (await this.getDataset(slugOrId)).entries) {
|
|
6463
|
+
if (!(key in row.entry)) continue;
|
|
6464
|
+
const rowKey = keyOf(row.entry[key]);
|
|
6465
|
+
existing.set(rowKey, [...(_a = existing.get(rowKey)) != null ? _a : [], row]);
|
|
6466
|
+
}
|
|
6467
|
+
const duplicated = entries.filter((entry) => {
|
|
6468
|
+
var _a2, _b2;
|
|
6469
|
+
return ((_b2 = (_a2 = existing.get(keyOf(entry[key]))) == null ? void 0 : _a2.length) != null ? _b2 : 0) > 1;
|
|
6470
|
+
}).map((entry) => keyOf(entry[key]));
|
|
6471
|
+
if (duplicated.length > 0) {
|
|
6472
|
+
throw new DatasetValidationError(
|
|
6473
|
+
`More than one row holds ${key} = ${duplicated.join(", ")}. Delete the extra rows, then upsert again.`,
|
|
6474
|
+
"dataset_has_duplicate_key"
|
|
6475
|
+
);
|
|
6476
|
+
}
|
|
6477
|
+
const toCreate = [];
|
|
6478
|
+
for (const entry of entries) {
|
|
6479
|
+
const row = (_b = existing.get(keyOf(entry[key]))) == null ? void 0 : _b[0];
|
|
6480
|
+
if (!row) {
|
|
6481
|
+
toCreate.push(entry);
|
|
6482
|
+
continue;
|
|
6483
|
+
}
|
|
6484
|
+
const merged = __spreadValues(__spreadValues({}, row.entry), entry);
|
|
6485
|
+
if (sameEntry(merged, row.entry)) {
|
|
6486
|
+
result.unchanged++;
|
|
6487
|
+
continue;
|
|
6488
|
+
}
|
|
6489
|
+
result.updated.push(await this.updateRecord(slugOrId, row.id, merged));
|
|
6490
|
+
}
|
|
6491
|
+
for (let start = 0; start < toCreate.length; start += CREATE_BATCH_SIZE) {
|
|
6492
|
+
const batch = toCreate.slice(start, start + CREATE_BATCH_SIZE);
|
|
6493
|
+
result.created.push(...(await this.createRecords(slugOrId, batch)).data);
|
|
6494
|
+
}
|
|
6495
|
+
return result;
|
|
6496
|
+
}
|
|
6414
6497
|
/**
|
|
6415
6498
|
* Deletes records from a dataset by IDs.
|
|
6416
6499
|
*/
|
|
@@ -6686,6 +6769,22 @@ var DatasetsFacade = class {
|
|
|
6686
6769
|
this.updateRecord = (slugOrId, recordId, entry) => {
|
|
6687
6770
|
return __privateGet(this, _datasetService).updateRecord(slugOrId, recordId, entry);
|
|
6688
6771
|
};
|
|
6772
|
+
/**
|
|
6773
|
+
* Upserts rows matched on a key column: a known key updates in place (columns left out are
|
|
6774
|
+
* kept), a new key adds a row, and an unchanged row is not written, so a rerun writes nothing.
|
|
6775
|
+
* @param slugOrId - The slug or ID of the dataset
|
|
6776
|
+
* @param entries - The rows to upsert; each must hold the key column
|
|
6777
|
+
* @param options - The key column that identifies a row, such as "case_id"
|
|
6778
|
+
* @returns The created and updated records and the number of rows left unchanged
|
|
6779
|
+
*/
|
|
6780
|
+
this.upsertRecords = async (slugOrId, entries, options) => {
|
|
6781
|
+
const { key } = options;
|
|
6782
|
+
if (!key) {
|
|
6783
|
+
throw new DatasetValidationError("key must name the column that identifies a row");
|
|
6784
|
+
}
|
|
6785
|
+
assertUpsertableKeys(entries, key);
|
|
6786
|
+
return __privateGet(this, _datasetService).upsertRecords(slugOrId, entries, options);
|
|
6787
|
+
};
|
|
6689
6788
|
/**
|
|
6690
6789
|
* Deletes records from a dataset by IDs.
|
|
6691
6790
|
* @param slugOrId - The slug or ID of the dataset
|
|
@@ -8161,7 +8260,8 @@ var toRunStartRequest = ({
|
|
|
8161
8260
|
datasetVersion,
|
|
8162
8261
|
parameters,
|
|
8163
8262
|
rowIndices,
|
|
8164
|
-
concurrency
|
|
8263
|
+
concurrency,
|
|
8264
|
+
repeat
|
|
8165
8265
|
}) => {
|
|
8166
8266
|
const body = {};
|
|
8167
8267
|
if (data !== void 0) body.data = data;
|
|
@@ -8170,6 +8270,7 @@ var toRunStartRequest = ({
|
|
|
8170
8270
|
if (parameters !== void 0) body.parameters = parameters;
|
|
8171
8271
|
if (rowIndices !== void 0) body.row_indices = rowIndices;
|
|
8172
8272
|
if (concurrency !== void 0) body.concurrency = concurrency;
|
|
8273
|
+
if (repeat !== void 0) body.repeat = repeat;
|
|
8173
8274
|
return Object.keys(body).length > 0 ? body : void 0;
|
|
8174
8275
|
};
|
|
8175
8276
|
var ExperimentsApiServiceError = class extends Error {
|
|
@@ -8244,7 +8345,8 @@ var ExperimentsApiService = class {
|
|
|
8244
8345
|
const body = toRunStartRequest({
|
|
8245
8346
|
parameters: options.parameters,
|
|
8246
8347
|
concurrency: options.concurrency,
|
|
8247
|
-
datasetVersion: options.datasetVersion
|
|
8348
|
+
datasetVersion: options.datasetVersion,
|
|
8349
|
+
repeat: options.repeat
|
|
8248
8350
|
});
|
|
8249
8351
|
const { data, error, response } = await this.apiClient.POST("/api/v1/experiments/{slug}/run", __spreadValues({
|
|
8250
8352
|
params: { path: { slug } }
|
|
@@ -9871,6 +9973,34 @@ var TestSuitesApiService = class {
|
|
|
9871
9973
|
onError: this.handleApiError.bind(this)
|
|
9872
9974
|
});
|
|
9873
9975
|
}
|
|
9976
|
+
/** Lists the suite templates that ship with LangWatch, scenarios included. */
|
|
9977
|
+
async listTemplates() {
|
|
9978
|
+
const { data, error, response } = await this.apiClient.GET("/api/v1/test-suites/templates");
|
|
9979
|
+
return unwrapApiResult({
|
|
9980
|
+
operation: "list suite templates",
|
|
9981
|
+
data,
|
|
9982
|
+
error,
|
|
9983
|
+
response,
|
|
9984
|
+
onError: this.handleApiError.bind(this)
|
|
9985
|
+
});
|
|
9986
|
+
}
|
|
9987
|
+
/** Creates a test suite from a template, fitted to the agent under test. */
|
|
9988
|
+
async applyTemplate({
|
|
9989
|
+
templateId,
|
|
9990
|
+
body
|
|
9991
|
+
}) {
|
|
9992
|
+
const { data, error, response } = await this.apiClient.POST(
|
|
9993
|
+
"/api/v1/test-suites/templates/{templateId}/apply",
|
|
9994
|
+
{ params: { path: { templateId } }, body }
|
|
9995
|
+
);
|
|
9996
|
+
return unwrapApiResult({
|
|
9997
|
+
operation: `apply suite template "${templateId}"`,
|
|
9998
|
+
data,
|
|
9999
|
+
error,
|
|
10000
|
+
response,
|
|
10001
|
+
onError: this.handleApiError.bind(this)
|
|
10002
|
+
});
|
|
10003
|
+
}
|
|
9874
10004
|
};
|
|
9875
10005
|
|
|
9876
10006
|
// src/client-sdk/services/workflows/workflows-api.service.ts
|