@theokit/agents 0.22.0 → 0.23.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/{bridge-entry-CHodDWs0.d.ts → bridge-entry-DlW7p2I4.d.ts} +59 -2
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +5 -1
- package/dist/{chunk-ITKVE65Q.js → chunk-ZTVXZIBZ.js} +94 -2
- package/dist/chunk-ZTVXZIBZ.js.map +1 -0
- package/dist/decorators.d.ts +2 -2
- package/dist/index.d.ts +10 -4
- package/dist/index.js +5 -1
- package/dist/{skills-BzEzl0YN.d.ts → skills-CTzgfoff.d.ts} +6 -0
- package/package.json +1 -1
- package/dist/chunk-ITKVE65Q.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExecutionContext } from '@theokit/http';
|
|
2
|
-
import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, t as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig, R as ReasoningEffort } from './skills-
|
|
2
|
+
import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, t as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig, R as ReasoningEffort } from './skills-CTzgfoff.js';
|
|
3
3
|
import { SystemPromptResolver, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, ConversationStorageAdapter, CustomTool, ModelSelection } from '@theokit/sdk';
|
|
4
4
|
import { RetryOptions } from '@theokit/sdk/retry';
|
|
5
5
|
import { z } from 'zod';
|
|
@@ -136,6 +136,8 @@ interface CompiledAgentOptions {
|
|
|
136
136
|
model?: string;
|
|
137
137
|
/** Extended-thinking effort declared via `@Agent({ reasoningEffort })`; mapped to SDK ModelSelection.params. */
|
|
138
138
|
reasoningEffort?: ReasoningEffort;
|
|
139
|
+
/** Opt-in `<think>`-tag extraction declared via `@Agent({ parseThinkTags })` (M2); wraps the stream when true. */
|
|
140
|
+
parseThinkTags?: boolean;
|
|
139
141
|
/** Static prompt OR a per-request {@link SystemPromptResolver} (V4-L.1, Axis-B). */
|
|
140
142
|
systemPrompt?: string | SystemPromptResolver;
|
|
141
143
|
tools: CompiledTool[];
|
|
@@ -420,6 +422,11 @@ interface RuntimeOverrides {
|
|
|
420
422
|
* `ModelSelection.params` so the provider produces reasoning (surfaced as `thinking` StreamEvents).
|
|
421
423
|
*/
|
|
422
424
|
reasoningEffort?: ReasoningEffort;
|
|
425
|
+
/**
|
|
426
|
+
* Per-run opt-in (`?? compiled.parseThinkTags`): when true, wrap the event stream with the M2
|
|
427
|
+
* `<think>`-tag extractor so inline `<think>…</think>` text becomes `thinking` StreamEvents.
|
|
428
|
+
*/
|
|
429
|
+
parseThinkTags?: boolean;
|
|
423
430
|
/** Per-run cwd → `Agent.create({ local: { cwd } })` → `SystemPromptContext.cwd`. */
|
|
424
431
|
cwd?: string;
|
|
425
432
|
/**
|
|
@@ -470,6 +477,56 @@ declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTo
|
|
|
470
477
|
*/
|
|
471
478
|
declare function buildModelSelection(modelId: string, effort?: ReasoningEffort): ModelSelection;
|
|
472
479
|
|
|
480
|
+
/**
|
|
481
|
+
* `<think>`-tag reasoning extractor (M2 reasoning-visibility) — bridge middleware.
|
|
482
|
+
*
|
|
483
|
+
* Converts inline `<think>…</think>` in the assistant TEXT stream into `thinking` segments, so
|
|
484
|
+
* models that emit reasoning as inline tags (qwen3-coder / deepseek-class) surface reasoning the
|
|
485
|
+
* same way native-reasoning providers do (M1's `reasoningEffort`). Two exports:
|
|
486
|
+
* - `createThinkTagExtractor` — the pure incremental splitter (handles a tag straddling a chunk
|
|
487
|
+
* boundary); the testable core.
|
|
488
|
+
* - `extractThinkTagStream` — a StreamEvent transform that applies the extractor to `text_delta`
|
|
489
|
+
* events and passes every other event through unchanged (Phase 2).
|
|
490
|
+
*
|
|
491
|
+
* Opt-in: wired into `createSdkAgentStream` only when `parseThinkTags` is set (Phase 3) — default
|
|
492
|
+
* off, because a code assistant can legitimately emit literal `<think>` in answer/code text.
|
|
493
|
+
*
|
|
494
|
+
* Reference patterns: Aider `reasoning_tags.py`, Vercel AI SDK `extract-reasoning-middleware.ts`
|
|
495
|
+
* (blueprint `code-assistant-reasoning-ux` ADR-3).
|
|
496
|
+
*/
|
|
497
|
+
|
|
498
|
+
/** A typed slice of the text stream: ordinary `text` vs extracted `thinking`. */
|
|
499
|
+
interface Segment {
|
|
500
|
+
kind: 'text' | 'thinking';
|
|
501
|
+
content: string;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* A pure, stateful, incremental `<think>` splitter. Feed it text chunks via `write`; it returns the
|
|
505
|
+
* segments it can resolve so far, holding back only a tail that is still a viable prefix of the
|
|
506
|
+
* active delimiter (so a tag split across two chunks is recognized). Call `end()` once the stream
|
|
507
|
+
* is done to flush any buffered tail (a truncated `<think>` with no close is flushed as `thinking`,
|
|
508
|
+
* so reasoning is never silently dropped).
|
|
509
|
+
*
|
|
510
|
+
* One instance per stream (per round); never shared — there is no cross-instance state.
|
|
511
|
+
*/
|
|
512
|
+
declare function createThinkTagExtractor(): {
|
|
513
|
+
write: (chunk: string) => Segment[];
|
|
514
|
+
end: () => Segment[];
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* Stream transform: convert inline `<think>…</think>` carried in `text_delta` events into `thinking`
|
|
518
|
+
* events, passing every other event (native `thinking`, `tool_call`, `done`, `error`, …) through
|
|
519
|
+
* unchanged. A fresh extractor per call ⇒ per-stream (per-round) state; the extractor's mode persists
|
|
520
|
+
* across interleaved non-text events (a reasoning block split by a tool call is not corrupted). On
|
|
521
|
+
* source end, the extractor is flushed so a truncated `<think>` is still surfaced (as `thinking`).
|
|
522
|
+
*
|
|
523
|
+
* Non-string `text_delta.content` is passed through untouched (defensive — never throws). The
|
|
524
|
+
* `end()` flush runs in a `finally`, so a buffered unclosed `<think>` is surfaced as `thinking`
|
|
525
|
+
* even when the source errors mid-stream (the flushed segments are delivered before the error
|
|
526
|
+
* re-propagates) — never silently dropped (Unbreakable Rule 8: fail loud, lose nothing).
|
|
527
|
+
*/
|
|
528
|
+
declare function extractThinkTagStream(source: AsyncIterable<StreamEvent>): AsyncGenerator<StreamEvent>;
|
|
529
|
+
|
|
473
530
|
/**
|
|
474
531
|
* Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
|
|
475
532
|
*
|
|
@@ -819,4 +876,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
819
876
|
register(app: PluginApp): void;
|
|
820
877
|
};
|
|
821
878
|
|
|
822
|
-
export {
|
|
879
|
+
export { createAgentExecutionContext as $, type AgentExecutionContext as A, BudgetExceededError as B, type CompiledAgentOptions as C, type DelegationResult as D, type ErrorEvent as E, type FileEditEvent as F, type RunStartedEvent as G, type SdkMessage as H, type IterationEvent as I, type Segment as J, type StateUpdateEvent as K, type LoopStrategy as L, type ThinkingEvent as M, type ToolCallEvent as N, type ToolResultEvent as O, type ToolWalkResult as P, type ToolboxWalkResult as Q, type ReflectionStrategy as R, type StreamEvent as S, type TextDeltaEvent as T, agentsPlugin as U, buildModelSelection as V, compileAgent as W, compileContextWindow as X, compileProjectContext as Y, compileSkills as Z, compileTools as _, type CompiledTool as a, createSdkAgentStream as a0, createThinkTagExtractor as a1, delegate as a2, extractThinkTagStream as a3, generateAgentManifest as a4, generateAgentRoutes as a5, isAgentContext as a6, isApprovalRequired as a7, isDone as a8, isError as a9, isTextDelta as aa, isToolCall as ab, isToolResult as ac, ladderReflectionStrategy as ad, loopStrategyConfigSchema as ae, noopReflectionStrategy as af, projectContextMetadataOnlyKnobs as ag, reflectionStrategyConfigSchema as ah, resolveLoopStrategy as ai, streamAgentResponse as aj, translateSdkEvent as ak, validateUniqueRoutes as al, walkAgentMetadata as am, type AgentManifest as b, type AgentManifestEntry as c, type AgentManifestTool as d, type AgentRoute as e, type AgentRouteContext as f, type AgentRunInfo as g, type AgentStreamEvent as h, type AgentWalkResult as i, AgentWarningCode as j, type AgentsPluginOptions as k, type ApprovalRequiredEvent as l, type ArtifactChunkEvent as m, type ArtifactStartEvent as n, type CheckpointSavedEvent as o, type CompiledContextWindow as p, DEFAULT_MAX_ITERATIONS as q, type DelegateOptions as r, DelegationError as s, type DoneEvent as t, type LoopFinishReason as u, type LoopOutcome as v, type LoopStrategyConfig as w, type ReflectionContext as x, type ReflectionResult as y, type ReflectionStrategyConfig as z };
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent,
|
|
1
|
+
export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as Segment, K as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, M as ThinkingEvent, N as ToolCallEvent, O as ToolResultEvent, P as ToolWalkResult, Q as ToolboxWalkResult, U as agentsPlugin, V as buildModelSelection, W as compileAgent, X as compileContextWindow, Y as compileProjectContext, Z as compileSkills, _ as compileTools, $ as createAgentExecutionContext, a0 as createSdkAgentStream, a1 as createThinkTagExtractor, a2 as delegate, a3 as extractThinkTagStream, a4 as generateAgentManifest, a5 as generateAgentRoutes, a6 as isAgentContext, a7 as isApprovalRequired, a8 as isDone, a9 as isError, aa as isTextDelta, ab as isToolCall, ac as isToolResult, ag as projectContextMetadataOnlyKnobs, aj as streamAgentResponse, ak as translateSdkEvent, al as validateUniqueRoutes, am as walkAgentMetadata } from './bridge-entry-DlW7p2I4.js';
|
|
2
2
|
import '@theokit/http';
|
|
3
|
-
import './skills-
|
|
3
|
+
import './skills-CTzgfoff.js';
|
|
4
4
|
import '@theokit/sdk';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '@theokit/sdk/retry';
|
package/dist/bridge.js
CHANGED
|
@@ -11,7 +11,9 @@ import {
|
|
|
11
11
|
compileTools,
|
|
12
12
|
createAgentExecutionContext,
|
|
13
13
|
createSdkAgentStream,
|
|
14
|
+
createThinkTagExtractor,
|
|
14
15
|
delegate,
|
|
16
|
+
extractThinkTagStream,
|
|
15
17
|
generateAgentManifest,
|
|
16
18
|
generateAgentRoutes,
|
|
17
19
|
isAgentContext,
|
|
@@ -26,7 +28,7 @@ import {
|
|
|
26
28
|
translateSdkEvent,
|
|
27
29
|
validateUniqueRoutes,
|
|
28
30
|
walkAgentMetadata
|
|
29
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-ZTVXZIBZ.js";
|
|
30
32
|
import "./chunk-GVPUUKKE.js";
|
|
31
33
|
import "./chunk-7QVYU63E.js";
|
|
32
34
|
export {
|
|
@@ -42,7 +44,9 @@ export {
|
|
|
42
44
|
compileTools,
|
|
43
45
|
createAgentExecutionContext,
|
|
44
46
|
createSdkAgentStream,
|
|
47
|
+
createThinkTagExtractor,
|
|
45
48
|
delegate,
|
|
49
|
+
extractThinkTagStream,
|
|
46
50
|
generateAgentManifest,
|
|
47
51
|
generateAgentRoutes,
|
|
48
52
|
isAgentContext,
|
|
@@ -301,6 +301,7 @@ function compileAgent(walkResult, toolboxInstances = /* @__PURE__ */ new Map())
|
|
|
301
301
|
return {
|
|
302
302
|
model: walkResult.agentConfig.model,
|
|
303
303
|
reasoningEffort: walkResult.agentConfig.reasoningEffort,
|
|
304
|
+
parseThinkTags: walkResult.agentConfig.parseThinkTags,
|
|
304
305
|
systemPrompt: walkResult.agentConfig.systemPrompt,
|
|
305
306
|
tools,
|
|
306
307
|
agents,
|
|
@@ -667,6 +668,91 @@ function buildModelSelection(modelId, effort) {
|
|
|
667
668
|
}
|
|
668
669
|
__name(buildModelSelection, "buildModelSelection");
|
|
669
670
|
|
|
671
|
+
// src/bridge/think-tag-extractor.ts
|
|
672
|
+
var TAG = "think";
|
|
673
|
+
var OPEN = `<${TAG}>`;
|
|
674
|
+
var CLOSE = `</${TAG}>`;
|
|
675
|
+
function heldPrefixLength(s, delim) {
|
|
676
|
+
const max = Math.min(s.length, delim.length - 1);
|
|
677
|
+
for (let k = max; k >= 1; k--) {
|
|
678
|
+
if (s.slice(s.length - k) === delim.slice(0, k)) return k;
|
|
679
|
+
}
|
|
680
|
+
return 0;
|
|
681
|
+
}
|
|
682
|
+
__name(heldPrefixLength, "heldPrefixLength");
|
|
683
|
+
function createThinkTagExtractor() {
|
|
684
|
+
let mode = "text";
|
|
685
|
+
let buffer = "";
|
|
686
|
+
const write = /* @__PURE__ */ __name((chunk) => {
|
|
687
|
+
buffer += chunk;
|
|
688
|
+
const out = [];
|
|
689
|
+
for (; ; ) {
|
|
690
|
+
const delim = mode === "text" ? OPEN : CLOSE;
|
|
691
|
+
const idx = buffer.indexOf(delim);
|
|
692
|
+
if (idx !== -1) {
|
|
693
|
+
const content = buffer.slice(0, idx);
|
|
694
|
+
if (content) out.push({
|
|
695
|
+
kind: mode,
|
|
696
|
+
content
|
|
697
|
+
});
|
|
698
|
+
buffer = buffer.slice(idx + delim.length);
|
|
699
|
+
mode = mode === "text" ? "thinking" : "text";
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const keep = heldPrefixLength(buffer, delim);
|
|
703
|
+
const emit = buffer.slice(0, buffer.length - keep);
|
|
704
|
+
if (emit) out.push({
|
|
705
|
+
kind: mode,
|
|
706
|
+
content: emit
|
|
707
|
+
});
|
|
708
|
+
buffer = buffer.slice(buffer.length - keep);
|
|
709
|
+
break;
|
|
710
|
+
}
|
|
711
|
+
return out;
|
|
712
|
+
}, "write");
|
|
713
|
+
const end = /* @__PURE__ */ __name(() => {
|
|
714
|
+
if (!buffer) return [];
|
|
715
|
+
const seg = {
|
|
716
|
+
kind: mode,
|
|
717
|
+
content: buffer
|
|
718
|
+
};
|
|
719
|
+
buffer = "";
|
|
720
|
+
return [
|
|
721
|
+
seg
|
|
722
|
+
];
|
|
723
|
+
}, "end");
|
|
724
|
+
return {
|
|
725
|
+
write,
|
|
726
|
+
end
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
__name(createThinkTagExtractor, "createThinkTagExtractor");
|
|
730
|
+
function segmentToEvent(seg) {
|
|
731
|
+
return seg.kind === "thinking" ? {
|
|
732
|
+
type: "thinking",
|
|
733
|
+
content: seg.content
|
|
734
|
+
} : {
|
|
735
|
+
type: "text_delta",
|
|
736
|
+
content: seg.content
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
__name(segmentToEvent, "segmentToEvent");
|
|
740
|
+
async function* extractThinkTagStream(source) {
|
|
741
|
+
const extractor = createThinkTagExtractor();
|
|
742
|
+
try {
|
|
743
|
+
for await (const event of source) {
|
|
744
|
+
if (event.type === "text_delta" && typeof event.content === "string") {
|
|
745
|
+
for (const seg of extractor.write(event.content)) yield segmentToEvent(seg);
|
|
746
|
+
} else {
|
|
747
|
+
yield event;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
} finally {
|
|
751
|
+
for (const seg of extractor.end()) yield segmentToEvent(seg);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
__name(extractThinkTagStream, "extractThinkTagStream");
|
|
755
|
+
|
|
670
756
|
// src/bridge/sdk-adapter.ts
|
|
671
757
|
function assembleM8CreateOptions(compiled) {
|
|
672
758
|
const options = {};
|
|
@@ -847,6 +933,7 @@ __name(createDeltaSink, "createDeltaSink");
|
|
|
847
933
|
function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
848
934
|
const model = overrides.model ?? compiled.model ?? "openai/gpt-4o-mini";
|
|
849
935
|
const reasoningEffort = overrides.reasoningEffort ?? compiled.reasoningEffort;
|
|
936
|
+
const parseThinkTags = overrides.parseThinkTags ?? compiled.parseThinkTags ?? false;
|
|
850
937
|
let storage = overrides.conversationStorage;
|
|
851
938
|
return (message, sessionId) => ({
|
|
852
939
|
async *[Symbol.asyncIterator]() {
|
|
@@ -908,7 +995,9 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
908
995
|
onDelta
|
|
909
996
|
});
|
|
910
997
|
const openStream = /* @__PURE__ */ __name(async () => (await sendPromise).stream(), "openStream");
|
|
911
|
-
|
|
998
|
+
const merged = mergeDeltaStream(queue, openStream, runId, state);
|
|
999
|
+
const events = parseThinkTags ? extractThinkTagStream(merged) : merged;
|
|
1000
|
+
for await (const event of events) {
|
|
912
1001
|
yield event;
|
|
913
1002
|
}
|
|
914
1003
|
if (!state.sawError) {
|
|
@@ -1352,6 +1441,7 @@ var AgentRunner = class {
|
|
|
1352
1441
|
const streamFactory = opts.streamFactory ?? createSdkAgentStream(this.compiled, tools, opts.apiKey, {
|
|
1353
1442
|
model: opts.model,
|
|
1354
1443
|
reasoningEffort: opts.reasoningEffort,
|
|
1444
|
+
parseThinkTags: opts.parseThinkTags,
|
|
1355
1445
|
cwd: opts.cwd,
|
|
1356
1446
|
plugins: opts.plugins,
|
|
1357
1447
|
providers: opts.providers,
|
|
@@ -1634,6 +1724,8 @@ export {
|
|
|
1634
1724
|
generateAgentRoutes,
|
|
1635
1725
|
translateSdkEvent,
|
|
1636
1726
|
buildModelSelection,
|
|
1727
|
+
createThinkTagExtractor,
|
|
1728
|
+
extractThinkTagStream,
|
|
1637
1729
|
createSdkAgentStream,
|
|
1638
1730
|
DEFAULT_KEEP_TOKENS,
|
|
1639
1731
|
compactionStrategyConfigSchema,
|
|
@@ -1653,4 +1745,4 @@ export {
|
|
|
1653
1745
|
generateAgentManifest,
|
|
1654
1746
|
agentsPlugin
|
|
1655
1747
|
};
|
|
1656
|
-
//# sourceMappingURL=chunk-
|
|
1748
|
+
//# sourceMappingURL=chunk-ZTVXZIBZ.js.map
|