@parcha/agentrun-serve 0.1.0-beta.42 → 0.1.0-beta.44
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 +126 -0
- package/README.md +221 -31
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +0 -4
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-sources.js +25 -5
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +203 -87
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +516 -134
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type TriggerAdapter } from "./trigger-adapter.js";
|
|
1
|
+
import { type Source, type TriggerAdapter } from "./trigger-adapter.js";
|
|
2
|
+
import { type Json } from "./validate.js";
|
|
2
3
|
/** A Composio trigger slug: upper case, digits and `_` (GITHUB_ISSUE_ADDED_EVENT). */
|
|
3
4
|
export declare const COMPOSIO_EVENT: RegExp;
|
|
4
5
|
/** The id of a project's route here, made once when its subscription is made or moved here. */
|
|
@@ -7,4 +8,60 @@ export declare const COMPOSIO_HOOK: RegExp;
|
|
|
7
8
|
export declare const MOVE_FIELD = "move_subscription";
|
|
8
9
|
/** The settings field the project's subscription secret is sealed under, one scope per hook. */
|
|
9
10
|
export declare const COMPOSIO_SECRET = "secret";
|
|
11
|
+
/** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
|
|
12
|
+
* CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
|
|
13
|
+
* echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
|
|
14
|
+
export declare const CONFIG_SECRET = "config";
|
|
15
|
+
export declare const CONFIG_UNLISTED = "config_unlisted";
|
|
16
|
+
/** What a trigger keeps, and answers, in place of a sealed config value. */
|
|
17
|
+
export declare const SEALED_MASK = "[sealed]";
|
|
18
|
+
/** The source's field that names its sealed config fields, set by this server. */
|
|
19
|
+
export declare const SEALED_FIELD = "sealed_config";
|
|
20
|
+
/** The settings scope of trigger `id`'s sealed config field `field`. */
|
|
21
|
+
export declare const configScope: (id: string, field: string) => string;
|
|
22
|
+
/** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
|
|
23
|
+
* the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
|
|
24
|
+
* apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
|
|
25
|
+
* word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
|
|
26
|
+
* count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
|
|
27
|
+
* budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
|
|
28
|
+
export declare const secretConfigName: (name: string) => boolean;
|
|
29
|
+
/** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
|
|
30
|
+
* credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
|
|
31
|
+
* before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
|
|
32
|
+
* ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
|
|
33
|
+
* name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
|
|
34
|
+
export declare const credentialUrl: (value: string) => boolean;
|
|
35
|
+
/** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
|
|
36
|
+
* sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
|
|
37
|
+
export declare const sealableValue: (value: unknown) => value is string | number;
|
|
38
|
+
/** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
|
|
39
|
+
* is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
|
|
40
|
+
* those its event's schema marks (sealedSchemaFields). */
|
|
41
|
+
export declare const sealedConfigFields: (config: unknown) => string[];
|
|
42
|
+
/** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
|
|
43
|
+
* or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
|
|
44
|
+
* of those, or says none). What the console's form takes as a password. */
|
|
45
|
+
export declare const sealedSchemaFields: (schema: unknown) => string[];
|
|
46
|
+
/** A credential in a config, where it is: `name`, its top-level field's name or, below the top level, its JSON Pointer
|
|
47
|
+
* (/auth/api_key), as sealed_config names it and its sealed scope is keyed (configScope); `path`, its keys from the
|
|
48
|
+
* config down; `value`. */
|
|
49
|
+
export type ConfigSecret = {
|
|
50
|
+
name: string;
|
|
51
|
+
path: string[];
|
|
52
|
+
value: string | number;
|
|
53
|
+
};
|
|
54
|
+
/** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
|
|
55
|
+
* number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
|
|
56
|
+
* object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
|
|
57
|
+
* at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
|
|
58
|
+
export declare const configSecrets: (config: unknown) => ConfigSecret[];
|
|
59
|
+
/** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
|
|
60
|
+
* in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
|
|
61
|
+
* leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
|
|
62
|
+
export declare const sealedKept: (sent: Json, shown: unknown, sealed: readonly string[]) => Json;
|
|
63
|
+
/** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
|
|
64
|
+
* named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
|
|
65
|
+
* the next start seals it: composio-triggers.ts sealKept). */
|
|
66
|
+
export declare const shownSource: (source: Source) => Source;
|
|
10
67
|
export declare const composio: TriggerAdapter;
|
package/dist/trigger-composio.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// that scope. Every event of the project comes to that one route, checked once with the secret (trigger-signatures.ts's
|
|
7
7
|
// composio scheme); each trigger whose instance is the delivery's metadata.trigger_id and whose `accept` takes it fires,
|
|
8
8
|
// each its own run. This is the one way Composio's events start runs: a webhook trigger takes no composio signature.
|
|
9
|
+
// A config can hold a credential (HubSpot's deal-stage event takes {app_id, developer_api_key}). Composio's trigger
|
|
10
|
+
// schemas mark no field secret (their `config` is a plain JSON schema: type, title, description, required), so a field is
|
|
11
|
+
// sealed by its name (sealedConfigFields), or as an address carrying a credential (credentialUrl): kept in this source's sealed settings, the trigger keeping SEALED_MASK in its
|
|
12
|
+
// place and the field named in `sealed_config`, so no answer, row or log holds it (composio-triggers.ts).
|
|
9
13
|
import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
|
|
10
14
|
import { closedSchema, unknownSourceFields } from "./trigger-adapter.js";
|
|
11
15
|
import { SIGNATURE_SCHEMES } from "./trigger-signatures.js";
|
|
@@ -26,6 +30,151 @@ const CONFIG_BYTES = 8 * 1024;
|
|
|
26
30
|
export const MOVE_FIELD = "move_subscription";
|
|
27
31
|
/** The settings field the project's subscription secret is sealed under, one scope per hook. */
|
|
28
32
|
export const COMPOSIO_SECRET = "secret";
|
|
33
|
+
/** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
|
|
34
|
+
* CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
|
|
35
|
+
* echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
|
|
36
|
+
export const CONFIG_SECRET = "config";
|
|
37
|
+
export const CONFIG_UNLISTED = "config_unlisted";
|
|
38
|
+
/** What a trigger keeps, and answers, in place of a sealed config value. */
|
|
39
|
+
export const SEALED_MASK = "[sealed]";
|
|
40
|
+
/** The source's field that names its sealed config fields, set by this server. */
|
|
41
|
+
export const SEALED_FIELD = "sealed_config";
|
|
42
|
+
/** The settings scope of trigger `id`'s sealed config field `field`. */
|
|
43
|
+
export const configScope = (id, field) => `config:${id}:${encodeURIComponent(field)}`;
|
|
44
|
+
/** The words of a config field's name, lower case: snake, kebab, dotted and camel case split (developerApiKey and
|
|
45
|
+
* developer_api_key both read developer, api, key). */
|
|
46
|
+
const wordsOf = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
47
|
+
/** A word of a name read as its singular: a trailing s dropped (tokens, secrets, keys), from a word of two letters or more. */
|
|
48
|
+
const singular = (word) => (word.length > 1 && word.endsWith("s") ? word.slice(0, -1) : word);
|
|
49
|
+
/** A word that names a credential wherever it stands in a name, read as its singular (credentials, tokens). */
|
|
50
|
+
const SECRET_WORDS = new Set(["secret", "password", "passwd", "passphrase", "passcode", "pwd", "pat", "token", "credential", "apikey", "hapikey", "jwt", "dsn", "sig", "authorization", "bearer", "cookie"]);
|
|
51
|
+
/** A word that, beside a credential's word, makes the name a count or size of it (max_tokens, token_count, tokens_used,
|
|
52
|
+
* tokens_per_minute, password_min_length): no credential. */
|
|
53
|
+
const COUNT_WORDS = new Set(["max", "min", "num", "number", "count", "limit", "total", "used", "usage", "budget", "remaining", "per", "length", "size", "quota"]);
|
|
54
|
+
/** Two words that name a credential together, the one after the other (connection_string); neither does alone. */
|
|
55
|
+
const SECRET_PAIRS = [["connection", "string"]];
|
|
56
|
+
/** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
|
|
57
|
+
* the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
|
|
58
|
+
* apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
|
|
59
|
+
* word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
|
|
60
|
+
* count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
|
|
61
|
+
* budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
|
|
62
|
+
export const secretConfigName = (name) => {
|
|
63
|
+
const words = wordsOf(name).map(singular);
|
|
64
|
+
const counted = (i) => COUNT_WORDS.has(words[i - 1] ?? "") || COUNT_WORDS.has(words[i + 1] ?? "");
|
|
65
|
+
return words.some((word, i) => SECRET_WORDS.has(word) && !counted(i)) || (words.at(-1) === "key" && !counted(words.length - 1)) || SECRET_PAIRS.some(([first, then]) => words.some((word, i) => word === first && words[i + 1] === then));
|
|
66
|
+
};
|
|
67
|
+
/** An address in any scheme with an authority (scheme://...): its authority, path, query and fragment, split by hand so a
|
|
68
|
+
* form a URL parser refuses (mongodb://h1:1,h2:2/db) is read too. */
|
|
69
|
+
const ADDRESS = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)[^?#]*(\?[^#]*)?(#.*)?$/is;
|
|
70
|
+
/** Whether query or fragment `part` (with its leading ? or #) has a parameter with a value named like a credential. */
|
|
71
|
+
const credentialParam = (part) => part !== undefined && [...new URLSearchParams(part.slice(1))].some(([name, given]) => given !== "" && secretConfigName(name));
|
|
72
|
+
/** An address in any scheme with an '@' after its scheme:// and before any whitespace: a user part, read so whatever a
|
|
73
|
+
* password holds (a raw '/', '?' or '#' that would end the authority early, as in mongodb://u:pa/ss@h) is still one. */
|
|
74
|
+
const USER_PART = /^[a-z][a-z0-9+.-]*:\/\/\S*@/i;
|
|
75
|
+
/** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
|
|
76
|
+
* credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
|
|
77
|
+
* before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
|
|
78
|
+
* ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
|
|
79
|
+
* name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
|
|
80
|
+
export const credentialUrl = (value) => {
|
|
81
|
+
if (USER_PART.test(value))
|
|
82
|
+
return true;
|
|
83
|
+
const parts = ADDRESS.exec(value);
|
|
84
|
+
return parts !== null && (credentialParam(parts[2]) || credentialParam(parts[3]));
|
|
85
|
+
};
|
|
86
|
+
/** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
|
|
87
|
+
* sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
|
|
88
|
+
export const sealableValue = (value) => (typeof value === "string" && value !== "") || (typeof value === "number" && Number.isFinite(value));
|
|
89
|
+
/** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
|
|
90
|
+
* is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
|
|
91
|
+
* those its event's schema marks (sealedSchemaFields). */
|
|
92
|
+
export const sealedConfigFields = (config) => isObject(config) ? Object.entries(config).filter(([name, value]) => (sealableValue(value) && secretConfigName(name)) || (typeof value === "string" && credentialUrl(value))).map(([name]) => name) : [];
|
|
93
|
+
/** The JSON Schema types a credential's value may have. */
|
|
94
|
+
const SEALABLE_TYPES = ["string", "number", "integer"];
|
|
95
|
+
/** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
|
|
96
|
+
* or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
|
|
97
|
+
* of those, or says none). What the console's form takes as a password. */
|
|
98
|
+
export const sealedSchemaFields = (schema) => {
|
|
99
|
+
const properties = isObject(schema) && isObject(schema.properties) ? schema.properties : {};
|
|
100
|
+
return Object.entries(properties).filter(([name, property]) => {
|
|
101
|
+
if (isObject(property) && (property.format === "password" || property.writeOnly === true))
|
|
102
|
+
return true;
|
|
103
|
+
const type = isObject(property) ? property.type : undefined;
|
|
104
|
+
return secretConfigName(name) && (type === undefined || SEALABLE_TYPES.includes(String(type)) || (Array.isArray(type) && type.some((one) => SEALABLE_TYPES.includes(String(one)))));
|
|
105
|
+
}).map(([name]) => name);
|
|
106
|
+
};
|
|
107
|
+
const pointerOf = (path) => `/${path.map((key) => key.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
|
|
108
|
+
/** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
|
|
109
|
+
* number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
|
|
110
|
+
* object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
|
|
111
|
+
* at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
|
|
112
|
+
export const configSecrets = (config) => {
|
|
113
|
+
const found = [];
|
|
114
|
+
const walk = (node, path, named) => {
|
|
115
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
116
|
+
if ((named || (typeof node === "string" && credentialUrl(node))) && sealableValue(node) && node !== SEALED_MASK)
|
|
117
|
+
found.push({ name: path.length === 1 ? path[0] : pointerOf(path), path, value: node });
|
|
118
|
+
}
|
|
119
|
+
else if (Array.isArray(node))
|
|
120
|
+
node.forEach((item, i) => walk(item, [...path, String(i)], named));
|
|
121
|
+
else if (isObject(node))
|
|
122
|
+
for (const [key, item] of Object.entries(node))
|
|
123
|
+
walk(item, [...path, key], named || secretConfigName(key));
|
|
124
|
+
};
|
|
125
|
+
if (isObject(config))
|
|
126
|
+
for (const [key, item] of Object.entries(config))
|
|
127
|
+
walk(item, [key], secretConfigName(key));
|
|
128
|
+
return found;
|
|
129
|
+
};
|
|
130
|
+
/** `config` with each of `secrets` as SEALED_MASK, at its place. */
|
|
131
|
+
const maskedConfig = (config, secrets) => {
|
|
132
|
+
const copy = structuredClone(config);
|
|
133
|
+
for (const { path } of secrets) {
|
|
134
|
+
let node = copy;
|
|
135
|
+
for (const key of path.slice(0, -1))
|
|
136
|
+
node = node[key];
|
|
137
|
+
node[path.at(-1)] = SEALED_MASK;
|
|
138
|
+
}
|
|
139
|
+
return copy;
|
|
140
|
+
};
|
|
141
|
+
/** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
|
|
142
|
+
* in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
|
|
143
|
+
* leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
|
|
144
|
+
export const sealedKept = (sent, shown, sealed) => {
|
|
145
|
+
const names = new Set(sealed);
|
|
146
|
+
const places = [];
|
|
147
|
+
const walk = (node, path) => {
|
|
148
|
+
if (path.length && names.has(path.length === 1 ? path[0] : pointerOf(path)))
|
|
149
|
+
places.push(path);
|
|
150
|
+
else if (Array.isArray(node))
|
|
151
|
+
node.forEach((item, i) => walk(item, [...path, String(i)]));
|
|
152
|
+
else if (isObject(node))
|
|
153
|
+
for (const [key, item] of Object.entries(node))
|
|
154
|
+
walk(item, [...path, key]);
|
|
155
|
+
};
|
|
156
|
+
walk(shown, []);
|
|
157
|
+
const copy = structuredClone(sent);
|
|
158
|
+
for (const path of places) {
|
|
159
|
+
let node = copy;
|
|
160
|
+
for (const key of path.slice(0, -1))
|
|
161
|
+
node = isObject(node) ? node[key] : undefined;
|
|
162
|
+
if (isObject(node) && node[path.at(-1)] === undefined)
|
|
163
|
+
node[path.at(-1)] = SEALED_MASK;
|
|
164
|
+
}
|
|
165
|
+
return copy;
|
|
166
|
+
};
|
|
167
|
+
/** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
|
|
168
|
+
* named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
|
|
169
|
+
* the next start seals it: composio-triggers.ts sealKept). */
|
|
170
|
+
export const shownSource = (source) => {
|
|
171
|
+
const config = source.config;
|
|
172
|
+
const clear = configSecrets(config);
|
|
173
|
+
if (!clear.length || !isObject(config))
|
|
174
|
+
return source;
|
|
175
|
+
const sealed = Array.isArray(source[SEALED_FIELD]) ? source[SEALED_FIELD] : [];
|
|
176
|
+
return { ...source, config: maskedConfig(config, clear), [SEALED_FIELD]: [...new Set([...sealed, ...clear.map((secret) => secret.name)])] };
|
|
177
|
+
};
|
|
29
178
|
const jsonOf = (text) => {
|
|
30
179
|
try {
|
|
31
180
|
return JSON.parse(text);
|
|
@@ -39,7 +188,7 @@ const jsonOf = (text) => {
|
|
|
39
188
|
function fieldsOf(value, bad) {
|
|
40
189
|
let failed = false;
|
|
41
190
|
const fail = (...args) => ((failed = true), bad(...args));
|
|
42
|
-
const { server, event, config, instance_id: instance, hook } = value;
|
|
191
|
+
const { server, event, config, instance_id: instance, hook, [SEALED_FIELD]: sealed } = value;
|
|
43
192
|
if (typeof server !== "string" || !MCP_SERVER_NAME.test(server))
|
|
44
193
|
fail("server", server === undefined ? "missing" : "invalid", "server is the name of a saved Composio MCP server (Settings → MCP servers), whose key and account the trigger uses");
|
|
45
194
|
if (typeof event !== "string" || !COMPOSIO_EVENT.test(event))
|
|
@@ -50,6 +199,8 @@ function fieldsOf(value, bad) {
|
|
|
50
199
|
fail("instance_id", "invalid", "instance_id is Composio's id for the trigger's instance, set by this server");
|
|
51
200
|
if (hook !== undefined && !(typeof hook === "string" && COMPOSIO_HOOK.test(hook)))
|
|
52
201
|
fail("hook", "invalid", "hook is the id of the project's route here, set by this server");
|
|
202
|
+
if (sealed !== undefined && !(Array.isArray(sealed) && sealed.length <= 100 && sealed.every((name) => typeof name === "string" && name.length <= 200)))
|
|
203
|
+
fail(SEALED_FIELD, "invalid", `${SEALED_FIELD} names the config's sealed fields, set by this server`);
|
|
53
204
|
if (value[MOVE_FIELD] !== undefined && value[MOVE_FIELD] !== true)
|
|
54
205
|
fail(MOVE_FIELD, "invalid", `${MOVE_FIELD} is true, or left out`);
|
|
55
206
|
const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
|
|
@@ -59,7 +210,7 @@ function fieldsOf(value, bad) {
|
|
|
59
210
|
return undefined;
|
|
60
211
|
return {
|
|
61
212
|
kind: "composio", server: server, event: event, config: config,
|
|
62
|
-
...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
|
|
213
|
+
...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(Array.isArray(sealed) ? { [SEALED_FIELD]: sealed } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
|
|
63
214
|
};
|
|
64
215
|
}
|
|
65
216
|
export const composio = {
|
|
@@ -67,8 +218,9 @@ export const composio = {
|
|
|
67
218
|
label: "Composio trigger",
|
|
68
219
|
delivery: "push",
|
|
69
220
|
owner: false,
|
|
70
|
-
// Each project's subscription secret, Composio's own, sealed under its hook's scope
|
|
71
|
-
|
|
221
|
+
// Each project's subscription secret, Composio's own, sealed under its hook's scope, and each trigger's sealed config
|
|
222
|
+
// value under its own (configScope): composio-triggers.ts keeps them.
|
|
223
|
+
settings: { scope: "server", fields: { [COMPOSIO_SECRET]: {}, [CONFIG_SECRET]: {}, [CONFIG_UNLISTED]: { public: true } } },
|
|
72
224
|
describe: '{kind: "composio", server, event, config, accept?: [{event, where?}], move_subscription?: true}',
|
|
73
225
|
fires: "an event of a saved Composio server's toolkit that Composio delivers to /hooks/composio/{hook} for the trigger's instance, that its `accept` takes (`composio`)",
|
|
74
226
|
firedBy: "`composio`: an event Composio delivered for the trigger's instance (the delivery's metadata.trigger_id) that its accept took, its key from the trigger and the delivery's `webhook-id`.",
|
|
@@ -77,18 +229,20 @@ export const composio = {
|
|
|
77
229
|
kind: { const: "composio" },
|
|
78
230
|
server: { type: "string", pattern: MCP_SERVER_NAME.source, description: "A saved Composio MCP server (Settings → MCP servers): its key makes the instance, for the account it is connected as." },
|
|
79
231
|
event: { type: "string", pattern: COMPOSIO_EVENT.source, description: "One of the server's toolkit's events, Composio's trigger slug (GET /settings/mcp-servers/{name}/composio/events)." },
|
|
80
|
-
config: { type: "object", description:
|
|
232
|
+
config: { type: "object", description: `The event's config, as its schema in the events list says (GitHub's new-issue event: {owner, repo}). A field named like a credential (a word of its name, read as its singular, is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential, apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie, unless a count word (max, min, num, number, count, limit, total, used, usage, budget, remaining, per, length, size, quota) is right beside it: max_tokens and token_count are counts; it has connection then string; or its last word is key: developer_api_key, api_keys), or one the event's schema marks with format: password or writeOnly, holding a string or a number, is sealed at the save, as is any http(s) address with a password in its user part or a query parameter so named with a value: Composio gets it, and every answer has "${SEALED_MASK}" in its place, the field named in ${SEALED_FIELD}. One below the config's top level is refused 422. A PATCH that leaves it out or sends "${SEALED_MASK}" keeps it; another value is a change to the config, refused as any is.` },
|
|
81
233
|
}, {
|
|
82
234
|
accept: { ...ACCEPT_SCHEMA, description: "Optional: which of the event's deliveries fire it. A rule's `event` is the trigger's own, `where` pointers read the delivery, its event's data under `/data` (`/data/title`). None: every delivery for its instance fires." },
|
|
83
235
|
instance_id: { type: "string", readOnly: true, description: "Composio's id for the trigger's instance, set by this server when it makes it: the delivery's metadata.trigger_id. Triggers with the same server, event and config share one." },
|
|
236
|
+
[SEALED_FIELD]: { type: "array", items: { type: "string" }, readOnly: true, description: `The config's sealed fields, set by this server at the save: each answered as "${SEALED_MASK}", its value kept sealed here. Each is a top-level field's name, or, for one an earlier server kept below the top level, its JSON Pointer (/auth/api_key).` },
|
|
84
237
|
hook: { type: "string", pattern: COMPOSIO_HOOK.source, readOnly: true, description: "The id of the project's route here, /hooks/composio/{hook}, set by this server: the address of the project's webhook subscription on Composio." },
|
|
85
238
|
[MOVE_FIELD]: { type: "boolean", enum: [true], writeOnly: true, description: "At a create alone, never kept: the project's webhook subscription is at another address, and the owner moves it here. Without it, such a create is refused 409 composio_subscription_elsewhere, naming the address." },
|
|
86
239
|
}),
|
|
87
240
|
],
|
|
88
241
|
parse(value, _now, bad, issues) {
|
|
89
|
-
issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", MOVE_FIELD]));
|
|
242
|
+
issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", SEALED_FIELD, MOVE_FIELD]));
|
|
90
243
|
return fieldsOf(value, bad);
|
|
91
244
|
},
|
|
245
|
+
shown: shownSource,
|
|
92
246
|
wellFormed: (source) => {
|
|
93
247
|
const read = fieldsOf(source, () => { });
|
|
94
248
|
return read !== undefined && typeof read.instance_id === "string" && typeof read.hook === "string";
|
package/dist/triggers.d.ts
CHANGED
|
@@ -358,6 +358,7 @@ export declare class Triggers {
|
|
|
358
358
|
name: string;
|
|
359
359
|
enabled: boolean;
|
|
360
360
|
source: Source;
|
|
361
|
+
updatedAt: number;
|
|
361
362
|
}[]>;
|
|
362
363
|
/** Every trigger of source `kind` that is on, turned off because the connection it needs is gone (`disabled: {reason:
|
|
363
364
|
* "connection_lost", detail}`), and said; how many. They are kept: on again once it is back. */
|
|
@@ -439,6 +440,9 @@ export declare class Triggers {
|
|
|
439
440
|
} | null | undefined;
|
|
440
441
|
hook_url?: string | undefined;
|
|
441
442
|
}>;
|
|
443
|
+
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
444
|
+
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
445
|
+
private updateOnce;
|
|
442
446
|
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds). */
|
|
443
447
|
remove(id: string): Promise<Json | undefined>;
|
|
444
448
|
/** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
|
package/dist/triggers.js
CHANGED
|
@@ -101,6 +101,8 @@ const REAL_CLOCK = {
|
|
|
101
101
|
},
|
|
102
102
|
};
|
|
103
103
|
const iso = (ms) => new Date(ms).toISOString();
|
|
104
|
+
/** How many times a PATCH carrying a source is checked again when the trigger changed between its read and its write. */
|
|
105
|
+
const SOURCE_EDIT_TRIES = 3;
|
|
104
106
|
export const firingKey = (by, triggerId, what) => `fir_${createHash("sha256").update(`${by}\n${triggerId}\n${what}`).digest("hex").slice(0, 32)}`;
|
|
105
107
|
/** The adapter of `kind`, among `adapters`. */
|
|
106
108
|
const adapterIn = (adapters, kind) => adapters.find((a) => a.id === kind);
|
|
@@ -348,7 +350,7 @@ export class Triggers {
|
|
|
348
350
|
/** Every trigger of source `kind`, on or off, with its name and source: what a source's sender keeps of them is shared
|
|
349
351
|
* between some (composio-triggers.ts: one Composio instance per server, event and config). */
|
|
350
352
|
async ofKind(kind) {
|
|
351
|
-
return (await this.store.triggers.all()).map(asTrigger).filter((t) => t.source.kind === kind).map((t) => ({ id: t.id, name: t.name, enabled: t.enabled, source: t.source }));
|
|
353
|
+
return (await this.store.triggers.all()).map(asTrigger).filter((t) => t.source.kind === kind).map((t) => ({ id: t.id, name: t.name, enabled: t.enabled, source: t.source, updatedAt: t.updatedAt }));
|
|
352
354
|
}
|
|
353
355
|
/** Every trigger of source `kind` that is on, turned off because the connection it needs is gone (`disabled: {reason:
|
|
354
356
|
* "connection_lost", detail}`), and said; how many. They are kept: on again once it is back. */
|
|
@@ -440,6 +442,18 @@ export class Triggers {
|
|
|
440
442
|
* paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
|
|
441
443
|
* the target's check is done: an edit made meanwhile keeps its own. */
|
|
442
444
|
async update(id, body) {
|
|
445
|
+
// A source is written only on the row it was checked against (its updatedAt): another write meanwhile (the
|
|
446
|
+
// after-start seal's, a poll's next time) checks it again on the row as it is then, so a source read before a seal
|
|
447
|
+
// never writes the clear value back over it.
|
|
448
|
+
for (let tries = 1;; tries++) {
|
|
449
|
+
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES);
|
|
450
|
+
if (done)
|
|
451
|
+
return done;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
455
|
+
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
456
|
+
async updateOnce(id, body, retry) {
|
|
443
457
|
const was = await this.need(id);
|
|
444
458
|
const issues = unknownFields(body, WRITABLE);
|
|
445
459
|
let source = body.source === undefined ? undefined : sourceOf(this.adapters, body.source, this.clock.now(), issues);
|
|
@@ -497,9 +511,14 @@ export class Triggers {
|
|
|
497
511
|
...(settings.catchup_window_s !== undefined ? { catchupWindowS: settings.catchup_window_s } : {}),
|
|
498
512
|
...(settings.max_active_runs !== undefined ? { maxActiveRuns: settings.max_active_runs } : {}), ...again, enabled, nextAt: next,
|
|
499
513
|
};
|
|
500
|
-
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : []).catch(async (error) => {
|
|
514
|
+
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : [], source ? { ifUpdatedAt: trigger.updatedAt, ifSource: trigger.source } : undefined).catch(async (error) => {
|
|
501
515
|
throw (await this.scopeTaken(error, scopeSource, trigger.id)) ?? (await this.archivedRefusal(error)) ?? nameTaken(error, patch.name ?? trigger.name);
|
|
502
516
|
});
|
|
517
|
+
if (!row && source && (await this.store.triggers.get(id))) {
|
|
518
|
+
if (retry)
|
|
519
|
+
return undefined;
|
|
520
|
+
throw new ApiError("precondition_failed", "the trigger kept changing while this edit was checked: read it again, then send the edit again");
|
|
521
|
+
}
|
|
503
522
|
if (!row)
|
|
504
523
|
throw new ApiError("not_found", `no trigger ${id}`);
|
|
505
524
|
// Turned on again, a polled source forgets its cursor and last check, so its first poll watches from now, and is
|
|
@@ -1120,7 +1139,7 @@ export class Triggers {
|
|
|
1120
1139
|
return {
|
|
1121
1140
|
...(hook ? { hook_url: `${this.deps.publicUrl ?? ""}${hook}` } : {}),
|
|
1122
1141
|
...(adapter?.poll ? { last_check: check ? { at: check.at, ok: check.ok, message: check.message } : null } : {}),
|
|
1123
|
-
id: trigger.id, name: trigger.name, enabled: trigger.enabled, source: trigger.source, target: trigger.target, catchup_window_s: trigger.catchupWindowS ?? CATCHUP_WINDOW_S,
|
|
1142
|
+
id: trigger.id, name: trigger.name, enabled: trigger.enabled, source: adapter?.shown ? adapter.shown(trigger.source) : trigger.source, target: trigger.target, catchup_window_s: trigger.catchupWindowS ?? CATCHUP_WINDOW_S,
|
|
1124
1143
|
max_active_runs: trigger.maxActiveRuns ?? null, failures_in_a_row: trigger.failuresInARow, disabled: trigger.disabled ?? null, next_at: trigger.nextAt === null ? null : iso(trigger.nextAt), last_run_id: trigger.lastRunId,
|
|
1125
1144
|
created_at: iso(trigger.createdAt), updated_at: iso(trigger.updatedAt), last_firing: last ? firingView(last) : null,
|
|
1126
1145
|
};
|
package/dist/validate.d.ts
CHANGED
|
@@ -28,10 +28,12 @@ export declare const skillNames: (files: Iterable<string>) => string[];
|
|
|
28
28
|
/**
|
|
29
29
|
* A definition as `POST /agents` and `PUT .../definition` take it: what one revision of an agent keeps. `instructions`
|
|
30
30
|
* makes an agentic revision, `workflow` (an agentrun-dsl workflow) a workflow revision. `creating` asks for a name.
|
|
31
|
+
* `harnesses`: the ids `harness` may name, the server's table's (harness-table.ts harnessIds); the built-in ones by default.
|
|
31
32
|
*/
|
|
32
|
-
export declare function definitionIssues(definition: unknown, { at, creating }?: {
|
|
33
|
-
at?: string
|
|
34
|
-
creating?: boolean
|
|
33
|
+
export declare function definitionIssues(definition: unknown, { at, creating, harnesses }?: {
|
|
34
|
+
at?: string;
|
|
35
|
+
creating?: boolean;
|
|
36
|
+
harnesses?: readonly string[];
|
|
35
37
|
}): InputIssue[];
|
|
36
38
|
/** A definition's skill names against the files its revision holds: each named skill has its SKILL.md, and each
|
|
37
39
|
* SKILL.md is named. */
|
|
@@ -42,16 +44,18 @@ export type DefinitionBody = {
|
|
|
42
44
|
note?: string;
|
|
43
45
|
};
|
|
44
46
|
/** What is wrong with `{definition, skills?, note?}`, as checkDefinitionBody refuses it: every field issue. */
|
|
45
|
-
export declare function definitionBodyIssues(body: Json, { creating }?: {
|
|
46
|
-
creating?: boolean
|
|
47
|
+
export declare function definitionBodyIssues(body: Json, { creating, harnesses }?: {
|
|
48
|
+
creating?: boolean;
|
|
49
|
+
harnesses?: readonly string[];
|
|
47
50
|
}): InputIssue[];
|
|
48
51
|
/**
|
|
49
52
|
* `{definition, skills?, note?}`, as `POST /agents` and `PUT .../definition` take it. `skills` are the revision's skill
|
|
50
53
|
* files (absent on an edit: the current revision's); `note` says what the revision changes. Throws `422 input_invalid`
|
|
51
54
|
* naming every field that is wrong.
|
|
52
55
|
*/
|
|
53
|
-
export declare function checkDefinitionBody(body: Json, { creating }?: {
|
|
54
|
-
creating?: boolean
|
|
56
|
+
export declare function checkDefinitionBody(body: Json, { creating, harnesses }?: {
|
|
57
|
+
creating?: boolean;
|
|
58
|
+
harnesses?: readonly string[];
|
|
55
59
|
}): DefinitionBody;
|
|
56
60
|
/** The default input schema: `{content: string}`. */
|
|
57
61
|
export declare const DEFAULT_INPUT_SCHEMA: {
|
package/dist/validate.js
CHANGED
|
@@ -57,8 +57,9 @@ export const skillNames = (files) => [...files].filter((path) => path.endsWith(S
|
|
|
57
57
|
/**
|
|
58
58
|
* A definition as `POST /agents` and `PUT .../definition` take it: what one revision of an agent keeps. `instructions`
|
|
59
59
|
* makes an agentic revision, `workflow` (an agentrun-dsl workflow) a workflow revision. `creating` asks for a name.
|
|
60
|
+
* `harnesses`: the ids `harness` may name, the server's table's (harness-table.ts harnessIds); the built-in ones by default.
|
|
60
61
|
*/
|
|
61
|
-
export function definitionIssues(definition, { at = "definition", creating = true } = {}) {
|
|
62
|
+
export function definitionIssues(definition, { at = "definition", creating = true, harnesses = HARNESSES } = {}) {
|
|
62
63
|
if (!isObject(definition))
|
|
63
64
|
return [issue(at, definition === undefined ? "missing" : "wrong_type", `${at} is not an object`)];
|
|
64
65
|
const out = [];
|
|
@@ -105,8 +106,8 @@ export function definitionIssues(definition, { at = "definition", creating = tru
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
if (d.harness !== undefined && !
|
|
109
|
-
out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${
|
|
109
|
+
if (d.harness !== undefined && !harnesses.includes(d.harness))
|
|
110
|
+
out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${harnesses.join(", ")}`));
|
|
110
111
|
if (d.place !== undefined)
|
|
111
112
|
out.push(...placeIssues(d.place, `${at}.place`));
|
|
112
113
|
if (d.computer !== undefined)
|
|
@@ -202,12 +203,12 @@ export function skillIssues(named, files) {
|
|
|
202
203
|
];
|
|
203
204
|
}
|
|
204
205
|
/** What is wrong with `{definition, skills?, note?}`, as checkDefinitionBody refuses it: every field issue. */
|
|
205
|
-
export function definitionBodyIssues(body, { creating = true } = {}) {
|
|
206
|
+
export function definitionBodyIssues(body, { creating = true, harnesses } = {}) {
|
|
206
207
|
const out = [];
|
|
207
208
|
for (const key of Object.keys(body))
|
|
208
209
|
if (!["definition", "skills", "note"].includes(key))
|
|
209
210
|
out.push(issue(key, "not_allowed", `The body keeps no field ${key}.`, `Remove ${key}.`));
|
|
210
|
-
out.push(...definitionIssues(body.definition, { creating }));
|
|
211
|
+
out.push(...definitionIssues(body.definition, { creating, ...(harnesses ? { harnesses } : {}) }));
|
|
211
212
|
if (body.skills !== undefined || creating)
|
|
212
213
|
skillFileIssues(body.skills ?? {}, out);
|
|
213
214
|
if (body.note !== undefined && !(typeof body.note === "string" && body.note.length <= 2_000))
|
|
@@ -219,8 +220,8 @@ export function definitionBodyIssues(body, { creating = true } = {}) {
|
|
|
219
220
|
* files (absent on an edit: the current revision's); `note` says what the revision changes. Throws `422 input_invalid`
|
|
220
221
|
* naming every field that is wrong.
|
|
221
222
|
*/
|
|
222
|
-
export function checkDefinitionBody(body, { creating = true } = {}) {
|
|
223
|
-
const out = definitionBodyIssues(body, { creating });
|
|
223
|
+
export function checkDefinitionBody(body, { creating = true, harnesses } = {}) {
|
|
224
|
+
const out = definitionBodyIssues(body, { creating, ...(harnesses ? { harnesses } : {}) });
|
|
224
225
|
if (out.length)
|
|
225
226
|
throw invalid(out);
|
|
226
227
|
return { definition: body.definition, ...(body.skills !== undefined || creating ? { skills: (body.skills ?? {}) } : {}), ...(typeof body.note === "string" ? { note: body.note } : {}) };
|
|
@@ -115,11 +115,12 @@ export interface ComputerForClaimDeps {
|
|
|
115
115
|
readonly revokeMount?: () => Promise<void>;
|
|
116
116
|
/** The live view's registration for a desktop or a phone (proxy-only). Absent: no view is opened. */
|
|
117
117
|
readonly openComputerView?: OpenComputerView;
|
|
118
|
-
/** Where the agent's setting asks for a video of its
|
|
118
|
+
/** Where the agent's setting asks for a video of its computer's screen (computer.record): the run's
|
|
119
119
|
* recordings folder on this machine (paths.ts recordingsFolder) and where its lines on the run's timeline go
|
|
120
|
-
* (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The
|
|
121
|
-
* attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's
|
|
122
|
-
* park
|
|
120
|
+
* (computer-record.ts startRecording; for tests, the program in ffmpeg's place and the bounds). The desktop or phone
|
|
121
|
+
* this claim attaches is recorded through a watch of its own, with or without a viewer, until its release, the run's
|
|
122
|
+
* end or its park; a browser's sessions each by the run's browser tool, through its ClaimBrowser's `record`. Absent:
|
|
123
|
+
* nothing is recorded. */
|
|
123
124
|
readonly recordings?: Pick<RecordInput, "folder" | "say" | "ffmpeg" | "limits">;
|
|
124
125
|
/** Told once, before the claim waits on its computer's image (a provider that makes its own: Docker's recipe built on
|
|
125
126
|
* a host that lacks it, or a named image pulled); never when the host has it. The run's caller says it on the run's
|
|
@@ -144,8 +145,17 @@ export interface ComputerForClaimDeps {
|
|
|
144
145
|
* it refuses is refused with code computer_unavailable before anything is made. Absent: every kind. */
|
|
145
146
|
readonly refuseKind?: (kind: Exclude<ComputerSettingKind, "none">) => string | undefined;
|
|
146
147
|
/** Told what became of the agent's own computer at the claim (a persistent setting): made, attached from an earlier
|
|
147
|
-
* run, or made again because the one this server kept is gone
|
|
148
|
+
* run, or made again because the one this server kept is gone; and when a sandbox the claim made was lost mid-run and
|
|
149
|
+
* a new one started in its place (computer-lost.ts lostRecreatedWords). The run's caller says it on the run's
|
|
150
|
+
* timeline. */
|
|
148
151
|
readonly onComputerNote?: (words: string) => void;
|
|
152
|
+
/** The most new sandboxes the claim starts in place of ones its provider lost mid-run (lostAware); the next loss past
|
|
153
|
+
* them ends the run, code computer_unavailable. Default LOST_RECREATES (2). */
|
|
154
|
+
readonly recreates?: number;
|
|
155
|
+
/** Stops the run for good in `words`, from any caller (paid-calls.ts stopRunWith over the run's ledger's pause): how a
|
|
156
|
+
* loss past `recreates` ends the run, whoever's call found it (the owner's computer channel too). Absent: the ledger
|
|
157
|
+
* of the tool call that found it (stopRun), and a loss found outside one stops nothing. */
|
|
158
|
+
readonly stopRun?: (words: string) => Promise<void>;
|
|
149
159
|
/** Whether the run's journal says an earlier claim made the run a computer of its own (ClaimComputer.made, recorded by
|
|
150
160
|
* the adapter loop: computer-journal.ts hadComputer): asked at a later claim that makes a fresh one, before anything
|
|
151
161
|
* is rented, so a claim that finds no older computer of the run to let go (the earlier claim let its own go at its
|