@withgateway/sdk 0.2.3 → 0.2.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.
Files changed (50) hide show
  1. package/dist/cli.js +12557 -5244
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs +12557 -5244
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/files/index.js +65 -29
  6. package/dist/files/index.js.map +1 -1
  7. package/dist/files/index.mjs +53 -18
  8. package/dist/files/index.mjs.map +1 -1
  9. package/dist/hooks/index.d.mts +1 -0
  10. package/dist/hooks/index.d.ts +1 -0
  11. package/dist/hooks/index.js +4355 -0
  12. package/dist/hooks/index.js.map +1 -0
  13. package/dist/hooks/index.mjs +4243 -0
  14. package/dist/hooks/index.mjs.map +1 -0
  15. package/dist/{index-Dpo-t8iO.d.ts → index-1xnxt0Cc.d.ts} +58 -2
  16. package/dist/index-B0R3IgsV.d.mts +1279 -0
  17. package/dist/index-B0R3IgsV.d.ts +1279 -0
  18. package/dist/{index-B5HUQQDE.d.mts → index-C1wDEwH4.d.mts} +58 -2
  19. package/dist/index.d.mts +4 -3
  20. package/dist/index.d.ts +4 -3
  21. package/dist/index.js +6538 -1549
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +6628 -1652
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/traces/index.js +54 -18
  26. package/dist/traces/index.js.map +1 -1
  27. package/dist/traces/index.mjs +45 -10
  28. package/dist/traces/index.mjs.map +1 -1
  29. package/dist/tracing/index.d.mts +1 -1
  30. package/dist/tracing/index.d.ts +1 -1
  31. package/dist/tracing/index.js +46 -3
  32. package/dist/tracing/index.js.map +1 -1
  33. package/dist/tracing/index.mjs +41 -2
  34. package/dist/tracing/index.mjs.map +1 -1
  35. package/dist/worlds/index.d.mts +365 -6
  36. package/dist/worlds/index.d.ts +365 -6
  37. package/dist/worlds/index.js +2037 -216
  38. package/dist/worlds/index.js.map +1 -1
  39. package/dist/worlds/index.mjs +2026 -205
  40. package/dist/worlds/index.mjs.map +1 -1
  41. package/package.json +6 -1
  42. package/runtime/gatewaysdk/environment/_materialize.py +3 -3
  43. package/runtime/gatewaysdk/environment/schema/api.py +116 -2
  44. package/runtime/gatewaysdk/environment/schema/compiler.py +14 -0
  45. package/runtime/gatewaysdk/environment/schema/host.py +37 -11
  46. package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +154 -0
  47. package/runtime/gatewaysdk/environment/schema/snapshot.py +6 -5
  48. package/runtime/gatewaysdk/environment/schema/tasks.py +12 -2
  49. package/runtime/gatewaysdk/environment/schema/workers.py +30 -13
  50. package/skills/hooks-getting-started/SKILL.md +154 -0
@@ -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.3",
19
+ version: "0.2.4",
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",
@@ -92,6 +92,11 @@ var require_package = __commonJS({
92
92
  import: "./dist/traces/index.mjs",
93
93
  require: "./dist/traces/index.js"
94
94
  },
95
+ "./hooks": {
96
+ types: "./dist/hooks/index.d.ts",
97
+ import: "./dist/hooks/index.mjs",
98
+ require: "./dist/hooks/index.js"
99
+ },
95
100
  "./cli": {
96
101
  types: "./dist/cli.d.ts",
97
102
  import: "./dist/cli.mjs",
@@ -472,6 +477,35 @@ function debugLog(message, ...args) {
472
477
  }
473
478
  }
474
479
 
480
+ // src/tracing/session.ts
481
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
482
+ var SESSION_ID_ATTRIBUTE = "gateway.session.id";
483
+ var currentSessionStorage = new AsyncLocalStorage2();
484
+ function getAmbientSessionId() {
485
+ return currentSessionStorage.getStore();
486
+ }
487
+ function withSession(sessionId, fn) {
488
+ return new Promise((resolve, reject) => {
489
+ currentSessionStorage.run(sessionId, () => {
490
+ Promise.resolve().then(fn).then(resolve, reject);
491
+ });
492
+ });
493
+ }
494
+ var SessionSpanProcessor = class {
495
+ onStart(span, _parentContext) {
496
+ const sessionId = getAmbientSessionId();
497
+ if (sessionId) {
498
+ span.setAttribute(SESSION_ID_ATTRIBUTE, sessionId);
499
+ }
500
+ }
501
+ onEnd(_span) {
502
+ }
503
+ async shutdown() {
504
+ }
505
+ async forceFlush() {
506
+ }
507
+ };
508
+
475
509
  // src/scores/index.ts
476
510
  import { isSpanContextValid as isSpanContextValid2, trace as trace2 } from "@opentelemetry/api";
477
511
  var SUCCESS_SIGNAL_KEY = "gateway.success.signal";
@@ -1007,6 +1041,7 @@ function buildProvider(config, logFn) {
1007
1041
  }
1008
1042
  }
1009
1043
  spanProcessors.push(new IdentitySpanProcessor());
1044
+ spanProcessors.push(new SessionSpanProcessor());
1010
1045
  const batchConfig = {};
1011
1046
  if (config.batch?.maxQueueSize) {
1012
1047
  batchConfig.maxQueueSize = config.batch.maxQueueSize;
@@ -1377,8 +1412,11 @@ async function* observeClaude(stream, options) {
1377
1412
  }
1378
1413
  export {
1379
1414
  IdentitySpanProcessor,
1415
+ SESSION_ID_ATTRIBUTE,
1416
+ SessionSpanProcessor,
1380
1417
  USER_ID_ATTRIBUTE,
1381
1418
  flush,
1419
+ getAmbientSessionId,
1382
1420
  identify,
1383
1421
  init,
1384
1422
  initIsolated,
@@ -1390,6 +1428,7 @@ export {
1390
1428
  observeOpenAI,
1391
1429
  resetAmbientUser,
1392
1430
  resolveUserId,
1393
- shutdown
1431
+ shutdown,
1432
+ withSession
1394
1433
  };
1395
1434
  //# sourceMappingURL=index.mjs.map