@deepstrike/sdk 0.1.14 → 0.1.15
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/index.d.ts +1 -1
- package/dist/providers/anthropic.d.ts +3 -2
- package/dist/providers/anthropic.js +15 -9
- package/dist/providers/openai-chat.d.ts +1 -1
- package/dist/providers/openai-chat.js +5 -7
- package/dist/providers/openai.d.ts +3 -1
- package/dist/providers/openai.js +11 -0
- package/dist/runtime/provider-replay.d.ts +7 -0
- package/dist/runtime/provider-replay.js +18 -0
- package/dist/runtime/runner.js +4 -0
- package/dist/runtime/session-log.d.ts +2 -1
- package/dist/types.d.ts +11 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export { Governance } from "./governance.js";
|
|
|
43
43
|
export type { GovernanceVerdict } from "./governance.js";
|
|
44
44
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
45
45
|
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
46
|
-
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, RenderedContext, } from "./types.js";
|
|
46
|
+
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, ProviderReplay, RenderedContext, } from "./types.js";
|
|
47
47
|
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
48
48
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
49
49
|
export { AgentPool } from "./collaboration/pool.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
1
|
+
import type { Message, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
2
|
interface AnthropicProviderOptions {
|
|
3
3
|
baseURL?: string;
|
|
4
4
|
authMode?: "api-key" | "bearer";
|
|
@@ -15,6 +15,8 @@ export declare class AnthropicProvider implements LLMProvider {
|
|
|
15
15
|
baseDelay: number;
|
|
16
16
|
}, options?: AnthropicProviderOptions);
|
|
17
17
|
runtimePolicy(): RuntimePolicy;
|
|
18
|
+
peekProviderReplay(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
|
|
19
|
+
seedProviderReplay(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
|
|
18
20
|
private buildTools;
|
|
19
21
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
20
22
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
@@ -24,6 +26,5 @@ export declare class AnthropicProvider implements LLMProvider {
|
|
|
24
26
|
private streamMessage;
|
|
25
27
|
private buildMessages;
|
|
26
28
|
private rememberNativeBlocks;
|
|
27
|
-
private assistantReplayKey;
|
|
28
29
|
}
|
|
29
30
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
import { assistantReplayKey } from "../runtime/provider-replay.js";
|
|
2
3
|
import { withServerRuntimeGuard } from "../runtime/server.js";
|
|
3
4
|
import { CircuitBreaker, normalizeToolCall, omitExtensionKeys, toAnthropicMessages } from "./base.js";
|
|
4
5
|
const CLAUDE_POLICIES = {
|
|
@@ -28,6 +29,15 @@ export class AnthropicProvider {
|
|
|
28
29
|
runtimePolicy() {
|
|
29
30
|
return CLAUDE_POLICIES[this.model] ?? {};
|
|
30
31
|
}
|
|
32
|
+
peekProviderReplay(message) {
|
|
33
|
+
const blocks = this.nativeAssistantBlocks.get(assistantReplayKey(message));
|
|
34
|
+
return blocks?.length ? { native_blocks: blocks } : undefined;
|
|
35
|
+
}
|
|
36
|
+
seedProviderReplay(message, replay) {
|
|
37
|
+
if (replay.native_blocks?.length) {
|
|
38
|
+
this.nativeAssistantBlocks.set(assistantReplayKey(message), replay.native_blocks);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
31
41
|
buildTools(tools) {
|
|
32
42
|
return tools.map(t => ({
|
|
33
43
|
name: t.name,
|
|
@@ -161,17 +171,13 @@ export class AnthropicProvider {
|
|
|
161
171
|
: this.client.messages.stream(params));
|
|
162
172
|
}
|
|
163
173
|
buildMessages(context) {
|
|
164
|
-
return toAnthropicMessages(context.turns, message => this.nativeAssistantBlocks.get(
|
|
174
|
+
return toAnthropicMessages(context.turns, message => this.nativeAssistantBlocks.get(assistantReplayKey(message)));
|
|
165
175
|
}
|
|
166
176
|
rememberNativeBlocks(message, blocks) {
|
|
167
|
-
if (!
|
|
177
|
+
if (!blocks.length)
|
|
168
178
|
return;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return JSON.stringify({
|
|
173
|
-
content: message.content,
|
|
174
|
-
toolCalls: message.toolCalls ?? [],
|
|
175
|
-
});
|
|
179
|
+
if (!message.toolCalls?.length && !blocks.some(b => b.type === "thinking"))
|
|
180
|
+
return;
|
|
181
|
+
this.nativeAssistantBlocks.set(assistantReplayKey(message), blocks);
|
|
176
182
|
}
|
|
177
183
|
}
|
|
@@ -23,5 +23,5 @@ export declare class OpenAIChatAdapter {
|
|
|
23
23
|
arguments: string;
|
|
24
24
|
}>;
|
|
25
25
|
rememberReplayFields(message: Pick<Message, "content" | "toolCalls">, fields: Record<string, unknown>): void;
|
|
26
|
-
|
|
26
|
+
peekReplayFields(message: Pick<Message, "content" | "toolCalls">): Record<string, unknown> | undefined;
|
|
27
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assistantReplayKey } from "../runtime/provider-replay.js";
|
|
1
2
|
import { normalizeToolCall, toOpenAIMessageParams } from "./base.js";
|
|
2
3
|
export class OpenAIChatAdapter {
|
|
3
4
|
replayFields = new Map();
|
|
@@ -18,7 +19,7 @@ export class OpenAIChatAdapter {
|
|
|
18
19
|
continue;
|
|
19
20
|
}
|
|
20
21
|
if (source.role === "assistant") {
|
|
21
|
-
const replay = this.replayFields.get(
|
|
22
|
+
const replay = this.replayFields.get(assistantReplayKey(source));
|
|
22
23
|
if (replay)
|
|
23
24
|
serialized[cursor] = { ...serialized[cursor], ...replay };
|
|
24
25
|
}
|
|
@@ -32,12 +33,9 @@ export class OpenAIChatAdapter {
|
|
|
32
33
|
.filter(Boolean);
|
|
33
34
|
}
|
|
34
35
|
rememberReplayFields(message, fields) {
|
|
35
|
-
this.replayFields.set(
|
|
36
|
+
this.replayFields.set(assistantReplayKey(message), fields);
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
content: message.content,
|
|
40
|
-
toolCalls: message.toolCalls ?? [],
|
|
41
|
-
});
|
|
38
|
+
peekReplayFields(message) {
|
|
39
|
+
return this.replayFields.get(assistantReplayKey(message));
|
|
42
40
|
}
|
|
43
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import type { Message, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
2
|
+
import type { Message, ProviderReplay, RenderedContext, ToolSchema, StreamEvent, LLMProvider, RuntimePolicy } from "../types.js";
|
|
3
3
|
import { CircuitBreaker } from "./base.js";
|
|
4
4
|
import { OpenAIChatAdapter } from "./openai-chat.js";
|
|
5
5
|
export declare class OpenAIChatProvider implements LLMProvider {
|
|
@@ -14,6 +14,8 @@ export declare class OpenAIChatProvider implements LLMProvider {
|
|
|
14
14
|
baseDelay: number;
|
|
15
15
|
}, baseURL?: string);
|
|
16
16
|
runtimePolicy(): RuntimePolicy;
|
|
17
|
+
peekProviderReplay(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
|
|
18
|
+
seedProviderReplay(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
|
|
17
19
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
18
20
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
19
21
|
protected requestExtensions(extensions?: Record<string, unknown>): Record<string, unknown>;
|
package/dist/providers/openai.js
CHANGED
|
@@ -33,6 +33,17 @@ export class OpenAIChatProvider {
|
|
|
33
33
|
runtimePolicy() {
|
|
34
34
|
return OPENAI_POLICIES[this.model] ?? {};
|
|
35
35
|
}
|
|
36
|
+
peekProviderReplay(message) {
|
|
37
|
+
const fields = this.chat.peekReplayFields(message);
|
|
38
|
+
if (!fields?.reasoning_content)
|
|
39
|
+
return undefined;
|
|
40
|
+
return { reasoning_content: String(fields.reasoning_content) };
|
|
41
|
+
}
|
|
42
|
+
seedProviderReplay(message, replay) {
|
|
43
|
+
if (replay.reasoning_content) {
|
|
44
|
+
this.chat.rememberReplayFields(message, { reasoning_content: replay.reasoning_content });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
36
47
|
async complete(context, tools, extensions) {
|
|
37
48
|
if (this.circuit.isOpen())
|
|
38
49
|
throw new Error("Circuit breaker open");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LLMProvider, Message, ProviderReplay, ToolCall } from "../types.js";
|
|
2
|
+
import type { SessionEvent } from "./session-log.js";
|
|
3
|
+
export declare function assistantReplayKey(message: Pick<Message, "content" | "toolCalls">): string;
|
|
4
|
+
export declare function seedProviderReplayFromEvents(provider: LLMProvider, events: Array<{
|
|
5
|
+
event: SessionEvent;
|
|
6
|
+
}>): void;
|
|
7
|
+
export declare function peekProviderReplay(provider: LLMProvider, content: string, toolCalls: ToolCall[]): ProviderReplay | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function assistantReplayKey(message) {
|
|
2
|
+
return JSON.stringify({
|
|
3
|
+
content: message.content,
|
|
4
|
+
toolCalls: message.toolCalls ?? [],
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
export function seedProviderReplayFromEvents(provider, events) {
|
|
8
|
+
if (!provider.seedProviderReplay)
|
|
9
|
+
return;
|
|
10
|
+
for (const { event } of events) {
|
|
11
|
+
if (event.kind !== "llm_completed" || !event.provider_replay)
|
|
12
|
+
continue;
|
|
13
|
+
provider.seedProviderReplay({ content: event.content, toolCalls: event.tool_calls ?? [] }, event.provider_replay);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function peekProviderReplay(provider, content, toolCalls) {
|
|
17
|
+
return provider.peekProviderReplay?.({ content, toolCalls });
|
|
18
|
+
}
|
package/dist/runtime/runner.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getKernel } from "../kernel.js";
|
|
2
|
+
import { peekProviderReplay, seedProviderReplayFromEvents } from "./provider-replay.js";
|
|
2
3
|
export class RuntimeRunner {
|
|
3
4
|
opts;
|
|
4
5
|
interrupted = false;
|
|
@@ -128,6 +129,7 @@ export class RuntimeRunner {
|
|
|
128
129
|
if (this.opts.knowledgeSource)
|
|
129
130
|
sm.setKnowledgeEnabled(true);
|
|
130
131
|
if (priorEvents && priorEvents.length > 0) {
|
|
132
|
+
seedProviderReplayFromEvents(this.opts.provider, priorEvents);
|
|
131
133
|
sm.preloadHistory(replayMessages(priorEvents));
|
|
132
134
|
}
|
|
133
135
|
const sessionStart = Date.now();
|
|
@@ -202,12 +204,14 @@ export class RuntimeRunner {
|
|
|
202
204
|
toolCalls: finalToolCalls,
|
|
203
205
|
tokenCount: turnTokens || undefined,
|
|
204
206
|
});
|
|
207
|
+
const providerReplay = peekProviderReplay(this.opts.provider, finalText, finalToolCalls);
|
|
205
208
|
await this.opts.sessionLog.append(sessionId, {
|
|
206
209
|
kind: "llm_completed",
|
|
207
210
|
turn: sm.turn,
|
|
208
211
|
content: finalText,
|
|
209
212
|
token_count: turnTokens || undefined,
|
|
210
213
|
tool_calls: finalToolCalls,
|
|
214
|
+
...(providerReplay ? { provider_replay: providerReplay } : {}),
|
|
211
215
|
});
|
|
212
216
|
}
|
|
213
217
|
else if (action.kind === "execute_tools") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolCall } from "../types.js";
|
|
1
|
+
import type { ProviderReplay, ToolCall } from "../types.js";
|
|
2
2
|
export type SessionEvent = {
|
|
3
3
|
kind: "run_started";
|
|
4
4
|
run_id: string;
|
|
@@ -12,6 +12,7 @@ export type SessionEvent = {
|
|
|
12
12
|
content: string;
|
|
13
13
|
token_count?: number;
|
|
14
14
|
tool_calls: ToolCall[];
|
|
15
|
+
provider_replay?: ProviderReplay;
|
|
15
16
|
} | {
|
|
16
17
|
kind: "tool_requested";
|
|
17
18
|
turn: number;
|
package/dist/types.d.ts
CHANGED
|
@@ -152,6 +152,13 @@ export interface RetryConfig {
|
|
|
152
152
|
* Responses `previous_response_id` without leaking those semantics into the kernel.
|
|
153
153
|
*/
|
|
154
154
|
export type ProviderRunState = Record<string, unknown>;
|
|
155
|
+
/** Provider-native fields required to replay a turn across requests (thinking blocks, reasoning_content, etc.). */
|
|
156
|
+
export interface ProviderReplay {
|
|
157
|
+
/** Anthropic-style assistant content blocks (thinking, text, tool_use). */
|
|
158
|
+
native_blocks?: Array<Record<string, unknown>>;
|
|
159
|
+
/** OpenAI-compatible reasoning field (DeepSeek, etc.). */
|
|
160
|
+
reasoning_content?: string;
|
|
161
|
+
}
|
|
155
162
|
/** Structured render output produced by the kernel for each LLM call. */
|
|
156
163
|
export interface RenderedContext {
|
|
157
164
|
/** Combined system text: system partition + dashboard (when non-empty).
|
|
@@ -180,6 +187,10 @@ export interface LLMProvider {
|
|
|
180
187
|
* maxTurns / timeoutMs in RuntimeOptions.
|
|
181
188
|
*/
|
|
182
189
|
runtimePolicy?(): RuntimePolicy;
|
|
190
|
+
/** Read provider-native replay fields captured after the most recent assistant turn. */
|
|
191
|
+
peekProviderReplay?(message: Pick<Message, "content" | "toolCalls">): ProviderReplay | undefined;
|
|
192
|
+
/** Restore provider-native replay fields when rebuilding history from SessionLog. */
|
|
193
|
+
seedProviderReplay?(message: Pick<Message, "content" | "toolCalls">, replay: ProviderReplay): void;
|
|
183
194
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
184
195
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>, state?: ProviderRunState): AsyncIterable<StreamEvent>;
|
|
185
196
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "DeepStrike Node.js SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@anthropic-ai/sdk": "^0.39.0",
|
|
20
|
-
"@deepstrike/core": "0.1.
|
|
20
|
+
"@deepstrike/core": "0.1.15",
|
|
21
21
|
"@google/generative-ai": "^0.24.1",
|
|
22
22
|
"openai": "^4.77.0"
|
|
23
23
|
},
|