@astrosheep/keiyaku 4.6.31 → 4.6.32
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 +34 -17
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/pi/README.md +16 -18
- package/build/plugins/pi/akuma-tools.ts +31 -38
- package/build/plugins/pi/keiyaku.ts +15 -4
- package/build/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/akuma-call.d.ts +3 -5
- package/build/src/akuma/akuma-call.js +7 -10
- package/build/src/akuma/akuma-errors.d.ts +7 -4
- package/build/src/akuma/akuma-errors.js +16 -12
- package/build/src/akuma/akuma-instance.d.ts +39 -303
- package/build/src/akuma/akuma-instance.js +48 -48
- package/build/src/akuma/akuma-observe.d.ts +5 -4
- package/build/src/akuma/akuma-observe.js +1 -7
- package/build/src/akuma/akuma-owner.d.ts +14 -6
- package/build/src/akuma/akuma-owner.js +33 -27
- package/build/src/akuma/akuma-selection-execution.d.ts +22 -19
- package/build/src/akuma/akuma-selection-execution.js +71 -124
- package/build/src/akuma/akuma-wait.d.ts +3 -3
- package/build/src/akuma/akuma.d.ts +47 -384
- package/build/src/akuma/akuma.js +8 -58
- package/build/src/akuma/archetype.d.ts +16 -19
- package/build/src/akuma/archetype.js +48 -49
- package/build/src/akuma/body.js +31 -26
- package/build/src/akuma/call-initial-tell.d.ts +4 -1
- package/build/src/akuma/call-initial-tell.js +9 -1
- package/build/src/akuma/call-input.d.ts +8 -1
- package/build/src/akuma/call-input.js +27 -18
- package/build/src/akuma/caller.js +2 -1
- package/build/src/akuma/detached-body.js +1 -1
- package/build/src/akuma/heart/facts.d.ts +5 -4
- package/build/src/akuma/heart/facts.js +5 -5
- package/build/src/akuma/heart/soul.js +20 -4
- package/build/src/akuma/identity.d.ts +1 -1
- package/build/src/akuma/identity.js +9 -4
- package/build/src/akuma/index.d.ts +6 -7
- package/build/src/akuma/index.js +2 -3
- package/build/src/akuma/projection.d.ts +3 -0
- package/build/src/akuma/provider-recipe.js +3 -2
- package/build/src/akuma/providers/acp/config.js +11 -10
- package/build/src/akuma/providers/acp/index.js +2 -1
- package/build/src/akuma/providers/codex-app-server/index.js +7 -1
- package/build/src/akuma/providers/grok-build/index.js +2 -1
- package/build/src/akuma/providers/index.d.ts +0 -1
- package/build/src/akuma/providers/index.js +0 -8
- package/build/src/akuma/providers/paseo/index.js +7 -4
- package/build/src/akuma/providers/pi/index.js +4 -3
- package/build/src/akuma/publication.d.ts +1 -2
- package/build/src/akuma/publication.js +16 -14
- package/build/src/akuma/schema.d.ts +3 -49
- package/build/src/akuma/schema.js +6 -147
- package/build/src/akuma/selection-observation.d.ts +281 -240
- package/build/src/akuma/selection-observation.js +122 -68
- package/build/src/akuma/status-projection.d.ts +49 -285
- package/build/src/akuma/status-projection.js +178 -138
- package/build/src/body/amend.js +2 -1
- package/build/src/body/arc.js +3 -2
- package/build/src/body/criteria.js +4 -3
- package/build/src/body/decode.js +2 -1
- package/build/src/body/envelope.js +2 -1
- package/build/src/body/region.d.ts +1 -3
- package/build/src/body/region.js +3 -8
- package/build/src/body-host.d.ts +4 -11
- package/build/src/body-host.js +5 -4
- package/build/src/bounded-list.js +2 -1
- package/build/src/cli/commands/akuma-grammar.d.ts +109 -66
- package/build/src/cli/commands/akuma-grammar.js +75 -95
- package/build/src/cli/commands/akuma.d.ts +8 -3
- package/build/src/cli/commands/akuma.js +63 -122
- package/build/src/cli/commands/contract-grammar.d.ts +3 -135
- package/build/src/cli/commands/contract-grammar.js +125 -218
- package/build/src/cli/commands/contract-help.d.ts +24 -21
- package/build/src/cli/commands/contract-help.js +43 -35
- package/build/src/cli/commands/contract.d.ts +6 -18
- package/build/src/cli/commands/contract.js +65 -272
- package/build/src/cli/commands/debt-grammar.d.ts +2 -4
- package/build/src/cli/commands/debt-grammar.js +22 -190
- package/build/src/cli/commands/debt.js +10 -87
- package/build/src/cli/commands/report.d.ts +2 -4
- package/build/src/cli/coordinates.d.ts +1 -1
- package/build/src/cli/coordinates.js +1 -1
- package/build/src/cli/main.js +9 -3
- package/build/src/cli/parse.d.ts +80 -3
- package/build/src/cli/parse.js +76 -16
- package/build/src/cli/render/akuma-activity.d.ts +19 -24
- package/build/src/cli/render/akuma-activity.js +164 -259
- package/build/src/cli/render/akuma.d.ts +3 -3
- package/build/src/cli/render/akuma.js +36 -43
- package/build/src/cli/render/catalog.d.ts +2 -5
- package/build/src/cli/render/catalog.js +2 -33
- package/build/src/cli/render/contract-history.js +1 -2
- package/build/src/cli/render/contract-observation.d.ts +0 -7
- package/build/src/cli/render/contract-observation.js +0 -3
- package/build/src/cli/render/contract.d.ts +7 -9
- package/build/src/cli/render/contract.js +35 -64
- package/build/src/cli/render/debt.d.ts +3 -11
- package/build/src/cli/render/debt.js +17 -88
- package/build/src/cli/render/delivery-preview.js +4 -4
- package/build/src/cli/render/kanshi-akuma.d.ts +5 -3
- package/build/src/cli/render/kanshi-akuma.js +22 -18
- package/build/src/cli/render/kanshi.d.ts +1 -3
- package/build/src/cli/render/kanshi.js +16 -39
- package/build/src/cli/render/receipt.d.ts +21 -12
- package/build/src/cli/render/receipt.js +49 -44
- package/build/src/cli/render/refusal.d.ts +4 -3
- package/build/src/cli/render/refusal.js +15 -17
- package/build/src/cli/render/settings.d.ts +1 -1
- package/build/src/cli/render/terminal.d.ts +9 -8
- package/build/src/cli/render/terminal.js +48 -32
- package/build/src/cli/render/verbs.d.ts +3 -1
- package/build/src/cli/render/verbs.js +74 -116
- package/build/src/cli/runtime.js +66 -65
- package/build/src/cli/streams.d.ts +2 -9
- package/build/src/cli/streams.js +8 -1
- package/build/src/cli/usage.d.ts +2 -1
- package/build/src/cli/usage.js +3 -2
- package/build/src/contract-worktree.js +2 -10
- package/build/src/core/facts/codec.js +9 -23
- package/build/src/core/facts/errors.d.ts +2 -1
- package/build/src/core/facts/errors.js +3 -3
- package/build/src/core/facts/types.d.ts +2 -13
- package/build/src/core/facts/types.js +1 -6
- package/build/src/core/verbs/abandon.d.ts +1 -2
- package/build/src/core/verbs/amend.d.ts +1 -2
- package/build/src/core/verbs/arc.d.ts +1 -2
- package/build/src/core/verbs/attestation.d.ts +1 -2
- package/build/src/core/verbs/bind.d.ts +1 -2
- package/build/src/core/verbs/deliver.d.ts +1 -2
- package/build/src/core/verbs/placement.d.ts +1 -2
- package/build/src/core/verbs/reintegrate.d.ts +1 -2
- package/build/src/debt/board.d.ts +14 -94
- package/build/src/debt/board.js +25 -160
- package/build/src/debt/catalog.d.ts +0 -2
- package/build/src/debt/catalog.js +1 -22
- package/build/src/debt/document.d.ts +8 -11
- package/build/src/debt/document.js +19 -62
- package/build/src/debt/identity.d.ts +2 -14
- package/build/src/debt/identity.js +19 -49
- package/build/src/debt/index.d.ts +81 -219
- package/build/src/debt/index.js +61 -110
- package/build/src/debt/input.d.ts +19 -5
- package/build/src/debt/input.js +51 -177
- package/build/src/debt/lifecycle-operations.d.ts +1 -3
- package/build/src/debt/lifecycle-operations.js +1 -73
- package/build/src/debt/operation-types.d.ts +24 -128
- package/build/src/debt/operation-types.js +6 -62
- package/build/src/debt/operations.d.ts +8 -17
- package/build/src/debt/operations.js +58 -154
- package/build/src/debt/store.d.ts +0 -2
- package/build/src/debt/store.js +32 -87
- package/build/src/errors.d.ts +28 -0
- package/build/src/errors.js +26 -0
- package/build/src/git/hooks.d.ts +1 -1
- package/build/src/git/observe.d.ts +3 -0
- package/build/src/git/observe.js +19 -5
- package/build/src/git/reconcile.d.ts +3 -16
- package/build/src/git/reconcile.js +0 -18
- package/build/src/git/repository.d.ts +2 -1
- package/build/src/git/repository.js +3 -3
- package/build/src/git/target-placement.d.ts +4 -4
- package/build/src/git/target.d.ts +2 -2
- package/build/src/git/tender.d.ts +1 -2
- package/build/src/git/tender.js +5 -12
- package/build/src/identity/coordinates.d.ts +1 -1
- package/build/src/identity/coordinates.js +3 -2
- package/build/src/identity/normalize.js +2 -1
- package/build/src/identity/selector.js +4 -3
- package/build/src/index.d.ts +34 -57
- package/build/src/index.js +11 -36
- package/build/src/kanshi/counts.d.ts +3 -8
- package/build/src/kanshi/counts.js +6 -14
- package/build/src/kanshi/index.d.ts +22 -7
- package/build/src/kanshi/index.js +30 -4
- package/build/src/kanshi/read.d.ts +81 -270
- package/build/src/kanshi/read.js +39 -199
- package/build/src/kanshi/report.d.ts +340 -1619
- package/build/src/kanshi/report.js +19 -31
- package/build/src/library/address.d.ts +11 -11
- package/build/src/library/address.js +34 -27
- package/build/src/library/akuma-creation.d.ts +210 -79
- package/build/src/library/akuma-creation.js +201 -242
- package/build/src/library/akumas.d.ts +24 -5
- package/build/src/library/akumas.js +96 -29
- package/build/src/library/bind.d.ts +7 -10
- package/build/src/library/bind.js +2 -8
- package/build/src/library/continuation.d.ts +141 -231
- package/build/src/library/continuation.js +22 -31
- package/build/src/library/contract-address.d.ts +6 -9
- package/build/src/library/contract-address.js +11 -16
- package/build/src/library/contract-composition.d.ts +2 -3
- package/build/src/library/contract-composition.js +12 -19
- package/build/src/library/contract-creation.js +33 -34
- package/build/src/library/contract-outcomes.d.ts +1278 -806
- package/build/src/library/contract-outcomes.js +11 -37
- package/build/src/library/contract-settings.d.ts +1 -2
- package/build/src/library/contract-settings.js +5 -7
- package/build/src/library/contract-types.d.ts +42 -67
- package/build/src/library/contract-types.js +15 -56
- package/build/src/library/contract-wait.d.ts +40 -3
- package/build/src/library/contract-wait.js +28 -21
- package/build/src/library/delivery.d.ts +366 -389
- package/build/src/library/delivery.js +5 -25
- package/build/src/library/input.d.ts +31 -5
- package/build/src/library/input.js +40 -40
- package/build/src/library/invocation.d.ts +13 -11
- package/build/src/library/invocation.js +69 -58
- package/build/src/library/kei.d.ts +16 -8
- package/build/src/library/kei.js +459 -19
- package/build/src/library/keiyaku-attribution.d.ts +0 -8
- package/build/src/library/keiyaku-attribution.js +0 -11
- package/build/src/library/keiyaku-classify.d.ts +2 -2
- package/build/src/library/keiyaku-classify.js +40 -59
- package/build/src/library/keiyaku-coordinates.d.ts +3 -8
- package/build/src/library/keiyaku-coordinates.js +6 -26
- package/build/src/library/keiyaku-debt.d.ts +21 -93
- package/build/src/library/keiyaku-debt.js +8 -157
- package/build/src/library/keiyaku-identity.js +5 -4
- package/build/src/library/keiyaku-verbs.d.ts +4004 -3885
- package/build/src/library/keiyaku-verbs.js +309 -271
- package/build/src/library/keiyaku.d.ts +30 -860
- package/build/src/library/keiyaku.js +169 -256
- package/build/src/library/nuke.d.ts +4 -2
- package/build/src/library/nuke.js +5 -1
- package/build/src/library/outcome.d.ts +424 -307
- package/build/src/library/outcome.js +167 -362
- package/build/src/library/reconcile.d.ts +331 -143
- package/build/src/library/reconcile.js +38 -72
- package/build/src/library/refusal.d.ts +20 -28
- package/build/src/library/refusal.js +1 -11
- package/build/src/library/repo.js +4 -3
- package/build/src/library/selection.d.ts +32 -21
- package/build/src/library/selection.js +63 -87
- package/build/src/mcp/adapter.d.ts +6 -0
- package/build/src/mcp/adapter.js +177 -42
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +12 -7
- package/build/src/mcp/output.d.ts +385 -0
- package/build/src/mcp/output.js +193 -0
- package/build/src/plugin/public.d.ts +4 -0
- package/build/src/plugin/runtime.d.ts +1 -1
- package/build/src/plugin/runtime.js +2 -2
- package/build/src/protocol/amend.d.ts +1 -1
- package/build/src/protocol/amend.js +2 -2
- package/build/src/protocol/bind.d.ts +5 -7
- package/build/src/protocol/bind.js +3 -3
- package/build/src/protocol/completion.d.ts +158 -195
- package/build/src/protocol/completion.js +55 -19
- package/build/src/protocol/deliver.d.ts +11 -6
- package/build/src/protocol/deliver.js +30 -30
- package/build/src/protocol/delivery-preview.d.ts +13 -11
- package/build/src/protocol/delivery-preview.js +2 -2
- package/build/src/protocol/execution-observation.d.ts +5 -13
- package/build/src/protocol/intent.d.ts +6 -9
- package/build/src/protocol/intent.js +18 -31
- package/build/src/protocol/operations.d.ts +48 -53
- package/build/src/protocol/operations.js +16 -25
- package/build/src/protocol/outcome.d.ts +3 -1
- package/build/src/protocol/placement.d.ts +1 -2
- package/build/src/protocol/placement.js +1 -1
- package/build/src/protocol/progress.d.ts +1 -0
- package/build/src/protocol/read/status.d.ts +29 -112
- package/build/src/protocol/read/status.js +52 -78
- package/build/src/protocol/reintegrate.d.ts +1 -2
- package/build/src/protocol/reintegrate.js +0 -1
- package/build/src/protocol/result-leaves.d.ts +11 -32
- package/build/src/protocol/result-leaves.js +18 -57
- package/build/src/protocol/result-reasons.d.ts +6 -6
- package/build/src/protocol/review.js +0 -1
- package/build/src/protocol/verify.d.ts +192 -146
- package/build/src/protocol/verify.js +60 -47
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settings.d.ts +8 -9
- package/build/src/settings.js +16 -13
- package/build/src/settlement/holder.js +2 -2
- package/build/src/settlement/settle.d.ts +0 -6
- package/build/src/settlement/settle.js +0 -4
- package/build/src/verification/declaration.d.ts +3 -6
- package/build/src/verification/declaration.js +3 -5
- package/build/src/verification/observation.d.ts +2 -2
- package/build/src/world.d.ts +3 -2
- package/build/src/world.js +5 -6
- package/package.json +1 -1
- package/plugins/paseo/plugin/index.server.ts +1 -1
- package/plugins/paseo/plugin/server/attach.ts +74 -67
- package/plugins/paseo/plugin/server/keiyaku.ts +80 -14
- package/plugins/paseo/plugin/server/message.ts +2 -1
- package/plugins/paseo/plugin/server/mirror-identity.ts +6 -4
- package/plugins/paseo/plugin/server/sdk.ts +9 -11
- package/plugins/paseo/plugin/server/transport.ts +24 -1
- package/plugins/pi/README.md +16 -18
- package/plugins/pi/akuma-tools.ts +31 -38
- package/plugins/pi/keiyaku.ts +15 -4
- package/skills/keiyaku-akuma/SKILL.md +16 -11
- package/skills/keiyaku-babysit/SKILL.md +5 -3
- package/skills/keiyaku-bind/SKILL.md +4 -3
- package/skills/keiyaku-debt/SKILL.md +17 -17
- package/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/providers/codex-app-server/configuration.d.ts +0 -5
- package/build/src/akuma/providers/codex-app-server/configuration.js +0 -72
- package/build/src/cli/commands/debt-query.d.ts +0 -5
- package/build/src/cli/commands/debt-query.js +0 -194
- package/build/src/cli/render/akuma-tool-command.d.ts +0 -6
- package/build/src/cli/render/akuma-tool-command.js +0 -143
- package/build/src/cli/render/akuma-tool.d.ts +0 -29
- package/build/src/cli/render/akuma-tool.js +0 -225
- package/build/src/debt/context.d.ts +0 -28
- package/build/src/debt/context.js +0 -102
- package/build/src/debt/created-observation.d.ts +0 -26
- package/build/src/debt/created-observation.js +0 -38
- package/build/src/debt/query.d.ts +0 -80
- package/build/src/debt/query.js +0 -283
- package/build/src/library/contract-execution.d.ts +0 -28
- package/build/src/library/contract-execution.js +0 -506
- package/build/src/library/keiyaku-policy.d.ts +0 -27
- package/build/src/library/keiyaku-policy.js +0 -44
- package/build/src/library/keiyaku-status.d.ts +0 -1487
- package/build/src/library/keiyaku-status.js +0 -92
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { randomBytes } from "node:crypto";
|
|
3
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
@@ -13,6 +14,10 @@ export function parsePublicHistoryId(value) {
|
|
|
13
14
|
return Number.isSafeInteger(sequence) ? sequence : null;
|
|
14
15
|
}
|
|
15
16
|
export function parseExactHistorySelector(value) {
|
|
17
|
+
if (/^[1-9][0-9]*$/u.test(value)) {
|
|
18
|
+
const sequence = Number(value);
|
|
19
|
+
return Number.isSafeInteger(sequence) ? { kind: "activity", sequence } : null;
|
|
20
|
+
}
|
|
16
21
|
const match = /^(turn|report)\/([1-9][0-9]*)$/u.exec(value);
|
|
17
22
|
if (match === null)
|
|
18
23
|
return null;
|
|
@@ -31,7 +36,7 @@ export const akumaPathsSchema = z
|
|
|
31
36
|
.strict();
|
|
32
37
|
function suffixSegment(value) {
|
|
33
38
|
if (!HEX8.test(value))
|
|
34
|
-
throw new
|
|
39
|
+
throw new KeiyakuError("invalid-input", "Akuma suffix must be lower hex8");
|
|
35
40
|
return value;
|
|
36
41
|
}
|
|
37
42
|
export function akumaId(input) {
|
|
@@ -43,11 +48,11 @@ export function akumaId(input) {
|
|
|
43
48
|
export function parseAkumaId(value) {
|
|
44
49
|
const segments = identitySegments({ family: "aku", value });
|
|
45
50
|
if (segments.length !== 2)
|
|
46
|
-
throw new
|
|
51
|
+
throw new KeiyakuError("invalid-input", "Akuma identity must be aku/<akuma>/<hex8>");
|
|
47
52
|
const akumaName = segments[0];
|
|
48
53
|
// Existing identities remain addressable after new births gain a name limit.
|
|
49
54
|
if (!isCanonicalAkumaName(akumaName))
|
|
50
|
-
throw new
|
|
55
|
+
throw new KeiyakuError("invalid-input", "Akuma name must be one normalized human identity segment");
|
|
51
56
|
const suffix = suffixSegment(segments[1]);
|
|
52
57
|
return { id: value, akumaName, suffix };
|
|
53
58
|
}
|
|
@@ -68,7 +73,7 @@ export function akumaRunRoot(worldRoot) {
|
|
|
68
73
|
}
|
|
69
74
|
export function akumaPaths(input) {
|
|
70
75
|
if (!isCanonicalAkumaName(input.akumaName))
|
|
71
|
-
throw new
|
|
76
|
+
throw new KeiyakuError("invalid-input", "Akuma name must be one normalized human identity segment");
|
|
72
77
|
const directory = join(input.runRoot, `${input.akumaName}-${suffixSegment(input.suffix)}`);
|
|
73
78
|
return {
|
|
74
79
|
directory,
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export type { AkumaCaller } from "./caller.js";
|
|
2
2
|
export type { AkumaOrigin } from "./heart/index.js";
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
5
|
-
export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError } from "./akuma-errors.js";
|
|
3
|
+
export { AkumaNameError } from "./archetype.js";
|
|
4
|
+
export type { AkumaNameCatalog, AkumaNameCatalogInput, AkumaNameCatalogRow } from "./archetype.js";
|
|
5
|
+
export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaObservationError, AkumaProviderError, } from "./akuma-errors.js";
|
|
6
6
|
export { Akuma } from "./akuma-instance.js";
|
|
7
7
|
export type { AkumaAskOptions, AkumaBirthInput, AkumaHistoryOptions, AkumaHostOptions, AkumaIdleOptions, AkumaIdleResult, AkumaReportOptions, AkumaReportResult, AkumaSignalOptions, AkumaTellOptions, } from "./akuma-instance.js";
|
|
8
8
|
export type { AkumaStreamSnapshot } from "./akuma-stream.js";
|
|
9
|
-
export type { AkumaStatus } from "./akuma.js";
|
|
9
|
+
export type { AkumaStatus, AkumaRosterInput } from "./akuma.js";
|
|
10
10
|
export type { KillEvidence } from "./heart/index.js";
|
|
11
11
|
export type { AkumaId } from "./identity.js";
|
|
12
|
-
export type { ActivityHistory, ActivityRow } from "./projection.js";
|
|
13
|
-
export {
|
|
14
|
-
export type { JsonSchema, JsonSchemaDocument, SchemaLike, StandardSchemaV1 } from "./schema.js";
|
|
12
|
+
export type { ActivityHistory, ActivityRow, ActivitySnapshot } from "./projection.js";
|
|
13
|
+
export type { JsonSchema, JsonSchemaDocument } from "./schema.js";
|
|
15
14
|
export type { AkumaAskObservation, AkumaAskResult, AkumaTellResult } from "./selection-observation.js";
|
package/build/src/akuma/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError } from "./akuma-errors.js";
|
|
1
|
+
export { AkumaNameError } from "./archetype.js";
|
|
2
|
+
export { AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaObservationError, AkumaProviderError, } from "./akuma-errors.js";
|
|
3
3
|
export { Akuma } from "./akuma-instance.js";
|
|
4
|
-
export { Schema } from "./schema.js";
|
|
@@ -1116,6 +1116,9 @@ export type ExactHistory = Readonly<{
|
|
|
1116
1116
|
}> | Readonly<{
|
|
1117
1117
|
kind: "exact-report";
|
|
1118
1118
|
report: ReportRow;
|
|
1119
|
+
}> | Readonly<{
|
|
1120
|
+
kind: "exact-activity";
|
|
1121
|
+
row: ActivityRow;
|
|
1119
1122
|
}> | Readonly<{
|
|
1120
1123
|
kind: "unknown-history";
|
|
1121
1124
|
id: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
const modelText = z
|
|
3
4
|
.string({ error: "provider option model must be a nonblank string" })
|
|
@@ -78,7 +79,7 @@ export function withoutModel(options) {
|
|
|
78
79
|
export function decodeProviderOptions(value) {
|
|
79
80
|
const parsed = providerOptionsSchema.safeParse(value);
|
|
80
81
|
if (!parsed.success)
|
|
81
|
-
throw new
|
|
82
|
+
throw new KeiyakuError("invalid-input", parsed.error.issues[0]?.message ?? "provider options must be an object", {
|
|
82
83
|
cause: parsed.error,
|
|
83
84
|
});
|
|
84
85
|
return parsed.data;
|
|
@@ -86,7 +87,7 @@ export function decodeProviderOptions(value) {
|
|
|
86
87
|
export function decodeProviderRecipe(value) {
|
|
87
88
|
const parsed = providerRecipeSchema.safeParse(value);
|
|
88
89
|
if (!parsed.success)
|
|
89
|
-
throw new
|
|
90
|
+
throw new KeiyakuError("invalid-input", parsed.error.issues[0]?.message ?? "provider execution must be an object", {
|
|
90
91
|
cause: parsed.error,
|
|
91
92
|
});
|
|
92
93
|
return parsed.data;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../../errors.js";
|
|
1
2
|
function argumentName(value, key) {
|
|
2
3
|
const selected = value[key];
|
|
3
4
|
if (selected === undefined)
|
|
4
5
|
return undefined;
|
|
5
6
|
if (typeof selected !== "string" || selected.trim().length === 0) {
|
|
6
|
-
throw new
|
|
7
|
+
throw new KeiyakuError("invalid-input", `ACP provider config ${key} must be a nonblank string`);
|
|
7
8
|
}
|
|
8
9
|
return selected;
|
|
9
10
|
}
|
|
10
11
|
function validateSelectorMappings(config) {
|
|
11
12
|
if (config.modelArg !== undefined && config.modelConfigId !== undefined) {
|
|
12
|
-
throw new
|
|
13
|
+
throw new KeiyakuError("invalid-input", "ACP provider config cannot map model to both an argument and a session option");
|
|
13
14
|
}
|
|
14
15
|
if (config.effortArg !== undefined && config.effortConfigId !== undefined) {
|
|
15
|
-
throw new
|
|
16
|
+
throw new KeiyakuError("invalid-input", "ACP provider config cannot map effort to both an argument and a session option");
|
|
16
17
|
}
|
|
17
18
|
if (config.modelConfigId !== undefined && config.modelConfigId === config.effortConfigId) {
|
|
18
|
-
throw new
|
|
19
|
+
throw new KeiyakuError("invalid-input", "ACP provider config model and effort must use different session options");
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
export function decodeAcpConfig(value) {
|
|
22
23
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
23
|
-
throw new
|
|
24
|
+
throw new KeiyakuError("invalid-input", "ACP provider config must be an object");
|
|
24
25
|
}
|
|
25
26
|
const config = value;
|
|
26
27
|
const unknown = Object.keys(config).find((key) => ![
|
|
@@ -34,14 +35,14 @@ export function decodeAcpConfig(value) {
|
|
|
34
35
|
"systemPromptMode",
|
|
35
36
|
].includes(key));
|
|
36
37
|
if (unknown !== undefined)
|
|
37
|
-
throw new
|
|
38
|
+
throw new KeiyakuError("invalid-input", `ACP provider config has unknown field ${unknown}`);
|
|
38
39
|
if (!Array.isArray(config.argvBefore) ||
|
|
39
40
|
config.argvBefore.some((arg) => typeof arg !== "string" || arg.trim().length === 0)) {
|
|
40
|
-
throw new
|
|
41
|
+
throw new KeiyakuError("invalid-input", "ACP provider config argvBefore must be an array of nonblank strings");
|
|
41
42
|
}
|
|
42
43
|
if (!Array.isArray(config.argvAfter) ||
|
|
43
44
|
config.argvAfter.some((arg) => typeof arg !== "string" || arg.trim().length === 0)) {
|
|
44
|
-
throw new
|
|
45
|
+
throw new KeiyakuError("invalid-input", "ACP provider config argvAfter must be an array of nonblank strings");
|
|
45
46
|
}
|
|
46
47
|
const modelArg = argumentName(config, "modelArg");
|
|
47
48
|
const effortArg = argumentName(config, "effortArg");
|
|
@@ -51,10 +52,10 @@ export function decodeAcpConfig(value) {
|
|
|
51
52
|
const systemPromptArg = argumentName(config, "systemPromptArg");
|
|
52
53
|
const systemPromptMode = config.systemPromptMode;
|
|
53
54
|
if (systemPromptMode !== undefined && systemPromptMode !== "append" && systemPromptMode !== "replace") {
|
|
54
|
-
throw new
|
|
55
|
+
throw new KeiyakuError("invalid-input", "ACP provider config systemPromptMode must be append, replace");
|
|
55
56
|
}
|
|
56
57
|
if (systemPromptMode !== undefined && systemPromptArg === undefined) {
|
|
57
|
-
throw new
|
|
58
|
+
throw new KeiyakuError("invalid-input", "ACP provider config systemPromptMode requires systemPromptArg");
|
|
58
59
|
}
|
|
59
60
|
return Object.freeze({
|
|
60
61
|
argvBefore: Object.freeze([...config.argvBefore]),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../../errors.js";
|
|
1
2
|
import { providerLifecycle } from "../lifecycle.js";
|
|
2
3
|
import { decodeAcpConfig } from "./config.js";
|
|
3
4
|
import { startAcpSession } from "./core.js";
|
|
@@ -44,7 +45,7 @@ function argv(execution, config, options) {
|
|
|
44
45
|
}
|
|
45
46
|
export function createAcpProvider(execution, dependencies = {}) {
|
|
46
47
|
if (execution.executable === undefined)
|
|
47
|
-
throw new
|
|
48
|
+
throw new KeiyakuError("invalid-input", "ACP provider execution requires executable");
|
|
48
49
|
const config = decodeAcpConfig(execution.config);
|
|
49
50
|
const drive = async (input, custody) => {
|
|
50
51
|
if (input.runtimeInstructions !== undefined) {
|
|
@@ -3,8 +3,14 @@ import { AgentEventChannel, createProviderAttempt, launchPrompt, modelEvent, } f
|
|
|
3
3
|
import { akumaExecutionEnvironment } from "../execution-environment.js";
|
|
4
4
|
import { providerLifecycle } from "../lifecycle.js";
|
|
5
5
|
import { codexNotificationResult, codexObject, codexText } from "./events.js";
|
|
6
|
-
import { initializeCodex } from "./configuration.js";
|
|
7
6
|
export { CODEX_ITEM_DISPOSITIONS, CODEX_NOTIFICATION_DISPOSITIONS } from "./events.js";
|
|
7
|
+
async function initializeCodex(server) {
|
|
8
|
+
await server.request("initialize", {
|
|
9
|
+
clientInfo: { name: "keiyaku", title: "keiyaku", version: "4" },
|
|
10
|
+
capabilities: { experimentalApi: true, requestAttestation: false },
|
|
11
|
+
});
|
|
12
|
+
server.notify("initialized");
|
|
13
|
+
}
|
|
8
14
|
function diagnostic(error) {
|
|
9
15
|
return error instanceof Error ? error.message : String(error);
|
|
10
16
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../../errors.js";
|
|
1
2
|
import { tellRegistry } from "../../provider.js";
|
|
2
3
|
import { nonblank, object, searchToolCall } from "../decode.js";
|
|
3
4
|
import { providerLifecycle } from "../lifecycle.js";
|
|
@@ -126,7 +127,7 @@ function withInterject(live, tells) {
|
|
|
126
127
|
}
|
|
127
128
|
export function createGrokBuildProvider(execution, dependencies = {}) {
|
|
128
129
|
if (execution.executable === undefined)
|
|
129
|
-
throw new
|
|
130
|
+
throw new KeiyakuError("invalid-input", "Grok Build provider execution requires executable");
|
|
130
131
|
const drive = async (input, custody) => {
|
|
131
132
|
const tells = tellRegistry();
|
|
132
133
|
let live;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ProviderAdapter } from "../provider.js";
|
|
2
2
|
import type { ProviderExecution } from "../provider-recipe.js";
|
|
3
3
|
export { decodeProviderRecipe as decodeProviderExecution } from "../provider-recipe.js";
|
|
4
|
-
export declare function withWritableDirectories(execution: ProviderExecution, cwd: string, directories: readonly string[], signal?: AbortSignal): Promise<ProviderExecution>;
|
|
5
4
|
export declare function resolveProviderExecution(execution: ProviderExecution): Promise<Readonly<{
|
|
6
5
|
execution: ProviderExecution;
|
|
7
6
|
adapter: ProviderAdapter;
|
|
@@ -20,14 +20,6 @@ async function adapterFor(execution) {
|
|
|
20
20
|
return (await import("./pi/index.js")).createPiProvider(execution);
|
|
21
21
|
throw new TypeError(`unknown Akuma provider kind ${execution.kind}`);
|
|
22
22
|
}
|
|
23
|
-
export async function withWritableDirectories(execution, cwd, directories, signal) {
|
|
24
|
-
if (directories.length === 0)
|
|
25
|
-
return execution;
|
|
26
|
-
if (execution.kind !== "codex-app-server")
|
|
27
|
-
throw new TypeError(`writableDirectories is unsupported by provider ${execution.kind}`);
|
|
28
|
-
const { withCodexWritableDirectories } = await import("./codex-app-server/configuration.js");
|
|
29
|
-
return await withCodexWritableDirectories(execution, cwd, directories, signal);
|
|
30
|
-
}
|
|
31
23
|
export async function resolveProviderExecution(execution) {
|
|
32
24
|
return Object.freeze({ execution, adapter: await adapterFor(execution) });
|
|
33
25
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../../errors.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
// Pinned vendor CLI entry: the public SDK does not expose cancellation or selectors.
|
|
@@ -96,10 +97,12 @@ async function setup(signal, operation) {
|
|
|
96
97
|
}
|
|
97
98
|
function configuration(execution) {
|
|
98
99
|
if (execution.executable !== undefined)
|
|
99
|
-
throw new
|
|
100
|
+
throw new KeiyakuError("invalid-input", "Paseo connects to a local daemon, not an executable");
|
|
100
101
|
const parsed = configSchema.safeParse(execution.config ?? {});
|
|
101
102
|
if (!parsed.success)
|
|
102
|
-
throw new
|
|
103
|
+
throw new KeiyakuError("invalid-input", `Paseo configuration: ${parsed.error.issues[0]?.message}`, {
|
|
104
|
+
cause: parsed.error,
|
|
105
|
+
});
|
|
103
106
|
const config = parsed.data;
|
|
104
107
|
const url = new URL(config.url);
|
|
105
108
|
if (!["ws:", "wss:"].includes(url.protocol) ||
|
|
@@ -109,10 +112,10 @@ function configuration(execution) {
|
|
|
109
112
|
url.password !== "" ||
|
|
110
113
|
url.search !== "" ||
|
|
111
114
|
url.hash !== "") {
|
|
112
|
-
throw new
|
|
115
|
+
throw new KeiyakuError("invalid-input", "Paseo url must be a loopback WebSocket endpoint ending in /ws");
|
|
113
116
|
}
|
|
114
117
|
if (config.provider.includes("/"))
|
|
115
|
-
throw new
|
|
118
|
+
throw new KeiyakuError("invalid-input", "Paseo provider must be a bare native provider id; use the model option separately");
|
|
116
119
|
return config;
|
|
117
120
|
}
|
|
118
121
|
function optionAdmission(options) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "../../../errors.js";
|
|
1
2
|
import { abortable } from "../../abort.js";
|
|
2
3
|
import { akumaExecutionEnvironment } from "../execution-environment.js";
|
|
3
4
|
import { AgentEventChannel, createProviderAttempt, launchPrompt, modelEvent, noteEvent, tellRegistry, } from "../../provider.js";
|
|
@@ -54,7 +55,7 @@ function piCreateOptions(sdk, input, services) {
|
|
|
54
55
|
}
|
|
55
56
|
async function createPiSession(sdk, execution, input) {
|
|
56
57
|
if (execution.config !== undefined) {
|
|
57
|
-
throw new
|
|
58
|
+
throw new KeiyakuError("invalid-input", "Pi provider config cannot be consumed by native CreateAgentSessionOptions");
|
|
58
59
|
}
|
|
59
60
|
const personality = input.options.systemPrompt;
|
|
60
61
|
const append = [
|
|
@@ -320,9 +321,9 @@ async function loadPiSdk() {
|
|
|
320
321
|
}
|
|
321
322
|
export function createPiProvider(execution = { name: "pi", kind: "pi" }, load = loadPiSdk) {
|
|
322
323
|
if (execution.executable !== undefined)
|
|
323
|
-
throw new
|
|
324
|
+
throw new KeiyakuError("invalid-input", "Pi provider does not support executable");
|
|
324
325
|
if (execution.env !== undefined && Object.keys(execution.env).length > 0) {
|
|
325
|
-
throw new
|
|
326
|
+
throw new KeiyakuError("invalid-input", "env injection not supported for provider pi");
|
|
326
327
|
}
|
|
327
328
|
const drive = async (input, custody) => {
|
|
328
329
|
custody.signal.throwIfAborted();
|
|
@@ -4,7 +4,6 @@ import { type AllocatedAkuma } from "./identity.js";
|
|
|
4
4
|
import type { ChildBodyLaunch, LiveBodyLaunch } from "./body-launch.js";
|
|
5
5
|
import type { CallInitialTell, CallInitialTellAdmission, InitialTellAdmissionInput, TellResult } from "./call-initial-tell.js";
|
|
6
6
|
import type { WorldRoot } from "../world.js";
|
|
7
|
-
export declare const BIRTH_TIMEOUT_MS = 30000;
|
|
8
7
|
export type BirthInput = Readonly<{
|
|
9
8
|
worldPath: string;
|
|
10
9
|
akumaName: string;
|
|
@@ -36,11 +35,11 @@ type PreparedCallResult = Readonly<{
|
|
|
36
35
|
tell?: TellResult;
|
|
37
36
|
/** The native launch or initial-Tell failure that stopped after a confirmed birth. */
|
|
38
37
|
failure?: unknown;
|
|
38
|
+
failureStage?: "birth" | "tell" | "wake";
|
|
39
39
|
}>;
|
|
40
40
|
type PreparedCallInput = Readonly<{
|
|
41
41
|
akumaName: string;
|
|
42
42
|
cwd: string;
|
|
43
|
-
writableDirectories?: readonly string[];
|
|
44
43
|
caller?: AkumaCaller;
|
|
45
44
|
initialTell?: CallInitialTell;
|
|
46
45
|
signal?: AbortSignal;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { decodeAkumaCaller } from "./caller.js";
|
|
2
|
+
import { errorCategory } from "../errors.js";
|
|
2
3
|
import { HeldAkumaLeash, initializeHeart, readHeart, readSeal, readSoul } from "./heart/index.js";
|
|
3
4
|
import { acquireLeash } from "./control.js";
|
|
4
5
|
import { allocateAkumaDirectory } from "./identity.js";
|
|
5
6
|
import { abortableDelay } from "./abort.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { BIRTH_TIMEOUT_MS, pendingTellReceipt } from "./call-initial-tell.js";
|
|
8
|
+
import { resolveProviderExecution } from "./providers/index.js";
|
|
8
9
|
const POLL_MS = 100;
|
|
9
10
|
const CUSTODY_HANDOFF_MS = 1_000;
|
|
10
|
-
export const BIRTH_TIMEOUT_MS = 30_000;
|
|
11
11
|
class LaunchCompletedError extends Error {
|
|
12
12
|
}
|
|
13
13
|
function diagnostic(error) {
|
|
@@ -293,16 +293,14 @@ export class PreparedCallAdmissionError extends Error {
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
/** Admit the provider recipe once before allocating any child. */
|
|
296
|
-
async function admittedRecipe(recipe
|
|
296
|
+
async function admittedRecipe(recipe) {
|
|
297
297
|
let selected;
|
|
298
298
|
try {
|
|
299
|
-
|
|
300
|
-
const provider = await withWritableDirectories(recipe.provider, input.cwd, directories, input.signal);
|
|
301
|
-
selected = await resolveProviderExecution(provider);
|
|
299
|
+
selected = await resolveProviderExecution(recipe.provider);
|
|
302
300
|
}
|
|
303
301
|
catch (error) {
|
|
304
|
-
if (error
|
|
305
|
-
throw new PreparedCallAdmissionError("resolve", error.message);
|
|
302
|
+
if (errorCategory(error) === "invalid-input")
|
|
303
|
+
throw new PreparedCallAdmissionError("resolve", error instanceof Error ? error.message : String(error));
|
|
306
304
|
throw error;
|
|
307
305
|
}
|
|
308
306
|
const admission = selected.adapter.admitOptions(recipe.options);
|
|
@@ -324,7 +322,7 @@ async function durablyBorn(allocated) {
|
|
|
324
322
|
/** Validate completely, then reserve one coordinate before any birth or input. */
|
|
325
323
|
export async function prepareCall(input) {
|
|
326
324
|
const caller = decodeAkumaCaller(input.caller);
|
|
327
|
-
const recipe = await admittedRecipe(input.recipe
|
|
325
|
+
const recipe = await admittedRecipe(input.recipe);
|
|
328
326
|
input.signal?.throwIfAborted();
|
|
329
327
|
const allocated = await allocateAkumaDirectory({ worldRoot: input.world, akumaName: input.akumaName });
|
|
330
328
|
return { allocated, input, recipe, caller };
|
|
@@ -364,7 +362,7 @@ export async function publishPreparedCall(prepared) {
|
|
|
364
362
|
catch (error) {
|
|
365
363
|
if (!(await durablyBorn(allocated)))
|
|
366
364
|
throw error;
|
|
367
|
-
return { child: allocated, failure: error };
|
|
365
|
+
return { child: allocated, failure: error, failureStage: "birth" };
|
|
368
366
|
}
|
|
369
367
|
if (input.initialTell === undefined)
|
|
370
368
|
return { child };
|
|
@@ -379,12 +377,16 @@ export async function publishPreparedCall(prepared) {
|
|
|
379
377
|
throw new Error(admitted.diagnostic);
|
|
380
378
|
if (admitted.kind === "not-born")
|
|
381
379
|
throw new Error(`Akuma ${child.id} was not born for its initial Tell`);
|
|
380
|
+
told = pendingTellReceipt(admitted.tell);
|
|
382
381
|
told = await admitted.wake;
|
|
383
382
|
return { child, tell: told };
|
|
384
383
|
}
|
|
385
384
|
catch (error) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
return {
|
|
386
|
+
child,
|
|
387
|
+
...(told === undefined ? {} : { tell: told }),
|
|
388
|
+
failure: error,
|
|
389
|
+
failureStage: told === undefined ? "tell" : "wake",
|
|
390
|
+
};
|
|
389
391
|
}
|
|
390
392
|
}
|
|
@@ -1,54 +1,8 @@
|
|
|
1
|
-
import { type ZodType } from "zod";
|
|
2
1
|
export type JsonSchemaDocument = Readonly<{
|
|
3
2
|
readonly [key: string]: unknown;
|
|
4
3
|
}>;
|
|
5
4
|
export type JsonSchema = JsonSchemaDocument;
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}> | Readonly<{
|
|
10
|
-
readonly issues: readonly Readonly<{
|
|
11
|
-
readonly message: string;
|
|
12
|
-
}>[];
|
|
5
|
+
export declare function canonicalDocument(value: unknown, label?: string): Readonly<{
|
|
6
|
+
json: JsonSchemaDocument;
|
|
7
|
+
jsonText: string;
|
|
13
8
|
}>;
|
|
14
|
-
/** Structural Standard Schema v1 marker; no runtime dependency on a library. */
|
|
15
|
-
export type StandardSchemaV1<Output = unknown> = Readonly<{
|
|
16
|
-
readonly "~standard": Readonly<{
|
|
17
|
-
readonly version: 1;
|
|
18
|
-
readonly vendor: string;
|
|
19
|
-
readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>;
|
|
20
|
-
readonly types?: Readonly<{
|
|
21
|
-
readonly input: unknown;
|
|
22
|
-
readonly output: Output;
|
|
23
|
-
}> | undefined;
|
|
24
|
-
readonly jsonSchema?: Readonly<{
|
|
25
|
-
readonly output: (options: Readonly<{
|
|
26
|
-
readonly target: string;
|
|
27
|
-
}>) => unknown;
|
|
28
|
-
}> | undefined;
|
|
29
|
-
}>;
|
|
30
|
-
}>;
|
|
31
|
-
/** The schema forms a Tell answer contract accepts. */
|
|
32
|
-
export type SchemaLike<T> = Schema<T> | StandardSchemaV1<T>;
|
|
33
|
-
export declare class Schema<T> {
|
|
34
|
-
readonly jsonSchema: JsonSchemaDocument;
|
|
35
|
-
readonly decode: (value: unknown) => T;
|
|
36
|
-
private constructor();
|
|
37
|
-
static zod<Output>(schema: ZodType<Output>): Schema<Output>;
|
|
38
|
-
static json<Output>(schema: JsonSchemaDocument, decode: (value: unknown) => Output): Schema<Output>;
|
|
39
|
-
/**
|
|
40
|
-
* Bless a Standard Schema v1 value as a real Schema: validate the marker,
|
|
41
|
-
* project a JSON Schema document, refuse shapes outside the simple
|
|
42
|
-
* vocabulary, and decode at the boundary. The class owns this path so every
|
|
43
|
-
* normalized schema is born through the constructor rather than around it.
|
|
44
|
-
*/
|
|
45
|
-
static standard<Output>(value: StandardSchemaV1<Output>): Schema<Output>;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Normalize a Tell answer contract to the internal Schema. The package's own
|
|
49
|
-
* Schema passes through; anything else delegates to the class's own blessing
|
|
50
|
-
* path, so inferred output types keep flowing from a genuine Schema instance.
|
|
51
|
-
*/
|
|
52
|
-
export declare function schemaFromStandard<T>(value: SchemaLike<T>): Schema<T>;
|
|
53
|
-
/** Internal neutral serialization for Heart/provider forwarding. */
|
|
54
|
-
export declare function schemaJsonText(schema: Schema<unknown>): string;
|
|
@@ -1,25 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeiyakuError } from "../errors.js";
|
|
2
2
|
const SCHEMA_JSON_MAX_BYTES = 65_536;
|
|
3
|
-
/**
|
|
4
|
-
* Keywords a provider answer contract may carry. Provider failures from
|
|
5
|
-
* fragile constraints are expensive to diagnose, so the seam refuses any
|
|
6
|
-
* projected document that steps outside simple JSON shape vocabulary.
|
|
7
|
-
*/
|
|
8
|
-
const SIMPLE_SCHEMA_KEYWORDS = new Set([
|
|
9
|
-
"type",
|
|
10
|
-
"properties",
|
|
11
|
-
"required",
|
|
12
|
-
"items",
|
|
13
|
-
"enum",
|
|
14
|
-
"const",
|
|
15
|
-
"anyOf",
|
|
16
|
-
"additionalProperties",
|
|
17
|
-
"description",
|
|
18
|
-
"title",
|
|
19
|
-
"$schema",
|
|
20
|
-
"$defs",
|
|
21
|
-
"$ref",
|
|
22
|
-
]);
|
|
23
3
|
function isPlainObject(value) {
|
|
24
4
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
25
5
|
return false;
|
|
@@ -32,7 +12,7 @@ function assertJsonValue(value, path) {
|
|
|
32
12
|
if (typeof value === "number") {
|
|
33
13
|
if (Number.isFinite(value))
|
|
34
14
|
return;
|
|
35
|
-
throw new
|
|
15
|
+
throw new KeiyakuError("invalid-input", `${path} contains a non-JSON number`);
|
|
36
16
|
}
|
|
37
17
|
if (Array.isArray(value)) {
|
|
38
18
|
for (let index = 0; index < value.length; index += 1)
|
|
@@ -44,39 +24,7 @@ function assertJsonValue(value, path) {
|
|
|
44
24
|
assertJsonValue(entry, `${path}.${key}`);
|
|
45
25
|
return;
|
|
46
26
|
}
|
|
47
|
-
throw new
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Walk every subschema position and refuse a keyword outside the blessed shape
|
|
51
|
-
* vocabulary. Property names and enum/const data are not keywords, so their
|
|
52
|
-
* keys are never judged.
|
|
53
|
-
*/
|
|
54
|
-
function assertSimpleSchema(value, path) {
|
|
55
|
-
if (!isPlainObject(value))
|
|
56
|
-
throw new TypeError(`${path} must be a JSON Schema object`);
|
|
57
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
58
|
-
if (!SIMPLE_SCHEMA_KEYWORDS.has(key)) {
|
|
59
|
-
throw new TypeError(`provider answer contract uses unsupported JSON Schema keyword "${key}" at ${path}; ` +
|
|
60
|
-
"provider answer contracts carry simple shapes only");
|
|
61
|
-
}
|
|
62
|
-
if (key === "properties" || key === "$defs") {
|
|
63
|
-
for (const [name, subschema] of Object.entries(entry)) {
|
|
64
|
-
assertSimpleSchema(subschema, `${path}.${key}.${name}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
else if (key === "items") {
|
|
68
|
-
if (Array.isArray(entry))
|
|
69
|
-
entry.forEach((subschema, index) => assertSimpleSchema(subschema, `${path}.items[${index}]`));
|
|
70
|
-
else
|
|
71
|
-
assertSimpleSchema(entry, `${path}.items`);
|
|
72
|
-
}
|
|
73
|
-
else if (key === "anyOf") {
|
|
74
|
-
entry.forEach((subschema, index) => assertSimpleSchema(subschema, `${path}.anyOf[${index}]`));
|
|
75
|
-
}
|
|
76
|
-
else if (key === "additionalProperties" && typeof entry !== "boolean") {
|
|
77
|
-
assertSimpleSchema(entry, `${path}.additionalProperties`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
27
|
+
throw new KeiyakuError("invalid-input", `${path} contains a non-JSON value`);
|
|
80
28
|
}
|
|
81
29
|
function sortValue(value) {
|
|
82
30
|
if (Array.isArray(value))
|
|
@@ -85,8 +33,6 @@ function sortValue(value) {
|
|
|
85
33
|
return value;
|
|
86
34
|
const sorted = {};
|
|
87
35
|
for (const key of Object.keys(value).sort()) {
|
|
88
|
-
if (key === "~standard")
|
|
89
|
-
continue;
|
|
90
36
|
sorted[key] = sortValue(value[key]);
|
|
91
37
|
}
|
|
92
38
|
return sorted;
|
|
@@ -103,101 +49,14 @@ function freezeValue(value) {
|
|
|
103
49
|
freezeValue(value[key]);
|
|
104
50
|
return Object.freeze(value);
|
|
105
51
|
}
|
|
106
|
-
function canonicalDocument(value, label) {
|
|
52
|
+
export function canonicalDocument(value, label = "JSON Schema") {
|
|
107
53
|
assertJsonValue(value, label);
|
|
108
54
|
const sorted = sortValue(value);
|
|
109
55
|
if (!isPlainObject(sorted))
|
|
110
|
-
throw new
|
|
56
|
+
throw new KeiyakuError("invalid-input", `${label} must be a JSON object`);
|
|
111
57
|
const jsonText = JSON.stringify(sorted);
|
|
112
58
|
if (new TextEncoder().encode(jsonText).byteLength > SCHEMA_JSON_MAX_BYTES) {
|
|
113
|
-
throw new
|
|
59
|
+
throw new KeiyakuError("invalid-input", `${label} exceeds the ${SCHEMA_JSON_MAX_BYTES}-byte bound`);
|
|
114
60
|
}
|
|
115
61
|
return { json: freezeValue(JSON.parse(jsonText)), jsonText };
|
|
116
62
|
}
|
|
117
|
-
function standardMarker(value) {
|
|
118
|
-
const marker = typeof value === "object" && value !== null ? value["~standard"] : undefined;
|
|
119
|
-
if (typeof marker !== "object" ||
|
|
120
|
-
marker === null ||
|
|
121
|
-
marker.version !== 1 ||
|
|
122
|
-
typeof marker.vendor !== "string" ||
|
|
123
|
-
typeof marker.validate !== "function") {
|
|
124
|
-
throw new TypeError("schema must be a Schema or a Standard Schema v1 value");
|
|
125
|
-
}
|
|
126
|
-
return marker;
|
|
127
|
-
}
|
|
128
|
-
/** Project a Standard Schema value to a JSON Schema document, or refuse honestly. */
|
|
129
|
-
function projectStandardSchema(value, marker) {
|
|
130
|
-
if (marker.vendor === "zod") {
|
|
131
|
-
return toJSONSchema(value, { target: "draft-07", unrepresentable: "throw", cycles: "throw" });
|
|
132
|
-
}
|
|
133
|
-
const converter = marker.jsonSchema;
|
|
134
|
-
if (converter !== undefined && typeof converter.output === "function") {
|
|
135
|
-
return converter.output({ target: "draft-07" });
|
|
136
|
-
}
|
|
137
|
-
const method = value.toJSONSchema;
|
|
138
|
-
if (typeof method === "function") {
|
|
139
|
-
return method.call(value, { target: "draft-07" });
|
|
140
|
-
}
|
|
141
|
-
throw new TypeError(`schema vendor "${marker.vendor}" does not carry a JSON Schema projection; ` +
|
|
142
|
-
"pass a JSON Schema document and decoder to Schema.json instead");
|
|
143
|
-
}
|
|
144
|
-
function decodeStandard(value, marker) {
|
|
145
|
-
const result = marker.validate(value);
|
|
146
|
-
if (result instanceof Promise || (typeof result === "object" && result !== null && "then" in result)) {
|
|
147
|
-
throw new TypeError(`schema vendor "${marker.vendor}" validates asynchronously`);
|
|
148
|
-
}
|
|
149
|
-
if ("issues" in result && result.issues !== undefined) {
|
|
150
|
-
const detail = result.issues.map((issue) => issue.message).join("; ");
|
|
151
|
-
throw new Error(detail.length === 0 ? "Standard Schema validation failed" : detail);
|
|
152
|
-
}
|
|
153
|
-
return result.value;
|
|
154
|
-
}
|
|
155
|
-
export class Schema {
|
|
156
|
-
jsonSchema;
|
|
157
|
-
decode;
|
|
158
|
-
constructor(jsonSchema, decode) {
|
|
159
|
-
this.jsonSchema = jsonSchema;
|
|
160
|
-
this.decode = decode;
|
|
161
|
-
Object.freeze(this);
|
|
162
|
-
}
|
|
163
|
-
static zod(schema) {
|
|
164
|
-
const payload = toJSONSchema(schema, { target: "draft-07", unrepresentable: "throw", cycles: "throw" });
|
|
165
|
-
assertSimpleSchema(payload, "$");
|
|
166
|
-
const canonical = canonicalDocument(payload, "Zod JSON Schema");
|
|
167
|
-
return new Schema(canonical.json, (value) => schema.parse(value));
|
|
168
|
-
}
|
|
169
|
-
static json(schema, decode) {
|
|
170
|
-
if (typeof decode !== "function")
|
|
171
|
-
throw new TypeError("JSON Schema decoder must be a function");
|
|
172
|
-
const document = schema;
|
|
173
|
-
const canonical = canonicalDocument(document, "JSON Schema");
|
|
174
|
-
return new Schema(canonical.json, decode);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Bless a Standard Schema v1 value as a real Schema: validate the marker,
|
|
178
|
-
* project a JSON Schema document, refuse shapes outside the simple
|
|
179
|
-
* vocabulary, and decode at the boundary. The class owns this path so every
|
|
180
|
-
* normalized schema is born through the constructor rather than around it.
|
|
181
|
-
*/
|
|
182
|
-
static standard(value) {
|
|
183
|
-
const marker = standardMarker(value);
|
|
184
|
-
const payload = projectStandardSchema(value, marker);
|
|
185
|
-
assertSimpleSchema(payload, "$");
|
|
186
|
-
const canonical = canonicalDocument(payload, `${marker.vendor} JSON Schema`);
|
|
187
|
-
return new Schema(canonical.json, (input) => decodeStandard(input, marker));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Normalize a Tell answer contract to the internal Schema. The package's own
|
|
192
|
-
* Schema passes through; anything else delegates to the class's own blessing
|
|
193
|
-
* path, so inferred output types keep flowing from a genuine Schema instance.
|
|
194
|
-
*/
|
|
195
|
-
export function schemaFromStandard(value) {
|
|
196
|
-
if (value instanceof Schema)
|
|
197
|
-
return value;
|
|
198
|
-
return Schema.standard(value);
|
|
199
|
-
}
|
|
200
|
-
/** Internal neutral serialization for Heart/provider forwarding. */
|
|
201
|
-
export function schemaJsonText(schema) {
|
|
202
|
-
return JSON.stringify(schema.jsonSchema);
|
|
203
|
-
}
|