@withgateway/sdk 0.2.4 → 0.2.6
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/cli.js +4304 -2381
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +4266 -2343
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +56 -31
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +52 -27
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +280 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +272 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-1xnxt0Cc.d.ts → index-BO2SNSgy.d.ts} +12 -1
- package/dist/{index-B0R3IgsV.d.mts → index-BaKu5ZSU.d.mts} +124 -2
- package/dist/{index-B0R3IgsV.d.ts → index-BaKu5ZSU.d.ts} +124 -2
- package/dist/{index-C1wDEwH4.d.mts → index-Cz8Q6Keo.d.mts} +12 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1100 -438
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1079 -424
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +45 -20
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +41 -16
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +98 -61
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +98 -61
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +179 -25
- package/dist/worlds/index.d.ts +179 -25
- package/dist/worlds/index.js +639 -284
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +631 -276
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +2 -1
- package/runtime/gatewaysdk/environment/_bundle.py +15 -25
- package/runtime/gatewaysdk/environment/_materialize.py +53 -9
- package/runtime/gatewaysdk/environment/_toml.py +13 -0
- package/runtime/gatewaysdk/environment/schema/api.py +40 -25
- package/runtime/gatewaysdk/environment/schema/batch.py +15 -11
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +24 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +60 -28
- package/runtime/gatewaysdk/environment/schema/conform.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connector.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.ingest.toml +25 -0
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +17 -0
- package/runtime/gatewaysdk/environment/schema/data.py +21 -19
- package/runtime/gatewaysdk/environment/schema/extract.py +1 -5
- package/runtime/gatewaysdk/environment/schema/grading.py +225 -0
- package/runtime/gatewaysdk/environment/schema/host.py +156 -546
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +1 -5
- package/runtime/gatewaysdk/environment/schema/ingest.py +3 -11
- package/runtime/gatewaysdk/environment/schema/local.py +32 -126
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/platform.py +30 -26
- package/runtime/gatewaysdk/environment/schema/proof.py +237 -0
- package/runtime/gatewaysdk/environment/schema/redaction.py +1 -1
- package/runtime/gatewaysdk/environment/schema/runtime.py +686 -0
- package/runtime/gatewaysdk/environment/schema/scaffold.py +9 -2
- package/runtime/gatewaysdk/environment/schema/skill.py +1 -0
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +67 -6
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
- package/runtime/gatewaysdk/environment/schema/snapshot.py +1 -5
- package/runtime/gatewaysdk/environment/schema/tools_world.py +71 -23
- package/runtime/gatewaysdk/environment/schema/ui.py +1 -5
- package/runtime/gatewaysdk/environment/schema/verbs.py +136 -0
- package/runtime/gatewaysdk/environment/schema/workers.py +14 -0
- package/runtime/gatewaysdk/environment/schema/world_tests.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +507 -0
- package/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/skills/connector-schema-authoring/connector-worlds.md +8 -1
- package/skills/connector-schema-authoring/world-schema.md +1 -1
- package/skills/hooks-getting-started/SKILL.md +67 -6
- package/skills/world-data-ingestion/SKILL.md +4 -1
- package/skills/worlds-getting-started/SKILL.md +11 -11
- package/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
package/dist/tracing/index.mjs
CHANGED
|
@@ -16,7 +16,7 @@ var require_package = __commonJS({
|
|
|
16
16
|
"package.json"(exports, module) {
|
|
17
17
|
module.exports = {
|
|
18
18
|
name: "@withgateway/sdk",
|
|
19
|
-
version: "0.2.
|
|
19
|
+
version: "0.2.6",
|
|
20
20
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
21
21
|
main: "./dist/index.js",
|
|
22
22
|
module: "./dist/index.mjs",
|
|
@@ -120,6 +120,7 @@ var require_package = __commonJS({
|
|
|
120
120
|
"typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
121
121
|
test: "vitest",
|
|
122
122
|
"test:run": "vitest run",
|
|
123
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
123
124
|
lint: "eslint src --ext .ts",
|
|
124
125
|
clean: "rm -rf dist",
|
|
125
126
|
example: "tsx examples/test-ab-experiment.ts",
|
|
@@ -1275,10 +1276,28 @@ function toolResultText(content) {
|
|
|
1275
1276
|
).join("");
|
|
1276
1277
|
return JSON.stringify(content ?? "");
|
|
1277
1278
|
}
|
|
1279
|
+
function toolSummary(names) {
|
|
1280
|
+
return names.map((n) => `\u2192 ${n}`).join(", ");
|
|
1281
|
+
}
|
|
1282
|
+
var USAGE_ATTRIBUTES = [
|
|
1283
|
+
["input_tokens", "llm.token_count.prompt"],
|
|
1284
|
+
["output_tokens", "llm.token_count.completion"],
|
|
1285
|
+
["cache_read_input_tokens", "llm.token_count.prompt_details.cache_read"],
|
|
1286
|
+
["cache_creation_input_tokens", "llm.token_count.prompt_details.cache_write"]
|
|
1287
|
+
];
|
|
1288
|
+
function setUsageAttributes(span, usage) {
|
|
1289
|
+
if (!usage || typeof usage !== "object") return;
|
|
1290
|
+
const u = usage;
|
|
1291
|
+
for (const [field, attribute] of USAGE_ATTRIBUTES) {
|
|
1292
|
+
const value = u[field];
|
|
1293
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
1294
|
+
span.setAttribute(attribute, value);
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1278
1297
|
var TURN_INPUT_MAX = 4e3;
|
|
1279
1298
|
async function* observeClaude(stream, options) {
|
|
1280
1299
|
const tracer = options.tracer ?? trace4.getTracer("@withgateway/sdk");
|
|
1281
|
-
const
|
|
1300
|
+
const fallbackModel = options.model ?? "claude";
|
|
1282
1301
|
const openTools = /* @__PURE__ */ new Map();
|
|
1283
1302
|
let root = null;
|
|
1284
1303
|
let rootCtx = null;
|
|
@@ -1296,85 +1315,102 @@ async function* observeClaude(stream, options) {
|
|
|
1296
1315
|
let turnCtx = null;
|
|
1297
1316
|
let turnIndex = 0;
|
|
1298
1317
|
let turnText = "";
|
|
1318
|
+
let turnTools = [];
|
|
1299
1319
|
let pendingTurnInput = options.input ?? "";
|
|
1320
|
+
let gen = null;
|
|
1321
|
+
let genMessageId;
|
|
1322
|
+
let genText = "";
|
|
1323
|
+
let genTools = [];
|
|
1324
|
+
let genUsage;
|
|
1300
1325
|
let finalText = "";
|
|
1326
|
+
const endGeneration = () => {
|
|
1327
|
+
if (!gen) return;
|
|
1328
|
+
gen.setAttribute("output.value", genText || toolSummary(genTools));
|
|
1329
|
+
setUsageAttributes(gen, genUsage);
|
|
1330
|
+
gen.setStatus({ code: SpanStatusCode2.OK });
|
|
1331
|
+
gen.end();
|
|
1332
|
+
gen = null;
|
|
1333
|
+
genMessageId = void 0;
|
|
1334
|
+
genText = "";
|
|
1335
|
+
genTools = [];
|
|
1336
|
+
genUsage = void 0;
|
|
1337
|
+
};
|
|
1301
1338
|
const endTurn = () => {
|
|
1302
1339
|
if (!turnRoot) return;
|
|
1303
|
-
|
|
1340
|
+
const output = turnText || toolSummary(turnTools);
|
|
1341
|
+
if (output) turnRoot.setAttribute("output.value", output);
|
|
1304
1342
|
turnRoot.setStatus({ code: SpanStatusCode2.OK });
|
|
1305
1343
|
turnRoot.end();
|
|
1306
1344
|
turnRoot = null;
|
|
1307
1345
|
turnCtx = null;
|
|
1308
1346
|
};
|
|
1347
|
+
const startTurn = () => {
|
|
1348
|
+
for (const span of openTools.values()) span.end();
|
|
1349
|
+
openTools.clear();
|
|
1350
|
+
endTurn();
|
|
1351
|
+
turnIndex += 1;
|
|
1352
|
+
turnText = "";
|
|
1353
|
+
turnTools = [];
|
|
1354
|
+
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
1355
|
+
root: true,
|
|
1356
|
+
attributes: {
|
|
1357
|
+
"openinference.span.kind": "AGENT",
|
|
1358
|
+
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
1359
|
+
...options.attributes ?? {}
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
turnCtx = trace4.setSpan(context2.active(), turnRoot);
|
|
1363
|
+
pendingTurnInput = "";
|
|
1364
|
+
};
|
|
1365
|
+
const startGeneration = (message) => {
|
|
1366
|
+
endGeneration();
|
|
1367
|
+
if (options.perTurn) startTurn();
|
|
1368
|
+
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
1369
|
+
genMessageId = message.message?.id;
|
|
1370
|
+
gen = tracer.startSpan(
|
|
1371
|
+
"assistant",
|
|
1372
|
+
{
|
|
1373
|
+
attributes: {
|
|
1374
|
+
"openinference.span.kind": "LLM",
|
|
1375
|
+
"llm.model_name": message.message?.model ?? fallbackModel,
|
|
1376
|
+
"llm.provider": "anthropic"
|
|
1377
|
+
}
|
|
1378
|
+
},
|
|
1379
|
+
childCtx
|
|
1380
|
+
);
|
|
1381
|
+
};
|
|
1309
1382
|
try {
|
|
1310
1383
|
for await (const message of stream) {
|
|
1311
1384
|
if (message?.type === "assistant") {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
endTurn();
|
|
1316
|
-
turnIndex += 1;
|
|
1317
|
-
turnText = "";
|
|
1318
|
-
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
1319
|
-
root: true,
|
|
1320
|
-
attributes: {
|
|
1321
|
-
"openinference.span.kind": "AGENT",
|
|
1322
|
-
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
1323
|
-
...options.attributes ?? {}
|
|
1324
|
-
}
|
|
1325
|
-
});
|
|
1326
|
-
turnCtx = trace4.setSpan(context2.active(), turnRoot);
|
|
1327
|
-
pendingTurnInput = "";
|
|
1328
|
-
}
|
|
1385
|
+
const messageId = message.message?.id;
|
|
1386
|
+
const continuesGeneration = gen !== null && messageId !== void 0 && messageId === genMessageId;
|
|
1387
|
+
if (!continuesGeneration) startGeneration(message);
|
|
1329
1388
|
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
1330
|
-
let text = "";
|
|
1331
|
-
const toolUses = [];
|
|
1332
1389
|
for (const block of message.message?.content ?? []) {
|
|
1333
1390
|
if (block?.type === "text") {
|
|
1334
1391
|
finalText += block.text;
|
|
1335
|
-
|
|
1392
|
+
turnText += block.text;
|
|
1393
|
+
genText += block.text;
|
|
1336
1394
|
}
|
|
1337
1395
|
if (block?.type === "tool_use") {
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1396
|
+
const name = cleanToolName(block.name);
|
|
1397
|
+
genTools.push(name);
|
|
1398
|
+
turnTools.push(name);
|
|
1399
|
+
const span = tracer.startSpan(
|
|
1400
|
+
`tool.${name}`,
|
|
1401
|
+
{
|
|
1402
|
+
attributes: {
|
|
1403
|
+
"openinference.span.kind": "TOOL",
|
|
1404
|
+
"tool.name": name,
|
|
1405
|
+
"input.value": JSON.stringify(block.input)
|
|
1406
|
+
}
|
|
1407
|
+
},
|
|
1408
|
+
childCtx
|
|
1409
|
+
);
|
|
1410
|
+
openTools.set(block.id, span);
|
|
1343
1411
|
}
|
|
1344
1412
|
}
|
|
1345
|
-
|
|
1346
|
-
const gen = tracer.startSpan(
|
|
1347
|
-
"assistant",
|
|
1348
|
-
{
|
|
1349
|
-
attributes: {
|
|
1350
|
-
"openinference.span.kind": "LLM",
|
|
1351
|
-
"llm.model_name": model,
|
|
1352
|
-
"llm.provider": "anthropic",
|
|
1353
|
-
"output.value": text || toolUses.map((t) => `\u2192 ${cleanToolName(t.name)}`).join(", ")
|
|
1354
|
-
}
|
|
1355
|
-
},
|
|
1356
|
-
childCtx
|
|
1357
|
-
);
|
|
1358
|
-
const usage = message.message?.usage;
|
|
1359
|
-
if (usage?.input_tokens != null)
|
|
1360
|
-
gen.setAttribute("llm.token_count.prompt", usage.input_tokens);
|
|
1361
|
-
if (usage?.output_tokens != null)
|
|
1362
|
-
gen.setAttribute("llm.token_count.completion", usage.output_tokens);
|
|
1363
|
-
gen.end();
|
|
1364
|
-
for (const t of toolUses) {
|
|
1365
|
-
const span = tracer.startSpan(
|
|
1366
|
-
`tool.${cleanToolName(t.name)}`,
|
|
1367
|
-
{
|
|
1368
|
-
attributes: {
|
|
1369
|
-
"openinference.span.kind": "TOOL",
|
|
1370
|
-
"tool.name": cleanToolName(t.name),
|
|
1371
|
-
"input.value": JSON.stringify(t.input)
|
|
1372
|
-
}
|
|
1373
|
-
},
|
|
1374
|
-
childCtx
|
|
1375
|
-
);
|
|
1376
|
-
openTools.set(t.id, span);
|
|
1377
|
-
}
|
|
1413
|
+
if (message.message?.usage) genUsage = message.message.usage;
|
|
1378
1414
|
}
|
|
1379
1415
|
if (message?.type === "user") {
|
|
1380
1416
|
const content = message.message?.content;
|
|
@@ -1399,6 +1435,7 @@ async function* observeClaude(stream, options) {
|
|
|
1399
1435
|
yield message;
|
|
1400
1436
|
}
|
|
1401
1437
|
} finally {
|
|
1438
|
+
endGeneration();
|
|
1402
1439
|
for (const span of openTools.values()) span.end();
|
|
1403
1440
|
openTools.clear();
|
|
1404
1441
|
if (options.perTurn) {
|