@withgateway/sdk 0.1.11 → 0.1.12

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.11",
24
+ version: "0.1.12",
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",
@@ -2764,6 +2764,7 @@ function sha256(text) {
2764
2764
  var registeredTools = /* @__PURE__ */ new Map();
2765
2765
  var registeredPrompts = /* @__PURE__ */ new Map();
2766
2766
  var registeredSkills = /* @__PURE__ */ new Map();
2767
+ var registeredArtifacts = /* @__PURE__ */ new Map();
2767
2768
  function captureSource() {
2768
2769
  const stack = new Error().stack?.split("\n") ?? [];
2769
2770
  for (const line of stack.slice(1)) {
@@ -2797,9 +2798,24 @@ function defineTool(tool) {
2797
2798
  notifyRegistryChanged();
2798
2799
  return tool;
2799
2800
  }
2800
- function registerPrompt(name, content) {
2801
- registeredPrompts.set(name, sha256(content));
2801
+ function registerArtifact(kind, name, options = {}) {
2802
+ const source = captureSource();
2803
+ const identity = {
2804
+ kind,
2805
+ name,
2806
+ ...options.version !== void 0 ? { version: options.version } : {},
2807
+ ...options.content !== void 0 ? { contentHash: sha256(options.content) } : {},
2808
+ ...options.ref !== void 0 ? { ref: options.ref } : {},
2809
+ ...source ? { source } : {},
2810
+ ...options.metadata ? { metadata: options.metadata } : {}
2811
+ };
2812
+ registeredArtifacts.set(`${kind}:${name}`, identity);
2802
2813
  notifyRegistryChanged();
2814
+ return identity;
2815
+ }
2816
+ function registerPrompt(name, content, options = {}) {
2817
+ registeredPrompts.set(name, sha256(content));
2818
+ registerArtifact("prompt", name, { ...options, content });
2803
2819
  return content;
2804
2820
  }
2805
2821
  function getRegisteredTools() {
@@ -2807,9 +2823,14 @@ function getRegisteredTools() {
2807
2823
  (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
2808
2824
  );
2809
2825
  }
2810
- function registerSkill(name, version) {
2826
+ function registerSkill(name, version, options = {}) {
2811
2827
  registeredSkills.set(name, version);
2812
- notifyRegistryChanged();
2828
+ registerArtifact("skill", name, { version, ...options });
2829
+ }
2830
+ function getRegisteredArtifacts() {
2831
+ return [...registeredArtifacts.values()].sort(
2832
+ (a, b) => `${a.kind}:${a.name}` < `${b.kind}:${b.name}` ? -1 : 1
2833
+ );
2813
2834
  }
2814
2835
  function getRegisteredSkills() {
2815
2836
  return Object.fromEntries(
@@ -2829,6 +2850,7 @@ function resetBuildRegistry() {
2829
2850
  registeredTools.clear();
2830
2851
  registeredPrompts.clear();
2831
2852
  registeredSkills.clear();
2853
+ registeredArtifacts.clear();
2832
2854
  activeBuilds.length = 0;
2833
2855
  if (reRegisterTimer) clearTimeout(reRegisterTimer);
2834
2856
  reRegisterTimer = null;
@@ -2841,11 +2863,62 @@ function sdkVersion() {
2841
2863
  return "@withgateway/sdk";
2842
2864
  }
2843
2865
  }
2866
+ function paasGitContext() {
2867
+ const env = process.env;
2868
+ if (env.VERCEL_GIT_COMMIT_SHA) {
2869
+ const isGithub = (env.VERCEL_GIT_PROVIDER ?? "github") === "github";
2870
+ return {
2871
+ provider: "vercel",
2872
+ sha: env.VERCEL_GIT_COMMIT_SHA,
2873
+ repo: isGithub && env.VERCEL_GIT_REPO_OWNER && env.VERCEL_GIT_REPO_SLUG ? `${env.VERCEL_GIT_REPO_OWNER}/${env.VERCEL_GIT_REPO_SLUG}` : void 0,
2874
+ branch: env.VERCEL_GIT_COMMIT_REF,
2875
+ login: env.VERCEL_GIT_COMMIT_AUTHOR_LOGIN
2876
+ };
2877
+ }
2878
+ if (env.RENDER_GIT_COMMIT) {
2879
+ return {
2880
+ provider: "render",
2881
+ sha: env.RENDER_GIT_COMMIT,
2882
+ repo: env.RENDER_GIT_REPO_SLUG,
2883
+ // already "owner/repo"
2884
+ branch: env.RENDER_GIT_BRANCH
2885
+ };
2886
+ }
2887
+ if (env.RAILWAY_GIT_COMMIT_SHA) {
2888
+ return {
2889
+ provider: "railway",
2890
+ sha: env.RAILWAY_GIT_COMMIT_SHA,
2891
+ repo: env.RAILWAY_GIT_REPO_OWNER && env.RAILWAY_GIT_REPO_NAME ? `${env.RAILWAY_GIT_REPO_OWNER}/${env.RAILWAY_GIT_REPO_NAME}` : void 0,
2892
+ branch: env.RAILWAY_GIT_BRANCH,
2893
+ login: env.RAILWAY_GIT_AUTHOR
2894
+ };
2895
+ }
2896
+ if (env.NETLIFY && env.COMMIT_REF) {
2897
+ const repoMatch = /github\.com[/:]([^/]+\/[^/.]+)/.exec(
2898
+ env.REPOSITORY_URL ?? ""
2899
+ );
2900
+ return {
2901
+ provider: "netlify",
2902
+ sha: env.COMMIT_REF,
2903
+ repo: repoMatch?.[1],
2904
+ branch: env.BRANCH
2905
+ };
2906
+ }
2907
+ const bareSha = env.HEROKU_SLUG_COMMIT ?? env.SOURCE_VERSION ?? env.GIT_COMMIT ?? env.COMMIT_SHA;
2908
+ if (bareSha) {
2909
+ return {
2910
+ provider: env.HEROKU_SLUG_COMMIT || env.SOURCE_VERSION ? "heroku" : "generic",
2911
+ sha: bareSha
2912
+ };
2913
+ }
2914
+ return null;
2915
+ }
2844
2916
  function codeRef() {
2917
+ const paas = paasGitContext();
2845
2918
  const sha = process.env.GATEWAY_COMMIT ?? process.env.GITHUB_SHA ?? process.env.CI_COMMIT_SHA ?? // GitLab
2846
- process.env.CIRCLE_SHA1;
2919
+ process.env.CIRCLE_SHA1 ?? paas?.sha;
2847
2920
  if (!sha) return void 0;
2848
- const repo = process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH;
2921
+ const repo = process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH ?? paas?.repo;
2849
2922
  return repo ? `git:${repo}@${sha}` : `git:${sha}`;
2850
2923
  }
2851
2924
  function assembleManifest(agentId) {
@@ -2855,13 +2928,17 @@ function assembleManifest(agentId) {
2855
2928
  sdk: sdkVersion(),
2856
2929
  tools: getRegisteredTools(),
2857
2930
  prompts: getRegisteredPrompts(),
2858
- skills: getRegisteredSkills()
2931
+ skills: getRegisteredSkills(),
2932
+ artifacts: getRegisteredArtifacts()
2859
2933
  };
2860
2934
  }
2861
2935
  function computeBuildHash(manifest) {
2862
2936
  const identity = {
2863
2937
  ...manifest,
2864
- tools: manifest.tools.map(({ source: _source, ...tool }) => tool)
2938
+ tools: manifest.tools.map(({ source: _source, ...tool }) => tool),
2939
+ artifacts: manifest.artifacts.map(
2940
+ ({ source: _source, ...artifact }) => artifact
2941
+ )
2865
2942
  };
2866
2943
  return sha256(canonicalJson(identity));
2867
2944
  }
@@ -2874,6 +2951,14 @@ function attributionFromEnv() {
2874
2951
  if (process.env.GITHUB_REPOSITORY) attribution.repo = process.env.GITHUB_REPOSITORY;
2875
2952
  const branch = process.env.GITHUB_HEAD_REF ?? process.env.GITHUB_REF_NAME;
2876
2953
  if (branch) attribution.branch = branch;
2954
+ const paas = paasGitContext();
2955
+ if (paas) {
2956
+ if (attribution.source === "runtime") attribution.source = `paas:${paas.provider}`;
2957
+ if (!attribution.commitSha && paas.sha) attribution.commitSha = paas.sha;
2958
+ if (!attribution.repo && paas.repo) attribution.repo = paas.repo;
2959
+ if (!attribution.branch && paas.branch) attribution.branch = paas.branch;
2960
+ if (!attribution.githubLogin && paas.login) attribution.githubLogin = paas.login;
2961
+ }
2877
2962
  const ref = process.env.GITHUB_REF ?? "";
2878
2963
  const prMatch = /refs\/pull\/(\d+)\//.exec(ref);
2879
2964
  if (prMatch) attribution.prNumber = Number(prMatch[1]);
@@ -3589,6 +3674,7 @@ export {
3589
3674
  singleton_exports as experiments,
3590
3675
  gateway,
3591
3676
  getExperimentContext,
3677
+ getRegisteredArtifacts,
3592
3678
  getRegisteredPrompts,
3593
3679
  getRegisteredSkills,
3594
3680
  getRegisteredTools,
@@ -3596,6 +3682,7 @@ export {
3596
3682
  loadSession,
3597
3683
  memory,
3598
3684
  personas,
3685
+ registerArtifact,
3599
3686
  registerPrompt,
3600
3687
  registerSkill,
3601
3688
  renderAgentSystem,