@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.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SESSION_ID_ATTRIBUTE, d as SessionSpanProcessor, T as TracingConfig, e as TracingHandle, f as TracingState, U as USER_ID_ATTRIBUTE, g as flush, h as getAmbientSessionId, i as identify, j as init, k as initIsolated, l as isGatewayConfigured, m as isInitialized, o as observe, n as observeAnthropic, p as observeClaude, q as observeOpenAI, s as resetAmbientUser, r as resolveUserId, t as shutdown, w as withSession } from '../index-
|
|
1
|
+
export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SESSION_ID_ATTRIBUTE, d as SessionSpanProcessor, T as TracingConfig, e as TracingHandle, f as TracingState, U as USER_ID_ATTRIBUTE, g as flush, h as getAmbientSessionId, i as identify, j as init, k as initIsolated, l as isGatewayConfigured, m as isInitialized, o as observe, n as observeAnthropic, p as observeClaude, q as observeOpenAI, s as resetAmbientUser, r as resolveUserId, t as shutdown, w as withSession } from '../index-Cz8Q6Keo.mjs';
|
|
2
2
|
import '@opentelemetry/api';
|
|
3
3
|
import '../scores/index.mjs';
|
|
4
4
|
import '@opentelemetry/sdk-trace-base';
|
package/dist/tracing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SESSION_ID_ATTRIBUTE, d as SessionSpanProcessor, T as TracingConfig, e as TracingHandle, f as TracingState, U as USER_ID_ATTRIBUTE, g as flush, h as getAmbientSessionId, i as identify, j as init, k as initIsolated, l as isGatewayConfigured, m as isInitialized, o as observe, n as observeAnthropic, p as observeClaude, q as observeOpenAI, s as resetAmbientUser, r as resolveUserId, t as shutdown, w as withSession } from '../index-
|
|
1
|
+
export { I as IdentifyOptions, a as IdentitySpanProcessor, O as ObservationKind, b as ObserveClaudeOptions, c as ObserveOptions, S as SESSION_ID_ATTRIBUTE, d as SessionSpanProcessor, T as TracingConfig, e as TracingHandle, f as TracingState, U as USER_ID_ATTRIBUTE, g as flush, h as getAmbientSessionId, i as identify, j as init, k as initIsolated, l as isGatewayConfigured, m as isInitialized, o as observe, n as observeAnthropic, p as observeClaude, q as observeOpenAI, s as resetAmbientUser, r as resolveUserId, t as shutdown, w as withSession } from '../index-BO2SNSgy.js';
|
|
2
2
|
import '@opentelemetry/api';
|
|
3
3
|
import '../scores/index.js';
|
|
4
4
|
import '@opentelemetry/sdk-trace-base';
|
package/dist/tracing/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var require_package = __commonJS({
|
|
|
25
25
|
"package.json"(exports2, module2) {
|
|
26
26
|
module2.exports = {
|
|
27
27
|
name: "@withgateway/sdk",
|
|
28
|
-
version: "0.2.
|
|
28
|
+
version: "0.2.6",
|
|
29
29
|
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
30
30
|
main: "./dist/index.js",
|
|
31
31
|
module: "./dist/index.mjs",
|
|
@@ -129,6 +129,7 @@ var require_package = __commonJS({
|
|
|
129
129
|
"typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
130
130
|
test: "vitest",
|
|
131
131
|
"test:run": "vitest run",
|
|
132
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
132
133
|
lint: "eslint src --ext .ts",
|
|
133
134
|
clean: "rm -rf dist",
|
|
134
135
|
example: "tsx examples/test-ab-experiment.ts",
|
|
@@ -1305,10 +1306,28 @@ function toolResultText(content) {
|
|
|
1305
1306
|
).join("");
|
|
1306
1307
|
return JSON.stringify(content ?? "");
|
|
1307
1308
|
}
|
|
1309
|
+
function toolSummary(names) {
|
|
1310
|
+
return names.map((n) => `\u2192 ${n}`).join(", ");
|
|
1311
|
+
}
|
|
1312
|
+
var USAGE_ATTRIBUTES = [
|
|
1313
|
+
["input_tokens", "llm.token_count.prompt"],
|
|
1314
|
+
["output_tokens", "llm.token_count.completion"],
|
|
1315
|
+
["cache_read_input_tokens", "llm.token_count.prompt_details.cache_read"],
|
|
1316
|
+
["cache_creation_input_tokens", "llm.token_count.prompt_details.cache_write"]
|
|
1317
|
+
];
|
|
1318
|
+
function setUsageAttributes(span, usage) {
|
|
1319
|
+
if (!usage || typeof usage !== "object") return;
|
|
1320
|
+
const u = usage;
|
|
1321
|
+
for (const [field, attribute] of USAGE_ATTRIBUTES) {
|
|
1322
|
+
const value = u[field];
|
|
1323
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
1324
|
+
span.setAttribute(attribute, value);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1308
1327
|
var TURN_INPUT_MAX = 4e3;
|
|
1309
1328
|
async function* observeClaude(stream, options) {
|
|
1310
1329
|
const tracer = options.tracer ?? import_api4.trace.getTracer("@withgateway/sdk");
|
|
1311
|
-
const
|
|
1330
|
+
const fallbackModel = options.model ?? "claude";
|
|
1312
1331
|
const openTools = /* @__PURE__ */ new Map();
|
|
1313
1332
|
let root = null;
|
|
1314
1333
|
let rootCtx = null;
|
|
@@ -1326,85 +1345,102 @@ async function* observeClaude(stream, options) {
|
|
|
1326
1345
|
let turnCtx = null;
|
|
1327
1346
|
let turnIndex = 0;
|
|
1328
1347
|
let turnText = "";
|
|
1348
|
+
let turnTools = [];
|
|
1329
1349
|
let pendingTurnInput = options.input ?? "";
|
|
1350
|
+
let gen = null;
|
|
1351
|
+
let genMessageId;
|
|
1352
|
+
let genText = "";
|
|
1353
|
+
let genTools = [];
|
|
1354
|
+
let genUsage;
|
|
1330
1355
|
let finalText = "";
|
|
1356
|
+
const endGeneration = () => {
|
|
1357
|
+
if (!gen) return;
|
|
1358
|
+
gen.setAttribute("output.value", genText || toolSummary(genTools));
|
|
1359
|
+
setUsageAttributes(gen, genUsage);
|
|
1360
|
+
gen.setStatus({ code: import_api4.SpanStatusCode.OK });
|
|
1361
|
+
gen.end();
|
|
1362
|
+
gen = null;
|
|
1363
|
+
genMessageId = void 0;
|
|
1364
|
+
genText = "";
|
|
1365
|
+
genTools = [];
|
|
1366
|
+
genUsage = void 0;
|
|
1367
|
+
};
|
|
1331
1368
|
const endTurn = () => {
|
|
1332
1369
|
if (!turnRoot) return;
|
|
1333
|
-
|
|
1370
|
+
const output = turnText || toolSummary(turnTools);
|
|
1371
|
+
if (output) turnRoot.setAttribute("output.value", output);
|
|
1334
1372
|
turnRoot.setStatus({ code: import_api4.SpanStatusCode.OK });
|
|
1335
1373
|
turnRoot.end();
|
|
1336
1374
|
turnRoot = null;
|
|
1337
1375
|
turnCtx = null;
|
|
1338
1376
|
};
|
|
1377
|
+
const startTurn = () => {
|
|
1378
|
+
for (const span of openTools.values()) span.end();
|
|
1379
|
+
openTools.clear();
|
|
1380
|
+
endTurn();
|
|
1381
|
+
turnIndex += 1;
|
|
1382
|
+
turnText = "";
|
|
1383
|
+
turnTools = [];
|
|
1384
|
+
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
1385
|
+
root: true,
|
|
1386
|
+
attributes: {
|
|
1387
|
+
"openinference.span.kind": "AGENT",
|
|
1388
|
+
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
1389
|
+
...options.attributes ?? {}
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
turnCtx = import_api4.trace.setSpan(import_api4.context.active(), turnRoot);
|
|
1393
|
+
pendingTurnInput = "";
|
|
1394
|
+
};
|
|
1395
|
+
const startGeneration = (message) => {
|
|
1396
|
+
endGeneration();
|
|
1397
|
+
if (options.perTurn) startTurn();
|
|
1398
|
+
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
1399
|
+
genMessageId = message.message?.id;
|
|
1400
|
+
gen = tracer.startSpan(
|
|
1401
|
+
"assistant",
|
|
1402
|
+
{
|
|
1403
|
+
attributes: {
|
|
1404
|
+
"openinference.span.kind": "LLM",
|
|
1405
|
+
"llm.model_name": message.message?.model ?? fallbackModel,
|
|
1406
|
+
"llm.provider": "anthropic"
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
childCtx
|
|
1410
|
+
);
|
|
1411
|
+
};
|
|
1339
1412
|
try {
|
|
1340
1413
|
for await (const message of stream) {
|
|
1341
1414
|
if (message?.type === "assistant") {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
endTurn();
|
|
1346
|
-
turnIndex += 1;
|
|
1347
|
-
turnText = "";
|
|
1348
|
-
turnRoot = tracer.startSpan(`${options.name} \xB7 turn ${turnIndex}`, {
|
|
1349
|
-
root: true,
|
|
1350
|
-
attributes: {
|
|
1351
|
-
"openinference.span.kind": "AGENT",
|
|
1352
|
-
...pendingTurnInput ? { "input.value": pendingTurnInput.slice(0, TURN_INPUT_MAX) } : {},
|
|
1353
|
-
...options.attributes ?? {}
|
|
1354
|
-
}
|
|
1355
|
-
});
|
|
1356
|
-
turnCtx = import_api4.trace.setSpan(import_api4.context.active(), turnRoot);
|
|
1357
|
-
pendingTurnInput = "";
|
|
1358
|
-
}
|
|
1415
|
+
const messageId = message.message?.id;
|
|
1416
|
+
const continuesGeneration = gen !== null && messageId !== void 0 && messageId === genMessageId;
|
|
1417
|
+
if (!continuesGeneration) startGeneration(message);
|
|
1359
1418
|
const childCtx = options.perTurn ? turnCtx : rootCtx;
|
|
1360
|
-
let text = "";
|
|
1361
|
-
const toolUses = [];
|
|
1362
1419
|
for (const block of message.message?.content ?? []) {
|
|
1363
1420
|
if (block?.type === "text") {
|
|
1364
1421
|
finalText += block.text;
|
|
1365
|
-
|
|
1422
|
+
turnText += block.text;
|
|
1423
|
+
genText += block.text;
|
|
1366
1424
|
}
|
|
1367
1425
|
if (block?.type === "tool_use") {
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1426
|
+
const name = cleanToolName(block.name);
|
|
1427
|
+
genTools.push(name);
|
|
1428
|
+
turnTools.push(name);
|
|
1429
|
+
const span = tracer.startSpan(
|
|
1430
|
+
`tool.${name}`,
|
|
1431
|
+
{
|
|
1432
|
+
attributes: {
|
|
1433
|
+
"openinference.span.kind": "TOOL",
|
|
1434
|
+
"tool.name": name,
|
|
1435
|
+
"input.value": JSON.stringify(block.input)
|
|
1436
|
+
}
|
|
1437
|
+
},
|
|
1438
|
+
childCtx
|
|
1439
|
+
);
|
|
1440
|
+
openTools.set(block.id, span);
|
|
1373
1441
|
}
|
|
1374
1442
|
}
|
|
1375
|
-
|
|
1376
|
-
const gen = tracer.startSpan(
|
|
1377
|
-
"assistant",
|
|
1378
|
-
{
|
|
1379
|
-
attributes: {
|
|
1380
|
-
"openinference.span.kind": "LLM",
|
|
1381
|
-
"llm.model_name": model,
|
|
1382
|
-
"llm.provider": "anthropic",
|
|
1383
|
-
"output.value": text || toolUses.map((t) => `\u2192 ${cleanToolName(t.name)}`).join(", ")
|
|
1384
|
-
}
|
|
1385
|
-
},
|
|
1386
|
-
childCtx
|
|
1387
|
-
);
|
|
1388
|
-
const usage = message.message?.usage;
|
|
1389
|
-
if (usage?.input_tokens != null)
|
|
1390
|
-
gen.setAttribute("llm.token_count.prompt", usage.input_tokens);
|
|
1391
|
-
if (usage?.output_tokens != null)
|
|
1392
|
-
gen.setAttribute("llm.token_count.completion", usage.output_tokens);
|
|
1393
|
-
gen.end();
|
|
1394
|
-
for (const t of toolUses) {
|
|
1395
|
-
const span = tracer.startSpan(
|
|
1396
|
-
`tool.${cleanToolName(t.name)}`,
|
|
1397
|
-
{
|
|
1398
|
-
attributes: {
|
|
1399
|
-
"openinference.span.kind": "TOOL",
|
|
1400
|
-
"tool.name": cleanToolName(t.name),
|
|
1401
|
-
"input.value": JSON.stringify(t.input)
|
|
1402
|
-
}
|
|
1403
|
-
},
|
|
1404
|
-
childCtx
|
|
1405
|
-
);
|
|
1406
|
-
openTools.set(t.id, span);
|
|
1407
|
-
}
|
|
1443
|
+
if (message.message?.usage) genUsage = message.message.usage;
|
|
1408
1444
|
}
|
|
1409
1445
|
if (message?.type === "user") {
|
|
1410
1446
|
const content = message.message?.content;
|
|
@@ -1429,6 +1465,7 @@ async function* observeClaude(stream, options) {
|
|
|
1429
1465
|
yield message;
|
|
1430
1466
|
}
|
|
1431
1467
|
} finally {
|
|
1468
|
+
endGeneration();
|
|
1432
1469
|
for (const span of openTools.values()) span.end();
|
|
1433
1470
|
openTools.clear();
|
|
1434
1471
|
if (options.perTurn) {
|