openpond-sdk 0.12.4 → 0.12.6
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/TASKSETS.md +13 -0
- package/TRAINING_PROTOCOL.md +25 -0
- package/dist/advanced-refiner-evaluations.js +7 -7
- package/dist/candidate-evaluations.js +6 -6
- package/dist/{chunk-MO4HAJZG.js → chunk-2XLKMZH5.js} +486 -252
- package/dist/chunk-2XLKMZH5.js.map +1 -0
- package/dist/{chunk-HGXVOFCL.js → chunk-3SIGXGAE.js} +133 -88
- package/dist/chunk-3SIGXGAE.js.map +1 -0
- package/dist/{chunk-WMIKJGXW.js → chunk-3VGTVZHL.js} +3 -3
- package/dist/{chunk-U7XWIOSB.js → chunk-5T76GARR.js} +2 -2
- package/dist/{chunk-WQFU635Q.js → chunk-ATVQQCYN.js} +8 -4
- package/dist/chunk-ATVQQCYN.js.map +1 -0
- package/dist/{chunk-QRS7Y3EM.js → chunk-B2MKB7NB.js} +2 -2
- package/dist/{chunk-H4NTJFEE.js → chunk-D3WOJTUY.js} +3 -2
- package/dist/{chunk-H4NTJFEE.js.map → chunk-D3WOJTUY.js.map} +1 -1
- package/dist/{chunk-EFUT3XKW.js → chunk-ETFWUMEJ.js} +2 -2
- package/dist/{chunk-B5XTGEBE.js → chunk-FPA3AVCP.js} +85 -8
- package/dist/chunk-FPA3AVCP.js.map +1 -0
- package/dist/{chunk-BVMR5OFW.js → chunk-HRJKDHHG.js} +6 -4
- package/dist/chunk-HRJKDHHG.js.map +1 -0
- package/dist/{chunk-VN5V2E2S.js → chunk-HRZLFJXX.js} +3 -3
- package/dist/{chunk-I54WQBXL.js → chunk-KD6MM67B.js} +6 -6
- package/dist/{chunk-ZHQK3MOM.js → chunk-LIMTJR3A.js} +3 -3
- package/dist/{chunk-GAIDBPFY.js → chunk-ONGOAEY6.js} +14 -2
- package/dist/chunk-ONGOAEY6.js.map +1 -0
- package/dist/{chunk-CMWZZZGW.js → chunk-QDYHSJT5.js} +22 -8
- package/dist/chunk-QDYHSJT5.js.map +1 -0
- package/dist/{chunk-VHGC44HA.js → chunk-RDL6QIQO.js} +2 -2
- package/dist/{chunk-LHX7ENKZ.js → chunk-S2IASCGW.js} +3 -3
- package/dist/{chunk-XON75UFN.js → chunk-SER76PQ7.js} +2 -2
- package/dist/{chunk-ETX25FTB.js → chunk-SMHZT6RM.js} +2 -2
- package/dist/{chunk-24N6A6SF.js → chunk-SQBYHWZU.js} +2 -2
- package/dist/{chunk-DF2QXVZ3.js → chunk-VBVFE33M.js} +5 -5
- package/dist/{chunk-53LLNDXF.js → chunk-VQGTYGZH.js} +2 -2
- package/dist/{chunk-OR3TMIJN.js → chunk-VTAGUWXH.js} +2 -2
- package/dist/{chunk-LR5CTOC5.js → chunk-XF3JR72U.js} +3 -3
- package/dist/{chunk-ZIFZFP5I.js → chunk-Y3I7SN5W.js} +61 -35
- package/dist/chunk-Y3I7SN5W.js.map +1 -0
- package/dist/{chunk-RRKRA237.js → chunk-Z4XGSEKC.js} +577 -249
- package/dist/chunk-Z4XGSEKC.js.map +1 -0
- package/dist/{chunk-K5LWSWV7.js → chunk-ZGZLN4LH.js} +2 -2
- package/dist/connected-evidence.js +14 -14
- package/dist/dataset-workspaces.js +14 -14
- package/dist/experiment-evaluation-schedules.js +18 -18
- package/dist/experiment-improvements.js +7 -7
- package/dist/experiments.js +17 -17
- package/dist/index.js +90 -45
- package/dist/index.js.map +1 -1
- package/dist/learning.js +113 -9
- package/dist/learning.js.map +1 -1
- package/dist/model-projects.js +1 -1
- package/dist/model-starter-attempts.js +2 -2
- package/dist/model-starter-catalog.js +9 -9
- package/dist/model-starters.js +13 -9
- package/dist/model-taskset-runs.js +3 -3
- package/dist/post-training.js +6 -6
- package/dist/taskset-drafts.js +12 -12
- package/dist/taskset-packages.js +15 -15
- package/dist/training-bundle.js +81 -19
- package/dist/training-bundle.js.map +1 -1
- package/dist/training.js +39 -7
- package/dist/types/packages/cloud/src/hosted-chat.d.ts +28 -0
- package/dist/types/packages/cloud/src/hosted-chat.d.ts.map +1 -1
- package/dist/types/packages/cloud/src/sandbox/sandbox-instance-client.d.ts.map +1 -1
- package/dist/types/packages/cloud/src/sandbox/url.d.ts +3 -1
- package/dist/types/packages/cloud/src/sandbox/url.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/connected-evidence-client.d.ts +4 -0
- package/dist/types/packages/sdk/src/connected-evidence-client.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/dataset-preparation-workspace.d.ts +2 -0
- package/dist/types/packages/sdk/src/dataset-preparation-workspace.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/dataset-workspace-client.d.ts +14 -0
- package/dist/types/packages/sdk/src/dataset-workspace-client.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/dataset-workspace-contracts.d.ts +4 -0
- package/dist/types/packages/sdk/src/dataset-workspace-contracts.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/dataset-workspace-operations.d.ts +4 -0
- package/dist/types/packages/sdk/src/dataset-workspace-operations.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/learning-client.d.ts +1 -0
- package/dist/types/packages/sdk/src/learning-client.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/learning-correction-metrics.d.ts +358 -0
- package/dist/types/packages/sdk/src/learning-correction-metrics.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/learning.d.ts +1 -0
- package/dist/types/packages/sdk/src/learning.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/managed-training-preparation.d.ts +24 -0
- package/dist/types/packages/sdk/src/managed-training-preparation.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/model-bound-taskset-authoring.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/model-learning-policy.d.ts +16 -0
- package/dist/types/packages/sdk/src/model-learning-policy.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/model-projects.d.ts +192 -0
- package/dist/types/packages/sdk/src/model-projects.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/model-starters.d.ts +84 -1
- package/dist/types/packages/sdk/src/model-starters.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/model-taskset-runs.d.ts +28 -28
- package/dist/types/packages/sdk/src/model-training-defaults.d.ts +14 -0
- package/dist/types/packages/sdk/src/model-training-defaults.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/post-training.d.ts +54 -0
- package/dist/types/packages/sdk/src/post-training.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-authored-files.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-authored-portable-release.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-draft-api-contracts.d.ts +4 -0
- package/dist/types/packages/sdk/src/taskset-draft-api-contracts.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-draft-client.d.ts +142 -120
- package/dist/types/packages/sdk/src/taskset-draft-client.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-draft-document.d.ts +4 -0
- package/dist/types/packages/sdk/src/taskset-draft-document.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-draft-source.d.ts +4 -0
- package/dist/types/packages/sdk/src/taskset-draft-source.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-draft-workspace.d.ts +4 -0
- package/dist/types/packages/sdk/src/taskset-draft-workspace.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-package-client.d.ts +63 -0
- package/dist/types/packages/sdk/src/taskset-package-client.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-package-contracts.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/taskset-package-projection.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/training-bundle.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/training-compute-selection.d.ts +52 -0
- package/dist/types/packages/sdk/src/training-compute-selection.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training-estimates.d.ts +1069 -0
- package/dist/types/packages/sdk/src/training-estimates.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training-learning-batch.d.ts +40 -40
- package/dist/types/packages/sdk/src/training-physical-placement.d.ts +16 -0
- package/dist/types/packages/sdk/src/training-physical-placement.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training-preparations.d.ts +248 -0
- package/dist/types/packages/sdk/src/training-preparations.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/training-qualification-preparation.d.ts +20 -0
- package/dist/types/packages/sdk/src/training-qualification-preparation.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/training-queue.d.ts +24 -0
- package/dist/types/packages/sdk/src/training-queue.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training-recipe-binding.d.ts.map +1 -1
- package/dist/types/packages/sdk/src/training-recovery.d.ts +85 -0
- package/dist/types/packages/sdk/src/training-recovery.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training-verifier-assets.d.ts +7 -0
- package/dist/types/packages/sdk/src/training-verifier-assets.d.ts.map +1 -0
- package/dist/types/packages/sdk/src/training.d.ts +599 -0
- package/dist/types/packages/sdk/src/training.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-B5XTGEBE.js.map +0 -1
- package/dist/chunk-BVMR5OFW.js.map +0 -1
- package/dist/chunk-CMWZZZGW.js.map +0 -1
- package/dist/chunk-GAIDBPFY.js.map +0 -1
- package/dist/chunk-HGXVOFCL.js.map +0 -1
- package/dist/chunk-MO4HAJZG.js.map +0 -1
- package/dist/chunk-RRKRA237.js.map +0 -1
- package/dist/chunk-WQFU635Q.js.map +0 -1
- package/dist/chunk-ZIFZFP5I.js.map +0 -1
- /package/dist/{chunk-WMIKJGXW.js.map → chunk-3VGTVZHL.js.map} +0 -0
- /package/dist/{chunk-U7XWIOSB.js.map → chunk-5T76GARR.js.map} +0 -0
- /package/dist/{chunk-QRS7Y3EM.js.map → chunk-B2MKB7NB.js.map} +0 -0
- /package/dist/{chunk-EFUT3XKW.js.map → chunk-ETFWUMEJ.js.map} +0 -0
- /package/dist/{chunk-VN5V2E2S.js.map → chunk-HRZLFJXX.js.map} +0 -0
- /package/dist/{chunk-I54WQBXL.js.map → chunk-KD6MM67B.js.map} +0 -0
- /package/dist/{chunk-ZHQK3MOM.js.map → chunk-LIMTJR3A.js.map} +0 -0
- /package/dist/{chunk-VHGC44HA.js.map → chunk-RDL6QIQO.js.map} +0 -0
- /package/dist/{chunk-LHX7ENKZ.js.map → chunk-S2IASCGW.js.map} +0 -0
- /package/dist/{chunk-XON75UFN.js.map → chunk-SER76PQ7.js.map} +0 -0
- /package/dist/{chunk-ETX25FTB.js.map → chunk-SMHZT6RM.js.map} +0 -0
- /package/dist/{chunk-24N6A6SF.js.map → chunk-SQBYHWZU.js.map} +0 -0
- /package/dist/{chunk-DF2QXVZ3.js.map → chunk-VBVFE33M.js.map} +0 -0
- /package/dist/{chunk-53LLNDXF.js.map → chunk-VQGTYGZH.js.map} +0 -0
- /package/dist/{chunk-OR3TMIJN.js.map → chunk-VTAGUWXH.js.map} +0 -0
- /package/dist/{chunk-LR5CTOC5.js.map → chunk-XF3JR72U.js.map} +0 -0
- /package/dist/{chunk-K5LWSWV7.js.map → chunk-ZGZLN4LH.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenPondLearningClient,
|
|
3
3
|
OpenPondLearningError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-D3WOJTUY.js";
|
|
5
5
|
import {
|
|
6
6
|
OpenPondProfileActionsClient
|
|
7
7
|
} from "./chunk-3DWPLYFJ.js";
|
|
@@ -66,7 +66,7 @@ import {
|
|
|
66
66
|
hashCollectorEligibleBoundaries,
|
|
67
67
|
summarizeCollectorCoverage,
|
|
68
68
|
verifyConnectedRecordedExecution
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-SQBYHWZU.js";
|
|
70
70
|
import {
|
|
71
71
|
AgentImportCommitRequestSchema,
|
|
72
72
|
AgentImportFileSchema,
|
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
ConnectedStartingAssetsReceiptSchema,
|
|
84
84
|
ConnectedStartingAssetsRequestSchema,
|
|
85
85
|
verifyConnectedStartingAssetsReceipt
|
|
86
|
-
} from "./chunk-
|
|
86
|
+
} from "./chunk-ETFWUMEJ.js";
|
|
87
87
|
import {
|
|
88
88
|
CandidateEvaluationControlSchema,
|
|
89
89
|
CandidateEvaluationOptionSchema,
|
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
CandidateEvaluationPreparationSchema,
|
|
92
92
|
CandidateEvaluationRequestSchema,
|
|
93
93
|
createCandidateEvaluationClient
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-SMHZT6RM.js";
|
|
95
95
|
import {
|
|
96
96
|
ExperimentImprovementClient,
|
|
97
97
|
HostedProfileCandidateCommandSchema,
|
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
HostedProfileCandidateReceiptSchema,
|
|
100
100
|
verifyHostedProfileCandidateExport,
|
|
101
101
|
verifyHostedProfileCandidateReceipt
|
|
102
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-VTAGUWXH.js";
|
|
103
103
|
import {
|
|
104
104
|
ExperimentEvaluationFireSchema,
|
|
105
105
|
ExperimentEvaluationScheduleCommandSchema,
|
|
@@ -110,7 +110,7 @@ import {
|
|
|
110
110
|
scheduledExperimentHash,
|
|
111
111
|
sealExperimentEvaluationSchedule,
|
|
112
112
|
verifyExperimentEvaluationSchedule
|
|
113
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-ZGZLN4LH.js";
|
|
114
114
|
import {
|
|
115
115
|
AdvancedRefinerEvaluationAccountingSchema,
|
|
116
116
|
AdvancedRefinerEvaluationCommandSchema,
|
|
@@ -125,7 +125,7 @@ import {
|
|
|
125
125
|
sealAdvancedRefinerEvaluationPin,
|
|
126
126
|
sealAdvancedRefinerReviewReceipt,
|
|
127
127
|
verifyAdvancedRefinerEvaluationPin
|
|
128
|
-
} from "./chunk-
|
|
128
|
+
} from "./chunk-RDL6QIQO.js";
|
|
129
129
|
import {
|
|
130
130
|
ExperimentImprovementCommandSchema,
|
|
131
131
|
ExperimentImprovementHumanOptionsSchema,
|
|
@@ -139,39 +139,39 @@ import {
|
|
|
139
139
|
sealExperimentImprovementState,
|
|
140
140
|
verifyExperimentImprovementHumanOptions,
|
|
141
141
|
verifyExperimentImprovementState
|
|
142
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-SER76PQ7.js";
|
|
143
143
|
import "./chunk-3B5KSH3V.js";
|
|
144
144
|
import {
|
|
145
145
|
OpenPondExperimentsClient
|
|
146
|
-
} from "./chunk-
|
|
147
|
-
import "./chunk-
|
|
148
|
-
import "./chunk-
|
|
146
|
+
} from "./chunk-KD6MM67B.js";
|
|
147
|
+
import "./chunk-VBVFE33M.js";
|
|
148
|
+
import "./chunk-HRJKDHHG.js";
|
|
149
149
|
import "./chunk-GPQLBVQC.js";
|
|
150
|
-
import "./chunk-
|
|
151
|
-
import "./chunk-
|
|
152
|
-
import "./chunk-
|
|
150
|
+
import "./chunk-QDYHSJT5.js";
|
|
151
|
+
import "./chunk-FPA3AVCP.js";
|
|
152
|
+
import "./chunk-XF3JR72U.js";
|
|
153
153
|
import "./chunk-Z252BNAZ.js";
|
|
154
|
-
import "./chunk-
|
|
155
|
-
import "./chunk-
|
|
154
|
+
import "./chunk-ATVQQCYN.js";
|
|
155
|
+
import "./chunk-ONGOAEY6.js";
|
|
156
156
|
import {
|
|
157
157
|
ConnectedDatasetSourceRefSchema,
|
|
158
158
|
serializeStructuredOutput,
|
|
159
159
|
structuredOutputTools,
|
|
160
160
|
structuredToolOutput,
|
|
161
161
|
validateOutputBytes
|
|
162
|
-
} from "./chunk-
|
|
162
|
+
} from "./chunk-2XLKMZH5.js";
|
|
163
163
|
import "./chunk-TK3DXH7A.js";
|
|
164
|
-
import "./chunk-
|
|
165
|
-
import "./chunk-
|
|
166
|
-
import "./chunk-
|
|
164
|
+
import "./chunk-Z4XGSEKC.js";
|
|
165
|
+
import "./chunk-LIMTJR3A.js";
|
|
166
|
+
import "./chunk-3VGTVZHL.js";
|
|
167
167
|
import "./chunk-Q4TKI2MV.js";
|
|
168
168
|
import "./chunk-H3367ISL.js";
|
|
169
|
-
import "./chunk-
|
|
169
|
+
import "./chunk-VQGTYGZH.js";
|
|
170
170
|
import "./chunk-O6FKHAWN.js";
|
|
171
|
-
import "./chunk-
|
|
172
|
-
import "./chunk-
|
|
173
|
-
import "./chunk-
|
|
174
|
-
import "./chunk-
|
|
171
|
+
import "./chunk-B2MKB7NB.js";
|
|
172
|
+
import "./chunk-HRZLFJXX.js";
|
|
173
|
+
import "./chunk-5T76GARR.js";
|
|
174
|
+
import "./chunk-3SIGXGAE.js";
|
|
175
175
|
import "./chunk-CL3IOOVL.js";
|
|
176
176
|
import "./chunk-H3JZ3P5T.js";
|
|
177
177
|
import "./chunk-YLJ4XMA6.js";
|
|
@@ -737,7 +737,7 @@ function parseProcessOutputEvent(event) {
|
|
|
737
737
|
}
|
|
738
738
|
|
|
739
739
|
// ../cloud/dist/sandbox/url.js
|
|
740
|
-
function normalizeSandboxApiUrl(baseUrlOrApiUrl) {
|
|
740
|
+
function normalizeSandboxApiUrl(baseUrlOrApiUrl, options = {}) {
|
|
741
741
|
const trimmed = baseUrlOrApiUrl.trim().replace(/\/$/, "");
|
|
742
742
|
if (!trimmed) {
|
|
743
743
|
throw new Error("sandbox API URL must be non-empty");
|
|
@@ -750,12 +750,13 @@ function normalizeSandboxApiUrl(baseUrlOrApiUrl) {
|
|
|
750
750
|
if (normalizedPath.endsWith("/v1")) {
|
|
751
751
|
return `${url.origin}${normalizedPath}/sandboxes`;
|
|
752
752
|
}
|
|
753
|
-
if (isOpenPondHostedApiHost(url.hostname)) {
|
|
754
|
-
return `${url.origin}${normalizedPath}/v1/sandboxes`;
|
|
755
|
-
}
|
|
756
753
|
if (url.origin === DEFAULT_OPENPOND_WEB_BASE_URL) {
|
|
757
754
|
return `${DEFAULT_OPENPOND_API_BASE_URL}/v1/sandboxes`;
|
|
758
755
|
}
|
|
756
|
+
const configuredApiOrigin = options.apiBaseUrl ? new URL(options.apiBaseUrl).origin : DEFAULT_OPENPOND_API_BASE_URL;
|
|
757
|
+
if (url.origin === configuredApiOrigin) {
|
|
758
|
+
return `${url.origin}${normalizedPath}/v1/sandboxes`;
|
|
759
|
+
}
|
|
759
760
|
return `${url.origin}${normalizedPath}/api/sandboxes`;
|
|
760
761
|
}
|
|
761
762
|
function apiRootUrlFromSandboxApiUrl(sandboxApiUrl) {
|
|
@@ -765,9 +766,6 @@ function apiRootUrlFromSandboxApiUrl(sandboxApiUrl) {
|
|
|
765
766
|
}
|
|
766
767
|
return sandboxApiUrl.slice(0, -suffix.length);
|
|
767
768
|
}
|
|
768
|
-
function isOpenPondHostedApiHost(hostname) {
|
|
769
|
-
return hostname === "api.openpond.ai" || hostname === "staging-api.openpond.ai" || hostname.startsWith("api") && hostname.endsWith(".openpond.ai");
|
|
770
|
-
}
|
|
771
769
|
|
|
772
770
|
// ../cloud/dist/sandbox/sandbox-instance-client.js
|
|
773
771
|
var OpenPondSandboxInstanceClient = class {
|
|
@@ -778,7 +776,10 @@ var OpenPondSandboxInstanceClient = class {
|
|
|
778
776
|
constructor(options) {
|
|
779
777
|
this.apiKey = options.apiKey;
|
|
780
778
|
this.customEndpoint = options.customEndpoint ?? false;
|
|
781
|
-
|
|
779
|
+
const configuredEndpoint2 = options.sandboxApiUrl ?? options.baseUrl ?? DEFAULT_OPENPOND_API_BASE_URL;
|
|
780
|
+
this.sandboxApiUrl = normalizeSandboxApiUrl(configuredEndpoint2, {
|
|
781
|
+
apiBaseUrl: this.customEndpoint ? void 0 : configuredEndpoint2
|
|
782
|
+
});
|
|
782
783
|
this.apiRootUrl = apiRootUrlFromSandboxApiUrl(this.sandboxApiUrl);
|
|
783
784
|
}
|
|
784
785
|
create(input, options = {}) {
|
|
@@ -1792,13 +1793,17 @@ function requireToken(value) {
|
|
|
1792
1793
|
throw new Error("OpenPond API key is required");
|
|
1793
1794
|
return trimmed;
|
|
1794
1795
|
}
|
|
1795
|
-
function hostedHeaders(token, accept, requestId) {
|
|
1796
|
+
function hostedHeaders(token, accept, requestId, teamId) {
|
|
1796
1797
|
const headers = new Headers();
|
|
1797
1798
|
headers.set("Authorization", `Bearer ${requireToken(token)}`);
|
|
1798
1799
|
headers.set("Content-Type", "application/json");
|
|
1799
1800
|
headers.set("Accept", accept);
|
|
1800
1801
|
headers.set("x-openpond-client", "openpond-code");
|
|
1801
|
-
|
|
1802
|
+
const operationId = requestId || randomUUID();
|
|
1803
|
+
headers.set("x-openpond-request-id", operationId);
|
|
1804
|
+
headers.set("x-request-id", operationId);
|
|
1805
|
+
if (teamId)
|
|
1806
|
+
headers.set("x-openpond-team-id", teamId);
|
|
1802
1807
|
return headers;
|
|
1803
1808
|
}
|
|
1804
1809
|
async function readError(response) {
|
|
@@ -1850,7 +1855,8 @@ async function listOpChatModels(options) {
|
|
|
1850
1855
|
const requestUrl = `${apiBaseUrl}/models`;
|
|
1851
1856
|
const response = await fetch(requestUrl, {
|
|
1852
1857
|
method: "GET",
|
|
1853
|
-
|
|
1858
|
+
redirect: "error",
|
|
1859
|
+
headers: hostedHeaders(options.token, "application/json", void 0, options.teamId),
|
|
1854
1860
|
signal: options.signal
|
|
1855
1861
|
});
|
|
1856
1862
|
if (!response.ok) {
|
|
@@ -1863,7 +1869,8 @@ async function getOpChatModel(options) {
|
|
|
1863
1869
|
const requestUrl = `${apiBaseUrl}/models/${encodeURIComponent(options.model)}`;
|
|
1864
1870
|
const response = await fetch(requestUrl, {
|
|
1865
1871
|
method: "GET",
|
|
1866
|
-
|
|
1872
|
+
redirect: "error",
|
|
1873
|
+
headers: hostedHeaders(options.token, "application/json", void 0, options.teamId),
|
|
1867
1874
|
signal: options.signal
|
|
1868
1875
|
});
|
|
1869
1876
|
if (!response.ok) {
|
|
@@ -1876,7 +1883,8 @@ async function listOpChatProviders(options) {
|
|
|
1876
1883
|
const requestUrl = `${apiBaseUrl}/providers`;
|
|
1877
1884
|
const response = await fetch(requestUrl, {
|
|
1878
1885
|
method: "GET",
|
|
1879
|
-
|
|
1886
|
+
redirect: "error",
|
|
1887
|
+
headers: hostedHeaders(options.token, "application/json", void 0, options.teamId),
|
|
1880
1888
|
signal: options.signal
|
|
1881
1889
|
});
|
|
1882
1890
|
if (!response.ok) {
|
|
@@ -1889,7 +1897,8 @@ async function getOpChatProvider(options) {
|
|
|
1889
1897
|
const requestUrl = `${apiBaseUrl}/providers/${encodeURIComponent(options.provider)}`;
|
|
1890
1898
|
const response = await fetch(requestUrl, {
|
|
1891
1899
|
method: "GET",
|
|
1892
|
-
|
|
1900
|
+
redirect: "error",
|
|
1901
|
+
headers: hostedHeaders(options.token, "application/json", void 0, options.teamId),
|
|
1893
1902
|
signal: options.signal
|
|
1894
1903
|
});
|
|
1895
1904
|
if (!response.ok) {
|
|
@@ -1902,7 +1911,8 @@ async function sendHostedChatTurn(options) {
|
|
|
1902
1911
|
const requestUrl = `${apiBaseUrl}/chat/completions`;
|
|
1903
1912
|
const response = await fetch(requestUrl, {
|
|
1904
1913
|
method: "POST",
|
|
1905
|
-
|
|
1914
|
+
redirect: "error",
|
|
1915
|
+
headers: hostedHeaders(options.token, "application/json", options.requestId, options.teamId),
|
|
1906
1916
|
body: JSON.stringify(buildHostedChatBody(options, false)),
|
|
1907
1917
|
signal: options.signal
|
|
1908
1918
|
});
|
|
@@ -1911,10 +1921,11 @@ async function sendHostedChatTurn(options) {
|
|
|
1911
1921
|
}
|
|
1912
1922
|
return await response.json();
|
|
1913
1923
|
}
|
|
1914
|
-
async function* parseOpenAISSE(stream, signal) {
|
|
1924
|
+
async function* parseOpenAISSE(stream, signal, observe) {
|
|
1915
1925
|
const reader = stream.getReader();
|
|
1916
1926
|
const decoder = new TextDecoder();
|
|
1917
1927
|
let buffer = "";
|
|
1928
|
+
let sawDone = false;
|
|
1918
1929
|
const readAbortError = () => signal?.reason instanceof Error ? signal.reason : new Error("hosted_chat_aborted");
|
|
1919
1930
|
try {
|
|
1920
1931
|
while (true) {
|
|
@@ -1923,22 +1934,38 @@ async function* parseOpenAISSE(stream, signal) {
|
|
|
1923
1934
|
const result = await reader.read();
|
|
1924
1935
|
if (result.done)
|
|
1925
1936
|
break;
|
|
1937
|
+
observe?.({ type: "bytes", byteLength: result.value.byteLength });
|
|
1926
1938
|
buffer += decoder.decode(result.value, { stream: true });
|
|
1927
1939
|
const lines = buffer.split("\n");
|
|
1928
1940
|
buffer = lines.pop() || "";
|
|
1929
1941
|
for (const line of lines) {
|
|
1930
1942
|
const trimmed = line.trim();
|
|
1943
|
+
if (trimmed.startsWith(":"))
|
|
1944
|
+
observe?.({ type: "comment" });
|
|
1931
1945
|
if (!trimmed.startsWith("data:"))
|
|
1932
1946
|
continue;
|
|
1933
1947
|
const data = trimmed.slice(5).trim();
|
|
1934
1948
|
if (!data)
|
|
1935
1949
|
continue;
|
|
1936
|
-
if (data === "[DONE]")
|
|
1950
|
+
if (data === "[DONE]") {
|
|
1951
|
+
sawDone = true;
|
|
1952
|
+
observe?.({ type: "done" });
|
|
1937
1953
|
return;
|
|
1938
|
-
|
|
1954
|
+
}
|
|
1955
|
+
const parsed = JSON.parse(data);
|
|
1956
|
+
observe?.({
|
|
1957
|
+
type: "data",
|
|
1958
|
+
errorFrame: Boolean(parsed && typeof parsed === "object" && "error" in parsed)
|
|
1959
|
+
});
|
|
1960
|
+
yield parsed;
|
|
1939
1961
|
}
|
|
1940
1962
|
}
|
|
1963
|
+
throw new Error("Hosted chat stream ended before [DONE].");
|
|
1941
1964
|
} finally {
|
|
1965
|
+
if (!sawDone) {
|
|
1966
|
+
await reader.cancel().catch(() => {
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1942
1969
|
try {
|
|
1943
1970
|
reader.releaseLock();
|
|
1944
1971
|
} catch {
|
|
@@ -1948,16 +1975,34 @@ async function* parseOpenAISSE(stream, signal) {
|
|
|
1948
1975
|
async function* streamHostedChatTurn(options) {
|
|
1949
1976
|
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
1950
1977
|
const requestUrl = `${apiBaseUrl}/chat/completions`;
|
|
1978
|
+
const started = performance.now();
|
|
1979
|
+
const observe = (event) => {
|
|
1980
|
+
try {
|
|
1981
|
+
options.onStreamDiagnostic?.({ ...event, elapsedMs: Math.round(performance.now() - started) });
|
|
1982
|
+
} catch {
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
observe({ type: "request" });
|
|
1951
1986
|
const response = await fetch(requestUrl, {
|
|
1952
1987
|
method: "POST",
|
|
1953
|
-
|
|
1988
|
+
redirect: "error",
|
|
1989
|
+
headers: hostedHeaders(options.token, "text/event-stream", options.requestId, options.teamId),
|
|
1954
1990
|
body: JSON.stringify(buildHostedChatBody(options, true)),
|
|
1955
1991
|
signal: options.signal
|
|
1956
1992
|
});
|
|
1993
|
+
const cacheControl = response.headers.get("cache-control")?.toLowerCase().split(",").map((value) => value.trim()) ?? [];
|
|
1994
|
+
observe({
|
|
1995
|
+
type: "headers",
|
|
1996
|
+
status: response.status,
|
|
1997
|
+
eventStream: response.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() === "text/event-stream",
|
|
1998
|
+
noCache: cacheControl.includes("no-cache"),
|
|
1999
|
+
noTransform: cacheControl.includes("no-transform"),
|
|
2000
|
+
bufferingDisabled: response.headers.get("x-accel-buffering")?.toLowerCase() === "no"
|
|
2001
|
+
});
|
|
1957
2002
|
if (!response.ok || !response.body) {
|
|
1958
2003
|
throw new Error(`Hosted chat stream failed: ${response.status} ${await readError(response)}`);
|
|
1959
2004
|
}
|
|
1960
|
-
for await (const raw of parseOpenAISSE(response.body, options.signal)) {
|
|
2005
|
+
for await (const raw of parseOpenAISSE(response.body, options.signal, observe)) {
|
|
1961
2006
|
const chunk = raw;
|
|
1962
2007
|
if (chunk.error) {
|
|
1963
2008
|
throw new Error(chunk.error.message || "Hosted chat stream error");
|