catelog 0.0.0-stage → 1.0.1
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/DECISION.md +250 -0
- package/LICENSE +21 -0
- package/README.md +117 -2
- package/dist/agent.d.ts +38 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +309 -0
- package/dist/agent.js.map +1 -0
- package/dist/banner.d.ts +9 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +76 -0
- package/dist/banner.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +75 -0
- package/dist/schema.js.map +1 -0
- package/dist/security.d.ts +52 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +126 -0
- package/dist/security.js.map +1 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +26 -0
- package/dist/server.js.map +1 -0
- package/dist/sse.d.ts +32 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +141 -0
- package/dist/sse.js.map +1 -0
- package/dist/types.d.ts +128 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -4
- package/scripts/postinstall.js +61 -0
package/dist/security.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export class SecurityVerificationError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
statusCode;
|
|
5
|
+
constructor(code, message, statusCode = 401) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.name = "SecurityVerificationError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class SecurityManager {
|
|
13
|
+
secret;
|
|
14
|
+
maxTimestampDriftMs;
|
|
15
|
+
nonceTtlMs;
|
|
16
|
+
seenNonces = new Map();
|
|
17
|
+
activeRunIds = new Set();
|
|
18
|
+
completedRunIds = new Map();
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
this.secret = options.secret;
|
|
21
|
+
this.maxTimestampDriftMs = options.maxTimestampDriftMs ?? 300_000; // 5 minutes
|
|
22
|
+
this.nonceTtlMs = options.nonceTtlMs ?? 300_000; // 5 minutes
|
|
23
|
+
}
|
|
24
|
+
setSecret(secret) {
|
|
25
|
+
this.secret = secret;
|
|
26
|
+
}
|
|
27
|
+
getSecret() {
|
|
28
|
+
return this.secret;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Computes SHA-256 hash in lowercase hex of request body
|
|
32
|
+
*/
|
|
33
|
+
computeBodyHash(rawBody) {
|
|
34
|
+
return createHash("sha256").update(rawBody).digest("hex");
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Constructs the canonical string according to MAPS 1.0.0:
|
|
38
|
+
* METHOD\nPATH\nTIMESTAMP\nNONCE\nRUN_ID\nBodyHash
|
|
39
|
+
*/
|
|
40
|
+
buildCanonicalString(method, path, timestamp, nonce, runId, bodyHash) {
|
|
41
|
+
const normalizedMethod = method.toUpperCase();
|
|
42
|
+
const normalizedPath = path.split("?")[0] || "/";
|
|
43
|
+
return `${normalizedMethod}\n${normalizedPath}\n${timestamp}\n${nonce}\n${runId}\n${bodyHash}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Calculates HMAC-SHA256 signature in lowercase hex
|
|
47
|
+
*/
|
|
48
|
+
calculateSignature(canonicalString, secret) {
|
|
49
|
+
return createHmac("sha256", secret).update(canonicalString).digest("hex");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verifies headers, timestamp, nonce, and HMAC-SHA256 signature.
|
|
53
|
+
*/
|
|
54
|
+
verifyRequest(params) {
|
|
55
|
+
this.cleanupOldEntries();
|
|
56
|
+
// If no secret configured, skip HMAC check (e.g. local dev / unauthenticated mode)
|
|
57
|
+
if (!this.secret) {
|
|
58
|
+
const runId = params.headers["x-marketplace-run-id"] || "dev-run-id";
|
|
59
|
+
const nonce = params.headers["x-marketplace-nonce"] || "dev-nonce";
|
|
60
|
+
const timestamp = Date.now();
|
|
61
|
+
return { runId, nonce, timestamp };
|
|
62
|
+
}
|
|
63
|
+
const timestampHeader = params.headers["x-marketplace-timestamp"];
|
|
64
|
+
const nonceHeader = params.headers["x-marketplace-nonce"];
|
|
65
|
+
const runIdHeader = params.headers["x-marketplace-run-id"];
|
|
66
|
+
const signatureHeader = params.headers["x-marketplace-signature"];
|
|
67
|
+
if (!timestampHeader || !nonceHeader || !runIdHeader || !signatureHeader) {
|
|
68
|
+
throw new SecurityVerificationError("AUTH_INVALID_SIGNATURE", "Missing required marketplace authentication headers", 401);
|
|
69
|
+
}
|
|
70
|
+
const timestamp = Number.parseInt(timestampHeader, 10);
|
|
71
|
+
if (Number.isNaN(timestamp)) {
|
|
72
|
+
throw new SecurityVerificationError("AUTH_TIMESTAMP_OUT_OF_BOUNDS", "Malformed X-Marketplace-Timestamp header", 401);
|
|
73
|
+
}
|
|
74
|
+
// 1. Timestamp Bounds: Reject if |CurrentTime - Timestamp| > 5 minutes
|
|
75
|
+
const now = Date.now();
|
|
76
|
+
if (Math.abs(now - timestamp) > this.maxTimestampDriftMs) {
|
|
77
|
+
throw new SecurityVerificationError("AUTH_TIMESTAMP_OUT_OF_BOUNDS", `Timestamp out of allowable bounds (clock drift > ${this.maxTimestampDriftMs}ms)`, 401);
|
|
78
|
+
}
|
|
79
|
+
// 2. Nonce Uniqueness: Sliding cache
|
|
80
|
+
if (this.seenNonces.has(nonceHeader)) {
|
|
81
|
+
throw new SecurityVerificationError("AUTH_REPLAY_DETECTED", "Duplicate nonce detected (replay attack guard)", 401);
|
|
82
|
+
}
|
|
83
|
+
// 3. Run ID Idempotency: Duplicate active or completed run
|
|
84
|
+
if (this.activeRunIds.has(runIdHeader) || this.completedRunIds.has(runIdHeader)) {
|
|
85
|
+
throw new SecurityVerificationError("AUTH_REPLAY_DETECTED", `Run ID ${runIdHeader} is currently executing or has already been completed`, 401);
|
|
86
|
+
}
|
|
87
|
+
// 4. Verify HMAC signature
|
|
88
|
+
const bodyHash = this.computeBodyHash(params.rawBody);
|
|
89
|
+
const canonicalString = this.buildCanonicalString(params.method, params.path, timestampHeader, nonceHeader, runIdHeader, bodyHash);
|
|
90
|
+
const expectedSignature = this.calculateSignature(canonicalString, this.secret);
|
|
91
|
+
const sigBuf = Buffer.from(signatureHeader.toLowerCase(), "utf8");
|
|
92
|
+
const expBuf = Buffer.from(expectedSignature.toLowerCase(), "utf8");
|
|
93
|
+
if (sigBuf.length !== expBuf.length || !timingSafeEqual(sigBuf, expBuf)) {
|
|
94
|
+
throw new SecurityVerificationError("AUTH_INVALID_SIGNATURE", "HMAC-SHA256 signature verification failed", 401);
|
|
95
|
+
}
|
|
96
|
+
// Mark nonce as seen
|
|
97
|
+
this.seenNonces.set(nonceHeader, now);
|
|
98
|
+
return {
|
|
99
|
+
runId: runIdHeader,
|
|
100
|
+
nonce: nonceHeader,
|
|
101
|
+
timestamp,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
markRunStarted(runId) {
|
|
105
|
+
this.activeRunIds.add(runId);
|
|
106
|
+
}
|
|
107
|
+
markRunCompleted(runId) {
|
|
108
|
+
this.activeRunIds.delete(runId);
|
|
109
|
+
this.completedRunIds.set(runId, Date.now());
|
|
110
|
+
}
|
|
111
|
+
cleanupOldEntries() {
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
const expiry = now - this.nonceTtlMs;
|
|
114
|
+
for (const [nonce, time] of this.seenNonces.entries()) {
|
|
115
|
+
if (time < expiry) {
|
|
116
|
+
this.seenNonces.delete(nonce);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const [runId, time] of this.completedRunIds.entries()) {
|
|
120
|
+
if (time < expiry) {
|
|
121
|
+
this.completedRunIds.delete(runId);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAStE,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAEhC;IAEA;IAHlB,YACkB,IAAe,EAC/B,OAAe,EACC,aAAqB,GAAG;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAW;QAEf,eAAU,GAAV,UAAU,CAAc;QAGxC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IAClB,MAAM,CAAU;IAChB,mBAAmB,CAAS;IAC5B,UAAU,CAAS;IACnB,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,eAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEpD,YAAY,UAA2B,EAAE;QACvC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,OAAO,CAAC,CAAC,YAAY;QAC/E,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC,YAAY;IAC/D,CAAC;IAEM,SAAS,CAAC,MAAc;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,eAAe,CAAC,OAAwB;QAC7C,OAAO,UA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iB;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;QAErC,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC;YACtD,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;gBAClB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QAED,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3D,IAAI,IAAI,GAAG,MAAM,EAAE,CAAC;gBAClB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Server } from "node:http";
|
|
2
|
+
import type { MarketplaceAgent } from "./agent.js";
|
|
3
|
+
export interface ServerOptions {
|
|
4
|
+
port?: number;
|
|
5
|
+
host?: string;
|
|
6
|
+
silent?: boolean;
|
|
7
|
+
onListening?: (url: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function startAgentServer(agent: MarketplaceAgent<any, any>, options?: ServerOptions): Server;
|
|
10
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAA6C,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAwBvG"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { renderBanner } from "./banner.js";
|
|
3
|
+
export function startAgentServer(agent, options = {}) {
|
|
4
|
+
const port = options.port ?? (process.env.PORT ? Number.parseInt(process.env.PORT, 10) : 3000);
|
|
5
|
+
const host = options.host ?? "0.0.0.0";
|
|
6
|
+
const server = createServer((req, res) => {
|
|
7
|
+
agent.handleRequest(req, res).catch((err) => {
|
|
8
|
+
console.error("[catelog-sdk] Unhandled error during request handling:", err);
|
|
9
|
+
if (!res.writableEnded) {
|
|
10
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
11
|
+
res.end(JSON.stringify({ error: { code: "INTERNAL_CRASH", message: "Server encountered an unhandled error" } }));
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
server.listen(port, host, () => {
|
|
16
|
+
const url = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
17
|
+
if (options.onListening) {
|
|
18
|
+
options.onListening(url);
|
|
19
|
+
}
|
|
20
|
+
else if (!options.silent) {
|
|
21
|
+
renderBanner("startup", { name: agent.name, url });
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return server;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AAEjG,OAAO,E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AC;QAC3B,CAAC;aAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAC3B,YAAY,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
import type { AgentStream, StructuredError, TelemetryData } from "./types.js";
|
|
3
|
+
export interface SSEWriterOptions {
|
|
4
|
+
heartbeatIntervalMs?: number;
|
|
5
|
+
onClientDisconnect?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare class SSEWriter implements AgentStream {
|
|
8
|
+
private runId;
|
|
9
|
+
private res;
|
|
10
|
+
private heartbeatTimer?;
|
|
11
|
+
private stepIndex;
|
|
12
|
+
private deltaIndex;
|
|
13
|
+
private closed;
|
|
14
|
+
private abortController;
|
|
15
|
+
constructor(runId: string, res: ServerResponse, options?: SSEWriterOptions);
|
|
16
|
+
get signal(): AbortSignal;
|
|
17
|
+
isClosed(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Generic raw event sender adhering to SSE framing:
|
|
20
|
+
* event: <EVENT_TYPE>\ndata: <JSON_STRING>\n\n
|
|
21
|
+
*/
|
|
22
|
+
sendEvent(eventType: string, data: unknown): void;
|
|
23
|
+
sendRunStarted(): void;
|
|
24
|
+
step(label: string): void;
|
|
25
|
+
delta(content: string, delta_type?: "text" | "json_patch"): void;
|
|
26
|
+
emit(event: string, data: unknown): void;
|
|
27
|
+
sendRunSucceeded<TOutput>(output: TOutput, durationMs: number, telemetry?: TelemetryData): void;
|
|
28
|
+
sendRunFailed(error: StructuredError, durationMs: number): void;
|
|
29
|
+
close(): void;
|
|
30
|
+
private clearHeartbeat;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=sse.d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AU,EAAE,MAAM,GAAG,IAAI;IAY/D,KAAK,IAAI,IAAI;IAWpB,OAAO,CAAC,cAAc;CAMvB"}
|
package/dist/sse.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export class SSEWriter {
|
|
2
|
+
runId;
|
|
3
|
+
res;
|
|
4
|
+
heartbeatTimer;
|
|
5
|
+
stepIndex = 0;
|
|
6
|
+
deltaIndex = 0;
|
|
7
|
+
closed = false;
|
|
8
|
+
abortController;
|
|
9
|
+
constructor(runId, res, options = {}) {
|
|
10
|
+
this.runId = runId;
|
|
11
|
+
this.res = res;
|
|
12
|
+
this.abortController = new AbortController();
|
|
13
|
+
// Set standard SSE headers
|
|
14
|
+
this.res.writeHead(200, {
|
|
15
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
16
|
+
"Cache-Control": "no-cache, no-transform",
|
|
17
|
+
Connection: "keep-alive",
|
|
18
|
+
"X-Accel-Buffering": "no",
|
|
19
|
+
});
|
|
20
|
+
// Flush headers if supported
|
|
21
|
+
if (typeof this.res.flushHeaders === "function") {
|
|
22
|
+
this.res.flushHeaders();
|
|
23
|
+
}
|
|
24
|
+
// Client disconnect detection
|
|
25
|
+
this.res.on("close", () => {
|
|
26
|
+
if (!this.closed) {
|
|
27
|
+
this.closed = true;
|
|
28
|
+
this.clearHeartbeat();
|
|
29
|
+
this.abortController.abort();
|
|
30
|
+
options.onClientDisconnect?.();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Start 15-second heartbeat
|
|
34
|
+
const interval = options.heartbeatIntervalMs ?? 15_000;
|
|
35
|
+
this.heartbeatTimer = setInterval(() => {
|
|
36
|
+
if (!this.closed) {
|
|
37
|
+
this.sendEvent("heartbeat", {
|
|
38
|
+
event: "heartbeat",
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}, interval);
|
|
43
|
+
}
|
|
44
|
+
get signal() {
|
|
45
|
+
return this.abortController.signal;
|
|
46
|
+
}
|
|
47
|
+
isClosed() {
|
|
48
|
+
return this.closed;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Generic raw event sender adhering to SSE framing:
|
|
52
|
+
* event: <EVENT_TYPE>\ndata: <JSON_STRING>\n\n
|
|
53
|
+
*/
|
|
54
|
+
sendEvent(eventType, data) {
|
|
55
|
+
if (this.closed)
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
this.res.write(`event: ${eventType}\ndata: ${JSON.stringify(data)}\n\n`);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
this.closed = true;
|
|
62
|
+
this.clearHeartbeat();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
sendRunStarted() {
|
|
66
|
+
const payload = {
|
|
67
|
+
event: "run.started",
|
|
68
|
+
run_id: this.runId,
|
|
69
|
+
timestamp: Date.now(),
|
|
70
|
+
};
|
|
71
|
+
this.sendEvent("run.started", payload);
|
|
72
|
+
}
|
|
73
|
+
step(label) {
|
|
74
|
+
this.stepIndex += 1;
|
|
75
|
+
const payload = {
|
|
76
|
+
event: "step.started",
|
|
77
|
+
run_id: this.runId,
|
|
78
|
+
step_index: this.stepIndex,
|
|
79
|
+
label,
|
|
80
|
+
timestamp: Date.now(),
|
|
81
|
+
};
|
|
82
|
+
this.sendEvent("step.started", payload);
|
|
83
|
+
}
|
|
84
|
+
delta(content, delta_type = "text") {
|
|
85
|
+
const payload = {
|
|
86
|
+
event: "output.delta",
|
|
87
|
+
run_id: this.runId,
|
|
88
|
+
index: this.deltaIndex++,
|
|
89
|
+
delta_type,
|
|
90
|
+
content,
|
|
91
|
+
};
|
|
92
|
+
this.sendEvent("output.delta", payload);
|
|
93
|
+
}
|
|
94
|
+
emit(event, data) {
|
|
95
|
+
this.sendEvent(event, data);
|
|
96
|
+
}
|
|
97
|
+
sendRunSucceeded(output, durationMs, telemetry) {
|
|
98
|
+
if (this.closed)
|
|
99
|
+
return;
|
|
100
|
+
const payload = {
|
|
101
|
+
event: "run.succeeded",
|
|
102
|
+
run_id: this.runId,
|
|
103
|
+
duration_ms: durationMs,
|
|
104
|
+
output,
|
|
105
|
+
telemetry,
|
|
106
|
+
};
|
|
107
|
+
this.sendEvent("run.succeeded", payload);
|
|
108
|
+
this.close();
|
|
109
|
+
}
|
|
110
|
+
sendRunFailed(error, durationMs) {
|
|
111
|
+
if (this.closed)
|
|
112
|
+
return;
|
|
113
|
+
const payload = {
|
|
114
|
+
event: "run.failed",
|
|
115
|
+
run_id: this.runId,
|
|
116
|
+
duration_ms: durationMs,
|
|
117
|
+
error,
|
|
118
|
+
};
|
|
119
|
+
this.sendEvent("run.failed", payload);
|
|
120
|
+
this.close();
|
|
121
|
+
}
|
|
122
|
+
close() {
|
|
123
|
+
if (this.closed)
|
|
124
|
+
return;
|
|
125
|
+
this.closed = true;
|
|
126
|
+
this.clearHeartbeat();
|
|
127
|
+
try {
|
|
128
|
+
this.res.end();
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
// Ignore write errors on close
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
clearHeartbeat() {
|
|
135
|
+
if (this.heartbeatTimer) {
|
|
136
|
+
clearInterval(this.heartbeatTimer);
|
|
137
|
+
this.heartbeatTimer = undefined;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=sse.js.map
|
package/dist/sse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,SAAS;IACZ,KAAK,CAAS;IACd,GAAG,CAAiB;IACpB,cAAc,CAAkB;IAChC,SAAS,GAAG,CAAC,CAAC;IACd,UAAU,GAAG,CAAC,CAAC;IACf,MAAM,GAAG,KAAK,CAAC;IACf,eAAe,CAAkB;IAEzC,YAAY,KAAa,EAAE,GAAmB,EAAE,UAA4B,EAAE;QA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C,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION = "1.0.0";
|
|
2
|
+
/**
|
|
3
|
+
* Standard error codes defined by Marketplace Agent Protocol Specification (MAPS)
|
|
4
|
+
*/
|
|
5
|
+
export type ErrorCode = "AUTH_INVALID_SIGNATURE" | "AUTH_TIMESTAMP_OUT_OF_BOUNDS" | "AUTH_REPLAY_DETECTED" | "INVALID_INPUT" | "MODEL_RATE_LIMIT" | "UPSTREAM_TIMEOUT" | "EXECUTION_TIMEOUT" | "INTERNAL_CRASH" | "TOOL_FAILURE";
|
|
6
|
+
export interface StructuredError {
|
|
7
|
+
code: ErrorCode | string;
|
|
8
|
+
message: string;
|
|
9
|
+
retryable: boolean;
|
|
10
|
+
details?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface TelemetryData {
|
|
13
|
+
llm_tokens?: {
|
|
14
|
+
prompt?: number;
|
|
15
|
+
completion?: number;
|
|
16
|
+
total?: number;
|
|
17
|
+
};
|
|
18
|
+
model_used?: string;
|
|
19
|
+
cost_usd?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentCapabilities {
|
|
22
|
+
streaming: boolean;
|
|
23
|
+
delta_stream?: boolean;
|
|
24
|
+
max_timeout_seconds?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentManifest {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
description: string;
|
|
31
|
+
protocol_version: string;
|
|
32
|
+
capabilities: AgentCapabilities;
|
|
33
|
+
input_schema: Record<string, unknown>;
|
|
34
|
+
output_schema: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface HealthCheckResponse {
|
|
37
|
+
status: "ready" | "degraded" | "not_ready";
|
|
38
|
+
protocol_version: string;
|
|
39
|
+
uptime_seconds: number;
|
|
40
|
+
environment_ready: boolean;
|
|
41
|
+
details?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface ExecuteRequest<TInput = Record<string, unknown>> {
|
|
44
|
+
run_id: string;
|
|
45
|
+
input: TInput;
|
|
46
|
+
deadline_ms?: number;
|
|
47
|
+
metadata?: {
|
|
48
|
+
buyer_id?: string;
|
|
49
|
+
session_id?: string;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export interface ExecuteSuccessResponse<TOutput = Record<string, unknown>> {
|
|
54
|
+
run_id: string;
|
|
55
|
+
status: "succeeded";
|
|
56
|
+
duration_ms: number;
|
|
57
|
+
output: TOutput;
|
|
58
|
+
error?: false;
|
|
59
|
+
telemetry?: TelemetryData;
|
|
60
|
+
}
|
|
61
|
+
export interface ExecuteFailureResponse {
|
|
62
|
+
run_id: string;
|
|
63
|
+
status: "failed" | "cancelled";
|
|
64
|
+
duration_ms: number;
|
|
65
|
+
error: StructuredError;
|
|
66
|
+
output?: false;
|
|
67
|
+
telemetry?: TelemetryData;
|
|
68
|
+
}
|
|
69
|
+
export type ExecuteResponse<TOutput = Record<string, unknown>> = ExecuteSuccessResponse<TOutput> | ExecuteFailureResponse;
|
|
70
|
+
export interface RunStartedEvent {
|
|
71
|
+
event: "run.started";
|
|
72
|
+
run_id: string;
|
|
73
|
+
timestamp: number;
|
|
74
|
+
}
|
|
75
|
+
export interface StepStartedEvent {
|
|
76
|
+
event: "step.started";
|
|
77
|
+
run_id: string;
|
|
78
|
+
step_index: number;
|
|
79
|
+
label: string;
|
|
80
|
+
timestamp: number;
|
|
81
|
+
}
|
|
82
|
+
export interface OutputDeltaEvent {
|
|
83
|
+
event: "output.delta";
|
|
84
|
+
run_id: string;
|
|
85
|
+
index: number;
|
|
86
|
+
delta_type: "text" | "json_patch";
|
|
87
|
+
content: string;
|
|
88
|
+
}
|
|
89
|
+
export interface HeartbeatEvent {
|
|
90
|
+
event: "heartbeat";
|
|
91
|
+
timestamp: number;
|
|
92
|
+
}
|
|
93
|
+
export interface RunSucceededEvent<TOutput = Record<string, unknown>> {
|
|
94
|
+
event: "run.succeeded";
|
|
95
|
+
run_id: string;
|
|
96
|
+
duration_ms: number;
|
|
97
|
+
output: TOutput;
|
|
98
|
+
telemetry?: TelemetryData;
|
|
99
|
+
}
|
|
100
|
+
export interface RunFailedEvent {
|
|
101
|
+
event: "run.failed";
|
|
102
|
+
run_id: string;
|
|
103
|
+
duration_ms: number;
|
|
104
|
+
error: StructuredError;
|
|
105
|
+
}
|
|
106
|
+
export type SSEProtocolEvent = RunStartedEvent | StepStartedEvent | OutputDeltaEvent | HeartbeatEvent | RunSucceededEvent | RunFailedEvent;
|
|
107
|
+
/**
|
|
108
|
+
* Stream controller passed to agent execute handlers
|
|
109
|
+
*/
|
|
110
|
+
export interface AgentStream {
|
|
111
|
+
step: (label: string) => void;
|
|
112
|
+
delta: (content: string, type?: "text" | "json_patch") => void;
|
|
113
|
+
emit: (event: string, data: unknown) => void;
|
|
114
|
+
isClosed: () => boolean;
|
|
115
|
+
}
|
|
116
|
+
export interface AgentExecutionContext<TInput = Record<string, unknown>> {
|
|
117
|
+
runId: string;
|
|
118
|
+
input: TInput;
|
|
119
|
+
stream: AgentStream;
|
|
120
|
+
signal: AbortSignal;
|
|
121
|
+
metadata?: Record<string, unknown>;
|
|
122
|
+
deadlineMs?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface AgentExecutionResult<TOutput = Record<string, unknown>> {
|
|
125
|
+
output: TOutput;
|
|
126
|
+
telemetry?: TelemetryData;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,wBAAwB,GACxB,8BAA8B,GAC9B,sBAAsB,GACtB,eAAe,GACf,kBA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AAO,CAAC;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,WAAW,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrE,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "catelog",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Official TypeScript SDK for Marketplace Agent Protocol Specification (MAPS)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"catelog": "./scripts/postinstall.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"scripts",
|
|
22
|
+
"README.md",
|
|
23
|
+
"DECISION.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"author": "ROX",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"ai",
|
|
30
|
+
"agent",
|
|
31
|
+
"marketplace",
|
|
32
|
+
"maps",
|
|
33
|
+
"protocol",
|
|
34
|
+
"langgraph",
|
|
35
|
+
"openai",
|
|
36
|
+
"paypal",
|
|
37
|
+
"sdk"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"dev": "tsc --watch",
|
|
42
|
+
"test": "tsx test/index.test.ts",
|
|
43
|
+
"prepublishOnly": "npm run build",
|
|
44
|
+
"postinstall": "node ./scripts/postinstall.js"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"zod": "^3.23.8",
|
|
48
|
+
"zod-to-json-schema": "^3.24.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"tsx": "^4.19.0",
|
|
53
|
+
"typescript": "^5.5.0"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Catelog postinstall hook - Pure zero-dependency Node.js script
|
|
5
|
+
* Runs smoothly in npm, pnpm, yarn, and bun environments.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
if (process.env.CI || process.env.CATELOG_SILENT || process.env.npm_config_loglevel === "silent") {
|
|
9
|
+
process.exit(0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const c = {
|
|
13
|
+
reset: "\x1b[0m",
|
|
14
|
+
bold: "\x1b[1m",
|
|
15
|
+
dim: "\x1b[2m",
|
|
16
|
+
italic: "\x1b[3m",
|
|
17
|
+
cyan: "\x1b[36m",
|
|
18
|
+
brightCyan: "\x1b[96m",
|
|
19
|
+
magenta: "\x1b[35m",
|
|
20
|
+
brightMagenta: "\x1b[95m",
|
|
21
|
+
green: "\x1b[32m",
|
|
22
|
+
yellow: "\x1b[33m",
|
|
23
|
+
brightYellow: "\x1b[93m",
|
|
24
|
+
gray: "\x1b[90m",
|
|
25
|
+
white: "\x1b[97m",
|
|
26
|
+
brightBlue: "\x1b[94m",
|
|
27
|
+
bgMagenta: "\x1b[45m",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const ascii = `
|
|
31
|
+
${c.brightCyan} ██████╗ █████╗ ████████╗███████╗██╗ ██████╗ ██████╗
|
|
32
|
+
${c.brightCyan} ██╔════╝██╔══██╗╚══██╔══╝██╔════╝██║ ██╔═══██╗██╔════╝
|
|
33
|
+
${c.brightMagenta} ██║ ███████║ ██║ █████╗ ██║ ██║ ██║██║ ███╗
|
|
34
|
+
${c.brightMagenta} ██║ ██╔══██║ ██║ ██╔══╝ ██║ ██║ ██║██║ ██║
|
|
35
|
+
${c.magenta} ╚██████╗██║ ██║ ██║ ███████╗███████╗╚██████╔╝╚██████╔╝
|
|
36
|
+
${c.magenta} ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝
|
|
37
|
+
`.trimEnd();
|
|
38
|
+
|
|
39
|
+
const width = 68;
|
|
40
|
+
const line = c.gray + "─".repeat(width) + c.reset;
|
|
41
|
+
const doubleLine = c.brightMagenta + "═".repeat(width) + c.reset;
|
|
42
|
+
|
|
43
|
+
console.log("\n" + doubleLine);
|
|
44
|
+
console.log(ascii);
|
|
45
|
+
console.log(line);
|
|
46
|
+
console.log(` ${c.bgMagenta}${c.white}${c.bold} NOTE FROM TEAM ROX ${c.reset}`);
|
|
47
|
+
console.log(
|
|
48
|
+
` ${c.brightYellow}${c.italic}“Welcome to the agent economy, where humans and agents rent out intelligence.”${c.reset}`
|
|
49
|
+
);
|
|
50
|
+
console.log(line);
|
|
51
|
+
console.log(` ${c.green}✔${c.reset} ${c.bold}Catelog SDK installed successfully!${c.reset}`);
|
|
52
|
+
console.log(` ${c.dim}Supported runtimes & package managers:${c.reset}`);
|
|
53
|
+
console.log(
|
|
54
|
+
` ${c.cyan}pnpm${c.reset} ${c.gray}|${c.reset} ${c.brightBlue}npm${c.reset} ${c.gray}|${c.reset} ${c.brightMagenta}yarn${c.reset} ${c.gray}|${c.reset} ${c.brightYellow}bun${c.reset} ${c.gray}• Node.js 18+ • TypeScript 5+${c.reset}`
|
|
55
|
+
);
|
|
56
|
+
console.log("");
|
|
57
|
+
console.log(` ${c.bold}Quick Start:${c.reset}`);
|
|
58
|
+
console.log(` ${c.dim}import { createMarketplaceAgent } from "catelog";${c.reset}`);
|
|
59
|
+
console.log(` ${c.dim}const agent = createMarketplaceAgent({ ... });${c.reset}`);
|
|
60
|
+
console.log(` ${c.dim}agent.serve(3000);${c.reset}`);
|
|
61
|
+
console.log(doubleLine + "\n");
|