@withgateway/sdk 0.1.3
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/README.md +229 -0
- package/dist/context/index.d.mts +225 -0
- package/dist/context/index.d.ts +225 -0
- package/dist/context/index.js +440 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/index.mjs +411 -0
- package/dist/context/index.mjs.map +1 -0
- package/dist/experiments/index.d.mts +260 -0
- package/dist/experiments/index.d.ts +260 -0
- package/dist/experiments/index.js +407 -0
- package/dist/experiments/index.js.map +1 -0
- package/dist/experiments/index.mjs +374 -0
- package/dist/experiments/index.mjs.map +1 -0
- package/dist/index-Caw3XVub.d.mts +193 -0
- package/dist/index-Caw3XVub.d.ts +193 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +1476 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1434 -0
- package/dist/index.mjs.map +1 -0
- package/dist/memory/index.d.mts +124 -0
- package/dist/memory/index.d.ts +124 -0
- package/dist/memory/index.js +192 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/index.mjs +164 -0
- package/dist/memory/index.mjs.map +1 -0
- package/dist/security/index.d.mts +114 -0
- package/dist/security/index.d.ts +114 -0
- package/dist/security/index.js +297 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/index.mjs +275 -0
- package/dist/security/index.mjs.map +1 -0
- package/dist/tracing/index.d.mts +1 -0
- package/dist/tracing/index.d.ts +1 -0
- package/dist/tracing/index.js +226 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/index.mjs +202 -0
- package/dist/tracing/index.mjs.map +1 -0
- package/package.json +112 -0
package/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# @withgateway/sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for Gateway — A/B experiments, tracing, and observability for LLM agents.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @withgateway/sdk
|
|
9
|
+
|
|
10
|
+
# For tracing integration (required for tracing.init())
|
|
11
|
+
npm install @opentelemetry/api @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
### Option 1: One-Line Setup (Recommended)
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { tracing, experiments } from "@withgateway/sdk";
|
|
20
|
+
|
|
21
|
+
// 1. Initialize tracing - reads from env vars and sets up everything
|
|
22
|
+
tracing.init();
|
|
23
|
+
|
|
24
|
+
// 2. Initialize experiments
|
|
25
|
+
experiments.init({
|
|
26
|
+
apiKey: process.env.GATEWAY_PUBLIC_KEY!,
|
|
27
|
+
secretKey: process.env.GATEWAY_SECRET_KEY!,
|
|
28
|
+
baseUrl: process.env.GATEWAY_HOST!,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 3. Register and use experiment
|
|
32
|
+
await experiments.register({
|
|
33
|
+
key: "prompt-test",
|
|
34
|
+
variants: [
|
|
35
|
+
{ key: "control", weight: 50, config: { prompt: "Be helpful." } },
|
|
36
|
+
{ key: "treatment", weight: 50, config: { prompt: "Be concise." } },
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const result = await experiments.getVariant("prompt-test", "user-123");
|
|
41
|
+
|
|
42
|
+
// 4. Shutdown on exit
|
|
43
|
+
process.on("SIGTERM", async () => {
|
|
44
|
+
await tracing.shutdown();
|
|
45
|
+
await experiments.shutdown();
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Environment variables for `tracing.init()`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
export GATEWAY_HOST="https://withgateway.ai"
|
|
53
|
+
export GATEWAY_PUBLIC_KEY="pk-lf-..."
|
|
54
|
+
export GATEWAY_SECRET_KEY="sk-lf-..."
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Option 2: Explicit Configuration
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { tracing, experiments } from "@withgateway/sdk";
|
|
61
|
+
|
|
62
|
+
// Initialize with explicit config
|
|
63
|
+
tracing.init({
|
|
64
|
+
host: "https://withgateway.ai",
|
|
65
|
+
publicKey: "pk-lf-...",
|
|
66
|
+
secretKey: "sk-lf-...",
|
|
67
|
+
serviceName: "my-agent",
|
|
68
|
+
environment: "production",
|
|
69
|
+
debug: true, // Enable console logging
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
experiments.init({
|
|
73
|
+
apiKey: "pk-lf-...",
|
|
74
|
+
secretKey: "sk-lf-...",
|
|
75
|
+
baseUrl: "https://withgateway.ai",
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Option 3: Manual OpenTelemetry Setup (Advanced)
|
|
80
|
+
|
|
81
|
+
If you need full control over OpenTelemetry configuration:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { experiments, ExperimentSpanProcessor } from "@withgateway/sdk";
|
|
85
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
86
|
+
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
87
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
88
|
+
|
|
89
|
+
const provider = new NodeTracerProvider({
|
|
90
|
+
spanProcessors: [
|
|
91
|
+
new ExperimentSpanProcessor(), // Add BEFORE exporter
|
|
92
|
+
new BatchSpanProcessor(
|
|
93
|
+
new OTLPTraceExporter({
|
|
94
|
+
url: `${process.env.GATEWAY_HOST}/api/public/otel/v1/traces`,
|
|
95
|
+
headers: {
|
|
96
|
+
Authorization: `Basic ${Buffer.from(
|
|
97
|
+
`${process.env.GATEWAY_PUBLIC_KEY}:${process.env.GATEWAY_SECRET_KEY}`,
|
|
98
|
+
).toString("base64")}`,
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
provider.register();
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Spans created after `getVariant()` are automatically tagged with:
|
|
108
|
+
|
|
109
|
+
- `gateway.experiment.id` — experiment key
|
|
110
|
+
- `gateway.variant.key` — assigned variant
|
|
111
|
+
- `gateway.experiment.user_id` — user ID
|
|
112
|
+
|
|
113
|
+
## API Reference
|
|
114
|
+
|
|
115
|
+
### Tracing API
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { tracing } from "@withgateway/sdk";
|
|
119
|
+
|
|
120
|
+
tracing.init(config?) // Initialize OTel + Gateway exporter (call once)
|
|
121
|
+
tracing.flush() // Force flush pending spans
|
|
122
|
+
tracing.shutdown() // Flush + shutdown (call on exit)
|
|
123
|
+
tracing.isInitialized() // Check if initialized
|
|
124
|
+
tracing.isGatewayConfigured() // Check if env vars are set
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Config options:**
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
tracing.init({
|
|
131
|
+
host: string, // Gateway server URL (or GATEWAY_HOST env var)
|
|
132
|
+
publicKey: string, // Auth key (or GATEWAY_PUBLIC_KEY env var)
|
|
133
|
+
secretKey: string, // Secret key (or GATEWAY_SECRET_KEY env var)
|
|
134
|
+
serviceName?: string, // Service name for traces (default: "gatewaysdk-tracing")
|
|
135
|
+
environment?: string, // Environment tag (e.g., "production")
|
|
136
|
+
version?: string, // Version tag (e.g., "1.2.3")
|
|
137
|
+
debug?: boolean, // Enable console logging (default: false)
|
|
138
|
+
enableExperiments?: boolean, // Add ExperimentSpanProcessor (default: true)
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Experiments API
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { experiments } from "@withgateway/sdk";
|
|
146
|
+
|
|
147
|
+
experiments.init(config) // Initialize (call once)
|
|
148
|
+
experiments.register(input) // Register an experiment
|
|
149
|
+
experiments.getVariant(key, userId) // Get variant for user
|
|
150
|
+
experiments.fetch(keys?) // Fetch experiments from backend
|
|
151
|
+
experiments.clearExperimentContext() // Clear context (call after each request)
|
|
152
|
+
experiments.shutdown() // Cleanup (call on exit)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Security Wrapper
|
|
156
|
+
|
|
157
|
+
Use the security wrapper when you want Gateway to control tool visibility,
|
|
158
|
+
authorization, credential bindings, and evidence while your agent framework keeps
|
|
159
|
+
owning the native tool objects.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { gateway } from "@withgateway/sdk/security";
|
|
163
|
+
import { streamText, tool } from "ai";
|
|
164
|
+
|
|
165
|
+
const gw = gateway.fromEnv({
|
|
166
|
+
agent: {
|
|
167
|
+
id: "support-triage",
|
|
168
|
+
name: "Support Triage",
|
|
169
|
+
version: "1.4.2",
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const tools = await gw.secureTools({
|
|
174
|
+
toolsetId: "zendesk",
|
|
175
|
+
provider: "zendesk",
|
|
176
|
+
tools: {
|
|
177
|
+
searchTickets: tool({
|
|
178
|
+
description: "Search Zendesk tickets",
|
|
179
|
+
inputSchema: searchSchema,
|
|
180
|
+
execute: async (input) => zendesk.search(input),
|
|
181
|
+
}),
|
|
182
|
+
deleteTicket: tool({
|
|
183
|
+
description: "Delete a Zendesk ticket",
|
|
184
|
+
inputSchema: deleteSchema,
|
|
185
|
+
execute: async (input) => zendesk.delete(input),
|
|
186
|
+
}),
|
|
187
|
+
},
|
|
188
|
+
context: {
|
|
189
|
+
userId: currentUser.id,
|
|
190
|
+
teamId: "support",
|
|
191
|
+
environment: "production",
|
|
192
|
+
traceId,
|
|
193
|
+
sessionId,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await streamText({ model, prompt, tools });
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`secureTools` calls `/api/public/security/toolsets/resolve`, hides blocked tools
|
|
201
|
+
in `filter`/`enforce`, and calls `/api/public/security/tool-calls/authorize`
|
|
202
|
+
immediately before execution. It also stamps Gateway security attributes on
|
|
203
|
+
the active OpenTelemetry span when tracing is installed.
|
|
204
|
+
|
|
205
|
+
### Class-Based API (Advanced)
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { ExperimentClient } from "@withgateway/sdk";
|
|
209
|
+
|
|
210
|
+
const client = new ExperimentClient({
|
|
211
|
+
apiUrl: "https://withgateway.ai",
|
|
212
|
+
apiKey: "pk-lf-...",
|
|
213
|
+
secretKey: "sk-lf-...",
|
|
214
|
+
projectId: "...",
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Cross-Language Compatibility
|
|
219
|
+
|
|
220
|
+
This SDK produces **identical assignments** to the Python SDK (`gatewaysdk`) for the same `(experimentKey, userId)` pair. You can run experiments across services in different languages.
|
|
221
|
+
|
|
222
|
+
## Documentation
|
|
223
|
+
|
|
224
|
+
- [Full A/B Experiments Guide](https://github.com/gateway/gateway/blob/main/documentation/gatewaysdk/ab-experiments/README.md)
|
|
225
|
+
- [TypeScript SDK Deep Dive](https://github.com/gateway/gateway/blob/main/documentation/gatewaysdk/typescript-sdk/README.md)
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
type ContextRepoKind = "agent" | "prompt" | "skill" | "memory";
|
|
2
|
+
type ContextWritePolicy = "read_only" | "propose" | "commit";
|
|
3
|
+
type ContextFileEntry = {
|
|
4
|
+
type: "file";
|
|
5
|
+
content: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
mime_type: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "agent" | "skill";
|
|
10
|
+
repoHandle: string;
|
|
11
|
+
repo_handle: string;
|
|
12
|
+
commitId?: string | null;
|
|
13
|
+
commit_id?: string | null;
|
|
14
|
+
};
|
|
15
|
+
type ContextRepo<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
16
|
+
id: string;
|
|
17
|
+
repoHandle: string;
|
|
18
|
+
repo_handle: string;
|
|
19
|
+
ownerHandle: string;
|
|
20
|
+
owner_handle: string;
|
|
21
|
+
kind: TKind;
|
|
22
|
+
description: string;
|
|
23
|
+
readme: string;
|
|
24
|
+
tags: string[];
|
|
25
|
+
writePolicy: ContextWritePolicy;
|
|
26
|
+
write_policy: ContextWritePolicy;
|
|
27
|
+
isPublic: boolean;
|
|
28
|
+
is_public: boolean;
|
|
29
|
+
isArchived: boolean;
|
|
30
|
+
is_archived: boolean;
|
|
31
|
+
url?: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
created_at: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
updated_at: string;
|
|
36
|
+
};
|
|
37
|
+
type ContextCommit = {
|
|
38
|
+
id: string;
|
|
39
|
+
commitHash: string;
|
|
40
|
+
commit_hash: string;
|
|
41
|
+
parentCommitHash: string | null;
|
|
42
|
+
parent_commit_hash: string | null;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
};
|
|
46
|
+
type ContextSnapshot<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
47
|
+
repo: ContextRepo<TKind>;
|
|
48
|
+
commit: ContextCommit;
|
|
49
|
+
files: Record<string, ContextFileEntry>;
|
|
50
|
+
};
|
|
51
|
+
type ContextListResponse<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
52
|
+
repos: ContextRepo<TKind>[];
|
|
53
|
+
limit: number;
|
|
54
|
+
offset: number;
|
|
55
|
+
total: number;
|
|
56
|
+
};
|
|
57
|
+
type ContextPushResponse = {
|
|
58
|
+
url: string;
|
|
59
|
+
status: "committed" | "proposed";
|
|
60
|
+
repoId: string;
|
|
61
|
+
repo_id: string;
|
|
62
|
+
commitId: string | null;
|
|
63
|
+
commit_id: string | null;
|
|
64
|
+
commitHash: string | null;
|
|
65
|
+
commit_hash: string | null;
|
|
66
|
+
proposalId?: string | null;
|
|
67
|
+
proposal_id?: string | null;
|
|
68
|
+
};
|
|
69
|
+
type ContextFileInput = {
|
|
70
|
+
content: string;
|
|
71
|
+
mimeType?: string;
|
|
72
|
+
mime_type?: string;
|
|
73
|
+
} | {
|
|
74
|
+
repoHandle?: string;
|
|
75
|
+
repo_handle?: string;
|
|
76
|
+
kind?: "agent" | "skill";
|
|
77
|
+
type?: "agent" | "skill";
|
|
78
|
+
commitId?: string | null;
|
|
79
|
+
commit_id?: string | null;
|
|
80
|
+
} | null;
|
|
81
|
+
type ContextRuntimeContext = {
|
|
82
|
+
source?: "sdk" | "agent" | "dream" | "api" | "platform";
|
|
83
|
+
actorType?: "api_key" | "agent" | "process" | "user";
|
|
84
|
+
proposedBy?: string;
|
|
85
|
+
agentId?: string;
|
|
86
|
+
agentStableId?: string;
|
|
87
|
+
processId?: string;
|
|
88
|
+
traceId?: string;
|
|
89
|
+
spanId?: string;
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
userId?: string;
|
|
92
|
+
teamId?: string;
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
type ContextPullOptions = {
|
|
96
|
+
version?: string;
|
|
97
|
+
};
|
|
98
|
+
type ContextListOptions = {
|
|
99
|
+
query?: string;
|
|
100
|
+
isPublic?: boolean;
|
|
101
|
+
isArchived?: boolean;
|
|
102
|
+
limit?: number;
|
|
103
|
+
offset?: number;
|
|
104
|
+
};
|
|
105
|
+
type ContextPushOptions = ContextRuntimeContext & {
|
|
106
|
+
files: Record<string, ContextFileInput>;
|
|
107
|
+
parentCommit?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
readme?: string;
|
|
110
|
+
tags?: string[];
|
|
111
|
+
isPublic?: boolean;
|
|
112
|
+
writePolicy?: ContextWritePolicy;
|
|
113
|
+
message?: string;
|
|
114
|
+
};
|
|
115
|
+
type ResolvedContextRef<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
116
|
+
identifier: string;
|
|
117
|
+
version?: string;
|
|
118
|
+
writable?: boolean;
|
|
119
|
+
snapshot: ContextSnapshot<TKind>;
|
|
120
|
+
primaryPath: string | null;
|
|
121
|
+
content: string;
|
|
122
|
+
};
|
|
123
|
+
type ResolvedAgentContext = {
|
|
124
|
+
agent: ContextSnapshot<"agent">;
|
|
125
|
+
config: Record<string, unknown>;
|
|
126
|
+
prompt: ResolvedContextRef<"prompt"> | null;
|
|
127
|
+
prompts: ResolvedContextRef<"prompt">[];
|
|
128
|
+
skills: ResolvedContextRef<"skill">[];
|
|
129
|
+
memory: ResolvedContextRef<"memory">[];
|
|
130
|
+
system: string;
|
|
131
|
+
renderSystem: (options?: RenderSystemOptions) => string;
|
|
132
|
+
provenance: ContextProvenance[];
|
|
133
|
+
};
|
|
134
|
+
type ContextProvenance = {
|
|
135
|
+
kind: ContextRepoKind;
|
|
136
|
+
repoHandle: string;
|
|
137
|
+
commitHash: string;
|
|
138
|
+
label?: string;
|
|
139
|
+
};
|
|
140
|
+
type RenderSystemOptions = {
|
|
141
|
+
includeAgent?: boolean;
|
|
142
|
+
includePrompts?: boolean;
|
|
143
|
+
includeSkills?: boolean;
|
|
144
|
+
includeMemory?: boolean;
|
|
145
|
+
};
|
|
146
|
+
type GatewayContextConfig = {
|
|
147
|
+
host: string;
|
|
148
|
+
publicKey: string;
|
|
149
|
+
secretKey: string;
|
|
150
|
+
debug?: boolean;
|
|
151
|
+
};
|
|
152
|
+
type GatewayContextFromEnvConfig = Partial<GatewayContextConfig>;
|
|
153
|
+
declare class GatewayContextError extends Error {
|
|
154
|
+
constructor(message: string, options?: {
|
|
155
|
+
cause?: unknown;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
declare class GatewayContextConflictError extends GatewayContextError {
|
|
159
|
+
readonly latestCommit: unknown;
|
|
160
|
+
constructor(message: string, latestCommit: unknown);
|
|
161
|
+
}
|
|
162
|
+
declare class GatewayContext {
|
|
163
|
+
private readonly host;
|
|
164
|
+
private readonly publicKey;
|
|
165
|
+
private readonly secretKey;
|
|
166
|
+
private readonly debug;
|
|
167
|
+
constructor(config: GatewayContextConfig);
|
|
168
|
+
static fromEnv(config?: GatewayContextFromEnvConfig): GatewayContext;
|
|
169
|
+
pullAgent(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"agent">>;
|
|
170
|
+
pullPrompt(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"prompt">>;
|
|
171
|
+
pullSkill(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"skill">>;
|
|
172
|
+
pullMemory(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"memory">>;
|
|
173
|
+
pushAgent(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
174
|
+
pushPrompt(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
175
|
+
pushSkill(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
176
|
+
pushMemory(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
177
|
+
listAgents(options?: ContextListOptions): Promise<ContextListResponse<"agent">>;
|
|
178
|
+
listPrompts(options?: ContextListOptions): Promise<ContextListResponse<"prompt">>;
|
|
179
|
+
listSkills(options?: ContextListOptions): Promise<ContextListResponse<"skill">>;
|
|
180
|
+
listMemory(options?: ContextListOptions): Promise<ContextListResponse<"memory">>;
|
|
181
|
+
agentExists(identifier: string): Promise<boolean>;
|
|
182
|
+
promptExists(identifier: string): Promise<boolean>;
|
|
183
|
+
skillExists(identifier: string): Promise<boolean>;
|
|
184
|
+
memoryExists(identifier: string): Promise<boolean>;
|
|
185
|
+
deleteAgent(identifier: string): Promise<{
|
|
186
|
+
deleted: boolean;
|
|
187
|
+
repoHandle: string;
|
|
188
|
+
repo_handle: string;
|
|
189
|
+
}>;
|
|
190
|
+
deletePrompt(identifier: string): Promise<{
|
|
191
|
+
deleted: boolean;
|
|
192
|
+
repoHandle: string;
|
|
193
|
+
repo_handle: string;
|
|
194
|
+
}>;
|
|
195
|
+
deleteSkill(identifier: string): Promise<{
|
|
196
|
+
deleted: boolean;
|
|
197
|
+
repoHandle: string;
|
|
198
|
+
repo_handle: string;
|
|
199
|
+
}>;
|
|
200
|
+
deleteMemory(identifier: string): Promise<{
|
|
201
|
+
deleted: boolean;
|
|
202
|
+
repoHandle: string;
|
|
203
|
+
repo_handle: string;
|
|
204
|
+
}>;
|
|
205
|
+
resolveAgent(identifier: string, runtimeContext?: ContextRuntimeContext): Promise<ResolvedAgentContext>;
|
|
206
|
+
pull<TKind extends ContextRepoKind>(kind: TKind, identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<TKind>>;
|
|
207
|
+
push<TKind extends ContextRepoKind>(kind: TKind, identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
208
|
+
list<TKind extends ContextRepoKind>(kind: TKind, options?: ContextListOptions): Promise<ContextListResponse<TKind>>;
|
|
209
|
+
exists(kind: ContextRepoKind, identifier: string): Promise<boolean>;
|
|
210
|
+
delete(kind: ContextRepoKind, identifier: string): Promise<{
|
|
211
|
+
deleted: boolean;
|
|
212
|
+
repoHandle: string;
|
|
213
|
+
repo_handle: string;
|
|
214
|
+
}>;
|
|
215
|
+
private resolveRefs;
|
|
216
|
+
private requestJson;
|
|
217
|
+
private authHeader;
|
|
218
|
+
private log;
|
|
219
|
+
}
|
|
220
|
+
declare function renderAgentSystem(bundle: Omit<ResolvedAgentContext, "system" | "renderSystem">, options?: RenderSystemOptions): string;
|
|
221
|
+
declare const context: {
|
|
222
|
+
fromEnv: typeof GatewayContext.fromEnv;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export { GatewayContext, type ContextCommit as GatewayContextCommit, type GatewayContextConfig, GatewayContextConflictError, GatewayContextError, type ContextFileEntry as GatewayContextFileEntry, type ContextFileInput as GatewayContextFileInput, type ContextListOptions as GatewayContextListOptions, type ContextListResponse as GatewayContextListResponse, type ContextPullOptions as GatewayContextPullOptions, type ContextPushOptions as GatewayContextPushOptions, type ContextPushResponse as GatewayContextPushResponse, type ContextRepo as GatewayContextRepo, type ContextRepoKind as GatewayContextRepoKind, type ContextRuntimeContext as GatewayContextRuntimeContext, type ContextSnapshot as GatewayContextSnapshot, type ContextWritePolicy as GatewayContextWritePolicy, type RenderSystemOptions as GatewayRenderSystemOptions, type ResolvedAgentContext as GatewayResolvedAgentContext, type ResolvedContextRef as GatewayResolvedContextRef, context, renderAgentSystem };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
type ContextRepoKind = "agent" | "prompt" | "skill" | "memory";
|
|
2
|
+
type ContextWritePolicy = "read_only" | "propose" | "commit";
|
|
3
|
+
type ContextFileEntry = {
|
|
4
|
+
type: "file";
|
|
5
|
+
content: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
mime_type: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "agent" | "skill";
|
|
10
|
+
repoHandle: string;
|
|
11
|
+
repo_handle: string;
|
|
12
|
+
commitId?: string | null;
|
|
13
|
+
commit_id?: string | null;
|
|
14
|
+
};
|
|
15
|
+
type ContextRepo<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
16
|
+
id: string;
|
|
17
|
+
repoHandle: string;
|
|
18
|
+
repo_handle: string;
|
|
19
|
+
ownerHandle: string;
|
|
20
|
+
owner_handle: string;
|
|
21
|
+
kind: TKind;
|
|
22
|
+
description: string;
|
|
23
|
+
readme: string;
|
|
24
|
+
tags: string[];
|
|
25
|
+
writePolicy: ContextWritePolicy;
|
|
26
|
+
write_policy: ContextWritePolicy;
|
|
27
|
+
isPublic: boolean;
|
|
28
|
+
is_public: boolean;
|
|
29
|
+
isArchived: boolean;
|
|
30
|
+
is_archived: boolean;
|
|
31
|
+
url?: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
created_at: string;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
updated_at: string;
|
|
36
|
+
};
|
|
37
|
+
type ContextCommit = {
|
|
38
|
+
id: string;
|
|
39
|
+
commitHash: string;
|
|
40
|
+
commit_hash: string;
|
|
41
|
+
parentCommitHash: string | null;
|
|
42
|
+
parent_commit_hash: string | null;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
};
|
|
46
|
+
type ContextSnapshot<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
47
|
+
repo: ContextRepo<TKind>;
|
|
48
|
+
commit: ContextCommit;
|
|
49
|
+
files: Record<string, ContextFileEntry>;
|
|
50
|
+
};
|
|
51
|
+
type ContextListResponse<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
52
|
+
repos: ContextRepo<TKind>[];
|
|
53
|
+
limit: number;
|
|
54
|
+
offset: number;
|
|
55
|
+
total: number;
|
|
56
|
+
};
|
|
57
|
+
type ContextPushResponse = {
|
|
58
|
+
url: string;
|
|
59
|
+
status: "committed" | "proposed";
|
|
60
|
+
repoId: string;
|
|
61
|
+
repo_id: string;
|
|
62
|
+
commitId: string | null;
|
|
63
|
+
commit_id: string | null;
|
|
64
|
+
commitHash: string | null;
|
|
65
|
+
commit_hash: string | null;
|
|
66
|
+
proposalId?: string | null;
|
|
67
|
+
proposal_id?: string | null;
|
|
68
|
+
};
|
|
69
|
+
type ContextFileInput = {
|
|
70
|
+
content: string;
|
|
71
|
+
mimeType?: string;
|
|
72
|
+
mime_type?: string;
|
|
73
|
+
} | {
|
|
74
|
+
repoHandle?: string;
|
|
75
|
+
repo_handle?: string;
|
|
76
|
+
kind?: "agent" | "skill";
|
|
77
|
+
type?: "agent" | "skill";
|
|
78
|
+
commitId?: string | null;
|
|
79
|
+
commit_id?: string | null;
|
|
80
|
+
} | null;
|
|
81
|
+
type ContextRuntimeContext = {
|
|
82
|
+
source?: "sdk" | "agent" | "dream" | "api" | "platform";
|
|
83
|
+
actorType?: "api_key" | "agent" | "process" | "user";
|
|
84
|
+
proposedBy?: string;
|
|
85
|
+
agentId?: string;
|
|
86
|
+
agentStableId?: string;
|
|
87
|
+
processId?: string;
|
|
88
|
+
traceId?: string;
|
|
89
|
+
spanId?: string;
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
userId?: string;
|
|
92
|
+
teamId?: string;
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
};
|
|
95
|
+
type ContextPullOptions = {
|
|
96
|
+
version?: string;
|
|
97
|
+
};
|
|
98
|
+
type ContextListOptions = {
|
|
99
|
+
query?: string;
|
|
100
|
+
isPublic?: boolean;
|
|
101
|
+
isArchived?: boolean;
|
|
102
|
+
limit?: number;
|
|
103
|
+
offset?: number;
|
|
104
|
+
};
|
|
105
|
+
type ContextPushOptions = ContextRuntimeContext & {
|
|
106
|
+
files: Record<string, ContextFileInput>;
|
|
107
|
+
parentCommit?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
readme?: string;
|
|
110
|
+
tags?: string[];
|
|
111
|
+
isPublic?: boolean;
|
|
112
|
+
writePolicy?: ContextWritePolicy;
|
|
113
|
+
message?: string;
|
|
114
|
+
};
|
|
115
|
+
type ResolvedContextRef<TKind extends ContextRepoKind = ContextRepoKind> = {
|
|
116
|
+
identifier: string;
|
|
117
|
+
version?: string;
|
|
118
|
+
writable?: boolean;
|
|
119
|
+
snapshot: ContextSnapshot<TKind>;
|
|
120
|
+
primaryPath: string | null;
|
|
121
|
+
content: string;
|
|
122
|
+
};
|
|
123
|
+
type ResolvedAgentContext = {
|
|
124
|
+
agent: ContextSnapshot<"agent">;
|
|
125
|
+
config: Record<string, unknown>;
|
|
126
|
+
prompt: ResolvedContextRef<"prompt"> | null;
|
|
127
|
+
prompts: ResolvedContextRef<"prompt">[];
|
|
128
|
+
skills: ResolvedContextRef<"skill">[];
|
|
129
|
+
memory: ResolvedContextRef<"memory">[];
|
|
130
|
+
system: string;
|
|
131
|
+
renderSystem: (options?: RenderSystemOptions) => string;
|
|
132
|
+
provenance: ContextProvenance[];
|
|
133
|
+
};
|
|
134
|
+
type ContextProvenance = {
|
|
135
|
+
kind: ContextRepoKind;
|
|
136
|
+
repoHandle: string;
|
|
137
|
+
commitHash: string;
|
|
138
|
+
label?: string;
|
|
139
|
+
};
|
|
140
|
+
type RenderSystemOptions = {
|
|
141
|
+
includeAgent?: boolean;
|
|
142
|
+
includePrompts?: boolean;
|
|
143
|
+
includeSkills?: boolean;
|
|
144
|
+
includeMemory?: boolean;
|
|
145
|
+
};
|
|
146
|
+
type GatewayContextConfig = {
|
|
147
|
+
host: string;
|
|
148
|
+
publicKey: string;
|
|
149
|
+
secretKey: string;
|
|
150
|
+
debug?: boolean;
|
|
151
|
+
};
|
|
152
|
+
type GatewayContextFromEnvConfig = Partial<GatewayContextConfig>;
|
|
153
|
+
declare class GatewayContextError extends Error {
|
|
154
|
+
constructor(message: string, options?: {
|
|
155
|
+
cause?: unknown;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
declare class GatewayContextConflictError extends GatewayContextError {
|
|
159
|
+
readonly latestCommit: unknown;
|
|
160
|
+
constructor(message: string, latestCommit: unknown);
|
|
161
|
+
}
|
|
162
|
+
declare class GatewayContext {
|
|
163
|
+
private readonly host;
|
|
164
|
+
private readonly publicKey;
|
|
165
|
+
private readonly secretKey;
|
|
166
|
+
private readonly debug;
|
|
167
|
+
constructor(config: GatewayContextConfig);
|
|
168
|
+
static fromEnv(config?: GatewayContextFromEnvConfig): GatewayContext;
|
|
169
|
+
pullAgent(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"agent">>;
|
|
170
|
+
pullPrompt(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"prompt">>;
|
|
171
|
+
pullSkill(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"skill">>;
|
|
172
|
+
pullMemory(identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<"memory">>;
|
|
173
|
+
pushAgent(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
174
|
+
pushPrompt(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
175
|
+
pushSkill(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
176
|
+
pushMemory(identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
177
|
+
listAgents(options?: ContextListOptions): Promise<ContextListResponse<"agent">>;
|
|
178
|
+
listPrompts(options?: ContextListOptions): Promise<ContextListResponse<"prompt">>;
|
|
179
|
+
listSkills(options?: ContextListOptions): Promise<ContextListResponse<"skill">>;
|
|
180
|
+
listMemory(options?: ContextListOptions): Promise<ContextListResponse<"memory">>;
|
|
181
|
+
agentExists(identifier: string): Promise<boolean>;
|
|
182
|
+
promptExists(identifier: string): Promise<boolean>;
|
|
183
|
+
skillExists(identifier: string): Promise<boolean>;
|
|
184
|
+
memoryExists(identifier: string): Promise<boolean>;
|
|
185
|
+
deleteAgent(identifier: string): Promise<{
|
|
186
|
+
deleted: boolean;
|
|
187
|
+
repoHandle: string;
|
|
188
|
+
repo_handle: string;
|
|
189
|
+
}>;
|
|
190
|
+
deletePrompt(identifier: string): Promise<{
|
|
191
|
+
deleted: boolean;
|
|
192
|
+
repoHandle: string;
|
|
193
|
+
repo_handle: string;
|
|
194
|
+
}>;
|
|
195
|
+
deleteSkill(identifier: string): Promise<{
|
|
196
|
+
deleted: boolean;
|
|
197
|
+
repoHandle: string;
|
|
198
|
+
repo_handle: string;
|
|
199
|
+
}>;
|
|
200
|
+
deleteMemory(identifier: string): Promise<{
|
|
201
|
+
deleted: boolean;
|
|
202
|
+
repoHandle: string;
|
|
203
|
+
repo_handle: string;
|
|
204
|
+
}>;
|
|
205
|
+
resolveAgent(identifier: string, runtimeContext?: ContextRuntimeContext): Promise<ResolvedAgentContext>;
|
|
206
|
+
pull<TKind extends ContextRepoKind>(kind: TKind, identifier: string, options?: ContextPullOptions): Promise<ContextSnapshot<TKind>>;
|
|
207
|
+
push<TKind extends ContextRepoKind>(kind: TKind, identifier: string, options: ContextPushOptions): Promise<ContextPushResponse>;
|
|
208
|
+
list<TKind extends ContextRepoKind>(kind: TKind, options?: ContextListOptions): Promise<ContextListResponse<TKind>>;
|
|
209
|
+
exists(kind: ContextRepoKind, identifier: string): Promise<boolean>;
|
|
210
|
+
delete(kind: ContextRepoKind, identifier: string): Promise<{
|
|
211
|
+
deleted: boolean;
|
|
212
|
+
repoHandle: string;
|
|
213
|
+
repo_handle: string;
|
|
214
|
+
}>;
|
|
215
|
+
private resolveRefs;
|
|
216
|
+
private requestJson;
|
|
217
|
+
private authHeader;
|
|
218
|
+
private log;
|
|
219
|
+
}
|
|
220
|
+
declare function renderAgentSystem(bundle: Omit<ResolvedAgentContext, "system" | "renderSystem">, options?: RenderSystemOptions): string;
|
|
221
|
+
declare const context: {
|
|
222
|
+
fromEnv: typeof GatewayContext.fromEnv;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export { GatewayContext, type ContextCommit as GatewayContextCommit, type GatewayContextConfig, GatewayContextConflictError, GatewayContextError, type ContextFileEntry as GatewayContextFileEntry, type ContextFileInput as GatewayContextFileInput, type ContextListOptions as GatewayContextListOptions, type ContextListResponse as GatewayContextListResponse, type ContextPullOptions as GatewayContextPullOptions, type ContextPushOptions as GatewayContextPushOptions, type ContextPushResponse as GatewayContextPushResponse, type ContextRepo as GatewayContextRepo, type ContextRepoKind as GatewayContextRepoKind, type ContextRuntimeContext as GatewayContextRuntimeContext, type ContextSnapshot as GatewayContextSnapshot, type ContextWritePolicy as GatewayContextWritePolicy, type RenderSystemOptions as GatewayRenderSystemOptions, type ResolvedAgentContext as GatewayResolvedAgentContext, type ResolvedContextRef as GatewayResolvedContextRef, context, renderAgentSystem };
|