@context-action/core 0.8.6 → 0.9.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 +40 -10
- package/dist/index.cjs +637 -368
- package/dist/index.d.cts +91 -121
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +91 -121
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +632 -364
- package/dist/index.js.map +1 -1
- package/package.json +18 -25
package/README.md
CHANGED
|
@@ -53,6 +53,23 @@ await actions.dispatch('increment');
|
|
|
53
53
|
await actions.dispatch('setCount', 42);
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
## Tool protocol boundary
|
|
57
|
+
|
|
58
|
+
MCP, JSON Schema, provider conversion, action schemas, and approval queues are
|
|
59
|
+
owned by [`@context-action/tool-protocol`](../tool-protocol/README.md). Core
|
|
60
|
+
only owns action registration and execution. This keeps the runtime usable
|
|
61
|
+
without a tool-calling or Zod dependency.
|
|
62
|
+
|
|
63
|
+
Install the protocol package separately when an integration needs it:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install @context-action/tool-protocol zod
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The React-facing registry remains in `@context-action/react`; protocol symbols
|
|
70
|
+
such as `defineAction`, `listAllTools`, and `ToolManagementInterface` must be
|
|
71
|
+
imported from `@context-action/tool-protocol`.
|
|
72
|
+
|
|
56
73
|
## 🌟 Vanilla JavaScript Support
|
|
57
74
|
|
|
58
75
|
**@context-action/core works perfectly with vanilla JavaScript!** No React, Vue, or any framework required.
|
|
@@ -225,12 +242,21 @@ await actions.dispatch('backgroundTask', data, {
|
|
|
225
242
|
queuePriority: 5
|
|
226
243
|
});
|
|
227
244
|
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
});
|
|
245
|
+
// Wall-clock timeout (queue wait + retry delay included).
|
|
246
|
+
// Rejects with ActionTimeoutError while the internal operation drains safely.
|
|
247
|
+
await actions.dispatch('timedAction', data, { timeout: 5000 });
|
|
232
248
|
```
|
|
233
249
|
|
|
250
|
+
The default queue is single-slot. When a handler awaits another dispatch on
|
|
251
|
+
the **same** register, make that nested call explicit with `{ immediate: true }`
|
|
252
|
+
so it can run inside the current queue turn. Likewise, do not set
|
|
253
|
+
`queuePriority` on an awaited nested `dispatchWithResult` call. Independent
|
|
254
|
+
top-level dispatches should keep the queue defaults.
|
|
255
|
+
|
|
256
|
+
Handlers that perform cancellable I/O can observe `controller.signal`. It is
|
|
257
|
+
aborted for caller cancellation, timeout, provider teardown, and register
|
|
258
|
+
shutdown.
|
|
259
|
+
|
|
234
260
|
### Result Collection with Strategies
|
|
235
261
|
|
|
236
262
|
```typescript
|
|
@@ -406,7 +432,7 @@ actions.register('riskyOperation', async (data, controller) => {
|
|
|
406
432
|
// With retry configuration
|
|
407
433
|
await actions.dispatch('apiCall', data, {
|
|
408
434
|
retryOnError: {
|
|
409
|
-
maxAttempts: 3,
|
|
435
|
+
maxAttempts: 3, // Total attempts, including the first call
|
|
410
436
|
delay: 1000
|
|
411
437
|
}
|
|
412
438
|
});
|
|
@@ -440,8 +466,11 @@ const registry = new ActionRegister({ name: 'MyApp' });
|
|
|
440
466
|
|
|
441
467
|
// Use the registry...
|
|
442
468
|
|
|
443
|
-
//
|
|
444
|
-
registry.destroy();
|
|
469
|
+
// Begin terminal cleanup. New work is rejected immediately.
|
|
470
|
+
registry.destroy();
|
|
471
|
+
|
|
472
|
+
// Or await proof that started handlers settled and cleanup callbacks ran.
|
|
473
|
+
await registry.destroyAsync();
|
|
445
474
|
```
|
|
446
475
|
|
|
447
476
|
## API Reference
|
|
@@ -472,7 +501,8 @@ registry.destroy(); // Cleans up pipelines, guards, queues, stats
|
|
|
472
501
|
#### Utility Methods
|
|
473
502
|
- `getName()` - Get registry name
|
|
474
503
|
- `isDebugEnabled()` - Check if debug mode is enabled
|
|
475
|
-
- `destroy()` -
|
|
504
|
+
- `destroy()` - Begin terminal cleanup without waiting
|
|
505
|
+
- `destroyAsync()` - Resolve after started handlers settle and cleanup completes
|
|
476
506
|
|
|
477
507
|
### Configuration Interfaces
|
|
478
508
|
|
|
@@ -576,7 +606,7 @@ actions.destroy();
|
|
|
576
606
|
1. **Use handler IDs** for better debugging and filtering
|
|
577
607
|
2. **Enable replaceExisting** for React components to prevent duplicates
|
|
578
608
|
3. **Use immediate: false** (default) to benefit from queue optimizations
|
|
579
|
-
4. **
|
|
609
|
+
4. **Await destroyAsync()** when shutdown completion must be guaranteed
|
|
580
610
|
5. **Use priority filtering** instead of excludeHandlerIds for better performance
|
|
581
611
|
6. **Cache ActionRegister instances** - don't create new ones frequently
|
|
582
612
|
|
|
@@ -591,4 +621,4 @@ Apache-2.0
|
|
|
591
621
|
- [Vanilla JS Guide](../../docs/en/guide/vanilla-js-guide.md) - Complete vanilla JavaScript guide
|
|
592
622
|
- [Vanilla JS Examples](../../examples/vanilla-js/) - Interactive examples (counter, todo app)
|
|
593
623
|
- [React Package](../react/README.md) - React integration
|
|
594
|
-
- [Examples](../../example/README.md) - React example application
|
|
624
|
+
- [Examples](../../example/README.md) - React example application
|