nanocodex 0.4.0 → 0.6.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 +944 -78
- package/actions/events.mjs +14 -25
- package/actions/index.d.mts +1 -0
- package/actions/index.mjs +11 -1
- package/actions/session.d.mts +29 -1
- package/actions/session.mjs +22 -0
- package/actions/turn.d.mts +15 -6
- package/actions/turn.mjs +10 -0
- package/actions/voice.d.mts +26 -0
- package/actions/voice.mjs +54 -0
- package/browser/Agent.d.mts +41 -24
- package/browser/Agent.mjs +7 -84
- package/browser/ChatGptSubscription.d.mts +7 -0
- package/browser/ChatGptSubscription.mjs +19 -0
- package/browser/InlineAgent.mjs +267 -0
- package/browser/Transport.d.mts +80 -0
- package/browser/Transport.mjs +63 -0
- package/browser/Voice.d.mts +86 -0
- package/browser/Voice.mjs +316 -0
- package/browser/VoiceSession.mjs +763 -0
- package/browser/WorkerAgent.d.mts +65 -0
- package/browser/WorkerAgent.mjs +1467 -0
- package/browser/agent.worker.mjs +3 -0
- package/browser/config.d.mts +36 -0
- package/browser/config.mjs +439 -0
- package/browser/engine.mjs +13 -0
- package/browser/harness.mjs +55 -0
- package/browser/host.d.mts +33 -5
- package/browser/host.mjs +320 -26
- package/browser/hostManagedWebSocket.d.mts +14 -0
- package/browser/hostManagedWebSocket.mjs +110 -0
- package/browser/index.d.mts +64 -1
- package/browser/index.mjs +22 -1
- package/browser/indexeddb-durability-store.mjs +210 -0
- package/browser/workspace.d.mts +16 -0
- package/browser/workspace.mjs +107 -0
- package/cloud/Client.d.mts +83 -0
- package/cloud/Client.mjs +231 -0
- package/cloud/Decorator.d.mts +31 -0
- package/cloud/Decorator.mjs +37 -0
- package/cloud/Dialog.d.mts +113 -0
- package/cloud/Dialog.mjs +366 -0
- package/cloud/Errors.d.mts +22 -0
- package/cloud/Errors.mjs +39 -0
- package/cloud/Principal.d.mts +26 -0
- package/cloud/Principal.mjs +88 -0
- package/cloud/RemoteProvider.mjs +88 -0
- package/cloud/Transport.d.mts +47 -0
- package/cloud/Transport.mjs +454 -0
- package/cloud/actions/account.d.mts +9 -0
- package/cloud/actions/account.mjs +19 -0
- package/cloud/actions/agent.d.mts +18 -0
- package/cloud/actions/agent.mjs +429 -0
- package/cloud/actions/connection.d.mts +133 -0
- package/cloud/actions/connection.mjs +580 -0
- package/cloud/actions/grant.d.mts +10 -0
- package/cloud/actions/grant.mjs +12 -0
- package/cloud/actions/index.d.mts +7 -0
- package/cloud/actions/index.mjs +7 -0
- package/cloud/actions/machineUsd.d.mts +23 -0
- package/cloud/actions/machineUsd.mjs +37 -0
- package/cloud/actions/model.d.mts +12 -0
- package/cloud/actions/model.mjs +50 -0
- package/cloud/actions/mpp.d.mts +28 -0
- package/cloud/actions/mpp.mjs +39 -0
- package/cloud/index.d.mts +30 -0
- package/cloud/index.mjs +9 -0
- package/cloud/internal.mjs +533 -0
- package/cloud/mercator.mjs +108 -0
- package/cloud/server/HostPrincipal.d.mts +34 -0
- package/cloud/server/HostPrincipal.mjs +202 -0
- package/cloud/server/index.d.mts +1 -0
- package/cloud/server/index.mjs +1 -0
- package/cloud/types.d.mts +212 -0
- package/cloudflare/Agent.d.mts +136 -0
- package/cloudflare/Agent.mjs +784 -0
- package/cloudflare/egress-subject.mjs +19 -0
- package/cloudflare/egress.d.mts +41 -0
- package/cloudflare/egress.mjs +119 -0
- package/cloudflare/event-socket.mjs +316 -0
- package/cloudflare/index.d.mts +7 -0
- package/cloudflare/index.mjs +6 -0
- package/host/Agent.d.mts +55 -0
- package/host/Agent.mjs +1 -0
- package/host/index.d.mts +71 -0
- package/host/index.mjs +10 -0
- package/index.d.mts +46 -0
- package/index.mjs +11 -0
- package/internal.mjs +673 -61
- package/managed/Agent.d.mts +459 -0
- package/managed/Agent.mjs +1824 -0
- package/managed/ManagedError.d.mts +9 -0
- package/managed/ManagedError.mjs +8 -0
- package/managed/README.md +244 -0
- package/managed/Voice.mjs +209 -0
- package/managed/index.d.mts +22 -0
- package/managed/index.mjs +2 -0
- package/managed/internal.mjs +119 -0
- package/node/Agent.d.mts +35 -8
- package/node/Agent.mjs +116 -25
- package/node/ChatGptSubscription.d.mts +9 -0
- package/node/ChatGptSubscription.mjs +17 -0
- package/node/Transport.d.mts +41 -0
- package/node/Transport.mjs +46 -0
- package/node/host.mjs +99 -17
- package/node/index.d.mts +45 -1
- package/node/index.mjs +16 -1
- package/node/workspace.d.mts +10 -0
- package/node/workspace.mjs +198 -0
- package/package.json +145 -11
- package/pkg-node/nanocodex.d.ts +523 -11
- package/pkg-node/nanocodex.js +2038 -179
- package/pkg-node/nanocodex_bg.wasm.d.ts +100 -29
- package/pkg-web/.nanocodex-bindgen-stamp +6 -0
- package/pkg-web/nanocodex-build.json +1 -0
- package/pkg-web/nanocodex.d.ts +623 -40
- package/pkg-web/nanocodex.js +2031 -178
- package/pkg-web/nanocodex_bg.js +2667 -0
- package/pkg-web/nanocodex_bg.wasm +0 -0
- package/pkg-web/nanocodex_bg.wasm.d.ts +100 -29
- package/pkg-web/nanocodex_worker.js +9 -0
- package/runtime/chatgpt-subscription.mjs +212 -0
- package/runtime/cloudflare-durability-store.d.mts +26 -0
- package/runtime/cloudflare-durability-store.mjs +14 -0
- package/runtime/code-evaluator.worker.mjs +137 -0
- package/runtime/code-runtime.mjs +1 -243
- package/runtime/durability-store.d.mts +85 -0
- package/runtime/durability-store.mjs +752 -0
- package/runtime/durability.mjs +174 -0
- package/runtime/managed-transport.mjs +461 -0
- package/runtime/mcp-runtime.mjs +534 -0
- package/runtime/postgres-durability-store.d.mts +64 -0
- package/runtime/postgres-durability-store.mjs +581 -0
- package/runtime/quickjs-evaluator.d.mts +17 -0
- package/runtime/quickjs-evaluator.mjs +236 -0
- package/runtime/response-controls.mjs +42 -0
- package/runtime/response-lanes.mjs +72 -0
- package/runtime/responses-transport.mjs +22 -0
- package/runtime/subagents.d.mts +107 -0
- package/runtime/subagents.mjs +54 -0
- package/runtime/subscription-store.d.mts +8 -0
- package/runtime/subscription-store.mjs +42 -0
- package/runtime/tempo-provider.d.mts +125 -0
- package/runtime/tempo-provider.mjs +264 -0
- package/runtime/tool-configuration.mjs +1 -0
- package/runtime/tool-router.mjs +1 -0
- package/runtime/utf8.mjs +1 -0
- package/runtime/worker-evaluator.mjs +162 -0
- package/runtime/workspace.d.mts +1 -0
- package/runtime/workspace.mjs +1 -0
- package/tools/Tools.d.mts +56 -0
- package/tools/Tools.mjs +136 -0
- package/tools/artifact.d.mts +1 -0
- package/tools/artifact.mjs +1 -0
- package/tools/attachment.mjs +1 -0
- package/tools/bash.d.mts +1 -0
- package/tools/bash.mjs +1 -0
- package/tools/browser/accountInfo.mjs +795 -0
- package/tools/browser/browserBuffer.mjs +18 -0
- package/tools/browser/browserCompiler.mjs +155 -0
- package/tools/browser/browserEgress.mjs +161 -0
- package/tools/browser/browserPython.mjs +133 -0
- package/tools/browser/browserShell.mjs +1075 -0
- package/tools/browser/browserSprintf.mjs +4 -0
- package/tools/browser/browserSsh.mjs +201 -0
- package/tools/browser/browserZlib.mjs +136 -0
- package/tools/browser/compiler.worker.mjs +160 -0
- package/tools/browser/devTunnelsSshBrowser.mjs +13 -0
- package/tools/browser/index.d.mts +209 -0
- package/tools/browser/index.mjs +174 -0
- package/tools/browser/opfsGit.mjs +248 -0
- package/tools/browser/python.worker.mjs +114 -0
- package/tools/browser/threadGit.mjs +197 -0
- package/tools/browser/unsupportedNodeRsa.mjs +5 -0
- package/tools/browser/workspace.mjs +83 -0
- package/tools/dataset.d.mts +1 -0
- package/tools/dataset.mjs +1 -0
- package/tools/datasetContract.mjs +1 -0
- package/tools/datasetEngine.mjs +1 -0
- package/tools/hostedCatalog.d.mts +1 -0
- package/tools/hostedCatalog.mjs +1 -0
- package/tools/index.d.mts +49 -0
- package/tools/index.mjs +19 -0
- package/tools/namedTool.mjs +1 -0
- package/tools/repository-workspace.d.mts +1 -0
- package/tools/repository-workspace.mjs +1 -0
- package/tools/ssh.d.mts +1 -0
- package/tools/ssh.mjs +1 -0
- package/tools/standard.mjs +1 -0
- package/tools/standardDescriptions.mjs +1 -0
- package/types.d.mts +431 -16
- package/worker/ChatGptSubscription.d.mts +9 -0
- package/worker/ChatGptSubscription.mjs +29 -0
- package/worker/index.d.mts +18 -0
- package/worker/index.mjs +5 -0
- package/pkg-node/nanocodex_bg.wasm +0 -0
package/types.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type Thinking = "none" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
2
2
|
export type ReasoningMode = "standard" | "pro";
|
|
3
|
-
export type Model = "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-5.6-luna";
|
|
3
|
+
export type Model = "gpt-5.6-sol" | "gpt-5.6-terra" | "gpt-5.6-luna" | "gpt-6-astra";
|
|
4
4
|
|
|
5
5
|
export type PromptItem =
|
|
6
6
|
| { type: "text"; text: string }
|
|
@@ -18,7 +18,10 @@ export type AgentEvent = {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type AgentOptions = {
|
|
21
|
+
/** Replaces the selected model's built-in instructions. */
|
|
21
22
|
instructions?: string | undefined;
|
|
23
|
+
/** Appends host instructions while retaining the selected model's prompt. */
|
|
24
|
+
additionalInstructions?: string | undefined;
|
|
22
25
|
model?: Model | undefined;
|
|
23
26
|
reasoningMode?: ReasoningMode | undefined;
|
|
24
27
|
fastMode?: boolean | undefined;
|
|
@@ -28,13 +31,248 @@ export type AgentOptions = {
|
|
|
28
31
|
resume?: SessionSnapshot | undefined;
|
|
29
32
|
};
|
|
30
33
|
|
|
34
|
+
/** Model-visible facts for tools executing outside the embedding process. */
|
|
35
|
+
export type ExecutionEnvironment = Readonly<{
|
|
36
|
+
currentDate: string;
|
|
37
|
+
timezone: string;
|
|
38
|
+
projectInstructions?: string | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
|
|
41
|
+
/** Unsigned decimal revision. Strings preserve the complete Rust `u64` range. */
|
|
42
|
+
declare const durabilityRevisionBrand: unique symbol;
|
|
43
|
+
export type DurabilityRevision = string & {
|
|
44
|
+
readonly [durabilityRevisionBrand]: "NanocodexDurabilityRevision";
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Unsigned decimal owner generation. Strings preserve the complete Rust `u64` range. */
|
|
48
|
+
declare const durabilityFenceBrand: unique symbol;
|
|
49
|
+
export type DurabilityFence = string & {
|
|
50
|
+
readonly [durabilityFenceBrand]: "NanocodexDurabilityFence";
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type DurabilityStoredState = Readonly<{
|
|
54
|
+
revision: DurabilityRevision;
|
|
55
|
+
payload: string | null;
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
/** JSON-safe exact state archive used for an offline provider cutover. */
|
|
59
|
+
export type DurabilityPortableStateArchive = DurabilityStoredState & Readonly<{
|
|
60
|
+
format: "nanocodex-durability-state-v2";
|
|
61
|
+
stateId: string;
|
|
62
|
+
records: readonly DurabilityRecord[];
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
export type DurabilityExportCursor = string;
|
|
66
|
+
|
|
67
|
+
/** One deterministic page of the total-state replacement from `from` (exclusive) to `to` (inclusive). */
|
|
68
|
+
export type DurabilityPortableStatePage = Readonly<{
|
|
69
|
+
format: "nanocodex-durability-state-page-v2";
|
|
70
|
+
stateId: string;
|
|
71
|
+
from: DurabilityRevision;
|
|
72
|
+
/** SHA-256 over the UTF-8 JSON tuple `[from, fromPayload]`. */
|
|
73
|
+
fromDigest: string;
|
|
74
|
+
to: DurabilityRevision;
|
|
75
|
+
cursor: DurabilityExportCursor;
|
|
76
|
+
nextCursor: DurabilityExportCursor | null;
|
|
77
|
+
/** Total UTF-16 code units in the opaque state payload. */
|
|
78
|
+
payloadLength: number;
|
|
79
|
+
payload: string;
|
|
80
|
+
records: readonly DurabilityRecord[];
|
|
81
|
+
}>;
|
|
82
|
+
|
|
83
|
+
export type DurabilityExportPageRequest = Readonly<{
|
|
84
|
+
from: DurabilityRevision;
|
|
85
|
+
/** Digest of the exact state at `from`; omit only when `from` is revision zero. */
|
|
86
|
+
fromDigest?: string | undefined;
|
|
87
|
+
/** Omit on the first request to select the current source revision; repeat the returned `to`. */
|
|
88
|
+
to?: DurabilityRevision | undefined;
|
|
89
|
+
cursor?: DurabilityExportCursor | undefined;
|
|
90
|
+
/** UTF-16 code units per page. Defaults to 256 KiB and is capped at 1 MiB. */
|
|
91
|
+
limit?: number | undefined;
|
|
92
|
+
}>;
|
|
93
|
+
|
|
94
|
+
export type DurabilityAcquireRequest = Readonly<{
|
|
95
|
+
ownerId: string;
|
|
96
|
+
}>;
|
|
97
|
+
|
|
98
|
+
export type DurabilityAcquiredState = DurabilityStoredState & Readonly<{
|
|
99
|
+
ownerId: string;
|
|
100
|
+
fence: DurabilityFence;
|
|
101
|
+
}>;
|
|
102
|
+
|
|
103
|
+
export type DurabilityRecord = Readonly<{ key: string; value: string }>;
|
|
104
|
+
|
|
105
|
+
export type DurabilityReplaceRequest = Readonly<{
|
|
106
|
+
records: readonly DurabilityRecord[];
|
|
107
|
+
ownerId: string;
|
|
108
|
+
fence: DurabilityFence;
|
|
109
|
+
expectedRevision: DurabilityRevision;
|
|
110
|
+
payload: string;
|
|
111
|
+
}>;
|
|
112
|
+
|
|
113
|
+
export type DurabilityReplaceResult =
|
|
114
|
+
| Readonly<{ status: "replaced"; revision: DurabilityRevision }>
|
|
115
|
+
| Readonly<{ status: "fenced" }>
|
|
116
|
+
| Readonly<{ status: "conflict"; actualRevision: DurabilityRevision }>
|
|
117
|
+
| Readonly<{ status: "not_committed"; message: string }>;
|
|
118
|
+
|
|
119
|
+
/** Host capability consumed by the Rust/WASM durability driver. */
|
|
120
|
+
export type DurabilityStore = Readonly<{
|
|
121
|
+
readRecord(stateId: string, key: string): string | null | Promise<string | null>;
|
|
122
|
+
/** Optional single-query implementation; Rust requests at most 16 records. */
|
|
123
|
+
readRecords?(stateId: string, keys: readonly string[]): readonly (string | null)[] | Promise<readonly (string | null)[]>;
|
|
124
|
+
load(stateId: string): DurabilityStoredState | Promise<DurabilityStoredState>;
|
|
125
|
+
acquire(
|
|
126
|
+
stateId: string,
|
|
127
|
+
request: DurabilityAcquireRequest,
|
|
128
|
+
): DurabilityAcquiredState | Promise<DurabilityAcquiredState>;
|
|
129
|
+
replace(
|
|
130
|
+
stateId: string,
|
|
131
|
+
request: DurabilityReplaceRequest,
|
|
132
|
+
): DurabilityReplaceResult | Promise<DurabilityReplaceResult>;
|
|
133
|
+
}>;
|
|
134
|
+
|
|
135
|
+
/** Store that can atomically restore an exact revision into an empty destination. */
|
|
136
|
+
export type DurabilityPortableStore = DurabilityStore & Readonly<{
|
|
137
|
+
scanRecords(stateId: string, after?: string, limit?: number): readonly DurabilityRecord[] | Promise<readonly DurabilityRecord[]>;
|
|
138
|
+
importRecords(stateId: string, records: readonly DurabilityRecord[]): void | Promise<void>;
|
|
139
|
+
importState(
|
|
140
|
+
stateId: string,
|
|
141
|
+
state: DurabilityStoredState,
|
|
142
|
+
options?: Readonly<{
|
|
143
|
+
records?: readonly DurabilityRecord[];
|
|
144
|
+
expectedRevision?: DurabilityRevision | undefined;
|
|
145
|
+
/** When supplied, compare the complete expected state atomically before importing. */
|
|
146
|
+
expectedPayload?: string | null | undefined;
|
|
147
|
+
}> | undefined,
|
|
148
|
+
): DurabilityStoredState | Promise<DurabilityStoredState>;
|
|
149
|
+
}>;
|
|
150
|
+
|
|
151
|
+
/** In-process store for hosts that carry its snapshot across durable steps. */
|
|
152
|
+
export type MemoryDurabilityStore = DurabilityPortableStore & Readonly<{
|
|
153
|
+
stateId: string;
|
|
154
|
+
snapshot(): DurabilityStoredState;
|
|
155
|
+
}>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* SQLite scalar accepted by the generic adapter. Revision and fence numbers
|
|
159
|
+
* must be nonnegative safe integers; return exact decimal TEXT for larger values.
|
|
160
|
+
*/
|
|
161
|
+
export type DurabilitySqliteValue = string | number | null;
|
|
162
|
+
export type DurabilitySqliteRow = Record<string, DurabilitySqliteValue>;
|
|
163
|
+
|
|
164
|
+
export type DurabilitySqliteQuery = <Row extends DurabilitySqliteRow>(
|
|
165
|
+
sql: string,
|
|
166
|
+
args: readonly DurabilitySqliteValue[],
|
|
167
|
+
) => readonly Row[] | Promise<readonly Row[]>;
|
|
168
|
+
|
|
169
|
+
export type DurabilitySqliteTransaction = <Result>(
|
|
170
|
+
callback: (query: DurabilitySqliteQuery) => Result | Promise<Result>,
|
|
171
|
+
) => Result | Promise<Result>;
|
|
172
|
+
|
|
173
|
+
export type SqliteDurabilityStoreOptions = Readonly<{
|
|
174
|
+
transaction: DurabilitySqliteTransaction;
|
|
175
|
+
}>;
|
|
176
|
+
|
|
177
|
+
/** Unsigned decimal revision for opaque ChatGPT subscription state. */
|
|
178
|
+
declare const subscriptionRevisionBrand: unique symbol;
|
|
179
|
+
export type SubscriptionRevision = string & {
|
|
180
|
+
readonly [subscriptionRevisionBrand]: "NanocodexSubscriptionRevision";
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export type SubscriptionStoredValue = Readonly<{
|
|
184
|
+
revision: SubscriptionRevision;
|
|
185
|
+
payload?: string | undefined;
|
|
186
|
+
}>;
|
|
187
|
+
|
|
188
|
+
export type SubscriptionCommitRequest = Readonly<{
|
|
189
|
+
expectedRevision: SubscriptionRevision;
|
|
190
|
+
/** Opaque Rust-owned credential state. Hosts must store it as a secret. */
|
|
191
|
+
payload: string;
|
|
192
|
+
}>;
|
|
193
|
+
|
|
194
|
+
export type SubscriptionCommitResult =
|
|
195
|
+
| Readonly<{ status: "committed"; revision: SubscriptionRevision }>
|
|
196
|
+
| Readonly<{ status: "conflict"; actualRevision: SubscriptionRevision }>;
|
|
197
|
+
|
|
198
|
+
/** Generic secret persistence consumed by the Rust ChatGPT lifecycle. */
|
|
199
|
+
export type ChatGptSubscriptionStore = Readonly<{
|
|
200
|
+
load(id: string): SubscriptionStoredValue | Promise<SubscriptionStoredValue>;
|
|
201
|
+
compareAndSwap(
|
|
202
|
+
id: string,
|
|
203
|
+
request: SubscriptionCommitRequest,
|
|
204
|
+
): SubscriptionCommitResult | Promise<SubscriptionCommitResult>;
|
|
205
|
+
}>;
|
|
206
|
+
|
|
207
|
+
export type MemoryChatGptSubscriptionStore = ChatGptSubscriptionStore & Readonly<{
|
|
208
|
+
id: string;
|
|
209
|
+
snapshot(): SubscriptionStoredValue;
|
|
210
|
+
}>;
|
|
211
|
+
|
|
212
|
+
export type ChatGptCredentialSeed = Readonly<{
|
|
213
|
+
accessToken: string;
|
|
214
|
+
refreshToken?: string | undefined;
|
|
215
|
+
accountId: string;
|
|
216
|
+
fedramp?: boolean | undefined;
|
|
217
|
+
}>;
|
|
218
|
+
|
|
219
|
+
export type ChatGptLoginStatus =
|
|
220
|
+
| Readonly<{ state: "signed_out" | "expired" }>
|
|
221
|
+
| Readonly<{
|
|
222
|
+
state: "pending";
|
|
223
|
+
verificationUrl: string;
|
|
224
|
+
userCode: string;
|
|
225
|
+
expiresAt: number;
|
|
226
|
+
pollAfterMs: number;
|
|
227
|
+
}>
|
|
228
|
+
| Readonly<{
|
|
229
|
+
state: "authenticated";
|
|
230
|
+
accountId: string;
|
|
231
|
+
expiresAt: number | null;
|
|
232
|
+
}>;
|
|
233
|
+
|
|
234
|
+
export type ChatGptCredential = Readonly<{
|
|
235
|
+
kind: "chatgpt";
|
|
236
|
+
/** Resolved bearer credential. Do not retain or log it. */
|
|
237
|
+
accessToken: string;
|
|
238
|
+
accountId: string;
|
|
239
|
+
fedramp: boolean;
|
|
240
|
+
revision: SubscriptionRevision;
|
|
241
|
+
}>;
|
|
242
|
+
|
|
243
|
+
export type ChatGptSubscriptionHandle = Readonly<{
|
|
244
|
+
id: string;
|
|
245
|
+
startLogin(): Promise<ChatGptLoginStatus>;
|
|
246
|
+
status(): Promise<ChatGptLoginStatus>;
|
|
247
|
+
credential(): Promise<ChatGptCredential>;
|
|
248
|
+
recover(rejectedRevision: SubscriptionRevision): Promise<ChatGptCredential>;
|
|
249
|
+
logout(): Promise<void>;
|
|
250
|
+
dispose(): void;
|
|
251
|
+
}>;
|
|
252
|
+
|
|
253
|
+
export type ChatGptSubscriptionOptions = Readonly<{
|
|
254
|
+
id: string;
|
|
255
|
+
store: ChatGptSubscriptionStore;
|
|
256
|
+
/** Generic bounded HTTP capability; defaults to global fetch. */
|
|
257
|
+
fetch?: typeof globalThis.fetch | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Trusted initial credentials, typically imported from Codex auth.json.
|
|
260
|
+
* A same-account seed repairs stored access-only credentials; refreshable durable state wins.
|
|
261
|
+
*/
|
|
262
|
+
seed?: ChatGptCredentialSeed | undefined;
|
|
263
|
+
/** Test-only local issuer override. */
|
|
264
|
+
issuer?: string | undefined;
|
|
265
|
+
/** Browser WASM module compiled from the same nanocodex package. */
|
|
266
|
+
module?: unknown;
|
|
267
|
+
}>;
|
|
268
|
+
|
|
31
269
|
export type EstimatedUsdCost = Readonly<{
|
|
32
270
|
usd: string;
|
|
33
271
|
input_usd: string;
|
|
34
272
|
cached_input_usd: string;
|
|
35
273
|
cache_write_input_usd: string;
|
|
36
274
|
output_usd: string;
|
|
37
|
-
service_tier: "standard" | "priority";
|
|
275
|
+
service_tier: "standard" | "priority" | "fast";
|
|
38
276
|
}>;
|
|
39
277
|
|
|
40
278
|
export type CostStatus =
|
|
@@ -64,9 +302,20 @@ export type TurnUsage = Readonly<{
|
|
|
64
302
|
cost_status: CostStatus;
|
|
65
303
|
}>;
|
|
66
304
|
|
|
67
|
-
export type ForkOptions = { at?: TurnResult | undefined }
|
|
305
|
+
export type ForkOptions = Readonly<{ at?: TurnResult | undefined }>;
|
|
68
306
|
export type WatchEventsOptions = { includeAllSessions?: boolean | undefined };
|
|
69
307
|
|
|
308
|
+
/** Read-only model context captured at the latest safe agent boundary. */
|
|
309
|
+
export type AgentSessionContext = Readonly<{
|
|
310
|
+
workspace: string;
|
|
311
|
+
history: readonly Record<string, unknown>[];
|
|
312
|
+
}>;
|
|
313
|
+
|
|
314
|
+
export type RealtimeTranscriptEntry = Readonly<{
|
|
315
|
+
role: "user" | "assistant";
|
|
316
|
+
text: string;
|
|
317
|
+
}>;
|
|
318
|
+
|
|
70
319
|
export type EventWatcher = Readonly<{
|
|
71
320
|
onEvent(listener: (event: AgentEvent) => void): () => void;
|
|
72
321
|
off(): void;
|
|
@@ -78,19 +327,37 @@ export type AgentActions = {
|
|
|
78
327
|
watch(options?: WatchEventsOptions): EventWatcher;
|
|
79
328
|
};
|
|
80
329
|
session: {
|
|
330
|
+
appendDeveloperMessage(text: string): Promise<AgentSessionContext>;
|
|
81
331
|
compact(): Promise<void>;
|
|
332
|
+
context(): Promise<AgentSessionContext>;
|
|
82
333
|
fork(options?: ForkOptions): Promise<DefaultAgent>;
|
|
334
|
+
setModel(model: Model): Promise<void>;
|
|
83
335
|
setFastMode(enabled: boolean): Promise<void>;
|
|
84
336
|
setThinking(thinking: Thinking): Promise<void>;
|
|
85
337
|
shutdown(): Promise<void>;
|
|
86
338
|
spawn(): Promise<DefaultAgent>;
|
|
339
|
+
realtime: {
|
|
340
|
+
start(): Promise<AgentSessionContext>;
|
|
341
|
+
end(): Promise<AgentSessionContext>;
|
|
342
|
+
delegation(
|
|
343
|
+
input: string,
|
|
344
|
+
transcript?: readonly RealtimeTranscriptEntry[],
|
|
345
|
+
): Promise<string>;
|
|
346
|
+
tailDelegation(
|
|
347
|
+
transcript: readonly RealtimeTranscriptEntry[],
|
|
348
|
+
): Promise<string | undefined>;
|
|
349
|
+
};
|
|
87
350
|
};
|
|
88
351
|
turn: {
|
|
89
|
-
prompt(options: {
|
|
352
|
+
prompt(options: {
|
|
353
|
+
input: PromptInput;
|
|
354
|
+
id?: string | undefined;
|
|
355
|
+
}): Turn;
|
|
90
356
|
};
|
|
91
357
|
};
|
|
92
358
|
|
|
93
359
|
export type Agent<extended extends object = {}> = {
|
|
360
|
+
readonly agentId: string;
|
|
94
361
|
readonly key: string;
|
|
95
362
|
readonly name: string;
|
|
96
363
|
readonly sessionId: string;
|
|
@@ -105,34 +372,182 @@ export type Agent<extended extends object = {}> = {
|
|
|
105
372
|
|
|
106
373
|
export type DefaultAgent = Agent<AgentActions>;
|
|
107
374
|
|
|
375
|
+
/** Transport-independent Agent lifecycle shared by local and managed durable Agents. */
|
|
376
|
+
export type AgentLifecycle = {
|
|
377
|
+
readonly agentId: string;
|
|
378
|
+
readonly key: string;
|
|
379
|
+
readonly name: string;
|
|
380
|
+
readonly sessionId: string;
|
|
381
|
+
readonly type: string;
|
|
382
|
+
readonly uid: string;
|
|
383
|
+
dispose(): void;
|
|
384
|
+
events: {
|
|
385
|
+
watch(options?: WatchEventsOptions): EventWatcher;
|
|
386
|
+
};
|
|
387
|
+
session: {
|
|
388
|
+
/** Stops this client lifecycle. A managed shutdown never deletes the durable Agent. */
|
|
389
|
+
shutdown(): Promise<void>;
|
|
390
|
+
};
|
|
391
|
+
turn: {
|
|
392
|
+
prompt(options: {
|
|
393
|
+
input: PromptInput;
|
|
394
|
+
id?: string | undefined;
|
|
395
|
+
}): LifecycleTurn;
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export type LifecycleTurn = Readonly<{
|
|
400
|
+
readonly agent: Readonly<{
|
|
401
|
+
agentId: string;
|
|
402
|
+
key: string;
|
|
403
|
+
name: string;
|
|
404
|
+
sessionId: string;
|
|
405
|
+
type: string;
|
|
406
|
+
uid: string;
|
|
407
|
+
dispose(): void;
|
|
408
|
+
}>;
|
|
409
|
+
accepted(): Promise<string | undefined>;
|
|
410
|
+
result(): Promise<LifecycleTurnResult>;
|
|
411
|
+
steer(options: { input: PromptInput; messageId?: string }): Promise<void>;
|
|
412
|
+
/** Removes this identified steer only while it is still pending. */
|
|
413
|
+
withdrawSteer(options: { messageId: string }): Promise<boolean>;
|
|
414
|
+
cancel(): Promise<void>;
|
|
415
|
+
dispose(): void;
|
|
416
|
+
}>;
|
|
417
|
+
|
|
418
|
+
export type LifecycleTurnResult = Readonly<{
|
|
419
|
+
finalMessage: string;
|
|
420
|
+
/** Managed Agents may return null when the service did not report usage. */
|
|
421
|
+
usage(): Promise<TurnUsage | null>;
|
|
422
|
+
dispose(): void;
|
|
423
|
+
}>;
|
|
424
|
+
|
|
108
425
|
export type Turn<agent extends Agent<object> = Agent<object>> = Readonly<{
|
|
109
426
|
readonly agent: agent;
|
|
427
|
+
/**
|
|
428
|
+
* Waits for execution-policy admission and returns its durable request ID.
|
|
429
|
+
* Rejections are Errors whose `code` is `cancelled`, `blocked`, `conflict`,
|
|
430
|
+
* `retryable`, `reopen_required`, `invalid_request`, or `failed`.
|
|
431
|
+
*/
|
|
432
|
+
accepted(): Promise<string | undefined>;
|
|
433
|
+
/**
|
|
434
|
+
* Waits for the terminal result. A `reopen_required` rejection means this
|
|
435
|
+
* Agent is stale and the same durable turn may be resumed only on a new Agent.
|
|
436
|
+
*/
|
|
110
437
|
result(): Promise<TurnResult>;
|
|
111
|
-
steer(options: { input: PromptInput }): Promise<void>;
|
|
438
|
+
steer(options: { input: PromptInput; messageId?: string }): Promise<void>;
|
|
439
|
+
/** Removes this identified steer only while it is still pending. */
|
|
440
|
+
withdrawSteer(options: { messageId: string }): Promise<boolean>;
|
|
112
441
|
cancel(): Promise<void>;
|
|
113
442
|
/** Releases this handle without cancelling its accepted turn. */
|
|
114
443
|
dispose(): void;
|
|
115
444
|
}>;
|
|
116
445
|
|
|
446
|
+
declare const turnResultBrand: unique symbol;
|
|
447
|
+
/** Opaque completed-turn identity. Materialize large values explicitly and release it when done. */
|
|
117
448
|
export type TurnResult = Readonly<{
|
|
449
|
+
readonly [turnResultBrand]: "NanocodexTurnResult";
|
|
118
450
|
finalMessage: string;
|
|
119
|
-
snapshot: SessionSnapshot
|
|
120
|
-
usage: TurnUsage
|
|
451
|
+
snapshot(): Promise<SessionSnapshot>;
|
|
452
|
+
usage(): Promise<TurnUsage>;
|
|
453
|
+
dispose(): void;
|
|
121
454
|
}>;
|
|
122
455
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
456
|
+
import type { NamedTool, ToolMap } from "nanocodex-tools";
|
|
457
|
+
export type {
|
|
458
|
+
NamedTool,
|
|
459
|
+
SubagentToolContext,
|
|
460
|
+
Tool,
|
|
461
|
+
ToolContext,
|
|
462
|
+
ToolMap,
|
|
463
|
+
} from "nanocodex-tools";
|
|
464
|
+
|
|
465
|
+
/** Static JavaScript tools, optionally composed with Rust-backed extensions. */
|
|
466
|
+
export type ToolConfiguration<Extension = never> =
|
|
467
|
+
| ToolMap
|
|
468
|
+
| readonly (NamedTool | Extension)[]
|
|
469
|
+
| import("./tools/Tools.mjs").Tools;
|
|
470
|
+
|
|
471
|
+
export type CodeEvaluatorEnvironment = {
|
|
472
|
+
tools: Readonly<Record<string, (input: unknown) => Promise<unknown>>>;
|
|
473
|
+
toolDefinitions: readonly Record<string, unknown>[];
|
|
474
|
+
text(value: unknown): void;
|
|
475
|
+
image(value: unknown, detail?: string): void;
|
|
476
|
+
generatedImage(value: unknown): void;
|
|
477
|
+
audio(value: unknown): void;
|
|
478
|
+
notify(value: unknown): void;
|
|
479
|
+
yield_control(): void;
|
|
480
|
+
setTimeout(callback: () => void, delayMs?: number): number;
|
|
481
|
+
clearTimeout(timerId?: number): void;
|
|
482
|
+
store(key: string, value: unknown): void;
|
|
483
|
+
load(key: string): unknown;
|
|
484
|
+
exit(): never;
|
|
485
|
+
require?: unknown;
|
|
486
|
+
console?: Console;
|
|
487
|
+
/** Aborts the exact active Code Mode cell and all nested tool calls. */
|
|
488
|
+
signal: AbortSignal;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
export type CodeEvaluator = (
|
|
492
|
+
source: string,
|
|
493
|
+
environment: CodeEvaluatorEnvironment,
|
|
494
|
+
) => void | Promise<void>;
|
|
495
|
+
|
|
496
|
+
export type McpPayment = {
|
|
497
|
+
/** MPPx client methods, such as `tempo.session({ account, getClient, channelStore })`. */
|
|
498
|
+
methods: readonly unknown[];
|
|
499
|
+
/** Optional MPP method context forwarded for each paid MCP tool call. */
|
|
500
|
+
context?: unknown;
|
|
501
|
+
/** Called before MPPx creates a payment credential. */
|
|
502
|
+
onPaymentRequired?: ((challenge: unknown) => boolean | Promise<boolean>) | undefined;
|
|
503
|
+
orderChallenges?: ((challenges: readonly unknown[]) => readonly unknown[] | Promise<readonly unknown[]>) | undefined;
|
|
504
|
+
paymentPreferences?: unknown;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
export type McpClient = {
|
|
508
|
+
listTools(params?: { cursor?: string | undefined }, options?: Record<string, unknown>): Promise<{
|
|
509
|
+
tools: readonly McpTool[];
|
|
510
|
+
nextCursor?: string | undefined;
|
|
511
|
+
}>;
|
|
512
|
+
callTool(
|
|
513
|
+
params: { name: string; arguments?: Record<string, unknown> | undefined },
|
|
514
|
+
resultSchema?: unknown,
|
|
515
|
+
options?: Record<string, unknown>,
|
|
516
|
+
): Promise<unknown>;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
export type McpTool = {
|
|
520
|
+
name: string;
|
|
521
|
+
title?: string | undefined;
|
|
522
|
+
description?: string | undefined;
|
|
523
|
+
inputSchema?: Record<string, unknown> | undefined;
|
|
524
|
+
annotations?: Readonly<Record<string, unknown>> & {
|
|
525
|
+
readOnlyHint?: boolean | undefined;
|
|
526
|
+
} | undefined;
|
|
127
527
|
};
|
|
128
528
|
|
|
129
|
-
export type
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
529
|
+
export type McpServer = {
|
|
530
|
+
/** Public Streamable HTTP MCP endpoint. Omit when supplying an initialized client. */
|
|
531
|
+
url?: string | URL | undefined;
|
|
532
|
+
/** Existing MCP SDK-compatible client; Nanocodex does not close caller-owned clients. */
|
|
533
|
+
client?: McpClient | undefined;
|
|
534
|
+
description?: string | undefined;
|
|
535
|
+
headers?: HeadersInit | undefined;
|
|
536
|
+
fetch?: typeof globalThis.fetch | undefined;
|
|
537
|
+
payment?: McpPayment | undefined;
|
|
538
|
+
enabledTools?: readonly string[] | undefined;
|
|
539
|
+
disabledTools?: readonly string[] | undefined;
|
|
540
|
+
/** Declares every remote tool on this server safe for concurrent nested calls. */
|
|
541
|
+
supportsParallelToolCalls?: boolean | undefined;
|
|
542
|
+
/** Declares specific remote tool names safe for concurrent nested calls. */
|
|
543
|
+
parallelTools?: readonly string[] | undefined;
|
|
544
|
+
/** Synchronously reports whether this server may currently be discovered or called. */
|
|
545
|
+
isAvailable?: (() => boolean) | undefined;
|
|
546
|
+
startupTimeoutMs?: number | undefined;
|
|
547
|
+
timeoutMs?: number | undefined;
|
|
133
548
|
};
|
|
134
549
|
|
|
135
|
-
export type
|
|
550
|
+
export type McpServers = Record<string, string | URL | McpServer>;
|
|
136
551
|
|
|
137
552
|
/** A paid WebSocket session, such as an mppx Tempo session manager. */
|
|
138
553
|
export type MppSession = {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChatGptSubscriptionHandle,
|
|
3
|
+
ChatGptSubscriptionOptions,
|
|
4
|
+
} from "../types.mjs";
|
|
5
|
+
|
|
6
|
+
/** Opens the Rust-owned ChatGPT lifecycle in a module Worker. */
|
|
7
|
+
export function open(
|
|
8
|
+
options: Omit<ChatGptSubscriptionOptions, "module"> & { module: WebAssembly.Module },
|
|
9
|
+
): Promise<ChatGptSubscriptionHandle>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import init, { ChatGptSubscription as WasmChatGptSubscription } from "../pkg-web/nanocodex.js";
|
|
2
|
+
|
|
3
|
+
import { installHostBridge } from "../internal.mjs";
|
|
4
|
+
import { openSubscription } from "../runtime/chatgpt-subscription.mjs";
|
|
5
|
+
|
|
6
|
+
let initialization;
|
|
7
|
+
|
|
8
|
+
/** Opens the Rust-owned ChatGPT lifecycle in a module Worker. */
|
|
9
|
+
export async function open(options) {
|
|
10
|
+
installHostBridge();
|
|
11
|
+
if (options?.module === undefined) {
|
|
12
|
+
throw new TypeError("Worker ChatGptSubscription requires a precompiled WASM module");
|
|
13
|
+
}
|
|
14
|
+
await initialize(options.module);
|
|
15
|
+
return openSubscription(
|
|
16
|
+
options,
|
|
17
|
+
(config) => WasmChatGptSubscription.open(config),
|
|
18
|
+
// A Cloudflare isolate can outlive an evicted Durable Object instance.
|
|
19
|
+
// Rebind its stable subscription ID to the reconstructed instance.
|
|
20
|
+
{ replaceHost: true },
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function initialize(module) {
|
|
25
|
+
return initialization ??= init({ module_or_path: module }).catch((error) => {
|
|
26
|
+
initialization = undefined;
|
|
27
|
+
throw error;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createMemoryChatGptSubscriptionStore,
|
|
3
|
+
subscriptionRevision,
|
|
4
|
+
} from "../runtime/subscription-store.mjs";
|
|
5
|
+
export type {
|
|
6
|
+
ChatGptCredential,
|
|
7
|
+
ChatGptCredentialSeed,
|
|
8
|
+
ChatGptLoginStatus,
|
|
9
|
+
ChatGptSubscriptionHandle,
|
|
10
|
+
ChatGptSubscriptionOptions,
|
|
11
|
+
ChatGptSubscriptionStore,
|
|
12
|
+
MemoryChatGptSubscriptionStore,
|
|
13
|
+
SubscriptionCommitRequest,
|
|
14
|
+
SubscriptionCommitResult,
|
|
15
|
+
SubscriptionRevision,
|
|
16
|
+
SubscriptionStoredValue,
|
|
17
|
+
} from "../types.mjs";
|
|
18
|
+
export * as ChatGptSubscription from "./ChatGptSubscription.mjs";
|
package/worker/index.mjs
ADDED
|
Binary file
|