@jaypie/mcp 0.3.2 → 0.4.0

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.
Files changed (79) hide show
  1. package/dist/createMcpServer.d.ts +7 -1
  2. package/dist/index.js +26 -3135
  3. package/dist/index.js.map +1 -1
  4. package/dist/suite.d.ts +1 -0
  5. package/dist/suite.js +2442 -0
  6. package/dist/suite.js.map +1 -0
  7. package/package.json +8 -3
  8. package/release-notes/constructs/1.2.17.md +11 -0
  9. package/release-notes/fabric/0.1.2.md +11 -0
  10. package/release-notes/fabric/0.1.3.md +25 -0
  11. package/release-notes/fabric/0.1.4.md +42 -0
  12. package/release-notes/mcp/0.3.3.md +12 -0
  13. package/release-notes/mcp/0.3.4.md +36 -0
  14. package/release-notes/mcp/0.4.0.md +27 -0
  15. package/release-notes/testkit/1.2.15.md +23 -0
  16. package/skills/agents.md +25 -0
  17. package/skills/aws.md +107 -0
  18. package/skills/cdk.md +141 -0
  19. package/skills/cicd.md +152 -0
  20. package/skills/datadog.md +129 -0
  21. package/skills/debugging.md +148 -0
  22. package/skills/dns.md +134 -0
  23. package/skills/dynamodb.md +140 -0
  24. package/skills/errors.md +142 -0
  25. package/skills/fabric.md +191 -0
  26. package/skills/index.md +7 -0
  27. package/skills/jaypie.md +100 -0
  28. package/skills/legacy.md +97 -0
  29. package/skills/logs.md +160 -0
  30. package/skills/mocks.md +174 -0
  31. package/skills/models.md +195 -0
  32. package/skills/releasenotes.md +94 -0
  33. package/skills/secrets.md +155 -0
  34. package/skills/services.md +175 -0
  35. package/skills/style.md +190 -0
  36. package/skills/tests.md +209 -0
  37. package/skills/tools.md +127 -0
  38. package/skills/topics.md +116 -0
  39. package/skills/variables.md +146 -0
  40. package/skills/writing.md +153 -0
  41. package/prompts/Branch_Management.md +0 -34
  42. package/prompts/Development_Process.md +0 -89
  43. package/prompts/Jaypie_Agent_Rules.md +0 -110
  44. package/prompts/Jaypie_Auth0_Express_Mongoose.md +0 -736
  45. package/prompts/Jaypie_Browser_and_Frontend_Web_Packages.md +0 -18
  46. package/prompts/Jaypie_CDK_Constructs_and_Patterns.md +0 -430
  47. package/prompts/Jaypie_CICD_with_GitHub_Actions.md +0 -371
  48. package/prompts/Jaypie_Commander_CLI_Package.md +0 -166
  49. package/prompts/Jaypie_Core_Errors_and_Logging.md +0 -39
  50. package/prompts/Jaypie_DynamoDB_Package.md +0 -774
  51. package/prompts/Jaypie_Eslint_NPM_Package.md +0 -78
  52. package/prompts/Jaypie_Express_Package.md +0 -630
  53. package/prompts/Jaypie_Fabric_Commander.md +0 -411
  54. package/prompts/Jaypie_Fabric_LLM.md +0 -312
  55. package/prompts/Jaypie_Fabric_Lambda.md +0 -308
  56. package/prompts/Jaypie_Fabric_MCP.md +0 -316
  57. package/prompts/Jaypie_Fabric_Package.md +0 -513
  58. package/prompts/Jaypie_Fabricator.md +0 -617
  59. package/prompts/Jaypie_Ideal_Project_Structure.md +0 -78
  60. package/prompts/Jaypie_Init_CICD_with_GitHub_Actions.md +0 -1186
  61. package/prompts/Jaypie_Init_Express_on_Lambda.md +0 -115
  62. package/prompts/Jaypie_Init_Jaypie_CDK_Package.md +0 -35
  63. package/prompts/Jaypie_Init_Lambda_Package.md +0 -505
  64. package/prompts/Jaypie_Init_Monorepo_Project.md +0 -44
  65. package/prompts/Jaypie_Init_Project_Subpackage.md +0 -65
  66. package/prompts/Jaypie_Legacy_Patterns.md +0 -15
  67. package/prompts/Jaypie_Llm_Calls.md +0 -449
  68. package/prompts/Jaypie_Llm_Tools.md +0 -155
  69. package/prompts/Jaypie_MCP_Package.md +0 -281
  70. package/prompts/Jaypie_Mocks_and_Testkit.md +0 -137
  71. package/prompts/Jaypie_Repokit.md +0 -103
  72. package/prompts/Jaypie_Scrub.md +0 -177
  73. package/prompts/Jaypie_Streaming.md +0 -467
  74. package/prompts/Templates_CDK_Subpackage.md +0 -115
  75. package/prompts/Templates_Express_Subpackage.md +0 -187
  76. package/prompts/Templates_Project_Monorepo.md +0 -326
  77. package/prompts/Templates_Project_Subpackage.md +0 -93
  78. package/prompts/Write_Efficient_Prompt_Guides.md +0 -48
  79. package/prompts/Write_and_Maintain_Engaging_Readme.md +0 -67
