Skip to content

refactor(integrations): add typed interfaces for SQL/REST API integrations (#79)#82

Merged
larryro merged 7 commits into
mainfrom
claude/add-typed-api-interfaces-eiFcQ
Jan 6, 2026
Merged

refactor(integrations): add typed interfaces for SQL/REST API integrations (#79)#82
larryro merged 7 commits into
mainfrom
claude/add-typed-api-interfaces-eiFcQ

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Jan 5, 2026

Summary

  • Add typed interfaces (SqlIntegration, RestApiIntegration) and type guards to eliminate any casts when accessing integration-specific fields
  • Replace widespread (integration as any).sqlConnectionConfig patterns with proper type narrowing
  • Improve type safety across integration-related code

Problem

The Doc<'integrations'> type from Convex doesn't properly capture optional/discriminated fields like sqlConnectionConfig and sqlOperations at the type level. This led to widespread any usage and type assertions:

// Before
const sqlConnectionConfig = (integration as any).sqlConnectionConfig;
const integrationType = (integration as any).type || 'rest_api';


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Refactor**
  * Improved type safety and handling for SQL and REST integrations, with safer integration-type detection and stricter runtime validation.
  * Batch operations now return a consolidated result with aggregated stats and validation.
  * SQL and REST execution paths use clearer integration shapes, enabling tighter parameter validation and more consistent error handling.

<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 5, 2026

📝 Walkthrough

Walkthrough

The PR replaces raw Convex document typing for integrations with explicit public types (Integration, SqlIntegration, RestApiIntegration) and adds type-guard utilities (getIntegrationType, isSqlIntegration, isRestApiIntegration). Integration validators were added/tightened (integrationDocValidator, syncStatsValidator) and batch result validation was introduced (operationResultValidator, batchResultValidator, BatchResult). Multiple integration execution and introspection paths were updated to accept the new types, to destructure sqlConnectionConfig/sqlOperations from SqlIntegration, and to branch using the new guards; function signatures and internal operation typing (SqlOperation) were adjusted accordingly. Query return validators in integrations.ts were tightened to use the new integrationDocValidator.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs


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

Copy link
Copy Markdown

@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: 5

Fix all issues with AI Agents 🤖
In
@services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts:
- Around line 88-92: The code redundantly checks integration.type twice by
calling getIntegrationType(integration) then testing both integrationType ===
'sql' and isSqlIntegration(integration); simplify by removing the
integrationType === 'sql' check and use only the type guard
isSqlIntegration(integration) to enter the SQL branch (adjust any uses of
integrationType inside the block to call getIntegrationType only if still needed
elsewhere or remove that call entirely); update the conditional around the sql
branch where sqlConnectionConfig and sqlOperations are destructured so it reads
solely on isSqlIntegration(integration).
- Around line 16-21: The import isRestApiIntegration is unused; remove it from
the import list alongside getIntegrationType and isSqlIntegration in
integration_introspect_tool.ts, or alternatively apply the isRestApiIntegration
type guard to the REST API handling branch (the code that builds the REST path)
to mirror the SQL guard; pick one approach and update the import list and the
REST path branch accordingly so there are no unused imports and the REST path
uses a proper guard if kept.

In @services/platform/convex/model/integrations/types.ts:
- Around line 96-103: The RestApiIntegration interface currently requires type:
'rest_api' while the isRestApiIntegration type guard (isRestApiIntegration) also
treats type === undefined as valid for backward compatibility; reconcile them by
either changing RestApiIntegration to allow type: 'rest_api' | undefined (so the
interface matches the guard for legacy untyped integrations) or tighten
isRestApiIntegration to only accept 'rest_api' and update callers; update the
RestApiIntegration declaration (and any equivalent integrations/guards) and
ensure the connector: ConnectorConfig field remains unchanged so compile-time
narrowing works consistently with the chosen approach.

In
@services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts:
- Around line 38-46: The executeSqlIntegration function currently returns
Promise<unknown>; define a typed union (e.g., type ExecuteSqlResult =
ApprovalRequiredResult | { name: string; operation: string; engine: string;
data: unknown; rowCount: number; duration: number; }) and change the function
signature of executeSqlIntegration to return Promise<ExecuteSqlResult>, then
ensure all return sites inside executeSqlIntegration produce either an
ApprovalRequiredResult or the shaped result object (with name, operation,
engine, data, rowCount, duration) to satisfy the new type.

In @services/platform/convex/workflow/actions/integration/integration_action.ts:
- Around line 81-86: The code redundantly checks integrationType === 'sql'
before calling isSqlIntegration(integration) which already verifies
integration.type === 'sql'; remove the redundant integrationType === 'sql'
condition and simply use isSqlIntegration(integration) to gate the SQL path (the
branch that calls executeSqlIntegration). If integrationType is needed
elsewhere, keep its computation but drop it from the if condition so the SQL
branch reads only if (isSqlIntegration(integration)) return await
executeSqlIntegration(...).

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
services/platform/convex/workflow/actions/integration/integration_action.ts (1)

194-194: Prefer named export over default export.

As per coding guidelines, named exports are preferred. The named export integrationAction on Line 30 is already available.

🔎 Remove the default export
-export default integrationAction;
services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts (1)

57-63: Redundant null check — SqlIntegration guarantees sqlConnectionConfig presence.

The isSqlIntegration guard (called before this function is invoked) ensures sqlConnectionConfig is defined. The null check on Line 59 will never trigger for a properly narrowed SqlIntegration.

🔎 Remove redundant null check
   const { sqlConnectionConfig, sqlOperations } = integration;
-
-  if (!sqlConnectionConfig) {
-    throw new Error(
-      `SQL integration "${integration.name}" is missing sqlConnectionConfig`,
-    );
-  }

If you prefer defensive coding for future refactoring scenarios, keep it but consider adding a comment explaining why.

📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between f688585 and 8e36be2.

📒 Files selected for processing (5)
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: USE implicit typing whenever possible in TypeScript
DO NOT use type casting and avoid any and unknown types in TypeScript

Files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: ALWAYS put imports at the top and exports at the bottom, keeping them sorted correctly
PREFER named exports and AVOID default exports (only use if necessary)

Files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
**/{components,hooks,actions,utils}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place shared/reusable code in root-level /components, /hooks, /actions, /utils directories for use across multiple routes

Files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
**/convex/**/*.{ts,js}

📄 CodeRabbit inference engine (CLAUDE.md)

**/convex/**/*.{ts,js}: CONSIDER TO use rate limiting and action caching in Convex
DO NOT use .collect() in Convex; use for await (const ... of ...) instead

Files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
🧠 Learnings (41)
📓 Common learnings
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts:73-111
Timestamp: 2026-01-05T01:44:20.855Z
Learning: In Convex integration-related code (e.g., services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts, services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts), `as any` casts are necessary when accessing optional fields like `sqlOperations` and `connector` on `Doc<'integrations'>` because Convex's generated types don't capture these optional fields at the type level. This limitation is tracked in issue #79.
📚 Learning: 2026-01-05T01:44:20.855Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts:73-111
Timestamp: 2026-01-05T01:44:20.855Z
Learning: Guideline: In Convex integration-related TypeScript files (e.g., services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts and services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts), avoid relying on generated types for optional fields. If you must access optional fields like sqlOperations or connector on Doc<'integrations'> and the generated type doesn’t capture them, use an explicit as any cast to access those fields, and document this rationale (as referenced in issue #79). During reviews, flag such casts, verify they’re necessary due to known type limitations, and ensure alternative type-safe approaches aren’t feasible before accepting the cast.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-15T14:44:04.593Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:04.593Z
Learning: In Convex action files under services/platform/convex/workflow/actions/**, prefer maintaining a separate TypeScript type for the action parameters alongside the runtime validators (parametersValidator). The TypeScript type provides IDE support and compile-time checking, while the validator handles runtime validation. Document this design with a clear comment next to the type/validator pair explaining the rationale (e.g., separate types for static typing vs runtime checks, and how they relate). This pattern applies across all actions in this directory, not just a single file.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2026-01-05T01:37:40.813Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/lib/create_web_agent.ts:22-22
Timestamp: 2026-01-05T01:37:40.813Z
Learning: In agent factory files (services/platform/convex/lib/create_*_agent.ts), explicit `ToolName[]` type annotations for convexToolNames arrays are preferred over implicit typing for consistency across agent factories and clear type documentation.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-30T03:53:06.120Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/workflow_assistant_agent.ts:94-107
Timestamp: 2025-12-30T03:53:06.120Z
Learning: In services/platform/convex/workflow_assistant_agent.ts, using `any` type for step parameters during toonification (compact representation) is acceptable when step structures vary significantly by stepType (llm, condition, action, loop). The sanitization approach extracts only needed fields for context, and strict typing with complex discriminated unions would add maintenance burden without practical benefit since the data is only used for compact representation, not type-specific processing.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use the `internal` object from `convex/_generated/api.ts` to call internal functions registered with `internalQuery`, `internalMutation`, or `internalAction`

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Register internal functions with internalQuery, internalMutation, and internalAction (imported from ./_generated/server)

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Only call an action from another action if you need to cross runtimes (e.g., V8 to Node); otherwise, pull out shared code into a helper async function

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use the `api` object from `convex/_generated/api.ts` to call public functions registered with `query`, `mutation`, or `action`

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Try to use as few calls from actions to queries and mutations as possible to avoid race conditions, since queries and mutations are transactions

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Never use `ctx.db` inside of an action; actions don't have access to the database

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Add "use node" to the top of action files that use Node.js built-ins

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Register public functions with query, mutation, and action; do not use these for sensitive internal logic

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-07-03T08:43:49.346Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/next-best-practice.mdc:0-0
Timestamp: 2025-07-03T08:43:49.346Z
Learning: Applies to app/api/**/*.test.{ts,js} : Use integration tests for API routes

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-26T03:04:07.995Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/approvals.ts:51-62
Timestamp: 2025-12-26T03:04:07.995Z
Learning: In Convex approvals API (services/platform/convex/approvals.ts), continue the pattern of maintaining separate internalQuery functions for internal vs public API access (e.g., getApprovalInternal vs getApprovalById) even if implementations are identical. This separation preserves the ability to diverge access control patterns in the future without breaking call sites. Apply this guideline broadly to the Convex-related API files under services/platform/convex/, using the pattern services/platform/convex/**/*.ts to cover similar modules. Ensure new or refactored internal/public wrappers follow this convention and document intent where access rules may evolve.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-30T03:24:33.770Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/wf_step_defs.ts:33-39
Timestamp: 2025-12-30T03:24:33.770Z
Learning: In Convex API files under services/platform/convex (e.g., wf_step_defs.ts and peers) refrain from delegating trivial single-line database calls like ctx.db.get(id) to model helpers. Use direct calls for simple operations with no extra business logic. Reserve model helpers for complex tasks (ordering, filtering, validation, transformation). This guideline applies to all .ts files in this Convex API area.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-30T06:21:13.183Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/documents/validators.ts:89-102
Timestamp: 2025-12-30T06:21:13.183Z
Learning: Do not flag a missing trailing newline for TypeScript files in code reviews. POSIX text files should end with a trailing newline and Prettier (or your formatter) will enforce this. Treat the trailing newline as a non-issue in reviews for all TS files.

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Use Id helper type from ./_generated/dataModel to type document ids (e.g., Id<'users'>)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Be strict with types, particularly around IDs of documents; use `Id<'tableName'>` rather than `string` for function arguments and returns

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-15T14:44:09.823Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-08-21T15:03:10.828Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/supabase.mdc:0-0
Timestamp: 2025-08-21T15:03:10.828Z
Learning: Applies to supabase/types.ts : Do not edit `types.ts`; it is generated by the script

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/schema.ts : Import schema helpers (defineSchema, defineTable) from convex/server

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/schema.ts : Always define your schema in `convex/schema.ts` and import schema definition functions from `convex/server`

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `v.id(tableName)` validator for document IDs, and use strict TypeScript types with `Id<'tableName'>` instead of generic string types for function arguments and returns

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T12:29:39.745Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/workspace_rules.mdc:0-0
Timestamp: 2025-11-30T12:29:39.745Z
Learning: Applies to services/**/convex/*.ts : Thin wrapper API modules in services may export multiple Convex functions as thin wrappers that delegate to model helpers, must use snake_case file names and camelCase export names, and must not contain business logic

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use the documented Convex validators for all supported types (e.g., v.id, v.int64, v.number, v.boolean, v.string, v.bytes, v.array, v.object, v.record)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always include argument and return validators for all Convex functions (query, internalQuery, mutation, internalMutation, action, internalAction)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Ensure TypeScript Record key/value types match validators (e.g., Record<Id<'users'>, string>)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Always include argument and return validators for all Convex functions; if no return, set returns: v.null()

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/!(model)/*.ts : Exception: Thin wrapper API modules (e.g., `services/platform/convex/documents.ts`) may export multiple Convex functions if they only validate args/returns and delegate to the model layer; must use snake_case for file names and camelCase for function names

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-12-26T03:18:58.736Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/node_only/sql/helpers/execute_query.ts:25-40
Timestamp: 2025-12-26T03:18:58.736Z
Learning: In services/platform/convex/node_only/sql/helpers/execute_query.ts (and the SQL execution helper layer), errors from engine executors are intentionally allowed to propagate up with their full stack traces rather than being caught and converted to partial success results. The executeQuery function is designed as a thin routing layer, with error handling and observability managed at the caller level. This design prioritizes full error context over capturing metrics like duration on error paths.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-26T03:06:01.288Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/node_only/sql/helpers/execute_mysql_query.ts:0-0
Timestamp: 2025-12-26T03:06:01.288Z
Learning: In services/platform/convex/node_only/sql/helpers/execute_mysql_query.ts (and similar SQL query execution helpers), row limits are applied in JavaScript after fetching results rather than by injecting LIMIT clauses into SQL queries. This is a deliberate security trade-off to avoid SQL injection risks from modifying user queries. Predefined queries in SQL integrations can include their own LIMIT clauses directly.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `ctx.runQuery` to call a query from a query, mutation, or action; use `ctx.runMutation` to call a mutation from a mutation or action; use `ctx.runAction` to call an action from an action

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use ctx.runQuery to call queries, ctx.runMutation for mutations, and ctx.runAction for actions

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Do not access ctx.db inside actions (actions have no DB access)

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-07-03T08:43:49.346Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/next-best-practice.mdc:0-0
Timestamp: 2025-07-03T08:43:49.346Z
Learning: Applies to {actions/**/*.ts,actions/**/*.tsx,app/**/*.tsx} : Prioritize server actions for mutations and side effects (use `'use server'` and server action functions)

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-26T03:04:41.259Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/model/integrations/create_integration_logic.ts:81-84
Timestamp: 2025-12-26T03:04:41.259Z
Learning: For SQL integrations in the Tale project, connection validation is intentionally deferred to execution time rather than performed during integration creation. This design avoids potential timeout issues during the integration creation flow. Connection failures are handled gracefully at execution time with clear error messages.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-15T14:01:50.330Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/helpers/update_conversations.ts:7-10
Timestamp: 2025-12-15T14:01:50.330Z
Learning: In Convex action helper files under services/platform/convex/workflow/actions/**/helpers/*.ts, prefer using Record<string, unknown> for update parameter types since field validation is performed at the mutation layer. This allows dynamic update shapes while keeping validation centralized at mutation runtime.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2026-01-05T01:37:37.275Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/lib/create_integration_agent.ts:22-27
Timestamp: 2026-01-05T01:37:37.275Z
Learning: In agent factory files (e.g., services/platform/convex/lib/create_*_agent.ts), prefer explicit `ToolName[]` type annotations for tool name arrays over implicit typing (even with `as const satisfies ToolName[]`). The explicit annotation provides clear documentation, ensures type compatibility with `createAgentConfig`, maintains consistency across agent factories, and avoids requiring downstream consumers to handle narrower tuple types.

Applied to files:

  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-30T03:05:07.814Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/agent_tools/database/helpers/schema_definitions.ts:238-242
Timestamp: 2025-12-30T03:05:07.814Z
Learning: In any file under services/platform/convex/agent_tools (e.g., database/helpers/schema_definitions.ts) prefer runtime validation of identifiers like tableName coming from LLM/user input over relying on TypeScript type restrictions alone. Implement validation at call boundaries that returns descriptive, user-friendly errors (e.g., listing available options) instead of returning null or failing at compile time. This approach supports graceful error handling and better UX for misinput.

Applied to files:

  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-12-30T03:47:44.914Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/agent_tools/workflows/workflow_read_tool.ts:127-144
Timestamp: 2025-12-30T03:47:44.914Z
Learning: In AI agent tool APIs in services/platform/convex/agent_tools/workflows, using `any` type for return data that varies significantly based on runtime conditions (e.g., step structures in workflow_read_tool.ts that differ by stepType: LLM, code, condition, etc.) is acceptable when the caller (AI agent) treats the data as opaque for inspection. Strict typing with complex union types provides limited practical benefit in these cases.

Applied to files:

  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
🧬 Code graph analysis (4)
services/platform/convex/workflow/actions/integration/integration_action.ts (1)
services/platform/convex/model/integrations/types.ts (3)
  • Integration (84-84)
  • getIntegrationType (148-150)
  • isSqlIntegration (119-125)
services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts (1)
services/platform/convex/model/integrations/types.ts (2)
  • SqlIntegration (90-94)
  • SqlOperation (50-50)
services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts (1)
services/platform/convex/model/integrations/types.ts (5)
  • Integration (84-84)
  • getIntegrationType (148-150)
  • isSqlIntegration (119-125)
  • SqlIntegration (90-94)
  • SqlOperation (50-50)
services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts (2)
services/platform/convex/model/integrations/types.ts (3)
  • Integration (84-84)
  • getIntegrationType (148-150)
  • isSqlIntegration (119-125)
services/platform/convex/agent_tools/integrations/types.ts (1)
  • IntegrationIntrospectionResult (70-72)
⏰ 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). (1)
  • GitHub Check: Build Docker Image
🔇 Additional comments (15)
services/platform/convex/workflow/actions/integration/integration_action.ts (2)

20-24: Well-structured typed imports that eliminate any casts.

The new imports from ../../../model/integrations/types properly bring in the typed abstractions needed for safe integration handling. This directly addresses issue #79.


69-72: Type cast is acceptable here due to Convex runtime limitations.

The as Integration | null cast is necessary because ctx.runQuery returns an untyped result. This is an improvement over the previous Doc<'integrations'> usage since Integration is now the canonical public type for integrations across the codebase.

services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts (2)

91-126: Good use of type narrowing and destructuring for SQL integrations.

After the isSqlIntegration guard, the destructured sqlConnectionConfig and sqlOperations are properly typed. The simplified (op) => callback in Line 111 uses implicit typing per coding guidelines.


129-152: REST path improvements with predefined fallback.

The connector is now accessed via typed integration.connector instead of (integration as any).connector. The fallback to predefined integrations ensures backward compatibility. The return type assertion as IntegrationIntrospectionResult is acceptable given the union return type.

services/platform/convex/model/integrations/types.ts (3)

80-94: Well-documented typed integration interfaces.

The Integration type alias and the specialized SqlIntegration/RestApiIntegration interfaces provide the type-safe abstractions needed to replace any casts across the codebase. The JSDoc comments with examples are helpful.


119-125: Type guard correctly validates all required SQL fields.

The isSqlIntegration guard ensures both sqlConnectionConfig and sqlOperations are present, which prevents runtime errors when accessing these fields after narrowing.


148-150: Utility function provides safe default for legacy integrations.

The getIntegrationType function encapsulates the 'rest_api' default logic, ensuring consistent behavior across the codebase for integrations without an explicit type field.

services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts (5)

18-26: Imports properly updated to use public integration types.

The removal of direct Doc dependency and addition of typed abstractions (Integration, SqlIntegration, SqlOperation) aligns with the PR's goal of eliminating any casts. Based on learnings, this addresses the known type limitations tracked in issue #79.


114-122: Function signature correctly narrowed to SqlIntegration.

The executeSqlBatch function now accepts SqlIntegration, allowing direct destructuring of sqlConnectionConfig and sqlOperations without casts. This is a clean improvement.


157-157: Correct use of SqlOperation type for operation config.

Replacing the old SqlOperationConfig with the inferred SqlOperation type ensures consistency with the validators and removes duplicate type definitions.


322-324: REST batch function accepts base Integration type.

Using Integration here is appropriate since REST operations don't require the narrower SQL-specific fields. The function delegates to integrationAction.execute which handles further type routing.


98-103: Consistent with other files — same redundant guard observation applies.

For consistency, if you simplify the guard in integration_action.ts, apply the same simplification here.

⛔ Skipped due to learnings
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Only call an action from another action if crossing runtimes; otherwise factor shared logic into a helper
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Only call an action from another action if you need to cross runtimes (e.g., V8 to Node); otherwise, pull out shared code into a helper async function
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/agent_tools/convex_tools/workflows/update_workflow_step_tool.ts:20-21
Timestamp: 2025-12-15T14:43:53.478Z
Learning: In the tale-project/tale repository, when constants are duplicated between files (e.g., validStepTypes in update_workflow_step_tool.ts and validate_step_config.ts), the preference is to maintain self-contained file structure with sync comments documenting the relationship, rather than importing shared constants. This approach prioritizes clear, self-contained structure over strict DRY principles.
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-07-20T08:40:24.693Z
Learning: Applies to **/actions/*.ts : Never use custom wrappers that don't provide additional functionality
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Try to use as few calls from actions to queries and mutations as possible to avoid race conditions, since queries and mutations are transactions
Learnt from: larryro
Repo: talecorp/tale PR: 1299
File: features/platform/rest-contracts/src/contracts/platform/organization/organization-contract.ts:19-21
Timestamp: 2024-10-07T12:01:14.503Z
Learning: In TypeScript files like `organization-contract.ts`, avoid suggesting adding comments above the response schema when the code logic is very simple, as it may be unnecessary.
Learnt from: larryro
Repo: talecorp/tale PR: 1299
File: features/platform/rest-contracts/src/contracts/platform/organization/organization-contract.ts:19-21
Timestamp: 2024-10-08T16:22:15.228Z
Learning: In TypeScript files like `organization-contract.ts`, avoid suggesting adding comments above the response schema when the code logic is very simple, as it may be unnecessary.
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-08-21T14:59:56.034Z
Learning: Applies to {**/actions/*.ts,**/app/api/**/*.ts,**/lib/**/*.ts} : Avoid custom AI wrappers that do not add meaningful functionality beyond the Vercel AI SDK
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursorrules:0-0
Timestamp: 2025-10-11T11:46:02.452Z
Learning: Applies to **/*.{ts,tsx,js} : Maintain type safety throughout the codebase
services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts (3)

18-18: Clean import of typed abstractions.

Importing SqlIntegration and SqlOperation directly from the model types module is correct and aligns with the PR's type system improvements.


96-110: Clear error messaging with available operations.

The error message on Line 106-108 helpfully lists both user-defined and introspection operations, improving the developer/agent experience when an invalid operation is requested.


125-141: Typed access to integration properties in approval payload.

The approval mutation payload now uses typed property access (integration.organizationId, integration._id, integration.name) instead of (integration as any) casts. This is the core improvement this PR delivers.

Comment thread services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts Outdated
Comment thread services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts Outdated
Comment thread services/platform/convex/model/integrations/types.ts
…tions

Add typed interfaces and type guards to eliminate `any` casts when
accessing integration-specific fields like sqlConnectionConfig and
sqlOperations.

Changes:
- Add SqlIntegration and RestApiIntegration interfaces to types.ts
- Add isSqlIntegration() and isRestApiIntegration() type guards
- Add getIntegrationType() helper for backward-compatible type access
- Update execute_batch_integration_internal.ts to use type guards
- Update execute_sql_integration.ts to use SqlIntegration type
- Update integration_action.ts to use type guards
- Update integration_introspect_tool.ts to use type guards

This improves type safety and removes widespread `any` usage that was
identified during PR #76 code review.

Closes #79
@larryro larryro force-pushed the claude/add-typed-api-interfaces-eiFcQ branch from 8e36be2 to 0b86237 Compare January 6, 2026 14:48
larryro and others added 2 commits January 6, 2026 23:06
… files

Move type guards and utility functions out of types.ts to follow
single-responsibility principle. Types file now contains only type
definitions and constants.

- Create guards/ directory with is_sql_integration.ts and is_rest_api_integration.ts
- Create utils/ directory with get_integration_type.ts
- Update imports in dependent files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…sertions

- Add integrationDocValidator in validators.ts to provide typed returns
- Update getByNameInternal, getIntegrationInternal, and get queries to
  use the new validator instead of v.any()
- Add explicit handler return type in executeBatchIntegrationInternal
  to break TypeScript circular type inference
- Remove `as Integration` type assertions from integration tools

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@larryro
Copy link
Copy Markdown
Collaborator Author

larryro commented Jan 6, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 6, 2026

✅ Actions performed

Full review triggered.

Remove redundant integrationType === 'sql' check since isSqlIntegration
already verifies integration.type === 'sql' internally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts Outdated
Copy link
Copy Markdown

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
services/platform/convex/model/integrations/validators.ts (1)

123-123: Verify necessity of v.any() usage for dynamic schemas.

The coding guidelines recommend avoiding any, but parametersSchema (lines 123, 186) and metadata (line 240) use v.any() because these fields have inherently dynamic structures that vary by operation or user configuration.

Consider whether these fields could use more structured alternatives:

  • For parametersSchema: Could this use v.record(v.string(), v.union(...)) with common parameter types?
  • For metadata: Is this truly unstructured, or could it use v.record(v.string(), v.any()) for better type clarity?

If v.any() is truly necessary due to the dynamic nature, document the rationale with inline comments explaining why structured alternatives aren't feasible.

Also applies to: 186-186, 240-240

services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts (2)

110-143: Type narrowing successfully implemented with guards.

The integration loading and type checking now use proper type guards (getIntegrationType, isSqlIntegration) instead of type assertions. This provides runtime type safety and enables TypeScript to narrow the type correctly.

Line 137 performs both checks: integrationType === 'sql' && isSqlIntegration(integration). The type guard alone should be sufficient:

🔎 Consider simplifying the type check
-    const integrationType = getIntegrationType(integration);
-
-    // For SQL integrations, optimize by decrypting credentials once
-    if (integrationType === 'sql' && isSqlIntegration(integration)) {
+    // For SQL integrations, optimize by decrypting credentials once
+    if (isSqlIntegration(integration)) {

The isSqlIntegration guard already checks the type field internally, making the getIntegrationType call redundant unless the type string is used elsewhere.


358-366: REST API batch execution updated with typed interface.

The function now accepts the typed Integration interface instead of Doc<'integrations'>, eliminating the need for type assertions when accessing integration properties.

Consider using RestApiIntegration instead of the base Integration type for stricter type safety, similar to how executeSqlBatch uses SqlIntegration:

🔎 Optional: Use more specific RestApiIntegration type
 async function executeRestApiBatch(
   ctx: ActionCtx,
-  integration: Integration,
+  integration: RestApiIntegration,
   operations: Array<{ id?: string; operation: string; params?: Record<string, unknown> }>,
   organizationId: string,
   threadId: string | undefined,
   messageId: string | undefined,
   startTime: number,
 ) {

This would ensure REST API-specific fields are available if needed in the future.

🤖 Fix all issues with AI Agents
In
@services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts:
- Around line 84-88: The code redundantly checks integrationType === 'sql'
before calling the type guard isSqlIntegration; remove the redundant check and
simplify the branch to use only isSqlIntegration(integration) (i.e., change "if
(integrationType === 'sql' && isSqlIntegration(integration))" to "if
(isSqlIntegration(integration))"), and if getIntegrationType(integration) (the
integrationType variable) is no longer used elsewhere in this scope, remove that
call/variable as well; keep destructuring sqlConnectionConfig and sqlOperations
from integration inside the simplified branch.

In
@services/platform/convex/model/integrations/guards/is_rest_api_integration.ts:
- Around line 13-18: Update the isRestApiIntegration type guard to include a
brief inline comment explaining why type === undefined is accepted for backward
compatibility; specifically, add the note above or next to the return expression
in the isRestApiIntegration function so future maintainers know that legacy
integrations may lack a type but still safely expose connector, and reference
Integration and RestApiIntegration in the comment for clarity.

In @services/platform/convex/model/integrations/types.ts:
- Around line 100-103: The RestApiIntegration interface specifies type:
'rest_api' but the isRestApiIntegration type guard also treats type ===
undefined as valid for backward compatibility; add a concise comment explaining
this deliberate divergence so future readers know the guard accepts undefined to
support legacy/upgrade migration, and place that comment next to the
RestApiIntegration declaration and/or the isRestApiIntegration function name to
make intent explicit.

In @services/platform/convex/workflow/actions/integration/integration_action.ts:
- Around line 78-83: The guard redundantly checks integrationType === 'sql'
before calling isSqlIntegration; remove the explicit type comparison and rely
solely on isSqlIntegration(integration) to determine the SQL path, calling
executeSqlIntegration(...) when isSqlIntegration returns true. Also remove the
now-unused integrationType variable declaration
(getIntegrationType(integration)) if it isn’t used elsewhere in the function to
keep the code clean.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1aca12b and f118cae.

⛔ Files ignored due to path filters (1)
  • services/platform/convex/_generated/api.d.ts is excluded by !**/_generated/**
📒 Files selected for processing (10)
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: ALL pages should be optimized for accessibility (Level AA)
ALWAYS put imports at the top and exports at the bottom. Keep them sorted correctly
PREFER named exports. AVOID default exports (only if needed)

Files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: USE implicit typing whenever possible
DO NOT use type casting. Avoid any, and unknown whenever possible

Files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
🧠 Learnings (58)
📓 Common learnings
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts:73-111
Timestamp: 2026-01-05T01:44:20.855Z
Learning: In Convex integration-related code (e.g., services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts, services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts), `as any` casts are necessary when accessing optional fields like `sqlOperations` and `connector` on `Doc<'integrations'>` because Convex's generated types don't capture these optional fields at the type level. This limitation is tracked in issue #79.
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `v.id(tableName)` validator for document IDs, and use strict TypeScript types with `Id<'tableName'>` instead of generic string types for function arguments and returns
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use the documented Convex validators for all supported types (e.g., v.id, v.int64, v.number, v.boolean, v.string, v.bytes, v.array, v.object, v.record)
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always include argument and return validators for all Convex functions (query, internalQuery, mutation, internalMutation, action, internalAction)
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Be strict with types, particularly around IDs of documents; use `Id<'tableName'>` rather than `string` for function arguments and returns
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/approvals.ts:51-62
Timestamp: 2025-12-26T03:04:19.196Z
Learning: In Convex approvals API (services/platform/convex/approvals.ts), the codebase intentionally maintains separate internalQuery functions for internal vs public API access (e.g., getApprovalInternal vs getApprovalById) even when implementations are identical. This separation allows for future access control pattern divergence without breaking call sites.
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use the new Convex function syntax with `query`, `mutation`, `internalQuery`, `internalMutation`, `action`, or `internalAction` with explicit `args`, `returns`, and `handler` properties
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/model/integrations/create_integration_logic.ts:81-84
Timestamp: 2025-12-26T03:04:41.259Z
Learning: For SQL integrations in the Tale project, connection validation is intentionally deferred to execution time rather than performed during integration creation. This design avoids potential timeout issues during the integration creation flow. Connection failures are handled gracefully at execution time with clear error messages.
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/supabase.mdc:0-0
Timestamp: 2025-08-21T15:03:10.828Z
Learning: Applies to supabase/types.ts : Do not edit `types.ts`; it is generated by the script
📚 Learning: 2026-01-05T01:44:20.855Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts:73-111
Timestamp: 2026-01-05T01:44:20.855Z
Learning: Guideline: In Convex integration-related TypeScript files (e.g., services/platform/convex/agent_tools/sub_agents/helpers/format_integrations.ts and services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts), avoid relying on generated types for optional fields. If you must access optional fields like sqlOperations or connector on Doc<'integrations'> and the generated type doesn’t capture them, use an explicit as any cast to access those fields, and document this rationale (as referenced in issue #79). During reviews, flag such casts, verify they’re necessary due to known type limitations, and ensure alternative type-safe approaches aren’t feasible before accepting the cast.

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2026-01-05T01:37:40.813Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/lib/create_web_agent.ts:22-22
Timestamp: 2026-01-05T01:37:40.813Z
Learning: In agent factory files (services/platform/convex/lib/create_*_agent.ts), explicit `ToolName[]` type annotations for convexToolNames arrays are preferred over implicit typing for consistency across agent factories and clear type documentation.

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-07-03T08:43:49.346Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/next-best-practice.mdc:0-0
Timestamp: 2025-07-03T08:43:49.346Z
Learning: Applies to app/api/**/*.test.{ts,js} : Use integration tests for API routes

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-12-26T03:04:07.995Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/approvals.ts:51-62
Timestamp: 2025-12-26T03:04:07.995Z
Learning: In Convex approvals API (services/platform/convex/approvals.ts), continue the pattern of maintaining separate internalQuery functions for internal vs public API access (e.g., getApprovalInternal vs getApprovalById) even if implementations are identical. This separation preserves the ability to diverge access control patterns in the future without breaking call sites. Apply this guideline broadly to the Convex-related API files under services/platform/convex/, using the pattern services/platform/convex/**/*.ts to cover similar modules. Ensure new or refactored internal/public wrappers follow this convention and document intent where access rules may evolve.

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-30T03:24:33.770Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/wf_step_defs.ts:33-39
Timestamp: 2025-12-30T03:24:33.770Z
Learning: In Convex API files under services/platform/convex (e.g., wf_step_defs.ts and peers) refrain from delegating trivial single-line database calls like ctx.db.get(id) to model helpers. Use direct calls for simple operations with no extra business logic. Reserve model helpers for complex tasks (ordering, filtering, validation, transformation). This guideline applies to all .ts files in this Convex API area.

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-30T06:21:13.183Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/documents/validators.ts:89-102
Timestamp: 2025-12-30T06:21:13.183Z
Learning: Do not flag a missing trailing newline for TypeScript files in code reviews. POSIX text files should end with a trailing newline and Prettier (or your formatter) will enforce this. Treat the trailing newline as a non-issue in reviews for all TS files.

Applied to files:

  • services/platform/convex/model/integrations/utils/get_integration_type.ts
  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/guards/is_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-15T14:44:09.823Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:09.823Z
Learning: In Convex action files (services/platform/convex/workflow/actions/**/), maintaining a separate TypeScript type alongside the parametersValidator is an acceptable pattern when documented. The TypeScript type provides IDE support and compile-time checking, while the validator provides runtime validation. This intentional separation should be documented with a comment explaining the design choice.

Applied to files:

  • services/platform/convex/model/integrations/guards/is_rest_api_integration.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-26T03:18:58.736Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/node_only/sql/helpers/execute_query.ts:25-40
Timestamp: 2025-12-26T03:18:58.736Z
Learning: In services/platform/convex/node_only/sql/helpers/execute_query.ts (and the SQL execution helper layer), errors from engine executors are intentionally allowed to propagate up with their full stack traces rather than being caught and converted to partial success results. The executeQuery function is designed as a thin routing layer, with error handling and observability managed at the caller level. This design prioritizes full error context over capturing metrics like duration on error paths.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-12-26T03:06:01.288Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/node_only/sql/helpers/execute_mysql_query.ts:0-0
Timestamp: 2025-12-26T03:06:01.288Z
Learning: In services/platform/convex/node_only/sql/helpers/execute_mysql_query.ts (and similar SQL query execution helpers), row limits are applied in JavaScript after fetching results rather than by injecting LIMIT clauses into SQL queries. This is a deliberate security trade-off to avoid SQL injection risks from modifying user queries. Predefined queries in SQL integrations can include their own LIMIT clauses directly.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-30T03:05:13.035Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/agent_tools/database/helpers/schema_definitions.ts:238-242
Timestamp: 2025-12-30T03:05:13.035Z
Learning: For AI agent tool APIs in services/platform/convex/agent_tools that receive tableName or similar identifiers from runtime LLM/user input, prefer runtime validation with descriptive error messages over compile-time TypeScript type restrictions. The pattern of returning null and handling validation at the caller level with helpful error messages (listing available options) is the preferred approach for graceful error handling.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-07-19T15:29:09.401Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursorrules:0-0
Timestamp: 2025-07-19T15:29:09.401Z
Learning: Applies to **/*.{ts,tsx} : Always use typed database queries with Supabase.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-30T03:47:44.914Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/agent_tools/workflows/workflow_read_tool.ts:127-144
Timestamp: 2025-12-30T03:47:44.914Z
Learning: In AI agent tool APIs in services/platform/convex/agent_tools/workflows, using `any` type for return data that varies significantly based on runtime conditions (e.g., step structures in workflow_read_tool.ts that differ by stepType: LLM, code, condition, etc.) is acceptable when the caller (AI agent) treats the data as opaque for inspection. Strict typing with complex union types provides limited practical benefit in these cases.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-12-30T03:52:31.412Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/model/workflow_processing_records/query_building/types.ts:32-34
Timestamp: 2025-12-30T03:52:31.412Z
Learning: In Convex workflow processing query building (services/platform/convex/model/workflow_processing_records/query_building/types.ts), `FindUnprocessedResult` intentionally uses `unknown | null` for the document field rather than generics because: (1) the returned document shape varies by table at runtime (conversations, customers, products, etc.), (2) consumers must perform type narrowing regardless since the table is determined dynamically, and (3) adding generics would introduce complexity without practical type safety benefits since callers already know which table they queried.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Be strict with types, particularly around IDs of documents; use `Id<'tableName'>` rather than `string` for function arguments and returns

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2026-01-05T01:37:37.275Z
Learnt from: larryro
Repo: tale-project/tale PR: 76
File: services/platform/convex/lib/create_integration_agent.ts:22-27
Timestamp: 2026-01-05T01:37:37.275Z
Learning: In agent factory files (e.g., services/platform/convex/lib/create_*_agent.ts), prefer explicit `ToolName[]` type annotations for tool name arrays over implicit typing (even with `as const satisfies ToolName[]`). The explicit annotation provides clear documentation, ensures type compatibility with `createAgentConfig`, maintains consistency across agent factories, and avoids requiring downstream consumers to handle narrower tuple types.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : When using `ctx.runQuery`, `ctx.runMutation`, or `ctx.runAction` to call a function in the same file, specify a type annotation on the return value to work around TypeScript circularity limitations

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Never use `ctx.db` inside of an action; actions don't have access to the database

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Register internal functions with internalQuery, internalMutation, and internalAction (imported from ./_generated/server)

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `ctx.runQuery` to call a query from a query, mutation, or action; use `ctx.runMutation` to call a mutation from a mutation or action; use `ctx.runAction` to call an action from an action

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use the `internal` object from `convex/_generated/api.ts` to call internal functions registered with `internalQuery`, `internalMutation`, or `internalAction`

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/integrations.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use ctx.runQuery to call queries, ctx.runMutation for mutations, and ctx.runAction for actions

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Do not access ctx.db inside actions (actions have no DB access)

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Register public functions with query, mutation, and action; do not use these for sensitive internal logic

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Try to use as few calls from actions to queries and mutations as possible to avoid race conditions, since queries and mutations are transactions

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-07-03T08:43:49.346Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/next-best-practice.mdc:0-0
Timestamp: 2025-07-03T08:43:49.346Z
Learning: Applies to {actions/**/*.ts,actions/**/*.tsx,app/**/*.tsx} : Prioritize server actions for mutations and side effects (use `'use server'` and server action functions)

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use the `api` object from `convex/_generated/api.ts` to call public functions registered with `query`, `mutation`, or `action`

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-12-26T03:04:41.259Z
Learnt from: larryro
Repo: tale-project/tale PR: 35
File: services/platform/convex/model/integrations/create_integration_logic.ts:81-84
Timestamp: 2025-12-26T03:04:41.259Z
Learning: For SQL integrations in the Tale project, connection validation is intentionally deferred to execution time rather than performed during integration creation. This design avoids potential timeout issues during the integration creation flow. Connection failures are handled gracefully at execution time with clear error messages.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-15T14:01:50.330Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/helpers/update_conversations.ts:7-10
Timestamp: 2025-12-15T14:01:50.330Z
Learning: In Convex action helper files under services/platform/convex/workflow/actions/**/helpers/*.ts, prefer using Record<string, unknown> for update parameter types since field validation is performed at the mutation layer. This allows dynamic update shapes while keeping validation centralized at mutation runtime.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
📚 Learning: 2025-12-15T14:44:04.593Z
Learnt from: larryro
Repo: tale-project/tale PR: 18
File: services/platform/convex/workflow/actions/conversation/conversation_action.ts:47-98
Timestamp: 2025-12-15T14:44:04.593Z
Learning: In Convex action files under services/platform/convex/workflow/actions/**, prefer maintaining a separate TypeScript type for the action parameters alongside the runtime validators (parametersValidator). The TypeScript type provides IDE support and compile-time checking, while the validator handles runtime validation. Document this design with a clear comment next to the type/validator pair explaining the rationale (e.g., separate types for static typing vs runtime checks, and how they relate). This pattern applies across all actions in this directory, not just a single file.

Applied to files:

  • services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-12-30T03:05:07.814Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/agent_tools/database/helpers/schema_definitions.ts:238-242
Timestamp: 2025-12-30T03:05:07.814Z
Learning: In any file under services/platform/convex/agent_tools (e.g., database/helpers/schema_definitions.ts) prefer runtime validation of identifiers like tableName coming from LLM/user input over relying on TypeScript type restrictions alone. Implement validation at call boundaries that returns descriptive, user-friendly errors (e.g., listing available options) instead of returning null or failing at compile time. This approach supports graceful error handling and better UX for misinput.

Applied to files:

  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2024-10-12T10:20:33.353Z
Learnt from: yannickmonney
Repo: talecorp/tale PR: 1320
File: core/next/src/utils/next/metadata/generate-default-metadata.ts:3-3
Timestamp: 2024-10-12T10:20:33.353Z
Learning: In the TypeScript file `core/next/src/utils/next/metadata/generate-default-metadata.ts`, the import path `'tale/core/base/utils/utils/i18n/get-global-translate'` with the duplicated `'utils'` segment is intentional and correct. This is the proper import path for the `getGlobalTranslate` function and should not be flagged as a typo in future code reviews.

Applied to files:

  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-07-19T15:29:09.401Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursorrules:0-0
Timestamp: 2025-07-19T15:29:09.401Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use Vercel AI SDK only for AI integration; do not use direct OpenAI imports.

Applied to files:

  • services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts
📚 Learning: 2025-08-21T15:03:10.828Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/supabase.mdc:0-0
Timestamp: 2025-08-21T15:03:10.828Z
Learning: Applies to supabase/types.ts : Do not edit `types.ts`; it is generated by the script

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-08-21T14:59:56.034Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursor/rules/ai.mdc:0-0
Timestamp: 2025-08-21T14:59:56.034Z
Learning: Applies to {**/actions/*.ts,**/app/api/**/*.ts,**/lib/**/*.ts} : Avoid custom AI wrappers that do not add meaningful functionality beyond the Vercel AI SDK

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Only call an action from another action if you need to cross runtimes (e.g., V8 to Node); otherwise, pull out shared code into a helper async function

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Add "use node" to the top of action files that use Node.js built-ins

