@parcha/agentrun-serve 0.1.0-beta.61 → 0.1.0-beta.63
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/CHANGELOG.md +113 -0
- package/README.md +128 -20
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/api-only.d.ts +4 -0
- package/dist/api-only.js +5 -1
- package/dist/archil-settings.d.ts +9 -0
- package/dist/archil-settings.js +8 -1
- package/dist/bash-read-only.d.ts +3 -0
- package/dist/bash-read-only.js +6 -3
- package/dist/chatgpt-plan.d.ts +33 -8
- package/dist/chatgpt-plan.js +141 -24
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +19 -8
- package/dist/composio-triggers.d.ts +9 -3
- package/dist/computers.d.ts +3 -0
- package/dist/computers.js +2 -1
- package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/cut-pool.d.ts +14 -0
- package/dist/cut-pool.js +98 -0
- package/dist/cut-worker.d.ts +14 -0
- package/dist/cut-worker.js +16 -0
- package/dist/decisions.d.ts +4 -0
- package/dist/decisions.js +9 -1
- package/dist/env-switch.d.ts +3 -0
- package/dist/env-switch.js +3 -0
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/harness-table.d.ts +7 -0
- package/dist/harness-table.js +6 -3
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learned-nodes.d.ts +2 -1
- package/dist/learned-nodes.js +2 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-servers-store.d.ts +7 -10
- package/dist/mcp-servers-store.js +15 -9
- package/dist/native/cli.js +5 -1
- package/dist/ollama-provider.d.ts +10 -3
- package/dist/ollama-provider.js +17 -7
- package/dist/openapi.js +51 -20
- package/dist/otel/tracer.d.ts +6 -3
- package/dist/otel/tracer.js +24 -6
- package/dist/page.d.ts +7 -0
- package/dist/page.js +17 -4
- package/dist/place.d.ts +25 -9
- package/dist/place.js +37 -11
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +26 -6
- package/dist/run-model-key.d.ts +2 -1
- package/dist/run-model-key.js +2 -1
- package/dist/run-reads-over-store.d.ts +7 -0
- package/dist/run-reads-over-store.js +32 -4
- package/dist/run-view.js +9 -3
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +21 -11
- package/dist/runner/adapter-loop.js +95 -28
- package/dist/runner/adapter-run-spec.d.ts +20 -4
- package/dist/runner/adapter-run-spec.js +64 -30
- package/dist/runner/adapters/index.d.ts +6 -0
- package/dist/runner/adapters/index.js +5 -1
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +12 -5
- package/dist/runner/claim-secrets.js +28 -12
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +54 -25
- package/dist/runner/dispatch.js +2 -0
- package/dist/runner/harness-loops.d.ts +5 -0
- package/dist/runner/harness-loops.js +4 -1
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/live-ticker.js +3 -1
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/main.js +2 -0
- package/dist/runner/mcp-run.d.ts +5 -0
- package/dist/runner/mcp-run.js +18 -0
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +5 -3
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/native-loop.js +2 -2
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +65 -41
- package/dist/runner/run-child.js +2 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +158 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-calls.d.ts +4 -3
- package/dist/runner/workflow-calls.js +41 -12
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -1
- package/dist/secret-rules.js +88 -24
- package/dist/server.d.ts +10 -1
- package/dist/server.js +131 -44
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +669 -0
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/suggestions.js +32 -3
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +7 -3
- package/dist/tool-gate.d.ts +25 -9
- package/dist/tool-gate.js +58 -19
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tool-plane.d.ts +1 -0
- package/dist/tool-plane.js +6 -2
- package/dist/tools.js +2 -2
- package/dist/trigger-composio.js +1 -1
- package/dist/webhooks.d.ts +3 -0
- package/dist/webhooks.js +5 -0
- package/dist/workspace/archil-claim.d.ts +7 -3
- package/dist/workspace/archil-claim.js +13 -5
- package/dist/workspace/archil-mount-credential.d.ts +6 -0
- package/dist/workspace/archil-mount-credential.js +11 -0
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/computer-deps.d.ts +5 -3
- package/dist/workspace/computer-deps.js +11 -9
- package/dist/workspace/computer-for-claim.d.ts +6 -2
- package/dist/workspace/computer-for-claim.js +43 -12
- package/dist/workspace/computer-janitor.d.ts +7 -4
- package/dist/workspace/computer-janitor.js +7 -4
- package/dist/workspace/computer-kept.d.ts +7 -1
- package/dist/workspace/computer-kept.js +7 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
- package/dist/workspace/mount-revoke-left.d.ts +16 -4
- package/dist/workspace/mount-revoke-left.js +42 -22
- package/dist/workspace/resolve-computer.d.ts +11 -5
- package/dist/workspace/resolve-computer.js +22 -13
- package/dist/workspace/run-end-computers.js +1 -1
- package/dist/workspace/run-tools.d.ts +10 -3
- package/dist/workspace/run-tools.js +5 -4
- package/dist/wrapped.d.ts +29 -2
- package/dist/wrapped.js +20 -3
- package/launcher/agentrun-serve +1 -1
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/index-BnZV3lvW.js +0 -639
- package/dist/console/assets/share-B1o5mJ56.js +0 -6
- /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
package/dist/mcp-gateway.d.ts
CHANGED
|
@@ -134,9 +134,33 @@ export interface McpGatewayOptions {
|
|
|
134
134
|
* summary. UNREADABLE for a tool: a stored setting that does not read, and every call of the tool is refused unsent.
|
|
135
135
|
* None, or undefined for a tool: its answers are the model's, as always. */
|
|
136
136
|
filed?: (server: string, tool: string) => FileSetting | typeof UNREADABLE | undefined;
|
|
137
|
+
/** The run's redactor (the runner's one, holding every key the run opened: its own model and tool keys, the other
|
|
138
|
+
* servers' credentials), after each call's own scrub on every text the gateway answers or files: the model's answer,
|
|
139
|
+
* a filed answer, a long answer's filed rest, a server's results and an error's words; its values (heldValues) read
|
|
140
|
+
* in a binary payload filed whole (filedJson). Every claim's MCP gives it (mcp-run.ts); a gateway given none does not
|
|
141
|
+
* start. */
|
|
142
|
+
redact: ((text: string) => string) & {
|
|
143
|
+
readonly heldValues?: () => readonly string[];
|
|
144
|
+
};
|
|
137
145
|
}
|
|
138
146
|
/** A run's journal commit. */
|
|
139
147
|
export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
|
|
148
|
+
/** A binary payload of an answer filed whole (an image's or an audio's data, a resource's blob), as it is filed: scrubbed
|
|
149
|
+
* of the call's own credentials (`own`) and kept whole, unless it holds one of `values` (what the run's redactor holds),
|
|
150
|
+
* as written, in any form the matcher finds, or in the text of the bytes it decodes to, or that text holds a secret's shape (a JWT,
|
|
151
|
+
* a private key: SECRET_SHAPES, which the run's redactor cuts in text). Then it is "[redacted]" whole: a cut inside it
|
|
152
|
+
* would leave no payload a reader could open either. Its base64 text is not read for a shape: the MCP client takes no
|
|
153
|
+
* payload that is not base64, and in base64 a shape stands only by chance (a Google API key's run, about once in 50 MiB)
|
|
154
|
+
* or as a server's deliberate encoding, which no redactor stops. `values` undefined (a redactor that names none): the
|
|
155
|
+
* payload is cut as the rest is, by `clean`. */
|
|
156
|
+
export declare function binaryKept(payload: string, clean: (text: string) => string, own: (text: string) => string, values: readonly string[] | undefined): string;
|
|
157
|
+
/** The text in a payload's bytes, one run to a line. A run is the bytes between two that are neither text nor what the
|
|
158
|
+
* matcher reads past in a Latin-1 decode: printable ASCII and whitespace (a no-break space among it), and the bytes it
|
|
159
|
+
* reads as nothing (a NUL, a control character, a soft hyphen, a spacing accent: IGNORED_BYTES, which go). A held value
|
|
160
|
+
* cut into short pieces by one of them, or written as UTF-16 or UTF-32 in either byte order, still reads whole. A run is
|
|
161
|
+
* kept when MIN_SECRET or more printable characters are left. Both steps are linear in the bytes. Only these runs are
|
|
162
|
+
* read: a value or a shape the bytes carry is text, and every view read over binary bytes cost about 25 s a MiB. */
|
|
163
|
+
export declare function textRuns(bytes: string): string;
|
|
140
164
|
/** The gateway: a session's servers, and their calls. `credentials` is read at every call and every request, never
|
|
141
165
|
* copied: a change the claim step makes after (a token refreshed behind the claim, a server removed) reaches it, even
|
|
142
166
|
* through a client already connected. */
|
package/dist/mcp-gateway.js
CHANGED
|
@@ -30,6 +30,7 @@ import { saveOnce } from "./save-once.js";
|
|
|
30
30
|
import { paidLedger, paidStep } from "./paid-calls.js";
|
|
31
31
|
import { metaToolOf } from "./mcp-meta.js";
|
|
32
32
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
33
|
+
import { MIN_SECRET, secretShapes, valueLeft } from "./learn/secrets.js";
|
|
33
34
|
import { capped, mcpClient, scrub } from "./mcp-wire.js";
|
|
34
35
|
import { resourceResult, resourceToolOperation, resourceToolProblem } from "./mcp-resources.js";
|
|
35
36
|
import { mcpNameOf, mcpToolName } from "./tool-names.js";
|
|
@@ -190,7 +191,50 @@ function unreachable(error) {
|
|
|
190
191
|
const said = (text, isError = false) => ({ content: [{ type: "text", text }], ...(isError ? { isError: true } : {}) });
|
|
191
192
|
/** The refusal of a call of a tool whose stored file setting does not read (filed-tool.ts UNREADABLE). */
|
|
192
193
|
const unreadableFile = (server, tool) => `${mcpToolName(server, tool)} can't be called: its file setting in the agent's tool settings does not read, so no call is let through until the owner sets it again or removes it (Settings → Tools). Nothing was sent.`;
|
|
194
|
+
/** A binary payload of an answer filed whole (an image's or an audio's data, a resource's blob), as it is filed: scrubbed
|
|
195
|
+
* of the call's own credentials (`own`) and kept whole, unless it holds one of `values` (what the run's redactor holds),
|
|
196
|
+
* as written, in any form the matcher finds, or in the text of the bytes it decodes to, or that text holds a secret's shape (a JWT,
|
|
197
|
+
* a private key: SECRET_SHAPES, which the run's redactor cuts in text). Then it is "[redacted]" whole: a cut inside it
|
|
198
|
+
* would leave no payload a reader could open either. Its base64 text is not read for a shape: the MCP client takes no
|
|
199
|
+
* payload that is not base64, and in base64 a shape stands only by chance (a Google API key's run, about once in 50 MiB)
|
|
200
|
+
* or as a server's deliberate encoding, which no redactor stops. `values` undefined (a redactor that names none): the
|
|
201
|
+
* payload is cut as the rest is, by `clean`. */
|
|
202
|
+
export function binaryKept(payload, clean, own, values) {
|
|
203
|
+
if (!values)
|
|
204
|
+
return clean(payload);
|
|
205
|
+
const scrubbed = own(payload);
|
|
206
|
+
const text = textRuns(Buffer.from(scrubbed, "base64").toString("latin1"));
|
|
207
|
+
if (secretShapes(text).length > 0)
|
|
208
|
+
return "[redacted]";
|
|
209
|
+
if (!values.length)
|
|
210
|
+
return scrubbed;
|
|
211
|
+
return valueLeft(scrubbed, values, []) || valueLeft(text, values, []) ? "[redacted]" : scrubbed;
|
|
212
|
+
}
|
|
213
|
+
/** The text in a payload's bytes, one run to a line. A run is the bytes between two that are neither text nor what the
|
|
214
|
+
* matcher reads past in a Latin-1 decode: printable ASCII and whitespace (a no-break space among it), and the bytes it
|
|
215
|
+
* reads as nothing (a NUL, a control character, a soft hyphen, a spacing accent: IGNORED_BYTES, which go). A held value
|
|
216
|
+
* cut into short pieces by one of them, or written as UTF-16 or UTF-32 in either byte order, still reads whole. A run is
|
|
217
|
+
* kept when MIN_SECRET or more printable characters are left. Both steps are linear in the bytes. Only these runs are
|
|
218
|
+
* read: a value or a shape the bytes carry is text, and every view read over binary bytes cost about 25 s a MiB. */
|
|
219
|
+
export function textRuns(bytes) {
|
|
220
|
+
const runs = [];
|
|
221
|
+
for (const [found] of bytes.matchAll(RUN)) {
|
|
222
|
+
const text = found.replace(IGNORED_BYTES, "");
|
|
223
|
+
let printable = 0;
|
|
224
|
+
for (let at = 0; at < text.length && printable < MIN_SECRET; at++)
|
|
225
|
+
if (text.charCodeAt(at) > 0x20 && text.charCodeAt(at) < 0x7f)
|
|
226
|
+
printable++;
|
|
227
|
+
if (printable >= MIN_SECRET)
|
|
228
|
+
runs.push(text);
|
|
229
|
+
}
|
|
230
|
+
return runs.join("\n");
|
|
231
|
+
}
|
|
232
|
+
const RUN = /[\x00-\xa0\xa8\xad\xaf\xb4\xb8]+/g;
|
|
233
|
+
const IGNORED_BYTES = /[\x00-\x08\x0e-\x1f\x7f-\x9f\xa8\xad\xaf\xb4\xb8]+/g;
|
|
193
234
|
export function mcpGateway(options) {
|
|
235
|
+
if (typeof options.redact !== "function")
|
|
236
|
+
throw new TypeError("An MCP gateway was given no redactor (the run's), so it does not start: an answer would reach the model and the run's files cut of its own server's credentials alone");
|
|
237
|
+
const runCut = options.redact;
|
|
194
238
|
/** Each server's client, with the account query it was connected with (`query`, JSON): a message that binds the run to
|
|
195
239
|
* another account connects again, so no session made as one account carries another's calls. */
|
|
196
240
|
const clients = new Map();
|
|
@@ -300,13 +344,54 @@ export function mcpGateway(options) {
|
|
|
300
344
|
text = clean(JSON.stringify(result.structuredContent));
|
|
301
345
|
return { text, other: blocks.length - texts.length };
|
|
302
346
|
};
|
|
347
|
+
/** `result` as the JSON filed for an answer with blocks that are not text, every text in it cut by `clean`. An image's
|
|
348
|
+
* or an audio's data and a resource's blob are base64, one run with no whitespace, which the run's redactor would show
|
|
349
|
+
* as "[redacted]" past a piece (key-refusal.ts redactedAnswer), and a screenshot is far longer than one: each is
|
|
350
|
+
* filed as binaryKept keeps it, at its own block. */
|
|
351
|
+
const filedJson = (result, clean, own, values) => {
|
|
352
|
+
const blocks = Array.isArray(result.content) ? result.content : [];
|
|
353
|
+
const payloads = [];
|
|
354
|
+
const bare = blocks.map((block, at) => {
|
|
355
|
+
if (!block || typeof block !== "object")
|
|
356
|
+
return block;
|
|
357
|
+
const one = block;
|
|
358
|
+
if ((one.type === "image" || one.type === "audio") && typeof one.data === "string") {
|
|
359
|
+
payloads.push({ at, key: "data", text: one.data });
|
|
360
|
+
return { ...one, data: "" };
|
|
361
|
+
}
|
|
362
|
+
const resource = one.type === "resource" && one.resource && typeof one.resource === "object" ? one.resource : undefined;
|
|
363
|
+
if (resource && typeof resource.blob === "string") {
|
|
364
|
+
payloads.push({ at, key: "blob", text: resource.blob });
|
|
365
|
+
return { ...one, resource: { ...resource, blob: "" } };
|
|
366
|
+
}
|
|
367
|
+
return block;
|
|
368
|
+
});
|
|
369
|
+
const filed = clean(JSON.stringify(payloads.length ? { ...result, content: bare } : result));
|
|
370
|
+
if (!payloads.length)
|
|
371
|
+
return filed;
|
|
372
|
+
let doc;
|
|
373
|
+
try {
|
|
374
|
+
doc = JSON.parse(filed);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return filed;
|
|
378
|
+
}
|
|
379
|
+
const content = Array.isArray(doc.content) ? doc.content : [];
|
|
380
|
+
for (const { at, key, text } of payloads) {
|
|
381
|
+
const block = content[at];
|
|
382
|
+
const into = key === "data" ? block : block?.resource;
|
|
383
|
+
if (into && typeof into === "object" && into[key] === "")
|
|
384
|
+
into[key] = binaryKept(text, clean, own, values);
|
|
385
|
+
}
|
|
386
|
+
return JSON.stringify(doc);
|
|
387
|
+
};
|
|
303
388
|
/** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
|
|
304
389
|
* file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
|
|
305
390
|
* run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
|
|
306
391
|
* and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
|
|
307
392
|
* neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
|
|
308
393
|
* credential the call's server took or sent. */
|
|
309
|
-
const textOf = async (server, tool, result, clean) => {
|
|
394
|
+
const textOf = async (server, tool, result, clean, filedAs) => {
|
|
310
395
|
const { text, other } = answerOf(result, clean);
|
|
311
396
|
if (text.length <= MCP_CLIP && other === 0)
|
|
312
397
|
return text;
|
|
@@ -315,7 +400,7 @@ export function mcpGateway(options) {
|
|
|
315
400
|
return filedAnswer(async () => workspaceAt(await options.work()), `evidence/mcp/${server}`, name, text, MCP_CLIP);
|
|
316
401
|
const head = text.length > MCP_CLIP ? `${text.slice(0, MCP_CLIP)}\n[cut at ${MCP_CLIP} of ${text.length} characters; ` : `${text}\n[${other} block${other > 1 ? "s" : ""} that ${other > 1 ? "are" : "is"} not text; `;
|
|
317
402
|
try {
|
|
318
|
-
await workspaceAt(await options.work()).write(`evidence/mcp/${server}/${name}.json`,
|
|
403
|
+
await workspaceAt(await options.work()).write(`evidence/mcp/${server}/${name}.json`, filedAs(result));
|
|
319
404
|
}
|
|
320
405
|
catch (error) {
|
|
321
406
|
// The Workspace's code and the port's line for it, never the error's message, which names paths.
|
|
@@ -329,9 +414,9 @@ export function mcpGateway(options) {
|
|
|
329
414
|
* error, so the model can still react through a shown field. An answer with blocks that are not text is filed as the
|
|
330
415
|
* whole result's JSON. A write that fails (or a Workspace that cannot open) answers an error in the Workspace's words,
|
|
331
416
|
* none of the answer shown. */
|
|
332
|
-
const filedOf = async (setting, tool, result, clean) => {
|
|
417
|
+
const filedOf = async (setting, tool, result, clean, filedAs) => {
|
|
333
418
|
const { text: answer, other } = answerOf(result, clean);
|
|
334
|
-
const text = other === 0 ? answer :
|
|
419
|
+
const text = other === 0 ? answer : filedAs(result);
|
|
335
420
|
const path = `${setting.folder}/${tool.replace(/[^A-Za-z0-9_.-]/g, "_")}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}.json`;
|
|
336
421
|
try {
|
|
337
422
|
await workspaceAt(await options.work()).write(path, text);
|
|
@@ -387,8 +472,12 @@ export function mcpGateway(options) {
|
|
|
387
472
|
// Read at each use: a token refreshed while the call is out, and sent, is scrubbed with the one it took.
|
|
388
473
|
const held = callSet(server);
|
|
389
474
|
const scrubbed = scrubberOf(server, hold(server, headers), held.values);
|
|
390
|
-
// Every text the model reads of the call (its answer, a filed one, an error), its keys
|
|
391
|
-
|
|
475
|
+
// Every text the model reads of the call or the run's files keep of it (its answer, a filed one, an error), its keys
|
|
476
|
+
// read as the agent's own, then cut by the run's redactor: a value the run holds that the server echoed reaches
|
|
477
|
+
// neither. The one place each of those texts passes.
|
|
478
|
+
const own = back ? (text) => back(scrubbed(text)) : scrubbed;
|
|
479
|
+
const clean = (text) => runCut(own(text));
|
|
480
|
+
const filedAs = (whole) => filedJson(whole, clean, own, runCut.heldValues?.());
|
|
392
481
|
hold(server, queryOf(server));
|
|
393
482
|
try {
|
|
394
483
|
const upstream = await until(connect(server, url, headers), boundedSignal);
|
|
@@ -414,8 +503,8 @@ export function mcpGateway(options) {
|
|
|
414
503
|
if (filing === UNREADABLE)
|
|
415
504
|
return said(unreadableFile(server, tool.name), true);
|
|
416
505
|
if (filing)
|
|
417
|
-
return await filedOf(filing, tool.name, result, clean);
|
|
418
|
-
return said(await textOf(server, tool.name, result, clean), result.isError === true);
|
|
506
|
+
return await filedOf(filing, tool.name, result, clean, filedAs);
|
|
507
|
+
return said(await textOf(server, tool.name, result, clean, filedAs), result.isError === true);
|
|
419
508
|
}
|
|
420
509
|
catch (error) {
|
|
421
510
|
if (signal.aborted)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type InputIssue } from "./errors.js";
|
|
2
2
|
import { type Listed, type McpPrices, type McpTool } from "./mcp-probe.js";
|
|
3
|
+
import type { ComposioCredentialOf } from "./composio-triggers.js";
|
|
3
4
|
import { type SecretMeta } from "./secret-writes.js";
|
|
4
5
|
import { type ClientKind, type OAuthNetwork } from "./mcp-oauth.js";
|
|
5
6
|
import { type Cleanup, COMPOSIO_KEY_ENV, type ComposioMade } from "./composio-made.js";
|
|
@@ -439,17 +440,13 @@ export declare class McpServersOverStore {
|
|
|
439
440
|
/** The saved OAuth token set of `row` (the row read and checked, as opened), for a sign-in again that reuses the kept
|
|
440
441
|
* client. */
|
|
441
442
|
private openedSet;
|
|
442
|
-
/** A saved Composio preset server's key (its sealed x-api-key), the
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
443
|
+
/** A saved Composio preset server's key (its sealed x-api-key), its toolkit and the auth config its save recorded
|
|
444
|
+
* (composio-made.ts; none for a server saved before that was recorded), and for a trigger's own steps (`field`) the
|
|
445
|
+
* Composio user its address names (`user_id`, the preset's default when none): what its Composio triggers are made with
|
|
446
|
+
* (composio-triggers.ts). The server's own routes (`route`) are answered no user: none of them sends one. Refused when
|
|
447
|
+
* `name` is no such server: on the trigger's `source.server` at its create (`field`), as a 404 on the server's own
|
|
446
448
|
* routes (`route`). The key goes only to Composio. */
|
|
447
|
-
composioOf
|
|
448
|
-
key: string;
|
|
449
|
-
user: string;
|
|
450
|
-
toolkit: string;
|
|
451
|
-
auth_config?: string;
|
|
452
|
-
}>;
|
|
449
|
+
composioOf<R extends "field" | "route">(name: string, refusal: R): Promise<ComposioCredentialOf<R>>;
|
|
453
450
|
/** What the saved server `row` is, for a template's apply to match (mcp-sources.ts sourceOf): github on the GitHub App's
|
|
454
451
|
* tokens, else its record, else url with none. */
|
|
455
452
|
sourceOf(row: RecordedRow & {
|
|
@@ -829,10 +829,11 @@ export class McpServersOverStore {
|
|
|
829
829
|
const open = openMcpRow(this.sealKey, row);
|
|
830
830
|
return "credential" in open && open.credential.type === "oauth" ? open.credential.set : undefined;
|
|
831
831
|
}
|
|
832
|
-
/** A saved Composio preset server's key (its sealed x-api-key), the
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*
|
|
832
|
+
/** A saved Composio preset server's key (its sealed x-api-key), its toolkit and the auth config its save recorded
|
|
833
|
+
* (composio-made.ts; none for a server saved before that was recorded), and for a trigger's own steps (`field`) the
|
|
834
|
+
* Composio user its address names (`user_id`, the preset's default when none): what its Composio triggers are made with
|
|
835
|
+
* (composio-triggers.ts). The server's own routes (`route`) are answered no user: none of them sends one. Refused when
|
|
836
|
+
* `name` is no such server: on the trigger's `source.server` at its create (`field`), as a 404 on the server's own
|
|
836
837
|
* routes (`route`). The key goes only to Composio. */
|
|
837
838
|
async composioOf(name, refusal) {
|
|
838
839
|
const refuse = (message) => (refusal === "route" ? new ApiError("not_found", message) : invalid([{ field: "source.server", reason: "not_an_option", message }]));
|
|
@@ -853,15 +854,20 @@ export class McpServersOverStore {
|
|
|
853
854
|
if (!key)
|
|
854
855
|
throw refuse(`${name}'s saved credential holds no Composio key: save it again with its key.`);
|
|
855
856
|
const config = recordedMade(recorded, row.createdAt)?.auth_config?.id;
|
|
857
|
+
const made = { key, toolkit, ...(config ? { auth_config: config } : {}) };
|
|
858
|
+
// A route sends Composio no user: its events, its triggers and the project's subscription are read by the key, and a
|
|
859
|
+
// delete or a save takes the project's turn by it, so it is answered none, and a server with a blank user keeps its
|
|
860
|
+
// routes and that turn.
|
|
861
|
+
if (refusal === "route")
|
|
862
|
+
return made;
|
|
856
863
|
// Only an address with no user_id at all is the default user's: an empty one is a blank user, refused below.
|
|
857
864
|
const user = new URL(row.url).searchParams.get("user_id") ?? COMPOSIO_USER;
|
|
858
865
|
// A user that is no Composio user id (a blank one Composio may read as every user) is refused for a trigger's own steps
|
|
859
|
-
//
|
|
860
|
-
//
|
|
861
|
-
|
|
862
|
-
if (refusal === "field" && !COMPOSIO_USER_ID.test(user))
|
|
866
|
+
// before Composio is asked anything: a create sends the user (its account read, its connect link, its instance's
|
|
867
|
+
// upsert).
|
|
868
|
+
if (!COMPOSIO_USER_ID.test(user))
|
|
863
869
|
throw refuse(`${name}'s saved Composio user ${JSON.stringify(user)} is no Composio user id: save the server again with its user.`);
|
|
864
|
-
return {
|
|
870
|
+
return { ...made, user };
|
|
865
871
|
}
|
|
866
872
|
/** What the saved server `row` is, for a template's apply to match (mcp-sources.ts sourceOf): github on the GitHub App's
|
|
867
873
|
* tokens, else its record, else url with none. */
|
package/dist/native/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
+
import { keyBase } from '@parcha/agentrun-computer';
|
|
2
3
|
import { readFile } from 'node:fs/promises';
|
|
3
4
|
import { join } from 'node:path';
|
|
4
5
|
import { defaultData } from '../server-fs.js';
|
|
@@ -33,7 +34,10 @@ export async function nativeMain(argv, usage) {
|
|
|
33
34
|
recorded = record.base_url;
|
|
34
35
|
}
|
|
35
36
|
catch { /* explicit/default URL below */ }
|
|
36
|
-
const
|
|
37
|
+
const named = [['--url', values.url], ['AGENTRUN_BASE_URL', process.env.AGENTRUN_BASE_URL], ['AGENTRUN_URL', process.env.AGENTRUN_URL], ["the server's recorded base_url", recorded]];
|
|
38
|
+
const [setting, given] = named.find((entry) => entry[1] !== undefined) ?? ['the default URL', 'http://127.0.0.1:7340'];
|
|
39
|
+
// The token goes to it, and fetch's errors print the whole URL: the rule of a URL a key goes to (keyBase), over loopback's http or https.
|
|
40
|
+
const url = new URL(keyBase(given, setting, ['http:', 'https:']));
|
|
37
41
|
if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))
|
|
38
42
|
throw new Error('Run AgentRun on this source machine and connect to its loopback URL; hosted native pairing is not available yet.');
|
|
39
43
|
const token = secret('AGENTRUN_API_KEY') || secret('AGENTRUN_TOKEN') || (await readFile(join(data, '.token'), 'utf8')).trim();
|
|
@@ -110,18 +110,25 @@ export type OllamaPullLine = {
|
|
|
110
110
|
/** How long a pull may go with no byte from Ollama before it stops (ollamaPull): a registry that stalls, or an Ollama
|
|
111
111
|
* that wedges, frees the one pull here instead of holding it at `pulling` until the server restarts. */
|
|
112
112
|
export declare const PULL_STALL_MS = 120000;
|
|
113
|
-
/**
|
|
113
|
+
/** How long a pull may go with no byte from Ollama once it says `verifying sha256 digest`: it then hashes every blob of the
|
|
114
|
+
* model with no further line, and on a slow disk a model of gigabytes takes minutes. An Ollama that wedges there still
|
|
115
|
+
* frees the pull. */
|
|
116
|
+
export declare const PULL_VERIFY_STALL_MS: number;
|
|
117
|
+
/** The longest progress line a pull takes, in characters: Ollama's are a few hundred, so a stream that sends no newline
|
|
118
|
+
* ends. */
|
|
114
119
|
export declare const PULL_LINE_MAX: number;
|
|
115
120
|
/**
|
|
116
121
|
* Pulls `tag` through the Ollama `env` names (POST /api/pull, streamed as NDJSON), each line of progress to `onLine` as it
|
|
117
122
|
* comes. Resolves once Ollama says `success`; throws, in Ollama's words, on an `error` line, a refusal, a stream that ends
|
|
118
123
|
* before `success`, or `signal`; in its own, on `stallMs` with no byte from Ollama (the answer's head or a chunk of the
|
|
119
|
-
* stream)
|
|
124
|
+
* stream), `verifyStallMs` once Ollama says it is verifying the digest, or a line past PULL_LINE_MAX. No deadline on the
|
|
125
|
+
* whole: a model is gigabytes, and a pull that moves is let run.
|
|
120
126
|
*/
|
|
121
|
-
export declare function ollamaPull(env: NodeJS.ProcessEnv, tag: string, onLine: (line: OllamaPullLine) => void, { fetch: send, signal, stallMs }?: {
|
|
127
|
+
export declare function ollamaPull(env: NodeJS.ProcessEnv, tag: string, onLine: (line: OllamaPullLine) => void, { fetch: send, signal, stallMs, verifyStallMs }?: {
|
|
122
128
|
fetch?: typeof fetch;
|
|
123
129
|
signal?: AbortSignal;
|
|
124
130
|
stallMs?: number;
|
|
131
|
+
verifyStallMs?: number;
|
|
125
132
|
}): Promise<void>;
|
|
126
133
|
/** `env`'s Ollama listing as last kept (ollamaKept), in one string: each model's tag, capabilities and trained context.
|
|
127
134
|
* A server compares it to see a model pulled, removed or an Ollama started since it made its offers (server.ts). */
|
package/dist/ollama-provider.js
CHANGED
|
@@ -299,23 +299,31 @@ export async function ollamaVersion(env, { fetch: send = globalThis.fetch, timeo
|
|
|
299
299
|
/** How long a pull may go with no byte from Ollama before it stops (ollamaPull): a registry that stalls, or an Ollama
|
|
300
300
|
* that wedges, frees the one pull here instead of holding it at `pulling` until the server restarts. */
|
|
301
301
|
export const PULL_STALL_MS = 120_000;
|
|
302
|
-
/**
|
|
302
|
+
/** How long a pull may go with no byte from Ollama once it says `verifying sha256 digest`: it then hashes every blob of the
|
|
303
|
+
* model with no further line, and on a slow disk a model of gigabytes takes minutes. An Ollama that wedges there still
|
|
304
|
+
* frees the pull. */
|
|
305
|
+
export const PULL_VERIFY_STALL_MS = 15 * 60_000;
|
|
306
|
+
/** The longest progress line a pull takes, in characters: Ollama's are a few hundred, so a stream that sends no newline
|
|
307
|
+
* ends. */
|
|
303
308
|
export const PULL_LINE_MAX = 64 * 1024;
|
|
304
309
|
/**
|
|
305
310
|
* Pulls `tag` through the Ollama `env` names (POST /api/pull, streamed as NDJSON), each line of progress to `onLine` as it
|
|
306
311
|
* comes. Resolves once Ollama says `success`; throws, in Ollama's words, on an `error` line, a refusal, a stream that ends
|
|
307
312
|
* before `success`, or `signal`; in its own, on `stallMs` with no byte from Ollama (the answer's head or a chunk of the
|
|
308
|
-
* stream)
|
|
313
|
+
* stream), `verifyStallMs` once Ollama says it is verifying the digest, or a line past PULL_LINE_MAX. No deadline on the
|
|
314
|
+
* whole: a model is gigabytes, and a pull that moves is let run.
|
|
309
315
|
*/
|
|
310
|
-
export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fetch, signal, stallMs = PULL_STALL_MS } = {}) {
|
|
316
|
+
export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fetch, signal, stallMs = PULL_STALL_MS, verifyStallMs = PULL_VERIFY_STALL_MS } = {}) {
|
|
311
317
|
const base = baseOf(env);
|
|
312
318
|
if (base === undefined)
|
|
313
319
|
throw new Error("no Ollama is asked here");
|
|
314
320
|
const stall = new AbortController();
|
|
315
321
|
let timer;
|
|
322
|
+
// The silence let pass now: the stall deadline, until Ollama says it is verifying the digest.
|
|
323
|
+
let quietMs = stallMs;
|
|
316
324
|
const moved = () => {
|
|
317
325
|
clearTimeout(timer);
|
|
318
|
-
timer = setTimeout(() => stall.abort(),
|
|
326
|
+
timer = setTimeout(() => stall.abort(), quietMs);
|
|
319
327
|
};
|
|
320
328
|
const stopped = signal ? AbortSignal.any([signal, stall.signal]) : stall.signal;
|
|
321
329
|
moved();
|
|
@@ -338,10 +346,10 @@ export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fe
|
|
|
338
346
|
return;
|
|
339
347
|
if (line.status === "success")
|
|
340
348
|
succeeded = true;
|
|
349
|
+
quietMs = line.status.startsWith("verifying") ? Math.max(stallMs, verifyStallMs) : stallMs;
|
|
341
350
|
onLine({ status: line.status, ...(typeof line.digest === "string" ? { digest: line.digest } : {}), ...(line.total !== undefined ? { total: count(line.total) } : {}), ...(line.completed !== undefined ? { completed: count(line.completed) } : {}) });
|
|
342
351
|
};
|
|
343
352
|
for await (const chunk of response.body) {
|
|
344
|
-
moved();
|
|
345
353
|
rest += decoder.decode(chunk, { stream: true });
|
|
346
354
|
let cut;
|
|
347
355
|
while ((cut = rest.indexOf("\n")) >= 0) {
|
|
@@ -350,8 +358,10 @@ export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fe
|
|
|
350
358
|
if (text)
|
|
351
359
|
take(text);
|
|
352
360
|
}
|
|
361
|
+
// Armed after the chunk's lines are read, so a `verifying` line sets the silence that follows it.
|
|
362
|
+
moved();
|
|
353
363
|
if (rest.length > PULL_LINE_MAX)
|
|
354
|
-
throw new Error(`Ollama sent a progress line longer than ${PULL_LINE_MAX}
|
|
364
|
+
throw new Error(`Ollama sent a progress line longer than ${PULL_LINE_MAX} characters, so the pull stopped. Press Pull again.`);
|
|
355
365
|
}
|
|
356
366
|
if (rest.trim())
|
|
357
367
|
take(rest.trim());
|
|
@@ -360,7 +370,7 @@ export async function ollamaPull(env, tag, onLine, { fetch: send = globalThis.fe
|
|
|
360
370
|
}
|
|
361
371
|
catch (error) {
|
|
362
372
|
if (stall.signal.aborted && !signal?.aborted)
|
|
363
|
-
throw new Error(`Ollama sent nothing for ${Math.round(
|
|
373
|
+
throw new Error(`Ollama sent nothing for ${Math.round(quietMs / 1000)} s, so the pull stopped. Press Pull again.`);
|
|
364
374
|
throw error;
|
|
365
375
|
}
|
|
366
376
|
finally {
|