@deepstrike/sdk 0.1.14 → 0.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.
@@ -1,15 +1,24 @@
1
1
  import OpenAI from "openai";
2
2
  import { withServerRuntimeGuard } from "../runtime/server.js";
3
- import { CircuitBreaker, omitExtensionKeys } from "./base.js";
3
+ import { CircuitBreaker, omitExtensionKeys, ThinkingTagStreamExtractor } from "./base.js";
4
4
  import { OpenAIChatAdapter } from "./openai-chat.js";
5
5
  const OPENAI_POLICIES = {
6
+ "gpt-5.5": { maxTurns: 60 },
7
+ "gpt-5.4": { maxTurns: 50 },
8
+ "gpt-5.4-mini": { maxTurns: 25 },
9
+ "gpt-5.4-nano": { maxTurns: 15 },
10
+ "gpt-5.2": { maxTurns: 50 },
11
+ "gpt-5.2-pro": { maxTurns: 60 },
12
+ "gpt-5.1": { maxTurns: 50 },
6
13
  "gpt-4o": { maxTurns: 25 },
7
14
  "gpt-4o-mini": { maxTurns: 15 },
8
15
  "gpt-4.1": { maxTurns: 35 },
9
16
  "gpt-4.1-mini": { maxTurns: 20 },
10
17
  "gpt-4.1-nano": { maxTurns: 15 },
11
18
  "gpt-5": { maxTurns: 50 },
19
+ "gpt-5-pro": { maxTurns: 60 },
12
20
  "gpt-5-mini": { maxTurns: 25 },
21
+ "gpt-5-nano": { maxTurns: 15 },
13
22
  "o1": { maxTurns: 50 },
14
23
  "o1-mini": { maxTurns: 25 },
15
24
  "o3": { maxTurns: 50 },
@@ -33,6 +42,17 @@ export class OpenAIChatProvider {
33
42
  runtimePolicy() {
34
43
  return OPENAI_POLICIES[this.model] ?? {};
35
44
  }
45
+ peekProviderReplay(message) {
46
+ const fields = this.chat.peekReplayFields(message);
47
+ if (!fields || !("reasoning_content" in fields))
48
+ return undefined;
49
+ return { reasoning_content: String(fields.reasoning_content ?? "") };
50
+ }
51
+ seedProviderReplay(message, replay) {
52
+ if (replay.reasoning_content !== undefined) {
53
+ this.chat.rememberReplayFields(message, { reasoning_content: replay.reasoning_content });
54
+ }
55
+ }
36
56
  async complete(context, tools, extensions) {
37
57
  if (this.circuit.isOpen())
38
58
  throw new Error("Circuit breaker open");
@@ -64,6 +84,9 @@ export class OpenAIChatProvider {
64
84
  const msgs = this.chat.buildMessages(context);
65
85
  const toolCallBufs = {};
66
86
  const emittedToolCallIndexes = new Set();
87
+ const extractor = new ThinkingTagStreamExtractor();
88
+ let accumulatedReasoning = "";
89
+ let accumulatedContent = "";
67
90
  const stream = await this.client.chat.completions.create({
68
91
  ...this.requestExtensions(extensions),
69
92
  model: this.model,
@@ -82,8 +105,22 @@ export class OpenAIChatProvider {
82
105
  if (!choice)
83
106
  continue;
84
107
  const delta = choice.delta;
85
- if (delta.content)
86
- yield { type: "text_delta", delta: delta.content };
108
+ if (delta.reasoning_content) {
109
+ accumulatedReasoning += delta.reasoning_content;
110
+ yield { type: "thinking_delta", delta: delta.reasoning_content };
111
+ }
112
+ if (delta.content) {
113
+ for (const part of extractor.feed(delta.content)) {
114
+ if (part.type === "thinking") {
115
+ accumulatedReasoning += part.content;
116
+ yield { type: "thinking_delta", delta: part.content };
117
+ }
118
+ else {
119
+ accumulatedContent += part.content;
120
+ yield { type: "text_delta", delta: part.content };
121
+ }
122
+ }
123
+ }
87
124
  for (const tc of delta.tool_calls ?? []) {
88
125
  const idx = tc.index;
89
126
  if (!toolCallBufs[idx])
@@ -93,6 +130,10 @@ export class OpenAIChatProvider {
93
130
  toolCallBufs[idx].argsBuf += tc.function?.arguments ?? "";
94
131
  }
95
132
  if (choice.finish_reason === "tool_calls") {
133
+ const toolCalls = Object.values(toolCallBufs).map(tb => ({
134
+ id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
135
+ }));
136
+ this.chat.rememberReplayFields({ content: accumulatedContent, toolCalls }, { reasoning_content: accumulatedReasoning });
96
137
  for (const [index, tb] of Object.entries(toolCallBufs)) {
97
138
  const idx = Number(index);
98
139
  if (emittedToolCallIndexes.has(idx))
@@ -109,6 +150,22 @@ export class OpenAIChatProvider {
109
150
  }
110
151
  }
111
152
  }
153
+ for (const part of extractor.flush()) {
154
+ if (part.type === "thinking") {
155
+ accumulatedReasoning += part.content;
156
+ yield { type: "thinking_delta", delta: part.content };
157
+ }
158
+ else {
159
+ accumulatedContent += part.content;
160
+ yield { type: "text_delta", delta: part.content };
161
+ }
162
+ }
163
+ const toolCalls = Object.values(toolCallBufs).map(tb => ({
164
+ id: tb.id, name: tb.name, arguments: tb.argsBuf || "{}",
165
+ }));
166
+ if (toolCalls.length || accumulatedReasoning) {
167
+ this.chat.rememberReplayFields({ content: accumulatedContent, toolCalls }, { reasoning_content: accumulatedReasoning });
168
+ }
112
169
  for (const [index, tb] of Object.entries(toolCallBufs)) {
113
170
  const idx = Number(index);
114
171
  if (emittedToolCallIndexes.has(idx))