@mongrov/analytics 0.1.0-alpha.10 → 0.1.0-alpha.8
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 +21 -0
- package/README.md +0 -16
- package/dist/tools/index.d.ts +1 -13
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -21
- package/dist/tools/index.js.map +1 -1
- package/package.json +16 -31
- package/dist/tools/__fakes__/engine.d.ts +0 -25
- package/dist/tools/__fakes__/engine.d.ts.map +0 -1
- package/dist/tools/__fakes__/engine.js +0 -37
- package/dist/tools/__fakes__/engine.js.map +0 -1
- package/dist/tools/audit.d.ts +0 -31
- package/dist/tools/audit.d.ts.map +0 -1
- package/dist/tools/audit.js +0 -157
- package/dist/tools/audit.js.map +0 -1
- package/dist/tools/authorize.d.ts +0 -36
- package/dist/tools/authorize.d.ts.map +0 -1
- package/dist/tools/authorize.js +0 -87
- package/dist/tools/authorize.js.map +0 -1
- package/dist/tools/budget.d.ts +0 -15
- package/dist/tools/budget.d.ts.map +0 -1
- package/dist/tools/budget.js +0 -64
- package/dist/tools/budget.js.map +0 -1
- package/dist/tools/factory.d.ts +0 -43
- package/dist/tools/factory.d.ts.map +0 -1
- package/dist/tools/factory.js +0 -137
- package/dist/tools/factory.js.map +0 -1
- package/dist/tools/formatters.d.ts +0 -17
- package/dist/tools/formatters.d.ts.map +0 -1
- package/dist/tools/formatters.js +0 -30
- package/dist/tools/formatters.js.map +0 -1
- package/dist/tools/impls/activity.d.ts +0 -15
- package/dist/tools/impls/activity.d.ts.map +0 -1
- package/dist/tools/impls/activity.js +0 -61
- package/dist/tools/impls/activity.js.map +0 -1
- package/dist/tools/impls/anomaly.d.ts +0 -21
- package/dist/tools/impls/anomaly.d.ts.map +0 -1
- package/dist/tools/impls/anomaly.js +0 -70
- package/dist/tools/impls/anomaly.js.map +0 -1
- package/dist/tools/impls/compare.d.ts +0 -21
- package/dist/tools/impls/compare.d.ts.map +0 -1
- package/dist/tools/impls/compare.js +0 -68
- package/dist/tools/impls/compare.js.map +0 -1
- package/dist/tools/impls/hrv.d.ts +0 -15
- package/dist/tools/impls/hrv.d.ts.map +0 -1
- package/dist/tools/impls/hrv.js +0 -36
- package/dist/tools/impls/hrv.js.map +0 -1
- package/dist/tools/impls/insights.d.ts +0 -18
- package/dist/tools/impls/insights.d.ts.map +0 -1
- package/dist/tools/impls/insights.js +0 -41
- package/dist/tools/impls/insights.js.map +0 -1
- package/dist/tools/impls/sleep.d.ts +0 -15
- package/dist/tools/impls/sleep.d.ts.map +0 -1
- package/dist/tools/impls/sleep.js +0 -43
- package/dist/tools/impls/sleep.js.map +0 -1
- package/dist/tools/mcp/adapter.d.ts +0 -33
- package/dist/tools/mcp/adapter.d.ts.map +0 -1
- package/dist/tools/mcp/adapter.js +0 -56
- package/dist/tools/mcp/adapter.js.map +0 -1
- package/dist/tools/mcp/guard.d.ts +0 -17
- package/dist/tools/mcp/guard.d.ts.map +0 -1
- package/dist/tools/mcp/guard.js +0 -22
- package/dist/tools/mcp/guard.js.map +0 -1
- package/dist/tools/mcp/index.d.ts +0 -20
- package/dist/tools/mcp/index.d.ts.map +0 -1
- package/dist/tools/mcp/index.js +0 -16
- package/dist/tools/mcp/index.js.map +0 -1
- package/dist/tools/mcp/server.d.ts +0 -39
- package/dist/tools/mcp/server.d.ts.map +0 -1
- package/dist/tools/mcp/server.js +0 -70
- package/dist/tools/mcp/server.js.map +0 -1
- package/dist/tools/mcp/transports/http.d.ts +0 -54
- package/dist/tools/mcp/transports/http.d.ts.map +0 -1
- package/dist/tools/mcp/transports/http.js +0 -133
- package/dist/tools/mcp/transports/http.js.map +0 -1
- package/dist/tools/mcp/transports/stdio.d.ts +0 -22
- package/dist/tools/mcp/transports/stdio.d.ts.map +0 -1
- package/dist/tools/mcp/transports/stdio.js +0 -19
- package/dist/tools/mcp/transports/stdio.js.map +0 -1
- package/dist/tools/rate-limit.d.ts +0 -26
- package/dist/tools/rate-limit.d.ts.map +0 -1
- package/dist/tools/rate-limit.js +0 -67
- package/dist/tools/rate-limit.js.map +0 -1
- package/dist/tools/types.d.ts +0 -121
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js +0 -16
- package/dist/tools/types.js.map +0 -1
- package/dist/tools/wrap.d.ts +0 -53
- package/dist/tools/wrap.d.ts.map +0 -1
- package/dist/tools/wrap.js +0 -135
- package/dist/tools/wrap.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Mongrov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -451,22 +451,6 @@ Fixture exports used across mapper + firmware tests live at
|
|
|
451
451
|
Consumers writing their own regression tests can import them via a relative
|
|
452
452
|
path inside this workspace; they are excluded from the published `dist/`.
|
|
453
453
|
|
|
454
|
-
## AI tools (`@mongrov/analytics/tools`)
|
|
455
|
-
|
|
456
|
-
Six read-only AI SDK v4 tools (`getHRV`, `getSleepSummary`,
|
|
457
|
-
`getActivityTotal`, `compareTrend`, `detectAnomaly`, `getInsights`)
|
|
458
|
-
sit on top of the warehouse, wired through a
|
|
459
|
-
`rate → auth → execute → budget → audit` chain. See
|
|
460
|
-
[`src/tools/README.md`](./src/tools/README.md).
|
|
461
|
-
|
|
462
|
-
### MCP dev server (`@mongrov/analytics/tools/mcp`)
|
|
463
|
-
|
|
464
|
-
Same six tools, exposed over Model Context Protocol via stdio
|
|
465
|
-
(Claude Desktop) or HTTP with bearer auth (MCP Inspector, curl).
|
|
466
|
-
Dev-guarded (`shouldStartMcpServer()`) + `sideEffects: false` so
|
|
467
|
-
prod RN bundles drop the SDK. See
|
|
468
|
-
[`src/tools/mcp/README.md`](./src/tools/mcp/README.md).
|
|
469
|
-
|
|
470
454
|
## License
|
|
471
455
|
|
|
472
456
|
MIT
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './authorize';
|
|
3
|
-
export * from './budget';
|
|
4
|
-
export * from './factory';
|
|
5
|
-
export * from './rate-limit';
|
|
6
|
-
export * from './types';
|
|
7
|
-
export * from './wrap';
|
|
8
|
-
export { getHRV, getHRVInputSchema, type GetHRVInput, } from './impls/hrv';
|
|
9
|
-
export { getSleepSummary, getSleepSummaryInputSchema, type GetSleepSummaryInput, } from './impls/sleep';
|
|
10
|
-
export { getActivityTotal, getActivityTotalInputSchema, type GetActivityTotalInput, } from './impls/activity';
|
|
11
|
-
export { compareTrend, compareTrendInputSchema, type CompareTrendInput, } from './impls/compare';
|
|
12
|
-
export { detectAnomaly, detectAnomalyInputSchema, type DetectAnomalyInput, } from './impls/anomaly';
|
|
13
|
-
export { getInsights, getInsightsInputSchema, type GetInsightsInput, } from './impls/insights';
|
|
1
|
+
export {};
|
|
14
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAA"}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// v0.1.0-alpha (T-01..T-12 landed): tool impls, formatters, rate
|
|
4
|
-
// limiter, authorize hooks (with optional familyMembersProvider),
|
|
5
|
-
// batched `tool_call_audit` writer, output-budget helper, `makeTool`
|
|
6
|
-
// wrapper composing rate → auth → execute → budget → audit, and the
|
|
7
|
-
// `createAnalyticsTools` factory returning an AI SDK tool map.
|
|
8
|
-
// MCP subpath (T-13/T-14) still pending.
|
|
9
|
-
export * from './audit';
|
|
10
|
-
export * from './authorize';
|
|
11
|
-
export * from './budget';
|
|
12
|
-
export * from './factory';
|
|
13
|
-
export * from './rate-limit';
|
|
14
|
-
export * from './types';
|
|
15
|
-
export * from './wrap';
|
|
16
|
-
export { getHRV, getHRVInputSchema, } from './impls/hrv';
|
|
17
|
-
export { getSleepSummary, getSleepSummaryInputSchema, } from './impls/sleep';
|
|
18
|
-
export { getActivityTotal, getActivityTotalInputSchema, } from './impls/activity';
|
|
19
|
-
export { compareTrend, compareTrendInputSchema, } from './impls/compare';
|
|
20
|
-
export { detectAnomaly, detectAnomalyInputSchema, } from './impls/anomaly';
|
|
21
|
-
export { getInsights, getInsightsInputSchema, } from './impls/insights';
|
|
1
|
+
export {};
|
|
22
2
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongrov/analytics",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"sideEffects": false,
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
5
4
|
"description": "DuckDB + R2 Iceberg local analytics for @mongrov apps",
|
|
6
5
|
"license": "MIT",
|
|
7
6
|
"repository": {
|
|
@@ -39,11 +38,6 @@
|
|
|
39
38
|
"import": "./dist/tools/index.js",
|
|
40
39
|
"default": "./dist/tools/index.js"
|
|
41
40
|
},
|
|
42
|
-
"./tools/mcp": {
|
|
43
|
-
"types": "./dist/tools/mcp/index.d.ts",
|
|
44
|
-
"import": "./dist/tools/mcp/index.js",
|
|
45
|
-
"default": "./dist/tools/mcp/index.js"
|
|
46
|
-
},
|
|
47
41
|
"./sync": {
|
|
48
42
|
"types": "./dist/sync/index.d.ts",
|
|
49
43
|
"import": "./dist/sync/index.js",
|
|
@@ -58,28 +52,14 @@
|
|
|
58
52
|
"files": [
|
|
59
53
|
"dist"
|
|
60
54
|
],
|
|
61
|
-
"scripts": {
|
|
62
|
-
"build": "tsc -p tsconfig.build.json",
|
|
63
|
-
"clean": "rm -rf dist",
|
|
64
|
-
"prebuild": "pnpm run clean",
|
|
65
|
-
"test": "vitest run",
|
|
66
|
-
"test:watch": "vitest",
|
|
67
|
-
"typecheck": "tsc --noEmit",
|
|
68
|
-
"prepublishOnly": "pnpm run build"
|
|
69
|
-
},
|
|
70
55
|
"peerDependencies": {
|
|
71
|
-
"@modelcontextprotocol/sdk": ">=1.20.0",
|
|
72
|
-
"@mongrov/db": "workspace:*",
|
|
73
56
|
"@mongrov/types": "^0.4.0",
|
|
74
|
-
"ai": ">=4",
|
|
75
57
|
"react": ">=19",
|
|
76
58
|
"react-native": ">=0.81",
|
|
77
|
-
"react-native-duckdb": ">=1.0.0"
|
|
59
|
+
"react-native-duckdb": ">=1.0.0",
|
|
60
|
+
"@mongrov/db": "0.3.0"
|
|
78
61
|
},
|
|
79
62
|
"peerDependenciesMeta": {
|
|
80
|
-
"@modelcontextprotocol/sdk": {
|
|
81
|
-
"optional": true
|
|
82
|
-
},
|
|
83
63
|
"react": {
|
|
84
64
|
"optional": true
|
|
85
65
|
},
|
|
@@ -94,23 +74,28 @@
|
|
|
94
74
|
"@iarna/toml": "^2.2.5",
|
|
95
75
|
"date-fns-tz": "^3.2.0",
|
|
96
76
|
"p-queue": "^8.0.1",
|
|
97
|
-
"xstate": "^5.30.0"
|
|
98
|
-
"zod-to-json-schema": "^3.25.2"
|
|
77
|
+
"xstate": "^5.30.0"
|
|
99
78
|
},
|
|
100
79
|
"devDependencies": {
|
|
101
|
-
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
102
|
-
"@mongrov/db": "workspace:*",
|
|
103
|
-
"@mongrov/types": "workspace:*",
|
|
104
80
|
"@testing-library/react": "^14.3.1",
|
|
105
81
|
"@types/react": "^18.3.12",
|
|
106
82
|
"@types/react-dom": "^18.3.1",
|
|
107
|
-
"ai": "^4.3.0",
|
|
108
83
|
"fast-check": "^4.9.0",
|
|
109
84
|
"jsdom": "^25.0.1",
|
|
110
85
|
"react": "^18.3.1",
|
|
111
86
|
"react-dom": "^18.3.1",
|
|
112
87
|
"typescript": "^5.9.3",
|
|
113
88
|
"vitest": "^2.1.9",
|
|
114
|
-
"zod": "^3.23.8"
|
|
89
|
+
"zod": "^3.23.8",
|
|
90
|
+
"@mongrov/db": "0.3.0",
|
|
91
|
+
"@mongrov/types": "0.4.0"
|
|
92
|
+
},
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "tsc -p tsconfig.build.json",
|
|
95
|
+
"clean": "rm -rf dist",
|
|
96
|
+
"prebuild": "pnpm run clean",
|
|
97
|
+
"test": "vitest run",
|
|
98
|
+
"test:watch": "vitest",
|
|
99
|
+
"typecheck": "tsc --noEmit"
|
|
115
100
|
}
|
|
116
|
-
}
|
|
101
|
+
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { AnalyticsEngine } from '../../core/types';
|
|
2
|
-
/**
|
|
3
|
-
* Scriptable AnalyticsEngine fake for tool tests.
|
|
4
|
-
*
|
|
5
|
-
* Unlike the rules-side fake (single global queue), this fake supports
|
|
6
|
-
* per-SQL-substring row queues so multi-query tools (compare, activity)
|
|
7
|
-
* can script distinct responses per call.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* const engine = createFakeEngine()
|
|
11
|
-
* engine.queueRows('FROM hrv', [{ day: '2026-07-08', avg_hrv: 45 }])
|
|
12
|
-
* engine.queueRows('FROM sleep_session', [...])
|
|
13
|
-
* // ...invoke tool...
|
|
14
|
-
* engine.calls.forEach(c => ...)
|
|
15
|
-
*/
|
|
16
|
-
export interface FakeEngine extends AnalyticsEngine {
|
|
17
|
-
readonly calls: {
|
|
18
|
-
sql: string;
|
|
19
|
-
params: Record<string, unknown>;
|
|
20
|
-
}[];
|
|
21
|
-
queueRows: (sqlSubstring: string, rows: unknown[]) => void;
|
|
22
|
-
setError: (err: Error | null) => void;
|
|
23
|
-
}
|
|
24
|
-
export declare function createFakeEngine(): FakeEngine;
|
|
25
|
-
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../../src/tools/__fakes__/engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,UAAW,SAAQ,eAAe;IACjD,QAAQ,CAAC,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAAE,CAAA;IAClE,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;IAC1D,QAAQ,EAAE,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAA;CACtC;AAED,wBAAgB,gBAAgB,IAAI,UAAU,CAkC7C"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function createFakeEngine() {
|
|
2
|
-
const queues = [];
|
|
3
|
-
const calls = [];
|
|
4
|
-
let error = null;
|
|
5
|
-
const engine = {
|
|
6
|
-
async attach() { },
|
|
7
|
-
async detach() { },
|
|
8
|
-
async execute(sql, params) {
|
|
9
|
-
calls.push({ sql, params: params ?? {} });
|
|
10
|
-
if (error)
|
|
11
|
-
throw error;
|
|
12
|
-
const idx = queues.findIndex(q => sql.includes(q.substring));
|
|
13
|
-
if (idx === -1)
|
|
14
|
-
return [];
|
|
15
|
-
const [q] = queues.splice(idx, 1);
|
|
16
|
-
return q.rows;
|
|
17
|
-
},
|
|
18
|
-
stream() {
|
|
19
|
-
throw new Error('stream not implemented in fake');
|
|
20
|
-
},
|
|
21
|
-
createAppender() {
|
|
22
|
-
throw new Error('createAppender not implemented in fake');
|
|
23
|
-
},
|
|
24
|
-
state: 'attached',
|
|
25
|
-
lastError: null,
|
|
26
|
-
catalog: 'fake',
|
|
27
|
-
subscribe: () => () => { },
|
|
28
|
-
async setRetention() { },
|
|
29
|
-
async getLastAttach() { return null; },
|
|
30
|
-
async close() { },
|
|
31
|
-
calls,
|
|
32
|
-
queueRows(substring, rows) { queues.push({ substring, rows }); },
|
|
33
|
-
setError(err) { error = err; },
|
|
34
|
-
};
|
|
35
|
-
return engine;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../src/tools/__fakes__/engine.ts"],"names":[],"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MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA,CAAC,CAAC;QAC/D,QAAQ,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAA,CAAC,CAAC;KAC9B,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/tools/audit.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Batched writer for `tool_call_audit`.
|
|
3
|
-
*
|
|
4
|
-
* `record()` enqueues synchronously (non-blocking). The batch flushes
|
|
5
|
-
* whenever:
|
|
6
|
-
* - the pending queue reaches `batchSize` (default 10), or
|
|
7
|
-
* - the flush timer fires (`flushIntervalMs`, default 1000ms).
|
|
8
|
-
*
|
|
9
|
-
* `flush()` and `close()` are cooperative exit hooks — `close`
|
|
10
|
-
* additionally halts the timer.
|
|
11
|
-
*
|
|
12
|
-
* On flush failure the batch is retained and retried on the next
|
|
13
|
-
* tick. A defensive `MAX_CONSECUTIVE_FAILURES` cap drops the buffer
|
|
14
|
-
* after repeated errors to avoid unbounded growth on a stuck
|
|
15
|
-
* warehouse.
|
|
16
|
-
*
|
|
17
|
-
* SQL uses a single INSERT with a suffix-indexed VALUES tuple per
|
|
18
|
-
* row (`$p0_ts, $p0_brand, …, $p1_ts, …`). DuckDB honors named
|
|
19
|
-
* parameters in this form.
|
|
20
|
-
*/
|
|
21
|
-
import type { AnalyticsEngine } from '../core/types';
|
|
22
|
-
import type { AuditWriter, ToolsLogger } from './types';
|
|
23
|
-
export interface CreateAuditWriterConfig {
|
|
24
|
-
analytics: AnalyticsEngine;
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
batchSize?: number;
|
|
27
|
-
flushIntervalMs?: number;
|
|
28
|
-
logger?: ToolsLogger;
|
|
29
|
-
}
|
|
30
|
-
export declare function createAuditWriter(cfg: CreateAuditWriterConfig): AuditWriter;
|
|
31
|
-
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/tools/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,KAAK,EAAc,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAoBnE,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,eAAe,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,uBAAuB,GAAG,WAAW,CA6F3E"}
|
package/dist/tools/audit.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Batched writer for `tool_call_audit`.
|
|
3
|
-
*
|
|
4
|
-
* `record()` enqueues synchronously (non-blocking). The batch flushes
|
|
5
|
-
* whenever:
|
|
6
|
-
* - the pending queue reaches `batchSize` (default 10), or
|
|
7
|
-
* - the flush timer fires (`flushIntervalMs`, default 1000ms).
|
|
8
|
-
*
|
|
9
|
-
* `flush()` and `close()` are cooperative exit hooks — `close`
|
|
10
|
-
* additionally halts the timer.
|
|
11
|
-
*
|
|
12
|
-
* On flush failure the batch is retained and retried on the next
|
|
13
|
-
* tick. A defensive `MAX_CONSECUTIVE_FAILURES` cap drops the buffer
|
|
14
|
-
* after repeated errors to avoid unbounded growth on a stuck
|
|
15
|
-
* warehouse.
|
|
16
|
-
*
|
|
17
|
-
* SQL uses a single INSERT with a suffix-indexed VALUES tuple per
|
|
18
|
-
* row (`$p0_ts, $p0_brand, …, $p1_ts, …`). DuckDB honors named
|
|
19
|
-
* parameters in this form.
|
|
20
|
-
*/
|
|
21
|
-
const DEFAULT_BATCH_SIZE = 10;
|
|
22
|
-
const DEFAULT_FLUSH_INTERVAL_MS = 1000;
|
|
23
|
-
const MAX_CONSECUTIVE_FAILURES = 5;
|
|
24
|
-
const COLUMNS = [
|
|
25
|
-
'ts',
|
|
26
|
-
'brand',
|
|
27
|
-
'family_id',
|
|
28
|
-
'requester_user_id',
|
|
29
|
-
'tool_name',
|
|
30
|
-
'args',
|
|
31
|
-
'result_bytes',
|
|
32
|
-
'result_row_count',
|
|
33
|
-
'latency_ms',
|
|
34
|
-
'outcome',
|
|
35
|
-
'error_message',
|
|
36
|
-
];
|
|
37
|
-
export function createAuditWriter(cfg) {
|
|
38
|
-
const enabled = cfg.enabled ?? true;
|
|
39
|
-
const batchSize = cfg.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
40
|
-
const flushIntervalMs = cfg.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
41
|
-
const logger = cfg.logger;
|
|
42
|
-
const pending = [];
|
|
43
|
-
let timer = null;
|
|
44
|
-
let consecutiveFailures = 0;
|
|
45
|
-
let inFlight = null;
|
|
46
|
-
let closed = false;
|
|
47
|
-
function ensureTimer() {
|
|
48
|
-
if (timer || closed)
|
|
49
|
-
return;
|
|
50
|
-
timer = setInterval(() => {
|
|
51
|
-
void doFlush();
|
|
52
|
-
}, flushIntervalMs);
|
|
53
|
-
// Node timers are keep-alive by default; unref so a lingering
|
|
54
|
-
// audit writer doesn't block process exit.
|
|
55
|
-
if (typeof timer.unref === 'function') {
|
|
56
|
-
timer.unref();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function clearFlushTimer() {
|
|
60
|
-
if (!timer)
|
|
61
|
-
return;
|
|
62
|
-
clearInterval(timer);
|
|
63
|
-
timer = null;
|
|
64
|
-
}
|
|
65
|
-
async function doFlush() {
|
|
66
|
-
if (inFlight)
|
|
67
|
-
return inFlight;
|
|
68
|
-
if (pending.length === 0)
|
|
69
|
-
return;
|
|
70
|
-
const batch = pending.splice(0, pending.length);
|
|
71
|
-
inFlight = (async () => {
|
|
72
|
-
try {
|
|
73
|
-
await writeBatch(cfg.analytics, batch);
|
|
74
|
-
consecutiveFailures = 0;
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
consecutiveFailures += 1;
|
|
78
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
79
|
-
logger?.warn('audit flush failed', {
|
|
80
|
-
err: errMsg,
|
|
81
|
-
batchSize: batch.length,
|
|
82
|
-
consecutiveFailures,
|
|
83
|
-
});
|
|
84
|
-
if (consecutiveFailures >= MAX_CONSECUTIVE_FAILURES) {
|
|
85
|
-
logger?.error('audit flush cap reached, dropping batch', {
|
|
86
|
-
droppedRows: batch.length,
|
|
87
|
-
});
|
|
88
|
-
consecutiveFailures = 0;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
// Retain: prepend so retry preserves order.
|
|
92
|
-
pending.unshift(...batch);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
finally {
|
|
96
|
-
inFlight = null;
|
|
97
|
-
}
|
|
98
|
-
})();
|
|
99
|
-
return inFlight;
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
record(entry) {
|
|
103
|
-
if (!enabled || closed)
|
|
104
|
-
return;
|
|
105
|
-
pending.push(entry);
|
|
106
|
-
ensureTimer();
|
|
107
|
-
if (pending.length >= batchSize) {
|
|
108
|
-
void doFlush();
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
async flush() {
|
|
112
|
-
if (!enabled)
|
|
113
|
-
return;
|
|
114
|
-
await doFlush();
|
|
115
|
-
// If the flush swallowed a failure and re-queued, drain once
|
|
116
|
-
// more so callers get a best-effort guarantee.
|
|
117
|
-
if (pending.length > 0) {
|
|
118
|
-
await doFlush();
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
async close() {
|
|
122
|
-
closed = true;
|
|
123
|
-
clearFlushTimer();
|
|
124
|
-
if (!enabled)
|
|
125
|
-
return;
|
|
126
|
-
await doFlush();
|
|
127
|
-
if (pending.length > 0) {
|
|
128
|
-
await doFlush();
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
async function writeBatch(analytics, batch) {
|
|
134
|
-
if (batch.length === 0)
|
|
135
|
-
return;
|
|
136
|
-
const tuples = [];
|
|
137
|
-
const params = {};
|
|
138
|
-
batch.forEach((entry, i) => {
|
|
139
|
-
const prefix = `p${i}`;
|
|
140
|
-
const placeholders = COLUMNS.map(col => `$${prefix}_${col}`);
|
|
141
|
-
tuples.push(`(${placeholders.join(', ')})`);
|
|
142
|
-
params[`${prefix}_ts`] = entry.ts;
|
|
143
|
-
params[`${prefix}_brand`] = entry.brand;
|
|
144
|
-
params[`${prefix}_family_id`] = entry.familyId;
|
|
145
|
-
params[`${prefix}_requester_user_id`] = entry.requesterUserId;
|
|
146
|
-
params[`${prefix}_tool_name`] = entry.toolName;
|
|
147
|
-
params[`${prefix}_args`] = JSON.stringify(entry.args);
|
|
148
|
-
params[`${prefix}_result_bytes`] = entry.resultBytes;
|
|
149
|
-
params[`${prefix}_result_row_count`] = entry.resultRowCount;
|
|
150
|
-
params[`${prefix}_latency_ms`] = entry.latencyMs;
|
|
151
|
-
params[`${prefix}_outcome`] = entry.outcome;
|
|
152
|
-
params[`${prefix}_error_message`] = entry.errorMessage;
|
|
153
|
-
});
|
|
154
|
-
const sql = `INSERT INTO tool_call_audit (${COLUMNS.join(', ')}) VALUES ${tuples.join(', ')}`;
|
|
155
|
-
await analytics.execute(sql, params);
|
|
156
|
-
}
|
|
157
|
-
//# sourceMappingURL=audit.js.map
|
package/dist/tools/audit.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/tools/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,MAAM,kBAAkB,GAAG,EAAE,CAAA;AAC7B,MAAM,yBAAy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A;QACvC,MAAM,CAAC,GAAG,MAAM,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAA;QAC9C,MAAM,CAAC,GAAG,MAAM,oBAAoB,CAAC,GAAG,KAAK,CAAC,eAAe,CAAA;QAC7D,MAAM,CAAC,GAAG,MAAM,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAA;QAC9C,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACrD,MAAM,CAAC,GAAG,MAAM,eAAe,CAAC,GAAG,KAAK,CAAC,WAAW,CAAA;QACpD,MAAM,CAAC,GAAG,MAAM,mBAAmB,CAAC,GAAG,KAAK,CAAC,cAAc,CAAA;QAC3D,MAAM,CAAC,GAAG,MAAM,aAAa,CAAC,GAAG,KAAK,CAAC,SAAS,CAAA;QAChD,MAAM,CAAC,GAAG,MAAM,UAAU,CAAC,GAAG,KAAK,CAAC,OAAO,CAAA;QAC3C,MAAM,CAAC,GAAG,MAAM,gBAAgB,CAAC,GAAG,KAAK,CAAC,YAAY,CAAA;IACxD,CAAC,CAAC,CAAA;IAEF,MAAM,GAAG,GACL,gCAAgC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAErF,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AACtC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorize hooks for analytics tools.
|
|
3
|
-
*
|
|
4
|
-
* `familyScopeAuthorize` — grants access iff `args.userId` is either
|
|
5
|
-
* the requester themselves or another member of the requester's
|
|
6
|
-
* family. When `config.familyMembersProvider` is supplied (the
|
|
7
|
-
* factory path since T-11), membership resolves via that provider;
|
|
8
|
-
* otherwise the legacy SQL path against a `family_member` table is
|
|
9
|
-
* used (kept for standalone hook usage and backwards compat).
|
|
10
|
-
*
|
|
11
|
-
* Both hooks fail closed on any error — provider throws, engine
|
|
12
|
-
* throws, missing/malformed args — return `false` rather than
|
|
13
|
-
* surfacing the error to the LLM.
|
|
14
|
-
*/
|
|
15
|
-
import type { AnalyticsEngine, FamilyMembersProvider } from '../core/types';
|
|
16
|
-
import type { AuthorizeFn } from './types';
|
|
17
|
-
export interface AuthorizeConfig {
|
|
18
|
-
/**
|
|
19
|
-
* When present, membership is resolved via the provider instead of
|
|
20
|
-
* SQL. This is the path wired by `createAnalyticsTools`.
|
|
21
|
-
*/
|
|
22
|
-
familyMembersProvider?: FamilyMembersProvider;
|
|
23
|
-
}
|
|
24
|
-
export declare function familyScopeAuthorize(analytics: AnalyticsEngine, config?: AuthorizeConfig): AuthorizeFn;
|
|
25
|
-
/**
|
|
26
|
-
* `orgScopeAuthorize` — parity with family scope but against an
|
|
27
|
-
* `org_member` table. Orgs are not first-class in v0.1.0; the ctx
|
|
28
|
-
* `familyId` is treated as the org id until org membership is wired
|
|
29
|
-
* through `RequestContext`.
|
|
30
|
-
*
|
|
31
|
-
* When `familyMembersProvider` is supplied, the same provider is
|
|
32
|
-
* consulted (v0.1.0 shim — a dedicated `orgMembersProvider` will
|
|
33
|
-
* split out once orgs land).
|
|
34
|
-
*/
|
|
35
|
-
export declare function orgScopeAuthorize(analytics: AnalyticsEngine, config?: AuthorizeConfig): AuthorizeFn;
|
|
36
|
-
//# sourceMappingURL=authorize.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../src/tools/authorize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,qBAAqB,CAAA;CAC9C;AAED,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,eAAe,EAC1B,MAAM,GAAE,eAAoB,GAC3B,WAAW,CAmCb;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,eAAe,EAC1B,MAAM,GAAE,eAAoB,GAC3B,WAAW,CAmCb"}
|
package/dist/tools/authorize.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorize hooks for analytics tools.
|
|
3
|
-
*
|
|
4
|
-
* `familyScopeAuthorize` — grants access iff `args.userId` is either
|
|
5
|
-
* the requester themselves or another member of the requester's
|
|
6
|
-
* family. When `config.familyMembersProvider` is supplied (the
|
|
7
|
-
* factory path since T-11), membership resolves via that provider;
|
|
8
|
-
* otherwise the legacy SQL path against a `family_member` table is
|
|
9
|
-
* used (kept for standalone hook usage and backwards compat).
|
|
10
|
-
*
|
|
11
|
-
* Both hooks fail closed on any error — provider throws, engine
|
|
12
|
-
* throws, missing/malformed args — return `false` rather than
|
|
13
|
-
* surfacing the error to the LLM.
|
|
14
|
-
*/
|
|
15
|
-
export function familyScopeAuthorize(analytics, config = {}) {
|
|
16
|
-
return async (_toolName, args, ctx) => {
|
|
17
|
-
const targetUserId = args.userId;
|
|
18
|
-
if (typeof targetUserId !== 'string' || targetUserId.length === 0) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (targetUserId === ctx.requesterUserId) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (config.familyMembersProvider) {
|
|
25
|
-
try {
|
|
26
|
-
const members = await config.familyMembersProvider({
|
|
27
|
-
brand: ctx.brand,
|
|
28
|
-
familyId: ctx.familyId,
|
|
29
|
-
});
|
|
30
|
-
return members.includes(targetUserId);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const rows = await analytics.execute('SELECT 1 AS one FROM family_member '
|
|
38
|
-
+ 'WHERE family_id = $familyId AND user_id = $userId LIMIT 1', { familyId: ctx.familyId, userId: targetUserId });
|
|
39
|
-
return rows.length > 0;
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* `orgScopeAuthorize` — parity with family scope but against an
|
|
48
|
-
* `org_member` table. Orgs are not first-class in v0.1.0; the ctx
|
|
49
|
-
* `familyId` is treated as the org id until org membership is wired
|
|
50
|
-
* through `RequestContext`.
|
|
51
|
-
*
|
|
52
|
-
* When `familyMembersProvider` is supplied, the same provider is
|
|
53
|
-
* consulted (v0.1.0 shim — a dedicated `orgMembersProvider` will
|
|
54
|
-
* split out once orgs land).
|
|
55
|
-
*/
|
|
56
|
-
export function orgScopeAuthorize(analytics, config = {}) {
|
|
57
|
-
return async (_toolName, args, ctx) => {
|
|
58
|
-
const targetUserId = args.userId;
|
|
59
|
-
if (typeof targetUserId !== 'string' || targetUserId.length === 0) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
if (targetUserId === ctx.requesterUserId) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
if (config.familyMembersProvider) {
|
|
66
|
-
try {
|
|
67
|
-
const members = await config.familyMembersProvider({
|
|
68
|
-
brand: ctx.brand,
|
|
69
|
-
familyId: ctx.familyId,
|
|
70
|
-
});
|
|
71
|
-
return members.includes(targetUserId);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
try {
|
|
78
|
-
const rows = await analytics.execute('SELECT 1 AS one FROM org_member '
|
|
79
|
-
+ 'WHERE org_id = $orgId AND user_id = $userId LIMIT 1', { orgId: ctx.familyId, userId: targetUserId });
|
|
80
|
-
return rows.length > 0;
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=authorize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../../src/tools/authorize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAaH,MAAM,UAAU,oBAAoB,CAClC,SAA0B,EAC1B,SAA0B,EAAE;IAE5B,OAAO,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE;QACpC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAA;QAChC,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClE,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,YAAY,KAAK,GAAG,CAAC,eAAe,EAAE,CAAC;YACzC,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;YACjC,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC;oBACjD,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;iBACvB,CAAC,CAAA;gBACF,OAAO,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;YACvC,CAAC;YACD,MAAM,CAAC;gBACL,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,OAAO,CAClC,qCAAqC;kBACnC,2DAA2D,EAC7D,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,CACjD,CAAA;YACD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;QACxB,CAAC;QACD,MAAM,CAAC;YACL,OAAO,KA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4
|
-
* `applyOutputBudget` truncates `ToolResult.text` when its UTF-8
|
|
5
|
-
* byte size exceeds `budget.maxBytes`, appending a `\n[truncated]`
|
|
6
|
-
* suffix. Truncation is UTF-8-safe: bytes are sliced and re-decoded
|
|
7
|
-
* with `fatal: false` so any partial multi-byte codepoint at the
|
|
8
|
-
* boundary is dropped rather than emitting invalid sequences.
|
|
9
|
-
*
|
|
10
|
-
* `budget.maxRows` is informational — tool impls limit row count
|
|
11
|
-
* via SQL LIMIT. This helper does not attempt row-level truncation.
|
|
12
|
-
*/
|
|
13
|
-
import type { OutputBudget, ToolResult } from './types';
|
|
14
|
-
export declare function applyOutputBudget(result: ToolResult, budget: OutputBudget): ToolResult;
|
|
15
|
-
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../src/tools/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIvD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,YAAY,GACnB,UAAU,CAiBZ"}
|