GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mothership): fix superagent credentials by Sg312 · Pull Request #4185 · simstudioai/sim

Conversation

@Sg312

@Sg312 Sg312 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix credential injection for superagent

Type of Change

  • Bug fix

Testing

Manual

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Sg312 added 3 commits April 15, 2026 12:02
@Sg312
Fix
3811957
@Sg312
Fix ajv csp issue
d882018
@Sg312
Lint
a88c726
@vercel

vercel Bot commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 15, 2026 7:48pm

Request Review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vercel
vercel Bot temporarily deployed to Preview April 15, 2026 19:47 Inactive
@Sg312
Sg312 merged commit f0285ad into staging Apr 15, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@greptile-apps

greptile-apps Bot commented Apr 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes credential injection for Copilot/Superagent tool execution via two changes: (1) createUserToolSchema now adds credentialId as a required field only when surface === 'copilot', so the LLM is explicitly told to provide it; and (2) new helpers in executeTool normalize credentialId → credential and throw a descriptive error if an OAuth tool is called without any credential selector. A second commit replaces the Ajv-based stream event validator (which required eval/new Function and violated CSP) with a hand-written structural validator in contract.ts.

Confidence Score: 5/5

Safe to merge — both findings are P2 style/consistency issues that do not affect runtime correctness.

The core credential-injection fix is logically sound: the schema correctly marks credentialId as required for copilot surface, normalization copies it to the canonical credential field, and enforceCopilotCredentialSelection provides a fast-fail safety net. The Ajv→structural-validator swap is well-tested with full event-type coverage. The two P2 findings (required: false in VFS docs; missing scope guard on normalizeCopilotCredentialParams) are minor inconsistencies with no impact on the happy path.

apps/sim/lib/copilot/vfs/serializers.ts (credentialId still says required: false) and apps/sim/tools/index.ts (normalizeCopilotCredentialParams lacks scope guard).

Important Files Changed

Filename Overview
apps/sim/tools/index.ts Adds three new helpers for copilot credential injection: readExplicitCredentialSelector, normalizeCopilotCredentialParams (copies credentialId→credential), and enforceCopilotCredentialSelection (throws for copilot OAuth tools missing a credential). normalizeCopilotCredentialParams lacks the scope guard present on the sibling normalizeCopilotFileParams.
apps/sim/tools/params.ts Adds surface option to createUserToolSchema; credentialId is now only injected into the schema (and marked required) for surface === 'copilot', which is the correct fix.
apps/sim/lib/copilot/vfs/serializers.ts Updates credentialId description to "pass this explicitly", but leaves required: false, inconsistent with the new runtime enforcement and the params.ts copilot schema.
apps/sim/lib/copilot/request/session/contract.ts Replaces Ajv runtime schema compilation (which uses eval/new Function, violating CSP) with a hand-written structural validator; intentionally lightweight per comment, well-covered by new tests.
apps/sim/lib/copilot/request/session/contract.test.ts New tests covering all known event types (text, session, tool, span, resource, run, error, complete, synthetic file preview) plus rejection of invalid/unknown events and invalid JSON.
apps/sim/tools/index.test.ts Adds Copilot OAuth Credential Enforcement test suite verifying the fast-fail path when copilot executes an OAuth tool without an explicit credential selector.
apps/sim/tools/params.test.ts Adds tests asserting credentialId is absent in default-surface schemas and present (and required) only for copilot-surface OAuth tool schemas.
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Switches stream event parsing to use the new CSP-safe parsePersistedStreamEventEnvelope / parsePersistedStreamEventEnvelopeJson from the rewritten contract module; no logic changes to the chat hook itself.

Sequence Diagram

