@jaypie/mcp 0.2.9 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/prompts/Jaypie_CDK_Constructs_and_Patterns.md +23 -28
- package/prompts/Jaypie_DynamoDB_Package.md +62 -62
- package/prompts/Jaypie_Express_Package.md +101 -44
- package/prompts/{Jaypie_Vocabulary_Commander.md → Jaypie_Fabric_Commander.md} +38 -38
- package/prompts/{Jaypie_Vocabulary_LLM.md → Jaypie_Fabric_LLM.md} +45 -45
- package/prompts/{Jaypie_Vocabulary_Lambda.md → Jaypie_Fabric_Lambda.md} +40 -42
- package/prompts/{Jaypie_Vocabulary_MCP.md → Jaypie_Fabric_MCP.md} +39 -39
- package/prompts/{Jaypie_Vocabulary_Package.md → Jaypie_Fabric_Package.md} +151 -142
- package/prompts/Jaypie_Init_CICD_with_GitHub_Actions.md +12 -12
- package/prompts/Jaypie_Streaming.md +408 -0
- package/prompts/Templates_Express_Subpackage.md +6 -2
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Commander.js CLI integration with
|
|
2
|
+
description: Commander.js CLI integration with fabricService callbacks (onMessage, onComplete, onError, onFatal)
|
|
3
3
|
include: "**/cli/**"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Jaypie
|
|
6
|
+
# Jaypie Fabric Commander Adapter
|
|
7
7
|
|
|
8
|
-
The Commander adapter (`@jaypie/
|
|
8
|
+
The Commander adapter (`@jaypie/fabric/commander`) integrates Jaypie service handlers with Commander.js CLI applications, providing automatic option generation, type conversion, and callback hooks for progress reporting.
|
|
9
9
|
|
|
10
|
-
**See also:** [
|
|
10
|
+
**See also:** [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) for core fabricService documentation.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npm install @jaypie/
|
|
15
|
+
npm install @jaypie/fabric commander
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
import { Command } from "commander";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import { fabricService } from "@jaypie/fabric";
|
|
23
|
+
import { fabricCommand } from "@jaypie/fabric/commander";
|
|
24
24
|
|
|
25
|
-
const handler =
|
|
25
|
+
const handler = fabricService({
|
|
26
26
|
alias: "greet",
|
|
27
27
|
description: "Greet a user",
|
|
28
28
|
input: {
|
|
@@ -36,12 +36,12 @@ const handler = serviceHandler({
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
const program = new Command();
|
|
39
|
-
|
|
39
|
+
fabricCommand({ service: handler, program });
|
|
40
40
|
program.parse();
|
|
41
41
|
// Usage: greet --user Alice -l
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## fabricCommand
|
|
45
45
|
|
|
46
46
|
The primary function for registering a service handler as a Commander command.
|
|
47
47
|
|
|
@@ -49,7 +49,7 @@ The primary function for registering a service handler as a Commander command.
|
|
|
49
49
|
|
|
50
50
|
| Option | Type | Description |
|
|
51
51
|
|--------|------|-------------|
|
|
52
|
-
| `
|
|
52
|
+
| `service` | `Service` | Required. The service handler to register |
|
|
53
53
|
| `program` | `Command` | Required. Commander program or command |
|
|
54
54
|
| `name` | `string` | Override command name (default: handler.alias) |
|
|
55
55
|
| `description` | `string` | Override description (default: handler.description) |
|
|
@@ -68,10 +68,10 @@ Receives progress messages sent by the service via `context.sendMessage`:
|
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
70
|
import { Command } from "commander";
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
71
|
+
import { fabricService } from "@jaypie/fabric";
|
|
72
|
+
import { fabricCommand } from "@jaypie/fabric/commander";
|
|
73
73
|
|
|
74
|
-
const handler =
|
|
74
|
+
const handler = fabricService({
|
|
75
75
|
alias: "process",
|
|
76
76
|
input: { jobId: { type: String, letter: "j" } },
|
|
77
77
|
service: async ({ jobId }, context) => {
|
|
@@ -91,8 +91,8 @@ const handler = serviceHandler({
|
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
const program = new Command();
|
|
94
|
-
|
|
95
|
-
handler,
|
|
94
|
+
fabricCommand({
|
|
95
|
+
service: handler,
|
|
96
96
|
program,
|
|
97
97
|
onMessage: (msg) => {
|
|
98
98
|
// msg: { content: string, level?: "trace"|"debug"|"info"|"warn"|"error" }
|
|
@@ -110,8 +110,8 @@ program.parse();
|
|
|
110
110
|
Called with the handler's return value on successful completion:
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
|
|
114
|
-
handler,
|
|
113
|
+
fabricCommand({
|
|
114
|
+
service: handler,
|
|
115
115
|
program,
|
|
116
116
|
onComplete: (response) => {
|
|
117
117
|
// Called after service completes successfully
|
|
@@ -130,8 +130,8 @@ registerServiceCommand({
|
|
|
130
130
|
Receives errors that the service explicitly reports via `context.onError()`. Use this for recoverable errors that don't halt execution:
|
|
131
131
|
|
|
132
132
|
```typescript
|
|
133
|
-
|
|
134
|
-
handler,
|
|
133
|
+
fabricCommand({
|
|
134
|
+
service: handler,
|
|
135
135
|
program,
|
|
136
136
|
onError: (error) => {
|
|
137
137
|
// Log recoverable errors
|
|
@@ -145,8 +145,8 @@ registerServiceCommand({
|
|
|
145
145
|
Receives fatal errors - either thrown errors or errors reported via `context.onFatal()`. Any error that escapes the service (is thrown) is treated as fatal:
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
|
-
|
|
149
|
-
handler,
|
|
148
|
+
fabricCommand({
|
|
149
|
+
service: handler,
|
|
150
150
|
program,
|
|
151
151
|
onFatal: (error) => {
|
|
152
152
|
console.error("Fatal error:", error.message);
|
|
@@ -164,10 +164,10 @@ registerServiceCommand({
|
|
|
164
164
|
|
|
165
165
|
```typescript
|
|
166
166
|
import { Command } from "commander";
|
|
167
|
-
import {
|
|
168
|
-
import {
|
|
167
|
+
import { fabricService } from "@jaypie/fabric";
|
|
168
|
+
import { fabricCommand } from "@jaypie/fabric/commander";
|
|
169
169
|
|
|
170
|
-
const evaluateHandler =
|
|
170
|
+
const evaluateHandler = fabricService({
|
|
171
171
|
alias: "evaluate",
|
|
172
172
|
description: "Run an evaluation job",
|
|
173
173
|
input: {
|
|
@@ -231,8 +231,8 @@ const evaluateHandler = serviceHandler({
|
|
|
231
231
|
const program = new Command();
|
|
232
232
|
program.version("1.0.0").description("Evaluation CLI");
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
fabricCommand({
|
|
235
|
+
service: evaluateHandler,
|
|
236
236
|
program,
|
|
237
237
|
onMessage: (msg) => {
|
|
238
238
|
const prefix = msg.level === "warn" ? "WARNING: " :
|
|
@@ -309,13 +309,13 @@ For more control, use `createCommanderOptions` and `parseCommanderOptions`:
|
|
|
309
309
|
|
|
310
310
|
```typescript
|
|
311
311
|
import { Command } from "commander";
|
|
312
|
-
import {
|
|
312
|
+
import { fabricService } from "@jaypie/fabric";
|
|
313
313
|
import {
|
|
314
314
|
createCommanderOptions,
|
|
315
315
|
parseCommanderOptions,
|
|
316
|
-
} from "@jaypie/
|
|
316
|
+
} from "@jaypie/fabric/commander";
|
|
317
317
|
|
|
318
|
-
const handler =
|
|
318
|
+
const handler = fabricService({
|
|
319
319
|
input: {
|
|
320
320
|
userName: { type: String, description: "User name" },
|
|
321
321
|
maxRetries: { type: Number, default: 3 },
|
|
@@ -351,14 +351,14 @@ import type {
|
|
|
351
351
|
CommanderOptionOverride,
|
|
352
352
|
CreateCommanderOptionsConfig,
|
|
353
353
|
CreateCommanderOptionsResult,
|
|
354
|
+
FabricCommandConfig,
|
|
355
|
+
FabricCommandResult,
|
|
354
356
|
OnCompleteCallback,
|
|
355
357
|
OnErrorCallback,
|
|
356
358
|
OnFatalCallback,
|
|
357
359
|
OnMessageCallback,
|
|
358
360
|
ParseCommanderOptionsConfig,
|
|
359
|
-
|
|
360
|
-
RegisterServiceCommandResult,
|
|
361
|
-
} from "@jaypie/vocabulary/commander";
|
|
361
|
+
} from "@jaypie/fabric/commander";
|
|
362
362
|
```
|
|
363
363
|
|
|
364
364
|
### Callback Type Definitions
|
|
@@ -386,26 +386,26 @@ type OnFatalCallback = (error: unknown) => void | Promise<void>;
|
|
|
386
386
|
## Exports
|
|
387
387
|
|
|
388
388
|
```typescript
|
|
389
|
-
// @jaypie/
|
|
389
|
+
// @jaypie/fabric/commander
|
|
390
390
|
export { createCommanderOptions } from "./createCommanderOptions.js";
|
|
391
391
|
export { parseCommanderOptions } from "./parseCommanderOptions.js";
|
|
392
|
-
export {
|
|
392
|
+
export { fabricCommand } from "./fabricCommand.js";
|
|
393
393
|
|
|
394
394
|
export type {
|
|
395
395
|
CommanderOptionOverride,
|
|
396
396
|
CreateCommanderOptionsConfig,
|
|
397
397
|
CreateCommanderOptionsResult,
|
|
398
|
+
FabricCommandConfig,
|
|
399
|
+
FabricCommandResult,
|
|
398
400
|
OnCompleteCallback,
|
|
399
401
|
OnErrorCallback,
|
|
400
402
|
OnFatalCallback,
|
|
401
403
|
OnMessageCallback,
|
|
402
404
|
ParseCommanderOptionsConfig,
|
|
403
|
-
RegisterServiceCommandConfig,
|
|
404
|
-
RegisterServiceCommandResult,
|
|
405
405
|
} from "./types.js";
|
|
406
406
|
```
|
|
407
407
|
|
|
408
408
|
## Related
|
|
409
409
|
|
|
410
410
|
- [Jaypie_Commander_CLI_Package.md](Jaypie_Commander_CLI_Package.md) - Setting up a Commander CLI project from scratch
|
|
411
|
-
- [
|
|
411
|
+
- [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) - Core fabricService and type conversion
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: LLM tool creation from
|
|
2
|
+
description: LLM tool creation from fabricService for use with @jaypie/llm Toolkit
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
# Jaypie
|
|
5
|
+
# Jaypie Fabric LLM Adapter
|
|
6
6
|
|
|
7
|
-
The LLM adapter (`@jaypie/
|
|
7
|
+
The LLM adapter (`@jaypie/fabric/llm`) creates LLM tools from Jaypie service handlers for use with `@jaypie/llm` Toolkit, automatically generating JSON Schema from input definitions.
|
|
8
8
|
|
|
9
|
-
**See also:** [
|
|
9
|
+
**See also:** [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) for core fabricService documentation.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install @jaypie/
|
|
14
|
+
npm install @jaypie/fabric @jaypie/llm
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { fabricService } from "@jaypie/fabric";
|
|
21
|
+
import { fabricTool } from "@jaypie/fabric/llm";
|
|
22
22
|
import { Toolkit } from "@jaypie/llm";
|
|
23
23
|
|
|
24
|
-
const handler =
|
|
24
|
+
const handler = fabricService({
|
|
25
25
|
alias: "greet",
|
|
26
26
|
description: "Greet a user by name",
|
|
27
27
|
input: {
|
|
@@ -34,19 +34,19 @@ const handler = serviceHandler({
|
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
const { tool } =
|
|
37
|
+
const { tool } = fabricTool({ service: handler });
|
|
38
38
|
const toolkit = new Toolkit([tool]);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
##
|
|
41
|
+
## fabricTool
|
|
42
42
|
|
|
43
|
-
Creates an LLM tool from a
|
|
43
|
+
Creates an LLM tool from a fabricService.
|
|
44
44
|
|
|
45
45
|
### Options
|
|
46
46
|
|
|
47
47
|
| Option | Type | Description |
|
|
48
48
|
|--------|------|-------------|
|
|
49
|
-
| `
|
|
49
|
+
| `service` | `Service` | Required. The service handler to adapt |
|
|
50
50
|
| `name` | `string` | Override tool name (defaults to handler.alias) |
|
|
51
51
|
| `description` | `string` | Override tool description (defaults to handler.description) |
|
|
52
52
|
| `message` | `string \| function` | Custom message for logging |
|
|
@@ -59,10 +59,10 @@ Creates an LLM tool from a serviceHandler.
|
|
|
59
59
|
### Basic Usage
|
|
60
60
|
|
|
61
61
|
```typescript
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
62
|
+
import { fabricService } from "@jaypie/fabric";
|
|
63
|
+
import { fabricTool } from "@jaypie/fabric/llm";
|
|
64
64
|
|
|
65
|
-
const calculateHandler =
|
|
65
|
+
const calculateHandler = fabricService({
|
|
66
66
|
alias: "calculate",
|
|
67
67
|
description: "Perform a mathematical calculation",
|
|
68
68
|
input: {
|
|
@@ -80,7 +80,7 @@ const calculateHandler = serviceHandler({
|
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
const { tool } =
|
|
83
|
+
const { tool } = fabricTool({ service: calculateHandler });
|
|
84
84
|
|
|
85
85
|
// Tool has these properties:
|
|
86
86
|
// tool.name: "calculate"
|
|
@@ -92,8 +92,8 @@ const { tool } = createLlmTool({ handler: calculateHandler });
|
|
|
92
92
|
### Overriding Name and Description
|
|
93
93
|
|
|
94
94
|
```typescript
|
|
95
|
-
const { tool } =
|
|
96
|
-
handler,
|
|
95
|
+
const { tool } = fabricTool({
|
|
96
|
+
service: handler,
|
|
97
97
|
name: "math_calculator",
|
|
98
98
|
description: "A tool for performing basic math operations",
|
|
99
99
|
});
|
|
@@ -102,7 +102,7 @@ const { tool } = createLlmTool({
|
|
|
102
102
|
### Excluding Fields
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
|
-
const handler =
|
|
105
|
+
const handler = fabricService({
|
|
106
106
|
alias: "search",
|
|
107
107
|
input: {
|
|
108
108
|
query: { type: String },
|
|
@@ -112,8 +112,8 @@ const handler = serviceHandler({
|
|
|
112
112
|
service: async (params) => { /* ... */ },
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
const { tool } =
|
|
116
|
-
handler,
|
|
115
|
+
const { tool } = fabricTool({
|
|
116
|
+
service: handler,
|
|
117
117
|
exclude: ["_internalId"], // Not exposed to LLM
|
|
118
118
|
});
|
|
119
119
|
```
|
|
@@ -123,7 +123,7 @@ const { tool } = createLlmTool({
|
|
|
123
123
|
Services can use context callbacks to report progress, errors, and completion:
|
|
124
124
|
|
|
125
125
|
```typescript
|
|
126
|
-
const handler =
|
|
126
|
+
const handler = fabricService({
|
|
127
127
|
alias: "evaluate",
|
|
128
128
|
input: { jobId: { type: String } },
|
|
129
129
|
service: async ({ jobId }, context) => {
|
|
@@ -139,8 +139,8 @@ const handler = serviceHandler({
|
|
|
139
139
|
},
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
const { tool } =
|
|
143
|
-
handler,
|
|
142
|
+
const { tool } = fabricTool({
|
|
143
|
+
service: handler,
|
|
144
144
|
onComplete: (result) => console.log("Tool completed:", result),
|
|
145
145
|
onError: (error) => console.warn("Recoverable error:", error),
|
|
146
146
|
onFatal: (error) => console.error("Fatal error:", error),
|
|
@@ -152,10 +152,10 @@ const { tool } = createLlmTool({
|
|
|
152
152
|
|
|
153
153
|
## inputToJsonSchema
|
|
154
154
|
|
|
155
|
-
Converts
|
|
155
|
+
Converts fabric input definitions to JSON Schema:
|
|
156
156
|
|
|
157
157
|
```typescript
|
|
158
|
-
import { inputToJsonSchema } from "@jaypie/
|
|
158
|
+
import { inputToJsonSchema } from "@jaypie/fabric/llm";
|
|
159
159
|
|
|
160
160
|
const schema = inputToJsonSchema({
|
|
161
161
|
userName: { type: String, description: "User's name" },
|
|
@@ -177,8 +177,8 @@ const schema = inputToJsonSchema({
|
|
|
177
177
|
|
|
178
178
|
### Type Mappings
|
|
179
179
|
|
|
180
|
-
|
|
|
181
|
-
|
|
180
|
+
| Fabric Type | JSON Schema |
|
|
181
|
+
|-------------|-------------|
|
|
182
182
|
| `String` | `{ type: "string" }` |
|
|
183
183
|
| `Number` | `{ type: "number" }` |
|
|
184
184
|
| `Boolean` | `{ type: "boolean" }` |
|
|
@@ -201,12 +201,12 @@ const schema = inputToJsonSchema(handler.input, {
|
|
|
201
201
|
## Complete Example
|
|
202
202
|
|
|
203
203
|
```typescript
|
|
204
|
-
import {
|
|
205
|
-
import {
|
|
204
|
+
import { fabricService } from "@jaypie/fabric";
|
|
205
|
+
import { fabricTool } from "@jaypie/fabric/llm";
|
|
206
206
|
import { Llm, Toolkit } from "@jaypie/llm";
|
|
207
207
|
|
|
208
208
|
// Define service handlers
|
|
209
|
-
const weatherHandler =
|
|
209
|
+
const weatherHandler = fabricService({
|
|
210
210
|
alias: "get_weather",
|
|
211
211
|
description: "Get current weather for a location",
|
|
212
212
|
input: {
|
|
@@ -224,7 +224,7 @@ const weatherHandler = serviceHandler({
|
|
|
224
224
|
},
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
const searchHandler =
|
|
227
|
+
const searchHandler = fabricService({
|
|
228
228
|
alias: "search_web",
|
|
229
229
|
description: "Search the web for information",
|
|
230
230
|
input: {
|
|
@@ -237,8 +237,8 @@ const searchHandler = serviceHandler({
|
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
// Create tools
|
|
240
|
-
const { tool: weatherTool } =
|
|
241
|
-
const { tool: searchTool } =
|
|
240
|
+
const { tool: weatherTool } = fabricTool({ service: weatherHandler });
|
|
241
|
+
const { tool: searchTool } = fabricTool({ service: searchHandler });
|
|
242
242
|
|
|
243
243
|
// Use with Toolkit
|
|
244
244
|
const toolkit = new Toolkit([weatherTool, searchTool]);
|
|
@@ -251,14 +251,14 @@ const response = await llm.ask("What's the weather in Tokyo?");
|
|
|
251
251
|
|
|
252
252
|
```typescript
|
|
253
253
|
import type {
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
FabricToolConfig,
|
|
255
|
+
FabricToolResult,
|
|
256
256
|
LlmTool,
|
|
257
257
|
OnCompleteCallback,
|
|
258
258
|
OnErrorCallback,
|
|
259
259
|
OnFatalCallback,
|
|
260
260
|
OnMessageCallback,
|
|
261
|
-
} from "@jaypie/
|
|
261
|
+
} from "@jaypie/fabric/llm";
|
|
262
262
|
```
|
|
263
263
|
|
|
264
264
|
### Type Definitions
|
|
@@ -271,8 +271,8 @@ interface LlmTool {
|
|
|
271
271
|
function: (params: Record<string, unknown>) => Promise<unknown>;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
interface
|
|
275
|
-
|
|
274
|
+
interface FabricToolConfig {
|
|
275
|
+
service: Service;
|
|
276
276
|
name?: string;
|
|
277
277
|
description?: string;
|
|
278
278
|
message?: string | ((params: Record<string, unknown>) => string);
|
|
@@ -283,7 +283,7 @@ interface CreateLlmToolConfig {
|
|
|
283
283
|
onMessage?: OnMessageCallback;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
interface
|
|
286
|
+
interface FabricToolResult {
|
|
287
287
|
tool: LlmTool;
|
|
288
288
|
}
|
|
289
289
|
```
|
|
@@ -291,13 +291,13 @@ interface CreateLlmToolResult {
|
|
|
291
291
|
## Exports
|
|
292
292
|
|
|
293
293
|
```typescript
|
|
294
|
-
// @jaypie/
|
|
295
|
-
export {
|
|
294
|
+
// @jaypie/fabric/llm
|
|
295
|
+
export { fabricTool } from "./fabricTool.js";
|
|
296
296
|
export { inputToJsonSchema } from "./inputToJsonSchema.js";
|
|
297
297
|
|
|
298
298
|
export type {
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
FabricToolConfig,
|
|
300
|
+
FabricToolResult,
|
|
301
301
|
LlmTool,
|
|
302
302
|
OnCompleteCallback,
|
|
303
303
|
OnErrorCallback,
|
|
@@ -308,5 +308,5 @@ export type {
|
|
|
308
308
|
|
|
309
309
|
## Related
|
|
310
310
|
|
|
311
|
-
- [
|
|
311
|
+
- [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) - Core fabricService and type conversion
|
|
312
312
|
- [Jaypie_Llm_Tools.md](Jaypie_Llm_Tools.md) - LLM tools and Toolkit usage
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: AWS Lambda integration with
|
|
2
|
+
description: AWS Lambda integration with fabricService for event processing and callbacks
|
|
3
3
|
include: "**/lambda/**"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Jaypie
|
|
6
|
+
# Jaypie Fabric Lambda Adapter
|
|
7
7
|
|
|
8
|
-
The Lambda adapter (`@jaypie/
|
|
8
|
+
The Lambda adapter (`@jaypie/fabric/lambda`) wraps Jaypie service handlers for use as AWS Lambda handlers, providing automatic event parsing, secrets management, and lifecycle hooks.
|
|
9
9
|
|
|
10
|
-
**See also:** [
|
|
10
|
+
**See also:** [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) for core fabricService documentation.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
npm install @jaypie/
|
|
15
|
+
npm install @jaypie/fabric
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
21
|
+
import { fabricService } from "@jaypie/fabric";
|
|
22
|
+
import { fabricLambda } from "@jaypie/fabric/lambda";
|
|
23
23
|
|
|
24
|
-
const handler =
|
|
24
|
+
const handler = fabricService({
|
|
25
25
|
alias: "processOrder",
|
|
26
26
|
input: { orderId: { type: String } },
|
|
27
27
|
service: async ({ orderId }) => {
|
|
@@ -29,18 +29,18 @@ const handler = serviceHandler({
|
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
export const lambdaHandler =
|
|
32
|
+
export const lambdaHandler = fabricLambda({ service: handler });
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## fabricLambda
|
|
36
36
|
|
|
37
|
-
Wraps a
|
|
37
|
+
Wraps a fabricService for use as an AWS Lambda handler.
|
|
38
38
|
|
|
39
39
|
### Options
|
|
40
40
|
|
|
41
41
|
| Option | Type | Description |
|
|
42
42
|
|--------|------|-------------|
|
|
43
|
-
| `
|
|
43
|
+
| `service` | `Service` | Required. The service handler to wrap |
|
|
44
44
|
| `chaos` | `string` | Chaos testing mode |
|
|
45
45
|
| `name` | `string` | Override handler name for logging (default: handler.alias) |
|
|
46
46
|
| `onComplete` | `OnCompleteCallback` | Called with handler's return value on success |
|
|
@@ -59,10 +59,10 @@ Wraps a serviceHandler for use as an AWS Lambda handler.
|
|
|
59
59
|
Services can use context callbacks to report progress, errors, and completion:
|
|
60
60
|
|
|
61
61
|
```typescript
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
62
|
+
import { fabricService } from "@jaypie/fabric";
|
|
63
|
+
import { fabricLambda } from "@jaypie/fabric/lambda";
|
|
64
64
|
|
|
65
|
-
const handler =
|
|
65
|
+
const handler = fabricService({
|
|
66
66
|
alias: "evaluate",
|
|
67
67
|
input: { jobId: { type: String } },
|
|
68
68
|
service: async ({ jobId }, context) => {
|
|
@@ -84,8 +84,8 @@ const handler = serviceHandler({
|
|
|
84
84
|
},
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
export const lambdaHandler =
|
|
88
|
-
handler,
|
|
87
|
+
export const lambdaHandler = fabricLambda({
|
|
88
|
+
service: handler,
|
|
89
89
|
onComplete: (response) => {
|
|
90
90
|
console.log("Done:", JSON.stringify(response, null, 2));
|
|
91
91
|
},
|
|
@@ -110,8 +110,8 @@ export const lambdaHandler = lambdaServiceHandler({
|
|
|
110
110
|
Automatically loads AWS Secrets Manager values into `process.env`:
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
export const lambdaHandler =
|
|
114
|
-
handler,
|
|
113
|
+
export const lambdaHandler = fabricLambda({
|
|
114
|
+
service: handler,
|
|
115
115
|
secrets: ["ANTHROPIC_API_KEY", "DATABASE_URL"],
|
|
116
116
|
});
|
|
117
117
|
// Before handler runs, secrets are fetched and available as:
|
|
@@ -126,8 +126,8 @@ export const lambdaHandler = lambdaServiceHandler({
|
|
|
126
126
|
Functions to run before the handler:
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
|
-
export const lambdaHandler =
|
|
130
|
-
handler,
|
|
129
|
+
export const lambdaHandler = fabricLambda({
|
|
130
|
+
service: handler,
|
|
131
131
|
setup: [
|
|
132
132
|
async () => {
|
|
133
133
|
await initializeDatabase();
|
|
@@ -144,8 +144,8 @@ export const lambdaHandler = lambdaServiceHandler({
|
|
|
144
144
|
Functions to run after the handler (always runs, even on error):
|
|
145
145
|
|
|
146
146
|
```typescript
|
|
147
|
-
export const lambdaHandler =
|
|
148
|
-
handler,
|
|
147
|
+
export const lambdaHandler = fabricLambda({
|
|
148
|
+
service: handler,
|
|
149
149
|
teardown: [
|
|
150
150
|
async () => {
|
|
151
151
|
await closeConnections();
|
|
@@ -159,8 +159,8 @@ export const lambdaHandler = lambdaServiceHandler({
|
|
|
159
159
|
Validation functions to run before handler. If any returns falsy or throws, handler is skipped:
|
|
160
160
|
|
|
161
161
|
```typescript
|
|
162
|
-
export const lambdaHandler =
|
|
163
|
-
handler,
|
|
162
|
+
export const lambdaHandler = fabricLambda({
|
|
163
|
+
service: handler,
|
|
164
164
|
validate: [
|
|
165
165
|
(event) => event.headers?.authorization !== undefined,
|
|
166
166
|
async (event) => {
|
|
@@ -197,11 +197,11 @@ const results = await lambdaHandler(sqsBatchEvent);
|
|
|
197
197
|
## Complete Example
|
|
198
198
|
|
|
199
199
|
```typescript
|
|
200
|
-
import {
|
|
201
|
-
import {
|
|
200
|
+
import { fabricService } from "@jaypie/fabric";
|
|
201
|
+
import { fabricLambda } from "@jaypie/fabric/lambda";
|
|
202
202
|
import log from "@jaypie/logger";
|
|
203
203
|
|
|
204
|
-
const processOrderHandler =
|
|
204
|
+
const processOrderHandler = fabricService({
|
|
205
205
|
alias: "processOrder",
|
|
206
206
|
description: "Process an incoming order",
|
|
207
207
|
input: {
|
|
@@ -224,8 +224,8 @@ const processOrderHandler = serviceHandler({
|
|
|
224
224
|
},
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
export const handler =
|
|
228
|
-
|
|
227
|
+
export const handler = fabricLambda({
|
|
228
|
+
service: processOrderHandler,
|
|
229
229
|
name: "order-processor",
|
|
230
230
|
secrets: ["DATABASE_URL", "STRIPE_API_KEY"],
|
|
231
231
|
setup: [
|
|
@@ -265,8 +265,8 @@ Errors are caught and returned as structured error responses:
|
|
|
265
265
|
Set `throw: true` to re-throw errors (useful for SQS retry behavior):
|
|
266
266
|
|
|
267
267
|
```typescript
|
|
268
|
-
export const lambdaHandler =
|
|
269
|
-
handler,
|
|
268
|
+
export const lambdaHandler = fabricLambda({
|
|
269
|
+
service: handler,
|
|
270
270
|
throw: true, // Errors will propagate, triggering SQS retry
|
|
271
271
|
});
|
|
272
272
|
```
|
|
@@ -275,28 +275,26 @@ export const lambdaHandler = lambdaServiceHandler({
|
|
|
275
275
|
|
|
276
276
|
```typescript
|
|
277
277
|
import type {
|
|
278
|
+
FabricLambdaConfig,
|
|
279
|
+
FabricLambdaOptions,
|
|
278
280
|
LambdaContext,
|
|
279
|
-
LambdaServiceHandlerConfig,
|
|
280
|
-
LambdaServiceHandlerOptions,
|
|
281
|
-
LambdaServiceHandlerResult,
|
|
282
281
|
OnCompleteCallback,
|
|
283
282
|
OnErrorCallback,
|
|
284
283
|
OnFatalCallback,
|
|
285
284
|
OnMessageCallback,
|
|
286
|
-
} from "@jaypie/
|
|
285
|
+
} from "@jaypie/fabric/lambda";
|
|
287
286
|
```
|
|
288
287
|
|
|
289
288
|
## Exports
|
|
290
289
|
|
|
291
290
|
```typescript
|
|
292
|
-
// @jaypie/
|
|
293
|
-
export {
|
|
291
|
+
// @jaypie/fabric/lambda
|
|
292
|
+
export { fabricLambda } from "./fabricLambda.js";
|
|
294
293
|
|
|
295
294
|
export type {
|
|
295
|
+
FabricLambdaConfig,
|
|
296
|
+
FabricLambdaOptions,
|
|
296
297
|
LambdaContext,
|
|
297
|
-
LambdaServiceHandlerConfig,
|
|
298
|
-
LambdaServiceHandlerOptions,
|
|
299
|
-
LambdaServiceHandlerResult,
|
|
300
298
|
OnCompleteCallback,
|
|
301
299
|
OnErrorCallback,
|
|
302
300
|
OnFatalCallback,
|
|
@@ -306,5 +304,5 @@ export type {
|
|
|
306
304
|
|
|
307
305
|
## Related
|
|
308
306
|
|
|
309
|
-
- [
|
|
307
|
+
- [Jaypie_Fabric_Package.md](Jaypie_Fabric_Package.md) - Core fabricService and type conversion
|
|
310
308
|
- [Jaypie_Init_Lambda_Package.md](Jaypie_Init_Lambda_Package.md) - Setting up Lambda projects
|