@ycodium-ai/agent-fake 0.2.2690 → 0.2.2696
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 +3 -0
- package/dist/index.js +127 -0
- package/locales/en.json +9 -0
- package/locales/zh-CN.json +9 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,9 +8,12 @@ A minimal executor plugin. It starts no CLI and replays a fixed event script:
|
|
|
8
8
|
- `interruptTurn` (or an aborted `AbortSignal`) ends the in-flight turn as `interrupted`
|
|
9
9
|
- `readThread` returns the bookkeeping the instance recorded
|
|
10
10
|
- `probe` reports two models, `fake` (default) and `fake-large`
|
|
11
|
+
- `usage` answers quota and token reads deterministically (no network, no disk): `readQuota` returns a session and a weekly window that creep up by one percent per read, `readTokenUsage` returns one record per day for the past two weeks (alternating a priced and an unpriced model), `redeemQuotaReset` spends one of two reset credits and zeroes the session window
|
|
11
12
|
|
|
12
13
|
The card also shows how a third-party executor gets its own settings form: `configSchema` marks `replyText` with `x-ycodium-form`, and the labels resolve in this package's `locales/en.json` and `locales/zh-CN.json`. `replyText` is what the plain script answers; empty means `fake turn complete`.
|
|
13
14
|
|
|
15
|
+
The instance config `usageScript` picks how quota reads answer: `available` (default), `balance` (the API-key shape: a remaining CNY balance, no windows), `rate-limited`, `custom-endpoint` or `signed-out`. It is not in the settings form; edit the instance config to change it. The window labels are locale keys (`usage.window.session`, `usage.window.weekly`, `usage.balance.account`), a worked example of how an agent plugin labels its quota rows.
|
|
16
|
+
|
|
14
17
|
Two uses:
|
|
15
18
|
|
|
16
19
|
1. **Template** for an `@ycodium-ai/agent-*` author: one card, `createInstance`, lease-scoped `host.process.spawn` (this fake never calls it), `ctx.log` instead of console.
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,11 @@ var FAKE_CARD = {
|
|
|
43
43
|
script: { type: "string", enum: ["plain", "approval-tool", "async-question", "stream"] },
|
|
44
44
|
streamChunks: { type: "integer", minimum: 1 },
|
|
45
45
|
streamIntervalMs: { type: "integer", minimum: 0 },
|
|
46
|
+
// 额度与用量怎么答(见 fakeUsage.ts);不进设置表单,开发与验收时手改实例配置。
|
|
47
|
+
usageScript: {
|
|
48
|
+
type: "string",
|
|
49
|
+
enum: ["available", "balance", "rate-limited", "custom-endpoint", "signed-out"]
|
|
50
|
+
},
|
|
46
51
|
replyText: {
|
|
47
52
|
type: "string",
|
|
48
53
|
"x-ycodium-form": {
|
|
@@ -63,6 +68,127 @@ var FAKE_CARD = {
|
|
|
63
68
|
|
|
64
69
|
// src/fakeInstance.ts
|
|
65
70
|
import * as NodeCrypto from "node:crypto";
|
|
71
|
+
|
|
72
|
+
// src/fakeUsage.ts
|
|
73
|
+
var FAKE_USAGE_SCRIPTS = [
|
|
74
|
+
"available",
|
|
75
|
+
"balance",
|
|
76
|
+
"rate-limited",
|
|
77
|
+
"custom-endpoint",
|
|
78
|
+
"signed-out"
|
|
79
|
+
];
|
|
80
|
+
var parseUsageScript = (input) => {
|
|
81
|
+
const config = input?.config;
|
|
82
|
+
return FAKE_USAGE_SCRIPTS.find((script) => script === config?.usageScript) ?? "available";
|
|
83
|
+
};
|
|
84
|
+
var HOUR_MS = 60 * 60 * 1e3;
|
|
85
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
86
|
+
var INITIAL_RESET_CREDITS = 2;
|
|
87
|
+
var FAKE_DAYS = 14;
|
|
88
|
+
var createFakeUsage = (input) => {
|
|
89
|
+
const now = input.now ?? Date.now;
|
|
90
|
+
let reads = 0;
|
|
91
|
+
let resetCredits = INITIAL_RESET_CREDITS;
|
|
92
|
+
let sessionUsed = 40;
|
|
93
|
+
const readQuota = async () => {
|
|
94
|
+
switch (input.script) {
|
|
95
|
+
case "custom-endpoint":
|
|
96
|
+
return { status: "unavailable", reason: "customEndpoint" };
|
|
97
|
+
case "signed-out":
|
|
98
|
+
return { status: "unavailable", reason: "missingCredentials" };
|
|
99
|
+
case "rate-limited":
|
|
100
|
+
return { status: "unavailable", reason: "rateLimited", retryAfterMs: 3e4 };
|
|
101
|
+
case "balance":
|
|
102
|
+
reads += 1;
|
|
103
|
+
return {
|
|
104
|
+
status: "available",
|
|
105
|
+
windows: [],
|
|
106
|
+
balances: [
|
|
107
|
+
{
|
|
108
|
+
id: "account",
|
|
109
|
+
label: { key: "usage.balance.account" },
|
|
110
|
+
remaining: Math.max(0, 100 - reads),
|
|
111
|
+
used: null,
|
|
112
|
+
limit: null,
|
|
113
|
+
unit: { kind: "money", currency: "CNY" },
|
|
114
|
+
resetsAt: null
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
accountKey: `fake:${input.instanceId}`
|
|
118
|
+
};
|
|
119
|
+
case "available":
|
|
120
|
+
reads += 1;
|
|
121
|
+
sessionUsed = Math.min(100, sessionUsed + 1);
|
|
122
|
+
return {
|
|
123
|
+
status: "available",
|
|
124
|
+
plan: "Fake Pro",
|
|
125
|
+
accountKey: `fake:${input.instanceId}`,
|
|
126
|
+
windows: [
|
|
127
|
+
{
|
|
128
|
+
id: "session",
|
|
129
|
+
label: { key: "usage.window.session" },
|
|
130
|
+
// 兑换过重置额度后,会话窗口从 0 重新算。
|
|
131
|
+
usedPercent: sessionUsed,
|
|
132
|
+
resetsAt: new Date(now() + 3 * HOUR_MS).toISOString(),
|
|
133
|
+
windowMs: 5 * HOUR_MS
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: "weekly",
|
|
137
|
+
label: { key: "usage.window.weekly" },
|
|
138
|
+
usedPercent: Math.min(100, 16 + reads),
|
|
139
|
+
resetsAt: new Date(now() + 4 * DAY_MS).toISOString(),
|
|
140
|
+
windowMs: 7 * DAY_MS
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
balances: [],
|
|
144
|
+
resetCredits: { availableCount: resetCredits }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const readTokenUsage = async (request) => {
|
|
149
|
+
const since = Date.parse(request.since);
|
|
150
|
+
const until = Date.parse(request.until);
|
|
151
|
+
const todayStart = Math.floor(now() / DAY_MS) * DAY_MS;
|
|
152
|
+
const records = [];
|
|
153
|
+
for (let age = 0; age < FAKE_DAYS; age += 1) {
|
|
154
|
+
const at = todayStart - age * DAY_MS + 9 * HOUR_MS;
|
|
155
|
+
if (at < since || at >= until) continue;
|
|
156
|
+
records.push({
|
|
157
|
+
at: new Date(at).toISOString(),
|
|
158
|
+
// gpt-4o 在价格表里,fake-model 不在:两种费用来源都能在页面上看到。
|
|
159
|
+
model: age % 2 === 0 ? "gpt-4o" : "fake-model",
|
|
160
|
+
sessionId: `fake-${input.instanceId}-${age}`,
|
|
161
|
+
totals: {
|
|
162
|
+
uncachedInputTokens: 1200 + 100 * age,
|
|
163
|
+
cachedInputTokens: 8e3,
|
|
164
|
+
cacheCreationTokens: 300,
|
|
165
|
+
outputTokens: 900 + 50 * age,
|
|
166
|
+
reasoningTokens: 100
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
records,
|
|
172
|
+
source: {
|
|
173
|
+
homePath: `fake://${input.instanceId}`,
|
|
174
|
+
volumeId: "fake",
|
|
175
|
+
status: "ok",
|
|
176
|
+
scannedFiles: FAKE_DAYS,
|
|
177
|
+
skippedFiles: 0
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
const redeemQuotaReset = async () => {
|
|
182
|
+
if (input.script !== "available") return { outcome: "nothingToReset" };
|
|
183
|
+
if (resetCredits <= 0) return { outcome: "noCredit" };
|
|
184
|
+
resetCredits -= 1;
|
|
185
|
+
sessionUsed = 0;
|
|
186
|
+
return { outcome: "reset" };
|
|
187
|
+
};
|
|
188
|
+
return { readQuota, readTokenUsage, redeemQuotaReset };
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/fakeInstance.ts
|
|
66
192
|
var yieldTick = () => Promise.resolve();
|
|
67
193
|
var EventBus = class {
|
|
68
194
|
#queued = [];
|
|
@@ -458,6 +584,7 @@ var createFakeInstance = (config, host) => {
|
|
|
458
584
|
return { threadId, turns: booked.turns };
|
|
459
585
|
},
|
|
460
586
|
events,
|
|
587
|
+
usage: createFakeUsage({ instanceId: host.instanceId, script: parseUsageScript(config) }),
|
|
461
588
|
dispose: async () => {
|
|
462
589
|
disposed = true;
|
|
463
590
|
inflight?.abort();
|
package/locales/en.json
CHANGED
|
@@ -5,5 +5,14 @@
|
|
|
5
5
|
"description": "What the fake executor answers to every message. Leave empty to use the built-in reply.",
|
|
6
6
|
"placeholder": "fake turn complete"
|
|
7
7
|
}
|
|
8
|
+
},
|
|
9
|
+
"usage": {
|
|
10
|
+
"window": {
|
|
11
|
+
"session": "Session (5 hours)",
|
|
12
|
+
"weekly": "Weekly"
|
|
13
|
+
},
|
|
14
|
+
"balance": {
|
|
15
|
+
"account": "Account balance"
|
|
16
|
+
}
|
|
8
17
|
}
|
|
9
18
|
}
|
package/locales/zh-CN.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-fake",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2696",
|
|
4
4
|
"description": "Minimal fake executor for plugin authors and host orchestration tests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"@types/node": "24.12.4",
|
|
22
22
|
"esbuild": "0.28.1",
|
|
23
23
|
"vite-plus": "0.2.2",
|
|
24
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
24
|
+
"@ycodium-ai/plugin-api": "0.2.2696",
|
|
25
|
+
"ycodium-executor-testing": "0.0.0"
|
|
25
26
|
},
|
|
26
27
|
"ycodium": {
|
|
27
28
|
"plugin": "./dist/index.js",
|