@plumbus/ai-decision-laya 0.2.1 → 0.3.0-beta.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.
@@ -5,8 +5,13 @@
5
5
  | [framework.md](framework.md) | Installation, public exports, adapter boundary, usage rules |
6
6
  | [testing.md](testing.md) | Offline validation and live environment setup |
7
7
 
8
- Keep app business logic in Plumbus primitives and `ctx.*`. These packages do not
9
- add `ctx.ai.decide()` or automatic provider discovery yet. Never route model
10
- predictions directly around capability access checks or confirmation policy.
8
+ **Classification, categorization, provider/model selection, TypeSafe/Jev or Laya:**
9
+ read `node_modules/@plumbus/core/instructions/ai-classification.md` first (core
10
+ **0.8.0-beta.6+**), then [framework.md](framework.md) for this package.
11
+
12
+ Core 0.8.0-beta.6+ provides `ctx.ai.decide()` and also routes `ctx.ai.classify()`
13
+ to explicitly registered decision adapters. Keep app business logic in Plumbus
14
+ primitives and `ctx.*`. Never route predictions around capability access checks
15
+ or confirmation policy. Provider registration is explicit in `app/server.ts`.
11
16
 
12
17
  [Package README](../README.md) · [Monorepo guide](https://github.com/plumbus-framework/plumbus/blob/main/docs/ai/decision-providers.md)
@@ -4,7 +4,7 @@ Laya provider for self-hosted typed decision inference, with a persistent Python
4
4
 
5
5
  ## Install and ownership
6
6
 
7
- Install `@plumbus/ai-decision-laya` explicitly. Its core peer is exactly `"0.7.x"`.
7
+ Install `@plumbus/ai-decision-laya` explicitly. Its core peer is exactly `">=0.8.0-beta.0 <0.9.0"` (core 0.8 beta family).
8
8
  Consumers reuse Zod/testing utilities from core; do not install them separately.
9
9
  Use this package for bounded typed decisions. Use core generation and embeddings
10
10
  for text responses and vector inference.
@@ -14,7 +14,19 @@ Public exports: `createLayaDecisionAdapter` — construct an explicitly configur
14
14
  File map: `src/index.ts` is the public barrel, `src/__tests__/` exercises the public
15
15
  API, `instructions/` contains these recipes. Laya alone also ships `service/`.
16
16
 
17
- ## Minimal usage
17
+ ## Classification and model selection (core 0.8.0-beta.6+)
18
+
19
+ Read `node_modules/@plumbus/core/instructions/ai-classification.md` for the complete
20
+ registration and usage recipe. Call `ctx.ai.classify({ text, labels, provider, model,
21
+ threshold })` inside capabilities/flows. `provider` is your registered decision map
22
+ key; `model` is an optional endpoint-supported ID. Native `threshold` defaults to
23
+ 0.5 and returns all matching labels. Use `decide()` for richer questions.
24
+
25
+ Core records one `classify` cost row, including dispatched failures, with actual
26
+ model/usage and identity. Omitted `provider` still uses the text default. Keep
27
+ decision adapters under `decisions.providers`, separate from text providers.
28
+
29
+ ## Minimal usage (infrastructure / smoke testing)
18
30
 
19
31
  ```ts
20
32
  import { createLayaDecisionAdapter } from '@plumbus/ai-decision-laya';
@@ -33,7 +45,7 @@ console.log(result.answers.refund.probability);
33
45
  1. Keep capabilities, flows, access policy and `ctx.*` as the application implementation path.
34
46
  2. Construct adapters at a server-owned infrastructure boundary and inject them. Keep keys on the server.
35
47
  3. Treat direct adapter usage as protocol integration, not a replacement for core's security/budget/audit lifecycle.
36
- 4. With core 0.7.3+, use `ctx.ai.decide()` in capabilities/flows. Export `decisions = { providers, defaultProvider }` from `app/server.ts`; API and workers share it. Do not register decision adapters as completion providers.
48
+ 4. With core 0.8.0-beta.6+, use `ctx.ai.decide()` in capabilities/flows. Export `decisions = { providers, defaultProvider }` from `app/server.ts`; API and workers share it. Do not register decision adapters as completion providers.
37
49
  5. Preserve distributions and provider confidence separately. A high confidence value is not authorization or proof of correctness.
38
50
  6. Validate thresholds on the actual task/model/language. Unknown cost is `null`, not free.
39
51
  7. Pass `signal: ctx.signal` and `timeoutMs` where needed. Flow steps supply their signal by default.
@@ -18,7 +18,12 @@ Validate choices, scores, probabilities, actual model/routing, usage and unknown
18
18
  cost handling. Measure live accuracy and calibration separately from connection
19
19
  success. Do not assert a universal confidence cutoff or guaranteed live label.
20
20
 
21
- For core 0.7.3+ integration tests, configure `mockAI({ decide: result })` or a real
21
+ For core 0.8.0-beta.6+ classification, use `mockAI({ classify: ['billing'] })` and test
22
+ through `runCapability()` / `simulateFlow()`. Integration tests should assert
23
+ provider/model forwarding, zero/multiple matches, inclusive thresholds, and one
24
+ `classify` cost row. Use injected fetch; routine tests do not require live Laya.
25
+
26
+ For core 0.8.0-beta.6+ integration tests, configure `mockAI({ decide: result })` or a real
22
27
  `createAIService({ decisions, costTracker, onAICostRecorded })` with injected
23
28
  provider fetch. Assert exactly one cost row, identity, actual model/usage, unknown
24
29
  cost handling, billed validation failures, and budget rejection before dispatch.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumbus/ai-decision-laya",
3
- "version": "0.2.1",
3
+ "version": "0.3.0-beta.0",
4
4
  "description": "Self-hosted Laya typed decision adapter and Python reference service for Plumbus.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -36,17 +36,17 @@
36
36
  "node": ">=20.6.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@plumbus/core": "0.7.x"
39
+ "@plumbus/core": ">=0.8.0-beta.0 <0.9.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@biomejs/biome": "^2.4.6",
43
43
  "@types/node": "^25.4.0",
44
44
  "typescript": "^5.7.0",
45
45
  "vitest": "^3.2.4",
46
- "@plumbus/core": "0.7.3"
46
+ "@plumbus/core": "0.8.0-beta.6"
47
47
  },
48
48
  "dependencies": {
49
- "@plumbus/ai-decision": "~0.2.1"
49
+ "@plumbus/ai-decision": "~0.3.0-beta.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsc -b",
@@ -43,6 +43,14 @@ class ServiceRoundTwo(unittest.TestCase):
43
43
  finally:
44
44
  conn.close()
45
45
 
46
+ def refused(self, address):
47
+ # Over capacity the server answers at accept without reading a request, so a client
48
+ # still sending one can be reset before it reads the 503. Connect and only read.
49
+ with socket.create_connection(address, timeout=2) as sock:
50
+ response = http.client.HTTPResponse(sock)
51
+ response.begin()
52
+ return response.status, json.loads(response.read())
53
+
46
54
  def test_L23_missing_length_cannot_start_inference(self):
47
55
  self.assertEqual(self.send(length=None)[0], 400)
48
56
  self.assertEqual(self.backend.calls, [])
@@ -108,7 +116,7 @@ class ServiceRoundTwo(unittest.TestCase):
108
116
  first.start()
109
117
  try:
110
118
  self.assertTrue(entered.wait(1))
111
- self.assertEqual(self.send(address=server.server_address)[0], 503)
119
+ self.assertEqual(self.refused(server.server_address)[0], 503)
112
120
  finish.set()
113
121
  first.join(2)
114
122
  self.assertEqual(results, [200])