@dirgha/code 1.7.1 → 1.7.7
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/CHANGELOG.md +52 -5
- package/CREDITS.md +46 -0
- package/LICENSE +101 -21
- package/README.md +15 -9
- package/dist_v2/cli/config.d.ts +1 -0
- package/dist_v2/cli/config.js.map +1 -1
- package/dist_v2/cli/main.js +8 -4
- package/dist_v2/cli/main.js.map +1 -1
- package/dist_v2/cli/subcommands/index.js +2 -0
- package/dist_v2/cli/subcommands/index.js.map +1 -1
- package/dist_v2/cli/subcommands/web.d.ts +13 -0
- package/dist_v2/cli/subcommands/web.js +61 -0
- package/dist_v2/cli/subcommands/web.js.map +1 -0
- package/dist_v2/intelligence/models-dev-sync.d.ts +39 -0
- package/dist_v2/intelligence/models-dev-sync.js +103 -0
- package/dist_v2/intelligence/models-dev-sync.js.map +1 -0
- package/dist_v2/kernel/agent-loop.d.ts +8 -38
- package/dist_v2/kernel/agent-loop.js +18 -57
- package/dist_v2/kernel/agent-loop.js.map +1 -1
- package/dist_v2/kernel/index.d.ts +0 -1
- package/dist_v2/kernel/index.js +0 -1
- package/dist_v2/kernel/index.js.map +1 -1
- package/dist_v2/kernel/message.d.ts +1 -17
- package/dist_v2/kernel/message.js +0 -26
- package/dist_v2/kernel/message.js.map +1 -1
- package/dist_v2/kernel/types.d.ts +0 -29
- package/dist_v2/skills/install-npm.d.ts +16 -0
- package/dist_v2/skills/install-npm.js +97 -0
- package/dist_v2/skills/install-npm.js.map +1 -0
- package/dist_v2/tools/browser.js +6 -3
- package/dist_v2/tools/browser.js.map +1 -1
- package/dist_v2/tui/ink/App.d.ts +3 -0
- package/dist_v2/tui/ink/App.js +72 -22
- package/dist_v2/tui/ink/App.js.map +1 -1
- package/dist_v2/tui/ink/index.js +4 -0
- package/dist_v2/tui/ink/index.js.map +1 -1
- package/dist_v2/web/cost.d.ts +35 -0
- package/dist_v2/web/cost.js +211 -0
- package/dist_v2/web/cost.js.map +1 -0
- package/dist_v2/web/ledger.d.ts +25 -0
- package/dist_v2/web/ledger.js +156 -0
- package/dist_v2/web/ledger.js.map +1 -0
- package/dist_v2/web/server.d.ts +30 -0
- package/dist_v2/web/server.js +199 -0
- package/dist_v2/web/server.js.map +1 -0
- package/package.json +32 -52
- package/dist_v2/kernel/queues.d.ts +0 -82
- package/dist_v2/kernel/queues.js +0 -105
- package/dist_v2/kernel/queues.js.map +0 -1
- package/dist_v2/providers/faux.d.ts +0 -99
- package/dist_v2/providers/faux.js +0 -153
- package/dist_v2/providers/faux.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dirgha/code",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.7.7",
|
|
4
|
+
"description": "CLI coding agent for complex agentic workflows and long-horizon development. Local models (llama.cpp / Ollama), BYOK across 17 providers, parallel agents, persistent memory, scanned skills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist_v2/index.js",
|
|
7
7
|
"types": "./dist_v2/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"dirgha": "./dist_v2/cli/main.js"
|
|
10
|
-
"dirgha-v1": "./dist/cli.js"
|
|
9
|
+
"dirgha": "./dist_v2/cli/main.js"
|
|
11
10
|
},
|
|
12
11
|
"files": [
|
|
13
12
|
"dist_v2/",
|
|
@@ -17,59 +16,27 @@
|
|
|
17
16
|
"CHANGELOG.md"
|
|
18
17
|
],
|
|
19
18
|
"scripts": {
|
|
20
|
-
"build": "tsc
|
|
21
|
-
"build:watch": "tsc
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"clean": "rm -rf ./dist ./dist_v2",
|
|
25
|
-
"test": "vitest run",
|
|
26
|
-
"test:watch": "vitest",
|
|
27
|
-
"test:coverage": "vitest run --coverage",
|
|
28
|
-
"test:v2": "vitest run --dir src_v2",
|
|
19
|
+
"build": "tsc -p tsconfig.v2.json && cp src_v2/context/default-soul.md dist_v2/context/default-soul.md",
|
|
20
|
+
"build:watch": "tsc -p tsconfig.v2.json --watch",
|
|
21
|
+
"clean": "rm -rf ./dist_v2",
|
|
22
|
+
"test": "vitest run --dir src_v2",
|
|
29
23
|
"test:cli": "node scripts/qa-app/run-all.mjs",
|
|
30
|
-
"test:cli:quick": "node scripts/qa-app/run-all.mjs --quick",
|
|
31
24
|
"test:cli:offline": "node scripts/qa-app/run-all.mjs --offline",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"typecheck
|
|
35
|
-
"
|
|
36
|
-
"
|
|
25
|
+
"test:tui": "bash scripts/qa-app/picker-flow.sh",
|
|
26
|
+
"test:smoke": "bash scripts/smoke-matrix.sh all",
|
|
27
|
+
"typecheck": "tsc -p tsconfig.v2.json --noEmit",
|
|
28
|
+
"verify-install": "bash scripts/verify-install.sh",
|
|
29
|
+
"prepublish-guard": "bash scripts/prepublish-guard.sh",
|
|
30
|
+
"prepublishOnly": "npm run prepublish-guard && npm run build && npm run verify-install"
|
|
37
31
|
},
|
|
38
32
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/google": "^0.0.48",
|
|
40
|
-
"@ai-sdk/openai": "^0.0.66",
|
|
41
|
-
"@anthropic-ai/sdk": "^0.24.0",
|
|
42
|
-
"@dirgha/pricing": "workspace:*",
|
|
43
|
-
"ai": "^3.0.0",
|
|
44
|
-
"better-sqlite3": "^11.3.0",
|
|
45
|
-
"chalk": "^5.3.0",
|
|
46
|
-
"cli-markdown": "^1.0.0",
|
|
47
|
-
"commander": "^12.0.0",
|
|
48
|
-
"dotenv": "^16.4.1",
|
|
49
|
-
"express": "^4.18.2",
|
|
50
|
-
"figlet": "^1.7.0",
|
|
51
33
|
"ink": "^5.0.0",
|
|
52
34
|
"ink-text-input": "^6.0.0",
|
|
53
|
-
"
|
|
54
|
-
"ora": "^7.0.1",
|
|
55
|
-
"pino": "^8.19.0",
|
|
56
|
-
"pino-pretty": "^10.3.1",
|
|
57
|
-
"playwright": "^1.47.0",
|
|
58
|
-
"react": "^18.3.0",
|
|
59
|
-
"readline": "^1.3.0",
|
|
60
|
-
"uuid": "^9.0.1",
|
|
61
|
-
"yaml": "^2.3.4",
|
|
62
|
-
"zod": "^3.22.4"
|
|
35
|
+
"react": "^18.3.0"
|
|
63
36
|
},
|
|
64
37
|
"devDependencies": {
|
|
65
|
-
"@types/express": "^4.17.21",
|
|
66
|
-
"@types/figlet": "^1.5.8",
|
|
67
38
|
"@types/node": "^20.11.5",
|
|
68
|
-
"@types/
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
70
|
-
"@typescript-eslint/parser": "^6.19.1",
|
|
71
|
-
"@vitest/coverage-v8": "^1.2.2",
|
|
72
|
-
"eslint": "^8.56.0",
|
|
39
|
+
"@types/react": "^18.3.0",
|
|
73
40
|
"typescript": "^5.3.3",
|
|
74
41
|
"vitest": "^1.2.2"
|
|
75
42
|
},
|
|
@@ -77,12 +44,25 @@
|
|
|
77
44
|
"node": ">=18.0.0"
|
|
78
45
|
},
|
|
79
46
|
"keywords": [
|
|
80
|
-
"ai",
|
|
81
47
|
"cli",
|
|
82
|
-
"agent",
|
|
48
|
+
"coding-agent",
|
|
83
49
|
"llm",
|
|
84
|
-
"
|
|
50
|
+
"byok",
|
|
51
|
+
"ai",
|
|
52
|
+
"agent",
|
|
53
|
+
"tool-calling",
|
|
54
|
+
"openrouter",
|
|
55
|
+
"anthropic",
|
|
56
|
+
"openai"
|
|
85
57
|
],
|
|
58
|
+
"homepage": "https://github.com/Dirgha-AI/dirgha-code",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "git+https://github.com/Dirgha-AI/dirgha-code.git"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/Dirgha-AI/dirgha-code/issues"
|
|
65
|
+
},
|
|
86
66
|
"author": "Dirgha AI Team",
|
|
87
|
-
"license": "
|
|
67
|
+
"license": "SEE LICENSE IN LICENSE"
|
|
88
68
|
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Steering and follow-up queues for mid-flight agent control.
|
|
3
|
-
*
|
|
4
|
-
* Two queue types with different drain semantics:
|
|
5
|
-
*
|
|
6
|
-
* - SteeringQueue: drain mode 'all'. Every queued message replaces the
|
|
7
|
-
* current turn's prompt mid-flight. Used for "stop and do this instead".
|
|
8
|
-
* When drained, all queued messages are returned and the queue is cleared.
|
|
9
|
-
*
|
|
10
|
-
* - FollowUpQueue: drain mode 'one-at-a-time'. Each queued message becomes
|
|
11
|
-
* the next turn after the current one completes. When drained, only one
|
|
12
|
-
* message is returned (if any), leaving the rest for subsequent drains.
|
|
13
|
-
*
|
|
14
|
-
* Both queues accept `AgentMessage` (user messages to inject into the
|
|
15
|
-
* conversation) and expose the standard queue operations: enqueue, drain,
|
|
16
|
-
* peek, and clear.
|
|
17
|
-
*/
|
|
18
|
-
import type { AgentMessage } from './types.js';
|
|
19
|
-
/**
|
|
20
|
-
* Drain mode determines how many messages are removed on drain.
|
|
21
|
-
* - 'all': drain removes every queued message.
|
|
22
|
-
* - 'one': drain removes at most one message.
|
|
23
|
-
*/
|
|
24
|
-
type DrainMode = 'all' | 'one';
|
|
25
|
-
/**
|
|
26
|
-
* Base queue implementation with configurable drain behaviour.
|
|
27
|
-
*/
|
|
28
|
-
declare class MessageQueue {
|
|
29
|
-
protected readonly messages: AgentMessage[];
|
|
30
|
-
protected readonly mode: DrainMode;
|
|
31
|
-
constructor(mode: DrainMode);
|
|
32
|
-
/**
|
|
33
|
-
* Append a message to the end of the queue.
|
|
34
|
-
*/
|
|
35
|
-
enqueue(msg: AgentMessage): void;
|
|
36
|
-
/**
|
|
37
|
-
* Remove and return messages according to the drain mode.
|
|
38
|
-
*
|
|
39
|
-
* - 'all': returns all messages (or null if empty), clears the queue.
|
|
40
|
-
* - 'one': returns the oldest message as a single-element array (or null
|
|
41
|
-
* if empty), removes only that message.
|
|
42
|
-
*/
|
|
43
|
-
drain(): AgentMessage[] | null;
|
|
44
|
-
/**
|
|
45
|
-
* Peek at queued messages without removing them.
|
|
46
|
-
*
|
|
47
|
-
* - 'all': returns all messages (or null if empty).
|
|
48
|
-
* - 'one': returns the oldest message as a single-element array (or null
|
|
49
|
-
* if empty).
|
|
50
|
-
*/
|
|
51
|
-
peek(): AgentMessage[] | null;
|
|
52
|
-
/**
|
|
53
|
-
* Remove all messages from the queue.
|
|
54
|
-
*/
|
|
55
|
-
clear(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Number of messages currently in the queue.
|
|
58
|
-
*/
|
|
59
|
-
get length(): number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* SteeringQueue: drain mode 'all'.
|
|
63
|
-
*
|
|
64
|
-
* Used for mid-flight steering — "stop and do this instead". When drained,
|
|
65
|
-
* all queued messages are returned and the queue is cleared. The agent loop
|
|
66
|
-
* should push these messages into history and continue looping (i.e. not
|
|
67
|
-
* break on end_turn).
|
|
68
|
-
*/
|
|
69
|
-
export declare class SteeringQueue extends MessageQueue {
|
|
70
|
-
constructor();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* FollowUpQueue: drain mode 'one-at-a-time'.
|
|
74
|
-
*
|
|
75
|
-
* Used for scheduling follow-up turns. Each queued message becomes the next
|
|
76
|
-
* turn after the current one completes. When drained, only one message is
|
|
77
|
-
* returned (if any), leaving the rest for subsequent drains.
|
|
78
|
-
*/
|
|
79
|
-
export declare class FollowUpQueue extends MessageQueue {
|
|
80
|
-
constructor();
|
|
81
|
-
}
|
|
82
|
-
export {};
|
package/dist_v2/kernel/queues.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Steering and follow-up queues for mid-flight agent control.
|
|
3
|
-
*
|
|
4
|
-
* Two queue types with different drain semantics:
|
|
5
|
-
*
|
|
6
|
-
* - SteeringQueue: drain mode 'all'. Every queued message replaces the
|
|
7
|
-
* current turn's prompt mid-flight. Used for "stop and do this instead".
|
|
8
|
-
* When drained, all queued messages are returned and the queue is cleared.
|
|
9
|
-
*
|
|
10
|
-
* - FollowUpQueue: drain mode 'one-at-a-time'. Each queued message becomes
|
|
11
|
-
* the next turn after the current one completes. When drained, only one
|
|
12
|
-
* message is returned (if any), leaving the rest for subsequent drains.
|
|
13
|
-
*
|
|
14
|
-
* Both queues accept `AgentMessage` (user messages to inject into the
|
|
15
|
-
* conversation) and expose the standard queue operations: enqueue, drain,
|
|
16
|
-
* peek, and clear.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Base queue implementation with configurable drain behaviour.
|
|
20
|
-
*/
|
|
21
|
-
class MessageQueue {
|
|
22
|
-
messages = [];
|
|
23
|
-
mode;
|
|
24
|
-
constructor(mode) {
|
|
25
|
-
this.mode = mode;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Append a message to the end of the queue.
|
|
29
|
-
*/
|
|
30
|
-
enqueue(msg) {
|
|
31
|
-
this.messages.push(msg);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Remove and return messages according to the drain mode.
|
|
35
|
-
*
|
|
36
|
-
* - 'all': returns all messages (or null if empty), clears the queue.
|
|
37
|
-
* - 'one': returns the oldest message as a single-element array (or null
|
|
38
|
-
* if empty), removes only that message.
|
|
39
|
-
*/
|
|
40
|
-
drain() {
|
|
41
|
-
if (this.messages.length === 0)
|
|
42
|
-
return null;
|
|
43
|
-
if (this.mode === 'all') {
|
|
44
|
-
const drained = [...this.messages];
|
|
45
|
-
this.messages.length = 0;
|
|
46
|
-
return drained;
|
|
47
|
-
}
|
|
48
|
-
// mode === 'one'
|
|
49
|
-
return [this.messages.shift()];
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Peek at queued messages without removing them.
|
|
53
|
-
*
|
|
54
|
-
* - 'all': returns all messages (or null if empty).
|
|
55
|
-
* - 'one': returns the oldest message as a single-element array (or null
|
|
56
|
-
* if empty).
|
|
57
|
-
*/
|
|
58
|
-
peek() {
|
|
59
|
-
if (this.messages.length === 0)
|
|
60
|
-
return null;
|
|
61
|
-
if (this.mode === 'all') {
|
|
62
|
-
return [...this.messages];
|
|
63
|
-
}
|
|
64
|
-
// mode === 'one'
|
|
65
|
-
return [this.messages[0]];
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Remove all messages from the queue.
|
|
69
|
-
*/
|
|
70
|
-
clear() {
|
|
71
|
-
this.messages.length = 0;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Number of messages currently in the queue.
|
|
75
|
-
*/
|
|
76
|
-
get length() {
|
|
77
|
-
return this.messages.length;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* SteeringQueue: drain mode 'all'.
|
|
82
|
-
*
|
|
83
|
-
* Used for mid-flight steering — "stop and do this instead". When drained,
|
|
84
|
-
* all queued messages are returned and the queue is cleared. The agent loop
|
|
85
|
-
* should push these messages into history and continue looping (i.e. not
|
|
86
|
-
* break on end_turn).
|
|
87
|
-
*/
|
|
88
|
-
export class SteeringQueue extends MessageQueue {
|
|
89
|
-
constructor() {
|
|
90
|
-
super('all');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* FollowUpQueue: drain mode 'one-at-a-time'.
|
|
95
|
-
*
|
|
96
|
-
* Used for scheduling follow-up turns. Each queued message becomes the next
|
|
97
|
-
* turn after the current one completes. When drained, only one message is
|
|
98
|
-
* returned (if any), leaving the rest for subsequent drains.
|
|
99
|
-
*/
|
|
100
|
-
export class FollowUpQueue extends MessageQueue {
|
|
101
|
-
constructor() {
|
|
102
|
-
super('one');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=queues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queues.js","sourceRoot":"","sources":["../../src_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C9B,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C;QACE,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC7C;QACE,KAAK,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FauxProvider — deterministic, in-process Provider for testing the agent loop.
|
|
3
|
-
*
|
|
4
|
-
* Implements the same `Provider` contract as real providers (anthropic.ts,
|
|
5
|
-
* openai.ts, etc.) but consumes a pre-baked script of step descriptors
|
|
6
|
-
* instead of talking to a network. Each call to `stream()` consumes the
|
|
7
|
-
* NEXT step from the script and emits the corresponding `AgentEvent`s.
|
|
8
|
-
*
|
|
9
|
-
* Use it to drive `runAgentLoop` end-to-end without any I/O.
|
|
10
|
-
*
|
|
11
|
-
* const provider = new FauxProvider([
|
|
12
|
-
* { kind: 'tool-call', id: 'c1', name: 'shell', input: { cmd: 'ls' } },
|
|
13
|
-
* { kind: 'text', chunks: ['done'] },
|
|
14
|
-
* ]);
|
|
15
|
-
*
|
|
16
|
-
* The provider also records `callCount` and `lastMessages` so tests can
|
|
17
|
-
* assert what the loop sent to the LLM (post-projection from AgentMessage[]).
|
|
18
|
-
*/
|
|
19
|
-
import type { AgentEvent, Message } from '../kernel/types.js';
|
|
20
|
-
import type { Provider, StreamRequest } from './iface.js';
|
|
21
|
-
export type FauxScriptStep = {
|
|
22
|
-
kind: 'text';
|
|
23
|
-
chunks: string[];
|
|
24
|
-
usage?: {
|
|
25
|
-
inputTokens: number;
|
|
26
|
-
outputTokens: number;
|
|
27
|
-
cachedTokens?: number;
|
|
28
|
-
};
|
|
29
|
-
} | {
|
|
30
|
-
kind: 'tool-call';
|
|
31
|
-
id: string;
|
|
32
|
-
name: string;
|
|
33
|
-
input: unknown;
|
|
34
|
-
usage?: {
|
|
35
|
-
inputTokens: number;
|
|
36
|
-
outputTokens: number;
|
|
37
|
-
cachedTokens?: number;
|
|
38
|
-
};
|
|
39
|
-
} | {
|
|
40
|
-
kind: 'mixed';
|
|
41
|
-
text?: string;
|
|
42
|
-
toolCalls: {
|
|
43
|
-
id: string;
|
|
44
|
-
name: string;
|
|
45
|
-
input: unknown;
|
|
46
|
-
}[];
|
|
47
|
-
usage?: {
|
|
48
|
-
inputTokens: number;
|
|
49
|
-
outputTokens: number;
|
|
50
|
-
cachedTokens?: number;
|
|
51
|
-
};
|
|
52
|
-
} | {
|
|
53
|
-
kind: 'error';
|
|
54
|
-
error: Error;
|
|
55
|
-
} | {
|
|
56
|
-
kind: 'abort';
|
|
57
|
-
afterMs?: number;
|
|
58
|
-
} | {
|
|
59
|
-
kind: 'wait';
|
|
60
|
-
ms: number;
|
|
61
|
-
};
|
|
62
|
-
export interface FauxProviderOptions {
|
|
63
|
-
/** Provider id reported via `provider.id`. Defaults to `'faux'`. */
|
|
64
|
-
id?: string;
|
|
65
|
-
/** Whether `supportsTools` returns true (default: true). */
|
|
66
|
-
supportsTools?: boolean;
|
|
67
|
-
/** Whether `supportsThinking` returns true (default: false). */
|
|
68
|
-
supportsThinking?: boolean;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Synchronous-throwing AbortError. Mirrors the shape Node/undici fetch
|
|
72
|
-
* rejects with when an AbortSignal fires mid-request — `.name === 'AbortError'`
|
|
73
|
-
* is the discriminator real providers and the loop's error path see.
|
|
74
|
-
*/
|
|
75
|
-
export declare class FauxAbortError extends Error {
|
|
76
|
-
readonly name = "AbortError";
|
|
77
|
-
constructor(message?: string);
|
|
78
|
-
}
|
|
79
|
-
export declare class FauxProvider implements Provider {
|
|
80
|
-
readonly id: string;
|
|
81
|
-
private readonly script;
|
|
82
|
-
private cursor;
|
|
83
|
-
private readonly _toolsSupported;
|
|
84
|
-
private readonly _thinkingSupported;
|
|
85
|
-
/** Total number of times `stream()` has been called. */
|
|
86
|
-
callCount: number;
|
|
87
|
-
/** The `messages` argument from the most recent `stream()` call. */
|
|
88
|
-
lastMessages: Message[];
|
|
89
|
-
/** All `messages` arguments captured across every `stream()` call, in order. */
|
|
90
|
-
callHistory: Message[][];
|
|
91
|
-
constructor(script: FauxScriptStep[], opts?: FauxProviderOptions);
|
|
92
|
-
supportsTools(_modelId: string): boolean;
|
|
93
|
-
supportsThinking(_modelId: string): boolean;
|
|
94
|
-
/** Number of script steps not yet consumed. */
|
|
95
|
-
get remaining(): number;
|
|
96
|
-
/** Reset call counters and cursor. Useful between assertions in one test. */
|
|
97
|
-
reset(): void;
|
|
98
|
-
stream(req: StreamRequest): AsyncIterable<AgentEvent>;
|
|
99
|
-
}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FauxProvider — deterministic, in-process Provider for testing the agent loop.
|
|
3
|
-
*
|
|
4
|
-
* Implements the same `Provider` contract as real providers (anthropic.ts,
|
|
5
|
-
* openai.ts, etc.) but consumes a pre-baked script of step descriptors
|
|
6
|
-
* instead of talking to a network. Each call to `stream()` consumes the
|
|
7
|
-
* NEXT step from the script and emits the corresponding `AgentEvent`s.
|
|
8
|
-
*
|
|
9
|
-
* Use it to drive `runAgentLoop` end-to-end without any I/O.
|
|
10
|
-
*
|
|
11
|
-
* const provider = new FauxProvider([
|
|
12
|
-
* { kind: 'tool-call', id: 'c1', name: 'shell', input: { cmd: 'ls' } },
|
|
13
|
-
* { kind: 'text', chunks: ['done'] },
|
|
14
|
-
* ]);
|
|
15
|
-
*
|
|
16
|
-
* The provider also records `callCount` and `lastMessages` so tests can
|
|
17
|
-
* assert what the loop sent to the LLM (post-projection from AgentMessage[]).
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Synchronous-throwing AbortError. Mirrors the shape Node/undici fetch
|
|
21
|
-
* rejects with when an AbortSignal fires mid-request — `.name === 'AbortError'`
|
|
22
|
-
* is the discriminator real providers and the loop's error path see.
|
|
23
|
-
*/
|
|
24
|
-
export class FauxAbortError extends Error {
|
|
25
|
-
name = 'AbortError';
|
|
26
|
-
constructor(message = 'The operation was aborted') {
|
|
27
|
-
super(message);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export class FauxProvider {
|
|
31
|
-
id;
|
|
32
|
-
script;
|
|
33
|
-
cursor = 0;
|
|
34
|
-
_toolsSupported;
|
|
35
|
-
_thinkingSupported;
|
|
36
|
-
/** Total number of times `stream()` has been called. */
|
|
37
|
-
callCount = 0;
|
|
38
|
-
/** The `messages` argument from the most recent `stream()` call. */
|
|
39
|
-
lastMessages = [];
|
|
40
|
-
/** All `messages` arguments captured across every `stream()` call, in order. */
|
|
41
|
-
callHistory = [];
|
|
42
|
-
constructor(script, opts = {}) {
|
|
43
|
-
this.script = script;
|
|
44
|
-
this.id = opts.id ?? 'faux';
|
|
45
|
-
this._toolsSupported = opts.supportsTools ?? true;
|
|
46
|
-
this._thinkingSupported = opts.supportsThinking ?? false;
|
|
47
|
-
}
|
|
48
|
-
supportsTools(_modelId) {
|
|
49
|
-
return this._toolsSupported;
|
|
50
|
-
}
|
|
51
|
-
supportsThinking(_modelId) {
|
|
52
|
-
return this._thinkingSupported;
|
|
53
|
-
}
|
|
54
|
-
/** Number of script steps not yet consumed. */
|
|
55
|
-
get remaining() {
|
|
56
|
-
return this.script.length - this.cursor;
|
|
57
|
-
}
|
|
58
|
-
/** Reset call counters and cursor. Useful between assertions in one test. */
|
|
59
|
-
reset() {
|
|
60
|
-
this.cursor = 0;
|
|
61
|
-
this.callCount = 0;
|
|
62
|
-
this.lastMessages = [];
|
|
63
|
-
this.callHistory = [];
|
|
64
|
-
}
|
|
65
|
-
async *stream(req) {
|
|
66
|
-
// Capture the request BEFORE consuming the script so an exhausted-script
|
|
67
|
-
// throw still records the call (helps debugging in tests).
|
|
68
|
-
this.callCount += 1;
|
|
69
|
-
this.lastMessages = req.messages;
|
|
70
|
-
this.callHistory.push(req.messages);
|
|
71
|
-
if (this.cursor >= this.script.length) {
|
|
72
|
-
throw new Error('FauxProvider: script exhausted');
|
|
73
|
-
}
|
|
74
|
-
const step = this.script[this.cursor++];
|
|
75
|
-
switch (step.kind) {
|
|
76
|
-
case 'error':
|
|
77
|
-
// Real providers throw mid-fetch; FauxProvider throws on first
|
|
78
|
-
// iteration. The loop catches inside the `for await` either way.
|
|
79
|
-
throw step.error;
|
|
80
|
-
case 'abort': {
|
|
81
|
-
const ms = step.afterMs ?? 10;
|
|
82
|
-
await delay(ms);
|
|
83
|
-
if (req.signal?.aborted) {
|
|
84
|
-
// If the caller aborted us during the delay, surface that signal's
|
|
85
|
-
// reason instead of a synthetic one.
|
|
86
|
-
throw new FauxAbortError('Aborted by caller signal');
|
|
87
|
-
}
|
|
88
|
-
throw new FauxAbortError();
|
|
89
|
-
}
|
|
90
|
-
case 'wait':
|
|
91
|
-
await delay(step.ms);
|
|
92
|
-
return;
|
|
93
|
-
case 'text': {
|
|
94
|
-
yield { type: 'text_start' };
|
|
95
|
-
for (const chunk of step.chunks) {
|
|
96
|
-
if (req.signal?.aborted)
|
|
97
|
-
throw new FauxAbortError();
|
|
98
|
-
yield { type: 'text_delta', delta: chunk };
|
|
99
|
-
}
|
|
100
|
-
yield { type: 'text_end' };
|
|
101
|
-
if (step.usage) {
|
|
102
|
-
yield {
|
|
103
|
-
type: 'usage',
|
|
104
|
-
inputTokens: step.usage.inputTokens,
|
|
105
|
-
outputTokens: step.usage.outputTokens,
|
|
106
|
-
cachedTokens: step.usage.cachedTokens ?? 0,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
case 'tool-call': {
|
|
112
|
-
yield { type: 'toolcall_start', id: step.id, name: step.name };
|
|
113
|
-
const json = JSON.stringify(step.input ?? {});
|
|
114
|
-
yield { type: 'toolcall_delta', id: step.id, deltaJson: json };
|
|
115
|
-
yield { type: 'toolcall_end', id: step.id, input: step.input };
|
|
116
|
-
if (step.usage) {
|
|
117
|
-
yield {
|
|
118
|
-
type: 'usage',
|
|
119
|
-
inputTokens: step.usage.inputTokens,
|
|
120
|
-
outputTokens: step.usage.outputTokens,
|
|
121
|
-
cachedTokens: step.usage.cachedTokens ?? 0,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
case 'mixed': {
|
|
127
|
-
if (step.text && step.text.length > 0) {
|
|
128
|
-
yield { type: 'text_start' };
|
|
129
|
-
yield { type: 'text_delta', delta: step.text };
|
|
130
|
-
yield { type: 'text_end' };
|
|
131
|
-
}
|
|
132
|
-
for (const tc of step.toolCalls) {
|
|
133
|
-
yield { type: 'toolcall_start', id: tc.id, name: tc.name };
|
|
134
|
-
yield { type: 'toolcall_delta', id: tc.id, deltaJson: JSON.stringify(tc.input ?? {}) };
|
|
135
|
-
yield { type: 'toolcall_end', id: tc.id, input: tc.input };
|
|
136
|
-
}
|
|
137
|
-
if (step.usage) {
|
|
138
|
-
yield {
|
|
139
|
-
type: 'usage',
|
|
140
|
-
inputTokens: step.usage.inputTokens,
|
|
141
|
-
outputTokens: step.usage.outputTokens,
|
|
142
|
-
cachedTokens: step.usage.cachedTokens ?? 0,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function delay(ms) {
|
|
151
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
152
|
-
}
|
|
153
|
-
//# sourceMappingURL=faux.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"faux.js","sourceRoot":"","sources":["../../src_v2/providers/faux.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA2BH;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,GAAG,YAAY,CAAC;IAC7B,YAAY,OAAO,GAAG,2BAA2B;QAC/C,KAAK,CAA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