@skydiveai/pi-extensions 0.1.258-beta.117 → 0.1.258-beta.118
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.d.mts +19 -1
- package/dist/index.mjs +60 -29
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { A2AOptions, Middleware, ProtocolsOptions } from "@skydiveai/pi-server";
|
|
2
3
|
import { AgentSession, ExtensionFactory } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { Type } from "typebox";
|
|
4
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
|
+
import * as _$qs from "qs";
|
|
7
|
+
import * as _$express from "express";
|
|
5
8
|
import { Logger } from "pino";
|
|
6
9
|
|
|
10
|
+
//#region ../../node_modules/@types/express-serve-static-core/index.d.ts
|
|
11
|
+
declare global {
|
|
12
|
+
namespace Express {
|
|
13
|
+
// These open interfaces may be extended in an application-specific manner via declaration merging.
|
|
14
|
+
// See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
|
|
15
|
+
interface Request {}
|
|
16
|
+
interface Response {}
|
|
17
|
+
interface Locals {}
|
|
18
|
+
interface Application {}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
interface ParamsDictionary {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
7
25
|
//#region src/harness.d.ts
|
|
8
26
|
type CreateHarnessOptions = ProtocolsOptions & {
|
|
9
27
|
cwd: string;
|
|
@@ -26,7 +44,7 @@ declare function createHarness(options: CreateHarnessOptions): {
|
|
|
26
44
|
};
|
|
27
45
|
protocols: {
|
|
28
46
|
handlers: {
|
|
29
|
-
/** Express-style; mount at /a2a. */a2a: RequestHandler
|
|
47
|
+
/** Express-style; mount at /a2a. */a2a: _$express.RequestHandler<ParamsDictionary, any, any, _$qs.ParsedQs, Record<string, any>>; /** GET /.well-known/agent-card.json. */
|
|
30
48
|
agentCard: Middleware; /** Mirrors each vendor's API shape. */
|
|
31
49
|
openai: {
|
|
32
50
|
v1: {
|
package/dist/index.mjs
CHANGED
|
@@ -265,7 +265,7 @@ function createHealthHandler({ metadata }) {
|
|
|
265
265
|
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).";
|
|
266
266
|
//#endregion
|
|
267
267
|
//#region src/extensions/tool-call-summary.ts
|
|
268
|
-
const log$
|
|
268
|
+
const log$20 = logger.child({ module: "tool-call-summary-extension" });
|
|
269
269
|
/**
|
|
270
270
|
* The injected parameter name. Deliberately markdown-safe: the previous wire
|
|
271
271
|
* name (`__skydive_summary__`, now `TOOL_CALL_SUMMARY_FIELD_LEGACY`) carried
|
|
@@ -499,7 +499,7 @@ function withSummaryStrippedBeforeValidation(tool) {
|
|
|
499
499
|
try {
|
|
500
500
|
stripped = withoutInjectedSummary(args);
|
|
501
501
|
} catch (err) {
|
|
502
|
-
log$
|
|
502
|
+
log$20.error({
|
|
503
503
|
err,
|
|
504
504
|
event: "tool_call_summary_prepare_strip_failed",
|
|
505
505
|
toolName: tool.name
|
|
@@ -530,7 +530,7 @@ function stripInjectedSummary(pi, toolName, input) {
|
|
|
530
530
|
if (toolDeclaresSummaryParam(pi, toolName)) return;
|
|
531
531
|
for (const field of TOOL_CALL_SUMMARY_FIELDS) delete input[field];
|
|
532
532
|
} catch (err) {
|
|
533
|
-
log$
|
|
533
|
+
log$20.error({
|
|
534
534
|
err,
|
|
535
535
|
event: "tool_call_summary_strip_failed",
|
|
536
536
|
toolName
|
|
@@ -546,7 +546,7 @@ function buildInjectedPayload(pi, payload) {
|
|
|
546
546
|
try {
|
|
547
547
|
return injectToolCallSummary(payload, getStrictToolNames(pi));
|
|
548
548
|
} catch (err) {
|
|
549
|
-
log$
|
|
549
|
+
log$20.error({
|
|
550
550
|
err,
|
|
551
551
|
event: "tool_call_summary_injection_failed"
|
|
552
552
|
}, "tool_call_summary injection failed; passing payload through unchanged");
|
|
@@ -565,7 +565,7 @@ const toolCallSummaryExtension = (pi) => {
|
|
|
565
565
|
pi.registerTool(withSummaryStrippedBeforeValidation(createEditToolDefinition(ctx.cwd)));
|
|
566
566
|
editOverrideRegistered = true;
|
|
567
567
|
} catch (err) {
|
|
568
|
-
log$
|
|
568
|
+
log$20.error({
|
|
569
569
|
err,
|
|
570
570
|
event: "tool_call_summary_edit_override_failed"
|
|
571
571
|
}, "failed to register summary-tolerant edit tool; built-in remains active");
|
|
@@ -596,7 +596,7 @@ const toolCallSummaryExtension = (pi) => {
|
|
|
596
596
|
* or `ToolDefinition[]`. Files starting with `_` or `.` are skipped, so
|
|
597
597
|
* `tools/_example.ts` documents the shape without registering.
|
|
598
598
|
*/
|
|
599
|
-
const log$
|
|
599
|
+
const log$19 = logger.child({ module: "local-tools-extension" });
|
|
600
600
|
const TOOLS_DIRNAME = "tools";
|
|
601
601
|
const fileState = /* @__PURE__ */ new Map();
|
|
602
602
|
let pendingLocalToolsUpdate = null;
|
|
@@ -740,7 +740,7 @@ async function reconcileAndQueue({ pi, dir, reason }) {
|
|
|
740
740
|
dir
|
|
741
741
|
});
|
|
742
742
|
if (reason !== "session_start" && summaryHasChanges$1(summary)) pendingLocalToolsUpdate = summary;
|
|
743
|
-
log$
|
|
743
|
+
log$19.info({
|
|
744
744
|
event: "local_tools_reconcile",
|
|
745
745
|
reason,
|
|
746
746
|
total_tools: summary.totalTools,
|
|
@@ -762,7 +762,7 @@ const localToolsExtension = (pi) => {
|
|
|
762
762
|
reason: "session_start"
|
|
763
763
|
});
|
|
764
764
|
} catch (err) {
|
|
765
|
-
log$
|
|
765
|
+
log$19.error({
|
|
766
766
|
err,
|
|
767
767
|
event: "local_tools_reconcile_failed"
|
|
768
768
|
}, "local tools reconcile failed");
|
|
@@ -774,7 +774,7 @@ const localToolsExtension = (pi) => {
|
|
|
774
774
|
try {
|
|
775
775
|
current = await listToolFiles(dir);
|
|
776
776
|
} catch (err) {
|
|
777
|
-
log$
|
|
777
|
+
log$19.warn({
|
|
778
778
|
err,
|
|
779
779
|
event: "local_tools_listing_failed"
|
|
780
780
|
}, "tools/ listing failed");
|
|
@@ -796,7 +796,7 @@ const localToolsExtension = (pi) => {
|
|
|
796
796
|
reason: "auto_reload"
|
|
797
797
|
});
|
|
798
798
|
} catch (err) {
|
|
799
|
-
log$
|
|
799
|
+
log$19.error({
|
|
800
800
|
err,
|
|
801
801
|
event: "local_tools_auto_reload_failed"
|
|
802
802
|
}, "auto-reload after tools/ change failed");
|
|
@@ -1500,7 +1500,7 @@ function toProviderSafeSchema(inputSchema) {
|
|
|
1500
1500
|
* Clients are keyed by JSON-stringified config and reused across
|
|
1501
1501
|
* reloads — only changed configs reconnect.
|
|
1502
1502
|
*/
|
|
1503
|
-
const log$
|
|
1503
|
+
const log$18 = logger.child({ module: "mcp-extension" });
|
|
1504
1504
|
function resolveToolSelection(server) {
|
|
1505
1505
|
return {
|
|
1506
1506
|
allow: server?.tools?.length ? new Set(server.tools) : null,
|
|
@@ -1698,7 +1698,7 @@ function providerSafeTools({ serverId, tools }) {
|
|
|
1698
1698
|
for (const tool of tools) {
|
|
1699
1699
|
const result = toProviderSafeSchema(tool.inputSchema);
|
|
1700
1700
|
if (!result.ok) {
|
|
1701
|
-
log$
|
|
1701
|
+
log$18.warn({
|
|
1702
1702
|
event: "mcp_tool_schema_unsupported",
|
|
1703
1703
|
server_id: serverId,
|
|
1704
1704
|
tool_name: tool.name,
|
|
@@ -2172,7 +2172,7 @@ var McpExtension = class {
|
|
|
2172
2172
|
});
|
|
2173
2173
|
this.lastConfigMtimeMs = await readConfigMtimeMs(configPath);
|
|
2174
2174
|
if (reason !== "session_start" && summaryHasChanges(summary)) this.pendingMcpUpdate = summary;
|
|
2175
|
-
log$
|
|
2175
|
+
log$18.info({
|
|
2176
2176
|
event: "mcp_reconcile",
|
|
2177
2177
|
reason,
|
|
2178
2178
|
total_tools: summary.totalTools,
|
|
@@ -2199,7 +2199,7 @@ var McpExtension = class {
|
|
|
2199
2199
|
contextWindow: ctx.model?.contextWindow
|
|
2200
2200
|
});
|
|
2201
2201
|
} catch (err) {
|
|
2202
|
-
log$
|
|
2202
|
+
log$18.error({
|
|
2203
2203
|
err,
|
|
2204
2204
|
event: "mcp_reconcile_failed"
|
|
2205
2205
|
}, "MCP reconcile failed");
|
|
@@ -2213,7 +2213,7 @@ var McpExtension = class {
|
|
|
2213
2213
|
for (const legacy of renamed) {
|
|
2214
2214
|
if (this.loggedLegacyToolNames.has(legacy)) continue;
|
|
2215
2215
|
this.loggedLegacyToolNames.add(legacy);
|
|
2216
|
-
log$
|
|
2216
|
+
log$18.info({
|
|
2217
2217
|
event: "mcp_tool_legacy_name",
|
|
2218
2218
|
legacy_name: legacy,
|
|
2219
2219
|
tool_name: this.legacyToolNames.get(legacy)
|
|
@@ -2227,7 +2227,7 @@ var McpExtension = class {
|
|
|
2227
2227
|
try {
|
|
2228
2228
|
mtime = await readConfigMtimeMs(configPath);
|
|
2229
2229
|
} catch (err) {
|
|
2230
|
-
log$
|
|
2230
|
+
log$18.warn({
|
|
2231
2231
|
err,
|
|
2232
2232
|
event: "mcp_mtime_check_failed"
|
|
2233
2233
|
}, "mtime check on mcp.config.json failed");
|
|
@@ -2242,7 +2242,7 @@ var McpExtension = class {
|
|
|
2242
2242
|
contextWindow: ctx.model?.contextWindow
|
|
2243
2243
|
});
|
|
2244
2244
|
} catch (err) {
|
|
2245
|
-
log$
|
|
2245
|
+
log$18.error({
|
|
2246
2246
|
err,
|
|
2247
2247
|
event: "mcp_auto_reload_failed"
|
|
2248
2248
|
}, "auto-reload after mcp.config.json change failed");
|
|
@@ -2608,11 +2608,21 @@ const assistantSchema = z.object({
|
|
|
2608
2608
|
id: z.string(),
|
|
2609
2609
|
model: z.string()
|
|
2610
2610
|
});
|
|
2611
|
+
const sdkToolResultSchema = z.object({ content: z.array(z.object({ type: z.literal("tool_result") })).min(1) });
|
|
2611
2612
|
function assistantMessage(entry) {
|
|
2612
2613
|
if (entry.type !== "assistant") return null;
|
|
2613
2614
|
const parsed = assistantSchema.safeParse(entry.message);
|
|
2614
2615
|
return parsed.success ? parsed.data : null;
|
|
2615
2616
|
}
|
|
2617
|
+
/**
|
|
2618
|
+
* Claude Code answers some tool_use blocks itself mid-stream (e.g. "No such
|
|
2619
|
+
* tool available") and persists that result between the response's blocks.
|
|
2620
|
+
* Pi owns tool execution and replays its own results, so these never belong
|
|
2621
|
+
* in the accepted prefix.
|
|
2622
|
+
*/
|
|
2623
|
+
function isSdkToolResult(entry) {
|
|
2624
|
+
return entry.type === "user" && sdkToolResultSchema.safeParse(entry.message).success;
|
|
2625
|
+
}
|
|
2616
2626
|
function contentHash(message) {
|
|
2617
2627
|
return createHash("sha256").update(JSON.stringify(message.content)).digest("hex");
|
|
2618
2628
|
}
|
|
@@ -2670,7 +2680,7 @@ async function captureSeatTranscript({ configDir, sessionId, boundaryId, lastAss
|
|
|
2670
2680
|
const entry = byId.get(id);
|
|
2671
2681
|
if (!entry) break;
|
|
2672
2682
|
const assistant = assistantMessage(entry);
|
|
2673
|
-
if (!assistant || assistant.model === "<synthetic>" || acceptedIds.has(assistant.id)) entries.push(entry);
|
|
2683
|
+
if (!isSdkToolResult(entry) && (!assistant || assistant.model === "<synthetic>" || acceptedIds.has(assistant.id))) entries.push(entry);
|
|
2674
2684
|
id = entry.parentUuid;
|
|
2675
2685
|
}
|
|
2676
2686
|
if (id === boundaryId && entries.length) return entries.reverse();
|
|
@@ -2948,7 +2958,7 @@ const SEAT_QUERY_TIMEOUTS = {
|
|
|
2948
2958
|
preparation: 3e4
|
|
2949
2959
|
};
|
|
2950
2960
|
const PI_TOOLS_SERVER = "custom-tools";
|
|
2951
|
-
const log$
|
|
2961
|
+
const log$17 = logger.child({ module: "claude-seat-sdk" });
|
|
2952
2962
|
/** Preserve existing MCP names; only ordinary Pi tools need a server prefix. */
|
|
2953
2963
|
function toolBindings(context) {
|
|
2954
2964
|
const parsed = (context.tools ?? []).map((definition) => {
|
|
@@ -3006,7 +3016,7 @@ var SeatQuery = class {
|
|
|
3006
3016
|
this.deadline = setTimeout(() => {
|
|
3007
3017
|
const err = /* @__PURE__ */ new Error(`Claude seat SDK timed out waiting for ${phase}`);
|
|
3008
3018
|
err.name = "TimeoutError";
|
|
3009
|
-
log$
|
|
3019
|
+
log$17.error({
|
|
3010
3020
|
err,
|
|
3011
3021
|
phase
|
|
3012
3022
|
}, "Claude seat SDK wait deadline exceeded");
|
|
@@ -3187,7 +3197,7 @@ var SeatQuery = class {
|
|
|
3187
3197
|
}
|
|
3188
3198
|
} catch (err) {
|
|
3189
3199
|
this.failure = err;
|
|
3190
|
-
if (!this.controller.signal.aborted) log$
|
|
3200
|
+
if (!this.controller.signal.aborted) log$17.error({
|
|
3191
3201
|
err,
|
|
3192
3202
|
sessionId
|
|
3193
3203
|
}, "Claude seat SDK query failed");
|
|
@@ -3202,7 +3212,7 @@ var SeatQuery = class {
|
|
|
3202
3212
|
force: true
|
|
3203
3213
|
});
|
|
3204
3214
|
} catch (err) {
|
|
3205
|
-
log$
|
|
3215
|
+
log$17.error({
|
|
3206
3216
|
err,
|
|
3207
3217
|
sessionId
|
|
3208
3218
|
}, "Could not remove Claude seat SDK config");
|
|
@@ -3235,10 +3245,26 @@ function mapUsage(usage) {
|
|
|
3235
3245
|
//#endregion
|
|
3236
3246
|
//#region src/extensions/claude-seat-response.ts
|
|
3237
3247
|
const toolInput = z.record(z.string(), z.unknown());
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3248
|
+
const log$16 = logger.child({ module: "claude-seat-sdk" });
|
|
3249
|
+
/**
|
|
3250
|
+
* Claude sometimes calls a tool by the name it had outside the bridge (Pi's
|
|
3251
|
+
* own name from non-seat history, or a bare MCP tool name). Resolve those when
|
|
3252
|
+
* unambiguous; anything else passes through unbound so Pi's executor returns
|
|
3253
|
+
* its normal not-found error result and the model can recover.
|
|
3254
|
+
*/
|
|
3255
|
+
function piToolName({ name, context, sessionId }) {
|
|
3256
|
+
const bindings = toolBindings(context);
|
|
3257
|
+
const exact = bindings.find((binding) => binding.sdkName === name) ?? bindings.find((binding) => binding.definition.name === name);
|
|
3258
|
+
if (exact) return exact.definition.name;
|
|
3259
|
+
const bare = bindings.filter((binding) => binding.toolName === name);
|
|
3260
|
+
const [only] = bare;
|
|
3261
|
+
if (only && bare.length === 1) return only.definition.name;
|
|
3262
|
+
log$16.warn({
|
|
3263
|
+
sessionId,
|
|
3264
|
+
toolName: name,
|
|
3265
|
+
candidates: bare.length
|
|
3266
|
+
}, "Claude requested a tool outside the Pi bridge");
|
|
3267
|
+
return name;
|
|
3242
3268
|
}
|
|
3243
3269
|
/** Commit only the accepted SDK attempt: Pi deltas cannot retract retried output. */
|
|
3244
3270
|
var ModelResponse = class {
|
|
@@ -3246,9 +3272,10 @@ var ModelResponse = class {
|
|
|
3246
3272
|
pending = [];
|
|
3247
3273
|
messageId = null;
|
|
3248
3274
|
stopReason = null;
|
|
3249
|
-
constructor(model, context, events) {
|
|
3275
|
+
constructor(model, context, events, sessionId) {
|
|
3250
3276
|
this.context = context;
|
|
3251
3277
|
this.events = events;
|
|
3278
|
+
this.sessionId = sessionId;
|
|
3252
3279
|
this.message = {
|
|
3253
3280
|
role: "assistant",
|
|
3254
3281
|
content: [],
|
|
@@ -3343,7 +3370,11 @@ var ModelResponse = class {
|
|
|
3343
3370
|
block = {
|
|
3344
3371
|
type: "toolCall",
|
|
3345
3372
|
id: sdkBlock.id,
|
|
3346
|
-
name: piToolName(
|
|
3373
|
+
name: piToolName({
|
|
3374
|
+
name: sdkBlock.name,
|
|
3375
|
+
context: this.context,
|
|
3376
|
+
sessionId: this.sessionId
|
|
3377
|
+
}),
|
|
3347
3378
|
arguments: toolInput.parse(sdkBlock.input)
|
|
3348
3379
|
};
|
|
3349
3380
|
break;
|
|
@@ -3437,7 +3468,7 @@ var SeatSdkBridge = class {
|
|
|
3437
3468
|
}
|
|
3438
3469
|
stream(model, context, options = {}) {
|
|
3439
3470
|
const events = createAssistantMessageEventStream();
|
|
3440
|
-
const response = new ModelResponse(model, context, events);
|
|
3471
|
+
const response = new ModelResponse(model, context, events, this.deps.sessionId);
|
|
3441
3472
|
const signal = AbortSignal.any([this.controller.signal, ...options.signal ? [options.signal] : []]);
|
|
3442
3473
|
(async () => {
|
|
3443
3474
|
let seatQuery = null;
|