Applied to files:

  • services/platform/convex/workflow/actions/integration/integration_action.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Use Id helper type from ./_generated/dataModel to type document ids (e.g., Id<'users'>)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-07-20T08:40:41.255Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursor/rules/supabase.mdc:0-0
Timestamp: 2025-07-20T08:40:41.255Z
Learning: Applies to supabase/types.ts : `types.ts` was generated by the script. Never edit it manually

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use the helper TypeScript type `Id<'tableName'>` from `./_generated/dataModel` to get the type of the id for a given table

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/schema.ts : Import schema helpers (defineSchema, defineTable) from convex/server

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-07-19T15:29:09.401Z
Learnt from: CR
Repo: talecorp/poc PR: 0
File: .cursorrules:0-0
Timestamp: 2025-07-19T15:29:09.401Z
Learning: Applies to supabase/types.ts : Never edit `types.ts` manually; use `pnpm supabase:generate-types` to generate types.

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-08-21T14:59:36.874Z
Learnt from: CR
Repo: talecorp/lanserhof PR: 0
File: .cursorrules:0-0
Timestamp: 2025-08-21T14:59:36.874Z
Learning: Applies to supabase/types.ts : Never edit supabase/types.ts manually; generate types via pnpm supabase:generate-types

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-12-30T03:53:06.120Z
Learnt from: larryro
Repo: tale-project/tale PR: 36
File: services/platform/convex/workflow_assistant_agent.ts:94-107
Timestamp: 2025-12-30T03:53:06.120Z
Learning: In services/platform/convex/workflow_assistant_agent.ts, using `any` type for step parameters during toonification (compact representation) is acceptable when step structures vary significantly by stepType (llm, condition, action, loop). The sanitization approach extracts only needed fields for context, and strict typing with complex discriminated unions would add maintenance burden without practical benefit since the data is only used for compact representation, not type-specific processing.

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use the documented Convex validators for all supported types (e.g., v.id, v.int64, v.number, v.boolean, v.string, v.bytes, v.array, v.object, v.record)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always include argument and return validators for all Convex functions (query, internalQuery, mutation, internalMutation, action, internalAction)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
  • services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.ts : Ensure TypeScript Record key/value types match validators (e.g., Record<Id<'users'>, string>)

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Use `v.id(tableName)` validator for document IDs, and use strict TypeScript types with `Id<'tableName'>` instead of generic string types for function arguments and returns

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Always include argument and return validators for all Convex functions; if no return, set returns: v.null()

