@h1r-ai/croche 0.5.3 → 0.5.5
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 +2 -2
- package/dist/core-bindgen.js +18 -18
- package/dist/core-runtime.d.ts +8 -2
- package/dist/core-runtime.js +33 -15
- package/dist/core-wasm-bytes.d.ts +3 -3
- package/dist/core-wasm-bytes.js +3 -3
- package/dist/project-core.d.ts +7 -2
- package/dist/project-core.js +50 -21
- package/docs/SKILL.md +2 -2
- package/docs/skills/croche/references/first-turn.md +1 -1
- package/docs/skills/croche-cli/SKILL.md +1 -1
- package/docs/skills/croche-platforms/SKILL.md +2 -2
- package/docs/skills/croche-platforms/references/android.md +2 -2
- package/docs/skills/croche-platforms/references/ios.md +2 -2
- package/docs/skills/croche-platforms/references/react-native.md +1 -1
- package/docs/skills/croche-troubleshoot/references/recovery.md +1 -1
- package/package.json +1 -1
- package/src/core-bindgen.ts +18 -18
- package/src/core-runtime.ts +31 -14
- package/src/core-wasm-bytes.ts +3 -3
- package/src/project-core.ts +53 -23
package/dist/project-core.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export declare class CrocheAgent implements AgentToolControls {
|
|
|
12
12
|
private closing?;
|
|
13
13
|
private ended;
|
|
14
14
|
private hub;
|
|
15
|
-
private
|
|
15
|
+
private closedInfo?;
|
|
16
|
+
private handleValue;
|
|
17
|
+
private get handle();
|
|
16
18
|
private host;
|
|
17
19
|
private constructor();
|
|
18
20
|
private initialize;
|
|
@@ -57,7 +59,10 @@ export declare class CrocheAgent implements AgentToolControls {
|
|
|
57
59
|
export declare class Croche {
|
|
58
60
|
private readonly agents;
|
|
59
61
|
private closing?;
|
|
60
|
-
private
|
|
62
|
+
private closedInfo?;
|
|
63
|
+
private handleValue?;
|
|
64
|
+
private get handle();
|
|
65
|
+
private set handle(value);
|
|
61
66
|
private pals;
|
|
62
67
|
private constructor();
|
|
63
68
|
static open(options: OpenOptions): Promise<Croche>;
|
package/dist/project-core.js
CHANGED
|
@@ -56,25 +56,35 @@ export class CrocheAgent {
|
|
|
56
56
|
closing;
|
|
57
57
|
ended = false;
|
|
58
58
|
hub;
|
|
59
|
-
|
|
59
|
+
closedInfo;
|
|
60
|
+
handleValue;
|
|
61
|
+
get handle() {
|
|
62
|
+
if (this.host.disposed)
|
|
63
|
+
throw new CrocheError('closed', 'The agent is closed.');
|
|
64
|
+
return this.handleValue;
|
|
65
|
+
}
|
|
60
66
|
host;
|
|
61
67
|
constructor() { }
|
|
62
68
|
initialize(handle, host) {
|
|
63
|
-
this.
|
|
69
|
+
this.handleValue = handle;
|
|
64
70
|
this.host = host;
|
|
71
|
+
// Port callbacks can outlive SDK close: look up the checked owner at dispatch, not the
|
|
72
|
+
// borrowed raw handle that close has freed. Teardown below is already fenced by Core.
|
|
65
73
|
const port = {
|
|
66
74
|
observe: (onEvent, onEnd) => {
|
|
67
|
-
call(() => handle.observe((event) => onEvent(JSON.parse(event)), (error) => onEnd(JSON.parse(error))));
|
|
68
|
-
return { close: () =>
|
|
75
|
+
call(() => this.handle.observe((event) => onEvent(JSON.parse(event)), (error) => onEnd(JSON.parse(error))));
|
|
76
|
+
return { close: () => { if (!host.closed)
|
|
77
|
+
call(() => handle.unobserve()); } };
|
|
69
78
|
},
|
|
70
79
|
select: (options, onEvent) => {
|
|
71
|
-
const id = call(() => handle.select(json(options), (event) => onEvent(JSON.parse(event))));
|
|
72
|
-
return { close: () =>
|
|
73
|
-
|
|
80
|
+
const id = call(() => this.handle.select(json(options), (event) => onEvent(JSON.parse(event))));
|
|
81
|
+
return { close: () => { if (!host.closed)
|
|
82
|
+
call(() => handle.closeProjection(id)); },
|
|
83
|
+
history: options => held(() => this.handle.history(id, options.before, options.limit)) };
|
|
74
84
|
},
|
|
75
85
|
send: (input, options) => host[receiptSend](input, options),
|
|
76
|
-
cancel: id => held(() => id === undefined ? handle.cancelTurn() : handle.cancel(id)),
|
|
77
|
-
readOutcome: async (id, from, captured) => JSON.parse(await held(() => handle.readOutcome(id, from, (event) => captured(JSON.parse(event))))),
|
|
86
|
+
cancel: id => held(() => id === undefined ? this.handle.cancelTurn() : this.handle.cancel(id)),
|
|
87
|
+
readOutcome: async (id, from, captured) => JSON.parse(await held(() => this.handle.readOutcome(id, from, (event) => captured(JSON.parse(event))))),
|
|
78
88
|
};
|
|
79
89
|
this.hub = new StreamHub(port);
|
|
80
90
|
}
|
|
@@ -85,14 +95,14 @@ export class CrocheAgent {
|
|
|
85
95
|
return agent;
|
|
86
96
|
};
|
|
87
97
|
}
|
|
88
|
-
get id() { return call(() => this.handle.agentId()); }
|
|
89
|
-
get instance() { return call(() => this.handle.instance()) ?? null; }
|
|
90
|
-
get created() { return call(() => this.handle.created()); }
|
|
91
|
-
get name() { return call(() => this.handle.name()) ?? null; }
|
|
92
|
-
get mode() { return call(() => this.handle.mode()) ?? null; }
|
|
98
|
+
get id() { return this.closedInfo ? this.closedInfo.id : call(() => this.handle.agentId()); }
|
|
99
|
+
get instance() { return this.closedInfo ? this.closedInfo.instance : call(() => this.handle.instance()) ?? null; }
|
|
100
|
+
get created() { return this.closedInfo ? this.closedInfo.created : call(() => this.handle.created()); }
|
|
101
|
+
get name() { return this.closedInfo ? this.closedInfo.name : call(() => this.handle.name()) ?? null; }
|
|
102
|
+
get mode() { return this.closedInfo ? this.closedInfo.mode : call(() => this.handle.mode()) ?? null; }
|
|
93
103
|
get visibleTools() {
|
|
94
104
|
return call(() => {
|
|
95
|
-
const names = this.handle.visibleTools();
|
|
105
|
+
const names = this.closedInfo ? this.closedInfo.visibleTools : this.handle.visibleTools();
|
|
96
106
|
return names == null ? null : JSON.parse(names);
|
|
97
107
|
});
|
|
98
108
|
}
|
|
@@ -102,7 +112,7 @@ export class CrocheAgent {
|
|
|
102
112
|
setMode(mode) {
|
|
103
113
|
return held(() => this.handle.setMode(mode ?? undefined));
|
|
104
114
|
}
|
|
105
|
-
get closed() { return
|
|
115
|
+
get closed() { return this.ended || this.host.closed; }
|
|
106
116
|
get logId() { return call(() => this.handle.logId()); }
|
|
107
117
|
sync() { return this.host.sync(); }
|
|
108
118
|
send(input, options = {}) {
|
|
@@ -147,6 +157,12 @@ export class CrocheAgent {
|
|
|
147
157
|
return this.closing ??= (async () => {
|
|
148
158
|
this.ended = true;
|
|
149
159
|
try {
|
|
160
|
+
// Preserve the small getters that Core permits after close, not its Session. Close
|
|
161
|
+
// joins Core's one drain; host.close then releases this exported owner once.
|
|
162
|
+
await held(() => this.handleValue.close());
|
|
163
|
+
this.closedInfo = { id: this.handleValue.agentId(), instance: this.handleValue.instance() ?? null,
|
|
164
|
+
created: this.handleValue.created(), name: this.handleValue.name() ?? null,
|
|
165
|
+
mode: this.handleValue.mode() ?? null, visibleTools: this.handleValue.visibleTools() };
|
|
150
166
|
await this.host.close();
|
|
151
167
|
}
|
|
152
168
|
finally {
|
|
@@ -159,7 +175,14 @@ export class CrocheAgent {
|
|
|
159
175
|
export class Croche {
|
|
160
176
|
agents = new Map();
|
|
161
177
|
closing;
|
|
162
|
-
|
|
178
|
+
closedInfo;
|
|
179
|
+
handleValue;
|
|
180
|
+
get handle() {
|
|
181
|
+
if (!this.handleValue)
|
|
182
|
+
throw new CrocheError('closed', 'The project is closed.');
|
|
183
|
+
return this.handleValue;
|
|
184
|
+
}
|
|
185
|
+
set handle(handle) { this.handleValue = handle; }
|
|
163
186
|
pals;
|
|
164
187
|
constructor() { }
|
|
165
188
|
static async open(options) {
|
|
@@ -218,10 +241,10 @@ export class Croche {
|
|
|
218
241
|
const factory = (_agent) => projectPal(options, () => options.user ?? null).host;
|
|
219
242
|
await held(() => core().WasmProject.deleteStore(factory, json(deleteWire(options))));
|
|
220
243
|
}
|
|
221
|
-
get user() { return call(() => this.handle.user()) ?? null; }
|
|
222
|
-
get installationId() { return call(() => this.handle.installationId()) ?? null; }
|
|
223
|
-
get crocheUserId() { return call(() => this.handle.crocheUserId()) ?? null; }
|
|
224
|
-
get agentIds() { return call(() => JSON.parse(this.handle.agentIds())); }
|
|
244
|
+
get user() { return this.closedInfo ? this.closedInfo.user : call(() => this.handle.user()) ?? null; }
|
|
245
|
+
get installationId() { return this.closedInfo ? this.closedInfo.installationId : call(() => this.handle.installationId()) ?? null; }
|
|
246
|
+
get crocheUserId() { return this.closedInfo ? this.closedInfo.crocheUserId : call(() => this.handle.crocheUserId()) ?? null; }
|
|
247
|
+
get agentIds() { return this.closedInfo ? [...this.closedInfo.agentIds] : call(() => JSON.parse(this.handle.agentIds())); }
|
|
225
248
|
async agent(id, options = {}) {
|
|
226
249
|
// Core prunes its closed slots on open; release the corresponding JS handles and hosts too.
|
|
227
250
|
for (const [slot, agent] of this.agents) {
|
|
@@ -256,6 +279,12 @@ export class Croche {
|
|
|
256
279
|
finally {
|
|
257
280
|
await Promise.all([...this.agents.values()].map(agent => agent.close()));
|
|
258
281
|
}
|
|
282
|
+
this.closedInfo = { user: this.handle.user() ?? null, installationId: this.handle.installationId() ?? null,
|
|
283
|
+
crocheUserId: this.handle.crocheUserId() ?? null, agentIds: JSON.parse(this.handle.agentIds()) };
|
|
284
|
+
this.handleValue?.free();
|
|
285
|
+
this.handleValue = undefined;
|
|
286
|
+
this.agents.clear();
|
|
287
|
+
this.pals.clear();
|
|
259
288
|
})();
|
|
260
289
|
}
|
|
261
290
|
}
|
package/docs/SKILL.md
CHANGED
|
@@ -65,7 +65,7 @@ Choose the matching path:
|
|
|
65
65
|
|
|
66
66
|
- **Node script or web backend:** `@h1r-ai/croche`, Node.js 22+ on macOS/Linux.
|
|
67
67
|
- **React Native:** `@h1r-ai/croche` + `@h1r-ai/croche-react-native`; same project/agent API.
|
|
68
|
-
- **Native Swift/Kotlin SDKs are published as 0.5.
|
|
68
|
+
- **Native Swift/Kotlin SDKs are published as 0.5.5**, including the shared `Croche.open` project API.
|
|
69
69
|
Read the `croche-platforms` iOS/Android reference for installation and the first turn.
|
|
70
70
|
Verify package resolution and native execution in the target app; publication is not a test pass.
|
|
71
71
|
If its exact release is unavailable, offer TypeScript/React Native as an alternative, not an
|
|
@@ -73,7 +73,7 @@ Choose the matching path:
|
|
|
73
73
|
- **Windows:** verification pending; command forms are not a support claim. Use the
|
|
74
74
|
detected shell rather than assuming Bash; `croche-cli` has PowerShell guidance.
|
|
75
75
|
|
|
76
|
-
The TypeScript SDK, React Native SDK and CLI **0.5.
|
|
76
|
+
The TypeScript SDK, React Native SDK and CLI **0.5.5 are published on npm**. Use
|
|
77
77
|
`npm install @h1r-ai/croche` and `npm install -g @h1r-ai/croche-cli` without version suffixes;
|
|
78
78
|
for React Native, install `@h1r-ai/croche` and `@h1r-ai/croche-react-native` together. Commit
|
|
79
79
|
the project lockfile to record resolved versions. Check the installed version and command help. Publication alone does not prove the user's platform or first turn.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Node: one real reply
|
|
2
2
|
|
|
3
3
|
Use for a Node script or the first local check before adding UI. Node.js 22+ on macOS/Linux;
|
|
4
|
-
Windows verification pending. SDK 0.5.
|
|
4
|
+
Windows verification pending. SDK 0.5.5 is published on npm; a real first turn on the user’s
|
|
5
5
|
platform still needs verification. With installation permission, install the published SDK:
|
|
6
6
|
|
|
7
7
|
```sh
|
|
@@ -7,7 +7,7 @@ description: Use the Croche CLI to create an app project and private debug-key f
|
|
|
7
7
|
|
|
8
8
|
Do the permitted CLI work and explain the next user action. Node.js 22+ on macOS/Linux;
|
|
9
9
|
Windows verification pending. Check `croche --help` and installed version before relying on
|
|
10
|
-
a command. CLI 0.5.
|
|
10
|
+
a command. CLI 0.5.5 is published on npm; platform and login verification remain separate.
|
|
11
11
|
With installation permission:
|
|
12
12
|
|
|
13
13
|
```sh
|
|
@@ -21,7 +21,7 @@ Install npm packages without a version suffix; the project lockfile records reso
|
|
|
21
21
|
Minor releases in 0.x may break compatibility, so the native ranges above stay within 0.5.x.
|
|
22
22
|
|
|
23
23
|
Node.js 22+ on macOS/Linux; Windows verification pending. PowerShell syntax does not establish
|
|
24
|
-
Windows support. SDK 0.5.
|
|
24
|
+
Windows support. SDK 0.5.5 is published on npm; verify the installed version and platform behavior.
|
|
25
25
|
Node and RN do not automatically load the CLI-created `.env`: Node needs `--env-file` or an
|
|
26
26
|
existing dotenv loader, web secrets stay server-side only, and RN needs debug-only build config
|
|
27
27
|
with no secret in release artifacts. Read the matching reference above before the first turn.
|
|
@@ -39,7 +39,7 @@ Use `croche-config` for the complete selection and next-open rules.
|
|
|
39
39
|
|
|
40
40
|
## Native gate
|
|
41
41
|
|
|
42
|
-
**Native Swift and Kotlin SDKs are published as 0.5.
|
|
42
|
+
**Native Swift and Kotlin SDKs are published as 0.5.5**, including the shared
|
|
43
43
|
**project/agent `Croche.open` API**. Do not describe published SDKs as nonexistent.
|
|
44
44
|
Installation and `Croche.open` first-turn examples are in [ios.md](references/ios.md)
|
|
45
45
|
and [android.md](references/android.md). For a native request, read the matching reference,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Android · Kotlin project API
|
|
2
2
|
|
|
3
|
-
Use this guide for a native Android app, not the single-agent API. It targets **0.5.
|
|
3
|
+
Use this guide for a native Android app, not the single-agent API. It targets **0.5.5** and
|
|
4
4
|
`Croche.open` → `agent()` → `request()`.
|
|
5
5
|
|
|
6
|
-
> Version 0.5.
|
|
6
|
+
> Version 0.5.5 is published on Maven. Verify Gradle integration, emulator first turn and
|
|
7
7
|
> release credential exclusion in the target app; package publication is not proof of those checks.
|
|
8
8
|
> If the package cannot be resolved within the declared range, report that blocker; do not downgrade the API.
|
|
9
9
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# iOS · Swift project API
|
|
2
2
|
|
|
3
|
-
Use this guide for a native iOS app, not the single-agent API. It targets **0.5.
|
|
3
|
+
Use this guide for a native iOS app, not the single-agent API. It targets **0.5.5** and
|
|
4
4
|
`Croche.open` → `agent()` → `request()`.
|
|
5
5
|
|
|
6
|
-
> Version 0.5.
|
|
6
|
+
> Version 0.5.5 is published through SPM. Verify Xcode integration, simulator first turn and
|
|
7
7
|
> release credential exclusion in the target app; package publication is not proof of those checks.
|
|
8
8
|
> If the package cannot be resolved within the declared range, report that blocker; do not downgrade the API.
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# React Native
|
|
2
2
|
|
|
3
3
|
Requirements: React Native 0.76+ with New Architecture, iOS 15.1+ / Android API 26+.
|
|
4
|
-
Version 0.5.
|
|
4
|
+
Version 0.5.5 packages are published on npm; use the app's existing package manager.
|
|
5
5
|
With permission:
|
|
6
6
|
|
|
7
7
|
```sh
|
|
@@ -28,4 +28,4 @@ agent without deleting the whole project directory or another user's data.
|
|
|
28
28
|
|
|
29
29
|
Do not apply this recipe blindly to custom single-agent storage or an instance-specific case;
|
|
30
30
|
confirm the installed SDK's scoped deletion API first. A busy store must be closed, not forcibly
|
|
31
|
-
erased. Native 0.5.
|
|
31
|
+
erased. Native 0.5.5 recovery requires its reviewed API; do not translate this snippet by guesswork.
|
package/package.json
CHANGED
package/src/core-bindgen.ts
CHANGED
|
@@ -183,7 +183,7 @@ function _assertClass(instance, klass) {
|
|
|
183
183
|
throw new Error(`expected instance of ${klass.name}`);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
function
|
|
186
|
+
function __wbg_adapter_8(arg0, arg1, arg2) {
|
|
187
187
|
wasm.closure216_externref_shim(arg0, arg1, arg2);
|
|
188
188
|
}
|
|
189
189
|
|
|
@@ -1229,7 +1229,7 @@ function __wbg_get_imports() {
|
|
|
1229
1229
|
const ret = Reflect.get(arg0, arg1);
|
|
1230
1230
|
return ret;
|
|
1231
1231
|
}, arguments) };
|
|
1232
|
-
imports.wbg.
|
|
1232
|
+
imports.wbg.__wbg_http_0ae0fcfc317bf166 = function(arg0, arg1, arg2, arg3) {
|
|
1233
1233
|
const ret = arg0.http(arg1, WasmSink.__wrap(arg2), WasmCancel.__wrap(arg3));
|
|
1234
1234
|
return ret;
|
|
1235
1235
|
};
|
|
@@ -1251,7 +1251,7 @@ function __wbg_get_imports() {
|
|
|
1251
1251
|
const ret = arg0.length;
|
|
1252
1252
|
return ret;
|
|
1253
1253
|
};
|
|
1254
|
-
imports.wbg.
|
|
1254
|
+
imports.wbg.__wbg_lock_d8b2d93e8e4dbedb = function(arg0, arg1, arg2) {
|
|
1255
1255
|
const ret = arg0.lock(getStringFromWasm0(arg1, arg2));
|
|
1256
1256
|
return ret;
|
|
1257
1257
|
};
|
|
@@ -1285,7 +1285,7 @@ function __wbg_get_imports() {
|
|
|
1285
1285
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
1286
1286
|
return ret;
|
|
1287
1287
|
};
|
|
1288
|
-
imports.wbg.
|
|
1288
|
+
imports.wbg.__wbg_nowMs_347154ac53d09f5f = function(arg0) {
|
|
1289
1289
|
const ret = arg0.nowMs();
|
|
1290
1290
|
return ret;
|
|
1291
1291
|
};
|
|
@@ -1307,26 +1307,26 @@ function __wbg_get_imports() {
|
|
|
1307
1307
|
const ret = arg0.queueMicrotask;
|
|
1308
1308
|
return ret;
|
|
1309
1309
|
};
|
|
1310
|
-
imports.wbg.
|
|
1310
|
+
imports.wbg.__wbg_random_a551b19d3d5dd99a = function(arg0, arg1) {
|
|
1311
1311
|
const ret = arg1.random();
|
|
1312
1312
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1313
1313
|
const len1 = WASM_VECTOR_LEN;
|
|
1314
1314
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1315
1315
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1316
1316
|
};
|
|
1317
|
-
imports.wbg.
|
|
1317
|
+
imports.wbg.__wbg_readSecret_1b3cc2793ffc53a8 = function(arg0, arg1, arg2) {
|
|
1318
1318
|
const ret = arg0.readSecret(getStringFromWasm0(arg1, arg2));
|
|
1319
1319
|
return ret;
|
|
1320
1320
|
};
|
|
1321
|
-
imports.wbg.
|
|
1321
|
+
imports.wbg.__wbg_read_0e11fbfd1437442d = function(arg0, arg1, arg2) {
|
|
1322
1322
|
const ret = arg0.read(getStringFromWasm0(arg1, arg2));
|
|
1323
1323
|
return ret;
|
|
1324
1324
|
};
|
|
1325
|
-
imports.wbg.
|
|
1325
|
+
imports.wbg.__wbg_removeSecret_02cb803d87b6b01a = function(arg0, arg1, arg2) {
|
|
1326
1326
|
const ret = arg0.removeSecret(getStringFromWasm0(arg1, arg2));
|
|
1327
1327
|
return ret;
|
|
1328
1328
|
};
|
|
1329
|
-
imports.wbg.
|
|
1329
|
+
imports.wbg.__wbg_remove_ff9817388427e99d = function(arg0, arg1, arg2) {
|
|
1330
1330
|
const ret = arg0.remove(getStringFromWasm0(arg1, arg2));
|
|
1331
1331
|
return ret;
|
|
1332
1332
|
};
|
|
@@ -1338,7 +1338,7 @@ function __wbg_get_imports() {
|
|
|
1338
1338
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
1339
1339
|
return ret;
|
|
1340
1340
|
}, arguments) };
|
|
1341
|
-
imports.wbg.
|
|
1341
|
+
imports.wbg.__wbg_sleep_b62cf103dff85d47 = function(arg0, arg1) {
|
|
1342
1342
|
const ret = arg0.sleep(arg1);
|
|
1343
1343
|
return ret;
|
|
1344
1344
|
};
|
|
@@ -1358,7 +1358,7 @@ function __wbg_get_imports() {
|
|
|
1358
1358
|
const ret = typeof window === 'undefined' ? null : window;
|
|
1359
1359
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
1360
1360
|
};
|
|
1361
|
-
imports.wbg.
|
|
1361
|
+
imports.wbg.__wbg_storeIdentity_671b20e35ed46a3f = function(arg0, arg1) {
|
|
1362
1362
|
const ret = arg1.storeIdentity();
|
|
1363
1363
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1364
1364
|
const len1 = WASM_VECTOR_LEN;
|
|
@@ -1377,7 +1377,7 @@ function __wbg_get_imports() {
|
|
|
1377
1377
|
const ret = arg0.then(arg1);
|
|
1378
1378
|
return ret;
|
|
1379
1379
|
};
|
|
1380
|
-
imports.wbg.
|
|
1380
|
+
imports.wbg.__wbg_tool_2282738d031c879d = function(arg0, arg1, arg2, arg3) {
|
|
1381
1381
|
let deferred0_0;
|
|
1382
1382
|
let deferred0_1;
|
|
1383
1383
|
try {
|
|
@@ -1389,15 +1389,15 @@ function __wbg_get_imports() {
|
|
|
1389
1389
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
1390
1390
|
}
|
|
1391
1391
|
};
|
|
1392
|
-
imports.wbg.
|
|
1392
|
+
imports.wbg.__wbg_unlock_e37306332974be1e = function(arg0, arg1, arg2) {
|
|
1393
1393
|
const ret = arg0.unlock(getStringFromWasm0(arg1, arg2));
|
|
1394
1394
|
return ret;
|
|
1395
1395
|
};
|
|
1396
|
-
imports.wbg.
|
|
1396
|
+
imports.wbg.__wbg_utcOffsetMinutes_0d97c0b98316556d = function(arg0, arg1) {
|
|
1397
1397
|
const ret = arg0.utcOffsetMinutes(arg1);
|
|
1398
1398
|
return ret;
|
|
1399
1399
|
};
|
|
1400
|
-
imports.wbg.
|
|
1400
|
+
imports.wbg.__wbg_wake_f4f21f17647c711b = function(arg0, arg1) {
|
|
1401
1401
|
arg0.wake(arg1);
|
|
1402
1402
|
};
|
|
1403
1403
|
imports.wbg.__wbg_wasmproject_new = function(arg0) {
|
|
@@ -1436,7 +1436,7 @@ function __wbg_get_imports() {
|
|
|
1436
1436
|
imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
|
|
1437
1437
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
1438
1438
|
};
|
|
1439
|
-
imports.wbg.
|
|
1439
|
+
imports.wbg.__wbg_writeSecret_1227ccc16863f7c0 = function(arg0, arg1, arg2, arg3, arg4) {
|
|
1440
1440
|
let deferred0_0;
|
|
1441
1441
|
let deferred0_1;
|
|
1442
1442
|
try {
|
|
@@ -1448,7 +1448,7 @@ function __wbg_get_imports() {
|
|
|
1448
1448
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
1449
1449
|
}
|
|
1450
1450
|
};
|
|
1451
|
-
imports.wbg.
|
|
1451
|
+
imports.wbg.__wbg_write_a466c5779132150a = function(arg0, arg1, arg2, arg3, arg4) {
|
|
1452
1452
|
let deferred0_0;
|
|
1453
1453
|
let deferred0_1;
|
|
1454
1454
|
try {
|
|
@@ -1467,7 +1467,7 @@ function __wbg_get_imports() {
|
|
|
1467
1467
|
};
|
|
1468
1468
|
imports.wbg.__wbindgen_cast_9bf690dfafdef3b5 = function(arg0, arg1) {
|
|
1469
1469
|
// Cast intrinsic for `Closure(Closure { dtor_idx: 215, function: Function { arguments: [Externref], shim_idx: 216, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1470
|
-
const ret = makeMutClosure(arg0, arg1, 215,
|
|
1470
|
+
const ret = makeMutClosure(arg0, arg1, 215, __wbg_adapter_8);
|
|
1471
1471
|
return ret;
|
|
1472
1472
|
};
|
|
1473
1473
|
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
package/src/core-runtime.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
|
|
15
15
|
// Mirrors the protocol default; kept standalone so published SDK imports need no workspace.
|
|
16
16
|
export const DEFAULT_MODEL = 'deepseek/deepseek-v4.1-flash';
|
|
17
|
-
export const SDK_VERSION = '0.5.
|
|
17
|
+
export const SDK_VERSION = '0.5.5';
|
|
18
18
|
const DEFAULT_MAINTENANCE_INTERVAL_MS = 60_000;
|
|
19
19
|
/** What one round of background upkeep did. */
|
|
20
20
|
export interface MaintenanceResult { ran: boolean; ok?: boolean; preempted?: boolean; pendingEvents?: number; error?: { code: string; message: string } }
|
|
@@ -158,7 +158,16 @@ const storeIds = new WeakMap<object, string>();
|
|
|
158
158
|
* the app's tool callbacks) and the typed API over it.
|
|
159
159
|
*/
|
|
160
160
|
export class CrocheRuntime {
|
|
161
|
-
private
|
|
161
|
+
private coreValue?: WasmRuntime;
|
|
162
|
+
private closing?: Promise<void>;
|
|
163
|
+
private get core(): WasmRuntime {
|
|
164
|
+
if (!this.coreValue) throw new CrocheError('closed', 'The Runtime is closed.');
|
|
165
|
+
return this.coreValue;
|
|
166
|
+
}
|
|
167
|
+
private set core(handle: WasmRuntime) { this.coreValue = handle; }
|
|
168
|
+
get disposed(): boolean { return this.coreValue === undefined; }
|
|
169
|
+
/** Internal PAL/stream cleanup must not call a disposed wasm-bindgen handle. */
|
|
170
|
+
get closed(): boolean { return this.disposed || this.core.isClosed(); }
|
|
162
171
|
private bindings = new Map<string, Binding>();
|
|
163
172
|
private debugObserver?: RuntimeDebugObserverOptions['onDebugEvent'];
|
|
164
173
|
private usageObserver?: (event: RuntimeUsageEvent) => void;
|
|
@@ -509,27 +518,35 @@ export class CrocheRuntime {
|
|
|
509
518
|
/** Stops the running turn only: messages sent while it ran still go, together, as the next turn
|
|
510
519
|
* (a send's own `signal` drops just that send while it is held; once its turn has started, the
|
|
511
520
|
* turn stops, for every send it carries). */
|
|
512
|
-
cancel(): void { if (!this.
|
|
521
|
+
cancel(): void { if (!this.closed) void this.core.cancelTurn().catch(() => {}); } // stops at the call
|
|
513
522
|
/** Drops the messages held behind the running turn (each send ends `cancelled`); returns how many. */
|
|
514
523
|
clearQueued(): Promise<number> {
|
|
515
|
-
return this.ordered(undefined, async () => (this.
|
|
524
|
+
return this.ordered(undefined, async () => (this.closed ? 0 : Number(await this.core.clearQueued())));
|
|
516
525
|
}
|
|
517
526
|
|
|
518
527
|
/** When the Runtime next wants upkeep, in epoch ms (the same unit as the `clock` option), or null.
|
|
519
528
|
* With an injected clock, call maintain() once clock() reaches it. */
|
|
520
|
-
wakeAt(): number | null { return this.core.wakeAt() ?? null; }
|
|
529
|
+
wakeAt(): number | null { return this.closed ? null : this.core.wakeAt() ?? null; }
|
|
521
530
|
|
|
522
531
|
/** The Core projection fence joins its synchronous listener, not buffered SDK/UI consumers.
|
|
523
532
|
* An app callback that waits for work on the closer's thread deadlocks under any
|
|
524
533
|
* wait-for-callback fence. A synchronous Core-listener self-close does not wait on itself. */
|
|
525
|
-
|
|
526
|
-
this.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
534
|
+
close(): Promise<void> {
|
|
535
|
+
return this.closing ??= (async () => {
|
|
536
|
+
this.removeForegroundListener?.();
|
|
537
|
+
this.removeForegroundListener = undefined;
|
|
538
|
+
if (this.wakeTimer) clearTimeout(this.wakeTimer);
|
|
539
|
+
this.wakeTimer = undefined;
|
|
540
|
+
this.ready = false;
|
|
541
|
+
this.clearScheduleTimer();
|
|
542
|
+
const handle = this.core;
|
|
543
|
+
await held(handle.close());
|
|
544
|
+
// Rust close drains/unlocks; it cannot drop the exported owner's reference. The PAL
|
|
545
|
+
// and observers point back to this SDK object, so GC cannot break that cross-language
|
|
546
|
+
// cycle. Release our owner once the drain ends, never while it still owns the store.
|
|
547
|
+
this.coreValue = undefined;
|
|
548
|
+
handle.free();
|
|
549
|
+
})();
|
|
533
550
|
}
|
|
534
551
|
|
|
535
552
|
private now(): number { try { return Date.parse(hostNow(this.options.clock)); } catch { return Number.NaN; } }
|
|
@@ -656,7 +673,7 @@ export class CrocheRuntime {
|
|
|
656
673
|
if (this.wakeTimer) clearTimeout(this.wakeTimer);
|
|
657
674
|
this.wakeTimer = undefined;
|
|
658
675
|
if (atMs === null) return;
|
|
659
|
-
this.wakeTimer = setTimeout(() => { this.wakeTimer = undefined; void this.
|
|
676
|
+
this.wakeTimer = setTimeout(() => { this.wakeTimer = undefined; void this.coreValue?.tick().catch(() => {}); }, Math.max(0, atMs - Date.now()));
|
|
660
677
|
(this.wakeTimer as { unref?: () => void }).unref?.();
|
|
661
678
|
},
|
|
662
679
|
// The whole pending set, after each durable change and at open. Without a store lock no
|