@beeos-ai/bma-dsh-adapter 0.3.1 → 0.3.4
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 +21 -1
- package/lib/adapter.js +228 -27
- package/lib/context-store.d.ts +39 -0
- package/lib/context-store.js +95 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +4 -2
- package/lib/kernel.d.ts +7 -0
- package/lib/kernel.js +11 -1
- package/lib/model.d.ts +33 -0
- package/lib/model.js +143 -18
- package/lib/request-budget.d.ts +51 -0
- package/lib/request-budget.js +246 -0
- package/lib/spi.d.ts +39 -3
- package/lib/stop.js +6 -1
- package/lib/testing/tmp.js +3 -1
- package/package.json +1 -1
package/lib/spi.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CompactRequest, CompactReceipt } from "./context-store.ts";
|
|
1
2
|
import type { InputSkillDocument, InputSkillReceipt } from "./input-skills.ts";
|
|
2
3
|
/** The six official agent_toolset tools a server-side brain may call (ADR 0005). */
|
|
3
4
|
export type ToolName = "bash" | "read" | "write" | "edit" | "glob" | "grep";
|
|
@@ -34,6 +35,8 @@ export interface PlatformTool {
|
|
|
34
35
|
}
|
|
35
36
|
/** Where one session's model requests go: the platform model endpoint with a session-scoped token. */
|
|
36
37
|
export interface ModelRoute {
|
|
38
|
+
/** Maintenance requests have no executable tools; unexpected tool calls fail closed. */
|
|
39
|
+
readonly toolsDisabled?: boolean;
|
|
37
40
|
/** OpenAI-compatible base URL ending in /v1. */
|
|
38
41
|
readonly baseUrl: string;
|
|
39
42
|
/** Session-scoped bearer token; the platform attributes every request carrying it to the session. */
|
|
@@ -93,14 +96,41 @@ export interface ModelPort {
|
|
|
93
96
|
* model_transient_retry_total{result} and log it, like idleRetry.
|
|
94
97
|
*/
|
|
95
98
|
transientRetry?(sessionId: string, result: "retry" | "recovered" | "exhausted", reason?: string): void;
|
|
99
|
+
/** A step of the request size ladder (see RequestReduction); hosts count and log it. */
|
|
100
|
+
requestReduced?(sessionId: string, reduction: RequestReduction): void;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* How the adapter kept a model request inside the model window and the endpoint's body limit
|
|
104
|
+
* (dsh-adapter src/request-budget.ts). Levels: 2 older images, old tool results and long tool
|
|
105
|
+
* texts trimmed; 3 handed to dsh summary compaction; 4 oldest messages dropped (sliding window);
|
|
106
|
+
* 5 the newest user input shortened. Sizes and counts only, safe to log.
|
|
107
|
+
*/
|
|
108
|
+
export interface RequestReduction {
|
|
109
|
+
/**
|
|
110
|
+
* reduced: the request was trimmed and sent; compact: not sent, dsh compaction runs first;
|
|
111
|
+
* rejected: the endpoint refused the request for size, a smaller one follows unless exhausted
|
|
112
|
+
* comes next; exhausted: nothing fits, the turn fails.
|
|
113
|
+
*/
|
|
114
|
+
readonly step: "reduced" | "compact" | "rejected" | "exhausted";
|
|
115
|
+
readonly levels: readonly number[];
|
|
116
|
+
/** Body bytes and estimated input tokens of the request (as sent, or as it would have been). */
|
|
117
|
+
readonly bytes: number;
|
|
118
|
+
readonly tokens: number;
|
|
119
|
+
readonly byteBudget: number;
|
|
120
|
+
readonly tokenBudget: number;
|
|
121
|
+
/** HTTP status of a refusal. */
|
|
122
|
+
readonly status?: number;
|
|
96
123
|
}
|
|
97
124
|
export interface HarnessCapabilities {
|
|
98
125
|
/** Continues a session from the harness's own durable state in a fresh process. */
|
|
99
126
|
readonly resume: boolean;
|
|
100
127
|
/** Streams "delta" events before each message/thinking event. */
|
|
101
128
|
readonly deltas: boolean;
|
|
102
|
-
/**
|
|
103
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Takes user input in the running turn at its next step boundary (turn.input → appendInput; agent.steering):
|
|
131
|
+
* after the results of the current tool calls, before the next model request.
|
|
132
|
+
*/
|
|
133
|
+
readonly steering: boolean;
|
|
104
134
|
/** Passes HarnessInput.images to the model. */
|
|
105
135
|
readonly imageInput: boolean;
|
|
106
136
|
}
|
|
@@ -212,7 +242,13 @@ export interface HarnessAdapter {
|
|
|
212
242
|
prepareInputSkills?(sessionId: string, inputId: string, documents: readonly InputSkillDocument[]): InputSkillReceipt;
|
|
213
243
|
clearPreparedInputSkills?(sessionId: string, inputId: string): void;
|
|
214
244
|
submitInput(sessionId: string, input: HarnessInput, signal: AbortSignal): AsyncIterable<HarnessEvent>;
|
|
215
|
-
/**
|
|
245
|
+
/** Optional internal maintenance seam. A platform must reserve admission before calling. */
|
|
246
|
+
compact?(sessionId: string, request: CompactRequest, signal: AbortSignal): Promise<CompactReceipt>;
|
|
247
|
+
/** Readback never resumes, generates a summary or changes a selected pointer. */
|
|
248
|
+
compactReceipt?(sessionId: string, request: CompactRequest): CompactReceipt | undefined;
|
|
249
|
+
/** Atomically returns the applied receipt or fences future publication. No model call. */
|
|
250
|
+
abortCompact?(sessionId: string, request: CompactRequest): CompactReceipt | undefined;
|
|
251
|
+
/** Steers the running turn with input (read at its next step boundary); only when capabilities().steering. */
|
|
216
252
|
appendInput(sessionId: string, input: HarnessInput): void;
|
|
217
253
|
/** Durability barrier over the session's harness state (used before an approval wait). */
|
|
218
254
|
checkpoint(sessionId: string): Promise<void>;
|
package/lib/stop.js
CHANGED
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
// error, code RATE_LIMIT (429) model_rate_limited_error of a failed model request;
|
|
12
12
|
// error, code QUOTA (402) billing_error the detail is its message)
|
|
13
13
|
// error, code AUTH / PROVIDER_HTTP model_request_failed_error
|
|
14
|
+
// error, code REQUEST_TOO_LARGE model_request_failed_error (body over the endpoint limit after
|
|
15
|
+
// every reduction; the contract has
|
|
16
|
+
// no code of its own, the detail
|
|
17
|
+
// starts with request_too_large)
|
|
14
18
|
// anything else not completed agent_error: "dsh turn ended: <kind>[: <message>]"
|
|
15
19
|
//
|
|
16
20
|
// The codes are the executor contract's stop code table (contracts/bma/schemas/agent.json,
|
|
17
21
|
// $defs.AgentErrorCode); stop-contract.test.ts fails when the two drift.
|
|
18
22
|
import { CONTEXT_WINDOW_EXCEEDED_CODE, QUOTA_EXCEEDED_CODE } from "@deepseek-ai/dsh-llm";
|
|
19
23
|
import { TurnStopError } from "./spi.js";
|
|
20
|
-
import { MODEL_STREAM_IDLE } from "./model.js";
|
|
24
|
+
import { MODEL_STREAM_IDLE, REQUEST_TOO_LARGE } from "./model.js";
|
|
21
25
|
/** The stop code of a failed model request, by the class model.ts gave it. */
|
|
22
26
|
const MODEL_FAILURE_STOPS = {
|
|
23
27
|
SERVER: "model_overloaded_error",
|
|
@@ -25,6 +29,7 @@ const MODEL_FAILURE_STOPS = {
|
|
|
25
29
|
[QUOTA_EXCEEDED_CODE]: "billing_error",
|
|
26
30
|
AUTH: "model_request_failed_error",
|
|
27
31
|
PROVIDER_HTTP: "model_request_failed_error",
|
|
32
|
+
[REQUEST_TOO_LARGE]: "model_request_failed_error",
|
|
28
33
|
};
|
|
29
34
|
export function stopForTurnEnd(reason, context = {}) {
|
|
30
35
|
switch (reason.kind) {
|
package/lib/testing/tmp.js
CHANGED
|
@@ -7,7 +7,9 @@ import { tmpdir } from "node:os";
|
|
|
7
7
|
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
8
8
|
/** Name prefixes a test directory may carry; the clean script refuses any other. */
|
|
9
9
|
export const TEST_TMP_PREFIXES = ["bma-conf-", "bma-shell-", "bma-acp-"];
|
|
10
|
-
|
|
10
|
+
// One ledger per OS user: CI hosts run several runner users over one /tmp, and a ledger another user
|
|
11
|
+
// created is not appendable (EACCES), which would fail every test that makes a temp dir.
|
|
12
|
+
export const ledgerPath = () => join(tmpdir(), `bma-test-tmp-${process.getuid?.() ?? "shared"}.ledger`);
|
|
11
13
|
/** Creates a temp dir under tmpdir() and records its exact path in the ledger. */
|
|
12
14
|
export function createTestTempDir(prefix) {
|
|
13
15
|
const dir = mkdtempSync(join(tmpdir(), prefix));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beeos-ai/bma-dsh-adapter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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",
|