@intentic/sandbox-contract 1.432.0 → 1.433.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 +15 -0
- package/dist/contracts/agent.contract.d.ts +252 -72
- package/dist/contracts/agent.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.d.ts +67 -0
- package/dist/contracts/agents.contract.d.ts.map +1 -1
- package/dist/contracts/approvals.contract.d.ts +35 -0
- package/dist/contracts/approvals.contract.d.ts.map +1 -1
- package/dist/contracts/approvals.contract.js +13 -3
- package/dist/contracts/approvals.contract.js.map +1 -1
- package/dist/contracts/automations.contract.d.ts +1 -0
- package/dist/contracts/automations.contract.d.ts.map +1 -1
- package/dist/contracts/capabilities.contract.d.ts +3 -0
- package/dist/contracts/capabilities.contract.d.ts.map +1 -1
- package/dist/contracts/extensions.contract.d.ts +4 -0
- package/dist/contracts/extensions.contract.d.ts.map +1 -1
- package/dist/contracts/needs.contract.d.ts +198 -0
- package/dist/contracts/needs.contract.d.ts.map +1 -1
- package/dist/contracts/runner.contract.d.ts +156 -36
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/seal.contract.d.ts +5 -0
- package/dist/contracts/seal.contract.d.ts.map +1 -1
- package/dist/contracts/sessions.contract.d.ts +22 -0
- package/dist/contracts/sessions.contract.d.ts.map +1 -1
- package/dist/contracts/settings.contract.d.ts +16 -0
- package/dist/contracts/settings.contract.d.ts.map +1 -1
- package/dist/contracts/stack-grants.contract.d.ts +22 -0
- package/dist/contracts/stack-grants.contract.d.ts.map +1 -1
- package/dist/contracts/system.contract.d.ts +7 -4
- package/dist/contracts/system.contract.d.ts.map +1 -1
- package/dist/events/agent-events.d.ts +88 -0
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-transcript.d.ts +22 -0
- package/dist/events/agent-transcript.d.ts.map +1 -1
- package/dist/events/system-events.d.ts +4 -0
- package/dist/events/system-events.d.ts.map +1 -1
- package/dist/events/transcript.d.ts +110 -0
- package/dist/events/transcript.d.ts.map +1 -1
- package/dist/ids/conversation-ids.d.ts.map +1 -1
- package/dist/ids/conversation-ids.js.map +1 -1
- package/dist/protocol/raw/extension-protocol.d.ts +116 -0
- package/dist/protocol/raw/extension-protocol.d.ts.map +1 -1
- package/dist/protocol/raw/extension-protocol.js +17 -1
- package/dist/protocol/raw/extension-protocol.js.map +1 -1
- package/dist/protocol/raw/raw-json-routes.d.ts +2974 -0
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-json-routes.js +39 -0
- package/dist/protocol/raw/raw-json-routes.js.map +1 -1
- package/dist/protocol/raw/raw-routes.d.ts +179 -0
- package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-routes.js +41 -0
- package/dist/protocol/raw/raw-routes.js.map +1 -1
- package/dist/protocol/s2s/address.d.ts +53 -0
- package/dist/protocol/s2s/address.d.ts.map +1 -0
- package/dist/protocol/s2s/address.js +111 -0
- package/dist/protocol/s2s/address.js.map +1 -0
- package/dist/protocol/s2s/attestation.d.ts +41 -0
- package/dist/protocol/s2s/attestation.d.ts.map +1 -0
- package/dist/protocol/s2s/attestation.js +96 -0
- package/dist/protocol/s2s/attestation.js.map +1 -0
- package/dist/protocol/s2s/canonical.d.ts +10 -0
- package/dist/protocol/s2s/canonical.d.ts.map +1 -0
- package/dist/protocol/s2s/canonical.js +94 -0
- package/dist/protocol/s2s/canonical.js.map +1 -0
- package/dist/protocol/s2s/envelope.d.ts +40 -0
- package/dist/protocol/s2s/envelope.d.ts.map +1 -0
- package/dist/protocol/s2s/envelope.js +116 -0
- package/dist/protocol/s2s/envelope.js.map +1 -0
- package/dist/protocol/s2s/extension-sign.d.ts +21 -0
- package/dist/protocol/s2s/extension-sign.d.ts.map +1 -0
- package/dist/protocol/s2s/extension-sign.js +41 -0
- package/dist/protocol/s2s/extension-sign.js.map +1 -0
- package/dist/protocol/s2s/identity-doc.d.ts +50 -0
- package/dist/protocol/s2s/identity-doc.d.ts.map +1 -0
- package/dist/protocol/s2s/identity-doc.js +89 -0
- package/dist/protocol/s2s/identity-doc.js.map +1 -0
- package/dist/protocol/s2s/index.d.ts +12 -0
- package/dist/protocol/s2s/index.d.ts.map +1 -0
- package/dist/protocol/s2s/index.js +12 -0
- package/dist/protocol/s2s/index.js.map +1 -0
- package/dist/protocol/s2s/kem.d.ts +15 -0
- package/dist/protocol/s2s/kem.d.ts.map +1 -0
- package/dist/protocol/s2s/kem.js +34 -0
- package/dist/protocol/s2s/kem.js.map +1 -0
- package/dist/protocol/s2s/keys.d.ts +34 -0
- package/dist/protocol/s2s/keys.d.ts.map +1 -0
- package/dist/protocol/s2s/keys.js +81 -0
- package/dist/protocol/s2s/keys.js.map +1 -0
- package/dist/protocol/s2s/passkey-cosign.d.ts +44 -0
- package/dist/protocol/s2s/passkey-cosign.d.ts.map +1 -0
- package/dist/protocol/s2s/passkey-cosign.js +139 -0
- package/dist/protocol/s2s/passkey-cosign.js.map +1 -0
- package/dist/protocol/s2s/session.d.ts +61 -0
- package/dist/protocol/s2s/session.d.ts.map +1 -0
- package/dist/protocol/s2s/session.js +98 -0
- package/dist/protocol/s2s/session.js.map +1 -0
- package/dist/protocol/s2s/sign.d.ts +12 -0
- package/dist/protocol/s2s/sign.d.ts.map +1 -0
- package/dist/protocol/s2s/sign.js +33 -0
- package/dist/protocol/s2s/sign.js.map +1 -0
- package/dist/schemas/agents-list.d.ts +2 -0
- package/dist/schemas/agents-list.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +4 -0
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/approvals.d.ts +100 -0
- package/dist/schemas/approvals.d.ts.map +1 -1
- package/dist/schemas/approvals.js +21 -0
- package/dist/schemas/approvals.js.map +1 -1
- package/dist/schemas/automations.d.ts +2 -0
- package/dist/schemas/automations.d.ts.map +1 -1
- package/dist/schemas/automations.js +1 -1
- package/dist/schemas/automations.js.map +1 -1
- package/dist/schemas/capabilities.d.ts +1 -0
- package/dist/schemas/capabilities.d.ts.map +1 -1
- package/dist/schemas/command-admission.d.ts +6 -0
- package/dist/schemas/command-admission.d.ts.map +1 -1
- package/dist/schemas/command-admission.js +2 -1
- package/dist/schemas/command-admission.js.map +1 -1
- package/dist/schemas/contact-need.d.ts +50 -0
- package/dist/schemas/contact-need.d.ts.map +1 -0
- package/dist/schemas/contact-need.js +19 -0
- package/dist/schemas/contact-need.js.map +1 -0
- package/dist/schemas/contacts-settings.d.ts +5 -0
- package/dist/schemas/contacts-settings.d.ts.map +1 -0
- package/dist/schemas/contacts-settings.js +11 -0
- package/dist/schemas/contacts-settings.js.map +1 -0
- package/dist/schemas/extension-updates.d.ts +8 -0
- package/dist/schemas/extension-updates.d.ts.map +1 -1
- package/dist/schemas/issues.d.ts +2 -0
- package/dist/schemas/issues.d.ts.map +1 -1
- package/dist/schemas/issues.js +1 -0
- package/dist/schemas/issues.js.map +1 -1
- package/dist/schemas/links.d.ts +8 -0
- package/dist/schemas/links.d.ts.map +1 -1
- package/dist/schemas/links.js +4 -0
- package/dist/schemas/links.js.map +1 -1
- package/dist/schemas/need-kinds.d.ts +2 -1
- package/dist/schemas/need-kinds.d.ts.map +1 -1
- package/dist/schemas/need-kinds.js +2 -2
- package/dist/schemas/need-kinds.js.map +1 -1
- package/dist/schemas/needs.d.ts +156 -13
- package/dist/schemas/needs.d.ts.map +1 -1
- package/dist/schemas/needs.js +5 -12
- package/dist/schemas/needs.js.map +1 -1
- package/dist/schemas/redirect-need.d.ts +15 -0
- package/dist/schemas/redirect-need.d.ts.map +1 -0
- package/dist/schemas/redirect-need.js +14 -0
- package/dist/schemas/redirect-need.js.map +1 -0
- package/dist/schemas/s2s-identity.d.ts +521 -0
- package/dist/schemas/s2s-identity.d.ts.map +1 -0
- package/dist/schemas/s2s-identity.js +208 -0
- package/dist/schemas/s2s-identity.js.map +1 -0
- package/dist/schemas/s2s-views.d.ts +2127 -0
- package/dist/schemas/s2s-views.d.ts.map +1 -0
- package/dist/schemas/s2s-views.js +217 -0
- package/dist/schemas/s2s-views.js.map +1 -0
- package/dist/schemas/s2s-wire.d.ts +1616 -0
- package/dist/schemas/s2s-wire.d.ts.map +1 -0
- package/dist/schemas/s2s-wire.js +276 -0
- package/dist/schemas/s2s-wire.js.map +1 -0
- package/dist/schemas/s2s.d.ts +5 -0
- package/dist/schemas/s2s.d.ts.map +1 -0
- package/dist/schemas/s2s.js +5 -0
- package/dist/schemas/s2s.js.map +1 -0
- package/dist/schemas/settings.d.ts +16 -0
- package/dist/schemas/settings.d.ts.map +1 -1
- package/dist/schemas/settings.js +2 -0
- package/dist/schemas/settings.js.map +1 -1
- package/dist/schemas/terminal.d.ts +2 -0
- package/dist/schemas/terminal.d.ts.map +1 -1
- package/dist/schemas/terminal.js +4 -0
- package/dist/schemas/terminal.js.map +1 -1
- package/dist/schemas/vpn.d.ts +4 -0
- package/dist/schemas/vpn.d.ts.map +1 -1
- package/dist/schemas/vpn.js +9 -0
- package/dist/schemas/vpn.js.map +1 -1
- package/dist/state/auth-state.d.ts.map +1 -1
- package/dist/state/auth-state.js +6 -0
- package/dist/state/auth-state.js.map +1 -1
- package/dist/state/definition.d.ts +18 -0
- package/dist/state/definition.d.ts.map +1 -1
- package/package.json +20 -5
- package/src/contracts/approvals.contract.ts +24 -3
- package/src/ids/conversation-ids.test.ts +22 -3
- package/src/ids/conversation-ids.ts +5 -7
- package/src/protocol/ingress-contract.fixture.json +6 -1
- package/src/protocol/raw/extension-protocol.ts +45 -1
- package/src/protocol/raw/raw-json-routes.ts +85 -0
- package/src/protocol/raw/raw-routes.ts +66 -3
- package/src/protocol/s2s/address.test.ts +157 -0
- package/src/protocol/s2s/address.ts +193 -0
- package/src/protocol/s2s/attestation.test.ts +262 -0
- package/src/protocol/s2s/attestation.ts +173 -0
- package/src/protocol/s2s/canonical.test.ts +70 -0
- package/src/protocol/s2s/canonical.ts +119 -0
- package/src/protocol/s2s/envelope.test.ts +162 -0
- package/src/protocol/s2s/envelope.ts +194 -0
- package/src/protocol/s2s/extension-sign.test.ts +117 -0
- package/src/protocol/s2s/extension-sign.ts +76 -0
- package/src/protocol/s2s/identity-doc.test.ts +187 -0
- package/src/protocol/s2s/identity-doc.ts +169 -0
- package/src/protocol/s2s/index.ts +15 -0
- package/src/protocol/s2s/kem.ts +62 -0
- package/src/protocol/s2s/keys.test.ts +76 -0
- package/src/protocol/s2s/keys.ts +155 -0
- package/src/protocol/s2s/passkey-cosign.test.ts +98 -0
- package/src/protocol/s2s/passkey-cosign.testing.ts +86 -0
- package/src/protocol/s2s/passkey-cosign.ts +192 -0
- package/src/protocol/s2s/s2s.testing.ts +22 -0
- package/src/protocol/s2s/session.test.ts +133 -0
- package/src/protocol/s2s/session.ts +179 -0
- package/src/protocol/s2s/sign.test.ts +66 -0
- package/src/protocol/s2s/sign.ts +53 -0
- package/src/schemas/approvals.ts +41 -0
- package/src/schemas/automations.ts +4 -3
- package/src/schemas/command-admission.ts +4 -1
- package/src/schemas/contact-need.ts +26 -0
- package/src/schemas/contacts-settings.ts +16 -0
- package/src/schemas/issues.ts +1 -0
- package/src/schemas/links.ts +4 -0
- package/src/schemas/need-kinds.ts +2 -2
- package/src/schemas/needs.ts +5 -18
- package/src/schemas/redirect-need.ts +19 -0
- package/src/schemas/s2s-identity.ts +329 -0
- package/src/schemas/s2s-views.ts +326 -0
- package/src/schemas/s2s-wire.ts +401 -0
- package/src/schemas/s2s.test.ts +175 -0
- package/src/schemas/s2s.ts +9 -0
- package/src/schemas/settings.ts +2 -0
- package/src/schemas/terminal.ts +6 -0
- package/src/schemas/version-seam.test.ts +9 -0
- package/src/schemas/vpn.ts +13 -0
- package/src/state/auth-state.ts +10 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DROP_BYTES_MAX, DROP_FILES_MAX, DropFileSchema } from "./account-routes.js";
|
|
3
|
+
import { ConversationBundleSchema, DiagnosticsAnswerSchema, DiagnosticsQuerySchema } from "./diagnostics.js";
|
|
4
|
+
import { AccountReportSchema } from "./issues.js";
|
|
5
|
+
import {
|
|
6
|
+
LINK_MAX_HOPS,
|
|
7
|
+
LINK_OPERATE_WAIT_S_MAX,
|
|
8
|
+
LinkAnswerSchema,
|
|
9
|
+
LinkExecSchema,
|
|
10
|
+
LinkExecStatusSchema,
|
|
11
|
+
LinkMessageSchema,
|
|
12
|
+
LinkReadAnswerSchema,
|
|
13
|
+
LinkReadSchema,
|
|
14
|
+
LinkTaskSchema,
|
|
15
|
+
LinkTaskStatusSchema,
|
|
16
|
+
LinkWriteAnswerSchema,
|
|
17
|
+
LinkWriteSchema,
|
|
18
|
+
} from "./links.js";
|
|
19
|
+
import {
|
|
20
|
+
HybridSigSchema,
|
|
21
|
+
S2sAddressSchema,
|
|
22
|
+
S2sAttestationSchema,
|
|
23
|
+
S2sBase64UrlSchema,
|
|
24
|
+
S2sClaimsSchema,
|
|
25
|
+
S2sContactScopeSchema,
|
|
26
|
+
S2sFingerprintSchema,
|
|
27
|
+
S2sGrantsSchema,
|
|
28
|
+
S2S_NOTE_MAX,
|
|
29
|
+
S2sPersonSchema,
|
|
30
|
+
S2sRefSchema,
|
|
31
|
+
SandboxIdentitySchema,
|
|
32
|
+
} from "./s2s-identity.js";
|
|
33
|
+
|
|
34
|
+
// SANDBOX-TO-SANDBOX (docs/architecture/messages.md), the wire half: the envelope a message travels in, every kind of
|
|
35
|
+
// payload it can carry, what the inbox door answers, and the call sessions records and operating go through.
|
|
36
|
+
// Re-exported from schemas/s2s.ts.
|
|
37
|
+
|
|
38
|
+
// The sealed body's cap, in bytes; past it the door answers 413 `too_large` before reading further.
|
|
39
|
+
export const S2S_BODY_MAX_BYTES = 16 * 1024 * 1024;
|
|
40
|
+
// The same cap as base64url characters, the body field's own length.
|
|
41
|
+
export const S2S_BODY_MAX_CHARS = Math.ceil(S2S_BODY_MAX_BYTES / 3) * 4;
|
|
42
|
+
// The whole POST /s2s/inbox request: the body and room for the header, the key agreement and the signature.
|
|
43
|
+
export const S2S_ENVELOPE_MAX_BYTES = S2S_BODY_MAX_CHARS + 64 * 1024;
|
|
44
|
+
// A message's own limits: the drops' file count and bytes, and words.
|
|
45
|
+
export const S2S_MESSAGE_FILES_MAX = DROP_FILES_MAX;
|
|
46
|
+
export const S2S_MESSAGE_BYTES_MAX = DROP_BYTES_MAX;
|
|
47
|
+
export const S2S_MESSAGE_TEXT_MAX = 60_000;
|
|
48
|
+
export const S2S_SUBJECT_MAX = 200;
|
|
49
|
+
// How long an envelope id is remembered, so a retry of one already taken answers 200 and changes nothing.
|
|
50
|
+
export const S2S_SEEN_IDS_MS = 30 * 24 * 60 * 60 * 1000;
|
|
51
|
+
// How far an envelope's `sentAt` may be from the receiver's clock when it arrives: at most a day behind, at most five
|
|
52
|
+
// minutes ahead. The outbox seals afresh at every attempt, so an honest envelope is seconds old; one past either bound is
|
|
53
|
+
// refused `replay`, and a day sits well inside the time its id is remembered, so no id is forgotten while it could still be
|
|
54
|
+
// taken (2026-11-27).
|
|
55
|
+
export const S2S_ENVELOPE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
56
|
+
export const S2S_ENVELOPE_MAX_AHEAD_MS = 5 * 60 * 1000;
|
|
57
|
+
// What a stranger (no contact) may send: contact requests only, this many an hour per address and in all.
|
|
58
|
+
export const S2S_STRANGER_REQUESTS_PER_ADDRESS_HOUR = 3;
|
|
59
|
+
export const S2S_STRANGER_REQUESTS_PER_HOUR = 30;
|
|
60
|
+
// The per-contact minute limit by kind, as the passes had.
|
|
61
|
+
export const S2S_PER_MINUTE = { message: 60, report: 30, task: 10 } as const;
|
|
62
|
+
// The outbox: retried for a week, `min(30 s · 2^n, 30 min)` unless the far side says Retry-After.
|
|
63
|
+
export const S2S_OUTBOX_KEEP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
64
|
+
export const S2S_OUTBOX_BACKOFF_BASE_MS = 30_000;
|
|
65
|
+
export const S2S_OUTBOX_BACKOFF_MAX_MS = 30 * 60 * 1000;
|
|
66
|
+
// The query parameter an attempt to a contact holding this sandbox's wake grant carries its secret in.
|
|
67
|
+
export const S2S_WAKE_QUERY = "wake";
|
|
68
|
+
// Calls: the header naming the session, how long a session lives, and how far a call's clock may be from the callee's.
|
|
69
|
+
export const S2S_SESSION_HEADER = "x-intentic-s2s-session";
|
|
70
|
+
export const S2S_SESSION_TTL_MS = 60 * 60 * 1000;
|
|
71
|
+
export const S2S_CALL_SKEW_MS = 2 * 60 * 1000;
|
|
72
|
+
|
|
73
|
+
// An envelope's id: a UUIDv7, so ids sort by when they were made.
|
|
74
|
+
export const S2sEnvelopeIdSchema = z
|
|
75
|
+
.string()
|
|
76
|
+
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u)
|
|
77
|
+
.describe("A UUIDv7.");
|
|
78
|
+
|
|
79
|
+
export const S2S_PAYLOAD_KINDS = [
|
|
80
|
+
"contact.request",
|
|
81
|
+
"contact.accept",
|
|
82
|
+
"contact.update",
|
|
83
|
+
"contact.remove",
|
|
84
|
+
"identity.rotated",
|
|
85
|
+
"message",
|
|
86
|
+
"report",
|
|
87
|
+
"task.request",
|
|
88
|
+
"task.update",
|
|
89
|
+
"task.message",
|
|
90
|
+
"task.answer",
|
|
91
|
+
"task.stop",
|
|
92
|
+
"receipt",
|
|
93
|
+
"attestation.request",
|
|
94
|
+
"attestation.issued",
|
|
95
|
+
] as const;
|
|
96
|
+
export const S2sPayloadKindSchema = z.enum(S2S_PAYLOAD_KINDS);
|
|
97
|
+
export type S2sPayloadKind = z.infer<typeof S2sPayloadKindSchema>;
|
|
98
|
+
export const isS2sPayloadKind = (kind: string): kind is S2sPayloadKind => S2S_PAYLOAD_KINDS.some((known) => known === kind);
|
|
99
|
+
|
|
100
|
+
// The header, in the clear and signed. `kind` is any word here so a kind this build does not know is refused by name
|
|
101
|
+
// (422 `unknown_kind`), never misread. Loose, as the identity document is, so a later field still verifies; the type
|
|
102
|
+
// names the fields this build knows.
|
|
103
|
+
const headerFields = {
|
|
104
|
+
v: z.literal(1),
|
|
105
|
+
id: S2sEnvelopeIdSchema,
|
|
106
|
+
from: S2sAddressSchema.describe("The sender's address, as the receiver knows it."),
|
|
107
|
+
fromFp: S2sFingerprintSchema.describe("The key set the sender signed with."),
|
|
108
|
+
to: S2sAddressSchema.describe("The receiver's address."),
|
|
109
|
+
toFp: S2sFingerprintSchema.describe("The receiver's key set the body is sealed to: its current one or a kept previous one."),
|
|
110
|
+
kind: z.string().min(1).max(64).describe("The payload's kind (S2S_PAYLOAD_KINDS)."),
|
|
111
|
+
thread: S2sRefSchema.optional().describe("The thread it belongs to, as the sender names it."),
|
|
112
|
+
replyTo: S2sEnvelopeIdSchema.optional().describe("The envelope it answers."),
|
|
113
|
+
as: S2sPersonSchema.optional().describe("The person of a person-scoped contact it travels for."),
|
|
114
|
+
hops: z.number().int().min(0).max(10).describe("How many sandboxes the work it carries already crossed (LINK_MAX_HOPS)."),
|
|
115
|
+
sentAt: z.number().int().nonnegative().describe("When it was sealed, in epoch milliseconds."),
|
|
116
|
+
};
|
|
117
|
+
export const S2sEnvelopeHeaderSchema = z.looseObject(headerFields);
|
|
118
|
+
export type S2sEnvelopeHeader = z.infer<z.ZodObject<typeof headerFields>>;
|
|
119
|
+
|
|
120
|
+
// The hybrid key agreement to the receiver's key set: an ephemeral X25519 key, an ML-KEM-768 ciphertext, the AEAD nonce.
|
|
121
|
+
export const S2sEncSchema = z.object({
|
|
122
|
+
x25519: S2sBase64UrlSchema.describe("The sender's ephemeral X25519 public key, 32 bytes."),
|
|
123
|
+
mlkem768: S2sBase64UrlSchema.describe("The ML-KEM-768 ciphertext to the receiver's key, 1088 bytes."),
|
|
124
|
+
nonce: S2sBase64UrlSchema.describe("The AES-256-GCM nonce, 12 bytes."),
|
|
125
|
+
});
|
|
126
|
+
export type S2sEnc = z.infer<typeof S2sEncSchema>;
|
|
127
|
+
|
|
128
|
+
const envelopeFields = {
|
|
129
|
+
...headerFields,
|
|
130
|
+
enc: S2sEncSchema,
|
|
131
|
+
body: S2sBase64UrlSchema.max(S2S_BODY_MAX_CHARS).describe("The payload as JSON, sealed with AES-256-GCM; the tag at its end."),
|
|
132
|
+
sig: HybridSigSchema.describe("The sender's signature over the canonical header, `enc` and `body`."),
|
|
133
|
+
};
|
|
134
|
+
export const S2sEnvelopeSchema = z.looseObject(envelopeFields).describe("One signed, encrypted message between two sandboxes (POST /s2s/inbox).");
|
|
135
|
+
export type S2sEnvelope = z.infer<z.ZodObject<typeof envelopeFields>>;
|
|
136
|
+
|
|
137
|
+
/* PAYLOADS: the body, once opened, by kind. */
|
|
138
|
+
|
|
139
|
+
// A message's file, whole: its own name (never a path) and its bytes in base64, as a drop carried them.
|
|
140
|
+
export const S2sAttachmentSchema = DropFileSchema;
|
|
141
|
+
export type S2sAttachment = z.infer<typeof S2sAttachmentSchema>;
|
|
142
|
+
|
|
143
|
+
const wakeSecret = z.string().min(32).max(200).describe("This sandbox's wake secret, handed to a contact it grants `wake`.");
|
|
144
|
+
const taskRef = S2sRefSchema.describe("The task, by the asking side's own request id for it (LinkTask `requestId`).");
|
|
145
|
+
|
|
146
|
+
export const S2sContactRequestSchema = z.object({
|
|
147
|
+
kind: z.literal("contact.request"),
|
|
148
|
+
document: SandboxIdentitySchema.describe("The asking sandbox's identity; the receiver confirms it by fetching it from the claimed address."),
|
|
149
|
+
note: z.string().max(S2S_NOTE_MAX).optional().describe("Why it asks, in its own words."),
|
|
150
|
+
grants: S2sGrantsSchema.describe("What the asking sandbox gives the receiver, informational there."),
|
|
151
|
+
scope: S2sContactScopeSchema,
|
|
152
|
+
wake: wakeSecret.optional(),
|
|
153
|
+
});
|
|
154
|
+
export const S2sContactAcceptSchema = z.object({
|
|
155
|
+
kind: z.literal("contact.accept"),
|
|
156
|
+
document: SandboxIdentitySchema,
|
|
157
|
+
grants: S2sGrantsSchema.describe("What the accepting sandbox gives the asking one."),
|
|
158
|
+
wake: wakeSecret.optional(),
|
|
159
|
+
});
|
|
160
|
+
export const S2sContactUpdateSchema = z.object({
|
|
161
|
+
kind: z.literal("contact.update"),
|
|
162
|
+
grants: S2sGrantsSchema.optional().describe("The grants as they are now, when they changed."),
|
|
163
|
+
wake: wakeSecret.nullable().optional().describe("A new wake secret, or null when the grant was taken away."),
|
|
164
|
+
});
|
|
165
|
+
export const S2sContactRemoveSchema = z.object({
|
|
166
|
+
kind: z.literal("contact.remove"),
|
|
167
|
+
reason: z.string().max(S2S_NOTE_MAX).optional(),
|
|
168
|
+
});
|
|
169
|
+
export const S2sIdentityRotatedSchema = z.object({
|
|
170
|
+
kind: z.literal("identity.rotated"),
|
|
171
|
+
document: SandboxIdentitySchema.describe("The new document; its `prev` is signed by the key the contact pinned, or by the recovery key."),
|
|
172
|
+
});
|
|
173
|
+
export const S2sMessagePayloadSchema = z.object({
|
|
174
|
+
kind: z.literal("message"),
|
|
175
|
+
subject: z.string().max(S2S_SUBJECT_MAX).optional(),
|
|
176
|
+
text: z.string().max(S2S_MESSAGE_TEXT_MAX),
|
|
177
|
+
attachments: z.array(S2sAttachmentSchema).max(S2S_MESSAGE_FILES_MAX).default([]),
|
|
178
|
+
});
|
|
179
|
+
// A problem report, the account report's own fields (schemas/issues.ts), handed to the issues extension as before, and the
|
|
180
|
+
// project it is about, which a pass used to carry.
|
|
181
|
+
export const S2sReportPayloadSchema = AccountReportSchema.extend({
|
|
182
|
+
kind: z.literal("report"),
|
|
183
|
+
project: z.string().min(1).max(200).describe("The project it is about, as the receiving sandbox claims it (github.com/owner/repo)."),
|
|
184
|
+
});
|
|
185
|
+
// A task, the link task's own fields (schemas/links.ts).
|
|
186
|
+
export const S2sTaskRequestSchema = LinkTaskSchema.extend({ kind: z.literal("task.request") });
|
|
187
|
+
export const S2sTaskUpdateSchema = z.object({ kind: z.literal("task.update"), task: taskRef, status: LinkTaskStatusSchema });
|
|
188
|
+
export const S2sTaskMessageSchema = z.object({ kind: z.literal("task.message"), task: taskRef, message: LinkMessageSchema });
|
|
189
|
+
export const S2sTaskAnswerSchema = z.object({ kind: z.literal("task.answer"), task: taskRef, answer: LinkAnswerSchema });
|
|
190
|
+
export const S2sTaskStopSchema = z.object({ kind: z.literal("task.stop"), task: taskRef });
|
|
191
|
+
export const S2sReceiptSchema = z.object({
|
|
192
|
+
kind: z.literal("receipt"),
|
|
193
|
+
of: S2sEnvelopeIdSchema.describe("The envelope it is about."),
|
|
194
|
+
read: z.boolean().describe("A person (or the turn acting for one) read it."),
|
|
195
|
+
at: z.number().int().nonnegative(),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Attestations (docs/architecture/messages.md, "Attestations"), under the contact's `message` grant and between
|
|
199
|
+
// sandbox-scoped contacts only, since each is the sandbox speaking as itself. Neither is acted on when it arrives: it waits
|
|
200
|
+
// in the contact's thread for a person there, who issues a vouch for a request or adds an issued one to the identity.
|
|
201
|
+
// A request: the sandbox asks the contact to vouch for it, with the claims it hopes for. The issuer signs what it decides.
|
|
202
|
+
export const S2sAttestationRequestSchema = z.object({
|
|
203
|
+
kind: z.literal("attestation.request"),
|
|
204
|
+
claims: S2sClaimsSchema.describe("The claims it asks to be vouched for, in its own words."),
|
|
205
|
+
note: z.string().max(S2S_NOTE_MAX).optional().describe("Why it asks, or how the contact could check."),
|
|
206
|
+
});
|
|
207
|
+
// An issued one: the contact's signed vouch for this sandbox, sent by its issuer; the envelope's `replyTo` names the
|
|
208
|
+
// request it answers, when it answers one.
|
|
209
|
+
export const S2sAttestationIssuedSchema = z.object({
|
|
210
|
+
kind: z.literal("attestation.issued"),
|
|
211
|
+
attestation: S2sAttestationSchema.describe("The attestation, signed by the sender about the receiver."),
|
|
212
|
+
note: z.string().max(S2S_NOTE_MAX).optional(),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* The line a thread files an attestation's message under: the note it came with, else its claims by name ("kind:
|
|
217
|
+
* organisation, country: PL"). The daemon writes it; the editor, which draws the claims themselves, leaves out a line
|
|
218
|
+
* that is only them.
|
|
219
|
+
*/
|
|
220
|
+
export const attestationText = (claims: Readonly<Record<string, string | number | boolean>>, note?: string): string => {
|
|
221
|
+
if (note !== undefined && note.trim() !== "") {
|
|
222
|
+
return note;
|
|
223
|
+
}
|
|
224
|
+
const named = Object.entries(claims).map(([name, value]) => `${name}: ${String(value)}`);
|
|
225
|
+
return named.length === 0 ? "No claims named." : named.join(", ");
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export const S2sPayloadSchema = z.discriminatedUnion("kind", [
|
|
229
|
+
S2sContactRequestSchema,
|
|
230
|
+
S2sContactAcceptSchema,
|
|
231
|
+
S2sContactUpdateSchema,
|
|
232
|
+
S2sContactRemoveSchema,
|
|
233
|
+
S2sIdentityRotatedSchema,
|
|
234
|
+
S2sMessagePayloadSchema,
|
|
235
|
+
S2sReportPayloadSchema,
|
|
236
|
+
S2sTaskRequestSchema,
|
|
237
|
+
S2sTaskUpdateSchema,
|
|
238
|
+
S2sTaskMessageSchema,
|
|
239
|
+
S2sTaskAnswerSchema,
|
|
240
|
+
S2sTaskStopSchema,
|
|
241
|
+
S2sReceiptSchema,
|
|
242
|
+
S2sAttestationRequestSchema,
|
|
243
|
+
S2sAttestationIssuedSchema,
|
|
244
|
+
]);
|
|
245
|
+
export type S2sPayload = z.infer<typeof S2sPayloadSchema>;
|
|
246
|
+
export type S2sPayloadOf<K extends S2sPayloadKind> = Extract<S2sPayload, { readonly kind: K }>;
|
|
247
|
+
|
|
248
|
+
/* THE INBOX DOOR's answers. */
|
|
249
|
+
|
|
250
|
+
export const S2sInboxAcceptedSchema = z.object({
|
|
251
|
+
ok: z.literal(true),
|
|
252
|
+
id: S2sEnvelopeIdSchema,
|
|
253
|
+
duplicate: z.boolean().optional().describe("It had already arrived; nothing changed."),
|
|
254
|
+
});
|
|
255
|
+
export type S2sInboxAccepted = z.infer<typeof S2sInboxAcceptedSchema>;
|
|
256
|
+
|
|
257
|
+
// Why a door refused, with the status it answers. A blocked sender is never told: it is answered as if accepted.
|
|
258
|
+
export const S2S_REFUSAL_CODES = [
|
|
259
|
+
"malformed",
|
|
260
|
+
"signature",
|
|
261
|
+
"not_contact",
|
|
262
|
+
"grant",
|
|
263
|
+
"floor",
|
|
264
|
+
"key_changed",
|
|
265
|
+
"unconfirmed",
|
|
266
|
+
"recipient",
|
|
267
|
+
"hops",
|
|
268
|
+
"too_large",
|
|
269
|
+
"unknown_kind",
|
|
270
|
+
"rate",
|
|
271
|
+
"unready",
|
|
272
|
+
"task",
|
|
273
|
+
"session",
|
|
274
|
+
"replay",
|
|
275
|
+
] as const;
|
|
276
|
+
export const S2sRefusalCodeSchema = z
|
|
277
|
+
.enum(S2S_REFUSAL_CODES)
|
|
278
|
+
.describe(
|
|
279
|
+
"malformed: not an envelope. signature: it does not verify against the pinned key. not_contact: a stranger may only ask to be one. grant: the contact lacks the grant for this kind. floor: a person-scoped contact's person is not on the roster above the kind's floor. key_changed: held until a person trusts the new key. unconfirmed: a request's document is not what its address serves. recipient: not this sandbox's address or key. hops: crossed too many sandboxes. too_large: past the size cap. unknown_kind: a kind this build does not know. rate: past the per-contact minute limit (retried). unready: nothing here takes this kind yet (retried). task: the task cannot be taken or acted on as asked (no such task, one not allowed yet or declined, the task grant's hourly turns spent), in words, never retried. session: a call names no session this sandbox holds (it expired, this sandbox restarted, or a key changed since it opened): open a new one. replay: a call or session request outside the clock window, or one seen before; an envelope sealed more than a day before it arrived or more than five minutes ahead of the receiver's clock.",
|
|
280
|
+
);
|
|
281
|
+
export type S2sRefusalCode = z.infer<typeof S2sRefusalCodeSchema>;
|
|
282
|
+
// 403, 409 and 422 end a send at once; 429 and 503 are tried again. Never 401, which a sender reads as a daemon too old
|
|
283
|
+
// for the door.
|
|
284
|
+
export const S2S_REFUSAL_STATUS = {
|
|
285
|
+
malformed: 400,
|
|
286
|
+
signature: 403,
|
|
287
|
+
not_contact: 403,
|
|
288
|
+
grant: 403,
|
|
289
|
+
floor: 403,
|
|
290
|
+
key_changed: 403,
|
|
291
|
+
unconfirmed: 403,
|
|
292
|
+
recipient: 409,
|
|
293
|
+
hops: 409,
|
|
294
|
+
too_large: 413,
|
|
295
|
+
unknown_kind: 422,
|
|
296
|
+
rate: 429,
|
|
297
|
+
unready: 503,
|
|
298
|
+
task: 409,
|
|
299
|
+
session: 409,
|
|
300
|
+
replay: 409,
|
|
301
|
+
} as const satisfies Record<S2sRefusalCode, number>;
|
|
302
|
+
export const S2sRefusalSchema = z.object({
|
|
303
|
+
error: z.string().describe("Why, in words a person can act on."),
|
|
304
|
+
code: S2sRefusalCodeSchema,
|
|
305
|
+
});
|
|
306
|
+
export type S2sRefusal = z.infer<typeof S2sRefusalSchema>;
|
|
307
|
+
|
|
308
|
+
/* CALLS: records and operating, request and response under a session key; nothing stored or retried. */
|
|
309
|
+
|
|
310
|
+
// POST /s2s/session: a fresh key agreement to the callee's key, signed by the caller. Loose for the same reason as the
|
|
311
|
+
// envelope header: the signature covers every field.
|
|
312
|
+
const sessionOpenFields = {
|
|
313
|
+
v: z.literal(1),
|
|
314
|
+
from: S2sAddressSchema,
|
|
315
|
+
fromFp: S2sFingerprintSchema,
|
|
316
|
+
to: S2sAddressSchema,
|
|
317
|
+
toFp: S2sFingerprintSchema,
|
|
318
|
+
as: S2sPersonSchema.optional().describe("The person of a person-scoped contact the calls are for."),
|
|
319
|
+
at: z.number().int().nonnegative().describe("When it was made, in epoch milliseconds; within S2S_CALL_SKEW_MS of the callee's clock."),
|
|
320
|
+
nonce: S2sBase64UrlSchema.describe("16 random bytes."),
|
|
321
|
+
enc: S2sEncSchema.omit({ nonce: true }),
|
|
322
|
+
sig: HybridSigSchema.describe("The caller's signature over the canonical request without `sig`."),
|
|
323
|
+
};
|
|
324
|
+
export const S2sSessionOpenSchema = z.looseObject(sessionOpenFields);
|
|
325
|
+
export type S2sSessionOpen = z.infer<z.ZodObject<typeof sessionOpenFields>>;
|
|
326
|
+
|
|
327
|
+
export const S2sSessionAnswerSchema = z.object({
|
|
328
|
+
session: S2sRefSchema.describe("The session's id, sent back in x-intentic-s2s-session on every call."),
|
|
329
|
+
expiresAt: z.number().int().describe("When the callee forgets it, in epoch milliseconds."),
|
|
330
|
+
confirm: S2sBase64UrlSchema.describe("HMAC-SHA256 under the session key over the session id: the callee derived the same key."),
|
|
331
|
+
});
|
|
332
|
+
export type S2sSessionAnswer = z.infer<typeof S2sSessionAnswerSchema>;
|
|
333
|
+
|
|
334
|
+
// What a sealed answer opens to: the method's status and what it answered, its output (S2S_CALLS) at 200 and a refusal in
|
|
335
|
+
// words (`error`, or the fleet reads' own `message`) otherwise. Sealed whole, so the edge reads no more of an answer than
|
|
336
|
+
// that one came back.
|
|
337
|
+
export const S2sCallAnswerSchema = z.object({
|
|
338
|
+
status: z.number().int().min(200).max(599).describe("The method's own status: 200, or why it refused (404 nothing by that name, 409, 429, 503)."),
|
|
339
|
+
body: z.unknown().describe("The method's output at 200; a refusal in words otherwise."),
|
|
340
|
+
});
|
|
341
|
+
export type S2sCallAnswer = z.infer<typeof S2sCallAnswerSchema>;
|
|
342
|
+
|
|
343
|
+
// A call's body or its answer, sealed under the session key with a fresh nonce.
|
|
344
|
+
export const S2sCallSealedSchema = z.object({
|
|
345
|
+
at: z.number().int().nonnegative().describe("When it was sealed, in epoch milliseconds."),
|
|
346
|
+
nonce: S2sBase64UrlSchema.describe("12 random bytes, never seen before in the session."),
|
|
347
|
+
body: S2sBase64UrlSchema.max(S2S_BODY_MAX_CHARS).describe("The method's input or answer as JSON, AES-256-GCM sealed."),
|
|
348
|
+
});
|
|
349
|
+
export type S2sCallSealed = z.infer<typeof S2sCallSealedSchema>;
|
|
350
|
+
|
|
351
|
+
export const S2S_CALL_METHODS = [
|
|
352
|
+
"records.fleet",
|
|
353
|
+
"records.show",
|
|
354
|
+
"records.bundle",
|
|
355
|
+
"records.diagnostics",
|
|
356
|
+
"operate.exec",
|
|
357
|
+
"operate.status",
|
|
358
|
+
"operate.stop",
|
|
359
|
+
"operate.read",
|
|
360
|
+
"operate.write",
|
|
361
|
+
"task.watch",
|
|
362
|
+
] as const;
|
|
363
|
+
export const S2sCallMethodSchema = z.enum(S2S_CALL_METHODS);
|
|
364
|
+
export type S2sCallMethod = z.infer<typeof S2sCallMethodSchema>;
|
|
365
|
+
|
|
366
|
+
const handle = z.string().min(1).max(200).describe("A conversation, by handle or id, as `agents show` takes it.");
|
|
367
|
+
// The rest of a fleet read's query, as `agents ls|find|show` spell it over HTTP (limit, all, repo, owner, transcript, last,
|
|
368
|
+
// grep, message, raw, stored, diff…).
|
|
369
|
+
const fleetQuery = z.record(z.string().max(40), z.string().max(2000)).optional().describe("The read's other query parameters, as `agents ls|show` send them.");
|
|
370
|
+
// The fleet reads answer what the `agents` command's own routes answer, which share no schema yet.
|
|
371
|
+
const FleetAnswerSchema = z.record(z.string(), z.unknown()).describe("What `agents ls|find|show` answers here.");
|
|
372
|
+
|
|
373
|
+
const commandId = z.string().min(1).max(100).describe("The command, by the id operate.exec answered.");
|
|
374
|
+
export const S2sOperateStatusInputSchema = z.object({
|
|
375
|
+
id: commandId,
|
|
376
|
+
waitS: z.number().int().min(0).max(LINK_OPERATE_WAIT_S_MAX).optional().describe("Hold the call this long for it to end."),
|
|
377
|
+
});
|
|
378
|
+
export const S2sTaskWatchInputSchema = z.object({
|
|
379
|
+
task: taskRef,
|
|
380
|
+
after: z.number().int().nonnegative().optional().describe("Answer once the status's version moves past this one."),
|
|
381
|
+
waitS: z.number().int().min(0).max(25).optional(),
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// Each method's input and answer, opened from the sealed call and answer.
|
|
385
|
+
export const S2S_CALLS = {
|
|
386
|
+
"records.fleet": { grant: "records", input: z.object({ q: z.string().max(200).optional(), query: fleetQuery }), output: FleetAnswerSchema },
|
|
387
|
+
"records.show": { grant: "records", input: z.object({ handle, query: fleetQuery }), output: FleetAnswerSchema },
|
|
388
|
+
"records.bundle": { grant: "records", input: z.object({ handle }), output: ConversationBundleSchema },
|
|
389
|
+
"records.diagnostics": { grant: "records", input: DiagnosticsQuerySchema, output: DiagnosticsAnswerSchema },
|
|
390
|
+
"operate.exec": { grant: "operate", input: LinkExecSchema, output: LinkExecStatusSchema },
|
|
391
|
+
"operate.status": { grant: "operate", input: S2sOperateStatusInputSchema, output: LinkExecStatusSchema },
|
|
392
|
+
"operate.stop": { grant: "operate", input: z.object({ id: commandId }), output: LinkExecStatusSchema },
|
|
393
|
+
"operate.read": { grant: "operate", input: LinkReadSchema, output: LinkReadAnswerSchema },
|
|
394
|
+
"operate.write": { grant: "operate", input: LinkWriteSchema, output: LinkWriteAnswerSchema },
|
|
395
|
+
"task.watch": { grant: "task", input: S2sTaskWatchInputSchema, output: LinkTaskStatusSchema },
|
|
396
|
+
} as const satisfies Record<S2sCallMethod, { readonly grant: "records" | "operate" | "task"; readonly input: z.ZodType; readonly output: z.ZodType }>;
|
|
397
|
+
export type S2sCallInput<M extends S2sCallMethod> = z.input<(typeof S2S_CALLS)[M]["input"]>;
|
|
398
|
+
export type S2sCallOutput<M extends S2sCallMethod> = z.output<(typeof S2S_CALLS)[M]["output"]>;
|
|
399
|
+
|
|
400
|
+
// LINK_MAX_HOPS, under the name the inbox's hop check reads.
|
|
401
|
+
export const S2S_MAX_HOPS = LINK_MAX_HOPS;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { RAW_JSON_ROUTES } from "../protocol/raw/raw-json-routes.js";
|
|
2
|
+
import { RAW_ROUTES } from "../protocol/raw/raw-routes.js";
|
|
3
|
+
import { LINK_TURNS_PER_HOUR_DEFAULT } from "./links.js";
|
|
4
|
+
import { NeedAskSchema, NeedSubjectSchema } from "./needs.js";
|
|
5
|
+
import {
|
|
6
|
+
S2S_CALL_METHODS,
|
|
7
|
+
S2S_CALLS,
|
|
8
|
+
S2S_CLAIM_VALUE_MAX,
|
|
9
|
+
S2S_CLAIMS_MAX,
|
|
10
|
+
S2S_PAYLOAD_KINDS,
|
|
11
|
+
S2S_REFUSAL_CODES,
|
|
12
|
+
S2S_REFUSAL_STATUS,
|
|
13
|
+
S2sAddressSchema,
|
|
14
|
+
S2sClaimsSchema,
|
|
15
|
+
S2sContactScopeSchema,
|
|
16
|
+
S2sGrantsSchema,
|
|
17
|
+
S2sPayloadSchema,
|
|
18
|
+
S2sTaskGrantSchema,
|
|
19
|
+
} from "./s2s.js";
|
|
20
|
+
|
|
21
|
+
const s2sRoutes = Object.entries(RAW_ROUTES).filter(([key]) => key.includes(` /s2s/`) || key.endsWith(`/upgrade`) || key.endsWith(`/contact-bootstrap`));
|
|
22
|
+
|
|
23
|
+
describe("grants", () => {
|
|
24
|
+
it("default to messages only", () => {
|
|
25
|
+
expect(S2sGrantsSchema.parse({})).toEqual({ message: true, report: false, records: false, operate: false, wake: false });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("carry a task grant as the link terms do, under their names and defaults", () => {
|
|
29
|
+
expect(S2sTaskGrantSchema.parse({})).toEqual({ approve: false, turnsPerHour: LINK_TURNS_PER_HOUR_DEFAULT });
|
|
30
|
+
expect(S2sTaskGrantSchema.parse({ actsAs: `reviewer`, approve: true })).toEqual({ actsAs: `reviewer`, approve: true, turnsPerHour: LINK_TURNS_PER_HOUR_DEFAULT });
|
|
31
|
+
expect(S2sTaskGrantSchema.safeParse({ turnsPerHour: 121 }).success).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("addresses and scopes", () => {
|
|
36
|
+
it("take a host, a domain, localhost with a port, and nothing uppercase or with a path", () => {
|
|
37
|
+
for (const ok of [`0123456789ab.sandbox.example`, `ops.acme.example`, `localhost:8443`, `a.b:65535`]) {
|
|
38
|
+
expect(S2sAddressSchema.safeParse(ok).success).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
for (const bad of [`Ops.Example`, `ops.example/x`, `ops`, `https://ops.example`, `ops.example.`]) {
|
|
41
|
+
expect(S2sAddressSchema.safeParse(bad).success).toBe(false);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("names the person of a person-scoped contact and nobody for a sandbox-scoped one", () => {
|
|
46
|
+
expect(S2sContactScopeSchema.parse({ kind: `person`, person: `ada@acme.example` })).toEqual({ kind: `person`, person: `ada@acme.example` });
|
|
47
|
+
expect(S2sContactScopeSchema.safeParse({ kind: `person` }).success).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("payloads", () => {
|
|
52
|
+
it("have one schema per kind the header may name, and refuse any other", () => {
|
|
53
|
+
expect(S2S_PAYLOAD_KINDS.length).toBe(15);
|
|
54
|
+
expect(S2sPayloadSchema.safeParse({ kind: `poll.vote` }).success).toBe(false);
|
|
55
|
+
expect(S2sPayloadSchema.parse({ kind: `message`, text: `hi` })).toEqual({ kind: `message`, text: `hi`, attachments: [] });
|
|
56
|
+
expect(S2sPayloadSchema.parse({ kind: `task.stop`, task: `r-1` })).toEqual({ kind: `task.stop`, task: `r-1` });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("carry a report and a task in the account report's and the link task's own fields", () => {
|
|
60
|
+
const report = { kind: `report`, project: `github.com/acme/app`, report: { kind: `detection`, title: `x`, fingerprint: `f`, message: `m` }, times: 2 };
|
|
61
|
+
expect(S2sPayloadSchema.safeParse(report).success).toBe(true);
|
|
62
|
+
// The project a pass used to carry rides the report itself.
|
|
63
|
+
const { project: _project, ...unnamed } = report;
|
|
64
|
+
expect(S2sPayloadSchema.safeParse(unnamed).success).toBe(false);
|
|
65
|
+
expect(S2sPayloadSchema.parse({ kind: `task.request`, requestId: `r-1`, task: `do it` })).toEqual({ kind: `task.request`, requestId: `r-1`, task: `do it`, hops: 0 });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("attestation payloads", () => {
|
|
70
|
+
it("carry a request's claims and note, and an issued attestation whole, of a type this build reads or not", () => {
|
|
71
|
+
const request = { kind: `attestation.request`, claims: { kind: `organisation`, over18: true, staff: 12 }, note: `we met in Gdańsk` } as const;
|
|
72
|
+
expect(S2sPayloadSchema.parse(request)).toEqual(request);
|
|
73
|
+
expect(S2sPayloadSchema.safeParse({ kind: `attestation.request`, claims: { Kind: `person` } }).success).toBe(false);
|
|
74
|
+
const later = { kind: `attestation.issued`, attestation: { type: `zk-uniqueness`, v: 2, proof: `…` } } as const;
|
|
75
|
+
expect(S2sPayloadSchema.parse(later)).toEqual(later);
|
|
76
|
+
expect(S2sPayloadSchema.safeParse({ kind: `attestation.issued`, attestation: { v: 1 } }).success).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("bound the claims by count, by a word's length and by their bytes whole", () => {
|
|
80
|
+
const claims = (count: number, value: string) => Object.fromEntries(Array.from({ length: count }, (_, at) => [`c${at}`, value]));
|
|
81
|
+
expect(S2sClaimsSchema.safeParse(claims(S2S_CLAIMS_MAX, `x`)).success).toBe(true);
|
|
82
|
+
expect(S2sClaimsSchema.safeParse(claims(S2S_CLAIMS_MAX + 1, `x`)).success).toBe(false);
|
|
83
|
+
expect(S2sClaimsSchema.safeParse({ name: `x`.repeat(S2S_CLAIM_VALUE_MAX) }).success).toBe(true);
|
|
84
|
+
expect(S2sClaimsSchema.safeParse({ name: `x`.repeat(S2S_CLAIM_VALUE_MAX + 1) }).success).toBe(false);
|
|
85
|
+
// Six words of 120 characters come to 769 bytes of JSON, one past the bytes and well inside the count.
|
|
86
|
+
expect(S2sClaimsSchema.safeParse(claims(6, `x`.repeat(S2S_CLAIM_VALUE_MAX))).success).toBe(false);
|
|
87
|
+
expect(S2sClaimsSchema.safeParse({ ...claims(5, `x`.repeat(S2S_CLAIM_VALUE_MAX)), c5: `x`.repeat(S2S_CLAIM_VALUE_MAX - 1) }).success).toBe(true);
|
|
88
|
+
expect(S2sClaimsSchema.safeParse({ "verified by": `x` }).success).toBe(false);
|
|
89
|
+
expect(S2sClaimsSchema.safeParse({ nested: { a: 1 } }).success).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("refusals", () => {
|
|
94
|
+
it("answer a status for every code and never 401, which a sender reads as a daemon too old for the door", () => {
|
|
95
|
+
expect(Object.keys(S2S_REFUSAL_STATUS).toSorted()).toEqual([...S2S_REFUSAL_CODES].toSorted());
|
|
96
|
+
expect(Object.values(S2S_REFUSAL_STATUS).toSorted((a, b) => a - b)).toEqual([400, 403, 403, 403, 403, 403, 403, 409, 409, 409, 409, 409, 413, 422, 429, 503]);
|
|
97
|
+
expect(S2S_REFUSAL_STATUS.rate).toBe(429);
|
|
98
|
+
// A task refused in words (no such task, not allowed yet, the grant's hourly turns spent) is never retried.
|
|
99
|
+
expect(S2S_REFUSAL_STATUS.task).toBe(409);
|
|
100
|
+
expect(S2S_REFUSAL_STATUS.unready).toBe(503);
|
|
101
|
+
expect(S2S_REFUSAL_STATUS.unknown_kind).toBe(422);
|
|
102
|
+
// A call's session gone, or a call replayed or held back: refused in words, never 401.
|
|
103
|
+
expect(S2S_REFUSAL_STATUS.session).toBe(409);
|
|
104
|
+
expect(S2S_REFUSAL_STATUS.replay).toBe(409);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("calls", () => {
|
|
109
|
+
it("give every method a grant, an input and an answer", () => {
|
|
110
|
+
expect(Object.keys(S2S_CALLS).toSorted()).toEqual([...S2S_CALL_METHODS].toSorted());
|
|
111
|
+
expect(S2S_CALLS[`operate.exec`].grant).toBe(`operate`);
|
|
112
|
+
expect(S2S_CALLS[`records.bundle`].grant).toBe(`records`);
|
|
113
|
+
expect(S2S_CALLS[`task.watch`].grant).toBe(`task`);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("the contact need", () => {
|
|
118
|
+
it("is a need subject and an ask like every other kind", () => {
|
|
119
|
+
const subject = { kind: `contact` as const, address: `ops.acme.example`, action: `add` as const, grants: { report: true } };
|
|
120
|
+
expect(NeedSubjectSchema.parse(subject)).toEqual({ ...subject, grants: { message: true, report: true, records: false, operate: false, wake: false } });
|
|
121
|
+
expect(NeedAskSchema.parse({ kind: `contact`, action: `accept`, contactId: `c-1` })).toEqual({
|
|
122
|
+
kind: `contact`,
|
|
123
|
+
action: `accept`,
|
|
124
|
+
contactId: `c-1`,
|
|
125
|
+
grants: { message: true, report: false, records: false, operate: false, wake: false },
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("the s2s routes", () => {
|
|
131
|
+
it("are doors that check their own credential for another daemon, and no control token reaches any", () => {
|
|
132
|
+
const doors = s2sRoutes.filter(([, meta]) => `auth` in meta && meta.auth === `door`).map(([key]) => key);
|
|
133
|
+
expect(doors.toSorted()).toEqual(
|
|
134
|
+
[
|
|
135
|
+
`GET /s2s/identity`,
|
|
136
|
+
`POST /s2s/inbox`,
|
|
137
|
+
`POST /s2s/session`,
|
|
138
|
+
`POST /s2s/call/{method}`,
|
|
139
|
+
`POST /link/upgrade`,
|
|
140
|
+
`POST /account/pairings/upgrade`,
|
|
141
|
+
`POST /account/contact-bootstrap`,
|
|
142
|
+
].toSorted(),
|
|
143
|
+
);
|
|
144
|
+
expect(s2sRoutes.filter(([, meta]) => !(`control` in meta) || meta.control !== `never`).map(([key]) => key)).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("keep the recovery key the owner's alone", () => {
|
|
148
|
+
expect(RAW_ROUTES[`POST /s2s/me/recovery`]).toEqual({ floor: `owner`, panel: false, control: `never` });
|
|
149
|
+
expect(RAW_ROUTES[`POST /s2s/me/recover`]).toEqual({ floor: `owner`, panel: false, control: `never` });
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("keep attestations the owner's or a maintainer's, and out of every agent's and panel's reach", () => {
|
|
153
|
+
const attestations = s2sRoutes.filter(([key]) => key.includes(`attestations`));
|
|
154
|
+
expect(attestations.map(([key]) => key)).toEqual([
|
|
155
|
+
`GET /s2s/me/attestations`,
|
|
156
|
+
`POST /s2s/me/attestations`,
|
|
157
|
+
`DELETE /s2s/me/attestations/{id}`,
|
|
158
|
+
`POST /s2s/me/attestations/ask`,
|
|
159
|
+
`POST /s2s/attestations/issue`,
|
|
160
|
+
]);
|
|
161
|
+
expect(RAW_ROUTES[`GET /s2s/me/attestations`]).toEqual({ floor: `maintainer`, control: `never` });
|
|
162
|
+
for (const [, meta] of attestations.slice(1)) {
|
|
163
|
+
expect(meta).toEqual({ panel: false, control: `never` });
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("register paired before a contact's id, which would otherwise take it", () => {
|
|
168
|
+
const keys = Object.keys(RAW_ROUTES);
|
|
169
|
+
expect(keys.indexOf(`POST /s2s/contacts/paired`)).toBeLessThan(keys.indexOf(`POST /s2s/contacts/{id}`));
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("answer JSON on every one but a message's file, which answers its bytes", () => {
|
|
173
|
+
expect(s2sRoutes.map(([key]) => key).filter((key) => !(key in RAW_JSON_ROUTES))).toEqual([`GET /s2s/messages/{id}/files/{name}`]);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SANDBOX-TO-SANDBOX (docs/architecture/messages.md): every wire and editor shape of contacts, messages and calls,
|
|
2
|
+
// imported from here. s2s-identity.ts: the identity document, keys, addresses and grants. s2s-wire.ts: the envelope, its
|
|
3
|
+
// payload kinds, the doors' refusals, sessions and calls. s2s-views.ts: what the Messages tab and the `messages` command
|
|
4
|
+
// read and send, and the pairing and upgrade exchanges. contact-need.ts: the card an agent raises to add or accept a
|
|
5
|
+
// contact. The primitives that make and check them are protocol/s2s/ (`@intentic/sandbox-contract/s2s`).
|
|
6
|
+
export * from "./s2s-identity.js";
|
|
7
|
+
export * from "./s2s-wire.js";
|
|
8
|
+
export * from "./s2s-views.js";
|
|
9
|
+
export * from "./contact-need.js";
|
package/src/schemas/settings.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { CommandJudgeModeSchema, ProjectInstallModeSchema } from "../policy/safe
|
|
|
5
5
|
import { ModelRoleSchema } from "../models/model-roles.js";
|
|
6
6
|
import { MODEL_SETUP_ID, ModelSetupSchema } from "../models/model-setups.js";
|
|
7
7
|
import { AdmissionPolicySchema, AdmissionRuleSchema } from "./command-admission.js";
|
|
8
|
+
import { ContactsSettingsSchema } from "./contacts-settings.js";
|
|
8
9
|
import { KeepWarmSettingsSchema } from "./keep-warm.js";
|
|
9
10
|
import { commitAttributionSetting } from "./commit-attribution.js";
|
|
10
11
|
import { autoResumeOnRestartSetting, contextContinuesSetting, continueWhenNeedMetSetting } from "./context-continues.js";
|
|
@@ -694,6 +695,7 @@ export const SandboxSettingsSchema = z.object({
|
|
|
694
695
|
.record(z.string(), AdmissionRuleSchema)
|
|
695
696
|
.default({})
|
|
696
697
|
.describe("What an agent may do out in the world, per kind of action: go ahead, ask first, or never."),
|
|
698
|
+
contacts: ContactsSettingsSchema,
|
|
697
699
|
// Command policy itself lives at .intentic/config/safety.md (edited by the Safety page), not here; this only says
|
|
698
700
|
// whether the judge runs at all. Which model judges is the `safety-judge` job's setup (`roleSetups`), not a field here.
|
|
699
701
|
commandJudge: CommandJudgeModeSchema.default("off").describe(
|
package/src/schemas/terminal.ts
CHANGED
|
@@ -408,6 +408,12 @@ export const SubagentSessionSchema = z.object({
|
|
|
408
408
|
.describe(
|
|
409
409
|
"Handed over as the person the asking conversation acts for, not over a link card: that person is in the conversation there and reads it, and nothing waits for that sandbox's owner to allow it.",
|
|
410
410
|
),
|
|
411
|
+
contact: z
|
|
412
|
+
.string()
|
|
413
|
+
.optional()
|
|
414
|
+
.describe(
|
|
415
|
+
"Handed to a contact (messages.md, Tasks), not over a link card: the contact's id here. A task waiting for its owner is allowed on this sandbox's contact over there, on its Messages tab; `conversationId` is empty until the far side says which conversation it opened.",
|
|
416
|
+
),
|
|
411
417
|
})
|
|
412
418
|
.optional()
|
|
413
419
|
.describe("For a task handed to another sandbox: which one, and the conversation it runs in there."),
|
|
@@ -59,6 +59,15 @@ test("routed networks take a CIDR list and reject what charon could not load", (
|
|
|
59
59
|
expect(IpsecVpnConfigSchema.safeParse({ ...ipsec, routedNetworks: "" }).success).toBe(false);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
// The tunnel MTU arrives as a form's text; absent means no cap at all, never a default one.
|
|
63
|
+
test("an ipsec tunnel MTU is optional, read from text, and bounded to a real packet size", () => {
|
|
64
|
+
expect(IpsecVpnConfigSchema.parse(ipsec).mtu).toBeUndefined();
|
|
65
|
+
expect(IpsecVpnConfigSchema.parse({ ...ipsec, mtu: "1190" }).mtu).toBe(1190);
|
|
66
|
+
expect(IpsecVpnConfigSchema.safeParse({ ...ipsec, mtu: "500" }).success).toBe(false);
|
|
67
|
+
expect(IpsecVpnConfigSchema.safeParse({ ...ipsec, mtu: "9000" }).success).toBe(false);
|
|
68
|
+
expect(IpsecVpnConfigSchema.safeParse({ ...ipsec, mtu: "1300.5" }).success).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
62
71
|
const smb = { provider: "smb", server: "nas.local", share: "archive", username: "agent" };
|
|
63
72
|
|
|
64
73
|
test("a network disk is read-only, auto-negotiated and mounted on start unless it says otherwise", () => {
|