@geohar/pi-mcp-combiner 0.16.0-dev.4 → 0.17.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/client/proxy-tool.d.ts +2 -0
- package/dist/client/proxy-tool.d.ts.map +1 -1
- package/dist/client/proxy-tool.js +24 -8
- package/dist/client/proxy-tool.js.map +1 -1
- package/dist/client/render.d.ts +45 -5
- package/dist/client/render.d.ts.map +1 -1
- package/dist/client/render.js +95 -13
- package/dist/client/render.js.map +1 -1
- package/dist/client/runner-stale.d.ts +26 -0
- package/dist/client/runner-stale.d.ts.map +1 -0
- package/dist/client/runner-stale.js +57 -0
- package/dist/client/runner-stale.js.map +1 -0
- package/dist/client/settings.d.ts +5 -0
- package/dist/client/settings.d.ts.map +1 -1
- package/dist/client/settings.js +12 -0
- package/dist/client/settings.js.map +1 -1
- package/dist/client/widget-support.d.ts +1 -5
- package/dist/client/widget-support.d.ts.map +1 -1
- package/dist/client/widget-support.js +7 -50
- package/dist/client/widget-support.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/native/combiner-connection.js +1 -1
- package/dist/native/combiner-connection.js.map +1 -1
- package/dist/native/index.d.ts +3 -0
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js +2 -0
- package/dist/native/index.js.map +1 -1
- package/dist/native/resources.d.ts +2 -0
- package/dist/native/resources.d.ts.map +1 -1
- package/dist/native/resources.js +11 -2
- package/dist/native/resources.js.map +1 -1
- package/dist/native/tool-surface.d.ts +4 -0
- package/dist/native/tool-surface.d.ts.map +1 -1
- package/dist/native/tool-surface.js +25 -4
- package/dist/native/tool-surface.js.map +1 -1
- package/dist/pi.d.ts +6 -0
- package/dist/pi.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/proxy-tool.ts +36 -9
- package/src/client/render.ts +130 -13
- package/src/client/runner-stale.ts +66 -0
- package/src/client/settings.ts +17 -0
- package/src/client/widget-support.ts +7 -42
- package/src/index.ts +2 -0
- package/src/native/combiner-connection.ts +1 -1
- package/src/native/index.ts +5 -0
- package/src/native/resources.ts +13 -2
- package/src/native/tool-surface.ts +34 -4
- package/src/pi.ts +4 -0
|
@@ -33,6 +33,8 @@ import type { NativeCombinerConnection, ToolSummary } from "./combiner-connectio
|
|
|
33
33
|
import { applyServerFilter, matchesGlob, RESERVED_TOOL_NAMES } from "../client/tool-matching.js"
|
|
34
34
|
import { renderSchemaSignature } from "../client/schema-signature.js"
|
|
35
35
|
import { toLlmContent, type CallToolResult } from "@earendil-works/pi-mcp"
|
|
36
|
+
import { renderToolResultBlocks } from "../client/render.js"
|
|
37
|
+
import { isRunnerStaleError, runnerStaleHint, safeModel } from "../client/runner-stale.js"
|
|
36
38
|
import type { ServerFilter } from "../client/config-ladder.js"
|
|
37
39
|
|
|
38
40
|
export type NativeToolSurfaceOptions = {
|
|
@@ -51,6 +53,10 @@ export type NativeToolSurfaceOptions = {
|
|
|
51
53
|
* first call; the SAME object on every pass so the diffing + hidden-removal
|
|
52
54
|
* work. native/index.ts owns one per activation. */
|
|
53
55
|
state?: NativeToolSurfaceState
|
|
56
|
+
/** Cap on guarded tool-result text before spill-to-file (maxResultChars setting).
|
|
57
|
+
* Captured per Registration pass — changing it takes effect on the next
|
|
58
|
+
* re-registration (/reload, per the settings file's read-only-at-load rule). */
|
|
59
|
+
maxResultChars?: number
|
|
54
60
|
/** Warn when the direct-exposure set grows large (every declared schema rides in
|
|
55
61
|
* every request). Settings kill-switch: warnLargeDirectExposure (default true). */
|
|
56
62
|
warnLargeDirectExposure?: boolean
|
|
@@ -93,7 +99,12 @@ const DIRECT_EXPOSURE_WARN_THRESHOLD = 50
|
|
|
93
99
|
|
|
94
100
|
/** Turn one combiner ToolSummary into pi's ToolDefinition, plus the native-only fields
|
|
95
101
|
* pi 1.0 accepts on registerTool (exposure/namespace/annotations). */
|
|
96
|
-
function toNativeTool(
|
|
102
|
+
function toNativeTool(
|
|
103
|
+
sum: ToolSummary,
|
|
104
|
+
conn: NativeCombinerConnection,
|
|
105
|
+
exposure: ToolDefinition["exposure"],
|
|
106
|
+
maxResultChars?: number,
|
|
107
|
+
): ToolDefinition {
|
|
97
108
|
const name = sum.name
|
|
98
109
|
return {
|
|
99
110
|
name,
|
|
@@ -107,16 +118,35 @@ function toNativeTool(sum: ToolSummary, conn: NativeCombinerConnection, exposure
|
|
|
107
118
|
exposure,
|
|
108
119
|
namespace: COMBINER_NAMESPACE,
|
|
109
120
|
annotations: sum.annotations,
|
|
110
|
-
execute: async (_toolCallId, params, signal) => {
|
|
121
|
+
execute: async (_toolCallId, params, signal, _onUpdate, ctx) => {
|
|
122
|
+
// SAFETY: guarded ctx read ONCE at entry (runner-stale rule) — the model
|
|
123
|
+
// feeds the non-vision omission note (render parity with pi's read tool).
|
|
124
|
+
const model = safeModel(ctx)
|
|
111
125
|
// The abort signal rides into the transport (callTool's options.signal):
|
|
112
126
|
// cancellation cancels upstream work, and widget holds respect it
|
|
113
127
|
// (notifications/cancelled).
|
|
114
128
|
try {
|
|
115
129
|
const result = await conn.callTool(name, params, { signal })
|
|
116
|
-
|
|
130
|
+
// Guard: text blocks join + spill over the char cap (notice names the
|
|
131
|
+
// 0600 temp file with the FULL text; never a mid-JSON dead end);
|
|
132
|
+
// images stay real blocks (toLlmContent already made them lossless).
|
|
133
|
+
const guarded = await renderToolResultBlocks(toToolResult(result),
|
|
134
|
+
{ maxResultChars, model }, name)
|
|
135
|
+
// SAFETY: CallToolResult is a JSON-RPC result object (plain key/value) —
|
|
136
|
+
// TS lacks the index signature, but spreading it into a Record<string,
|
|
137
|
+
// unknown> is exactly what renderers expect (details carry the full
|
|
138
|
+
// result; full_output_path is added below when text spilled).
|
|
139
|
+
const details: Record<string, unknown> = { ...(result as unknown as Record<string, unknown>) }
|
|
140
|
+
if (guarded.spillPath) details.full_output_path = guarded.spillPath
|
|
141
|
+
return { content: guarded.content, details }
|
|
117
142
|
} catch (e) {
|
|
118
143
|
// pi's error convention: THROWING marks the call an error (no isError
|
|
119
144
|
// property on successful results).
|
|
145
|
+
if (isRunnerStaleError(e)) {
|
|
146
|
+
// pi#10599: a completed call must not surface pi's raw stale-text
|
|
147
|
+
// — name what happened, when retrying is safe.
|
|
148
|
+
throw new Error(isRunnerStaleError(e) ? runnerStaleHint(name) : undefined as never)
|
|
149
|
+
}
|
|
120
150
|
throw e instanceof Error ? e : new Error(String(e))
|
|
121
151
|
}
|
|
122
152
|
},
|
|
@@ -170,7 +200,7 @@ export async function activateNativeTools(pi: ExtensionAPI, opts: NativeToolSurf
|
|
|
170
200
|
if (state.names.has(sum.name) && state.signatures.get(sum.name) === sig) {
|
|
171
201
|
continue
|
|
172
202
|
}
|
|
173
|
-
pi.registerTool(toNativeTool(sum, opts.connection, exposure))
|
|
203
|
+
pi.registerTool(toNativeTool(sum, opts.connection, exposure, opts.maxResultChars))
|
|
174
204
|
state.signatures.set(sum.name, sig)
|
|
175
205
|
state.names.add(sum.name)
|
|
176
206
|
fresh++
|
package/src/pi.ts
CHANGED
|
@@ -64,6 +64,10 @@ export type ToolParameters = Record<string, unknown>
|
|
|
64
64
|
|
|
65
65
|
export type ToolCallContext = ExtensionContext & {
|
|
66
66
|
onUpdate?: (update: { level: "info" | "warn" | "error"; message: string }) => void
|
|
67
|
+
/** The active model (pi passes it on tool calls); the tool-result guard reads
|
|
68
|
+
* `input` for image-visibility parity with the read tool. Runtime has more
|
|
69
|
+
* members (inputLimits etc.) — declared only to the slice we use. */
|
|
70
|
+
model?: { input?: string[] }
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
export type TextBlock = { type: "text"; text: string }
|