Applied to files:

  • services/platform/convex/model/integrations/types.ts
  • services/platform/convex/integrations.ts
  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/!(model)/*.ts : Exception: Thin wrapper API modules (e.g., `services/platform/convex/documents.ts`) may export multiple Convex functions if they only validate args/returns and delegate to the model layer; must use snake_case for file names and camelCase for function names

Applied to files:

  • services/platform/convex/model/integrations/types.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use the new Convex function syntax with `query`, `mutation`, `internalQuery`, `internalMutation`, `action`, or `internalAction` with explicit `args`, `returns`, and `handler` properties

Applied to files:

  • services/platform/convex/integrations.ts
📚 Learning: 2025-11-30T03:53:00.316Z
Learnt from: CR
Repo: tale-project/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-11-30T03:53:00.316Z
Learning: Applies to convex/**/*.ts : Always use `v.null()` validator when a function returns a null value, and include `returns: v.null()` even if the function doesn't explicitly return anything

Applied to files:

  • services/platform/convex/integrations.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: Applies to convex/**/*.{ts,js} : Use v.null() as the return validator when returning null

Applied to files:

  • services/platform/convex/integrations.ts
📚 Learning: 2025-12-30T13:28:34.559Z
Learnt from: larryro
Repo: tale-project/tale PR: 48
File: services/platform/convex/model/documents/validators.ts:104-107
Timestamp: 2025-12-30T13:28:34.559Z
Learning: In services/platform/convex/model/**/validators.ts, sortOrderValidator is intentionally duplicated across documents, members, vendors, and products to keep models independent. This duplication is acceptable for now; avoid consolidating into a shared validators module in future PR unless it shows clear maintenance benefits. If you centralize later, ensure API compatibility and update all references accordingly.

