openpond 0.0.38 → 0.0.39
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/README.md +3 -4
- package/dist/api/core.d.ts +6 -0
- package/dist/api/vercel-protection.d.ts +1 -0
- package/dist/chunks/{app-layer-DPUJRNO2.js → app-layer-LTBWNA2F.js} +32 -10
- package/dist/chunks/app-server-runtime-VYYJ2AWX.js +18 -0
- package/dist/chunks/{apps-AKBI6AS7.js → apps-CZAJBGE3.js} +6 -4
- package/dist/chunks/{chunk-LZZM3IHS.js → chunk-2SF6HLT7.js} +5899 -5939
- package/dist/chunks/{chunk-XCATKTK3.js → chunk-3CDPPVLE.js} +108 -66
- package/dist/chunks/{chunk-JWF37O5E.js → chunk-3HW6OSHP.js} +1 -3
- package/dist/chunks/{chunk-43YI36NA.js → chunk-3KLQ52B2.js} +228 -5
- package/dist/chunks/chunk-4HIWFIMN.js +37172 -0
- package/dist/chunks/{chunk-AHPQTEIJ.js → chunk-4N6E3OVF.js} +4 -4
- package/dist/chunks/{chunk-YTJL6XPU.js → chunk-6V7MJVRO.js} +56 -11
- package/dist/chunks/{chunk-QRM7XMAO.js → chunk-BQQZNGI6.js} +152 -161
- package/dist/chunks/chunk-DBHSOTYZ.js +1552 -0
- package/dist/chunks/{chunk-275WCETC.js → chunk-FCVVOMIP.js} +145 -5
- package/dist/chunks/{chunk-GB6VUZUA.js → chunk-JIEUB6OS.js} +1 -1
- package/dist/chunks/{chunk-HS2AGRDV.js → chunk-JJPAMKXZ.js} +1 -1
- package/dist/chunks/{chunk-GDZYDLEL.js → chunk-JRROTGQT.js} +1 -110
- package/dist/chunks/chunk-KHNHUA2H.js +1737 -0
- package/dist/chunks/{chunk-AHNFNWUN.js → chunk-L6XH4ZGZ.js} +1 -1
- package/dist/chunks/chunk-M2NXTLH2.js +4054 -0
- package/dist/chunks/{chunk-SLMP353Q.js → chunk-MIZHCABO.js} +2 -195
- package/dist/chunks/chunk-SMNFI2FU.js +113 -0
- package/dist/chunks/chunk-VCVQLECH.js +675 -0
- package/dist/chunks/{chunk-V35STJF4.js → chunk-ZJBJQCQZ.js} +179 -52
- package/dist/chunks/{cli-7BKDWFNU.js → cli-JS76LCW2.js} +9 -5
- package/dist/chunks/{core-commands-YN4RMWA3.js → core-commands-4MRJQZJV.js} +7 -5
- package/dist/chunks/{harness-BHQRMXJR.js → desktop-test-RNMWLOVU.js} +15 -14
- package/dist/chunks/{chunk-XERQHYBO.js → extension-GDRW22N3.js} +5868 -3580
- package/dist/chunks/{help-VREQNA4I.js → help-LWNREJ7U.js} +1 -1
- package/dist/chunks/{opchat-D63YTNSX.js → opchat-2K2JIGK3.js} +9 -10
- package/dist/chunks/{organizations-I46KG7TC.js → organizations-Z5HVD2E7.js} +11 -9
- package/dist/chunks/{profile-WKZJHEPG.js → profile-QNECVVGN.js} +12 -38
- package/dist/chunks/{project-agent-ZUC3YMCT.js → project-agent-W3V75WBR.js} +9 -411
- package/dist/chunks/{sandbox-command-AAOPFTI5.js → sandbox-command-X3FO74NX.js} +7 -5
- package/dist/chunks/{sandbox-template-GKNVR4C5.js → sandbox-template-5B4T4BGU.js} +8 -6
- package/dist/chunks/{src-RPW5TOPI.js → src-ESAILPUH.js} +32 -30
- package/dist/chunks/src-IC5RX4L6.js +63517 -0
- package/dist/chunks/{teams-bot-PSL3ZO6Z.js → teams-bot-NTQ6VFFL.js} +6 -4
- package/dist/chunks/training-BR5A7SPU.js +320 -0
- package/dist/chunks/{workspaces-BPXC2DHT.js → workspaces-XC3QBD2Y.js} +2 -2
- package/dist/cli.js +24 -12
- package/dist/config.d.ts +9 -3
- package/dist/index.js +1300 -1045
- package/dist/profile/local-profile-types.d.ts +16 -0
- package/dist/profile/local-profile.d.ts +50 -4
- package/dist/sandbox/client-handles.d.ts +33 -46
- package/dist/sandbox/client.d.ts +4 -26
- package/dist/sandbox/sandbox-instance-client.d.ts +5 -5
- package/dist/sandbox/types/client.d.ts +1 -2
- package/dist/sandbox/types/core.d.ts +0 -1
- package/dist/sandbox/types/org-project-agent.d.ts +3 -89
- package/dist/sandbox/types/record.d.ts +1 -2
- package/dist/sandbox/types/runtime-profiles.d.ts +2 -2
- package/dist/sandbox-template/manifest.d.ts +1 -1
- package/dist/skills/openpond-agent-authoring/SKILL.md +40 -0
- package/dist/skills/openpond-agent-authoring/references/action-and-chat-design.md +13 -0
- package/dist/skills/openpond-agent-authoring/references/integrations-and-setup.md +13 -0
- package/dist/skills/openpond-agent-authoring/references/profile-layout.md +29 -0
- package/dist/skills/openpond-agent-authoring/references/validation-and-repair.md +14 -0
- package/dist/skills/openpond-desktop-harness/SKILL.md +1 -1
- package/dist/skills/openpond-skill-authoring/SKILL.md +44 -0
- package/dist/skills/openpond-skill-authoring/references/copying-and-adaptation.md +16 -0
- package/dist/skills/openpond-skill-authoring/references/skill-package-layout.md +38 -0
- package/dist/skills/openpond-skill-authoring/references/validation-and-repair.md +24 -0
- package/dist/skills/openpond-skill-authoring/scripts/validate-skill.mjs +102 -0
- package/dist/skills/openpond-taskset-authoring/SKILL.md +64 -22
- package/dist/skills/openpond-taskset-authoring/artifact.json +39 -0
- package/dist/skills/openpond-taskset-authoring/references/graders-and-rewards.md +3 -0
- package/dist/skills/openpond-taskset-authoring/references/method-selection.md +1 -1
- package/dist/skills/openpond-taskset-authoring/references/privacy-and-provenance.md +2 -0
- package/dist/skills/openpond-taskset-authoring/references/task-design.md +32 -0
- package/dist/web/assets/{AppDialog-DrwJb_wG.js → AppDialog-Bua3f-6v.js} +1 -1
- package/dist/web/assets/{AppsView-DPagLMsc.js → AppsView-DrJkHeSO.js} +1 -1
- package/dist/web/assets/BrowserSidebar-Bf-4Vozm.js +1 -0
- package/dist/web/assets/CommandMenu-DDZlGQiB.js +1 -0
- package/dist/web/assets/CommunityView-BtcCrba7.js +1 -0
- package/dist/web/assets/ComposerCreateImproveStrip-DOe5Otg6.js +1 -0
- package/dist/web/assets/GetStartedView-CG4z0Dtw.js +1 -0
- package/dist/web/assets/GetStartedView-yVmnGZPw.css +1 -0
- package/dist/web/assets/LabModelVersionDetailPage-BEkmSKuv.js +1 -0
- package/dist/web/assets/LabSkillSidebar-BIotN_RB.js +1 -0
- package/dist/web/assets/LabsRoute-CfOe0Zt5.js +3 -0
- package/dist/web/assets/LabsRoute-CoSPO4HR.css +1 -0
- package/dist/web/assets/MainChatThread-C0-l1mHt.js +2 -0
- package/dist/web/assets/MainPane-Bky_Rqcx.css +1 -0
- package/dist/web/assets/MainPane-aOVlVyRK.js +6 -0
- package/dist/web/assets/MarkdownText-D7DT1k1k.js +9 -0
- package/dist/web/assets/Messages-CBIXruA9.js +9 -0
- package/dist/web/assets/NativeSkillSidebar-C4t69Y7B.js +1 -0
- package/dist/web/assets/NewProjectDialog-Bat65tYD.js +1 -0
- package/dist/web/assets/OutputsPage-C58n39Db.js +1 -0
- package/dist/web/assets/RightChatPanelStack-Bp7nZxQ0.js +1 -0
- package/dist/web/assets/ScheduledWorkPage-BXP0j_c_.js +1 -0
- package/dist/web/assets/SettingsView-CtWK_aQ0.css +1 -0
- package/dist/web/assets/SettingsView-DOOfhO9a.js +6 -0
- package/dist/web/assets/TeamChatView-Cgxm-pKA.css +1 -0
- package/dist/web/assets/TeamChatView-De2wdqyY.js +3 -0
- package/dist/web/assets/{TerminalOverlay-BKl0p8pa.js → TerminalOverlay-BsuCH3NX.js} +1 -1
- package/dist/web/assets/TrainingCreationPanel-D2OFWyQ-.js +1 -0
- package/dist/web/assets/TrainingDraftPanel-DBpulXTz.js +1 -0
- package/dist/web/assets/{UsageSettingsSection-zDAwzTGl.js → UsageSettingsSection-DzMLUXAO.js} +37 -37
- package/dist/web/assets/WorkspaceDiffPanel-B7yIhjNF.js +14 -0
- package/dist/web/assets/WorkspaceEnvironmentMenu-B6jXM9xG.js +32 -0
- package/dist/web/assets/WorkspaceGitDialogs-CQ0fl9Qk.js +1 -0
- package/dist/web/assets/{WorkspaceMonacoEditor-DPGcG8fy.js → WorkspaceMonacoEditor-C2ctzITz.js} +3 -3
- package/dist/web/assets/arrow-up-right-ecwcx3xt.js +1 -0
- package/dist/web/assets/chevron-up-DP8PPfWd.js +1 -0
- package/dist/web/assets/circle-alert-envg1D6O.js +1 -0
- package/dist/web/assets/cloud-upload-5MGPLnaA.js +1 -0
- package/dist/web/assets/{cssMode-CKN9CcfG.js → cssMode-CFifcEfw.js} +1 -1
- package/dist/web/assets/folder-open-Dq3ZjeEP.js +1 -0
- package/dist/web/assets/folder-plus-EiZ5wbv_.js +1 -0
- package/dist/web/assets/git-branch-w29jmQ-X.js +1 -0
- package/dist/web/assets/{git-commit-horizontal-Bxi8YPep.js → git-commit-horizontal-CGZM0PZo.js} +1 -1
- package/dist/web/assets/{htmlMode-CeUcNhBZ.js → htmlMode-Ct1P-_lf.js} +1 -1
- package/dist/web/assets/index-ByIQyiUl.js +178 -0
- package/dist/web/assets/index-D4uCeiep.js +1 -0
- package/dist/web/assets/index-D9jTe16Q.css +1 -0
- package/dist/web/assets/info-Cd2HkIeb.js +1 -0
- package/dist/web/assets/{jsonMode-97z0Yz9u.js → jsonMode-BAUNCNAX.js} +1 -1
- package/dist/web/assets/{lspLanguageFeatures-D4Tp-JmI.js → lspLanguageFeatures-fucFYI1A.js} +1 -1
- package/dist/web/assets/monaco.contribution-Ce4v5kei.js +2 -0
- package/dist/web/assets/monaco.contribution-DLLMi4cB.js +2 -0
- package/dist/web/assets/monaco.contribution-g9QiIm1d.js +2 -0
- package/dist/web/assets/monaco.contribution-nG-5Cyjz.js +2 -0
- package/dist/web/assets/monitor-DgHCnCKl.js +1 -0
- package/dist/web/assets/{play-C-37dnR1.js → play-Be0XDHBu.js} +1 -1
- package/dist/web/assets/{python-CGpDXY7_.js → python-CEhEiPo7.js} +1 -1
- package/dist/web/assets/{refresh-cw-BAaaPCXl.js → refresh-cw-DH0KLbdD.js} +1 -1
- package/dist/web/assets/reply-D1TK2yV8.js +1 -0
- package/dist/web/assets/{save-Cvxs3XyC.js → save-C1MSeBnQ.js} +1 -1
- package/dist/web/assets/square-CemI-0g5.js +1 -0
- package/dist/web/assets/square-pen-CqfsvR_n.js +1 -0
- package/dist/web/assets/{toggleHighContrast-CD42jH4g.js → toggleHighContrast-DrdQN3Rl.js} +1 -1
- package/dist/web/assets/training-BQVNUTZA.css +1 -0
- package/dist/web/assets/training-model-data-B7-1Bxil.js +1 -0
- package/dist/web/assets/{tsMode-ZROIxEjv.js → tsMode-CKB5oOUU.js} +1 -1
- package/dist/web/assets/{upload-DvCSGERK.js → upload-t751LLqP.js} +1 -1
- package/dist/web/assets/useLocalAgentSchedules-CzC3wfIP.js +1 -0
- package/dist/web/assets/{wifi-off-BIb94PkS.js → wifi-off-CxTHH3JU.js} +1 -1
- package/dist/web/assets/{workers-oYqbrVYG.js → workers-CqYddzCd.js} +1 -1
- package/dist/web/assets/{yaml-WqBjNgOO.js → yaml-e5wBkc-C.js} +1 -1
- package/dist/web/index.html +2 -2
- package/docs/command-reference.md +75 -40
- package/package.json +3 -1
- package/dist/chunks/chunk-FWLOFUPU.js +0 -864
- package/dist/chunks/chunk-HLCTINEP.js +0 -224
- package/dist/chunks/chunk-MPGSHXGF.js +0 -3896
- package/dist/chunks/chunk-T4QXKU5Y.js +0 -1
- package/dist/chunks/chunk-XEJ7XXUQ.js +0 -1301
- package/dist/chunks/chunk-ZI4GDAUB.js +0 -3522
- package/dist/chunks/cli-2KBVNDRY.js +0 -23
- package/dist/chunks/extend-REGNTBK3.js +0 -89
- package/dist/chunks/extension-7K77DAVL.js +0 -121
- package/dist/chunks/fileFromPath-DHCRY3BD.js +0 -2151
- package/dist/chunks/src-MWDIK56B.js +0 -105881
- package/dist/web/assets/BrowserSidebar-DMn2V8RV.js +0 -1
- package/dist/web/assets/CloudWorkView-Cl_7mM3c.js +0 -1
- package/dist/web/assets/CloudWorkView-DNoPIlMj.css +0 -1
- package/dist/web/assets/CommandMenu-CHMQLez_.js +0 -1
- package/dist/web/assets/CommunityView-DcHVDUk0.js +0 -1
- package/dist/web/assets/ComposerCreateImproveStrip-BZ3Dgzmo.js +0 -1
- package/dist/web/assets/GetStartedView-DBLdduwr.css +0 -1
- package/dist/web/assets/GetStartedView-DTRotFqz.js +0 -1
- package/dist/web/assets/LabSkillSidebar-D-PqFe1T.js +0 -1
- package/dist/web/assets/LabsRoute-BrJkBNig.css +0 -1
- package/dist/web/assets/LabsRoute-Dew1BwK5.js +0 -3
- package/dist/web/assets/MainChatThread-BaPxxzrw.js +0 -2
- package/dist/web/assets/MakeAgentTutorialLearningPanel-CBsfnONQ.js +0 -2
- package/dist/web/assets/MarkdownText-DGLfAM_Z.js +0 -7
- package/dist/web/assets/Messages-CIX9uTjX.js +0 -10
- package/dist/web/assets/NativeSkillSidebar-AP_uHn6g.js +0 -1
- package/dist/web/assets/NewProjectDialog-C6lHkafU.js +0 -1
- package/dist/web/assets/PostTrainingLearningPanel-CZEgPc8O.js +0 -2
- package/dist/web/assets/PostTrainingStatusPill-CeEpwUDB.js +0 -1
- package/dist/web/assets/ProfileSettingsSection-Cg4tKO-C.css +0 -1
- package/dist/web/assets/ProfileSettingsSection-EumMLlEp.js +0 -1
- package/dist/web/assets/RightChatPanelStack-MXBcx3zO.js +0 -1
- package/dist/web/assets/SettingsView-Caljbns2.css +0 -1
- package/dist/web/assets/SettingsView-DyURG_Uh.js +0 -6
- package/dist/web/assets/TeamChatView-Bx44q3WV.css +0 -1
- package/dist/web/assets/TeamChatView-D3v6aqJ3.js +0 -3
- package/dist/web/assets/TrainingCreationPanel-CfZQTuT5.js +0 -1
- package/dist/web/assets/TrainingDraftPanel-DslRPSDW.js +0 -1
- package/dist/web/assets/WorkspaceDiffPanel-C_MZPPlL.js +0 -14
- package/dist/web/assets/WorkspaceEnvironmentMenu-BUAnn80j.js +0 -32
- package/dist/web/assets/WorkspaceGitDialogs-Drbf4ujA.js +0 -1
- package/dist/web/assets/activity-Dnr3jqb3.js +0 -1
- package/dist/web/assets/boxes-BinC8UPn.js +0 -1
- package/dist/web/assets/chevron-up-Bjp_-_Cb.js +0 -1
- package/dist/web/assets/circle-x-ubnvEYuE.js +0 -1
- package/dist/web/assets/copy-B_ZCCUMz.js +0 -1
- package/dist/web/assets/create-pipeline-request-D6uLUxe9.js +0 -4
- package/dist/web/assets/file-8HAMlTmQ.js +0 -1
- package/dist/web/assets/git-branch-l2Zih3Bv.js +0 -1
- package/dist/web/assets/index-BMFyOFRU.css +0 -1
- package/dist/web/assets/index-BzwcDzbT.js +0 -1
- package/dist/web/assets/index-KoQSSt_f.js +0 -177
- package/dist/web/assets/info-JTbDQxHx.js +0 -1
- package/dist/web/assets/make-agent-tutorial-D6nBCgv-.js +0 -2
- package/dist/web/assets/monaco.contribution-B3j6oown.js +0 -2
- package/dist/web/assets/monaco.contribution-BXHxPPWL.js +0 -2
- package/dist/web/assets/monaco.contribution-C2P5zIzh.js +0 -2
- package/dist/web/assets/monaco.contribution-C8c6OtGi.js +0 -2
- package/dist/web/assets/monitor-kzHtxHnA.js +0 -1
- package/dist/web/assets/reply-9rehU13k.js +0 -1
- package/dist/web/assets/rotate-cw-C1Z_Xs23.js +0 -1
- package/dist/web/assets/training-BN8CALIc.css +0 -1
- package/dist/web/assets/training-model-data-BXUCzS0p.js +0 -1
- package/docs/agent-edit-check-status-json.md +0 -132
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import { createRequire as __openpondCreateRequire } from "node:module"; var require = __openpondCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
DEFAULT_OPENPOND_OPCHAT_API_BASE_URL
|
|
4
|
-
} from "./chunk-KSRWKXRB.js";
|
|
5
|
-
|
|
6
|
-
// ../../packages/cloud/src/hosted-chat.ts
|
|
7
|
-
import { randomUUID } from "node:crypto";
|
|
8
|
-
function normalizeApiBaseUrl(value) {
|
|
9
|
-
const trimmed = normalizeOptionalOpChatApiBaseUrl(value);
|
|
10
|
-
if (!trimmed) throw new Error("apiBaseUrl is required");
|
|
11
|
-
return trimmed;
|
|
12
|
-
}
|
|
13
|
-
function trimTrailingSlashes(value) {
|
|
14
|
-
return value.replace(/\/+$/, "");
|
|
15
|
-
}
|
|
16
|
-
function normalizeOptionalOpChatApiBaseUrl(value) {
|
|
17
|
-
let trimmed = trimTrailingSlashes(value?.trim() ?? "");
|
|
18
|
-
if (!trimmed) return null;
|
|
19
|
-
trimmed = trimmed.replace(/\/chat\/completions$/i, "").replace(/\/models(?:\/[^/]+)?$/i, "");
|
|
20
|
-
if (trimmed.endsWith("/opchat/v1")) return trimmed;
|
|
21
|
-
if (trimmed.endsWith("/opchat")) return `${trimmed}/v1`;
|
|
22
|
-
if (trimmed.endsWith("/v1")) {
|
|
23
|
-
trimmed = trimmed.slice(0, -"/v1".length);
|
|
24
|
-
}
|
|
25
|
-
return `${trimTrailingSlashes(trimmed)}/opchat/v1`;
|
|
26
|
-
}
|
|
27
|
-
function resolveOpChatApiBaseUrl(options = {}) {
|
|
28
|
-
const runtimeEnv = options.env ?? (typeof process !== "undefined" ? process.env : {});
|
|
29
|
-
const explicit = normalizeOptionalOpChatApiBaseUrl(options.opChatApiBaseUrl) ?? normalizeOptionalOpChatApiBaseUrl(runtimeEnv.OPENPOND_OPCHAT_API_URL);
|
|
30
|
-
if (explicit) return explicit;
|
|
31
|
-
const migrationInput = normalizeOptionalOpChatApiBaseUrl(options.chatApiBaseUrl) ?? normalizeOptionalOpChatApiBaseUrl(runtimeEnv.OPENPOND_CHAT_API_URL) ?? normalizeOptionalOpChatApiBaseUrl(runtimeEnv.OPENPOND_GATEWAY_URL);
|
|
32
|
-
if (migrationInput) return migrationInput;
|
|
33
|
-
const apiBase = normalizeOptionalOpChatApiBaseUrl(options.apiBaseUrl) ?? normalizeOptionalOpChatApiBaseUrl(runtimeEnv.OPENPOND_API_URL);
|
|
34
|
-
return apiBase ?? DEFAULT_OPENPOND_OPCHAT_API_BASE_URL;
|
|
35
|
-
}
|
|
36
|
-
function requireToken(value) {
|
|
37
|
-
const trimmed = value.trim();
|
|
38
|
-
if (!trimmed) throw new Error("OpenPond API key is required");
|
|
39
|
-
return trimmed;
|
|
40
|
-
}
|
|
41
|
-
function hostedHeaders(token, accept, requestId) {
|
|
42
|
-
const headers = new Headers();
|
|
43
|
-
headers.set("Authorization", `Bearer ${requireToken(token)}`);
|
|
44
|
-
headers.set("Content-Type", "application/json");
|
|
45
|
-
headers.set("Accept", accept);
|
|
46
|
-
headers.set("x-openpond-client", "openpond-code");
|
|
47
|
-
headers.set("x-openpond-request-id", requestId || randomUUID());
|
|
48
|
-
return headers;
|
|
49
|
-
}
|
|
50
|
-
async function readError(response) {
|
|
51
|
-
const text = await response.text().catch(() => "");
|
|
52
|
-
if (!text) return response.statusText || `HTTP ${response.status}`;
|
|
53
|
-
try {
|
|
54
|
-
const payload = JSON.parse(text);
|
|
55
|
-
const error = typeof payload.error === "string" ? payload.error : payload.error && typeof payload.error === "object" && !Array.isArray(payload.error) ? payload.error : null;
|
|
56
|
-
const code = typeof payload.code === "string" ? payload.code : error && typeof error !== "string" && typeof error.code === "string" ? error.code : null;
|
|
57
|
-
const message = typeof payload.message === "string" ? payload.message : error && typeof error !== "string" && typeof error.message === "string" ? error.message : null;
|
|
58
|
-
const label = typeof error === "string" ? error : error && typeof error.type === "string" ? error.type : null;
|
|
59
|
-
return [code, label, message].filter(Boolean).join(": ") || text;
|
|
60
|
-
} catch {
|
|
61
|
-
return text;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function buildHostedChatBody(options, stream) {
|
|
65
|
-
const body = {
|
|
66
|
-
model: options.model,
|
|
67
|
-
messages: options.messages,
|
|
68
|
-
stream
|
|
69
|
-
};
|
|
70
|
-
if (typeof options.temperature === "number") {
|
|
71
|
-
body.temperature = options.temperature;
|
|
72
|
-
}
|
|
73
|
-
if (typeof options.maxTokens === "number") {
|
|
74
|
-
body.max_tokens = options.maxTokens;
|
|
75
|
-
}
|
|
76
|
-
if (options.tools) {
|
|
77
|
-
body.tools = options.tools;
|
|
78
|
-
}
|
|
79
|
-
const toolChoice = options.toolChoice ?? options.tool_choice;
|
|
80
|
-
if (toolChoice !== void 0) {
|
|
81
|
-
body.tool_choice = toolChoice;
|
|
82
|
-
}
|
|
83
|
-
if (options.metadata) {
|
|
84
|
-
body.metadata = options.metadata;
|
|
85
|
-
}
|
|
86
|
-
return body;
|
|
87
|
-
}
|
|
88
|
-
async function listOpChatModels(options) {
|
|
89
|
-
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
90
|
-
const response = await fetch(`${apiBaseUrl}/models`, {
|
|
91
|
-
method: "GET",
|
|
92
|
-
headers: hostedHeaders(options.token, "application/json"),
|
|
93
|
-
signal: options.signal
|
|
94
|
-
});
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
`Hosted model list failed: ${response.status} ${await readError(
|
|
98
|
-
response
|
|
99
|
-
)}`
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
return await response.json();
|
|
103
|
-
}
|
|
104
|
-
async function getOpChatModel(options) {
|
|
105
|
-
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
106
|
-
const response = await fetch(
|
|
107
|
-
`${apiBaseUrl}/models/${encodeURIComponent(options.model)}`,
|
|
108
|
-
{
|
|
109
|
-
method: "GET",
|
|
110
|
-
headers: hostedHeaders(options.token, "application/json"),
|
|
111
|
-
signal: options.signal
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Hosted model lookup failed: ${response.status} ${await readError(
|
|
117
|
-
response
|
|
118
|
-
)}`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
return await response.json();
|
|
122
|
-
}
|
|
123
|
-
async function sendHostedChatTurn(options) {
|
|
124
|
-
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
125
|
-
const response = await fetch(`${apiBaseUrl}/chat/completions`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
headers: hostedHeaders(
|
|
128
|
-
options.token,
|
|
129
|
-
"application/json",
|
|
130
|
-
options.requestId
|
|
131
|
-
),
|
|
132
|
-
body: JSON.stringify(buildHostedChatBody(options, false)),
|
|
133
|
-
signal: options.signal
|
|
134
|
-
});
|
|
135
|
-
if (!response.ok) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
`Hosted chat failed: ${response.status} ${await readError(response)}`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
return await response.json();
|
|
141
|
-
}
|
|
142
|
-
async function* parseOpenAISSE(stream, signal) {
|
|
143
|
-
const reader = stream.getReader();
|
|
144
|
-
const decoder = new TextDecoder();
|
|
145
|
-
let buffer = "";
|
|
146
|
-
const readAbortError = () => signal?.reason instanceof Error ? signal.reason : new Error("hosted_chat_aborted");
|
|
147
|
-
try {
|
|
148
|
-
while (true) {
|
|
149
|
-
if (signal?.aborted) throw readAbortError();
|
|
150
|
-
const result = await reader.read();
|
|
151
|
-
if (result.done) break;
|
|
152
|
-
buffer += decoder.decode(result.value, { stream: true });
|
|
153
|
-
const lines = buffer.split("\n");
|
|
154
|
-
buffer = lines.pop() || "";
|
|
155
|
-
for (const line of lines) {
|
|
156
|
-
const trimmed = line.trim();
|
|
157
|
-
if (!trimmed.startsWith("data:")) continue;
|
|
158
|
-
const data = trimmed.slice(5).trim();
|
|
159
|
-
if (!data) continue;
|
|
160
|
-
if (data === "[DONE]") return;
|
|
161
|
-
yield JSON.parse(data);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} finally {
|
|
165
|
-
try {
|
|
166
|
-
reader.releaseLock();
|
|
167
|
-
} catch {
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
async function* streamHostedChatTurn(options) {
|
|
172
|
-
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
173
|
-
const response = await fetch(`${apiBaseUrl}/chat/completions`, {
|
|
174
|
-
method: "POST",
|
|
175
|
-
headers: hostedHeaders(
|
|
176
|
-
options.token,
|
|
177
|
-
"text/event-stream",
|
|
178
|
-
options.requestId
|
|
179
|
-
),
|
|
180
|
-
body: JSON.stringify(buildHostedChatBody(options, true)),
|
|
181
|
-
signal: options.signal
|
|
182
|
-
});
|
|
183
|
-
if (!response.ok || !response.body) {
|
|
184
|
-
throw new Error(
|
|
185
|
-
`Hosted chat stream failed: ${response.status} ${await readError(
|
|
186
|
-
response
|
|
187
|
-
)}`
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
for await (const raw of parseOpenAISSE(response.body, options.signal)) {
|
|
191
|
-
const chunk = raw;
|
|
192
|
-
if (chunk.error) {
|
|
193
|
-
throw new Error(chunk.error.message || "Hosted chat stream error");
|
|
194
|
-
}
|
|
195
|
-
if (chunk.usage) {
|
|
196
|
-
yield { type: "usage", usage: chunk.usage, raw };
|
|
197
|
-
}
|
|
198
|
-
const choice = chunk.choices?.[0];
|
|
199
|
-
if (!choice) continue;
|
|
200
|
-
const content = choice.delta?.content;
|
|
201
|
-
if (content) {
|
|
202
|
-
yield { type: "text_delta", text: content, raw };
|
|
203
|
-
}
|
|
204
|
-
const reasoning = choice.delta?.reasoning_content;
|
|
205
|
-
if (reasoning) {
|
|
206
|
-
yield { type: "reasoning_delta", text: reasoning, raw };
|
|
207
|
-
}
|
|
208
|
-
const toolCalls = choice.delta?.tool_calls;
|
|
209
|
-
if (Array.isArray(toolCalls) && toolCalls.length > 0) {
|
|
210
|
-
yield { type: "tool_call_delta", toolCalls, raw };
|
|
211
|
-
}
|
|
212
|
-
if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
|
|
213
|
-
yield { type: "finish", finishReason: choice.finish_reason, raw };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export {
|
|
219
|
-
resolveOpChatApiBaseUrl,
|
|
220
|
-
listOpChatModels,
|
|
221
|
-
getOpChatModel,
|
|
222
|
-
sendHostedChatTurn,
|
|
223
|
-
streamHostedChatTurn
|
|
224
|
-
};
|