@molecule/api-ai-decisions-jev 1.0.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/LICENSE +115 -0
- package/README.md +318 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +19 -0
- package/dist/browser-guard.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +88 -0
- package/dist/provider.js.map +1 -0
- package/dist/secrets.d.ts +11 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +20 -0
- package/dist/secrets.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/wire.d.ts +89 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +188 -0
- package/dist/wire.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-09-28T17:40:31.759Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/api-ai-decisions-jev
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
Jev decisions provider for molecule.dev — typed decisions from TypeSafe AI's
|
|
16
|
+
hosted Jev "System One" model.
|
|
17
|
+
|
|
18
|
+
Jev answers `choice`, `score` and yes/no questions about text or JSON with a
|
|
19
|
+
probability distribution instead of generated text. This bond calls
|
|
20
|
+
`POST https://api.typesafe.ai/v1/systemone` with your `TYPESAFE_API_KEY`.
|
|
21
|
+
The open-weights Laya server speaks the same protocol, so
|
|
22
|
+
`@molecule/api-ai-decisions-laya` is a drop-in self-hosted swap.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { setProvider, requireProvider } from '@molecule/api-ai-decisions'
|
|
28
|
+
import { provider } from '@molecule/api-ai-decisions-jev'
|
|
29
|
+
|
|
30
|
+
setProvider(provider) // reads TYPESAFE_API_KEY on first use
|
|
31
|
+
|
|
32
|
+
const { answers } = await requireProvider().decide({
|
|
33
|
+
state: { from: 'ana@example.com', body: 'Your app deleted my notes!!' },
|
|
34
|
+
questions: {
|
|
35
|
+
severity: {
|
|
36
|
+
type: 'score',
|
|
37
|
+
instructions: 'How severe is the problem?',
|
|
38
|
+
criteria: ['cosmetic', 'annoying', 'blocking', 'data loss'],
|
|
39
|
+
},
|
|
40
|
+
churnRisk: { type: 'yesNo', instructions: 'The customer is likely to cancel.' },
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
answers.severity.level // 3
|
|
44
|
+
answers.churnRisk.probability // 0.81
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Type
|
|
48
|
+
|
|
49
|
+
`provider`
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install @molecule/api-ai-decisions-jev @molecule/api-ai-decisions @molecule/api-secrets
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
### Interfaces
|
|
60
|
+
|
|
61
|
+
#### `JevConfig`
|
|
62
|
+
|
|
63
|
+
Configuration for the Jev decisions provider.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
interface JevConfig {
|
|
67
|
+
/** TypeSafe API key. Defaults to the `TYPESAFE_API_KEY` env var (the name TypeSafe's own SDKs read). */
|
|
68
|
+
apiKey?: string
|
|
69
|
+
/**
|
|
70
|
+
* API base URL. Defaults to `TYPESAFE_BASE_URL`, then `https://api.typesafe.ai`.
|
|
71
|
+
* Point it at a gateway that relays `/v1/systemone` (or at a `laya-serve`
|
|
72
|
+
* host — same protocol) without changing code.
|
|
73
|
+
*/
|
|
74
|
+
baseUrl?: string
|
|
75
|
+
/** Default model id. Defaults to `'jev-latest'`. */
|
|
76
|
+
model?: string
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### `PostOptions`
|
|
81
|
+
|
|
82
|
+
Options for {@link postSystemOne}.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
interface PostOptions {
|
|
86
|
+
/** Full endpoint URL. */
|
|
87
|
+
url: string
|
|
88
|
+
/** Bearer token, if any. */
|
|
89
|
+
apiKey?: string
|
|
90
|
+
/** Request body. */
|
|
91
|
+
body: Record<string, unknown>
|
|
92
|
+
/** Abort signal. */
|
|
93
|
+
signal?: AbortSignal
|
|
94
|
+
/** Label for error messages (`'Laya'`, `'Jev'`). */
|
|
95
|
+
label: string
|
|
96
|
+
/** Max retries on a retryable status (default 3). */
|
|
97
|
+
maxRetries?: number
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### `WireAnswer`
|
|
102
|
+
|
|
103
|
+
One answer as received on the wire (only the fields we read).
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
interface WireAnswer {
|
|
107
|
+
type?: string
|
|
108
|
+
choice?: string
|
|
109
|
+
score?: number
|
|
110
|
+
noul?: number
|
|
111
|
+
probabilities?: Record<string, number>
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### `WireQuestion`
|
|
116
|
+
|
|
117
|
+
One question as sent on the wire.
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
interface WireQuestion {
|
|
121
|
+
type: 'choice' | 'score' | 'noul'
|
|
122
|
+
instructions: string
|
|
123
|
+
criteria?: Record<string, string> | string[]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### `WireResponse`
|
|
128
|
+
|
|
129
|
+
The response body (only the fields we read).
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface WireResponse {
|
|
133
|
+
model?: string
|
|
134
|
+
answers?: Record<string, WireAnswer>
|
|
135
|
+
usage?: { input_tokens?: number; output_tokens?: number }
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Functions
|
|
140
|
+
|
|
141
|
+
#### `createProvider(config)`
|
|
142
|
+
|
|
143
|
+
Creates a Jev decisions provider.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
function createProvider(config?: JevConfig): AIDecisionsProvider
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- `config` — API key, base URL and default model.
|
|
150
|
+
|
|
151
|
+
**Returns:** An `AIDecisionsProvider` backed by TypeSafe's Jev API.
|
|
152
|
+
|
|
153
|
+
#### `fromWireAnswer(id, question, wire, minConfidence)`
|
|
154
|
+
|
|
155
|
+
Converts one wire answer into the core's answer for `question`.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
function fromWireAnswer(
|
|
159
|
+
id: string,
|
|
160
|
+
question: DecisionQuestion,
|
|
161
|
+
wire: WireAnswer | undefined,
|
|
162
|
+
minConfidence?: number,
|
|
163
|
+
): DecisionAnswer
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- `id` — The question id (for error messages).
|
|
167
|
+
- `question` — The question that was asked.
|
|
168
|
+
- `wire` — The wire answer.
|
|
169
|
+
- `minConfidence` — Optional low-confidence threshold.
|
|
170
|
+
|
|
171
|
+
**Returns:** The typed answer.
|
|
172
|
+
|
|
173
|
+
#### `fromWireResponse(questions, body, minConfidence)`
|
|
174
|
+
|
|
175
|
+
Converts a whole wire response into the core's result.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
function fromWireResponse(questions: Q, body: WireResponse, minConfidence?: number): DecideResult<Q>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- `questions` — The questions that were asked.
|
|
182
|
+
- `body` — The parsed response body.
|
|
183
|
+
- `minConfidence` — Optional low-confidence threshold.
|
|
184
|
+
|
|
185
|
+
**Returns:** The typed result.
|
|
186
|
+
|
|
187
|
+
#### `postSystemOne(opts)`
|
|
188
|
+
|
|
189
|
+
POSTs a `/v1/systemone` request with retry on 429/5xx-busy, honouring
|
|
190
|
+
`Retry-After`. Throws an Error carrying `status` on a non-2xx response.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
function postSystemOne(opts: PostOptions): Promise<WireResponse>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- `opts` — Request options.
|
|
197
|
+
|
|
198
|
+
**Returns:** The parsed response body.
|
|
199
|
+
|
|
200
|
+
#### `toWireQuestions(questions)`
|
|
201
|
+
|
|
202
|
+
Converts the core's questions into wire questions (`yesNo` → `noul`).
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
function toWireQuestions(questions: Record<string, DecisionQuestion>): Record<string, WireQuestion>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
- `questions` — The questions keyed by id.
|
|
209
|
+
|
|
210
|
+
**Returns:** The wire `questions` object.
|
|
211
|
+
|
|
212
|
+
### Constants
|
|
213
|
+
|
|
214
|
+
#### `aiDecisionsJevSecretDefinitions`
|
|
215
|
+
|
|
216
|
+
Secret definitions required by the Jev decisions bond.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const aiDecisionsJevSecretDefinitions: SecretDefinition[]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
#### `DEFAULT_JEV_MODEL`
|
|
223
|
+
|
|
224
|
+
TypeSafe's flagship model id.
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const DEFAULT_JEV_MODEL: 'jev-latest'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `DEFAULT_JEV_URL`
|
|
231
|
+
|
|
232
|
+
TypeSafe's API host.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const DEFAULT_JEV_URL: 'https://api.typesafe.ai'
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### `provider`
|
|
239
|
+
|
|
240
|
+
The provider implementation — lazy, so env vars are read on first use.
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const provider: AIDecisionsProvider
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Core Interface
|
|
247
|
+
|
|
248
|
+
Implements `@molecule/api-ai-decisions` interface.
|
|
249
|
+
|
|
250
|
+
## Bond Wiring
|
|
251
|
+
|
|
252
|
+
Setup function to register this provider with the core interface:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { setProvider } from '@molecule/api-ai-decisions'
|
|
256
|
+
import { provider } from '@molecule/api-ai-decisions-jev'
|
|
257
|
+
|
|
258
|
+
export function setupAiDecisionsJev(): void {
|
|
259
|
+
setProvider(provider)
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Injection Notes
|
|
264
|
+
|
|
265
|
+
### Requirements
|
|
266
|
+
|
|
267
|
+
Peer dependencies:
|
|
268
|
+
|
|
269
|
+
- `@molecule/api-ai-decisions` ^1.0.0
|
|
270
|
+
- `@molecule/api-secrets` ^1.0.1
|
|
271
|
+
|
|
272
|
+
### Environment Variables
|
|
273
|
+
|
|
274
|
+
- `TYPESAFE_API_KEY` _(required)_ — TypeSafe API key
|
|
275
|
+
- Setup: Create an API key in your TypeSafe AI account; it is sent as a bearer token to the Jev API.
|
|
276
|
+
- Get it here: [https://docs.typesafe.ai/api](https://docs.typesafe.ai/api)
|
|
277
|
+
- Example: `ts-...`
|
|
278
|
+
|
|
279
|
+
### Runtime Dependencies
|
|
280
|
+
|
|
281
|
+
- `@molecule/api-ai-decisions`
|
|
282
|
+
- `@molecule/api-secrets`
|
|
283
|
+
|
|
284
|
+
- Config: `TYPESAFE_API_KEY` (required — sent as `Authorization: Bearer …`),
|
|
285
|
+
`TYPESAFE_BASE_URL` (optional; a gateway, or a `laya-serve` host), and
|
|
286
|
+
`createProvider({ model })` (default `'jev-latest'`, or pass `model` per call).
|
|
287
|
+
- **Limits (TypeSafe docs):** up to 255 options per `choice`, 2–10 levels per
|
|
288
|
+
`score`. 429 (rate limit) and 529 (overloaded) are retried up to 3 times
|
|
289
|
+
with backoff; 401 and 422 throw immediately with the API's message and a
|
|
290
|
+
`status` property.
|
|
291
|
+
- **English-first.** TypeSafe describes English as Jev's primary training
|
|
292
|
+
language; for other languages evaluate carefully or use Laya's
|
|
293
|
+
multilingual checkpoint.
|
|
294
|
+
- **Your data leaves your servers** (TypeSafe processes the `state`). For
|
|
295
|
+
data that must stay in your environment, bond the Laya provider instead.
|
|
296
|
+
- `confidence` in the answers is the probability of the reported answer,
|
|
297
|
+
NOT Jev's own `confidence` field (see the core's remarks).
|
|
298
|
+
- Use the core's `setProvider`, not `bond('ai-decisions', …)` directly.
|
|
299
|
+
|
|
300
|
+
## E2E Tests
|
|
301
|
+
|
|
302
|
+
Integration checklist — drive the real UI (live preview, no mocks), adapt
|
|
303
|
+
each item to this app's actual screens/flows, and check every box off one
|
|
304
|
+
by one. A box you can't check is an integration bug to fix — not a skip:
|
|
305
|
+
|
|
306
|
+
- [ ] Each flow that makes a decision (routing, triage, moderation, a
|
|
307
|
+
guardrail) runs it from the real UI, and the answer DRIVES what happens
|
|
308
|
+
next (the item lands in the chosen queue, the badge shows, the action is
|
|
309
|
+
blocked) — not just printed.
|
|
310
|
+
- [ ] Both directions: a clearly-billing input routes to billing AND a
|
|
311
|
+
clearly-technical one routes elsewhere. One label for every input is a
|
|
312
|
+
broken integration.
|
|
313
|
+
- [ ] A low-confidence answer takes the app's fallback path (human review,
|
|
314
|
+
"unsure" state) instead of being acted on.
|
|
315
|
+
- [ ] Provider errors (service down, bad key) show a visible, recoverable
|
|
316
|
+
state — never a blank screen or an unhandled rejection.
|
|
317
|
+
- [ ] The call runs server-side: no provider request or key in the browser's
|
|
318
|
+
Network tab.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-ai-decisions-jev` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-ai-decisions-jev is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=browser-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.js","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,GAAG,UAIT,CAAA;AACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IACrF,MAAM,IAAI,KAAK,CACb,yGAAyG;QACvG,sFAAsF;QACtF,iFAAiF;QACjF,0CAA0C,CAC7C,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev decisions provider for molecule.dev — typed decisions from TypeSafe AI's
|
|
3
|
+
* hosted Jev "System One" model.
|
|
4
|
+
*
|
|
5
|
+
* Jev answers `choice`, `score` and yes/no questions about text or JSON with a
|
|
6
|
+
* probability distribution instead of generated text. This bond calls
|
|
7
|
+
* `POST https://api.typesafe.ai/v1/systemone` with your `TYPESAFE_API_KEY`.
|
|
8
|
+
* The open-weights Laya server speaks the same protocol, so
|
|
9
|
+
* `@molecule/api-ai-decisions-laya` is a drop-in self-hosted swap.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { setProvider, requireProvider } from '@molecule/api-ai-decisions'
|
|
14
|
+
* import { provider } from '@molecule/api-ai-decisions-jev'
|
|
15
|
+
*
|
|
16
|
+
* setProvider(provider) // reads TYPESAFE_API_KEY on first use
|
|
17
|
+
*
|
|
18
|
+
* const { answers } = await requireProvider().decide({
|
|
19
|
+
* state: { from: 'ana@example.com', body: 'Your app deleted my notes!!' },
|
|
20
|
+
* questions: {
|
|
21
|
+
* severity: { type: 'score', instructions: 'How severe is the problem?', criteria: ['cosmetic', 'annoying', 'blocking', 'data loss'] },
|
|
22
|
+
* churnRisk: { type: 'yesNo', instructions: 'The customer is likely to cancel.' },
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* answers.severity.level // 3
|
|
26
|
+
* answers.churnRisk.probability // 0.81
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - Config: `TYPESAFE_API_KEY` (required — sent as `Authorization: Bearer …`),
|
|
31
|
+
* `TYPESAFE_BASE_URL` (optional; a gateway, or a `laya-serve` host), and
|
|
32
|
+
* `createProvider({ model })` (default `'jev-latest'`, or pass `model` per call).
|
|
33
|
+
* - **Limits (TypeSafe docs):** up to 255 options per `choice`, 2–10 levels per
|
|
34
|
+
* `score`. 429 (rate limit) and 529 (overloaded) are retried up to 3 times
|
|
35
|
+
* with backoff; 401 and 422 throw immediately with the API's message and a
|
|
36
|
+
* `status` property.
|
|
37
|
+
* - **English-first.** TypeSafe describes English as Jev's primary training
|
|
38
|
+
* language; for other languages evaluate carefully or use Laya's
|
|
39
|
+
* multilingual checkpoint.
|
|
40
|
+
* - **Your data leaves your servers** (TypeSafe processes the `state`). For
|
|
41
|
+
* data that must stay in your environment, bond the Laya provider instead.
|
|
42
|
+
* - `confidence` in the answers is the probability of the reported answer,
|
|
43
|
+
* NOT Jev's own `confidence` field (see the core's remarks).
|
|
44
|
+
* - Use the core's `setProvider`, not `bond('ai-decisions', …)` directly.
|
|
45
|
+
*
|
|
46
|
+
* @module
|
|
47
|
+
*/
|
|
48
|
+
export * from './browser-guard.js';
|
|
49
|
+
export * from './provider.js';
|
|
50
|
+
export * from './secrets.js';
|
|
51
|
+
export * from './types.js';
|
|
52
|
+
export * from './wire.js';
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev decisions provider for molecule.dev — typed decisions from TypeSafe AI's
|
|
3
|
+
* hosted Jev "System One" model.
|
|
4
|
+
*
|
|
5
|
+
* Jev answers `choice`, `score` and yes/no questions about text or JSON with a
|
|
6
|
+
* probability distribution instead of generated text. This bond calls
|
|
7
|
+
* `POST https://api.typesafe.ai/v1/systemone` with your `TYPESAFE_API_KEY`.
|
|
8
|
+
* The open-weights Laya server speaks the same protocol, so
|
|
9
|
+
* `@molecule/api-ai-decisions-laya` is a drop-in self-hosted swap.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { setProvider, requireProvider } from '@molecule/api-ai-decisions'
|
|
14
|
+
* import { provider } from '@molecule/api-ai-decisions-jev'
|
|
15
|
+
*
|
|
16
|
+
* setProvider(provider) // reads TYPESAFE_API_KEY on first use
|
|
17
|
+
*
|
|
18
|
+
* const { answers } = await requireProvider().decide({
|
|
19
|
+
* state: { from: 'ana@example.com', body: 'Your app deleted my notes!!' },
|
|
20
|
+
* questions: {
|
|
21
|
+
* severity: { type: 'score', instructions: 'How severe is the problem?', criteria: ['cosmetic', 'annoying', 'blocking', 'data loss'] },
|
|
22
|
+
* churnRisk: { type: 'yesNo', instructions: 'The customer is likely to cancel.' },
|
|
23
|
+
* },
|
|
24
|
+
* })
|
|
25
|
+
* answers.severity.level // 3
|
|
26
|
+
* answers.churnRisk.probability // 0.81
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - Config: `TYPESAFE_API_KEY` (required — sent as `Authorization: Bearer …`),
|
|
31
|
+
* `TYPESAFE_BASE_URL` (optional; a gateway, or a `laya-serve` host), and
|
|
32
|
+
* `createProvider({ model })` (default `'jev-latest'`, or pass `model` per call).
|
|
33
|
+
* - **Limits (TypeSafe docs):** up to 255 options per `choice`, 2–10 levels per
|
|
34
|
+
* `score`. 429 (rate limit) and 529 (overloaded) are retried up to 3 times
|
|
35
|
+
* with backoff; 401 and 422 throw immediately with the API's message and a
|
|
36
|
+
* `status` property.
|
|
37
|
+
* - **English-first.** TypeSafe describes English as Jev's primary training
|
|
38
|
+
* language; for other languages evaluate carefully or use Laya's
|
|
39
|
+
* multilingual checkpoint.
|
|
40
|
+
* - **Your data leaves your servers** (TypeSafe processes the `state`). For
|
|
41
|
+
* data that must stay in your environment, bond the Laya provider instead.
|
|
42
|
+
* - `confidence` in the answers is the probability of the reported answer,
|
|
43
|
+
* NOT Jev's own `confidence` field (see the core's remarks).
|
|
44
|
+
* - Use the core's `setProvider`, not `bond('ai-decisions', …)` directly.
|
|
45
|
+
*
|
|
46
|
+
* @module
|
|
47
|
+
*/
|
|
48
|
+
export * from './browser-guard.js';
|
|
49
|
+
export * from './provider.js';
|
|
50
|
+
export * from './secrets.js';
|
|
51
|
+
export * from './types.js';
|
|
52
|
+
export * from './wire.js';
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev implementation of `AIDecisionsProvider`.
|
|
3
|
+
*
|
|
4
|
+
* Calls TypeSafe AI's hosted Jev model over `POST /v1/systemone`.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import './secrets.js';
|
|
9
|
+
import type { AIDecisionsProvider } from '@molecule/api-ai-decisions';
|
|
10
|
+
import type { JevConfig } from './types.js';
|
|
11
|
+
/** TypeSafe's API host. */
|
|
12
|
+
export declare const DEFAULT_JEV_URL = "https://api.typesafe.ai";
|
|
13
|
+
/** TypeSafe's flagship model id. */
|
|
14
|
+
export declare const DEFAULT_JEV_MODEL = "jev-latest";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a Jev decisions provider.
|
|
17
|
+
*
|
|
18
|
+
* @param config - API key, base URL and default model.
|
|
19
|
+
* @returns An `AIDecisionsProvider` backed by TypeSafe's Jev API.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createProvider(config?: JevConfig): AIDecisionsProvider;
|
|
22
|
+
/**
|
|
23
|
+
* The provider implementation — lazy, so env vars are read on first use.
|
|
24
|
+
*/
|
|
25
|
+
export declare const provider: AIDecisionsProvider;
|
|
26
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,mBAAmB,EAIpB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAG3C,2BAA2B;AAC3B,eAAO,MAAM,eAAe,4BAA4B,CAAA;AACxD,oCAAoC;AACpC,eAAO,MAAM,iBAAiB,eAAe,CAAA;AA4D7C;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,mBAAmB,CAEtE;AAGD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,mBASrB,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev implementation of `AIDecisionsProvider`.
|
|
3
|
+
*
|
|
4
|
+
* Calls TypeSafe AI's hosted Jev model over `POST /v1/systemone`.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
// Side-effect import: registers this bond's secret definitions.
|
|
9
|
+
import './secrets.js';
|
|
10
|
+
import { fromWireResponse, postSystemOne, toWireQuestions } from './wire.js';
|
|
11
|
+
/** TypeSafe's API host. */
|
|
12
|
+
export const DEFAULT_JEV_URL = 'https://api.typesafe.ai';
|
|
13
|
+
/** TypeSafe's flagship model id. */
|
|
14
|
+
export const DEFAULT_JEV_MODEL = 'jev-latest';
|
|
15
|
+
/**
|
|
16
|
+
* Jev decisions provider over HTTP.
|
|
17
|
+
*/
|
|
18
|
+
class JevDecisionsProvider {
|
|
19
|
+
name = 'jev';
|
|
20
|
+
baseUrl;
|
|
21
|
+
apiKey;
|
|
22
|
+
model;
|
|
23
|
+
/**
|
|
24
|
+
* Creates the provider.
|
|
25
|
+
*
|
|
26
|
+
* @param config - Provider configuration; env vars fill anything omitted.
|
|
27
|
+
*/
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
this.baseUrl = (config.baseUrl || process.env.TYPESAFE_BASE_URL || DEFAULT_JEV_URL).replace(/\/+$/, '');
|
|
30
|
+
this.apiKey = config.apiKey ?? (process.env.TYPESAFE_API_KEY || undefined);
|
|
31
|
+
this.model = config.model ?? DEFAULT_JEV_MODEL;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Answers every question about `input.state` in one request.
|
|
35
|
+
*
|
|
36
|
+
* @param input - The state, questions and options.
|
|
37
|
+
* @returns One typed answer per question id.
|
|
38
|
+
*/
|
|
39
|
+
async decide(input) {
|
|
40
|
+
if (input.state === undefined || input.state === null) {
|
|
41
|
+
throw new Error('ai-decisions: decide() requires a `state`');
|
|
42
|
+
}
|
|
43
|
+
if (!input.questions || Object.keys(input.questions).length === 0) {
|
|
44
|
+
throw new Error('ai-decisions: decide() requires at least one question');
|
|
45
|
+
}
|
|
46
|
+
if (!this.apiKey) {
|
|
47
|
+
throw new Error('ai-decisions-jev: TYPESAFE_API_KEY is not set. Create a key at typesafe.ai, or bond @molecule/api-ai-decisions-laya to self-host.');
|
|
48
|
+
}
|
|
49
|
+
const body = await postSystemOne({
|
|
50
|
+
url: `${this.baseUrl}/v1/systemone`,
|
|
51
|
+
apiKey: this.apiKey,
|
|
52
|
+
body: {
|
|
53
|
+
model: input.model ?? this.model,
|
|
54
|
+
state: input.state,
|
|
55
|
+
questions: toWireQuestions(input.questions),
|
|
56
|
+
},
|
|
57
|
+
signal: input.signal,
|
|
58
|
+
label: 'Jev',
|
|
59
|
+
});
|
|
60
|
+
return fromWireResponse(input.questions, body, input.minConfidence);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a Jev decisions provider.
|
|
65
|
+
*
|
|
66
|
+
* @param config - API key, base URL and default model.
|
|
67
|
+
* @returns An `AIDecisionsProvider` backed by TypeSafe's Jev API.
|
|
68
|
+
*/
|
|
69
|
+
export function createProvider(config) {
|
|
70
|
+
return new JevDecisionsProvider(config);
|
|
71
|
+
}
|
|
72
|
+
let _provider = null;
|
|
73
|
+
/**
|
|
74
|
+
* The provider implementation — lazy, so env vars are read on first use.
|
|
75
|
+
*/
|
|
76
|
+
export const provider = new Proxy({}, {
|
|
77
|
+
get(_, prop, receiver) {
|
|
78
|
+
if (!_provider)
|
|
79
|
+
_provider = createProvider();
|
|
80
|
+
return Reflect.get(_provider, prop, receiver);
|
|
81
|
+
},
|
|
82
|
+
set(_, prop, value) {
|
|
83
|
+
if (!_provider)
|
|
84
|
+
_provider = createProvider();
|
|
85
|
+
return Reflect.set(_provider, prop, value);
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,gEAAgE;AAChE,OAAO,cAAc,CAAA;AAUrB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE5E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,eAAe,GAAG,yBAAyB,CAAA;AACxD,oCAAoC;AACpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAA;AAE7C;;GAEG;AACH,MAAM,oBAAoB;IACf,IAAI,GAAG,K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CAAC,KAAK,CAAC,SAAS,CAAC;aAC5C;YACD,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK;SACb,CAAC,CAAA;QACF,OAAO,gBAAgB,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACrE,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAAkB;IAC/C,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAA;AACzC,CAAC;AAED,IAAI,SAAS,GAA+B,IAAI,CAAA;AAChD;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAwB,IAAI,KAAK,CAAC,EAAyB,EAAE;IAChF,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ;QACnB,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,cAAc,EAAE,CAAA;QAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;IACD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK;QAChB,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,cAAc,EAAE,CAAA;QAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev secret definitions — self-registered at import time so the runtime
|
|
3
|
+
* secrets registry (`@molecule/api-secrets`) can drive boot-time configuration
|
|
4
|
+
* reports and actionable "not configured" errors.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { SecretDefinition } from '@molecule/api-secrets';
|
|
9
|
+
/** Secret definitions required by the Jev decisions bond. */
|
|
10
|
+
export declare const aiDecisionsJevSecretDefinitions: SecretDefinition[];
|
|
11
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAG7D,6DAA6D;AAC7D,eAAO,MAAM,+BAA+B,EAAE,gBAAgB,EAS7D,CAAA"}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev secret definitions — self-registered at import time so the runtime
|
|
3
|
+
* secrets registry (`@molecule/api-secrets`) can drive boot-time configuration
|
|
4
|
+
* reports and actionable "not configured" errors.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { registerSecrets } from '@molecule/api-secrets';
|
|
9
|
+
/** Secret definitions required by the Jev decisions bond. */
|
|
10
|
+
export const aiDecisionsJevSecretDefinitions = [
|
|
11
|
+
{
|
|
12
|
+
key: 'TYPESAFE_API_KEY',
|
|
13
|
+
description: 'TypeSafe API key — Create an API key in your TypeSafe AI account; it is sent as a bearer token to the Jev API.',
|
|
14
|
+
helpUrl: 'https://docs.typesafe.ai/api',
|
|
15
|
+
required: true,
|
|
16
|
+
example: 'ts-...',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
registerSecrets(aiDecisionsJevSecretDefinitions);
|
|
20
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,+BAA+B,GAAuB;IACjE;QACE,GAAG,EAAE,kBAAkB;QACvB,WAAW,EACT,gHAAgH;QAClH,OAAO,EAAE,8BAA8B;QACvC,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,QAAQ;KAClB;CACF,CAAA;AAED,eAAe,CAAC,+BAA+B,CAAC,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev decisions provider configuration.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for the Jev decisions provider.
|
|
8
|
+
*/
|
|
9
|
+
export interface JevConfig {
|
|
10
|
+
/** TypeSafe API key. Defaults to the `TYPESAFE_API_KEY` env var (the name TypeSafe's own SDKs read). */
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
/**
|
|
13
|
+
* API base URL. Defaults to `TYPESAFE_BASE_URL`, then `https://api.typesafe.ai`.
|
|
14
|
+
* Point it at a gateway that relays `/v1/systemone` (or at a `laya-serve`
|
|
15
|
+
* host — same protocol) without changing code.
|
|
16
|
+
*/
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Default model id. Defaults to `'jev-latest'`. */
|
|
19
|
+
model?: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,wGAAwG;IACxG,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/wire.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/v1/systemone` wire protocol (TypeSafe Jev, spoken verbatim by
|
|
3
|
+
* `laya-serve`) ↔ the `@molecule/api-ai-decisions` types.
|
|
4
|
+
*
|
|
5
|
+
* Wire facts (laya `docs/http-api.md`, docs.typesafe.ai/api): request
|
|
6
|
+
* `{ model?, state, questions: { <id>: { type: 'choice'|'score'|'noul', instructions, criteria } } }`;
|
|
7
|
+
* `choice` criteria is `{ label: description }`, `score` criteria a list of
|
|
8
|
+
* levels, `noul` criteria optional `{ true, false }`. Answers carry `choice` +
|
|
9
|
+
* `probabilities` keyed by label, `score` (expected level) + `probabilities`
|
|
10
|
+
* keyed `"0".."k-1"`, or `noul` (P(true)). Vendor `confidence` fields are
|
|
11
|
+
* ignored: the core defines `confidence` as the probability of the reported
|
|
12
|
+
* answer, computed here from the distribution.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
import type { DecideResult, DecisionAnswer, DecisionQuestion } from '@molecule/api-ai-decisions';
|
|
17
|
+
/** One question as sent on the wire. */
|
|
18
|
+
export interface WireQuestion {
|
|
19
|
+
type: 'choice' | 'score' | 'noul';
|
|
20
|
+
instructions: string;
|
|
21
|
+
criteria?: Record<string, string> | string[];
|
|
22
|
+
}
|
|
23
|
+
/** One answer as received on the wire (only the fields we read). */
|
|
24
|
+
export interface WireAnswer {
|
|
25
|
+
type?: string;
|
|
26
|
+
choice?: string;
|
|
27
|
+
score?: number;
|
|
28
|
+
noul?: number;
|
|
29
|
+
probabilities?: Record<string, number>;
|
|
30
|
+
}
|
|
31
|
+
/** The response body (only the fields we read). */
|
|
32
|
+
export interface WireResponse {
|
|
33
|
+
model?: string;
|
|
34
|
+
answers?: Record<string, WireAnswer>;
|
|
35
|
+
usage?: {
|
|
36
|
+
input_tokens?: number;
|
|
37
|
+
output_tokens?: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Converts the core's questions into wire questions (`yesNo` → `noul`).
|
|
42
|
+
*
|
|
43
|
+
* @param questions - The questions keyed by id.
|
|
44
|
+
* @returns The wire `questions` object.
|
|
45
|
+
*/
|
|
46
|
+
export declare function toWireQuestions(questions: Record<string, DecisionQuestion>): Record<string, WireQuestion>;
|
|
47
|
+
/**
|
|
48
|
+
* Converts one wire answer into the core's answer for `question`.
|
|
49
|
+
*
|
|
50
|
+
* @param id - The question id (for error messages).
|
|
51
|
+
* @param question - The question that was asked.
|
|
52
|
+
* @param wire - The wire answer.
|
|
53
|
+
* @param minConfidence - Optional low-confidence threshold.
|
|
54
|
+
* @returns The typed answer.
|
|
55
|
+
*/
|
|
56
|
+
export declare function fromWireAnswer(id: string, question: DecisionQuestion, wire: WireAnswer | undefined, minConfidence?: number): DecisionAnswer;
|
|
57
|
+
/**
|
|
58
|
+
* Converts a whole wire response into the core's result.
|
|
59
|
+
*
|
|
60
|
+
* @param questions - The questions that were asked.
|
|
61
|
+
* @param body - The parsed response body.
|
|
62
|
+
* @param minConfidence - Optional low-confidence threshold.
|
|
63
|
+
* @returns The typed result.
|
|
64
|
+
*/
|
|
65
|
+
export declare function fromWireResponse<Q extends Record<string, DecisionQuestion>>(questions: Q, body: WireResponse, minConfidence?: number): DecideResult<Q>;
|
|
66
|
+
/** Options for {@link postSystemOne}. */
|
|
67
|
+
export interface PostOptions {
|
|
68
|
+
/** Full endpoint URL. */
|
|
69
|
+
url: string;
|
|
70
|
+
/** Bearer token, if any. */
|
|
71
|
+
apiKey?: string;
|
|
72
|
+
/** Request body. */
|
|
73
|
+
body: Record<string, unknown>;
|
|
74
|
+
/** Abort signal. */
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
/** Label for error messages (`'Laya'`, `'Jev'`). */
|
|
77
|
+
label: string;
|
|
78
|
+
/** Max retries on a retryable status (default 3). */
|
|
79
|
+
maxRetries?: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* POSTs a `/v1/systemone` request with retry on 429/5xx-busy, honouring
|
|
83
|
+
* `Retry-After`. Throws an Error carrying `status` on a non-2xx response.
|
|
84
|
+
*
|
|
85
|
+
* @param opts - Request options.
|
|
86
|
+
* @returns The parsed response body.
|
|
87
|
+
*/
|
|
88
|
+
export declare function postSystemOne(opts: PostOptions): Promise<WireResponse>;
|
|
89
|
+
//# sourceMappingURL=wire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAEV,YAAY,EACZ,cAAc,EACd,gBAAgB,EAGjB,MAAM,4BAA4B,CAAA;AAEnC,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAA;IACjC,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAAA;CAC7C;AAED,oEAAoE;AACpE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACvC;AAED,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACpC,KAAK,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC1C,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAuB9B;AAKD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE,UAAU,GAAG,SAAS,EAC5B,aAAa,CAAC,EAAE,MAAM,GACrB,cAAc,CAiDhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzE,SAAS,EAAE,CAAC,EACZ,IAAI,EAAE,YAAY,EAClB,aAAa,CAAC,EAAE,MAAM,GACrB,YAAY,CAAC,CAAC,CAAC,CAiBjB;AAKD,yCAAyC;AACzC,MAAM,WAAW,WAAW;IAC1B,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,oBAAoB;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAqC5E"}
|
package/dist/wire.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/v1/systemone` wire protocol (TypeSafe Jev, spoken verbatim by
|
|
3
|
+
* `laya-serve`) ↔ the `@molecule/api-ai-decisions` types.
|
|
4
|
+
*
|
|
5
|
+
* Wire facts (laya `docs/http-api.md`, docs.typesafe.ai/api): request
|
|
6
|
+
* `{ model?, state, questions: { <id>: { type: 'choice'|'score'|'noul', instructions, criteria } } }`;
|
|
7
|
+
* `choice` criteria is `{ label: description }`, `score` criteria a list of
|
|
8
|
+
* levels, `noul` criteria optional `{ true, false }`. Answers carry `choice` +
|
|
9
|
+
* `probabilities` keyed by label, `score` (expected level) + `probabilities`
|
|
10
|
+
* keyed `"0".."k-1"`, or `noul` (P(true)). Vendor `confidence` fields are
|
|
11
|
+
* ignored: the core defines `confidence` as the probability of the reported
|
|
12
|
+
* answer, computed here from the distribution.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Converts the core's questions into wire questions (`yesNo` → `noul`).
|
|
18
|
+
*
|
|
19
|
+
* @param questions - The questions keyed by id.
|
|
20
|
+
* @returns The wire `questions` object.
|
|
21
|
+
*/
|
|
22
|
+
export function toWireQuestions(questions) {
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const [id, q] of Object.entries(questions)) {
|
|
25
|
+
if (q.type === 'choice') {
|
|
26
|
+
out[id] = { type: 'choice', instructions: q.instructions, criteria: q.criteria };
|
|
27
|
+
}
|
|
28
|
+
else if (q.type === 'score') {
|
|
29
|
+
out[id] = { type: 'score', instructions: q.instructions, criteria: q.criteria };
|
|
30
|
+
}
|
|
31
|
+
else if (q.type === 'yesNo') {
|
|
32
|
+
const criteria = {};
|
|
33
|
+
if (q.criteria?.yes)
|
|
34
|
+
criteria.true = q.criteria.yes;
|
|
35
|
+
if (q.criteria?.no)
|
|
36
|
+
criteria.false = q.criteria.no;
|
|
37
|
+
out[id] = {
|
|
38
|
+
type: 'noul',
|
|
39
|
+
instructions: q.instructions,
|
|
40
|
+
...(Object.keys(criteria).length ? { criteria } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
throw new Error(`ai-decisions: question "${id}" has unknown type "${q.type}"`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
50
|
+
const clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
51
|
+
/**
|
|
52
|
+
* Converts one wire answer into the core's answer for `question`.
|
|
53
|
+
*
|
|
54
|
+
* @param id - The question id (for error messages).
|
|
55
|
+
* @param question - The question that was asked.
|
|
56
|
+
* @param wire - The wire answer.
|
|
57
|
+
* @param minConfidence - Optional low-confidence threshold.
|
|
58
|
+
* @returns The typed answer.
|
|
59
|
+
*/
|
|
60
|
+
export function fromWireAnswer(id, question, wire, minConfidence) {
|
|
61
|
+
if (!wire || typeof wire !== 'object') {
|
|
62
|
+
throw new Error(`ai-decisions: the provider returned no answer for question "${id}"`);
|
|
63
|
+
}
|
|
64
|
+
let answer;
|
|
65
|
+
if (question.type === 'choice') {
|
|
66
|
+
const labels = Object.keys(question.criteria);
|
|
67
|
+
const probabilities = {};
|
|
68
|
+
for (const label of labels)
|
|
69
|
+
probabilities[label] = clamp01(num(wire.probabilities?.[label]));
|
|
70
|
+
let top = labels[0] ?? '';
|
|
71
|
+
for (const label of labels)
|
|
72
|
+
if (probabilities[label] > probabilities[top])
|
|
73
|
+
top = label;
|
|
74
|
+
const choice = typeof wire.choice === 'string' && labels.includes(wire.choice) ? wire.choice : top;
|
|
75
|
+
answer = {
|
|
76
|
+
type: 'choice',
|
|
77
|
+
choice,
|
|
78
|
+
probabilities,
|
|
79
|
+
confidence: probabilities[choice] ?? 0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else if (question.type === 'score') {
|
|
83
|
+
const probabilities = question.criteria.map((_, i) => clamp01(num(wire.probabilities?.[String(i)])));
|
|
84
|
+
let level = 0;
|
|
85
|
+
probabilities.forEach((p, i) => {
|
|
86
|
+
if (p > probabilities[level])
|
|
87
|
+
level = i;
|
|
88
|
+
});
|
|
89
|
+
const expected = probabilities.reduce((sum, p, i) => sum + p * i, 0);
|
|
90
|
+
answer = {
|
|
91
|
+
type: 'score',
|
|
92
|
+
score: typeof wire.score === 'number' && Number.isFinite(wire.score) ? wire.score : expected,
|
|
93
|
+
level,
|
|
94
|
+
probabilities,
|
|
95
|
+
confidence: probabilities[level] ?? 0,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (typeof wire.noul !== 'number' || !Number.isFinite(wire.noul)) {
|
|
100
|
+
throw new Error(`ai-decisions: the provider's answer to "${id}" has no noul probability`);
|
|
101
|
+
}
|
|
102
|
+
const probability = clamp01(wire.noul);
|
|
103
|
+
answer = {
|
|
104
|
+
type: 'yesNo',
|
|
105
|
+
probability,
|
|
106
|
+
answer: probability >= 0.5,
|
|
107
|
+
confidence: Math.max(probability, 1 - probability),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (typeof minConfidence === 'number')
|
|
111
|
+
answer.lowConfidence = answer.confidence < minConfidence;
|
|
112
|
+
return answer;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Converts a whole wire response into the core's result.
|
|
116
|
+
*
|
|
117
|
+
* @param questions - The questions that were asked.
|
|
118
|
+
* @param body - The parsed response body.
|
|
119
|
+
* @param minConfidence - Optional low-confidence threshold.
|
|
120
|
+
* @returns The typed result.
|
|
121
|
+
*/
|
|
122
|
+
export function fromWireResponse(questions, body, minConfidence) {
|
|
123
|
+
const answers = {};
|
|
124
|
+
for (const [id, q] of Object.entries(questions)) {
|
|
125
|
+
answers[id] = fromWireAnswer(id, q, body.answers?.[id], minConfidence);
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
answers: answers,
|
|
129
|
+
...(typeof body.model === 'string' ? { model: body.model } : {}),
|
|
130
|
+
...(body.usage
|
|
131
|
+
? {
|
|
132
|
+
usage: {
|
|
133
|
+
inputTokens: num(body.usage.input_tokens),
|
|
134
|
+
outputTokens: num(body.usage.output_tokens),
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
: {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** Statuses worth retrying: rate limit, busy (`laya-serve` 503 + Retry-After), overloaded (Jev 529). */
|
|
141
|
+
const RETRYABLE = new Set([429, 502, 503, 504, 529]);
|
|
142
|
+
/**
|
|
143
|
+
* POSTs a `/v1/systemone` request with retry on 429/5xx-busy, honouring
|
|
144
|
+
* `Retry-After`. Throws an Error carrying `status` on a non-2xx response.
|
|
145
|
+
*
|
|
146
|
+
* @param opts - Request options.
|
|
147
|
+
* @returns The parsed response body.
|
|
148
|
+
*/
|
|
149
|
+
export async function postSystemOne(opts) {
|
|
150
|
+
const { url, apiKey, body, signal, label, maxRetries = 3 } = opts;
|
|
151
|
+
const headers = { 'content-type': 'application/json' };
|
|
152
|
+
if (apiKey)
|
|
153
|
+
headers.authorization = `Bearer ${apiKey}`;
|
|
154
|
+
for (let attempt = 0;; attempt++) {
|
|
155
|
+
const response = await fetch(url, {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers,
|
|
158
|
+
body: JSON.stringify(body),
|
|
159
|
+
signal,
|
|
160
|
+
});
|
|
161
|
+
if (response.ok)
|
|
162
|
+
return (await response.json());
|
|
163
|
+
if (RETRYABLE.has(response.status) && attempt < maxRetries) {
|
|
164
|
+
const retryAfter = Number(response.headers.get('retry-after'));
|
|
165
|
+
const waitMs = Number.isFinite(retryAfter) && retryAfter > 0
|
|
166
|
+
? Math.min(retryAfter * 1000, 10_000)
|
|
167
|
+
: 250 * 2 ** attempt;
|
|
168
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const text = await response.text().catch(() => '');
|
|
172
|
+
let detail = text.length > 0 && text.length < 300 ? text : `HTTP ${response.status}`;
|
|
173
|
+
try {
|
|
174
|
+
const parsed = JSON.parse(text);
|
|
175
|
+
if (typeof parsed.detail === 'string')
|
|
176
|
+
detail = parsed.detail;
|
|
177
|
+
else if (typeof parsed.error?.message === 'string')
|
|
178
|
+
detail = parsed.error.message;
|
|
179
|
+
}
|
|
180
|
+
catch (_error) {
|
|
181
|
+
// Not JSON — keep the raw text (or the status) as the detail.
|
|
182
|
+
}
|
|
183
|
+
throw Object.assign(new Error(`${label} decision request failed (${response.status}): ${detail}`), {
|
|
184
|
+
status: response.status,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=wire.js.map
|
package/dist/wire.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkCH;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA2C;IAE3C,MAAM,GAAG,GAAiC,EAAE,CAAA;IAC5C,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAChD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxB,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;QAClF,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC9B,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;QACjF,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAA2B,EAAE,CAAA;YAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE,GAAG;gBAAE,QAAQ,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAA;YACnD,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAAE,QAAQ,CAAC,K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;gBAAE,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAA;QACnF,CAAC;QAAC,OAAO,MAAM,EAAE,CAAC;YAChB,8DAA8D;QAChE,CAAC;QACD,MAAM,MAAM,CAAC,MAAM,CACjB,IAAI,KAAK,CAAC,GAAG,KAAK,6BAA6B,QAAQ,CAAC,MAAM,MAAM,MAAM,EAAE,CAAC,EAC7E;YACE,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/api-ai-decisions-jev",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Jev decisions provider for molecule.dev — typed choice/score/yes-no answers from TypeSafe's hosted Jev System One API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"keywords": [
|
|
24
|
+
"molecule",
|
|
25
|
+
"ai",
|
|
26
|
+
"decisions",
|
|
27
|
+
"jev",
|
|
28
|
+
"typesafe"
|
|
29
|
+
],
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@molecule/api-ai-decisions": "^1.0.0",
|
|
34
|
+
"@molecule/api-secrets": "^1.0.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@molecule/api-ai-decisions": "1.0.0",
|
|
38
|
+
"@molecule/api-secrets": "1.0.2",
|
|
39
|
+
"@types/node": "26.1.2",
|
|
40
|
+
"typescript": "6.0.3",
|
|
41
|
+
"vitest": "4.1.11"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
46
|
+
"directory": "packages/api/bonds/ai-decisions/jev"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://www.molecule.dev/packages/api-ai-decisions-jev",
|
|
49
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
}
|
|
53
|
+
}
|