Applied to files:

  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-12-30T06:20:46.309Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:106-139
Timestamp: 2025-12-30T06:20:46.309Z
Learning: In services/platform/convex/model/conversations/validators.ts, conversationItemValidator and conversationWithMessagesValidator are intentionally kept as separate validators despite having identical structures. This separation serves different semantic purposes: conversationItemValidator is for list responses while conversationWithMessagesValidator is for single conversation detail views. The duplication allows future divergence when list views might need different fields than detail views for performance or feature reasons.

Applied to files:

  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-12-30T06:20:18.848Z
Learnt from: larryro
Repo: tale-project/tale PR: 37
File: services/platform/convex/model/conversations/validators.ts:31-39
Timestamp: 2025-12-30T06:20:18.848Z
Learning: In services/platform/convex/model/conversations/validators.ts, the messageValidator intentionally uses v.string() for the status field because message statuses are dynamic and come from different sources (email providers, internal state, etc.) and are not yet constrained to a fixed set of values.

Applied to files:

  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2026-01-01T09:48:06.791Z
Learnt from: larryro
Repo: tale-project/tale PR: 58
File: services/platform/convex/model/vendors/validators.ts:41-41
Timestamp: 2026-01-01T09:48:06.791Z
Learning: Use v.string() for organizationId fields in Convex schemas instead of v.id('organizations'), since organization identifiers come from the external Better Auth system and are external IDs, not Convex document IDs. This pattern should be applied consistently across all validators (documents, products, customers, vendors, integrations, etc.) and across all files with validators, not just this one.

