@beeuni/sdk 0.1.0 → 0.2.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/README.md +35 -83
- package/dist/beeuni.esm.min.js +35 -35
- package/dist/beeuni.global.js +35 -35
- package/dist/browser/stores/sync-store.d.ts +6 -0
- package/dist/browser/stores/sync-store.js +52 -21
- package/dist/core/client/beeuni.d.ts +7 -29
- package/dist/core/client/beeuni.js +3 -11
- package/dist/core/client/facade-catalog.d.ts +0 -4
- package/dist/core/client/facade-catalog.js +1 -5
- package/dist/core/client/project-connections.d.ts +2 -2
- package/dist/core/client/project-connections.js +2 -2
- package/dist/core/client/project-operations.d.ts +4 -15
- package/dist/core/client/project-operations.js +2 -6
- package/dist/core/client/project-platform-security.d.ts +1 -1
- package/dist/core/client/project-platform-settings.d.ts +1 -1
- package/dist/core/http/api-client.d.ts +0 -7
- package/dist/core/http/api-client.js +1 -37
- package/dist/core/http/auth.d.ts +2 -4
- package/dist/core/http/auth.js +2 -8
- package/dist/core/rest/platform-client/client-policy.d.ts +8 -0
- package/dist/core/rest/platform-client/client-policy.js +30 -0
- package/dist/core/rest/platform-client/index.d.ts +3 -4
- package/dist/core/rest/platform-client/index.js +3 -4
- package/dist/core/rest/platform-client/types.d.ts +1 -1
- package/dist/core/rest/projects-client/apps.d.ts +8 -1
- package/dist/core/rest/projects-client/connectors.d.ts +6 -55
- package/dist/core/rest/projects-client/connectors.js +2 -29
- package/dist/core/rest/projects-client/git-backend.d.ts +1 -10
- package/dist/core/rest/projects-client/git-backend.js +0 -10
- package/dist/core/rest/projects-client/iam-sso.d.ts +0 -10
- package/dist/core/rest/projects-client/iam-sso.js +0 -3
- package/dist/core/rest/projects-client/index.d.ts +1 -4
- package/dist/core/rest/projects-client/index.js +1 -4
- package/dist/core/rest/projects-client/projects.d.ts +2 -1
- package/dist/core/rest/projects-client/projects.js +3 -0
- package/dist/core/rest/projects-client/sandbox.d.ts +8 -9
- package/dist/core/rest/projects-client/session-sandbox.d.ts +1 -1
- package/dist/core/rest/projects-client/sessions.d.ts +2 -2
- package/dist/core/session/control-stream.d.ts +1 -0
- package/dist/core/session/control-stream.js +18 -1
- package/dist/core/session-log/guard.d.ts +6 -0
- package/dist/core/session-log/guard.js +109 -0
- package/dist/core/session-log/index.d.ts +3 -0
- package/dist/core/session-log/index.js +2 -0
- package/dist/core/session-log/saved-log.d.ts +10 -0
- package/dist/core/session-log/saved-log.js +25 -0
- package/dist/core/session-log/source.d.ts +25 -0
- package/dist/core/session-log/source.js +30 -0
- package/dist/core/session-log/store.d.ts +21 -0
- package/dist/core/session-log/store.js +126 -0
- package/dist/core/session-log/tool-call.d.ts +6 -0
- package/dist/core/session-log/tool-call.js +46 -0
- package/dist/core/session-log/types.d.ts +264 -0
- package/dist/core/session-log/types.js +6 -0
- package/dist/core/session-log/v1-view.d.ts +10 -0
- package/dist/core/session-log/v1-view.js +151 -0
- package/dist/core/session-log/v1.d.ts +31 -0
- package/dist/core/session-log/v1.js +466 -0
- package/dist/core/session-sync/copy-store-types.d.ts +19 -0
- package/dist/core/session-sync/copy-store-types.js +1 -0
- package/dist/core/session-sync/saved-copy-store.js +25 -4
- package/dist/core/stream/event-stream.js +2 -2
- package/dist/core/turns/classify.d.ts +2 -1
- package/dist/core/turns/classify.js +3 -1
- package/dist/core/turns/parts.d.ts +3 -2
- package/dist/core/turns/parts.js +4 -2
- package/dist/core/turns/segments/index.d.ts +1 -0
- package/dist/core/turns/segments/index.js +1 -0
- package/dist/core/turns/segments/work-split.d.ts +10 -0
- package/dist/core/turns/segments/work-split.js +40 -0
- package/dist/core/turns/state.d.ts +2 -7
- package/dist/core/turns/state.js +28 -134
- package/dist/core/turns/tools/tool-meta.d.ts +2 -1
- package/dist/core/turns/tools/tool-meta.js +3 -1
- package/dist/core/turns/tools/tool-outcome.d.ts +2 -1
- package/dist/core/turns/tools/tool-outcome.js +3 -1
- package/dist/core/turns/types.d.ts +1 -1
- package/dist/core/warm-session-pool.d.ts +29 -0
- package/dist/core/warm-session-pool.js +127 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/internal/connector-catalog.d.ts +47 -0
- package/dist/internal/connector-catalog.js +27 -0
- package/dist/internal/host-configuration.d.ts +22 -0
- package/dist/internal/host-configuration.js +28 -0
- package/dist/internal/platform-admin-react.d.ts +12 -0
- package/dist/internal/platform-admin-react.js +13 -0
- package/dist/internal/platform-admin.d.ts +9 -0
- package/dist/internal/platform-admin.js +9 -0
- package/dist/react/index.d.ts +0 -13
- package/dist/react/index.js +0 -13
- package/dist/react/opencode.d.ts +1 -0
- package/dist/react/opencode.js +1 -0
- package/dist/react/query-keys.d.ts +0 -1
- package/dist/react/query-keys.js +0 -1
- package/dist/react/session-transcript-subscription.js +3 -1
- package/dist/react/sign-in-with-beeuni.d.ts +1 -1
- package/dist/react/use-admin-providers.d.ts +5 -5
- package/dist/react/use-opencode-events/handle-event.d.ts +1 -0
- package/dist/react/use-opencode-events/handle-event.js +5 -0
- package/dist/react/use-opencode-events/index.js +1 -0
- package/dist/react/use-runtime-reconnect.js +2 -2
- package/dist/react/use-session-log.d.ts +15 -0
- package/dist/react/use-session-log.js +134 -0
- package/dist/react/use-session.js +2 -0
- package/package.json +15 -7
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SessionLogSessionRecord, SessionLogThreadHead } from './store.js';
|
|
2
|
+
import type { SessionLogMessage } from './types.js';
|
|
3
|
+
export interface SessionLogPage {
|
|
4
|
+
session: Partial<SessionLogSessionRecord>;
|
|
5
|
+
generation: number;
|
|
6
|
+
threads: SessionLogThreadHead[];
|
|
7
|
+
thread_id: string | null;
|
|
8
|
+
messages: SessionLogMessage[];
|
|
9
|
+
has_more: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface SessionLogPageQuery {
|
|
12
|
+
thread?: string;
|
|
13
|
+
before_seq?: number;
|
|
14
|
+
limit?: number;
|
|
15
|
+
}
|
|
16
|
+
export type LoadSessionLogPage = (projectId: string, sessionId: string, query: SessionLogPageQuery, signal?: AbortSignal) => Promise<unknown>;
|
|
17
|
+
export declare const loadSessionLogPage: LoadSessionLogPage | null;
|
|
18
|
+
export declare const SESSION_LOG_FIRST_PAGE_LIMIT = 40;
|
|
19
|
+
export type SessionLogDialect = 'v1' | 'v2';
|
|
20
|
+
export declare function negotiateSessionLog(input: {
|
|
21
|
+
capabilities: readonly string[] | null | undefined;
|
|
22
|
+
flag: boolean | undefined;
|
|
23
|
+
loader: LoadSessionLogPage | null;
|
|
24
|
+
}): SessionLogDialect;
|
|
25
|
+
export declare function fetchFirstSessionLogPage(load: LoadSessionLogPage, projectId: string, sessionId: string, signal?: AbortSignal): Promise<SessionLogPage | null>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { backendApi } from '../http/api-client.js';
|
|
2
|
+
import { isSessionLogPage } from './guard.js';
|
|
3
|
+
export const loadSessionLogPage = async (projectId, sessionId, query, signal) => {
|
|
4
|
+
const search = new URLSearchParams();
|
|
5
|
+
if (query.thread !== undefined)
|
|
6
|
+
search.set('thread', query.thread);
|
|
7
|
+
if (query.before_seq !== undefined)
|
|
8
|
+
search.set('before_seq', String(query.before_seq));
|
|
9
|
+
if (query.limit !== undefined)
|
|
10
|
+
search.set('limit', String(query.limit));
|
|
11
|
+
const qs = search.toString();
|
|
12
|
+
const response = await backendApi.get(`/projects/${encodeURIComponent(projectId)}/sessions/${encodeURIComponent(sessionId)}/log${qs ? `?${qs}` : ''}`, { showErrors: false, signal });
|
|
13
|
+
if (!response.success)
|
|
14
|
+
throw response.error ?? new Error('Session log request failed');
|
|
15
|
+
return response.data;
|
|
16
|
+
};
|
|
17
|
+
export const SESSION_LOG_FIRST_PAGE_LIMIT = 40;
|
|
18
|
+
export function negotiateSessionLog(input) {
|
|
19
|
+
const served = Array.isArray(input.capabilities) && input.capabilities.includes('session.log.v2');
|
|
20
|
+
return served && input.flag === true && input.loader !== null ? 'v2' : 'v1';
|
|
21
|
+
}
|
|
22
|
+
export async function fetchFirstSessionLogPage(load, projectId, sessionId, signal) {
|
|
23
|
+
try {
|
|
24
|
+
const page = await load(projectId, sessionId, { limit: SESSION_LOG_FIRST_PAGE_LIMIT }, signal);
|
|
25
|
+
return isSessionLogPage(page) ? page : null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionLogPage } from './source.js';
|
|
2
|
+
import type { SessionLog, SessionLogMessage, SessionLogThread } from './types.js';
|
|
3
|
+
export type SessionLogThreadHead = Omit<SessionLogThread, 'messages'>;
|
|
4
|
+
export type SessionLogSessionRecord = Omit<SessionLog, 'threads'>;
|
|
5
|
+
export interface SessionLogState {
|
|
6
|
+
generation: number;
|
|
7
|
+
session: Partial<SessionLogSessionRecord>;
|
|
8
|
+
threads: Record<string, SessionLogThreadHead>;
|
|
9
|
+
messages: Record<string, SessionLogMessage[]>;
|
|
10
|
+
revs: Record<string, number>;
|
|
11
|
+
}
|
|
12
|
+
export interface SessionLogEventInput {
|
|
13
|
+
type: string;
|
|
14
|
+
properties: unknown;
|
|
15
|
+
id?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const EMPTY_SESSION_LOG_STATE: SessionLogState;
|
|
18
|
+
export declare function applySessionLogEvent(state: SessionLogState, event: SessionLogEventInput): SessionLogState;
|
|
19
|
+
export declare function applySessionLogPage(state: SessionLogState, page: SessionLogPage): SessionLogState;
|
|
20
|
+
export declare function selectSessionLog(state: SessionLogState): SessionLog | null;
|
|
21
|
+
export declare function selectSessionLogThread(state: SessionLogState, threadId?: string | null): SessionLogThread | null;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { isSessionLogMessage, isSessionLogThreadHead } from './guard.js';
|
|
2
|
+
export const EMPTY_SESSION_LOG_STATE = Object.freeze({
|
|
3
|
+
generation: 0,
|
|
4
|
+
session: {},
|
|
5
|
+
threads: {},
|
|
6
|
+
messages: {},
|
|
7
|
+
revs: {},
|
|
8
|
+
});
|
|
9
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
10
|
+
const isRev = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
11
|
+
function threadOfMessage(state, id) {
|
|
12
|
+
for (const [thread, list] of Object.entries(state.messages))
|
|
13
|
+
if (list.some((m) => m.message_id === id))
|
|
14
|
+
return thread;
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
function without(state, id) {
|
|
18
|
+
const thread = threadOfMessage(state, id);
|
|
19
|
+
if (thread === undefined)
|
|
20
|
+
return state.messages;
|
|
21
|
+
return { ...state.messages, [thread]: state.messages[thread].filter((m) => m.message_id !== id) };
|
|
22
|
+
}
|
|
23
|
+
function put(messages, message) {
|
|
24
|
+
const list = (messages[message.thread_id] ?? []).filter((m) => m.message_id !== message.message_id);
|
|
25
|
+
let at = list.length;
|
|
26
|
+
while (at > 0 && list[at - 1].seq > message.seq)
|
|
27
|
+
at--;
|
|
28
|
+
list.splice(at, 0, message);
|
|
29
|
+
return { ...messages, [message.thread_id]: list };
|
|
30
|
+
}
|
|
31
|
+
function applyMessage(state, p) {
|
|
32
|
+
if (!isObj(p) || !isRev(p.rev))
|
|
33
|
+
return state;
|
|
34
|
+
if ('message' in p) {
|
|
35
|
+
if (!isSessionLogMessage(p.message))
|
|
36
|
+
return state;
|
|
37
|
+
const id = p.message.message_id;
|
|
38
|
+
if ((state.revs[id] ?? -1) >= p.rev)
|
|
39
|
+
return state;
|
|
40
|
+
return { ...state, messages: put(without(state, id), p.message), revs: { ...state.revs, [id]: p.rev } };
|
|
41
|
+
}
|
|
42
|
+
if (typeof p.message_id !== 'string' || (state.revs[p.message_id] ?? -1) >= p.rev)
|
|
43
|
+
return state;
|
|
44
|
+
return { ...state, messages: without(state, p.message_id), revs: { ...state.revs, [p.message_id]: p.rev } };
|
|
45
|
+
}
|
|
46
|
+
function applyDelta(state, p) {
|
|
47
|
+
if (!isObj(p) || typeof p.delta !== 'string' || typeof p.thread_id !== 'string')
|
|
48
|
+
return state;
|
|
49
|
+
const list = state.messages[p.thread_id];
|
|
50
|
+
const at = list?.findIndex((m) => m.message_id === p.message_id) ?? -1;
|
|
51
|
+
if (!list || at < 0)
|
|
52
|
+
return state;
|
|
53
|
+
const message = list[at];
|
|
54
|
+
const index = message.blocks.findIndex((b) => b.id === p.block_id);
|
|
55
|
+
const block = message.blocks[index];
|
|
56
|
+
if (!block || (block.type !== 'text' && block.type !== 'reasoning'))
|
|
57
|
+
return state;
|
|
58
|
+
const blocks = message.blocks.slice();
|
|
59
|
+
blocks[index] = { ...block, text: block.text + p.delta };
|
|
60
|
+
const next = list.slice();
|
|
61
|
+
next[at] = { ...message, blocks };
|
|
62
|
+
return { ...state, messages: { ...state.messages, [p.thread_id]: next } };
|
|
63
|
+
}
|
|
64
|
+
export function applySessionLogEvent(state, event) {
|
|
65
|
+
const p = event.properties;
|
|
66
|
+
switch (event.type) {
|
|
67
|
+
case 'log.message':
|
|
68
|
+
return applyMessage(state, p);
|
|
69
|
+
case 'log.block.delta':
|
|
70
|
+
return applyDelta(state, p);
|
|
71
|
+
case 'log.thread':
|
|
72
|
+
return isSessionLogThreadHead(p) ? { ...state, threads: { ...state.threads, [p.thread_id]: p } } : state;
|
|
73
|
+
case 'log.state':
|
|
74
|
+
if (!isObj(p) || !isRev(p.generation) || p.generation < state.generation || !isObj(p.session))
|
|
75
|
+
return state;
|
|
76
|
+
return { ...state, generation: p.generation, session: { ...state.session, ...p.session } };
|
|
77
|
+
default:
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function applySessionLogPage(state, page) {
|
|
82
|
+
let messages = state.messages;
|
|
83
|
+
const thread = page.thread_id;
|
|
84
|
+
const held = thread === null ? undefined : messages[thread];
|
|
85
|
+
if (thread !== null && held) {
|
|
86
|
+
const from = page.has_more ? (page.messages[0]?.seq ?? Infinity) : -Infinity;
|
|
87
|
+
const kept = new Set(page.messages.map((m) => m.message_id));
|
|
88
|
+
const settled = held.filter((m) => m.seq < from || kept.has(m.message_id) || state.revs[m.message_id] !== undefined);
|
|
89
|
+
if (settled.length !== held.length)
|
|
90
|
+
messages = { ...messages, [thread]: settled };
|
|
91
|
+
}
|
|
92
|
+
for (const message of page.messages) {
|
|
93
|
+
if (!isSessionLogMessage(message) || state.revs[message.message_id] !== undefined)
|
|
94
|
+
continue;
|
|
95
|
+
messages = put(messages, message);
|
|
96
|
+
}
|
|
97
|
+
const threads = { ...state.threads };
|
|
98
|
+
for (const head of page.threads)
|
|
99
|
+
if (isSessionLogThreadHead(head))
|
|
100
|
+
threads[head.thread_id] = head;
|
|
101
|
+
const newer = page.generation > state.generation;
|
|
102
|
+
return {
|
|
103
|
+
...state,
|
|
104
|
+
generation: Math.max(page.generation, state.generation),
|
|
105
|
+
session: newer ? { ...state.session, ...page.session } : { ...page.session, ...state.session },
|
|
106
|
+
threads,
|
|
107
|
+
messages,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const logs = new WeakMap();
|
|
111
|
+
export function selectSessionLog(state) {
|
|
112
|
+
const cached = logs.get(state);
|
|
113
|
+
if (cached !== undefined)
|
|
114
|
+
return cached;
|
|
115
|
+
const session = state.session.session_id === undefined ? null : state.session;
|
|
116
|
+
const log = session && {
|
|
117
|
+
...session,
|
|
118
|
+
threads: Object.values(state.threads).map((head) => ({ ...head, messages: state.messages[head.thread_id] ?? [] })),
|
|
119
|
+
};
|
|
120
|
+
logs.set(state, log);
|
|
121
|
+
return log;
|
|
122
|
+
}
|
|
123
|
+
export function selectSessionLogThread(state, threadId) {
|
|
124
|
+
const threads = selectSessionLog(state)?.threads ?? [];
|
|
125
|
+
return threads.find((t) => (threadId ? t.thread_id === threadId : t.parent_thread_id === null)) ?? null;
|
|
126
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ToolPart } from '../runtime/runtime-types.js';
|
|
2
|
+
import { type ToolCallBlock } from './types.js';
|
|
3
|
+
export declare function toolCallBlock(part: ToolPart): ToolCallBlock;
|
|
4
|
+
export declare function toolPartOf(call: ToolCallBlock): ToolPart;
|
|
5
|
+
export declare const isToolCallBlock: (value: unknown) => value is ToolCallBlock;
|
|
6
|
+
export declare function toolCallMetadata(call: ToolCallBlock): Record<string, unknown>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BEEUNI_TRANSCRIPT_SCHEMA } from '../runtime/transcript-types.js';
|
|
2
|
+
import { SESSION_LOG_MINOR, SESSION_LOG_SCHEMA } from './types.js';
|
|
3
|
+
import { fromV1, toV1 } from './v1.js';
|
|
4
|
+
const V = { schema: SESSION_LOG_SCHEMA, v: SESSION_LOG_MINOR };
|
|
5
|
+
const EMPTY = Object.freeze({});
|
|
6
|
+
const blocks = new WeakMap();
|
|
7
|
+
export function toolCallBlock(part) {
|
|
8
|
+
const cached = blocks.get(part);
|
|
9
|
+
if (cached && cached.state === part.state)
|
|
10
|
+
return cached.block;
|
|
11
|
+
const sid = part.sessionID ?? null;
|
|
12
|
+
const info = { id: part.messageID, sessionID: part.sessionID, role: 'assistant' };
|
|
13
|
+
const log = fromV1({ session_id: '', root_id: sid, rows: [{ runtime_session_id: sid, info: info, parts: [part] }] }, { live: true });
|
|
14
|
+
const block = log.threads[0].messages[0].blocks[0];
|
|
15
|
+
blocks.set(part, { state: part.state, block });
|
|
16
|
+
return block;
|
|
17
|
+
}
|
|
18
|
+
const parts = new WeakMap();
|
|
19
|
+
export function toolPartOf(call) {
|
|
20
|
+
const cached = parts.get(call);
|
|
21
|
+
if (cached)
|
|
22
|
+
return cached;
|
|
23
|
+
const thread = {
|
|
24
|
+
...V, thread_id: '', parent_thread_id: null, spawned_by: null, agent: null, title: null, created_at: '',
|
|
25
|
+
ext: { opencode: { version: BEEUNI_TRANSCRIPT_SCHEMA } },
|
|
26
|
+
messages: [{
|
|
27
|
+
...V, message_id: '', thread_id: '', seq: 1, role: 'assistant', kind: 'turn', status: 'complete', in_context: true,
|
|
28
|
+
model: null, usage: null, finish: null, error: null, created_at: '', completed_at: null,
|
|
29
|
+
producer: { harness: '', harness_version: '', adapter_version: '' }, blocks: [call],
|
|
30
|
+
}],
|
|
31
|
+
};
|
|
32
|
+
const { rows } = toV1({
|
|
33
|
+
...V, session_id: '', title: null, created_at: '', restore_grade: 'native', harness: { current: '', history: [] },
|
|
34
|
+
selection: { agent: null, model: null }, todos: [], pending: { questions: [], permissions: [] }, threads: [thread],
|
|
35
|
+
});
|
|
36
|
+
const part = rows[0].parts[0];
|
|
37
|
+
parts.set(call, part);
|
|
38
|
+
return part;
|
|
39
|
+
}
|
|
40
|
+
export const isToolCallBlock = (value) => typeof value === 'object' && value !== null && value.type === 'tool_call';
|
|
41
|
+
export function toolCallMetadata(call) {
|
|
42
|
+
const metadata = toolPartOf(call).state.metadata;
|
|
43
|
+
return typeof metadata === 'object' && metadata !== null && !Array.isArray(metadata) && Object.keys(metadata).length
|
|
44
|
+
? metadata
|
|
45
|
+
: EMPTY;
|
|
46
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
export declare const SESSION_LOG_SCHEMA: "beeuni.session/2";
|
|
2
|
+
export declare const SESSION_LOG_MINOR = 1;
|
|
3
|
+
export type SchemaRef = {
|
|
4
|
+
schema: typeof SESSION_LOG_SCHEMA;
|
|
5
|
+
v: number;
|
|
6
|
+
};
|
|
7
|
+
export type Ext = Record<string, {
|
|
8
|
+
version: string;
|
|
9
|
+
native_id?: string;
|
|
10
|
+
data?: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
export type Producer = {
|
|
13
|
+
harness: string;
|
|
14
|
+
harness_version: string;
|
|
15
|
+
adapter_version: string;
|
|
16
|
+
};
|
|
17
|
+
export type ModelRef = {
|
|
18
|
+
provider: string;
|
|
19
|
+
model: string;
|
|
20
|
+
api?: 'anthropic-messages' | 'openai-chat' | 'openai-responses' | (string & {});
|
|
21
|
+
variant?: string;
|
|
22
|
+
reasoning_effort?: string;
|
|
23
|
+
};
|
|
24
|
+
export type Todo = {
|
|
25
|
+
id?: string;
|
|
26
|
+
content: string;
|
|
27
|
+
status: 'pending' | 'in_progress' | 'completed' | 'cancelled';
|
|
28
|
+
priority?: 'high' | 'medium' | 'low';
|
|
29
|
+
};
|
|
30
|
+
export type Pending = {
|
|
31
|
+
id: string;
|
|
32
|
+
thread_id: string;
|
|
33
|
+
call_id?: string;
|
|
34
|
+
payload: unknown;
|
|
35
|
+
asked_at: string;
|
|
36
|
+
};
|
|
37
|
+
export type RestoreGrade = 'native' | 'converted' | 'partial';
|
|
38
|
+
export type GradeCounts = {
|
|
39
|
+
tool_input: number;
|
|
40
|
+
cut_point: number;
|
|
41
|
+
attachment: number;
|
|
42
|
+
};
|
|
43
|
+
export type SessionLog = SchemaRef & {
|
|
44
|
+
session_id: string;
|
|
45
|
+
title: string | null;
|
|
46
|
+
created_at: string;
|
|
47
|
+
restore_grade: RestoreGrade;
|
|
48
|
+
grade_counts?: GradeCounts;
|
|
49
|
+
harness: {
|
|
50
|
+
current: string;
|
|
51
|
+
history: Array<{
|
|
52
|
+
harness: string;
|
|
53
|
+
version: string;
|
|
54
|
+
from_seq: number;
|
|
55
|
+
at: string;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
selection: {
|
|
59
|
+
agent: string | null;
|
|
60
|
+
model: ModelRef | null;
|
|
61
|
+
};
|
|
62
|
+
todos: Todo[];
|
|
63
|
+
pending: {
|
|
64
|
+
questions: Pending[];
|
|
65
|
+
permissions: Pending[];
|
|
66
|
+
};
|
|
67
|
+
threads: SessionLogThread[];
|
|
68
|
+
ext?: Ext;
|
|
69
|
+
};
|
|
70
|
+
export type ThreadInteraction = {
|
|
71
|
+
message_id: string;
|
|
72
|
+
call_id: string;
|
|
73
|
+
op: 'spawn' | 'send' | 'wait' | 'close' | 'resume' | 'result';
|
|
74
|
+
};
|
|
75
|
+
export type SessionLogThread = SchemaRef & {
|
|
76
|
+
thread_id: string;
|
|
77
|
+
parent_thread_id: string | null;
|
|
78
|
+
spawned_by: {
|
|
79
|
+
message_id: string;
|
|
80
|
+
call_id: string;
|
|
81
|
+
} | null;
|
|
82
|
+
interactions?: ThreadInteraction[];
|
|
83
|
+
agent: string | null;
|
|
84
|
+
native_agent_id?: string;
|
|
85
|
+
nickname?: string | null;
|
|
86
|
+
title: string | null;
|
|
87
|
+
created_at: string;
|
|
88
|
+
messages: SessionLogMessage[];
|
|
89
|
+
ext?: Ext;
|
|
90
|
+
};
|
|
91
|
+
export type Role = 'user' | 'assistant' | 'system';
|
|
92
|
+
export type SessionLogMessage = SchemaRef & {
|
|
93
|
+
message_id: string;
|
|
94
|
+
thread_id: string;
|
|
95
|
+
seq: number;
|
|
96
|
+
role: Role;
|
|
97
|
+
kind: 'turn' | 'compaction' | 'context';
|
|
98
|
+
status: 'streaming' | 'complete' | 'error' | 'aborted' | 'interrupted';
|
|
99
|
+
in_context: boolean;
|
|
100
|
+
hidden_reason?: 'failed_attempt' | 'aborted' | 'retracted' | 'reverted' | 'superseded';
|
|
101
|
+
origin?: 'prompt' | 'steer' | 'command' | 'automation' | 'subagent' | 'notification';
|
|
102
|
+
agent?: string | null;
|
|
103
|
+
native_agent_id?: string;
|
|
104
|
+
reply_to?: string | null;
|
|
105
|
+
parent_message_id?: string | null;
|
|
106
|
+
model: ModelRef | null;
|
|
107
|
+
usage: Usage | null;
|
|
108
|
+
finish: 'stop' | 'tool_calls' | 'length' | 'error' | 'aborted' | null;
|
|
109
|
+
error: {
|
|
110
|
+
code: string;
|
|
111
|
+
message: string;
|
|
112
|
+
} | null;
|
|
113
|
+
created_at: string;
|
|
114
|
+
completed_at: string | null;
|
|
115
|
+
producer: Producer;
|
|
116
|
+
blocks: SessionLogBlock[];
|
|
117
|
+
context_ref?: string;
|
|
118
|
+
ext?: Ext;
|
|
119
|
+
};
|
|
120
|
+
export type Usage = {
|
|
121
|
+
input: number;
|
|
122
|
+
output: number;
|
|
123
|
+
cache_read: number;
|
|
124
|
+
cache_write: number;
|
|
125
|
+
reasoning?: number;
|
|
126
|
+
cost?: number;
|
|
127
|
+
};
|
|
128
|
+
export type BlockBase = {
|
|
129
|
+
id: string;
|
|
130
|
+
};
|
|
131
|
+
export type SessionLogBlock = TextBlock | ReasoningBlock | AttachmentBlock | ToolCallBlock | CompactionBlock | SubtaskBlock | StepBlock | HarnessBlock;
|
|
132
|
+
export type TextBlock = BlockBase & {
|
|
133
|
+
type: 'text';
|
|
134
|
+
text: string;
|
|
135
|
+
model_text?: string;
|
|
136
|
+
synthetic?: boolean;
|
|
137
|
+
ref?: string;
|
|
138
|
+
bytes?: number;
|
|
139
|
+
ext?: Ext;
|
|
140
|
+
};
|
|
141
|
+
export type ReasoningBlock = BlockBase & {
|
|
142
|
+
type: 'reasoning';
|
|
143
|
+
text: string;
|
|
144
|
+
summary?: string[];
|
|
145
|
+
redacted?: boolean;
|
|
146
|
+
ext?: Ext;
|
|
147
|
+
};
|
|
148
|
+
export type AttachmentBlock = BlockBase & {
|
|
149
|
+
type: 'attachment';
|
|
150
|
+
ref?: string;
|
|
151
|
+
mime: string;
|
|
152
|
+
name?: string;
|
|
153
|
+
label?: string;
|
|
154
|
+
source_path?: string;
|
|
155
|
+
bytes?: number;
|
|
156
|
+
sha256?: string;
|
|
157
|
+
url?: string;
|
|
158
|
+
ext?: Ext;
|
|
159
|
+
};
|
|
160
|
+
export declare const KNOWN_TOOL_KINDS: readonly ["shell", "read", "write", "edit", "patch", "list", "glob", "grep", "web_fetch", "web_search", "todo", "task", "question", "plan", "mcp", "other"];
|
|
161
|
+
export type KnownToolKind = (typeof KNOWN_TOOL_KINDS)[number];
|
|
162
|
+
export type ToolKind = KnownToolKind | (string & {});
|
|
163
|
+
export type ToolResultContent = {
|
|
164
|
+
type: 'text';
|
|
165
|
+
text: string;
|
|
166
|
+
ref?: string;
|
|
167
|
+
bytes?: number;
|
|
168
|
+
} | {
|
|
169
|
+
type: 'attachment';
|
|
170
|
+
ref?: string;
|
|
171
|
+
mime: string;
|
|
172
|
+
sha256?: string;
|
|
173
|
+
url?: string;
|
|
174
|
+
};
|
|
175
|
+
export type ToolCallBlock = BlockBase & {
|
|
176
|
+
type: 'tool_call';
|
|
177
|
+
call_id: string;
|
|
178
|
+
name: string;
|
|
179
|
+
kind: ToolKind;
|
|
180
|
+
input: unknown;
|
|
181
|
+
input_format?: 'json' | 'text';
|
|
182
|
+
status: 'pending' | 'running' | 'complete' | 'error';
|
|
183
|
+
result?: {
|
|
184
|
+
content: ToolResultContent[];
|
|
185
|
+
model_content?: ToolResultContent[];
|
|
186
|
+
is_error: boolean;
|
|
187
|
+
error?: {
|
|
188
|
+
code?: string;
|
|
189
|
+
message: string;
|
|
190
|
+
};
|
|
191
|
+
exit_code?: number;
|
|
192
|
+
synthetic?: boolean;
|
|
193
|
+
cleared_at?: string;
|
|
194
|
+
details?: unknown;
|
|
195
|
+
};
|
|
196
|
+
title?: string;
|
|
197
|
+
started_at?: string;
|
|
198
|
+
ended_at?: string;
|
|
199
|
+
ext?: Ext;
|
|
200
|
+
};
|
|
201
|
+
export type CompactionLayoutEntry = {
|
|
202
|
+
summary: true;
|
|
203
|
+
} | {
|
|
204
|
+
message_id: string;
|
|
205
|
+
text_only?: boolean;
|
|
206
|
+
} | {
|
|
207
|
+
text: string;
|
|
208
|
+
};
|
|
209
|
+
export type CompactionBlock = BlockBase & {
|
|
210
|
+
type: 'compaction';
|
|
211
|
+
summary: string | null;
|
|
212
|
+
opaque?: boolean;
|
|
213
|
+
first_kept_message_id: string | null;
|
|
214
|
+
layout?: CompactionLayoutEntry[];
|
|
215
|
+
tokens_before?: number;
|
|
216
|
+
trigger?: 'auto' | 'manual' | 'overflow' | 'unknown';
|
|
217
|
+
ext?: Ext;
|
|
218
|
+
};
|
|
219
|
+
export type SubtaskBlock = BlockBase & {
|
|
220
|
+
type: 'subtask';
|
|
221
|
+
thread_id: string;
|
|
222
|
+
agent: string;
|
|
223
|
+
description: string;
|
|
224
|
+
call_id?: string;
|
|
225
|
+
call_ids?: string[];
|
|
226
|
+
};
|
|
227
|
+
export type StepBlock = BlockBase & {
|
|
228
|
+
type: 'step';
|
|
229
|
+
phase: 'start' | 'finish';
|
|
230
|
+
ext?: Ext;
|
|
231
|
+
};
|
|
232
|
+
export type HarnessBlock = BlockBase & {
|
|
233
|
+
type: 'harness';
|
|
234
|
+
harness: string;
|
|
235
|
+
kind: string;
|
|
236
|
+
data: unknown;
|
|
237
|
+
model_visible: boolean;
|
|
238
|
+
fallback_text?: string;
|
|
239
|
+
};
|
|
240
|
+
export type CapabilityFeatures = {
|
|
241
|
+
tool_error_channel: boolean;
|
|
242
|
+
attachments: {
|
|
243
|
+
user: string[];
|
|
244
|
+
tool_result: boolean;
|
|
245
|
+
};
|
|
246
|
+
compaction: Array<'summary_first_tail' | 'layout' | 'text_tail' | 'opaque'>;
|
|
247
|
+
subagents: 'none' | 'sync' | 'async';
|
|
248
|
+
todos: boolean;
|
|
249
|
+
reasoning_replay: 'none' | 'same_model' | 'lowers_to_text';
|
|
250
|
+
freeform_tool_input: boolean;
|
|
251
|
+
};
|
|
252
|
+
export type AdapterCapabilities = {
|
|
253
|
+
harness: string;
|
|
254
|
+
harness_versions: string;
|
|
255
|
+
schema_minors: number[];
|
|
256
|
+
dialects: Array<NonNullable<ModelRef['api']>>;
|
|
257
|
+
native: CapabilityFeatures;
|
|
258
|
+
rendered: CapabilityFeatures;
|
|
259
|
+
};
|
|
260
|
+
export type ExportCursor = {
|
|
261
|
+
thread_id: string;
|
|
262
|
+
last_seq: number;
|
|
263
|
+
native_hashes: Record<string, string>;
|
|
264
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const SESSION_LOG_SCHEMA = 'beeuni.session/2';
|
|
2
|
+
export const SESSION_LOG_MINOR = 1;
|
|
3
|
+
export const KNOWN_TOOL_KINDS = [
|
|
4
|
+
'shell', 'read', 'write', 'edit', 'patch', 'list', 'glob', 'grep',
|
|
5
|
+
'web_fetch', 'web_search', 'todo', 'task', 'question', 'plan', 'mcp', 'other',
|
|
6
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Message, Part } from '../runtime/runtime-types.js';
|
|
2
|
+
import type { SessionLogState, SessionLogThreadHead } from './store.js';
|
|
3
|
+
import { type SessionLog } from './types.js';
|
|
4
|
+
export interface V1MessageRow {
|
|
5
|
+
info: Message;
|
|
6
|
+
parts: Part[];
|
|
7
|
+
}
|
|
8
|
+
export declare const isV1Thread: (head: SessionLogThreadHead | undefined) => boolean;
|
|
9
|
+
export declare function sessionLogRowsFor<R extends V1MessageRow>(logs: Record<string, SessionLogState>, runtimeSessionId: string, v1Rows: R[]): R[];
|
|
10
|
+
export declare function sessionLogOfV1Rows(sessionId: string, runtimeSessionId: string, rows: readonly V1MessageRow[]): SessionLog;
|