briefcase-wasm 2.0.0 → 2.0.2
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 +244 -0
- package/briefcase_wasm_bg.wasm +0 -0
- package/package.json +8 -1
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Briefcase AI WebAssembly
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for Briefcase AI - A high-performance SDK for AI observability, replay, and decision tracking.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/briefcase-wasm)
|
|
6
|
+
[](https://github.com/briefcasebrain/briefcase-ai-core/actions)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **AI Decision Tracking** - Capture inputs, outputs, and context for every AI decision
|
|
11
|
+
- **High Performance** - Rust core compiled to WebAssembly for maximum speed
|
|
12
|
+
- **Browser Compatible** - Works in modern browsers and Node.js environments
|
|
13
|
+
- **Type Safe** - Full TypeScript definitions included
|
|
14
|
+
- **Zero Dependencies** - Self-contained WebAssembly module
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install briefcase-wasm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Browser
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<!DOCTYPE html>
|
|
28
|
+
<html>
|
|
29
|
+
<head>
|
|
30
|
+
<script type="module">
|
|
31
|
+
import init, { DecisionSnapshot, Input, Output, SqliteBackend } from './node_modules/briefcase-wasm/briefcase_wasm.js';
|
|
32
|
+
|
|
33
|
+
async function run() {
|
|
34
|
+
// Initialize the WASM module
|
|
35
|
+
await init();
|
|
36
|
+
|
|
37
|
+
// Create a decision snapshot
|
|
38
|
+
const decision = new DecisionSnapshot('ai_function');
|
|
39
|
+
|
|
40
|
+
// Add input and output
|
|
41
|
+
decision.add_input(new Input('user_query', 'Hello world', 'string'));
|
|
42
|
+
decision.add_output(new Output('response', 'Hello back!', 'string').with_confidence(0.95));
|
|
43
|
+
|
|
44
|
+
// Save to storage
|
|
45
|
+
const storage = SqliteBackend.in_memory();
|
|
46
|
+
const decisionId = storage.save_decision(decision);
|
|
47
|
+
|
|
48
|
+
console.log('Saved decision:', decisionId);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
run();
|
|
52
|
+
</script>
|
|
53
|
+
</head>
|
|
54
|
+
<body>
|
|
55
|
+
<h1>Briefcase AI WebAssembly Demo</h1>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Node.js
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
import init, { DecisionSnapshot, Input, Output, SqliteBackend } from 'briefcase-wasm';
|
|
64
|
+
|
|
65
|
+
async function main() {
|
|
66
|
+
// Initialize the WASM module
|
|
67
|
+
await init();
|
|
68
|
+
|
|
69
|
+
// Create a decision snapshot
|
|
70
|
+
const decision = new DecisionSnapshot('ai_function');
|
|
71
|
+
|
|
72
|
+
// Add input and output
|
|
73
|
+
decision.add_input(new Input('user_query', 'Hello world', 'string'));
|
|
74
|
+
decision.add_output(new Output('response', 'Hello back!', 'string').with_confidence(0.95));
|
|
75
|
+
|
|
76
|
+
// Save to storage
|
|
77
|
+
const storage = SqliteBackend.in_memory();
|
|
78
|
+
const decisionId = storage.save_decision(decision);
|
|
79
|
+
|
|
80
|
+
console.log('Saved decision:', decisionId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
main().catch(console.error);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### TypeScript
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import init, { DecisionSnapshot, Input, Output, SqliteBackend } from 'briefcase-wasm';
|
|
90
|
+
|
|
91
|
+
async function trackAIDecision(userInput: string, aiResponse: string): Promise<string> {
|
|
92
|
+
await init();
|
|
93
|
+
|
|
94
|
+
const decision = new DecisionSnapshot('ai_chat')
|
|
95
|
+
.add_input(new Input('user_message', userInput, 'string'))
|
|
96
|
+
.add_output(new Output('ai_response', aiResponse, 'string').with_confidence(0.95))
|
|
97
|
+
.with_execution_time(150.5)
|
|
98
|
+
.add_tag('model', 'gpt-4')
|
|
99
|
+
.add_tag('version', '1.0');
|
|
100
|
+
|
|
101
|
+
const storage = SqliteBackend.file('chat_history.db');
|
|
102
|
+
return storage.save_decision(decision);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## API Reference
|
|
107
|
+
|
|
108
|
+
### DecisionSnapshot
|
|
109
|
+
|
|
110
|
+
The main class for tracking AI decisions:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
class DecisionSnapshot {
|
|
114
|
+
constructor(functionName: string);
|
|
115
|
+
|
|
116
|
+
add_input(input: Input): DecisionSnapshot;
|
|
117
|
+
add_output(output: Output): DecisionSnapshot;
|
|
118
|
+
with_module(moduleName: string): DecisionSnapshot;
|
|
119
|
+
with_execution_time(timeMs: number): DecisionSnapshot;
|
|
120
|
+
add_tag(key: string, value: string): DecisionSnapshot;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Input/Output
|
|
125
|
+
|
|
126
|
+
Data structures for function inputs and outputs:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
class Input {
|
|
130
|
+
constructor(name: string, value: any, dataType: string);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class Output {
|
|
134
|
+
constructor(name: string, value: any, dataType: string);
|
|
135
|
+
with_confidence(confidence: number): Output;
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Storage Backends
|
|
140
|
+
|
|
141
|
+
#### SqliteBackend
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
class SqliteBackend {
|
|
145
|
+
static in_memory(): SqliteBackend;
|
|
146
|
+
static file(path: string): SqliteBackend;
|
|
147
|
+
|
|
148
|
+
save_decision(decision: DecisionSnapshot): string;
|
|
149
|
+
load_decision(id: string): DecisionSnapshot | null;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Model Parameters
|
|
154
|
+
|
|
155
|
+
Track model configuration for reproducibility:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { ModelParameters } from 'briefcase-wasm';
|
|
159
|
+
|
|
160
|
+
const params = new ModelParameters('gpt-4')
|
|
161
|
+
.with_provider('openai')
|
|
162
|
+
.with_version('1.0')
|
|
163
|
+
.with_parameter('temperature', 0.7)
|
|
164
|
+
.with_parameter('max_tokens', 1000);
|
|
165
|
+
|
|
166
|
+
decision.with_model_parameters(params);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Execution Context
|
|
170
|
+
|
|
171
|
+
Capture environment for deterministic replay:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { ExecutionContext } from 'briefcase-wasm';
|
|
175
|
+
|
|
176
|
+
const context = new ExecutionContext()
|
|
177
|
+
.with_runtime_version('Node 18.0.0')
|
|
178
|
+
.with_dependency('openai', '4.0.0')
|
|
179
|
+
.with_random_seed(42)
|
|
180
|
+
.with_env_var('MODEL_ENDPOINT', 'https://api.openai.com');
|
|
181
|
+
|
|
182
|
+
decision.with_context(context);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Use Cases
|
|
186
|
+
|
|
187
|
+
- **Browser-based AI Apps** - Track decisions in client-side applications
|
|
188
|
+
- **Node.js Services** - High-performance decision tracking for backend services
|
|
189
|
+
- **Edge Computing** - Lightweight observability at the edge
|
|
190
|
+
- **Development Tools** - Debug and analyze AI model behavior
|
|
191
|
+
- **A/B Testing** - Compare model variants in production
|
|
192
|
+
|
|
193
|
+
## Performance
|
|
194
|
+
|
|
195
|
+
- **Fast Initialization** - WASM module loads in ~10ms
|
|
196
|
+
- **Low Memory Usage** - Optimized for resource-constrained environments
|
|
197
|
+
- **High Throughput** - Process thousands of decisions per second
|
|
198
|
+
- **Small Bundle Size** - ~77KB compressed package
|
|
199
|
+
|
|
200
|
+
## Browser Compatibility
|
|
201
|
+
|
|
202
|
+
- Chrome 57+
|
|
203
|
+
- Firefox 52+
|
|
204
|
+
- Safari 11+
|
|
205
|
+
- Edge 16+
|
|
206
|
+
|
|
207
|
+
Requires WebAssembly support and ES modules.
|
|
208
|
+
|
|
209
|
+
## Node.js Compatibility
|
|
210
|
+
|
|
211
|
+
- Node.js 14+
|
|
212
|
+
- ES modules support required
|
|
213
|
+
|
|
214
|
+
## TypeScript Support
|
|
215
|
+
|
|
216
|
+
Full TypeScript definitions are included. No additional `@types` package needed.
|
|
217
|
+
|
|
218
|
+
## Contributing
|
|
219
|
+
|
|
220
|
+
This package is part of the [Briefcase AI Core](https://github.com/briefcasebrain/briefcase-ai-core) project.
|
|
221
|
+
|
|
222
|
+
1. Fork the repository
|
|
223
|
+
2. Make your changes in `crates/wasm/`
|
|
224
|
+
3. Run tests: `wasm-pack test --node`
|
|
225
|
+
4. Submit a pull request
|
|
226
|
+
|
|
227
|
+
## Support
|
|
228
|
+
|
|
229
|
+
- **Issues**: [GitHub Issues](https://github.com/briefcasebrain/briefcase-ai-core/issues)
|
|
230
|
+
- **Documentation**: [https://docs.briefcase.ai](https://docs.briefcase.ai)
|
|
231
|
+
- **Discussions**: [GitHub Discussions](https://github.com/briefcasebrain/briefcase-ai-core/discussions)
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT License - see [LICENSE](https://github.com/briefcasebrain/briefcase-ai-core/blob/main/LICENSE) file for details.
|
|
236
|
+
|
|
237
|
+
## Related Packages
|
|
238
|
+
|
|
239
|
+
- [`briefcase-ai`](https://pypi.org/project/briefcase-ai/) - Python bindings
|
|
240
|
+
- [`briefcase-core`](https://crates.io/crates/briefcase-core) - Rust crate
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
**Briefcase AI** - Making AI decisions transparent, reproducible, and observable.
|
package/briefcase_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"Briefcase AI Team"
|
|
6
6
|
],
|
|
7
7
|
"description": "WebAssembly bindings for Briefcase AI",
|
|
8
|
-
"version": "2.0.
|
|
8
|
+
"version": "2.0.2",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -20,5 +20,12 @@
|
|
|
20
20
|
"types": "briefcase_wasm.d.ts",
|
|
21
21
|
"sideEffects": [
|
|
22
22
|
"./snippets/*"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"ai",
|
|
26
|
+
"observability",
|
|
27
|
+
"replay",
|
|
28
|
+
"webassembly",
|
|
29
|
+
"wasm"
|
|
23
30
|
]
|
|
24
31
|
}
|