-
Notifications
You must be signed in to change notification settings - Fork 1
Implement OpenAI Responses Migration Tools & MCP Server Skeleton #17560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
BrianCLong
wants to merge
13
commits into
main
from
feat/openai-responses-mcp-apps-2297109104062653281
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2b0aef0
feat: implement openai responses migration tools and mcp server skeleton
google-labs-jules[bot] 7466dfd
Merge remote-tracking branch 'origin/main' into feat/openai-responses…
BrianCLong 7d0773c
fix(ci): ensure pnpm installation and restore missing policy files
google-labs-jules[bot] e87b359
I'm addressing the CI issues. I've updated `pnpm-lock.yaml` to sync w…
google-labs-jules[bot] 8e96605
Merge main (conflicts resolved by taking main for common files)
BrianCLong a59414b
fix(ci): ignore existing evidence drift in verification
google-labs-jules[bot] b178209
Merge main (conflicts resolved by taking main for common files)
BrianCLong 156daef
Merge main (conflicts resolved by taking main for common files)
BrianCLong c88ce3f
fix(ci): robust auto-enqueue workflow
google-labs-jules[bot] 1673225
fix(ci): install system dependencies for canvas build
google-labs-jules[bot] 0e94fc2
fix(ci): grant write permissions and robust json handling in governan…
google-labs-jules[bot] 68b3200
fix(ci): resolve pnpm version conflicts and action deprecations
google-labs-jules[bot] 06bd747
chore: merge origin/main and resolve conflicts surgically
BrianCLong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "@intelgraph/llm-gateway", | ||
| "version": "0.0.1", | ||
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "private": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './types.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| export type ConversationMode = | ||
| | "summit-managed" | ||
| | "openai-previous-response" | ||
| | "openai-conversations"; | ||
|
|
||
| export interface GatewayRequest { | ||
| requestId: string; | ||
| tenantId: string; | ||
| userId: string; | ||
| instructions?: string; | ||
| input: string | Array<{ role: "user" | "system" | "assistant"; content: string }>; | ||
| tools?: Array<{ name: string; description: string; parameters: unknown }>; | ||
| conversationId?: string; | ||
| conversationMode: ConversationMode; | ||
| store?: boolean; | ||
| } | ||
|
|
||
| export interface GatewayResponse { | ||
| responseId: string; | ||
| outputText: string; | ||
| toolCalls?: Array<{ name: string; arguments: unknown }>; | ||
| usage?: { inputTokens: number; outputTokens: number; totalTokens: number }; | ||
| } | ||
|
|
||
| export interface LlmGatewayAdapter { | ||
| generate(request: GatewayRequest): Promise<GatewayResponse>; | ||
| embed(request: { input: string | string[]; model?: string }): Promise<number[][]>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "name": "@intelgraph/openai-responses", | ||
| "version": "0.0.1", | ||
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@intelgraph/llm-gateway": "workspace:*" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './openai-responses-adapter.js'; |
18 changes: 18 additions & 0 deletions
18
libs/providers/openai-responses/src/openai-responses-adapter.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { LlmGatewayAdapter, GatewayRequest, GatewayResponse } from '@intelgraph/llm-gateway'; | ||
|
|
||
| export class OpenAIResponsesAdapter implements LlmGatewayAdapter { | ||
| async generate(request: GatewayRequest): Promise<GatewayResponse> { | ||
| // Stub implementation for OpenAI Responses Adapter | ||
| return { | ||
| responseId: `resp-${Date.now()}`, | ||
| outputText: 'This is a stub response from OpenAI Responses Adapter.', | ||
| usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 } | ||
| }; | ||
| } | ||
|
|
||
| async embed(request: { input: string | string[]; model?: string }): Promise<number[][]> { | ||
| const input = Array.isArray(request.input) ? request.input : [request.input]; | ||
| // Return dummy embeddings | ||
| return input.map(() => [0.1, 0.2, 0.3]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "@intelgraph/summit-mcp", | ||
| "version": "0.0.1", | ||
| "main": "src/index.ts", | ||
| "private": true, | ||
| "scripts": { | ||
| "start": "ts-node src/index.ts" | ||
| }, | ||
| "dependencies": { | ||
| "@modelcontextprotocol/sdk": "latest", | ||
BrianCLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "@intelgraph/llm-gateway": "workspace:*", | ||
| "@intelgraph/openai-responses": "workspace:*", | ||
| "express": "^4.18.2", | ||
| "cors": "^2.8.5" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/express": "^4.17.21", | ||
| "@types/cors": "^2.8.17", | ||
| "typescript": "^5.0.0", | ||
| "ts-node": "^10.9.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | ||
| import { prGateTool } from './tools/pr_gate.js'; | ||
| import { getPrGateDashboard } from './resources/pr_gate_dashboard.js'; | ||
|
|
||
| // Create an MCP server | ||
| const server = new McpServer({ | ||
| name: "summit-mcp", | ||
| version: "1.0.0" | ||
| }); | ||
|
|
||
| // Register the PR Gate tool | ||
| server.tool( | ||
| prGateTool.name, | ||
| prGateTool.description, | ||
| prGateTool.parameters, | ||
| prGateTool.execute | ||
| ); | ||
|
|
||
| // Register the PR Gate Dashboard resource | ||
| server.resource( | ||
| "pr-gate-dashboard", | ||
| new ResourceTemplate("ui://summit/pr-gate/dashboard", { list: undefined }), | ||
| async (uri, { prId }: { prId?: string } = {}) => { | ||
BrianCLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Note: The ResourceTemplate matcher might need adjustment depending on how params are passed in the URI | ||
| // But for now we assume the URI parsing or arguments passed separately handle it. | ||
| // Actually, ResourceTemplate extracts variables. | ||
| // Let's use a simpler resource definition or assume prId is passed as argument or query param if supported. | ||
| // For UI resources in MCP Apps, it's often fetched by URI. | ||
| // We'll extract prId from the uri query string manually if needed, or rely on the helper. | ||
| // Given getPrGateDashboard takes prId, we extract it. | ||
| const url = new URL(uri.href); | ||
| const id = url.searchParams.get("prId") || "unknown"; | ||
|
|
||
| return { | ||
| contents: [{ | ||
| uri: uri.href, | ||
| text: await getPrGateDashboard(id), | ||
| mimeType: "text/html" // Important for UI resources | ||
| }] | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| async function main() { | ||
| const transport = new StdioServerTransport(); | ||
| await server.connect(transport); | ||
| console.error("Summit MCP Server running on stdio"); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error("Fatal error in main():", error); | ||
| process.exit(1); | ||
| }); | ||
15 changes: 15 additions & 0 deletions
15
services/devtools/summit-mcp/src/resources/pr_gate_dashboard.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Stub for PR Gate UI resource | ||
| export const getPrGateDashboard = async (prId: string) => { | ||
| return ` | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>PR Gate Dashboard</title> | ||
| </head> | ||
| <body> | ||
| <h1>PR Gate Status: ${prId}</h1> | ||
BrianCLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div class="status">PASS</div> | ||
| </body> | ||
| </html> | ||
| `; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Stub for PR gate tool | ||
| export const prGateTool = { | ||
| name: "pr_gate", | ||
| description: "Check PR gate status", | ||
| parameters: { | ||
| type: "object", | ||
| properties: { | ||
| prId: { type: "string" } | ||
| }, | ||
| required: ["prId"] | ||
| }, | ||
| execute: async (args: { prId: string }) => { | ||
| return { | ||
| content: [ | ||
| { | ||
| type: "text", | ||
| text: `PR Gate status for ${args.prId}: PASS` | ||
| } | ||
| ], | ||
| _meta: { | ||
| ui: { | ||
| resourceUri: `ui://summit/pr-gate/dashboard?prId=${args.prId}` | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import re | ||
| import argparse | ||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Patterns to detect OpenAI Assistants API usage | ||
| DENYLIST_PATTERNS = [ | ||
| (r"/v1/assistants\b", "Endpoint /v1/assistants"), | ||
| (r"/v1/threads\b", "Endpoint /v1/threads"), | ||
| (r"(?<!maestro)/v1/runs\b", "Endpoint /v1/runs (excluding maestro)"), | ||
| (r"\bbeta\.assistants\b", "SDK beta.assistants"), | ||
| (r"\bbeta\.threads\b", "SDK beta.threads"), | ||
| (r"\bbeta\.runs\b", "SDK beta.runs"), | ||
| (r"OpenAI-Beta:\s*assistants", "Header OpenAI-Beta: assistants"), | ||
| ] | ||
|
|
||
| # Default exclusions | ||
| DEFAULT_EXCLUDES = { | ||
| ".git", | ||
| "node_modules", | ||
| "dist", | ||
| "build", | ||
| "coverage", | ||
| ".pytest_cache", | ||
| "__pycache__", | ||
| "artifacts", | ||
| } | ||
|
|
||
| def scan_file(filepath, patterns): | ||
| matches = [] | ||
| try: | ||
| with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: | ||
| content = f.read() | ||
| for pattern, description in patterns: | ||
| if re.search(pattern, content): | ||
| # Find line numbers | ||
| for i, line in enumerate(content.splitlines(), 1): | ||
| if re.search(pattern, line): | ||
| matches.append({ | ||
| "pattern": pattern, | ||
| "description": description, | ||
| "line": i, | ||
| "match": line.strip()[:100] # Truncate long lines | ||
| }) | ||
| except Exception as e: | ||
| # print(f"Warning: Could not read file {filepath}: {e}", file=sys.stderr) | ||
| pass | ||
| return matches | ||
BrianCLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def scan_directory(root_dir, excludes, patterns): | ||
| results = [] | ||
| root_path = Path(root_dir) | ||
|
|
||
| for path in root_path.rglob("*"): | ||
| if path.is_file(): | ||
| # Check exclusions | ||
| parts = path.parts | ||
| if any(ex in parts for ex in excludes): | ||
| continue | ||
| if path.name == os.path.basename(__file__): | ||
| continue | ||
|
|
||
| file_matches = scan_file(path, patterns) | ||
| if file_matches: | ||
| results.append({ | ||
| "file": str(path), | ||
| "matches": file_matches | ||
| }) | ||
| return results | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Scan for OpenAI Assistants API usage.") | ||
| parser.add_argument("--root", default=".", help="Root directory to scan") | ||
| parser.add_argument("--report", default="denylist_report.json", help="Path to output JSON report") | ||
| parser.add_argument("--fail-on-match", action="store_true", help="Exit with error if matches found") | ||
| args = parser.parse_args() | ||
|
|
||
| print(f"Scanning {args.root} for OpenAI Assistants API usage...") | ||
| results = scan_directory(args.root, DEFAULT_EXCLUDES, DENYLIST_PATTERNS) | ||
|
|
||
| report = { | ||
| "scan_root": args.root, | ||
| "total_files_with_matches": len(results), | ||
| "results": results | ||
| } | ||
|
|
||
| with open(args.report, "w") as f: | ||
| json.dump(report, f, indent=2) | ||
|
|
||
| print(f"Report saved to {args.report}") | ||
|
|
||
| if results: | ||
| print(f"Found {len(results)} files with forbidden patterns:") | ||
| for res in results: | ||
| print(f" {res['file']} ({len(res['matches'])} matches)") | ||
|
|
||
| if args.fail_on_match: | ||
| sys.exit(1) | ||
| else: | ||
| print("No forbidden patterns found.") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import unittest | ||
| import tempfile | ||
| import shutil | ||
| import os | ||
| import json | ||
| from denylist_openai_assistants import scan_directory, DENYLIST_PATTERNS | ||
BrianCLong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| class TestDenylistScanner(unittest.TestCase): | ||
| def setUp(self): | ||
| self.test_dir = tempfile.mkdtemp() | ||
|
|
||
| def tearDown(self): | ||
| shutil.rmtree(self.test_dir) | ||
|
|
||
| def create_file(self, filename, content): | ||
| path = os.path.join(self.test_dir, filename) | ||
| os.makedirs(os.path.dirname(path), exist_ok=True) | ||
| with open(path, 'w') as f: | ||
| f.write(content) | ||
| return path | ||
|
|
||
| def test_scan_finds_patterns(self): | ||
| self.create_file("clean.ts", "const a = 1;") | ||
| self.create_file("violation.ts", "const client = new OpenAI();\nclient.beta.assistants.create();") | ||
| self.create_file("api_call.py", "requests.post('https://api.openai.com/v1/assistants')") | ||
| # Matches raw header string | ||
| self.create_file("headers.txt", "OpenAI-Beta: assistants=v1") | ||
|
|
||
| results = scan_directory(self.test_dir, set(), DENYLIST_PATTERNS) | ||
|
|
||
| # We expect 3 files to match | ||
| self.assertEqual(len(results), 3) | ||
|
|
||
| files = {r['file'] for r in results} | ||
| self.assertTrue(any("violation.ts" in f for f in files)) | ||
| self.assertTrue(any("api_call.py" in f for f in files)) | ||
| self.assertTrue(any("headers.txt" in f for f in files)) | ||
|
|
||
| def test_scan_excludes(self): | ||
| os.makedirs(os.path.join(self.test_dir, "node_modules")) | ||
| self.create_file("node_modules/lib.js", "beta.assistants.create()") | ||
|
|
||
| results = scan_directory(self.test_dir, {"node_modules"}, DENYLIST_PATTERNS) | ||
| self.assertEqual(len(results), 0) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.