@theokit/agents 0.22.0 → 0.24.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/LICENSE +201 -0
- package/dist/{bridge-entry-CHodDWs0.d.ts → bridge-entry-CILcYM0y.d.ts} +62 -3
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +5 -1
- package/dist/{chunk-ITKVE65Q.js → chunk-FJXXNWCG.js} +108 -5
- package/dist/chunk-FJXXNWCG.js.map +1 -0
- package/dist/decorators.d.ts +2 -2
- package/dist/index.d.ts +19 -5
- package/dist/index.js +5 -1
- package/dist/{skills-BzEzl0YN.d.ts → skills-CTzgfoff.d.ts} +6 -0
- package/package.json +11 -11
- package/dist/chunk-ITKVE65Q.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 usetheo.dev
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -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
|
/**
|
|
@@ -454,7 +461,9 @@ interface RuntimeOverrides {
|
|
|
454
461
|
* Returns a function that, given a message + sessionId, yields TheoKit
|
|
455
462
|
* AgentStreamEvent via the SDK's Agent.create() + Run.stream() pipeline.
|
|
456
463
|
*/
|
|
457
|
-
declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTools: CompiledTool[], apiKey: string, overrides?: RuntimeOverrides): (message: string, sessionId: string
|
|
464
|
+
declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTools: CompiledTool[], apiKey: string, overrides?: RuntimeOverrides): (message: string, sessionId: string, factoryOpts?: {
|
|
465
|
+
disableTools?: boolean;
|
|
466
|
+
}) => AsyncIterable<StreamEvent>;
|
|
458
467
|
|
|
459
468
|
/**
|
|
460
469
|
* Model-selection mapping (M1 reasoning-visibility) — the single site that turns a
|
|
@@ -470,6 +479,56 @@ declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTo
|
|
|
470
479
|
*/
|
|
471
480
|
declare function buildModelSelection(modelId: string, effort?: ReasoningEffort): ModelSelection;
|
|
472
481
|
|
|
482
|
+
/**
|
|
483
|
+
* `<think>`-tag reasoning extractor (M2 reasoning-visibility) — bridge middleware.
|
|
484
|
+
*
|
|
485
|
+
* Converts inline `<think>…</think>` in the assistant TEXT stream into `thinking` segments, so
|
|
486
|
+
* models that emit reasoning as inline tags (qwen3-coder / deepseek-class) surface reasoning the
|
|
487
|
+
* same way native-reasoning providers do (M1's `reasoningEffort`). Two exports:
|
|
488
|
+
* - `createThinkTagExtractor` — the pure incremental splitter (handles a tag straddling a chunk
|
|
489
|
+
* boundary); the testable core.
|
|
490
|
+
* - `extractThinkTagStream` — a StreamEvent transform that applies the extractor to `text_delta`
|
|
491
|
+
* events and passes every other event through unchanged (Phase 2).
|
|
492
|
+
*
|
|
493
|
+
* Opt-in: wired into `createSdkAgentStream` only when `parseThinkTags` is set (Phase 3) — default
|
|
494
|
+
* off, because a code assistant can legitimately emit literal `<think>` in answer/code text.
|
|
495
|
+
*
|
|
496
|
+
* Reference patterns: Aider `reasoning_tags.py`, Vercel AI SDK `extract-reasoning-middleware.ts`
|
|
497
|
+
* (blueprint `code-assistant-reasoning-ux` ADR-3).
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
/** A typed slice of the text stream: ordinary `text` vs extracted `thinking`. */
|
|
501
|
+
interface Segment {
|
|
502
|
+
kind: 'text' | 'thinking';
|
|
503
|
+
content: string;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* A pure, stateful, incremental `<think>` splitter. Feed it text chunks via `write`; it returns the
|
|
507
|
+
* segments it can resolve so far, holding back only a tail that is still a viable prefix of the
|
|
508
|
+
* active delimiter (so a tag split across two chunks is recognized). Call `end()` once the stream
|
|
509
|
+
* is done to flush any buffered tail (a truncated `<think>` with no close is flushed as `thinking`,
|
|
510
|
+
* so reasoning is never silently dropped).
|
|
511
|
+
*
|
|
512
|
+
* One instance per stream (per round); never shared — there is no cross-instance state.
|
|
513
|
+
*/
|
|
514
|
+
declare function createThinkTagExtractor(): {
|
|
515
|
+
write: (chunk: string) => Segment[];
|
|
516
|
+
end: () => Segment[];
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* Stream transform: convert inline `<think>…</think>` carried in `text_delta` events into `thinking`
|
|
520
|
+
* events, passing every other event (native `thinking`, `tool_call`, `done`, `error`, …) through
|
|
521
|
+
* unchanged. A fresh extractor per call ⇒ per-stream (per-round) state; the extractor's mode persists
|
|
522
|
+
* across interleaved non-text events (a reasoning block split by a tool call is not corrupted). On
|
|
523
|
+
* source end, the extractor is flushed so a truncated `<think>` is still surfaced (as `thinking`).
|
|
524
|
+
*
|
|
525
|
+
* Non-string `text_delta.content` is passed through untouched (defensive — never throws). The
|
|
526
|
+
* `end()` flush runs in a `finally`, so a buffered unclosed `<think>` is surfaced as `thinking`
|
|
527
|
+
* even when the source errors mid-stream (the flushed segments are delivered before the error
|
|
528
|
+
* re-propagates) — never silently dropped (Unbreakable Rule 8: fail loud, lose nothing).
|
|
529
|
+
*/
|
|
530
|
+
declare function extractThinkTagStream(source: AsyncIterable<StreamEvent>): AsyncGenerator<StreamEvent>;
|
|
531
|
+
|
|
473
532
|
/**
|
|
474
533
|
* Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
|
|
475
534
|
*
|
|
@@ -819,4 +878,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
819
878
|
register(app: PluginApp): void;
|
|
820
879
|
};
|
|
821
880
|
|
|
822
|
-
export {
|
|
881
|
+
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-CILcYM0y.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-FJXXNWCG.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,8 +933,9 @@ __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
|
-
return (message, sessionId) => ({
|
|
938
|
+
return (message, sessionId, factoryOpts) => ({
|
|
852
939
|
async *[Symbol.asyncIterator]() {
|
|
853
940
|
const runId = `run-${Date.now()}`;
|
|
854
941
|
const t0 = Date.now();
|
|
@@ -904,11 +991,16 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
904
991
|
});
|
|
905
992
|
const queue = createAsyncQueue();
|
|
906
993
|
const { state, onDelta } = createDeltaSink(queue);
|
|
907
|
-
const sendPromise = agent.send(message, {
|
|
994
|
+
const sendPromise = agent.send(message, factoryOpts?.disableTools === true ? {
|
|
995
|
+
onDelta,
|
|
996
|
+
toolChoice: "none"
|
|
997
|
+
} : {
|
|
908
998
|
onDelta
|
|
909
999
|
});
|
|
910
1000
|
const openStream = /* @__PURE__ */ __name(async () => (await sendPromise).stream(), "openStream");
|
|
911
|
-
|
|
1001
|
+
const merged = mergeDeltaStream(queue, openStream, runId, state);
|
|
1002
|
+
const events = parseThinkTags ? extractThinkTagStream(merged) : merged;
|
|
1003
|
+
for await (const event of events) {
|
|
912
1004
|
yield event;
|
|
913
1005
|
}
|
|
914
1006
|
if (!state.sawError) {
|
|
@@ -1233,6 +1325,13 @@ async function* consumeOneRound(factory, prompt, sessionId, signal, retry) {
|
|
|
1233
1325
|
return r;
|
|
1234
1326
|
}
|
|
1235
1327
|
__name(consumeOneRound, "consumeOneRound");
|
|
1328
|
+
function ceilingRoundFactory(factory, round, maxIterations) {
|
|
1329
|
+
if (round !== maxIterations) return factory;
|
|
1330
|
+
return (m, s) => factory(m, s, {
|
|
1331
|
+
disableTools: true
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
__name(ceilingRoundFactory, "ceilingRoundFactory");
|
|
1236
1335
|
async function* runReflectiveLoopStream(factory, message, sessionId, config) {
|
|
1237
1336
|
const { loop, reflection, budget = Number.POSITIVE_INFINITY, signal, agentName = loop.name, retry } = config;
|
|
1238
1337
|
const acc = {
|
|
@@ -1254,8 +1353,9 @@ async function* runReflectiveLoopStream(factory, message, sessionId, config) {
|
|
|
1254
1353
|
let stuck = 0;
|
|
1255
1354
|
while (!signal?.aborted) {
|
|
1256
1355
|
const prompt = buildPrompt(round, loop.maxIterations, message, feedback);
|
|
1356
|
+
const roundFactory = ceilingRoundFactory(factory, round, loop.maxIterations);
|
|
1257
1357
|
const r = yield* consumeRoundOrThrow({
|
|
1258
|
-
factory,
|
|
1358
|
+
factory: roundFactory,
|
|
1259
1359
|
prompt,
|
|
1260
1360
|
sessionId,
|
|
1261
1361
|
signal,
|
|
@@ -1352,6 +1452,7 @@ var AgentRunner = class {
|
|
|
1352
1452
|
const streamFactory = opts.streamFactory ?? createSdkAgentStream(this.compiled, tools, opts.apiKey, {
|
|
1353
1453
|
model: opts.model,
|
|
1354
1454
|
reasoningEffort: opts.reasoningEffort,
|
|
1455
|
+
parseThinkTags: opts.parseThinkTags,
|
|
1355
1456
|
cwd: opts.cwd,
|
|
1356
1457
|
plugins: opts.plugins,
|
|
1357
1458
|
providers: opts.providers,
|
|
@@ -1634,6 +1735,8 @@ export {
|
|
|
1634
1735
|
generateAgentRoutes,
|
|
1635
1736
|
translateSdkEvent,
|
|
1636
1737
|
buildModelSelection,
|
|
1738
|
+
createThinkTagExtractor,
|
|
1739
|
+
extractThinkTagStream,
|
|
1637
1740
|
createSdkAgentStream,
|
|
1638
1741
|
DEFAULT_KEEP_TOKENS,
|
|
1639
1742
|
compactionStrategyConfigSchema,
|
|
@@ -1653,4 +1756,4 @@ export {
|
|
|
1653
1756
|
generateAgentManifest,
|
|
1654
1757
|
agentsPlugin
|
|
1655
1758
|
};
|
|
1656
|
-
//# sourceMappingURL=chunk-
|
|
1759
|
+
//# sourceMappingURL=chunk-FJXXNWCG.js.map
|