Applied to files:

  • services/platform/convex/model/integrations/validators.ts
📚 Learning: 2025-10-03T11:34:20.628Z
Learnt from: CR
Repo: talecorp/poc2 PR: 0
File: .cursor/rules/convex_rules.mdc:0-0
Timestamp: 2025-10-03T11:34:20.628Z
Learning: System fields _id and _creationTime are auto-added to documents with validators v.id(tableName) and v.number()

Applied to files:

  • services/platform/convex/model/integrations/validators.ts
🧬 Code graph analysis (6)
services/platform/convex/model/integrations/utils/get_integration_type.ts (1)
services/platform/convex/model/integrations/types.ts (2)
  • Integration (84-84)
  • IntegrationType (32-32)
services/platform/convex/model/integrations/guards/is_rest_api_integration.ts (1)
services/platform/convex/model/integrations/types.ts (2)
  • Integration (84-84)
  • RestApiIntegration (100-103)
services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts (1)
services/platform/convex/model/integrations/types.ts (2)
  • SqlIntegration (90-94)
  • SqlOperation (50-50)
services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts (3)
services/platform/convex/model/integrations/utils/get_integration_type.ts (1)
  • getIntegrationType (7-9)
services/platform/convex/model/integrations/guards/is_sql_integration.ts (1)
  • isSqlIntegration (13-19)
