-
Notifications
You must be signed in to change notification settings - Fork 1
Fix instrumentation hook error with conditional loading and restore chat prototype #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix instrumentation hook error with conditional loading and restore chat prototype #286
Conversation
This reverts commit a61babf.
* add totalChunks to metadata for tracing * improve RAG retrieval process * POC UI for chat based documentation * update Start / Continue course * expand text * fix scrollbar problem and chat input resizing * adding progress tracker * center the progress bar * testing out new terminal component and websocket servert * fix terminal issue not staying on * fix weird terminal display * fix self is not defined error * remove unnecessary terminal message * typo * fix weird flow * remove duplicated butotn * playing with coding web server * remove websocket server * creating api for tutorials * fix interface * modify tutorials workflow -- vibecoded * dummy demo code execution api next.js * New pulse agent using response api tools calling * re-build the entire Pulse agent with new design * adding tutorial step workflow * simplify tutorial reader to have consistent api * cleaning up some more steps * breaking frontend to smaller components; * link doc-qa to pulse agent * removing unused import * fix chat input box and have split pane for code editor * enhancing file display * simplify chat interface -- removing unnecessary code block displays * add editor close button * make side bar icons smaller * implement chunk streaming structure * clean up some items * Revert "Implement Copy Page Dropdown Functionality (#239)" This reverts commit 5eb9f16. * fix tutorial step data handling issue * add kv store api service * remove unused interfaces * remove unneeded conversation type * reformat chat history * add kv store api * Simplify and refactor chat to connect with kv store * add uuid package * update example env * share session context * removing debug * Adding session cache with SWR * add .env to gitignore * sync with main * adjust chat message area width and dynamic spacing with sessionsbar * add code editor content * remove redundant comments * display tutorial instruction content * add user based session management * enable split pane resize * adding sessions cursor * sessions paginated loading * clean up env variables * enabling direct llm access flag * add title generation * remove session update redundancy * render session messages directly * fix streaming bug on UI * merge conflict resolution * remove tutorial agent set up that is not currently needed * remove package json * rebuilt package json and remove /api/chat and /api/terminal that were mock/test * delete dummy terminal websocket server * Add tutorial structure rules and enhance tutorial API responses - Introduced a new markdown file defining the structure and authoring guidelines for tutorials. - Updated the tutorial API to return detailed step data, including snippets and metadata. - Refactored tutorial step fetching logic to improve error handling and data retrieval. - Implemented a new `<CodeFromFiles />` component for rendering code snippets from files. - Enhanced chat message rendering to support tutorial content and snippets. * chore(lockfile): sync package-lock with package.json to fix npm ci (add data-uri-to-buffer@2.0.2) * sync package * fix build error * synchronize name of totalSteps * fix linter failure * cleaning up debug log and unused modules * remove debug log from ChatMessage * remove dummy tutorial content * simplify code pieces * add total steps * remove unused components * removing unused module * Remove integration md * replace div with interactable button * remove unused import * toIsoString formatting * gracefully handle setKVValue error * improve tool param wording * remove unused websocket server * add user tutorial status * add tutorial state management * refactor tutorial state route handlers to improve JSON body parsing and error handling * update ChatMessage component to format code snippets with labels above code fences for improved readability * remove python tutorial mdx * Fix CodeRabbit issues: implement validation middleware and improve error handling (#283) * Fix CodeRabbit issues: implement validation middleware, fix config imports, handle KV errors - Add comprehensive body validation middleware for /sessions, /tutorials, /users endpoints - Fix config import issues by moving to static imports at top of files - Add proper KV persistence error handling with success checks - Validate tutorialId as string and prevent path traversal attacks - Fix implicit any types on request body parameters - Replace parseInt with Number.parseInt for consistency - Add proper 400 error responses with detailed validation messages - Use existing types from app/chat/types.ts for validation - Prevent TypeError when no progress exists by handling 404 responses gracefully Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * Fix TypeScript compilation errors in validation middleware - Add SessionMessageValidationResult and SessionMessageOnlyValidationResult types - Fix validation function return type mismatches in session routes - Add proper bounds checking for stepIndex in tutorial route - Ensure all validation errors use consistent error structure - Generate missing docs.json file to resolve import errors All TypeScript compilation errors resolved, ready for CI Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * Refactor validation middleware to be generic and scalable - Add FieldSchema and ValidationSchema interfaces for declarative validation - Implement validateField and validateObject for schema-based validation - Add overloaded parseAndValidateJSON to accept both validators and schemas - Maintain backward compatibility with existing validation functions - Fix TypeScript compilation errors with explicit Message type annotations - Enable reusable validation for current and future types Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * Refactor validation to use Zod schemas and eliminate duplicate source of truth - Replace TypeScript interfaces with Zod schemas in app/chat/types.ts - Derive types using z.infer<typeof Schema> instead of separate interfaces - Update validation middleware to use Zod's safeParse and error handling - Maintain all existing validation behavior while using industry-standard Zod - Fix TypeScript compilation errors and import issues - All API endpoints now use consistent Zod-based validation This eliminates the duplicate source of truth between validation schemas and TypeScript interfaces, making the codebase more maintainable and following modern best practices. Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * Complete Zod migration for messages API endpoint - Replace custom validation logic with SessionMessageRequestSchema - Simplify validation code by using Zod's built-in validation - Maintain all existing functionality while using industry-standard validation Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * Complete Zod migration: remove redundant interfaces and convert utility functions - Remove unused SessionMessageValidationResult and SessionMessageOnlyValidationResult interfaces - Convert validateStepNumber and validateTutorialId to use Zod schemas internally - Add StepNumberSchema and TutorialIdSchema for consistent validation - Maintain backward compatibility with existing function signatures - Complete elimination of duplicate source of truth between validation and types - All validation now uses Zod schemas as single source of truth Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com> * delete lib/validation/types.ts unused module * defensively check tutorials state * update tools description and enhance the path checking --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: srith@agentuity.com <rithsenghorn@gmail.com> Co-authored-by: afterrburn <sun_rsh@outlook.com> * Apply suggestion from @coderabbitai[bot] Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Seng Rith <50646727+afterrburn@users.noreply.github.com> * fix typo * clean up * small fixes * revert css * remove tutorial * remove Tutorial page * remove outdated readme * remove unnecessary dependencies * remove debug logging * example of how tutorial is structured * Revert "example of how tutorial is structured" This reverts commit 6d70c4e. * move helper out of the POST body --------- Signed-off-by: Seng Rith <50646727+afterrburn@users.noreply.github.com> Co-authored-by: afterrburn <sun_rsh@outlook.com> Co-authored-by: Seng Rith <50646727+senghorn@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Add runtime environment detection to prevent @agentuity/sdk loading in Cloudflare Workers - Implement conditional agent loader that only loads agent code in Node.js environments - Fix TypeScript errors in agent-docs tools.ts for ai package v5.0.45 API - Restore chat prototype functionality from PR #279 with instrumentation fix - Add webpack ignore rule for agent-docs to prevent build-time loading - Update tsconfig to exclude agent-docs from TypeScript compilation This resolves the 'Failed to prepare server Error: An error occurred while loading the instrumentation hook' error on agentuity.dev by preventing OpenTelemetry auto-instrumentations from loading in Cloudflare Workers runtime while preserving full chat functionality in Node.js environments. Co-Authored-By: srith@agentuity.com <rithsenghorn@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Caution Review failedThe pull request is closed. WalkthroughThis PR decouples agent-docs from the external SDK by replacing imported types with local aliases, adds environment detection and conditional agent loading, gates tutorial-state operations in API routes, introduces an agent stub fallback, and updates build config to exclude agent-docs from bundling. Minor tool interface tweaks and dependency/config updates are included. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Req as Caller
participant Env as env-detection
participant Loader as agent-loader
participant Agent as agent-docs Agent
participant Stub as agent-stub
Req->>Loader: loadAgentCode()
Loader->>Env: canLoadAgentCode()
alt can load
Loader->>Agent: dynamic import('../agent-docs/.../agent-pulse/index')
alt import fails
Loader->>Stub: dynamic import('./agent-stub')
Loader-->>Req: default export (throws on use)
else import ok
Loader-->>Req: default export (Agent)
end
else cannot load
Loader-->>Req: Error("Agent code cannot be loaded...")
end
sequenceDiagram
autonumber
actor Client
participant Route as /api/sessions/[sessionId]/messages
participant Env as env-detection
participant TSM as TutorialStateManager (dynamic)
participant Agent as Agent (stream)
Note over Route: Build agentPayload (tutorialData may be null)
Client->>Route: POST message
Route->>Env: canLoadAgentCode()
alt can load
Route->>TSM: import + getCurrentState(user)
Route->>Agent: streamText(payload with tutorialData)
else cannot load
Note over Route: tutorialData = null
Route->>Agent: streamText(payload)
end
Agent-->>Route: stream events
loop on data events
alt data.type == "tutorial-data"
Route->>Env: canLoadAgentCode()
alt can load
Route->>TSM: updateTutorialProgress(...)
else cannot load
Note over Route: skip update
end
else other events
Note over Route: forward to client
end
end
Route-->>Client: streamed response
sequenceDiagram
autonumber
actor Client
participant Route as /api/users/tutorial-state
participant Env as env-detection
participant TSM as TutorialStateManager (dynamic)
Client->>Route: GET/POST/DELETE
Route->>Env: canLoadAgentCode()
alt cannot load
Route-->>Client: 503 Service Unavailable
else can load
Route->>TSM: dynamic import
alt GET
Route->>TSM: getCurrentState(user)
Route-->>Client: JSON state
else POST
Route->>TSM: updateTutorialProgress(...)
Route-->>Client: JSON updated
else DELETE
Route->>TSM: resetTutorial(user)
Route-->>Client: 204 No Content
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (22)
Comment |
Fix instrumentation hook error with conditional loading and restore chat prototype
Summary
This PR fixes the "Failed to prepare server Error: An error occurred while loading the instrumentation hook" error on agentuity.dev by implementing conditional loading of
@agentuity/sdk
to prevent OpenTelemetry auto-instrumentations from loading in Cloudflare Workers, while restoring the chat prototype functionality from PR #279.Root Cause: The
@agentuity/sdk
dependency contains@opentelemetry/auto-instrumentations-node
which automatically loads Node.js-specific instrumentation hooks during module resolution. These hooks are incompatible with the Cloudflare Workers runtime.Solution: Implemented runtime environment detection and conditional loading that prevents the problematic OpenTelemetry code from being loaded during Cloudflare Workers initialization while preserving full functionality in Node.js environments.
Key Changes:
lib/env-detection.ts
) to identify Cloudflare Workers vs Node.js environmentslib/agent-loader.ts
) that only imports agent code when safe to do so@agentuity/sdk
imports with generic typesparameters
→inputSchema
, properexecute
signature)Review & Testing Checklist for Human
any
) doesn't cause runtime errorsinputSchema
andexecute
signaturesTest Plan
Notes
Summary by CodeRabbit
New Features
Bug Fixes
Chores