@ancha-labs/cli 0.4.40 → 0.4.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ancha.mjs +1170 -584
- package/lib/assets/SKILL.md +4 -1
- package/lib/assets/agents-section.md +4 -1
- package/lib/assets/data/pellmont/pellmont-approved-merge.yaml +75 -0
- package/lib/assets/data/pellmont/pellmont-building-services.yaml +1704 -0
- package/lib/assets/data/pellmont/pellmont-duplicates.yaml +21 -0
- package/lib/assets/docs/cloud.md +26 -9
- package/lib/assets/docs/run.md +1 -1
- package/lib/assets/docs/setup.md +4 -1
- package/lib/assets/harbor/companion.mjs +209 -18
- package/lib/assets/ui/app.js +8 -6
- package/lib/mcp-entry.mjs +1 -1
- package/lib/worker.mjs +354 -84
- package/lib/world-server.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Pellmont Building Services (QuickBooks, 2025): find the duplicates and double entries; read-only.
|
|
2
|
+
# Passes when the answer names the three vendors recorded under two names (Halvorsen & Diaz Electrical, Northpoint
|
|
3
|
+
# Fleet Fuel, Ostrander Janitorial Supply), the invoices entered twice (1116 and 1141, 1129 and 1142), the bills
|
|
4
|
+
# recorded twice (NFF-25-10, HD-3317) and the money at stake, 20,519.37, and every vendor, customer, item, invoice
|
|
5
|
+
# and bill stays unchanged.
|
|
6
|
+
version: 2
|
|
7
|
+
id: pellmont-duplicates
|
|
8
|
+
title: "Pellmont: report the duplicate vendors, the invoices and bills entered twice and the money at stake; change nothing"
|
|
9
|
+
world: pellmont-building-services
|
|
10
|
+
timeout: 10m
|
|
11
|
+
start:
|
|
12
|
+
task: "For Pellmont Building Services, pull vendors, customers, items, bills and invoices for 2025. Find vendors that are the same company under different names and invoices entered twice, and size the money at stake: the extra copy of each invoice entered twice, plus the extra copy of each vendor bill recorded twice under two names for the same vendor. Report the vendor pairs, the invoice numbers and bill numbers involved, and the total. The operator has not approved any change yet: do not modify any QuickBooks record."
|
|
13
|
+
checks:
|
|
14
|
+
- id: findings_reported
|
|
15
|
+
answer:
|
|
16
|
+
contains: ["Halvorsen", "Northpoint", "Ostrander", "1116", "1141", "1129", "1142", "NFF-25-10", "HD-3317"]
|
|
17
|
+
numbers: [ { value: "20,519.37" } ]
|
|
18
|
+
- id: books_unchanged
|
|
19
|
+
state:
|
|
20
|
+
quickbooks.unchanged:
|
|
21
|
+
types: [ Vendor, Customer, Item, Invoice, Bill ]
|
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -20,6 +20,9 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
|
|
|
20
20
|
```
|
|
21
21
|
- To name the command yourself: `ancha init --agent "<the command that starts your agent>"`.
|
|
22
22
|
- To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.
|
|
23
|
+
- **Composio agents.** Init detects Python `composio` / `composio_client` and TypeScript `@composio/core`, and finds tools from explicit toolkit lists and tool slugs. It writes each available Composio route under `agent.routes` and adds `COMPOSIO_API_KEY` to `agent.pass_env`, preserving existing settings. The world of each test decides which routed tools answer there.
|
|
24
|
+
- When init asks which tools the agent reaches through Composio, ask the user which tools they use. Set `agent.routes.<tool>: composio` for each routed tool (for example, `agent.routes.quickbooks: composio`) and add `COMPOSIO_API_KEY` to `agent.pass_env` in `ancha.yaml`. Configure the Composio client to read `COMPOSIO_BASE_URL` from the attempt environment.
|
|
25
|
+
- For a routed agent with no tests or traces, init writes a starter test that reads from each routed tool, plus the QuickBooks examples when the agent uses QuickBooks. Routed tests run in the cloud: with `COMPOSIO_API_KEY` in your shell, the steps below store it, upload the agent and run the tests.
|
|
23
26
|
3. **Point the agent at Ancha's tools.** In a test, the agent calls Ancha instead of production:
|
|
24
27
|
- Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.
|
|
25
28
|
- Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.
|
|
@@ -32,7 +35,7 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
|
|
|
32
35
|
ancha agent upload
|
|
33
36
|
```
|
|
34
37
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
35
|
-
6. **Without production traces.** For an agent that
|
|
38
|
+
6. **Without production traces.** For an agent that calls NetSuite directly, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows. For an agent that uses QuickBooks, it writes Pellmont Building Services' 2025 books and two tests: `pellmont-duplicates` reports the duplicate vendors, the invoices and bills entered twice and the money at stake without changing the books, and `pellmont-approved-merge` merges the three duplicate vendor pairs as approved and changes nothing else.
|
|
36
39
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
37
40
|
- Your evals: `ancha test import <file>` (JSONL, JSON, CSV or YAML with a question and an expected answer) writes tests for the only world in `ancha/worlds/`, or the one `--world <id>` names; with none, `ancha init --on local --template starter` adds one.
|
|
38
41
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
|
@@ -74,12 +77,24 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
|
|
|
74
77
|
|
|
75
78
|
## Upload the agent
|
|
76
79
|
|
|
77
|
-
`ancha agent upload` (also `ancha doctor --on cloud`) checks the agent where its tests run, before any test exists. A fresh machine installs the project's dependencies and starts the agent once with a task, through the same launcher and variables as an attempt. An agent that uses NetSuite has 90 seconds to find one customer in NetSuite and reply with its name; any other agent has 20 seconds, and exiting 0 or showing any work in that time makes it ready. The result says what happened in one sentence: the NetSuite calls it made and the answer it gave, or what stopped it (credentials NetSuite refused, a NetSuite host outside Ancha, a model key its provider refused, an answer missing where your tests read it, no output at all) with the change that fixes it. One that exits with an error shows its exit code, the end of its log and, when the log names where it looks for its task, the `ancha.yaml` line that gives it there. An agent served over HTTP (`agent.url`) starts and answers its ready check. That marks the agent uploaded in the workspace's first steps, and the command prints the link to the upload.
|
|
80
|
+
`ancha agent upload` (also `ancha doctor --on cloud`) checks the agent where its tests run, before any test exists. A fresh machine installs the project's dependencies and starts the agent once with a task, through the same launcher and variables as an attempt. An agent that uses NetSuite has 90 seconds to find one customer in NetSuite and reply with its name; any other agent has 20 seconds, and exiting 0 or showing any work in that time makes it ready. The result says what happened in one sentence: the NetSuite calls it made and the answer it gave, or what stopped it (credentials NetSuite refused, a NetSuite host outside Ancha, a model key its provider refused, an answer missing where your tests read it, no output at all) with the change that fixes it. One that exits with an error shows its exit code, the end of its log and, when the log names where it looks for its task, the `ancha.yaml` line that gives it there. With `agent.routes`, the task asks for a read through the agent’s own Composio client for each routed tool. The result reports executions reaching the world, their direct/session/MCP path, and any refused call with its reason and fix. A client that calls Composio’s own API host is directed to read its API URL from `COMPOSIO_BASE_URL`. An agent served over HTTP (`agent.url`) starts and answers its ready check. That marks the agent uploaded in the workspace's first steps, and the command prints the link to the upload.
|
|
78
81
|
|
|
79
82
|
The task's world includes tools found in your agent and the `twins` in the tests matched by your project's `scenes` globs, up to six tools with the agent's tools first. The result lists each tool and its call count. A tool with no calls gets a warning. If the check gave the agent no tools, name them with `ancha init --tools <tools>` or your tests' `twins`.
|
|
80
83
|
|
|
81
84
|
The install follows the project's own files, Node and Python alike: a Node lockfile installs exactly what it locks, with its package manager, and a `package.json` without one runs `npm install`; `uv.lock` and `pyproject.toml` run `uv sync`, and `requirements.txt` installs with pip into `.venv`. `agent.install` in `ancha.yaml` sets the command instead, for example `agent: { install: "npm ci && npm run build" }`. The machine has Node 24 and Python 3.12 with their package managers. The install runs as its own user with public internet; the agent then runs as another, and its network reaches only its tools and its model providers.
|
|
82
85
|
|
|
86
|
+
|
|
87
|
+
If a JSON-reading agent fails while parsing the check’s plain-text task, the upload result explains the parse failure. When source inspection identifies the input and task field, it gives the `ancha.yaml` mapping for that input: stdin, an argument, a file or an environment variable. For an agent that reads `json.loads(os.environ["AGENT_TASK"])["task"]`, set:
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
agent:
|
|
91
|
+
command: python agent.py
|
|
92
|
+
env:
|
|
93
|
+
AGENT_TASK: '{"task": {{task_json}}}'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`{{task_json}}` encodes the task as a JSON string, including quotes and newlines. The CLI, `ancha agent upload --json` and the console’s Get started upload result show the same explanation and mapping. Apply the mapping, then run `ancha agent upload` again.
|
|
97
|
+
|
|
83
98
|
## Run tests in the cloud
|
|
84
99
|
|
|
85
100
|
```sh
|
|
@@ -146,12 +161,13 @@ Run in the agent's project, `ancha secrets set` also names each one under `agent
|
|
|
146
161
|
|
|
147
162
|
## Tools reached through Composio
|
|
148
163
|
|
|
149
|
-
An agent that runs QuickBooks tools through Composio keeps
|
|
164
|
+
An agent that runs QuickBooks or NetSuite tools through Composio keeps its client code in cloud runs. QuickBooks calls go through Composio's servers to the world's QuickBooks. `NETSUITE_RUN_SUITEQL_QUERY` through `session.execute` or `tools.execute` runs against the world's NetSuite through the attempt's gateway.
|
|
150
165
|
|
|
151
166
|
```yaml
|
|
152
167
|
agent:
|
|
153
168
|
routes:
|
|
154
169
|
quickbooks: composio
|
|
170
|
+
netsuite: composio
|
|
155
171
|
pass_env: [COMPOSIO_API_KEY]
|
|
156
172
|
```
|
|
157
173
|
|
|
@@ -161,14 +177,15 @@ ancha secrets set COMPOSIO_API_KEY
|
|
|
161
177
|
ancha run --on cloud
|
|
162
178
|
```
|
|
163
179
|
|
|
164
|
-
- Each test's world
|
|
165
|
-
- The agent keeps its Composio code. Each attempt sets `COMPOSIO_BASE_URL` to Composio's API through the attempt's gateway (the Composio SDKs read it; a client built with an explicit base URL takes this value) and `COMPOSIO_API_KEY` to a key for this attempt; the gateway sends the project's key to Composio. `QUICKBOOKS_PUBLIC_URL` is this world's QuickBooks at an address Composio reaches for this attempt only; `QUICKBOOKS_ACCESS_TOKEN` and `QUICKBOOKS_REALM_ID` are the world's, as in any test with QuickBooks.
|
|
166
|
-
-
|
|
167
|
-
- Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
168
|
-
-
|
|
180
|
+
- Declare either route or both. Each test's world decides which routed tools it answers. QuickBooks-only and NetSuite-only tests can use the same agent configuration. A call to a declared tool that the world lacks returns `403 COMPOSIO_ROUTE_REFUSED` with reason `NO_WORLD` and a fix to add the tool to the world or run the call in a test whose world has it. The agent gets that answer and the attempt is graded as usual, as it is when a SuiteQL call's arguments are invalid.
|
|
181
|
+
- The agent keeps its Composio code. Each attempt sets `COMPOSIO_BASE_URL` to Composio's API through the attempt's gateway (the Composio SDKs read it; a client built with an explicit base URL takes this value) and `COMPOSIO_API_KEY` to a key for this attempt; the gateway sends the project's key to Composio for QuickBooks calls. `QUICKBOOKS_PUBLIC_URL` is this world's QuickBooks at an address Composio reaches for this attempt only; `QUICKBOOKS_ACCESS_TOKEN` and `QUICKBOOKS_REALM_ID` are the world's, as in any test with QuickBooks.
|
|
182
|
+
- QuickBooks direct executions (`tools.execute`) reach the world whatever user ID or connected account the agent names: the gateway supplies the world's address and credentials on each call. An agent that already passes `custom_auth_params` keeps them: `base_url` is `QUICKBOOKS_PUBLIC_URL` with the world's `Authorization` and `x-quickbooks-realm-id` headers.
|
|
183
|
+
- When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
184
|
+
- NetSuite calls use `NETSUITE_RUN_SUITEQL_QUERY`, its SuiteQL query in `q` and optional paging arguments, through `session.execute` or `tools.execute`. The gateway supplies the world's NetSuite credentials and returns the SuiteQL REST body in the Composio response. When QuickBooks is inactive in the test, sessions are created, read and deleted in the gateway; when both routes are active, the gateway handles NetSuite reads and Composio handles QuickBooks.
|
|
185
|
+
- Before an agent with an active QuickBooks route starts, the attempt checks that `QUICKBOOKS_PUBLIC_URL` answers from outside.
|
|
169
186
|
- The gateway keeps every call on the world: a call that names another toolkit's tools, changes a session's connection, proxies a request or reaches another attempt's session gets `403 COMPOSIO_ROUTE_REFUSED` with a `reason`, and the attempt is invalid with `ROUTE_REFUSED`, so every result rests on calls inside the world.
|
|
170
187
|
- Composio's calls reach the world like the agent's own: the world's trace and the checks see them. An execution with no request reaching the world makes the attempt invalid with `ROUTE_NOT_REACHED`.
|
|
171
|
-
- The summary counts the route under `routes.quickbooks`: executions by path (`via.direct`, `via.session`, `via.mcp`), how many reached the world, refusals, sessions, and
|
|
188
|
+
- The summary counts the route under `routes.quickbooks` and `routes.netsuite`: executions by path (`via.direct`, `via.session`, `via.mcp`), how many reached the world, refusals, sessions, and lifecycle evidence (`connection`, `cleanup`) for each route. An inactive route appears when it records a refused call.
|
|
172
189
|
|
|
173
190
|
## CI
|
|
174
191
|
|
package/lib/assets/docs/run.md
CHANGED
|
@@ -12,7 +12,7 @@ When `CI=true` or `CI=1` (case-insensitive), a verdict using simulated tool answ
|
|
|
12
12
|
|
|
13
13
|
New run summaries use `verdictVersion: 3`. Each test (an entry of `scenes`) has `counts.requested`, `completed`, `valid`, `passed`, `invalid` and `skipped`. The pass-rate denominator is the requested count, including invalid, skipped and unfinished trials. “Pass all k” requires all k requested trials to complete validly and pass. A test with no check evaluated is ungraded (`graded: false`); the run's verdict is `ungraded` when any test is ungraded and none failed. HTML and the console show invalid attempts separately. Older reports stay readable; comparison with an old baseline lacking these counts exits 2 and asks you to rerun the reference and save a fresh baseline.
|
|
14
14
|
|
|
15
|
-
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK` and `ANCHA_TASK_FILE` (a file holding the task), `ANCHA_ATTEMPT_ID`, `ANCHA_STATE_DIR` (keep memory there, so trials stay independent), `ANCHA_EVENTS_URL`, `ANCHA_EVENTS_TOKEN` and `ANCHA_DONE_URL` for agents that receive events or finish explicitly, and `ANCHA_AGENT_PORT` for HTTP agents. No SDK is installed and no paid AI call is made for you. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: "{{task}}" }` (`{{task_file}}` for the file's path); `ancha init` writes that line when it finds the name in the agent's code or usage text.
|
|
15
|
+
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK` and `ANCHA_TASK_FILE` (a file holding the task), `ANCHA_ATTEMPT_ID`, `ANCHA_STATE_DIR` (keep memory there, so trials stay independent), `ANCHA_EVENTS_URL`, `ANCHA_EVENTS_TOKEN` and `ANCHA_DONE_URL` for agents that receive events or finish explicitly, and `ANCHA_AGENT_PORT` for HTTP agents. No SDK is installed and no paid AI call is made for you. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: "{{task}}" }` (`{{task_file}}` for the file's path, `{{task_json}}` for the task encoded as a JSON string); `ancha init` writes that line when it finds the name in the agent's code or usage text.
|
|
16
16
|
|
|
17
17
|
Map your agent's tool settings with `agent.env`: `{{<tool>.url}}`, `{{<tool>.host_url}}` and `{{<tool>.token}}` use that tool's connection. Jira also offers `{{jira.email}}` (the login email, also `{{jira.access_key}}`) and `{{jira.access_key_secret}}` (the API token). For example, `env: { JIRA_USERNAME: "{{jira.email}}", JIRA_INSTANCE_URL: "{{jira.url}}"` gives an agent its own names for Jira's email and URL; `JIRA_API_TOKEN` is supplied automatically. An unknown template produces `CONFIG_INVALID` with the available template names before a run or upload check starts the agent.
|
|
18
18
|
|
package/lib/assets/docs/setup.md
CHANGED
|
@@ -18,6 +18,9 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
18
18
|
```
|
|
19
19
|
- To name the command yourself: `ancha init --agent "<the command that starts your agent>"`.
|
|
20
20
|
- To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.
|
|
21
|
+
- **Composio agents.** Init detects Python `composio` / `composio_client` and TypeScript `@composio/core`, and finds tools from explicit toolkit lists and tool slugs. It writes each available Composio route under `agent.routes` and adds `COMPOSIO_API_KEY` to `agent.pass_env`, preserving existing settings. The world of each test decides which routed tools answer there.
|
|
22
|
+
- When init asks which tools the agent reaches through Composio, ask the user which tools they use. Set `agent.routes.<tool>: composio` for each routed tool (for example, `agent.routes.quickbooks: composio`) and add `COMPOSIO_API_KEY` to `agent.pass_env` in `ancha.yaml`. Configure the Composio client to read `COMPOSIO_BASE_URL` from the attempt environment.
|
|
23
|
+
- For a routed agent with no tests or traces, init writes a starter test that reads from each routed tool, plus the QuickBooks examples when the agent uses QuickBooks. Routed tests run in the cloud: with `COMPOSIO_API_KEY` in your shell, the steps below store it, upload the agent and run the tests.
|
|
21
24
|
3. **Point the agent at Ancha's tools.** In a test, the agent calls Ancha instead of production:
|
|
22
25
|
- Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.
|
|
23
26
|
- Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.
|
|
@@ -30,7 +33,7 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
30
33
|
ancha agent upload
|
|
31
34
|
```
|
|
32
35
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
33
|
-
6. **Without production traces.** For an agent that
|
|
36
|
+
6. **Without production traces.** For an agent that calls NetSuite directly, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows. For an agent that uses QuickBooks, it writes Pellmont Building Services' 2025 books and two tests: `pellmont-duplicates` reports the duplicate vendors, the invoices and bills entered twice and the money at stake without changing the books, and `pellmont-approved-merge` merges the three duplicate vendor pairs as approved and changes nothing else.
|
|
34
37
|
- Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.
|
|
35
38
|
- Your evals: `ancha test import <file>` (JSONL, JSON, CSV or YAML with a question and an expected answer) writes tests for the only world in `ancha/worlds/`, or the one `--world <id>` names; with none, `ancha init --on local --template starter` adds one.
|
|
36
39
|
- One test from a sentence: `ancha test new "<sentence>" --world <id>`.
|
|
@@ -76215,7 +76215,7 @@ function toErrorJson(e) {
|
|
|
76215
76215
|
}
|
|
76216
76216
|
|
|
76217
76217
|
// packages/core/src/agent-routes.ts
|
|
76218
|
-
var agentRoutesSchema = external_exports.strictObject({ quickbooks: external_exports.literal("composio").optional() });
|
|
76218
|
+
var agentRoutesSchema = external_exports.strictObject({ quickbooks: external_exports.literal("composio").optional(), netsuite: external_exports.literal("composio").optional() });
|
|
76219
76219
|
|
|
76220
76220
|
// packages/core/src/execution-support.ts
|
|
76221
76221
|
var all = { local: true, container: true, managed: true, "cloud-vm": true };
|
|
@@ -76697,6 +76697,16 @@ var SimClock = class {
|
|
|
76697
76697
|
|
|
76698
76698
|
// packages/core/src/ids.ts
|
|
76699
76699
|
import { createHash } from "node:crypto";
|
|
76700
|
+
function memoryCounters() {
|
|
76701
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
76702
|
+
return {
|
|
76703
|
+
next(namespace) {
|
|
76704
|
+
const n2 = counts2.get(namespace) ?? 0;
|
|
76705
|
+
counts2.set(namespace, n2 + 1);
|
|
76706
|
+
return n2;
|
|
76707
|
+
}
|
|
76708
|
+
};
|
|
76709
|
+
}
|
|
76700
76710
|
var ALNUM_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
76701
76711
|
var ID_ENCODING_VERSION = 1;
|
|
76702
76712
|
function validateLength(len) {
|
|
@@ -186917,18 +186927,30 @@ function createAttemptConnectionManifest(env, options4 = {}) {
|
|
|
186917
186927
|
|
|
186918
186928
|
// backend/src/execution/composio.ts
|
|
186919
186929
|
import { timingSafeEqual as timingSafeEqual11 } from "node:crypto";
|
|
186930
|
+
function noWorldMessage(toolkit) {
|
|
186931
|
+
const name5 = toolkit === "quickbooks" ? "QuickBooks" : "NetSuite";
|
|
186932
|
+
return `This test's world has no ${name5}. Add ${name5} to the test's world or run this call in a test whose world has it.`;
|
|
186933
|
+
}
|
|
186920
186934
|
var RouteRefusal = class extends Error {
|
|
186921
186935
|
reason;
|
|
186922
|
-
|
|
186923
|
-
|
|
186936
|
+
toolkit;
|
|
186937
|
+
constructor(reason2, toolkit) {
|
|
186938
|
+
super(reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
|
|
186924
186939
|
this.reason = reason2;
|
|
186940
|
+
this.toolkit = toolkit;
|
|
186925
186941
|
}
|
|
186926
186942
|
};
|
|
186943
|
+
var activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
|
|
186944
|
+
function requireWorld(name5, route15) {
|
|
186945
|
+
const toolkit = name5.startsWith("QUICKBOOKS_") ? "quickbooks" : name5.startsWith("NETSUITE_") ? "netsuite" : void 0;
|
|
186946
|
+
if (toolkit && (route15.toolkits ?? { quickbooks: "composio" })[toolkit] && !activeComposioToolkits(route15)[toolkit]) throw new RouteRefusal("NO_WORLD", toolkit);
|
|
186947
|
+
}
|
|
186927
186948
|
var refuse = (reason2) => {
|
|
186928
186949
|
throw new RouteRefusal(reason2);
|
|
186929
186950
|
};
|
|
186930
|
-
var
|
|
186931
|
-
var
|
|
186951
|
+
var NETSUITE_FIX = "Use session.execute or tools.execute with NETSUITE_RUN_SUITEQL_QUERY.";
|
|
186952
|
+
var slug10 = "(?:QUICKBOOKS|NETSUITE)_[A-Z0-9_]{1,96}";
|
|
186953
|
+
var quickbooks = new RegExp("^QUICKBOOKS_[A-Z0-9_]{1,96}$");
|
|
186932
186954
|
var execution = new RegExp(`^/api/v3(?:\\.1)?/tools/execute/(${slug10})$`);
|
|
186933
186955
|
var catalogTool = new RegExp(`^/api/v3(?:\\.1)?/tools/(${slug10}|COMPOSIO_MULTI_EXECUTE_TOOL|COMPOSIO_SEARCH_TOOLS|COMPOSIO_GET_TOOL_SCHEMAS)$`);
|
|
186934
186956
|
var identifier4 = /^[a-zA-Z0-9_-]{1,256}$/;
|
|
@@ -186978,12 +187000,16 @@ function jsonBody3(body7, contentType) {
|
|
|
186978
187000
|
return refuse("JSON");
|
|
186979
187001
|
}
|
|
186980
187002
|
}
|
|
186981
|
-
function toolArguments(name5, value5 = {}, metaOnly = false) {
|
|
187003
|
+
function toolArguments(route15, name5, value5 = {}, metaOnly = false) {
|
|
187004
|
+
requireWorld(name5, route15);
|
|
187005
|
+
if (name5.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
|
|
186982
187006
|
if (!meta5.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
|
|
186983
187007
|
const { account: _account, ...args } = value5;
|
|
186984
187008
|
if (name5 === multi) {
|
|
186985
187009
|
const items = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record10.optional() }).passthrough()).min(1), args.tools);
|
|
187010
|
+
for (const item2 of items) requireWorld(item2.tool_slug, route15);
|
|
186986
187011
|
args.tools = items.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
|
|
187012
|
+
if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
|
|
186987
187013
|
if (!quickbooks.test(item2.tool_slug)) refuse(item2.tool_slug.startsWith("COMPOSIO_") ? "META_TOOL" : "TOOL");
|
|
186988
187014
|
return item2;
|
|
186989
187015
|
});
|
|
@@ -187009,18 +187035,32 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187009
187035
|
if (typeof apiKey !== "string" || !route15.agentKey || Buffer.byteLength(apiKey) !== Buffer.byteLength(route15.agentKey) || !timingSafeEqual11(Buffer.from(apiKey), Buffer.from(route15.agentKey))) refuse("API_KEY");
|
|
187010
187036
|
if (!target5.startsWith("/") || target5.length > 8192 || target5.includes("#") || /[%\\\x00-\x20\x7f#]/.test(target5.split("?")[0]) || target5.includes("//") || target5.split("?")[0].split("/").some((part) => part === "." || part === "..")) refuse("PATH");
|
|
187011
187037
|
const url4 = new URL(target5, "https://backend.composio.dev");
|
|
187012
|
-
const
|
|
187038
|
+
const qb = !!activeComposioToolkits(route15).quickbooks;
|
|
187039
|
+
const base6 = { toolkit: qb ? "quickbooks" : "netsuite", op: "catalog", via: composioVia(target5), target: target5 };
|
|
187013
187040
|
const noQuery = () => {
|
|
187014
187041
|
if (url4.search) refuse("QUERY");
|
|
187015
187042
|
};
|
|
187016
187043
|
const empty2 = () => {
|
|
187017
187044
|
if (body7.length) refuse("SCHEMA");
|
|
187018
187045
|
};
|
|
187046
|
+
if (/^\/api\/v3(?:\.1)?\/tools\/execute\/COMPOSIO_MULTI_EXECUTE_TOOL$/.test(url4.pathname)) {
|
|
187047
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
187048
|
+
noQuery();
|
|
187049
|
+
const value5 = parsed3(bodySchema, jsonBody3(body7, contentType));
|
|
187050
|
+
toolArguments(route15, multi, value5.arguments);
|
|
187051
|
+
refuse("META_TOOL");
|
|
187052
|
+
}
|
|
187019
187053
|
const match3 = execution.exec(url4.pathname);
|
|
187020
187054
|
if (match3) {
|
|
187021
187055
|
if (method2 !== "POST") refuse("METHOD");
|
|
187022
187056
|
noQuery();
|
|
187023
187057
|
const value5 = parsed3(bodySchema, jsonBody3(body7, contentType));
|
|
187058
|
+
requireWorld(match3[1], route15);
|
|
187059
|
+
if (match3[1].startsWith("NETSUITE_")) {
|
|
187060
|
+
if (!route15.netsuite || match3[1] !== "NETSUITE_RUN_SUITEQL_QUERY") refuse("NETSUITE_TOOL");
|
|
187061
|
+
return { ...base6, toolkit: "netsuite", op: "execute", local: "netsuite", slug: match3[1], arguments: value5.arguments ?? {} };
|
|
187062
|
+
}
|
|
187063
|
+
if (!qb) refuse("TOOL");
|
|
187024
187064
|
const { connected_account_id: _id, custom_connection_data: _data, entity_id: _entity, custom_auth_params: _auth, ...kept } = value5;
|
|
187025
187065
|
return { ...base6, op: "execute", slug: match3[1], body: bytes2({ ...kept, user_id: route15.user, custom_auth_params: {
|
|
187026
187066
|
base_url: route15.publicUrl,
|
|
@@ -187038,11 +187078,13 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187038
187078
|
if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
|
|
187039
187079
|
if (value5.method === "tools/call") {
|
|
187040
187080
|
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
|
|
187041
|
-
const call2 = toolArguments(params10.name, params10.arguments);
|
|
187081
|
+
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
187082
|
+
if (!qb) refuse("SESSION_ENDPOINT");
|
|
187042
187083
|
const { account: _account, ...kept } = params10;
|
|
187043
187084
|
value5.params = { ...kept, arguments: call2.arguments };
|
|
187044
187085
|
return { ...base6, op: call2.op, slug: params10.name, headers: forwarded, body: bytes2(value5) };
|
|
187045
187086
|
}
|
|
187087
|
+
if (!qb) refuse("SESSION_ENDPOINT");
|
|
187046
187088
|
return { ...base6, headers: forwarded, body: bytes2(value5) };
|
|
187047
187089
|
}
|
|
187048
187090
|
const session2 = /^\/api\/v3(?:\.1)?\/tool_router\/session(?:\/([^/]+)(.*))?$/.exec(url4.pathname);
|
|
@@ -187053,13 +187095,14 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187053
187095
|
noQuery();
|
|
187054
187096
|
const value6 = parsed3(sessionSchema, jsonBody3(body7, contentType));
|
|
187055
187097
|
const narrowed = /* @__PURE__ */ new Set();
|
|
187098
|
+
const declared = route15.toolkits ?? { quickbooks: "composio" };
|
|
187056
187099
|
const note2 = (name6) => {
|
|
187057
|
-
if (name6.toLowerCase()
|
|
187100
|
+
if (!(name6.toLowerCase() === "quickbooks" && declared.quickbooks) && !(name6.toLowerCase() === "netsuite" && declared.netsuite)) narrowed.add(name6);
|
|
187058
187101
|
};
|
|
187059
187102
|
const toolkitApprovals = slugList.safeParse(value6.toolkits?.require_approval);
|
|
187060
187103
|
for (const name6 of [...Object.keys(value6.auth_configs ?? {}), ...Object.keys(value6.connected_accounts ?? {}), ...Object.keys(value6.tools ?? {}), ...value6.toolkits?.enable ?? [], ...toolkitApprovals.success ? toolkitApprovals.data : []]) note2(name6);
|
|
187061
187104
|
const keepSlugs = (slugs2) => slugs2.filter((name6) => {
|
|
187062
|
-
if (quickbooks.test(name6)) return true;
|
|
187105
|
+
if (qb && quickbooks.test(name6)) return true;
|
|
187063
187106
|
const toolkit2 = /^([A-Z0-9]+)_/.exec(name6)?.[1]?.toLowerCase();
|
|
187064
187107
|
if (toolkit2) note2(toolkit2);
|
|
187065
187108
|
return false;
|
|
@@ -187081,6 +187124,7 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187081
187124
|
const preload = listed.success ? { tools: listed.data.tools === "all" ? "all" : keepSlugs(listed.data.tools) } : void 0;
|
|
187082
187125
|
const search10 = switchOf(value6.search, "enable"), multiExecute = switchOf(value6.execute, "enable_multi_execute");
|
|
187083
187126
|
const approveToolkit = toolkitApprovals.success && toolkitApprovals.data.some((name6) => name6.toLowerCase() === "quickbooks");
|
|
187127
|
+
if (!qb) return { ...base6, local: "session", response: "session-create", narrowed: [...narrowed] };
|
|
187084
187128
|
return { ...base6, connection: "session", response: "session-create", narrowed: [...narrowed], body: bytes2({
|
|
187085
187129
|
user_id: route15.user,
|
|
187086
187130
|
toolkits: { enable: ["quickbooks"], ...approveToolkit && { require_approval: ["quickbooks"] } },
|
|
@@ -187098,12 +187142,13 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187098
187142
|
if (!identifier4.test(sid) || !route15.sessions.has(sid)) refuse("SESSION");
|
|
187099
187143
|
if (method2 === "PATCH") refuse("SESSION_MUTATION");
|
|
187100
187144
|
if (!["", "/tools", "/toolkits", "/execute", "/execute_meta", "/search"].includes(suffix)) refuse("SESSION_ENDPOINT");
|
|
187145
|
+
if (!qb && suffix !== "" && suffix !== "/execute" && suffix !== "/execute_meta") refuse("SESSION_ENDPOINT");
|
|
187101
187146
|
if (suffix === "" || suffix === "/tools" || suffix === "/toolkits") {
|
|
187102
187147
|
if (method2 !== "GET" && !(suffix === "" && method2 === "DELETE")) refuse("METHOD");
|
|
187103
187148
|
empty2();
|
|
187104
187149
|
if (suffix === "") {
|
|
187105
187150
|
noQuery();
|
|
187106
|
-
return { ...base6, response: method2 === "GET" ? "session-get" : "session-delete", sessionId: sid };
|
|
187151
|
+
return { ...base6, ...!qb && { local: "session" }, response: method2 === "GET" ? "session-get" : "session-delete", sessionId: sid };
|
|
187107
187152
|
}
|
|
187108
187153
|
return base6;
|
|
187109
187154
|
}
|
|
@@ -187114,12 +187159,19 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187114
187159
|
const extra2 = { input_responses: external_exports.unknown().optional(), request_state: external_exports.unknown().optional(), experimental: external_exports.unknown().optional() };
|
|
187115
187160
|
const call2 = suffix === "/execute" ? parsed3(external_exports.strictObject({ tool_slug: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), enable_auto_workbench_offload: external_exports.boolean().optional(), ...extra2 }), value5) : parsed3(external_exports.strictObject({ slug: external_exports.string(), arguments: record10.optional(), ...extra2 }), value5);
|
|
187116
187161
|
const name5 = "tool_slug" in call2 ? call2.tool_slug : call2.slug;
|
|
187117
|
-
|
|
187162
|
+
requireWorld(name5, route15);
|
|
187163
|
+
if (name5.startsWith("NETSUITE_")) {
|
|
187164
|
+
if (!route15.netsuite || name5 !== "NETSUITE_RUN_SUITEQL_QUERY" || suffix !== "/execute") refuse("NETSUITE_TOOL");
|
|
187165
|
+
return { ...base6, toolkit: "netsuite", op: "execute", local: "netsuite", slug: name5, arguments: call2.arguments ?? {} };
|
|
187166
|
+
}
|
|
187167
|
+
const checked = toolArguments(route15, name5, call2.arguments, suffix === "/execute_meta");
|
|
187168
|
+
if (!qb) refuse("SESSION_ENDPOINT");
|
|
187118
187169
|
const kept = { ...call2.input_responses !== void 0 && { input_responses: call2.input_responses }, ...call2.request_state !== void 0 && { request_state: call2.request_state } };
|
|
187119
187170
|
return { ...base6, op: checked.op, slug: name5, body: bytes2(suffix === "/execute" ? { tool_slug: name5, arguments: checked.arguments, ..."enable_auto_workbench_offload" in call2 && { enable_auto_workbench_offload: false }, ...kept } : { slug: name5, arguments: checked.arguments, ...kept }) };
|
|
187120
187171
|
}
|
|
187121
187172
|
const accounts2 = /^\/api\/v3(?:\.1)?\/connected_accounts(?:\/(.*))?$/.exec(url4.pathname);
|
|
187122
187173
|
if (accounts2) {
|
|
187174
|
+
if (!qb) refuse("ACCOUNT");
|
|
187123
187175
|
if (method2 !== "GET") refuse("ACCOUNT");
|
|
187124
187176
|
empty2();
|
|
187125
187177
|
const id14 = accounts2[1];
|
|
@@ -187136,6 +187188,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187136
187188
|
}
|
|
187137
187189
|
return { ...base6, connection: "accounts", target: url4.pathname + "?" + query11.toString() };
|
|
187138
187190
|
}
|
|
187191
|
+
const schema2 = /^\/api\/v3(?:\.1)?\/tools\/(NETSUITE_RUN_SUITEQL_QUERY)$/.exec(url4.pathname);
|
|
187192
|
+
if (schema2) {
|
|
187193
|
+
requireWorld(schema2[1], route15);
|
|
187194
|
+
if (!route15.netsuite) refuse("NETSUITE_TOOL");
|
|
187195
|
+
if (method2 !== "GET") refuse("METHOD");
|
|
187196
|
+
empty2();
|
|
187197
|
+
return { ...base6, toolkit: "netsuite", slug: schema2[1] };
|
|
187198
|
+
}
|
|
187199
|
+
if (/NETSUITE_/i.test(url4.pathname)) refuse("NETSUITE_TOOL");
|
|
187200
|
+
if (!qb) refuse("SESSION_ENDPOINT");
|
|
187139
187201
|
const tool = catalogTool.exec(url4.pathname), toolkit = /^\/api\/v3(?:\.1)?\/toolkits\/quickbooks$/i.test(url4.pathname);
|
|
187140
187202
|
const list17 = /^\/api\/v3(?:\.1)?\/tools$/.test(url4.pathname);
|
|
187141
187203
|
if (!tool && !toolkit && !list17) refuse("PATH");
|
|
@@ -187174,9 +187236,93 @@ async function readComposioBody(req) {
|
|
|
187174
187236
|
}
|
|
187175
187237
|
return Buffer.concat(chunks);
|
|
187176
187238
|
}
|
|
187177
|
-
function refuseComposio(res, reason2) {
|
|
187239
|
+
function refuseComposio(res, reason2, toolkit) {
|
|
187178
187240
|
res.writeHead(403, { "content-type": "application/json", connection: "close" });
|
|
187179
|
-
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message:
|
|
187241
|
+
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
|
|
187242
|
+
}
|
|
187243
|
+
var routeIds = /* @__PURE__ */ new WeakMap();
|
|
187244
|
+
function nextRouteId(route15, kind) {
|
|
187245
|
+
let ids2 = routeIds.get(route15);
|
|
187246
|
+
if (!ids2) {
|
|
187247
|
+
ids2 = new IdStream(route15.attemptId, "composio-route", memoryCounters());
|
|
187248
|
+
routeIds.set(route15, ids2);
|
|
187249
|
+
}
|
|
187250
|
+
return `${kind}_${ids2.fork(kind).alnumUpper(16)}`;
|
|
187251
|
+
}
|
|
187252
|
+
var suiteqlArguments = external_exports.strictObject({ q: external_exports.string(), limit: external_exports.number().int().min(1).optional(), offset: external_exports.number().int().min(0).optional() });
|
|
187253
|
+
async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
|
|
187254
|
+
if (call2.local === "session") {
|
|
187255
|
+
route15.narrowed(call2.narrowed ?? []);
|
|
187256
|
+
if (call2.response === "session-delete") {
|
|
187257
|
+
route15.sessions.delete(call2.sessionId);
|
|
187258
|
+
return { status: 204 };
|
|
187259
|
+
}
|
|
187260
|
+
const id14 = call2.sessionId ?? nextRouteId(route15, "trs");
|
|
187261
|
+
if (call2.response === "session-create") route15.sessions.add(id14);
|
|
187262
|
+
return { status: call2.response === "session-create" ? 201 : 200, body: {
|
|
187263
|
+
session_id: id14,
|
|
187264
|
+
mcp: { type: "http", url: `${origin}/_tool/composio/tool_router/${id14}/mcp` },
|
|
187265
|
+
tool_router_tools: [],
|
|
187266
|
+
config_version: 1,
|
|
187267
|
+
config: {
|
|
187268
|
+
user_id: route15.user,
|
|
187269
|
+
toolkits: { enabled: ["netsuite"] },
|
|
187270
|
+
preload: { tools: [] },
|
|
187271
|
+
search: { enable: false },
|
|
187272
|
+
execute: { enable_multi_execute: false },
|
|
187273
|
+
manage_connections: { enabled: false },
|
|
187274
|
+
multi_account: { enable: false },
|
|
187275
|
+
workbench: { enable: false }
|
|
187276
|
+
}
|
|
187277
|
+
} };
|
|
187278
|
+
}
|
|
187279
|
+
const log_id = nextRouteId(route15, "log");
|
|
187280
|
+
const envelope = (data7, error64, reached2) => ({ status: 200, reached: reached2, body: {
|
|
187281
|
+
data: data7,
|
|
187282
|
+
error: error64,
|
|
187283
|
+
log_id,
|
|
187284
|
+
...call2.via === "session" ? { result_type: error64 === null ? "completed" : "failed" } : { successful: error64 === null }
|
|
187285
|
+
} });
|
|
187286
|
+
const failure5 = (message9, status_code, reached2 = false) => {
|
|
187287
|
+
for (const secret of [route15.agentKey, route15.apiKey, route15.token, route15.netsuite?.token]) if (secret) message9 = message9.replaceAll(secret, "[redacted]");
|
|
187288
|
+
return envelope({ message: message9, status_code }, message9, reached2);
|
|
187289
|
+
};
|
|
187290
|
+
const args = suiteqlArguments.safeParse(call2.arguments ?? {});
|
|
187291
|
+
if (!args.success) return { ...failure5(call2.arguments?.q === void 0 ? "Invalid request data provided\n- Following fields are missing: {'q'}" : "Invalid request data provided: q must be a string, limit an integer >= 1, and offset an integer >= 0; use only q, limit and offset.", 400), invalidArguments: true };
|
|
187292
|
+
if (args.data.limit !== void 0 && args.data.offset !== void 0 && args.data.offset % args.data.limit !== 0)
|
|
187293
|
+
return { ...failure5("Invalid request data provided: offset must be a multiple of limit.", 400), invalidArguments: true };
|
|
187294
|
+
const connection4 = route15.netsuite;
|
|
187295
|
+
const url4 = new URL(connection4.url.replace(/\/$/, "") + "/services/rest/query/v1/suiteql");
|
|
187296
|
+
for (const key5 of ["limit", "offset"]) if (args.data[key5] !== void 0) url4.searchParams.set(key5, String(args.data[key5]));
|
|
187297
|
+
let reached = false;
|
|
187298
|
+
try {
|
|
187299
|
+
const reply6 = await fetcher(url4, {
|
|
187300
|
+
method: "POST",
|
|
187301
|
+
redirect: "error",
|
|
187302
|
+
signal: AbortSignal.any([AbortSignal.timeout(55e3), ...signal ? [signal] : []]),
|
|
187303
|
+
headers: { authorization: `Bearer ${connection4.token}`, "content-type": "application/json", accept: "application/json", prefer: "transient" },
|
|
187304
|
+
body: JSON.stringify({ q: args.data.q })
|
|
187305
|
+
});
|
|
187306
|
+
reached = true;
|
|
187307
|
+
const chunks = [];
|
|
187308
|
+
let size2 = 0;
|
|
187309
|
+
if (Number(reply6.headers.get("content-length") ?? 0) > 8 * 1024 * 1024) {
|
|
187310
|
+
await reply6.body?.cancel();
|
|
187311
|
+
throw new Error("Response bound");
|
|
187312
|
+
}
|
|
187313
|
+
if (reply6.body) for await (const chunk of reply6.body) {
|
|
187314
|
+
size2 += chunk.length;
|
|
187315
|
+
if (size2 > 8 * 1024 * 1024) throw new Error("Response bound");
|
|
187316
|
+
chunks.push(chunk);
|
|
187317
|
+
}
|
|
187318
|
+
const data7 = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
187319
|
+
if (reply6.ok) return envelope(data7, null, true);
|
|
187320
|
+
const details = external_exports.object({ "o:errorDetails": external_exports.array(external_exports.object({ detail: external_exports.string() })) }).safeParse(data7);
|
|
187321
|
+
const message9 = details.success ? details.data["o:errorDetails"].map((item2) => item2.detail).join("\n") : `NetSuite answered ${reply6.status}.`;
|
|
187322
|
+
return failure5(message9, reply6.status, true);
|
|
187323
|
+
} catch {
|
|
187324
|
+
return failure5("The NetSuite world request could not be completed.", 502, reached);
|
|
187325
|
+
}
|
|
187180
187326
|
}
|
|
187181
187327
|
|
|
187182
187328
|
// backend/src/execution/gateway.ts
|
|
@@ -187282,6 +187428,7 @@ async function startIsolationGateway(options4) {
|
|
|
187282
187428
|
const sockets = /* @__PURE__ */ new Set();
|
|
187283
187429
|
const upstreamRequests = /* @__PURE__ */ new Set();
|
|
187284
187430
|
const modelActivity = /* @__PURE__ */ new Set();
|
|
187431
|
+
const localRequests = /* @__PURE__ */ new Set();
|
|
187285
187432
|
let exposedOrigin, closed = false;
|
|
187286
187433
|
const mapped = (origin) => ({
|
|
187287
187434
|
env: { ...structuredClone(env), ...env.mcp && { mcp: Object.fromEntries(Object.entries(env.mcp).map(([tool, connection4]) => [tool, { ...connection4, url: origin + new URL(connection4.url).pathname }])) }, services: Object.fromEntries(Object.entries(env.services).map(([service, connection4]) => [service, {
|
|
@@ -187308,16 +187455,59 @@ async function startIsolationGateway(options4) {
|
|
|
187308
187455
|
toolCall = validateComposio(req.method ?? "", req.url.slice("/_tool/composio".length), req.headers["x-api-key"], toolBody, req.headers["content-type"], route15, req.headers);
|
|
187309
187456
|
} catch (error64) {
|
|
187310
187457
|
const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
|
|
187311
|
-
|
|
187312
|
-
|
|
187458
|
+
const toolkit = (error64 instanceof RouteRefusal ? error64.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
|
|
187459
|
+
route15?.record({ leg: "platform", op: "refused", toolkit, via: composioVia((req.url ?? "").slice("/_tool/composio".length)), method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
|
|
187460
|
+
refuseComposio(res, reason2, toolkit);
|
|
187313
187461
|
return;
|
|
187314
187462
|
}
|
|
187315
187463
|
}
|
|
187464
|
+
if (toolCall?.local && route15) {
|
|
187465
|
+
const call2 = toolCall, controller = new AbortController();
|
|
187466
|
+
const cancel4 = () => {
|
|
187467
|
+
controller.abort();
|
|
187468
|
+
};
|
|
187469
|
+
localRequests.add(controller);
|
|
187470
|
+
res.once("close", cancel4);
|
|
187471
|
+
const operation2 = (async () => {
|
|
187472
|
+
let reached, invalidArguments = false, busy = false;
|
|
187473
|
+
const activity3 = options4.onModelActivity ?? route15.activity;
|
|
187474
|
+
try {
|
|
187475
|
+
if (call2.op === "execute") {
|
|
187476
|
+
await activity3(true);
|
|
187477
|
+
busy = true;
|
|
187478
|
+
}
|
|
187479
|
+
controller.signal.throwIfAborted();
|
|
187480
|
+
if (closed || !route15.available()) throw new Error("Route closed");
|
|
187481
|
+
const result = await executeLocalComposio(call2, route15, exposedOrigin, fetch, controller.signal);
|
|
187482
|
+
reached = result.reached;
|
|
187483
|
+
invalidArguments = result.invalidArguments === true;
|
|
187484
|
+
if (!res.destroyed) {
|
|
187485
|
+
res.writeHead(result.status, { "content-type": "application/json" });
|
|
187486
|
+
res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
|
|
187487
|
+
}
|
|
187488
|
+
} catch {
|
|
187489
|
+
if (!res.destroyed) reject2(res, 502, "The routed world request could not be completed.");
|
|
187490
|
+
} finally {
|
|
187491
|
+
route15.record({ leg: "platform", toolkit: call2.toolkit, op: call2.op, via: call2.via, method: req.method, ...call2.slug && { slug: call2.slug }, ...invalidArguments && { reason: "ARGUMENTS" }, status: res.destroyed && !res.writableFinished ? 502 : res.statusCode, ms: Math.round(performance.now() - toolStarted) }, reached);
|
|
187492
|
+
if (busy) await activity3(false).catch(() => {
|
|
187493
|
+
});
|
|
187494
|
+
localRequests.delete(controller);
|
|
187495
|
+
res.removeListener("close", cancel4);
|
|
187496
|
+
}
|
|
187497
|
+
})();
|
|
187498
|
+
modelActivity.add(operation2);
|
|
187499
|
+
try {
|
|
187500
|
+
await operation2;
|
|
187501
|
+
} finally {
|
|
187502
|
+
modelActivity.delete(operation2);
|
|
187503
|
+
}
|
|
187504
|
+
return;
|
|
187505
|
+
}
|
|
187316
187506
|
if (toolCall && route15) {
|
|
187317
187507
|
try {
|
|
187318
187508
|
await prepareComposio(toolCall, route15);
|
|
187319
187509
|
} catch {
|
|
187320
|
-
route15.record({ leg: "platform", op: "catalog", via: toolCall.via, method: req.method, status: 502, ms: Math.round(performance.now() - toolStarted) });
|
|
187510
|
+
route15.record({ leg: "platform", toolkit: toolCall.toolkit, op: "catalog", via: toolCall.via, method: req.method, status: 502, ms: Math.round(performance.now() - toolStarted) });
|
|
187321
187511
|
res.writeHead(502, { "content-type": "application/json" });
|
|
187322
187512
|
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_CONNECTION", message: "The attempt's test connection is not available." } }));
|
|
187323
187513
|
return;
|
|
@@ -187341,7 +187531,7 @@ async function startIsolationGateway(options4) {
|
|
|
187341
187531
|
const record11 = () => {
|
|
187342
187532
|
if (recorded2) return;
|
|
187343
187533
|
recorded2 = true;
|
|
187344
|
-
route15.record({ leg: "platform", op: call2.op, via: call2.via, method: req.method, ...call2.slug && { slug: call2.slug }, status: res.writableFinished ? res.statusCode : 502, ms: Math.round(performance.now() - toolStarted) }, endWindow?.());
|
|
187534
|
+
route15.record({ leg: "platform", toolkit: call2.toolkit, op: call2.op, via: call2.via, method: req.method, ...call2.slug && { slug: call2.slug }, status: res.writableFinished ? res.statusCode : 502, ms: Math.round(performance.now() - toolStarted) }, endWindow?.());
|
|
187345
187535
|
};
|
|
187346
187536
|
res.once("finish", record11);
|
|
187347
187537
|
res.once("close", record11);
|
|
@@ -187632,6 +187822,7 @@ ${Object.entries(reply6.headers).map(([name5, value5]) => `${name5}: ${value5}`)
|
|
|
187632
187822
|
closed = true;
|
|
187633
187823
|
socketGrants.clear();
|
|
187634
187824
|
options4.signal?.removeEventListener("abort", abort);
|
|
187825
|
+
for (const controller of localRequests) controller.abort();
|
|
187635
187826
|
for (const target5 of upstreamRequests) target5.destroy();
|
|
187636
187827
|
for (const socket of sockets) socket.destroy();
|
|
187637
187828
|
await new Promise((resolve8) => server.close(() => resolve8()));
|