@pantheon.ai/mcp 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-DnpqwBBd.js +121 -0
- package/dist/bundle-stats.html +2 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +384 -409
- package/dist/schema.d.ts +471 -0
- package/dist/schema.js +1 -0
- package/dist/src-Dr_TLp_h.js +785 -0
- package/package.json +8 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { parseTemplate } from "url-template";
|
|
2
|
+
|
|
3
|
+
//#region packages/sdk/src/lib/stream-parser.ts
|
|
4
|
+
var StreamResponseParser = class {
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
async handleResponse(response, context) {
|
|
10
|
+
this.options.validateResponse?.(response);
|
|
11
|
+
if (!response.body) throw new Error("Response body is missing");
|
|
12
|
+
return this.options.pipe(response.body, Object.freeze({
|
|
13
|
+
...context,
|
|
14
|
+
response
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region packages/sdk/src/lib/validator.ts
|
|
21
|
+
const VALIDATOR_SYMBOL = Symbol("validator");
|
|
22
|
+
function isValidator(object) {
|
|
23
|
+
return typeof object === "object" && object !== null && object[VALIDATOR_SYMBOL] === true && typeof object.parse === "function";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region packages/sdk/src/lib/api.ts
|
|
28
|
+
function typeOf() {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function createUrlTemplate(method) {
|
|
32
|
+
return function(arr, ...params) {
|
|
33
|
+
let url = arr[0];
|
|
34
|
+
let expandedPaths = false;
|
|
35
|
+
for (let i = 1; i < arr.length; i++) if (params[i - 1] === "path*") {
|
|
36
|
+
url += "<path*>";
|
|
37
|
+
expandedPaths = true;
|
|
38
|
+
} else url += "{" + params[i - 1].replace(/\?$/, "") + "}" + arr[i];
|
|
39
|
+
const [pathPart, searchPart] = url.split("?");
|
|
40
|
+
const pathPartTemplate = expandedPaths ? { expand: (context) => {
|
|
41
|
+
return parseTemplate(pathPart.replace(/<path\*>/, String(context["path*"]).replace(/^\//, ""))).expand(context);
|
|
42
|
+
} } : parseTemplate(pathPart);
|
|
43
|
+
const searchParamsBuilders = [];
|
|
44
|
+
if (searchPart) searchPart.split("&").forEach((entry) => {
|
|
45
|
+
const [key, value = ""] = entry.split("=").map(decodeURIComponent);
|
|
46
|
+
if (/^\{[^}]+}$/.test(value)) {
|
|
47
|
+
const templateValue = value.slice(1, -1);
|
|
48
|
+
searchParamsBuilders.push((usp, context) => {
|
|
49
|
+
if (templateValue in context) {
|
|
50
|
+
const value = context[templateValue];
|
|
51
|
+
if (value === void 0) return;
|
|
52
|
+
if (Array.isArray(value)) value.forEach((v) => usp.append(key, String(v)));
|
|
53
|
+
else usp.append(key, String(value));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
} else if (value !== "") {
|
|
57
|
+
const template = parseTemplate(value);
|
|
58
|
+
searchParamsBuilders.push((usp, context) => {
|
|
59
|
+
usp.append(key, template.expand(context));
|
|
60
|
+
});
|
|
61
|
+
} else searchParamsBuilders.push((usp) => {
|
|
62
|
+
usp.append(key, "");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
method,
|
|
67
|
+
signature: `${method} ${url}`,
|
|
68
|
+
templateUrl: url,
|
|
69
|
+
template: { expand: (context) => {
|
|
70
|
+
const pathPart = pathPartTemplate.expand(context);
|
|
71
|
+
const usp = new URLSearchParams();
|
|
72
|
+
searchParamsBuilders.forEach((template) => {
|
|
73
|
+
template(usp, context);
|
|
74
|
+
});
|
|
75
|
+
if (Array.from(usp).length > 0) return pathPart + "?" + usp.toString();
|
|
76
|
+
else return pathPart;
|
|
77
|
+
} },
|
|
78
|
+
__params__: typeOf()
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const get = createUrlTemplate("get");
|
|
83
|
+
const post = createUrlTemplate("post");
|
|
84
|
+
const put = createUrlTemplate("put");
|
|
85
|
+
const del = createUrlTemplate("delete");
|
|
86
|
+
const patch = createUrlTemplate("patch");
|
|
87
|
+
function defineApi(urlTemplate, _type, responseSchema) {
|
|
88
|
+
const method = urlTemplate.method;
|
|
89
|
+
return {
|
|
90
|
+
method: urlTemplate.method,
|
|
91
|
+
signature: urlTemplate.signature,
|
|
92
|
+
url: ((params) => urlTemplate.template.expand(params ?? {})),
|
|
93
|
+
requestInit: (body) => {
|
|
94
|
+
if (method === "get" || method === "delete") return { method };
|
|
95
|
+
if (body instanceof ReadableStream) return {
|
|
96
|
+
method,
|
|
97
|
+
body,
|
|
98
|
+
duplex: "half"
|
|
99
|
+
};
|
|
100
|
+
else if (body instanceof FormData) return {
|
|
101
|
+
method,
|
|
102
|
+
body
|
|
103
|
+
};
|
|
104
|
+
else return {
|
|
105
|
+
method,
|
|
106
|
+
body: JSON.stringify(body),
|
|
107
|
+
headers: { "Content-Type": "application/json" }
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
handleResponse: async (response, context) => {
|
|
111
|
+
if (responseSchema instanceof StreamResponseParser) return responseSchema.handleResponse(response, context);
|
|
112
|
+
else if (responseSchema === "raw") return response;
|
|
113
|
+
else if (responseSchema === "text") return await response.text();
|
|
114
|
+
else if (isValidator(responseSchema)) return responseSchema.parse(response);
|
|
115
|
+
else return responseSchema.parse(await response.json());
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { typeOf as a, post as i, del as n, VALIDATOR_SYMBOL as o, get as r, StreamResponseParser as s, defineApi as t };
|