@intentic/sandbox-contract 1.394.0 → 1.396.0
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/README.md +20 -2
- package/dist/app-routes/app-pages.d.ts +97 -0
- package/dist/app-routes/app-pages.d.ts.map +1 -0
- package/dist/app-routes/app-pages.js +71 -0
- package/dist/app-routes/app-pages.js.map +1 -0
- package/dist/app-routes/index.d.ts +5 -0
- package/dist/app-routes/index.d.ts.map +1 -0
- package/dist/app-routes/index.js +5 -0
- package/dist/app-routes/index.js.map +1 -0
- package/dist/app-routes/legacy.d.ts +10 -0
- package/dist/app-routes/legacy.d.ts.map +1 -0
- package/dist/app-routes/legacy.js +92 -0
- package/dist/app-routes/legacy.js.map +1 -0
- package/dist/app-routes/paths.d.ts +38 -0
- package/dist/app-routes/paths.d.ts.map +1 -0
- package/dist/app-routes/paths.js +89 -0
- package/dist/app-routes/paths.js.map +1 -0
- package/dist/app-routes/patterns.d.ts +5 -0
- package/dist/app-routes/patterns.d.ts.map +1 -0
- package/dist/app-routes/patterns.js +94 -0
- package/dist/app-routes/patterns.js.map +1 -0
- package/dist/chores/stack.d.ts.map +1 -1
- package/dist/chores/stack.js +13 -2
- package/dist/chores/stack.js.map +1 -1
- package/dist/contracts/agent.contract.d.ts +115 -0
- package/dist/contracts/agent.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.d.ts +1300 -11
- package/dist/contracts/agents.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.js +12 -2
- package/dist/contracts/agents.contract.js.map +1 -1
- package/dist/contracts/capabilities.contract.d.ts +8 -0
- package/dist/contracts/capabilities.contract.d.ts.map +1 -1
- package/dist/contracts/endpoints.contract.d.ts +45 -0
- package/dist/contracts/endpoints.contract.d.ts.map +1 -1
- package/dist/contracts/endpoints.contract.js +9 -0
- package/dist/contracts/endpoints.contract.js.map +1 -1
- package/dist/contracts/git.contract.d.ts +5 -0
- package/dist/contracts/git.contract.d.ts.map +1 -1
- package/dist/contracts/org.contract.d.ts +8 -0
- package/dist/contracts/org.contract.d.ts.map +1 -1
- package/dist/contracts/runner.contract.d.ts +2765 -11
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/runner.contract.js +4 -1
- package/dist/contracts/runner.contract.js.map +1 -1
- package/dist/contracts/seal.contract.d.ts +2760 -0
- package/dist/contracts/seal.contract.d.ts.map +1 -0
- package/dist/contracts/seal.contract.js +95 -0
- package/dist/contracts/seal.contract.js.map +1 -0
- package/dist/contracts/sessions.contract.d.ts +16 -0
- package/dist/contracts/sessions.contract.d.ts.map +1 -1
- package/dist/contracts/settings.contract.d.ts +89 -2
- package/dist/contracts/settings.contract.d.ts.map +1 -1
- package/dist/contracts/settings.contract.js +21 -3
- package/dist/contracts/settings.contract.js.map +1 -1
- package/dist/contracts/system.contract.d.ts +419 -62
- package/dist/contracts/system.contract.d.ts.map +1 -1
- package/dist/contracts/webext.contract.d.ts +4 -0
- package/dist/contracts/webext.contract.d.ts.map +1 -1
- package/dist/contracts/workspace.contract.d.ts +6 -0
- package/dist/contracts/workspace.contract.d.ts.map +1 -1
- package/dist/contracts/workspace.contract.js +11 -1
- package/dist/contracts/workspace.contract.js.map +1 -1
- package/dist/events/agent-events.d.ts +80 -1
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-events.js +16 -0
- package/dist/events/agent-events.js.map +1 -1
- package/dist/events/agent-transcript.d.ts +16 -0
- package/dist/events/agent-transcript.d.ts.map +1 -1
- package/dist/events/requests.d.ts +2 -0
- package/dist/events/requests.d.ts.map +1 -1
- package/dist/events/requests.js +4 -0
- package/dist/events/requests.js.map +1 -1
- package/dist/events/system-events.d.ts +292 -62
- package/dist/events/system-events.d.ts.map +1 -1
- package/dist/events/system-events.js +3 -0
- package/dist/events/system-events.js.map +1 -1
- package/dist/events/transcript.d.ts +96 -0
- package/dist/events/transcript.d.ts.map +1 -1
- package/dist/events/transcript.js +7 -1
- package/dist/events/transcript.js.map +1 -1
- package/dist/ids/row-ids.d.ts.map +1 -1
- package/dist/ids/row-ids.js +7 -2
- package/dist/ids/row-ids.js.map +1 -1
- package/dist/index.d.ts +107 -34346
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/models/model-roles.d.ts +8 -0
- package/dist/models/model-roles.d.ts.map +1 -1
- package/dist/models/model-roles.js +8 -0
- package/dist/models/model-roles.js.map +1 -1
- package/dist/policy/org-locks.d.ts +1 -1
- package/dist/policy/org-locks.d.ts.map +1 -1
- package/dist/policy/org-locks.js +9 -1
- package/dist/policy/org-locks.js.map +1 -1
- package/dist/policy/request-status.d.ts.map +1 -1
- package/dist/policy/request-status.js +26 -10
- package/dist/policy/request-status.js.map +1 -1
- package/dist/protocol/doors/runner-protocol.d.ts +18 -0
- package/dist/protocol/doors/runner-protocol.d.ts.map +1 -1
- package/dist/protocol/doors/runner-protocol.js +15 -1
- package/dist/protocol/doors/runner-protocol.js.map +1 -1
- package/dist/protocol/raw/raw-json-routes.d.ts +6 -0
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/protocol/routes.d.ts +6 -0
- package/dist/protocol/routes.d.ts.map +1 -1
- package/dist/protocol/routes.js +64 -8
- package/dist/protocol/routes.js.map +1 -1
- package/dist/protocol/sse.d.ts.map +1 -1
- package/dist/protocol/sse.js +5 -1
- package/dist/protocol/sse.js.map +1 -1
- package/dist/schemas/agent-land.d.ts +78 -0
- package/dist/schemas/agent-land.d.ts.map +1 -0
- package/dist/schemas/agent-land.js +47 -0
- package/dist/schemas/agent-land.js.map +1 -0
- package/dist/schemas/agent.d.ts +4 -0
- package/dist/schemas/agent.d.ts.map +1 -1
- package/dist/schemas/agent.js +1 -0
- package/dist/schemas/agent.js.map +1 -1
- package/dist/schemas/agents-list.d.ts +130 -0
- package/dist/schemas/agents-list.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +196 -76
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/agents.js +5 -46
- package/dist/schemas/agents.js.map +1 -1
- package/dist/schemas/capabilities.d.ts +4 -0
- package/dist/schemas/capabilities.d.ts.map +1 -1
- package/dist/schemas/commit-attribution.d.ts +41 -0
- package/dist/schemas/commit-attribution.d.ts.map +1 -0
- package/dist/schemas/commit-attribution.js +16 -0
- package/dist/schemas/commit-attribution.js.map +1 -0
- package/dist/schemas/composer-drafts.d.ts +19 -0
- package/dist/schemas/composer-drafts.d.ts.map +1 -1
- package/dist/schemas/composer-drafts.js +10 -0
- package/dist/schemas/composer-drafts.js.map +1 -1
- package/dist/schemas/environment.d.ts +12 -0
- package/dist/schemas/environment.d.ts.map +1 -1
- package/dist/schemas/environment.js +1 -0
- package/dist/schemas/environment.js.map +1 -1
- package/dist/schemas/git/git-history.d.ts +10 -0
- package/dist/schemas/git/git-history.d.ts.map +1 -1
- package/dist/schemas/git/git-history.js +8 -0
- package/dist/schemas/git/git-history.js.map +1 -1
- package/dist/schemas/gpu-settings.d.ts +15 -0
- package/dist/schemas/gpu-settings.d.ts.map +1 -0
- package/dist/schemas/gpu-settings.js +18 -0
- package/dist/schemas/gpu-settings.js.map +1 -0
- package/dist/schemas/night-hours.d.ts +31 -0
- package/dist/schemas/night-hours.d.ts.map +1 -0
- package/dist/schemas/night-hours.js +33 -0
- package/dist/schemas/night-hours.js.map +1 -0
- package/dist/schemas/organisation.d.ts +33 -0
- package/dist/schemas/organisation.d.ts.map +1 -1
- package/dist/schemas/organisation.js +9 -0
- package/dist/schemas/organisation.js.map +1 -1
- package/dist/schemas/privacy.d.ts +1 -0
- package/dist/schemas/privacy.d.ts.map +1 -1
- package/dist/schemas/privacy.js +1 -0
- package/dist/schemas/privacy.js.map +1 -1
- package/dist/schemas/providers/plan-limits.d.ts +16 -0
- package/dist/schemas/providers/plan-limits.d.ts.map +1 -1
- package/dist/schemas/providers/plan-limits.js +3 -0
- package/dist/schemas/providers/plan-limits.js.map +1 -1
- package/dist/schemas/sandbox-mode.d.ts +20 -0
- package/dist/schemas/sandbox-mode.d.ts.map +1 -0
- package/dist/schemas/sandbox-mode.js +54 -0
- package/dist/schemas/sandbox-mode.js.map +1 -0
- package/dist/schemas/seal-proof.d.ts +20 -0
- package/dist/schemas/seal-proof.d.ts.map +1 -0
- package/dist/schemas/seal-proof.js +8 -0
- package/dist/schemas/seal-proof.js.map +1 -0
- package/dist/schemas/seal.d.ts +235 -0
- package/dist/schemas/seal.d.ts.map +1 -0
- package/dist/schemas/seal.js +97 -0
- package/dist/schemas/seal.js.map +1 -0
- package/dist/schemas/settings-experiments.d.ts.map +1 -1
- package/dist/schemas/settings-experiments.js +1 -1
- package/dist/schemas/settings-experiments.js.map +1 -1
- package/dist/schemas/settings-history.d.ts +2 -2
- package/dist/schemas/settings.d.ts +59 -15
- package/dist/schemas/settings.d.ts.map +1 -1
- package/dist/schemas/settings.js +23 -27
- package/dist/schemas/settings.js.map +1 -1
- package/dist/schemas/webext.d.ts +9 -0
- package/dist/schemas/webext.d.ts.map +1 -1
- package/dist/schemas/webext.js +2 -0
- package/dist/schemas/webext.js.map +1 -1
- package/dist/schemas/workspace/workspace-tree.d.ts +8 -0
- package/dist/schemas/workspace/workspace-tree.d.ts.map +1 -1
- package/dist/schemas/workspace/workspace-tree.js +16 -0
- package/dist/schemas/workspace/workspace-tree.js.map +1 -1
- package/dist/state/definition.d.ts +48 -8
- package/dist/state/definition.d.ts.map +1 -1
- package/dist/text/mentions.d.ts.map +1 -1
- package/dist/text/mentions.js +8 -1
- package/dist/text/mentions.js.map +1 -1
- package/dist/text/transcript-fold.d.ts.map +1 -1
- package/dist/text/transcript-fold.js +1 -0
- package/dist/text/transcript-fold.js.map +1 -1
- package/package.json +16 -5
- package/src/app-routes/app-pages.ts +148 -0
- package/src/app-routes/app-routes.test.ts +183 -0
- package/src/app-routes/index.ts +6 -0
- package/src/app-routes/legacy.ts +144 -0
- package/src/app-routes/paths.ts +160 -0
- package/src/app-routes/patterns.ts +145 -0
- package/src/chores/stack.ts +14 -2
- package/src/contracts/agents.contract.ts +16 -2
- package/src/contracts/endpoints.contract.ts +12 -0
- package/src/contracts/runner.contract.ts +12 -0
- package/src/contracts/seal.contract.ts +117 -0
- package/src/contracts/settings.contract.ts +30 -6
- package/src/contracts/workspace.contract.ts +16 -0
- package/src/events/agent-events.ts +20 -0
- package/src/events/requests.ts +8 -0
- package/src/events/system-events.ts +39 -4
- package/src/events/transcript.ts +9 -1
- package/src/ids/row-ids.test.ts +31 -0
- package/src/ids/row-ids.ts +10 -2
- package/src/index.ts +65 -5
- package/src/models/model-roles.ts +10 -0
- package/src/policy/org-locks.ts +9 -1
- package/src/policy/request-status.ts +38 -10
- package/src/protocol/doors/runner-protocol.ts +28 -1
- package/src/protocol/routes.test.ts +75 -2
- package/src/protocol/routes.ts +119 -11
- package/src/protocol/sse.ts +6 -1
- package/src/schemas/agent-land.ts +98 -0
- package/src/schemas/agent.ts +3 -0
- package/src/schemas/agents.ts +6 -94
- package/src/schemas/capabilities.ts +1 -1
- package/src/schemas/commit-attribution.ts +38 -0
- package/src/schemas/composer-drafts.ts +17 -0
- package/src/schemas/environment.ts +4 -0
- package/src/schemas/git/git-history.ts +10 -0
- package/src/schemas/gpu-settings.ts +31 -0
- package/src/schemas/night-hours.test.ts +54 -0
- package/src/schemas/night-hours.ts +70 -0
- package/src/schemas/organisation.ts +15 -0
- package/src/schemas/privacy.test.ts +8 -1
- package/src/schemas/privacy.ts +10 -1
- package/src/schemas/providers/plan-limits.ts +5 -0
- package/src/schemas/sandbox-mode.test.ts +68 -0
- package/src/schemas/sandbox-mode.ts +93 -0
- package/src/schemas/seal-proof.ts +12 -0
- package/src/schemas/seal.ts +175 -0
- package/src/schemas/settings-experiments.ts +3 -1
- package/src/schemas/settings.test.ts +7 -0
- package/src/schemas/settings.ts +60 -48
- package/src/schemas/webext.ts +8 -0
- package/src/schemas/workspace/workspace-tree.ts +23 -0
- package/src/state/daemon-floor.test.ts +1 -0
- package/src/text/mentions.ts +10 -1
- package/src/text/pages.test.ts +1 -0
- package/src/text/transcript-fold.ts +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { newRowId, positionRowId } from "./row-ids.js";
|
|
2
|
+
|
|
3
|
+
describe("row ids", () => {
|
|
4
|
+
it("mints twelve base-36 characters, a fresh one each time", () => {
|
|
5
|
+
const ids = Array.from({ length: 200 }, () => newRowId());
|
|
6
|
+
for (const id of ids) {
|
|
7
|
+
expect(id).toMatch(/^[0-9a-z]{12}$/);
|
|
8
|
+
}
|
|
9
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("draws a byte past the alphabet's last whole multiple again rather than folding it back", () => {
|
|
13
|
+
const draws = [new Uint8Array([255, 252, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), new Uint8Array([35, 251])];
|
|
14
|
+
const spy = jest.spyOn(globalThis.crypto, "getRandomValues").mockImplementation(<T extends ArrayBufferView | null>(array: T): T => {
|
|
15
|
+
const next = draws.shift();
|
|
16
|
+
if (array instanceof Uint8Array && next !== undefined) {
|
|
17
|
+
array.set(next.subarray(0, array.length));
|
|
18
|
+
}
|
|
19
|
+
return array;
|
|
20
|
+
});
|
|
21
|
+
try {
|
|
22
|
+
expect(newRowId()).toBe("0123456789zz");
|
|
23
|
+
} finally {
|
|
24
|
+
spy.mockRestore();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("names a row recorded before ids by its position", () => {
|
|
29
|
+
expect(positionRowId(7)).toBe("@7");
|
|
30
|
+
});
|
|
31
|
+
});
|
package/src/ids/row-ids.ts
CHANGED
|
@@ -7,10 +7,18 @@ const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
|
7
7
|
// row of every record carries one.
|
|
8
8
|
const LENGTH = 12;
|
|
9
9
|
|
|
10
|
+
// A byte at or above the last whole multiple of the alphabet is drawn again rather than folded back with `%`, which
|
|
11
|
+
// would make the first few characters likelier than the rest.
|
|
12
|
+
const BYTE_LIMIT = 256 - (256 % ALPHABET.length);
|
|
13
|
+
|
|
10
14
|
export const newRowId = (): string => {
|
|
11
15
|
let id = "";
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
while (id.length < LENGTH) {
|
|
17
|
+
for (const byte of globalThis.crypto.getRandomValues(new Uint8Array(LENGTH - id.length))) {
|
|
18
|
+
if (byte < BYTE_LIMIT) {
|
|
19
|
+
id += ALPHABET[byte % ALPHABET.length];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
23
|
return id;
|
|
16
24
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { getEventIteratorSchemaDetails, isContractProcedure } from "@orpc/contra
|
|
|
2
2
|
import type { z } from "zod";
|
|
3
3
|
import { RAW_JSON_ROUTES } from "./protocol/raw/raw-json-routes.js";
|
|
4
4
|
import { RAW_ROUTE_LIST } from "./protocol/raw/raw-routes.js";
|
|
5
|
-
import type
|
|
6
|
-
import { contractRoutes, rawRouteFingerprintsOf, requestPathFor, routeForProcedure, routeNameForRequest, routeShapes, servedRoute } from "./protocol/routes.js";
|
|
5
|
+
import { type ContractRoute,contractRoutes,rawRouteFingerprintsOf,requestPathFor,routeForProcedure,routeNameForRequest,routePrintsOf,type RoutePrints,routeShapes,servedRoute } from "./protocol/routes.js";
|
|
7
6
|
import { accessProfilesContract } from "./contracts/access-profiles.contract.js";
|
|
8
7
|
import { accountsContract } from "./contracts/accounts.contract.js";
|
|
9
8
|
import { activityContract } from "./contracts/activity.contract.js";
|
|
@@ -46,8 +45,9 @@ import { secretsContract } from "./contracts/secrets.contract.js";
|
|
|
46
45
|
import { servicesContract } from "./contracts/services.contract.js";
|
|
47
46
|
import { sessionsContract } from "./contracts/sessions.contract.js";
|
|
48
47
|
import { settingsContract } from "./contracts/settings.contract.js";
|
|
49
|
-
import {
|
|
48
|
+
import { sealContract } from "./contracts/seal.contract.js";
|
|
50
49
|
import { shareContract } from "./contracts/share.contract.js";
|
|
50
|
+
import { sharingContract } from "./contracts/sharing.contract.js";
|
|
51
51
|
import { skillsContract } from "./contracts/skills.contract.js";
|
|
52
52
|
import { systemContract } from "./contracts/system.contract.js";
|
|
53
53
|
import { translatorContract } from "./contracts/translator.contract.js";
|
|
@@ -61,7 +61,60 @@ export { HISTORY_ROOT, HOST_STATE_ROOT, STATE_DIR, WORKSPACE_ROOT } from "@inten
|
|
|
61
61
|
|
|
62
62
|
// The aggregated contract; implemented server-side by per-domain route factories, consumed by the browser's typed oRPC
|
|
63
63
|
// client. Mounted at the sandbox root, alongside plain Hono routes like /health and /workspace/raw.
|
|
64
|
-
export const sandboxContract
|
|
64
|
+
export const sandboxContract: {
|
|
65
|
+
accessProfiles: typeof accessProfilesContract;
|
|
66
|
+
accounts: typeof accountsContract;
|
|
67
|
+
activity: typeof activityContract;
|
|
68
|
+
agent: typeof agentContract;
|
|
69
|
+
agents: typeof agentsContract;
|
|
70
|
+
approvals: typeof approvalsContract;
|
|
71
|
+
areas: typeof areasContract;
|
|
72
|
+
audit: typeof auditContract;
|
|
73
|
+
automations: typeof automationsContract;
|
|
74
|
+
capabilities: typeof capabilitiesContract;
|
|
75
|
+
chores: typeof choresContract;
|
|
76
|
+
ci: typeof ciContract;
|
|
77
|
+
compliance: typeof complianceContract;
|
|
78
|
+
diff: typeof diffContract;
|
|
79
|
+
endpoints: typeof endpointsContract;
|
|
80
|
+
exit: typeof exitContract;
|
|
81
|
+
extensions: typeof extensionsContract;
|
|
82
|
+
git: typeof gitContract;
|
|
83
|
+
history: typeof historyContract;
|
|
84
|
+
intentic: typeof intenticContract;
|
|
85
|
+
inventory: typeof inventoryContract;
|
|
86
|
+
issues: typeof issuesContract;
|
|
87
|
+
logs: typeof logsContract;
|
|
88
|
+
loops: typeof loopsContract;
|
|
89
|
+
needs: typeof needsContract;
|
|
90
|
+
netdisk: typeof netdiskContract;
|
|
91
|
+
offload: typeof offloadContract;
|
|
92
|
+
org: typeof orgContract;
|
|
93
|
+
pages: typeof pagesContract;
|
|
94
|
+
panels: typeof panelsContract;
|
|
95
|
+
personas: typeof personasContract;
|
|
96
|
+
ports: typeof portsContract;
|
|
97
|
+
privacy: typeof privacyContract;
|
|
98
|
+
providers: typeof providersContract;
|
|
99
|
+
public: typeof publicContract;
|
|
100
|
+
push: typeof pushContract;
|
|
101
|
+
runs: typeof runsContract;
|
|
102
|
+
safety: typeof safetyContract;
|
|
103
|
+
secrets: typeof secretsContract;
|
|
104
|
+
services: typeof servicesContract;
|
|
105
|
+
sessions: typeof sessionsContract;
|
|
106
|
+
settings: typeof settingsContract;
|
|
107
|
+
seal: typeof sealContract;
|
|
108
|
+
share: typeof shareContract;
|
|
109
|
+
sharing: typeof sharingContract;
|
|
110
|
+
skills: typeof skillsContract;
|
|
111
|
+
system: typeof systemContract;
|
|
112
|
+
translator: typeof translatorContract;
|
|
113
|
+
usage: typeof usageContract;
|
|
114
|
+
vpn: typeof vpnContract;
|
|
115
|
+
workflows: typeof workflowsContract;
|
|
116
|
+
workspace: typeof workspaceContract;
|
|
117
|
+
} = {
|
|
65
118
|
accessProfiles: accessProfilesContract,
|
|
66
119
|
accounts: accountsContract,
|
|
67
120
|
activity: activityContract,
|
|
@@ -104,8 +157,9 @@ export const sandboxContract = {
|
|
|
104
157
|
services: servicesContract,
|
|
105
158
|
sessions: sessionsContract,
|
|
106
159
|
settings: settingsContract,
|
|
107
|
-
|
|
160
|
+
seal: sealContract,
|
|
108
161
|
share: shareContract,
|
|
162
|
+
sharing: sharingContract,
|
|
109
163
|
skills: skillsContract,
|
|
110
164
|
system: systemContract,
|
|
111
165
|
translator: translatorContract,
|
|
@@ -141,6 +195,12 @@ export const RAW_ROUTE_NAMES: readonly string[] = RAW_ROUTE_LIST.map((route) =>
|
|
|
141
195
|
let rawFingerprints: Readonly<Record<string, string>> | undefined;
|
|
142
196
|
export const rawRouteFingerprints = (): Readonly<Record<string, string>> => (rawFingerprints ??= rawRouteFingerprintsOf(RAW_JSON_ROUTES));
|
|
143
197
|
|
|
198
|
+
// Every route's second print, procedures and hand-written routes in one map (routes.ts says why there are two):
|
|
199
|
+
// memoised like the first, for the same startup reason.
|
|
200
|
+
let routePrints: Readonly<Record<string, RoutePrints>> | undefined;
|
|
201
|
+
export const sandboxRoutePrints = (): Readonly<Record<string, RoutePrints>> => (routePrints ??= routePrintsOf(sandboxContract, RAW_JSON_ROUTES));
|
|
202
|
+
export type { RoutePrints };
|
|
203
|
+
|
|
144
204
|
// The contract route a concrete browser request belongs to, bound to this build's route table.
|
|
145
205
|
export const sandboxRouteName = (method: string, pathWithQuery: string): string | undefined =>
|
|
146
206
|
routeNameForRequest(SANDBOX_ROUTES, method, pathWithQuery);
|
|
@@ -111,6 +111,16 @@ export const MODEL_ROLES = [
|
|
|
111
111
|
icon: "server",
|
|
112
112
|
setup: "high",
|
|
113
113
|
},
|
|
114
|
+
{
|
|
115
|
+
// Started by a person's press on a failure the app cannot settle by itself (agentFix.ts in the editor): a sync that
|
|
116
|
+
// conflicts, a push the remote refuses, a commit a hook refuses, a dev server that crashed, a build that failed.
|
|
117
|
+
id: "workflow-fix",
|
|
118
|
+
label: "Workflow fixes",
|
|
119
|
+
blurb: "The agent started by Fix with agent on a failed sync, push, commit, run or build.",
|
|
120
|
+
kind: "run",
|
|
121
|
+
icon: "wrench",
|
|
122
|
+
setup: "high",
|
|
123
|
+
},
|
|
114
124
|
{
|
|
115
125
|
id: "maintenance-chore",
|
|
116
126
|
label: "Maintenance chores",
|
package/src/policy/org-locks.ts
CHANGED
|
@@ -81,7 +81,15 @@ export const ORG_SECTION_ROUTES = {
|
|
|
81
81
|
// Leaving (`DELETE /members/self`) stays open: nobody can be held in a sandbox by a policy. Profiles and services
|
|
82
82
|
// decide what people and unattended work may reach, so they are Access's too (docs/architecture/access.md).
|
|
83
83
|
access: {
|
|
84
|
-
changes: [
|
|
84
|
+
changes: [
|
|
85
|
+
"POST /members",
|
|
86
|
+
"DELETE /members",
|
|
87
|
+
"accessProfiles.save",
|
|
88
|
+
"accessProfiles.remove",
|
|
89
|
+
"services.save",
|
|
90
|
+
"services.remove",
|
|
91
|
+
"seal.setHouse",
|
|
92
|
+
],
|
|
85
93
|
},
|
|
86
94
|
areas: { changes: ["areas.save", "areas.remove"] },
|
|
87
95
|
personas: { changes: ["personas.save", "personas.remove", "personas.savePrompt", "personas.saveSkill", "personas.removeSkill"] },
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type PermissionStatus,
|
|
3
|
+
REQUEST_FIELDS,
|
|
4
|
+
type RequestField,
|
|
5
|
+
type TranscriptPlan,
|
|
6
|
+
type TranscriptQuestion,
|
|
7
|
+
type TranscriptRequests,
|
|
8
|
+
type TranscriptRow,
|
|
9
|
+
} from "../events/transcript.js";
|
|
2
10
|
import type { AgentReply } from "../schemas/providers/plan-limits.js";
|
|
3
11
|
import { startedChildCard } from "../events/child-run.js";
|
|
4
12
|
|
|
@@ -22,21 +30,41 @@ const permissionStatusOf = (reply: AgentReply | undefined): PermissionStatus =>
|
|
|
22
30
|
}
|
|
23
31
|
};
|
|
24
32
|
|
|
33
|
+
const settledPlan = (plan: TranscriptPlan, reply: AgentReply | undefined): TranscriptPlan => {
|
|
34
|
+
const settled: TranscriptPlan = { ...plan, status: reply?.kind !== "plan" ? "cancelled" : reply.approve ? "approved" : "rejected" };
|
|
35
|
+
// Approved by night hours rather than a person, which the frozen card says.
|
|
36
|
+
if (reply?.kind === "plan" && reply.night !== undefined) {
|
|
37
|
+
settled.night = reply.night;
|
|
38
|
+
}
|
|
39
|
+
return settled;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const settledQuestion = (question: TranscriptQuestion, reply: AgentReply | undefined): TranscriptQuestion => {
|
|
43
|
+
if (reply?.kind !== "question") {
|
|
44
|
+
return { ...question, status: "cancelled" };
|
|
45
|
+
}
|
|
46
|
+
const settled: TranscriptQuestion = { ...question, status: reply.cancelled === true ? "cancelled" : "answered" };
|
|
47
|
+
if (reply.answers !== undefined) {
|
|
48
|
+
settled.answers = reply.answers;
|
|
49
|
+
}
|
|
50
|
+
if (reply.attachments !== undefined) {
|
|
51
|
+
settled.attachments = reply.attachments;
|
|
52
|
+
}
|
|
53
|
+
// Which night answer it got, so the frozen card says the sandbox chose and not the reader.
|
|
54
|
+
if (reply.night !== undefined) {
|
|
55
|
+
settled.night = reply.night;
|
|
56
|
+
}
|
|
57
|
+
return settled;
|
|
58
|
+
};
|
|
59
|
+
|
|
25
60
|
export const settledRequests = (cards: TranscriptRequests, reply: AgentReply | undefined): TranscriptRequests => {
|
|
26
61
|
const out: Cards = {};
|
|
27
62
|
const { plan, question, permission, browserHelp, terminalHelp, capabilityOffer, paymentOffer, credentialOffer, pageAsk } = cards;
|
|
28
63
|
if (plan !== undefined) {
|
|
29
|
-
out.plan =
|
|
64
|
+
out.plan = settledPlan(plan, reply);
|
|
30
65
|
}
|
|
31
66
|
if (question !== undefined) {
|
|
32
|
-
|
|
33
|
-
const attachments = reply?.kind === "question" ? reply.attachments : undefined;
|
|
34
|
-
out.question = {
|
|
35
|
-
...question,
|
|
36
|
-
status: reply?.kind === "question" && reply.cancelled !== true ? "answered" : "cancelled",
|
|
37
|
-
...(answers === undefined ? {} : { answers }),
|
|
38
|
-
...(attachments === undefined ? {} : { attachments }),
|
|
39
|
-
};
|
|
67
|
+
out.question = settledQuestion(question, reply);
|
|
40
68
|
}
|
|
41
69
|
if (permission !== undefined) {
|
|
42
70
|
out.permission = {
|
|
@@ -185,7 +185,14 @@ export type RunnerSync = z.infer<typeof RunnerSyncSchema>;
|
|
|
185
185
|
|
|
186
186
|
export const RunnerSyncLineSchema = z.union([
|
|
187
187
|
z.object({ kind: z.literal("line"), text: z.string() }),
|
|
188
|
-
z.object({
|
|
188
|
+
z.object({
|
|
189
|
+
kind: z.literal("done"),
|
|
190
|
+
ok: z.boolean(),
|
|
191
|
+
detail: z.string().optional(),
|
|
192
|
+
// Why a pull touched nothing: the conversation's previous turn is still running on the runner, in the checkout
|
|
193
|
+
// a pull would reset. The parent collects a held turn before it pulls (runner-dispatch.ts), so this is a guard.
|
|
194
|
+
code: z.enum(["busy"]).optional(),
|
|
195
|
+
}),
|
|
189
196
|
]);
|
|
190
197
|
export type RunnerSyncLine = z.infer<typeof RunnerSyncLineSchema>;
|
|
191
198
|
|
|
@@ -211,6 +218,26 @@ export const RunnerTurnSchema = z.object({
|
|
|
211
218
|
});
|
|
212
219
|
export type RunnerTurn = z.infer<typeof RunnerTurnSchema>;
|
|
213
220
|
|
|
221
|
+
// A turn the runner holds for a conversation, which outlives the socket it was dispatched over: the runner runs it to
|
|
222
|
+
// its end whoever is listening, and keeps every frame it produced until the parent has collected the turn's branch, so a
|
|
223
|
+
// `finished` one is always one the parent has not collected yet (a restart, a wait that ran out). `events` counts those
|
|
224
|
+
// frames; a parent that saw N of them re-attaches with `after: N` and misses nothing.
|
|
225
|
+
export const RunnerHeldTurnSchema = z.object({
|
|
226
|
+
state: z.enum(["none", "live", "finished"]),
|
|
227
|
+
events: z.number().int().nonnegative(),
|
|
228
|
+
// How many the parent last said it has (runnerContract.ackTurn): where a parent that lost its own count, a restart,
|
|
229
|
+
// reads on from without repeating what it already drew.
|
|
230
|
+
acked: z.number().int().nonnegative(),
|
|
231
|
+
});
|
|
232
|
+
export type RunnerHeldTurn = z.infer<typeof RunnerHeldTurnSchema>;
|
|
233
|
+
|
|
234
|
+
export const RunnerAttachSchema = z.object({
|
|
235
|
+
conversationId: z.string().min(1),
|
|
236
|
+
// How many of the turn's frames the parent already has; the replay starts with the next one.
|
|
237
|
+
after: z.number().int().nonnegative(),
|
|
238
|
+
});
|
|
239
|
+
export type RunnerAttach = z.infer<typeof RunnerAttachSchema>;
|
|
240
|
+
|
|
214
241
|
// OFFLOADED COMMANDS: one shell line the parent hands a runner instead of running it itself (settings `offload`). The
|
|
215
242
|
// code travels as a snapshot commit of the parent's working tree, uncommitted and untracked work included, parked under
|
|
216
243
|
// this ref in the repo's git dir for the runner to fetch through the git door, and deleted once the run ends.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { eventIterator, oc } from "@orpc/contract";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { RAW_JSON_ROUTES } from "./raw/raw-json-routes.js";
|
|
4
|
-
import { RAW_ROUTE_NAMES, rawRouteFingerprints, SANDBOX_ROUTE_NAMES, SANDBOX_ROUTES, sandboxRouteName, sandboxRouteFingerprints } from "../index.js";
|
|
4
|
+
import { RAW_ROUTE_NAMES, rawRouteFingerprints, SANDBOX_ROUTE_NAMES, SANDBOX_ROUTES, sandboxRouteName, sandboxRouteFingerprints, sandboxRoutePrints } from "../index.js";
|
|
5
5
|
import { procedure } from "./route-meta.js";
|
|
6
|
-
import { contractRoutes, routeNameForRequest, routeShapes, servedRoute, streamOf } from "./routes.js";
|
|
6
|
+
import { contractRoutes, routeNameForRequest, routePrintsOf, routeShapes, servedRoute, streamOf } from "./routes.js";
|
|
7
7
|
|
|
8
8
|
const fixture = {
|
|
9
9
|
vpn: {
|
|
@@ -228,6 +228,73 @@ describe(`routeShapes`, () => {
|
|
|
228
228
|
});
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
+
describe(`routePrintsOf`, () => {
|
|
232
|
+
// [wire, core] of `vpn.list` answering `output` and taking `input`.
|
|
233
|
+
const printed = (output: z.ZodType, input?: z.ZodType) => {
|
|
234
|
+
const route = oc.route({ method: "GET", path: "/vpn" });
|
|
235
|
+
const prints = routePrintsOf({ vpn: { list: input === undefined ? route.output(output) : route.input(input).output(output) } }, {});
|
|
236
|
+
const found = prints[`vpn.list`];
|
|
237
|
+
if (found === undefined) {
|
|
238
|
+
throw new Error(`vpn.list was not printed`);
|
|
239
|
+
}
|
|
240
|
+
return { wire: found[0], core: found[1] };
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
it(`is blind to a description: rewording a field is not a wire change`, () => {
|
|
244
|
+
const one = printed(z.object({ a: z.string().describe(`one`) }));
|
|
245
|
+
const other = printed(z.object({ a: z.string().describe(`another`) }));
|
|
246
|
+
expect(other).toEqual(one);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it(`still reads a field that is itself called description`, () => {
|
|
250
|
+
expect(printed(z.object({ description: z.string() })).wire).not.toBe(printed(z.object({ title: z.string() })).wire);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it(`tells an added optional field apart on the wire and not in the core`, () => {
|
|
254
|
+
const before = printed(z.object({ a: z.string() }), z.object({ q: z.string() }));
|
|
255
|
+
const after = printed(z.object({ a: z.string(), b: z.number().optional() }), z.object({ q: z.string(), r: z.boolean().optional() }));
|
|
256
|
+
expect(after.wire).not.toBe(before.wire);
|
|
257
|
+
expect(after.core).toBe(before.core);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it(`keeps a defaulted field out of the core, since a parser fills it in`, () => {
|
|
261
|
+
const before = printed(z.object({ a: z.string() }));
|
|
262
|
+
const after = printed(z.object({ a: z.string(), hours: z.object({ from: z.string() }).prefault({ from: `23:00` }) }));
|
|
263
|
+
expect(after.wire).not.toBe(before.wire);
|
|
264
|
+
expect(after.core).toBe(before.core);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it(`changes the core when a required field is added or retyped`, () => {
|
|
268
|
+
const before = printed(z.object({ a: z.string() }));
|
|
269
|
+
expect(printed(z.object({ a: z.string(), b: z.number() })).core).not.toBe(before.core);
|
|
270
|
+
expect(printed(z.object({ a: z.number() })).core).not.toBe(before.core);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it(`changes the core when an enum moves, in either direction`, () => {
|
|
274
|
+
const before = printed(z.object({ a: z.enum([`x`, `y`]) }));
|
|
275
|
+
expect(printed(z.object({ a: z.enum([`x`, `y`, `z`]) })).core).not.toBe(before.core);
|
|
276
|
+
expect(printed(z.object({ a: z.enum([`x`]) })).core).not.toBe(before.core);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it(`keeps a strict object's optional fields in the core, since there an unknown key is a refusal`, () => {
|
|
280
|
+
const before = printed(z.object({ a: z.string() }), z.strictObject({ q: z.string() }));
|
|
281
|
+
const after = printed(z.object({ a: z.string() }), z.strictObject({ q: z.string(), r: z.boolean().optional() }));
|
|
282
|
+
expect(after.core).not.toBe(before.core);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it(`reaches optional fields nested inside required ones`, () => {
|
|
286
|
+
const before = printed(z.object({ a: z.object({ x: z.string() }) }));
|
|
287
|
+
const after = printed(z.object({ a: z.object({ x: z.string(), y: z.string().optional() }) }));
|
|
288
|
+
expect(after.core).toBe(before.core);
|
|
289
|
+
expect(after.wire).not.toBe(before.wire);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it(`prints the hand-written routes in the same map`, () => {
|
|
293
|
+
const prints = routePrintsOf({}, { "GET /x": { output: z.object({ a: z.string() }) } });
|
|
294
|
+
expect(Object.keys(prints)).toEqual([`GET /x`]);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
231
298
|
describe(`the real sandbox contract`, () => {
|
|
232
299
|
it(`fingerprints every route, streams included`, () => {
|
|
233
300
|
// Nothing may opt out: a route with no fingerprint is a route the browser can never tell has drifted, and the
|
|
@@ -269,6 +336,12 @@ describe(`the real sandbox contract`, () => {
|
|
|
269
336
|
]);
|
|
270
337
|
});
|
|
271
338
|
|
|
339
|
+
it(`prints every route the first print covers, procedures and hand-written ones in one map`, () => {
|
|
340
|
+
const prints = sandboxRoutePrints();
|
|
341
|
+
const first = [...Object.keys(sandboxRouteFingerprints()), ...Object.keys(rawRouteFingerprints())].toSorted();
|
|
342
|
+
expect(Object.keys(prints).toSorted()).toEqual(first);
|
|
343
|
+
});
|
|
344
|
+
|
|
272
345
|
it(`fingerprints every route exactly once`, () => {
|
|
273
346
|
expect(Object.keys(sandboxRouteFingerprints()).every((name) => SANDBOX_ROUTE_NAMES.includes(name))).toBe(true);
|
|
274
347
|
expect(Object.keys(sandboxRouteFingerprints()).length).toBe(SANDBOX_ROUTE_NAMES.length);
|
package/src/protocol/routes.ts
CHANGED
|
@@ -116,6 +116,88 @@ const wireShape = (schema: unknown, io: "input" | "output"): unknown => {
|
|
|
116
116
|
return frame === undefined ? z.toJSONSchema(schema as z.ZodType, { io }) : { stream: z.toJSONSchema(frame, { io }) };
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
+
// THE SECOND PRINT, AND WHY THE FIRST ONE CRIED WOLF. The print above hashes the JSON Schema whole, and two things in
|
|
120
|
+
// it change on almost every push without changing what either side can send or read: the prose (`description`,
|
|
121
|
+
// `title`) every schema here carries at length, and a new optional field. Against a page deployed ahead of the
|
|
122
|
+
// sandboxes, both read as "may misbehave" on routes that work exactly as before. So a route is printed twice more:
|
|
123
|
+
//
|
|
124
|
+
// - `wire`: the shape as above with the words taken out. It differs only where the payload's shape differs.
|
|
125
|
+
// - `core`: what has to hold for the call to work at all, read as each side's parser reads the other's message (zod's
|
|
126
|
+
// `parse`, which is the input side of a schema whichever way the message travels: the daemon parses a request, the
|
|
127
|
+
// page parses every answer, sandboxRpc.ts). It drops defaults, and every optional property of an object that strips
|
|
128
|
+
// what it doesn't know, since such a property can be absent on either side and missing from either side's schema
|
|
129
|
+
// without the other refusing anything. A strict object (`additionalProperties: false`) keeps them all: there an
|
|
130
|
+
// unknown key is a refusal.
|
|
131
|
+
//
|
|
132
|
+
// Equal cores with different wires is a sandbox that answers every call and lacks some optional part of one, which is
|
|
133
|
+
// a feature arriving with the next update rather than a fault. A different core is a real disagreement.
|
|
134
|
+
//
|
|
135
|
+
// What the core cannot see: an existing optional field whose type changed. That is a narrowing the contract-shrink gate
|
|
136
|
+
// already makes a commit declare, and it still shows as a different `wire`.
|
|
137
|
+
export type RoutePrints = [wire: string, core: string];
|
|
138
|
+
|
|
139
|
+
// Keywords that carry words for a reader and never a constraint on the payload.
|
|
140
|
+
const DOC_KEYWORDS = new Set(["description", "title", "examples", "$comment", "deprecated"]);
|
|
141
|
+
// Keywords whose value maps a NAME to a schema; inside one a key is a field, never a keyword.
|
|
142
|
+
const NAME_MAPS = new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);
|
|
143
|
+
// Keywords whose value is payload data, not schema, and is hashed as written.
|
|
144
|
+
const DATA_KEYWORDS = new Set(["const", "enum", "default"]);
|
|
145
|
+
|
|
146
|
+
// JSON as z.toJSONSchema writes it, which is all the prints ever walk.
|
|
147
|
+
type Json = string | number | boolean | null | readonly Json[] | { readonly [key: string]: Json };
|
|
148
|
+
type JsonObject = { readonly [key: string]: Json };
|
|
149
|
+
|
|
150
|
+
const isObject = (value: Json): value is JsonObject => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
151
|
+
|
|
152
|
+
// The names a schema object requires, or none.
|
|
153
|
+
const requiredOf = (schema: JsonObject): ReadonlySet<Json> => {
|
|
154
|
+
const required = schema["required"];
|
|
155
|
+
return new Set(Array.isArray(required) ? required : []);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// The schema with its words removed and, for the core, its defaults and its strip objects' optional properties too.
|
|
159
|
+
// `named` is a map of field name → schema, whose keys are never keywords.
|
|
160
|
+
const pruned = (value: Json, core: boolean, named = false): Json => {
|
|
161
|
+
if (Array.isArray(value)) {
|
|
162
|
+
return value.map((item) => pruned(item, core));
|
|
163
|
+
}
|
|
164
|
+
if (!isObject(value)) {
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
const out: Record<string, Json> = {};
|
|
168
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
169
|
+
if (named) {
|
|
170
|
+
out[key] = pruned(nested, core);
|
|
171
|
+
} else if (!DOC_KEYWORDS.has(key) && !(core && key === "default")) {
|
|
172
|
+
out[key] = DATA_KEYWORDS.has(key) ? nested : pruned(nested, core, NAME_MAPS.has(key));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const properties = out["properties"];
|
|
176
|
+
if (core && !named && value["additionalProperties"] !== false && properties !== undefined && isObject(properties)) {
|
|
177
|
+
const required = requiredOf(value);
|
|
178
|
+
out["properties"] = Object.fromEntries(Object.entries(properties).filter(([name]) => required.has(name)));
|
|
179
|
+
}
|
|
180
|
+
return out;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// The two schemas of a route, whichever kind declares them.
|
|
184
|
+
interface RawRouteSchemas {
|
|
185
|
+
readonly input?: unknown;
|
|
186
|
+
readonly output?: unknown;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// One side of a route as JSON for the prints. SAFETY: wireShape is z.toJSONSchema's output (or a `{ stream }` wrapper
|
|
190
|
+
// around it, or undefined for a side with no schema), which is JSON by construction; undefined becomes null so the
|
|
191
|
+
// side still counts.
|
|
192
|
+
const sideOf = (route: RawRouteSchemas, side: keyof RawRouteSchemas, io: "input" | "output"): Json => (wireShape(route[side], io) ?? null) as Json;
|
|
193
|
+
|
|
194
|
+
// Both prints of one route's two sides. The wire reads each side as the first print does (a `.default()` field is
|
|
195
|
+
// optional in, required out); the core reads both as a parser does.
|
|
196
|
+
const printsOf = (route: RawRouteSchemas): RoutePrints => [
|
|
197
|
+
fingerprint(pruned({ in: sideOf(route, "input", "input"), out: sideOf(route, "output", "output") }, false)),
|
|
198
|
+
fingerprint(pruned({ in: sideOf(route, "input", "input"), out: sideOf(route, "output", "input") }, true)),
|
|
199
|
+
];
|
|
200
|
+
|
|
119
201
|
// One route's wire shape, or undefined if it can't be expressed at all.
|
|
120
202
|
const procedureShape = (value: unknown): string | undefined => {
|
|
121
203
|
if (typeof value !== "object" || value === null || !("~orpc" in value)) {
|
|
@@ -129,27 +211,53 @@ const procedureShape = (value: unknown): string | undefined => {
|
|
|
129
211
|
}
|
|
130
212
|
};
|
|
131
213
|
|
|
132
|
-
// Every
|
|
133
|
-
|
|
134
|
-
export const routeShapes = (contract: Record<string, unknown>): Record<string, string> => {
|
|
135
|
-
const shapes: Record<string, string> = {};
|
|
214
|
+
// Every procedure of a contract that has a route, as `group.name` → procedure; the one walk every print shares.
|
|
215
|
+
function* routedProcedures(contract: Record<string, unknown>): Generator<readonly [string, ContractSchemasLike]> {
|
|
136
216
|
for (const [group, procedures] of Object.entries(contract)) {
|
|
137
217
|
if (typeof procedures !== "object" || procedures === null) {
|
|
138
218
|
continue;
|
|
139
219
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const shape = procedureShape(procedure);
|
|
145
|
-
if (shape !== undefined) {
|
|
146
|
-
shapes[`${group}.${name}`] = shape;
|
|
220
|
+
// SAFETY: a contract group is an object of procedures; procedureRoute below admits only what carries `~orpc`.
|
|
221
|
+
for (const [name, procedure] of Object.entries(procedures as Record<string, ContractSchemasLike>)) {
|
|
222
|
+
if (procedureRoute(procedure) !== undefined) {
|
|
223
|
+
yield [`${group}.${name}`, procedure];
|
|
147
224
|
}
|
|
148
225
|
}
|
|
149
226
|
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Every route whose shape this build can express, as name → fingerprint. A separate map from ContractRoute since
|
|
230
|
+
// existence and shape are advertised, and checked, independently.
|
|
231
|
+
export const routeShapes = (contract: Record<string, unknown>): Record<string, string> => {
|
|
232
|
+
const shapes: Record<string, string> = {};
|
|
233
|
+
for (const [name, procedure] of routedProcedures(contract)) {
|
|
234
|
+
const shape = procedureShape(procedure);
|
|
235
|
+
if (shape !== undefined) {
|
|
236
|
+
shapes[name] = shape;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
150
239
|
return shapes;
|
|
151
240
|
};
|
|
152
241
|
|
|
242
|
+
// The second print of every route the first one prints (RoutePrints), procedures and hand-written routes in one map:
|
|
243
|
+
// their names never collide, a raw one being `METHOD /path`. A route whose shape can't be expressed is left out, as
|
|
244
|
+
// above.
|
|
245
|
+
export const routePrintsOf = (contract: Record<string, unknown>, raw: Readonly<Record<string, RawRouteSchemas>>) => {
|
|
246
|
+
const prints: Record<string, RoutePrints> = {};
|
|
247
|
+
const sides: (readonly [string, RawRouteSchemas])[] = [
|
|
248
|
+
...[...routedProcedures(contract)].map(([name, procedure]) => [name, { input: procedure["~orpc"].inputSchema, output: procedure["~orpc"].outputSchema }] as const),
|
|
249
|
+
...Object.entries(raw),
|
|
250
|
+
];
|
|
251
|
+
for (const [name, route] of sides) {
|
|
252
|
+
try {
|
|
253
|
+
prints[name] = printsOf(route);
|
|
254
|
+
} catch {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return prints;
|
|
259
|
+
};
|
|
260
|
+
|
|
153
261
|
// The same, for the hand-written routes that answer plain JSON (raw-json-routes.ts). They carry their schemas directly
|
|
154
262
|
// rather than through oRPC, so they need their own walk — and without one they were the half of the surface no version
|
|
155
263
|
// check could see: a browser calling a raw route an older daemon predates got a bare 404 with nothing to say about it.
|
package/src/protocol/sse.ts
CHANGED
|
@@ -192,7 +192,12 @@ export async function* sseEvents(body: ReadableStream<Uint8Array>, idleMs: numbe
|
|
|
192
192
|
// it with `sseData`. The same idle window as `sseEvents`.
|
|
193
193
|
export async function* sseFrames(body: ReadableStream<Uint8Array>, idleMs: number = SSE_IDLE_MS): AsyncGenerator<string> {
|
|
194
194
|
for await (const event of sseEvents(body, idleMs)) {
|
|
195
|
-
|
|
195
|
+
// A loop rather than `/(?:\r\n|\r|\n)+$/u`, which backtracks without end on a long run of line breaks.
|
|
196
|
+
let end = event.raw.length;
|
|
197
|
+
while (end > 0 && (event.raw[end - 1] === `\n` || event.raw[end - 1] === `\r`)) {
|
|
198
|
+
end -= 1;
|
|
199
|
+
}
|
|
200
|
+
yield event.raw.slice(0, end);
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
|