@h1r-ai/croche 0.5.2 → 0.5.4

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.
@@ -12,7 +12,9 @@ export declare class CrocheAgent implements AgentToolControls {
12
12
  private closing?;
13
13
  private ended;
14
14
  private hub;
15
- private handle;
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 handle;
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>;
@@ -56,25 +56,35 @@ export class CrocheAgent {
56
56
  closing;
57
57
  ended = false;
58
58
  hub;
59
- handle;
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.handle = handle;
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: () => call(() => handle.unobserve()) };
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: () => call(() => handle.closeProjection(id)),
73
- history: options => held(() => handle.history(id, options.before, options.limit)) };
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 call(() => this.handle.isClosed()); }
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
- handle;
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
  }
@@ -10,7 +10,7 @@ export interface ToolDeclaration {
10
10
  export type DeepPartial<T> = T extends readonly unknown[] ? T : T extends object ? {
11
11
  [K in keyof T]?: DeepPartial<T[K]>;
12
12
  } : T;
13
- export interface AgentConfig extends Pick<AppOptions, 'instructions' | 'markerGuide' | 'maxContextTokens' | 'maxOutputTokens' | 'maxIterations' | 'crocheTools' | 'heartbeat'> {
13
+ export interface AgentConfig extends Pick<AppOptions, 'instructions' | 'markerGuide' | 'maxContextTokens' | 'maxOutputTokens' | 'maxIterations' | 'crocheTools' | 'heartbeat' | 'temperature'> {
14
14
  toolGuide?: string;
15
15
  modes?: Record<string, {
16
16
  tools?: ToolDeclaration[];
package/dist/types.d.ts CHANGED
@@ -60,6 +60,9 @@ export interface ToolContext {
60
60
  * does not create a separate app-snapshot export.
61
61
  */
62
62
  export interface AppOptions {
63
+ /** Agent sampling: finite 0–2; absent uses a tuned default; null omits it. Structured
64
+ * calls always omit temperature. Studio delivery of this field requires schema 4 / SDK 0.5.3+. */
65
+ temperature?: number | null;
63
66
  instructions: string;
64
67
  /** App-authored guidance, verbatim at the start of run_tool's App tools section. */
65
68
  toolGuide?: string;
@@ -159,7 +162,9 @@ export interface HostOptions {
159
162
  * Background upkeep (default true): after each turn and every maintenanceIntervalMs, the
160
163
  * Runtime delivers its outbox of call reports and syncs balances, policy and the model
161
164
  * key. Browsers also check on a visible foreground return, coalesced within the interval.
162
- * Turns never wait for it. False disables the timer and foreground hook; call maintain() yourself.
165
+ * Turns never wait for it. False disables the timer and foreground hook. With
166
+ * CrocheRuntime.create, call maintain() yourself. With Croche.open, leave it on: that API has
167
+ * no maintain(), so call reports are kept and sent at the next open.
163
168
  */
164
169
  backgroundSync?: boolean;
165
170
  /**
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.2**, including the shared `Croche.open` project API.
68
+ - **Native Swift/Kotlin SDKs are published as 0.5.4**, 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,9 +73,10 @@ 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.2 are published on npm**. Use
77
- `npm install @h1r-ai/croche` and `npm install -g @h1r-ai/croche-cli`; check the installed
78
- version and command help. Publication alone does not prove the user's platform or first turn.
76
+ The TypeScript SDK, React Native SDK and CLI **0.5.4 are published on npm**. Use
77
+ `npm install @h1r-ai/croche` and `npm install -g @h1r-ai/croche-cli` without version suffixes;
78
+ for React Native, install `@h1r-ai/croche` and `@h1r-ai/croche-react-native` together. Commit
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.
79
80
  TODO verify: the matching release's first-turn and login workflows. The examples use
80
81
  `debugKey`, Studio **Debug keys**, and automatic connection setup; do not substitute a
81
82
  source build or guessed package. Native project API availability remains a separate gate.
@@ -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.2 is published on npm; a real first turn on the user’s
4
+ Windows verification pending. SDK 0.5.4 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.2 is published on npm; platform and login verification remain separate.
10
+ a command. CLI 0.5.4 is published on npm; platform and login verification remain separate.
11
11
  With installation permission:
12
12
 
13
13
  ```sh
@@ -100,7 +100,10 @@ croche config save croche.config.json --project PROJECT_ID
100
100
 
101
101
  Preserve the full project document. If no draft exists, prepare `schema: 2` with the complete
102
102
  app config in `config`, not the returned `null`. Use `schema: 3` when `crocheTools` sets an object for
103
- `web.search` (see the `croche` skill's web-search.md). On a conflict, keep the local edit, fetch the
103
+ `web.search` (see the `croche` skill's web-search.md). Use `schema: 4` when setting
104
+ `temperature`: number 0–2, absent uses a tuned default, null = omit. This field requires SDK 0.5.3+
105
+ and structured calls always omit it. Preserve schema 4 when later editing web tools;
106
+ never downlabel a document carrying temperature. On a conflict, keep the local edit, fetch the
104
107
  latest draft separately and reconcile; do not force an empty base or blindly overwrite.
105
108
  Saving affects debug-key apps, not production: every debug key follows drafts. Verify all tool
106
109
  handlers, allow sync and reopen; the change applies on the **next open after sync**, never
@@ -1,5 +1,15 @@
1
1
  # Allowed model IDs
2
2
 
3
+ ## Temperature (0.5.3)
4
+
5
+ The app's `config.temperature` is a finite number 0–2. Absent uses a tuned default;
6
+ null omits the parameter, overriding an inherited value. Structured calls always
7
+ omit it, even when the app set a number; summaries keep their current behavior.
8
+ Use project document schema 4 for this field. Cloud delivers schema 4 only to SDK
9
+ 0.5.3+ that report support; existing schema-2/3 documents keep their identities.
10
+ Local code config needs no explicit schema number. This is app configuration,
11
+ not a Croche setting or a host credential option.
12
+
3
13
  Use an exact ID below for the `model` field in a Croche project config. These are the IDs
4
14
  supported by the current SDK candidate; public package availability remains pending verification.
5
15
 
@@ -14,11 +14,14 @@ use the usage and limits shown in Studio, not a separate model-service setup.
14
14
  | Local Node check | `@h1r-ai/croche`, durable `FileStorage`, SDK debug key | Core `croche` skill |
15
15
  | React Native | `Croche` from `@h1r-ai/croche-react-native`, SDK-managed storage | [react-native.md](references/react-native.md) |
16
16
  | Web (local and production) | `Croche` on the app's Node backend, server key stays there | [web-backend.md](references/web-backend.md) |
17
- | iOS · Swift | SPM, exact **0.5.2**, `Croche.open` | [ios.md](references/ios.md) |
18
- | Android · Kotlin | Maven, exact **0.5.2**, `Croche.open` | [android.md](references/android.md) |
17
+ | iOS · Swift | SPM, **Up to Next Minor Version** from **0.5.2**, `Croche.open` | [ios.md](references/ios.md) |
18
+ | Android · Kotlin | Maven, **0.5.+**, `Croche.open` | [android.md](references/android.md) |
19
+
20
+ Install npm packages without a version suffix; the project lockfile records resolved versions.
21
+ Minor releases in 0.x may break compatibility, so the native ranges above stay within 0.5.x.
19
22
 
20
23
  Node.js 22+ on macOS/Linux; Windows verification pending. PowerShell syntax does not establish
21
- Windows support. SDK 0.5.2 is published on npm; verify the installed version and platform behavior.
24
+ Windows support. SDK 0.5.4 is published on npm; verify the installed version and platform behavior.
22
25
  Node and RN do not automatically load the CLI-created `.env`: Node needs `--env-file` or an
23
26
  existing dotenv loader, web secrets stay server-side only, and RN needs debug-only build config
24
27
  with no secret in release artifacts. Read the matching reference above before the first turn.
@@ -36,11 +39,12 @@ Use `croche-config` for the complete selection and next-open rules.
36
39
 
37
40
  ## Native gate
38
41
 
39
- **Native Swift and Kotlin SDKs are published as 0.5.2**, including the shared
42
+ **Native Swift and Kotlin SDKs are published as 0.5.4**, including the shared
40
43
  **project/agent `Croche.open` API**. Do not describe published SDKs as nonexistent.
41
44
  Installation and `Croche.open` first-turn examples are in [ios.md](references/ios.md)
42
45
  and [android.md](references/android.md). For a native request, read the matching reference,
43
- prepare the integration and resolve exactly 0.5.2. Verify simulator/emulator first turn
46
+ prepare the integration using the declared 0.5.x range and record its resolved version.
47
+ Verify simulator/emulator first turn
44
48
  and release credential exclusion in the target app. Do not substitute the native
45
49
  0.5.0 single-agent API or claim an example was run without running it. Use git-ignored `.xcconfig` (iOS) or
46
50
  `local.properties` (Android), wired only into Debug and excluded from Release at build time.
@@ -1,11 +1,11 @@
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.2** and
3
+ Use this guide for a native Android app, not the single-agent API. It targets **0.5.4** and
4
4
  `Croche.open` → `agent()` → `request()`.
5
5
 
6
- > Version 0.5.2 is published on Maven. Verify Gradle integration, emulator first turn and
6
+ > Version 0.5.4 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
- > If the exact package cannot be resolved, report that blocker; do not downgrade the API.
8
+ > If the package cannot be resolved within the declared range, report that blocker; do not downgrade the API.
9
9
 
10
10
  ## Install from Maven
11
11
 
@@ -21,16 +21,17 @@ dependencyResolutionManagement {
21
21
  }
22
22
  ```
23
23
 
24
- Add the exact dependency in `app/build.gradle.kts`:
24
+ Add the dependency range in `app/build.gradle.kts`:
25
25
 
26
26
  ```kotlin
27
27
  dependencies {
28
- implementation("ai.croche:croche-android:0.5.2")
28
+ implementation("ai.croche:croche-android:0.5.+")
29
29
  }
30
30
  ```
31
31
 
32
32
  The distribution supplies the native binary and dependency metadata. No manual Rust/NDK build
33
33
  or copied AAR is needed for this install path. Preserve the app's existing Android/Kotlin setup.
34
+ Minor releases in 0.x may break compatibility, so `0.5.+` stays within 0.5.x.
34
35
  Windows verification is pending; these Gradle examples are not a Windows support claim.
35
36
 
36
37
  ## One human step; the agent sets up the project
@@ -176,7 +177,8 @@ Choose a model using [Models](https://docs.croche.ai/models.md).
176
177
 
177
178
  ## Verify before shipping
178
179
 
179
- - Resolve exactly 0.5.2, build Debug and run on the selected emulator. Confirm a nonempty,
180
+ - Resolve the latest available 0.5.x patch, record the resolved version, build Debug and run on the
181
+ selected emulator. Confirm a nonempty,
180
182
  completed reply; report the real error if it fails. In Studio, inspect **Monitoring → Logs**
181
183
  with the development filter. Never paste credentials or private app data into the report.
182
184
  - Inspect a clean Release APK/AAB without printing secrets: no debug key in classes/resources,
@@ -1,30 +1,31 @@
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.2** and
3
+ Use this guide for a native iOS app, not the single-agent API. It targets **0.5.4** and
4
4
  `Croche.open` → `agent()` → `request()`.
5
5
 
6
- > Version 0.5.2 is published through SPM. Verify Xcode integration, simulator first turn and
6
+ > Version 0.5.4 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
- > If the exact package cannot be resolved, report that blocker; do not downgrade the API.
8
+ > If the package cannot be resolved within the declared range, report that blocker; do not downgrade the API.
9
9
 
10
10
  ## Install with Swift Package Manager
11
11
 
12
12
  Requires iOS 15+ and a Swift 6-capable Xcode. In Xcode, **File → Add Package Dependencies…**:
13
13
 
14
14
  - URL: `https://github.com/H1R-AI/croche-swift`
15
- - Dependency rule: **Exact Version**, **0.5.2**
15
+ - Dependency rule: **Up to Next Minor Version**, from **0.5.2**
16
16
  - Add the **CrocheRuntime** product to your app target; import `CrocheRuntime`.
17
17
 
18
18
  For a Swift package target, add the dependency and product to its existing manifest:
19
19
 
20
20
  ```swift
21
- .package(url: "https://github.com/H1R-AI/croche-swift", exact: "0.5.2")
21
+ .package(url: "https://github.com/H1R-AI/croche-swift", .upToNextMinor(from: "0.5.2"))
22
22
  // In the app target's dependencies:
23
23
  .product(name: "CrocheRuntime", package: "croche-swift")
24
24
  ```
25
25
 
26
26
  The distribution supplies the native binary; an app developer does not need a Rust toolchain.
27
- Do not replace the app's existing package dependencies.
27
+ Do not replace the app's existing package dependencies. Minor releases in 0.x may break
28
+ compatibility, so this range accepts 0.5.x patches from 0.5.2 and stops before 0.6.0.
28
29
 
29
30
  ## One human step; the agent sets up the project
30
31
 
@@ -156,7 +157,8 @@ Choose a model using [Models](https://docs.croche.ai/models.md).
156
157
 
157
158
  ## Verify before shipping
158
159
 
159
- - Resolve exactly 0.5.2, build Debug and run on the selected simulator. Confirm a nonempty,
160
+ - Resolve the configured 0.5.x range, record the resolved version, build Debug and run on the
161
+ selected simulator. Confirm a nonempty,
160
162
  completed reply; report the real error if it fails. In Studio, inspect **Monitoring → Logs**
161
163
  with the development filter. Never paste credentials or private app data into the report.
162
164
  - Inspect a clean Release archive without printing secrets: no debug key in the binary/plist,
@@ -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.2 packages are published on npm; use the app's existing package manager.
4
+ Version 0.5.4 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.2 recovery requires its reviewed API; do not translate this snippet by guesswork.
31
+ erased. Native 0.5.4 recovery requires its reviewed API; do not translate this snippet by guesswork.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1r-ai/croche",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -183,7 +183,7 @@ function _assertClass(instance, klass) {
183
183
  throw new Error(`expected instance of ${klass.name}`);
184
184
  }
185
185
  }
186
- function __wbg_adapter_10(arg0, arg1, arg2) {
186
+ function __wbg_adapter_6(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.__wbg_http_18b3e005e7618f7a = function(arg0, arg1, arg2, arg3) {
1232
+ imports.wbg.__wbg_http_e9b575fe3d265a7a = 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.__wbg_lock_904efb61fb548b1f = function(arg0, arg1, arg2) {
1254
+ imports.wbg.__wbg_lock_e0eaba7753ddb53e = 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.__wbg_nowMs_14c2a07c06614f73 = function(arg0) {
1288
+ imports.wbg.__wbg_nowMs_1ca5891a40094dae = 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.__wbg_random_679898e6bd0741ac = function(arg0, arg1) {
1310
+ imports.wbg.__wbg_random_1e43f80205bcda1a = 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.__wbg_readSecret_f65ef4b8ddd21804 = function(arg0, arg1, arg2) {
1317
+ imports.wbg.__wbg_readSecret_54824834e3c0cb53 = function(arg0, arg1, arg2) {
1318
1318
  const ret = arg0.readSecret(getStringFromWasm0(arg1, arg2));
1319
1319
  return ret;
1320
1320
  };
1321
- imports.wbg.__wbg_read_ce1fe505575c8a22 = function(arg0, arg1, arg2) {
1321
+ imports.wbg.__wbg_read_9c800ddb8c809500 = function(arg0, arg1, arg2) {
1322
1322
  const ret = arg0.read(getStringFromWasm0(arg1, arg2));
1323
1323
  return ret;
1324
1324
  };
1325
- imports.wbg.__wbg_removeSecret_0fb2f98faf247a00 = function(arg0, arg1, arg2) {
1325
+ imports.wbg.__wbg_removeSecret_9250e3320cd1ce02 = function(arg0, arg1, arg2) {
1326
1326
  const ret = arg0.removeSecret(getStringFromWasm0(arg1, arg2));
1327
1327
  return ret;
1328
1328
  };
1329
- imports.wbg.__wbg_remove_48ab8ef2bf887788 = function(arg0, arg1, arg2) {
1329
+ imports.wbg.__wbg_remove_ab1cab75d56111c0 = 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.__wbg_sleep_6f4058b67459cecd = function(arg0, arg1) {
1341
+ imports.wbg.__wbg_sleep_e48af34a7ce11555 = 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.__wbg_storeIdentity_77a87bc19ddddbc0 = function(arg0, arg1) {
1361
+ imports.wbg.__wbg_storeIdentity_6d65d77997c4e424 = 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.__wbg_tool_50b751b1e195c261 = function(arg0, arg1, arg2, arg3) {
1380
+ imports.wbg.__wbg_tool_c59f7574a5578ba1 = 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.__wbg_unlock_dc85d9ec9f810f34 = function(arg0, arg1, arg2) {
1392
+ imports.wbg.__wbg_unlock_679023430ed0a7ca = function(arg0, arg1, arg2) {
1393
1393
  const ret = arg0.unlock(getStringFromWasm0(arg1, arg2));
1394
1394
  return ret;
1395
1395
  };
1396
- imports.wbg.__wbg_utcOffsetMinutes_5c6173afedde38dc = function(arg0, arg1) {
1396
+ imports.wbg.__wbg_utcOffsetMinutes_0ba1ff47635aea27 = function(arg0, arg1) {
1397
1397
  const ret = arg0.utcOffsetMinutes(arg1);
1398
1398
  return ret;
1399
1399
  };
1400
- imports.wbg.__wbg_wake_0ae632fff1f043e5 = function(arg0, arg1) {
1400
+ imports.wbg.__wbg_wake_f83d318227a0c2ab = 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.__wbg_writeSecret_8ccdd2b3efc6f6f2 = function(arg0, arg1, arg2, arg3, arg4) {
1439
+ imports.wbg.__wbg_writeSecret_f07aee1666487fc5 = 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.__wbg_write_2073bd38037ca3be = function(arg0, arg1, arg2, arg3, arg4) {
1451
+ imports.wbg.__wbg_write_12da9c010f1662f3 = 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, __wbg_adapter_10);
1470
+ const ret = makeMutClosure(arg0, arg1, 215, __wbg_adapter_6);
1471
1471
  return ret;
1472
1472
  };
1473
1473
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
@@ -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.2';
17
+ export const SDK_VERSION = '0.5.4';
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 core!: WasmRuntime;
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.core.isClosed()) void this.core.cancelTurn().catch(() => {}); } // stops at the call
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.core.isClosed() ? 0 : Number(await this.core.clearQueued())));
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
- async close(): Promise<void> {
526
- this.removeForegroundListener?.();
527
- this.removeForegroundListener = undefined;
528
- if (this.wakeTimer) clearTimeout(this.wakeTimer);
529
- this.wakeTimer = undefined;
530
- this.ready = false;
531
- this.clearScheduleTimer();
532
- await held(this.core.close());
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.core?.tick().catch(() => {}); }, Math.max(0, atMs - Date.now()));
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