@withgateway/sdk 0.1.10 → 0.1.11

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.mjs CHANGED
@@ -21,7 +21,7 @@ var require_package = __commonJS({
21
21
  "package.json"(exports, module) {
22
22
  module.exports = {
23
23
  name: "@withgateway/sdk",
24
- version: "0.1.10",
24
+ version: "0.1.11",
25
25
  description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
26
26
  main: "./dist/index.js",
27
27
  module: "./dist/index.mjs",
@@ -2763,6 +2763,7 @@ function sha256(text) {
2763
2763
  }
2764
2764
  var registeredTools = /* @__PURE__ */ new Map();
2765
2765
  var registeredPrompts = /* @__PURE__ */ new Map();
2766
+ var registeredSkills = /* @__PURE__ */ new Map();
2766
2767
  function captureSource() {
2767
2768
  const stack = new Error().stack?.split("\n") ?? [];
2768
2769
  for (const line of stack.slice(1)) {
@@ -2793,10 +2794,12 @@ function defineTool(tool) {
2793
2794
  ...source ? { source } : {}
2794
2795
  };
2795
2796
  registeredTools.set(tool.name, identity);
2797
+ notifyRegistryChanged();
2796
2798
  return tool;
2797
2799
  }
2798
2800
  function registerPrompt(name, content) {
2799
2801
  registeredPrompts.set(name, sha256(content));
2802
+ notifyRegistryChanged();
2800
2803
  return content;
2801
2804
  }
2802
2805
  function getRegisteredTools() {
@@ -2804,6 +2807,17 @@ function getRegisteredTools() {
2804
2807
  (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
2805
2808
  );
2806
2809
  }
2810
+ function registerSkill(name, version) {
2811
+ registeredSkills.set(name, version);
2812
+ notifyRegistryChanged();
2813
+ }
2814
+ function getRegisteredSkills() {
2815
+ return Object.fromEntries(
2816
+ [...registeredSkills.entries()].sort(
2817
+ ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
2818
+ )
2819
+ );
2820
+ }
2807
2821
  function getRegisteredPrompts() {
2808
2822
  return Object.fromEntries(
2809
2823
  [...registeredPrompts.entries()].sort(
@@ -2814,6 +2828,10 @@ function getRegisteredPrompts() {
2814
2828
  function resetBuildRegistry() {
2815
2829
  registeredTools.clear();
2816
2830
  registeredPrompts.clear();
2831
+ registeredSkills.clear();
2832
+ activeBuilds.length = 0;
2833
+ if (reRegisterTimer) clearTimeout(reRegisterTimer);
2834
+ reRegisterTimer = null;
2817
2835
  }
2818
2836
  function sdkVersion() {
2819
2837
  try {
@@ -2836,7 +2854,8 @@ function assembleManifest(agentId) {
2836
2854
  ...codeRef() ? { codeRef: codeRef() } : {},
2837
2855
  sdk: sdkVersion(),
2838
2856
  tools: getRegisteredTools(),
2839
- prompts: getRegisteredPrompts()
2857
+ prompts: getRegisteredPrompts(),
2858
+ skills: getRegisteredSkills()
2840
2859
  };
2841
2860
  }
2842
2861
  function computeBuildHash(manifest) {
@@ -2869,6 +2888,31 @@ function attributionFromEnv() {
2869
2888
  }
2870
2889
  return attribution;
2871
2890
  }
2891
+ var activeBuilds = [];
2892
+ var reRegisterTimer = null;
2893
+ var RE_REGISTER_DEBOUNCE_MS = 3e3;
2894
+ function trackActiveBuild(context4) {
2895
+ activeBuilds.push(context4);
2896
+ }
2897
+ function notifyRegistryChanged() {
2898
+ if (activeBuilds.length === 0) return;
2899
+ if (reRegisterTimer) clearTimeout(reRegisterTimer);
2900
+ reRegisterTimer = setTimeout(() => {
2901
+ reRegisterTimer = null;
2902
+ for (const context4 of activeBuilds) {
2903
+ const manifest = assembleManifest(context4.agentId);
2904
+ const buildHash = computeBuildHash(manifest);
2905
+ if (buildHash === context4.lastRegisteredHash) continue;
2906
+ context4.lastRegisteredHash = buildHash;
2907
+ void registerBuild({ ...context4, manifest, buildHash }).catch(() => {
2908
+ context4.lastRegisteredHash = void 0;
2909
+ });
2910
+ }
2911
+ }, RE_REGISTER_DEBOUNCE_MS);
2912
+ if (typeof reRegisterTimer === "object" && "unref" in reRegisterTimer) {
2913
+ reRegisterTimer.unref();
2914
+ }
2915
+ }
2872
2916
  async function registerBuild(params) {
2873
2917
  const auth = Buffer.from(`${params.publicKey}:${params.secretKey}`).toString(
2874
2918
  "base64"
@@ -3149,6 +3193,14 @@ function scheduleBuildRegistration(config, built) {
3149
3193
  return;
3150
3194
  }
3151
3195
  const { manifest, buildHash } = built.buildInfo;
3196
+ trackActiveBuild({
3197
+ host: built.connection.host,
3198
+ publicKey: built.connection.publicKey,
3199
+ secretKey: built.connection.secretKey,
3200
+ agentId: config.agent,
3201
+ version: config.version,
3202
+ lastRegisteredHash: buildHash
3203
+ });
3152
3204
  void registerBuild({
3153
3205
  host: built.connection.host,
3154
3206
  publicKey: built.connection.publicKey,
@@ -3538,12 +3590,14 @@ export {
3538
3590
  gateway,
3539
3591
  getExperimentContext,
3540
3592
  getRegisteredPrompts,
3593
+ getRegisteredSkills,
3541
3594
  getRegisteredTools,
3542
3595
  identify,
3543
3596
  loadSession,
3544
3597
  memory,
3545
3598
  personas,
3546
3599
  registerPrompt,
3600
+ registerSkill,
3547
3601
  renderAgentSystem,
3548
3602
  replay,
3549
3603
  resetBuildRegistry,