services/platform/convex/agent_tools/integrations/types.ts (1)
  • IntegrationIntrospectionResult (70-72)
services/platform/convex/model/integrations/guards/is_sql_integration.ts (1)
services/platform/convex/model/integrations/types.ts (2)
  • Integration (84-84)
  • SqlIntegration (90-94)
services/platform/convex/workflow/actions/integration/integration_action.ts (2)
services/platform/convex/model/integrations/utils/get_integration_type.ts (1)
  • getIntegrationType (7-9)
services/platform/convex/model/integrations/guards/is_sql_integration.ts (1)
  • isSqlIntegration (13-19)
🔇 Additional comments (20)
services/platform/convex/model/integrations/utils/get_integration_type.ts (1)

1-9: Clean utility for backward-compatible type extraction.

This properly centralizes the legacy fallback logic that was previously scattered as (integration as any).type || 'rest_api'. The nullish coalescing operator correctly handles both undefined and null cases.

services/platform/convex/model/integrations/guards/is_sql_integration.ts (1)

13-19: Well-structured type guard with complete field validation.

The guard correctly validates all three discriminating properties of SqlIntegration: the type literal, sqlConnectionConfig, and sqlOperations. This ensures safe access to SQL-specific fields after narrowing.

services/platform/convex/model/integrations/types.ts (1)

