@skydiveai/pi-extensions 0.1.0-beta.2398 → 0.1.0-beta.2401
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/index.mjs +22 -85
- package/package.json +1 -3
package/dist/index.mjs
CHANGED
|
@@ -12,8 +12,6 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
12
12
|
import { StdioClientTransport, getDefaultEnvironment } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
13
13
|
import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
14
14
|
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
15
|
-
import { Ajv } from "ajv";
|
|
16
|
-
import addFormats from "ajv-formats";
|
|
17
15
|
import { Check, Errors } from "typebox/value";
|
|
18
16
|
import { hc } from "hono/client";
|
|
19
17
|
import { ROOT_CONTEXT, SpanStatusCode, propagation, trace } from "@opentelemetry/api";
|
|
@@ -261,7 +259,7 @@ function createHealthHandler({ metadata }) {
|
|
|
261
259
|
* read on the hot path before every LLM call), it falls back to the default
|
|
262
260
|
* for that knob and logs once.
|
|
263
261
|
*/
|
|
264
|
-
const log$
|
|
262
|
+
const log$15 = logger.child({ module: "context-management-config" });
|
|
265
263
|
const DEFAULT_CONTEXT_MANAGEMENT_CONFIG = {
|
|
266
264
|
enabled: false,
|
|
267
265
|
perResultMaxBytes: 16 * 1024,
|
|
@@ -309,7 +307,7 @@ function resolveContextManagementConfig(env = process.env) {
|
|
|
309
307
|
maxModelCallsPerTurn: env.SKYDIVE_CTX_MAX_MODEL_CALLS
|
|
310
308
|
});
|
|
311
309
|
if (!parsed.success) {
|
|
312
|
-
log$
|
|
310
|
+
log$15.warn({
|
|
313
311
|
event: "context_management_config_invalid",
|
|
314
312
|
err: parsed.error
|
|
315
313
|
}, "falling back to default context-management config");
|
|
@@ -421,7 +419,7 @@ function installIterationCap({ session, log }, configOverride = null) {
|
|
|
421
419
|
const CAPABILITY_SOUL_NUDGE = "New capability gained — once the current task is done, if this changes what you can do for the user, record it in `soul.md` so it carries into future conversations rather than being rediscovered from scratch (then commit and push).";
|
|
422
420
|
//#endregion
|
|
423
421
|
//#region src/extensions/tool-call-summary.ts
|
|
424
|
-
const log$
|
|
422
|
+
const log$14 = logger.child({ module: "tool-call-summary-extension" });
|
|
425
423
|
/**
|
|
426
424
|
* The injected parameter name: a namespaced sentinel, so it can never collide
|
|
427
425
|
* with a real tool argument and is unmistakable in transcripts and logs. The
|
|
@@ -629,7 +627,7 @@ function withSummaryStrippedBeforeValidation(tool) {
|
|
|
629
627
|
try {
|
|
630
628
|
stripped = withoutInjectedSummary(args);
|
|
631
629
|
} catch (err) {
|
|
632
|
-
log$
|
|
630
|
+
log$14.error({
|
|
633
631
|
err,
|
|
634
632
|
event: "tool_call_summary_prepare_strip_failed",
|
|
635
633
|
toolName: tool.name
|
|
@@ -659,7 +657,7 @@ function stripInjectedSummary(pi, toolName, input) {
|
|
|
659
657
|
if (toolDeclaresSummaryParam(pi, toolName)) return;
|
|
660
658
|
delete input[TOOL_CALL_SUMMARY_FIELD];
|
|
661
659
|
} catch (err) {
|
|
662
|
-
log$
|
|
660
|
+
log$14.error({
|
|
663
661
|
err,
|
|
664
662
|
event: "tool_call_summary_strip_failed",
|
|
665
663
|
toolName
|
|
@@ -675,7 +673,7 @@ function buildInjectedPayload(pi, payload) {
|
|
|
675
673
|
try {
|
|
676
674
|
return injectToolCallSummary(payload, getStrictToolNames(pi));
|
|
677
675
|
} catch (err) {
|
|
678
|
-
log$
|
|
676
|
+
log$14.error({
|
|
679
677
|
err,
|
|
680
678
|
event: "tool_call_summary_injection_failed"
|
|
681
679
|
}, "tool_call_summary injection failed; passing payload through unchanged");
|
|
@@ -712,7 +710,7 @@ const toolCallSummaryExtension = (pi) => {
|
|
|
712
710
|
* or `ToolDefinition[]`. Files starting with `_` or `.` are skipped, so
|
|
713
711
|
* `tools/_example.ts` documents the shape without registering.
|
|
714
712
|
*/
|
|
715
|
-
const log$
|
|
713
|
+
const log$13 = logger.child({ module: "local-tools-extension" });
|
|
716
714
|
const TOOLS_DIRNAME = "tools";
|
|
717
715
|
const fileState = /* @__PURE__ */ new Map();
|
|
718
716
|
let pendingLocalToolsUpdate = null;
|
|
@@ -856,7 +854,7 @@ async function reconcileAndQueue({ pi, dir, reason }) {
|
|
|
856
854
|
dir
|
|
857
855
|
});
|
|
858
856
|
if (reason !== "session_start" && summaryHasChanges$1(summary)) pendingLocalToolsUpdate = summary;
|
|
859
|
-
log$
|
|
857
|
+
log$13.info({
|
|
860
858
|
event: "local_tools_reconcile",
|
|
861
859
|
reason,
|
|
862
860
|
total_tools: summary.totalTools,
|
|
@@ -878,7 +876,7 @@ const localToolsExtension = (pi) => {
|
|
|
878
876
|
reason: "session_start"
|
|
879
877
|
});
|
|
880
878
|
} catch (err) {
|
|
881
|
-
log$
|
|
879
|
+
log$13.error({
|
|
882
880
|
err,
|
|
883
881
|
event: "local_tools_reconcile_failed"
|
|
884
882
|
}, "local tools reconcile failed");
|
|
@@ -890,7 +888,7 @@ const localToolsExtension = (pi) => {
|
|
|
890
888
|
try {
|
|
891
889
|
current = await listToolFiles(dir);
|
|
892
890
|
} catch (err) {
|
|
893
|
-
log$
|
|
891
|
+
log$13.warn({
|
|
894
892
|
err,
|
|
895
893
|
event: "local_tools_listing_failed"
|
|
896
894
|
}, "tools/ listing failed");
|
|
@@ -912,7 +910,7 @@ const localToolsExtension = (pi) => {
|
|
|
912
910
|
reason: "auto_reload"
|
|
913
911
|
});
|
|
914
912
|
} catch (err) {
|
|
915
|
-
log$
|
|
913
|
+
log$13.error({
|
|
916
914
|
err,
|
|
917
915
|
event: "local_tools_auto_reload_failed"
|
|
918
916
|
}, "auto-reload after tools/ change failed");
|
|
@@ -943,77 +941,6 @@ function createStderrBuffer({ maxBytes }) {
|
|
|
943
941
|
};
|
|
944
942
|
}
|
|
945
943
|
//#endregion
|
|
946
|
-
//#region src/extensions/mcp/schema-validator.ts
|
|
947
|
-
/**
|
|
948
|
-
* Lenient JSON-schema validator for MCP tool output schemas.
|
|
949
|
-
*
|
|
950
|
-
* The MCP SDK's `Client.listTools()` eagerly compiles every tool's
|
|
951
|
-
* `outputSchema` (`cacheToolMetadata`), and its default AJV instance
|
|
952
|
-
* compiles `pattern` with the `u` (unicode) flag. Real vendor servers
|
|
953
|
-
* ship legacy Annex-B escapes in their patterns — PayPal's hosted MCP
|
|
954
|
-
* publishes `^https\:\/\/`, whose `\:` is a hard SyntaxError under `/u`
|
|
955
|
-
* ("Invalid regular expression: /^https\:\/\//u: Invalid escape").
|
|
956
|
-
* With the default validator that one schema throws inside `listTools`,
|
|
957
|
-
* the whole server lands in `failed`, and zero tools bind even though
|
|
958
|
-
* the credential is live.
|
|
959
|
-
*
|
|
960
|
-
* Two layers of leniency, both scoped to *output* validation (tool
|
|
961
|
-
* results), never to anything security-relevant:
|
|
962
|
-
*
|
|
963
|
-
* 1. `unicodeRegExp: false` — compile `pattern` without the `u` flag,
|
|
964
|
-
* which restores Annex-B tolerance for escapes like `\:` and matches
|
|
965
|
-
* what most other MCP clients (and JSON Schema's own spec, which
|
|
966
|
-
* does not require unicode mode) accept.
|
|
967
|
-
* 2. A compile failure on one tool's schema must not kill the server:
|
|
968
|
-
* `getValidator` catches the throw and degrades to a pass-through
|
|
969
|
-
* validator for that tool only, so its results are simply not
|
|
970
|
-
* output-validated while every other tool stays fully functional.
|
|
971
|
-
*/
|
|
972
|
-
const log$13 = logger.child({ module: "mcp-schema-validator" });
|
|
973
|
-
function createLenientAjv() {
|
|
974
|
-
const ajv = new Ajv({
|
|
975
|
-
strict: false,
|
|
976
|
-
validateFormats: true,
|
|
977
|
-
validateSchema: false,
|
|
978
|
-
allErrors: true,
|
|
979
|
-
unicodeRegExp: false
|
|
980
|
-
});
|
|
981
|
-
addFormats(ajv);
|
|
982
|
-
return ajv;
|
|
983
|
-
}
|
|
984
|
-
var LenientJsonSchemaValidator = class {
|
|
985
|
-
ajv = createLenientAjv();
|
|
986
|
-
getValidator(schema) {
|
|
987
|
-
let compiled = null;
|
|
988
|
-
try {
|
|
989
|
-
compiled = this.ajv.compile(schema);
|
|
990
|
-
} catch (err) {
|
|
991
|
-
log$13.warn({
|
|
992
|
-
err,
|
|
993
|
-
event: "mcp_output_schema_compile_failed"
|
|
994
|
-
}, "tool outputSchema failed to compile; skipping output validation for this tool");
|
|
995
|
-
return (input) => ({
|
|
996
|
-
valid: true,
|
|
997
|
-
data: input,
|
|
998
|
-
errorMessage: void 0
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
const validate = compiled;
|
|
1002
|
-
return (input) => {
|
|
1003
|
-
if (validate(input)) return {
|
|
1004
|
-
valid: true,
|
|
1005
|
-
data: input,
|
|
1006
|
-
errorMessage: void 0
|
|
1007
|
-
};
|
|
1008
|
-
return {
|
|
1009
|
-
valid: false,
|
|
1010
|
-
data: void 0,
|
|
1011
|
-
errorMessage: this.ajv.errorsText(validate.errors)
|
|
1012
|
-
};
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
};
|
|
1016
|
-
//#endregion
|
|
1017
944
|
//#region src/extensions/mcp/connect-client.ts
|
|
1018
945
|
/**
|
|
1019
946
|
* Spawns an MCP server's transport and races the initialize handshake
|
|
@@ -1027,6 +954,16 @@ var LenientJsonSchemaValidator = class {
|
|
|
1027
954
|
* The transport stays alive — caller holds the client so the bridge's
|
|
1028
955
|
* callback server keeps listening and a later reconcile re-probes.
|
|
1029
956
|
*/
|
|
957
|
+
var SkipOutputSchemaValidation = class {
|
|
958
|
+
getValidator(_schema) {
|
|
959
|
+
return (input) => ({
|
|
960
|
+
valid: true,
|
|
961
|
+
data: input,
|
|
962
|
+
errorMessage: void 0
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
const skipOutputSchemaValidation = new SkipOutputSchemaValidation();
|
|
1030
967
|
const DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
|
|
1031
968
|
const STDERR_BUFFER_BYTES = 4096;
|
|
1032
969
|
const SESSION_NOT_FOUND_RETRY_DELAYS_MS = [
|
|
@@ -1166,7 +1103,7 @@ async function connectClient(id, config, opts = {}) {
|
|
|
1166
1103
|
version: "0.1.0"
|
|
1167
1104
|
}, {
|
|
1168
1105
|
capabilities: {},
|
|
1169
|
-
jsonSchemaValidator:
|
|
1106
|
+
jsonSchemaValidator: skipOutputSchemaValidation
|
|
1170
1107
|
});
|
|
1171
1108
|
if (config.transport === "http") return connectHttp(id, config, client);
|
|
1172
1109
|
const params = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skydiveai/pi-extensions",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2401",
|
|
4
4
|
"homepage": "https://skydive.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Create, Inc.",
|
|
@@ -36,8 +36,6 @@
|
|
|
36
36
|
"@opentelemetry/sdk-trace-node": "^1.30.1",
|
|
37
37
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
38
38
|
"@skydiveai/pi-server": "^0.1.0",
|
|
39
|
-
"ajv": "^8.17.1",
|
|
40
|
-
"ajv-formats": "^3.0.1",
|
|
41
39
|
"hono": "^4.6.14",
|
|
42
40
|
"pino": "^9.6.0",
|
|
43
41
|
"shell-quote": "^1.8.4",
|