@howaboua/pi-codex-web-run 0.0.9 → 0.0.10
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/CHANGELOG.md +4 -0
- package/README.md +26 -0
- package/index.ts +12 -2
- package/package.json +3 -3
- package/src/service.ts +65 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @howaboua/pi-codex-web-run
|
|
2
2
|
|
|
3
|
+
## 0.0.10
|
|
4
|
+
|
|
5
|
+
- Added an extension API for Web Run search and navigation, using the existing provider and login without adding conversation messages.
|
|
6
|
+
|
|
3
7
|
## 0.0.9
|
|
4
8
|
|
|
5
9
|
- - Keep provider bookkeeping out of structured search results while preserving result references and content.
|
package/README.md
CHANGED
|
@@ -31,3 +31,29 @@ For a proxy that renames Codex providers or models, create `pi-codex-tools.json`
|
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Each provider key identifies a Codex endpoint route. Its object maps the tool's canonical model names to that provider's aliases. Use an empty object when the provider renames no models.
|
|
34
|
+
|
|
35
|
+
## Extension API
|
|
36
|
+
|
|
37
|
+
Other extensions can discover optional search and navigation through Pi's event bus on each call:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
let service: CodexWebRunService | undefined;
|
|
41
|
+
pi.events.emit("@howaboua/pi-codex-web-run.service/v1", {
|
|
42
|
+
use(candidate: CodexWebRunService) {
|
|
43
|
+
service = candidate;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
if (!service)
|
|
47
|
+
throw new Error("Web search is unavailable. Install pi-codex-web-run.");
|
|
48
|
+
const result = await service.run(
|
|
49
|
+
ctx,
|
|
50
|
+
{ search_query: [{ q: "Pi extensions" }] },
|
|
51
|
+
signal,
|
|
52
|
+
);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`CodexWebRunService` is a type export from this package. Discovery is synchronous and works in either extension load order after initialisation. It does not check account access or start a request.
|
|
56
|
+
|
|
57
|
+
`run` accepts the existing `web_run` arguments, including `open`, `click` and `find`. It returns `{ text, details }` with the same source URLs and reusable result references as the tool. It uses the tool's configured provider and existing login without switching accounts. Errors reject the promise. Pass an `AbortSignal` to cancel work. Session shutdown cancels outstanding requests and invalidates retained service handles.
|
|
58
|
+
|
|
59
|
+
Results go only to the caller. The API does not add messages to Pi's conversation or change the model's tools.
|
package/index.ts
CHANGED
|
@@ -2,22 +2,31 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import registerPackageChangelog from "./changelog.js";
|
|
3
3
|
import { webRunCodeModeResult } from "./src/code-mode.js";
|
|
4
4
|
import { resolveHostedCodexToolProvider } from "./src/codex-runtime/policy.js";
|
|
5
|
+
import type { WebSearchToolOptions } from "./src/contract.js";
|
|
6
|
+
import { registerCodexWebRunService } from "./src/service.js";
|
|
5
7
|
import { createWebSearchTool } from "./src/tool.js";
|
|
6
8
|
|
|
7
9
|
const CODE_MODE_PACKAGE = "@howaboua/pi-codex-conversion";
|
|
8
10
|
const CODE_MODE_MODULE = CODE_MODE_PACKAGE + "/code-mode";
|
|
9
11
|
|
|
10
12
|
export { webRunCodeModeResult } from "./src/code-mode.js";
|
|
13
|
+
export type { WebRunExecutionResult } from "./src/execute.js";
|
|
11
14
|
export { executeCodexWebSearch } from "./src/execute.js";
|
|
15
|
+
export {
|
|
16
|
+
CODEX_WEB_RUN_SERVICE,
|
|
17
|
+
type CodexWebRunService,
|
|
18
|
+
type CodexWebRunServiceRequest,
|
|
19
|
+
} from "./src/service.js";
|
|
12
20
|
export { createWebSearchTool } from "./src/tool.js";
|
|
13
21
|
|
|
14
22
|
export default async function webRunExtension(pi: ExtensionAPI): Promise<void> {
|
|
15
23
|
registerPackageChangelog(pi);
|
|
16
|
-
const
|
|
24
|
+
const options: WebSearchToolOptions = {
|
|
17
25
|
allowCodexProviderFallback: true,
|
|
18
26
|
resolveProvider: (ctx) => resolveHostedCodexToolProvider(pi, ctx),
|
|
19
27
|
promptSnippet: false,
|
|
20
|
-
}
|
|
28
|
+
};
|
|
29
|
+
const tool = createWebSearchTool("web_run", options);
|
|
21
30
|
pi.registerTool(tool);
|
|
22
31
|
let gpt = false;
|
|
23
32
|
let registration: Awaited<ReturnType<typeof registerWebRunInCodeMode>>;
|
|
@@ -61,6 +70,7 @@ export default async function webRunExtension(pi: ExtensionAPI): Promise<void> {
|
|
|
61
70
|
throw error;
|
|
62
71
|
}
|
|
63
72
|
registration = await registerWebRunInCodeMode(pi, tool, () => gpt);
|
|
73
|
+
registerCodexWebRunService(pi, options);
|
|
64
74
|
pi.on("session_shutdown", () => registration?.unregister());
|
|
65
75
|
}
|
|
66
76
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-codex-web-run",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Codex web search and navigation for Pi, Code Mode and Notebook Mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@earendil-works/pi-coding-agent": ">=1.0.0",
|
|
51
51
|
"@earendil-works/pi-tui": ">=1.0.0",
|
|
52
52
|
"typebox": "*",
|
|
53
|
-
"@howaboua/pi-codex-conversion": ">=4.0.
|
|
53
|
+
"@howaboua/pi-codex-conversion": ">=4.0.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@biomejs/biome": "^2.6.3",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tsx": "^4.23.15",
|
|
61
61
|
"typebox": "1.4.3",
|
|
62
62
|
"typescript": "^7.0.2",
|
|
63
|
-
"@howaboua/pi-codex-conversion": "4.0.
|
|
63
|
+
"@howaboua/pi-codex-conversion": "4.0.6"
|
|
64
64
|
},
|
|
65
65
|
"pi": {
|
|
66
66
|
"extensions": [
|
package/src/service.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { WebSearchToolOptions } from "./contract.js";
|
|
6
|
+
import {
|
|
7
|
+
executeCodexWebSearch,
|
|
8
|
+
type WebRunExecutionResult,
|
|
9
|
+
} from "./execute.js";
|
|
10
|
+
|
|
11
|
+
export const CODEX_WEB_RUN_SERVICE = "@howaboua/pi-codex-web-run.service/v1";
|
|
12
|
+
|
|
13
|
+
/** Discover synchronously per use; discovery does not check auth or run a search. */
|
|
14
|
+
export interface CodexWebRunServiceRequest {
|
|
15
|
+
use(service: CodexWebRunService): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CodexWebRunService {
|
|
19
|
+
readonly protocol: 1;
|
|
20
|
+
/** Explicit web_run arguments; results are returned only to the caller. */
|
|
21
|
+
run(
|
|
22
|
+
ctx: ExtensionContext,
|
|
23
|
+
params: Record<string, unknown>,
|
|
24
|
+
signal?: AbortSignal,
|
|
25
|
+
): Promise<WebRunExecutionResult>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerCodexWebRunService(
|
|
29
|
+
pi: ExtensionAPI,
|
|
30
|
+
options: WebSearchToolOptions,
|
|
31
|
+
): void {
|
|
32
|
+
const lifetime = new AbortController();
|
|
33
|
+
const service: CodexWebRunService = {
|
|
34
|
+
protocol: 1,
|
|
35
|
+
async run(ctx, params, signal) {
|
|
36
|
+
const operation = signal
|
|
37
|
+
? AbortSignal.any([lifetime.signal, signal])
|
|
38
|
+
: lifetime.signal;
|
|
39
|
+
operation.throwIfAborted();
|
|
40
|
+
const result = await executeCodexWebSearch(
|
|
41
|
+
params,
|
|
42
|
+
ctx,
|
|
43
|
+
operation,
|
|
44
|
+
options,
|
|
45
|
+
);
|
|
46
|
+
operation.throwIfAborted();
|
|
47
|
+
return result;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const off = pi.events.on(CODEX_WEB_RUN_SERVICE, (request) => {
|
|
51
|
+
if (
|
|
52
|
+
request &&
|
|
53
|
+
typeof request === "object" &&
|
|
54
|
+
"use" in request &&
|
|
55
|
+
typeof request.use === "function"
|
|
56
|
+
)
|
|
57
|
+
request.use(service);
|
|
58
|
+
});
|
|
59
|
+
pi.on("session_shutdown", () => {
|
|
60
|
+
off();
|
|
61
|
+
lifetime.abort(
|
|
62
|
+
new Error("Web search session ended. Retry in the current session."),
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
}
|