75-104: Clean typed integration interfaces that address issue #79.

The Integration base type alias and the discriminated SqlIntegration/RestApiIntegration interfaces properly model the integration variants. This eliminates the need for as any casts when accessing optional fields like sqlConnectionConfig and sqlOperations.

services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts (3)

16-17: Clean import of new type utilities.

The imports align with the PR's typed integration model and replace previous as any casts.


107-113: Improved type inference eliminates explicit any annotation.

The sqlOperations array is now properly typed via the SqlIntegration narrowing, allowing the callback parameter to be inferred without explicit typing.


126-134: REST connector access without type cast.

Direct access to integration.connector is now safe since the base Integration type properly declares the optional field. The fallback to predefined integration is preserved for legacy support.

services/platform/convex/workflow/actions/integration/integration_action.ts (1)

20-21: Correct imports for typed integration handling.

services/platform/convex/integrations.ts (3)

36-36: Tightened return validator for type safety.

Replacing v.any() with integrationDocValidator ensures runtime validation matches the expected integration document shape. This aligns with Convex best practices for strict return validators.


63-63: Consistent return validator for internal query.


189-189: Consistent return validator for internal query.

services/platform/convex/model/integrations/validators.ts (2)

202-209: LGTM!

The sync stats validator correctly models optional numeric fields for tracking synchronization metrics.


