@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.d.mts CHANGED
@@ -28,6 +28,7 @@ interface AgentBuildManifest {
28
28
  sdk: string;
29
29
  tools: ToolIdentity[];
30
30
  prompts: Record<string, string>;
31
+ skills: Record<string, string>;
31
32
  }
32
33
  /** Deterministic JSON: object keys sorted recursively, arrays kept in order. */
33
34
  declare function canonicalJson(value: unknown): string;
@@ -62,6 +63,13 @@ declare function defineTool<T extends DefineToolInput>(tool: T): T;
62
63
  */
63
64
  declare function registerPrompt(name: string, content: string): string;
64
65
  declare function getRegisteredTools(): ToolIdentity[];
66
+ /**
67
+ * Register a skill's identity — `registerSkill("triage", "1.0")` — so skills
68
+ * are versioned in the build like tools and prompts. The version string is
69
+ * whatever you bump (or a content hash for file-based skills).
70
+ */
71
+ declare function registerSkill(name: string, version: string): void;
72
+ declare function getRegisteredSkills(): Record<string, string>;
65
73
  declare function getRegisteredPrompts(): Record<string, string>;
66
74
  /** Test hook. */
67
75
  declare function resetBuildRegistry(): void;
@@ -78,4 +86,4 @@ declare function computeBuildHash(manifest: AgentBuildManifest): string;
78
86
  */
79
87
  declare const tracing: typeof _tracingModule;
80
88
 
81
- export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredTools, registerPrompt, resetBuildRegistry, tracing };
89
+ export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredSkills, getRegisteredTools, registerPrompt, registerSkill, resetBuildRegistry, tracing };
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ interface AgentBuildManifest {
28
28
  sdk: string;
29
29
  tools: ToolIdentity[];
30
30
  prompts: Record<string, string>;
31
+ skills: Record<string, string>;
31
32
  }
32
33
  /** Deterministic JSON: object keys sorted recursively, arrays kept in order. */
33
34
  declare function canonicalJson(value: unknown): string;
@@ -62,6 +63,13 @@ declare function defineTool<T extends DefineToolInput>(tool: T): T;
62
63
  */
63
64
  declare function registerPrompt(name: string, content: string): string;
64
65
  declare function getRegisteredTools(): ToolIdentity[];
66
+ /**
67
+ * Register a skill's identity — `registerSkill("triage", "1.0")` — so skills
68
+ * are versioned in the build like tools and prompts. The version string is
69
+ * whatever you bump (or a content hash for file-based skills).
70
+ */
71
+ declare function registerSkill(name: string, version: string): void;
72
+ declare function getRegisteredSkills(): Record<string, string>;
65
73
  declare function getRegisteredPrompts(): Record<string, string>;
66
74
  /** Test hook. */
67
75
  declare function resetBuildRegistry(): void;
@@ -78,4 +86,4 @@ declare function computeBuildHash(manifest: AgentBuildManifest): string;
78
86
  */
79
87
  declare const tracing: typeof _tracingModule;
80
88
 
