@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.
@@ -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";
@@ -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 sessionId = ctx.sessionManager?.getSessionId();
435
- const searchInput = recentSearchInput(ctx, invocation.turnId);
436
- const turnMetadata = invocation.turnId
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
- ...(sessionId ? { session_id: sessionId, thread_id: sessionId } : {}),
439
- turn_id: invocation.turnId,
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 ?? `pi-search-${Date.now()}`,
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: options.getCurrentTurnId?.(sessionId),
543
+ turnId: identity?.turnId
544
+ ?? options.getCurrentTurnId?.(sessionId),
545
+ identity,
516
546
  });
517
547
  }
518
548
  return {