@workser/engine 0.1.17 → 0.1.18
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/src/dsml.d.ts +12 -0
- package/dist/src/dsml.js +44 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/model.d.ts +0 -5
- package/dist/src/model.js +18 -4
- package/dist/src/tools/workser-tool.js +10 -5
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** A whole message with its markup tags taken out (untouched, not even trimmed, when it has none). */
|
|
2
|
+
export declare function stripDsml(text: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* The same for a reply that arrives in pieces: a tag can be cut anywhere (`<`, `|DSML|`, ` calls`, `>`), so what might
|
|
5
|
+
* still become a tag is held back until the next piece says. Everything else passes at once.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DsmlFilter {
|
|
8
|
+
private held;
|
|
9
|
+
push(chunk: string): string;
|
|
10
|
+
/** The stream ended: an unfinished tag is dropped, a lone `<` (or the start of one that never came) is text. */
|
|
11
|
+
flush(): string;
|
|
12
|
+
}
|
package/dist/src/dsml.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DEEPSEEK'S OWN TOOL-CALL MARKUP, KEPT OUT OF THE OWNER'S CHAT (trace 01a1d4cc, 13 Nov: the owner's chat showed grey
|
|
3
|
+
* chips reading "< | DSML | calls>"). DeepSeek writes its tool calls with `<|DSML|function_calls>` style tags and now and
|
|
4
|
+
* then lets a bare tag leak into the reply text, in 4 of 57 calls of one job; the structured tool calls still arrived and
|
|
5
|
+
* ran, so only the visible text was wrong. A tag is `<` or `</`, then `|DSML|` (full-width bars), then a name, then `>`.
|
|
6
|
+
*/
|
|
7
|
+
const OPEN = '<|DSML|';
|
|
8
|
+
const CLOSE = '</|DSML|';
|
|
9
|
+
const TAG = /<\/?|DSML|[^>\n]*>/g;
|
|
10
|
+
/** A whole message with its markup tags taken out (untouched, not even trimmed, when it has none). */
|
|
11
|
+
export function stripDsml(text) {
|
|
12
|
+
if (!text.includes('|DSML|'))
|
|
13
|
+
return text;
|
|
14
|
+
const out = text.replace(TAG, '');
|
|
15
|
+
return out === text ? text : out.replace(/\n{3,}/g, '\n\n').trim();
|
|
16
|
+
}
|
|
17
|
+
function mayBecomeTag(tail) {
|
|
18
|
+
if (tail.includes('>') || tail.includes('\n'))
|
|
19
|
+
return false;
|
|
20
|
+
return OPEN.startsWith(tail) || CLOSE.startsWith(tail) || tail.startsWith(OPEN) || tail.startsWith(CLOSE);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The same for a reply that arrives in pieces: a tag can be cut anywhere (`<`, `|DSML|`, ` calls`, `>`), so what might
|
|
24
|
+
* still become a tag is held back until the next piece says. Everything else passes at once.
|
|
25
|
+
*/
|
|
26
|
+
export class DsmlFilter {
|
|
27
|
+
held = '';
|
|
28
|
+
push(chunk) {
|
|
29
|
+
let text = (this.held + chunk).replace(TAG, '');
|
|
30
|
+
this.held = '';
|
|
31
|
+
const at = text.lastIndexOf('<');
|
|
32
|
+
if (at >= 0 && mayBecomeTag(text.slice(at))) {
|
|
33
|
+
this.held = text.slice(at);
|
|
34
|
+
text = text.slice(0, at);
|
|
35
|
+
}
|
|
36
|
+
return text;
|
|
37
|
+
}
|
|
38
|
+
/** The stream ended: an unfinished tag is dropped, a lone `<` (or the start of one that never came) is text. */
|
|
39
|
+
flush() {
|
|
40
|
+
const rest = this.held;
|
|
41
|
+
this.held = '';
|
|
42
|
+
return rest.startsWith(OPEN) || rest.startsWith(CLOSE) ? '' : rest;
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -13,3 +13,4 @@ export { workserTool, type ToolsClient } from './tools/workser-tool.js';
|
|
|
13
13
|
export { publishFileTool, mimeOf, MAX_PUBLISH_BYTES, type FileClient } from './tools/publish.js';
|
|
14
14
|
export { withCommandEnv } from './place/env.js';
|
|
15
15
|
export { repairArgs, parseLoose, TOOL_ALIASES, type Repaired } from './tools/repair.js';
|
|
16
|
+
export { DsmlFilter, stripDsml } from './dsml.js';
|
package/dist/src/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { workserTool } from './tools/workser-tool.js';
|
|
|
13
13
|
export { publishFileTool, mimeOf, MAX_PUBLISH_BYTES } from './tools/publish.js';
|
|
14
14
|
export { withCommandEnv } from './place/env.js';
|
|
15
15
|
export { repairArgs, parseLoose, TOOL_ALIASES } from './tools/repair.js';
|
|
16
|
+
export { DsmlFilter, stripDsml } from './dsml.js';
|
package/dist/src/model.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An OpenAI-compatible chat-completions client — Workser's gateway speaks
|
|
3
|
-
* this, and the key is the RUN token (the gateway books every call against
|
|
4
|
-
* the run). Nothing else: no provider key is known to the engine.
|
|
5
|
-
*/
|
|
6
1
|
export interface ChatMessage {
|
|
7
2
|
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
8
3
|
content: string | null;
|
package/dist/src/model.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An OpenAI-compatible chat-completions client — Workser's gateway speaks
|
|
3
|
+
* this, and the key is the RUN token (the gateway books every call against
|
|
4
|
+
* the run). Nothing else: no provider key is known to the engine.
|
|
5
|
+
*/
|
|
6
|
+
import { DsmlFilter, stripDsml } from './dsml.js';
|
|
1
7
|
export class ModelError extends Error {
|
|
2
8
|
status;
|
|
3
9
|
constructor(message, status) {
|
|
@@ -94,12 +100,13 @@ export async function chat(input) {
|
|
|
94
100
|
const thought = reasoningOf(choice.message);
|
|
95
101
|
if (thought && input.onReasoning)
|
|
96
102
|
input.onReasoning(thought);
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
const said = typeof choice.message.content === 'string' ? stripDsml(choice.message.content) : choice.message.content;
|
|
104
|
+
if (said && input.onDelta)
|
|
105
|
+
input.onDelta(said);
|
|
99
106
|
return {
|
|
100
107
|
message: {
|
|
101
108
|
role: 'assistant',
|
|
102
|
-
content:
|
|
109
|
+
content: said || null,
|
|
103
110
|
...(Array.isArray(choice.message.tool_calls) && choice.message.tool_calls.length
|
|
104
111
|
? { tool_calls: choice.message.tool_calls }
|
|
105
112
|
: {}),
|
|
@@ -128,6 +135,7 @@ async function readStream(body, onDelta, status, onReasoning) {
|
|
|
128
135
|
let finishReason = null;
|
|
129
136
|
let usage;
|
|
130
137
|
let provider = '';
|
|
138
|
+
const dsml = new DsmlFilter();
|
|
131
139
|
const calls = [];
|
|
132
140
|
let sawChoice = false;
|
|
133
141
|
const handle = (data) => {
|
|
@@ -158,7 +166,9 @@ async function readStream(body, onDelta, status, onReasoning) {
|
|
|
158
166
|
onReasoning(thought);
|
|
159
167
|
if (typeof delta.content === 'string' && delta.content) {
|
|
160
168
|
content += delta.content;
|
|
161
|
-
|
|
169
|
+
const shown = dsml.push(delta.content);
|
|
170
|
+
if (shown)
|
|
171
|
+
onDelta(shown);
|
|
162
172
|
}
|
|
163
173
|
for (const part of Array.isArray(delta.tool_calls) ? delta.tool_calls : []) {
|
|
164
174
|
const index = typeof part.index === 'number' ? part.index : calls.length;
|
|
@@ -193,6 +203,10 @@ async function readStream(body, onDelta, status, onReasoning) {
|
|
|
193
203
|
handle(buffer.trim().slice(5).trim());
|
|
194
204
|
if (!sawChoice)
|
|
195
205
|
throw new ModelError('The model answered with no message.', status);
|
|
206
|
+
const rest = dsml.flush();
|
|
207
|
+
if (rest)
|
|
208
|
+
onDelta(rest);
|
|
209
|
+
content = stripDsml(content);
|
|
196
210
|
const toolCalls = calls.filter(Boolean).map((call, i) => ({ ...call, id: call.id || `call_${i}` }));
|
|
197
211
|
return {
|
|
198
212
|
message: { role: 'assistant', content: content || null, ...(toolCalls.length ? { tool_calls: toolCalls } : {}) },
|
|
@@ -14,7 +14,9 @@ export function workserTool(client) {
|
|
|
14
14
|
name: 'workser_tool',
|
|
15
15
|
description: "Use Workser's tools and the project's connected apps. action 'list' shows the tools (add query, e.g. \"db\", \"env\", \"payments\", to see only those); action 'call' runs one by name. " +
|
|
16
16
|
"A tool that changes something outside this job, or spends money, needs the owner's yes first: you get approval_required " +
|
|
17
|
-
'and an approval_id; call again with approval_id (and spend_approval_id for a spend over the limit) after they approve.'
|
|
17
|
+
'and an approval_id; call again with approval_id (and spend_approval_id for a spend over the limit) after they approve. ' +
|
|
18
|
+
'Send approval fields only with an id a result gave you, never empty. Every call needs its name. Work on the preview copy (its database, its settings) runs at once with no approval; ' +
|
|
19
|
+
'only the live site, live data, money and domains ask the owner first.',
|
|
18
20
|
parameters: {
|
|
19
21
|
type: 'object',
|
|
20
22
|
properties: {
|
|
@@ -37,13 +39,16 @@ export function workserTool(client) {
|
|
|
37
39
|
output: JSON.stringify({ ...list, tools: shown, ...(shown.length < list.tools.length ? { of: list.tools.length } : {}) }, null, 1).slice(0, 50_000),
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
// Trace 01a1d4cc (13 Nov): 4 of 57 calls of a job went out as {action: "call", approval_id: "", spend_approval_id: ""} with no
|
|
43
|
+
// name (the model reached for an approval on a preview DELETE that needed none), failed, and were sent again.
|
|
44
|
+
if (args.action !== 'call' || typeof args.name !== 'string' || !args.name) {
|
|
45
|
+
throw new Error("action is 'list' or 'call'. A call needs a name (the tool's, for example name: \"app_db_query\" with its arguments); approval_id only when a result gave you one.");
|
|
46
|
+
}
|
|
42
47
|
const out = await client.callTool(args.name, {
|
|
43
48
|
...(args.arguments && typeof args.arguments === 'object' ? { arguments: args.arguments } : {}),
|
|
44
|
-
...(typeof args.approval_id === 'string' ? { approval_id: args.approval_id } : {}),
|
|
49
|
+
...(typeof args.approval_id === 'string' && args.approval_id.trim() ? { approval_id: args.approval_id } : {}),
|
|
45
50
|
...(typeof args.amount_usd === 'number' ? { amount_usd: args.amount_usd } : {}),
|
|
46
|
-
...(typeof args.spend_approval_id === 'string' ? { spend_approval_id: args.spend_approval_id } : {}),
|
|
51
|
+
...(typeof args.spend_approval_id === 'string' && args.spend_approval_id.trim() ? { spend_approval_id: args.spend_approval_id } : {}),
|
|
47
52
|
});
|
|
48
53
|
return {
|
|
49
54
|
title: `${args.name}: ${out.status}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workser/engine",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Workser's coding engine for the 'loop in our service' mode: OpenCode's agent contract (its prompts, tool schemas and edit semantics, vendored from v1.19.5) running on Node, with every file and shell action going through a Place — so the machine can be a remote sandbox and no model key is ever on it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|