@linxiraos/pi-agent-core 1.1.14 → 1.1.16
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 +169 -26
- package/THIRD-PARTY-NOTICES.txt +54 -25
- package/dist/types/agent.d.ts +17 -4
- package/dist/types/append-only-context.d.ts +0 -4
- package/dist/types/compaction/anthropic.d.ts +108 -0
- package/dist/types/compaction/compaction-v2-streaming.d.ts +2 -2
- package/dist/types/compaction/compaction.d.ts +33 -18
- package/dist/types/compaction/entries.d.ts +2 -0
- package/dist/types/compaction/index.d.ts +1 -0
- package/dist/types/compaction/openai.d.ts +9 -8
- package/dist/types/index.d.ts +1 -0
- package/dist/types/speculative-execution.d.ts +63 -0
- package/dist/types/thinking.d.ts +1 -1
- package/dist/types/types.d.ts +212 -3
- package/package.json +10 -10
- package/src/agent-loop.ts +582 -86
- package/src/agent.ts +183 -38
- package/src/append-only-context.ts +122 -1
- package/src/compaction/anthropic.ts +310 -0
- package/src/compaction/compaction-v2-streaming.ts +4 -3
- package/src/compaction/compaction.ts +299 -131
- package/src/compaction/entries.ts +2 -0
- package/src/compaction/index.ts +1 -0
- package/src/compaction/openai.ts +17 -10
- package/src/compaction/prompts/anthropic-compaction-instructions.md +17 -0
- package/src/index.ts +2 -0
- package/src/proxy.ts +49 -8
- package/src/speculative-execution.ts +953 -0
- package/src/telemetry.ts +1 -0
- package/src/thinking.ts +1 -1
- package/src/tokenizer.ts +11 -2
- package/src/types.ts +232 -4
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
* summarization endpoints that accept `{ systemPrompt, prompt }` and reply
|
|
15
15
|
* with `{ summary, shortSummary? }`.
|
|
16
16
|
*/
|
|
17
|
-
import type { CodexCompactionContext, FetchImpl, Message, Model, ProviderSessionState } from "@linxiraos/pi-ai/types";
|
|
17
|
+
import type { Api, CodexCompactionContext, FetchImpl, Message, Model, ProviderSessionState } from "@linxiraos/pi-ai/types";
|
|
18
18
|
import { Tokenizer } from "../tokenizer.js";
|
|
19
19
|
export * from "./compaction-v2-streaming.js";
|
|
20
20
|
export declare const OPENAI_REMOTE_COMPACTION_PRESERVE_KEY = "openaiRemoteCompaction";
|
|
21
21
|
/**
|
|
22
|
-
* Hard ceiling on remote compaction HTTP requests. Unlike every
|
|
23
|
-
* stream (guarded by first-event/idle watchdogs in pi-ai), these are
|
|
24
|
-
* fetches awaiting one non-streamed JSON body — a connection silently
|
|
25
|
-
* by a middlebox would otherwise hang the whole compaction pipeline
|
|
26
|
-
* (frozen "Auto context-full maintenance…" spinner, manual /compact
|
|
27
|
-
* behind it). On timeout the caller falls back to local summarization.
|
|
22
|
+
* Hard ceiling on remote compaction HTTP requests (5 minutes). Unlike every
|
|
23
|
+
* provider stream (guarded by first-event/idle watchdogs in pi-ai), these are
|
|
24
|
+
* raw fetches awaiting one non-streamed JSON body — a connection silently
|
|
25
|
+
* dropped by a middlebox would otherwise hang the whole compaction pipeline
|
|
26
|
+
* forever (frozen "Auto context-full maintenance…" spinner, manual /compact
|
|
27
|
+
* queueing behind it). On timeout the caller falls back to local summarization.
|
|
28
28
|
*/
|
|
29
|
-
export declare const REMOTE_COMPACTION_TIMEOUT_MS =
|
|
29
|
+
export declare const REMOTE_COMPACTION_TIMEOUT_MS = 300000;
|
|
30
30
|
export declare const CONTEXT_WINDOW_TRUNCATED_OUTPUT_MESSAGE: string;
|
|
31
31
|
export interface TrimRemoteCompactionInputResult {
|
|
32
32
|
input: Array<Record<string, unknown>>;
|
|
@@ -72,6 +72,7 @@ export interface RemoteCompactionResponse {
|
|
|
72
72
|
summary: string;
|
|
73
73
|
shortSummary?: string;
|
|
74
74
|
}
|
|
75
|
+
export declare function isOpenAiRemoteCompactionApi(api: Api | undefined): boolean;
|
|
75
76
|
export declare function shouldUseOpenAiRemoteCompaction(model: Model): boolean;
|
|
76
77
|
export declare function getPreservedOpenAiRemoteCompactionData(preserveData: Record<string, unknown> | undefined): OpenAiRemoteCompactionPreserveData | undefined;
|
|
77
78
|
export declare function withOpenAiRemoteCompactionPreserveData(preserveData: Record<string, unknown> | undefined, remoteCompaction: OpenAiRemoteCompactionPreserveData | undefined): Record<string, unknown> | undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./pause.js";
|
|
|
6
6
|
export * from "./proxy.js";
|
|
7
7
|
export * from "./replay-policy.js";
|
|
8
8
|
export * from "./run-collector.js";
|
|
9
|
+
export * from "./speculative-execution.js";
|
|
9
10
|
export * from "./telemetry.js";
|
|
10
11
|
export * from "./thinking.js";
|
|
11
12
|
export * from "./tokenizer.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type AssistantMessage } from "@linxiraos/pi-ai";
|
|
2
|
+
import type { AgentContext, AgentLoopConfig, AgentTool, AgentToolCall, AgentToolResult, SpeculativeChildDefinition, SpeculativeChildHandle, SpeculativeToolExecutionConfig, ToolSpeculationEffect, ToolSpeculationStreamSession } from "./types.js";
|
|
3
|
+
export type SpeculativeRawOutcome = {
|
|
4
|
+
result: AgentToolResult<unknown>;
|
|
5
|
+
isError: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type CoerceToolResult = (raw: unknown) => {
|
|
8
|
+
result: AgentToolResult<unknown>;
|
|
9
|
+
malformed: boolean;
|
|
10
|
+
};
|
|
11
|
+
type CoordinatorEnvironment = {
|
|
12
|
+
context: AgentContext;
|
|
13
|
+
loopConfig: AgentLoopConfig;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
};
|
|
16
|
+
/** JSON canonicalization shared by assessment and final reconciliation. */
|
|
17
|
+
export declare function canonicalJson(value: unknown, ancestors?: Set<object>): string;
|
|
18
|
+
export declare function createExecutionFingerprint(toolCall: AgentToolCall, executionArgs: Readonly<Record<string, unknown>>, effect: ToolSpeculationEffect): string;
|
|
19
|
+
/** Rejects malformed or ambiguous effects and returns a frozen logical identity. */
|
|
20
|
+
export declare function normalizeSpeculationEffect(effect: unknown): ToolSpeculationEffect | undefined;
|
|
21
|
+
/** One streamed assistant response's invisible speculative-operation lifecycle. */
|
|
22
|
+
export declare class SpeculativeOperationCoordinator {
|
|
23
|
+
#private;
|
|
24
|
+
readonly config: SpeculativeToolExecutionConfig;
|
|
25
|
+
readonly environment?: CoordinatorEnvironment | undefined;
|
|
26
|
+
constructor(config: SpeculativeToolExecutionConfig, environment?: CoordinatorEnvironment | undefined);
|
|
27
|
+
get maxInFlight(): number;
|
|
28
|
+
get size(): number;
|
|
29
|
+
register(_contentIndex: number): void;
|
|
30
|
+
registerStreamSession(toolCallId: string, session: ToolSpeculationStreamSession): boolean;
|
|
31
|
+
streamSession(toolCallId: string): ToolSpeculationStreamSession | undefined;
|
|
32
|
+
takeStreamSession(toolCallId: string): ToolSpeculationStreamSession | undefined;
|
|
33
|
+
discardStreamSession(toolCallId: string, reason: string): Promise<void>;
|
|
34
|
+
finalizeAdmissions(): Promise<void>;
|
|
35
|
+
attach(message: AssistantMessage): void;
|
|
36
|
+
static take(message: AssistantMessage): SpeculativeOperationCoordinator | undefined;
|
|
37
|
+
static discardForMessage(message: AssistantMessage, reason: string, outcome?: "discarded" | "aborted"): void;
|
|
38
|
+
ineligible(toolCall: AgentToolCall, reason: string, source?: "direct" | "eval_shadow", parentToolCallId?: string): false;
|
|
39
|
+
close(reason: string, outcome?: "discarded" | "aborted"): Promise<void>;
|
|
40
|
+
discardAll(reason: string, outcome?: "discarded" | "aborted"): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Settles queued admissions without releasing host-deferred work. Lets
|
|
43
|
+
* final reconciliation reuse an admission-time transform result instead of
|
|
44
|
+
* running the (possibly stateful) transform a second time. Unlike
|
|
45
|
+
* `finalizeAdmissions` this never starts deferred candidates, so the
|
|
46
|
+
* `beforeToolCall` gate keeps its release semantics.
|
|
47
|
+
*/
|
|
48
|
+
settleAdmissions(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Admission-time transformed args for a direct candidate whose raw call is
|
|
51
|
+
* unchanged. Returns undefined when there is no usable candidate, in which
|
|
52
|
+
* case the caller recomputes at most once via the transform. Gating on the
|
|
53
|
+
* raw call keeps `beforeToolCall` policy intact: any hook revision changes
|
|
54
|
+
* the raw args and forces a fresh transform plus re-reconciliation.
|
|
55
|
+
*/
|
|
56
|
+
directExecutionArgsFor(toolCallId: string, rawArgs: Readonly<Record<string, unknown>>): Record<string, unknown> | undefined;
|
|
57
|
+
reconcileFinalCalls(calls: ReadonlyMap<string, AgentToolCall>): Promise<void>;
|
|
58
|
+
discardChildren(parentToolCallId: string, reason: string): Promise<void>;
|
|
59
|
+
claim(tool: AgentTool | undefined, toolCall: AgentToolCall, args: Record<string, unknown>): Promise<SpeculativeRawOutcome | undefined>;
|
|
60
|
+
admitFinalized(context: AgentContext, toolCall: AgentToolCall, loopConfig: AgentLoopConfig, signal: AbortSignal | undefined): void;
|
|
61
|
+
admit(definition: SpeculativeChildDefinition): Promise<SpeculativeChildHandle | undefined>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
package/dist/types/thinking.d.ts
CHANGED
package/dist/types/types.d.ts
CHANGED
|
@@ -6,8 +6,17 @@ import type { AgentRunCoverage, AgentRunSummary } from "./run-collector.js";
|
|
|
6
6
|
import type { AgentTelemetryConfig } from "./telemetry.js";
|
|
7
7
|
/** Stream function - can return sync or Promise for async config lookup */
|
|
8
8
|
export type StreamFn = (...args: Parameters<typeof streamSimple>) => AssistantMessageEventStream | Promise<AssistantMessageEventStream>;
|
|
9
|
+
/** Staged queue preparation; commit synchronously only while the batch is still owned. */
|
|
10
|
+
export interface QueuedMessagePreparation {
|
|
11
|
+
/** Append context after the originals; undefined stops this attempt, retaining originals unless explicitly removed. */
|
|
12
|
+
commit(): readonly AgentMessage[] | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Prepare an exclusively claimed batch. Undefined delivers unchanged; the signal also aborts when the claim is cancelled. */
|
|
15
|
+
export type PrepareQueuedMessages = (messages: readonly AgentMessage[], signal: AbortSignal) => QueuedMessagePreparation | undefined | Promise<QueuedMessagePreparation | undefined>;
|
|
9
16
|
/** Called once an aside has been inserted into the agent's live context. */
|
|
10
17
|
export declare const ASIDE_MESSAGE_COMMIT: unique symbol;
|
|
18
|
+
/** Symbol-keyed handoff for one finalized, tool-owned stream speculation session. */
|
|
19
|
+
export declare const SPECULATIVE_STREAM_SESSION: unique symbol;
|
|
11
20
|
/** Called when an aside was drained but the agent loop ended before inserting it. */
|
|
12
21
|
export declare const ASIDE_MESSAGE_DISCARD: unique symbol;
|
|
13
22
|
export type CommittableAsideMessage = AgentMessage & {
|
|
@@ -281,13 +290,33 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
281
290
|
* Use for deobfuscating secrets or rewriting arguments.
|
|
282
291
|
*/
|
|
283
292
|
transformToolCallArguments?: (args: Record<string, unknown>, toolName: string) => Record<string, unknown>;
|
|
293
|
+
/**
|
|
294
|
+
* Opt-in speculative execution for finalized, discard-safe tool calls.
|
|
295
|
+
*
|
|
296
|
+
* Candidates remain invisible until ordinary dispatch commits their result.
|
|
297
|
+
*/
|
|
298
|
+
speculativeToolExecution?: SpeculativeToolExecutionConfig;
|
|
284
299
|
/**
|
|
285
300
|
* Resolve a tool call whose name matched no advertised tool (including
|
|
286
301
|
* `customWireName` aliases). Lets hosts route calls to tools they expose
|
|
287
302
|
* through side transports (e.g. `xd://` device mounts) instead of failing
|
|
288
303
|
* with "Tool not found". Returning `undefined` keeps the failure.
|
|
304
|
+
*
|
|
305
|
+
* `advertised` is the very snapshot exact-name dispatch just searched — the
|
|
306
|
+
* set offered to THIS request. A host must resolve against it rather than
|
|
307
|
+
* its own live tool state: an MCP `tools/list_changed` mid-stream reassigns
|
|
308
|
+
* the agent's tools, so live state can hold a roster the model never saw,
|
|
309
|
+
* and a name-recovering host would dispatch a tool this request never
|
|
310
|
+
* advertised while exact dispatch still answered from the snapshot.
|
|
311
|
+
*/
|
|
312
|
+
resolveFallbackTool?: (name: string, advertised: readonly AgentTool<any>[]) => AgentTool<any> | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* Names reachable through {@link resolveFallbackTool} but absent from the
|
|
315
|
+
* advertised set (e.g. `xd://` device mounts). Consulted only to name a
|
|
316
|
+
* plausible target when a call misses, so a mis-transcribed device call is
|
|
317
|
+
* recoverable; never a dispatch source.
|
|
289
318
|
*/
|
|
290
|
-
|
|
319
|
+
suggestFallbackToolNames?: () => Iterable<string>;
|
|
291
320
|
/**
|
|
292
321
|
* Enable intent tracing for tool calls.
|
|
293
322
|
* When enabled, the harness injects a `string` field into tool schemas sent to the model,
|
|
@@ -491,6 +520,178 @@ export interface ToolCallContext {
|
|
|
491
520
|
export type AgentToolCall = Extract<AssistantMessage["content"][number], {
|
|
492
521
|
type: "toolCall";
|
|
493
522
|
}>;
|
|
523
|
+
export interface SpeculativeResourceAccess {
|
|
524
|
+
scheme: "file";
|
|
525
|
+
path: string;
|
|
526
|
+
access: "read";
|
|
527
|
+
}
|
|
528
|
+
/** Declares an operation whose early execution can be discarded without rollback. */
|
|
529
|
+
export type ToolSpeculationEffect = {
|
|
530
|
+
kind: "pure";
|
|
531
|
+
} | {
|
|
532
|
+
kind: "local_read";
|
|
533
|
+
resources: readonly SpeculativeResourceAccess[];
|
|
534
|
+
};
|
|
535
|
+
export type ToolSpeculationAssessment = {
|
|
536
|
+
eligible: false;
|
|
537
|
+
reason: string;
|
|
538
|
+
} | {
|
|
539
|
+
eligible: true;
|
|
540
|
+
effect: ToolSpeculationEffect;
|
|
541
|
+
};
|
|
542
|
+
/** Immutable finalized call data provided to a tool-owned policy. */
|
|
543
|
+
export interface ToolSpeculationAssessmentContext {
|
|
544
|
+
toolCall: AgentToolCall;
|
|
545
|
+
args: Readonly<Record<string, unknown>>;
|
|
546
|
+
}
|
|
547
|
+
export interface ToolSpeculationExecutionContext extends ToolSpeculationAssessmentContext {
|
|
548
|
+
effect: ToolSpeculationEffect;
|
|
549
|
+
}
|
|
550
|
+
export interface ToolSpeculationCommitContext extends ToolSpeculationExecutionContext {
|
|
551
|
+
physicalOutcome: SpeculativePhysicalOutcome;
|
|
552
|
+
}
|
|
553
|
+
export interface ToolSpeculationDiscardContext extends ToolSpeculationExecutionContext {
|
|
554
|
+
reason: string;
|
|
555
|
+
}
|
|
556
|
+
export interface SpeculativePhysicalOutcome {
|
|
557
|
+
kind: "result";
|
|
558
|
+
result: AgentToolResult<unknown>;
|
|
559
|
+
isError: boolean;
|
|
560
|
+
/** Opaque evidence binding the result to the local bytes actually consumed. */
|
|
561
|
+
evidence?: unknown;
|
|
562
|
+
}
|
|
563
|
+
export interface SpeculativeToolReference {
|
|
564
|
+
name: string;
|
|
565
|
+
approval?: ToolApproval;
|
|
566
|
+
formatApprovalDetails?: (args: unknown) => string | string[] | undefined;
|
|
567
|
+
}
|
|
568
|
+
export interface SpeculativeOperationContext extends ToolSpeculationExecutionContext {
|
|
569
|
+
tool: SpeculativeToolReference;
|
|
570
|
+
candidateId: string;
|
|
571
|
+
source: "direct" | "eval_shadow";
|
|
572
|
+
dependencies: readonly string[];
|
|
573
|
+
}
|
|
574
|
+
export interface SpeculativeCommitContext extends SpeculativeOperationContext {
|
|
575
|
+
physicalOutcome: SpeculativePhysicalOutcome;
|
|
576
|
+
}
|
|
577
|
+
export interface SpeculativeDiscardContext extends SpeculativeOperationContext {
|
|
578
|
+
reason: string;
|
|
579
|
+
}
|
|
580
|
+
export type SpeculativeAuthorization = {
|
|
581
|
+
allowed: false;
|
|
582
|
+
reason: string;
|
|
583
|
+
} | {
|
|
584
|
+
allowed: true;
|
|
585
|
+
deferBeforeToolCall?: boolean;
|
|
586
|
+
};
|
|
587
|
+
export type SpeculativeCommitDecision = {
|
|
588
|
+
kind: "committed";
|
|
589
|
+
result: AgentToolResult<unknown>;
|
|
590
|
+
} | {
|
|
591
|
+
kind: "fallback";
|
|
592
|
+
reason: string;
|
|
593
|
+
} | {
|
|
594
|
+
kind: "failed";
|
|
595
|
+
error: unknown;
|
|
596
|
+
};
|
|
597
|
+
export interface SpeculativeExecutionHost {
|
|
598
|
+
authorize(context: SpeculativeOperationContext): SpeculativeAuthorization | Promise<SpeculativeAuthorization>;
|
|
599
|
+
/**
|
|
600
|
+
* Capture content evidence after admission gates pass but before the
|
|
601
|
+
* candidate executes. The coordinator invokes this immediately before
|
|
602
|
+
* starting speculative execution — which for hook-deferred candidates is
|
|
603
|
+
* after `beforeToolCall` runs — so content inspection never precedes a
|
|
604
|
+
* hook that may block the call. Return false (or throw) to veto the
|
|
605
|
+
* candidate without executing it. Hosts without this hook keep the legacy
|
|
606
|
+
* behavior of capturing during `authorize`.
|
|
607
|
+
*/
|
|
608
|
+
captureEvidence?(context: SpeculativeOperationContext): boolean | Promise<boolean>;
|
|
609
|
+
validate?(context: SpeculativeCommitContext): boolean | Promise<boolean>;
|
|
610
|
+
commit?(context: SpeculativeCommitContext, commitDefault: () => Promise<AgentToolResult<unknown>>): Promise<SpeculativeCommitDecision>;
|
|
611
|
+
discard?(context: SpeculativeDiscardContext): void | Promise<void>;
|
|
612
|
+
close?(reason: string): void | Promise<void>;
|
|
613
|
+
}
|
|
614
|
+
export interface ToolSpeculationStreamContext {
|
|
615
|
+
readonly coordinator: SpeculativeOperationSink;
|
|
616
|
+
readonly parentToolCallId: string;
|
|
617
|
+
}
|
|
618
|
+
/** One dependency-aware child operation projected by a streamed outer tool. */
|
|
619
|
+
export interface SpeculativeChildDefinition {
|
|
620
|
+
candidateId: string;
|
|
621
|
+
parentToolCallId: string;
|
|
622
|
+
dependencies: readonly string[];
|
|
623
|
+
toolCall: AgentToolCall;
|
|
624
|
+
tool: AgentTool;
|
|
625
|
+
source: "eval_shadow";
|
|
626
|
+
virtualDurationMs?: number;
|
|
627
|
+
}
|
|
628
|
+
/** Opaque ownership handle returned after agent-core validates and authorizes a child. */
|
|
629
|
+
export interface SpeculativeChildHandle {
|
|
630
|
+
readonly candidateId: string;
|
|
631
|
+
readonly fingerprint: string;
|
|
632
|
+
readonly effect: ToolSpeculationEffect;
|
|
633
|
+
readonly outcome: Promise<SpeculativePhysicalOutcome>;
|
|
634
|
+
commit(actualArgs: Readonly<Record<string, unknown>>): Promise<AgentToolResult<unknown> | undefined>;
|
|
635
|
+
discard(reason: string): Promise<void>;
|
|
636
|
+
}
|
|
637
|
+
export interface ToolSpeculationStreamSession {
|
|
638
|
+
/** True when the tool owns claim routing and does not need an AgentToolContext attachment. */
|
|
639
|
+
readonly contextIndependent?: boolean;
|
|
640
|
+
update(toolCall: AgentToolCall, partialJson?: string): void | Promise<void>;
|
|
641
|
+
finalize(context: ToolSpeculationAssessmentContext): void | Promise<void>;
|
|
642
|
+
commit(): void | Promise<void>;
|
|
643
|
+
discard(reason: string): void | Promise<void>;
|
|
644
|
+
/**
|
|
645
|
+
* Whether the session's streamed plan still authorizes these final
|
|
646
|
+
* arguments. The coordinator discards the session when the finalized call
|
|
647
|
+
* kept its ID but a hook or argument transform replaced its arguments:
|
|
648
|
+
* deferred work planned from the original code must never release.
|
|
649
|
+
* Sessions without this predicate are always retained.
|
|
650
|
+
*/
|
|
651
|
+
matchesFinalArgs?(args: Readonly<Record<string, unknown>>): boolean;
|
|
652
|
+
}
|
|
653
|
+
export interface SpeculativeOperationSink {
|
|
654
|
+
readonly maxInFlight: number;
|
|
655
|
+
admit(definition: SpeculativeChildDefinition): Promise<SpeculativeChildHandle | undefined>;
|
|
656
|
+
discardChildren?(parentToolCallId: string, reason: string): void | Promise<void>;
|
|
657
|
+
close(reason: string): void | Promise<void>;
|
|
658
|
+
}
|
|
659
|
+
export interface ToolSpeculationPolicy {
|
|
660
|
+
finalized?: {
|
|
661
|
+
assess(context: ToolSpeculationAssessmentContext): ToolSpeculationAssessment | Promise<ToolSpeculationAssessment>;
|
|
662
|
+
execute(context: ToolSpeculationExecutionContext, signal: AbortSignal): Promise<SpeculativePhysicalOutcome>;
|
|
663
|
+
commit?(context: ToolSpeculationCommitContext, outcome: SpeculativePhysicalOutcome): Promise<AgentToolResult<unknown>>;
|
|
664
|
+
discard?(context: ToolSpeculationDiscardContext): void | Promise<void>;
|
|
665
|
+
};
|
|
666
|
+
stream?: {
|
|
667
|
+
open(context: ToolSpeculationStreamContext): ToolSpeculationStreamSession | Promise<ToolSpeculationStreamSession | undefined>;
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
/** Diagnostic information for one speculative operation. */
|
|
671
|
+
export interface SpeculativeToolTelemetry {
|
|
672
|
+
source: "direct" | "eval_shadow";
|
|
673
|
+
candidateId: string;
|
|
674
|
+
parentToolCallId?: string;
|
|
675
|
+
toolName: string;
|
|
676
|
+
effectKind?: ToolSpeculationEffect["kind"];
|
|
677
|
+
candidateStartedAt?: number;
|
|
678
|
+
candidateFinishedAt?: number;
|
|
679
|
+
dispatchReachedAt?: number;
|
|
680
|
+
dependencyCount: number;
|
|
681
|
+
queueMs?: number;
|
|
682
|
+
executionDurationMs?: number;
|
|
683
|
+
overlapMs?: number;
|
|
684
|
+
outcome: "committed" | "discarded" | "ineligible" | "fingerprint_mismatch" | "aborted" | "commit_conflict";
|
|
685
|
+
reason?: string;
|
|
686
|
+
resourceCount: number;
|
|
687
|
+
}
|
|
688
|
+
/** Opt-in configuration for discard-safe speculative tool execution. */
|
|
689
|
+
export interface SpeculativeToolExecutionConfig {
|
|
690
|
+
enabled: boolean;
|
|
691
|
+
maxInFlight?: number;
|
|
692
|
+
host?: SpeculativeExecutionHost;
|
|
693
|
+
onTelemetry?: (event: SpeculativeToolTelemetry) => void;
|
|
694
|
+
}
|
|
494
695
|
/**
|
|
495
696
|
* Result returned from `beforeToolCall`.
|
|
496
697
|
*
|
|
@@ -533,7 +734,7 @@ export interface BeforeToolCallContext {
|
|
|
533
734
|
/** The raw tool call block from `assistantMessage.content`. */
|
|
534
735
|
toolCall: AgentToolCall;
|
|
535
736
|
/** The resolved tool the call dispatches to. */
|
|
536
|
-
tool: AgentTool
|
|
737
|
+
tool: AgentTool;
|
|
537
738
|
/**
|
|
538
739
|
* Validated tool arguments. The same reference is forwarded to `tool.execute`
|
|
539
740
|
* (after any `transformToolCallArguments` pass), so in-place mutations stick;
|
|
@@ -653,6 +854,8 @@ export type ToolApproval = ToolApprovalDecision | ((args: unknown) => ToolApprov
|
|
|
653
854
|
* Apps can extend via declaration merging.
|
|
654
855
|
*/
|
|
655
856
|
export interface AgentToolContext {
|
|
857
|
+
/** Present only while the matching outer tool owns its finalized stream session. */
|
|
858
|
+
[SPECULATIVE_STREAM_SESSION]?: ToolSpeculationStreamSession;
|
|
656
859
|
}
|
|
657
860
|
export type AgentToolExecFn<TParameters extends TSchema = TSchema, TDetails = any, TTheme = unknown> = (this: AgentTool<TParameters, TDetails, TTheme>, toolCallId: string, params: Static<TParameters>, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<TDetails, TParameters>, context?: AgentToolContext) => Promise<AgentToolResult<TDetails, TParameters>>;
|
|
658
861
|
/** Live receiver for a tool call's streamed arguments (see AgentTool.openArgStream). */
|
|
@@ -678,8 +881,9 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
678
881
|
* Called at `toolcall_start`, before any argument delta. Return `undefined` to opt out.
|
|
679
882
|
*/
|
|
680
883
|
openArgStream?: (init: AgentToolArgStreamInit) => AgentToolArgStream | undefined;
|
|
681
|
-
/** If true, tool is excluded unless explicitly listed in --tools or agent's tools field */
|
|
682
884
|
hidden?: boolean;
|
|
885
|
+
/** If true, the tool can read `skill://<name>` instruction content; prompt builders gate skill guidance on it. */
|
|
886
|
+
readsSkillUris?: boolean;
|
|
683
887
|
/** If true, tool can stage a pending action that requires explicit resolution via the resolve tool. */
|
|
684
888
|
deferrable?: boolean;
|
|
685
889
|
/** How an enabled tool is presented. See {@link ToolLoadMode}. Omitted is treated as `"essential"` for built-ins; custom-tool adapters normalize omission to `"discoverable"`. */
|
|
@@ -693,6 +897,11 @@ export interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any
|
|
|
693
897
|
* - function: resolved per call from the (raw, pre-validation) arguments
|
|
694
898
|
*/
|
|
695
899
|
concurrency?: "shared" | "exclusive" | ((args: Partial<Static<TParameters>>) => "shared" | "exclusive");
|
|
900
|
+
/**
|
|
901
|
+
* Declares the bounded, validated effect of a finalized call that may execute
|
|
902
|
+
* before ordinary dispatch commits its result.
|
|
903
|
+
*/
|
|
904
|
+
speculation?: ToolSpeculationPolicy;
|
|
696
905
|
/** If true, argument validation errors are non-fatal: raw args are passed to execute() instead of returning an error to the LLM. */
|
|
697
906
|
lenientArgValidation?: boolean;
|
|
698
907
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@linxiraos/pi-agent-core",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.16",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
6
|
"homepage": "https://linxira-os.github.io/zeta/",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -35,19 +35,19 @@
|
|
|
35
35
|
"fmt": "oxfmt --no-error-on-unmatched-pattern 'src/**/*.{ts,tsx}' '{test,bench,examples,scripts}/**/*.ts' '*.ts'"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@linxiraos/pi-
|
|
40
|
-
"@linxiraos/pi-
|
|
41
|
-
"@linxiraos/pi-
|
|
42
|
-
"@linxiraos/pi-
|
|
43
|
-
"@linxiraos/pi-
|
|
44
|
-
"@
|
|
38
|
+
"@opentelemetry/api": "^1.9.1",
|
|
39
|
+
"@linxiraos/pi-ai": "1.1.16",
|
|
40
|
+
"@linxiraos/pi-catalog": "1.1.16",
|
|
41
|
+
"@linxiraos/pi-natives": "1.1.16",
|
|
42
|
+
"@linxiraos/pi-utils": "1.1.16",
|
|
43
|
+
"@linxiraos/pi-wire": "1.1.16",
|
|
44
|
+
"@linxiraos/pi-snapcompact": "1.1.16"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@linxiraos/pi-omptype": "1.1.14",
|
|
48
47
|
"@opentelemetry/context-async-hooks": "^2.9.0",
|
|
49
48
|
"@opentelemetry/sdk-trace-base": "^2.9.0",
|
|
50
|
-
"@types/bun": "^1.3.14"
|
|
49
|
+
"@types/bun": "^1.3.14",
|
|
50
|
+
"@linxiraos/pi-omptype": "1.1.16"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"bun": ">=1.3.14"
|