@@ -1,115 +0,0 @@
1
- ---
2
- trigger: model_decision
3
- description: Create a new Express application subpackage that runs as a serverless Lambda behind API Gateway using @jaypie/express utilities
4
- ---
5
-
6
- # Jaypie Initialize Express Application on Lambda
7
-
8
- Create an Express application subpackage that uses @jaypie/express to run as a serverless Lambda behind API Gateway. This prompt is for creating **application packages** (like packages/api or packages/backend), not the @jaypie/express library itself.
9
-
10
- ## Process
11
-
12
- 1. Follow Jaypie_Init_Project_Subpackage.md:
13
- * Choose an appropriate package name (e.g., @project-org/api, @project-org/backend)
14
- * Use packages/<package-name> for the directory (e.g., packages/api)
15
- * This creates the basic subpackage structure with package.json, tsconfig.json, and vitest config files
16
-
17
- 2. Create Express application files using Templates_Express_Subpackage.md:
18
- * Create `packages/<package-name>/index.ts` using the index.ts template
19
- * Create `packages/<package-name>/src/app.ts` using the app.ts template
20
- * Create `packages/<package-name>/src/handler.config.ts` using the handler.config.ts template
21
- * Create `packages/<package-name>/src/routes/resource.router.ts` using the resource.router.ts template
22
- * Create `packages/<package-name>/src/routes/resource/resourceGet.route.ts` using the resourceGet.route.ts template
23
- * Create `packages/<package-name>/src/routes/resource/__tests__/resourceGet.route.spec.ts` using the test template
24
- * Create `packages/<package-name>/src/types/express.ts` using the express types template
25
- * All templates are documented in Templates_Express_Subpackage.md
26
-
27
- 3. Update package.json scripts:
28
- * Add these scripts to the package.json:
29
- * `"dev": "tsx watch index.ts"`
30
- * `"start": "node dist/index.js"`
31
- * `"build": "tsc"`
32
- * Keep existing scripts from the template (test, lint, typecheck, format)
33
- * Run `npm --workspace ./packages/<package-name> run format:package`
34
-
35
- 4. Install dependencies:
36
- * `npm --workspace ./packages/<package-name> install jaypie express @codegenie/serverless-express`
37
- * `npm --workspace ./packages/<package-name> install --save-dev @types/express @types/cors tsx`
38
- * Always use npm install commands; never manually edit package.json dependencies
39
-
40
- 5. Update TypeScript configuration:
41
- * Edit packages/<package-name>/tsconfig.json to include index.ts in the include array
42
- * Change include to: `"include": ["src/**/*", "index.ts"]`
43
- * Change exclude to: `"exclude": ["node_modules", "dist", "**/*.spec.ts"]`
44
- * Test the build with `npm --workspace ./packages/<package-name> run build`
45
- * Verify dist/ is in root .gitignore (it should already be there)
46
-
47
- 6. Update the top-level package.json:
48
- * Add workspace-specific dev and start scripts
49
- * Add `"dev:<package-name>": "npm --workspace packages/<package-name> run dev"`
50
- * Add `"start:<package-name>": "npm --workspace packages/<package-name> run start"`
51
- * If there is no standalone `dev` or `start` script, create them referencing the new package
52
- * If `dev` or `start` scripts already exist, consider whether to update them based on project needs
53
-
54
- ## Pattern
55
-
56
- - TypeScript with ES modules (`"type": "module"`)
57
- - Handler pattern: configuration → lifecycle → processing → response
58
- - Use `handlerConfig` helper for shared configuration and lifecycle management
59
- - Separation of concerns: routers, route handlers, and middleware
60
- - Lambda-optimized Express configuration using @codegenie/serverless-express
61
- - Development mode: Express listens on port 8080 when NODE_ENV=development
62
-
63
- ## Structure
64
-
65
- ```
66
- <package-name>/
67
- ├── package.json
68
- ├── tsconfig.json
69
- ├── vite.config.ts # From template
70
- ├── vitest.config.ts # From template
71
- ├── vitest.setup.ts # From template
72
- ├── index.ts # Lambda handler entry point
73
- ├── src/
74
- │ ├── app.ts # Express app configuration
75
- │ ├── handler.config.ts # Shared handler configuration helper
76
- │ ├── routes/
77
- │ │ ├── resource.router.ts
78
- │ │ └── resource/
79
- │ │ ├── resourceGet.route.ts
80
- │ │ └── __tests__/
81
- │ │ └── resourceGet.route.spec.ts
82
- │ └── types/
83
- │ └── express.ts # Express type augmentation for req.locals
84
- └── dist/ # Generated by tsc
85
- ```
86
-
87
- ## Local Development
88
-
89
- The index.ts template checks `process.env.NODE_ENV === "development"` to enable local development mode. In this mode, Express listens on port 8080 (port 3000 is typically reserved for frontend applications).
90
-
91
- Start local development with:
92
- ```bash
93
- npm run dev:<package-name>
94
- ```
95
-
96
- This runs `tsx watch index.ts`, which:
97
- - Sets up the Express app
98
- - Listens on port 8080
99
- - Auto-reloads on file changes
100
- - Does not invoke serverless-express wrapper
101
-
102
- ## Version Compatibility
103
-
104
- - Express: 4.x (Express 5 upgrade not planned)
105
- - Node: ES modules with TypeScript
106
- - @codegenie/serverless-express: 4.x
107
- - @types/express: Compatible with Express 4.x
108
-
109
- ## Context Files
110
-
111
- Reference these files for additional guidance:
112
- - `Jaypie_Init_Project_Subpackage.md` - Subpackage initialization process
113
- - `Templates_Express_Subpackage.md` - Code templates for all files
114
- - `Jaypie_Express_Package.md` - Documentation on @jaypie/express features
115
- - `Jaypie_Core_Errors_and_Logging.md` - Error handling patterns
@@ -1,35 +0,0 @@
1
- ---
2
- trigger: model_decision
3
- description: When asked to create a new workspace or subpackage for cdk, usually packages/cdk
4
- ---
5
-
6
- # Jaypie Initialize CDK Subpackage
7
-
8
- ## Process
9
-
10
- 1. Follow Jaypie_Init_Project_Subpackage.md:
11
- * Use @project-org/cdk in packages/cdk
12
- * Skip the src structure
13
-
14
- 2. Copy template files:
15
- * Copy `prompts/templates/cdk-subpackage/bin/cdk.ts` to `packages/cdk/bin/cdk.ts`
16
- * Copy `prompts/templates/cdk-subpackage/lib/cdk-app.ts` to `packages/cdk/lib/cdk-app.ts`
17
- * Copy `prompts/templates/cdk-subpackage/lib/cdk-infrastructure.ts` to `packages/cdk/lib/cdk-infrastructure.ts`
18
- * Copy `prompts/templates/cdk-subpackage/cdk.json` to `packages/cdk/cdk.json`
19
-
20
- 3. Update package.json:
21
- * Add `"bin": {"cdk": "dist/cdk.js"}`
22
- * In `scripts`,
23
- * Make `"clean": "rimfaf cdk.out",`
24
- * Add `"cdk": "cdk",`
25
- * Run `npm run format:package`
26
-
27
- 4. Install dependencies:
28
- * `npm --workspace ./packages/cdk install @jaypie/constructs aws-cdk-lib constructs`
29
- * `npm --workspace ./packages/cdk install --save-dev aws-cdk`
30
- * Always run `npm install`, never update package.json with dependencies from memory
31
-
32
- 5. Update TypeScript build:
33
- * Update packages/cdk/tsconfig.json and packages/cdk/vite.config.ts to build from bin and lib while creating dist/cdk.js
34
- * Test the build
35
- * Make sure `cdk.out` is in gitignore
@@ -1,505 +0,0 @@
1
- ---
2
- trigger: model_decision
3
- description: When asked to create a new workspace or subpackage for lambdas
4
- ---
5
-
6
- # Jaypie Lambda Package
7
-
8
- Lambda package structure for AWS Lambda functions using Jaypie.
9
-
10
- ## Goal
11
-
12
- Create AWS Lambda functions that integrate with Jaypie for event-driven processing.
13
-
14
- ## Guidelines
15
-
16
- - Uses TypeScript with ES modules
17
- - Leverages Jaypie's lambdaHandler wrapper for setup/teardown
18
- - Built with Rollup for optimized deployment packages
19
- - Tests with Vitest and Jaypie testkit
20
-
21
- ## Process
22
-
23
- ### 1. Setup Package Structure
24
-
25
- ```
26
- packages/lambda/
27
- ├── package.json # Define dependencies and scripts
28
- ├── tsconfig.json # TypeScript configuration
29
- ├── rollup.config.mjs # Bundle configuration
30
- ├── vite.config.js # Test configuration
31
- ├── testSetup.ts # Test setup and matchers
32
- └── src/
33
- ├── index.ts # Export handlers
34
- ├── worker.ts # Lambda function implementation
35
- └── __tests__/ # Test files
36
- └── worker.spec.ts
37
- ```
38
-
39
- ### 2. Configure package.json
40
-
41
- ```json
42
- {
43
- "name": "@yourorg/lambda",
44
- "version": "0.1.0",
45
- "type": "module",
46
- "exports": {
47
- ".": {
48
- "types": "./dist/esm/index.d.ts",
49
- "import": "./dist/esm/index.js",
50
- "require": "./dist/cjs/index.cjs"
51
- }
52
- },
53
- "main": "./dist/cjs/index.cjs",
54
- "module": "./dist/esm/index.js",
55
- "types": "./dist/esm/index.d.ts",
56
- "files": [
57
- "dist"
58
- ],
59
- "scripts": {
60
- "build": "rollup --config",
61
- "format": "npm run format:package && npm run format:lint",
62
- "format:lint": "eslint --fix .",
63
- "format:package": "sort-package-json ./package.json",
64
- "lint": "eslint .",
65
- "test": "vitest run .",
66
- "typecheck": "tsc --noEmit"
67
- },
68
- "dependencies": {
69
- "@jaypie/core": "^1.1.0",
70
- "@jaypie/lambda": "^1.1.0"
71
- },
72
- "devDependencies": {
73
- "@rollup/plugin-typescript": "^12.0.0",
74
- "@types/aws-lambda": "^8.10.0",
75
- "rollup": "^4.0.0",
76
- "rollup-plugin-auto-external": "^2.0.0",
77
- "typescript": "^5.0.0"
78
- }
79
- }
80
- ```
81
-
82
- ### 3. Configure TypeScript
83
-
84
- ```json
85
- {
86
- "compilerOptions": {
87
- "target": "ES2020",
88
- "module": "ESNext",
89
- "moduleResolution": "node",
90
- "declaration": true,
91
- "outDir": "./dist",
92
- "strict": true,
93
- "esModuleInterop": true,
94
- "skipLibCheck": true,
95
- "forceConsistentCasingInFileNames": true
96
- },
97
- "include": ["src/**/*"],
98
- "exclude": ["node_modules", "dist", "src/__tests__"]
99
- }
100
- ```
101
-
102
- ### 4. Configure Rollup
103
-
104
- Create `rollup.config.mjs`:
105
-
106
- ```javascript
107
- import autoExternal from "rollup-plugin-auto-external";
108
- import typescript from "@rollup/plugin-typescript";
109
-
110
- export default [
111
- // ES modules version
112
- {
113
- input: "src/index.ts",
114
- output: {
115
- dir: "dist/esm",
116
- format: "es",
117
- sourcemap: true,
118
- },
119
- plugins: [
120
- autoExternal(),
121
- typescript({
122
- tsconfig: "./tsconfig.json",
123
- declaration: true,
124
- outDir: "dist/esm",
125
- }),
126
- ],
127
- },
128
- // CommonJS version
129
- {
130
- input: "src/index.ts",
131
- output: {
132
- dir: "dist/cjs",
133
- format: "cjs",
134
- sourcemap: true,
135
- exports: "named",
136
- entryFileNames: "[name].cjs",
137
- },
138
- plugins: [
139
- autoExternal(),
140
- typescript({
141
- tsconfig: "./tsconfig.json",
142
- declaration: true,
143
- outDir: "dist/cjs",
144
- }),
145
- ],
146
- },
147
- ];
148
- ```
149
-
150
- ### 5. Setup Vitest
151
-
152
- Create `vite.config.js`:
153
-
154
- ```javascript
155
- /// <reference types="vitest" />
156
-
157
- import { defineConfig } from "vite";
158
-
159
- export default defineConfig({
160
- test: {
161
- setupFiles: ["./testSetup.ts"],
162
- },
163
- });
164
- ```
165
-
166
- Create `testSetup.ts`:
167
-
168
- ```typescript
169
- import { matchers as jaypieMatchers } from "@jaypie/testkit";
170
- import * as extendedMatchers from "jest-extended";
171
- import { expect } from "vitest";
172
-
173
- expect.extend(extendedMatchers);
174
- expect.extend(jaypieMatchers);
175
- ```
176
-
177
- Note: Do not mock `jaypie` in the setup file for lambda consumer packages. Mock in individual test files as needed.
178
-
179
- ### 6. Create Handler Implementation
180
-
181
- ```typescript
182
- // src/worker.ts
183
- import { log } from "@jaypie/core";
184
- import { lambdaHandler } from "@jaypie/lambda";
185
- import type { LambdaContext } from "@jaypie/lambda";
186
-
187
- export interface WorkerEvent {
188
- message?: string;
189
- }
190
-
191
- export const handler = lambdaHandler(
192
- async (event: WorkerEvent, context?: LambdaContext) => {
193
- log.trace("worker: start");
194
-
195
- const message = event?.message || "Hello, world!";
196
-
197
- log.trace("worker: processing message", { message });
198
-
199
- const response = {
200
- status: "success",
201
- message,
202
- timestamp: new Date().toISOString(),
203
- };
204
-
205
- log.trace("worker: complete");
206
- return response;
207
- },
208
- {
209
- name: "worker",
210
- },
211
- );
212
- ```
213
-
214
- ### 7. Export Handler
215
-
216
- ```typescript
217
- // src/index.ts
218
- export { handler as workerHandler } from "./worker.js";
219
- ```
220
-
221
- ### 8. Write Tests
222
-
223
- Tests are organized in sections: Base Cases, Error Conditions, Security, Observability, Happy Paths, Features, Specific Scenarios. Omit sections that are not applicable.
224
-
225
- ```typescript
226
- // src/__tests__/worker.spec.ts
227
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
228
-
229
- import { log } from "@jaypie/core";
230
- import { restoreLog, spyLog } from "@jaypie/testkit";
231
-
232
- // Subject
233
- import { handler } from "../worker.js";
234
- import type { WorkerEvent } from "../worker.js";
235
-
236
- //
237
- //
238
- // Mock modules
239
- //
240
-
241
- vi.mock("@jaypie/core", async () => {
242
- const actual = await vi.importActual("@jaypie/core");
243
- return {
244
- ...actual,
245
- };
246
- });
247
-
248
- //
249
- //
250
- // Mock environment
251
- //
252
-
253
- const DEFAULT_ENV = process.env;
254
- beforeEach(() => {
255
- process.env = { ...process.env };
256
- spyLog(log);
257
- });
258
- afterEach(() => {
259
- process.env = DEFAULT_ENV;
260
- vi.clearAllMocks();
261
- restoreLog(log);
262
- });
263
-
264
- //
265
- //
266
- // Run tests
267
- //
268
-
269
- describe("worker Lambda handler", () => {
270
- describe("Base Cases", () => {
271
- it("Works", async () => {
272
- const event: WorkerEvent = {};
273
- const result = await handler(event);
274
- expect(result).toBeDefined();
275
- });
276
- });
277
-
278
- describe("Observability", () => {
279
- it("Does not log above trace", async () => {
280
- const event: WorkerEvent = { message: "Test" };
281
- await handler(event);
282
- expect(log).not.toBeCalledAboveTrace();
283
- });
284
- });
285
-
286
- describe("Happy Paths", () => {
287
- it("Returns success with provided message", async () => {
288
- const event: WorkerEvent = {
289
- message: "Test message",
290
- };
291
-
292
- const result = await handler(event);
293
-
294
- expect(result).toHaveProperty("status", "success");
295
- expect(result).toHaveProperty("message", "Test message");
296
- expect(result).toHaveProperty("timestamp");
297
- });
298
-
299
- it("Returns default message when none provided", async () => {
300
- const event: WorkerEvent = {};
301
-
302
- const result = await handler(event);
303
-
304
- expect(result).toHaveProperty("message", "Hello, world!");
305
- });
306
- });
307
- });
308
- ```
309
-
310
- ### 9. Build and Test
311
-
312
- Build, lint, typecheck, and test the package:
313
-
314
- ```bash
315
- # Install dependencies (from monorepo root)
316
- npm install <package> -w packages/lambda
317
-
318
- # Lint and format
319
- npm run format -w packages/lambda
320
-
321
- # Type check
322
- npm run typecheck -w packages/lambda
323
-
324
- # Build the package
325
- npm run build -w packages/lambda
326
-
327
- # Run tests
328
- npm run test -w packages/lambda
329
- ```
330
-
331
- ### 10. Deploy
332
-
333
- Deploy using AWS CDK or other deployment tool. The Lambda handler will be referenced as "workerHandler" from the built package.
334
-
335
- ## Important Notes
336
-
337
- ### Import Patterns
338
-
339
- - Import `lambdaHandler` from `@jaypie/lambda`, not from `jaypie`
340
- - Import `log` from `@jaypie/core`, not from `jaypie`
341
- - Use `LambdaContext` type from `@jaypie/lambda`, not `Context` from `jaypie`
342
- - TypeScript files must use `.js` extension in relative imports (e.g., `from "./worker.js"`)
343
-
344
- ### Test Structure
345
-
346
- - Tests are organized in 7 sections: Base Cases, Error Conditions, Security, Observability, Happy Paths, Features, Specific Scenarios
347
- - Omit sections that are not applicable
348
- - Use `spyLog` and `restoreLog` from `@jaypie/testkit` for logging tests
349
- - Use Jaypie matchers like `toBeCalledAboveTrace()` for observability tests
350
- - Mock `@jaypie/core` in test files, not in `testSetup.ts`
351
-
352
- ### Build Configuration
353
-
354
- - Use `rollup-plugin-auto-external` to automatically exclude dependencies from bundles
355
- - Build both ESM and CommonJS formats for maximum compatibility
356
- - Use `vite.config.js` (not `vitest.config.ts`) for test configuration
357
- - Use `testSetup.ts` (not `vitest.setup.ts`) for test setup
358
-
359
- ### Code Style
360
-
361
- - Use double quotes, trailing commas, semicolons
362
- - Alphabetize imports and properties
363
- - Define constants for hard-coded values at file top
364
- - Never throw vanilla Error; use errors from `@jaypie/errors`
365
-
366
- ## Streaming Lambda Functions
367
-
368
- Use `lambdaStreamHandler` for AWS Lambda Response Streaming. This enables real-time streaming responses for LLM interactions, large file processing, and SSE endpoints.
369
-
370
- ### Lambda Streaming Setup
371
-
372
- Create a streaming Lambda handler with `awslambda.streamifyResponse`:
373
-
374
- ```typescript
375
- // src/streamWorker.ts
376
- import { log } from "@jaypie/core";
377
- import { lambdaStreamHandler, createLambdaStream, Llm } from "jaypie";
378
- import type { StreamHandlerContext } from "@jaypie/lambda";
379
-
380
- export interface StreamWorkerEvent {
381
- prompt?: string;
382
- }
383
-
384
- const streamWorker = lambdaStreamHandler(
385
- async (event: StreamWorkerEvent, context: StreamHandlerContext) => {
386
- log.trace("streamWorker: start");
387
-
388
- const llm = new Llm("anthropic");
389
- const stream = llm.stream(event.prompt || "Hello");
390
-
391
- // createLambdaStream pipes LLM chunks as SSE events
392
- await createLambdaStream(stream, context.responseStream);
393
-
394
- log.trace("streamWorker: complete");
395
- },
396
- {
397
- name: "streamWorker",
398
- contentType: "text/event-stream",
399
- }
400
- );
401
-
402
- // Wrap with AWS streamifyResponse
403
- declare const awslambda: { streamifyResponse: <T>(handler: T) => T };
404
- export const handler = awslambda.streamifyResponse(streamWorker);
405
- ```
406
-
407
- ### Manual Stream Writing
408
-
409
- Write directly to the response stream for custom SSE events:
410
-
411
- ```typescript
412
- import { lambdaStreamHandler } from "jaypie";
413
- import type { StreamHandlerContext } from "@jaypie/lambda";
414
-
415
- const manualStreamHandler = lambdaStreamHandler(
416
- async (event: unknown, context: StreamHandlerContext) => {
417
- const { responseStream } = context;
418
-
419
- // Write SSE events directly
420
- responseStream.write("event: start\ndata: {\"status\": \"processing\"}\n\n");
421
-
422
- // Process data in chunks
423
- for (const item of items) {
424
- const result = await process(item);
425
- responseStream.write(`event: data\ndata: ${JSON.stringify(result)}\n\n`);
426
- }
427
-
428
- responseStream.write("event: done\ndata: {\"status\": \"complete\"}\n\n");
429
- // Handler automatically calls responseStream.end()
430
- },
431
- {
432
- name: "manualStream",
433
- }
434
- );
435
- ```
436
-
437
- ### Stream Handler Options
438
-
439
- ```typescript
440
- import type { LambdaStreamHandlerOptions } from "@jaypie/lambda";
441
-
442
- const options: LambdaStreamHandlerOptions = {
443
- name: "myStreamHandler", // Handler name for logging
444
- contentType: "text/event-stream", // Response content type (default)
445
- chaos: "low", // Chaos testing level
446
- secrets: ["API_KEY"], // AWS secrets to load into process.env
447
- setup: [], // Setup function(s)
448
- teardown: [], // Teardown function(s)
449
- validate: [], // Validation function(s)
450
- throw: false, // Re-throw errors instead of SSE error
451
- unavailable: false, // Return 503 if true
452
- };
453
- ```
454
-
455
- ### Stream Handler Types
456
-
457
- ```typescript
458
- import type {
459
- LambdaStreamHandlerOptions,
460
- StreamHandlerContext,
461
- ResponseStream,
462
- AwsStreamingHandler,
463
- } from "@jaypie/lambda";
464
- ```
465
-
466
- ### CDK Configuration for Streaming
467
-
468
- Enable Lambda Response Streaming via Function URL in CDK:
469
-
470
- ```typescript
471
- import { JaypieLambda } from "@jaypie/constructs";
472
- import { FunctionUrlAuthType, InvokeMode } from "aws-cdk-lib/aws-lambda";
473
-
474
- const streamingLambda = new JaypieLambda(this, "StreamingFunction", {
475
- code: "dist",
476
- handler: "streamWorker.handler",
477
- timeout: Duration.minutes(5),
478
- });
479
-
480
- // Add Function URL with streaming enabled
481
- streamingLambda.addFunctionUrl({
482
- authType: FunctionUrlAuthType.NONE, // or AWS_IAM for auth
483
- invokeMode: InvokeMode.RESPONSE_STREAM,
484
- });
485
-
486
- // Or use JaypieDistribution with streaming: true for CloudFront integration
487
- new JaypieDistribution(this, "Distribution", {
488
- handler: streamingLambda,
489
- streaming: true,
490
- host: "api.example.com",
491
- zone: "example.com",
492
- });
493
- ```
494
-
495
- ### Error Handling in Streams
496
-
497
- Errors are formatted as SSE error events:
498
-
499
- ```typescript
500
- // Jaypie errors written as:
501
- // event: error
502
- // data: {"errors":[{"status":500,"title":"Internal Error"}]}
503
- ```
504
-
505
- Set `throw: true` to re-throw errors instead of writing to stream.
@@ -1,44 +0,0 @@
1
- ---
2
- description: Monorepo setup using Jaypie conventions and utilities
3
- ---
4
-
5
- # Jaypie Initialize Monorepo Project
6
-
7
- Monorepo setup using Jaypie conventions and utilities
8
-
9
- ## Goal
10
-
11
- * Jaypie project opinions and tooling
12
- * ESLint 9+ flat config with @jaypie/eslint
13
- * NPM with Workspaces ("monorepo")
14
- * TypeScript
15
- * Vite and Vitest
16
-
17
- ## Guidelines
18
-
19
- * This guide should compliment Jaypie_Project_Structure.md. The two should not conflict. Raise any conflicts with the user.
20
- * Run `npm install` to get the latest version of all software and generate a package-lock.json. Do not hard-code package versions from memory.
21
- * If this is the very first commit, you should make it on main. This is the only time a commit should be made and pushed on main.
22
-
23
- ## Process
24
-
25
- 1. Copy all the files from `prompts/templates/project-monorepo/` to the root directory
26
- 2. Edit name in "@project-org/project-name" based on user instruction or infer from the directory name
27
- 3. Remove the sample paths from tsconfig.base.json
28
- 4. Remove the sample references from tsconfig.json
29
- 5. Install requisite packages
30
-
31
- ```bash
32
- npm install --save-dev @jaypie/eslint @jaypie/testkit eslint rimraf sort-package-json tsx vite vite-plugin-dts vitest
33
- ```
34
-
35
- ## Context
36
-
37
- prompts/Jaypie_Ideal_Project_Structure.md
38
- prompts/templates/project-monorepo/gitignore (rename to .gitignore when copying)
39
- prompts/templates/project-monorepo/.vscode/settings.json
40
- prompts/templates/project-monorepo/eslint.config.mjs
41
- prompts/templates/project-monorepo/package.json
42
- prompts/templates/project-monorepo/tsconfig.base.json
43
- prompts/templates/project-monorepo/tsconfig.json
44
- prompts/templates/project-monorepo/vitest.workspace.js