@humain/humain-code-contracts 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +92 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +218 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestration.d.ts +327 -0
- package/dist/orchestration.d.ts.map +1 -0
- package/dist/orchestration.js +307 -0
- package/dist/orchestration.js.map +1 -0
- package/dist/rpc.d.ts +63 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +147 -0
- package/dist/rpc.js.map +1 -0
- package/dist/subagent-progress.d.ts +106 -0
- package/dist/subagent-progress.d.ts.map +1 -0
- package/dist/subagent-progress.js +440 -0
- package/dist/subagent-progress.js.map +1 -0
- package/dist/testing.d.ts +390 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +431 -0
- package/dist/testing.js.map +1 -0
- package/dist/trace-api.d.ts +293 -0
- package/dist/trace-api.d.ts.map +1 -0
- package/dist/trace-api.js +202 -0
- package/dist/trace-api.js.map +1 -0
- package/dist/trace-artifact.d.ts +94 -0
- package/dist/trace-artifact.d.ts.map +1 -0
- package/dist/trace-artifact.js +168 -0
- package/dist/trace-artifact.js.map +1 -0
- package/dist/trace-canonical.d.ts +23 -0
- package/dist/trace-canonical.d.ts.map +1 -0
- package/dist/trace-canonical.js +240 -0
- package/dist/trace-canonical.js.map +1 -0
- package/dist/trace-export.d.ts +94 -0
- package/dist/trace-export.d.ts.map +1 -0
- package/dist/trace-export.js +374 -0
- package/dist/trace-export.js.map +1 -0
- package/dist/trace-http.d.ts +1294 -0
- package/dist/trace-http.d.ts.map +1 -0
- package/dist/trace-http.js +1481 -0
- package/dist/trace-http.js.map +1 -0
- package/dist/trace-payload.d.ts +425 -0
- package/dist/trace-payload.d.ts.map +1 -0
- package/dist/trace-payload.js +1519 -0
- package/dist/trace-payload.js.map +1 -0
- package/dist/trace.d.ts +257 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +1014 -0
- package/dist/trace.js.map +1 -0
- package/package.json +64 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
## [0.3.1] - 2026-10-01
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Accept the `switch_session { id, sessionPath }` RPC command in the strict wire
|
|
10
|
+
command union, so a host can rebind a running RPC process to a stored session
|
|
11
|
+
instead of restarting it. HUMAIN Terminal 0.3.0 already implements the command;
|
|
12
|
+
its `{ cancelled }` response is covered by the existing generic response frame.
|
|
13
|
+
|
|
14
|
+
## [0.3.0] - 2026-09-19
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Add the `orchestration-disabled` degradation reason to the run orchestration
|
|
19
|
+
decision record, so a workspace policy kill switch can be told apart from a
|
|
20
|
+
runtime that could not support orchestration at all.
|
|
21
|
+
|
|
22
|
+
## [0.2.0] - 2026-09-17
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Add the orchestration policy contract Forge writes for the sandbox extension.
|
|
27
|
+
- Add the frozen run orchestration decision record.
|
|
28
|
+
- Add the subagent task event contract emitted by the runtime's task graph.
|
|
29
|
+
- Add the subagent identity envelope contract.
|
|
30
|
+
|
|
31
|
+
## [0.1.0] - 2026-09-08
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- Updated TypeBox to 1.3.27.
|
|
36
|
+
|
|
37
|
+
## 0.0.3
|
|
38
|
+
|
|
39
|
+
- Export the canonical execution artifact kinds.
|
|
40
|
+
- Enforce the shared RPC frame limit while parsing encoded frames.
|
|
41
|
+
- Reject additional provider-model identifiers from public execution summaries.
|
|
42
|
+
|
|
43
|
+
## 0.0.2
|
|
44
|
+
|
|
45
|
+
- Share the persistent RPC frame limit across Terminal and hosts.
|
|
46
|
+
- Add workflow-mode parser compatibility vectors.
|
|
47
|
+
|
|
48
|
+
## 0.0.1
|
|
49
|
+
|
|
50
|
+
- Add agent-execution v1 contracts and shared conformance vectors.
|
|
51
|
+
- Add runtime-neutral RPC command encoding and frame parsing.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @humain/humain-code-contracts
|
|
2
|
+
|
|
3
|
+
Runtime-neutral contracts shared by HUMAIN Code CLI and its hosts.
|
|
4
|
+
|
|
5
|
+
- The package root exports agent-execution v1 schemas, types, validators, and parsers.
|
|
6
|
+
- The package root also exports Auto-mode orchestration contracts: the orchestration
|
|
7
|
+
policy block Forge writes for the sandbox extension (`OrchestrationPolicyV1Schema`,
|
|
8
|
+
`parseOrchestrationPolicy`), the frozen run decision record
|
|
9
|
+
(`RunOrchestrationDecisionV1Schema`), and the subagent task event and identity
|
|
10
|
+
envelope shapes the runtime emits (`SubagentTaskEventSchema`,
|
|
11
|
+
`parseSubagentTaskEvent`, `SubagentIdentityEnvelopeSchema`).
|
|
12
|
+
- `@humain/humain-code-contracts/orchestration` exports the same orchestration contracts
|
|
13
|
+
directly.
|
|
14
|
+
- `@humain/humain-code-contracts/rpc` exports the minimal persistent RPC wire seam used by Forge. It is
|
|
15
|
+
dependency-free (no TypeBox, no Node APIs) and reads the optional `subagentProgress` metadata through
|
|
16
|
+
`readRpcSubagentProgress`.
|
|
17
|
+
- The subagent progress projection (schemaVersion 1, "C1") carries per-worker `agent`, `label`, `task`,
|
|
18
|
+
`model`, timestamps, `turns`, `toolCalls`, `failureKind` and `resultPreview`, and per-run `toolCallId`,
|
|
19
|
+
`mode`, `startedAt` and `endedAt`. Text fields are presentation text: render as plain text, never
|
|
20
|
+
markdown or HTML. Producers sanitize with `toSubagentPresentationText`; parsers validate with
|
|
21
|
+
`isSubagentPresentationText`. See `docs/research/a04-c1-contract.md`.
|
|
22
|
+
- `@humain/humain-code-contracts/testing` exports immutable execution conformance vectors and
|
|
23
|
+
`subagentProgressFixtures` / `invalidSubagentProgressFixtures` for progress consumers.
|
|
24
|
+
|
|
25
|
+
## Synthetic-local trace contracts
|
|
26
|
+
|
|
27
|
+
`@humain/humain-code-contracts/trace` exports the runtime-neutral C0 raw JSON/JCS,
|
|
28
|
+
admission, workload/delegation, managed retry and ACK context helpers. Origin event,
|
|
29
|
+
artifact and ACK schemas remain `/1`; producer enrollment and enrollment requests
|
|
30
|
+
use `/2`. Parser success is not authentication, registry admission or durable receipt.
|
|
31
|
+
Callers supply authenticated ownership and committed amendment context for retry
|
|
32
|
+
eligibility; missing authority cannot resolve an unknown terminal.
|
|
33
|
+
|
|
34
|
+
Package version `0.3.2` records the disabled-by-default C0 technical
|
|
35
|
+
resolution, not production approval. Batch ingress remains exclusively
|
|
36
|
+
`dh.batch/1-proposal` (`resolved-synthetic-local`); origin contractVersion stays 1.
|
|
37
|
+
|
|
38
|
+
Read pages and complete cursor bindings use `/2`. A `dh.snapshot-cutoff/1`
|
|
39
|
+
committed receipt ordinal fixes the snapshot; captureCutoff is display time only.
|
|
40
|
+
Bindings include the immutable generation root (or project mapping for lists),
|
|
41
|
+
principal, grant, session and authorization revision. Compare the full returned
|
|
42
|
+
binding across pages and processes; never reconstruct it from timestamps.
|
|
43
|
+
|
|
44
|
+
Export header/page `/2` carries sorted, representation-specific digests and segment
|
|
45
|
+
ownership. `beginDhExportManifest` / `acceptDhExportManifestPage` /
|
|
46
|
+
`finishDhExportManifest` retain one last identity and at most 1,024 descriptors
|
|
47
|
+
and navigation cursors, not all records. Hash callbacks consume exact Uint8Array
|
|
48
|
+
bytes, including the binary root chain. `parseDhExportManifestResponse` places the
|
|
49
|
+
first opaque cursor outside the sealed header. The older monolithic manifest is
|
|
50
|
+
historical/import-only.
|
|
51
|
+
|
|
52
|
+
Passive `DH-BUNDLE/1` verification checks frames, membership, omissions, canonical
|
|
53
|
+
records, header/root, seal and entire-byte download `/2` digest. Artifact chunks
|
|
54
|
+
are never buffered by contracts. Publish an owned staged file only after
|
|
55
|
+
`finishDhBundleVerification` succeeds; native reads and atomic publication remain
|
|
56
|
+
consumer responsibilities.
|
|
57
|
+
|
|
58
|
+
Control requests/status use `/2` admission, attempt, session and capability fences.
|
|
59
|
+
Applied retry requires both observed start IDs with actual linkage; applied
|
|
60
|
+
continue requires target consumption, never queue-steering. Controller descriptors
|
|
61
|
+
are non-secret. The handshake token belongs only to private socket/fd3 transport,
|
|
62
|
+
not journals or diagnostics. Delivery assertions recheck supplied live authority,
|
|
63
|
+
deadline, scope, fences and request digest; they do not implement durable effects.
|
|
64
|
+
|
|
65
|
+
Capability and artifact manifests bind package/export/schema/vector identities and
|
|
66
|
+
exact build/mode/platform qualifications. Required controls are not supported
|
|
67
|
+
controls. A contracts-only manifest may have no runtimes. Artifact fixture bytes
|
|
68
|
+
are synthetic vectors, not a delivered tarball or native qualification evidence.
|
|
69
|
+
See [the decision record](docs/dh-trace-decision-record-v1.md) for parser enforcement
|
|
70
|
+
and remaining product-owner integration requirements.
|
|
71
|
+
|
|
72
|
+
`parseDhRawJson` rejects decoded duplicate keys, malformed UTF-8/Unicode and
|
|
73
|
+
integer-form tokens that change mathematical integer value in binary64. Exactly
|
|
74
|
+
representable larger integers, including `100000000000000000000`, are accepted;
|
|
75
|
+
decimal/exponent tokens use finite binary64 semantics. Count fields still require
|
|
76
|
+
safe integers. `dhCanonicalText` uses RFC 8785 ECMAScript number rendering and
|
|
77
|
+
UTF-16 key order without Unicode normalization. It rejects getters, toJSON and
|
|
78
|
+
sparse arrays before invocation. `dhDigestInput` returns UTF-8 domain + NUL + JCS;
|
|
79
|
+
callers hash those bytes with native SHA-256. Artifact content and spool integrity
|
|
80
|
+
hashes remain raw-byte hashes, not canonical record digests.
|
|
81
|
+
|
|
82
|
+
For POST replies, validate sent views with `assertDhAckSentBatch` and pass the
|
|
83
|
+
parsed mandatory `x-dh-previous-acked-sequence` to the unchanged
|
|
84
|
+
`validateDhBatchAck`. Empty event prefixes never advance the local cursor.
|
|
85
|
+
Artifact metadata acceptance is separate from byte durability: inspect the PUT
|
|
86
|
+
receipt's state even after validating its ID/hash/size.
|
|
87
|
+
|
|
88
|
+
These helpers do not implement workload registries, publication/revocation locks,
|
|
89
|
+
private bootstrap custody, native launch/cancellation, transport retries or GC.
|
|
90
|
+
Synthetic capability and production activation remain product-owner decisions.
|
|
91
|
+
|
|
92
|
+
This package contains no process, stream, provider, filesystem, or execution-host code.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
export * from "./orchestration.ts";
|
|
3
|
+
export declare const HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION: 1;
|
|
4
|
+
export declare const HUMAIN_AGENT_ARTIFACT_KINDS: readonly ["candidate-patch", "dependency-output", "source-observation", "validation-report"];
|
|
5
|
+
export type HumainAgentArtifactKind = (typeof HUMAIN_AGENT_ARTIFACT_KINDS)[number];
|
|
6
|
+
export declare const HumainAgentRouteRefSchema: Type.TUnion<[Type.TLiteral<"route:fast">, Type.TLiteral<"route:balanced">, Type.TLiteral<"route:thorough">]>;
|
|
7
|
+
export type HumainAgentRouteRef = Static<typeof HumainAgentRouteRefSchema>;
|
|
8
|
+
export declare const HumainAgentArtifactSchema: Type.TObject<{
|
|
9
|
+
readonly id: Type.TString;
|
|
10
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"candidate-patch">, Type.TLiteral<"dependency-output">, Type.TLiteral<"source-observation">, Type.TLiteral<"validation-report">]>;
|
|
11
|
+
readonly reference: Type.TString;
|
|
12
|
+
readonly digest: Type.TString;
|
|
13
|
+
}>;
|
|
14
|
+
export type HumainAgentArtifact = Static<typeof HumainAgentArtifactSchema>;
|
|
15
|
+
export declare const HumainAgentExecutionControlsSchema: Type.TObject<{
|
|
16
|
+
readonly maxConcurrency: Type.TInteger;
|
|
17
|
+
readonly maxDepth: Type.TInteger;
|
|
18
|
+
readonly depth: Type.TInteger;
|
|
19
|
+
readonly timeoutMs: Type.TInteger;
|
|
20
|
+
}>;
|
|
21
|
+
export type HumainAgentExecutionControls = Static<typeof HumainAgentExecutionControlsSchema>;
|
|
22
|
+
export declare const HumainAgentExecutionClaimSchema: Type.TObject<{
|
|
23
|
+
readonly workUnitId: Type.TString;
|
|
24
|
+
readonly nodeId: Type.TString;
|
|
25
|
+
readonly attemptNumber: Type.TInteger;
|
|
26
|
+
readonly attemptFence: Type.TInteger;
|
|
27
|
+
readonly segmentFence: Type.TInteger;
|
|
28
|
+
readonly routeRef: Type.TUnion<[Type.TLiteral<"route:fast">, Type.TLiteral<"route:balanced">, Type.TLiteral<"route:thorough">]>;
|
|
29
|
+
readonly task: Type.TString;
|
|
30
|
+
readonly controls: Type.TObject<{
|
|
31
|
+
readonly maxConcurrency: Type.TInteger;
|
|
32
|
+
readonly maxDepth: Type.TInteger;
|
|
33
|
+
readonly depth: Type.TInteger;
|
|
34
|
+
readonly timeoutMs: Type.TInteger;
|
|
35
|
+
}>;
|
|
36
|
+
readonly input: Type.TObject<{
|
|
37
|
+
readonly artifacts: Type.TArray<Type.TObject<{
|
|
38
|
+
readonly id: Type.TString;
|
|
39
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"candidate-patch">, Type.TLiteral<"dependency-output">, Type.TLiteral<"source-observation">, Type.TLiteral<"validation-report">]>;
|
|
40
|
+
readonly reference: Type.TString;
|
|
41
|
+
readonly digest: Type.TString;
|
|
42
|
+
}>>;
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
export type HumainAgentExecutionClaim = Static<typeof HumainAgentExecutionClaimSchema>;
|
|
46
|
+
export declare const HumainAgentExecutionRequestSchema: Type.TObject<{
|
|
47
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
48
|
+
readonly kind: Type.TLiteral<"execute">;
|
|
49
|
+
readonly mode: Type.TUnion<[Type.TLiteral<"node">, Type.TLiteral<"workflow">]>;
|
|
50
|
+
readonly invocationId: Type.TString;
|
|
51
|
+
readonly batchId: Type.TOptional<Type.TString>;
|
|
52
|
+
readonly claims: Type.TArray<Type.TObject<{
|
|
53
|
+
readonly workUnitId: Type.TString;
|
|
54
|
+
readonly nodeId: Type.TString;
|
|
55
|
+
readonly attemptNumber: Type.TInteger;
|
|
56
|
+
readonly attemptFence: Type.TInteger;
|
|
57
|
+
readonly segmentFence: Type.TInteger;
|
|
58
|
+
readonly routeRef: Type.TUnion<[Type.TLiteral<"route:fast">, Type.TLiteral<"route:balanced">, Type.TLiteral<"route:thorough">]>;
|
|
59
|
+
readonly task: Type.TString;
|
|
60
|
+
readonly controls: Type.TObject<{
|
|
61
|
+
readonly maxConcurrency: Type.TInteger;
|
|
62
|
+
readonly maxDepth: Type.TInteger;
|
|
63
|
+
readonly depth: Type.TInteger;
|
|
64
|
+
readonly timeoutMs: Type.TInteger;
|
|
65
|
+
}>;
|
|
66
|
+
readonly input: Type.TObject<{
|
|
67
|
+
readonly artifacts: Type.TArray<Type.TObject<{
|
|
68
|
+
readonly id: Type.TString;
|
|
69
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"candidate-patch">, Type.TLiteral<"dependency-output">, Type.TLiteral<"source-observation">, Type.TLiteral<"validation-report">]>;
|
|
70
|
+
readonly reference: Type.TString;
|
|
71
|
+
readonly digest: Type.TString;
|
|
72
|
+
}>>;
|
|
73
|
+
}>;
|
|
74
|
+
}>>;
|
|
75
|
+
}>;
|
|
76
|
+
export type HumainAgentExecutionRequest = Static<typeof HumainAgentExecutionRequestSchema>;
|
|
77
|
+
export declare const HumainAgentUsageSchema: Type.TUnion<[Type.TObject<{
|
|
78
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
79
|
+
}>, Type.TObject<{
|
|
80
|
+
readonly status: Type.TLiteral<"measured">;
|
|
81
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
82
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
83
|
+
readonly totalTokens: Type.TInteger;
|
|
84
|
+
readonly costMicrocents: Type.TInteger;
|
|
85
|
+
}>]>;
|
|
86
|
+
export type HumainAgentUsage = Static<typeof HumainAgentUsageSchema>;
|
|
87
|
+
export declare const HUMAIN_AGENT_EXECUTION_FAILURE_CODES: readonly ["adapter_execution_failed", "incompatible_adapter_capability", "invalid_adapter_result", "invalid_execution_request", "provider_timeout", "provider_unavailable", "reused_execution_context", "transport_interrupted"];
|
|
88
|
+
export type HumainAgentExecutionFailureCode = (typeof HUMAIN_AGENT_EXECUTION_FAILURE_CODES)[number];
|
|
89
|
+
export declare const HumainAgentExecutionFailureCodeSchema: Type.TUnion<[Type.TLiteral<"adapter_execution_failed">, Type.TLiteral<"incompatible_adapter_capability">, Type.TLiteral<"invalid_adapter_result">, Type.TLiteral<"invalid_execution_request">, Type.TLiteral<"provider_timeout">, Type.TLiteral<"provider_unavailable">, Type.TLiteral<"reused_execution_context">, Type.TLiteral<"transport_interrupted">]>;
|
|
90
|
+
export declare const HumainAgentExecutionOutcomeSchema: Type.TUnion<[Type.TObject<{
|
|
91
|
+
readonly workUnitId: Type.TString;
|
|
92
|
+
readonly nodeId: Type.TString;
|
|
93
|
+
readonly attemptNumber: Type.TInteger;
|
|
94
|
+
readonly attemptFence: Type.TInteger;
|
|
95
|
+
readonly segmentFence: Type.TInteger;
|
|
96
|
+
readonly kind: Type.TLiteral<"succeeded">;
|
|
97
|
+
readonly output: Type.TObject<{
|
|
98
|
+
readonly summary: Type.TString;
|
|
99
|
+
readonly artifacts: Type.TArray<Type.TObject<{
|
|
100
|
+
readonly id: Type.TString;
|
|
101
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"candidate-patch">, Type.TLiteral<"dependency-output">, Type.TLiteral<"source-observation">, Type.TLiteral<"validation-report">]>;
|
|
102
|
+
readonly reference: Type.TString;
|
|
103
|
+
readonly digest: Type.TString;
|
|
104
|
+
}>>;
|
|
105
|
+
}>;
|
|
106
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
107
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
108
|
+
}>, Type.TObject<{
|
|
109
|
+
readonly status: Type.TLiteral<"measured">;
|
|
110
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
111
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
112
|
+
readonly totalTokens: Type.TInteger;
|
|
113
|
+
readonly costMicrocents: Type.TInteger;
|
|
114
|
+
}>]>;
|
|
115
|
+
}>, Type.TObject<{
|
|
116
|
+
readonly workUnitId: Type.TString;
|
|
117
|
+
readonly nodeId: Type.TString;
|
|
118
|
+
readonly attemptNumber: Type.TInteger;
|
|
119
|
+
readonly attemptFence: Type.TInteger;
|
|
120
|
+
readonly segmentFence: Type.TInteger;
|
|
121
|
+
readonly kind: Type.TLiteral<"failed">;
|
|
122
|
+
readonly failureCode: Type.TUnion<[Type.TLiteral<"adapter_execution_failed">, Type.TLiteral<"incompatible_adapter_capability">, Type.TLiteral<"invalid_adapter_result">, Type.TLiteral<"invalid_execution_request">, Type.TLiteral<"provider_timeout">, Type.TLiteral<"provider_unavailable">, Type.TLiteral<"reused_execution_context">, Type.TLiteral<"transport_interrupted">]>;
|
|
123
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
124
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
125
|
+
}>, Type.TObject<{
|
|
126
|
+
readonly status: Type.TLiteral<"measured">;
|
|
127
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
128
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
129
|
+
readonly totalTokens: Type.TInteger;
|
|
130
|
+
readonly costMicrocents: Type.TInteger;
|
|
131
|
+
}>]>;
|
|
132
|
+
}>, Type.TObject<{
|
|
133
|
+
readonly workUnitId: Type.TString;
|
|
134
|
+
readonly nodeId: Type.TString;
|
|
135
|
+
readonly attemptNumber: Type.TInteger;
|
|
136
|
+
readonly attemptFence: Type.TInteger;
|
|
137
|
+
readonly segmentFence: Type.TInteger;
|
|
138
|
+
readonly kind: Type.TLiteral<"cancelled">;
|
|
139
|
+
readonly terminationConfirmed: Type.TBoolean;
|
|
140
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
141
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
142
|
+
}>, Type.TObject<{
|
|
143
|
+
readonly status: Type.TLiteral<"measured">;
|
|
144
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
145
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
146
|
+
readonly totalTokens: Type.TInteger;
|
|
147
|
+
readonly costMicrocents: Type.TInteger;
|
|
148
|
+
}>]>;
|
|
149
|
+
}>]>;
|
|
150
|
+
export type HumainAgentExecutionOutcome = Static<typeof HumainAgentExecutionOutcomeSchema>;
|
|
151
|
+
export declare const HumainAgentExecutionResponseSchema: Type.TObject<{
|
|
152
|
+
readonly schemaVersion: Type.TLiteral<1>;
|
|
153
|
+
readonly kind: Type.TLiteral<"result">;
|
|
154
|
+
readonly mode: Type.TUnion<[Type.TLiteral<"node">, Type.TLiteral<"workflow">]>;
|
|
155
|
+
readonly invocationId: Type.TString;
|
|
156
|
+
readonly batchId: Type.TOptional<Type.TString>;
|
|
157
|
+
readonly termination: Type.TUnion<[Type.TLiteral<"not-requested">, Type.TLiteral<"confirmed">, Type.TLiteral<"unconfirmed">]>;
|
|
158
|
+
readonly outcomes: Type.TArray<Type.TUnion<[Type.TObject<{
|
|
159
|
+
readonly workUnitId: Type.TString;
|
|
160
|
+
readonly nodeId: Type.TString;
|
|
161
|
+
readonly attemptNumber: Type.TInteger;
|
|
162
|
+
readonly attemptFence: Type.TInteger;
|
|
163
|
+
readonly segmentFence: Type.TInteger;
|
|
164
|
+
readonly kind: Type.TLiteral<"succeeded">;
|
|
165
|
+
readonly output: Type.TObject<{
|
|
166
|
+
readonly summary: Type.TString;
|
|
167
|
+
readonly artifacts: Type.TArray<Type.TObject<{
|
|
168
|
+
readonly id: Type.TString;
|
|
169
|
+
readonly kind: Type.TUnion<[Type.TLiteral<"candidate-patch">, Type.TLiteral<"dependency-output">, Type.TLiteral<"source-observation">, Type.TLiteral<"validation-report">]>;
|
|
170
|
+
readonly reference: Type.TString;
|
|
171
|
+
readonly digest: Type.TString;
|
|
172
|
+
}>>;
|
|
173
|
+
}>;
|
|
174
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
175
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
176
|
+
}>, Type.TObject<{
|
|
177
|
+
readonly status: Type.TLiteral<"measured">;
|
|
178
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
179
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
180
|
+
readonly totalTokens: Type.TInteger;
|
|
181
|
+
readonly costMicrocents: Type.TInteger;
|
|
182
|
+
}>]>;
|
|
183
|
+
}>, Type.TObject<{
|
|
184
|
+
readonly workUnitId: Type.TString;
|
|
185
|
+
readonly nodeId: Type.TString;
|
|
186
|
+
readonly attemptNumber: Type.TInteger;
|
|
187
|
+
readonly attemptFence: Type.TInteger;
|
|
188
|
+
readonly segmentFence: Type.TInteger;
|
|
189
|
+
readonly kind: Type.TLiteral<"failed">;
|
|
190
|
+
readonly failureCode: Type.TUnion<[Type.TLiteral<"adapter_execution_failed">, Type.TLiteral<"incompatible_adapter_capability">, Type.TLiteral<"invalid_adapter_result">, Type.TLiteral<"invalid_execution_request">, Type.TLiteral<"provider_timeout">, Type.TLiteral<"provider_unavailable">, Type.TLiteral<"reused_execution_context">, Type.TLiteral<"transport_interrupted">]>;
|
|
191
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
192
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
193
|
+
}>, Type.TObject<{
|
|
194
|
+
readonly status: Type.TLiteral<"measured">;
|
|
195
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
196
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
197
|
+
readonly totalTokens: Type.TInteger;
|
|
198
|
+
readonly costMicrocents: Type.TInteger;
|
|
199
|
+
}>]>;
|
|
200
|
+
}>, Type.TObject<{
|
|
201
|
+
readonly workUnitId: Type.TString;
|
|
202
|
+
readonly nodeId: Type.TString;
|
|
203
|
+
readonly attemptNumber: Type.TInteger;
|
|
204
|
+
readonly attemptFence: Type.TInteger;
|
|
205
|
+
readonly segmentFence: Type.TInteger;
|
|
206
|
+
readonly kind: Type.TLiteral<"cancelled">;
|
|
207
|
+
readonly terminationConfirmed: Type.TBoolean;
|
|
208
|
+
readonly usage: Type.TUnion<[Type.TObject<{
|
|
209
|
+
readonly status: Type.TLiteral<"unknown">;
|
|
210
|
+
}>, Type.TObject<{
|
|
211
|
+
readonly status: Type.TLiteral<"measured">;
|
|
212
|
+
readonly totalCalls: Type.TOptional<Type.TInteger>;
|
|
213
|
+
readonly totalTurns: Type.TOptional<Type.TInteger>;
|
|
214
|
+
readonly totalTokens: Type.TInteger;
|
|
215
|
+
readonly costMicrocents: Type.TInteger;
|
|
216
|
+
}>]>;
|
|
217
|
+
}>]>>;
|
|
218
|
+
}>;
|
|
219
|
+
export type HumainAgentExecutionResponse = Static<typeof HumainAgentExecutionResponseSchema>;
|
|
220
|
+
export declare function isSafeHumainAgentArtifactReference(value: unknown): value is string;
|
|
221
|
+
export declare function isSafeHumainAgentExecutionSummary(value: unknown): value is string;
|
|
222
|
+
export declare function parseHumainAgentExecutionRequest(input: unknown): HumainAgentExecutionRequest;
|
|
223
|
+
export declare function parseHumainAgentExecutionResponse(requestInput: unknown, responseInput: unknown): HumainAgentExecutionResponse;
|
|
224
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,cAAc,oBAAoB,CAAC;AAEnC,eAAO,MAAM,qCAAqC,EA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CAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsB5C,CAAC;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAE3F,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQ7C,CAAC;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC,OAAO,kCAAkC,CAAC,CAAC;AAM7F,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAElF;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAiBjF;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,OAAO,GAAG,2BAA2B,CAmB5F;AAED,wBAAgB,iCAAiC,CAChD,YAAY,EAAE,OAAO,EACrB,aAAa,EAAE,OAAO,GACpB,4BAA4B,CA+C9B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { Compile } from "typebox/compile";
|
|
3
|
+
export * from "./orchestration.js";
|
|
4
|
+
export const HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION = 1;
|
|
5
|
+
export const HUMAIN_AGENT_ARTIFACT_KINDS = [
|
|
6
|
+
"candidate-patch",
|
|
7
|
+
"dependency-output",
|
|
8
|
+
"source-observation",
|
|
9
|
+
"validation-report",
|
|
10
|
+
];
|
|
11
|
+
const StrictObject = (properties) => Type.Object(properties, { additionalProperties: false });
|
|
12
|
+
const StableIdentifier = Type.String({ minLength: 1, maxLength: 256 });
|
|
13
|
+
const PositiveInteger = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
14
|
+
const NonnegativeInteger = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
15
|
+
const Digest = Type.String({ pattern: "^[a-f0-9]{64}$" });
|
|
16
|
+
const SafeArtifactReference = Type.String({
|
|
17
|
+
minLength: 1,
|
|
18
|
+
maxLength: 512,
|
|
19
|
+
pattern: "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$",
|
|
20
|
+
});
|
|
21
|
+
export const HumainAgentRouteRefSchema = Type.Union([
|
|
22
|
+
Type.Literal("route:fast"),
|
|
23
|
+
Type.Literal("route:balanced"),
|
|
24
|
+
Type.Literal("route:thorough"),
|
|
25
|
+
]);
|
|
26
|
+
export const HumainAgentArtifactSchema = StrictObject({
|
|
27
|
+
id: StableIdentifier,
|
|
28
|
+
kind: Type.Union([
|
|
29
|
+
Type.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[0]),
|
|
30
|
+
Type.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[1]),
|
|
31
|
+
Type.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[2]),
|
|
32
|
+
Type.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[3]),
|
|
33
|
+
]),
|
|
34
|
+
reference: SafeArtifactReference,
|
|
35
|
+
digest: Digest,
|
|
36
|
+
});
|
|
37
|
+
export const HumainAgentExecutionControlsSchema = StrictObject({
|
|
38
|
+
maxConcurrency: Type.Integer({ minimum: 1, maximum: 16 }),
|
|
39
|
+
maxDepth: Type.Integer({ minimum: 1, maximum: 16 }),
|
|
40
|
+
depth: Type.Integer({ minimum: 0, maximum: 16 }),
|
|
41
|
+
timeoutMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),
|
|
42
|
+
});
|
|
43
|
+
export const HumainAgentExecutionClaimSchema = StrictObject({
|
|
44
|
+
workUnitId: StableIdentifier,
|
|
45
|
+
nodeId: StableIdentifier,
|
|
46
|
+
attemptNumber: PositiveInteger,
|
|
47
|
+
attemptFence: PositiveInteger,
|
|
48
|
+
segmentFence: PositiveInteger,
|
|
49
|
+
routeRef: HumainAgentRouteRefSchema,
|
|
50
|
+
task: Type.String({ minLength: 1, maxLength: 100_000 }),
|
|
51
|
+
controls: HumainAgentExecutionControlsSchema,
|
|
52
|
+
input: StrictObject({
|
|
53
|
+
artifacts: Type.Array(HumainAgentArtifactSchema, { maxItems: 16 }),
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
export const HumainAgentExecutionRequestSchema = StrictObject({
|
|
57
|
+
schemaVersion: Type.Literal(HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION),
|
|
58
|
+
kind: Type.Literal("execute"),
|
|
59
|
+
mode: Type.Union([Type.Literal("node"), Type.Literal("workflow")]),
|
|
60
|
+
invocationId: StableIdentifier,
|
|
61
|
+
batchId: Type.Optional(StableIdentifier),
|
|
62
|
+
claims: Type.Array(HumainAgentExecutionClaimSchema, { minItems: 1, maxItems: 8 }),
|
|
63
|
+
});
|
|
64
|
+
export const HumainAgentUsageSchema = Type.Union([
|
|
65
|
+
StrictObject({ status: Type.Literal("unknown") }),
|
|
66
|
+
StrictObject({
|
|
67
|
+
status: Type.Literal("measured"),
|
|
68
|
+
totalCalls: Type.Optional(NonnegativeInteger),
|
|
69
|
+
totalTurns: Type.Optional(NonnegativeInteger),
|
|
70
|
+
totalTokens: NonnegativeInteger,
|
|
71
|
+
costMicrocents: NonnegativeInteger,
|
|
72
|
+
}),
|
|
73
|
+
]);
|
|
74
|
+
export const HUMAIN_AGENT_EXECUTION_FAILURE_CODES = [
|
|
75
|
+
"adapter_execution_failed",
|
|
76
|
+
"incompatible_adapter_capability",
|
|
77
|
+
"invalid_adapter_result",
|
|
78
|
+
"invalid_execution_request",
|
|
79
|
+
"provider_timeout",
|
|
80
|
+
"provider_unavailable",
|
|
81
|
+
"reused_execution_context",
|
|
82
|
+
"transport_interrupted",
|
|
83
|
+
];
|
|
84
|
+
export const HumainAgentExecutionFailureCodeSchema = Type.Union([
|
|
85
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[0]),
|
|
86
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[1]),
|
|
87
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[2]),
|
|
88
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[3]),
|
|
89
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[4]),
|
|
90
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[5]),
|
|
91
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[6]),
|
|
92
|
+
Type.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[7]),
|
|
93
|
+
]);
|
|
94
|
+
const OutcomeIdentity = {
|
|
95
|
+
workUnitId: StableIdentifier,
|
|
96
|
+
nodeId: StableIdentifier,
|
|
97
|
+
attemptNumber: PositiveInteger,
|
|
98
|
+
attemptFence: PositiveInteger,
|
|
99
|
+
segmentFence: PositiveInteger,
|
|
100
|
+
};
|
|
101
|
+
export const HumainAgentExecutionOutcomeSchema = Type.Union([
|
|
102
|
+
StrictObject({
|
|
103
|
+
...OutcomeIdentity,
|
|
104
|
+
kind: Type.Literal("succeeded"),
|
|
105
|
+
output: StrictObject({
|
|
106
|
+
summary: Type.String({ minLength: 1, maxLength: 512 }),
|
|
107
|
+
artifacts: Type.Array(HumainAgentArtifactSchema, { maxItems: 16 }),
|
|
108
|
+
}),
|
|
109
|
+
usage: HumainAgentUsageSchema,
|
|
110
|
+
}),
|
|
111
|
+
StrictObject({
|
|
112
|
+
...OutcomeIdentity,
|
|
113
|
+
kind: Type.Literal("failed"),
|
|
114
|
+
failureCode: HumainAgentExecutionFailureCodeSchema,
|
|
115
|
+
usage: HumainAgentUsageSchema,
|
|
116
|
+
}),
|
|
117
|
+
StrictObject({
|
|
118
|
+
...OutcomeIdentity,
|
|
119
|
+
kind: Type.Literal("cancelled"),
|
|
120
|
+
terminationConfirmed: Type.Boolean(),
|
|
121
|
+
usage: HumainAgentUsageSchema,
|
|
122
|
+
}),
|
|
123
|
+
]);
|
|
124
|
+
export const HumainAgentExecutionResponseSchema = StrictObject({
|
|
125
|
+
schemaVersion: Type.Literal(HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION),
|
|
126
|
+
kind: Type.Literal("result"),
|
|
127
|
+
mode: Type.Union([Type.Literal("node"), Type.Literal("workflow")]),
|
|
128
|
+
invocationId: StableIdentifier,
|
|
129
|
+
batchId: Type.Optional(StableIdentifier),
|
|
130
|
+
termination: Type.Union([Type.Literal("not-requested"), Type.Literal("confirmed"), Type.Literal("unconfirmed")]),
|
|
131
|
+
outcomes: Type.Array(HumainAgentExecutionOutcomeSchema, { minItems: 1, maxItems: 8 }),
|
|
132
|
+
});
|
|
133
|
+
const RequestValidator = Compile(HumainAgentExecutionRequestSchema);
|
|
134
|
+
const ResponseValidator = Compile(HumainAgentExecutionResponseSchema);
|
|
135
|
+
const ArtifactReferenceValidator = Compile(SafeArtifactReference);
|
|
136
|
+
export function isSafeHumainAgentArtifactReference(value) {
|
|
137
|
+
return ArtifactReferenceValidator.Check(value);
|
|
138
|
+
}
|
|
139
|
+
export function isSafeHumainAgentExecutionSummary(value) {
|
|
140
|
+
return (typeof value === "string" &&
|
|
141
|
+
value.length >= 1 &&
|
|
142
|
+
value.length <= 512 &&
|
|
143
|
+
value === value.trim() &&
|
|
144
|
+
/^[\p{L}\p{N}][\p{L}\p{N} .,;:!?()&'-]*$/u.test(value) &&
|
|
145
|
+
!/\b(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}(?::\d{1,5})?\b/u.test(value) &&
|
|
146
|
+
!/\b(?:\d{1,3}\.){3}\d{1,3}(?::\d{1,5})?\b/u.test(value) &&
|
|
147
|
+
!/^(?:rm|curl|wget|sh|bash|zsh|fish|pwsh|powershell|cmd|node|bun|deno|npx|npm|pnpm|yarn|python(?:3)?|perl|ruby|git|docker|kubectl|ssh|scp|sudo|cat|ls|cd|mkdir|touch|chmod|chown|env|export|set|eval|exec)\b/iu.test(value) &&
|
|
148
|
+
!/\b(?:api[- ]?key|secret|token|credential|password)\s*:/iu.test(value) &&
|
|
149
|
+
!/\b(?:claude|gpt|gemini|llama|mistral|zai|glm|qwen|deepseek|grok|nova|o\d+)[-_.:][A-Za-z0-9._:-]+\b/iu.test(value));
|
|
150
|
+
}
|
|
151
|
+
export function parseHumainAgentExecutionRequest(input) {
|
|
152
|
+
if (!RequestValidator.Check(input)) {
|
|
153
|
+
throw new Error("Invalid HUMAIN agent execution request");
|
|
154
|
+
}
|
|
155
|
+
if (input.mode === "node" && (input.claims.length !== 1 || input.batchId !== undefined)) {
|
|
156
|
+
throw new Error("Invalid HUMAIN agent execution request: node mode requires one claim and no batch identity");
|
|
157
|
+
}
|
|
158
|
+
if (input.mode === "workflow" && input.batchId === undefined) {
|
|
159
|
+
throw new Error("Invalid HUMAIN agent execution request: workflow mode requires a batch identity");
|
|
160
|
+
}
|
|
161
|
+
const workUnitIds = new Set(input.claims.map(({ workUnitId }) => workUnitId));
|
|
162
|
+
const nodeIds = new Set(input.claims.map(({ nodeId }) => nodeId));
|
|
163
|
+
if (workUnitIds.size !== input.claims.length || nodeIds.size !== input.claims.length) {
|
|
164
|
+
throw new Error("Invalid HUMAIN agent execution request: claim identities must be unique");
|
|
165
|
+
}
|
|
166
|
+
if (input.claims.some(({ controls }) => controls.depth >= controls.maxDepth)) {
|
|
167
|
+
throw new Error("Invalid HUMAIN agent execution request: delegation depth limit is exhausted");
|
|
168
|
+
}
|
|
169
|
+
return deepFreeze(structuredClone(input));
|
|
170
|
+
}
|
|
171
|
+
export function parseHumainAgentExecutionResponse(requestInput, responseInput) {
|
|
172
|
+
const request = parseHumainAgentExecutionRequest(requestInput);
|
|
173
|
+
if (!ResponseValidator.Check(responseInput)) {
|
|
174
|
+
throw new Error("Invalid HUMAIN agent execution response");
|
|
175
|
+
}
|
|
176
|
+
const response = responseInput;
|
|
177
|
+
if (response.outcomes.some((outcome) => outcome.kind === "succeeded" && !isSafeHumainAgentExecutionSummary(outcome.output.summary))) {
|
|
178
|
+
throw new Error("Invalid HUMAIN agent execution response");
|
|
179
|
+
}
|
|
180
|
+
if (response.mode !== request.mode ||
|
|
181
|
+
response.invocationId !== request.invocationId ||
|
|
182
|
+
response.batchId !== request.batchId) {
|
|
183
|
+
throw new Error("HUMAIN agent result envelope mismatch");
|
|
184
|
+
}
|
|
185
|
+
if (response.outcomes.length !== request.claims.length) {
|
|
186
|
+
throw new Error("HUMAIN agent result cardinality mismatch");
|
|
187
|
+
}
|
|
188
|
+
for (const [index, outcome] of response.outcomes.entries()) {
|
|
189
|
+
const claim = request.claims[index];
|
|
190
|
+
if (!claim ||
|
|
191
|
+
outcome.workUnitId !== claim.workUnitId ||
|
|
192
|
+
outcome.nodeId !== claim.nodeId ||
|
|
193
|
+
outcome.attemptNumber !== claim.attemptNumber ||
|
|
194
|
+
outcome.attemptFence !== claim.attemptFence ||
|
|
195
|
+
outcome.segmentFence !== claim.segmentFence) {
|
|
196
|
+
throw new Error("HUMAIN agent result identity mismatch");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const cancelled = response.outcomes.filter((outcome) => outcome.kind === "cancelled");
|
|
200
|
+
const expectedTermination = cancelled.length === 0
|
|
201
|
+
? "not-requested"
|
|
202
|
+
: cancelled.every((outcome) => outcome.terminationConfirmed)
|
|
203
|
+
? "confirmed"
|
|
204
|
+
: "unconfirmed";
|
|
205
|
+
if (response.termination !== expectedTermination) {
|
|
206
|
+
throw new Error("HUMAIN agent result termination evidence mismatch");
|
|
207
|
+
}
|
|
208
|
+
return deepFreeze(structuredClone(response));
|
|
209
|
+
}
|
|
210
|
+
function deepFreeze(value) {
|
|
211
|
+
if (value === null || typeof value !== "object" || Object.isFrozen(value))
|
|
212
|
+
return value;
|
|
213
|
+
Object.freeze(value);
|
|
214
|
+
for (const child of Object.values(value))
|
|
215
|
+
deepFreeze(child);
|
|
216
|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C,CAAC;IACtF,MAAM,mBAAmB,GACxB,SAAS,CAAC,MAAM,KAAK,CAAC;QACrB,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC;YAC3D,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,aAAa,CAAC;IACnB,IAAI,QAAQ,CAAC,WAAW,KAAK,mBAAmB,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,UAAU,CAAI,KAAQ;IAC9B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport { Compile } from \"typebox/compile\";\n\nexport * from \"./orchestration.ts\";\n\nexport const HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION = 1 as const;\nexport const HUMAIN_AGENT_ARTIFACT_KINDS = [\n\t\"candidate-patch\",\n\t\"dependency-output\",\n\t\"source-observation\",\n\t\"validation-report\",\n] as const;\nexport type HumainAgentArtifactKind = (typeof HUMAIN_AGENT_ARTIFACT_KINDS)[number];\n\nconst StrictObject = <const T extends Parameters<typeof Type.Object>[0]>(properties: T) =>\n\tType.Object(properties, { additionalProperties: false });\nconst StableIdentifier = Type.String({ minLength: 1, maxLength: 256 });\nconst PositiveInteger = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });\nconst NonnegativeInteger = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });\nconst Digest = Type.String({ pattern: \"^[a-f0-9]{64}$\" });\nconst SafeArtifactReference = Type.String({\n\tminLength: 1,\n\tmaxLength: 512,\n\tpattern: \"^(?!/)(?!.*(?:^|/)\\\\.\\\\.(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$\",\n});\n\nexport const HumainAgentRouteRefSchema = Type.Union([\n\tType.Literal(\"route:fast\"),\n\tType.Literal(\"route:balanced\"),\n\tType.Literal(\"route:thorough\"),\n]);\nexport type HumainAgentRouteRef = Static<typeof HumainAgentRouteRefSchema>;\n\nexport const HumainAgentArtifactSchema = StrictObject({\n\tid: StableIdentifier,\n\tkind: Type.Union([\n\t\tType.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[0]),\n\t\tType.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[1]),\n\t\tType.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[2]),\n\t\tType.Literal(HUMAIN_AGENT_ARTIFACT_KINDS[3]),\n\t]),\n\treference: SafeArtifactReference,\n\tdigest: Digest,\n});\nexport type HumainAgentArtifact = Static<typeof HumainAgentArtifactSchema>;\n\nexport const HumainAgentExecutionControlsSchema = StrictObject({\n\tmaxConcurrency: Type.Integer({ minimum: 1, maximum: 16 }),\n\tmaxDepth: Type.Integer({ minimum: 1, maximum: 16 }),\n\tdepth: Type.Integer({ minimum: 0, maximum: 16 }),\n\ttimeoutMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n});\nexport type HumainAgentExecutionControls = Static<typeof HumainAgentExecutionControlsSchema>;\n\nexport const HumainAgentExecutionClaimSchema = StrictObject({\n\tworkUnitId: StableIdentifier,\n\tnodeId: StableIdentifier,\n\tattemptNumber: PositiveInteger,\n\tattemptFence: PositiveInteger,\n\tsegmentFence: PositiveInteger,\n\trouteRef: HumainAgentRouteRefSchema,\n\ttask: Type.String({ minLength: 1, maxLength: 100_000 }),\n\tcontrols: HumainAgentExecutionControlsSchema,\n\tinput: StrictObject({\n\t\tartifacts: Type.Array(HumainAgentArtifactSchema, { maxItems: 16 }),\n\t}),\n});\nexport type HumainAgentExecutionClaim = Static<typeof HumainAgentExecutionClaimSchema>;\n\nexport const HumainAgentExecutionRequestSchema = StrictObject({\n\tschemaVersion: Type.Literal(HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION),\n\tkind: Type.Literal(\"execute\"),\n\tmode: Type.Union([Type.Literal(\"node\"), Type.Literal(\"workflow\")]),\n\tinvocationId: StableIdentifier,\n\tbatchId: Type.Optional(StableIdentifier),\n\tclaims: Type.Array(HumainAgentExecutionClaimSchema, { minItems: 1, maxItems: 8 }),\n});\nexport type HumainAgentExecutionRequest = Static<typeof HumainAgentExecutionRequestSchema>;\n\nexport const HumainAgentUsageSchema = Type.Union([\n\tStrictObject({ status: Type.Literal(\"unknown\") }),\n\tStrictObject({\n\t\tstatus: Type.Literal(\"measured\"),\n\t\ttotalCalls: Type.Optional(NonnegativeInteger),\n\t\ttotalTurns: Type.Optional(NonnegativeInteger),\n\t\ttotalTokens: NonnegativeInteger,\n\t\tcostMicrocents: NonnegativeInteger,\n\t}),\n]);\nexport type HumainAgentUsage = Static<typeof HumainAgentUsageSchema>;\n\nexport const HUMAIN_AGENT_EXECUTION_FAILURE_CODES = [\n\t\"adapter_execution_failed\",\n\t\"incompatible_adapter_capability\",\n\t\"invalid_adapter_result\",\n\t\"invalid_execution_request\",\n\t\"provider_timeout\",\n\t\"provider_unavailable\",\n\t\"reused_execution_context\",\n\t\"transport_interrupted\",\n] as const;\nexport type HumainAgentExecutionFailureCode = (typeof HUMAIN_AGENT_EXECUTION_FAILURE_CODES)[number];\n\nexport const HumainAgentExecutionFailureCodeSchema = Type.Union([\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[0]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[1]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[2]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[3]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[4]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[5]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[6]),\n\tType.Literal(HUMAIN_AGENT_EXECUTION_FAILURE_CODES[7]),\n]);\n\nconst OutcomeIdentity = {\n\tworkUnitId: StableIdentifier,\n\tnodeId: StableIdentifier,\n\tattemptNumber: PositiveInteger,\n\tattemptFence: PositiveInteger,\n\tsegmentFence: PositiveInteger,\n};\n\nexport const HumainAgentExecutionOutcomeSchema = Type.Union([\n\tStrictObject({\n\t\t...OutcomeIdentity,\n\t\tkind: Type.Literal(\"succeeded\"),\n\t\toutput: StrictObject({\n\t\t\tsummary: Type.String({ minLength: 1, maxLength: 512 }),\n\t\t\tartifacts: Type.Array(HumainAgentArtifactSchema, { maxItems: 16 }),\n\t\t}),\n\t\tusage: HumainAgentUsageSchema,\n\t}),\n\tStrictObject({\n\t\t...OutcomeIdentity,\n\t\tkind: Type.Literal(\"failed\"),\n\t\tfailureCode: HumainAgentExecutionFailureCodeSchema,\n\t\tusage: HumainAgentUsageSchema,\n\t}),\n\tStrictObject({\n\t\t...OutcomeIdentity,\n\t\tkind: Type.Literal(\"cancelled\"),\n\t\tterminationConfirmed: Type.Boolean(),\n\t\tusage: HumainAgentUsageSchema,\n\t}),\n]);\nexport type HumainAgentExecutionOutcome = Static<typeof HumainAgentExecutionOutcomeSchema>;\n\nexport const HumainAgentExecutionResponseSchema = StrictObject({\n\tschemaVersion: Type.Literal(HUMAIN_AGENT_EXECUTION_SCHEMA_VERSION),\n\tkind: Type.Literal(\"result\"),\n\tmode: Type.Union([Type.Literal(\"node\"), Type.Literal(\"workflow\")]),\n\tinvocationId: StableIdentifier,\n\tbatchId: Type.Optional(StableIdentifier),\n\ttermination: Type.Union([Type.Literal(\"not-requested\"), Type.Literal(\"confirmed\"), Type.Literal(\"unconfirmed\")]),\n\toutcomes: Type.Array(HumainAgentExecutionOutcomeSchema, { minItems: 1, maxItems: 8 }),\n});\nexport type HumainAgentExecutionResponse = Static<typeof HumainAgentExecutionResponseSchema>;\n\nconst RequestValidator = Compile(HumainAgentExecutionRequestSchema);\nconst ResponseValidator = Compile(HumainAgentExecutionResponseSchema);\nconst ArtifactReferenceValidator = Compile(SafeArtifactReference);\n\nexport function isSafeHumainAgentArtifactReference(value: unknown): value is string {\n\treturn ArtifactReferenceValidator.Check(value);\n}\n\nexport function isSafeHumainAgentExecutionSummary(value: unknown): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.length >= 1 &&\n\t\tvalue.length <= 512 &&\n\t\tvalue === value.trim() &&\n\t\t/^[\\p{L}\\p{N}][\\p{L}\\p{N} .,;:!?()&'-]*$/u.test(value) &&\n\t\t!/\\b(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}(?::\\d{1,5})?\\b/u.test(value) &&\n\t\t!/\\b(?:\\d{1,3}\\.){3}\\d{1,3}(?::\\d{1,5})?\\b/u.test(value) &&\n\t\t!/^(?:rm|curl|wget|sh|bash|zsh|fish|pwsh|powershell|cmd|node|bun|deno|npx|npm|pnpm|yarn|python(?:3)?|perl|ruby|git|docker|kubectl|ssh|scp|sudo|cat|ls|cd|mkdir|touch|chmod|chown|env|export|set|eval|exec)\\b/iu.test(\n\t\t\tvalue,\n\t\t) &&\n\t\t!/\\b(?:api[- ]?key|secret|token|credential|password)\\s*:/iu.test(value) &&\n\t\t!/\\b(?:claude|gpt|gemini|llama|mistral|zai|glm|qwen|deepseek|grok|nova|o\\d+)[-_.:][A-Za-z0-9._:-]+\\b/iu.test(\n\t\t\tvalue,\n\t\t)\n\t);\n}\n\nexport function parseHumainAgentExecutionRequest(input: unknown): HumainAgentExecutionRequest {\n\tif (!RequestValidator.Check(input)) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution request\");\n\t}\n\tif (input.mode === \"node\" && (input.claims.length !== 1 || input.batchId !== undefined)) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution request: node mode requires one claim and no batch identity\");\n\t}\n\tif (input.mode === \"workflow\" && input.batchId === undefined) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution request: workflow mode requires a batch identity\");\n\t}\n\tconst workUnitIds = new Set(input.claims.map(({ workUnitId }) => workUnitId));\n\tconst nodeIds = new Set(input.claims.map(({ nodeId }) => nodeId));\n\tif (workUnitIds.size !== input.claims.length || nodeIds.size !== input.claims.length) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution request: claim identities must be unique\");\n\t}\n\tif (input.claims.some(({ controls }) => controls.depth >= controls.maxDepth)) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution request: delegation depth limit is exhausted\");\n\t}\n\treturn deepFreeze(structuredClone(input));\n}\n\nexport function parseHumainAgentExecutionResponse(\n\trequestInput: unknown,\n\tresponseInput: unknown,\n): HumainAgentExecutionResponse {\n\tconst request = parseHumainAgentExecutionRequest(requestInput);\n\tif (!ResponseValidator.Check(responseInput)) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution response\");\n\t}\n\tconst response = responseInput;\n\tif (\n\t\tresponse.outcomes.some(\n\t\t\t(outcome) => outcome.kind === \"succeeded\" && !isSafeHumainAgentExecutionSummary(outcome.output.summary),\n\t\t)\n\t) {\n\t\tthrow new Error(\"Invalid HUMAIN agent execution response\");\n\t}\n\tif (\n\t\tresponse.mode !== request.mode ||\n\t\tresponse.invocationId !== request.invocationId ||\n\t\tresponse.batchId !== request.batchId\n\t) {\n\t\tthrow new Error(\"HUMAIN agent result envelope mismatch\");\n\t}\n\tif (response.outcomes.length !== request.claims.length) {\n\t\tthrow new Error(\"HUMAIN agent result cardinality mismatch\");\n\t}\n\tfor (const [index, outcome] of response.outcomes.entries()) {\n\t\tconst claim = request.claims[index];\n\t\tif (\n\t\t\t!claim ||\n\t\t\toutcome.workUnitId !== claim.workUnitId ||\n\t\t\toutcome.nodeId !== claim.nodeId ||\n\t\t\toutcome.attemptNumber !== claim.attemptNumber ||\n\t\t\toutcome.attemptFence !== claim.attemptFence ||\n\t\t\toutcome.segmentFence !== claim.segmentFence\n\t\t) {\n\t\t\tthrow new Error(\"HUMAIN agent result identity mismatch\");\n\t\t}\n\t}\n\tconst cancelled = response.outcomes.filter((outcome) => outcome.kind === \"cancelled\");\n\tconst expectedTermination =\n\t\tcancelled.length === 0\n\t\t\t? \"not-requested\"\n\t\t\t: cancelled.every((outcome) => outcome.terminationConfirmed)\n\t\t\t\t? \"confirmed\"\n\t\t\t\t: \"unconfirmed\";\n\tif (response.termination !== expectedTermination) {\n\t\tthrow new Error(\"HUMAIN agent result termination evidence mismatch\");\n\t}\n\treturn deepFreeze(structuredClone(response));\n}\n\nfunction deepFreeze<T>(value: T): T {\n\tif (value === null || typeof value !== \"object\" || Object.isFrozen(value)) return value;\n\tObject.freeze(value);\n\tfor (const child of Object.values(value)) deepFreeze(child);\n\treturn value;\n}\n"]}
|