agent-worker 0.9.0 → 0.11.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 +4 -4
- package/dist/backends-DG5igQii.mjs +3 -0
- package/dist/{backends-BOAkfYyL.mjs → backends-DLaP0rMW.mjs} +45 -30
- package/dist/cli/index.mjs +1408 -1505
- package/dist/context-CKL-RY7a.mjs +4 -0
- package/dist/{display-pretty-BL9H2ocr.mjs → display-pretty-BsCsnPqs.mjs} +35 -14
- package/dist/index.d.mts +42 -30
- package/dist/index.mjs +561 -5
- package/dist/{logger-C3ekEOzi.mjs → logger-CCFaMMV7.mjs} +2 -2
- package/dist/memory-provider-CBlKMdbJ.mjs +70 -0
- package/dist/worker-CJ5_b2_q.mjs +446 -0
- package/dist/{workflow-CoZnnJ3O.mjs → workflow-CfITD7TN.mjs} +36 -37
- package/package.json +3 -1
- package/dist/backends-e6gCxRZ9.mjs +0 -3
- package/dist/context-dgI2YCGG.mjs +0 -4
- package/dist/mcp-server-BQCQxv2v.mjs +0 -573
- package/dist/skills-xNmQZf8e.mjs +0 -1002
package/README.md
CHANGED
|
@@ -391,9 +391,9 @@ kickoff: |
|
|
|
391
391
|
For programmatic control (TypeScript/JavaScript):
|
|
392
392
|
|
|
393
393
|
```typescript
|
|
394
|
-
import {
|
|
394
|
+
import { AgentWorker } from 'agent-worker'
|
|
395
395
|
|
|
396
|
-
const session = new
|
|
396
|
+
const session = new AgentWorker({
|
|
397
397
|
model: 'anthropic/claude-sonnet-4-5',
|
|
398
398
|
system: 'You are a helpful assistant.',
|
|
399
399
|
tools: [/* your tools */]
|
|
@@ -418,12 +418,12 @@ const state = session.getState()
|
|
|
418
418
|
### With Skills
|
|
419
419
|
|
|
420
420
|
```typescript
|
|
421
|
-
import {
|
|
421
|
+
import { AgentWorker, SkillsProvider, createSkillsTool } from 'agent-worker'
|
|
422
422
|
|
|
423
423
|
const skillsProvider = new SkillsProvider()
|
|
424
424
|
await skillsProvider.scanDirectory('.agents/skills')
|
|
425
425
|
|
|
426
|
-
const session = new
|
|
426
|
+
const session = new AgentWorker({
|
|
427
427
|
model: 'anthropic/claude-sonnet-4-5',
|
|
428
428
|
system: 'You are a helpful assistant.',
|
|
429
429
|
tools: [createSkillsTool(skillsProvider)]
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { C as SDK_MODEL_ALIASES, S as CURSOR_MODEL_MAP, T as normalizeBackendType, _ as execWithIdleTimeout, a as createMockBackend, b as CLAUDE_MODEL_MAP, c as CodexBackend, d as codexAdapter, f as createStreamParser, g as IdleTimeoutError, h as formatEvent, i as MockAIBackend, l as ClaudeCodeBackend, m as extractCodexResult, n as createBackend, o as SdkBackend, p as extractClaudeResult, r as listBackends, s as CursorBackend, t as checkBackends, u as claudeAdapter, v as DEFAULT_IDLE_TIMEOUT, w as getModelForBackend, x as CODEX_MODEL_MAP, y as BACKEND_DEFAULT_MODELS } from "./backends-DLaP0rMW.mjs";
|
|
2
|
+
|
|
3
|
+
export { listBackends };
|
|
@@ -198,10 +198,15 @@ const FRONTIER_MODELS = {
|
|
|
198
198
|
|
|
199
199
|
//#endregion
|
|
200
200
|
//#region src/backends/model-maps.ts
|
|
201
|
+
/** Normalize backend type, mapping deprecated "sdk" to "default" */
|
|
202
|
+
function normalizeBackendType(type) {
|
|
203
|
+
if (type === "sdk") return "default";
|
|
204
|
+
return type;
|
|
205
|
+
}
|
|
201
206
|
/** Default model per backend */
|
|
202
207
|
const BACKEND_DEFAULT_MODELS = {
|
|
203
208
|
mock: "mock-model",
|
|
204
|
-
|
|
209
|
+
default: "claude-sonnet-4-5",
|
|
205
210
|
claude: "sonnet",
|
|
206
211
|
cursor: "sonnet-4.5",
|
|
207
212
|
codex: "gpt-5.2-codex"
|
|
@@ -274,7 +279,7 @@ function getModelForBackend(model, backend) {
|
|
|
274
279
|
if (!model) return BACKEND_DEFAULT_MODELS[backend];
|
|
275
280
|
const normalizedModel = model.includes("/") ? model.split("/").pop() : model;
|
|
276
281
|
switch (backend) {
|
|
277
|
-
case "
|
|
282
|
+
case "default": return SDK_MODEL_ALIASES[normalizedModel] || model;
|
|
278
283
|
case "cursor": return CURSOR_MODEL_MAP[model] || CURSOR_MODEL_MAP[normalizedModel] || normalizedModel;
|
|
279
284
|
case "claude": return CLAUDE_MODEL_MAP[model] || CLAUDE_MODEL_MAP[normalizedModel] || normalizedModel;
|
|
280
285
|
case "codex": return CODEX_MODEL_MAP[model] || CODEX_MODEL_MAP[normalizedModel] || normalizedModel;
|
|
@@ -659,14 +664,17 @@ function extractCodexResult(stdout) {
|
|
|
659
664
|
* Create a line-buffered stream parser.
|
|
660
665
|
*
|
|
661
666
|
* Accumulates stdout chunks, parses each line through the given adapter,
|
|
662
|
-
* and emits
|
|
667
|
+
* and emits structured events via callbacks.
|
|
668
|
+
*
|
|
669
|
+
* Tool call dedup: if a tool_call event's name is in mcpToolNames,
|
|
670
|
+
* it's skipped (MCP server already logged it with source="mcp").
|
|
663
671
|
*
|
|
664
|
-
* @param
|
|
672
|
+
* @param callbacks - Structured output callbacks
|
|
665
673
|
* @param backendName - Display name (e.g., "Cursor", "Claude", "Codex")
|
|
666
674
|
* @param adapter - Format-specific adapter to convert raw JSON → StreamEvent
|
|
667
|
-
* @param messageLog - Optional callback for agent output messages (tool calls, assistant messages) (kind="stream", visible in normal mode). If not provided, uses debugLog.
|
|
668
675
|
*/
|
|
669
|
-
function createStreamParser(
|
|
676
|
+
function createStreamParser(callbacks, backendName, adapter) {
|
|
677
|
+
const { debugLog, outputLog, toolCallLog, mcpToolNames } = callbacks;
|
|
670
678
|
let lineBuf = "";
|
|
671
679
|
return (chunk) => {
|
|
672
680
|
lineBuf += chunk;
|
|
@@ -682,10 +690,16 @@ function createStreamParser(debugLog, backendName, adapter, messageLog) {
|
|
|
682
690
|
type: raw.type,
|
|
683
691
|
raw
|
|
684
692
|
};
|
|
685
|
-
if (event)
|
|
686
|
-
|
|
687
|
-
if (
|
|
693
|
+
if (!event) continue;
|
|
694
|
+
if (event.kind === "tool_call" || event.kind === "tool_call_started") {
|
|
695
|
+
if (mcpToolNames?.has(event.name)) continue;
|
|
696
|
+
if (toolCallLog && event.kind === "tool_call") {
|
|
697
|
+
toolCallLog(event.name, event.args);
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
688
700
|
}
|
|
701
|
+
const progress = formatEvent(event, backendName);
|
|
702
|
+
if (progress) ((event.kind === "tool_call" || event.kind === "tool_call_started" || event.kind === "user_message" || event.kind === "assistant_message") && outputLog ? outputLog : debugLog)(progress);
|
|
689
703
|
} catch {}
|
|
690
704
|
}
|
|
691
705
|
};
|
|
@@ -739,7 +753,6 @@ var ClaudeCodeBackend = class {
|
|
|
739
753
|
async send(message, options) {
|
|
740
754
|
const args = this.buildArgs(message, options);
|
|
741
755
|
const cwd = this.options.workspace || this.options.cwd;
|
|
742
|
-
const debugLog = this.options.debugLog;
|
|
743
756
|
const outputFormat = this.options.outputFormat ?? "stream-json";
|
|
744
757
|
const timeout = this.options.timeout ?? DEFAULT_IDLE_TIMEOUT;
|
|
745
758
|
try {
|
|
@@ -748,7 +761,7 @@ var ClaudeCodeBackend = class {
|
|
|
748
761
|
args,
|
|
749
762
|
cwd,
|
|
750
763
|
timeout,
|
|
751
|
-
onStdout: outputFormat === "stream-json" &&
|
|
764
|
+
onStdout: outputFormat === "stream-json" && this.options.streamCallbacks ? createStreamParser(this.options.streamCallbacks, "Claude", claudeAdapter) : void 0
|
|
752
765
|
});
|
|
753
766
|
this.currentAbort = abort;
|
|
754
767
|
const { stdout } = await promise;
|
|
@@ -864,7 +877,6 @@ var CodexBackend = class {
|
|
|
864
877
|
async send(message, _options) {
|
|
865
878
|
const args = this.buildArgs(message);
|
|
866
879
|
const cwd = this.options.workspace || this.options.cwd;
|
|
867
|
-
const debugLog = this.options.debugLog;
|
|
868
880
|
const timeout = this.options.timeout ?? DEFAULT_IDLE_TIMEOUT;
|
|
869
881
|
try {
|
|
870
882
|
const { stdout } = await execWithIdleTimeout({
|
|
@@ -872,7 +884,7 @@ var CodexBackend = class {
|
|
|
872
884
|
args,
|
|
873
885
|
cwd,
|
|
874
886
|
timeout,
|
|
875
|
-
onStdout:
|
|
887
|
+
onStdout: this.options.streamCallbacks ? createStreamParser(this.options.streamCallbacks, "Codex", codexAdapter) : void 0
|
|
876
888
|
});
|
|
877
889
|
return extractCodexResult(stdout);
|
|
878
890
|
} catch (error) {
|
|
@@ -952,8 +964,6 @@ var CursorBackend = class {
|
|
|
952
964
|
async send(message, _options) {
|
|
953
965
|
const { command, args } = await this.buildCommand(message);
|
|
954
966
|
const cwd = this.options.workspace || this.options.cwd;
|
|
955
|
-
const debugLog = this.options.debugLog;
|
|
956
|
-
const messageLog = this.options.messageLog;
|
|
957
967
|
const timeout = this.options.timeout ?? DEFAULT_IDLE_TIMEOUT;
|
|
958
968
|
try {
|
|
959
969
|
const { stdout } = await execWithIdleTimeout({
|
|
@@ -961,7 +971,7 @@ var CursorBackend = class {
|
|
|
961
971
|
args,
|
|
962
972
|
cwd,
|
|
963
973
|
timeout,
|
|
964
|
-
onStdout:
|
|
974
|
+
onStdout: this.options.streamCallbacks ? createStreamParser(this.options.streamCallbacks, "Cursor", cursorAdapter) : void 0
|
|
965
975
|
});
|
|
966
976
|
return extractClaudeResult(stdout);
|
|
967
977
|
} catch (error) {
|
|
@@ -1035,7 +1045,7 @@ var CursorBackend = class {
|
|
|
1035
1045
|
* Uses the AI SDK for direct API access
|
|
1036
1046
|
*/
|
|
1037
1047
|
var SdkBackend = class {
|
|
1038
|
-
type = "
|
|
1048
|
+
type = "default";
|
|
1039
1049
|
modelId;
|
|
1040
1050
|
model = null;
|
|
1041
1051
|
maxTokens;
|
|
@@ -1110,31 +1120,36 @@ function createMockBackend(debugLog) {
|
|
|
1110
1120
|
/**
|
|
1111
1121
|
* Create a backend instance
|
|
1112
1122
|
* Model names are automatically translated to backend-specific format
|
|
1123
|
+
* Accepts "sdk" as deprecated alias for "default"
|
|
1113
1124
|
*
|
|
1114
1125
|
* Examples:
|
|
1115
|
-
* - "sonnet" → cursor: "sonnet-4.5", claude: "sonnet",
|
|
1126
|
+
* - "sonnet" → cursor: "sonnet-4.5", claude: "sonnet", default: "claude-sonnet-4-5-20250514"
|
|
1116
1127
|
* - "anthropic/claude-sonnet-4-5" → cursor: "sonnet-4.5", claude: "sonnet"
|
|
1117
1128
|
*/
|
|
1118
1129
|
function createBackend(config) {
|
|
1119
|
-
const
|
|
1120
|
-
|
|
1121
|
-
|
|
1130
|
+
const normalized = {
|
|
1131
|
+
...config,
|
|
1132
|
+
type: normalizeBackendType(config.type)
|
|
1133
|
+
};
|
|
1134
|
+
const model = getModelForBackend(normalized.model, normalized.type);
|
|
1135
|
+
switch (normalized.type) {
|
|
1136
|
+
case "default": return new SdkBackend({
|
|
1122
1137
|
model,
|
|
1123
|
-
maxTokens:
|
|
1138
|
+
maxTokens: normalized.maxTokens
|
|
1124
1139
|
});
|
|
1125
1140
|
case "claude": return new ClaudeCodeBackend({
|
|
1126
|
-
...
|
|
1141
|
+
...normalized.options,
|
|
1127
1142
|
model
|
|
1128
1143
|
});
|
|
1129
1144
|
case "codex": return new CodexBackend({
|
|
1130
|
-
...
|
|
1145
|
+
...normalized.options,
|
|
1131
1146
|
model
|
|
1132
1147
|
});
|
|
1133
1148
|
case "cursor": return new CursorBackend({
|
|
1134
|
-
...
|
|
1149
|
+
...normalized.options,
|
|
1135
1150
|
model
|
|
1136
1151
|
});
|
|
1137
|
-
default: throw new Error(`Unknown backend type: ${
|
|
1152
|
+
default: throw new Error(`Unknown backend type: ${normalized.type}`);
|
|
1138
1153
|
}
|
|
1139
1154
|
}
|
|
1140
1155
|
/** Check availability with a timeout to avoid hanging when CLIs are missing */
|
|
@@ -1154,7 +1169,7 @@ async function checkBackends() {
|
|
|
1154
1169
|
withTimeout(cursor.isAvailable(), 3e3)
|
|
1155
1170
|
]);
|
|
1156
1171
|
return {
|
|
1157
|
-
|
|
1172
|
+
default: true,
|
|
1158
1173
|
claude: claudeAvailable,
|
|
1159
1174
|
codex: codexAvailable,
|
|
1160
1175
|
cursor: cursorAvailable,
|
|
@@ -1168,8 +1183,8 @@ async function listBackends() {
|
|
|
1168
1183
|
const availability = await checkBackends();
|
|
1169
1184
|
return [
|
|
1170
1185
|
{
|
|
1171
|
-
type: "
|
|
1172
|
-
available: availability.
|
|
1186
|
+
type: "default",
|
|
1187
|
+
available: availability.default,
|
|
1173
1188
|
name: "Vercel AI SDK"
|
|
1174
1189
|
},
|
|
1175
1190
|
{
|
|
@@ -1191,4 +1206,4 @@ async function listBackends() {
|
|
|
1191
1206
|
}
|
|
1192
1207
|
|
|
1193
1208
|
//#endregion
|
|
1194
|
-
export {
|
|
1209
|
+
export { createModelAsync as A, SDK_MODEL_ALIASES as C, FRONTIER_MODELS as D, parseModel as E, SUPPORTED_PROVIDERS as O, CURSOR_MODEL_MAP as S, normalizeBackendType as T, execWithIdleTimeout as _, createMockBackend as a, CLAUDE_MODEL_MAP as b, CodexBackend as c, codexAdapter as d, createStreamParser as f, IdleTimeoutError as g, formatEvent as h, MockAIBackend as i, getDefaultModel as j, createModel as k, ClaudeCodeBackend as l, extractCodexResult as m, createBackend as n, SdkBackend as o, extractClaudeResult as p, listBackends as r, CursorBackend as s, checkBackends as t, claudeAdapter as u, DEFAULT_IDLE_TIMEOUT as v, getModelForBackend as w, CODEX_MODEL_MAP as x, BACKEND_DEFAULT_MODELS as y };
|