@withgateway/sdk 0.1.9 → 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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -2
- package/dist/index.mjs.map +1 -1
- package/dist/tracing/index.js +32 -2
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +32 -2
- package/dist/tracing/index.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
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) {
|
|
@@ -2858,8 +2877,42 @@ function attributionFromEnv() {
|
|
|
2858
2877
|
const ref = process.env.GITHUB_REF ?? "";
|
|
2859
2878
|
const prMatch = /refs\/pull\/(\d+)\//.exec(ref);
|
|
2860
2879
|
if (prMatch) attribution.prNumber = Number(prMatch[1]);
|
|
2880
|
+
if (process.env.GATEWAY_PR_TITLE) {
|
|
2881
|
+
attribution.prTitle = process.env.GATEWAY_PR_TITLE.slice(0, 300);
|
|
2882
|
+
}
|
|
2883
|
+
if (process.env.GATEWAY_PR_BODY) {
|
|
2884
|
+
attribution.prDescription = process.env.GATEWAY_PR_BODY.slice(0, 2e3);
|
|
2885
|
+
}
|
|
2886
|
+
if (attribution.repo && attribution.prNumber && !("prUrl" in attribution)) {
|
|
2887
|
+
attribution.prUrl = `https://github.com/${String(attribution.repo)}/pull/${String(attribution.prNumber)}`;
|
|
2888
|
+
}
|
|
2861
2889
|
return attribution;
|
|
2862
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
|
+
}
|
|
2863
2916
|
async function registerBuild(params) {
|
|
2864
2917
|
const auth = Buffer.from(`${params.publicKey}:${params.secretKey}`).toString(
|
|
2865
2918
|
"base64"
|
|
@@ -3140,6 +3193,14 @@ function scheduleBuildRegistration(config, built) {
|
|
|
3140
3193
|
return;
|
|
3141
3194
|
}
|
|
3142
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
|
+
});
|
|
3143
3204
|
void registerBuild({
|
|
3144
3205
|
host: built.connection.host,
|
|
3145
3206
|
publicKey: built.connection.publicKey,
|
|
@@ -3529,12 +3590,14 @@ export {
|
|
|
3529
3590
|
gateway,
|
|
3530
3591
|
getExperimentContext,
|
|
3531
3592
|
getRegisteredPrompts,
|
|
3593
|
+
getRegisteredSkills,
|
|
3532
3594
|
getRegisteredTools,
|
|
3533
3595
|
identify,
|
|
3534
3596
|
loadSession,
|
|
3535
3597
|
memory,
|
|
3536
3598
|
personas,
|
|
3537
3599
|
registerPrompt,
|
|
3600
|
+
registerSkill,
|
|
3538
3601
|
renderAgentSystem,
|
|
3539
3602
|
replay,
|
|
3540
3603
|
resetBuildRegistry,
|