@oai404iao/pi-codex-minimal-tools 1.3.0 → 1.4.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/README.md +21 -0
- package/package.json +6 -2
- package/src/codex-identity-extension.ts +339 -0
- package/src/codex-wire-identity.ts +532 -118
- package/src/index.ts +2 -0
- package/src/provider-shim.ts +270 -97
- package/src/subagent-inline.ts +8 -0
- package/src/tools/web-search.ts +37 -7
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export {
|
|
2
|
+
CODEX_IDENTITY_CUSTOM_TYPE,
|
|
3
|
+
createCodexSubagentInlineExtension,
|
|
4
|
+
} from "./codex-identity-extension.js";
|
|
5
|
+
export type {
|
|
6
|
+
CodexIdentitySessionView,
|
|
7
|
+
} from "./codex-identity-extension.js";
|
|
8
|
+
export type { CodexThreadIdentity } from "./codex-wire-identity.js";
|
package/src/tools/web-search.ts
CHANGED
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
} from "../codex-http.js";
|
|
9
9
|
import { glyphs, truncateText } from "../glyphs.js";
|
|
10
10
|
import { loadModelSettings } from "../model-catalog/runtime.js";
|
|
11
|
+
import {
|
|
12
|
+
resolveCodexRequestIdentity,
|
|
13
|
+
type CodexRequestIdentity,
|
|
14
|
+
} from "../codex-wire-identity.js";
|
|
11
15
|
|
|
12
16
|
export interface SearchQuery {
|
|
13
17
|
q: string;
|
|
@@ -80,6 +84,7 @@ export interface StandaloneWebSearchDetails {
|
|
|
80
84
|
|
|
81
85
|
export interface StandaloneWebSearchInvocation {
|
|
82
86
|
turnId?: string;
|
|
87
|
+
identity?: CodexRequestIdentity;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
const CODEX_STANDALONE_SEARCH_OUTPUT_TOKEN_LIMIT = 10_000;
|
|
@@ -431,12 +436,29 @@ export async function standaloneWebSearch(
|
|
|
431
436
|
}
|
|
432
437
|
|
|
433
438
|
const url = resolveCodexApiEndpoint(model.baseUrl, settings.apiKeyMode, "alpha/search");
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
|
|
439
|
+
const piSessionId = ctx.sessionManager?.getSessionId();
|
|
440
|
+
const identity = invocation.identity
|
|
441
|
+
?? resolveCodexRequestIdentity(
|
|
442
|
+
piSessionId,
|
|
443
|
+
invocation.turnId ? { turn_id: invocation.turnId } : undefined,
|
|
444
|
+
"turn",
|
|
445
|
+
);
|
|
446
|
+
const turnId = identity?.turnId || invocation.turnId;
|
|
447
|
+
const searchInput = recentSearchInput(ctx, turnId);
|
|
448
|
+
const turnMetadata = identity && turnId
|
|
437
449
|
? JSON.stringify({
|
|
438
|
-
|
|
439
|
-
|
|
450
|
+
session_id: identity.sessionId,
|
|
451
|
+
thread_id: identity.threadId,
|
|
452
|
+
turn_id: turnId,
|
|
453
|
+
...(identity.forkedFromThreadId
|
|
454
|
+
? {
|
|
455
|
+
forked_from_thread_id:
|
|
456
|
+
identity.forkedFromThreadId,
|
|
457
|
+
}
|
|
458
|
+
: {}),
|
|
459
|
+
...(identity.parentThreadId
|
|
460
|
+
? { parent_thread_id: identity.parentThreadId }
|
|
461
|
+
: {}),
|
|
440
462
|
model: model.id,
|
|
441
463
|
})
|
|
442
464
|
: undefined;
|
|
@@ -451,7 +473,9 @@ export async function standaloneWebSearch(
|
|
|
451
473
|
: {}),
|
|
452
474
|
}),
|
|
453
475
|
body: JSON.stringify({
|
|
454
|
-
id: sessionId
|
|
476
|
+
id: identity?.sessionId
|
|
477
|
+
?? piSessionId
|
|
478
|
+
?? `pi-search-${Date.now()}`,
|
|
455
479
|
model: model.id,
|
|
456
480
|
...(searchInput ? { input: searchInput } : {}),
|
|
457
481
|
commands: input,
|
|
@@ -482,6 +506,9 @@ export async function standaloneWebSearch(
|
|
|
482
506
|
|
|
483
507
|
export function createWebSearchToolDefinition(options: {
|
|
484
508
|
getCurrentTurnId?: (sessionId: string | undefined) => string | undefined;
|
|
509
|
+
getRequestIdentity?: (
|
|
510
|
+
sessionId: string | undefined,
|
|
511
|
+
) => CodexRequestIdentity | undefined;
|
|
485
512
|
} = {}) {
|
|
486
513
|
return {
|
|
487
514
|
name: "web_search",
|
|
@@ -511,8 +538,11 @@ export function createWebSearchToolDefinition(options: {
|
|
|
511
538
|
const settings = loadModelSettings(ctx.model, ctx.cwd);
|
|
512
539
|
if (settings.webSearchImplementation === "standalone") {
|
|
513
540
|
const sessionId = ctx.sessionManager?.getSessionId();
|
|
541
|
+
const identity = options.getRequestIdentity?.(sessionId);
|
|
514
542
|
return standaloneWebSearch(input, ctx, signal, {
|
|
515
|
-
turnId:
|
|
543
|
+
turnId: identity?.turnId
|
|
544
|
+
?? options.getCurrentTurnId?.(sessionId),
|
|
545
|
+
identity,
|
|
516
546
|
});
|
|
517
547
|
}
|
|
518
548
|
return {
|