Fix AI Gateway demo org context and text extraction#1508
Conversation
- Add `getAIGatewayCompletionText` for completion payloads - Read OpenAI-compatible `choices` message content - Read Responses-style `output` message content - Read Gemini-style `candidates` content parts - Use shared extraction in framework demo routes - Cover supported shapes in AI Gateway core tests
|
The latest Agentuity deployment details.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🧰 Additional context used📓 Path-based instructions (4)**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/cli/src/cmd/**/index.ts📄 CodeRabbit inference engine (packages/cli/AGENTS.md)
Files:
packages/cli/src/**/*.ts📄 CodeRabbit inference engine (packages/cli/AGENTS.md)
Files:
🧠 Learnings (2)📚 Learning: 2025-12-21T00:31:41.858ZApplied to files:
📚 Learning: 2026-02-17T14:23:15.448ZApplied to files:
🔇 Additional comments (1)
📝 WalkthroughWalkthroughAdds getAIGatewayCompletionText with type guards and extractors, re-exports it through core and aigateway, replaces local parsing across templates and demo routes/tests, and introduces orgId normalization/resolution helpers with tests for header and CLI resolution behavior. ChangesCompletion Text Extraction Helper
Org ID normalization and resolution
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Canary Packages Publishedversion: PackagesInstallAdd to your {
"dependencies": {
"@agentuity/coder-tui": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-tui-3.0.1-9cfe4c9.tgz",
"@agentuity/webhook": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-webhook-3.0.1-9cfe4c9.tgz",
"@agentuity/hono": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-hono-3.0.1-9cfe4c9.tgz",
"@agentuity/schedule": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schedule-3.0.1-9cfe4c9.tgz",
"create-agentuity": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/create-agentuity-3.0.1-9cfe4c9.tgz",
"@agentuity/adapter": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-adapter-3.0.1-9cfe4c9.tgz",
"@agentuity/opencode": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-opencode-3.0.1-9cfe4c9.tgz",
"@agentuity/vite": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vite-3.0.1-9cfe4c9.tgz",
"@agentuity/keyvalue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-keyvalue-3.0.1-9cfe4c9.tgz",
"@agentuity/storage": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-storage-3.0.1-9cfe4c9.tgz",
"@agentuity/analytics": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-analytics-3.0.1-9cfe4c9.tgz",
"@agentuity/sandbox": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-sandbox-3.0.1-9cfe4c9.tgz",
"@agentuity/aigateway": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-aigateway-3.0.1-9cfe4c9.tgz",
"@agentuity/claude-code": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-claude-code-3.0.1-9cfe4c9.tgz",
"@agentuity/queue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-queue-3.0.1-9cfe4c9.tgz",
"@agentuity/vector": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vector-3.0.1-9cfe4c9.tgz",
"@agentuity/db": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-db-3.0.1-9cfe4c9.tgz",
"@agentuity/postgres": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-postgres-3.0.1-9cfe4c9.tgz",
"@agentuity/task": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-task-3.0.1-9cfe4c9.tgz",
"@agentuity/core": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-core-3.0.1-9cfe4c9.tgz",
"@agentuity/pi": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-pi-3.0.1-9cfe4c9.tgz",
"@agentuity/coder": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-3.0.1-9cfe4c9.tgz",
"@agentuity/email": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-email-3.0.1-9cfe4c9.tgz",
"@agentuity/cli": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-cli-3.0.1-9cfe4c9.tgz",
"@agentuity/drizzle": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-drizzle-3.0.1-9cfe4c9.tgz",
"@agentuity/schema": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schema-3.0.1-9cfe4c9.tgz",
"@agentuity/server": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-server-3.0.1-9cfe4c9.tgz",
"@agentuity/local": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-local-3.0.1-9cfe4c9.tgz",
"@agentuity/stream": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-stream-3.0.1-9cfe4c9.tgz",
"@agentuity/runtime": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-runtime-3.0.1-9cfe4c9.tgz",
"@agentuity/migrate": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-migrate-3.0.1-9cfe4c9.tgz",
"@agentuity/telemetry": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-telemetry-3.0.1-9cfe4c9.tgz"
}
}Or install directly: bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-tui-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-webhook-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-hono-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schedule-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/create-agentuity-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-adapter-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-opencode-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vite-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-keyvalue-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-storage-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-analytics-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-sandbox-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-aigateway-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-claude-code-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-queue-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vector-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-db-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-postgres-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-task-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-core-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-pi-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-email-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-cli-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-drizzle-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schema-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-server-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-local-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-stream-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-runtime-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-migrate-3.0.1-9cfe4c9.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-telemetry-3.0.1-9cfe4c9.tgz |
- Set `AGENTUITY_ORGID` for generated dev apps - Let `AIGatewayClient` read org env fallbacks - Move generated routes to shared text extraction - Test org resolution and framework API routes
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/frameworks/nextjs-app/tests/e2e.pw.ts (1)
3-27: ⚡ Quick winExtract
readTranslationhelpers into a shared test utility.This block is duplicated in the Next.js, Svelte, and TanStack e2e suites. Moving it to one shared helper will keep parsing/assertion behavior consistent across frameworks.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/frameworks/nextjs-app/tests/e2e.pw.ts` around lines 3 - 27, The readTranslation helper (functions/types TranslationResponse, isRecord, and readTranslation) is duplicated across multiple e2e suites; extract these into a shared test utility module and import it from Next.js, Svelte, and TanStack e2e tests. Create a single exported helper (e.g., export async function readTranslation(response: TranslationResponse): Promise<string> plus the TranslationResponse type and isRecord helper) in a common test-utils file, update each test file to import and use that exported readTranslation, and remove the duplicated implementations from the individual e2e test files.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/cmd/dev/index.ts`:
- Around line 182-184: The guard that decides whether to inject the resolved
orgId treats whitespace-only AGENTUITY_ORGID as set; change the check to treat
normalized emptiness as unset by trimming and checking truthiness before
injection. Specifically, when using resolveDevOrgId and the variables orgId and
env.AGENTUITY_ORGID, compute a trimmed/normalized value of env.AGENTUITY_ORGID
(e.g., env.AGENTUITY_ORGID?.trim()) and only set env.AGENTUITY_ORGID = orgId
when orgId is truthy and the trimmed env value is empty or falsy.
In `@tests/frameworks/nextjs-app/tests/e2e.pw.ts`:
- Around line 18-23: The parser currently throws plain Error when the response
body isn't an object or when translation is missing; update those throws to use
StructuredError from `@agentuity/core` instead. Import or reference
StructuredError and replace the two throw sites (the checks in the block using
isRecord(body) and the typeof translation check) so they throw new
StructuredError with a concise message (e.g., "Translation response body was not
an object" and "Translation response was missing text") and any relevant
metadata if available.
---
Nitpick comments:
In `@tests/frameworks/nextjs-app/tests/e2e.pw.ts`:
- Around line 3-27: The readTranslation helper (functions/types
TranslationResponse, isRecord, and readTranslation) is duplicated across
multiple e2e suites; extract these into a shared test utility module and import
it from Next.js, Svelte, and TanStack e2e tests. Create a single exported helper
(e.g., export async function readTranslation(response: TranslationResponse):
Promise<string> plus the TranslationResponse type and isRecord helper) in a
common test-utils file, update each test file to import and use that exported
readTranslation, and remove the duplicated implementations from the individual
e2e test files.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f60e3259-b7ab-491e-85bc-01d472e80421
📒 Files selected for processing (15)
packages/aigateway/src/index.tspackages/aigateway/test/index.test.tspackages/cli/src/cmd/dev/index.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/test/cmd/dev/org-id.test.tstests/frameworks/nextjs-app/app/api/translate/route.tstests/frameworks/nextjs-app/tests/e2e.pw.tstests/frameworks/svelte-web/src/routes/api/translate/+server.tstests/frameworks/svelte-web/tests/e2e.pw.tstests/frameworks/tanstack-start/src/routes/api/translate.tstests/frameworks/tanstack-start/tests/e2e.pw.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: Package Installation & Usage Test (node)
- GitHub Check: Queue CLI Tests (node)
- GitHub Check: Framework Demo Tests
- GitHub Check: Pack & Upload
- GitHub Check: Windows WSL CLI Smoke Test
- GitHub Check: Build
- GitHub Check: Agentuity Deployment
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx,js,jsx}: Format code with Biome using tabs (width 3), single quotes, semicolons, lineWidth 100, and trailing commas es5
UseStructuredErrorfrom@agentuity/corefor error handling
Files:
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tstests/frameworks/svelte-web/src/routes/api/translate/+server.tspackages/aigateway/src/index.tspackages/cli/test/cmd/dev/org-id.test.tstests/frameworks/tanstack-start/src/routes/api/translate.tstests/frameworks/tanstack-start/tests/e2e.pw.tstests/frameworks/nextjs-app/app/api/translate/route.tstests/frameworks/nextjs-app/tests/e2e.pw.tspackages/aigateway/test/index.test.tspackages/cli/src/cmd/dev/index.tstests/frameworks/svelte-web/tests/e2e.pw.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with ESNext and bundler moduleResolution
Files:
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tstests/frameworks/svelte-web/src/routes/api/translate/+server.tspackages/aigateway/src/index.tspackages/cli/test/cmd/dev/org-id.test.tstests/frameworks/tanstack-start/src/routes/api/translate.tstests/frameworks/tanstack-start/tests/e2e.pw.tstests/frameworks/nextjs-app/app/api/translate/route.tstests/frameworks/nextjs-app/tests/e2e.pw.tspackages/aigateway/test/index.test.tspackages/cli/src/cmd/dev/index.tstests/frameworks/svelte-web/tests/e2e.pw.ts
packages/cli/src/**/*.ts
📄 CodeRabbit inference engine (packages/cli/AGENTS.md)
packages/cli/src/**/*.ts: Usetui.*helpers for formatted output (header,info,success,warning,error,table,progress)
Usectx.loggerfor logging;logger.fatal()logs and exits with code 1
Useawait readFile(p, 'utf-8')andawait writeFile(p, content)fromnode:fs/promisesfor file I/O
For file existence checks, importpathExistsfromnode-compat/fsinstead of using Node's fs.existsSync
No Bun globals in production source code.Bun.file,Bun.spawn,Bun.color,Bun.stringWidth, etc. are forbidden
Imports must use explicit.tsextensions for relative paths (e.g.,from './foo.ts', notfrom './foo'). TypeScript'srewriteRelativeImportExtensionsrewrites them to.jsin the emitted output
Always checkisJSONMode()for machine-readable output and useoutputJSON()when in JSON mode
Access Bun-specific performance wins (Bun'sS3Client, nativebun:sqlite) through dedicated abstractions in@agentuity/storageornode-compat/shims
Files:
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tspackages/cli/src/cmd/dev/index.ts
packages/*/src/index.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use named exports from package
index.tsfiles
Files:
packages/aigateway/src/index.ts
packages/*/test/**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
packages/*/test/**/*.test.{ts,tsx,js,jsx}: Place tests intest/folder parallel tosrc/(never insidesrc/or under__tests__/)
Import from../src/in test files
Use@agentuity/test-utilsfor shared mocks in tests
Files:
packages/cli/test/cmd/dev/org-id.test.tspackages/aigateway/test/index.test.ts
packages/cli/src/cmd/**/index.ts
📄 CodeRabbit inference engine (packages/cli/AGENTS.md)
packages/cli/src/cmd/**/index.ts: Each command must be a directory insrc/cmd/with anindex.tsfile
Always define interfaces for command options using Zod schemas (never useany)
UserequireAuth(ctx)oroptionalAuth(ctx)for authenticated commands
Files:
packages/cli/src/cmd/dev/index.ts
🧠 Learnings (3)
📚 Learning: 2025-12-21T00:31:41.858Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.
Applied to files:
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tstests/frameworks/svelte-web/src/routes/api/translate/+server.tspackages/aigateway/src/index.tspackages/cli/test/cmd/dev/org-id.test.tstests/frameworks/tanstack-start/src/routes/api/translate.tstests/frameworks/tanstack-start/tests/e2e.pw.tstests/frameworks/nextjs-app/app/api/translate/route.tstests/frameworks/nextjs-app/tests/e2e.pw.tspackages/aigateway/test/index.test.tspackages/cli/src/cmd/dev/index.tstests/frameworks/svelte-web/tests/e2e.pw.ts
📚 Learning: 2026-02-17T14:23:15.448Z
Learnt from: potofpie
Repo: agentuity/sdk PR: 974
File: packages/cli/src/cmd/git/account/list.ts:39-40
Timestamp: 2026-02-17T14:23:15.448Z
Learning: In the Agentuity CLI framework (packages/cli), when a subcommand declares requires: { auth: true }, the framework will automatically call requireAuth() before invoking the handler. Do not call requireAuth(ctx) manually inside command handlers. This applies to all TypeScript command files under packages/cli/src, including paths like packages/cli/src/cmd/git/account/list.ts.
Applied to files:
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.tspackages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.tspackages/cli/src/cmd/project/templates/astro/src/lib/translate.tspackages/cli/src/cmd/project/templates/hono/src/translate.tspackages/cli/src/cmd/project/templates/nuxt/server/utils/translate.tspackages/cli/src/cmd/dev/index.ts
📚 Learning: 2026-02-21T02:05:57.982Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 1010
File: packages/drizzle/test/proxy.test.ts:594-603
Timestamp: 2026-02-21T02:05:57.982Z
Learning: Do not rely on StructuredError from agentuity/core in test files or simple error handling paths. In tests and straightforward error handling, use plain Error objects to represent failures, reserving StructuredError for more complex error scenarios in application logic.
Applied to files:
packages/cli/test/cmd/dev/org-id.test.tspackages/aigateway/test/index.test.ts
🔇 Additional comments (17)
packages/aigateway/test/index.test.ts (1)
1-92: LGTM!packages/cli/src/cmd/dev/index.ts (1)
50-69: LGTM!packages/cli/test/cmd/dev/org-id.test.ts (1)
1-52: LGTM!packages/aigateway/src/index.ts (1)
50-62: LGTM!Also applies to: 90-90
packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts (1)
1-1: LGTM!Also applies to: 43-43
packages/cli/src/cmd/project/templates/hono/src/translate.ts (1)
1-1: LGTM!Also applies to: 43-43
packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.ts (1)
1-1: LGTM!Also applies to: 43-43
packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts (1)
1-1: LGTM!Also applies to: 43-43
packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts (1)
1-1: LGTM!Also applies to: 43-43
tests/frameworks/nextjs-app/app/api/translate/route.ts (1)
5-5: LGTM!tests/frameworks/svelte-web/src/routes/api/translate/+server.ts (1)
5-5: LGTM!tests/frameworks/svelte-web/tests/e2e.pw.ts (2)
3-27: Same issues as already noted intests/frameworks/nextjs-app/tests/e2e.pw.ts: plainErrorusage (should useStructuredError) and duplicated translation helper block.
44-54: LGTM!tests/frameworks/tanstack-start/tests/e2e.pw.ts (2)
3-27: Same issues as already noted intests/frameworks/nextjs-app/tests/e2e.pw.ts: plainErrorusage (should useStructuredError) and duplicated translation helper block.
44-54: LGTM!tests/frameworks/tanstack-start/src/routes/api/translate.ts (1)
5-5: LGTM!tests/frameworks/nextjs-app/tests/e2e.pw.ts (1)
44-54: LGTM!
| if (!isRecord(body)) throw new Error('Translation response body was not an object'); | ||
|
|
||
| const translation = body.translation; | ||
| expect(typeof translation).toBe('string'); | ||
| if (typeof translation !== 'string') throw new Error('Translation response was missing text'); | ||
| expect(translation.trim().length).toBeGreaterThan(0); |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Replace Error with StructuredError in the response parser.
The new helper throws plain Error at Lines 18 and 22; switch these to StructuredError to match repo-wide error handling rules.
As per coding guidelines: "Use StructuredError from @agentuity/core for error handling".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/frameworks/nextjs-app/tests/e2e.pw.ts` around lines 18 - 23, The parser
currently throws plain Error when the response body isn't an object or when
translation is missing; update those throws to use StructuredError from
`@agentuity/core` instead. Import or reference StructuredError and replace the two
throw sites (the checks in the block using isRecord(body) and the typeof
translation check) so they throw new StructuredError with a concise message
(e.g., "Translation response body was not an object" and "Translation response
was missing text") and any relevant metadata if available.
There was a problem hiding this comment.
Given this is Playwright test code, I'm gonna use plain Error here (consistent with test paths).
There was a problem hiding this comment.
@parteeksingh24, that makes sense — test utilities sit outside production error-handling conventions, and plain Error is the idiomatic choice in Playwright test helpers. Happy to defer to your judgment here.
✏️ Learnings added
Learnt from: parteeksingh24
Repo: agentuity/sdk PR: 1508
File: tests/frameworks/nextjs-app/tests/e2e.pw.ts:18-23
Timestamp: 2026-05-28T02:29:30.980Z
Learning: In the `agentuity/sdk` repository, Playwright test files (e.g., `tests/frameworks/*/tests/*.pw.ts`) intentionally use plain `Error` rather than `StructuredError` from `agentuity/core`. The `StructuredError` convention applies only to production/library code paths, not to test utilities and test helpers.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.
There was a problem hiding this comment.
Hmmm, small clarification: by this I mean failures created by Playwright/test helper code should use plain Error or expect assertions. Tests can still import or assert StructuredError when the production code under test intentionally returns or throws one.
There was a problem hiding this comment.
@parteeksingh24, understood — good clarification. The rule is specifically about the error-throw sites in test helper/infrastructure code (like readTranslation), which should use plain Error or expect assertions. Tests can absolutely still import and assert against StructuredError when they're verifying that production code throws one. I'll update the learning to reflect this distinction.
(∩`-´)⊃━☆゚.*・。゚
✏️ Learnings added
Learnt from: parteeksingh24
Repo: agentuity/sdk PR: 1508
File: tests/frameworks/nextjs-app/tests/e2e.pw.ts:18-23
Timestamp: 2026-05-28T02:34:13.751Z
Learning: In Playwright E2E test files under `tests/frameworks/*/tests/` (e.g., `*.pw.ts`) in the `agentuity/sdk` repository, test helper/utility code (e.g., `readTranslation`) should throw plain `Error` and use `expect` assertions rather than `StructuredError` from `agentuity/core`. However, tests *can* still import and assert `StructuredError` when the production code under test intentionally returns or throws one. The distinction is: plain `Error` for failures originating in test infrastructure/helpers; `StructuredError` assertions are valid when testing production code behavior.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
⛔ Learnings removed
Learnt from: parteeksingh24
Repo: agentuity/sdk PR: 1508
File: tests/frameworks/nextjs-app/tests/e2e.pw.ts:18-23
Timestamp: 2026-05-28T02:29:30.980Z
Learning: In Playwright E2E test files under `tests/frameworks/*/tests/` (e.g., `*.pw.ts`), use plain `Error` when throwing/creating errors. Do not require `StructuredError` from `agentuity/core` in these test utilities/helpers, because the `StructuredError` convention is intended only for production/library code paths.
🧠 Learnings used
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.
Learnt from: parteeksingh24
Repo: agentuity/sdk PR: 1508
File: tests/frameworks/nextjs-app/tests/e2e.pw.ts:18-23
Timestamp: 2026-05-28T02:29:30.980Z
Learning: In Playwright E2E test files under `tests/frameworks/*/tests/` (e.g., `*.pw.ts`), use plain `Error` when throwing/creating errors. Do not require `StructuredError` from `agentuity/core` in these test utilities/helpers, because the `StructuredError` convention is intended only for production/library code paths.
|
Actionable comments posted: 0 |
Conflicts in the AI Gateway helpers from #1508. Resolved by: - packages/core/src/services/aigateway/service.ts: keeping the structured extractors and offering #1508's getAIGatewayCompletionText(): string as a thin wrapper around getAIGatewayCompletionTextResult().text. Re-used isUnknownRecord helper from #1508 inside the new extractors for style consistency with the surrounding code. - packages/aigateway/src/index.ts: keeping #1508's resolveOrgId helper + our completeText / completeStructured methods. - packages/aigateway/test/index.test.ts: union of both test files (orgId resolution + completeText/completeStructured). Also applied CodeRabbit review fixes (PR #1515): 1. z.custom<{ '~standard': unknown }>() now uses a predicate so invalid response_schema values fail at parse time instead of leaking into toPlainJsonSchema(). Added a test covering the rejection paths. 2. Raw Error throws in the schema conversion replaced with a typed AIGatewayResponseSchemaError (via StructuredError), matching the convention used elsewhere in this service. 3. The schema-injected system message in the fallback path now always includes 'Output JSON only, no prose, no code fences', even when a description is supplied. 4. hasText now reflects whether a text-bearing field was present, not whether the concatenated text is non-empty. Explicit '' replies now correctly report hasText: true and distinguish from null content that triggered tool_calls / length / refusal. Test updated and an end-to-end test added at the @agentuity/aigateway level. Verification: - bun test packages/core packages/aigateway -> 585 pass / 0 fail - bun run --filter @agentuity/{core,aigateway,cli,pi} typecheck - bun run --filter @agentuity/{core,aigateway} build - bunx biome lint on touched files -> clean
Summary
agentuity devfor unlinked demo projects.AIGatewayClientread org IDs from standard Agentuity env vars./api/translatedirectly.Fixes #1506.
Why
The failing demos had two separate problems that could look similar from the UI.
First, the demo routes assumed every completion looked like OpenAI Chat Completions:
That misses other valid AI Gateway response shapes, so a successful completion could still become an empty
translation.Second, generated or test-suite projects may be unlinked. In
agentuity dev, those projects can fall back to CLI-key auth, and that path still needs org context. The SDK should pass that context through when it already exists locally, rather than requiring every demo route to wire it by hand.Implementation
The route code stays small:
agentuity devnow resolves the org once for the child app process:The AI Gateway client then uses the same org envs users already have:
Generated templates now call the shared helper too:
Framework Playwright tests now call the route directly:
That keeps browser rendering separate from route/auth/AI Gateway behavior, so failures point at the real layer.
Verification
bun test packages/aigateway/test/index.test.tsbun test packages/cli/test/cmd/dev/org-id.test.tsbun test packages/core/test/aigateway.test.tsbun run --filter @agentuity/core typecheckbun run --filter @agentuity/aigateway typecheckbun run --filter @agentuity/cli typecheckbun run --filter @agentuity/aigateway buildbun run --filter @agentuity/cli buildcd tests/frameworks/tanstack-start && bun run typecheckcd tests/frameworks/svelte-web && bun run typecheckcd tests/frameworks/nextjs-app && bunx tsc --noEmit --allowImportingTsExtensionsbunx biome lint <changed files>scripts/test-framework-demos.sh --skip-buildNote: the standard Next.js demo
bun run typecheckstill reports existingTS5097errors from test files that import.ts/.tsxpaths withoutallowImportingTsExtensions; the supplemental Next.js typecheck above passes.Summary by CodeRabbit
New Features
Bug Fixes
Tests