@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
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
// src/context/index.ts
|
|
2
|
+
var GatewayContextError = class extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "GatewayContextError";
|
|
6
|
+
this.cause = options?.cause;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
var GatewayContextConflictError = class extends GatewayContextError {
|
|
10
|
+
latestCommit;
|
|
11
|
+
constructor(message, latestCommit) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "GatewayContextConflictError";
|
|
14
|
+
this.latestCommit = latestCommit;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var GatewayContext = class _GatewayContext {
|
|
18
|
+
host;
|
|
19
|
+
publicKey;
|
|
20
|
+
secretKey;
|
|
21
|
+
debug;
|
|
22
|
+
constructor(config) {
|
|
23
|
+
this.host = config.host.replace(/\/$/, "");
|
|
24
|
+
this.publicKey = config.publicKey;
|
|
25
|
+
this.secretKey = config.secretKey;
|
|
26
|
+
this.debug = config.debug ?? false;
|
|
27
|
+
}
|
|
28
|
+
static fromEnv(config = {}) {
|
|
29
|
+
const host = config.host ?? process.env.GATEWAY_HOST ?? process.env.GATEWAY_HOST;
|
|
30
|
+
const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY ?? process.env.GATEWAY_PUBLIC_KEY;
|
|
31
|
+
const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY ?? process.env.GATEWAY_SECRET_KEY;
|
|
32
|
+
const missing = [
|
|
33
|
+
["host", host],
|
|
34
|
+
["publicKey", publicKey],
|
|
35
|
+
["secretKey", secretKey]
|
|
36
|
+
].filter(([, value]) => !value).map(([name]) => name);
|
|
37
|
+
if (missing.length > 0) {
|
|
38
|
+
throw new GatewayContextError(
|
|
39
|
+
`Missing Gateway context configuration: ${missing.join(", ")}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return new _GatewayContext({
|
|
43
|
+
...config,
|
|
44
|
+
host,
|
|
45
|
+
publicKey,
|
|
46
|
+
secretKey
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
pullAgent(identifier, options = {}) {
|
|
50
|
+
return this.pull("agent", identifier, options);
|
|
51
|
+
}
|
|
52
|
+
pullPrompt(identifier, options = {}) {
|
|
53
|
+
return this.pull("prompt", identifier, options);
|
|
54
|
+
}
|
|
55
|
+
pullSkill(identifier, options = {}) {
|
|
56
|
+
return this.pull("skill", identifier, options);
|
|
57
|
+
}
|
|
58
|
+
pullMemory(identifier, options = {}) {
|
|
59
|
+
return this.pull("memory", identifier, options);
|
|
60
|
+
}
|
|
61
|
+
pushAgent(identifier, options) {
|
|
62
|
+
return this.push("agent", identifier, options);
|
|
63
|
+
}
|
|
64
|
+
pushPrompt(identifier, options) {
|
|
65
|
+
return this.push("prompt", identifier, options);
|
|
66
|
+
}
|
|
67
|
+
pushSkill(identifier, options) {
|
|
68
|
+
return this.push("skill", identifier, options);
|
|
69
|
+
}
|
|
70
|
+
pushMemory(identifier, options) {
|
|
71
|
+
return this.push("memory", identifier, options);
|
|
72
|
+
}
|
|
73
|
+
listAgents(options = {}) {
|
|
74
|
+
return this.list("agent", options);
|
|
75
|
+
}
|
|
76
|
+
listPrompts(options = {}) {
|
|
77
|
+
return this.list("prompt", options);
|
|
78
|
+
}
|
|
79
|
+
listSkills(options = {}) {
|
|
80
|
+
return this.list("skill", options);
|
|
81
|
+
}
|
|
82
|
+
listMemory(options = {}) {
|
|
83
|
+
return this.list("memory", options);
|
|
84
|
+
}
|
|
85
|
+
agentExists(identifier) {
|
|
86
|
+
return this.exists("agent", identifier);
|
|
87
|
+
}
|
|
88
|
+
promptExists(identifier) {
|
|
89
|
+
return this.exists("prompt", identifier);
|
|
90
|
+
}
|
|
91
|
+
skillExists(identifier) {
|
|
92
|
+
return this.exists("skill", identifier);
|
|
93
|
+
}
|
|
94
|
+
memoryExists(identifier) {
|
|
95
|
+
return this.exists("memory", identifier);
|
|
96
|
+
}
|
|
97
|
+
deleteAgent(identifier) {
|
|
98
|
+
return this.delete("agent", identifier);
|
|
99
|
+
}
|
|
100
|
+
deletePrompt(identifier) {
|
|
101
|
+
return this.delete("prompt", identifier);
|
|
102
|
+
}
|
|
103
|
+
deleteSkill(identifier) {
|
|
104
|
+
return this.delete("skill", identifier);
|
|
105
|
+
}
|
|
106
|
+
deleteMemory(identifier) {
|
|
107
|
+
return this.delete("memory", identifier);
|
|
108
|
+
}
|
|
109
|
+
async resolveAgent(identifier, runtimeContext = {}) {
|
|
110
|
+
const agent = await this.pullAgent(identifier);
|
|
111
|
+
const config = parseJsonFile(agent, "config.json");
|
|
112
|
+
const prompts = await this.resolveRefs("prompt", getPromptRefs(config));
|
|
113
|
+
const skills = await this.resolveRefs("skill", getRefList(config.skills));
|
|
114
|
+
const memory = await this.resolveRefs("memory", getRefList(config.memory));
|
|
115
|
+
const bundleBase = {
|
|
116
|
+
agent,
|
|
117
|
+
config,
|
|
118
|
+
prompt: prompts[0] ?? null,
|
|
119
|
+
prompts,
|
|
120
|
+
skills,
|
|
121
|
+
memory,
|
|
122
|
+
provenance: [
|
|
123
|
+
provenanceFor(agent),
|
|
124
|
+
...prompts.map(({ snapshot, version }) => provenanceFor(snapshot, version)),
|
|
125
|
+
...skills.map(({ snapshot, version }) => provenanceFor(snapshot, version)),
|
|
126
|
+
...memory.map(({ snapshot, version }) => provenanceFor(snapshot, version))
|
|
127
|
+
]
|
|
128
|
+
};
|
|
129
|
+
const renderSystem = (options = {}) => renderAgentSystem(bundleBase, options);
|
|
130
|
+
if (Object.keys(runtimeContext).length > 0) {
|
|
131
|
+
this.log("resolveAgent runtime context %o", runtimeContext);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
...bundleBase,
|
|
135
|
+
system: renderSystem(),
|
|
136
|
+
renderSystem
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async pull(kind, identifier, options = {}) {
|
|
140
|
+
const query = new URLSearchParams();
|
|
141
|
+
if (options.version) query.set("version", options.version);
|
|
142
|
+
const suffix = query.toString() ? `?${query.toString()}` : "";
|
|
143
|
+
return this.requestJson(
|
|
144
|
+
"GET",
|
|
145
|
+
`/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(
|
|
146
|
+
identifier
|
|
147
|
+
)}${suffix}`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
async push(kind, identifier, options) {
|
|
151
|
+
return this.requestJson(
|
|
152
|
+
"POST",
|
|
153
|
+
`/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(
|
|
154
|
+
identifier
|
|
155
|
+
)}`,
|
|
156
|
+
{
|
|
157
|
+
files: options.files,
|
|
158
|
+
...options.parentCommit ? { parentCommit: options.parentCommit } : {},
|
|
159
|
+
...options.description ? { description: options.description } : {},
|
|
160
|
+
...options.readme ? { readme: options.readme } : {},
|
|
161
|
+
...options.tags ? { tags: options.tags } : {},
|
|
162
|
+
...options.isPublic !== void 0 ? { isPublic: options.isPublic } : {},
|
|
163
|
+
...options.writePolicy ? { writePolicy: options.writePolicy } : {},
|
|
164
|
+
...options.message ? { message: options.message } : {},
|
|
165
|
+
...runtimeContextPayload(options)
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
async list(kind, options = {}) {
|
|
170
|
+
const query = new URLSearchParams();
|
|
171
|
+
if (options.query) query.set("query", options.query);
|
|
172
|
+
if (options.isPublic !== void 0) query.set("isPublic", String(options.isPublic));
|
|
173
|
+
if (options.isArchived !== void 0)
|
|
174
|
+
query.set("isArchived", String(options.isArchived));
|
|
175
|
+
if (options.limit !== void 0) query.set("limit", String(options.limit));
|
|
176
|
+
if (options.offset !== void 0) query.set("offset", String(options.offset));
|
|
177
|
+
const suffix = query.toString() ? `?${query.toString()}` : "";
|
|
178
|
+
return this.requestJson(
|
|
179
|
+
"GET",
|
|
180
|
+
`/api/public/context/${endpointForKind(kind)}${suffix}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
async exists(kind, identifier) {
|
|
184
|
+
const query = new URLSearchParams({ exists: "true" });
|
|
185
|
+
const response = await this.requestJson(
|
|
186
|
+
"GET",
|
|
187
|
+
`/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(
|
|
188
|
+
identifier
|
|
189
|
+
)}?${query.toString()}`
|
|
190
|
+
);
|
|
191
|
+
return response.exists;
|
|
192
|
+
}
|
|
193
|
+
async delete(kind, identifier) {
|
|
194
|
+
return this.requestJson(
|
|
195
|
+
"DELETE",
|
|
196
|
+
`/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(identifier)}`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
async resolveRefs(kind, refs) {
|
|
200
|
+
const resolved = [];
|
|
201
|
+
for (const ref of refs) {
|
|
202
|
+
const normalized = normalizeRef(ref);
|
|
203
|
+
if (!normalized) continue;
|
|
204
|
+
const snapshot = await this.pull(kind, normalized.identifier, {
|
|
205
|
+
version: normalized.version
|
|
206
|
+
});
|
|
207
|
+
const primaryPath = primaryPathForKind(kind, snapshot);
|
|
208
|
+
const content = primaryPath ? readFile(snapshot, primaryPath) ?? "" : "";
|
|
209
|
+
resolved.push({
|
|
210
|
+
...normalized,
|
|
211
|
+
snapshot,
|
|
212
|
+
primaryPath,
|
|
213
|
+
content
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return resolved;
|
|
217
|
+
}
|
|
218
|
+
async requestJson(method, path, payload) {
|
|
219
|
+
const response = await fetch(`${this.host}${path}`, {
|
|
220
|
+
method,
|
|
221
|
+
headers: {
|
|
222
|
+
Authorization: this.authHeader(),
|
|
223
|
+
...payload ? { "Content-Type": "application/json" } : {}
|
|
224
|
+
},
|
|
225
|
+
...payload ? { body: JSON.stringify(payload) } : {}
|
|
226
|
+
});
|
|
227
|
+
const text = await response.text();
|
|
228
|
+
const body = text ? safeJson(text) : {};
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
const message = typeof body.message === "string" ? body.message : `Gateway API ${response.status} on ${path}`;
|
|
231
|
+
if (response.status === 409) {
|
|
232
|
+
throw new GatewayContextConflictError(
|
|
233
|
+
message,
|
|
234
|
+
body.latestCommit ?? null
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
throw new GatewayContextError(message);
|
|
238
|
+
}
|
|
239
|
+
this.log("%s %s -> %s", method, path, response.status);
|
|
240
|
+
return body;
|
|
241
|
+
}
|
|
242
|
+
authHeader() {
|
|
243
|
+
return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
|
|
244
|
+
"base64"
|
|
245
|
+
)}`;
|
|
246
|
+
}
|
|
247
|
+
log(message, ...args) {
|
|
248
|
+
if (this.debug) {
|
|
249
|
+
console.log(`[gateway.context] ${message}`, ...args);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function renderAgentSystem(bundle, options = {}) {
|
|
254
|
+
const includeAgent = options.includeAgent ?? true;
|
|
255
|
+
const includePrompts = options.includePrompts ?? true;
|
|
256
|
+
const includeSkills = options.includeSkills ?? true;
|
|
257
|
+
const includeMemory = options.includeMemory ?? false;
|
|
258
|
+
const sections = [];
|
|
259
|
+
if (includeAgent) {
|
|
260
|
+
const agentContent = readFile(bundle.agent, "AGENTS.md");
|
|
261
|
+
if (agentContent) sections.push(formatSection("Agent", bundle.agent, agentContent));
|
|
262
|
+
}
|
|
263
|
+
if (includePrompts) {
|
|
264
|
+
for (const prompt of bundle.prompts) {
|
|
265
|
+
if (prompt.content) {
|
|
266
|
+
sections.push(formatSection("Prompt", prompt.snapshot, prompt.content));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (includeSkills) {
|
|
271
|
+
for (const skill of bundle.skills) {
|
|
272
|
+
if (skill.content) {
|
|
273
|
+
sections.push(formatSection("Skill", skill.snapshot, skill.content));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (includeMemory) {
|
|
278
|
+
for (const memory of bundle.memory) {
|
|
279
|
+
if (memory.content) {
|
|
280
|
+
sections.push(formatSection("Memory", memory.snapshot, memory.content));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return sections.join("\n\n---\n\n");
|
|
285
|
+
}
|
|
286
|
+
function formatSection(title, snapshot, content) {
|
|
287
|
+
return [
|
|
288
|
+
`# ${title}: ${snapshot.repo.repoHandle}`,
|
|
289
|
+
`<!-- commit: ${snapshot.commit.commitHash} -->`,
|
|
290
|
+
"",
|
|
291
|
+
content.trim()
|
|
292
|
+
].join("\n");
|
|
293
|
+
}
|
|
294
|
+
function getPromptRefs(config) {
|
|
295
|
+
const refs = [
|
|
296
|
+
...getRefList(config.prompt),
|
|
297
|
+
...getRefList(config.promptRef),
|
|
298
|
+
...getRefList(config.prompt_ref),
|
|
299
|
+
...getRefList(config.prompts)
|
|
300
|
+
];
|
|
301
|
+
return dedupeRefs(refs);
|
|
302
|
+
}
|
|
303
|
+
function getRefList(value) {
|
|
304
|
+
if (!value) return [];
|
|
305
|
+
if (typeof value === "string") return [value];
|
|
306
|
+
if (Array.isArray(value)) return value.filter(isContextRepoRef);
|
|
307
|
+
if (isContextRepoRef(value)) return [value];
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
function isContextRepoRef(value) {
|
|
311
|
+
if (typeof value === "string") return true;
|
|
312
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
313
|
+
const record = value;
|
|
314
|
+
return ["identifier", "repoHandle", "repo_handle"].some(
|
|
315
|
+
(key) => typeof record[key] === "string"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function dedupeRefs(refs) {
|
|
319
|
+
const seen = /* @__PURE__ */ new Set();
|
|
320
|
+
return refs.filter((ref) => {
|
|
321
|
+
const normalized = normalizeRef(ref);
|
|
322
|
+
if (!normalized) return false;
|
|
323
|
+
const key = `${normalized.identifier}:${normalized.version ?? ""}`;
|
|
324
|
+
if (seen.has(key)) return false;
|
|
325
|
+
seen.add(key);
|
|
326
|
+
return true;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function normalizeRef(ref) {
|
|
330
|
+
if (typeof ref === "string") {
|
|
331
|
+
const identifier2 = ref.trim();
|
|
332
|
+
return identifier2 ? { identifier: identifier2 } : null;
|
|
333
|
+
}
|
|
334
|
+
const identifier = (ref.identifier ?? ref.repoHandle ?? ref.repo_handle ?? "").trim();
|
|
335
|
+
if (!identifier) return null;
|
|
336
|
+
return {
|
|
337
|
+
identifier,
|
|
338
|
+
version: ref.version ?? ref.label,
|
|
339
|
+
writable: ref.writable
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function primaryPathForKind(kind, snapshot) {
|
|
343
|
+
const preferred = kind === "agent" ? "AGENTS.md" : kind === "prompt" ? "PROMPT.md" : kind === "skill" ? "SKILL.md" : "MEMORY.md";
|
|
344
|
+
if (readFile(snapshot, preferred)) return preferred;
|
|
345
|
+
return Object.entries(snapshot.files).find(
|
|
346
|
+
([path, entry]) => entry.type === "file" && path.endsWith(".md")
|
|
347
|
+
)?.[0] ?? null;
|
|
348
|
+
}
|
|
349
|
+
function parseJsonFile(snapshot, path) {
|
|
350
|
+
const content = readFile(snapshot, path);
|
|
351
|
+
if (!content) return {};
|
|
352
|
+
try {
|
|
353
|
+
const parsed = JSON.parse(content);
|
|
354
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
355
|
+
} catch {
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function readFile(snapshot, path) {
|
|
360
|
+
const entry = snapshot.files[path];
|
|
361
|
+
return entry?.type === "file" ? entry.content : null;
|
|
362
|
+
}
|
|
363
|
+
function provenanceFor(snapshot, label) {
|
|
364
|
+
return {
|
|
365
|
+
kind: snapshot.repo.kind,
|
|
366
|
+
repoHandle: snapshot.repo.repoHandle,
|
|
367
|
+
commitHash: snapshot.commit.commitHash,
|
|
368
|
+
...label ? { label } : {}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function endpointForKind(kind) {
|
|
372
|
+
return kind === "memory" ? "memory" : `${kind}s`;
|
|
373
|
+
}
|
|
374
|
+
function runtimeContextPayload(options) {
|
|
375
|
+
return {
|
|
376
|
+
...options.source ? { source: options.source } : {},
|
|
377
|
+
...options.actorType ? { actorType: options.actorType } : {},
|
|
378
|
+
...options.proposedBy ? { proposedBy: options.proposedBy } : {},
|
|
379
|
+
...options.agentId ? { agentId: options.agentId } : {},
|
|
380
|
+
...options.agentStableId ? { agentStableId: options.agentStableId } : {},
|
|
381
|
+
...options.processId ? { processId: options.processId } : {},
|
|
382
|
+
...options.traceId ? { traceId: options.traceId } : {},
|
|
383
|
+
...options.spanId ? { spanId: options.spanId } : {},
|
|
384
|
+
...options.sessionId ? { sessionId: options.sessionId } : {},
|
|
385
|
+
...options.userId ? { userId: options.userId } : {},
|
|
386
|
+
...options.teamId ? { teamId: options.teamId } : {},
|
|
387
|
+
...options.metadata ? { metadata: options.metadata } : {}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function encodeIdentifier(identifier) {
|
|
391
|
+
return identifier.split("/").filter(Boolean).map((part) => encodeURIComponent(part)).join("/");
|
|
392
|
+
}
|
|
393
|
+
function safeJson(value) {
|
|
394
|
+
try {
|
|
395
|
+
const parsed = JSON.parse(value);
|
|
396
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
397
|
+
} catch {
|
|
398
|
+
return {};
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
var context = {
|
|
402
|
+
fromEnv: GatewayContext.fromEnv
|
|
403
|
+
};
|
|
404
|
+
export {
|
|
405
|
+
GatewayContext,
|
|
406
|
+
GatewayContextConflictError,
|
|
407
|
+
GatewayContextError,
|
|
408
|
+
context,
|
|
409
|
+
renderAgentSystem
|
|
410
|
+
};
|
|
411
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["type ContextRepoKind = \"agent\" | \"prompt\" | \"skill\" | \"memory\";\ntype ContextWritePolicy = \"read_only\" | \"propose\" | \"commit\";\n\ntype ContextFileEntry =\n | {\n type: \"file\";\n content: string;\n mimeType: string;\n mime_type: string;\n }\n | {\n type: \"agent\" | \"skill\";\n repoHandle: string;\n repo_handle: string;\n commitId?: string | null;\n commit_id?: string | null;\n };\n\ntype ContextRepo<TKind extends ContextRepoKind = ContextRepoKind> = {\n id: string;\n repoHandle: string;\n repo_handle: string;\n ownerHandle: string;\n owner_handle: string;\n kind: TKind;\n description: string;\n readme: string;\n tags: string[];\n writePolicy: ContextWritePolicy;\n write_policy: ContextWritePolicy;\n isPublic: boolean;\n is_public: boolean;\n isArchived: boolean;\n is_archived: boolean;\n url?: string;\n createdAt: string;\n created_at: string;\n updatedAt: string;\n updated_at: string;\n};\n\ntype ContextCommit = {\n id: string;\n commitHash: string;\n commit_hash: string;\n parentCommitHash: string | null;\n parent_commit_hash: string | null;\n createdAt: string;\n created_at: string;\n};\n\ntype ContextSnapshot<TKind extends ContextRepoKind = ContextRepoKind> = {\n repo: ContextRepo<TKind>;\n commit: ContextCommit;\n files: Record<string, ContextFileEntry>;\n};\n\ntype ContextListResponse<TKind extends ContextRepoKind = ContextRepoKind> = {\n repos: ContextRepo<TKind>[];\n limit: number;\n offset: number;\n total: number;\n};\n\ntype ContextPushResponse = {\n url: string;\n status: \"committed\" | \"proposed\";\n repoId: string;\n repo_id: string;\n commitId: string | null;\n commit_id: string | null;\n commitHash: string | null;\n commit_hash: string | null;\n proposalId?: string | null;\n proposal_id?: string | null;\n};\n\ntype ContextFileInput =\n | {\n content: string;\n mimeType?: string;\n mime_type?: string;\n }\n | {\n repoHandle?: string;\n repo_handle?: string;\n kind?: \"agent\" | \"skill\";\n type?: \"agent\" | \"skill\";\n commitId?: string | null;\n commit_id?: string | null;\n }\n | null;\n\ntype ContextRuntimeContext = {\n source?: \"sdk\" | \"agent\" | \"dream\" | \"api\" | \"platform\";\n actorType?: \"api_key\" | \"agent\" | \"process\" | \"user\";\n proposedBy?: string;\n agentId?: string;\n agentStableId?: string;\n processId?: string;\n traceId?: string;\n spanId?: string;\n sessionId?: string;\n userId?: string;\n teamId?: string;\n metadata?: Record<string, unknown>;\n};\n\ntype ContextPullOptions = {\n version?: string;\n};\n\ntype ContextListOptions = {\n query?: string;\n isPublic?: boolean;\n isArchived?: boolean;\n limit?: number;\n offset?: number;\n};\n\ntype ContextPushOptions = ContextRuntimeContext & {\n files: Record<string, ContextFileInput>;\n parentCommit?: string;\n description?: string;\n readme?: string;\n tags?: string[];\n isPublic?: boolean;\n writePolicy?: ContextWritePolicy;\n message?: string;\n};\n\ntype ContextRepoRef =\n | string\n | {\n identifier?: string;\n repoHandle?: string;\n repo_handle?: string;\n label?: string;\n version?: string;\n writable?: boolean;\n };\n\ntype ResolvedContextRef<TKind extends ContextRepoKind = ContextRepoKind> = {\n identifier: string;\n version?: string;\n writable?: boolean;\n snapshot: ContextSnapshot<TKind>;\n primaryPath: string | null;\n content: string;\n};\n\ntype ResolvedAgentContext = {\n agent: ContextSnapshot<\"agent\">;\n config: Record<string, unknown>;\n prompt: ResolvedContextRef<\"prompt\"> | null;\n prompts: ResolvedContextRef<\"prompt\">[];\n skills: ResolvedContextRef<\"skill\">[];\n memory: ResolvedContextRef<\"memory\">[];\n system: string;\n renderSystem: (options?: RenderSystemOptions) => string;\n provenance: ContextProvenance[];\n};\n\ntype ContextProvenance = {\n kind: ContextRepoKind;\n repoHandle: string;\n commitHash: string;\n label?: string;\n};\n\ntype RenderSystemOptions = {\n includeAgent?: boolean;\n includePrompts?: boolean;\n includeSkills?: boolean;\n includeMemory?: boolean;\n};\n\ntype GatewayContextConfig = {\n host: string;\n publicKey: string;\n secretKey: string;\n debug?: boolean;\n};\n\ntype GatewayContextFromEnvConfig = Partial<GatewayContextConfig>;\n\nexport class GatewayContextError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = \"GatewayContextError\";\n this.cause = options?.cause;\n }\n}\n\nexport class GatewayContextConflictError extends GatewayContextError {\n readonly latestCommit: unknown;\n\n constructor(message: string, latestCommit: unknown) {\n super(message);\n this.name = \"GatewayContextConflictError\";\n this.latestCommit = latestCommit;\n }\n}\n\nexport class GatewayContext {\n private readonly host: string;\n private readonly publicKey: string;\n private readonly secretKey: string;\n private readonly debug: boolean;\n\n constructor(config: GatewayContextConfig) {\n this.host = config.host.replace(/\\/$/, \"\");\n this.publicKey = config.publicKey;\n this.secretKey = config.secretKey;\n this.debug = config.debug ?? false;\n }\n\n static fromEnv(config: GatewayContextFromEnvConfig = {}) {\n const host =\n config.host ?? process.env.GATEWAY_HOST ?? process.env.GATEWAY_HOST;\n const publicKey =\n config.publicKey ??\n process.env.GATEWAY_PUBLIC_KEY ??\n process.env.GATEWAY_PUBLIC_KEY;\n const secretKey =\n config.secretKey ??\n process.env.GATEWAY_SECRET_KEY ??\n process.env.GATEWAY_SECRET_KEY;\n\n const missing = [\n [\"host\", host],\n [\"publicKey\", publicKey],\n [\"secretKey\", secretKey],\n ]\n .filter(([, value]) => !value)\n .map(([name]) => name);\n\n if (missing.length > 0) {\n throw new GatewayContextError(\n `Missing Gateway context configuration: ${missing.join(\", \")}`,\n );\n }\n\n return new GatewayContext({\n ...config,\n host: host!,\n publicKey: publicKey!,\n secretKey: secretKey!,\n });\n }\n\n pullAgent(identifier: string, options: ContextPullOptions = {}) {\n return this.pull(\"agent\", identifier, options);\n }\n\n pullPrompt(identifier: string, options: ContextPullOptions = {}) {\n return this.pull(\"prompt\", identifier, options);\n }\n\n pullSkill(identifier: string, options: ContextPullOptions = {}) {\n return this.pull(\"skill\", identifier, options);\n }\n\n pullMemory(identifier: string, options: ContextPullOptions = {}) {\n return this.pull(\"memory\", identifier, options);\n }\n\n pushAgent(identifier: string, options: ContextPushOptions) {\n return this.push(\"agent\", identifier, options);\n }\n\n pushPrompt(identifier: string, options: ContextPushOptions) {\n return this.push(\"prompt\", identifier, options);\n }\n\n pushSkill(identifier: string, options: ContextPushOptions) {\n return this.push(\"skill\", identifier, options);\n }\n\n pushMemory(identifier: string, options: ContextPushOptions) {\n return this.push(\"memory\", identifier, options);\n }\n\n listAgents(options: ContextListOptions = {}) {\n return this.list(\"agent\", options);\n }\n\n listPrompts(options: ContextListOptions = {}) {\n return this.list(\"prompt\", options);\n }\n\n listSkills(options: ContextListOptions = {}) {\n return this.list(\"skill\", options);\n }\n\n listMemory(options: ContextListOptions = {}) {\n return this.list(\"memory\", options);\n }\n\n agentExists(identifier: string) {\n return this.exists(\"agent\", identifier);\n }\n\n promptExists(identifier: string) {\n return this.exists(\"prompt\", identifier);\n }\n\n skillExists(identifier: string) {\n return this.exists(\"skill\", identifier);\n }\n\n memoryExists(identifier: string) {\n return this.exists(\"memory\", identifier);\n }\n\n deleteAgent(identifier: string) {\n return this.delete(\"agent\", identifier);\n }\n\n deletePrompt(identifier: string) {\n return this.delete(\"prompt\", identifier);\n }\n\n deleteSkill(identifier: string) {\n return this.delete(\"skill\", identifier);\n }\n\n deleteMemory(identifier: string) {\n return this.delete(\"memory\", identifier);\n }\n\n async resolveAgent(\n identifier: string,\n runtimeContext: ContextRuntimeContext = {},\n ): Promise<ResolvedAgentContext> {\n const agent = await this.pullAgent(identifier);\n const config = parseJsonFile(agent, \"config.json\");\n const prompts = await this.resolveRefs(\"prompt\", getPromptRefs(config));\n const skills = await this.resolveRefs(\"skill\", getRefList(config.skills));\n const memory = await this.resolveRefs(\"memory\", getRefList(config.memory));\n const bundleBase = {\n agent,\n config,\n prompt: prompts[0] ?? null,\n prompts,\n skills,\n memory,\n provenance: [\n provenanceFor(agent),\n ...prompts.map(({ snapshot, version }) => provenanceFor(snapshot, version)),\n ...skills.map(({ snapshot, version }) => provenanceFor(snapshot, version)),\n ...memory.map(({ snapshot, version }) => provenanceFor(snapshot, version)),\n ],\n };\n\n const renderSystem = (options: RenderSystemOptions = {}) =>\n renderAgentSystem(bundleBase, options);\n\n if (Object.keys(runtimeContext).length > 0) {\n this.log(\"resolveAgent runtime context %o\", runtimeContext);\n }\n\n return {\n ...bundleBase,\n system: renderSystem(),\n renderSystem,\n };\n }\n\n async pull<TKind extends ContextRepoKind>(\n kind: TKind,\n identifier: string,\n options: ContextPullOptions = {},\n ): Promise<ContextSnapshot<TKind>> {\n const query = new URLSearchParams();\n if (options.version) query.set(\"version\", options.version);\n const suffix = query.toString() ? `?${query.toString()}` : \"\";\n return this.requestJson<ContextSnapshot<TKind>>(\n \"GET\",\n `/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(\n identifier,\n )}${suffix}`,\n );\n }\n\n async push<TKind extends ContextRepoKind>(\n kind: TKind,\n identifier: string,\n options: ContextPushOptions,\n ): Promise<ContextPushResponse> {\n return this.requestJson<ContextPushResponse>(\n \"POST\",\n `/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(\n identifier,\n )}`,\n {\n files: options.files,\n ...(options.parentCommit ? { parentCommit: options.parentCommit } : {}),\n ...(options.description ? { description: options.description } : {}),\n ...(options.readme ? { readme: options.readme } : {}),\n ...(options.tags ? { tags: options.tags } : {}),\n ...(options.isPublic !== undefined ? { isPublic: options.isPublic } : {}),\n ...(options.writePolicy ? { writePolicy: options.writePolicy } : {}),\n ...(options.message ? { message: options.message } : {}),\n ...runtimeContextPayload(options),\n },\n );\n }\n\n async list<TKind extends ContextRepoKind>(\n kind: TKind,\n options: ContextListOptions = {},\n ): Promise<ContextListResponse<TKind>> {\n const query = new URLSearchParams();\n if (options.query) query.set(\"query\", options.query);\n if (options.isPublic !== undefined) query.set(\"isPublic\", String(options.isPublic));\n if (options.isArchived !== undefined)\n query.set(\"isArchived\", String(options.isArchived));\n if (options.limit !== undefined) query.set(\"limit\", String(options.limit));\n if (options.offset !== undefined) query.set(\"offset\", String(options.offset));\n const suffix = query.toString() ? `?${query.toString()}` : \"\";\n return this.requestJson<ContextListResponse<TKind>>(\n \"GET\",\n `/api/public/context/${endpointForKind(kind)}${suffix}`,\n );\n }\n\n async exists(kind: ContextRepoKind, identifier: string): Promise<boolean> {\n const query = new URLSearchParams({ exists: \"true\" });\n const response = await this.requestJson<{ exists: boolean }>(\n \"GET\",\n `/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(\n identifier,\n )}?${query.toString()}`,\n );\n return response.exists;\n }\n\n async delete(kind: ContextRepoKind, identifier: string) {\n return this.requestJson<{ deleted: boolean; repoHandle: string; repo_handle: string }>(\n \"DELETE\",\n `/api/public/context/${endpointForKind(kind)}/${encodeIdentifier(identifier)}`,\n );\n }\n\n private async resolveRefs<TKind extends ContextRepoKind>(\n kind: TKind,\n refs: ContextRepoRef[],\n ): Promise<ResolvedContextRef<TKind>[]> {\n const resolved: ResolvedContextRef<TKind>[] = [];\n for (const ref of refs) {\n const normalized = normalizeRef(ref);\n if (!normalized) continue;\n const snapshot = await this.pull(kind, normalized.identifier, {\n version: normalized.version,\n });\n const primaryPath = primaryPathForKind(kind, snapshot);\n const content = primaryPath ? readFile(snapshot, primaryPath) ?? \"\" : \"\";\n resolved.push({\n ...normalized,\n snapshot,\n primaryPath,\n content,\n });\n }\n return resolved;\n }\n\n private async requestJson<TResponse>(\n method: \"GET\" | \"POST\" | \"DELETE\",\n path: string,\n payload?: Record<string, unknown>,\n ): Promise<TResponse> {\n const response = await fetch(`${this.host}${path}`, {\n method,\n headers: {\n Authorization: this.authHeader(),\n ...(payload ? { \"Content-Type\": \"application/json\" } : {}),\n },\n ...(payload ? { body: JSON.stringify(payload) } : {}),\n });\n\n const text = await response.text();\n const body = text ? safeJson(text) : {};\n if (!response.ok) {\n const message =\n typeof body.message === \"string\"\n ? body.message\n : `Gateway API ${response.status} on ${path}`;\n if (response.status === 409) {\n throw new GatewayContextConflictError(\n message,\n body.latestCommit ?? null,\n );\n }\n throw new GatewayContextError(message);\n }\n\n this.log(\"%s %s -> %s\", method, path, response.status);\n return body as TResponse;\n }\n\n private authHeader() {\n return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(\n \"base64\",\n )}`;\n }\n\n private log(message: string, ...args: unknown[]) {\n if (this.debug) {\n console.log(`[gateway.context] ${message}`, ...args);\n }\n }\n}\n\nfunction renderAgentSystem(\n bundle: Omit<ResolvedAgentContext, \"system\" | \"renderSystem\">,\n options: RenderSystemOptions = {},\n) {\n const includeAgent = options.includeAgent ?? true;\n const includePrompts = options.includePrompts ?? true;\n const includeSkills = options.includeSkills ?? true;\n const includeMemory = options.includeMemory ?? false;\n const sections: string[] = [];\n\n if (includeAgent) {\n const agentContent = readFile(bundle.agent, \"AGENTS.md\");\n if (agentContent) sections.push(formatSection(\"Agent\", bundle.agent, agentContent));\n }\n\n if (includePrompts) {\n for (const prompt of bundle.prompts) {\n if (prompt.content) {\n sections.push(formatSection(\"Prompt\", prompt.snapshot, prompt.content));\n }\n }\n }\n\n if (includeSkills) {\n for (const skill of bundle.skills) {\n if (skill.content) {\n sections.push(formatSection(\"Skill\", skill.snapshot, skill.content));\n }\n }\n }\n\n if (includeMemory) {\n for (const memory of bundle.memory) {\n if (memory.content) {\n sections.push(formatSection(\"Memory\", memory.snapshot, memory.content));\n }\n }\n }\n\n return sections.join(\"\\n\\n---\\n\\n\");\n}\n\nfunction formatSection(\n title: string,\n snapshot: ContextSnapshot,\n content: string,\n) {\n return [\n `# ${title}: ${snapshot.repo.repoHandle}`,\n `<!-- commit: ${snapshot.commit.commitHash} -->`,\n \"\",\n content.trim(),\n ].join(\"\\n\");\n}\n\nfunction getPromptRefs(config: Record<string, unknown>): ContextRepoRef[] {\n const refs = [\n ...getRefList(config.prompt),\n ...getRefList(config.promptRef),\n ...getRefList(config.prompt_ref),\n ...getRefList(config.prompts),\n ];\n return dedupeRefs(refs);\n}\n\nfunction getRefList(value: unknown): ContextRepoRef[] {\n if (!value) return [];\n if (typeof value === \"string\") return [value];\n if (Array.isArray(value)) return value.filter(isContextRepoRef);\n if (isContextRepoRef(value)) return [value];\n return [];\n}\n\nfunction isContextRepoRef(value: unknown): value is ContextRepoRef {\n if (typeof value === \"string\") return true;\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n const record = value as Record<string, unknown>;\n return [\"identifier\", \"repoHandle\", \"repo_handle\"].some(\n (key) => typeof record[key] === \"string\",\n );\n}\n\nfunction dedupeRefs(refs: ContextRepoRef[]) {\n const seen = new Set<string>();\n return refs.filter((ref) => {\n const normalized = normalizeRef(ref);\n if (!normalized) return false;\n const key = `${normalized.identifier}:${normalized.version ?? \"\"}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n\nfunction normalizeRef(ref: ContextRepoRef) {\n if (typeof ref === \"string\") {\n const identifier = ref.trim();\n return identifier ? { identifier } : null;\n }\n\n const identifier = (\n ref.identifier ??\n ref.repoHandle ??\n ref.repo_handle ??\n \"\"\n ).trim();\n if (!identifier) return null;\n\n return {\n identifier,\n version: ref.version ?? ref.label,\n writable: ref.writable,\n };\n}\n\nfunction primaryPathForKind(kind: ContextRepoKind, snapshot: ContextSnapshot) {\n const preferred =\n kind === \"agent\"\n ? \"AGENTS.md\"\n : kind === \"prompt\"\n ? \"PROMPT.md\"\n : kind === \"skill\"\n ? \"SKILL.md\"\n : \"MEMORY.md\";\n if (readFile(snapshot, preferred)) return preferred;\n return (\n Object.entries(snapshot.files).find(\n ([path, entry]) => entry.type === \"file\" && path.endsWith(\".md\"),\n )?.[0] ?? null\n );\n}\n\nfunction parseJsonFile(snapshot: ContextSnapshot, path: string) {\n const content = readFile(snapshot, path);\n if (!content) return {};\n try {\n const parsed = JSON.parse(content);\n return parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\nfunction readFile(snapshot: ContextSnapshot, path: string) {\n const entry = snapshot.files[path];\n return entry?.type === \"file\" ? entry.content : null;\n}\n\nfunction provenanceFor(\n snapshot: ContextSnapshot,\n label?: string,\n): ContextProvenance {\n return {\n kind: snapshot.repo.kind,\n repoHandle: snapshot.repo.repoHandle,\n commitHash: snapshot.commit.commitHash,\n ...(label ? { label } : {}),\n };\n}\n\nfunction endpointForKind(kind: ContextRepoKind) {\n return kind === \"memory\" ? \"memory\" : `${kind}s`;\n}\n\nfunction runtimeContextPayload(options: ContextRuntimeContext) {\n return {\n ...(options.source ? { source: options.source } : {}),\n ...(options.actorType ? { actorType: options.actorType } : {}),\n ...(options.proposedBy ? { proposedBy: options.proposedBy } : {}),\n ...(options.agentId ? { agentId: options.agentId } : {}),\n ...(options.agentStableId ? { agentStableId: options.agentStableId } : {}),\n ...(options.processId ? { processId: options.processId } : {}),\n ...(options.traceId ? { traceId: options.traceId } : {}),\n ...(options.spanId ? { spanId: options.spanId } : {}),\n ...(options.sessionId ? { sessionId: options.sessionId } : {}),\n ...(options.userId ? { userId: options.userId } : {}),\n ...(options.teamId ? { teamId: options.teamId } : {}),\n ...(options.metadata ? { metadata: options.metadata } : {}),\n };\n}\n\nfunction encodeIdentifier(identifier: string) {\n return identifier\n .split(\"/\")\n .filter(Boolean)\n .map((part) => encodeURIComponent(part))\n .join(\"/\");\n}\n\nfunction safeJson(value: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(value);\n return parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\nexport const context = {\n fromEnv: GatewayContext.fromEnv,\n};\n\nexport { renderAgentSystem };\n\nexport type {\n GatewayContextConfig,\n ContextCommit as GatewayContextCommit,\n ContextFileEntry as GatewayContextFileEntry,\n ContextFileInput as GatewayContextFileInput,\n ContextListOptions as GatewayContextListOptions,\n ContextListResponse as GatewayContextListResponse,\n ContextPullOptions as GatewayContextPullOptions,\n ContextPushOptions as GatewayContextPushOptions,\n ContextPushResponse as GatewayContextPushResponse,\n ContextRepo as GatewayContextRepo,\n ContextRepoKind as GatewayContextRepoKind,\n ContextRuntimeContext as GatewayContextRuntimeContext,\n ContextSnapshot as GatewayContextSnapshot,\n ContextWritePolicy as GatewayContextWritePolicy,\n RenderSystemOptions as GatewayRenderSystemOptions,\n ResolvedAgentContext as GatewayResolvedAgentContext,\n ResolvedContextRef as GatewayResolvedContextRef,\n};\n"],"mappings":";AA0LO,IAAM,sBAAN,cAAkC,MAAM;A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