Skip to content

Fix AI Gateway demo org context and text extraction#1508

Merged
parteeksingh24 merged 4 commits into
mainfrom
fix/aigateway-completion-text
May 28, 2026
Merged

Fix AI Gateway demo org context and text extraction#1508
parteeksingh24 merged 4 commits into
mainfrom
fix/aigateway-completion-text

Conversation

@parteeksingh24
Copy link
Copy Markdown
Contributor

@parteeksingh24 parteeksingh24 commented May 28, 2026

Summary

Fixes two SDK-side AI Gateway demo gaps: org context for unlinked dev projects, and completion text extraction across supported response shapes.

  • Adds shared AI Gateway completion text extraction.
  • Passes org context through agentuity dev for unlinked demo projects.
  • Lets AIGatewayClient read org IDs from standard Agentuity env vars.
  • Updates generated templates to use the shared extraction helper.
  • Makes framework translation tests hit /api/translate directly.

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:

completion.choices?.[0]?.message?.content

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:

const gateway = new AIGatewayClient();
const completion = await gateway.complete(...);
const translation = getAIGatewayCompletionText(completion);

agentuity dev now resolves the org once for the child app process:

const orgId = resolveDevOrgId({ env, projectConfig, config });

if (orgId && !env.AGENTUITY_ORGID) {
  env.AGENTUITY_ORGID = orgId;
}

The AI Gateway client then uses the same org envs users already have:

orgId ??
  AGENTUITY_ORGID ??
  AGENTUITY_ORG_ID ??
  AGENTUITY_CLOUD_ORG_ID

Generated templates now call the shared helper too:

return getAIGatewayCompletionText(completion);

Framework Playwright tests now call the route directly:

const response = await request.post('/api/translate', {
  data: { text: 'Hello world' },
});

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.ts
  • bun test packages/cli/test/cmd/dev/org-id.test.ts
  • bun test packages/core/test/aigateway.test.ts
  • bun run --filter @agentuity/core typecheck
  • bun run --filter @agentuity/aigateway typecheck
  • bun run --filter @agentuity/cli typecheck
  • bun run --filter @agentuity/aigateway build
  • bun run --filter @agentuity/cli build
  • cd tests/frameworks/tanstack-start && bun run typecheck
  • cd tests/frameworks/svelte-web && bun run typecheck
  • cd tests/frameworks/nextjs-app && bunx tsc --noEmit --allowImportingTsExtensions
  • bunx biome lint <changed files>
  • scripts/test-framework-demos.sh --skip-build

Note: the standard Next.js demo bun run typecheck still reports existing TS5097 errors from test files that import .ts / .tsx paths without allowImportingTsExtensions; the supplemental Next.js typecheck above passes.

Summary by CodeRabbit

  • New Features

    • New text-extraction utility for AI Gateway completions that handles responses from major providers and unifies parsing across templates and apps.
    • Re-exported completion-text helper for easier import throughout the project.
  • Bug Fixes

    • Client now normalizes org-id headers, trims blanks, and falls back to configured environment/profile values when an org-id is not provided.
  • Tests

    • Added unit and e2e tests validating text extraction and org-id header selection.

Review Change Stack

- 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
@agentuity-agent
Copy link
Copy Markdown

agentuity-agent Bot commented May 28, 2026

The latest Agentuity deployment details.

Project Deployment Preview Updated (UTC)
docs 🔴 Failed (deploy_2b4178a4b79d07cb593b35e33048adb5) - 2026-05-28T18:23:25Z

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d17e1246-e646-4665-8817-c6723db8a810

📥 Commits

Reviewing files that changed from the base of the PR and between a5b4d4f and 9cfe4c9.

📒 Files selected for processing (1)
  • packages/cli/src/cmd/dev/index.ts
