@openllmsh/sdk 0.0.0-stage → 2.10.12-alpha.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/ARCHITECTURE.md +43 -0
- package/LICENSE +202 -0
- package/README.md +142 -2
- package/assets/openllm-light.svg +18 -0
- package/assets/openllm.svg +18 -0
- package/client/chat.ts +140 -0
- package/client/devices.ts +269 -0
- package/client/http.ts +72 -0
- package/client/index.ts +129 -0
- package/client/relay-mux.ts +547 -0
- package/client/types.ts +51 -0
- package/client/vault.ts +239 -0
- package/connect/chat.ts +58 -0
- package/connect/client.ts +240 -0
- package/connect/config.ts +47 -0
- package/connect/errors.ts +121 -0
- package/connect/index.ts +23 -0
- package/connect/oauth.ts +265 -0
- package/connect/routes.ts +234 -0
- package/connect/store.ts +107 -0
- package/mcp/handle.ts +24 -0
- package/mcp/index.ts +76 -0
- package/mcp/server.ts +319 -0
- package/mcp/tools/marketplace.ts +439 -0
- package/mcp/tools/memory-client.ts +297 -0
- package/mcp/tools/memory-config.ts +32 -0
- package/mcp/tools/memory.ts +369 -0
- package/mcp/tools/model-priority.ts +88 -0
- package/mcp/tools/openllm.ts +883 -0
- package/mcp/types.ts +28 -0
- package/openapi/call.ts +90 -0
- package/openapi/index.ts +8 -0
- package/openapi/openapi.json +80213 -0
- package/openapi/operations.ts +2075 -0
- package/package.json +39 -4
- package/protocol/CONTRIBUTING.md +21 -0
- package/protocol/README.md +134 -0
- package/protocol/access.ts +186 -0
- package/protocol/agent-prompt-text.ts +32 -0
- package/protocol/agent.ts +991 -0
- package/protocol/api-key-syntax.ts +105 -0
- package/protocol/assets/openllm-light.svg +18 -0
- package/protocol/assets/openllm.svg +18 -0
- package/protocol/audio.ts +29 -0
- package/protocol/auth.ts +142 -0
- package/protocol/changelog.ts +155 -0
- package/protocol/chat.ts +458 -0
- package/protocol/client-registry.ts +356 -0
- package/protocol/config.ts +345 -0
- package/protocol/control-channel.ts +115 -0
- package/protocol/cooldown-reason.ts +78 -0
- package/protocol/cost.ts +10 -0
- package/protocol/daemon-port.ts +31 -0
- package/protocol/daemon.ts +1524 -0
- package/protocol/default-chains.ts +66 -0
- package/protocol/device-state.ts +85 -0
- package/protocol/doctor-report-local.ts +443 -0
- package/protocol/doctor-report-policy.ts +119 -0
- package/protocol/doctor-report.ts +947 -0
- package/protocol/errors.ts +14 -0
- package/protocol/execution-selection.ts +141 -0
- package/protocol/hop-grant.ts +33 -0
- package/protocol/image-edit-parse.ts +263 -0
- package/protocol/images.ts +298 -0
- package/protocol/index.ts +74 -0
- package/protocol/inference-headers.ts +3 -0
- package/protocol/keepalive.ts +69 -0
- package/protocol/local-auth.ts +300 -0
- package/protocol/local-device-control.ts +133 -0
- package/protocol/local-provider.ts +288 -0
- package/protocol/local-session.ts +118 -0
- package/protocol/marketplace.ts +187 -0
- package/protocol/media-attempt.ts +81 -0
- package/protocol/media-bytes.ts +28 -0
- package/protocol/media-default.ts +357 -0
- package/protocol/media-dimensions.ts +132 -0
- package/protocol/media-input.ts +61 -0
- package/protocol/media-model.ts +142 -0
- package/protocol/media-option-issue.ts +90 -0
- package/protocol/media-types.ts +70 -0
- package/protocol/model-match.ts +1051 -0
- package/protocol/model-settings.ts +327 -0
- package/protocol/models.ts +767 -0
- package/protocol/mux.ts +722 -0
- package/protocol/plan-surface.ts +59 -0
- package/protocol/provider-models.ts +16 -0
- package/protocol/provider-status.ts +206 -0
- package/protocol/provider-tier.ts +67 -0
- package/protocol/provider-usage.ts +263 -0
- package/protocol/providers.ts +901 -0
- package/protocol/public-usage-index.ts +354 -0
- package/protocol/realtime-generated.ts +31 -0
- package/protocol/realtime.ts +324 -0
- package/protocol/registry-pointer.ts +118 -0
- package/protocol/relay.ts +702 -0
- package/protocol/replay-session.ts +11 -0
- package/protocol/responses.ts +280 -0
- package/protocol/semver.ts +182 -0
- package/protocol/setup-mode.ts +22 -0
- package/protocol/sha256-hex.ts +98 -0
- package/protocol/stats.ts +406 -0
- package/protocol/streaming.ts +19 -0
- package/protocol/subscription-daemon-floors.ts +33 -0
- package/protocol/subscription-provider-compat.ts +104 -0
- package/protocol/subscription-provider.ts +32 -0
- package/protocol/team-grant.ts +17 -0
- package/protocol/team-shareable.ts +61 -0
- package/protocol/transcription-encoding.ts +76 -0
- package/protocol/url-locality-dns.ts +37 -0
- package/protocol/url-locality.ts +288 -0
- package/protocol/usage-snapshots.ts +9 -0
- package/protocol/vendor-cli-install.ts +29 -0
- package/protocol/video-job-plan.ts +50 -0
- package/protocol/videos.ts +227 -0
- package/tsconfig.json +14 -0
- package/tunnel/ARCHITECTURE.md +111 -0
- package/tunnel/LICENSE +33 -0
- package/tunnel/README.md +45 -0
- package/tunnel/assets/openllm-light.svg +18 -0
- package/tunnel/assets/openllm.svg +18 -0
- package/tunnel/channel-envelope.ts +139 -0
- package/tunnel/codec.ts +191 -0
- package/tunnel/device-anchor.ts +229 -0
- package/tunnel/device-control.ts +118 -0
- package/tunnel/device-grant.ts +173 -0
- package/tunnel/fleet.ts +77 -0
- package/tunnel/index.ts +22 -0
- package/tunnel/mux.ts +580 -0
- package/tunnel/peer-link.ts +390 -0
- package/tunnel/rtc-auth.ts +415 -0
- package/tunnel/rtc-duplex.ts +187 -0
- package/tunnel/rtc-ice.ts +136 -0
- package/tunnel/secure.ts +1298 -0
- package/tunnel/stream-reset-error.ts +14 -0
- package/tunnel/streams.ts +1430 -0
- package/tunnel/team-grant.ts +302 -0
- package/tunnel/wire-bytes.ts +102 -0
- package/vault/ARCHITECTURE.md +470 -0
- package/vault/LICENSE +33 -0
- package/vault/api-key.ts +190 -0
- package/vault/argon2.ts +106 -0
- package/vault/cli-auth-seal.ts +157 -0
- package/vault/cred-seal.ts +146 -0
- package/vault/credential.ts +55 -0
- package/vault/crypto.ts +210 -0
- package/vault/daemon-attest.ts +229 -0
- package/vault/derive.ts +113 -0
- package/vault/device-access.ts +87 -0
- package/vault/device-anchor.ts +185 -0
- package/vault/device-control.ts +174 -0
- package/vault/handoff.ts +396 -0
- package/vault/index.ts +21 -0
- package/vault/passkey.ts +243 -0
- package/vault/phrase.ts +65 -0
- package/vault/pin.ts +153 -0
- package/vault/public-key-seal.ts +131 -0
- package/vault/seed.ts +272 -0
- package/vault/team.ts +355 -0
- package/vault/vault-item.ts +131 -0
- package/vault/vault-migrate-digest.ts +29 -0
- package/vault/wrapped.ts +77 -0
- package/wire/ARCHITECTURE.md +90 -0
- package/wire/CONTRIBUTING.md +19 -0
- package/wire/LICENSE +33 -0
- package/wire/README.md +51 -0
- package/wire/adapters/messages/anthropic-map.ts +37 -0
- package/wire/adapters/messages/index.ts +7 -0
- package/wire/adapters/messages/reasoning-from-items.ts +38 -0
- package/wire/adapters/messages/reasoning-signature.ts +243 -0
- package/wire/adapters/messages/request.ts +574 -0
- package/wire/adapters/messages/response.ts +215 -0
- package/wire/adapters/messages/streaming.ts +1027 -0
- package/wire/adapters/messages/usage.ts +43 -0
- package/wire/adapters/responses/index.ts +3 -0
- package/wire/adapters/responses/request.ts +395 -0
- package/wire/adapters/responses/response.ts +88 -0
- package/wire/adapters/responses/streaming.ts +344 -0
- package/wire/assets/openllm-light.svg +18 -0
- package/wire/assets/openllm.svg +18 -0
- package/wire/features/account-rank.ts +166 -0
- package/wire/features/compaction/compact-request.ts +862 -0
- package/wire/features/compaction/compaction-text.ts +43 -0
- package/wire/features/context-demote.ts +47 -0
- package/wire/features/context-overflow-strategy.ts +26 -0
- package/wire/features/context-skip.ts +170 -0
- package/wire/features/conversation-affinity.ts +144 -0
- package/wire/features/max-tokens-backfill.ts +141 -0
- package/wire/features/model-caps.ts +53 -0
- package/wire/features/model-settings.ts +24 -0
- package/wire/features/output-limit-clamp.ts +64 -0
- package/wire/features/quota-gate.ts +85 -0
- package/wire/index.ts +44 -0
- package/wire/lib/attempt-outcome.ts +43 -0
- package/wire/lib/canonical/content-part.ts +38 -0
- package/wire/lib/canonical/count-tokens-capability.ts +138 -0
- package/wire/lib/canonical/encoding-select.ts +82 -0
- package/wire/lib/canonical/image-signature.ts +202 -0
- package/wire/lib/canonical/image-sse.ts +216 -0
- package/wire/lib/canonical/message.ts +43 -0
- package/wire/lib/canonical/token-estimate.ts +266 -0
- package/wire/lib/encrypted-content.ts +66 -0
- package/wire/lib/error-class.ts +154 -0
- package/wire/lib/error-envelope.ts +56 -0
- package/wire/lib/forwarded-headers.ts +180 -0
- package/wire/lib/provider-error-rules.ts +48 -0
- package/wire/lib/refusal.ts +38 -0
- package/wire/lib/responses-apply-patch.ts +104 -0
- package/wire/lib/responses-namespace.ts +53 -0
- package/wire/lib/secret-scrub.ts +101 -0
- package/wire/lib/streaming/accumulate.ts +221 -0
- package/wire/lib/streaming/finish-reason.ts +33 -0
- package/wire/lib/streaming/peek.ts +154 -0
- package/wire/lib/streaming/provider-decode.ts +259 -0
- package/wire/lib/streaming/response-stream.ts +71 -0
- package/wire/lib/streaming/sse.ts +699 -0
- package/wire/lib/streaming/strip-tool-calls.ts +95 -0
- package/wire/lib/streaming/upstream-error.ts +58 -0
- package/wire/lib/strip-subagent-isolation.ts +284 -0
- package/wire/lib/thinking-signature.ts +156 -0
- package/wire/lib/token-ruler/bpe-core.ts +426 -0
- package/wire/lib/token-ruler/index.ts +2 -0
- package/wire/lib/token-ruler/ruler.ts +79 -0
- package/wire/lib/token-ruler/vocab/claude-ranks.ts +16 -0
- package/wire/lib/token-ruler/vocab/claude.ts +22 -0
- package/wire/lib/token-ruler/vocab/o200k-ranks.ts +18 -0
- package/wire/lib/token-ruler/vocab/o200k.ts +19 -0
- package/wire/lib/tool-name-map.ts +271 -0
- package/wire/lib/tool-schema.ts +353 -0
- package/wire/lib/usage-observer.ts +125 -0
- package/wire/providers/anthropic/adaptive-thinking.ts +291 -0
- package/wire/providers/anthropic/beta-headers.ts +165 -0
- package/wire/providers/anthropic/index.ts +10 -0
- package/wire/providers/anthropic/request.ts +607 -0
- package/wire/providers/anthropic/response.ts +155 -0
- package/wire/providers/anthropic/streaming.ts +315 -0
- package/wire/providers/anthropic/web-search-domains.ts +49 -0
- package/wire/providers/chatgpt/common.ts +136 -0
- package/wire/providers/chatgpt/index.ts +9 -0
- package/wire/providers/chatgpt/request.ts +959 -0
- package/wire/providers/chatgpt/streaming.ts +1007 -0
- package/wire/providers/chatgpt/web-search.ts +63 -0
- package/wire/providers/grok/web-search.ts +87 -0
- package/wire/providers/kimi/web-search.ts +145 -0
- package/wire/providers/upstream-deny.ts +355 -0
- package/wire/providers/upstream-request.ts +619 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema as S } from "effect";
|
|
2
|
+
|
|
3
|
+
/** PostHog's UUIDv7 session ID, not a command ID or proof of session ownership. */
|
|
4
|
+
export const ReplaySessionId = S.String.pipe(
|
|
5
|
+
S.check(
|
|
6
|
+
S.isPattern(
|
|
7
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
|
|
8
|
+
),
|
|
9
|
+
),
|
|
10
|
+
);
|
|
11
|
+
export const isReplaySessionId = S.is(ReplaySessionId);
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { Schema as S } from "effect";
|
|
2
|
+
import { ReasoningEffort } from "./chat";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenAI **Responses API** wire types (`POST /v1/responses`) — the inbound
|
|
6
|
+
* surface the Codex CLI speaks (it dropped chat-completions: `wire_api="chat"`
|
|
7
|
+
* errors). We model the SUBSET Codex emits + expects; unknown extra keys are
|
|
8
|
+
* tolerated (the structs aren't sealed). The gateway adapts a Responses
|
|
9
|
+
* request → canonical ChatCompletion (`@openllmsh/sdk/wire/adapters/responses`), runs
|
|
10
|
+
* the normal pipeline, and adapts the canonical response/stream back to
|
|
11
|
+
* Responses shape.
|
|
12
|
+
*
|
|
13
|
+
* The request shape mirrors (inverts) `toChatGptRequest`'s body in
|
|
14
|
+
* `@openllmsh/sdk/wire/providers/chatgpt/request.ts`, which is the same Responses
|
|
15
|
+
* API the daemon already speaks UPSTREAM to chatgpt.com.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// ─── Request ─────────────────────────────────────────────────────────
|
|
19
|
+
|
|
20
|
+
const ResponsesInputContentPart = S.Union([
|
|
21
|
+
S.Struct({ type: S.Literals(["input_text"]), text: S.String }),
|
|
22
|
+
S.Struct({ type: S.Literals(["output_text"]), text: S.String }),
|
|
23
|
+
S.Struct({
|
|
24
|
+
type: S.Literals(["input_image"]),
|
|
25
|
+
image_url: S.String,
|
|
26
|
+
detail: S.optional(S.Literals(["auto", "low", "high"])),
|
|
27
|
+
}),
|
|
28
|
+
S.Struct({
|
|
29
|
+
type: S.Literals(["input_file"]),
|
|
30
|
+
filename: S.optional(S.String),
|
|
31
|
+
// Data URL (`data:<mime>;base64,<b64>`) — same encoding as the
|
|
32
|
+
// canonical chat `file` part's `file_data`.
|
|
33
|
+
file_data: S.optional(S.String),
|
|
34
|
+
file_id: S.optional(S.NullOr(S.String)),
|
|
35
|
+
}),
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
// `type` is optional on message items, as in the OpenAI Responses API: an
|
|
39
|
+
// input item carrying only `role` + `content` is a message. Every other item
|
|
40
|
+
// kind has a required, distinct `type`, so the union still discriminates.
|
|
41
|
+
const ResponsesMessageItem = S.Struct({
|
|
42
|
+
type: S.optional(S.Literals(["message"])),
|
|
43
|
+
role: S.Literals(["user", "assistant", "system", "developer"]),
|
|
44
|
+
// Responses allows a bare string or an array of typed parts.
|
|
45
|
+
content: S.Union([S.String, S.Array(ResponsesInputContentPart)]),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const ResponsesFunctionCallItem = S.Struct({
|
|
49
|
+
type: S.Literals(["function_call"]),
|
|
50
|
+
call_id: S.String,
|
|
51
|
+
name: S.String,
|
|
52
|
+
/** Codex namespace-scoped tools (MCP servers, …) name their group here. */
|
|
53
|
+
namespace: S.optional(S.String),
|
|
54
|
+
arguments: S.String,
|
|
55
|
+
id: S.optional(S.String),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const ResponsesFunctionCallOutputItem = S.Struct({
|
|
59
|
+
type: S.Literals(["function_call_output"]),
|
|
60
|
+
call_id: S.String,
|
|
61
|
+
output: S.Union([S.String, S.Array(ResponsesInputContentPart)]),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A reasoning item echoed back on a follow-up turn (Codex replays these for
|
|
66
|
+
* `store:false` reasoning models). Opaque here — the adapter carries it onto
|
|
67
|
+
* the canonical assistant's `reasoning_items` so it round-trips intact.
|
|
68
|
+
*/
|
|
69
|
+
const ResponsesReasoningItem = S.Struct({
|
|
70
|
+
type: S.Literals(["reasoning"]),
|
|
71
|
+
id: S.optional(S.String),
|
|
72
|
+
summary: S.optional(S.Unknown),
|
|
73
|
+
content: S.optional(S.Unknown),
|
|
74
|
+
encrypted_content: S.optional(S.NullishOr(S.String)),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A tool definition in the Responses API. Codex ships a MIX on every request:
|
|
79
|
+
* classic `function` tools (`exec_command`, `update_plan`, `view_image`, …)
|
|
80
|
+
* AND built-in non-function tools — `custom` (the freeform-grammar
|
|
81
|
+
* `apply_patch`), `web_search`, `image_generation`, `tool_search`. We accept
|
|
82
|
+
* ALL of them: the old `type: "function"`-only struct made the whole `tools`
|
|
83
|
+
* array fail decode → a hard 400 on every Codex request. The index signature
|
|
84
|
+
* (`S.Record`) preserves each tool's extra keys verbatim (`format`,
|
|
85
|
+
* `external_web_access`, `output_format`, …) so the chatgpt round-trip can
|
|
86
|
+
* re-emit them intact via the canonical `responses_tools` passthrough. `name`
|
|
87
|
+
* is optional — `web_search` / `image_generation` carry none.
|
|
88
|
+
*/
|
|
89
|
+
const ResponsesToolDef = S.StructWithRest(
|
|
90
|
+
S.Struct({
|
|
91
|
+
type: S.String,
|
|
92
|
+
name: S.optional(S.String),
|
|
93
|
+
description: S.optional(S.NullishOr(S.String)),
|
|
94
|
+
parameters: S.optional(S.Unknown),
|
|
95
|
+
strict: S.optional(S.NullishOr(S.Boolean)),
|
|
96
|
+
}),
|
|
97
|
+
[S.Record(S.String, S.Unknown)],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Codex v0.147 carries its harness-owned tools as the first Responses input
|
|
102
|
+
* item rather than in the top-level `tools` array. The tool definitions remain
|
|
103
|
+
* opaque so nested namespaces and freeform custom tools round-trip intact.
|
|
104
|
+
*/
|
|
105
|
+
const ResponsesAdditionalToolsItem = S.Struct({
|
|
106
|
+
type: S.Literals(["additional_tools"]),
|
|
107
|
+
role: S.Literals(["developer"]),
|
|
108
|
+
tools: S.Array(ResponsesToolDef),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A call to OpenAI's hosted `apply_patch` tool replayed on a follow-up turn
|
|
113
|
+
* (the OpenAI Agents SDK echoes these). The adapter maps it to a function call
|
|
114
|
+
* to the tool's canonical stand-in; `operation` stays opaque here.
|
|
115
|
+
*/
|
|
116
|
+
const ResponsesApplyPatchCallItem = S.Struct({
|
|
117
|
+
type: S.Literals(["apply_patch_call"]),
|
|
118
|
+
call_id: S.String,
|
|
119
|
+
id: S.optional(S.String),
|
|
120
|
+
status: S.optional(S.String),
|
|
121
|
+
operation: S.Unknown,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const ResponsesApplyPatchCallOutputItem = S.Struct({
|
|
125
|
+
type: S.Literals(["apply_patch_call_output"]),
|
|
126
|
+
call_id: S.String,
|
|
127
|
+
id: S.optional(S.String),
|
|
128
|
+
status: S.optional(S.String),
|
|
129
|
+
output: S.optional(S.NullishOr(S.String)),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export const ResponsesInputItem = S.Union([
|
|
133
|
+
ResponsesMessageItem,
|
|
134
|
+
ResponsesFunctionCallItem,
|
|
135
|
+
ResponsesFunctionCallOutputItem,
|
|
136
|
+
ResponsesReasoningItem,
|
|
137
|
+
ResponsesAdditionalToolsItem,
|
|
138
|
+
ResponsesApplyPatchCallItem,
|
|
139
|
+
ResponsesApplyPatchCallOutputItem,
|
|
140
|
+
]);
|
|
141
|
+
export type TResponsesAdditionalToolsItem = S.Schema.Type<
|
|
142
|
+
typeof ResponsesAdditionalToolsItem
|
|
143
|
+
>;
|
|
144
|
+
export type TResponsesInputItem = S.Schema.Type<typeof ResponsesInputItem>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* `allowed_tools` restricts one turn to a subset of the declared tools while
|
|
148
|
+
* the full list stays in the prompt (the OpenAI Agents SDK sends it every
|
|
149
|
+
* turn). Entries are tool references: `{type:"function", name}` or a
|
|
150
|
+
* non-function tool's bare `{type}`. `{type:"apply_patch"}` forces the hosted
|
|
151
|
+
* patch tool.
|
|
152
|
+
*/
|
|
153
|
+
const ResponsesAllowedToolsChoice = S.Struct({
|
|
154
|
+
type: S.Literals(["allowed_tools"]),
|
|
155
|
+
mode: S.Literals(["auto", "required"]),
|
|
156
|
+
tools: S.Array(
|
|
157
|
+
S.StructWithRest(S.Struct({ type: S.String, name: S.optional(S.String) }), [
|
|
158
|
+
S.Record(S.String, S.Unknown),
|
|
159
|
+
]),
|
|
160
|
+
),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const ResponsesToolChoice = S.Union([
|
|
164
|
+
S.Literals(["auto", "none", "required"]),
|
|
165
|
+
S.Struct({ type: S.Literals(["function"]), name: S.String }),
|
|
166
|
+
S.Struct({ type: S.Literals(["apply_patch"]) }),
|
|
167
|
+
ResponsesAllowedToolsChoice,
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
export const ResponsesRequest = S.Struct({
|
|
171
|
+
model: S.String,
|
|
172
|
+
service_tier: S.optional(S.Unknown),
|
|
173
|
+
// `input` is either a bare prompt string or the ordered item array.
|
|
174
|
+
input: S.Union([S.String, S.Array(ResponsesInputItem)]),
|
|
175
|
+
instructions: S.optional(S.NullishOr(S.String)),
|
|
176
|
+
// Nullish, not just optional: Codex emits explicit `null`s for unset fields.
|
|
177
|
+
tools: S.optional(S.NullishOr(S.Array(ResponsesToolDef))),
|
|
178
|
+
tool_choice: S.optional(S.NullishOr(ResponsesToolChoice)),
|
|
179
|
+
// Codex sends `reasoning: null` (not just omitted) when the effort is
|
|
180
|
+
// `none` — so the whole object must be nullish, not only its `effort`.
|
|
181
|
+
reasoning: S.optional(
|
|
182
|
+
S.NullishOr(
|
|
183
|
+
S.Struct({
|
|
184
|
+
effort: S.optional(S.NullishOr(ReasoningEffort)),
|
|
185
|
+
}),
|
|
186
|
+
),
|
|
187
|
+
),
|
|
188
|
+
max_output_tokens: S.optional(S.NullishOr(S.Number)),
|
|
189
|
+
temperature: S.optional(S.NullishOr(S.Number)),
|
|
190
|
+
top_p: S.optional(S.NullishOr(S.Number)),
|
|
191
|
+
stream: S.optional(S.NullishOr(S.Boolean)),
|
|
192
|
+
parallel_tool_calls: S.optional(S.NullishOr(S.Boolean)),
|
|
193
|
+
/**
|
|
194
|
+
* Codex Desktop mirrors its Responses-Lite websocket header here as
|
|
195
|
+
* `ws_request_header_x_openai_internal_codex_responses_lite`. Preserve this
|
|
196
|
+
* opaque object through the canonical round-trip so ChatGPT can apply its
|
|
197
|
+
* Lite-specific request requirements without guessing from a model id.
|
|
198
|
+
*/
|
|
199
|
+
client_metadata: S.optional(S.Unknown),
|
|
200
|
+
// Tolerated + ignored (Codex sets these); kept off the canonical mapping.
|
|
201
|
+
store: S.optional(S.NullishOr(S.Boolean)),
|
|
202
|
+
previous_response_id: S.optional(S.NullishOr(S.String)),
|
|
203
|
+
// Codex sends this per conversation (stable across turns) to route prompt-cache
|
|
204
|
+
// hits — preserve it so the daemon's re-encoded upstream keeps the same key
|
|
205
|
+
// rather than dropping it. See `fromResponsesRequest` / `toChatGptRequest`.
|
|
206
|
+
prompt_cache_key: S.optional(S.NullishOr(S.String)),
|
|
207
|
+
});
|
|
208
|
+
export type TResponsesRequest = S.Schema.Type<typeof ResponsesRequest>;
|
|
209
|
+
|
|
210
|
+
// ─── Response (non-streaming) ────────────────────────────────────────
|
|
211
|
+
|
|
212
|
+
const ResponsesOutputTextPart = S.Struct({
|
|
213
|
+
type: S.Literals(["output_text"]),
|
|
214
|
+
text: S.String,
|
|
215
|
+
annotations: S.optional(S.Array(S.Unknown)),
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const ResponsesOutputMessage = S.Struct({
|
|
219
|
+
type: S.Literals(["message"]),
|
|
220
|
+
id: S.String,
|
|
221
|
+
role: S.Literals(["assistant"]),
|
|
222
|
+
status: S.Literals(["completed", "in_progress", "incomplete"]),
|
|
223
|
+
content: S.Array(ResponsesOutputTextPart),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const ResponsesOutputFunctionCall = S.Struct({
|
|
227
|
+
type: S.Literals(["function_call"]),
|
|
228
|
+
id: S.String,
|
|
229
|
+
call_id: S.String,
|
|
230
|
+
name: S.String,
|
|
231
|
+
/** Set for Codex namespace-scoped tools; Codex routes the call by it. */
|
|
232
|
+
namespace: S.optional(S.String),
|
|
233
|
+
arguments: S.String,
|
|
234
|
+
status: S.optional(S.Literals(["completed", "in_progress", "incomplete"])),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const ResponsesOutputReasoning = S.Struct({
|
|
238
|
+
type: S.Literals(["reasoning"]),
|
|
239
|
+
id: S.String,
|
|
240
|
+
summary: S.Array(S.Unknown),
|
|
241
|
+
encrypted_content: S.optional(S.NullishOr(S.String)),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
/** A call to the hosted `apply_patch` tool, as OpenAI's API returns it. */
|
|
245
|
+
const ResponsesOutputApplyPatchCall = S.Struct({
|
|
246
|
+
type: S.Literals(["apply_patch_call"]),
|
|
247
|
+
id: S.String,
|
|
248
|
+
call_id: S.String,
|
|
249
|
+
status: S.Literals(["completed", "in_progress"]),
|
|
250
|
+
operation: S.Struct({
|
|
251
|
+
type: S.Literals(["create_file", "update_file", "delete_file"]),
|
|
252
|
+
path: S.String,
|
|
253
|
+
diff: S.optional(S.String),
|
|
254
|
+
}),
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
export const ResponsesOutputItem = S.Union([
|
|
258
|
+
ResponsesOutputMessage,
|
|
259
|
+
ResponsesOutputFunctionCall,
|
|
260
|
+
ResponsesOutputReasoning,
|
|
261
|
+
ResponsesOutputApplyPatchCall,
|
|
262
|
+
]);
|
|
263
|
+
export type TResponsesOutputItem = S.Schema.Type<typeof ResponsesOutputItem>;
|
|
264
|
+
|
|
265
|
+
export const ResponsesUsage = S.Struct({
|
|
266
|
+
input_tokens: S.Number,
|
|
267
|
+
output_tokens: S.Number,
|
|
268
|
+
total_tokens: S.Number,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export const ResponsesResponse = S.Struct({
|
|
272
|
+
id: S.String,
|
|
273
|
+
object: S.Literals(["response"]),
|
|
274
|
+
created_at: S.Number,
|
|
275
|
+
status: S.Literals(["completed", "incomplete", "failed", "in_progress"]),
|
|
276
|
+
model: S.String,
|
|
277
|
+
output: S.Array(ResponsesOutputItem),
|
|
278
|
+
usage: S.optional(ResponsesUsage),
|
|
279
|
+
});
|
|
280
|
+
export type TResponsesResponse = S.Schema.Type<typeof ResponsesResponse>;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semver comparison for vendor CLI versions reported by the daemon.
|
|
3
|
+
*
|
|
4
|
+
* Versions arrive as whatever the CLI prints (`codex-cli 0.142.0`), so the
|
|
5
|
+
* x.y.z is extracted rather than assumed to be the whole string. Shared by
|
|
6
|
+
* the cloud (model-cache write guard), the dashboard (update notices), and
|
|
7
|
+
* the daemon — providers can gate model visibility by client version
|
|
8
|
+
* (Codex does), so version comparison is protocol-level, not app-local.
|
|
9
|
+
*
|
|
10
|
+
* Daemon binary floors (subscription-provider compatibility) need full
|
|
11
|
+
* SemVer §11 prerelease precedence — see {@link compareDaemonSemver}. The
|
|
12
|
+
* CLI helpers below deliberately keep extracting bare `x.y.z` so a noisy
|
|
13
|
+
* vendor banner never invents a prerelease channel.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The bare `x.y.z` inside whatever the CLI (or a GitHub release tag) prints —
|
|
18
|
+
* `codex-cli 0.142.0`, `v0.142.0`. Null when there is no semver to find, or
|
|
19
|
+
* the input isn't a string (a release tag arrives as `unknown` from JSON).
|
|
20
|
+
*/
|
|
21
|
+
export const extractSemver = (version: unknown): string | null => {
|
|
22
|
+
if (typeof version !== "string") return null;
|
|
23
|
+
return version.match(/\d+\.\d+\.\d+/)?.[0] ?? null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const parseSemver = (version: string): readonly number[] | null => {
|
|
27
|
+
const match = extractSemver(version);
|
|
28
|
+
if (match === null) return null;
|
|
29
|
+
return match.split(".").map((part) => Number.parseInt(part, 10));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** `-1` / `0` / `1`, or null when either side carries no parseable semver. */
|
|
33
|
+
export const compareSemver = (left: string, right: string): number | null => {
|
|
34
|
+
const leftParts = parseSemver(left);
|
|
35
|
+
const rightParts = parseSemver(right);
|
|
36
|
+
if (leftParts === null || rightParts === null) return null;
|
|
37
|
+
const length = Math.max(leftParts.length, rightParts.length);
|
|
38
|
+
for (let i = 0; i < length; i += 1) {
|
|
39
|
+
const leftPart = leftParts[i] ?? 0;
|
|
40
|
+
const rightPart = rightParts[i] ?? 0;
|
|
41
|
+
if (leftPart < rightPart) return -1;
|
|
42
|
+
if (leftPart > rightPart) return 1;
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** True only when both parse AND `current` is strictly behind `latest`. */
|
|
48
|
+
export const isOlderSemver = (current: string, latest: string): boolean =>
|
|
49
|
+
compareSemver(current, latest) === -1;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* True only when both parse AND `current`'s `major.minor` is strictly
|
|
53
|
+
* behind `latest`'s — the patch component is ignored, so a patch-only
|
|
54
|
+
* lag (0.144.0 vs 0.144.1) is NOT "behind". Used for update notices:
|
|
55
|
+
* patch bumps are too noisy to nag about.
|
|
56
|
+
*/
|
|
57
|
+
export const isMinorBehind = (current: string, latest: string): boolean => {
|
|
58
|
+
const currentParts = extractSemver(current)?.split(".");
|
|
59
|
+
const latestParts = extractSemver(latest)?.split(".");
|
|
60
|
+
if (currentParts === undefined || latestParts === undefined) return false;
|
|
61
|
+
const currentMinor = `${currentParts[0]}.${currentParts[1]}.0`;
|
|
62
|
+
const latestMinor = `${latestParts[0]}.${latestParts[1]}.0`;
|
|
63
|
+
return compareSemver(currentMinor, latestMinor) === -1;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** Source / custom daemon build — never treated as a released floor pin. */
|
|
67
|
+
export const DEV_DAEMON_VERSION = "0.0.0-dev";
|
|
68
|
+
|
|
69
|
+
/** Canonical numeric identifier: `0` or no-leading-zero digits. */
|
|
70
|
+
const CANONICAL_NUMERIC_ID = /^(0|[1-9]\d*)$/;
|
|
71
|
+
/** SemVer alphanumeric identifier: nonempty, [0-9A-Za-z-], not purely numeric. */
|
|
72
|
+
const ALPHANUMERIC_ID = /^[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*$/;
|
|
73
|
+
|
|
74
|
+
export type TDaemonSemver = {
|
|
75
|
+
/** Digit strings — compared by length then lexicographically (§11 / no Number). */
|
|
76
|
+
readonly major: string;
|
|
77
|
+
readonly minor: string;
|
|
78
|
+
readonly patch: string;
|
|
79
|
+
readonly pre: readonly string[] | null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const compareDigitIds = (left: string, right: string): -1 | 0 | 1 => {
|
|
83
|
+
if (left.length !== right.length) return left.length < right.length ? -1 : 1;
|
|
84
|
+
if (left === right) return 0;
|
|
85
|
+
return left < right ? -1 : 1;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const isValidPreIdentifier = (id: string): boolean =>
|
|
89
|
+
CANONICAL_NUMERIC_ID.test(id) || ALPHANUMERIC_ID.test(id);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parse a daemon binary version stamp (`2.7.5`, `v2.8.0-alpha.0`). Null when
|
|
93
|
+
* the input is missing or not canonical SemVer (unlike {@link extractSemver},
|
|
94
|
+
* prerelease identifiers are preserved and validated — no leading zeros,
|
|
95
|
+
* nonempty identifiers). Invalid stamps fall through to live capability
|
|
96
|
+
* probes via {@link subscriptionProviderSupportedOnDaemon}.
|
|
97
|
+
*/
|
|
98
|
+
export const parseDaemonSemver = (version: unknown): TDaemonSemver | null => {
|
|
99
|
+
if (typeof version !== "string") return null;
|
|
100
|
+
const trimmed = version.trim();
|
|
101
|
+
if (trimmed.length === 0) return null;
|
|
102
|
+
const match = trimmed.match(
|
|
103
|
+
/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/,
|
|
104
|
+
);
|
|
105
|
+
if (match === null) return null;
|
|
106
|
+
const major = match[1] ?? "";
|
|
107
|
+
const minor = match[2] ?? "";
|
|
108
|
+
const patch = match[3] ?? "";
|
|
109
|
+
if (
|
|
110
|
+
!CANONICAL_NUMERIC_ID.test(major) ||
|
|
111
|
+
!CANONICAL_NUMERIC_ID.test(minor) ||
|
|
112
|
+
!CANONICAL_NUMERIC_ID.test(patch)
|
|
113
|
+
) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const build = match[5];
|
|
117
|
+
if (build !== undefined) {
|
|
118
|
+
const buildIds = build.split(".");
|
|
119
|
+
if (buildIds.some((id) => id.length === 0 || !/^[0-9A-Za-z-]+$/.test(id))) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let pre: readonly string[] | null = null;
|
|
124
|
+
if (match[4] !== undefined) {
|
|
125
|
+
const ids = match[4].split(".");
|
|
126
|
+
if (ids.length === 0 || !ids.every(isValidPreIdentifier)) return null;
|
|
127
|
+
pre = ids;
|
|
128
|
+
}
|
|
129
|
+
return { major, minor, patch, pre };
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** True for the compiled-from-source sentinel (`0.0.0-dev`). */
|
|
133
|
+
export const isDevDaemonVersion = (version: unknown): boolean => {
|
|
134
|
+
if (typeof version !== "string") return false;
|
|
135
|
+
return version.trim() === DEV_DAEMON_VERSION;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* SemVer §11 precedence for daemon binary floors: `-1` / `0` / `1`, or null
|
|
140
|
+
* when either side is unparseable. A release outranks any prerelease of the
|
|
141
|
+
* same base; numeric prerelease identifiers compare by digit length then
|
|
142
|
+
* lexicographically (arbitrary magnitude — never `Number`).
|
|
143
|
+
*/
|
|
144
|
+
export const compareDaemonSemver = (
|
|
145
|
+
left: string,
|
|
146
|
+
right: string,
|
|
147
|
+
): -1 | 0 | 1 | null => {
|
|
148
|
+
const leftParts = parseDaemonSemver(left);
|
|
149
|
+
const rightParts = parseDaemonSemver(right);
|
|
150
|
+
if (leftParts === null || rightParts === null) return null;
|
|
151
|
+
for (const key of ["major", "minor", "patch"] as const) {
|
|
152
|
+
const order = compareDigitIds(leftParts[key], rightParts[key]);
|
|
153
|
+
if (order !== 0) return order;
|
|
154
|
+
}
|
|
155
|
+
if (leftParts.pre === null && rightParts.pre === null) return 0;
|
|
156
|
+
if (leftParts.pre === null) return 1;
|
|
157
|
+
if (rightParts.pre === null) return -1;
|
|
158
|
+
const leftIds = leftParts.pre;
|
|
159
|
+
const rightIds = rightParts.pre;
|
|
160
|
+
const shared = Math.min(leftIds.length, rightIds.length);
|
|
161
|
+
for (let i = 0; i < shared; i += 1) {
|
|
162
|
+
const a = leftIds[i] ?? "";
|
|
163
|
+
const b = rightIds[i] ?? "";
|
|
164
|
+
if (a === b) continue;
|
|
165
|
+
const aNumeric = CANONICAL_NUMERIC_ID.test(a);
|
|
166
|
+
const bNumeric = CANONICAL_NUMERIC_ID.test(b);
|
|
167
|
+
if (aNumeric && bNumeric) return compareDigitIds(a, b);
|
|
168
|
+
if (aNumeric !== bNumeric) return aNumeric ? -1 : 1;
|
|
169
|
+
return a < b ? -1 : 1;
|
|
170
|
+
}
|
|
171
|
+
if (leftIds.length === rightIds.length) return 0;
|
|
172
|
+
return leftIds.length < rightIds.length ? -1 : 1;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** True when both parse and `current` is greater than or equal to `minimum`. */
|
|
176
|
+
export const isDaemonVersionAtLeast = (
|
|
177
|
+
current: string,
|
|
178
|
+
minimum: string,
|
|
179
|
+
): boolean => {
|
|
180
|
+
const order = compareDaemonSemver(current, minimum);
|
|
181
|
+
return order !== null && order >= 0;
|
|
182
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe product setup-mode contract (protocol SSOT).
|
|
3
|
+
*
|
|
4
|
+
* Shared by the CLI and the dashboard install one-liners. Pure constants +
|
|
5
|
+
* parse — no Node, no env-file I/O.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Env-file / process-env / install-one-liner key. */
|
|
9
|
+
export const SETUP_MODE_ENV = "OPENLLM_SETUP_MODE";
|
|
10
|
+
|
|
11
|
+
export const SETUP_MODES = ["full", "minimal"] as const;
|
|
12
|
+
export type TSetupMode = (typeof SETUP_MODES)[number];
|
|
13
|
+
|
|
14
|
+
/** Fresh-install / omitted-option default. */
|
|
15
|
+
export const DEFAULT_SETUP_MODE: TSetupMode = "full";
|
|
16
|
+
|
|
17
|
+
/** Accept only the documented values; reject anything else (incl. install/update). */
|
|
18
|
+
export const parseSetupMode = (raw: string | undefined): TSetupMode | null => {
|
|
19
|
+
const value = raw?.trim();
|
|
20
|
+
if (value === "full" || value === "minimal") return value;
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Pure SHA-256 hex digest. Protocol may not import `node:crypto`. */
|
|
2
|
+
|
|
3
|
+
const K: readonly number[] = [
|
|
4
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
|
|
5
|
+
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
|
6
|
+
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
7
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
8
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
|
|
9
|
+
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
10
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
|
|
11
|
+
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
12
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
13
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
|
14
|
+
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const rotr = (x: number, n: number): number => (x >>> n) | (x << (32 - n));
|
|
18
|
+
|
|
19
|
+
export const sha256Hex = (utf8: string): string => {
|
|
20
|
+
const msg = new TextEncoder().encode(utf8);
|
|
21
|
+
const bitLen = msg.length * 8;
|
|
22
|
+
const withPad = msg.length + 1 + 8;
|
|
23
|
+
const paddedLen = ((withPad + 63) & ~63) >>> 0;
|
|
24
|
+
const bytes = new Uint8Array(paddedLen);
|
|
25
|
+
bytes.set(msg);
|
|
26
|
+
bytes[msg.length] = 0x80;
|
|
27
|
+
const view = new DataView(bytes.buffer);
|
|
28
|
+
view.setUint32(paddedLen - 4, bitLen >>> 0);
|
|
29
|
+
|
|
30
|
+
let h0 = 0x6a09e667;
|
|
31
|
+
let h1 = 0xbb67ae85;
|
|
32
|
+
let h2 = 0x3c6ef372;
|
|
33
|
+
let h3 = 0xa54ff53a;
|
|
34
|
+
let h4 = 0x510e527f;
|
|
35
|
+
let h5 = 0x9b05688c;
|
|
36
|
+
let h6 = 0x1f83d9ab;
|
|
37
|
+
let h7 = 0x5be0cd19;
|
|
38
|
+
const w = new Int32Array(64);
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < paddedLen; i += 64) {
|
|
41
|
+
for (let t = 0; t < 16; t++) {
|
|
42
|
+
w[t] = view.getUint32(i + t * 4);
|
|
43
|
+
}
|
|
44
|
+
for (let t = 16; t < 64; t++) {
|
|
45
|
+
const wt15 = w[t - 15] as number;
|
|
46
|
+
const wt2 = w[t - 2] as number;
|
|
47
|
+
const s0 = rotr(wt15, 7) ^ rotr(wt15, 18) ^ (wt15 >>> 3);
|
|
48
|
+
const s1 = rotr(wt2, 17) ^ rotr(wt2, 19) ^ (wt2 >>> 10);
|
|
49
|
+
w[t] = ((w[t - 16] as number) + s0 + (w[t - 7] as number) + s1) | 0;
|
|
50
|
+
}
|
|
51
|
+
let a = h0;
|
|
52
|
+
let b = h1;
|
|
53
|
+
let c = h2;
|
|
54
|
+
let d = h3;
|
|
55
|
+
let e = h4;
|
|
56
|
+
let f = h5;
|
|
57
|
+
let g = h6;
|
|
58
|
+
let h = h7;
|
|
59
|
+
for (let t = 0; t < 64; t++) {
|
|
60
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
61
|
+
const ch = (e & f) ^ (~e & g);
|
|
62
|
+
const temp1 = (h + S1 + ch + (K[t] as number) + (w[t] as number)) | 0;
|
|
63
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
64
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
65
|
+
const temp2 = (S0 + maj) | 0;
|
|
66
|
+
h = g;
|
|
67
|
+
g = f;
|
|
68
|
+
f = e;
|
|
69
|
+
e = (d + temp1) | 0;
|
|
70
|
+
d = c;
|
|
71
|
+
c = b;
|
|
72
|
+
b = a;
|
|
73
|
+
a = (temp1 + temp2) | 0;
|
|
74
|
+
}
|
|
75
|
+
h0 = (h0 + a) | 0;
|
|
76
|
+
h1 = (h1 + b) | 0;
|
|
77
|
+
h2 = (h2 + c) | 0;
|
|
78
|
+
h3 = (h3 + d) | 0;
|
|
79
|
+
h4 = (h4 + e) | 0;
|
|
80
|
+
h5 = (h5 + f) | 0;
|
|
81
|
+
h6 = (h6 + g) | 0;
|
|
82
|
+
h7 = (h7 + h) | 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const out = new Uint8Array(32);
|
|
86
|
+
const outView = new DataView(out.buffer);
|
|
87
|
+
outView.setUint32(0, h0 >>> 0);
|
|
88
|
+
outView.setUint32(4, h1 >>> 0);
|
|
89
|
+
outView.setUint32(8, h2 >>> 0);
|
|
90
|
+
outView.setUint32(12, h3 >>> 0);
|
|
91
|
+
outView.setUint32(16, h4 >>> 0);
|
|
92
|
+
outView.setUint32(20, h5 >>> 0);
|
|
93
|
+
outView.setUint32(24, h6 >>> 0);
|
|
94
|
+
outView.setUint32(28, h7 >>> 0);
|
|
95
|
+
let hex = "";
|
|
96
|
+
for (const b of out) hex += b.toString(16).padStart(2, "0");
|
|
97
|
+
return hex;
|
|
98
|
+
};
|