@withgateway/sdk 0.1.8 → 0.1.10
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-CubrUmOe.d.mts → index-CTc8iOrx.d.mts} +13 -0
- package/dist/{index-CubrUmOe.d.ts → index-CTc8iOrx.d.ts} +13 -0
- package/dist/index.d.mts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +359 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +352 -3
- package/dist/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +303 -3
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +304 -3
- package/dist/tracing/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -99,6 +99,19 @@ interface TracingConfig {
|
|
|
99
99
|
* Sets resource attribute for filtering traces in Gateway.
|
|
100
100
|
*/
|
|
101
101
|
environment?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Agent identity (gateway.agent.id). When set, the SDK assembles the
|
|
104
|
+
* build manifest from everything registered so far (defineTool /
|
|
105
|
+
* registerPrompt), stamps gateway.build.hash on every span, and
|
|
106
|
+
* auto-registers the build with Gateway (idempotent on hash). Define
|
|
107
|
+
* tools BEFORE init so they join the build identity.
|
|
108
|
+
*/
|
|
109
|
+
agent?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Set false to stamp build identity without registering it with Gateway.
|
|
112
|
+
* Defaults to true when `agent` is set.
|
|
113
|
+
*/
|
|
114
|
+
registerBuild?: boolean;
|
|
102
115
|
/**
|
|
103
116
|
* Application version (e.g., "1.2.3", git SHA).
|
|
104
117
|
* Sets resource attribute for tracking regressions.
|
|
@@ -99,6 +99,19 @@ interface TracingConfig {
|
|
|
99
99
|
* Sets resource attribute for filtering traces in Gateway.
|
|
100
100
|
*/
|
|
101
101
|
environment?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Agent identity (gateway.agent.id). When set, the SDK assembles the
|
|
104
|
+
* build manifest from everything registered so far (defineTool /
|
|
105
|
+
* registerPrompt), stamps gateway.build.hash on every span, and
|
|
106
|
+
* auto-registers the build with Gateway (idempotent on hash). Define
|
|
107
|
+
* tools BEFORE init so they join the build identity.
|
|
108
|
+
*/
|
|
109
|
+
agent?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Set false to stamp build identity without registering it with Gateway.
|
|
112
|
+
* Defaults to true when `agent` is set.
|
|
113
|
+
*/
|
|
114
|
+
registerBuild?: boolean;
|
|
102
115
|
/**
|
|
103
116
|
* Application version (e.g., "1.2.3", git SHA).
|
|
104
117
|
* Sets resource attribute for tracking regressions.
|
package/dist/index.d.mts
CHANGED
|
@@ -6,12 +6,68 @@ export { DriftError, LocalTool, MissPolicy, REPLAY_ENVIRONMENT, RecordedToolCall
|
|
|
6
6
|
export { GatewayAgentDescriptor, GatewaySecurity, GatewaySecurityConfig, GatewaySecurityContext, GatewaySecurityError, GatewayToolApprovalRequiredError, GatewayToolBlockedError, GatewayToolCallAuthorizeResponse, GatewayToolDescriptor, GatewayToolsetResolveResponse, SecureToolsOptions, gateway } from './security/index.mjs';
|
|
7
7
|
export { DEFAULT_TIMEOUT_SECONDS, ENV_GATEWAY_HOST, ENV_GATEWAY_PUBLIC_KEY, ENV_GATEWAY_SECRET_KEY, LoadSessionOptions, SessionLoadError, SessionObservation, SessionRecording, SessionTrace, basicAuthHeader, loadSession, sessionObservationFromApi, sessions } from './sessions/index.mjs';
|
|
8
8
|
export { UserEvent, UserEventOptions, UserProfile, UserProfileError, UserProfileUpdate, UsersClient, UsersClientConfig, UsersClientFromEnvConfig, users } from './users/index.mjs';
|
|
9
|
-
import { _ as _tracingModule } from './index-
|
|
10
|
-
export { I as IdentifyOptions, i as identify, r as resolveUserId } from './index-
|
|
9
|
+
import { _ as _tracingModule } from './index-CTc8iOrx.mjs';
|
|
10
|
+
export { I as IdentifyOptions, i as identify, r as resolveUserId } from './index-CTc8iOrx.mjs';
|
|
11
11
|
import 'async_hooks';
|
|
12
12
|
import '@opentelemetry/api';
|
|
13
13
|
import '@opentelemetry/sdk-trace-base';
|
|
14
14
|
|
|
15
|
+
type ToolEffects = "read" | "write" | "irreversible";
|
|
16
|
+
interface ToolIdentity {
|
|
17
|
+
name: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
effects?: ToolEffects;
|
|
20
|
+
schemaHash: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Source location of the defineTool call ("src/tools/checkout.ts:42"). */
|
|
23
|
+
source?: string;
|
|
24
|
+
}
|
|
25
|
+
interface AgentBuildManifest {
|
|
26
|
+
agentId: string;
|
|
27
|
+
codeRef?: string;
|
|
28
|
+
sdk: string;
|
|
29
|
+
tools: ToolIdentity[];
|
|
30
|
+
prompts: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
/** Deterministic JSON: object keys sorted recursively, arrays kept in order. */
|
|
33
|
+
declare function canonicalJson(value: unknown): string;
|
|
34
|
+
interface DefineToolInput {
|
|
35
|
+
name: string;
|
|
36
|
+
/** Developer-declared tool version, e.g. "2.1" (v1: bumped manually). */
|
|
37
|
+
version?: string;
|
|
38
|
+
/** Side-effect class — feeds approval policies and gate severity. */
|
|
39
|
+
effects?: ToolEffects;
|
|
40
|
+
description?: string;
|
|
41
|
+
/** JSON schema (or zod-serializable shape) of the tool's parameters. */
|
|
42
|
+
schema?: unknown;
|
|
43
|
+
/** Alias accepted for frameworks that call it inputSchema. */
|
|
44
|
+
inputSchema?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a tool's identity and pass the definition through unchanged, so
|
|
48
|
+
* it wraps ANY framework's tool shape:
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const checkout = defineTool({
|
|
52
|
+
* name: "checkout", version: "2.1", effects: "write",
|
|
53
|
+
* schema, description, execute,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function defineTool<T extends DefineToolInput>(tool: T): T;
|
|
58
|
+
/**
|
|
59
|
+
* Register a code-shipped prompt so it joins the build identity:
|
|
60
|
+
* `const SYSTEM = registerPrompt("system", "You are…")`. Returns the content
|
|
61
|
+
* unchanged. Platform-served prompts don't need this — pin them by label.
|
|
62
|
+
*/
|
|
63
|
+
declare function registerPrompt(name: string, content: string): string;
|
|
64
|
+
declare function getRegisteredTools(): ToolIdentity[];
|
|
65
|
+
declare function getRegisteredPrompts(): Record<string, string>;
|
|
66
|
+
/** Test hook. */
|
|
67
|
+
declare function resetBuildRegistry(): void;
|
|
68
|
+
declare function assembleManifest(agentId: string): AgentBuildManifest;
|
|
69
|
+
declare function computeBuildHash(manifest: AgentBuildManifest): string;
|
|
70
|
+
|
|
15
71
|
/**
|
|
16
72
|
* Tracing module with automatic ExperimentSpanProcessor wiring.
|
|
17
73
|
*
|
|
@@ -22,4 +78,4 @@ import '@opentelemetry/sdk-trace-base';
|
|
|
22
78
|
*/
|
|
23
79
|
declare const tracing: typeof _tracingModule;
|
|
24
80
|
|
|
25
|
-
export { tracing };
|
|
81
|
+
export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredTools, registerPrompt, resetBuildRegistry, tracing };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,68 @@ export { DriftError, LocalTool, MissPolicy, REPLAY_ENVIRONMENT, RecordedToolCall
|
|
|
6
6
|
export { GatewayAgentDescriptor, GatewaySecurity, GatewaySecurityConfig, GatewaySecurityContext, GatewaySecurityError, GatewayToolApprovalRequiredError, GatewayToolBlockedError, GatewayToolCallAuthorizeResponse, GatewayToolDescriptor, GatewayToolsetResolveResponse, SecureToolsOptions, gateway } from './security/index.js';
|
|
7
7
|
export { DEFAULT_TIMEOUT_SECONDS, ENV_GATEWAY_HOST, ENV_GATEWAY_PUBLIC_KEY, ENV_GATEWAY_SECRET_KEY, LoadSessionOptions, SessionLoadError, SessionObservation, SessionRecording, SessionTrace, basicAuthHeader, loadSession, sessionObservationFromApi, sessions } from './sessions/index.js';
|
|
8
8
|
export { UserEvent, UserEventOptions, UserProfile, UserProfileError, UserProfileUpdate, UsersClient, UsersClientConfig, UsersClientFromEnvConfig, users } from './users/index.js';
|
|
9
|
-
import { _ as _tracingModule } from './index-
|
|
10
|
-
export { I as IdentifyOptions, i as identify, r as resolveUserId } from './index-
|
|
9
|
+
import { _ as _tracingModule } from './index-CTc8iOrx.js';
|
|
10
|
+
export { I as IdentifyOptions, i as identify, r as resolveUserId } from './index-CTc8iOrx.js';
|
|
11
11
|
import 'async_hooks';
|
|
12
12
|
import '@opentelemetry/api';
|
|
13
13
|
import '@opentelemetry/sdk-trace-base';
|
|
14
14
|
|
|
15
|
+
type ToolEffects = "read" | "write" | "irreversible";
|
|
16
|
+
interface ToolIdentity {
|
|
17
|
+
name: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
effects?: ToolEffects;
|
|
20
|
+
schemaHash: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Source location of the defineTool call ("src/tools/checkout.ts:42"). */
|
|
23
|
+
source?: string;
|
|
24
|
+
}
|
|
25
|
+
interface AgentBuildManifest {
|
|
26
|
+
agentId: string;
|
|
27
|
+
codeRef?: string;
|
|
28
|
+
sdk: string;
|
|
29
|
+
tools: ToolIdentity[];
|
|
30
|
+
prompts: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
/** Deterministic JSON: object keys sorted recursively, arrays kept in order. */
|
|
33
|
+
declare function canonicalJson(value: unknown): string;
|
|
34
|
+
interface DefineToolInput {
|
|
35
|
+
name: string;
|
|
36
|
+
/** Developer-declared tool version, e.g. "2.1" (v1: bumped manually). */
|
|
37
|
+
version?: string;
|
|
38
|
+
/** Side-effect class — feeds approval policies and gate severity. */
|
|
39
|
+
effects?: ToolEffects;
|
|
40
|
+
description?: string;
|
|
41
|
+
/** JSON schema (or zod-serializable shape) of the tool's parameters. */
|
|
42
|
+
schema?: unknown;
|
|
43
|
+
/** Alias accepted for frameworks that call it inputSchema. */
|
|
44
|
+
inputSchema?: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a tool's identity and pass the definition through unchanged, so
|
|
48
|
+
* it wraps ANY framework's tool shape:
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const checkout = defineTool({
|
|
52
|
+
* name: "checkout", version: "2.1", effects: "write",
|
|
53
|
+
* schema, description, execute,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function defineTool<T extends DefineToolInput>(tool: T): T;
|
|
58
|
+
/**
|
|
59
|
+
* Register a code-shipped prompt so it joins the build identity:
|
|
60
|
+
* `const SYSTEM = registerPrompt("system", "You are…")`. Returns the content
|
|
61
|
+
* unchanged. Platform-served prompts don't need this — pin them by label.
|
|
62
|
+
*/
|
|
63
|
+
declare function registerPrompt(name: string, content: string): string;
|
|
64
|
+
declare function getRegisteredTools(): ToolIdentity[];
|
|
65
|
+
declare function getRegisteredPrompts(): Record<string, string>;
|
|
66
|
+
/** Test hook. */
|
|
67
|
+
declare function resetBuildRegistry(): void;
|
|
68
|
+
declare function assembleManifest(agentId: string): AgentBuildManifest;
|
|
69
|
+
declare function computeBuildHash(manifest: AgentBuildManifest): string;
|
|
70
|
+
|
|
15
71
|
/**
|
|
16
72
|
* Tracing module with automatic ExperimentSpanProcessor wiring.
|
|
17
73
|
*
|
|
@@ -22,4 +78,4 @@ import '@opentelemetry/sdk-trace-base';
|
|
|
22
78
|
*/
|
|
23
79
|
declare const tracing: typeof _tracingModule;
|
|
24
80
|
|
|
25
|
-
export { tracing };
|
|
81
|
+
export { type AgentBuildManifest, type DefineToolInput, type ToolEffects, type ToolIdentity, assembleManifest, canonicalJson, computeBuildHash, defineTool, getRegisteredPrompts, getRegisteredTools, registerPrompt, resetBuildRegistry, tracing };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
7
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
8
|
+
};
|
|
6
9
|
var __export = (target, all) => {
|
|
7
10
|
for (var name in all)
|
|
8
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,6 +20,148 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
20
|
};
|
|
18
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
22
|
|
|
23
|
+
// package.json
|
|
24
|
+
var require_package = __commonJS({
|
|
25
|
+
"package.json"(exports2, module2) {
|
|
26
|
+
module2.exports = {
|
|
27
|
+
name: "@withgateway/sdk",
|
|
28
|
+
version: "0.1.10",
|
|
29
|
+
description: "Gateway SDK for TypeScript - A/B experiments, tracing, and observability",
|
|
30
|
+
main: "./dist/index.js",
|
|
31
|
+
module: "./dist/index.mjs",
|
|
32
|
+
types: "./dist/index.d.ts",
|
|
33
|
+
exports: {
|
|
34
|
+
".": {
|
|
35
|
+
types: "./dist/index.d.ts",
|
|
36
|
+
import: "./dist/index.mjs",
|
|
37
|
+
require: "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./experiments": {
|
|
40
|
+
types: "./dist/experiments/index.d.ts",
|
|
41
|
+
import: "./dist/experiments/index.mjs",
|
|
42
|
+
require: "./dist/experiments/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./context": {
|
|
45
|
+
types: "./dist/context/index.d.ts",
|
|
46
|
+
import: "./dist/context/index.mjs",
|
|
47
|
+
require: "./dist/context/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./memory": {
|
|
50
|
+
types: "./dist/memory/index.d.ts",
|
|
51
|
+
import: "./dist/memory/index.mjs",
|
|
52
|
+
require: "./dist/memory/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./personas": {
|
|
55
|
+
types: "./dist/personas/index.d.ts",
|
|
56
|
+
import: "./dist/personas/index.mjs",
|
|
57
|
+
require: "./dist/personas/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./replay": {
|
|
60
|
+
types: "./dist/replay/index.d.ts",
|
|
61
|
+
import: "./dist/replay/index.mjs",
|
|
62
|
+
require: "./dist/replay/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./sessions": {
|
|
65
|
+
types: "./dist/sessions/index.d.ts",
|
|
66
|
+
import: "./dist/sessions/index.mjs",
|
|
67
|
+
require: "./dist/sessions/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./tracing": {
|
|
70
|
+
types: "./dist/tracing/index.d.ts",
|
|
71
|
+
import: "./dist/tracing/index.mjs",
|
|
72
|
+
require: "./dist/tracing/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./security": {
|
|
75
|
+
types: "./dist/security/index.d.ts",
|
|
76
|
+
import: "./dist/security/index.mjs",
|
|
77
|
+
require: "./dist/security/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./users": {
|
|
80
|
+
types: "./dist/users/index.d.ts",
|
|
81
|
+
import: "./dist/users/index.mjs",
|
|
82
|
+
require: "./dist/users/index.js"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
files: [
|
|
86
|
+
"dist",
|
|
87
|
+
"README.md"
|
|
88
|
+
],
|
|
89
|
+
publishConfig: {
|
|
90
|
+
access: "public"
|
|
91
|
+
},
|
|
92
|
+
scripts: {
|
|
93
|
+
build: "tsup",
|
|
94
|
+
dev: "tsup --watch",
|
|
95
|
+
typecheck: "tsc --noEmit",
|
|
96
|
+
test: "vitest",
|
|
97
|
+
"test:run": "vitest run",
|
|
98
|
+
lint: "eslint src --ext .ts",
|
|
99
|
+
clean: "rm -rf dist",
|
|
100
|
+
example: "tsx examples/test-ab-experiment.ts",
|
|
101
|
+
"test:crm": "tsx examples/test-crm-ab-experiment.ts",
|
|
102
|
+
"test:crm:balanced": "tsx examples/test-crm-ab-experiment.ts --balanced",
|
|
103
|
+
"test:crm:full": "tsx examples/test-crm-ab-experiment.ts --users 12 --all-tasks --concurrency 3"
|
|
104
|
+
},
|
|
105
|
+
keywords: [
|
|
106
|
+
"gateway",
|
|
107
|
+
"ab-testing",
|
|
108
|
+
"experiments",
|
|
109
|
+
"opentelemetry",
|
|
110
|
+
"tracing",
|
|
111
|
+
"observability",
|
|
112
|
+
"llm"
|
|
113
|
+
],
|
|
114
|
+
author: "Gateway Team",
|
|
115
|
+
license: "MIT",
|
|
116
|
+
engines: {
|
|
117
|
+
node: ">=18.0.0"
|
|
118
|
+
},
|
|
119
|
+
peerDependencies: {
|
|
120
|
+
"@opentelemetry/api": "^1.0.0",
|
|
121
|
+
"@opentelemetry/exporter-trace-otlp-http": ">=0.50.0",
|
|
122
|
+
"@opentelemetry/resources": ">=1.0.0",
|
|
123
|
+
"@opentelemetry/sdk-trace-base": ">=1.0.0",
|
|
124
|
+
"@opentelemetry/sdk-trace-node": ">=1.0.0"
|
|
125
|
+
},
|
|
126
|
+
peerDependenciesMeta: {
|
|
127
|
+
"@opentelemetry/api": {
|
|
128
|
+
optional: true
|
|
129
|
+
},
|
|
130
|
+
"@opentelemetry/sdk-trace-base": {
|
|
131
|
+
optional: true
|
|
132
|
+
},
|
|
133
|
+
"@opentelemetry/sdk-trace-node": {
|
|
134
|
+
optional: true
|
|
135
|
+
},
|
|
136
|
+
"@opentelemetry/exporter-trace-otlp-http": {
|
|
137
|
+
optional: true
|
|
138
|
+
},
|
|
139
|
+
"@opentelemetry/resources": {
|
|
140
|
+
optional: true
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
optionalDependencies: {
|
|
144
|
+
"@arizeai/openinference-instrumentation-anthropic": "^0.1.15",
|
|
145
|
+
"@arizeai/openinference-instrumentation-openai": "^4.1.5"
|
|
146
|
+
},
|
|
147
|
+
devDependencies: {
|
|
148
|
+
"@anthropic-ai/sdk": "^0.79.0",
|
|
149
|
+
"@opentelemetry/api": "^1.9.0",
|
|
150
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.212.0",
|
|
151
|
+
"@opentelemetry/resources": "^2.6.0",
|
|
152
|
+
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
153
|
+
"@opentelemetry/sdk-trace-node": "^2.6.0",
|
|
154
|
+
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
155
|
+
"@types/node": "^20.0.0",
|
|
156
|
+
tsup: "^8.0.0",
|
|
157
|
+
tsx: "^4.0.0",
|
|
158
|
+
typescript: "^5.0.0",
|
|
159
|
+
vitest: "^2.0.0"
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
20
165
|
// src/index.ts
|
|
21
166
|
var src_exports = {};
|
|
22
167
|
__export(src_exports, {
|
|
@@ -58,21 +203,29 @@ __export(src_exports, {
|
|
|
58
203
|
UserProfileError: () => UserProfileError,
|
|
59
204
|
UsersClient: () => UsersClient,
|
|
60
205
|
addExperimentAttributes: () => addExperimentAttributes,
|
|
206
|
+
assembleManifest: () => assembleManifest,
|
|
61
207
|
assignVariant: () => assignVariant,
|
|
62
208
|
basicAuthHeader: () => basicAuthHeader,
|
|
209
|
+
canonicalJson: () => canonicalJson,
|
|
63
210
|
clearExperimentContext: () => clearExperimentContext,
|
|
211
|
+
computeBuildHash: () => computeBuildHash,
|
|
64
212
|
computeHash: () => computeHash,
|
|
65
213
|
context: () => context,
|
|
214
|
+
defineTool: () => defineTool,
|
|
66
215
|
experimentContextStorage: () => experimentContextStorage,
|
|
67
216
|
experiments: () => singleton_exports,
|
|
68
217
|
gateway: () => gateway,
|
|
69
218
|
getExperimentContext: () => getExperimentContext,
|
|
219
|
+
getRegisteredPrompts: () => getRegisteredPrompts,
|
|
220
|
+
getRegisteredTools: () => getRegisteredTools,
|
|
70
221
|
identify: () => identify,
|
|
71
222
|
loadSession: () => loadSession,
|
|
72
223
|
memory: () => memory,
|
|
73
224
|
personas: () => personas,
|
|
225
|
+
registerPrompt: () => registerPrompt,
|
|
74
226
|
renderAgentSystem: () => renderAgentSystem,
|
|
75
227
|
replay: () => replay,
|
|
228
|
+
resetBuildRegistry: () => resetBuildRegistry,
|
|
76
229
|
resolveUserId: () => resolveUserId,
|
|
77
230
|
runSuite: () => runSuite,
|
|
78
231
|
runWithExperimentContext: () => runWithExperimentContext,
|
|
@@ -2673,6 +2826,158 @@ var users = {
|
|
|
2673
2826
|
fromEnv: UsersClient.fromEnv
|
|
2674
2827
|
};
|
|
2675
2828
|
|
|
2829
|
+
// src/build/index.ts
|
|
2830
|
+
var import_node_crypto = require("crypto");
|
|
2831
|
+
function canonicalJson(value) {
|
|
2832
|
+
if (value === null || typeof value !== "object") {
|
|
2833
|
+
return JSON.stringify(value);
|
|
2834
|
+
}
|
|
2835
|
+
if (Array.isArray(value)) {
|
|
2836
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
2837
|
+
}
|
|
2838
|
+
const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
2839
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`).join(",")}}`;
|
|
2840
|
+
}
|
|
2841
|
+
function sha256(text) {
|
|
2842
|
+
return `sha256:${(0, import_node_crypto.createHash)("sha256").update(text).digest("hex")}`;
|
|
2843
|
+
}
|
|
2844
|
+
var registeredTools = /* @__PURE__ */ new Map();
|
|
2845
|
+
var registeredPrompts = /* @__PURE__ */ new Map();
|
|
2846
|
+
function captureSource() {
|
|
2847
|
+
const stack = new Error().stack?.split("\n") ?? [];
|
|
2848
|
+
for (const line of stack.slice(1)) {
|
|
2849
|
+
if (line.includes("build/index.ts") || line.includes("build/index.js") || line.includes("build/index.mjs") || line.includes("node_modules/@withgateway/")) {
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
if (line.includes("node:internal") || line.includes("(node:")) continue;
|
|
2853
|
+
const match = /\(?([^()\s]+):(\d+):\d+\)?$/.exec(line.trim());
|
|
2854
|
+
if (match) {
|
|
2855
|
+
const file = match[1].replace(/^file:\/\//, "");
|
|
2856
|
+
const short = file.includes("/") ? file.split("/").slice(-4).join("/") : file;
|
|
2857
|
+
return `${short}:${match[2]}`;
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
return void 0;
|
|
2861
|
+
}
|
|
2862
|
+
function defineTool(tool) {
|
|
2863
|
+
const schemaBasis = tool.schema ?? tool.inputSchema ?? null;
|
|
2864
|
+
const source = captureSource();
|
|
2865
|
+
const identity = {
|
|
2866
|
+
name: tool.name,
|
|
2867
|
+
...tool.version !== void 0 ? { version: tool.version } : {},
|
|
2868
|
+
...tool.effects !== void 0 ? { effects: tool.effects } : {},
|
|
2869
|
+
...tool.description !== void 0 ? { description: tool.description.slice(0, 500) } : {},
|
|
2870
|
+
schemaHash: sha256(
|
|
2871
|
+
canonicalJson({ schema: schemaBasis, description: tool.description ?? "" })
|
|
2872
|
+
),
|
|
2873
|
+
...source ? { source } : {}
|
|
2874
|
+
};
|
|
2875
|
+
registeredTools.set(tool.name, identity);
|
|
2876
|
+
return tool;
|
|
2877
|
+
}
|
|
2878
|
+
function registerPrompt(name, content) {
|
|
2879
|
+
registeredPrompts.set(name, sha256(content));
|
|
2880
|
+
return content;
|
|
2881
|
+
}
|
|
2882
|
+
function getRegisteredTools() {
|
|
2883
|
+
return [...registeredTools.values()].sort(
|
|
2884
|
+
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
|
|
2885
|
+
);
|
|
2886
|
+
}
|
|
2887
|
+
function getRegisteredPrompts() {
|
|
2888
|
+
return Object.fromEntries(
|
|
2889
|
+
[...registeredPrompts.entries()].sort(
|
|
2890
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
2891
|
+
)
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
function resetBuildRegistry() {
|
|
2895
|
+
registeredTools.clear();
|
|
2896
|
+
registeredPrompts.clear();
|
|
2897
|
+
}
|
|
2898
|
+
function sdkVersion() {
|
|
2899
|
+
try {
|
|
2900
|
+
const pkg = require_package();
|
|
2901
|
+
return `@withgateway/sdk@${pkg.version ?? "unknown"}`;
|
|
2902
|
+
} catch {
|
|
2903
|
+
return "@withgateway/sdk";
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
function codeRef() {
|
|
2907
|
+
const sha = process.env.GATEWAY_COMMIT ?? process.env.GITHUB_SHA ?? process.env.CI_COMMIT_SHA ?? // GitLab
|
|
2908
|
+
process.env.CIRCLE_SHA1;
|
|
2909
|
+
if (!sha) return void 0;
|
|
2910
|
+
const repo = process.env.GITHUB_REPOSITORY ?? process.env.CI_PROJECT_PATH;
|
|
2911
|
+
return repo ? `git:${repo}@${sha}` : `git:${sha}`;
|
|
2912
|
+
}
|
|
2913
|
+
function assembleManifest(agentId) {
|
|
2914
|
+
return {
|
|
2915
|
+
agentId,
|
|
2916
|
+
...codeRef() ? { codeRef: codeRef() } : {},
|
|
2917
|
+
sdk: sdkVersion(),
|
|
2918
|
+
tools: getRegisteredTools(),
|
|
2919
|
+
prompts: getRegisteredPrompts()
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
function computeBuildHash(manifest) {
|
|
2923
|
+
const identity = {
|
|
2924
|
+
...manifest,
|
|
2925
|
+
tools: manifest.tools.map(({ source: _source, ...tool }) => tool)
|
|
2926
|
+
};
|
|
2927
|
+
return sha256(canonicalJson(identity));
|
|
2928
|
+
}
|
|
2929
|
+
function attributionFromEnv() {
|
|
2930
|
+
const attribution = { source: "runtime" };
|
|
2931
|
+
if (process.env.GITHUB_ACTIONS) attribution.source = "ci";
|
|
2932
|
+
if (process.env.GITHUB_ACTOR) attribution.githubLogin = process.env.GITHUB_ACTOR;
|
|
2933
|
+
const sha = process.env.GATEWAY_COMMIT ?? process.env.GITHUB_SHA;
|
|
2934
|
+
if (sha) attribution.commitSha = sha;
|
|
2935
|
+
if (process.env.GITHUB_REPOSITORY) attribution.repo = process.env.GITHUB_REPOSITORY;
|
|
2936
|
+
const branch = process.env.GITHUB_HEAD_REF ?? process.env.GITHUB_REF_NAME;
|
|
2937
|
+
if (branch) attribution.branch = branch;
|
|
2938
|
+
const ref = process.env.GITHUB_REF ?? "";
|
|
2939
|
+
const prMatch = /refs\/pull\/(\d+)\//.exec(ref);
|
|
2940
|
+
if (prMatch) attribution.prNumber = Number(prMatch[1]);
|
|
2941
|
+
if (process.env.GATEWAY_PR_TITLE) {
|
|
2942
|
+
attribution.prTitle = process.env.GATEWAY_PR_TITLE.slice(0, 300);
|
|
2943
|
+
}
|
|
2944
|
+
if (process.env.GATEWAY_PR_BODY) {
|
|
2945
|
+
attribution.prDescription = process.env.GATEWAY_PR_BODY.slice(0, 2e3);
|
|
2946
|
+
}
|
|
2947
|
+
if (attribution.repo && attribution.prNumber && !("prUrl" in attribution)) {
|
|
2948
|
+
attribution.prUrl = `https://github.com/${String(attribution.repo)}/pull/${String(attribution.prNumber)}`;
|
|
2949
|
+
}
|
|
2950
|
+
return attribution;
|
|
2951
|
+
}
|
|
2952
|
+
async function registerBuild(params) {
|
|
2953
|
+
const auth = Buffer.from(`${params.publicKey}:${params.secretKey}`).toString(
|
|
2954
|
+
"base64"
|
|
2955
|
+
);
|
|
2956
|
+
const response = await fetch(
|
|
2957
|
+
`${params.host.replace(/\/$/, "")}/api/public/agent-builds`,
|
|
2958
|
+
{
|
|
2959
|
+
method: "POST",
|
|
2960
|
+
headers: {
|
|
2961
|
+
Authorization: `Basic ${auth}`,
|
|
2962
|
+
"Content-Type": "application/json"
|
|
2963
|
+
},
|
|
2964
|
+
body: JSON.stringify({
|
|
2965
|
+
agentId: params.agentId,
|
|
2966
|
+
buildHash: params.buildHash,
|
|
2967
|
+
...params.version ? { semanticVer: params.version } : {},
|
|
2968
|
+
manifest: params.manifest,
|
|
2969
|
+
attribution: attributionFromEnv()
|
|
2970
|
+
}),
|
|
2971
|
+
signal: AbortSignal.timeout(15e3)
|
|
2972
|
+
}
|
|
2973
|
+
);
|
|
2974
|
+
if (!response.ok) {
|
|
2975
|
+
throw new Error(
|
|
2976
|
+
`build registration failed (${response.status}): ${(await response.text()).slice(0, 300)}`
|
|
2977
|
+
);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2676
2981
|
// src/tracing/identity.ts
|
|
2677
2982
|
var import_async_hooks2 = require("async_hooks");
|
|
2678
2983
|
var import_api = require("@opentelemetry/api");
|
|
@@ -2836,6 +3141,24 @@ function buildProvider(config, logFn) {
|
|
|
2836
3141
|
if (config.version) {
|
|
2837
3142
|
resourceAttrs["gateway.version"] = config.version;
|
|
2838
3143
|
}
|
|
3144
|
+
let buildInfo = null;
|
|
3145
|
+
if (config.agent) {
|
|
3146
|
+
const manifest = assembleManifest(config.agent);
|
|
3147
|
+
const buildHash = computeBuildHash(manifest);
|
|
3148
|
+
buildInfo = { manifest, buildHash };
|
|
3149
|
+
resourceAttrs["gateway.agent.id"] = config.agent;
|
|
3150
|
+
resourceAttrs["gateway.build.hash"] = buildHash;
|
|
3151
|
+
if (config.version) {
|
|
3152
|
+
resourceAttrs["gateway.agent.version"] = config.version;
|
|
3153
|
+
}
|
|
3154
|
+
logFn(
|
|
3155
|
+
"Agent build identity: %s @ %s (%d tools, %d prompts)",
|
|
3156
|
+
config.agent,
|
|
3157
|
+
buildHash.slice(0, 15),
|
|
3158
|
+
manifest.tools.length,
|
|
3159
|
+
Object.keys(manifest.prompts).length
|
|
3160
|
+
);
|
|
3161
|
+
}
|
|
2839
3162
|
let isLocalhost = false;
|
|
2840
3163
|
if (endpoint) {
|
|
2841
3164
|
try {
|
|
@@ -2895,7 +3218,28 @@ function buildProvider(config, logFn) {
|
|
|
2895
3218
|
spanProcessors
|
|
2896
3219
|
});
|
|
2897
3220
|
}
|
|
2898
|
-
return
|
|
3221
|
+
return {
|
|
3222
|
+
provider,
|
|
3223
|
+
buildInfo,
|
|
3224
|
+
connection: { host, publicKey, secretKey }
|
|
3225
|
+
};
|
|
3226
|
+
}
|
|
3227
|
+
function scheduleBuildRegistration(config, built) {
|
|
3228
|
+
if (!config.agent || !built.buildInfo || config.registerBuild === false) {
|
|
3229
|
+
return;
|
|
3230
|
+
}
|
|
3231
|
+
const { manifest, buildHash } = built.buildInfo;
|
|
3232
|
+
void registerBuild({
|
|
3233
|
+
host: built.connection.host,
|
|
3234
|
+
publicKey: built.connection.publicKey,
|
|
3235
|
+
secretKey: built.connection.secretKey,
|
|
3236
|
+
agentId: config.agent,
|
|
3237
|
+
version: config.version,
|
|
3238
|
+
manifest,
|
|
3239
|
+
buildHash
|
|
3240
|
+
}).catch((err) => {
|
|
3241
|
+
warn("Build registration failed (agent keeps running):", err);
|
|
3242
|
+
});
|
|
2899
3243
|
}
|
|
2900
3244
|
function init2(config = {}) {
|
|
2901
3245
|
if (state.initialized) {
|
|
@@ -2903,8 +3247,10 @@ function init2(config = {}) {
|
|
|
2903
3247
|
return;
|
|
2904
3248
|
}
|
|
2905
3249
|
state.debug = config.debug ?? false;
|
|
2906
|
-
const
|
|
3250
|
+
const built = buildProvider(config, log);
|
|
3251
|
+
const provider = built.provider;
|
|
2907
3252
|
provider.register();
|
|
3253
|
+
scheduleBuildRegistration(config, built);
|
|
2908
3254
|
state.provider = provider;
|
|
2909
3255
|
state.initialized = true;
|
|
2910
3256
|
log(
|
|
@@ -2915,7 +3261,9 @@ function init2(config = {}) {
|
|
|
2915
3261
|
function initIsolated(config = {}) {
|
|
2916
3262
|
const debugLog2 = config.debug ? (message, ...args) => console.log(`[gatewaysdk.tracing:isolated] ${message}`, ...args) : () => {
|
|
2917
3263
|
};
|
|
2918
|
-
const
|
|
3264
|
+
const built = buildProvider(config, debugLog2);
|
|
3265
|
+
const provider = built.provider;
|
|
3266
|
+
scheduleBuildRegistration(config, built);
|
|
2919
3267
|
const tracer = provider.getTracer("@withgateway/sdk");
|
|
2920
3268
|
debugLog2(
|
|
2921
3269
|
"Isolated tracing provider created (service=%s)",
|
|
@@ -3253,21 +3601,29 @@ var tracing = {
|
|
|
3253
3601
|
UserProfileError,
|
|
3254
3602
|
UsersClient,
|
|
3255
3603
|
addExperimentAttributes,
|
|
3604
|
+
assembleManifest,
|
|
3256
3605
|
assignVariant,
|
|
3257
3606
|
basicAuthHeader,
|
|
3607
|
+
canonicalJson,
|
|
3258
3608
|
clearExperimentContext,
|
|
3609
|
+
computeBuildHash,
|
|
3259
3610
|
computeHash,
|
|
3260
3611
|
context,
|
|
3612
|
+
defineTool,
|
|
3261
3613
|
experimentContextStorage,
|
|
3262
3614
|
experiments,
|
|
3263
3615
|
gateway,
|
|
3264
3616
|
getExperimentContext,
|
|
3617
|
+
getRegisteredPrompts,
|
|
3618
|
+
getRegisteredTools,
|
|
3265
3619
|
identify,
|
|
3266
3620
|
loadSession,
|
|
3267
3621
|
memory,
|
|
3268
3622
|
personas,
|
|
3623
|
+
registerPrompt,
|
|
3269
3624
|
renderAgentSystem,
|
|
3270
3625
|
replay,
|
|
3626
|
+
resetBuildRegistry,
|
|
3271
3627
|
resolveUserId,
|
|
3272
3628
|
runSuite,
|
|
3273
3629
|
runWithExperimentContext,
|