@humain/humain-code 0.8.0 → 0.8.1
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 +21 -0
- package/dist/bundle/chunks/{anthropic-messages-UZB5HJE3.js → anthropic-messages-XFCDMGD6.js} +4 -4
- package/dist/bundle/chunks/{azure-openai-responses-J3LCMWPQ.js → azure-openai-responses-F4KQM3NK.js} +3 -3
- package/dist/bundle/chunks/{chunk-7EONJCBE.js → chunk-2JNJJ6SZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-WRYGY5XG.js → chunk-4MKATHT2.js} +1 -1
- package/dist/bundle/chunks/{chunk-ATFZAFMS.js → chunk-65FLSKDA.js} +1 -1
- package/dist/bundle/chunks/{chunk-CET2MXXN.js → chunk-6P6MMQUH.js} +1 -1
- package/dist/bundle/chunks/{chunk-CU6KU7JK.js → chunk-6TTMNQXI.js} +13 -13
- package/dist/bundle/chunks/{chunk-KQXXBQ57.js → chunk-6YVORXTX.js} +155 -125
- package/dist/bundle/chunks/{chunk-SQ7NTRLJ.js → chunk-7X6DNT45.js} +17 -16
- package/dist/bundle/chunks/{chunk-PGVDL4KB.js → chunk-CQ2CE3RB.js} +1 -1
- package/dist/bundle/chunks/{chunk-QRYDGY5I.js → chunk-DJG2WUNM.js} +1 -1
- package/dist/bundle/chunks/{chunk-R3VDXQW2.js → chunk-E7OBH44W.js} +5 -5
- package/dist/bundle/chunks/{chunk-4EV7CK26.js → chunk-F2H47FRF.js} +1 -1
- package/dist/bundle/chunks/chunk-FQ4KS5S4.js +23 -0
- package/dist/bundle/chunks/{chunk-TYN46EVI.js → chunk-GPLWWO5Q.js} +1 -1
- package/dist/bundle/chunks/{chunk-EMBIUIQ2.js → chunk-IMUFBWEK.js} +4 -4
- package/dist/bundle/chunks/{chunk-Z5UFSRO4.js → chunk-KI7CHPWC.js} +1 -1
- package/dist/bundle/chunks/{chunk-VKQNYZUA.js → chunk-KRBELWQH.js} +1 -1
- package/dist/bundle/chunks/{chunk-AI7EHDAX.js → chunk-LSRXA7OS.js} +1 -1
- package/dist/bundle/chunks/{chunk-XVIQYONJ.js → chunk-MIAXMK5F.js} +1 -1
- package/dist/bundle/chunks/{chunk-NNWNIBLG.js → chunk-NICPFMOP.js} +1 -1
- package/dist/bundle/chunks/{chunk-4SFWYKL5.js → chunk-P42E6YY6.js} +441 -415
- package/dist/bundle/chunks/{chunk-WGXMYMPE.js → chunk-PFBAIRCY.js} +2 -2
- package/dist/bundle/chunks/{chunk-OVDMYBIT.js → chunk-PWFM6AQQ.js} +1 -1
- package/dist/bundle/chunks/{chunk-JV7VHOAY.js → chunk-QRRVZYTG.js} +1 -1
- package/dist/bundle/chunks/{chunk-IOLLZXQN.js → chunk-ROFZVEFN.js} +125 -114
- package/dist/bundle/chunks/{chunk-C4DHVDYT.js → chunk-SXOIQWNX.js} +1 -1
- package/dist/bundle/chunks/{chunk-IXQYPQRQ.js → chunk-XZ7FTBXS.js} +1446 -1423
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-ETKC6B2S.js → cloudflare-workers-ai-system-one-JEZVYITT.js} +1 -1
- package/dist/bundle/chunks/{compat-HS4ARZK3.js → compat-SRCNS6OQ.js} +6 -6
- package/dist/bundle/chunks/{curator-server-TC7RVVN2.js → curator-server-QB4GITGS.js} +1 -1
- package/dist/bundle/chunks/{dist-5AQPJ2TI.js → dist-4OMLHRJE.js} +1 -1
- package/dist/bundle/chunks/{dist-NMEXYUP3.js → dist-CBODG4CA.js} +5 -5
- package/dist/bundle/chunks/{dist-DYB3AR7C.js → dist-TRAK7EXI.js} +7 -7
- package/dist/bundle/chunks/{extract-QHZTEVJP.js → extract-L373D6O7.js} +2 -2
- package/dist/bundle/chunks/{flow-implementer-QMN3HKE2.js → flow-implementer-4KO3Q4B5.js} +4 -4
- package/dist/bundle/chunks/github-copilot.js +53 -56
- package/dist/bundle/chunks/{google-generative-ai-ZND73WDQ.js → google-generative-ai-WIASMWS3.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-YAH62YRM.js → google-vertex-WSPHRZIZ.js} +3 -3
- package/dist/bundle/chunks/{host-Q565BCXB.js → host-WOLZCWQQ.js} +1 -1
- package/dist/bundle/chunks/{inprocess-453SLFL5.js → inprocess-TOBRVK4C.js} +5 -5
- package/dist/bundle/chunks/{interactive-mode-MVZOJ5OU.js → interactive-mode-BJJKPBXD.js} +3 -3
- package/dist/bundle/chunks/{llama-cpp-classify-Z4GZY4GC.js → llama-cpp-classify-KYZT532X.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-7I5JURDP.js → mistral-conversations-7JYDDRUT.js} +2 -2
- package/dist/bundle/chunks/{node-IMSYVRPL.js → node-N7TPBUJB.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-LTHOMN37.js → openai-codex-responses-7PAML4NF.js} +3 -3
- package/dist/bundle/chunks/{openai-completions-W2X635EE.js → openai-completions-UJDAIGTK.js} +3 -3
- package/dist/bundle/chunks/{openai-decisions-TN2GNOYI.js → openai-decisions-JMSDGR7K.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-DVY4QXOG.js → openai-responses-2WNCE6AY.js} +3 -3
- package/dist/bundle/chunks/{openrouter-images-SE2JMS44.js → openrouter-images-V3UCCO6X.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-WAS6Z5L5.js → pi-messages-TQ7LJUNQ.js} +2 -2
- package/dist/bundle/chunks/{session-picker-XNVLSJ22.js → session-picker-4JQEGLDD.js} +1 -1
- package/dist/bundle/chunks/{startup-ui-3TCT465D.js → startup-ui-AKTA4NDP.js} +1 -1
- package/dist/bundle/chunks/{typesafe-system-one-AAZH6S3I.js → typesafe-system-one-YP7GGN4C.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-CIVXCEAN.js → virtual-modules-3CT5BMBA.js} +8 -8
- package/dist/bundle/cli-runtime.js +5 -5
- package/dist/bundle/index.js +8 -8
- package/dist/bundle/rpc-entry.js +4 -4
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +16 -1
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +3 -2
- package/dist/cli/setup.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +3 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +11 -2
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/keybindings.d.ts +24 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +12 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +11 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -2
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +23 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +4 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +104 -20
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/sdk.js +2 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/extensions/usage/confirmation.d.ts.map +1 -1
- package/dist/extensions/usage/confirmation.js +1 -1
- package/dist/extensions/usage/confirmation.js.map +1 -1
- package/dist/extensions/usage/index.js +1 -1
- package/dist/extensions/usage/index.js.map +1 -1
- package/dist/extensions/usage/panes.d.ts +5 -0
- package/dist/extensions/usage/panes.d.ts.map +1 -0
- package/dist/extensions/usage/panes.js +10 -0
- package/dist/extensions/usage/panes.js.map +1 -0
- package/dist/extensions/usage/popup.d.ts.map +1 -1
- package/dist/extensions/usage/popup.js +9 -18
- package/dist/extensions/usage/popup.js.map +1 -1
- package/dist/humain/hcode/contracts.d.ts +15 -0
- package/dist/humain/hcode/contracts.d.ts.map +1 -1
- package/dist/humain/hcode/contracts.js +85 -10
- package/dist/humain/hcode/contracts.js.map +1 -1
- package/dist/humain/hcode/environment.d.ts.map +1 -1
- package/dist/humain/hcode/environment.js +4 -2
- package/dist/humain/hcode/environment.js.map +1 -1
- package/dist/humain/hcode/images.d.ts.map +1 -1
- package/dist/humain/hcode/images.js +4 -2
- package/dist/humain/hcode/images.js.map +1 -1
- package/dist/humain/hcode/login-copy.js +1 -1
- package/dist/humain/hcode/login-copy.js.map +1 -1
- package/dist/humain/hcode/notices.d.ts +22 -1
- package/dist/humain/hcode/notices.d.ts.map +1 -1
- package/dist/humain/hcode/notices.js +34 -3
- package/dist/humain/hcode/notices.js.map +1 -1
- package/dist/humain/hcode/provider.d.ts +3 -1
- package/dist/humain/hcode/provider.d.ts.map +1 -1
- package/dist/humain/hcode/provider.js +126 -46
- package/dist/humain/hcode/provider.js.map +1 -1
- package/dist/humain/hcode/run-credential.d.ts +21 -0
- package/dist/humain/hcode/run-credential.d.ts.map +1 -0
- package/dist/humain/hcode/run-credential.js +140 -0
- package/dist/humain/hcode/run-credential.js.map +1 -0
- package/dist/humain/hcode/sandbox.d.ts +6 -0
- package/dist/humain/hcode/sandbox.d.ts.map +1 -0
- package/dist/humain/hcode/sandbox.js +139 -0
- package/dist/humain/hcode/sandbox.js.map +1 -0
- package/dist/humain/hcode/selection.d.ts +7 -2
- package/dist/humain/hcode/selection.d.ts.map +1 -1
- package/dist/humain/hcode/selection.js +29 -5
- package/dist/humain/hcode/selection.js.map +1 -1
- package/dist/humain/hcode/transport.d.ts +3 -2
- package/dist/humain/hcode/transport.d.ts.map +1 -1
- package/dist/humain/hcode/transport.js +22 -7
- package/dist/humain/hcode/transport.js.map +1 -1
- package/dist/humain/remote/broker.d.ts +84 -0
- package/dist/humain/remote/broker.d.ts.map +1 -0
- package/dist/humain/remote/broker.js +427 -0
- package/dist/humain/remote/broker.js.map +1 -0
- package/dist/humain/remote/deny-store.d.ts +12 -0
- package/dist/humain/remote/deny-store.d.ts.map +1 -0
- package/dist/humain/remote/deny-store.js +164 -0
- package/dist/humain/remote/deny-store.js.map +1 -0
- package/dist/humain/remote/enablement.d.ts +5 -0
- package/dist/humain/remote/enablement.d.ts.map +1 -0
- package/dist/humain/remote/enablement.js +8 -0
- package/dist/humain/remote/enablement.js.map +1 -0
- package/dist/humain/remote/environment.d.ts +11 -0
- package/dist/humain/remote/environment.d.ts.map +1 -0
- package/dist/humain/remote/environment.js +19 -0
- package/dist/humain/remote/environment.js.map +1 -0
- package/dist/humain/remote/host-watch.d.ts +21 -0
- package/dist/humain/remote/host-watch.d.ts.map +1 -0
- package/dist/humain/remote/host-watch.js +186 -0
- package/dist/humain/remote/host-watch.js.map +1 -0
- package/dist/humain/remote/ipc-posix.d.ts +5 -0
- package/dist/humain/remote/ipc-posix.d.ts.map +1 -0
- package/dist/humain/remote/ipc-posix.js +29 -0
- package/dist/humain/remote/ipc-posix.js.map +1 -0
- package/dist/humain/remote/ipc-windows.d.ts +3 -0
- package/dist/humain/remote/ipc-windows.d.ts.map +1 -0
- package/dist/humain/remote/ipc-windows.js +5 -0
- package/dist/humain/remote/ipc-windows.js.map +1 -0
- package/dist/humain/remote/ipc.d.ts +10 -0
- package/dist/humain/remote/ipc.d.ts.map +1 -0
- package/dist/humain/remote/ipc.js +19 -0
- package/dist/humain/remote/ipc.js.map +1 -0
- package/dist/humain/remote/protocol.d.ts +43 -0
- package/dist/humain/remote/protocol.d.ts.map +1 -0
- package/dist/humain/remote/protocol.js +76 -0
- package/dist/humain/remote/protocol.js.map +1 -0
- package/dist/humain/remote/relay-socket.d.ts +30 -0
- package/dist/humain/remote/relay-socket.d.ts.map +1 -0
- package/dist/humain/remote/relay-socket.js +137 -0
- package/dist/humain/remote/relay-socket.js.map +1 -0
- package/dist/humain/remote/secure-channel.d.ts +10 -0
- package/dist/humain/remote/secure-channel.d.ts.map +1 -0
- package/dist/humain/remote/secure-channel.js +5 -0
- package/dist/humain/remote/secure-channel.js.map +1 -0
- package/dist/humain/remote/terminal.d.ts +48 -0
- package/dist/humain/remote/terminal.d.ts.map +1 -0
- package/dist/humain/remote/terminal.js +119 -0
- package/dist/humain/remote/terminal.js.map +1 -0
- package/dist/humain/remote/tickets.d.ts +35 -0
- package/dist/humain/remote/tickets.d.ts.map +1 -0
- package/dist/humain/remote/tickets.js +132 -0
- package/dist/humain/remote/tickets.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/account-picker.d.ts +31 -0
- package/dist/modes/interactive/components/account-picker.d.ts.map +1 -0
- package/dist/modes/interactive/components/account-picker.js +150 -0
- package/dist/modes/interactive/components/account-picker.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +15 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +225 -36
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/oauth-account-format.d.ts +9 -0
- package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
- package/dist/modes/interactive/oauth-account-format.js +31 -22
- package/dist/modes/interactive/oauth-account-format.js.map +1 -1
- package/docs/cli.md +1 -1
- package/docs/forge-run-bootstrap.md +46 -0
- package/docs/humain-code.md +2 -2
- package/docs/index.md +2 -1
- package/docs/keybindings.md +10 -0
- package/docs/providers.md +2 -2
- package/docs/quickstart.md +16 -2
- package/docs/slash-commands.md +4 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/keybindings.schema.json +12 -0
- package/dist/bundle/chunks/chunk-J5TSAJGC.js +0 -22
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Node pilot: bind a fresh, single-shot session to one model in Forge's run catalog.
|
|
2
|
+
import { parseArgs } from "../../cli/args.js";
|
|
3
|
+
import { getAgentDir } from "../../config.js";
|
|
4
|
+
import { AgentSessionRuntime } from "../../core/agent-session-runtime.js";
|
|
5
|
+
import { createAgentSessionFromServices, createAgentSessionServices } from "../../core/agent-session-services.js";
|
|
6
|
+
import { ModelRuntime } from "../../core/model-runtime.js";
|
|
7
|
+
import { flushRawStdout, restoreStdout, takeOverStdout } from "../../core/output-guard.js";
|
|
8
|
+
import { SessionManager } from "../../core/session-manager.js";
|
|
9
|
+
import { SettingsManager } from "../../core/settings-manager.js";
|
|
10
|
+
import { runPrintMode } from "../../modes/print-mode.js";
|
|
11
|
+
import { HCODE_PROVIDER } from "./http.js";
|
|
12
|
+
import { BUILD_SESSION_ENDED } from "./notices.js";
|
|
13
|
+
const SINGLE_SHOT_OPTIONS = new Set([
|
|
14
|
+
"messages",
|
|
15
|
+
"fileArgs",
|
|
16
|
+
"unknownFlags",
|
|
17
|
+
"diagnostics",
|
|
18
|
+
"mode",
|
|
19
|
+
"print",
|
|
20
|
+
"model",
|
|
21
|
+
"provider",
|
|
22
|
+
"environment",
|
|
23
|
+
"cwd",
|
|
24
|
+
"noSession",
|
|
25
|
+
"noExtensions",
|
|
26
|
+
"noMcp",
|
|
27
|
+
"noCoordinate",
|
|
28
|
+
"noSkills",
|
|
29
|
+
"noPromptTemplates",
|
|
30
|
+
"noThemes",
|
|
31
|
+
"noContextFiles",
|
|
32
|
+
"noTools",
|
|
33
|
+
"tools",
|
|
34
|
+
"excludeTools",
|
|
35
|
+
"literalPrompt",
|
|
36
|
+
"thinking",
|
|
37
|
+
"timeLimitSeconds",
|
|
38
|
+
]);
|
|
39
|
+
export async function runHcodeSandbox(args, bootstrap, resolveCwd) {
|
|
40
|
+
const parsed = parseArgs(args);
|
|
41
|
+
if (process.versions.bun ||
|
|
42
|
+
process.env.PI_OFFLINE ||
|
|
43
|
+
process.env.HUMAIN_TERMINAL_TRACE_BOOTSTRAP_FD !== undefined ||
|
|
44
|
+
!(parsed.mode === "json" || ((parsed.mode === undefined || parsed.mode === "text") && parsed.print)) ||
|
|
45
|
+
!parsed.model ||
|
|
46
|
+
(parsed.provider !== undefined && parsed.provider !== HCODE_PROVIDER) ||
|
|
47
|
+
(parsed.environment !== undefined && parsed.environment !== bootstrap.environment.id) ||
|
|
48
|
+
parsed.unknownFlags.size ||
|
|
49
|
+
parsed.diagnostics.length ||
|
|
50
|
+
parsed.fileArgs.length ||
|
|
51
|
+
parsed.tools?.some((tool) => tool === "subagent" || tool === "+subagent") ||
|
|
52
|
+
parsed.messages.length !== 1 ||
|
|
53
|
+
parsed.messages.some((message) => /^\s*\/flow(?:\s|$)/i.test(message)) ||
|
|
54
|
+
Object.keys(parsed).some((key) => !SINGLE_SHOT_OPTIONS.has(key))) {
|
|
55
|
+
console.error("Forge run inference requires a supported Node single-shot invocation and an explicit model. Flow and RPC are not supported.");
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
const refuse = () => {
|
|
59
|
+
throw new Error("Forge run inference cannot replace its session.");
|
|
60
|
+
};
|
|
61
|
+
const facade = bootstrap.open();
|
|
62
|
+
let modelRuntime;
|
|
63
|
+
let runtime;
|
|
64
|
+
takeOverStdout();
|
|
65
|
+
try {
|
|
66
|
+
const cwd = resolveCwd(parsed, process.env, process.cwd());
|
|
67
|
+
const agentDir = getAgentDir();
|
|
68
|
+
modelRuntime = await ModelRuntime.createForHcodeRun(facade);
|
|
69
|
+
const discovery = await modelRuntime.refresh({ providers: [HCODE_PROVIDER], signal: facade.signal });
|
|
70
|
+
if (discovery.aborted || discovery.errors.size || facade.tokenRejected()) {
|
|
71
|
+
console.error(facade.tokenRejected() ? BUILD_SESSION_ENDED : "Forge run model catalog is unavailable.");
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
const modelId = parsed.model.startsWith(`${HCODE_PROVIDER}/`)
|
|
75
|
+
? parsed.model.slice(HCODE_PROVIDER.length + 1)
|
|
76
|
+
: parsed.model;
|
|
77
|
+
const model = modelRuntime.getModel(HCODE_PROVIDER, modelId);
|
|
78
|
+
if (!model || model.id !== modelId) {
|
|
79
|
+
console.error("Requested model is not in the Forge run catalog.");
|
|
80
|
+
return 1;
|
|
81
|
+
}
|
|
82
|
+
const services = await createAgentSessionServices({
|
|
83
|
+
cwd,
|
|
84
|
+
agentDir,
|
|
85
|
+
modelRuntime,
|
|
86
|
+
settingsManager: SettingsManager.inMemory({ retry: { enabled: false } }, { projectTrusted: false }),
|
|
87
|
+
resourceLoaderOptions: {
|
|
88
|
+
noExtensions: true,
|
|
89
|
+
noSkills: true,
|
|
90
|
+
noPromptTemplates: true,
|
|
91
|
+
noThemes: true,
|
|
92
|
+
noContextFiles: true,
|
|
93
|
+
// Ambient SYSTEM.md / APPEND_SYSTEM.md in the agent dir or project must not reach a Build session.
|
|
94
|
+
systemPromptOverride: () => undefined,
|
|
95
|
+
appendSystemPromptOverride: () => [],
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
const created = await createAgentSessionFromServices({
|
|
99
|
+
services,
|
|
100
|
+
sessionManager: SessionManager.inMemory(cwd),
|
|
101
|
+
model,
|
|
102
|
+
thinkingLevel: parsed.thinking,
|
|
103
|
+
tools: parsed.tools,
|
|
104
|
+
// The native worker tool is built in, independent of extension and Flow loading.
|
|
105
|
+
excludeTools: [...(parsed.excludeTools ?? []), "subagent"],
|
|
106
|
+
noTools: parsed.noTools ? "all" : undefined,
|
|
107
|
+
timeLimitSeconds: parsed.timeLimitSeconds,
|
|
108
|
+
});
|
|
109
|
+
runtime = new AgentSessionRuntime(created.session, services, refuse);
|
|
110
|
+
if (created.session.model !== model)
|
|
111
|
+
throw new Error("Forge run model could not be selected.");
|
|
112
|
+
const code = await runPrintMode(runtime, {
|
|
113
|
+
mode: parsed.mode === "json" ? "json" : "text",
|
|
114
|
+
messages: parsed.messages,
|
|
115
|
+
expandPromptTemplates: false,
|
|
116
|
+
});
|
|
117
|
+
if (code !== 0 && facade.tokenRejected() && parsed.mode === "json")
|
|
118
|
+
console.error(BUILD_SESSION_ENDED);
|
|
119
|
+
return code;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
console.error(facade.tokenRejected() ? BUILD_SESSION_ENDED : "Forge run inference setup failed.");
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
try {
|
|
127
|
+
await runtime?.dispose();
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
if (modelRuntime)
|
|
131
|
+
modelRuntime.dispose();
|
|
132
|
+
else
|
|
133
|
+
facade.dispose();
|
|
134
|
+
await flushRawStdout();
|
|
135
|
+
restoreStdout();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../../src/humain/hcode/sandbox.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,OAAO,EAAa,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO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O,EAAE,CAAC;;gBACpC,MAAM,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,cAAc,EAAE,CAAC;YACvB,aAAa,EAAE,CAAC;QACjB,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["// Node pilot: bind a fresh, single-shot session to one model in Forge's run catalog.\nimport { type Args, parseArgs } from \"../../cli/args.ts\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\nimport { createAgentSessionFromServices, createAgentSessionServices } from \"../../core/agent-session-services.ts\";\nimport { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { flushRawStdout, restoreStdout, takeOverStdout } from \"../../core/output-guard.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { runPrintMode } from \"../../modes/print-mode.ts\";\nimport { HCODE_PROVIDER } from \"./http.ts\";\nimport { BUILD_SESSION_ENDED } from \"./notices.ts\";\nimport type { HcodeRunBootstrap } from \"./run-credential.ts\";\n\nconst SINGLE_SHOT_OPTIONS = new Set<keyof Args>([\n\t\"messages\",\n\t\"fileArgs\",\n\t\"unknownFlags\",\n\t\"diagnostics\",\n\t\"mode\",\n\t\"print\",\n\t\"model\",\n\t\"provider\",\n\t\"environment\",\n\t\"cwd\",\n\t\"noSession\",\n\t\"noExtensions\",\n\t\"noMcp\",\n\t\"noCoordinate\",\n\t\"noSkills\",\n\t\"noPromptTemplates\",\n\t\"noThemes\",\n\t\"noContextFiles\",\n\t\"noTools\",\n\t\"tools\",\n\t\"excludeTools\",\n\t\"literalPrompt\",\n\t\"thinking\",\n\t\"timeLimitSeconds\",\n]);\n\nexport async function runHcodeSandbox(\n\targs: string[],\n\tbootstrap: Extract<HcodeRunBootstrap, { kind: \"run\" }>,\n\tresolveCwd: (parsed: Pick<Args, \"cwd\">, env: NodeJS.ProcessEnv, cwd: string) => string,\n): Promise<number> {\n\tconst parsed = parseArgs(args);\n\tif (\n\t\tprocess.versions.bun ||\n\t\tprocess.env.PI_OFFLINE ||\n\t\tprocess.env.HUMAIN_TERMINAL_TRACE_BOOTSTRAP_FD !== undefined ||\n\t\t!(parsed.mode === \"json\" || ((parsed.mode === undefined || parsed.mode === \"text\") && parsed.print)) ||\n\t\t!parsed.model ||\n\t\t(parsed.provider !== undefined && parsed.provider !== HCODE_PROVIDER) ||\n\t\t(parsed.environment !== undefined && parsed.environment !== bootstrap.environment.id) ||\n\t\tparsed.unknownFlags.size ||\n\t\tparsed.diagnostics.length ||\n\t\tparsed.fileArgs.length ||\n\t\tparsed.tools?.some((tool) => tool === \"subagent\" || tool === \"+subagent\") ||\n\t\tparsed.messages.length !== 1 ||\n\t\tparsed.messages.some((message) => /^\\s*\\/flow(?:\\s|$)/i.test(message)) ||\n\t\tObject.keys(parsed).some((key) => !SINGLE_SHOT_OPTIONS.has(key as keyof Args))\n\t) {\n\t\tconsole.error(\n\t\t\t\"Forge run inference requires a supported Node single-shot invocation and an explicit model. Flow and RPC are not supported.\",\n\t\t);\n\t\treturn 1;\n\t}\n\n\tconst refuse = () => {\n\t\tthrow new Error(\"Forge run inference cannot replace its session.\");\n\t};\n\tconst facade = bootstrap.open();\n\tlet modelRuntime: ModelRuntime | undefined;\n\tlet runtime: AgentSessionRuntime | undefined;\n\ttakeOverStdout();\n\ttry {\n\t\tconst cwd = resolveCwd(parsed, process.env, process.cwd());\n\t\tconst agentDir = getAgentDir();\n\t\tmodelRuntime = await ModelRuntime.createForHcodeRun(facade);\n\t\tconst discovery = await modelRuntime.refresh({ providers: [HCODE_PROVIDER], signal: facade.signal });\n\t\tif (discovery.aborted || discovery.errors.size || facade.tokenRejected()) {\n\t\t\tconsole.error(facade.tokenRejected() ? BUILD_SESSION_ENDED : \"Forge run model catalog is unavailable.\");\n\t\t\treturn 1;\n\t\t}\n\t\tconst modelId = parsed.model.startsWith(`${HCODE_PROVIDER}/`)\n\t\t\t? parsed.model.slice(HCODE_PROVIDER.length + 1)\n\t\t\t: parsed.model;\n\t\tconst model = modelRuntime.getModel(HCODE_PROVIDER, modelId);\n\t\tif (!model || model.id !== modelId) {\n\t\t\tconsole.error(\"Requested model is not in the Forge run catalog.\");\n\t\t\treturn 1;\n\t\t}\n\t\tconst services = await createAgentSessionServices({\n\t\t\tcwd,\n\t\t\tagentDir,\n\t\t\tmodelRuntime,\n\t\t\tsettingsManager: SettingsManager.inMemory({ retry: { enabled: false } }, { projectTrusted: false }),\n\t\t\tresourceLoaderOptions: {\n\t\t\t\tnoExtensions: true,\n\t\t\t\tnoSkills: true,\n\t\t\t\tnoPromptTemplates: true,\n\t\t\t\tnoThemes: true,\n\t\t\t\tnoContextFiles: true,\n\t\t\t\t// Ambient SYSTEM.md / APPEND_SYSTEM.md in the agent dir or project must not reach a Build session.\n\t\t\t\tsystemPromptOverride: () => undefined,\n\t\t\t\tappendSystemPromptOverride: () => [],\n\t\t\t},\n\t\t});\n\t\tconst created = await createAgentSessionFromServices({\n\t\t\tservices,\n\t\t\tsessionManager: SessionManager.inMemory(cwd),\n\t\t\tmodel,\n\t\t\tthinkingLevel: parsed.thinking,\n\t\t\ttools: parsed.tools,\n\t\t\t// The native worker tool is built in, independent of extension and Flow loading.\n\t\t\texcludeTools: [...(parsed.excludeTools ?? []), \"subagent\"],\n\t\t\tnoTools: parsed.noTools ? \"all\" : undefined,\n\t\t\ttimeLimitSeconds: parsed.timeLimitSeconds,\n\t\t});\n\t\truntime = new AgentSessionRuntime(created.session, services, refuse);\n\t\tif (created.session.model !== model) throw new Error(\"Forge run model could not be selected.\");\n\t\tconst code = await runPrintMode(runtime, {\n\t\t\tmode: parsed.mode === \"json\" ? \"json\" : \"text\",\n\t\t\tmessages: parsed.messages,\n\t\t\texpandPromptTemplates: false,\n\t\t});\n\t\tif (code !== 0 && facade.tokenRejected() && parsed.mode === \"json\") console.error(BUILD_SESSION_ENDED);\n\t\treturn code;\n\t} catch {\n\t\tconsole.error(facade.tokenRejected() ? BUILD_SESSION_ENDED : \"Forge run inference setup failed.\");\n\t\treturn 1;\n\t} finally {\n\t\ttry {\n\t\t\tawait runtime?.dispose();\n\t\t} finally {\n\t\t\tif (modelRuntime) modelRuntime.dispose();\n\t\t\telse facade.dispose();\n\t\t\tawait flushRawStdout();\n\t\t\trestoreStdout();\n\t\t}\n\t}\n}\n"]}
|
|
@@ -7,8 +7,13 @@ export declare const HCODE_SELECTION_CHANGED_MESSAGE = "Your HUMAIN Code account
|
|
|
7
7
|
export declare const HCODE_UNSUPPORTED_THINKING_MESSAGE = "This HUMAIN Code model doesn't support that thinking level. Choose a supported level with /thinking.";
|
|
8
8
|
/** Whether an error message is one of the fixed selection refusals above, safe to show outside the TUI. */
|
|
9
9
|
export declare function isHcodeSelectionMessage(message: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Explain a native selection failure without resolving auth or probing inference. When Forge's current catalog
|
|
12
|
+
* for this account excluded one of the requested exact IDs with a known reason, name that reason.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hcodeSelectionUnavailable(runtime: ModelRuntime, requestedIds?: readonly string[]): string;
|
|
15
|
+
/** The refusal for an exact `/model` reference Forge excluded from this account's catalog, or undefined. */
|
|
16
|
+
export declare function hcodeExcludedSelection(runtime: ModelRuntime, reference: string): string | undefined;
|
|
12
17
|
/** Look up a current, available native catalog entry without any network or credential resolution. */
|
|
13
18
|
export declare function availableHcodeSelection(runtime: ModelRuntime, modelId: string): Model<Api> | undefined;
|
|
14
19
|
/** Capture the exact canonical account selection before asynchronous authentication. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/selection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/selection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qGAAqG;AACrG,eAAO,MAAM,+BAA+B,gFACkC,CAAC;AAE/E,8FAA8F;AAC9F,eAAO,MAAM,kCAAkC,yGACwD,CAAC;AAKxG,2GAA2G;AAC3G,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAMhE;AAcD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAS7G;AAED,4GAA4G;AAC5G,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOnG;AAED,sGAAsG;AACtG,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAKtG;AAED,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,eAAe,CAM/F;AAED,kGAAkG;AAClG,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAQ9G"}
|
|
@@ -11,12 +11,36 @@ export function isHcodeSelectionMessage(message) {
|
|
|
11
11
|
message === HCODE_UNSUPPORTED_THINKING_MESSAGE ||
|
|
12
12
|
message.startsWith(HCODE_SELECTION_UNAVAILABLE_MESSAGE));
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// Fixed copy for Forge's catalog exclusion codes; server text is never shown.
|
|
15
|
+
const EXCLUSION_REASONS = {
|
|
16
|
+
missing_trusted_metadata: "HUMAIN Code hasn't verified this model's details for CLI use. Ask an admin to report it to the HUMAIN Code platform team.",
|
|
17
|
+
credential_unavailable: "The model's provider key isn't enabled for CLI. Ask an admin to enable CLI on the key in Settings > Provider Keys.",
|
|
18
|
+
provider_quota_isolation_unverified: "The model's provider key is shared or isn't approved for CLI use. Ask an admin to configure a dedicated key for HUMAIN Code CLI.",
|
|
19
|
+
quota_mapping_unavailable: "The model's CLI usage limits aren't set up. Ask the HUMAIN Code platform team to check the deployment's CLI capacity limits.",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Explain a native selection failure without resolving auth or probing inference. When Forge's current catalog
|
|
23
|
+
* for this account excluded one of the requested exact IDs with a known reason, name that reason.
|
|
24
|
+
*/
|
|
25
|
+
export function hcodeSelectionUnavailable(runtime, requestedIds = []) {
|
|
16
26
|
const message = HCODE_SELECTION_UNAVAILABLE_MESSAGE;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
if (!runtime.hcode.account.status(runtime.hcode.environment.id))
|
|
28
|
+
return `${message} Use /login to sign in to HUMAIN Code first.`;
|
|
29
|
+
for (const id of requestedIds) {
|
|
30
|
+
const reason = runtime.hcodeCatalogExclusionReason(id);
|
|
31
|
+
if (reason)
|
|
32
|
+
return `${message} Reason: ${EXCLUSION_REASONS[reason]}`;
|
|
33
|
+
}
|
|
34
|
+
return message;
|
|
35
|
+
}
|
|
36
|
+
/** The refusal for an exact `/model` reference Forge excluded from this account's catalog, or undefined. */
|
|
37
|
+
export function hcodeExcludedSelection(runtime, reference) {
|
|
38
|
+
const text = reference.trim();
|
|
39
|
+
const prefix = `${HCODE_PROVIDER}/`;
|
|
40
|
+
const id = text.toLowerCase().startsWith(prefix) ? text.slice(prefix.length).trim() : text;
|
|
41
|
+
return runtime.hcode.account.status(runtime.hcode.environment.id) && runtime.hcodeCatalogExclusionReason(id)
|
|
42
|
+
? hcodeSelectionUnavailable(runtime, [id])
|
|
43
|
+
: undefined;
|
|
20
44
|
}
|
|
21
45
|
/** Look up a current, available native catalog entry without any network or credential resolution. */
|
|
22
46
|
export function availableHcodeSelection(runtime, modelId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../../src/humain/hcode/selection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../../src/humain/hcode/selection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,qGAAqG;AACrG,MAAM,CAAC,MAAM,+BAA+B,GAC3C,6EAA6E,CAAC;AAE/E,8FAA8F;AAC9F,MAAM,CAAC,MAAM,kCAAkC,GAC9C,sGAAsG,CAAC;AAExG,MAAM,mCAAmC,GACxC,uJAAuJ,CAAC;AAEzJ,2GAA2G;AAC3G,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACtD,OAAO,CACN,OAAO,KAAK,+BAA+B;QAC3C,OAAO,KAAK,kCAAkC;QAC9C,OAAO,CAAC,UAAU,CAAC,mCAAmC,CAAC,CACvD,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,MAAM,iBAAiB,GAA0D;IAChF,wBAAwB,EACvB,2HAA2H;IAC5H,sBAAsB,EACrB,oHAAoH;IACrH,mCAAmC,EAClC,kIAAkI;IACnI,yBAAyB,EACxB,8HAA8H;CAC/H,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAqB,EAAE,YAAY,GAAsB,EAAE;IACpG,MAAM,OAAO,GAAG,mCAAmC,CAAC;IACpD,IAAI,CAAC,OAAO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,CAAC,oBAAoB,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC1G,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AACd,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,qBAAqB,CAAC,OAAqB,EAAE,KAAiB;IAC7E,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC7E,IAAI,CAAC,SAAS,IAAI,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK;QACrE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,oBAAoB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAChD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,oBAAoB,CAAC,OAAqB,EAAE,KAAiB,EAAE,QAAyB;IACvG,IACC,KAAK,CAAC,QAAQ,KAAK,cAAc;QACjC,QAAQ,CAAC,aAAa,KAAK,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE;QACvD,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC;QACpF,uBAAuB,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK;QAEpD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;AACnD,CAAC","sourcesContent":["// Native selection uses only the current approved catalog; unavailable choices never authorize fallback.\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { sameReference } from \"./account-store.ts\";\nimport type { HcodeCatalogExclusionReason } from \"./contracts.ts\";\nimport { HCODE_PROVIDER } from \"./http.ts\";\nimport type { HcodeAccountRef } from \"./ports.ts\";\n\n/** Explain an invalidated account/catalog selection without leaking account or model identifiers. */\nexport const HCODE_SELECTION_CHANGED_MESSAGE =\n\t\"Your HUMAIN Code account or model list changed. Use /model to choose again.\";\n\n/** Guide the user to an explicitly supported thinking level without coercing their choice. */\nexport const HCODE_UNSUPPORTED_THINKING_MESSAGE =\n\t\"This HUMAIN Code model doesn't support that thinking level. Choose a supported level with /thinking.\";\n\nconst HCODE_SELECTION_UNAVAILABLE_MESSAGE =\n\t\"This HUMAIN Code model is unavailable for your account in this environment. Use /model to refresh and choose an enabled model. No model was switched.\";\n\n/** Whether an error message is one of the fixed selection refusals above, safe to show outside the TUI. */\nexport function isHcodeSelectionMessage(message: string): boolean {\n\treturn (\n\t\tmessage === HCODE_SELECTION_CHANGED_MESSAGE ||\n\t\tmessage === HCODE_UNSUPPORTED_THINKING_MESSAGE ||\n\t\tmessage.startsWith(HCODE_SELECTION_UNAVAILABLE_MESSAGE)\n\t);\n}\n\n// Fixed copy for Forge's catalog exclusion codes; server text is never shown.\nconst EXCLUSION_REASONS: Readonly<Record<HcodeCatalogExclusionReason, string>> = {\n\tmissing_trusted_metadata:\n\t\t\"HUMAIN Code hasn't verified this model's details for CLI use. Ask an admin to report it to the HUMAIN Code platform team.\",\n\tcredential_unavailable:\n\t\t\"The model's provider key isn't enabled for CLI. Ask an admin to enable CLI on the key in Settings > Provider Keys.\",\n\tprovider_quota_isolation_unverified:\n\t\t\"The model's provider key is shared or isn't approved for CLI use. Ask an admin to configure a dedicated key for HUMAIN Code CLI.\",\n\tquota_mapping_unavailable:\n\t\t\"The model's CLI usage limits aren't set up. Ask the HUMAIN Code platform team to check the deployment's CLI capacity limits.\",\n};\n\n/**\n * Explain a native selection failure without resolving auth or probing inference. When Forge's current catalog\n * for this account excluded one of the requested exact IDs with a known reason, name that reason.\n */\nexport function hcodeSelectionUnavailable(runtime: ModelRuntime, requestedIds: readonly string[] = []): string {\n\tconst message = HCODE_SELECTION_UNAVAILABLE_MESSAGE;\n\tif (!runtime.hcode.account.status(runtime.hcode.environment.id))\n\t\treturn `${message} Use /login to sign in to HUMAIN Code first.`;\n\tfor (const id of requestedIds) {\n\t\tconst reason = runtime.hcodeCatalogExclusionReason(id);\n\t\tif (reason) return `${message} Reason: ${EXCLUSION_REASONS[reason]}`;\n\t}\n\treturn message;\n}\n\n/** The refusal for an exact `/model` reference Forge excluded from this account's catalog, or undefined. */\nexport function hcodeExcludedSelection(runtime: ModelRuntime, reference: string): string | undefined {\n\tconst text = reference.trim();\n\tconst prefix = `${HCODE_PROVIDER}/`;\n\tconst id = text.toLowerCase().startsWith(prefix) ? text.slice(prefix.length).trim() : text;\n\treturn runtime.hcode.account.status(runtime.hcode.environment.id) && runtime.hcodeCatalogExclusionReason(id)\n\t\t? hcodeSelectionUnavailable(runtime, [id])\n\t\t: undefined;\n}\n\n/** Look up a current, available native catalog entry without any network or credential resolution. */\nexport function availableHcodeSelection(runtime: ModelRuntime, modelId: string): Model<Api> | undefined {\n\tconst model = runtime.getModel(HCODE_PROVIDER, modelId);\n\treturn model && runtime.hasConfiguredAuth(HCODE_PROVIDER) && runtime.getAvailableSnapshot().includes(model)\n\t\t? model\n\t\t: undefined;\n}\n\n/** Capture the exact canonical account selection before asynchronous authentication. */\nexport function captureHcodeSelection(runtime: ModelRuntime, model: Model<Api>): HcodeAccountRef {\n\tconst reference = runtime.hcode.account.status(runtime.hcode.environment.id);\n\tif (!reference || availableHcodeSelection(runtime, model.id) !== model)\n\t\tthrow new Error(hcodeSelectionUnavailable(runtime));\n\tassertHcodeSelection(runtime, model, reference);\n\treturn reference;\n}\n\n/** Fence account/environment/generation and canonical approval in the synchronous commit turn. */\nexport function assertHcodeSelection(runtime: ModelRuntime, model: Model<Api>, expected: HcodeAccountRef): void {\n\tif (\n\t\tmodel.provider !== HCODE_PROVIDER ||\n\t\texpected.environmentId !== runtime.hcode.environment.id ||\n\t\t!sameReference(runtime.hcode.account.status(runtime.hcode.environment.id), expected) ||\n\t\tavailableHcodeSelection(runtime, model.id) !== model\n\t)\n\t\tthrow new Error(HCODE_SELECTION_CHANGED_MESSAGE);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type DelegatedFetch, type JsonObject, type Model } from "@earendil-works/pi-ai";
|
|
2
2
|
import { type HcodeInferenceError, type HcodeMessagesRequest } from "./contracts.ts";
|
|
3
3
|
import type { HcodeEnvironment } from "./environment.ts";
|
|
4
|
-
import { type HcodeLocalReason } from "./notices.ts";
|
|
4
|
+
import { type HcodeLocalDetail, type HcodeLocalReason } from "./notices.ts";
|
|
5
5
|
import type { HcodeAccountPort, HcodeAccountRef } from "./ports.ts";
|
|
6
6
|
/** A fixed failure, optionally carrying only schema-validated service refusal facts for the UI. */
|
|
7
7
|
export declare class HcodeTransportError extends Error {
|
|
@@ -16,7 +16,8 @@ export declare class HcodeTransportError extends Error {
|
|
|
16
16
|
/** A closed reason that proves the request stopped before inference dispatch. */
|
|
17
17
|
export declare class HcodeLocalRefusal extends Error {
|
|
18
18
|
readonly reason: HcodeLocalReason;
|
|
19
|
-
|
|
19
|
+
readonly detail: HcodeLocalDetail | undefined;
|
|
20
|
+
constructor(reason: HcodeLocalReason, detail?: HcodeLocalDetail);
|
|
20
21
|
}
|
|
21
22
|
/** Parse the closed request schema without exposing raw validation errors. */
|
|
22
23
|
export declare function parseHcodeRequestBody(body: string): HcodeMessagesRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/transport.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAG/G,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/humain/hcode/transport.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AgB,EACzB,WAAW,EAAE,gBAAgB,EAC7B,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,EAC3B,cAAc,EAAE,MAAM,EACtB,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAC/B,cAAc,CAsHhB"}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { isDeepStrictEqual } from "node:util";
|
|
3
3
|
import { createDelegatedFetch } from "@earendil-works/pi-ai";
|
|
4
4
|
import { sameReference } from "./account-store.js";
|
|
5
|
-
import { createHcodePiEventValidator, HCODE_ERROR_STATUS, MAX_PI_EVENT_FRAME_BYTES, parseHcodeInferenceError, parseHcodeMessagesRequest, } from "./contracts.js";
|
|
5
|
+
import { createHcodePiEventValidator, HCODE_ERROR_STATUS, HcodeRequestSchemaError, MAX_PI_EVENT_FRAME_BYTES, parseHcodeInferenceError, parseHcodeMessagesRequest, } from "./contracts.js";
|
|
6
6
|
import { assertHcodeRequest, readHcodeJson } from "./http.js";
|
|
7
7
|
import { fitHcodeRequestSize, reportHcodeImageOmissions, validateHcodeImages } from "./images.js";
|
|
8
|
-
import { formatHcodeLocalRefusal, HCODE_REFUSAL_REASON_HEADERS } from "./notices.js";
|
|
8
|
+
import { formatHcodeLocalRefusal, HCODE_REFUSAL_REASON_HEADERS, } from "./notices.js";
|
|
9
9
|
/** A fixed failure, optionally carrying only schema-validated service refusal facts for the UI. */
|
|
10
10
|
export class HcodeTransportError extends Error {
|
|
11
11
|
failure;
|
|
@@ -35,18 +35,33 @@ export class HcodeTransportError extends Error {
|
|
|
35
35
|
/** A closed reason that proves the request stopped before inference dispatch. */
|
|
36
36
|
export class HcodeLocalRefusal extends Error {
|
|
37
37
|
reason;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
detail;
|
|
39
|
+
constructor(reason, detail) {
|
|
40
|
+
super(formatHcodeLocalRefusal(reason, detail));
|
|
40
41
|
this.reason = reason;
|
|
42
|
+
this.detail = detail;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
/** Parse the closed request schema without exposing raw validation errors. */
|
|
44
46
|
export function parseHcodeRequestBody(body) {
|
|
45
47
|
try {
|
|
46
|
-
|
|
48
|
+
const value = JSON.parse(body);
|
|
49
|
+
// Payload hooks are an untrusted boundary; inspect only the fixed message-array path.
|
|
50
|
+
if (value && typeof value === "object" && "context" in value) {
|
|
51
|
+
const context = value.context;
|
|
52
|
+
if (context &&
|
|
53
|
+
typeof context === "object" &&
|
|
54
|
+
"messages" in context &&
|
|
55
|
+
Array.isArray(context.messages) &&
|
|
56
|
+
context.messages.length > 512)
|
|
57
|
+
throw new HcodeLocalRefusal("envelope", "messageLimit");
|
|
58
|
+
}
|
|
59
|
+
return parseHcodeMessagesRequest(value);
|
|
47
60
|
}
|
|
48
|
-
catch {
|
|
49
|
-
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof HcodeLocalRefusal)
|
|
63
|
+
throw error;
|
|
64
|
+
throw new HcodeLocalRefusal("envelope", error instanceof HcodeRequestSchemaError ? error.detail : "schema");
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
/** Captures one exact environment/model/reference/key and permits at most one account submission. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/humain/hcode/transport.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAoD,MAAM,uBAAuB,CAAC;AAE/G,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,2BAA2B,EAC3B,kBAAkB,EAGlB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EA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I,KAAK,OAAO;oBAAE,QAAQ,GAAG,SAAS,CAAC;;oBACrE,MAAM,SAAS,CAAC;gBACrB,2EAA2E;gBAC3E,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC7B,IAAI,GAAG,CAAC,CAAC;YACV,CAAC;QACF,CAAC;QACD,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,IAAI,IAAI;YAAE,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAC1C,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,iGAAiG;QACjG,IAAI,QAAQ;YAAE,MAAM,QAAQ,CAAC;IAC9B,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["// One invocation's final-send authority and bounded, validated managed response boundary.\nimport { isDeepStrictEqual } from \"node:util\";\n\nimport { createDelegatedFetch, type DelegatedFetch, type JsonObject, type Model } from \"@earendil-works/pi-ai\";\n\nimport { sameReference } from \"./account-store.ts\";\nimport {\n\tcreateHcodePiEventValidator,\n\tHCODE_ERROR_STATUS,\n\ttype HcodeInferenceError,\n\ttype HcodeMessagesRequest,\n\tMAX_PI_EVENT_FRAME_BYTES,\n\tparseHcodeInferenceError,\n\tparseHcodeMessagesRequest,\n} from \"./contracts.ts\";\nimport type { HcodeEnvironment } from \"./environment.ts\";\nimport { assertHcodeRequest, readHcodeJson } from \"./http.ts\";\nimport { fitHcodeRequestSize, reportHcodeImageOmissions, validateHcodeImages } from \"./images.ts\";\nimport { formatHcodeLocalRefusal, HCODE_REFUSAL_REASON_HEADERS, type HcodeLocalReason } from \"./notices.ts\";\nimport type { HcodeAccountPort, HcodeAccountRef } from \"./ports.ts\";\n\n/** A fixed failure, optionally carrying only schema-validated service refusal facts for the UI. */\nexport class HcodeTransportError extends Error {\n\treadonly failure: HcodeInferenceError | undefined;\n\treadonly status: number | undefined;\n\treadonly retryAfter: string | undefined;\n\treadonly reason: string | undefined;\n\tconstructor(failure?: HcodeInferenceError, status?: number, retryAfter?: string, reason?: string) {\n\t\tsuper(\"HUMAIN Code request unavailable. Do not automatically resend.\");\n\t\tthis.name = \"HcodeTransportError\";\n\t\tthis.failure = failure;\n\t\tthis.status = status;\n\t\tthis.retryAfter = retryAfter;\n\t\tthis.reason = reason;\n\t}\n\t/** Returns only validated JSON facts; never remote diagnostics, headers or body text. */\n\tdiagnostics(): JsonObject {\n\t\t// The closed X1 error parser guarantees plain JSON, including the allowance snapshot.\n\t\tconst safe: JsonObject = this.failure ? JSON.parse(JSON.stringify(this.failure)) : {};\n\t\treturn {\n\t\t\t...safe,\n\t\t\t...(this.status === undefined ? {} : { status: this.status }),\n\t\t\t...(this.retryAfter ? { retryAfter: this.retryAfter } : {}),\n\t\t\t...(this.reason ? { reason: this.reason } : {}),\n\t\t};\n\t}\n}\n\n/** A closed reason that proves the request stopped before inference dispatch. */\nexport class HcodeLocalRefusal extends Error {\n\treadonly reason: HcodeLocalReason;\n\tconstructor(reason: HcodeLocalReason) {\n\t\tsuper(formatHcodeLocalRefusal(reason));\n\t\tthis.reason = reason;\n\t}\n}\n\n/** Parse the closed request schema without exposing raw validation errors. */\nexport function parseHcodeRequestBody(body: string): HcodeMessagesRequest {\n\ttry {\n\t\treturn parseHcodeMessagesRequest(JSON.parse(body));\n\t} catch {\n\t\tthrow new HcodeLocalRefusal(\"envelope\");\n\t}\n}\n\n/** Captures one exact environment/model/reference/key and permits at most one account submission. */\nexport function createHcodeTransport(\n\taccount: HcodeAccountPort,\n\tenvironment: HcodeEnvironment,\n\texpected: HcodeAccountRef,\n\tmodel: Model<\"pi-messages\">,\n\tidempotencyKey: string,\n\tprojectedOmissions?: () => number,\n): DelegatedFetch {\n\tlet submitted = false;\n\treturn createDelegatedFetch(async (input, init = {}) => {\n\t\tconst controller = new AbortController();\n\t\tconst signal = init.signal ? AbortSignal.any([init.signal, controller.signal]) : controller.signal;\n\t\ttry {\n\t\t\tif (submitted) throw new HcodeTransportError();\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tif (expected.environmentId !== environment.id || !sameReference(account.status(environment.id), expected))\n\t\t\t\tthrow new HcodeLocalRefusal(\"account\");\n\t\t\tconst url = input instanceof Request ? input.url : String(input);\n\t\t\tif (\n\t\t\t\turl !== `${environment.inferenceBaseUrl}/messages` ||\n\t\t\t\tinit.method !== \"POST\" ||\n\t\t\t\ttypeof init.body !== \"string\" ||\n\t\t\t\t!/^[\\x20-\\x7e]{1,256}$/.test(idempotencyKey)\n\t\t\t)\n\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\");\n\t\t\ttry {\n\t\t\t\tassertHcodeRequest(url, init, environment);\n\t\t\t} catch {\n\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\");\n\t\t\t}\n\t\t\tconst rawBytes = Buffer.byteLength(init.body, \"utf8\");\n\t\t\tif (rawBytes > 12582912) throw new HcodeLocalRefusal(\"size\");\n\t\t\tconst request = parseHcodeRequestBody(init.body);\n\t\t\tawait validateCapabilities(request, model);\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tlet body = JSON.stringify(request);\n\t\t\tlet omitted = projectedOmissions?.() ?? 0;\n\t\t\tconst limit = model.inputLimits?.maxRequestBytes ?? 12582912;\n\t\t\tif (Math.max(rawBytes, Buffer.byteLength(body, \"utf8\")) > limit) {\n\t\t\t\t// Provider payload hooks run after projection and may reorder messages. Never evict by stale indices.\n\t\t\t\tif (projectedOmissions) throw new HcodeLocalRefusal(\"size\");\n\t\t\t\tconst active = new Set([\n\t\t\t\t\trequest.context.messages.findLastIndex(\n\t\t\t\t\t\t(message) => message.role === \"user\" || message.role === \"assistant\",\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t\tconst fitted = await fitHcodeRequestSize(model, request.context.messages, active, (messages) =>\n\t\t\t\t\tJSON.stringify({ ...request, context: { messages } }),\n\t\t\t\t);\n\t\t\t\tif (!fitted || Buffer.byteLength(fitted.body, \"utf8\") > limit) throw new HcodeLocalRefusal(\"size\");\n\t\t\t\tbody = fitted.body;\n\t\t\t\tomitted += fitted.omitted;\n\t\t\t\tawait validateCapabilities(parseHcodeRequestBody(body), model);\n\t\t\t}\n\t\t\tconst headers = new Headers({\n\t\t\t\taccept: \"text/event-stream\",\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"Idempotency-Key\": idempotencyKey,\n\t\t\t});\n\t\t\t// No await separates this fence from the account owner's own private refresh/generation fence.\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tif (submitted) throw new HcodeTransportError();\n\t\t\tif (!sameReference(account.status(environment.id), expected)) throw new HcodeLocalRefusal(\"account\");\n\t\t\tsubmitted = true;\n\t\t\tconst submission = account.authorizedFetch(expected, url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody,\n\t\t\t\theaders,\n\t\t\t\tsignal,\n\t\t\t\tredirect: \"error\",\n\t\t\t\tcredentials: \"omit\",\n\t\t\t\tcache: \"no-store\",\n\t\t\t});\n\t\t\tif (omitted) reportHcodeImageOmissions(omitted, model);\n\t\t\tconst response = await submission;\n\t\t\tif (!response.ok) {\n\t\t\t\tlet failure: HcodeInferenceError | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tfailure = parseHcodeInferenceError(\n\t\t\t\t\t\tawait readHcodeJson(\n\t\t\t\t\t\t\tnew Response(response.body, { headers: response.headers }),\n\t\t\t\t\t\t\t65536,\n\t\t\t\t\t\t\tAbortSignal.any([signal, AbortSignal.timeout(3000)]),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tif (!HCODE_ERROR_STATUS[failure.error.code].has(response.status)) failure = undefined;\n\t\t\t\t} catch {\n\t\t\t\t\t/* Malformed remote bodies never become diagnostics. */\n\t\t\t\t}\n\t\t\t\tconst retry = response.headers.get(\"retry-after\");\n\t\t\t\tconst retryAfter =\n\t\t\t\t\tretry && (/^\\d{1,10}$/.test(retry) || /^\\w{3}, \\d{2} \\w{3} \\d{4} \\d{2}:\\d{2}:\\d{2} GMT$/.test(retry))\n\t\t\t\t\t\t? retry\n\t\t\t\t\t\t: undefined;\n\t\t\t\t// Only Forge's closed reason values for this refusal code are kept; anything else is dropped.\n\t\t\t\tconst reasonHeader = failure\n\t\t\t\t\t? (HCODE_REFUSAL_REASON_HEADERS as Record<string, readonly [string, readonly string[]]>)[\n\t\t\t\t\t\t\tfailure.error.code\n\t\t\t\t\t\t]\n\t\t\t\t\t: undefined;\n\t\t\t\tconst reason = reasonHeader ? response.headers.get(reasonHeader[0]) : null;\n\t\t\t\tthrow new HcodeTransportError(\n\t\t\t\t\tfailure,\n\t\t\t\t\tfailure ? response.status : undefined,\n\t\t\t\t\tfailure ? retryAfter : undefined,\n\t\t\t\t\treason && reasonHeader?.[1].includes(reason) ? reason : undefined,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tresponse.headers.get(\"content-type\")?.split(\";\")[0]?.trim().toLowerCase() !== \"text/event-stream\" ||\n\t\t\t\t!response.body\n\t\t\t) {\n\t\t\t\tawait response.body?.cancel().catch(() => {});\n\t\t\t\tthrow new HcodeTransportError();\n\t\t\t}\n\t\t\treturn new Response(validatedBody(response.body, controller, signal), {\n\t\t\t\theaders: { \"content-type\": \"text/event-stream\" },\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tcontroller.abort();\n\t\t\tthrow error instanceof HcodeTransportError || error instanceof HcodeLocalRefusal\n\t\t\t\t? error\n\t\t\t\t: new HcodeTransportError();\n\t\t}\n\t});\n}\n\nasync function validateCapabilities(request: HcodeMessagesRequest, model: Model<\"pi-messages\">): Promise<void> {\n\tconst options = request.options;\n\tif (request.model !== model.id) throw new HcodeLocalRefusal(\"model\");\n\tif (!model.thinkingLevelMap?.[options?.reasoning ?? \"off\"]) throw new HcodeLocalRefusal(\"reasoning\");\n\tif ((options?.maxTokens ?? Math.min(4096, model.maxTokens)) > model.maxTokens) throw new HcodeLocalRefusal(\"output\");\n\tif (options?.cacheRetention !== \"none\") throw new HcodeLocalRefusal(\"cache\");\n\tfor (const message of request.context.messages) {\n\t\tif (\n\t\t\t!model.tools &&\n\t\t\t((message.role === \"system\" && (message.toolsAdded?.length || message.toolsRemoved?.length)) ||\n\t\t\t\tmessage.role === \"toolResult\" ||\n\t\t\t\toptions?.toolChoice)\n\t\t)\n\t\t\tthrow new HcodeLocalRefusal(\"tools\");\n\t\tif (message.role === \"system\" && message.toolsAdded?.some((tool) => tool.constrainedSampling))\n\t\t\tthrow new HcodeLocalRefusal(\"strictTools\");\n\t\tif (typeof message.content === \"string\") continue;\n\t\tfor (const block of message.content)\n\t\t\tif (block.type === \"thinking\" && !model.reasoning) throw new HcodeLocalRefusal(\"reasoning\");\n\t}\n\ttry {\n\t\tawait validateHcodeImages(model, request.context.messages);\n\t} catch {\n\t\tthrow new HcodeLocalRefusal(\"images\");\n\t}\n}\n\nconst MAX_QUEUE = 1048576;\nfunction validatedBody(\n\tbody: ReadableStream<Uint8Array>,\n\tcontroller: AbortController,\n\tsignal: AbortSignal,\n): ReadableStream<Uint8Array> {\n\tconst events = validatedEvents(body, signal);\n\tconst abort = () => {\n\t\tvoid body.cancel().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", abort, { once: true });\n\tlet pending: Uint8Array | undefined;\n\tlet offset = 0;\n\tlet cancelled = false;\n\treturn new ReadableStream<Uint8Array>(\n\t\t{\n\t\t\tasync pull(output) {\n\t\t\t\ttry {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\tif (!pending) {\n\t\t\t\t\t\tconst next = await events.next();\n\t\t\t\t\t\tif (next.done) {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t\t\t\toutput.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpending = next.value;\n\t\t\t\t\t\toffset = 0;\n\t\t\t\t\t}\n\t\t\t\t\t// Bound each downstream chunk without copying its frame.\n\t\t\t\t\tconst end = Math.min(pending.length, offset + MAX_QUEUE);\n\t\t\t\t\toutput.enqueue(pending.subarray(offset, end));\n\t\t\t\t\toffset = end;\n\t\t\t\t\tif (offset === pending.length) pending = undefined;\n\t\t\t\t} catch {\n\t\t\t\t\tcontroller.abort();\n\t\t\t\t\tif (!cancelled) output.error(new HcodeTransportError());\n\t\t\t\t\tawait events.return(undefined).catch(() => {});\n\t\t\t\t\tawait body.cancel().catch(() => {});\n\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync cancel() {\n\t\t\t\tcancelled = true;\n\t\t\t\tcontroller.abort();\n\t\t\t\tawait events.return(undefined).catch(() => {});\n\t\t\t\tawait body.cancel().catch(() => {});\n\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t},\n\t\t},\n\t\t{ highWaterMark: 0 },\n\t);\n}\n\nasync function* validatedEvents(body: ReadableStream<Uint8Array>, signal: AbortSignal): AsyncGenerator<Uint8Array> {\n\tconst reader = body.getReader();\n\tconst validator = createHcodePiEventValidator();\n\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\tconst encoder = new TextEncoder();\n\tlet frame = new Uint8Array(4096);\n\tlet size = 0;\n\tlet terminal: Uint8Array | undefined;\n\tconst argumentsText = new Map<number, string>();\n\tconst abort = () => {\n\t\tvoid reader.cancel().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", abort, { once: true });\n\ttry {\n\t\tfor (;;) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst next = await reader.read();\n\t\t\tif (next.done) break;\n\t\t\t// Scan bytes before decoding/parsing, including chunks containing many frames.\n\t\t\tfor (const byte of next.value) {\n\t\t\t\tif (size === MAX_PI_EVENT_FRAME_BYTES) throw new HcodeTransportError();\n\t\t\t\tif (size === frame.length) {\n\t\t\t\t\tconst grown = new Uint8Array(Math.min(MAX_PI_EVENT_FRAME_BYTES, frame.length * 2));\n\t\t\t\t\tgrown.set(frame);\n\t\t\t\t\tframe = grown;\n\t\t\t\t}\n\t\t\t\tframe[size++] = byte;\n\t\t\t\tif (size < 2 || byte !== 10 || frame[size - 2] !== 10) continue;\n\t\t\t\tconst raw = decoder.decode(frame.subarray(0, size - 2));\n\t\t\t\tif (!raw.startsWith(\"data: \") || raw.includes(\"\\n\")) throw new HcodeTransportError();\n\t\t\t\tconst input: unknown = JSON.parse(raw.slice(6));\n\t\t\t\tconst event = validator.parse(input);\n\t\t\t\tif (event.type === \"toolcall_start\") argumentsText.set(event.contentIndex, \"\");\n\t\t\t\tif (event.type === \"toolcall_delta\")\n\t\t\t\t\targumentsText.set(event.contentIndex, argumentsText.get(event.contentIndex)! + event.delta);\n\t\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\t\tconst text = argumentsText.get(event.contentIndex)!;\n\t\t\t\t\tif (text) {\n\t\t\t\t\t\tconst args: unknown = JSON.parse(text);\n\t\t\t\t\t\tif (!args || typeof args !== \"object\" || Array.isArray(args)) throw new HcodeTransportError();\n\t\t\t\t\t}\n\t\t\t\t\targumentsText.delete(event.contentIndex);\n\t\t\t\t}\n\t\t\t\t// Reuse the input bytes (minus BOM) only when Pi would see exactly the validated event.\n\t\t\t\tconst bom = frame[0] === 0xef && frame[1] === 0xbb && frame[2] === 0xbf ? 3 : 0;\n\t\t\t\tconst validated = isDeepStrictEqual(input, event)\n\t\t\t\t\t? frame.subarray(bom, size)\n\t\t\t\t\t: encoder.encode(`data: ${JSON.stringify(event)}\\n\\n`);\n\t\t\t\tif (validated.length > MAX_PI_EVENT_FRAME_BYTES) throw new HcodeTransportError();\n\t\t\t\tif (event.type === \"done\" || event.type === \"error\") terminal = validated;\n\t\t\t\telse yield validated;\n\t\t\t\t// Delivered views keep their storage; later input must never overwrite it.\n\t\t\t\tframe = new Uint8Array(4096);\n\t\t\t\tsize = 0;\n\t\t\t}\n\t\t}\n\t\tsignal.throwIfAborted();\n\t\tif (size) throw new HcodeTransportError();\n\t\tvalidator.finish();\n\t\t// Withhold terminal success until EOF proves there is exactly one terminal and no trailing data.\n\t\tif (terminal) yield terminal;\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", abort);\n\t\tawait reader.cancel().catch(() => {});\n\t\treader.releaseLock();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/humain/hcode/transport.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAoD,MAAM,uBAAuB,CAAC;AAE/G,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,2BAA2B,EAC3B,kBAAkB,EAGlB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,yBAAyB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClG,OAAO,EACN,uBAAuB,EACvB,4BAA4B,GAG5B,MAAM,cAAc,CAAC;AAGtB,mGAAmG;AACnG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACpC,OAAO,CAAkC;IACzC,MAAM,CAAqB;IAC3B,UAAU,CAAqB;IAC/B,MAAM,CAAqB;IACpC,YAAY,OAA6B,EAAE,MAAe,EAAE,UAAmB,EAAE,MAAe;QAC/F,KAAK,CAAC,+DAA+D,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC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EAAE,IAAI,CAAC;oBAC3B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBACxD,IAAI,SAAS,CAAC,MAAM,GAAG,wBAAwB;oBAAE,MAAM,IAAI,mBAAmB,EAAE,CAAC;gBACjF,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;oBAAE,QAAQ,GAAG,SAAS,CAAC;;oBACrE,MAAM,SAAS,CAAC;gBACrB,2EAA2E;gBAC3E,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;gBAC7B,IAAI,GAAG,CAAC,CAAC;YACV,CAAC;QACF,CAAC;QACD,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,IAAI,IAAI;YAAE,MAAM,IAAI,mBAAmB,EAAE,CAAC;QAC1C,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,iGAAiG;QACjG,IAAI,QAAQ;YAAE,MAAM,QAAQ,CAAC;IAC9B,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3C,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["// One invocation's final-send authority and bounded, validated managed response boundary.\nimport { isDeepStrictEqual } from \"node:util\";\n\nimport { createDelegatedFetch, type DelegatedFetch, type JsonObject, type Model } from \"@earendil-works/pi-ai\";\n\nimport { sameReference } from \"./account-store.ts\";\nimport {\n\tcreateHcodePiEventValidator,\n\tHCODE_ERROR_STATUS,\n\ttype HcodeInferenceError,\n\ttype HcodeMessagesRequest,\n\tHcodeRequestSchemaError,\n\tMAX_PI_EVENT_FRAME_BYTES,\n\tparseHcodeInferenceError,\n\tparseHcodeMessagesRequest,\n} from \"./contracts.ts\";\nimport type { HcodeEnvironment } from \"./environment.ts\";\nimport { assertHcodeRequest, readHcodeJson } from \"./http.ts\";\nimport { fitHcodeRequestSize, reportHcodeImageOmissions, validateHcodeImages } from \"./images.ts\";\nimport {\n\tformatHcodeLocalRefusal,\n\tHCODE_REFUSAL_REASON_HEADERS,\n\ttype HcodeLocalDetail,\n\ttype HcodeLocalReason,\n} from \"./notices.ts\";\nimport type { HcodeAccountPort, HcodeAccountRef } from \"./ports.ts\";\n\n/** A fixed failure, optionally carrying only schema-validated service refusal facts for the UI. */\nexport class HcodeTransportError extends Error {\n\treadonly failure: HcodeInferenceError | undefined;\n\treadonly status: number | undefined;\n\treadonly retryAfter: string | undefined;\n\treadonly reason: string | undefined;\n\tconstructor(failure?: HcodeInferenceError, status?: number, retryAfter?: string, reason?: string) {\n\t\tsuper(\"HUMAIN Code request unavailable. Do not automatically resend.\");\n\t\tthis.name = \"HcodeTransportError\";\n\t\tthis.failure = failure;\n\t\tthis.status = status;\n\t\tthis.retryAfter = retryAfter;\n\t\tthis.reason = reason;\n\t}\n\t/** Returns only validated JSON facts; never remote diagnostics, headers or body text. */\n\tdiagnostics(): JsonObject {\n\t\t// The closed X1 error parser guarantees plain JSON, including the allowance snapshot.\n\t\tconst safe: JsonObject = this.failure ? JSON.parse(JSON.stringify(this.failure)) : {};\n\t\treturn {\n\t\t\t...safe,\n\t\t\t...(this.status === undefined ? {} : { status: this.status }),\n\t\t\t...(this.retryAfter ? { retryAfter: this.retryAfter } : {}),\n\t\t\t...(this.reason ? { reason: this.reason } : {}),\n\t\t};\n\t}\n}\n\n/** A closed reason that proves the request stopped before inference dispatch. */\nexport class HcodeLocalRefusal extends Error {\n\treadonly reason: HcodeLocalReason;\n\treadonly detail: HcodeLocalDetail | undefined;\n\tconstructor(reason: HcodeLocalReason, detail?: HcodeLocalDetail) {\n\t\tsuper(formatHcodeLocalRefusal(reason, detail));\n\t\tthis.reason = reason;\n\t\tthis.detail = detail;\n\t}\n}\n\n/** Parse the closed request schema without exposing raw validation errors. */\nexport function parseHcodeRequestBody(body: string): HcodeMessagesRequest {\n\ttry {\n\t\tconst value: unknown = JSON.parse(body);\n\t\t// Payload hooks are an untrusted boundary; inspect only the fixed message-array path.\n\t\tif (value && typeof value === \"object\" && \"context\" in value) {\n\t\t\tconst context = value.context;\n\t\t\tif (\n\t\t\t\tcontext &&\n\t\t\t\ttypeof context === \"object\" &&\n\t\t\t\t\"messages\" in context &&\n\t\t\t\tArray.isArray(context.messages) &&\n\t\t\t\tcontext.messages.length > 512\n\t\t\t)\n\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\", \"messageLimit\");\n\t\t}\n\t\treturn parseHcodeMessagesRequest(value);\n\t} catch (error) {\n\t\tif (error instanceof HcodeLocalRefusal) throw error;\n\t\tthrow new HcodeLocalRefusal(\"envelope\", error instanceof HcodeRequestSchemaError ? error.detail : \"schema\");\n\t}\n}\n\n/** Captures one exact environment/model/reference/key and permits at most one account submission. */\nexport function createHcodeTransport(\n\taccount: HcodeAccountPort,\n\tenvironment: HcodeEnvironment,\n\texpected: HcodeAccountRef,\n\tmodel: Model<\"pi-messages\">,\n\tidempotencyKey: string,\n\tprojectedOmissions?: () => number,\n): DelegatedFetch {\n\tlet submitted = false;\n\treturn createDelegatedFetch(async (input, init = {}) => {\n\t\tconst controller = new AbortController();\n\t\tconst signal = init.signal ? AbortSignal.any([init.signal, controller.signal]) : controller.signal;\n\t\ttry {\n\t\t\tif (submitted) throw new HcodeTransportError();\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tif (expected.environmentId !== environment.id || !sameReference(account.status(environment.id), expected))\n\t\t\t\tthrow new HcodeLocalRefusal(\"account\");\n\t\t\tconst url = input instanceof Request ? input.url : String(input);\n\t\t\tif (\n\t\t\t\turl !== `${environment.inferenceBaseUrl}/messages` ||\n\t\t\t\tinit.method !== \"POST\" ||\n\t\t\t\ttypeof init.body !== \"string\" ||\n\t\t\t\t!/^[\\x20-\\x7e]{1,256}$/.test(idempotencyKey)\n\t\t\t)\n\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\");\n\t\t\ttry {\n\t\t\t\tassertHcodeRequest(url, init, environment);\n\t\t\t} catch {\n\t\t\t\tthrow new HcodeLocalRefusal(\"envelope\");\n\t\t\t}\n\t\t\tconst rawBytes = Buffer.byteLength(init.body, \"utf8\");\n\t\t\tif (rawBytes > 12582912) throw new HcodeLocalRefusal(\"size\");\n\t\t\tconst request = parseHcodeRequestBody(init.body);\n\t\t\tawait validateCapabilities(request, model);\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tlet body = JSON.stringify(request);\n\t\t\tlet omitted = projectedOmissions?.() ?? 0;\n\t\t\tconst limit = model.inputLimits?.maxRequestBytes ?? 12582912;\n\t\t\tif (Math.max(rawBytes, Buffer.byteLength(body, \"utf8\")) > limit) {\n\t\t\t\t// Provider payload hooks run after projection and may reorder messages. Never evict by stale indices.\n\t\t\t\tif (projectedOmissions) throw new HcodeLocalRefusal(\"size\");\n\t\t\t\tconst active = new Set([\n\t\t\t\t\trequest.context.messages.findLastIndex(\n\t\t\t\t\t\t(message) => message.role === \"user\" || message.role === \"assistant\",\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t\tconst fitted = await fitHcodeRequestSize(model, request.context.messages, active, (messages) =>\n\t\t\t\t\tJSON.stringify({ ...request, context: { messages } }),\n\t\t\t\t);\n\t\t\t\tif (!fitted || Buffer.byteLength(fitted.body, \"utf8\") > limit) throw new HcodeLocalRefusal(\"size\");\n\t\t\t\tbody = fitted.body;\n\t\t\t\tomitted += fitted.omitted;\n\t\t\t\tawait validateCapabilities(parseHcodeRequestBody(body), model);\n\t\t\t}\n\t\t\tconst headers = new Headers({\n\t\t\t\taccept: \"text/event-stream\",\n\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\"Idempotency-Key\": idempotencyKey,\n\t\t\t});\n\t\t\t// No await separates this fence from the account owner's own private refresh/generation fence.\n\t\t\tif (signal.aborted) throw new HcodeLocalRefusal(\"cancelled\");\n\t\t\tif (submitted) throw new HcodeTransportError();\n\t\t\tif (!sameReference(account.status(environment.id), expected)) throw new HcodeLocalRefusal(\"account\");\n\t\t\tsubmitted = true;\n\t\t\tconst submission = account.authorizedFetch(expected, url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\tbody,\n\t\t\t\theaders,\n\t\t\t\tsignal,\n\t\t\t\tredirect: \"error\",\n\t\t\t\tcredentials: \"omit\",\n\t\t\t\tcache: \"no-store\",\n\t\t\t});\n\t\t\tif (omitted) reportHcodeImageOmissions(omitted, model);\n\t\t\tconst response = await submission;\n\t\t\tif (!response.ok) {\n\t\t\t\tlet failure: HcodeInferenceError | undefined;\n\t\t\t\ttry {\n\t\t\t\t\tfailure = parseHcodeInferenceError(\n\t\t\t\t\t\tawait readHcodeJson(\n\t\t\t\t\t\t\tnew Response(response.body, { headers: response.headers }),\n\t\t\t\t\t\t\t65536,\n\t\t\t\t\t\t\tAbortSignal.any([signal, AbortSignal.timeout(3000)]),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tif (!HCODE_ERROR_STATUS[failure.error.code].has(response.status)) failure = undefined;\n\t\t\t\t} catch {\n\t\t\t\t\t/* Malformed remote bodies never become diagnostics. */\n\t\t\t\t}\n\t\t\t\tconst retry = response.headers.get(\"retry-after\");\n\t\t\t\tconst retryAfter =\n\t\t\t\t\tretry && (/^\\d{1,10}$/.test(retry) || /^\\w{3}, \\d{2} \\w{3} \\d{4} \\d{2}:\\d{2}:\\d{2} GMT$/.test(retry))\n\t\t\t\t\t\t? retry\n\t\t\t\t\t\t: undefined;\n\t\t\t\t// Only Forge's closed reason values for this refusal code are kept; anything else is dropped.\n\t\t\t\tconst reasonHeader = failure\n\t\t\t\t\t? (HCODE_REFUSAL_REASON_HEADERS as Record<string, readonly [string, readonly string[]]>)[\n\t\t\t\t\t\t\tfailure.error.code\n\t\t\t\t\t\t]\n\t\t\t\t\t: undefined;\n\t\t\t\tconst reason = reasonHeader ? response.headers.get(reasonHeader[0]) : null;\n\t\t\t\tthrow new HcodeTransportError(\n\t\t\t\t\tfailure,\n\t\t\t\t\tfailure ? response.status : undefined,\n\t\t\t\t\tfailure ? retryAfter : undefined,\n\t\t\t\t\treason && reasonHeader?.[1].includes(reason) ? reason : undefined,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tresponse.headers.get(\"content-type\")?.split(\";\")[0]?.trim().toLowerCase() !== \"text/event-stream\" ||\n\t\t\t\t!response.body\n\t\t\t) {\n\t\t\t\tawait response.body?.cancel().catch(() => {});\n\t\t\t\tthrow new HcodeTransportError();\n\t\t\t}\n\t\t\treturn new Response(validatedBody(response.body, controller, signal), {\n\t\t\t\theaders: { \"content-type\": \"text/event-stream\" },\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tcontroller.abort();\n\t\t\tthrow error instanceof HcodeTransportError || error instanceof HcodeLocalRefusal\n\t\t\t\t? error\n\t\t\t\t: new HcodeTransportError();\n\t\t}\n\t});\n}\n\nasync function validateCapabilities(request: HcodeMessagesRequest, model: Model<\"pi-messages\">): Promise<void> {\n\tconst options = request.options;\n\tif (request.model !== model.id) throw new HcodeLocalRefusal(\"model\");\n\tif (!model.thinkingLevelMap?.[options?.reasoning ?? \"off\"]) throw new HcodeLocalRefusal(\"reasoning\");\n\tif ((options?.maxTokens ?? Math.min(4096, model.maxTokens)) > model.maxTokens) throw new HcodeLocalRefusal(\"output\");\n\tif (options?.cacheRetention !== \"none\") throw new HcodeLocalRefusal(\"cache\");\n\tfor (const message of request.context.messages) {\n\t\tif (\n\t\t\t!model.tools &&\n\t\t\t((message.role === \"system\" && (message.toolsAdded?.length || message.toolsRemoved?.length)) ||\n\t\t\t\tmessage.role === \"toolResult\" ||\n\t\t\t\toptions?.toolChoice)\n\t\t)\n\t\t\tthrow new HcodeLocalRefusal(\"tools\");\n\t\tif (message.role === \"system\" && message.toolsAdded?.some((tool) => tool.constrainedSampling))\n\t\t\tthrow new HcodeLocalRefusal(\"strictTools\");\n\t\tif (typeof message.content === \"string\") continue;\n\t\tfor (const block of message.content)\n\t\t\tif (block.type === \"thinking\" && !model.reasoning) throw new HcodeLocalRefusal(\"reasoning\");\n\t}\n\ttry {\n\t\tawait validateHcodeImages(model, request.context.messages);\n\t} catch {\n\t\tthrow new HcodeLocalRefusal(\"images\");\n\t}\n}\n\nconst MAX_QUEUE = 1048576;\nfunction validatedBody(\n\tbody: ReadableStream<Uint8Array>,\n\tcontroller: AbortController,\n\tsignal: AbortSignal,\n): ReadableStream<Uint8Array> {\n\tconst events = validatedEvents(body, signal);\n\tconst abort = () => {\n\t\tvoid body.cancel().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", abort, { once: true });\n\tlet pending: Uint8Array | undefined;\n\tlet offset = 0;\n\tlet cancelled = false;\n\treturn new ReadableStream<Uint8Array>(\n\t\t{\n\t\t\tasync pull(output) {\n\t\t\t\ttry {\n\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\tif (!pending) {\n\t\t\t\t\t\tconst next = await events.next();\n\t\t\t\t\t\tif (next.done) {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t\t\t\toutput.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpending = next.value;\n\t\t\t\t\t\toffset = 0;\n\t\t\t\t\t}\n\t\t\t\t\t// Bound each downstream chunk without copying its frame.\n\t\t\t\t\tconst end = Math.min(pending.length, offset + MAX_QUEUE);\n\t\t\t\t\toutput.enqueue(pending.subarray(offset, end));\n\t\t\t\t\toffset = end;\n\t\t\t\t\tif (offset === pending.length) pending = undefined;\n\t\t\t\t} catch {\n\t\t\t\t\tcontroller.abort();\n\t\t\t\t\tif (!cancelled) output.error(new HcodeTransportError());\n\t\t\t\t\tawait events.return(undefined).catch(() => {});\n\t\t\t\t\tawait body.cancel().catch(() => {});\n\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t}\n\t\t\t},\n\t\t\tasync cancel() {\n\t\t\t\tcancelled = true;\n\t\t\t\tcontroller.abort();\n\t\t\t\tawait events.return(undefined).catch(() => {});\n\t\t\t\tawait body.cancel().catch(() => {});\n\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t},\n\t\t},\n\t\t{ highWaterMark: 0 },\n\t);\n}\n\nasync function* validatedEvents(body: ReadableStream<Uint8Array>, signal: AbortSignal): AsyncGenerator<Uint8Array> {\n\tconst reader = body.getReader();\n\tconst validator = createHcodePiEventValidator();\n\tconst decoder = new TextDecoder(\"utf-8\", { fatal: true });\n\tconst encoder = new TextEncoder();\n\tlet frame = new Uint8Array(4096);\n\tlet size = 0;\n\tlet terminal: Uint8Array | undefined;\n\tconst argumentsText = new Map<number, string>();\n\tconst abort = () => {\n\t\tvoid reader.cancel().catch(() => {});\n\t};\n\tsignal.addEventListener(\"abort\", abort, { once: true });\n\ttry {\n\t\tfor (;;) {\n\t\t\tsignal.throwIfAborted();\n\t\t\tconst next = await reader.read();\n\t\t\tif (next.done) break;\n\t\t\t// Scan bytes before decoding/parsing, including chunks containing many frames.\n\t\t\tfor (const byte of next.value) {\n\t\t\t\tif (size === MAX_PI_EVENT_FRAME_BYTES) throw new HcodeTransportError();\n\t\t\t\tif (size === frame.length) {\n\t\t\t\t\tconst grown = new Uint8Array(Math.min(MAX_PI_EVENT_FRAME_BYTES, frame.length * 2));\n\t\t\t\t\tgrown.set(frame);\n\t\t\t\t\tframe = grown;\n\t\t\t\t}\n\t\t\t\tframe[size++] = byte;\n\t\t\t\tif (size < 2 || byte !== 10 || frame[size - 2] !== 10) continue;\n\t\t\t\tconst raw = decoder.decode(frame.subarray(0, size - 2));\n\t\t\t\tif (!raw.startsWith(\"data: \") || raw.includes(\"\\n\")) throw new HcodeTransportError();\n\t\t\t\tconst input: unknown = JSON.parse(raw.slice(6));\n\t\t\t\tconst event = validator.parse(input);\n\t\t\t\tif (event.type === \"toolcall_start\") argumentsText.set(event.contentIndex, \"\");\n\t\t\t\tif (event.type === \"toolcall_delta\")\n\t\t\t\t\targumentsText.set(event.contentIndex, argumentsText.get(event.contentIndex)! + event.delta);\n\t\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\t\tconst text = argumentsText.get(event.contentIndex)!;\n\t\t\t\t\tif (text) {\n\t\t\t\t\t\tconst args: unknown = JSON.parse(text);\n\t\t\t\t\t\tif (!args || typeof args !== \"object\" || Array.isArray(args)) throw new HcodeTransportError();\n\t\t\t\t\t}\n\t\t\t\t\targumentsText.delete(event.contentIndex);\n\t\t\t\t}\n\t\t\t\t// Reuse the input bytes (minus BOM) only when Pi would see exactly the validated event.\n\t\t\t\tconst bom = frame[0] === 0xef && frame[1] === 0xbb && frame[2] === 0xbf ? 3 : 0;\n\t\t\t\tconst validated = isDeepStrictEqual(input, event)\n\t\t\t\t\t? frame.subarray(bom, size)\n\t\t\t\t\t: encoder.encode(`data: ${JSON.stringify(event)}\\n\\n`);\n\t\t\t\tif (validated.length > MAX_PI_EVENT_FRAME_BYTES) throw new HcodeTransportError();\n\t\t\t\tif (event.type === \"done\" || event.type === \"error\") terminal = validated;\n\t\t\t\telse yield validated;\n\t\t\t\t// Delivered views keep their storage; later input must never overwrite it.\n\t\t\t\tframe = new Uint8Array(4096);\n\t\t\t\tsize = 0;\n\t\t\t}\n\t\t}\n\t\tsignal.throwIfAborted();\n\t\tif (size) throw new HcodeTransportError();\n\t\tvalidator.finish();\n\t\t// Withhold terminal success until EOF proves there is exactly one terminal and no trailing data.\n\t\tif (terminal) yield terminal;\n\t} finally {\n\t\tsignal.removeEventListener(\"abort\", abort);\n\t\tawait reader.cancel().catch(() => {});\n\t\treader.releaseLock();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { HcodeAccountPort, HcodeAccountRef } from "../hcode/ports.ts";
|
|
2
|
+
import { type WatchAttachment, type WatchProjection } from "./host-watch.ts";
|
|
3
|
+
import type { LiveRoute, PrincipalKey } from "./protocol.ts";
|
|
4
|
+
import type { SecureChannel } from "./secure-channel.ts";
|
|
5
|
+
/** Trusted ingress supplies a verified, claimed candidate, never a decoded browser object. */
|
|
6
|
+
export interface PendingWatchCandidate {
|
|
7
|
+
readonly pendingId: string;
|
|
8
|
+
readonly offerId: string;
|
|
9
|
+
readonly route: Readonly<LiveRoute>;
|
|
10
|
+
readonly principal: Readonly<PrincipalKey>;
|
|
11
|
+
readonly hostGeneration: string;
|
|
12
|
+
readonly browserGeneration: string;
|
|
13
|
+
readonly installKey: string;
|
|
14
|
+
readonly deviceKey: string;
|
|
15
|
+
readonly transcript: string;
|
|
16
|
+
readonly credential: string | null;
|
|
17
|
+
readonly mode: "uv" | "short";
|
|
18
|
+
readonly expiresAt: number;
|
|
19
|
+
}
|
|
20
|
+
type TerminalWatchConsent = (candidate: PendingWatchCandidate, signal: AbortSignal) => Promise<"allow" | "deny">;
|
|
21
|
+
interface CommittedPairing {
|
|
22
|
+
readonly candidate: PendingWatchCandidate;
|
|
23
|
+
readonly pairingId: string;
|
|
24
|
+
readonly pairedAt: number;
|
|
25
|
+
}
|
|
26
|
+
/** Only the future trusted proof/lease adapter may construct this input. Times use the broker clock. */
|
|
27
|
+
export interface VerifiedPairing extends CommittedPairing {
|
|
28
|
+
readonly verifiedAt: number;
|
|
29
|
+
readonly leaseUntil: number;
|
|
30
|
+
readonly reconnect: boolean;
|
|
31
|
+
readonly durable?: CommittedPairing;
|
|
32
|
+
}
|
|
33
|
+
/** Only the trusted lease adapter may apply fresh, ordered grants for this attachment. */
|
|
34
|
+
interface LeasedWatchAttachment extends WatchAttachment {
|
|
35
|
+
renewLease(route: LiveRoute, pairingId: string, leaseUntil: number): boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface WatchAuthority {
|
|
38
|
+
commit(candidate: PendingWatchCandidate, signal: AbortSignal): Promise<CommittedPairing | undefined>;
|
|
39
|
+
reconcile(installScopedDenied: readonly string[]): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface WatchDenyScope {
|
|
42
|
+
installId: string;
|
|
43
|
+
principal: PrincipalKey;
|
|
44
|
+
}
|
|
45
|
+
export declare const MAX_WATCH_DENIES = 4096;
|
|
46
|
+
/** One exclusive store lifetime per broker. An unclean exit must leave restart fenced. */
|
|
47
|
+
export interface WatchDenyStore {
|
|
48
|
+
read(scope: WatchDenyScope): Promise<readonly string[]>;
|
|
49
|
+
save(ids: readonly string[]): Promise<void>;
|
|
50
|
+
/** Release only after closing delivery and draining successful writes. */
|
|
51
|
+
release(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
interface BrokerOptions extends WatchDenyScope {
|
|
54
|
+
store: WatchDenyStore;
|
|
55
|
+
authority: WatchAuthority;
|
|
56
|
+
account: Pick<HcodeAccountPort, "status" | "subscribe">;
|
|
57
|
+
reference: Readonly<HcodeAccountRef>;
|
|
58
|
+
/** Verified Remote authority generation, distinct from the CLI's local account generation. */
|
|
59
|
+
hostGeneration: string;
|
|
60
|
+
/** Monotonic clock on the same timeline as the authority adapter's converted deadlines. */
|
|
61
|
+
now?: () => number;
|
|
62
|
+
}
|
|
63
|
+
/** Install-local watch fences. No socket, user input, agent or provider capability is accepted here. */
|
|
64
|
+
export declare class WatchBroker {
|
|
65
|
+
#private;
|
|
66
|
+
constructor(options: BrokerOptions);
|
|
67
|
+
start(): Promise<void>;
|
|
68
|
+
/** Bind the share to the owning terminal's notice, consent and session lifetime. */
|
|
69
|
+
shareSession(source: WatchProjection, notify: (pairingId: string, reconnect: boolean) => void, lifetime: AbortSignal, confirm: TerminalWatchConsent, onUnshare?: () => void): string;
|
|
70
|
+
routeFor(sessionId: string): LiveRoute;
|
|
71
|
+
unshare(sessionId: string): void;
|
|
72
|
+
/** Trusted ingress requests consent from the share's terminal; it cannot supply the decision callback. */
|
|
73
|
+
confirmPairing(candidate: PendingWatchCandidate, setupSignal: AbortSignal): Promise<boolean>;
|
|
74
|
+
attachWatch(route: LiveRoute, peer: VerifiedPairing, channel: SecureChannel): LeasedWatchAttachment | undefined;
|
|
75
|
+
revokePairing(id: string): Promise<void>;
|
|
76
|
+
/** Fence immediately, then release the restart guard only if local persistence succeeded. */
|
|
77
|
+
shutdown(): Promise<void>;
|
|
78
|
+
close(): void;
|
|
79
|
+
}
|
|
80
|
+
/** A live broker is pinned to one account generation; later login needs a new broker and trust reconciliation. */
|
|
81
|
+
export declare function bindWatchAccount(broker: WatchBroker, account: Pick<HcodeAccountPort, "status" | "subscribe">, reference: HcodeAccountRef): () => void;
|
|
82
|
+
export declare function opaqueId(id: unknown): id is string;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../../src/humain/remote/broker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAe,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAOzD,8FAA8F;AAC9F,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC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