@proofline/sdk 1.0.1 → 1.0.3
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 +44 -0
- package/dist/exports.d.ts +11 -0
- package/dist/exports.js +94 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/knowledge.d.ts +31 -0
- package/dist/knowledge.js +87 -0
- package/dist/operations.d.ts +5 -0
- package/dist/operations.js +6 -0
- package/dist/schema.d.ts +621 -7
- package/dist/transport.d.ts +1 -1
- package/dist/transport.js +29 -6
- package/openapi.public.json +1228 -24
- package/package.json +1 -1
package/dist/transport.d.ts
CHANGED
|
@@ -33,6 +33,6 @@ export declare class Transport {
|
|
|
33
33
|
#private;
|
|
34
34
|
constructor(options: ClientOptions);
|
|
35
35
|
reviewUrl(orgId: string, reviewId: string): string;
|
|
36
|
-
request<T>(method: string, template: string, parameters: Parameters, deadline?: number, body?: object): Promise<T>;
|
|
36
|
+
request<T>(method: string, template: string, parameters: Parameters, deadline?: number, body?: object, decode?: (text: string, headers: Headers) => unknown, accept?: string, mcpPhase?: "initialize" | "notification" | "call"): Promise<T>;
|
|
37
37
|
}
|
|
38
38
|
export {};
|
package/dist/transport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const VERSION = "1.0.
|
|
1
|
+
const VERSION = "1.0.3";
|
|
2
2
|
const MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
3
3
|
const MAX_RETRIES = 3;
|
|
4
4
|
const MAX_RETRY_SECONDS = 60;
|
|
@@ -82,7 +82,7 @@ function positive(value, name) {
|
|
|
82
82
|
}
|
|
83
83
|
return value;
|
|
84
84
|
}
|
|
85
|
-
async function
|
|
85
|
+
async function decoded(response, deadline, signal, waitTimeout, decode) {
|
|
86
86
|
const reader = response.body?.getReader();
|
|
87
87
|
if (!reader) {
|
|
88
88
|
throw new ProoflineError(response.status, "urn:proofline:sdk:invalid-response", "the response has no JSON body");
|
|
@@ -107,7 +107,10 @@ async function json(response, deadline, signal, waitTimeout) {
|
|
|
107
107
|
data.set(chunk, offset);
|
|
108
108
|
offset += chunk.length;
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(data);
|
|
111
|
+
return response.ok
|
|
112
|
+
? decode(text, response.headers)
|
|
113
|
+
: JSON.parse(text);
|
|
111
114
|
}
|
|
112
115
|
catch (error) {
|
|
113
116
|
if (error instanceof ProoflineError)
|
|
@@ -185,7 +188,7 @@ export class Transport {
|
|
|
185
188
|
reviewUrl(orgId, reviewId) {
|
|
186
189
|
return new URL(`/orgs/by-id/${coordinate(orgId)}/reviews/${coordinate(reviewId)}`, this.#base).href;
|
|
187
190
|
}
|
|
188
|
-
async request(method, template, parameters, deadline, body) {
|
|
191
|
+
async request(method, template, parameters, deadline, body, decode = (text) => JSON.parse(text), accept = "application/json, application/problem+json", mcpPhase) {
|
|
189
192
|
const path = Object.entries(parameters.path ?? {}).reduce((value, [key, coordinateValue]) => value.replace(`{${key}}`, coordinate(coordinateValue)), template);
|
|
190
193
|
if (/[{}]/.test(path))
|
|
191
194
|
throw new TypeError("a required path coordinate is missing");
|
|
@@ -195,13 +198,20 @@ export class Transport {
|
|
|
195
198
|
url.searchParams.set(key, String(value));
|
|
196
199
|
}
|
|
197
200
|
const requestBody = body === undefined ? undefined : JSON.stringify(body);
|
|
201
|
+
if (mcpPhase && new TextEncoder().encode(requestBody).length > 8192)
|
|
202
|
+
throw new TypeError("MCP request exceeds 8192 bytes");
|
|
198
203
|
for (let attempt = 0;; attempt += 1) {
|
|
199
204
|
const headers = new Headers({
|
|
200
|
-
Accept:
|
|
205
|
+
Accept: accept,
|
|
201
206
|
"User-Agent": `proofline-typescript/${VERSION}`,
|
|
202
207
|
});
|
|
203
208
|
if (requestBody !== undefined)
|
|
204
209
|
headers.set("Content-Type", "application/json");
|
|
210
|
+
if (mcpPhase) {
|
|
211
|
+
headers.set("Origin", this.#base.origin);
|
|
212
|
+
if (mcpPhase !== "initialize")
|
|
213
|
+
headers.set("MCP-Protocol-Version", "2025-11-25");
|
|
214
|
+
}
|
|
205
215
|
this.#token.apply(headers);
|
|
206
216
|
const now = performance.now();
|
|
207
217
|
const waitRemaining = deadline === undefined ? this.#timeout : deadline - now;
|
|
@@ -227,7 +237,20 @@ export class Transport {
|
|
|
227
237
|
throw new ProoflineError(0, "urn:proofline:sdk:timeout", "the review wait deadline expired");
|
|
228
238
|
throw new ProoflineError(0, "urn:proofline:sdk:transport", "the request did not receive a response within its timeout");
|
|
229
239
|
}
|
|
230
|
-
|
|
240
|
+
if (mcpPhase && response.ok) {
|
|
241
|
+
const notification = mcpPhase === "notification";
|
|
242
|
+
if (response.status !== (notification ? 202 : 200) ||
|
|
243
|
+
response.headers.has("mcp-session-id") ||
|
|
244
|
+
(!notification &&
|
|
245
|
+
response.headers.get("content-type")?.split(";")[0]?.trim() !==
|
|
246
|
+
"application/json")) {
|
|
247
|
+
await response.body?.cancel();
|
|
248
|
+
throw new ProoflineError(0, "urn:proofline:sdk:mcp", "Unsupported MCP response");
|
|
249
|
+
}
|
|
250
|
+
if (notification && !response.body)
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
const value = await decoded(response, requestDeadline, signal, waitTimeout, decode);
|
|
231
254
|
if (response.ok)
|
|
232
255
|
return value;
|
|
233
256
|
const error = problem(response.status, value);
|