sequenceDiagram
    participant LLM as Copilot / Superagent LLM
    participant Schema as createUserToolSchema surface=copilot
    participant Exec as executeTool
    participant Norm as normalizeCopilotCredentialParams
    participant Enforce as enforceCopilotCredentialSelection
    participant Token as OAuth Token API

    LLM->>Schema: request tool definitions
    Schema-->>LLM: schema with credentialId required

    LLM->>Exec: tool call with credentialId and params
    Exec->>Norm: normalize params unconditional
    Norm-->>Exec: params.credential set from credentialId
    Exec->>Enforce: check copilotToolExecution and oauth.required
    alt no credential selector found
        Enforce-->>Exec: throw Error must pass credentialId
        Exec-->>LLM: success false with error message
    else credential found
        Enforce-->>Exec: ok
        Exec->>Token: fetch access token for credential
        Token-->>Exec: accessToken
        Exec-->>LLM: success true with output
    end
Loading

Comments Outside Diff (1)

  1. apps/sim/lib/copilot/vfs/serializers.ts, line 750-757 (link)

    P2 credentialId still marked required: false in VFS documentation

    serializeIntegrationSchema is what the Copilot agent reads from the virtual filesystem to understand the tool API. With required: false here, the agent may conclude it can omit credentialId — even though createUserToolSchema (copilot surface) now places it in the JSON Schema required array and enforceCopilotCredentialSelection throws at runtime if it's missing. Consider updating to required: true to align the documentation with the enforcement.

Reviews (1): Last reviewed commit: "Lint" | Re-trigger Greptile

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

greptile-apps[bot]
greptile-apps Bot reviewed Apr 15, 2026
View reviewed changes
Comment thread apps/sim/tools/index.ts
Comment on lines +178 to +183
function normalizeCopilotCredentialParams(params: Record<string, unknown>): void {
const credentialId = typeof params.credentialId === 'string' ? params.credentialId.trim() : ''
if (credentialId && !params.credential && !params.oauthCredential) {
params.credential = credentialId
}
}

@greptile-apps greptile-apps Bot Apr 15, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

P2 Missing scope guard, inconsistent with sibling function

normalizeCopilotFileParams guards with if (!scope.copilotToolExecution) return before doing anything. normalizeCopilotCredentialParams has no such guard and runs unconditionally for every tool execution. In practice this is a no-op for non-copilot paths (since credentialId won't be in contextParams), but the inconsistency is a readability and maintenance hazard.

Suggested change
function normalizeCopilotCredentialParams(params: Record<string, unknown>): void {
const credentialId = typeof params.credentialId === 'string' ? params.credentialId.trim() : ''
if (credentialId && !params.credential && !params.oauthCredential) {
params.credential = credentialId
}
}
function normalizeCopilotCredentialParams(params: Record<string, unknown>, scope: ToolExecutionScope): void {
if (!scope.copilotToolExecution) {
return
}
const credentialId = typeof params.credentialId === 'string' ? params.credentialId.trim() : ''
if (credentialId && !params.credential && !params.oauthCredential) {
params.credential = credentialId
}
}

And update the call site to pass scope as a second argument.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@icecrasher321 icecrasher321 mentioned this pull request Apr 15, 2026
v0.6.45: superagent, csp, brightdata integration, gemini response format, logs performance improvements #4187
Merged
Sg312 added a commit that referenced this pull request Apr 15, 2026
@Sg312
v0.6.45: superagent, csp, brightdata integration, gemini response for…
010435c
…mat, logs performance improvements

fix(csp): add missing analytics domains, remove unsafe-eval, fix workspace CSP gap (#4179)
fix(landing): return 404 for invalid dynamic route slugs (#4182)
improvement(seo): optimize sitemaps, robots.txt, and core web vitals across sim and docs (#4170)
fix(gemini): support structured output with tools on Gemini 3 models (#4184)
feat(brightdata): add Bright Data integration with 8 tools (#4183)
fix(mothership): fix superagent credentials (#4185)
fix(logs): close sidebar when selected log disappears from filtered list; cleanup (#4186)
@waleedlatif1
waleedlatif1 deleted the fix/superagent-credentials branch April 16, 2026 20:05

This branch was previously deployed

1 inactive deployment
Preview — a88c7268 Deployed Apr 15, 2026 by vercel[bot]
View deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Sg312
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.