@beeos-ai/bma-dsh-adapter 0.2.1 → 0.3.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/lib/adapter.d.ts +14 -0
- package/lib/adapter.js +70 -8
- package/lib/catalog-gate.d.ts +2 -0
- package/lib/catalog-gate.js +20 -17
- package/lib/index.d.ts +1 -0
- package/lib/input-skills.d.ts +22 -0
- package/lib/input-skills.js +23 -0
- package/lib/model.js +6 -2
- package/lib/spi.d.ts +24 -0
- package/lib/spi.js +5 -9
- package/lib/system-prompt.js +5 -1
- package/lib/testing/scripted-model.d.ts +6 -0
- package/lib/testing/scripted-model.js +6 -1
- package/package.json +1 -1
package/lib/adapter.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Context } from "@deepseek-ai/cordis";
|
|
2
2
|
import { type HarnessAdapter, type HarnessCapabilities, type HarnessEvent, type HarnessInput, type ModelPort, type PlatformTool, type SessionInit } from "./spi.ts";
|
|
3
|
+
import { type InputSkillDocument, type InputSkillReceipt } from "./input-skills.ts";
|
|
3
4
|
export interface DshAdapterOptions {
|
|
4
5
|
home: string;
|
|
5
6
|
/** Concurrent read-only tool calls per step (dsh agent-loop); omitted = dsh's own default. */
|
|
@@ -28,7 +29,20 @@ export declare class DshAdapter implements HarnessAdapter {
|
|
|
28
29
|
resumeSession(init: SessionInit): Promise<void>;
|
|
29
30
|
private open;
|
|
30
31
|
private get;
|
|
32
|
+
/**
|
|
33
|
+
* The session's host tools from now on (AgentTurnConfig.host_tools of the
|
|
34
|
+
* turn about to run), next to the registered platform tools: the previous
|
|
35
|
+
* set is unregistered first. Not while an input runs.
|
|
36
|
+
*/
|
|
37
|
+
setHostTools(sessionId: string, tools: readonly PlatformTool[]): void;
|
|
31
38
|
toolCatalog(sessionId: string): readonly string[];
|
|
39
|
+
/** Installs exact turn-only context before returning its executor receipt.
|
|
40
|
+
* The host must bind this to the accepted opening input and durable turn config.
|
|
41
|
+
* No public capability is advertised until that contract is wired end to end.
|
|
42
|
+
*/
|
|
43
|
+
prepareInputSkills(sessionId: string, inputId: string, documents: readonly InputSkillDocument[]): InputSkillReceipt;
|
|
44
|
+
/** Cancelled accepted work may never enter submitInput. Release only its idle preparation. */
|
|
45
|
+
clearPreparedInputSkills(sessionId: string, inputId: string): void;
|
|
32
46
|
submitInput(sessionId: string, input: HarnessInput, signal: AbortSignal): AsyncIterable<HarnessEvent>;
|
|
33
47
|
/** Text-only input only: the host queues an input with images as the next turn instead. */
|
|
34
48
|
appendInput(sessionId: string, input: HarnessInput): void;
|
package/lib/adapter.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MessageId, freezeMessage } from "@deepseek-ai/dsh-llm";
|
|
2
2
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
3
3
|
import {} from "./spi.js";
|
|
4
|
+
import { prepareInputSkills } from "./input-skills.js";
|
|
4
5
|
import { AsyncQueue } from "./async-queue.js";
|
|
5
|
-
import { restrictToPlatformTools } from "./catalog-gate.js";
|
|
6
|
+
import { registerPlatformTool, restrictToPlatformTools } from "./catalog-gate.js";
|
|
6
7
|
import { requestMaxTokens } from "./model-catalog.js";
|
|
7
8
|
import { harnessEventFromStreamFrame, harnessEventsFromSessionEvent } from "./events.js";
|
|
8
9
|
import { CONTINUE_NOTE, assertResumable, continuationId, hasRecordedInput } from "./recovery.js";
|
|
@@ -66,10 +67,11 @@ export class DshAdapter {
|
|
|
66
67
|
if (this.sessions.has(init.sessionId))
|
|
67
68
|
throw new Error(`session ${init.sessionId} is already open`);
|
|
68
69
|
const sessionId = SessionId(init.sessionId);
|
|
69
|
-
const state = { init };
|
|
70
|
+
const state = { init, hostTools: { tools: [], dispose: [] } };
|
|
70
71
|
const setup = (scope) => {
|
|
71
|
-
scope
|
|
72
|
-
|
|
72
|
+
state.scope = scope;
|
|
73
|
+
scope.systemPrompt.section({ name: "bma", order: 0, complete: true, interpolate: false, text: () => state.init.systemPrompt + (state.inputSkills?.system ?? "") });
|
|
74
|
+
restrictToPlatformTools(scope, init.sessionId, [...this.tools, ...(init.sessionTools ?? [])], (callId, images) => this.toolImages.remember(init.sessionId, callId, images));
|
|
73
75
|
scope.on("session/event", (session, event) => {
|
|
74
76
|
if (session.id === sessionId)
|
|
75
77
|
this.onSessionEvent(state, event);
|
|
@@ -88,26 +90,83 @@ export class DshAdapter {
|
|
|
88
90
|
throw new Error(`session ${sessionId} is not open`);
|
|
89
91
|
return state;
|
|
90
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The session's host tools from now on (AgentTurnConfig.host_tools of the
|
|
95
|
+
* turn about to run), next to the registered platform tools: the previous
|
|
96
|
+
* set is unregistered first. Not while an input runs.
|
|
97
|
+
*/
|
|
98
|
+
setHostTools(sessionId, tools) {
|
|
99
|
+
const state = this.get(sessionId);
|
|
100
|
+
if (state.sink)
|
|
101
|
+
throw new Error("cannot change host tools during an active input");
|
|
102
|
+
for (const dispose of state.hostTools.dispose)
|
|
103
|
+
dispose();
|
|
104
|
+
state.hostTools = {
|
|
105
|
+
tools,
|
|
106
|
+
dispose: tools.map((tool) => registerPlatformTool(state.scope, sessionId, tool, (callId, images) => this.toolImages.remember(sessionId, callId, images))),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
91
109
|
toolCatalog(sessionId) {
|
|
92
110
|
return this.ctx.tools.schemas(this.get(sessionId).handle.agent).map((s) => s.name);
|
|
93
111
|
}
|
|
112
|
+
/** Installs exact turn-only context before returning its executor receipt.
|
|
113
|
+
* The host must bind this to the accepted opening input and durable turn config.
|
|
114
|
+
* No public capability is advertised until that contract is wired end to end.
|
|
115
|
+
*/
|
|
116
|
+
prepareInputSkills(sessionId, inputId, documents) {
|
|
117
|
+
const state = this.get(sessionId);
|
|
118
|
+
if (state.sink)
|
|
119
|
+
throw new Error("cannot change selected skills during an active input");
|
|
120
|
+
const candidate = prepareInputSkills(inputId, documents);
|
|
121
|
+
if (state.inputSkills && JSON.stringify(state.inputSkills.receipt) !== JSON.stringify(candidate.receipt)) {
|
|
122
|
+
throw new Error("another input skill context is already installed");
|
|
123
|
+
}
|
|
124
|
+
if (state.inputSkills)
|
|
125
|
+
return state.inputSkills.receipt;
|
|
126
|
+
state.inputSkills = candidate;
|
|
127
|
+
return candidate.receipt;
|
|
128
|
+
}
|
|
129
|
+
/** Cancelled accepted work may never enter submitInput. Release only its idle preparation. */
|
|
130
|
+
clearPreparedInputSkills(sessionId, inputId) {
|
|
131
|
+
const state = this.get(sessionId);
|
|
132
|
+
if (state.sink)
|
|
133
|
+
throw new Error("cannot clear selected skills while input is active");
|
|
134
|
+
if (state.inputSkills?.receipt.input_id === inputId)
|
|
135
|
+
state.inputSkills = undefined;
|
|
136
|
+
}
|
|
94
137
|
async *submitInput(sessionId, input, signal) {
|
|
95
138
|
const state = this.get(sessionId);
|
|
139
|
+
if (state.sink)
|
|
140
|
+
throw new Error("session already has an active input");
|
|
141
|
+
if (state.inputSkills && state.inputSkills.receipt.input_id !== (input.bindingInputId ?? input.id))
|
|
142
|
+
throw new Error("selected skills belong to another input");
|
|
96
143
|
const agent = state.handle.agent;
|
|
97
144
|
const queue = new AsyncQueue();
|
|
98
145
|
state.sink = (e) => queue.push(e);
|
|
99
146
|
const onAbort = () => agent.cancel({ kind: "user" });
|
|
100
147
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
101
148
|
const from = agent.session.snapshotEvents().length;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const idle = agent.whenIdle().then(() => queue.end(), (err) => queue.fail(err));
|
|
149
|
+
let idle;
|
|
150
|
+
let settled = false;
|
|
105
151
|
try {
|
|
152
|
+
signal.throwIfAborted();
|
|
153
|
+
const seen = hasRecordedInput(agent.session.snapshotEvents(), input.id);
|
|
154
|
+
const content = seen ? [{ type: "text", text: CONTINUE_NOTE }] : await this.content(input);
|
|
155
|
+
signal.throwIfAborted();
|
|
156
|
+
agent.followup(userMessage(seen ? continuationId(input.id) : input.id, content));
|
|
157
|
+
idle = agent.whenIdle().then(() => { settled = true; queue.end(); }, (err) => { settled = true; queue.fail(err); });
|
|
106
158
|
yield* queue;
|
|
107
159
|
await idle;
|
|
108
160
|
}
|
|
109
161
|
finally {
|
|
162
|
+
// A consumer may stop iterating before the agent is idle. Retain the
|
|
163
|
+
// context and exclusion until cancellation has actually settled.
|
|
164
|
+
if (idle && !settled) {
|
|
165
|
+
agent.cancel({ kind: "user" });
|
|
166
|
+
await idle;
|
|
167
|
+
}
|
|
110
168
|
state.sink = undefined;
|
|
169
|
+
state.inputSkills = undefined;
|
|
111
170
|
signal.removeEventListener("abort", onAbort);
|
|
112
171
|
}
|
|
113
172
|
if (signal.aborted)
|
|
@@ -125,7 +184,10 @@ export class DshAdapter {
|
|
|
125
184
|
appendInput(sessionId, input) {
|
|
126
185
|
if (input.images?.length)
|
|
127
186
|
throw new Error("appendInput does not take images");
|
|
128
|
-
this.get(sessionId)
|
|
187
|
+
const state = this.get(sessionId);
|
|
188
|
+
if (state.inputSkills)
|
|
189
|
+
throw new Error("cannot append another input to a selected-skill turn");
|
|
190
|
+
state.handle.agent.followup(userMessage(input.id, [{ type: "text", text: input.text }]));
|
|
129
191
|
}
|
|
130
192
|
/**
|
|
131
193
|
* Whether this build can take image input: the attachment service decodes
|
package/lib/catalog-gate.d.ts
CHANGED
|
@@ -3,5 +3,7 @@ import type { InputImage, PlatformTool } from "./spi.ts";
|
|
|
3
3
|
/** Receives the images of a tool result (they are not part of the stored result; see model.ts). */
|
|
4
4
|
export type ToolImageSink = (callId: string, images: readonly InputImage[]) => void;
|
|
5
5
|
export declare function restrictToPlatformTools(scope: Context, sessionId: string, tools: readonly PlatformTool[], onImages?: ToolImageSink): void;
|
|
6
|
+
/** Registers one platform tool into the agent scope; returns its disposer. */
|
|
7
|
+
export declare function registerPlatformTool(scope: Context, sessionId: string, tool: PlatformTool, onImages?: ToolImageSink): () => void;
|
|
6
8
|
/** Why a session must be refused, or undefined when the catalog is exactly the expected tools. */
|
|
7
9
|
export declare function catalogViolation(harnessId: string, expected: readonly string[], actual: readonly string[]): string | undefined;
|
package/lib/catalog-gate.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
export function restrictToPlatformTools(scope, sessionId, tools, onImages) {
|
|
2
2
|
scope.tools.restrict({ allow: [] });
|
|
3
|
-
for (const tool of tools)
|
|
4
|
-
scope
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
for (const tool of tools)
|
|
4
|
+
registerPlatformTool(scope, sessionId, tool, onImages);
|
|
5
|
+
}
|
|
6
|
+
/** Registers one platform tool into the agent scope; returns its disposer. */
|
|
7
|
+
export function registerPlatformTool(scope, sessionId, tool, onImages) {
|
|
8
|
+
return scope.tools.register({
|
|
9
|
+
name: tool.name,
|
|
10
|
+
description: tool.description,
|
|
11
|
+
parameters: tool.parameters,
|
|
12
|
+
output: { schema: { type: "string" }, render: (_args, value) => [{ type: "text", text: String(value) }] },
|
|
13
|
+
isConcurrencySafe: () => tool.readOnly,
|
|
14
|
+
execute: async (args, exec) => {
|
|
15
|
+
const result = await tool.invoke({ sessionId, callId: exec.callId, input: (args ?? {}), signal: exec.signal });
|
|
16
|
+
if (result.isError)
|
|
17
|
+
throw new Error(result.text);
|
|
18
|
+
if (result.images?.length)
|
|
19
|
+
onImages?.(exec.callId, result.images);
|
|
20
|
+
return result.text;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
20
23
|
}
|
|
21
24
|
/** Why a session must be refused, or undefined when the catalog is exactly the expected tools. */
|
|
22
25
|
export function catalogViolation(harnessId, expected, actual) {
|
package/lib/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export { CONTINUE_NOTE, assertResumable, hasRecordedInput, continuationId } from
|
|
|
10
10
|
export { stopForTurnEnd, agentErrorCode, AGENT_ERROR_CODES, type AgentErrorCode, type DshTurnEndReason } from "./stop.ts";
|
|
11
11
|
export { BASE_SYSTEM_PROMPT, composeSystemPrompt } from "./system-prompt.ts";
|
|
12
12
|
export { DSH_VERSION } from "./version.ts";
|
|
13
|
+
export type { InputSkillDocument, InputSkillReceipt } from "./input-skills.ts";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Resolved by the platform under current grant and session-frozen revision checks. */
|
|
2
|
+
export interface InputSkillDocument {
|
|
3
|
+
readonly skill_id: string;
|
|
4
|
+
readonly revision_id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly body: string;
|
|
7
|
+
readonly body_sha256: string;
|
|
8
|
+
}
|
|
9
|
+
export interface InputSkillReceipt {
|
|
10
|
+
readonly input_id: string;
|
|
11
|
+
readonly skills: readonly {
|
|
12
|
+
readonly skill_id: string;
|
|
13
|
+
readonly revision_id: string;
|
|
14
|
+
readonly body_sha256: string;
|
|
15
|
+
}[];
|
|
16
|
+
}
|
|
17
|
+
export interface PreparedInputSkills {
|
|
18
|
+
readonly receipt: InputSkillReceipt;
|
|
19
|
+
readonly system: string;
|
|
20
|
+
}
|
|
21
|
+
/** Verify bytes again at the executor boundary; never acknowledge archive hashes. */
|
|
22
|
+
export declare function prepareInputSkills(inputId: string, documents: readonly InputSkillDocument[]): PreparedInputSkills;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/** Verify bytes again at the executor boundary; never acknowledge archive hashes. */
|
|
3
|
+
export function prepareInputSkills(inputId, documents) {
|
|
4
|
+
if (!inputId || documents.length < 1 || documents.length > 10)
|
|
5
|
+
throw new Error('invalid input skill selection');
|
|
6
|
+
const seen = new Set();
|
|
7
|
+
let total = 0;
|
|
8
|
+
const copies = documents.map(doc => {
|
|
9
|
+
if (!doc || !/^skl_[a-zA-Z0-9_-]{1,124}$/.test(doc.skill_id) || !/^skr_[a-zA-Z0-9_-]{1,124}$/.test(doc.revision_id)
|
|
10
|
+
|| seen.has(doc.skill_id) || typeof doc.name !== 'string' || !doc.name.trim() || Buffer.byteLength(doc.name) > 255
|
|
11
|
+
|| typeof doc.body !== 'string' || !doc.body.trim() || Buffer.byteLength(doc.body) > 65_536
|
|
12
|
+
|| createHash('sha256').update(doc.body, 'utf8').digest('hex') !== doc.body_sha256) {
|
|
13
|
+
throw new Error('selected skill bytes do not match the admitted version');
|
|
14
|
+
}
|
|
15
|
+
total += Buffer.byteLength(doc.body);
|
|
16
|
+
if (total > 262_144)
|
|
17
|
+
throw new Error('selected skill context is too large');
|
|
18
|
+
seen.add(doc.skill_id);
|
|
19
|
+
return { skill_id: doc.skill_id, revision_id: doc.revision_id, name: doc.name, body: doc.body, body_sha256: doc.body_sha256 };
|
|
20
|
+
});
|
|
21
|
+
const receipt = Object.freeze({ input_id: inputId, skills: Object.freeze(copies.map(({ skill_id, revision_id, body_sha256 }) => Object.freeze({ skill_id, revision_id, body_sha256 }))) });
|
|
22
|
+
return Object.freeze({ receipt, system: '\n\nSkills explicitly selected for this input only:\n' + JSON.stringify(copies) });
|
|
23
|
+
}
|
package/lib/model.js
CHANGED
|
@@ -196,6 +196,7 @@ export class ChatCompletionsAdapter extends LlmAdapter {
|
|
|
196
196
|
messages,
|
|
197
197
|
...(request.tools?.length ? { tools: request.tools.map((t) => ({ type: "function", function: { name: t.name, description: t.description, parameters: t.parameters } })) } : {}),
|
|
198
198
|
max_tokens: maxTokens,
|
|
199
|
+
...(route.reasoningEffort ? { reasoning_effort: route.reasoningEffort } : {}),
|
|
199
200
|
...(request.temperature !== undefined ? { temperature: request.temperature } : {}),
|
|
200
201
|
...(request.stop?.length ? { stop: request.stop } : {}),
|
|
201
202
|
}),
|
|
@@ -235,12 +236,15 @@ export class ChatCompletionsAdapter extends LlmAdapter {
|
|
|
235
236
|
throw new LlmError(`model stream error: ${JSON.stringify(json.error).slice(0, 300)}`, "PROVIDER_STREAM");
|
|
236
237
|
if (json.usage) {
|
|
237
238
|
// dsh requires losslessly JSON-serializable chunks: no undefined members.
|
|
239
|
+
// OpenAI prompt_tokens include the cached reads; dsh counts input and cache reads apart
|
|
240
|
+
// (its context pressure is input + cacheRead + cacheWrite), so input is the uncached part.
|
|
238
241
|
const u = json.usage;
|
|
242
|
+
const cached = u.prompt_tokens_details?.cached_tokens;
|
|
239
243
|
usage = {
|
|
240
|
-
inputTokens: u.prompt_tokens ?? 0,
|
|
244
|
+
inputTokens: Math.max(0, (u.prompt_tokens ?? 0) - (cached ?? 0)),
|
|
241
245
|
outputTokens: u.completion_tokens ?? 0,
|
|
242
246
|
...(u.total_tokens !== undefined ? { totalTokens: u.total_tokens } : {}),
|
|
243
|
-
...(
|
|
247
|
+
...(cached !== undefined ? { cacheReadTokens: cached } : {}),
|
|
244
248
|
...(u.completion_tokens_details?.reasoning_tokens !== undefined ? { reasoningTokens: u.completion_tokens_details.reasoning_tokens } : {}),
|
|
245
249
|
};
|
|
246
250
|
}
|
package/lib/spi.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InputSkillDocument, InputSkillReceipt } from "./input-skills.ts";
|
|
1
2
|
/** The six official agent_toolset tools a server-side brain may call (ADR 0005). */
|
|
2
3
|
export type ToolName = "bash" | "read" | "write" | "edit" | "glob" | "grep";
|
|
3
4
|
/** One model tool call handed to the platform. */
|
|
@@ -38,7 +39,18 @@ export interface ModelRoute {
|
|
|
38
39
|
/** Session-scoped bearer token; the platform attributes every request carrying it to the session. */
|
|
39
40
|
readonly token: string;
|
|
40
41
|
readonly model: string;
|
|
42
|
+
/**
|
|
43
|
+
* Sent as the Chat Completions `reasoning_effort` (one of REASONING_EFFORTS); omitted: the
|
|
44
|
+
* model's own default. The host checks that the model takes the level; the adapter passes it as is.
|
|
45
|
+
*/
|
|
46
|
+
readonly reasoningEffort?: ReasoningEffort;
|
|
41
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Reasoning effort levels, the union of OpenAI's `reasoning_effort` (none, minimal, low, medium,
|
|
50
|
+
* high, xhigh, max) and Claude Code's effort levels (low, medium, high, xhigh, max), lowest first.
|
|
51
|
+
*/
|
|
52
|
+
export declare const REASONING_EFFORTS: readonly ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
53
|
+
export type ReasoningEffort = (typeof REASONING_EFFORTS)[number];
|
|
42
54
|
export interface ModelUsage {
|
|
43
55
|
readonly inputTokens: number;
|
|
44
56
|
readonly outputTokens: number;
|
|
@@ -88,6 +100,8 @@ export interface SessionInit {
|
|
|
88
100
|
readonly systemPrompt: string;
|
|
89
101
|
/** Working directory on the session's machine, for the prompt only (tools run on the machine). */
|
|
90
102
|
readonly cwd: string;
|
|
103
|
+
/** Tools of this session only, next to the registered platform tools (the agent's custom tools). */
|
|
104
|
+
readonly sessionTools?: readonly PlatformTool[];
|
|
91
105
|
}
|
|
92
106
|
/** One image of a user input, already fetched by the host. */
|
|
93
107
|
export interface InputImage {
|
|
@@ -100,6 +114,8 @@ export interface HarnessInput {
|
|
|
100
114
|
/** Platform input id, or a host-made id for a recovery note. */
|
|
101
115
|
readonly id: string;
|
|
102
116
|
readonly text: string;
|
|
117
|
+
/** Host recovery can use a new transcript message while retaining its admitted opening-input binding. */
|
|
118
|
+
readonly bindingInputId?: string;
|
|
103
119
|
/** Images the model sees with the text; only when capabilities().imageInput. */
|
|
104
120
|
readonly images?: readonly InputImage[];
|
|
105
121
|
}
|
|
@@ -158,6 +174,12 @@ export interface HarnessAdapter {
|
|
|
158
174
|
createSession(init: SessionInit): Promise<void>;
|
|
159
175
|
/** Loads a session this or an earlier process created (capabilities().resume). */
|
|
160
176
|
resumeSession(init: SessionInit): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Replaces the session's host tools (AgentTurnConfig.host_tools of the next
|
|
179
|
+
* turn; empty: none) next to the registered tools. Only an adapter that
|
|
180
|
+
* offers it takes a turn with host tools.
|
|
181
|
+
*/
|
|
182
|
+
setHostTools?(sessionId: string, tools: readonly PlatformTool[]): void;
|
|
161
183
|
/** The tool names the model will see in this session. */
|
|
162
184
|
toolCatalog(sessionId: string): readonly string[];
|
|
163
185
|
/**
|
|
@@ -168,6 +190,8 @@ export interface HarnessAdapter {
|
|
|
168
190
|
* input the harness already recorded; the harness then continues that
|
|
169
191
|
* input instead of adding it twice.
|
|
170
192
|
*/
|
|
193
|
+
prepareInputSkills?(sessionId: string, inputId: string, documents: readonly InputSkillDocument[]): InputSkillReceipt;
|
|
194
|
+
clearPreparedInputSkills?(sessionId: string, inputId: string): void;
|
|
171
195
|
submitInput(sessionId: string, input: HarnessInput, signal: AbortSignal): AsyncIterable<HarnessEvent>;
|
|
172
196
|
/** Adds input to the running turn; only when capabilities().midTurnInput. */
|
|
173
197
|
appendInput(sessionId: string, input: HarnessInput): void;
|
package/lib/spi.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// only through these interfaces.
|
|
7
|
-
//
|
|
8
|
-
// Shape follows duyet/oma HarnessInterface/HarnessRuntime/HarnessContext and
|
|
9
|
-
// BMA H0 driver.Harness (ADR 0001/0004).
|
|
1
|
+
/**
|
|
2
|
+
* Reasoning effort levels, the union of OpenAI's `reasoning_effort` (none, minimal, low, medium,
|
|
3
|
+
* high, xhigh, max) and Claude Code's effort levels (low, medium, high, xhigh, max), lowest first.
|
|
4
|
+
*/
|
|
5
|
+
export const REASONING_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
10
6
|
export class TurnStopError extends Error {
|
|
11
7
|
name = "TurnStopError";
|
|
12
8
|
code;
|
package/lib/system-prompt.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
// The kernel adds nothing of its own (no harness identity, no runtime context).
|
|
5
5
|
export const BASE_SYSTEM_PROMPT = [
|
|
6
6
|
"You are an agent running on BMA (BeeOS Managed Agents).",
|
|
7
|
-
"Your tools run on the session's machine; use absolute paths.
|
|
7
|
+
"Your tools run on the session's machine; use absolute paths.",
|
|
8
|
+
// Session deliverables (docs/architecture/session-deliverables.md): outputs
|
|
9
|
+
// holds only final files, and a file is delivered when the final reply names it.
|
|
10
|
+
"Keep intermediate files (extracted text, helper scripts, logs, drafts) in your home directory or /tmp, never in the session's outputs directory.",
|
|
11
|
+
"Write to the session's outputs directory (named under Session files) only the final files the user asked for, and name each one by its file name in your final reply: only the files named there are delivered to the user.",
|
|
8
12
|
"Be concise. When a task is done, say what you did.",
|
|
9
13
|
].join("\n");
|
|
10
14
|
/** Base prompt, then the agent's `system` after one blank line; no `system` (or an empty one) is the base prompt alone. */
|
|
@@ -45,6 +45,12 @@ export interface Reply {
|
|
|
45
45
|
errorText?: string;
|
|
46
46
|
/** finish_reason of a non-tool reply (default "stop"); "length" simulates a max_tokens cut. */
|
|
47
47
|
finishReason?: string;
|
|
48
|
+
/** Usage of the reply (default 11 prompt / 7 completion, no cache); cachedTokens is prompt_tokens_details.cached_tokens, part of promptTokens. */
|
|
49
|
+
usage?: {
|
|
50
|
+
promptTokens: number;
|
|
51
|
+
completionTokens: number;
|
|
52
|
+
cachedTokens?: number;
|
|
53
|
+
};
|
|
48
54
|
}
|
|
49
55
|
export type Script = (req: ModelRequest, index: number) => Reply;
|
|
50
56
|
export interface ScriptedModel {
|
|
@@ -46,7 +46,12 @@ export async function startScriptedModel(script, listen = "127.0.0.1") {
|
|
|
46
46
|
return;
|
|
47
47
|
(reply.toolCalls ?? []).forEach((c, i) => send({ tool_calls: [{ index: i, id: c.id, type: "function", function: { name: c.name, arguments: JSON.stringify(c.args) } }] }));
|
|
48
48
|
send({}, reply.toolCalls?.length && !reply.finishReason ? "tool_calls" : (reply.finishReason ?? "stop"));
|
|
49
|
-
|
|
49
|
+
const u = reply.usage ?? { promptTokens: 11, completionTokens: 7 };
|
|
50
|
+
const usage = {
|
|
51
|
+
prompt_tokens: u.promptTokens, completion_tokens: u.completionTokens, total_tokens: u.promptTokens + u.completionTokens,
|
|
52
|
+
...(u.cachedTokens !== undefined ? { prompt_tokens_details: { cached_tokens: u.cachedTokens } } : {}),
|
|
53
|
+
};
|
|
54
|
+
res.write(`data: ${JSON.stringify({ choices: [], usage })}\n\n`);
|
|
50
55
|
res.end("data: [DONE]\n\n");
|
|
51
56
|
});
|
|
52
57
|
server.on("connection", (s) => { sockets.add(s); s.on("close", () => sockets.delete(s)); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeos-ai/bma-dsh-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "BMA's shared DSH adapter: kernel assembly, platform-tools-only catalog gate, event translation, approval ids, JSONL resume, typed stop reasons, plus a conformance suite for hosts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|