📜 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)
  • GitHub Check: Linux distro install smoke
  • GitHub Check: Windows WSL CLI Smoke Test
  • GitHub Check: Framework Demo Tests
  • GitHub Check: Migrate Chain (v1 → v2 → v3)
  • GitHub Check: Agentuity Deployment
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{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
Use StructuredError from @agentuity/core for error handling

Files:

  • packages/cli/src/cmd/dev/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript in strict mode with ESNext and bundler moduleResolution

Files:

  • packages/cli/src/cmd/dev/index.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 in src/cmd/ with an index.ts file
Always define interfaces for command options using Zod schemas (never use any)
Use requireAuth(ctx) or optionalAuth(ctx) for authenticated commands

Files:

  • packages/cli/src/cmd/dev/index.ts
packages/cli/src/**/*.ts

📄 CodeRabbit inference engine (packages/cli/AGENTS.md)

packages/cli/src/**/*.ts: Use tui.* helpers for formatted output (header, info, success, warning, error, table, progress)
Use ctx.logger for logging; logger.fatal() logs and exits with code 1
Use await readFile(p, 'utf-8') and await writeFile(p, content) from node:fs/promises for file I/O
For file existence checks, import pathExists from node-compat/fs instead 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 .ts extensions for relative paths (e.g., from './foo.ts', not from './foo'). TypeScript's rewriteRelativeImportExtensions rewrites them to .js in the emitted output
Always check isJSONMode() for machine-readable output and use outputJSON() when in JSON mode
Access Bun-specific performance wins (Bun's S3Client, native bun:sqlite) through dedicated abstractions in @agentuity/storage or node-compat/ shims

Files:

  • packages/cli/src/cmd/dev/index.ts
🧠 Learnings (2)
📚 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/dev/index.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/dev/index.ts
🔇 Additional comments (1)
packages/cli/src/cmd/dev/index.ts (1)

183-184: LGTM!


📝 Walkthrough

Walkthrough

Adds 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.

Changes

Completion Text Extraction Helper

Layer / File(s) Summary
Core service implementation and tests
packages/core/src/services/aigateway/service.ts, packages/core/test/aigateway.test.ts
Adds isUnknownRecord and extractor helpers, exports getAIGatewayCompletionText() returning the first non-empty text from choices, output_text, output, then candidates; unit test verifies OpenAI/Responses/Gemini shapes.
Package export wiring
packages/core/src/services/aigateway/index.ts, packages/aigateway/src/index.ts
Re-exports getAIGatewayCompletionText through core aigateway and the top-level aegateway package.
Template & framework route integrations
packages/cli/src/cmd/project/templates/*, tests/frameworks/*/src/routes/api/translate*, tests/frameworks/*/app/api/translate/route.ts
Replaces local completion parsing with getAIGatewayCompletionText across project templates and demo framework routes; removes local parsing helpers and related comments.
E2E test updates
tests/frameworks/*/tests/e2e.pw.ts
Replaces UI-driven translation e2e tests with API-based requests and adds helpers that assert response.ok and extract a non-empty translation string.

Org ID normalization and resolution

Layer / File(s) Summary
AIGateway client header resolution and tests
packages/aigateway/src/index.ts, packages/aigateway/test/index.test.ts
Adds normalizeOrgId/resolveOrgId, passes resolved orgId into AIGatewayClient headers, and adds tests that stub fetch and assert x-agentuity-orgid selection across option/env combinations (including blank-value handling).
CLI dev org-id resolver and tests
packages/cli/src/cmd/dev/index.ts, packages/cli/test/cmd/dev/org-id.test.ts
Adds exported resolveDevOrgId used by the dev command to set AGENTUITY_ORGID from project config, multiple env vars, or CLI profile preferences; tests cover precedence and blank/whitespace handling.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR successfully addresses all linked issue objectives by implementing shape-tolerant text extraction across AI Gateway responses and adding focused tests.
Out of Scope Changes check ✅ Passed All code changes are directly scoped to the linked issue objectives: text extraction normalization, org ID handling, and test adjustments.

✏️ 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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

📦 Canary Packages Published

version: 3.0.1-9cfe4c9

Packages
Package Version URL
@agentuity/coder-tui 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-tui-3.0.1-9cfe4c9.tgz
@agentuity/webhook 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-webhook-3.0.1-9cfe4c9.tgz
@agentuity/hono 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-hono-3.0.1-9cfe4c9.tgz
@agentuity/schedule 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schedule-3.0.1-9cfe4c9.tgz
create-agentuity 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/create-agentuity-3.0.1-9cfe4c9.tgz
@agentuity/adapter 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-adapter-3.0.1-9cfe4c9.tgz
@agentuity/opencode 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-opencode-3.0.1-9cfe4c9.tgz
@agentuity/vite 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vite-3.0.1-9cfe4c9.tgz
@agentuity/keyvalue 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-keyvalue-3.0.1-9cfe4c9.tgz
@agentuity/storage 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-storage-3.0.1-9cfe4c9.tgz
@agentuity/analytics 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-analytics-3.0.1-9cfe4c9.tgz
@agentuity/sandbox 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-sandbox-3.0.1-9cfe4c9.tgz
@agentuity/aigateway 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-aigateway-3.0.1-9cfe4c9.tgz
@agentuity/claude-code 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-claude-code-3.0.1-9cfe4c9.tgz
@agentuity/queue 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-queue-3.0.1-9cfe4c9.tgz
@agentuity/vector 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-vector-3.0.1-9cfe4c9.tgz
@agentuity/db 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-db-3.0.1-9cfe4c9.tgz
@agentuity/postgres 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-postgres-3.0.1-9cfe4c9.tgz
@agentuity/task 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-task-3.0.1-9cfe4c9.tgz
@agentuity/core 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-core-3.0.1-9cfe4c9.tgz
@agentuity/pi 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-pi-3.0.1-9cfe4c9.tgz
@agentuity/coder 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-coder-3.0.1-9cfe4c9.tgz
@agentuity/email 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-email-3.0.1-9cfe4c9.tgz
@agentuity/cli 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-cli-3.0.1-9cfe4c9.tgz
@agentuity/drizzle 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-drizzle-3.0.1-9cfe4c9.tgz
@agentuity/schema 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-schema-3.0.1-9cfe4c9.tgz
@agentuity/server 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-server-3.0.1-9cfe4c9.tgz
@agentuity/local 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-local-3.0.1-9cfe4c9.tgz
@agentuity/stream 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-stream-3.0.1-9cfe4c9.tgz
@agentuity/runtime 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-runtime-3.0.1-9cfe4c9.tgz
@agentuity/migrate 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-migrate-3.0.1-9cfe4c9.tgz
@agentuity/telemetry 3.0.1-9cfe4c9 https://agentuity-sdk-objects.t3.storageapi.dev/npm/3.0.1-9cfe4c9/agentuity-telemetry-3.0.1-9cfe4c9.tgz
Install

Add to your package.json:

{
  "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

@parteeksingh24 parteeksingh24 marked this pull request as ready for review May 28, 2026 00:52
@parteeksingh24 parteeksingh24 changed the title Fix AI Gateway demo translation text Fix AI Gateway completion text extraction May 28, 2026
- 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
@parteeksingh24 parteeksingh24 changed the title Fix AI Gateway completion text extraction Fix AI Gateway demo org context and text extraction May 28, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/frameworks/nextjs-app/tests/e2e.pw.ts (1)

3-27: ⚡ Quick win

Extract readTranslation helpers 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

📥 Commits

Reviewing files that changed from the base of the PR and between 79d0cc3 and a5b4d4f.

📒 Files selected for processing (15)
  • packages/aigateway/src/index.ts
  • packages/aigateway/test/index.test.ts
  • packages/cli/src/cmd/dev/index.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/test/cmd/dev/org-id.test.ts
  • tests/frameworks/nextjs-app/app/api/translate/route.ts
  • tests/frameworks/nextjs-app/tests/e2e.pw.ts
  • tests/frameworks/svelte-web/src/routes/api/translate/+server.ts
  • tests/frameworks/svelte-web/tests/e2e.pw.ts
  • tests/frameworks/tanstack-start/src/routes/api/translate.ts
  • tests/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
Use StructuredError from @agentuity/core for error handling

Files:

  • packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • tests/frameworks/svelte-web/src/routes/api/translate/+server.ts
  • packages/aigateway/src/index.ts
  • packages/cli/test/cmd/dev/org-id.test.ts
  • tests/frameworks/tanstack-start/src/routes/api/translate.ts
  • tests/frameworks/tanstack-start/tests/e2e.pw.ts
  • tests/frameworks/nextjs-app/app/api/translate/route.ts
  • tests/frameworks/nextjs-app/tests/e2e.pw.ts
  • packages/aigateway/test/index.test.ts
  • packages/cli/src/cmd/dev/index.ts
  • tests/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.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • tests/frameworks/svelte-web/src/routes/api/translate/+server.ts
  • packages/aigateway/src/index.ts
  • packages/cli/test/cmd/dev/org-id.test.ts
  • tests/frameworks/tanstack-start/src/routes/api/translate.ts
  • tests/frameworks/tanstack-start/tests/e2e.pw.ts
  • tests/frameworks/nextjs-app/app/api/translate/route.ts
  • tests/frameworks/nextjs-app/tests/e2e.pw.ts
  • packages/aigateway/test/index.test.ts
  • packages/cli/src/cmd/dev/index.ts
  • tests/frameworks/svelte-web/tests/e2e.pw.ts
packages/cli/src/**/*.ts

📄 CodeRabbit inference engine (packages/cli/AGENTS.md)

packages/cli/src/**/*.ts: Use tui.* helpers for formatted output (header, info, success, warning, error, table, progress)
Use ctx.logger for logging; logger.fatal() logs and exits with code 1
Use await readFile(p, 'utf-8') and await writeFile(p, content) from node:fs/promises for file I/O
For file existence checks, import pathExists from node-compat/fs instead 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 .ts extensions for relative paths (e.g., from './foo.ts', not from './foo'). TypeScript's rewriteRelativeImportExtensions rewrites them to .js in the emitted output
Always check isJSONMode() for machine-readable output and use outputJSON() when in JSON mode
Access Bun-specific performance wins (Bun's S3Client, native bun:sqlite) through dedicated abstractions in @agentuity/storage or node-compat/ shims

Files:

  • packages/cli/src/cmd/project/templates/nextjs/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • packages/cli/src/cmd/dev/index.ts
packages/*/src/index.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use named exports from package index.ts files

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 in test/ folder parallel to src/ (never inside src/ or under __tests__/)
Import from ../src/ in test files
Use @agentuity/test-utils for shared mocks in tests

Files:

  • packages/cli/test/cmd/dev/org-id.test.ts
  • packages/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 in src/cmd/ with an index.ts file
Always define interfaces for command options using Zod schemas (never use any)
Use requireAuth(ctx) or optionalAuth(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.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • tests/frameworks/svelte-web/src/routes/api/translate/+server.ts
  • packages/aigateway/src/index.ts
  • packages/cli/test/cmd/dev/org-id.test.ts
  • tests/frameworks/tanstack-start/src/routes/api/translate.ts
  • tests/frameworks/tanstack-start/tests/e2e.pw.ts
  • tests/frameworks/nextjs-app/app/api/translate/route.ts
  • tests/frameworks/nextjs-app/tests/e2e.pw.ts
  • packages/aigateway/test/index.test.ts
  • packages/cli/src/cmd/dev/index.ts
  • tests/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.ts
  • packages/cli/src/cmd/project/templates/sveltekit/src/lib/server/translate.ts
  • packages/cli/src/cmd/project/templates/astro/src/lib/translate.ts
  • packages/cli/src/cmd/project/templates/hono/src/translate.ts
  • packages/cli/src/cmd/project/templates/nuxt/server/utils/translate.ts
  • packages/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.ts
  • packages/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 in tests/frameworks/nextjs-app/tests/e2e.pw.ts: plain Error usage (should use StructuredError) and duplicated translation helper block.


44-54: LGTM!

tests/frameworks/tanstack-start/tests/e2e.pw.ts (2)

3-27: Same issues as already noted in tests/frameworks/nextjs-app/tests/e2e.pw.ts: plain Error usage (should use StructuredError) 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!

Comment thread packages/cli/src/cmd/dev/index.ts
Comment on lines +18 to +23
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);
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is Playwright test code, I'm gonna use plain Error here (consistent with test paths).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

@jhaynie jhaynie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally! 💯

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@parteeksingh24 parteeksingh24 merged commit 9e4cfb8 into main May 28, 2026
26 of 29 checks passed
@parteeksingh24 parteeksingh24 deleted the fix/aigateway-completion-text branch May 28, 2026 18:45
Huijiro added a commit that referenced this pull request May 29, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Framework demos can return empty translations

2 participants