Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import { PYTHON_WORKBENCH_HELPER_SOURCE } from './python-helpers.generated'; |
| 2 | |
| 3 | export interface WorkbenchEnvOptions { |
| 4 | sessionId: string; |
| 5 | backendUrl: string; |
| 6 | apiKey: string; |
| 7 | } |
| 8 | |
| 9 | export interface PythonWorkbenchHelperSourceOptions { |
| 10 | invokeLlmModel?: string; |
| 11 | } |
| 12 | |
| 13 | function trimTrailingSlashes(value: string): string { |
| 14 | let end = value.length; |
| 15 | while (end > 0 && value.charCodeAt(end - 1) === 47) { |
| 16 | end -= 1; |
| 17 | } |
| 18 | return value.slice(0, end); |
| 19 | } |
| 20 | |
| 21 | export function experimental_createWorkbenchEnv(env: WorkbenchEnvOptions): Record<string, string> { |
| 22 | return { |
| 23 | BACKEND_URL: trimTrailingSlashes(env.backendUrl), |
| 24 | COMPOSIO_TOOLROUTER_SESSION_ID: env.sessionId, |
| 25 | // SECURITY: this is the developer's full *project* API key, placed in the |
| 26 | // sandbox env. Any code or tool output in the sandbox can read it and |
| 27 | // exfiltrate it, so treat the sandbox as your security boundary and rotate |
| 28 | // this key. The execute endpoint also accepts a session-scoped |
| 29 | // `x-session-access-key`; swapping to that (so the project key never enters |
| 30 | // the sandbox) is the planned follow-up. |
| 31 | COMPOSIO_API_KEY: env.apiKey, |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | export function experimental_createPythonWorkbenchHelperSource( |
| 36 | opts: PythonWorkbenchHelperSourceOptions = {} |
| 37 | ): string { |
| 38 | // Inject config by prepending an `_INTERNAL` prologue the helper reads from, |
| 39 | // rather than string-substituting a sentinel. The helper `.py` is authored as |
| 40 | // real, lintable/testable Python; the generated constant is verbatim. |
| 41 | // JSON.stringify-of-JSON.stringify yields a double-quoted string literal that |
| 42 | // is valid Python — JSON string escapes are a subset of Python's. |
| 43 | const config = { invoke_llm_model: opts.invokeLlmModel ?? 'openai/gpt-oss-120b' }; |
| 44 | const prologue = |
| 45 | `import json as _composio_internal_json\n` + |
| 46 | `_INTERNAL = _composio_internal_json.loads(${JSON.stringify(JSON.stringify(config))})\n`; |
| 47 | return prologue + PYTHON_WORKBENCH_HELPER_SOURCE; |
| 48 | } |