@herbertgao/pi-extensions 2026.11.2 → 2026.11.4
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 +19 -0
- package/README.md +13 -13
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +109 -16
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +33 -5
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +72 -17
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/write-execution.ts +5 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-io.ts +16 -7
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +7 -5
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-dark-hc.json +92 -0
- package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-light-hc.json +92 -0
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/README.md +12 -10
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-record-entry.ts +22 -6
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +9 -4
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +167 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/viewer-keys.ts +8 -4
- package/node_modules/@narumitw/pi-btw/CHANGELOG.md +259 -0
- package/node_modules/@narumitw/pi-btw/package.json +6 -5
- package/node_modules/@narumitw/pi-caffeinate/CHANGELOG.md +70 -0
- package/node_modules/@narumitw/pi-caffeinate/package.json +5 -4
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +48 -0
- package/node_modules/pi-commandcode-provider/CONTRIBUTING.md +64 -5
- package/node_modules/pi-commandcode-provider/README.md +44 -18
- package/node_modules/pi-commandcode-provider/RELEASE.md +25 -0
- package/node_modules/pi-commandcode-provider/index.ts +222 -42
- package/node_modules/pi-commandcode-provider/package.json +9 -8
- package/node_modules/pi-commandcode-provider/scripts/live-e2e-profile.mjs +6 -13
- package/node_modules/pi-commandcode-provider/scripts/typecheck-entrypoint.mjs +88 -0
- package/node_modules/pi-commandcode-provider/src/api-key.ts +67 -10
- package/node_modules/pi-commandcode-provider/src/auth-server.ts +33 -24
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog-overrides.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
- package/node_modules/pi-commandcode-provider/src/cost.ts +29 -43
- package/node_modules/pi-commandcode-provider/src/diagnostics.ts +215 -0
- package/node_modules/pi-commandcode-provider/src/oauth.ts +41 -7
- package/node_modules/pi-commandcode-provider/src/pricing.ts +5 -3
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +1 -1
- package/node_modules/pi-commandcode-provider/src/routing.ts +166 -0
- package/node_modules/pi-commandcode-provider/src/runtime.ts +23 -10
- package/node_modules/pi-commandcode-provider/src/transport.ts +82 -85
- package/node_modules/pi-commandcode-provider/src/types.ts +20 -39
- package/node_modules/pi-commandcode-provider/src/usage.ts +1 -1
- package/node_modules/pi-lens/CHANGELOG-USER.md +31 -0
- package/node_modules/pi-lens/CHANGELOG.md +178 -0
- package/node_modules/pi-lens/README.md +2 -1
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +1 -1
- package/node_modules/pi-lens/dist/{chunk-3O5EII3W.js → chunk-2VZ3VN3N.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SDFKOLSF.js → chunk-3HTZDY3C.js} +8 -6
- package/node_modules/pi-lens/dist/{chunk-A5GRLYPZ.js → chunk-3NPWO5UO.js} +7 -13
- package/node_modules/pi-lens/dist/{chunk-AGGUWKRK.js → chunk-47UCC4MM.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-4ENEJHF4.js +198 -0
- package/node_modules/pi-lens/dist/{chunk-WXUDRAG6.js → chunk-5GEYJJHG.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-HHR7WGCI.js → chunk-5YSEQHJN.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-L3CLUGDY.js → chunk-6GPB3JLL.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-5F3XF3SX.js → chunk-7R5GZIA6.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-CUDD35TW.js → chunk-7UTSNTWM.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-DYRZGUMA.js → chunk-7YTRG6YW.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-JZRP4DGP.js → chunk-AACN5GNE.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-7ANZ7XDD.js → chunk-ACRJ2GZ5.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-6FIRFP6A.js → chunk-C3YRO3EU.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-GMROJJRN.js → chunk-CB7PEVOJ.js} +9 -1
- package/node_modules/pi-lens/dist/{chunk-BBET6HD6.js → chunk-CDFJF5YD.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-NSPVR3FN.js → chunk-CJS6WE66.js} +17 -19
- package/node_modules/pi-lens/dist/{chunk-6YUNI7B5.js → chunk-CM6BDY4E.js} +14 -60
- package/node_modules/pi-lens/dist/{chunk-G5GV2Q7K.js → chunk-CZCAZVTD.js} +16 -2
- package/node_modules/pi-lens/dist/chunk-DGKFWQK4.js +23 -0
- package/node_modules/pi-lens/dist/{chunk-VOP4PJKA.js → chunk-E65WJVI5.js} +7 -9
- package/node_modules/pi-lens/dist/{chunk-TV6RXRYH.js → chunk-EKNYSXFB.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-4LL2VRNY.js → chunk-EY6LY2HO.js} +16 -18
- package/node_modules/pi-lens/dist/{chunk-MC6VB2E5.js → chunk-F6BEQWAK.js} +17 -5
- package/node_modules/pi-lens/dist/{chunk-R2QQC33W.js → chunk-FGNSESAC.js} +12 -14
- package/node_modules/pi-lens/dist/{chunk-OC7VWJBZ.js → chunk-FRUBVFXV.js} +35 -37
- package/node_modules/pi-lens/dist/{chunk-7CGIDRIK.js → chunk-G22UNQID.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-L4NEVZ4T.js → chunk-GQTQUNCG.js} +25 -27
- package/node_modules/pi-lens/dist/{chunk-ZKLTNLAW.js → chunk-H3BVMK47.js} +6 -6
- package/node_modules/pi-lens/dist/chunk-H6FLQ5NW.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-2ZE3AUJQ.js → chunk-HEA3EM23.js} +13 -15
- package/node_modules/pi-lens/dist/{chunk-CZL44WFN.js → chunk-HSOBIN22.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-PKSUMEPT.js → chunk-HYSKJMZK.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-VN3L2JWZ.js → chunk-IICERRFF.js} +5 -5
- package/node_modules/pi-lens/dist/{chunk-O4N5BQ3T.js → chunk-IILEH3ZC.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-WC6WRNQT.js → chunk-J3Q2NYJR.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-SFLHSL5R.js → chunk-JUZ67QZQ.js} +18 -7
- package/node_modules/pi-lens/dist/chunk-KR5VGMVT.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-UHHLR2VY.js → chunk-KV6GQOGN.js} +38 -41
- package/node_modules/pi-lens/dist/{chunk-HUAM7QG3.js → chunk-KXMJLOZF.js} +25 -23
- package/node_modules/pi-lens/dist/{chunk-BUZIQDFS.js → chunk-L4Y3ROKQ.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-JBP7KESM.js → chunk-L6WBJGQS.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-35WKJWO5.js → chunk-L7O774U7.js} +14 -14
- package/node_modules/pi-lens/dist/{chunk-BOPDQ7AZ.js → chunk-LAHHGNAY.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-RGGH6M34.js → chunk-LT62P654.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-5T5A6YAJ.js → chunk-LWOM6LVS.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-JYLOYTZD.js → chunk-MKPDIAZH.js} +5 -1
- package/node_modules/pi-lens/dist/{chunk-CM73PPGD.js → chunk-MN635QYA.js} +3 -4
- package/node_modules/pi-lens/dist/{chunk-BQG2QFVO.js → chunk-MQ4PPCJB.js} +21 -29
- package/node_modules/pi-lens/dist/{chunk-HXFUTMX2.js → chunk-MRLH4MYU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-XOMGO63G.js → chunk-N56BNAA6.js} +19 -21
- package/node_modules/pi-lens/dist/{chunk-7MAD5ZAY.js → chunk-N5CEGQPG.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-ZFORSIED.js → chunk-NCLO6E6N.js} +13 -33
- package/node_modules/pi-lens/dist/{chunk-SQC7K3SP.js → chunk-NL5LSKVD.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-I22THIHI.js → chunk-NMUSOZ2D.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-4NBWFYWW.js → chunk-NOWH2VA2.js} +8 -33
- package/node_modules/pi-lens/dist/{chunk-NM2NWH55.js → chunk-NUSXS6YB.js} +6 -5
- package/node_modules/pi-lens/dist/{chunk-OZWXLJMX.js → chunk-OSEKJEUU.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-2BKUFQKR.js → chunk-OUYAUXAT.js} +405 -181
- package/node_modules/pi-lens/dist/{chunk-JPRDTY5S.js → chunk-PBZNYHMM.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-JE6HKLC7.js → chunk-PIIUNJIT.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-ZZDIOAAJ.js → chunk-PRHYIA6X.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-4W52ZKZX.js → chunk-PXQ45SGD.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-Q6JQKWPK.js +25 -0
- package/node_modules/pi-lens/dist/{chunk-PIQQM32Y.js → chunk-QB7T2PHK.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-HKIL6DCL.js → chunk-QGITU23N.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-QJJKOHLH.js +57 -0
- package/node_modules/pi-lens/dist/{chunk-6LJOJ6EO.js → chunk-QP33NKYC.js} +14 -16
- package/node_modules/pi-lens/dist/{chunk-DIWK3LBC.js → chunk-QVBOXT3L.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-IYVYZQRL.js → chunk-RNJFRXEN.js} +5 -7
- package/node_modules/pi-lens/dist/{chunk-G6JKM4O7.js → chunk-RNXOWDM6.js} +10 -10
- package/node_modules/pi-lens/dist/{chunk-5RNB4HVK.js → chunk-RTFMDIKV.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-XWIME22V.js → chunk-SIQHOB6P.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-T2S3FNNJ.js → chunk-SLSMJPEF.js} +41 -42
- package/node_modules/pi-lens/dist/chunk-T5QSLSMM.js +50 -0
- package/node_modules/pi-lens/dist/chunk-TGQDAG4B.js +88 -0
- package/node_modules/pi-lens/dist/{chunk-6GMGEKQN.js → chunk-THYHUIDR.js} +39 -12
- package/node_modules/pi-lens/dist/{chunk-WMDUT4KH.js → chunk-TMNUTMT5.js} +72 -89
- package/node_modules/pi-lens/dist/{chunk-7TNILKGY.js → chunk-TOE2RRCS.js} +1 -1
- package/node_modules/pi-lens/dist/chunk-TYHPVE5H.js +25 -0
- package/node_modules/pi-lens/dist/chunk-UAKO2M6B.js +73 -0
- package/node_modules/pi-lens/dist/chunk-UC5AXW5Z.js +20 -0
- package/node_modules/pi-lens/dist/chunk-UTJP6WOS.js +28 -0
- package/node_modules/pi-lens/dist/{chunk-FRLAUP2B.js → chunk-UXTQ3QPD.js} +4 -4
- package/node_modules/pi-lens/dist/{chunk-4QG55RRC.js → chunk-V2WDBOLZ.js} +10 -12
- package/node_modules/pi-lens/dist/{chunk-FHEV6T4L.js → chunk-V67D6TMU.js} +8 -10
- package/node_modules/pi-lens/dist/{chunk-VLQ7UKZH.js → chunk-VCRVNLE7.js} +135 -2
- package/node_modules/pi-lens/dist/{chunk-KZ4ALBCH.js → chunk-VO4JFPTV.js} +2 -2
- package/node_modules/pi-lens/dist/{chunk-GIRBSBGL.js → chunk-VWLSU3XV.js} +3 -3
- package/node_modules/pi-lens/dist/{chunk-2453RRJ2.js → chunk-W5E72HJA.js} +59 -22
- package/node_modules/pi-lens/dist/{chunk-VPLBLWFO.js → chunk-W7TY6HYX.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-SP4TFY5F.js → chunk-WSSLVMDA.js} +11 -13
- package/node_modules/pi-lens/dist/{chunk-PPKECBPP.js → chunk-WTB4GKMH.js} +10 -1
- package/node_modules/pi-lens/dist/{chunk-X35S7HSB.js → chunk-X5BJ3G2P.js} +41 -30
- package/node_modules/pi-lens/dist/{chunk-X66YJ2SS.js → chunk-XKFO2SZV.js} +33 -34
- package/node_modules/pi-lens/dist/{chunk-OWTG6UMO.js → chunk-XLAI7UYY.js} +75 -22
- package/node_modules/pi-lens/dist/{chunk-4B2YFN4U.js → chunk-XO756WE5.js} +45 -33
- package/node_modules/pi-lens/dist/{chunk-VOXTCULR.js → chunk-XVB3Q2PG.js} +2 -4
- package/node_modules/pi-lens/dist/{chunk-XYLC35E4.js → chunk-YOXCCJDF.js} +517 -308
- package/node_modules/pi-lens/dist/{chunk-O2ARHQKF.js → chunk-ZCQBNPRH.js} +2 -2
- package/node_modules/pi-lens/dist/chunk-ZD4KVFXI.js +234 -0
- package/node_modules/pi-lens/dist/{chunk-LSFXZLPW.js → chunk-ZDMFGACN.js} +184 -235
- package/node_modules/pi-lens/dist/{chunk-4BKU7PV3.js → chunk-ZMMHHXSW.js} +1 -1
- package/node_modules/pi-lens/dist/{chunk-OY7WZI7Q.js → chunk-ZPM7ZIFL.js} +6 -6
- package/node_modules/pi-lens/dist/{chunk-R4QWJQ2H.js → chunk-ZVCDHYWZ.js} +9 -11
- package/node_modules/pi-lens/dist/{chunk-RZG472YW.js → chunk-ZZN74OGD.js} +83 -46
- package/node_modules/pi-lens/dist/{chunk-BHWW6FAX.js → chunk-ZZSJAR76.js} +37 -19
- package/node_modules/pi-lens/dist/index.js +4910 -4218
- package/node_modules/pi-lens/dist/mcp/analyze-cli.js +12 -17
- package/node_modules/pi-lens/dist/mcp/cli.js +41 -42
- package/node_modules/pi-lens/dist/mcp/server.js +1451 -648
- package/node_modules/pi-lens/dist/mcp/worker.js +59 -60
- package/node_modules/pi-lens/dist/probes/installer.js +17 -19
- package/node_modules/pi-lens/docs/agent-tools.md +40 -8
- package/node_modules/pi-lens/docs/analysisall.md +1 -1
- package/node_modules/pi-lens/docs/ci-bot-pr-checks.md +7 -5
- package/node_modules/pi-lens/docs/configuration.md +51 -9
- package/node_modules/pi-lens/docs/defect-shapes.md +52 -3
- package/node_modules/pi-lens/docs/environment-variables.md +18 -1
- package/node_modules/pi-lens/docs/features.md +12 -5
- package/node_modules/pi-lens/docs/globalconfig.md +11 -3
- package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +9 -2
- package/node_modules/pi-lens/docs/invariants/session-telemetry.md +2 -2
- package/node_modules/pi-lens/docs/language-coverage.md +1 -0
- package/node_modules/pi-lens/docs/lsp-capability-matrix.md +57 -35
- package/node_modules/pi-lens/docs/lsp-idle-eviction.md +4 -1
- package/node_modules/pi-lens/docs/merge-queue-rollout.md +10 -8
- package/node_modules/pi-lens/docs/module-report-read-symbol.md +34 -23
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +11 -1
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +3 -0
- package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +15 -7
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +1 -1
- package/node_modules/pi-lens/docs/pi-lens-subagent.md +13 -0
- package/node_modules/pi-lens/docs/public-api-stability.md +39 -5
- package/node_modules/pi-lens/docs/release-qa-baseline.md +7 -4
- package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +11 -2
- package/node_modules/pi-lens/docs/servercapabilities.md +3 -1
- package/node_modules/pi-lens/docs/settings.md +2 -2
- package/node_modules/pi-lens/docs/word-index.md +3 -2
- package/node_modules/pi-lens/package.json +8 -3
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute-js.yml +1 -2
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-sql-in-code-execute.yml +1 -2
- package/node_modules/pi-lens/scripts/download-grammars.js +3 -2
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +5 -1
- package/node_modules/pi-provider-qoder/dist/index.js +473 -62
- package/node_modules/pi-provider-qoder/package.json +1 -1
- package/node_modules/pi-web-access/CHANGELOG.md +22 -0
- package/node_modules/pi-web-access/README.md +31 -12
- package/node_modules/pi-web-access/curator-page.ts +5 -1
- package/node_modules/pi-web-access/curator-server.ts +2 -0
- package/node_modules/pi-web-access/dist/index.js +673 -308
- package/node_modules/pi-web-access/dist/mcp-cli.js +666 -309
- package/node_modules/pi-web-access/gemini-search.ts +12 -4
- package/node_modules/pi-web-access/github-api.ts +1 -1
- package/node_modules/pi-web-access/github-extract.ts +3 -2
- package/node_modules/pi-web-access/index.ts +7 -3
- package/node_modules/pi-web-access/mcp-tool-definitions.ts +1 -1
- package/node_modules/pi-web-access/outcrawl.ts +204 -0
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/pi-web-access/sofya.ts +201 -0
- package/node_modules/pi-web-access/utils.ts +16 -6
- package/node_modules/pi-web-access/web-tool-core.ts +4 -0
- package/package.json +16 -14
- package/node_modules/pi-commandcode-provider/src/converters.ts +0 -477
- package/node_modules/pi-commandcode-provider/src/core.ts +0 -836
- package/node_modules/pi-commandcode-provider/src/json-schema.ts +0 -417
- package/node_modules/pi-commandcode-provider/src/transcript.ts +0 -56
- package/node_modules/pi-lens/dist/chunk-2TS4GLOJ.js +0 -31
- package/node_modules/pi-lens/dist/chunk-3JAHQBSY.js +0 -27
- package/node_modules/pi-lens/dist/chunk-447YZL4S.js +0 -25
- package/node_modules/pi-lens/dist/chunk-565VRUP4.js +0 -136
- package/node_modules/pi-lens/dist/chunk-57X2CDRX.js +0 -49
- package/node_modules/pi-lens/dist/chunk-GGYOZWHW.js +0 -27
- package/node_modules/pi-lens/dist/chunk-IE5D3RA5.js +0 -58
- package/node_modules/pi-lens/dist/chunk-LPYTPNOJ.js +0 -22
- package/node_modules/pi-lens/dist/chunk-OFNMHPBT.js +0 -89
- package/node_modules/pi-lens/dist/chunk-U3AS2FR6.js +0 -106
- package/node_modules/pi-lens/dist/chunk-W3BGKBBK.js +0 -27
- package/node_modules/pi-lens/dist/chunk-WQV6BI4Q.js +0 -48
- package/node_modules/pi-lens/dist/chunk-YHGYAEFH.js +0 -443
- package/node_modules/pi-lens/dist/chunk-ZONZ6YY3.js +0 -74
- package/node_modules/pi-lens/dist/chunk-ZSM35JF4.js +0 -30
|
@@ -10,10 +10,17 @@ function stringValue(value: unknown): string | undefined {
|
|
|
10
10
|
return typeof value === "string" ? value : undefined
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Credential files consulted after the environment, in precedence order (also
|
|
15
|
+
* documented in README.md). pi honors `PI_CODING_AGENT_DIR` for its agent
|
|
16
|
+
* directory, so a profile started with that variable must not fall back to the
|
|
17
|
+
* default `~/.pi/agent/auth.json` of another profile.
|
|
18
|
+
*/
|
|
19
|
+
export function defaultAuthPaths(home: string, env: NodeJS.ProcessEnv = process.env): string[] {
|
|
20
|
+
const piAgentDir = env.PI_CODING_AGENT_DIR || join(home, ".pi", "agent")
|
|
14
21
|
return [
|
|
15
22
|
join(home, ".commandcode", "auth.json"),
|
|
16
|
-
join(
|
|
23
|
+
join(piAgentDir, "auth.json"),
|
|
17
24
|
join(home, ".omp", "agent", "auth.json"),
|
|
18
25
|
]
|
|
19
26
|
}
|
|
@@ -26,19 +33,25 @@ function apiKeyFromCredential(value: unknown): string | undefined {
|
|
|
26
33
|
return stringValue(value.access) ?? stringValue(value.key)
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
export interface ApiKeyLookupOptions {
|
|
37
|
+
env?: NodeJS.ProcessEnv
|
|
38
|
+
authPaths?: readonly string[]
|
|
39
|
+
homeDir?: () => string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The single credential reader shared by the Provider API path and the
|
|
44
|
+
* quota/usage commands: environment first, then the auth
|
|
45
|
+
* files above. Hosts resolve their own stored credentials before this runs;
|
|
46
|
+
* this is the ambient fallback for keys they do not know about.
|
|
47
|
+
*/
|
|
48
|
+
export function getConfiguredApiKey(options: ApiKeyLookupOptions = {}): string | undefined {
|
|
36
49
|
const env = options.env ?? process.env
|
|
37
50
|
if (env.COMMAND_CODE_API_KEY) return env.COMMAND_CODE_API_KEY
|
|
38
51
|
if (env.COMMANDCODE_API_KEY) return env.COMMANDCODE_API_KEY
|
|
39
52
|
|
|
40
53
|
const home = options.homeDir?.() ?? homedir()
|
|
41
|
-
const authPaths = options.authPaths ?? defaultAuthPaths(home)
|
|
54
|
+
const authPaths = options.authPaths ?? defaultAuthPaths(home, env)
|
|
42
55
|
|
|
43
56
|
for (const authPath of authPaths) {
|
|
44
57
|
try {
|
|
@@ -46,9 +59,12 @@ export function getConfiguredApiKey(
|
|
|
46
59
|
const parsed: unknown = JSON.parse(readFileSync(authPath, "utf-8"))
|
|
47
60
|
if (!isRecord(parsed)) continue
|
|
48
61
|
|
|
62
|
+
// Legacy: direct apiKey or commandcode field.
|
|
49
63
|
const apiKey = stringValue(parsed.apiKey)
|
|
50
64
|
if (apiKey) return apiKey
|
|
51
65
|
|
|
66
|
+
// pi stores OAuth credentials as {"commandcode": {"type":"oauth","access":"..."}}.
|
|
67
|
+
// The official Command Code CLI stores API credentials under "command-code".
|
|
52
68
|
const commandcode = stringValue(parsed.commandcode)
|
|
53
69
|
if (commandcode) return commandcode
|
|
54
70
|
|
|
@@ -67,3 +83,44 @@ export function getConfiguredApiKey(
|
|
|
67
83
|
|
|
68
84
|
return undefined
|
|
69
85
|
}
|
|
86
|
+
|
|
87
|
+
// Hosts such as OMP may pass a literal env-var name as the "resolved" registry
|
|
88
|
+
// key instead of the actual credential. Treat those as unresolved.
|
|
89
|
+
export const COMMAND_CODE_PLACEHOLDER_KEYS = new Set([
|
|
90
|
+
"$COMMAND_CODE_API_KEY",
|
|
91
|
+
"COMMAND_CODE_API_KEY",
|
|
92
|
+
"$COMMANDCODE_API_KEY",
|
|
93
|
+
"COMMANDCODE_API_KEY",
|
|
94
|
+
])
|
|
95
|
+
|
|
96
|
+
function usableCommandCodeApiKey(value: string | undefined): string | undefined {
|
|
97
|
+
const trimmed = typeof value === "string" ? value.trim() : undefined
|
|
98
|
+
if (!trimmed) return undefined
|
|
99
|
+
if (COMMAND_CODE_PLACEHOLDER_KEYS.has(trimmed)) return undefined
|
|
100
|
+
return trimmed
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Pick the real API key from a host registry value and/or the env/auth-file
|
|
105
|
+
* fallback, never returning a literal placeholder or an empty/whitespace value.
|
|
106
|
+
* Pure/testable.
|
|
107
|
+
*/
|
|
108
|
+
export function pickCommandCodeApiKey(
|
|
109
|
+
registryKey: string | undefined,
|
|
110
|
+
hostKey: string | undefined,
|
|
111
|
+
): string | undefined {
|
|
112
|
+
return usableCommandCodeApiKey(registryKey) ?? usableCommandCodeApiKey(hostKey)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Replace a host-supplied placeholder (or missing key) with the configured
|
|
117
|
+
* fallback. Used for both registerProvider and the Provider API stream path.
|
|
118
|
+
*/
|
|
119
|
+
export function withResolvedCommandCodeApiKey<T extends { apiKey?: string }>(
|
|
120
|
+
options: T | undefined,
|
|
121
|
+
configuredKey: string | undefined,
|
|
122
|
+
): T | { apiKey?: string } {
|
|
123
|
+
const apiKey = pickCommandCodeApiKey(options?.apiKey, configuredKey)
|
|
124
|
+
if (options && apiKey === options.apiKey) return options
|
|
125
|
+
return { ...options, apiKey }
|
|
126
|
+
}
|
|
@@ -11,6 +11,10 @@ import type { AddressInfo } from "node:net"
|
|
|
11
11
|
const DEFAULT_PORT = 5959
|
|
12
12
|
const DEFAULT_PORT_RANGE = 10
|
|
13
13
|
|
|
14
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export interface AuthCallback {
|
|
15
19
|
apiKey: string
|
|
16
20
|
state: string
|
|
@@ -92,13 +96,10 @@ export async function startAuthServer(options: AuthServerOptions = {}): Promise<
|
|
|
92
96
|
})
|
|
93
97
|
|
|
94
98
|
const server = createServer((req, res) => {
|
|
95
|
-
// CORS: allow requests from Command Code
|
|
99
|
+
// CORS: allow requests from the Command Code Studio origins only. A local
|
|
100
|
+
// development origin would let any page on that port reach the callback.
|
|
96
101
|
const origin = req.headers.origin || ""
|
|
97
|
-
const allowedOrigins = [
|
|
98
|
-
"http://localhost:3000",
|
|
99
|
-
"https://staging.commandcode.ai",
|
|
100
|
-
"https://commandcode.ai",
|
|
101
|
-
]
|
|
102
|
+
const allowedOrigins = ["https://commandcode.ai", "https://staging.commandcode.ai"]
|
|
102
103
|
// CORS response headers do not prevent cross-origin POST side effects.
|
|
103
104
|
// Reject untrusted browser origins before handling the callback.
|
|
104
105
|
if (origin && !allowedOrigins.includes(origin)) {
|
|
@@ -155,29 +156,43 @@ export async function startAuthServer(options: AuthServerOptions = {}): Promise<
|
|
|
155
156
|
|
|
156
157
|
req.on("end", () => {
|
|
157
158
|
try {
|
|
158
|
-
const
|
|
159
|
+
const payload: unknown = JSON.parse(body)
|
|
160
|
+
if (!isRecord(payload)) {
|
|
161
|
+
res.writeHead(400)
|
|
162
|
+
res.end(JSON.stringify({ success: false, error: "Invalid JSON" }))
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
const state = typeof payload.state === "string" ? payload.state : ""
|
|
159
166
|
|
|
160
|
-
|
|
167
|
+
// Only the page that received the state token may settle this login,
|
|
168
|
+
// including by reporting an error. Anything else keeps the server
|
|
169
|
+
// waiting for the legitimate callback.
|
|
170
|
+
if (options.expectedState !== undefined && state !== options.expectedState) {
|
|
171
|
+
res.writeHead(403)
|
|
172
|
+
res.end(JSON.stringify({ success: false, error: "Invalid state token" }))
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (payload.error) {
|
|
161
177
|
res.writeHead(200)
|
|
162
178
|
res.end(JSON.stringify({ success: true }))
|
|
163
179
|
const description =
|
|
164
|
-
typeof
|
|
165
|
-
?
|
|
166
|
-
: String(
|
|
167
|
-
if (
|
|
180
|
+
typeof payload.error_description === "string"
|
|
181
|
+
? payload.error_description
|
|
182
|
+
: String(payload.error)
|
|
183
|
+
if (payload.error === "access_denied") {
|
|
168
184
|
rejectCallback(new Error(description || "Authorization was denied by the user"))
|
|
169
185
|
} else {
|
|
170
|
-
rejectCallback(new Error(description || String(
|
|
186
|
+
rejectCallback(new Error(description || String(payload.error)))
|
|
171
187
|
}
|
|
172
188
|
closeServer(server)
|
|
173
189
|
return
|
|
174
190
|
}
|
|
175
191
|
|
|
176
|
-
const apiKey = typeof
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
const keyName = typeof parsed.keyName === "string" ? parsed.keyName : ""
|
|
192
|
+
const apiKey = typeof payload.apiKey === "string" ? payload.apiKey : ""
|
|
193
|
+
const userId = typeof payload.userId === "string" ? payload.userId : ""
|
|
194
|
+
const userName = typeof payload.userName === "string" ? payload.userName : ""
|
|
195
|
+
const keyName = typeof payload.keyName === "string" ? payload.keyName : ""
|
|
181
196
|
|
|
182
197
|
if (!apiKey || !state || !userId || !userName || !keyName) {
|
|
183
198
|
res.writeHead(400)
|
|
@@ -190,12 +205,6 @@ export async function startAuthServer(options: AuthServerOptions = {}): Promise<
|
|
|
190
205
|
return
|
|
191
206
|
}
|
|
192
207
|
|
|
193
|
-
if (options.expectedState !== undefined && state !== options.expectedState) {
|
|
194
|
-
res.writeHead(403)
|
|
195
|
-
res.end(JSON.stringify({ success: false, error: "Invalid state token" }))
|
|
196
|
-
return
|
|
197
|
-
}
|
|
198
|
-
|
|
199
208
|
res.writeHead(200)
|
|
200
209
|
res.end(JSON.stringify({ success: true }))
|
|
201
210
|
|
|
@@ -11,7 +11,7 @@ import type { CommandCodeReasoningEffort } from "./commandcode-catalog.ts"
|
|
|
11
11
|
* be removed by hand.
|
|
12
12
|
*
|
|
13
13
|
* An entry only takes effect for a model the generated catalog already marks as
|
|
14
|
-
* reasoning-capable:
|
|
14
|
+
* reasoning-capable: native hosts omit reasoning options when `model.reasoning`
|
|
15
15
|
* is false, and a model missing from `MODEL_REASONING` stays false. Upstream emits
|
|
16
16
|
* the flag whenever it emits efforts, so a sync that brings in new efforts brings
|
|
17
17
|
* the flag with it.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const COMMAND_CODE_CLI_VERSION = "1.88.
|
|
1
|
+
export const COMMAND_CODE_CLI_VERSION = "1.88.3"
|
|
2
2
|
|
|
3
3
|
export type CommandCodeInputType = "text" | "image"
|
|
4
4
|
export type CommandCodeReasoningEffort =
|
|
@@ -11,7 +11,7 @@ export type CommandCodeReasoningEffort =
|
|
|
11
11
|
| "max"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Generated from command-code@1.88.
|
|
14
|
+
* Generated from command-code@1.88.3 by `npm run sync:commandcode-catalog`.
|
|
15
15
|
* Do not edit manually.
|
|
16
16
|
*/
|
|
17
17
|
export const MODEL_INPUT_MODALITIES: Readonly<Record<string, readonly CommandCodeInputType[]>> = {
|
|
@@ -76,6 +76,7 @@ export const MODEL_INPUT_MODALITIES: Readonly<Record<string, readonly CommandCod
|
|
|
76
76
|
"Qwen/Qwen3.8-Max-Prime": ["text", "image"],
|
|
77
77
|
"Qwen/Qwen3.8-Omni-Flash": ["text", "image"],
|
|
78
78
|
"sakana/fugu-ultra": ["text", "image"],
|
|
79
|
+
"stealth/crouton-alpha": ["text", "image"],
|
|
79
80
|
"stepfun/Step-3.7-Flash": ["text", "image"],
|
|
80
81
|
"stepfun/Step-5-Preview": ["text", "image"],
|
|
81
82
|
"thinkingmachines/inkling": ["text", "image"],
|
|
@@ -127,6 +128,7 @@ export const MODEL_REASONING: Readonly<Record<string, true>> = {
|
|
|
127
128
|
"gpt-6.1-sol": true,
|
|
128
129
|
"gpt-6.1-terra": true,
|
|
129
130
|
"inclusionai/ling-3.1-flash": true,
|
|
131
|
+
"inclusionai/ling-3.1-flash-1019": true,
|
|
130
132
|
"meituan/LongCat-2.0": true,
|
|
131
133
|
"meta/muse-spark-1.1": true,
|
|
132
134
|
"meta/muse-spark-1.2": true,
|
|
@@ -159,6 +161,7 @@ export const MODEL_REASONING: Readonly<Record<string, true>> = {
|
|
|
159
161
|
"Qwen/Qwen3.8-Omni-Flash": true,
|
|
160
162
|
"reflection/beam:free": true,
|
|
161
163
|
"sakana/fugu-ultra": true,
|
|
164
|
+
"stealth/crouton-alpha": true,
|
|
162
165
|
"stealth/glyph-cluster:free": true,
|
|
163
166
|
"stepfun/Step-3.5-Flash": true,
|
|
164
167
|
"stepfun/Step-3.7-Flash": true,
|
|
@@ -213,6 +216,7 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
213
216
|
"gpt-6.1-sol": ["low", "medium", "high", "xhigh", "max"],
|
|
214
217
|
"gpt-6.1-terra": ["low", "medium", "high", "xhigh", "max"],
|
|
215
218
|
"inclusionai/ling-3.1-flash": ["low", "medium", "high"],
|
|
219
|
+
"inclusionai/ling-3.1-flash-1019": ["low", "medium", "high"],
|
|
216
220
|
"meta/muse-spark-1.1": ["low", "medium", "high", "xhigh"],
|
|
217
221
|
"meta/muse-spark-1.2": ["low", "medium", "high", "xhigh"],
|
|
218
222
|
"meta/muse-spark-1.2-contributor": ["low", "medium", "high", "xhigh"],
|
|
@@ -234,6 +238,7 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
234
238
|
"Qwen/Qwen3.8-Omni-Flash": ["low", "medium", "xhigh"],
|
|
235
239
|
"reflection/beam:free": ["low", "medium", "high", "xhigh", "max"],
|
|
236
240
|
"sakana/fugu-ultra": ["high", "xhigh"],
|
|
241
|
+
"stealth/crouton-alpha": ["low", "medium", "high", "xhigh", "max"],
|
|
237
242
|
"stealth/glyph-cluster:free": ["low", "medium", "high", "xhigh"],
|
|
238
243
|
"stepfun/Step-5-Preview": ["low", "medium", "high"],
|
|
239
244
|
"tencent/hy4-preview": ["low", "medium", "high"],
|
|
@@ -248,12 +253,14 @@ export const MODEL_EFFORTS: Readonly<Record<string, readonly CommandCodeReasonin
|
|
|
248
253
|
|
|
249
254
|
export const MODEL_MAX_OUTPUT_TOKENS: Readonly<Record<string, number>> = {
|
|
250
255
|
"inclusionai/ling-3.1-flash": 32_768,
|
|
256
|
+
"inclusionai/ling-3.1-flash-1019": 262_144,
|
|
251
257
|
"mistral/mistral-large-4": 262_144,
|
|
252
258
|
"poolside/laguna-s-2.1-free": 32_768,
|
|
253
259
|
"Qwen/Qwen3.8-27B": 32_768,
|
|
254
260
|
"Qwen/Qwen3.8-Max-Prime": 131_072,
|
|
255
261
|
"Qwen/Qwen3.8-Omni-Flash": 131_072,
|
|
256
262
|
"reflection/beam:free": 131_072,
|
|
263
|
+
"stealth/crouton-alpha": 943_718,
|
|
257
264
|
"stealth/glyph-cluster:free": 256_000,
|
|
258
265
|
"z-ai/glm-5.3-flash": 131_072,
|
|
259
266
|
"z-ai/glm-5.3-flashx": 131_072,
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local cost calculation for Command Code usage.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors pi-ai's `calculateCost` arithmetic exactly. The provider ships its
|
|
5
|
-
* own copy because Oh My Pi's legacy pi-ai shim does not export
|
|
6
|
-
* `calculateCost`, which broke extension installation there (issue #24).
|
|
7
|
-
* `tests/test-cost.ts` locks this implementation to the pi-ai original.
|
|
8
|
-
*/
|
|
1
|
+
/** Request-time Provider API rates; the native host calculates usage costs. */
|
|
9
2
|
|
|
10
|
-
import type {
|
|
3
|
+
import type { ModelCost, ModelCostRates, ModelCostTier } from "./types.ts"
|
|
11
4
|
|
|
12
5
|
const DEEPSEEK_V4_TIME_PRICED_MODELS = new Set([
|
|
13
6
|
"deepseek/deepseek-v4-pro",
|
|
@@ -30,18 +23,9 @@ export function isDeepSeekV4Peak(atMs: number): boolean {
|
|
|
30
23
|
return (hour >= 1 && hour < 4) || (hour >= 6 && hour < 10)
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
* Select request-time rates for both the native provider transport and the
|
|
35
|
-
* local generate fallback. DeepSeek V4 peak rates are exactly 2x off-peak.
|
|
36
|
-
*/
|
|
37
|
-
export function commandCodeCostRatesAt(
|
|
38
|
-
modelId: string,
|
|
39
|
-
rates: ModelCostRates,
|
|
40
|
-
atMs: number = Date.now(),
|
|
41
|
-
): ModelCostRates {
|
|
42
|
-
if (!DEEPSEEK_V4_TIME_PRICED_MODELS.has(modelId) || !isDeepSeekV4Peak(atMs)) return rates
|
|
43
|
-
|
|
26
|
+
function doubledRates<T extends ModelCostRates>(rates: T): T {
|
|
44
27
|
return {
|
|
28
|
+
...rates,
|
|
45
29
|
input: rates.input * 2,
|
|
46
30
|
output: rates.output * 2,
|
|
47
31
|
cacheRead: rates.cacheRead * 2,
|
|
@@ -49,28 +33,30 @@ export function commandCodeCostRatesAt(
|
|
|
49
33
|
}
|
|
50
34
|
}
|
|
51
35
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
rates = commandCodeCostRatesAt(model.id, rates, atMs)
|
|
36
|
+
/**
|
|
37
|
+
* Select request-time rates for the native provider transport. DeepSeek V4 peak rates are exactly 2x off-peak.
|
|
38
|
+
* Context tiers on a full model cost table are kept and doubled alongside
|
|
39
|
+
* the base rates so the host's tier selection still applies during peak.
|
|
40
|
+
*/
|
|
41
|
+
export function commandCodeCostRatesAt<
|
|
42
|
+
T extends ModelCostRates & { tiers?: readonly ModelCostTier[] },
|
|
43
|
+
>(modelId: string, rates: T, atMs: number = Date.now()): T {
|
|
44
|
+
if (!DEEPSEEK_V4_TIME_PRICED_MODELS.has(modelId) || !isDeepSeekV4Peak(atMs)) return rates
|
|
45
|
+
|
|
46
|
+
const doubled = doubledRates(rates)
|
|
47
|
+
if (!rates.tiers) return doubled
|
|
48
|
+
return { ...doubled, tiers: rates.tiers.map((tier) => doubledRates(tier)) }
|
|
49
|
+
}
|
|
67
50
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Native hosts accept mutable cost tiers, while our catalog is readonly.
|
|
53
|
+
* Give the host its own table, array, and tier objects at that boundary.
|
|
54
|
+
*/
|
|
55
|
+
export function commandCodeNativeCostRatesAt(
|
|
56
|
+
modelId: string,
|
|
57
|
+
rates: ModelCost,
|
|
58
|
+
atMs: number = Date.now(),
|
|
59
|
+
): ModelCostRates & { tiers?: ModelCostTier[] } {
|
|
60
|
+
const selected = commandCodeCostRatesAt(modelId, rates, atMs)
|
|
61
|
+
return { ...selected, tiers: selected.tiers?.map((tier) => ({ ...tier })) }
|
|
76
62
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MODEL_INPUT_MODALITIES,
|
|
3
|
+
MODEL_REASONING,
|
|
4
|
+
MODEL_EFFORTS,
|
|
5
|
+
COMMAND_CODE_CLI_VERSION,
|
|
6
|
+
} from "./commandcode-catalog.ts"
|
|
7
|
+
import { MODEL_COSTS, PRICING_LAST_VERIFIED, TEMPORARY_PRICING } from "./pricing.ts"
|
|
8
|
+
import { redactCommandCodeErrorText } from "./overflow.ts"
|
|
9
|
+
import type {
|
|
10
|
+
AssistantMessageEventStreamLike,
|
|
11
|
+
ContextLike,
|
|
12
|
+
ModelLike,
|
|
13
|
+
StreamOptions,
|
|
14
|
+
} from "./types.ts"
|
|
15
|
+
|
|
16
|
+
export interface RequestDiagnostic {
|
|
17
|
+
model: string
|
|
18
|
+
endpoint?: string
|
|
19
|
+
status?: number
|
|
20
|
+
requestId?: string
|
|
21
|
+
attempts: number
|
|
22
|
+
firstChunkMs?: number
|
|
23
|
+
longestChunkGapMs: number
|
|
24
|
+
durationMs?: number
|
|
25
|
+
outcome: "pending" | "done" | "error" | "aborted"
|
|
26
|
+
error?:
|
|
27
|
+
| "authentication"
|
|
28
|
+
| "permission"
|
|
29
|
+
| "rate_limit"
|
|
30
|
+
| "server"
|
|
31
|
+
| "context_length"
|
|
32
|
+
| "timeout"
|
|
33
|
+
| "request_failed"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function priceStatus(
|
|
37
|
+
modelId: string,
|
|
38
|
+
now = Date.now(),
|
|
39
|
+
): "known" | "unknown" | "review-required" {
|
|
40
|
+
if (!Object.hasOwn(MODEL_COSTS, modelId)) return "unknown"
|
|
41
|
+
const day = new Date(now).toISOString().slice(0, 10)
|
|
42
|
+
return TEMPORARY_PRICING.some(
|
|
43
|
+
(promotion) => promotion.models.includes(modelId) && promotion.expiresOn < day,
|
|
44
|
+
)
|
|
45
|
+
? "review-required"
|
|
46
|
+
: "known"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function safeIdentifier(value: string): string {
|
|
50
|
+
if (!/^[a-zA-Z0-9_./:+-]{1,160}$/.test(value)) return "[redacted]"
|
|
51
|
+
// Model IDs can come from host overrides: a slug's alphabet alone is not a trust boundary.
|
|
52
|
+
if (/^\/|(?:^|\/)\.{1,2}(?:\/|$)|^[a-z][a-z0-9+.-]*:/i.test(value)) return "[redacted]"
|
|
53
|
+
return redactCommandCodeErrorText(value) === value ? value : "[redacted]"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function classify(status: number | undefined, message: string): RequestDiagnostic["error"] {
|
|
57
|
+
if (status === 401) return "authentication"
|
|
58
|
+
if (status === 403) return "permission"
|
|
59
|
+
if (status === 429) return "rate_limit"
|
|
60
|
+
if (status && status >= 500) return "server"
|
|
61
|
+
if (/context_length_exceeded/.test(message)) return "context_length"
|
|
62
|
+
if (/timed?\s*out/i.test(message)) return "timeout"
|
|
63
|
+
return "request_failed"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const ENDPOINTS = [
|
|
67
|
+
"/provider/v1/responses",
|
|
68
|
+
"/provider/v1/chat/completions",
|
|
69
|
+
"/provider/v1/messages",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
/** Memory-only, content-free measurements. Never retain URLs, headers, bodies or credentials. */
|
|
73
|
+
export function createRequestDiagnostics(now: () => number = Date.now) {
|
|
74
|
+
let latest: RequestDiagnostic | undefined
|
|
75
|
+
return {
|
|
76
|
+
snapshot: () => (latest ? { ...latest } : undefined),
|
|
77
|
+
stream<
|
|
78
|
+
TModel extends ModelLike,
|
|
79
|
+
TContext extends ContextLike,
|
|
80
|
+
TReasoning extends string,
|
|
81
|
+
TStream extends AssistantMessageEventStreamLike,
|
|
82
|
+
>(
|
|
83
|
+
source: (
|
|
84
|
+
model: TModel,
|
|
85
|
+
context: TContext,
|
|
86
|
+
options?: StreamOptions<TModel, TReasoning>,
|
|
87
|
+
) => AssistantMessageEventStreamLike,
|
|
88
|
+
createStream: () => TStream,
|
|
89
|
+
model: TModel,
|
|
90
|
+
context: TContext,
|
|
91
|
+
options?: StreamOptions<TModel, TReasoning>,
|
|
92
|
+
): TStream {
|
|
93
|
+
const started = now()
|
|
94
|
+
const record: RequestDiagnostic = {
|
|
95
|
+
model: safeIdentifier(model.id),
|
|
96
|
+
attempts: 0,
|
|
97
|
+
longestChunkGapMs: 0,
|
|
98
|
+
outcome: "pending",
|
|
99
|
+
}
|
|
100
|
+
latest = record
|
|
101
|
+
const output = createStream()
|
|
102
|
+
let lastChunk: number | undefined
|
|
103
|
+
const instrumented: StreamOptions<TModel, TReasoning> = {
|
|
104
|
+
...options,
|
|
105
|
+
fetch: async (input, init) => {
|
|
106
|
+
record.attempts += 1
|
|
107
|
+
lastChunk = undefined
|
|
108
|
+
try {
|
|
109
|
+
const pathname = new URL(
|
|
110
|
+
typeof input === "string" ? input : input instanceof URL ? input.href : input.url,
|
|
111
|
+
).pathname
|
|
112
|
+
record.endpoint = ENDPOINTS.find((path) => pathname === path) ?? "custom endpoint"
|
|
113
|
+
} catch {
|
|
114
|
+
record.endpoint = "custom endpoint"
|
|
115
|
+
}
|
|
116
|
+
const response = await (options?.fetch ?? fetch)(input, init)
|
|
117
|
+
record.status = response.status
|
|
118
|
+
const requestId =
|
|
119
|
+
response.headers.get("x-request-id") ?? response.headers.get("request-id")
|
|
120
|
+
record.requestId =
|
|
121
|
+
requestId && /^[a-f0-9-]{16,64}$/i.test(requestId) ? requestId : undefined
|
|
122
|
+
if (!response.body) return response
|
|
123
|
+
return new Response(
|
|
124
|
+
response.body.pipeThrough(
|
|
125
|
+
new TransformStream<Uint8Array, Uint8Array>({
|
|
126
|
+
transform(chunk, controller) {
|
|
127
|
+
const at = now()
|
|
128
|
+
if (record.firstChunkMs === undefined) record.firstChunkMs = at - started
|
|
129
|
+
if (lastChunk !== undefined)
|
|
130
|
+
record.longestChunkGapMs = Math.max(record.longestChunkGapMs, at - lastChunk)
|
|
131
|
+
lastChunk = at
|
|
132
|
+
controller.enqueue(chunk)
|
|
133
|
+
},
|
|
134
|
+
}),
|
|
135
|
+
),
|
|
136
|
+
{ status: response.status, statusText: response.statusText, headers: response.headers },
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
const run = async () => {
|
|
141
|
+
try {
|
|
142
|
+
for await (const event of source(model, context, instrumented)) {
|
|
143
|
+
if (event.type === "done") record.outcome = "done"
|
|
144
|
+
if (event.type === "error") {
|
|
145
|
+
record.outcome = event.reason === "aborted" ? "aborted" : "error"
|
|
146
|
+
if (record.outcome !== "aborted")
|
|
147
|
+
record.error = classify(record.status, event.error.errorMessage ?? "")
|
|
148
|
+
}
|
|
149
|
+
output.push(event)
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
record.outcome = options?.signal?.aborted ? "aborted" : "error"
|
|
153
|
+
if (record.outcome !== "aborted")
|
|
154
|
+
record.error = classify(record.status, error instanceof Error ? error.message : "")
|
|
155
|
+
output.push({
|
|
156
|
+
type: "error",
|
|
157
|
+
reason: record.outcome === "aborted" ? "aborted" : "error",
|
|
158
|
+
error: {
|
|
159
|
+
role: "assistant",
|
|
160
|
+
content: [],
|
|
161
|
+
api: model.api,
|
|
162
|
+
provider: model.provider,
|
|
163
|
+
model: model.id,
|
|
164
|
+
timestamp: now(),
|
|
165
|
+
stopReason: record.outcome === "aborted" ? "aborted" : "error",
|
|
166
|
+
errorMessage:
|
|
167
|
+
"Command Code request failed before completing the stream; see /commandcode-diagnostics",
|
|
168
|
+
usage: {
|
|
169
|
+
input: 0,
|
|
170
|
+
output: 0,
|
|
171
|
+
cacheRead: 0,
|
|
172
|
+
cacheWrite: 0,
|
|
173
|
+
totalTokens: 0,
|
|
174
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
} finally {
|
|
179
|
+
record.durationMs = now() - started
|
|
180
|
+
output.end()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
run().catch(() => output.end())
|
|
184
|
+
return output
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function formatDiagnostics(input: {
|
|
190
|
+
pluginVersion: string
|
|
191
|
+
host: string
|
|
192
|
+
hostVersion: string
|
|
193
|
+
modelId?: string
|
|
194
|
+
route: string
|
|
195
|
+
request?: RequestDiagnostic
|
|
196
|
+
}): string {
|
|
197
|
+
const modelId = input.modelId
|
|
198
|
+
const known =
|
|
199
|
+
modelId &&
|
|
200
|
+
(Object.hasOwn(MODEL_INPUT_MODALITIES, modelId) ||
|
|
201
|
+
Object.hasOwn(MODEL_REASONING, modelId) ||
|
|
202
|
+
Object.hasOwn(MODEL_EFFORTS, modelId))
|
|
203
|
+
return [
|
|
204
|
+
`plugin: ${safeIdentifier(input.pluginVersion)}`,
|
|
205
|
+
`host: ${safeIdentifier(input.host)} ${safeIdentifier(input.hostVersion)}`,
|
|
206
|
+
`catalog CLI: ${COMMAND_CODE_CLI_VERSION}`,
|
|
207
|
+
`model: ${modelId ? safeIdentifier(modelId) : "none"}`,
|
|
208
|
+
// Caller supplies only a normalized routing description, never an error body.
|
|
209
|
+
`route: ${input.route}`,
|
|
210
|
+
`capabilities: ${known ? "bundled snapshot; host overrides may apply" : "not explicitly catalogued; conservative defaults"}`,
|
|
211
|
+
`price: ${modelId ? priceStatus(modelId) : "unknown"} (verified ${PRICING_LAST_VERIFIED}; estimate, not billing)`,
|
|
212
|
+
input.request ? `last request: ${JSON.stringify(input.request)}` : "last request: none",
|
|
213
|
+
"Timing measures received body chunks, not tokens. No prompts, tool content, credentials, account data or configured local paths are collected. Model IDs come from the host; review custom names before sharing.",
|
|
214
|
+
].join("\n")
|
|
215
|
+
}
|
|
@@ -20,13 +20,15 @@ const STUDIO_BASE_URL = "https://commandcode.ai"
|
|
|
20
20
|
const TEN_YEARS_MS = 10 * 365 * 24 * 60 * 60 * 1000 // API keys don't expire
|
|
21
21
|
const DEFAULT_AUTH_TIMEOUT_MS = 120_000
|
|
22
22
|
const DEFAULT_API_BASE = "https://api.commandcode.ai"
|
|
23
|
+
const DEFAULT_PROVIDER_API_BASE = `${DEFAULT_API_BASE}/provider/v1`
|
|
24
|
+
export const VALIDATE_API_KEY_TIMEOUT_MS = 15_000
|
|
23
25
|
|
|
24
26
|
export interface OAuthLoginCallbacks {
|
|
25
27
|
onAuth(params: { url: string }): void
|
|
26
28
|
onPrompt(params: { message: string }): Promise<string>
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export
|
|
31
|
+
export type OAuthCredentials = {
|
|
30
32
|
refresh: string
|
|
31
33
|
access: string
|
|
32
34
|
expires: number
|
|
@@ -96,22 +98,54 @@ export function sanitizeApiKey(input: string): string {
|
|
|
96
98
|
.trim()
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Base of the alpha endpoints used for key validation. Mirrors index.ts: the
|
|
103
|
+
* configured `COMMANDCODE_API_BASE` is the Provider API base, and the alpha
|
|
104
|
+
* endpoints live next to it without the `/provider/v1` suffix.
|
|
105
|
+
*/
|
|
106
|
+
export function validationApiBase(env: NodeJS.ProcessEnv = process.env): string {
|
|
107
|
+
const providerApiBase = env.COMMANDCODE_API_BASE ?? DEFAULT_PROVIDER_API_BASE
|
|
108
|
+
return providerApiBase.replace(/\/provider\/v1\/?$/, "")
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
export async function validateApiKey(
|
|
100
112
|
apiKey: string,
|
|
101
|
-
options: { fetchImpl?: typeof fetch; apiBase?: string } = {},
|
|
113
|
+
options: { fetchImpl?: typeof fetch; apiBase?: string; timeoutMs?: number } = {},
|
|
102
114
|
): Promise<void> {
|
|
115
|
+
const timeoutMs = options.timeoutMs ?? VALIDATE_API_KEY_TIMEOUT_MS
|
|
116
|
+
// AbortSignal is cooperative: a custom fetch may ignore it, so the deadline
|
|
117
|
+
// also races the request. /login must never hang on a stalled whoami.
|
|
118
|
+
const controller = new AbortController()
|
|
119
|
+
let rejectDeadline: ((error: Error) => void) | undefined
|
|
120
|
+
const deadline = new Promise<never>((_resolve, reject) => {
|
|
121
|
+
rejectDeadline = reject
|
|
122
|
+
})
|
|
123
|
+
const timer = setTimeout(() => {
|
|
124
|
+
const error = new Error(
|
|
125
|
+
`Could not validate the Command Code API key: request timed out after ${timeoutMs}ms`,
|
|
126
|
+
)
|
|
127
|
+
controller.abort(error)
|
|
128
|
+
rejectDeadline?.(error)
|
|
129
|
+
}, timeoutMs)
|
|
130
|
+
|
|
103
131
|
let response: Response
|
|
104
132
|
try {
|
|
105
|
-
response = await
|
|
106
|
-
`${options.apiBase ??
|
|
107
|
-
{
|
|
133
|
+
response = await Promise.race([
|
|
134
|
+
(options.fetchImpl ?? fetch)(`${options.apiBase ?? validationApiBase()}/alpha/whoami`, {
|
|
108
135
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
signal: controller.signal,
|
|
137
|
+
}),
|
|
138
|
+
deadline,
|
|
139
|
+
])
|
|
111
140
|
} catch (error) {
|
|
141
|
+
if (controller.signal.aborted && controller.signal.reason instanceof Error) {
|
|
142
|
+
throw controller.signal.reason
|
|
143
|
+
}
|
|
112
144
|
throw new Error(
|
|
113
145
|
`Could not validate the Command Code API key: ${error instanceof Error ? error.message : String(error)}`,
|
|
114
146
|
)
|
|
147
|
+
} finally {
|
|
148
|
+
clearTimeout(timer)
|
|
115
149
|
}
|
|
116
150
|
|
|
117
151
|
if (response.status === 401) throw new Error("Invalid Command Code API key")
|