@wlv-zedd/dsh-chatgpt-web 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/assets/demo.gif +0 -0
- package/assets/hero-demo.png +0 -0
- package/assets/promo-dshmarket-official.png +0 -0
- package/cordis.patch.yml +4 -0
- package/lib/cli.js +239642 -0
- package/lib/plugin.js +195 -0
- package/package.json +88 -0
- package/screenshots.json +5 -0
- package/src/adapters/base.ts +16 -0
- package/src/adapters/chatgpt-web/adapter-error.ts +59 -0
- package/src/adapters/chatgpt-web/browser-helper-main.ts +513 -0
- package/src/adapters/chatgpt-web/browser-helper-prompt-selection.ts +27 -0
- package/src/adapters/chatgpt-web/browser-worker.ts +4944 -0
- package/src/adapters/chatgpt-web/codex-rollout-environment.ts +628 -0
- package/src/adapters/chatgpt-web/compaction-handoff.ts +533 -0
- package/src/adapters/chatgpt-web/compaction-transaction.ts +142 -0
- package/src/adapters/chatgpt-web/concurrency.ts +6 -0
- package/src/adapters/chatgpt-web/conversation-key.ts +58 -0
- package/src/adapters/chatgpt-web/environment.ts +669 -0
- package/src/adapters/chatgpt-web/index.ts +1544 -0
- package/src/adapters/chatgpt-web/input-tokens.ts +74 -0
- package/src/adapters/chatgpt-web/launcher-helper-client.ts +695 -0
- package/src/adapters/chatgpt-web/markdown.ts +418 -0
- package/src/adapters/chatgpt-web/mcp-main.ts +25 -0
- package/src/adapters/chatgpt-web/mcp-server.ts +933 -0
- package/src/adapters/chatgpt-web/model.ts +70 -0
- package/src/adapters/chatgpt-web/native-compaction-control.ts +74 -0
- package/src/adapters/chatgpt-web/output-validation.ts +62 -0
- package/src/adapters/chatgpt-web/process-line-writer.ts +46 -0
- package/src/adapters/chatgpt-web/prompt.ts +702 -0
- package/src/adapters/chatgpt-web/retry-policy.ts +73 -0
- package/src/adapters/chatgpt-web/rolling-checkpoint.ts +384 -0
- package/src/adapters/chatgpt-web/thread-environment.ts +238 -0
- package/src/adapters/chatgpt-web/tool-stream-parser.ts +601 -0
- package/src/adapters/chatgpt-web/turn-broker.ts +1481 -0
- package/src/adapters/chatgpt-web/turn-execution.ts +816 -0
- package/src/adapters/chatgpt-web/turn-progress.ts +292 -0
- package/src/adapters/chatgpt-web/usage.ts +121 -0
- package/src/adapters/image.ts +9 -0
- package/src/bridge.ts +1083 -0
- package/src/browser-login.ts +521 -0
- package/src/chatgpt-session.ts +240 -0
- package/src/chatgpt-web-models.ts +400 -0
- package/src/cli.ts +568 -0
- package/src/codex-integration-document.ts +824 -0
- package/src/codex-integration-journal.ts +212 -0
- package/src/codex-integration-route.ts +515 -0
- package/src/codex-integration-shared.ts +332 -0
- package/src/codex-integration.ts +529 -0
- package/src/codex-interrupt-hook.ts +158 -0
- package/src/config.ts +616 -0
- package/src/dev-chat/cli.ts +432 -0
- package/src/dev-chat/constants.ts +3 -0
- package/src/dev-chat/driver.ts +655 -0
- package/src/dev-chat/profile.ts +223 -0
- package/src/dev-chat/session.ts +287 -0
- package/src/dev-chat/transport.ts +54 -0
- package/src/doctor.ts +237 -0
- package/src/event-queue.ts +45 -0
- package/src/http-body.ts +30 -0
- package/src/launcher-browser-host.ts +695 -0
- package/src/lib/errors.ts +281 -0
- package/src/lib/token-estimate.ts +42 -0
- package/src/login-helper.cjs +140 -0
- package/src/model-catalog.ts +197 -0
- package/src/native-passthrough.ts +261 -0
- package/src/plugin.ts +191 -0
- package/src/process.ts +45 -0
- package/src/responses/compaction.ts +199 -0
- package/src/responses/parser.ts +633 -0
- package/src/responses/reasoning-envelope.ts +49 -0
- package/src/responses/schema.ts +172 -0
- package/src/responses/state.ts +230 -0
- package/src/server.ts +1111 -0
- package/src/service.ts +315 -0
- package/src/setup.ts +671 -0
- package/src/stall-timeout.ts +23 -0
- package/src/tunnel-service.ts +160 -0
- package/src/tunnel.ts +417 -0
- package/src/turndown-plugin-gfm.d.ts +5 -0
- package/src/types.ts +307 -0
- package/src/usage/totals.ts +12 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CHATGPT_WEB_PLATFORM_RESERVE_TOKENS } from "../../chatgpt-web-models";
|
|
2
|
+
import { estimateTokens } from "../../lib/token-estimate";
|
|
3
|
+
import {
|
|
4
|
+
formatChatGptWebMultipartCommit,
|
|
5
|
+
formatChatGptWebMultipartStage,
|
|
6
|
+
type CompiledChatGptWebPrompt,
|
|
7
|
+
} from "./prompt";
|
|
8
|
+
|
|
9
|
+
// ChatGPT's product system prompt and the fixed Codex Native MCP schemas are not present in the
|
|
10
|
+
// visible composer text. Reserve them explicitly; over-counting fails safe by compacting earlier.
|
|
11
|
+
const CHATGPT_IMAGE_RESERVE_TOKENS = 4_096;
|
|
12
|
+
const CHATGPT_ORIGINAL_IMAGE_RESERVE_TOKENS = 8_192;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The Free/Luna product accepted measured browser inputs at 25,400 and 28,547 estimated tokens,
|
|
16
|
+
* but rejected the same shape at 32,283 before producing a response. This is a ChatGPT browser
|
|
17
|
+
* transport boundary, not Luna's model context window, and applies to normal and checkpoint turns.
|
|
18
|
+
*/
|
|
19
|
+
export const CHATGPT_LUNA_BROWSER_INPUT_TOKEN_BUDGET = 128_000;
|
|
20
|
+
|
|
21
|
+
const TOKEN_ESTIMATE_TRANSACTION = `ctx_${"0".repeat(32)}`;
|
|
22
|
+
|
|
23
|
+
export function compiledChatGptWebMessages(compiled: CompiledChatGptWebPrompt): string[] {
|
|
24
|
+
if (!compiled.multipart) return [compiled.text];
|
|
25
|
+
return [
|
|
26
|
+
...compiled.multipart.parts.slice(0, -1).map((payload, index) => (
|
|
27
|
+
formatChatGptWebMultipartStage(
|
|
28
|
+
payload,
|
|
29
|
+
TOKEN_ESTIMATE_TRANSACTION,
|
|
30
|
+
index + 1,
|
|
31
|
+
compiled.multipart!.parts.length,
|
|
32
|
+
).text
|
|
33
|
+
)),
|
|
34
|
+
formatChatGptWebMultipartCommit(compiled.multipart, TOKEN_ESTIMATE_TRANSACTION),
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function compiledChatGptWebMaxMessageChars(compiled: CompiledChatGptWebPrompt): number {
|
|
39
|
+
return Math.max(...compiledChatGptWebMessages(compiled).map(message => message.length));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Tokens present in the one visible browser message, excluding hidden product/tool reserves. */
|
|
43
|
+
export function estimateCompiledChatGptWebMessageTokens(
|
|
44
|
+
compiled: CompiledChatGptWebPrompt,
|
|
45
|
+
modelId: string,
|
|
46
|
+
): number {
|
|
47
|
+
return Math.max(...compiledChatGptWebMessages(compiled).map(message => estimateTokens(message, modelId)));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function estimateCompiledChatGptWebInputTokens(
|
|
51
|
+
compiled: CompiledChatGptWebPrompt,
|
|
52
|
+
modelId: string,
|
|
53
|
+
): number {
|
|
54
|
+
const imageTokens = compiled.images.reduce(
|
|
55
|
+
(total, image) => total + (image.detail === "original"
|
|
56
|
+
? CHATGPT_ORIGINAL_IMAGE_RESERVE_TOKENS
|
|
57
|
+
: CHATGPT_IMAGE_RESERVE_TOKENS),
|
|
58
|
+
0,
|
|
59
|
+
);
|
|
60
|
+
const messageTokens = compiledChatGptWebMessages(compiled)
|
|
61
|
+
.reduce((total, message) => total + estimateTokens(message, modelId), 0);
|
|
62
|
+
const acknowledgementTokens = compiled.multipart
|
|
63
|
+
? compiled.multipart.parts.slice(0, -1).reduce((total, payload, index) => total + estimateTokens(
|
|
64
|
+
formatChatGptWebMultipartStage(
|
|
65
|
+
payload,
|
|
66
|
+
TOKEN_ESTIMATE_TRANSACTION,
|
|
67
|
+
index + 1,
|
|
68
|
+
compiled.multipart!.parts.length,
|
|
69
|
+
).acknowledgement,
|
|
70
|
+
modelId,
|
|
71
|
+
), 0)
|
|
72
|
+
: 0;
|
|
73
|
+
return CHATGPT_WEB_PLATFORM_RESERVE_TOKENS + messageTokens + acknowledgementTokens + imageTokens;
|
|
74
|
+
}
|