nanocodex 0.2.0 → 0.3.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 +72 -13
- package/actions/events.mjs +105 -22
- package/actions/index.mjs +2 -0
- package/actions/session.d.mts +7 -1
- package/actions/session.mjs +10 -0
- package/actions/turn.d.mts +18 -5
- package/actions/turn.mjs +7 -2
- package/browser/Agent.d.mts +0 -3
- package/browser/Agent.mjs +12 -2
- package/browser/host.mjs +11 -7
- package/browser/index.d.mts +4 -0
- package/index.d.mts +4 -0
- package/internal.mjs +225 -24
- package/node/Agent.d.mts +0 -5
- package/node/Agent.mjs +9 -2
- package/node/host.mjs +33 -12
- package/node/index.d.mts +4 -0
- package/package.json +3 -3
- package/pkg-node/nanocodex.d.ts +69 -38
- package/pkg-node/nanocodex.js +193 -89
- package/pkg-node/nanocodex_bg.wasm +0 -0
- package/pkg-node/nanocodex_bg.wasm.d.ts +7 -2
- package/pkg-web/nanocodex.d.ts +76 -40
- package/pkg-web/nanocodex.js +191 -88
- package/pkg-web/nanocodex_bg.wasm +0 -0
- package/pkg-web/nanocodex_bg.wasm.d.ts +7 -2
- package/runtime/code-runtime.mjs +29 -12
- package/types.d.mts +38 -3
- package/scripts/check-package.mjs +0 -38
package/types.d.mts
CHANGED
|
@@ -22,9 +22,24 @@ export type AgentOptions = {
|
|
|
22
22
|
fastMode?: boolean | undefined;
|
|
23
23
|
sessionId?: string | undefined;
|
|
24
24
|
thinking?: Thinking | undefined;
|
|
25
|
+
workspace?: string | undefined;
|
|
25
26
|
resume?: SessionSnapshot | undefined;
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
export type EstimatedUsdCost = Readonly<{
|
|
30
|
+
usd: string;
|
|
31
|
+
input_usd: string;
|
|
32
|
+
cached_input_usd: string;
|
|
33
|
+
cache_write_input_usd: string;
|
|
34
|
+
output_usd: string;
|
|
35
|
+
service_tier: "standard" | "priority";
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
export type CostStatus =
|
|
39
|
+
| "estimated_from_usage"
|
|
40
|
+
| "usage_not_reported"
|
|
41
|
+
| "other";
|
|
42
|
+
|
|
28
43
|
export type SessionSnapshot = Readonly<{
|
|
29
44
|
version: number;
|
|
30
45
|
model: string;
|
|
@@ -36,7 +51,18 @@ export type SessionSnapshot = Readonly<{
|
|
|
36
51
|
history: readonly Record<string, unknown>[];
|
|
37
52
|
}>;
|
|
38
53
|
|
|
39
|
-
export type
|
|
54
|
+
export type TurnUsage = Readonly<{
|
|
55
|
+
input_tokens: number;
|
|
56
|
+
cached_input_tokens: number;
|
|
57
|
+
cache_write_input_tokens: number;
|
|
58
|
+
output_tokens: number;
|
|
59
|
+
reasoning_output_tokens: number;
|
|
60
|
+
total_tokens: number;
|
|
61
|
+
estimated_cost: EstimatedUsdCost | null;
|
|
62
|
+
cost_status: CostStatus;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
export type ForkOptions = { at?: TurnResult | undefined };
|
|
40
66
|
export type WatchEventsOptions = { includeAllSessions?: boolean | undefined };
|
|
41
67
|
|
|
42
68
|
export type EventWatcher = Readonly<{
|
|
@@ -50,9 +76,11 @@ export type AgentActions = {
|
|
|
50
76
|
watch(options?: WatchEventsOptions): EventWatcher;
|
|
51
77
|
};
|
|
52
78
|
session: {
|
|
79
|
+
compact(): Promise<void>;
|
|
53
80
|
fork(options?: ForkOptions): Promise<DefaultAgent>;
|
|
54
81
|
setFastMode(enabled: boolean): Promise<void>;
|
|
55
82
|
setThinking(thinking: Thinking): Promise<void>;
|
|
83
|
+
shutdown(): Promise<void>;
|
|
56
84
|
spawn(): Promise<DefaultAgent>;
|
|
57
85
|
};
|
|
58
86
|
turn: {
|
|
@@ -69,6 +97,7 @@ export type Agent<extended extends object = {}> = {
|
|
|
69
97
|
extend<const extension extends object>(
|
|
70
98
|
decorator: (agent: Agent<extended>) => extension,
|
|
71
99
|
): Agent<extended & extension>;
|
|
100
|
+
/** Releases this JavaScript/WASM handle without joining unfinished turns. */
|
|
72
101
|
dispose(): void;
|
|
73
102
|
} & extended;
|
|
74
103
|
|
|
@@ -76,13 +105,19 @@ export type DefaultAgent = Agent<AgentActions>;
|
|
|
76
105
|
|
|
77
106
|
export type Turn<agent extends Agent<object> = Agent<object>> = Readonly<{
|
|
78
107
|
readonly agent: agent;
|
|
79
|
-
result(): Promise<
|
|
80
|
-
snapshot(): SessionSnapshot;
|
|
108
|
+
result(): Promise<TurnResult>;
|
|
81
109
|
steer(options: { input: PromptInput }): Promise<void>;
|
|
82
110
|
cancel(): Promise<void>;
|
|
111
|
+
/** Releases this handle without cancelling its accepted turn. */
|
|
83
112
|
dispose(): void;
|
|
84
113
|
}>;
|
|
85
114
|
|
|
115
|
+
export type TurnResult = Readonly<{
|
|
116
|
+
finalMessage: string;
|
|
117
|
+
snapshot: SessionSnapshot;
|
|
118
|
+
usage: TurnUsage;
|
|
119
|
+
}>;
|
|
120
|
+
|
|
86
121
|
export type ToolContext = {
|
|
87
122
|
callId: string;
|
|
88
123
|
parentCallId: string;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { readFile, stat } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
const root = new URL("../", import.meta.url);
|
|
5
|
-
const packageJson = JSON.parse(await readFile(new URL("package.json", root), "utf8"));
|
|
6
|
-
|
|
7
|
-
assert.equal(packageJson.name, "nanocodex");
|
|
8
|
-
assert.equal(packageJson.type, "module");
|
|
9
|
-
assert.equal(packageJson.publishConfig?.access, "public");
|
|
10
|
-
assert.equal(packageJson.exports?.["./browser"]?.import, "./browser/index.mjs");
|
|
11
|
-
assert.equal(packageJson.exports?.["./node"]?.import, "./node/index.mjs");
|
|
12
|
-
|
|
13
|
-
const requiredFiles = [
|
|
14
|
-
"browser/index.mjs",
|
|
15
|
-
"browser/index.d.mts",
|
|
16
|
-
"node/index.mjs",
|
|
17
|
-
"node/index.d.mts",
|
|
18
|
-
"pkg-web/nanocodex.js",
|
|
19
|
-
"pkg-web/nanocodex.d.ts",
|
|
20
|
-
"pkg-web/nanocodex_bg.wasm",
|
|
21
|
-
"pkg-node/nanocodex.js",
|
|
22
|
-
"pkg-node/nanocodex.d.ts",
|
|
23
|
-
"pkg-node/nanocodex_bg.wasm",
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
for (const file of requiredFiles) {
|
|
27
|
-
const metadata = await stat(new URL(file, root));
|
|
28
|
-
assert(metadata.isFile(), `${file} must be a file`);
|
|
29
|
-
assert(metadata.size > 0, `${file} must not be empty`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
for (const target of ["web", "node"]) {
|
|
33
|
-
const wasm = await readFile(new URL(`pkg-${target}/nanocodex_bg.wasm`, root));
|
|
34
|
-
assert(wasm.byteLength > 100_000, `pkg-${target} WASM is unexpectedly small`);
|
|
35
|
-
assert.deepEqual([...wasm.subarray(0, 4)], [0x00, 0x61, 0x73, 0x6d]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
console.log(`nanocodex@${packageJson.version} package artifacts are complete`);
|