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/DECISION.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Architecture & Design Decisions: Catelog TypeScript SDK (`catelog`)
|
|
2
|
+
|
|
3
|
+
> **Note from Team ROX:**
|
|
4
|
+
> *“Welcome to the agent economy, where humans and agents rent out intelligence.”*
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Executive Summary & Vision
|
|
9
|
+
|
|
10
|
+
As AI agents transition from standalone chat interfaces into autonomous economic actors, developers face a fragmented ecosystem. Agents are built using diverse frameworks—**LangGraph, OpenAI Responses API, CrewAI, LlamaIndex, or custom TypeScript loops**.
|
|
11
|
+
|
|
12
|
+
However, when developers want to monetize or publish their agents on a decentralized, Bring-Your-Own-Server (BYOS) marketplace, they are forced to reinvent low-level infrastructure:
|
|
13
|
+
- Raw HTTP server routing and CORS handling.
|
|
14
|
+
- Cryptographic request signing and anti-replay defense.
|
|
15
|
+
- Server-Sent Events (SSE) streaming with heartbeat keep-alives.
|
|
16
|
+
- JSON Schema generation from TypeScript types.
|
|
17
|
+
- Client disconnect / cancellation propagation.
|
|
18
|
+
|
|
19
|
+
**`catelog` is the official, open-source TypeScript SDK designed to solve this problem.** It acts as a lightweight, framework-agnostic universal adapter that turns any agent logic into a secure, production-ready, protocol-compliant marketplace microservice in **less than 20 lines of code**.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 2. Core Architectural Decisions
|
|
24
|
+
|
|
25
|
+
### Decision 1: Canonical Protocol Specification (MAPS v1.0.0)
|
|
26
|
+
* **Context:** The marketplace requires standardized communication contracts between the Gateway and BYOS agent servers.
|
|
27
|
+
* **Decision:** `catelog` strictly implements the **Marketplace Agent Protocol Specification (MAPS v1.0.0)**.
|
|
28
|
+
* **Endpoints Exposed:**
|
|
29
|
+
1. `GET /health`: Instantaneous liveness and uptime probe ($< 10\text{ms}$).
|
|
30
|
+
2. `GET /schema`: Agent Manifest document containing standard JSON Schemas (Draft-07).
|
|
31
|
+
3. `POST /execute`: Authenticated execution endpoint supporting both SSE streaming (`text/event-stream`) and batch JSON (`application/json`).
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
### Decision 2: Zero-Trust Security & Anti-Replay Guard
|
|
36
|
+
* **Context:** Open-network agent servers are targets for denial-of-service, spoofed executions, and credential burn. Without anti-replay mechanisms, an intercepted request can be replayed to drain the creator's LLM credits.
|
|
37
|
+
* **Decision:**
|
|
38
|
+
- **Canonical HMAC-SHA256 Signing:** All `/execute` calls require a signature calculated over normalized components:
|
|
39
|
+
$$\text{BodyHash} = \text{HEX}(\text{SHA256}(\text{RawRequestBodyBytes}))$$
|
|
40
|
+
$$\text{CanonicalString} = \text{METHOD} + "\backslash\text{n}" + \text{PATH} + "\backslash\text{n}" + \text{TIMESTAMP} + "\backslash\text{n}" + \text{NONCE} + "\backslash\text{n}" + \text{RUN\_ID} + "\backslash\text{n}" + \text{BodyHash}$$
|
|
41
|
+
$$\text{Signature} = \text{HEX}(\text{HMAC-SHA256}(\text{Secret}, \text{CanonicalString}))$$
|
|
42
|
+
- **5-Minute Clock Drift Enforcement:** Requests with $|\text{CurrentTime} - \text{Timestamp}| > 300{,}000\text{ms}$ are rejected immediately (`AUTH_TIMESTAMP_OUT_OF_BOUNDS`).
|
|
43
|
+
- **Sliding Nonce Cache:** In-memory LRU cache with 5-minute TTL. Any repeated nonce within the drift window is blocked (`AUTH_REPLAY_DETECTED`).
|
|
44
|
+
- **Run ID Idempotency:** Duplicate active or completed run IDs cannot be re-executed.
|
|
45
|
+
- **Constant-Time Comparison:** Uses `crypto.timingSafeEqual` to eliminate side-channel timing attacks.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
### Decision 3: Framework-Agnostic Adapter Pattern
|
|
50
|
+
* **Context:** Forcing developers into a specific LLM library creates friction.
|
|
51
|
+
* **Decision:** `catelog` uses the **Adapter Pattern**. The SDK is completely decoupled from agent orchestration frameworks:
|
|
52
|
+
- Works with **LangGraph / LangChain**.
|
|
53
|
+
- Works with **OpenAI SDK** (`client.responses.create`).
|
|
54
|
+
- Works with **LlamaIndex**, **Vercel AI SDK**, or vanilla TypeScript loops.
|
|
55
|
+
Developers simply pass an `execute({ input, stream, signal })` async function.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
### Decision 4: Native Zod & JSON Schema Support
|
|
60
|
+
* **Context:** The marketplace UI and gateway validation engine require explicit JSON Schemas to generate input forms and enforce pre-execution contracts.
|
|
61
|
+
* **Decision:** Developers can define schemas using standard [Zod](https://zod.dev) or raw JSON Schema objects. `catelog` automatically converts Zod objects into standard JSON Schema Draft-07 for the `GET /schema` endpoint while providing runtime type safety for incoming buyer payloads.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### Decision 5: Real-Time SSE Streaming with Keep-Alive Heartbeats
|
|
66
|
+
* **Context:** Long-running deep research or multi-agent loops (e.g. 30–120 seconds) frequently get terminated prematurely by intermediate proxies (Cloudflare Error 524, AWS ALB 504 Gateway Timeout).
|
|
67
|
+
* **Decision:**
|
|
68
|
+
- **Automatic 15s Heartbeats:** The SDK spawns an internal timer emitting `{ event: "heartbeat", timestamp: ... }` every 15 seconds during active runs.
|
|
69
|
+
- **Clean Disconnect Handling:** If a buyer or gateway closes the socket, the SDK catches the event and trips an `AbortSignal`, allowing developers to abort downstream LLM calls immediately and prevent wasted API costs.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Decision 6: Simplified Ping Check (No Dry-Run Invariant)
|
|
74
|
+
* **Context:** Earlier concepts considered simulated "dry-runs" to check third-party balances. However, third-party API keys can run out mid-job, and dry-runs create false confidence while consuming maintenance overhead.
|
|
75
|
+
* **Decision:** Keep `/health` as a pure, lightweight network liveness and uptime probe (`GET /health`). It responds in milliseconds, uses zero credits, and certifies server uptime and protocol readiness.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 3. What the SDK Contains
|
|
80
|
+
|
|
81
|
+
The SDK codebase is modular, clean, and fully typed:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
sdk/ts-sdk/
|
|
85
|
+
├── package.json # Package name: "catelog", ESM, type exports
|
|
86
|
+
├── tsconfig.json # NodeNext ES2022 compiler configuration
|
|
87
|
+
├── README.md # Comprehensive developer documentation
|
|
88
|
+
├── DECISION.md # This architectural decision document
|
|
89
|
+
├── scripts/
|
|
90
|
+
│ └── postinstall.js # Zero-dependency install splash for npm/pnpm/yarn/bun
|
|
91
|
+
├── src/
|
|
92
|
+
│ ├── index.ts # Clean root exports
|
|
93
|
+
│ ├── types.ts # Protocol interfaces, event contracts & error codes
|
|
94
|
+
│ ├── security.ts # SecurityManager (HMAC-SHA256, nonce cache, replay guard)
|
|
95
|
+
│ ├── sse.ts # SSEWriter (heartbeat timer, stream formatting, abort signal)
|
|
96
|
+
│ ├── schema.ts # Zod-to-JSON-Schema converter & runtime validator
|
|
97
|
+
│ ├── agent.ts # MarketplaceAgent class & createMarketplaceAgent() factory
|
|
98
|
+
│ ├── server.ts # Lightweight native HTTP server runner (.serve(port))
|
|
99
|
+
│ └── banner.ts # Rich ANSI terminal diagnostics and startup splash
|
|
100
|
+
└── test/
|
|
101
|
+
└── index.test.ts # Automated verification test suite
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Module Highlights:
|
|
105
|
+
|
|
106
|
+
| File | Purpose |
|
|
107
|
+
| :--- | :--- |
|
|
108
|
+
| **`src/types.ts`** | Defines `ExecuteRequest`, `ExecuteResponse`, `AgentManifest`, `HealthCheckResponse`, and standard error codes (`AUTH_INVALID_SIGNATURE`, `INVALID_INPUT`, `MODEL_RATE_LIMIT`, `INTERNAL_CRASH`, etc.). |
|
|
109
|
+
| **`src/security.ts`** | Handles canonical string generation, body hashing (SHA-256), HMAC validation, and sliding nonce memory caches. |
|
|
110
|
+
| **`src/sse.ts`** | Handles chunk formatting (`event: ...\ndata: ...\n\n`), sequence numbering for deltas, step reporting, and automatic 15-second heartbeat intervals. |
|
|
111
|
+
| **`src/schema.ts`** | Provides unwrapped JSON Schema generation from Zod schemas and validates user inputs against registered contracts. |
|
|
112
|
+
| **`src/agent.ts`** | Core engine coordinating CORS, routing (`/health`, `/schema`, `/execute`), authentication, timeout deadlines, and error normalization. |
|
|
113
|
+
| **`src/server.ts`** | Zero-dependency Node.js HTTP server supporting standalone execution or mounting into Express/Fastify/Next.js. |
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 4. How to Use the SDK
|
|
118
|
+
|
|
119
|
+
### 1. Installation
|
|
120
|
+
`catelog` is universally compatible with all package managers:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# pnpm
|
|
124
|
+
pnpm add catelog zod
|
|
125
|
+
|
|
126
|
+
# npm
|
|
127
|
+
npm install catelog zod
|
|
128
|
+
|
|
129
|
+
# yarn
|
|
130
|
+
yarn add catelog zod
|
|
131
|
+
|
|
132
|
+
# bun
|
|
133
|
+
bun add catelog zod
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 2. Basic Agent Implementation
|
|
139
|
+
Wrap any agent function with `createMarketplaceAgent`:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { createMarketplaceAgent } from "catelog";
|
|
143
|
+
import { z } from "zod";
|
|
144
|
+
import OpenAI from "openai";
|
|
145
|
+
|
|
146
|
+
const client = new OpenAI();
|
|
147
|
+
|
|
148
|
+
// 1. Declare contract schemas
|
|
149
|
+
const InputSchema = z.object({
|
|
150
|
+
query: z.string().describe("Target company or topic"),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const OutputSchema = z.object({
|
|
154
|
+
summary: z.string(),
|
|
155
|
+
sources: z.array(z.string()),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// 2. Wrap the agent
|
|
159
|
+
export const agent = createMarketplaceAgent({
|
|
160
|
+
name: "B2B Market Research Agent",
|
|
161
|
+
version: "1.0.0",
|
|
162
|
+
description: "Autonomous research agent using OpenAI web search",
|
|
163
|
+
secret: process.env.MARKETPLACE_SECRET, // Provided by the marketplace
|
|
164
|
+
inputSchema: InputSchema,
|
|
165
|
+
outputSchema: OutputSchema,
|
|
166
|
+
|
|
167
|
+
async execute({ input, stream, signal }) {
|
|
168
|
+
// Report progress steps live to the buyer UI
|
|
169
|
+
stream.step("Initiating web discovery...");
|
|
170
|
+
|
|
171
|
+
const response = await client.responses.create({
|
|
172
|
+
model: "gpt-6-luna",
|
|
173
|
+
input: input.query,
|
|
174
|
+
tools: [{ type: "web_search" }],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
stream.step("Formatting structured report...");
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
output: {
|
|
181
|
+
summary: response.output_text || "",
|
|
182
|
+
sources: ["https://example.com/source1"],
|
|
183
|
+
},
|
|
184
|
+
telemetry: {
|
|
185
|
+
model_used: "gpt-6-luna",
|
|
186
|
+
llm_tokens: {
|
|
187
|
+
total: response.usage?.total_tokens || 350,
|
|
188
|
+
},
|
|
189
|
+
cost_usd: 0.002,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// 3. Start the server (prints the signature CATELOG banner)
|
|
196
|
+
agent.serve(4000);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### 3. Verification & Testing
|
|
202
|
+
|
|
203
|
+
#### Test Ping / Liveness:
|
|
204
|
+
```bash
|
|
205
|
+
curl http://localhost:4000/health
|
|
206
|
+
```
|
|
207
|
+
```json
|
|
208
|
+
{
|
|
209
|
+
"status": "ready",
|
|
210
|
+
"protocol_version": "1.0.0",
|
|
211
|
+
"uptime_seconds": 42,
|
|
212
|
+
"environment_ready": true
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### Test Manifest Document:
|
|
217
|
+
```bash
|
|
218
|
+
curl http://localhost:4000/schema
|
|
219
|
+
```
|
|
220
|
+
Returns the agent manifest with complete JSON Schemas ready for marketplace listing.
|
|
221
|
+
|
|
222
|
+
#### Test Execution with Signature:
|
|
223
|
+
Clients sign requests using HMAC-SHA256 headers:
|
|
224
|
+
- `X-Marketplace-Protocol: 1.0.0`
|
|
225
|
+
- `X-Marketplace-Timestamp: <timestamp>`
|
|
226
|
+
- `X-Marketplace-Nonce: <uuid>`
|
|
227
|
+
- `X-Marketplace-Run-Id: <run_id>`
|
|
228
|
+
- `X-Marketplace-Signature: <hex_hmac>`
|
|
229
|
+
|
|
230
|
+
The SDK streams live Server-Sent Events directly to the client:
|
|
231
|
+
```
|
|
232
|
+
event: run.started
|
|
233
|
+
data: {"event":"run.started","run_id":"run_123","timestamp":1729410000000}
|
|
234
|
+
|
|
235
|
+
event: step.started
|
|
236
|
+
data: {"event":"step.started","run_id":"run_123","step_index":1,"label":"Initiating web discovery..."}
|
|
237
|
+
|
|
238
|
+
event: run.succeeded
|
|
239
|
+
data: {"event":"run.succeeded","run_id":"run_123","duration_ms":3410,"output":{...},"telemetry":{...}}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 5. Why Developers Love `catelog`
|
|
245
|
+
|
|
246
|
+
1. **5-Minute Onboarding:** Turn existing scripts or notebooks into a monetizable microservice in $< 5$ minutes.
|
|
247
|
+
2. **Zero Framework Lock-in:** Use LangGraph, OpenAI, CrewAI, Anthropic, or pure JavaScript.
|
|
248
|
+
3. **Built-in Production Hardening:** Replay attacks, clock drifts, malformed payloads, and reverse proxy timeouts are solved out of the box.
|
|
249
|
+
4. **Autonomous Economy Ready:** Seamlessly hooks into PayPal Authorize & Capture and multi-agent escrow networks.
|
|
250
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ROX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Catelog SDK (`catelog`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```
|
|
4
|
+
════════════════════════════════════════════════════════════════════
|
|
5
|
+
██████╗ █████╗ ████████╗███████╗██╗ ██████╗ ██████╗
|
|
6
|
+
██╔════╝██╔══██╗╚══██╔══╝██╔════╝██║ ██╔═══██╗██╔════╝
|
|
7
|
+
██║ ███████║ ██║ █████╗ ██║ ██║ ██║██║ ███╗
|
|
8
|
+
██║ ██╔══██║ ██║ ██╔══╝ ██║ ██║ ██║██║ ██║
|
|
9
|
+
╚██████╗██║ ██║ ██║ ███████╗███████╗╚██████╔╝╚██████╔╝
|
|
10
|
+
╚═════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝
|
|
11
|
+
────────────────────────────────────────────────────────────────────
|
|
12
|
+
NOTE FROM TEAM ROX
|
|
13
|
+
“Welcome to the agent economy, where humans and agents rent out intelligence.”
|
|
14
|
+
════════════════════════════════════════════════════════════════════
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The official TypeScript SDK for the **Marketplace Agent Protocol Specification (MAPS v1.0.0)**.
|
|
18
|
+
Wrap any AI agent (LangGraph, OpenAI SDK, LlamaIndex, or custom logic) into a marketplace-compliant microservice in just a few lines of code.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📦 Universal Installation
|
|
23
|
+
|
|
24
|
+
Compatible with all JavaScript package managers and runtimes (Node.js 18+, Bun, Deno):
|
|
25
|
+
|
|
26
|
+
### **pnpm**
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add catelog zod
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### **npm**
|
|
32
|
+
```bash
|
|
33
|
+
npm install catelog zod
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### **yarn**
|
|
37
|
+
```bash
|
|
38
|
+
yarn add catelog zod
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### **bun**
|
|
42
|
+
```bash
|
|
43
|
+
bun add catelog zod
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 🚀 Features
|
|
49
|
+
|
|
50
|
+
- ✅ **Protocol Compliance:** Exposes `GET /health`, `GET /schema`, and `POST /execute`.
|
|
51
|
+
- 🛡️ **HMAC-SHA256 Security:** Canonical request signing and 5-minute sliding nonce anti-replay protection.
|
|
52
|
+
- ⚡ **Dual Execution Modes:** Streaming via Server-Sent Events (`text/event-stream`) or batch JSON (`application/json`).
|
|
53
|
+
- 💓 **Auto Heartbeats:** Emits automatic 15s heartbeats to prevent Cloudflare/ALB gateway timeouts.
|
|
54
|
+
- 📐 **Schema Flexibility:** Native support for [Zod](https://zod.dev) schemas or standard JSON Schema Draft-07.
|
|
55
|
+
- 📡 **Ping / Liveness Check:** Instant `GET /health` verification probe for reachability and uptime.
|
|
56
|
+
- 🎨 **Rich Terminal Aesthetics:** Modern shadcn-style terminal splash on install and server boot.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🛠️ Quick Start
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { createMarketplaceAgent } from "catelog";
|
|
64
|
+
import { z } from "zod";
|
|
65
|
+
|
|
66
|
+
// 1. Define Input & Output Schemas
|
|
67
|
+
const InputSchema = z.object({
|
|
68
|
+
topic: z.string().describe("Research topic"),
|
|
69
|
+
depth: z.enum(["quick", "deep"]).default("quick"),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const OutputSchema = z.object({
|
|
73
|
+
summary: z.string(),
|
|
74
|
+
citations: z.array(z.string()),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 2. Create the Agent
|
|
78
|
+
export const agent = createMarketplaceAgent({
|
|
79
|
+
name: "Deep Research Agent",
|
|
80
|
+
secret: process.env.MARKETPLACE_SECRET,
|
|
81
|
+
inputSchema: InputSchema,
|
|
82
|
+
outputSchema: OutputSchema,
|
|
83
|
+
|
|
84
|
+
// Main execution logic
|
|
85
|
+
async execute({ input, stream, signal }) {
|
|
86
|
+
stream.step("Searching web for topic: " + input.topic);
|
|
87
|
+
|
|
88
|
+
// Stream text deltas live to the buyer UI
|
|
89
|
+
stream.delta("Synthesizing research notes...\n");
|
|
90
|
+
|
|
91
|
+
// Call your LLM, LangGraph workflow, or custom code here:
|
|
92
|
+
const summary = `Comprehensive report on ${input.topic}`;
|
|
93
|
+
const citations = ["https://example.com/source1"];
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
output: { summary, citations },
|
|
97
|
+
telemetry: {
|
|
98
|
+
model_used: "gpt-4o-mini",
|
|
99
|
+
llm_tokens: { prompt: 250, completion: 400, total: 650 },
|
|
100
|
+
cost_usd: 0.0012,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 3. Start the server (prints the signature CATELOG banner)
|
|
107
|
+
agent.serve(3000);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 🔗 Endpoints Provided
|
|
113
|
+
|
|
114
|
+
| Endpoint | Method | Transport | Purpose |
|
|
115
|
+
| :--- | :--- | :--- | :--- |
|
|
116
|
+
| `/health` | `GET` | `application/json` | Liveness & uptime probe |
|
|
117
|
+
| `/schema` | `GET` | `application/json` | Agent manifest with input/output JSON Schemas |
|
|
118
|
+
| `/execute` | `POST` | `text/event-stream` / `application/json` | Secure HMAC-authenticated execution with streaming |
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { SecurityManager } from "./security.js";
|
|
2
|
+
import { type SchemaLike } from "./schema.js";
|
|
3
|
+
import { type AgentCapabilities, type AgentExecutionContext, type AgentExecutionResult, type AgentManifest, type HealthCheckResponse } from "./types.js";
|
|
4
|
+
import { type ServerOptions } from "./server.js";
|
|
5
|
+
import type { IncomingMessage, ServerResponse, Server } from "node:http";
|
|
6
|
+
export interface MarketplaceAgentConfig<TInput = Record<string, unknown>, TOutput = Record<string, unknown>> {
|
|
7
|
+
id?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
secret?: string;
|
|
12
|
+
capabilities?: Partial<AgentCapabilities>;
|
|
13
|
+
inputSchema: SchemaLike;
|
|
14
|
+
outputSchema: SchemaLike;
|
|
15
|
+
execute: (ctx: AgentExecutionContext<TInput>) => Promise<AgentExecutionResult<TOutput>>;
|
|
16
|
+
}
|
|
17
|
+
export declare class MarketplaceAgent<TInput = Record<string, unknown>, TOutput = Record<string, unknown>> {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly version: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
readonly capabilities: AgentCapabilities;
|
|
23
|
+
readonly security: SecurityManager;
|
|
24
|
+
private readonly config;
|
|
25
|
+
private readonly startTime;
|
|
26
|
+
constructor(config: MarketplaceAgentConfig<TInput, TOutput>);
|
|
27
|
+
getHealth(): HealthCheckResponse;
|
|
28
|
+
getManifest(): AgentManifest;
|
|
29
|
+
serve(portOrOptions?: number | ServerOptions): Server;
|
|
30
|
+
handleRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
31
|
+
private handleExecute;
|
|
32
|
+
private writeJsonResponse;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Convenience builder function for creating a compliant Marketplace Agent
|
|
36
|
+
*/
|
|
37
|
+
export declare function createMarketplaceAgent<TInput = Record<string, unknown>, TOutput = Record<string, unknown>>(config: MarketplaceAgentConfig<TInput, TOutput>): MarketplaceAgent<TInput, TOutput>;
|
|
38
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAGlB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEzE,MAAM,WAAW,sBAAsB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACzG,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1C,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,UAAU,CAAC;IACzB,OAAO,EAAE,CAAC,GAAG,EAAE,qBAAqB,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;CACzF;AAED,qBAAa,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/F,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,YAAY,EAAE,iBAAiB,CAAC;IAChD,SAAgB,QAAQ,EAAE,eAAe,CAAC;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,MAAM,EAAE,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC;IAgBpD,SAAS,IAAI,mBAAmB;IAShC,WAAW,IAAI,aAAa;IAa5B,KAAK,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,MAAM;IAK/C,aAAa,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;YAkDtE,aAAa;IAoK3B,OAAO,CAAC,iBAAiB;CAS1B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxG,MAAM,EAAE,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9C,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAEnC"}
|