@sma1lboy/kobe 0.5.20 → 0.5.22
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/bin/kobed.js +233 -7
- package/dist/cli/index.js +1277 -741
- package/package.json +1 -1
package/dist/bin/kobed.js
CHANGED
|
@@ -1601,11 +1601,22 @@ function codexAppServerItemNotificationToEvents(method, params) {
|
|
|
1601
1601
|
const itemType = typeof item?.type === "string" ? item.type : "tool";
|
|
1602
1602
|
if (isNonToolTranscriptItem(itemType))
|
|
1603
1603
|
return [];
|
|
1604
|
+
if (isReasoningItem(itemType)) {
|
|
1605
|
+
const text = reasoningTextFromItem(item ?? {});
|
|
1606
|
+
return text.length > 0 ? [{ type: "reasoning.delta", text }] : [];
|
|
1607
|
+
}
|
|
1604
1608
|
const payload = stripItemHousekeeping(item ?? {});
|
|
1605
1609
|
if (method === "item/started")
|
|
1606
1610
|
return [{ type: "tool.start", name: itemType, input: payload }];
|
|
1607
1611
|
return [{ type: "tool.result", name: itemType, output: payload }];
|
|
1608
1612
|
}
|
|
1613
|
+
function codexAppServerReasoningDeltaNotificationToEvent(method, params) {
|
|
1614
|
+
if (method !== "item/reasoning/summaryTextDelta" && method !== "item/reasoning/textDelta")
|
|
1615
|
+
return null;
|
|
1616
|
+
const p = asObject(params);
|
|
1617
|
+
const text = typeof p?.delta === "string" ? p.delta : "";
|
|
1618
|
+
return text.length > 0 ? { type: "reasoning.delta", text } : null;
|
|
1619
|
+
}
|
|
1609
1620
|
|
|
1610
1621
|
class AppServerRpc {
|
|
1611
1622
|
proc;
|
|
@@ -1771,6 +1782,14 @@ class AppServerRpc {
|
|
|
1771
1782
|
this.opts.onEvent({ type: "assistant.delta", text });
|
|
1772
1783
|
return;
|
|
1773
1784
|
}
|
|
1785
|
+
if (method === "item/reasoning/summaryTextDelta" || method === "item/reasoning/textDelta") {
|
|
1786
|
+
const event = codexAppServerReasoningDeltaNotificationToEvent(method, params);
|
|
1787
|
+
if (event)
|
|
1788
|
+
this.opts.onEvent(event);
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
if (method === "item/reasoning/summaryPartAdded")
|
|
1792
|
+
return;
|
|
1774
1793
|
if (method === "item/started" || method === "item/completed") {
|
|
1775
1794
|
for (const event of codexAppServerItemNotificationToEvents(method, params))
|
|
1776
1795
|
this.opts.onEvent(event);
|
|
@@ -1850,6 +1869,36 @@ function stripItemHousekeeping(item) {
|
|
|
1850
1869
|
function isNonToolTranscriptItem(itemType) {
|
|
1851
1870
|
return itemType === "agentMessage" || itemType === "agent_message" || itemType === "userMessage" || itemType === "user_message";
|
|
1852
1871
|
}
|
|
1872
|
+
function isReasoningItem(itemType) {
|
|
1873
|
+
return itemType.toLowerCase().includes("reason");
|
|
1874
|
+
}
|
|
1875
|
+
function reasoningTextFromItem(item) {
|
|
1876
|
+
const content = textFromReasoningValue(item.content);
|
|
1877
|
+
if (content.length > 0)
|
|
1878
|
+
return content;
|
|
1879
|
+
const text = typeof item.text === "string" ? item.text : "";
|
|
1880
|
+
if (text.length > 0)
|
|
1881
|
+
return text;
|
|
1882
|
+
return textFromReasoningValue(item.summary);
|
|
1883
|
+
}
|
|
1884
|
+
function textFromReasoningValue(value) {
|
|
1885
|
+
if (typeof value === "string")
|
|
1886
|
+
return value;
|
|
1887
|
+
if (!Array.isArray(value))
|
|
1888
|
+
return "";
|
|
1889
|
+
const parts = [];
|
|
1890
|
+
for (const entry of value) {
|
|
1891
|
+
if (typeof entry === "string") {
|
|
1892
|
+
parts.push(entry);
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
const object = asObject(entry);
|
|
1896
|
+
const text = typeof object?.text === "string" ? object.text : "";
|
|
1897
|
+
if (text.length > 0)
|
|
1898
|
+
parts.push(text);
|
|
1899
|
+
}
|
|
1900
|
+
return parts.join("");
|
|
1901
|
+
}
|
|
1853
1902
|
function stringifyErr2(err) {
|
|
1854
1903
|
if (err instanceof Error)
|
|
1855
1904
|
return err.message;
|
|
@@ -2214,19 +2263,148 @@ function parseJsonl2(raw, sessionId) {
|
|
|
2214
2263
|
const payload = isObject5(parsed.payload) ? parsed.payload : undefined;
|
|
2215
2264
|
if (!payload)
|
|
2216
2265
|
continue;
|
|
2217
|
-
|
|
2218
|
-
|
|
2266
|
+
const ts = typeof parsed.timestamp === "string" ? parsed.timestamp : new Date().toISOString();
|
|
2267
|
+
const msg = normalizeCodexResponseItem(payload, ts, sessionId);
|
|
2268
|
+
if (msg)
|
|
2269
|
+
out.push(msg);
|
|
2270
|
+
}
|
|
2271
|
+
return out;
|
|
2272
|
+
}
|
|
2273
|
+
function normalizeCodexResponseItem(payload, timestamp, sessionId) {
|
|
2274
|
+
if (payload.type === "message") {
|
|
2219
2275
|
const role = payload.role;
|
|
2220
2276
|
if (role !== "user" && role !== "assistant" && role !== "system")
|
|
2221
|
-
|
|
2277
|
+
return;
|
|
2222
2278
|
const blocks = normalizeCodexContent(payload.content);
|
|
2223
2279
|
if (role === "user" && isSyntheticCodexUserRow(blocks))
|
|
2280
|
+
return;
|
|
2281
|
+
return { role, blocks, timestamp, sessionId };
|
|
2282
|
+
}
|
|
2283
|
+
if (payload.type === "reasoning")
|
|
2284
|
+
return normalizeCodexReasoning(payload, timestamp, sessionId);
|
|
2285
|
+
if (payload.type === "function_call") {
|
|
2286
|
+
return normalizeCodexToolCall(payload, timestamp, sessionId, {
|
|
2287
|
+
name: stringOr(payload.name, "function_call"),
|
|
2288
|
+
input: parseMaybeJson(payload.arguments)
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
if (payload.type === "custom_tool_call") {
|
|
2292
|
+
return normalizeCodexToolCall(payload, timestamp, sessionId, {
|
|
2293
|
+
name: stringOr(payload.name, "custom_tool_call"),
|
|
2294
|
+
input: parseMaybeJson(payload.input)
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
if (payload.type === "tool_search_call") {
|
|
2298
|
+
return normalizeCodexToolCall(payload, timestamp, sessionId, {
|
|
2299
|
+
name: "tool_search_call",
|
|
2300
|
+
input: stripPayload(payload, ["type", "call_id", "status"])
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
if (payload.type === "function_call_output" || payload.type === "custom_tool_call_output") {
|
|
2304
|
+
return normalizeCodexToolResult(payload, timestamp, sessionId, parseMaybeJson(payload.output));
|
|
2305
|
+
}
|
|
2306
|
+
if (payload.type === "tool_search_output") {
|
|
2307
|
+
return normalizeCodexToolResult(payload, timestamp, sessionId, stripPayload(payload, ["type", "call_id"]));
|
|
2308
|
+
}
|
|
2309
|
+
if (payload.type === "web_search_call" || payload.type === "image_generation_call" || payload.type === "local_shell_call") {
|
|
2310
|
+
return normalizeSingleRecordTool(payload, timestamp, sessionId);
|
|
2311
|
+
}
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
function normalizeCodexReasoning(payload, timestamp, sessionId) {
|
|
2315
|
+
const text = reasoningTextFromItem2(payload);
|
|
2316
|
+
if (text.length === 0)
|
|
2317
|
+
return;
|
|
2318
|
+
return { role: "assistant", blocks: [{ type: "thinking", text }], timestamp, sessionId };
|
|
2319
|
+
}
|
|
2320
|
+
function normalizeCodexToolCall(payload, timestamp, sessionId, args) {
|
|
2321
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : undefined;
|
|
2322
|
+
if (!callId)
|
|
2323
|
+
return;
|
|
2324
|
+
const block = {
|
|
2325
|
+
type: "tool_call",
|
|
2326
|
+
callId,
|
|
2327
|
+
name: args.name,
|
|
2328
|
+
input: args.input
|
|
2329
|
+
};
|
|
2330
|
+
return { role: "assistant", blocks: [block], timestamp, sessionId };
|
|
2331
|
+
}
|
|
2332
|
+
function normalizeCodexToolResult(payload, timestamp, sessionId, output) {
|
|
2333
|
+
const callId = typeof payload.call_id === "string" ? payload.call_id : undefined;
|
|
2334
|
+
if (!callId)
|
|
2335
|
+
return;
|
|
2336
|
+
const block = {
|
|
2337
|
+
type: "tool_result",
|
|
2338
|
+
callId,
|
|
2339
|
+
output,
|
|
2340
|
+
isError: false
|
|
2341
|
+
};
|
|
2342
|
+
return { role: "user", blocks: [block], timestamp, sessionId };
|
|
2343
|
+
}
|
|
2344
|
+
function normalizeSingleRecordTool(payload, timestamp, sessionId) {
|
|
2345
|
+
const type = typeof payload.type === "string" ? payload.type : "tool";
|
|
2346
|
+
const callId = typeof payload.call_id === "string" && payload.call_id.length > 0 ? payload.call_id : `${type}:${timestamp}`;
|
|
2347
|
+
const name = stringOr(payload.name, type);
|
|
2348
|
+
const input = stripPayload(payload, ["type", "call_id", "status"]);
|
|
2349
|
+
const output = stripPayload(payload, ["type", "call_id"]);
|
|
2350
|
+
return {
|
|
2351
|
+
role: "assistant",
|
|
2352
|
+
timestamp,
|
|
2353
|
+
sessionId,
|
|
2354
|
+
blocks: [
|
|
2355
|
+
{ type: "tool_call", callId, name, input },
|
|
2356
|
+
{ type: "tool_result", callId, output, isError: false }
|
|
2357
|
+
]
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
function reasoningTextFromItem2(item) {
|
|
2361
|
+
const content = textFromReasoningValue2(item.content);
|
|
2362
|
+
if (content.length > 0)
|
|
2363
|
+
return content;
|
|
2364
|
+
const text = typeof item.text === "string" ? item.text : "";
|
|
2365
|
+
if (text.length > 0)
|
|
2366
|
+
return text;
|
|
2367
|
+
return textFromReasoningValue2(item.summary);
|
|
2368
|
+
}
|
|
2369
|
+
function textFromReasoningValue2(value) {
|
|
2370
|
+
if (typeof value === "string")
|
|
2371
|
+
return value;
|
|
2372
|
+
if (!Array.isArray(value))
|
|
2373
|
+
return "";
|
|
2374
|
+
const parts = [];
|
|
2375
|
+
for (const entry of value) {
|
|
2376
|
+
if (typeof entry === "string") {
|
|
2377
|
+
parts.push(entry);
|
|
2224
2378
|
continue;
|
|
2225
|
-
|
|
2226
|
-
|
|
2379
|
+
}
|
|
2380
|
+
if (!isObject5(entry))
|
|
2381
|
+
continue;
|
|
2382
|
+
const text = typeof entry.text === "string" ? entry.text : "";
|
|
2383
|
+
if (text.length > 0)
|
|
2384
|
+
parts.push(text);
|
|
2385
|
+
}
|
|
2386
|
+
return parts.join("");
|
|
2387
|
+
}
|
|
2388
|
+
function stripPayload(payload, keys) {
|
|
2389
|
+
const out = {};
|
|
2390
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
2391
|
+
if (!keys.includes(key))
|
|
2392
|
+
out[key] = value;
|
|
2227
2393
|
}
|
|
2228
2394
|
return out;
|
|
2229
2395
|
}
|
|
2396
|
+
function stringOr(value, fallback) {
|
|
2397
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
2398
|
+
}
|
|
2399
|
+
function parseMaybeJson(value) {
|
|
2400
|
+
if (typeof value !== "string")
|
|
2401
|
+
return value;
|
|
2402
|
+
try {
|
|
2403
|
+
return JSON.parse(value);
|
|
2404
|
+
} catch {
|
|
2405
|
+
return value;
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2230
2408
|
function deriveCodexUsageMetrics(raw) {
|
|
2231
2409
|
let latestUsage;
|
|
2232
2410
|
let latestUsageTimestampMs = null;
|
|
@@ -2540,6 +2718,12 @@ async function* parseStreamJson2(lines, opts = {}) {
|
|
|
2540
2718
|
yield { type: "assistant.delta", text };
|
|
2541
2719
|
continue;
|
|
2542
2720
|
}
|
|
2721
|
+
if (isReasoningItem2(itemType)) {
|
|
2722
|
+
const text = reasoningTextFromItem3(item);
|
|
2723
|
+
if (text.length > 0)
|
|
2724
|
+
yield { type: "reasoning.delta", text };
|
|
2725
|
+
continue;
|
|
2726
|
+
}
|
|
2543
2727
|
if (itemId) {
|
|
2544
2728
|
toolNameById.set(itemId, itemType);
|
|
2545
2729
|
}
|
|
@@ -2607,6 +2791,37 @@ function codexSessionId(msg) {
|
|
|
2607
2791
|
const id = msg.thread_id;
|
|
2608
2792
|
return typeof id === "string" && id.length > 0 ? id : undefined;
|
|
2609
2793
|
}
|
|
2794
|
+
function isReasoningItem2(itemType) {
|
|
2795
|
+
return itemType.toLowerCase().includes("reason");
|
|
2796
|
+
}
|
|
2797
|
+
function reasoningTextFromItem3(item) {
|
|
2798
|
+
const content = textFromReasoningValue3(item.content);
|
|
2799
|
+
if (content.length > 0)
|
|
2800
|
+
return content;
|
|
2801
|
+
const text = typeof item.text === "string" ? item.text : "";
|
|
2802
|
+
if (text.length > 0)
|
|
2803
|
+
return text;
|
|
2804
|
+
return textFromReasoningValue3(item.summary);
|
|
2805
|
+
}
|
|
2806
|
+
function textFromReasoningValue3(value) {
|
|
2807
|
+
if (typeof value === "string")
|
|
2808
|
+
return value;
|
|
2809
|
+
if (!Array.isArray(value))
|
|
2810
|
+
return "";
|
|
2811
|
+
const parts = [];
|
|
2812
|
+
for (const entry of value) {
|
|
2813
|
+
if (typeof entry === "string") {
|
|
2814
|
+
parts.push(entry);
|
|
2815
|
+
continue;
|
|
2816
|
+
}
|
|
2817
|
+
if (!isObject8(entry))
|
|
2818
|
+
continue;
|
|
2819
|
+
const text = typeof entry.text === "string" ? entry.text : "";
|
|
2820
|
+
if (text.length > 0)
|
|
2821
|
+
parts.push(text);
|
|
2822
|
+
}
|
|
2823
|
+
return parts.join("");
|
|
2824
|
+
}
|
|
2610
2825
|
function stripIdAndType(item) {
|
|
2611
2826
|
const { id: _id, type: _type, ...rest } = item;
|
|
2612
2827
|
return rest;
|
|
@@ -6207,6 +6422,7 @@ class Orchestrator {
|
|
|
6207
6422
|
seq: nextChatTabSeq(task.tabs),
|
|
6208
6423
|
createdAt: new Date().toISOString(),
|
|
6209
6424
|
model: active.model ?? task.model,
|
|
6425
|
+
modelEffort: active.modelEffort ?? task.modelEffort,
|
|
6210
6426
|
vendor: this.vendorForTab(task, active),
|
|
6211
6427
|
...opts.title ? { title: opts.title } : {}
|
|
6212
6428
|
};
|
|
@@ -6236,13 +6452,23 @@ class Orchestrator {
|
|
|
6236
6452
|
async createTab(id, opts = {}) {
|
|
6237
6453
|
const task = this.requireTask(id);
|
|
6238
6454
|
const active = this.resolveTab(task);
|
|
6455
|
+
const {
|
|
6456
|
+
id: _activeId,
|
|
6457
|
+
sessionId: _activeSessionId,
|
|
6458
|
+
title: _activeTitle,
|
|
6459
|
+
seq: _activeSeq,
|
|
6460
|
+
createdAt: _activeCreatedAt,
|
|
6461
|
+
...activeConfig
|
|
6462
|
+
} = active;
|
|
6239
6463
|
const tab = {
|
|
6464
|
+
...activeConfig,
|
|
6240
6465
|
id: ulid(),
|
|
6241
6466
|
sessionId: null,
|
|
6242
6467
|
seq: nextChatTabSeq(task.tabs),
|
|
6243
6468
|
createdAt: new Date().toISOString(),
|
|
6244
|
-
model:
|
|
6245
|
-
|
|
6469
|
+
model: activeConfig.model ?? task.model,
|
|
6470
|
+
modelEffort: activeConfig.modelEffort ?? task.modelEffort,
|
|
6471
|
+
vendor: activeConfig.vendor ?? this.vendorForTab(task, active),
|
|
6246
6472
|
...opts.title ? { title: opts.title } : {}
|
|
6247
6473
|
};
|
|
6248
6474
|
const tabs = [...task.tabs, tab];
|