@cutos/core 4.0.1 → 4.0.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.
package/README.md CHANGED
@@ -17,14 +17,6 @@ Hardware Device/Driver APIs remain available as the compatibility layer, but new
17
17
  - `CoreAPI` is the main entry point for connecting to CUTOS runtime.
18
18
  - It provides Promise-first methods for reading platform, configuration, box, device, volume, proxy, and shell information.
19
19
 
20
- ### Capability And Provider
21
-
22
- - `cutos.capability(name)` creates a client for calling a CUTOS capability.
23
- - `cutos.provider(name)` creates a Node-side provider implementation.
24
- - `Capability.call()` maps to request-response IPC.
25
- - `Provider.method()` registers a method handler.
26
- - `Provider.emit()` publishes events to consumers.
27
-
28
20
  ### IPC
29
21
 
30
22
  - IPC is a lower-level channel API for local and cross-device communication.
@@ -52,16 +44,14 @@ Hardware Device/Driver APIs remain available as the compatibility layer, but new
52
44
 
53
45
  1. [Quick Start](#quick-start)
54
46
  2. [Platform API](#platform-api)
55
- 3. [Capability API](#capability-api)
56
- 4. [Provider API](#provider-api)
57
- 5. [IPC API](#ipc-api)
58
- 6. [Database API](#database-api)
59
- 7. [Notification API](#notification-api)
60
- 8. [Logger API](#logger-api)
61
- 9. [Error Model](#error-model)
62
- 10. [Capability Contract](#capability-contract)
63
- 11. [Mock Dev](#mock-dev)
64
- 12. [Documentation](#documentation)
47
+ 3. [IPC API](#ipc-api)
48
+ 4. [Database API](#database-api)
49
+ 5. [Notification API](#notification-api)
50
+ 6. [Logger API](#logger-api)
51
+ 7. [Error Model](#error-model)
52
+ 8. [Capability Contract](#capability-contract)
53
+ 9. [Mock Dev](#mock-dev)
54
+ 10. [Documentation](#documentation)
65
55
 
66
56
  # Quick Start
67
57
 
@@ -78,8 +68,7 @@ import {
78
68
  CoreAPI,
79
69
  CoreClass,
80
70
  CoreSimulator,
81
- CutosError,
82
- cutos
71
+ CutosError
83
72
  } from "@cutos/core"
84
73
  ```
85
74
 
@@ -95,49 +84,14 @@ During development, connect to a target CUTOS device:
95
84
  await CoreAPI.init("192.168.1.100")
96
85
  ```
97
86
 
98
- ## LWA: Consume A Capability
99
-
100
- ```ts
101
- await CoreAPI.init("localhost")
102
-
103
- const hello = cutos.capability("hello-device")
104
-
105
- const result = await hello.call<
106
- { message: string },
107
- { message: string }
108
- >("echo", { message: "hello" })
109
-
110
- console.log(result.message)
111
- ```
112
-
113
- ## Node: Implement A Provider
114
-
115
- ```ts
116
- await CoreAPI.init("localhost")
117
-
118
- const provider = cutos.provider("hello-device")
119
-
120
- provider.method<
121
- { message: string },
122
- { message: string }
123
- >("echo", async params => {
124
- return { message: params.message }
125
- })
126
-
127
- provider.emit("statusChanged", {
128
- status: "connected",
129
- message: "hello-device ready"
130
- })
131
- ```
132
-
133
87
  ## Mock Dev
134
88
 
135
89
  Use Mock Dev when developing an LWA without a local CUTOS Node.
136
90
 
137
91
  ```ts
138
- import { CoreAPI, cutos, installCutosMock } from "@cutos/core"
92
+ import { CoreAPI, CutosMock } from "@cutos/core"
139
93
 
140
- installCutosMock({
94
+ CutosMock.install({
141
95
  capabilities: {
142
96
  "hello-device": {
143
97
  methods: {
@@ -147,10 +101,13 @@ installCutosMock({
147
101
  }
148
102
  })
149
103
 
150
- await CoreAPI.init()
104
+ await CoreAPI.init("mock")
105
+ ```
106
+
107
+ For simple UI development, set the CUTOS host to `mock` and keep application code unchanged:
151
108
 
152
- const hello = cutos.capability("hello-device")
153
- const result = await hello.call("echo", { message: "hello" })
109
+ ```bash
110
+ VITE_CUTOS_BROKER_URL=mock
154
111
  ```
155
112
 
156
113
  Mock Dev is intended for UI and SDK integration development. Real IPC, WebView host behavior, and Node Provider behavior should still be verified with a CUTOS Node before release.
@@ -271,138 +228,6 @@ const pwd = await CoreAPI.shell<string>("pwd")
271
228
 
272
229
  Use this API carefully. It should not be exposed to untrusted LWA code without permissions.
273
230
 
274
- # Capability API
275
-
276
- ## cutos.capability
277
-
278
- Create a capability client.
279
-
280
- ```ts
281
- const capability = cutos.capability("hello-device")
282
- ```
283
-
284
- `CoreAPI.capability()` is equivalent.
285
-
286
- ```ts
287
- const capability = CoreAPI.capability("hello-device")
288
- ```
289
-
290
- ## capability.call
291
-
292
- Call a Provider method.
293
-
294
- ```ts
295
- const result = await capability.call<
296
- { message: string },
297
- { message: string }
298
- >("echo", { message: "hello" })
299
- ```
300
-
301
- Set a per-call timeout:
302
-
303
- ```ts
304
- await capability.call(
305
- "connect",
306
- { name: "demo" },
307
- { timeout: 3000 }
308
- )
309
- ```
310
-
311
- ## capability.on
312
-
313
- Subscribe to Provider events.
314
-
315
- ```ts
316
- const unsubscribe = capability.on<{
317
- status: "idle" | "connected" | "error"
318
- message?: string
319
- }>("statusChanged", data => {
320
- console.log(data.status)
321
- })
322
- ```
323
-
324
- ## capability.off
325
-
326
- Remove one listener or all listeners for an event.
327
-
328
- ```ts
329
- capability.off("statusChanged")
330
- ```
331
-
332
- ## capability.dispose
333
-
334
- Clear listeners and release the underlying subscription.
335
-
336
- ```ts
337
- capability.dispose()
338
- ```
339
-
340
- # Provider API
341
-
342
- ## cutos.provider
343
-
344
- Create a Provider.
345
-
346
- ```ts
347
- const provider = cutos.provider("hello-device")
348
- ```
349
-
350
- `CoreAPI.provider()` is equivalent.
351
-
352
- ```ts
353
- const provider = CoreAPI.provider("hello-device")
354
- ```
355
-
356
- ## provider.method
357
-
358
- Register a method handler.
359
-
360
- ```ts
361
- provider.method<
362
- { message: string },
363
- { message: string }
364
- >("echo", async params => {
365
- return { message: params.message }
366
- })
367
- ```
368
-
369
- Use `context` when raw command information is needed.
370
-
371
- ```ts
372
- provider.method<{ name: string }, { connected: boolean }>(
373
- "connect",
374
- async (params, context) => {
375
- console.log(context.command.cmd)
376
- return { connected: true }
377
- }
378
- )
379
- ```
380
-
381
- Throw `CutosError` for expected business errors.
382
-
383
- ```ts
384
- throw new CutosError("HELLO_DEVICE_UNAVAILABLE", "The hello device is unavailable.")
385
- ```
386
-
387
- ## provider.emit
388
-
389
- Emit an event.
390
-
391
- ```ts
392
- provider.emit("statusChanged", {
393
- status: "connected",
394
- message: "hello-device ready"
395
- })
396
- ```
397
-
398
- ## provider.dispose
399
-
400
- Clear methods and release the underlying command listener.
401
-
402
- ```ts
403
- provider.dispose()
404
- ```
405
-
406
231
  # IPC API
407
232
 
408
233
  IPC is a lower-level channel API. Prefer Capability/Provider for product APIs.
@@ -604,7 +429,7 @@ CUTOS 4.0 normalizes SDK errors to `CutosError`.
604
429
 
605
430
  ```ts
606
431
  try {
607
- await cutos.capability("hello-device").call("connect", { name: "demo" })
432
+ await CoreAPI.getPlatform()
608
433
  } catch (error) {
609
434
  if (error instanceof CutosError) {
610
435
  console.log(error.code)