@ganju/utils 0.0.15 → 0.0.16
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/dist/constants.d.ts +23 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +95 -8
- package/dist/data.d.ts +9 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +78 -0
- package/dist/dataApi.d.ts +511 -0
- package/dist/dataApi.d.ts.map +1 -0
- package/dist/dataApi.js +355 -0
- package/dist/dataCompiler.d.ts +68 -0
- package/dist/dataCompiler.d.ts.map +1 -0
- package/dist/dataCompiler.js +726 -0
- package/dist/dataDdl.d.ts +29 -0
- package/dist/dataDdl.d.ts.map +1 -0
- package/dist/dataDdl.js +354 -0
- package/dist/dataEngine.d.ts +143 -0
- package/dist/dataEngine.d.ts.map +1 -0
- package/dist/dataEngine.js +2022 -0
- package/dist/dataIdentifiers.d.ts +8 -0
- package/dist/dataIdentifiers.d.ts.map +1 -0
- package/dist/dataIdentifiers.js +55 -0
- package/dist/dataImport.d.ts +77 -0
- package/dist/dataImport.d.ts.map +1 -0
- package/dist/dataImport.js +450 -0
- package/dist/dataRpc.d.ts +131 -0
- package/dist/dataRpc.d.ts.map +1 -0
- package/dist/dataRpc.js +2 -0
- package/dist/dataTypes.d.ts +157 -0
- package/dist/dataTypes.d.ts.map +1 -0
- package/dist/dataTypes.js +160 -0
- package/dist/index.d.ts +308 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/oauth.d.ts +14 -0
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +42 -2
- package/dist/resourceRerank.d.ts +3 -2
- package/dist/resourceRerank.d.ts.map +1 -1
- package/dist/resourceRerank.js +5 -2
- package/dist/schema.d.ts +285 -4
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +203 -0
- package/package.json +17 -2
- package/src/constants.ts +108 -8
- package/src/data.ts +74 -0
- package/src/dataApi.ts +428 -0
- package/src/dataCompiler.ts +948 -0
- package/src/dataDdl.ts +419 -0
- package/src/dataEngine.ts +2753 -0
- package/src/dataIdentifiers.ts +63 -0
- package/src/dataImport.ts +554 -0
- package/src/dataRpc.ts +121 -0
- package/src/dataTypes.ts +312 -0
- package/src/index.ts +4 -0
- package/src/oauth.ts +42 -1
- package/src/resourceRerank.ts +5 -2
- package/src/schema.ts +246 -0
package/src/constants.ts
CHANGED
|
@@ -144,6 +144,11 @@ const OAUTH_TOKEN_URLS: Record<string, string> = {
|
|
|
144
144
|
// MCP-proxy OAuth, in both apps/api and apps/mcp).
|
|
145
145
|
const CREDENTIAL_REFRESH_BUFFER_MS = 60 * 1000;
|
|
146
146
|
|
|
147
|
+
// A refresh the token endpoint rejects (4xx) without a reauth code still flags
|
|
148
|
+
// the credential once its access token has been expired this long, so the
|
|
149
|
+
// owner sees it as expired instead of every call failing behind "Connected".
|
|
150
|
+
const CREDENTIAL_REFRESH_GIVE_UP_MS = 60 * 60 * 1000;
|
|
151
|
+
|
|
147
152
|
const GOOGLE_CALENDAR_API_BASE = 'https://www.googleapis.com/calendar/v3';
|
|
148
153
|
|
|
149
154
|
const GOOGLE_DRIVE_API_BASE = 'https://www.googleapis.com/drive/v3';
|
|
@@ -228,7 +233,18 @@ const ONE_DRIVE_TAB_LABELS: ReadonlyArray<{
|
|
|
228
233
|
{ value: ONE_DRIVE_TAB_DRIVES, label: ONE_DRIVE_TAB_LABEL_DRIVES }
|
|
229
234
|
];
|
|
230
235
|
|
|
231
|
-
|
|
236
|
+
// Token-endpoint error codes that mean the stored refresh token is dead and
|
|
237
|
+
// only a reconnect brings it back. `unauthorized_client` is Google's answer
|
|
238
|
+
// when a token no longer belongs to the app it is refreshed with.
|
|
239
|
+
const REAUTH_ERROR_CODES = [
|
|
240
|
+
'invalid_grant',
|
|
241
|
+
'invalid_token',
|
|
242
|
+
'unauthorized_client'
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
// Token-endpoint error codes that are about our own client id / secret, not
|
|
246
|
+
// the user's token: a reconnect can't fix them, so they never flag one.
|
|
247
|
+
const OAUTH_CLIENT_ERROR_CODES = ['invalid_client'];
|
|
232
248
|
|
|
233
249
|
const RESOURCE_TYPE_TOOLTIP_MIN_WIDTH = 300;
|
|
234
250
|
|
|
@@ -992,10 +1008,14 @@ const RESOURCE_SEARCH_RRF_K = 60;
|
|
|
992
1008
|
// keeps its words.
|
|
993
1009
|
const RESOURCE_SEARCH_COMMON_TERM_DIVISOR = 10;
|
|
994
1010
|
const RESOURCE_SEARCH_COMMON_TERM_MIN = 5;
|
|
995
|
-
// Second stage
|
|
996
|
-
//
|
|
997
|
-
//
|
|
998
|
-
//
|
|
1011
|
+
// Second stage: the top fused candidates re-scored by a cross-encoder, which
|
|
1012
|
+
// reads query and chunk together instead of comparing two independently
|
|
1013
|
+
// computed vectors. One model call per search; a failure falls back to the
|
|
1014
|
+
// fused order. Off by default: on the golden sets (Spanish and English) the
|
|
1015
|
+
// fused order matched or beat it on every set — 10 cases better, 5 worse — and
|
|
1016
|
+
// it added 0.5–0.9 s a search plus a ~6 s cold start. The search eval can
|
|
1017
|
+
// still turn it on per request to re-measure.
|
|
1018
|
+
const RESOURCE_SEARCH_RERANK_ENABLED = false;
|
|
999
1019
|
const RESOURCE_SEARCH_RERANK_CANDIDATES = 30;
|
|
1000
1020
|
const RESOURCE_SEARCH_RERANK_MODEL = '@cf/baai/bge-reranker-base';
|
|
1001
1021
|
// An identifier in the query (a code mixing letters and digits, a snake_case
|
|
@@ -1834,6 +1854,10 @@ const MCP_AUTH_KINDS = [MCP_AUTH_KIND_JWT, MCP_AUTH_KIND_INTERNAL];
|
|
|
1834
1854
|
const MCP_SESSION_HEADER = 'mcp-session-id';
|
|
1835
1855
|
|
|
1836
1856
|
const MCP_INTERNAL_HEADER = 'x-ganju-internal-secret';
|
|
1857
|
+
// Sent with the internal secret by the search eval to measure the reranker:
|
|
1858
|
+
// `on` or `off` overrides RESOURCE_SEARCH_RERANK_ENABLED for that request.
|
|
1859
|
+
// Ignored on any other request.
|
|
1860
|
+
const MCP_EVAL_RERANK_HEADER = 'x-ganju-eval-rerank';
|
|
1837
1861
|
const MCP_CHANNEL_ID_HEADER = 'x-ganju-channel-id';
|
|
1838
1862
|
const MCP_CHANNEL_PLATFORM_HEADER = 'x-ganju-channel-platform';
|
|
1839
1863
|
// The conversation a channel turn belongs to. The MCP worker files that turn's
|
|
@@ -2127,6 +2151,40 @@ const PRICING_TOOL_CALL_PER_M_USD = 5;
|
|
|
2127
2151
|
const PRICING_TOOL_CALL_HARD_CAP = 20_000_000;
|
|
2128
2152
|
const PRICING_CUSTOM_DOMAIN_USD = 15;
|
|
2129
2153
|
|
|
2154
|
+
// Project data (one SQLite Durable Object per artifact). Cloudflare caps a
|
|
2155
|
+
// database at 10 GB; we stop writes that add data at 9 GB so there is room to
|
|
2156
|
+
// delete, archive and export.
|
|
2157
|
+
const DATA_MAX_DATABASE_BYTES = 9 * GB;
|
|
2158
|
+
const DATA_MAX_TABLES_PER_DATABASE = 50;
|
|
2159
|
+
const DATA_TRIGGER_RUN_HARD_CAP = 5_000_000;
|
|
2160
|
+
// A deleted database can be restored for this long before its storage is
|
|
2161
|
+
// freed.
|
|
2162
|
+
const DATA_DELETE_GRACE_DAYS = 7;
|
|
2163
|
+
const ARTIFACT_DATABASE_STATUS_CREATING = 'CREATING' as 'CREATING';
|
|
2164
|
+
const ARTIFACT_DATABASE_STATUS_READY = 'READY' as 'READY';
|
|
2165
|
+
const ARTIFACT_DATABASE_STATUS_FAILED = 'FAILED' as 'FAILED';
|
|
2166
|
+
const ARTIFACT_DATABASE_STATUS_DELETING = 'DELETING' as 'DELETING';
|
|
2167
|
+
// The hourly purge has claimed the row and is emptying the object; a restore
|
|
2168
|
+
// can no longer take it back.
|
|
2169
|
+
const ARTIFACT_DATABASE_STATUS_PURGING = 'PURGING' as 'PURGING';
|
|
2170
|
+
const ARTIFACT_DATABASE_STATUS_DELETED = 'DELETED' as 'DELETED';
|
|
2171
|
+
const ARTIFACT_DATABASE_STATUSES = [
|
|
2172
|
+
ARTIFACT_DATABASE_STATUS_CREATING,
|
|
2173
|
+
ARTIFACT_DATABASE_STATUS_READY,
|
|
2174
|
+
ARTIFACT_DATABASE_STATUS_FAILED,
|
|
2175
|
+
ARTIFACT_DATABASE_STATUS_DELETING,
|
|
2176
|
+
ARTIFACT_DATABASE_STATUS_PURGING,
|
|
2177
|
+
ARTIFACT_DATABASE_STATUS_DELETED
|
|
2178
|
+
];
|
|
2179
|
+
// A purge that claimed a row and never finished (the Worker died) is picked
|
|
2180
|
+
// up again after this long.
|
|
2181
|
+
const DATA_PURGE_STALE_MS = 60 * 60 * 1000;
|
|
2182
|
+
// Rows purged per hourly run: each is a call to its database object.
|
|
2183
|
+
const DATA_PURGE_BATCH = 20;
|
|
2184
|
+
// last_read_at / last_write_at move at most this often, so they aren't a
|
|
2185
|
+
// Postgres write per query.
|
|
2186
|
+
const DATA_ACTIVITY_THROTTLE_MS = 60 * 60 * 1000;
|
|
2187
|
+
|
|
2130
2188
|
interface PlanLimits {
|
|
2131
2189
|
// null on any field means "no hard limit" for that plan.
|
|
2132
2190
|
maxProjects: number | null;
|
|
@@ -2192,6 +2250,16 @@ interface PlanLimits {
|
|
|
2192
2250
|
autoSyncIntervals: ReadonlyArray<
|
|
2193
2251
|
typeof RESOURCE_SYNC_INTERVAL_DAILY | typeof RESOURCE_SYNC_INTERVAL_WEEKLY
|
|
2194
2252
|
>;
|
|
2253
|
+
// Whether a project may create a database (tables and rows). Paid-only: the
|
|
2254
|
+
// rows live in a Durable Object we pay storage and rows for. An org that
|
|
2255
|
+
// downgrades keeps its databases, read-only.
|
|
2256
|
+
canUseData: boolean;
|
|
2257
|
+
// Writes that add data stop here, under Cloudflare's 10 GB per database, so
|
|
2258
|
+
// the owner meets a readable "database full" rather than SQLITE_FULL.
|
|
2259
|
+
maxDataBytes: number | null;
|
|
2260
|
+
maxDataTablesPerDatabase: number | null;
|
|
2261
|
+
// Abuse backstop on data trigger runs a month. `null` = no backstop.
|
|
2262
|
+
triggerRunHardCap: number | null;
|
|
2195
2263
|
}
|
|
2196
2264
|
|
|
2197
2265
|
const PLAN_LIMITS: Record<
|
|
@@ -2232,7 +2300,11 @@ const PLAN_LIMITS: Record<
|
|
|
2232
2300
|
toolCallHardCap: 10_000,
|
|
2233
2301
|
includedMessages: 100,
|
|
2234
2302
|
includedEmbeddedBytes: 5 * MB,
|
|
2235
|
-
autoSyncIntervals: []
|
|
2303
|
+
autoSyncIntervals: [],
|
|
2304
|
+
canUseData: false,
|
|
2305
|
+
maxDataBytes: null,
|
|
2306
|
+
maxDataTablesPerDatabase: null,
|
|
2307
|
+
triggerRunHardCap: 0
|
|
2236
2308
|
},
|
|
2237
2309
|
PRO: {
|
|
2238
2310
|
maxProjects: null,
|
|
@@ -2259,7 +2331,11 @@ const PLAN_LIMITS: Record<
|
|
|
2259
2331
|
autoSyncIntervals: [
|
|
2260
2332
|
RESOURCE_SYNC_INTERVAL_DAILY,
|
|
2261
2333
|
RESOURCE_SYNC_INTERVAL_WEEKLY
|
|
2262
|
-
]
|
|
2334
|
+
],
|
|
2335
|
+
canUseData: true,
|
|
2336
|
+
maxDataBytes: DATA_MAX_DATABASE_BYTES,
|
|
2337
|
+
maxDataTablesPerDatabase: DATA_MAX_TABLES_PER_DATABASE,
|
|
2338
|
+
triggerRunHardCap: DATA_TRIGGER_RUN_HARD_CAP
|
|
2263
2339
|
},
|
|
2264
2340
|
ENTERPRISE: {
|
|
2265
2341
|
maxProjects: null,
|
|
@@ -2286,7 +2362,11 @@ const PLAN_LIMITS: Record<
|
|
|
2286
2362
|
autoSyncIntervals: [
|
|
2287
2363
|
RESOURCE_SYNC_INTERVAL_DAILY,
|
|
2288
2364
|
RESOURCE_SYNC_INTERVAL_WEEKLY
|
|
2289
|
-
]
|
|
2365
|
+
],
|
|
2366
|
+
canUseData: true,
|
|
2367
|
+
maxDataBytes: DATA_MAX_DATABASE_BYTES,
|
|
2368
|
+
maxDataTablesPerDatabase: DATA_MAX_TABLES_PER_DATABASE,
|
|
2369
|
+
triggerRunHardCap: null
|
|
2290
2370
|
}
|
|
2291
2371
|
};
|
|
2292
2372
|
|
|
@@ -2306,6 +2386,7 @@ const PLAN_FEATURE_EMBEDDED_STORAGE = 'embeddedStorage' as 'embeddedStorage';
|
|
|
2306
2386
|
const PLAN_FEATURE_MESSAGE = 'message' as 'message';
|
|
2307
2387
|
const PLAN_FEATURE_TOOL_CALL = 'toolCall' as 'toolCall';
|
|
2308
2388
|
const PLAN_FEATURE_RESOURCE_SYNC = 'resourceSync' as 'resourceSync';
|
|
2389
|
+
const PLAN_FEATURE_DATA = 'data' as 'data';
|
|
2309
2390
|
|
|
2310
2391
|
// Stable code returned on a quota block so clients can branch on it (402).
|
|
2311
2392
|
const PLAN_LIMIT_ERROR_CODE = 'PLAN_LIMIT_EXCEEDED';
|
|
@@ -2475,6 +2556,20 @@ export const constants = {
|
|
|
2475
2556
|
PRICING_TOOL_CALL_PER_M_USD,
|
|
2476
2557
|
PRICING_TOOL_CALL_HARD_CAP,
|
|
2477
2558
|
PRICING_CUSTOM_DOMAIN_USD,
|
|
2559
|
+
DATA_MAX_DATABASE_BYTES,
|
|
2560
|
+
DATA_MAX_TABLES_PER_DATABASE,
|
|
2561
|
+
DATA_TRIGGER_RUN_HARD_CAP,
|
|
2562
|
+
DATA_DELETE_GRACE_DAYS,
|
|
2563
|
+
DATA_PURGE_BATCH,
|
|
2564
|
+
DATA_ACTIVITY_THROTTLE_MS,
|
|
2565
|
+
ARTIFACT_DATABASE_STATUS_CREATING,
|
|
2566
|
+
ARTIFACT_DATABASE_STATUS_READY,
|
|
2567
|
+
ARTIFACT_DATABASE_STATUS_FAILED,
|
|
2568
|
+
ARTIFACT_DATABASE_STATUS_DELETING,
|
|
2569
|
+
ARTIFACT_DATABASE_STATUS_PURGING,
|
|
2570
|
+
ARTIFACT_DATABASE_STATUS_DELETED,
|
|
2571
|
+
DATA_PURGE_STALE_MS,
|
|
2572
|
+
ARTIFACT_DATABASE_STATUSES,
|
|
2478
2573
|
PLAN_FEATURE_ORGANIZATION,
|
|
2479
2574
|
PLAN_FEATURE_PROJECT,
|
|
2480
2575
|
PLAN_FEATURE_TOOL,
|
|
@@ -2489,6 +2584,7 @@ export const constants = {
|
|
|
2489
2584
|
PLAN_FEATURE_MESSAGE,
|
|
2490
2585
|
PLAN_FEATURE_TOOL_CALL,
|
|
2491
2586
|
PLAN_FEATURE_RESOURCE_SYNC,
|
|
2587
|
+
PLAN_FEATURE_DATA,
|
|
2492
2588
|
PLAN_LIMIT_ERROR_CODE,
|
|
2493
2589
|
BILLING_METER_MESSAGES,
|
|
2494
2590
|
BILLING_METER_SHARED_MESSAGES,
|
|
@@ -2577,6 +2673,7 @@ export const constants = {
|
|
|
2577
2673
|
SLACK_OAUTH_TOKEN_URL,
|
|
2578
2674
|
OAUTH_TOKEN_URLS,
|
|
2579
2675
|
CREDENTIAL_REFRESH_BUFFER_MS,
|
|
2676
|
+
CREDENTIAL_REFRESH_GIVE_UP_MS,
|
|
2580
2677
|
GOOGLE_CALENDAR_API_BASE,
|
|
2581
2678
|
GOOGLE_DRIVE_API_BASE,
|
|
2582
2679
|
GOOGLE_DRIVE_DEFAULT_PAGE_SIZE,
|
|
@@ -2612,6 +2709,7 @@ export const constants = {
|
|
|
2612
2709
|
ONE_DRIVE_TAB_LABEL_DRIVES,
|
|
2613
2710
|
ONE_DRIVE_TAB_LABELS,
|
|
2614
2711
|
REAUTH_ERROR_CODES,
|
|
2712
|
+
OAUTH_CLIENT_ERROR_CODES,
|
|
2615
2713
|
RESOURCE_TYPE_TOOLTIP_MIN_WIDTH,
|
|
2616
2714
|
SEARCH_DEBOUNCE_MS,
|
|
2617
2715
|
GOOGLE_DRIVE_EXPORT_MIME_TYPES,
|
|
@@ -2840,6 +2938,7 @@ export const constants = {
|
|
|
2840
2938
|
RESOURCE_SEARCH_RRF_K,
|
|
2841
2939
|
RESOURCE_SEARCH_COMMON_TERM_DIVISOR,
|
|
2842
2940
|
RESOURCE_SEARCH_COMMON_TERM_MIN,
|
|
2941
|
+
RESOURCE_SEARCH_RERANK_ENABLED,
|
|
2843
2942
|
RESOURCE_SEARCH_RERANK_CANDIDATES,
|
|
2844
2943
|
RESOURCE_SEARCH_RERANK_MODEL,
|
|
2845
2944
|
RESOURCE_SEARCH_EXACT_MAX_RESOURCES,
|
|
@@ -3025,6 +3124,7 @@ export const constants = {
|
|
|
3025
3124
|
CUSTOM_CODE_RESOURCE_FILE_TOO_LARGE_MESSAGE,
|
|
3026
3125
|
RESERVED_SLUGS,
|
|
3027
3126
|
MCP_INTERNAL_HEADER,
|
|
3127
|
+
MCP_EVAL_RERANK_HEADER,
|
|
3028
3128
|
MCP_CHANNEL_ID_HEADER,
|
|
3029
3129
|
MCP_CHANNEL_PLATFORM_HEADER,
|
|
3030
3130
|
MCP_CHANNEL_CONVERSATION_HEADER,
|
package/src/data.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Entry point for `@ganju/utils/data`: everything a project's database and
|
|
2
|
+
// its callers share, without pulling in the rest of the package.
|
|
3
|
+
export * from './dataTypes';
|
|
4
|
+
export {
|
|
5
|
+
DATA_IDENTIFIER_PATTERN,
|
|
6
|
+
DATA_SYSTEM_COLUMNS,
|
|
7
|
+
DATA_HIDDEN_COLUMNS,
|
|
8
|
+
identifierIssue,
|
|
9
|
+
isValidIdentifier
|
|
10
|
+
} from './dataIdentifiers';
|
|
11
|
+
export {
|
|
12
|
+
createTableSql,
|
|
13
|
+
columnDefinitionSql,
|
|
14
|
+
desiredIndexes,
|
|
15
|
+
desiredTriggers,
|
|
16
|
+
ftsCreateSql,
|
|
17
|
+
ftsTableName,
|
|
18
|
+
searchableColumns,
|
|
19
|
+
sqlLiteral
|
|
20
|
+
} from './dataDdl';
|
|
21
|
+
export {
|
|
22
|
+
chunkRows,
|
|
23
|
+
rowsPerInsert,
|
|
24
|
+
ftsMatch,
|
|
25
|
+
keysetCondition,
|
|
26
|
+
encodeCursor,
|
|
27
|
+
decodeCursor,
|
|
28
|
+
isSensitiveWrite,
|
|
29
|
+
tidyArgs,
|
|
30
|
+
zoned
|
|
31
|
+
} from './dataCompiler';
|
|
32
|
+
export type { SqlValue, KeysetCursor, SortKey } from './dataCompiler';
|
|
33
|
+
export {
|
|
34
|
+
INTERNAL_MIGRATIONS,
|
|
35
|
+
INTERNAL_SCHEMA_VERSION,
|
|
36
|
+
hasInternalTables,
|
|
37
|
+
getMeta,
|
|
38
|
+
setMeta,
|
|
39
|
+
migrateInternal,
|
|
40
|
+
loadSchema,
|
|
41
|
+
toTableInput,
|
|
42
|
+
normaliseColumn,
|
|
43
|
+
translateSqliteError,
|
|
44
|
+
describe,
|
|
45
|
+
query,
|
|
46
|
+
write,
|
|
47
|
+
rowHistory,
|
|
48
|
+
pruneHistory,
|
|
49
|
+
deleteImpact,
|
|
50
|
+
createTable,
|
|
51
|
+
updateTable,
|
|
52
|
+
dropTable,
|
|
53
|
+
addColumn,
|
|
54
|
+
updateColumn,
|
|
55
|
+
dropColumn,
|
|
56
|
+
columnChangeNeedsRebuild,
|
|
57
|
+
dropColumnNeedsRebuild,
|
|
58
|
+
readTableCopy,
|
|
59
|
+
clearFailedTableCopy,
|
|
60
|
+
copyTableStep,
|
|
61
|
+
writeReachesCopy,
|
|
62
|
+
assertActor,
|
|
63
|
+
assertWritable,
|
|
64
|
+
exportRows
|
|
65
|
+
} from './dataEngine';
|
|
66
|
+
export type { SqlRow, SqlRunner } from './dataEngine';
|
|
67
|
+
export type {
|
|
68
|
+
ProjectDatabaseRpc,
|
|
69
|
+
DatabaseInfo,
|
|
70
|
+
ExportFile,
|
|
71
|
+
ExportFormat,
|
|
72
|
+
ExportState,
|
|
73
|
+
RestoreResult
|
|
74
|
+
} from './dataRpc';
|