81
- export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredTools, registerPrompt, resetBuildRegistry, tracing };
89
+ export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredSkills, getRegisteredTools, registerPrompt, registerSkill, resetBuildRegistry, tracing };
package/dist/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.1.10",
28
+ version: "0.1.11",
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",
@@ -217,12 +217,14 @@ __export(src_exports, {
217
217
  gateway: () => gateway,
218
218
  getExperimentContext: () => getExperimentContext,
219
219
  getRegisteredPrompts: () => getRegisteredPrompts,
220
+ getRegisteredSkills: () => getRegisteredSkills,
220
221
  getRegisteredTools: () => getRegisteredTools,
221
222
  identify: () => identify,
222
223
  loadSession: () => loadSession,
223
224
  memory: () => memory,
224
225
  personas: () => personas,
225
226
  registerPrompt: () => registerPrompt,
227
+ registerSkill: () => registerSkill,
226
228
  renderAgentSystem: () => renderAgentSystem,
227
229
  replay: () => replay,
228
230
  resetBuildRegistry: () => resetBuildRegistry,
@@ -2843,6 +2845,7 @@ function sha256(text) {
2843
2845
  }
2844
2846
  var registeredTools = /* @__PURE__ */ new Map();
2845
2847
  var registeredPrompts = /* @__PURE__ */ new Map();
2848
+ var registeredSkills = /* @__PURE__ */ new Map();
2846
2849
  function captureSource() {
2847
2850
  const stack = new Error().stack?.split("\n") ?? [];
2848
2851
  for (const line of stack.slice(1)) {
@@ -2873,10 +2876,12 @@ function defineTool(tool) {
2873
2876
  ...source ? { source } : {}
2874
2877
  };
2875
2878
  registeredTools.set(tool.name, identity);
2879
+ notifyRegistryChanged();
2876
2880
  return tool;
2877
2881
  }
2878
2882
  function registerPrompt(name, content) {
2879
2883
  registeredPrompts.set(name, sha256(content));
2884
+ notifyRegistryChanged();
2880
2885
  return content;
2881
2886
  }
2882
2887
  function getRegisteredTools() {
@@ -2884,6 +2889,17 @@ function getRegisteredTools() {
2884
2889
  (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
2885
2890
  );
2886
2891
  }
2892
+ function registerSkill(name, version) {
2893
+ registeredSkills.set(name, version);
2894
+ notifyRegistryChanged();
2895
+ }
2896
+ function getRegisteredSkills() {
2897
+ return Object.fromEntries(
2898
+ [...registeredSkills.entries()].sort(
2899
+ ([a], [b]) => a < b ? -1 : a > b ? 1 : 0
2900
+ )
2901
+ );
2902
+ }
2887
2903
  function getRegisteredPrompts() {
2888
2904
  return Object.fromEntries(
2889
2905
  [...registeredPrompts.entries()].sort(
@@ -2894,6 +2910,10 @@ function getRegisteredPrompts() {
2894
2910
  function resetBuildRegistry() {
2895
2911
  registeredTools.clear();
2896
2912
  registeredPrompts.clear();
2913
+ registeredSkills.clear();
2914
+ activeBuilds.length = 0;
2915
+ if (reRegisterTimer) clearTimeout(reRegisterTimer);
2916
+ reRegisterTimer = null;
2897
2917
  }
2898
2918
  function sdkVersion() {
2899
2919
  try {
@@ -2916,7 +2936,8 @@ function assembleManifest(agentId) {
2916
2936
  ...codeRef() ? { codeRef: codeRef() } : {},
2917
2937
  sdk: sdkVersion(),
2918
2938
  tools: getRegisteredTools(),
2919
- prompts: getRegisteredPrompts()
2939
+ prompts: getRegisteredPrompts(),
2940
+ skills: getRegisteredSkills()
2920
2941
  };
2921
2942
  }
2922
2943
  function computeBuildHash(manifest) {
@@ -2949,6 +2970,31 @@ function attributionFromEnv() {
2949
2970
  }
2950
2971
  return attribution;
2951
2972
  }
2973
+ var activeBuilds = [];
2974
+ var reRegisterTimer = null;
2975
+ var RE_REGISTER_DEBOUNCE_MS = 3e3;
2976
+ function trackActiveBuild(context4) {
2977
+ activeBuilds.push(context4);
2978
+ }
2979
+ function notifyRegistryChanged() {
2980
+ if (activeBuilds.length === 0) return;
2981
+ if (reRegisterTimer) clearTimeout(reRegisterTimer);
2982
+ reRegisterTimer = setTimeout(() => {
2983
+ reRegisterTimer = null;
2984
+ for (const context4 of activeBuilds) {
2985
+ const manifest = assembleManifest(context4.agentId);
2986
+ const buildHash = computeBuildHash(manifest);
2987
+ if (buildHash === context4.lastRegisteredHash) continue;
2988
+ context4.lastRegisteredHash = buildHash;
2989
+ void registerBuild({ ...context4, manifest, buildHash }).catch(() => {
2990
+ context4.lastRegisteredHash = void 0;
2991
+ });
2992
+ }
2993
+ }, RE_REGISTER_DEBOUNCE_MS);
2994
+ if (typeof reRegisterTimer === "object" && "unref" in reRegisterTimer) {
2995
+ reRegisterTimer.unref();
2996
+ }
2997
+ }
2952
2998
  async function registerBuild(params) {
2953
2999
  const auth = Buffer.from(`${params.publicKey}:${params.secretKey}`).toString(
2954
3000
  "base64"
@@ -3229,6 +3275,14 @@ function scheduleBuildRegistration(config, built) {
3229
3275
  return;
3230
3276
  }
3231
3277
  const { manifest, buildHash } = built.buildInfo;
3278
+ trackActiveBuild({
3279
+ host: built.connection.host,
3280
+ publicKey: built.connection.publicKey,
3281
+ secretKey: built.connection.secretKey,
3282
+ agentId: config.agent,
3283
+ version: config.version,
3284
+ lastRegisteredHash: buildHash
3285
+ });
3232
3286
  void registerBuild({
3233
3287
  host: built.connection.host,
3234
3288
  publicKey: built.connection.publicKey,
@@ -3615,12 +3669,14 @@ var tracing = {
3615
3669
  gateway,
3616
3670
  getExperimentContext,
3617
3671
  getRegisteredPrompts,
3672
+ getRegisteredSkills,
3618
3673
  getRegisteredTools,
3619
3674
  identify,
3620
3675
  loadSession,
3621
3676
  memory,
3622
3677
  personas,
3623
3678
  registerPrompt,
3679
+ registerSkill,
3624
3680
  renderAgentSystem,
3625
3681
  replay,
3626
3682
  resetBuildRegistry,