222-222: The type field should remain optional. The schema explicitly documents this as "Default: rest_api for backward compatibility" to support existing integrations in the database that may not have this field populated. The isRestApiIntegration() guard appropriately handles undefined type by treating it as rest_api. Making this field required would break backward compatibility and require a database migration with no clear benefit, since the type narrowing guards already account for this optional state.

Likely an incorrect or invalid review comment.

services/platform/convex/workflow/actions/integration/helpers/execute_sql_integration.ts (4)

18-18: LGTM!

Proper use of type-only imports for the new typed integration interfaces.


38-46: Type safety improvements successfully implemented.

The function signature now uses SqlIntegration instead of Doc<'integrations'>, enabling type-safe access to SQL-specific fields throughout the function body. The Promise<unknown> return type is safer than the previous Promise<any>.

Note: A previous review suggested a typed union return (e.g., ExecuteSqlResult) for better downstream type safety. While this remains a valid enhancement, the current changes represent a significant improvement in eliminating type assertions.


57-68: Successfully eliminates type assertions with proper destructuring.

The destructuring of sqlConnectionConfig and sqlOperations from the typed SqlIntegration parameter cleanly replaces the previous (integration as any).sqlConnectionConfig pattern. The SqlOperation | undefined type for operationConfig provides appropriate type safety for the operation lookup.

This directly addresses issue #79 by leveraging the new typed interfaces instead of type casts.


99-103: LGTM! Type-safe property access throughout.

All property accesses now benefit from the typed interfaces: op.name (SqlOperation), integration.organizationId (SqlIntegration), eliminating the need for type assertions.

Also applies to: 129-129

services/platform/convex/agent_tools/integrations/execute_batch_integration_internal.ts (4)

18-22: LGTM! Comprehensive typed interface imports.

The imports properly bring in the new typed interfaces (Integration, SqlIntegration, SqlOperation) and type guards (getIntegrationType, isSqlIntegration) needed to eliminate type assertions throughout the file.


24-48: Validators correctly model batch execution results.

The new operationResultValidator and batchResultValidator properly validate the runtime shape of batch execution results. The use of v.optional for conditional fields (e.g., approvalId, rowCount) and the structured stats object provide good type safety.

Note: Line 29 uses v.any() for the data field, which is appropriate here since operation results have varying shapes depending on the integration type and operation.


63-74: LGTM! Follows Convex best practices for typed functions.

The BatchResult interface paired with batchResultValidator follows the established pattern of maintaining both TypeScript types (for compile-time checking) and runtime validators. The handler signature correctly returns Promise<BatchResult>, ensuring type safety at both compile time and runtime.

As per coding guidelines: Convex functions should include both argument and return validators.

Also applies to: 98-99


150-158: SQL batch execution properly typed throughout.

The executeSqlBatch function now accepts SqlIntegration instead of a generic document type, enabling type-safe access to sqlConnectionConfig and sqlOperations without casts. The operationConfig variable is correctly typed as SqlOperation | undefined, and all operations on the sqlOperations array are type-safe.

Also applies to: 193-193, 215-220

Comment thread services/platform/convex/agent_tools/integrations/integration_introspect_tool.ts Outdated
Comment thread services/platform/convex/model/integrations/types.ts
Comment thread services/platform/convex/workflow/actions/integration/integration_action.ts Outdated
Update RestApiIntegration interface to allow type: 'rest_api' | undefined
to match the isRestApiIntegration guard's backward compatibility handling
for legacy integrations created before the type field was added.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
larryro and others added 2 commits January 6, 2026 23:52
Remove redundant integrationType === 'sql' check since isSqlIntegration
already verifies integration.type === 'sql' internally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add inline comment explaining why type === undefined is accepted in
isRestApiIntegration guard for legacy integrations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@larryro larryro merged commit 22002c4 into main Jan 6, 2026
2 checks passed
@larryro larryro deleted the claude/add-typed-api-interfaces-eiFcQ branch January 6, 2026 16:08
yannickmonney pushed a commit that referenced this pull request Apr 8, 2026
…tions (#79) (#82)

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants