@usewhisper/sdk 3.2.0 → 3.3.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/index.d.mts +12 -0
- package/index.d.ts +12 -0
- package/index.js +151 -33
- package/index.mjs +151 -33
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1197,9 +1197,13 @@ declare class WhisperContext {
|
|
|
1197
1197
|
withProject(project: string): WhisperContext;
|
|
1198
1198
|
private getRequiredProject;
|
|
1199
1199
|
private refreshProjectCache;
|
|
1200
|
+
private fetchResolvedProject;
|
|
1201
|
+
resolveProject(projectRef?: string): Promise<Project>;
|
|
1200
1202
|
private resolveProjectId;
|
|
1201
1203
|
private getProjectRefCandidates;
|
|
1202
1204
|
private withProjectRefFallback;
|
|
1205
|
+
private shouldRetryWithResolvedProjectId;
|
|
1206
|
+
private withProjectPathFallback;
|
|
1203
1207
|
private classifyError;
|
|
1204
1208
|
private isEndpointNotFoundError;
|
|
1205
1209
|
private inferOperation;
|
|
@@ -1216,6 +1220,14 @@ declare class WhisperContext {
|
|
|
1216
1220
|
getProject(id: string): Promise<Project & {
|
|
1217
1221
|
sources: Source[];
|
|
1218
1222
|
}>;
|
|
1223
|
+
listSources(project?: string): Promise<{
|
|
1224
|
+
project: {
|
|
1225
|
+
id: string;
|
|
1226
|
+
name: string;
|
|
1227
|
+
slug: string;
|
|
1228
|
+
};
|
|
1229
|
+
sources: Source[];
|
|
1230
|
+
}>;
|
|
1219
1231
|
deleteProject(id: string): Promise<{
|
|
1220
1232
|
deleted: boolean;
|
|
1221
1233
|
}>;
|
package/index.d.ts
CHANGED
|
@@ -1197,9 +1197,13 @@ declare class WhisperContext {
|
|
|
1197
1197
|
withProject(project: string): WhisperContext;
|
|
1198
1198
|
private getRequiredProject;
|
|
1199
1199
|
private refreshProjectCache;
|
|
1200
|
+
private fetchResolvedProject;
|
|
1201
|
+
resolveProject(projectRef?: string): Promise<Project>;
|
|
1200
1202
|
private resolveProjectId;
|
|
1201
1203
|
private getProjectRefCandidates;
|
|
1202
1204
|
private withProjectRefFallback;
|
|
1205
|
+
private shouldRetryWithResolvedProjectId;
|
|
1206
|
+
private withProjectPathFallback;
|
|
1203
1207
|
private classifyError;
|
|
1204
1208
|
private isEndpointNotFoundError;
|
|
1205
1209
|
private inferOperation;
|
|
@@ -1216,6 +1220,14 @@ declare class WhisperContext {
|
|
|
1216
1220
|
getProject(id: string): Promise<Project & {
|
|
1217
1221
|
sources: Source[];
|
|
1218
1222
|
}>;
|
|
1223
|
+
listSources(project?: string): Promise<{
|
|
1224
|
+
project: {
|
|
1225
|
+
id: string;
|
|
1226
|
+
name: string;
|
|
1227
|
+
slug: string;
|
|
1228
|
+
};
|
|
1229
|
+
sources: Source[];
|
|
1230
|
+
}>;
|
|
1219
1231
|
deleteProject(id: string): Promise<{
|
|
1220
1232
|
deleted: boolean;
|
|
1221
1233
|
}>;
|
package/index.js
CHANGED
|
@@ -2423,9 +2423,71 @@ var WhisperContext = class _WhisperContext {
|
|
|
2423
2423
|
this.projectRefToId.set(p.slug, p.id);
|
|
2424
2424
|
this.projectRefToId.set(p.name, p.id);
|
|
2425
2425
|
}
|
|
2426
|
+
if (this.defaultProject) {
|
|
2427
|
+
const hasDefaultProject = this.projectCache.some(
|
|
2428
|
+
(project) => project.id === this.defaultProject || project.slug === this.defaultProject || project.name === this.defaultProject
|
|
2429
|
+
);
|
|
2430
|
+
if (!hasDefaultProject) {
|
|
2431
|
+
const resolvedDefault = await this.fetchResolvedProject(this.defaultProject);
|
|
2432
|
+
if (resolvedDefault) {
|
|
2433
|
+
this.projectCache = [...this.projectCache, resolvedDefault];
|
|
2434
|
+
this.projectRefToId.set(resolvedDefault.id, resolvedDefault.id);
|
|
2435
|
+
this.projectRefToId.set(resolvedDefault.slug, resolvedDefault.id);
|
|
2436
|
+
this.projectRefToId.set(resolvedDefault.name, resolvedDefault.id);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2426
2440
|
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2427
2441
|
return this.projectCache;
|
|
2428
2442
|
}
|
|
2443
|
+
async fetchResolvedProject(projectRef) {
|
|
2444
|
+
if (!projectRef) return null;
|
|
2445
|
+
try {
|
|
2446
|
+
const response = await this.request(`/v1/projects/resolve?project=${encodeURIComponent(projectRef)}`, { method: "GET" });
|
|
2447
|
+
return response?.resolved || null;
|
|
2448
|
+
} catch (error) {
|
|
2449
|
+
if (error instanceof WhisperError && error.code === "PROJECT_NOT_FOUND") {
|
|
2450
|
+
return null;
|
|
2451
|
+
}
|
|
2452
|
+
throw error;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
async resolveProject(projectRef) {
|
|
2456
|
+
const resolvedRef = this.getRequiredProject(projectRef);
|
|
2457
|
+
const cachedProjects = await this.refreshProjectCache(false);
|
|
2458
|
+
const cachedProject = cachedProjects.find(
|
|
2459
|
+
(project) => project.id === resolvedRef || project.slug === resolvedRef || project.name === resolvedRef
|
|
2460
|
+
);
|
|
2461
|
+
if (cachedProject) {
|
|
2462
|
+
return cachedProject;
|
|
2463
|
+
}
|
|
2464
|
+
const resolvedProject = await this.fetchResolvedProject(resolvedRef);
|
|
2465
|
+
if (resolvedProject) {
|
|
2466
|
+
this.projectRefToId.set(resolvedProject.id, resolvedProject.id);
|
|
2467
|
+
this.projectRefToId.set(resolvedProject.slug, resolvedProject.id);
|
|
2468
|
+
this.projectRefToId.set(resolvedProject.name, resolvedProject.id);
|
|
2469
|
+
this.projectCache = [
|
|
2470
|
+
...this.projectCache.filter((project) => project.id !== resolvedProject.id),
|
|
2471
|
+
resolvedProject
|
|
2472
|
+
];
|
|
2473
|
+
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2474
|
+
return resolvedProject;
|
|
2475
|
+
}
|
|
2476
|
+
if (isLikelyProjectId(resolvedRef)) {
|
|
2477
|
+
return {
|
|
2478
|
+
id: resolvedRef,
|
|
2479
|
+
orgId: "",
|
|
2480
|
+
name: resolvedRef,
|
|
2481
|
+
slug: resolvedRef,
|
|
2482
|
+
createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
2483
|
+
updatedAt: (/* @__PURE__ */ new Date(0)).toISOString()
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
throw new WhisperError({
|
|
2487
|
+
code: "PROJECT_NOT_FOUND",
|
|
2488
|
+
message: `Project '${resolvedRef}' not found`
|
|
2489
|
+
});
|
|
2490
|
+
}
|
|
2429
2491
|
async resolveProjectId(projectRef) {
|
|
2430
2492
|
if (this.projectRefToId.has(projectRef)) {
|
|
2431
2493
|
return this.projectRefToId.get(projectRef);
|
|
@@ -2446,6 +2508,18 @@ var WhisperContext = class _WhisperContext {
|
|
|
2446
2508
|
if (isLikelyProjectId(projectRef)) {
|
|
2447
2509
|
return projectRef;
|
|
2448
2510
|
}
|
|
2511
|
+
const resolvedProject = await this.fetchResolvedProject(projectRef);
|
|
2512
|
+
if (resolvedProject) {
|
|
2513
|
+
this.projectRefToId.set(resolvedProject.id, resolvedProject.id);
|
|
2514
|
+
this.projectRefToId.set(resolvedProject.slug, resolvedProject.id);
|
|
2515
|
+
this.projectRefToId.set(resolvedProject.name, resolvedProject.id);
|
|
2516
|
+
this.projectCache = [
|
|
2517
|
+
...this.projectCache.filter((project) => project.id !== resolvedProject.id),
|
|
2518
|
+
resolvedProject
|
|
2519
|
+
];
|
|
2520
|
+
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2521
|
+
return resolvedProject.id;
|
|
2522
|
+
}
|
|
2449
2523
|
throw new WhisperError({
|
|
2450
2524
|
code: "PROJECT_NOT_FOUND",
|
|
2451
2525
|
message: `Project '${projectRef}' not found`
|
|
@@ -2501,6 +2575,26 @@ var WhisperContext = class _WhisperContext {
|
|
|
2501
2575
|
message: `Project '${projectRef}' not found`
|
|
2502
2576
|
});
|
|
2503
2577
|
}
|
|
2578
|
+
shouldRetryWithResolvedProjectId(error) {
|
|
2579
|
+
return error instanceof WhisperError && error.status === 404 && !this.isEndpointNotFoundError(error);
|
|
2580
|
+
}
|
|
2581
|
+
async withProjectPathFallback(projectRef, execute) {
|
|
2582
|
+
try {
|
|
2583
|
+
return await execute(projectRef);
|
|
2584
|
+
} catch (error) {
|
|
2585
|
+
if (!this.shouldRetryWithResolvedProjectId(error)) {
|
|
2586
|
+
throw error;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
const resolvedProjectId = await this.resolveProjectId(projectRef);
|
|
2590
|
+
if (resolvedProjectId === projectRef) {
|
|
2591
|
+
throw new WhisperError({
|
|
2592
|
+
code: "PROJECT_NOT_FOUND",
|
|
2593
|
+
message: `Project '${projectRef}' not found`
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
return execute(resolvedProjectId);
|
|
2597
|
+
}
|
|
2504
2598
|
classifyError(status, message) {
|
|
2505
2599
|
if (status === 401 || /api key|unauthorized|forbidden/i.test(message)) {
|
|
2506
2600
|
return { code: "INVALID_API_KEY", retryable: false };
|
|
@@ -2616,29 +2710,42 @@ var WhisperContext = class _WhisperContext {
|
|
|
2616
2710
|
return projects;
|
|
2617
2711
|
}
|
|
2618
2712
|
async getProject(id) {
|
|
2619
|
-
|
|
2620
|
-
|
|
2713
|
+
return this.withProjectPathFallback(
|
|
2714
|
+
this.getRequiredProject(id),
|
|
2715
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}`)
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
async listSources(project) {
|
|
2719
|
+
const projectRef = this.getRequiredProject(project);
|
|
2720
|
+
return this.withProjectRefFallback(
|
|
2721
|
+
projectRef,
|
|
2722
|
+
(resolvedProject) => this.request(`/v1/sources?project=${encodeURIComponent(resolvedProject)}`, { method: "GET" })
|
|
2723
|
+
);
|
|
2621
2724
|
}
|
|
2622
2725
|
async deleteProject(id) {
|
|
2623
2726
|
const projectId = await this.resolveProjectId(id);
|
|
2624
2727
|
return this.request(`/v1/projects/${projectId}`, { method: "DELETE" });
|
|
2625
2728
|
}
|
|
2626
2729
|
async addSource(projectId, params) {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2730
|
+
return this.withProjectPathFallback(
|
|
2731
|
+
this.getRequiredProject(projectId),
|
|
2732
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/sources`, {
|
|
2733
|
+
method: "POST",
|
|
2734
|
+
body: JSON.stringify(params)
|
|
2735
|
+
})
|
|
2736
|
+
);
|
|
2632
2737
|
}
|
|
2633
2738
|
async syncSource(sourceId) {
|
|
2634
2739
|
return this.request(`/v1/sources/${sourceId}/sync`, { method: "POST" });
|
|
2635
2740
|
}
|
|
2636
2741
|
async addSourceByType(projectId, params) {
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2742
|
+
return this.withProjectPathFallback(
|
|
2743
|
+
this.getRequiredProject(projectId),
|
|
2744
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/add_source`, {
|
|
2745
|
+
method: "POST",
|
|
2746
|
+
body: JSON.stringify(params)
|
|
2747
|
+
})
|
|
2748
|
+
);
|
|
2642
2749
|
}
|
|
2643
2750
|
async getSourceStatus(sourceId) {
|
|
2644
2751
|
return this.request(`/v1/sources/${sourceId}/status`, { method: "GET" });
|
|
@@ -2700,14 +2807,16 @@ var WhisperContext = class _WhisperContext {
|
|
|
2700
2807
|
};
|
|
2701
2808
|
}
|
|
2702
2809
|
async ingest(projectId, documents) {
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2810
|
+
return this.withProjectPathFallback(
|
|
2811
|
+
this.getRequiredProject(projectId),
|
|
2812
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/ingest`, {
|
|
2813
|
+
method: "POST",
|
|
2814
|
+
body: JSON.stringify({ documents })
|
|
2815
|
+
})
|
|
2816
|
+
);
|
|
2708
2817
|
}
|
|
2709
2818
|
async addContext(params) {
|
|
2710
|
-
const projectId = await this.
|
|
2819
|
+
const projectId = (await this.resolveProject(this.getRequiredProject(params.project))).id;
|
|
2711
2820
|
return this.ingest(projectId, [
|
|
2712
2821
|
{
|
|
2713
2822
|
title: params.title || "Context",
|
|
@@ -3117,28 +3226,37 @@ var WhisperContext = class _WhisperContext {
|
|
|
3117
3226
|
});
|
|
3118
3227
|
}
|
|
3119
3228
|
async createSharedContext(params) {
|
|
3120
|
-
const
|
|
3121
|
-
return this.
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3229
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3230
|
+
return this.withProjectRefFallback(
|
|
3231
|
+
projectRef,
|
|
3232
|
+
(project) => this.request("/v1/context/share", {
|
|
3233
|
+
method: "POST",
|
|
3234
|
+
body: JSON.stringify({ ...params, project })
|
|
3235
|
+
})
|
|
3236
|
+
);
|
|
3125
3237
|
}
|
|
3126
3238
|
async loadSharedContext(shareId) {
|
|
3127
3239
|
return this.request(`/v1/context/shared/${shareId}`);
|
|
3128
3240
|
}
|
|
3129
3241
|
async resumeFromSharedContext(params) {
|
|
3130
|
-
const
|
|
3131
|
-
return this.
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3242
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3243
|
+
return this.withProjectRefFallback(
|
|
3244
|
+
projectRef,
|
|
3245
|
+
(project) => this.request("/v1/context/resume", {
|
|
3246
|
+
method: "POST",
|
|
3247
|
+
body: JSON.stringify({ ...params, project })
|
|
3248
|
+
})
|
|
3249
|
+
);
|
|
3135
3250
|
}
|
|
3136
3251
|
async consolidateMemories(params) {
|
|
3137
|
-
const
|
|
3138
|
-
return this.
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3252
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3253
|
+
return this.withProjectRefFallback(
|
|
3254
|
+
projectRef,
|
|
3255
|
+
(project) => this.request("/v1/memory/consolidate", {
|
|
3256
|
+
method: "POST",
|
|
3257
|
+
body: JSON.stringify({ ...params, project })
|
|
3258
|
+
})
|
|
3259
|
+
);
|
|
3142
3260
|
}
|
|
3143
3261
|
async updateImportanceDecay(params) {
|
|
3144
3262
|
const project = await this.resolveProjectId(this.getRequiredProject(params.project));
|
package/index.mjs
CHANGED
|
@@ -2374,9 +2374,71 @@ var WhisperContext = class _WhisperContext {
|
|
|
2374
2374
|
this.projectRefToId.set(p.slug, p.id);
|
|
2375
2375
|
this.projectRefToId.set(p.name, p.id);
|
|
2376
2376
|
}
|
|
2377
|
+
if (this.defaultProject) {
|
|
2378
|
+
const hasDefaultProject = this.projectCache.some(
|
|
2379
|
+
(project) => project.id === this.defaultProject || project.slug === this.defaultProject || project.name === this.defaultProject
|
|
2380
|
+
);
|
|
2381
|
+
if (!hasDefaultProject) {
|
|
2382
|
+
const resolvedDefault = await this.fetchResolvedProject(this.defaultProject);
|
|
2383
|
+
if (resolvedDefault) {
|
|
2384
|
+
this.projectCache = [...this.projectCache, resolvedDefault];
|
|
2385
|
+
this.projectRefToId.set(resolvedDefault.id, resolvedDefault.id);
|
|
2386
|
+
this.projectRefToId.set(resolvedDefault.slug, resolvedDefault.id);
|
|
2387
|
+
this.projectRefToId.set(resolvedDefault.name, resolvedDefault.id);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2377
2391
|
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2378
2392
|
return this.projectCache;
|
|
2379
2393
|
}
|
|
2394
|
+
async fetchResolvedProject(projectRef) {
|
|
2395
|
+
if (!projectRef) return null;
|
|
2396
|
+
try {
|
|
2397
|
+
const response = await this.request(`/v1/projects/resolve?project=${encodeURIComponent(projectRef)}`, { method: "GET" });
|
|
2398
|
+
return response?.resolved || null;
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
if (error instanceof WhisperError && error.code === "PROJECT_NOT_FOUND") {
|
|
2401
|
+
return null;
|
|
2402
|
+
}
|
|
2403
|
+
throw error;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
async resolveProject(projectRef) {
|
|
2407
|
+
const resolvedRef = this.getRequiredProject(projectRef);
|
|
2408
|
+
const cachedProjects = await this.refreshProjectCache(false);
|
|
2409
|
+
const cachedProject = cachedProjects.find(
|
|
2410
|
+
(project) => project.id === resolvedRef || project.slug === resolvedRef || project.name === resolvedRef
|
|
2411
|
+
);
|
|
2412
|
+
if (cachedProject) {
|
|
2413
|
+
return cachedProject;
|
|
2414
|
+
}
|
|
2415
|
+
const resolvedProject = await this.fetchResolvedProject(resolvedRef);
|
|
2416
|
+
if (resolvedProject) {
|
|
2417
|
+
this.projectRefToId.set(resolvedProject.id, resolvedProject.id);
|
|
2418
|
+
this.projectRefToId.set(resolvedProject.slug, resolvedProject.id);
|
|
2419
|
+
this.projectRefToId.set(resolvedProject.name, resolvedProject.id);
|
|
2420
|
+
this.projectCache = [
|
|
2421
|
+
...this.projectCache.filter((project) => project.id !== resolvedProject.id),
|
|
2422
|
+
resolvedProject
|
|
2423
|
+
];
|
|
2424
|
+
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2425
|
+
return resolvedProject;
|
|
2426
|
+
}
|
|
2427
|
+
if (isLikelyProjectId(resolvedRef)) {
|
|
2428
|
+
return {
|
|
2429
|
+
id: resolvedRef,
|
|
2430
|
+
orgId: "",
|
|
2431
|
+
name: resolvedRef,
|
|
2432
|
+
slug: resolvedRef,
|
|
2433
|
+
createdAt: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
2434
|
+
updatedAt: (/* @__PURE__ */ new Date(0)).toISOString()
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
throw new WhisperError({
|
|
2438
|
+
code: "PROJECT_NOT_FOUND",
|
|
2439
|
+
message: `Project '${resolvedRef}' not found`
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2380
2442
|
async resolveProjectId(projectRef) {
|
|
2381
2443
|
if (this.projectRefToId.has(projectRef)) {
|
|
2382
2444
|
return this.projectRefToId.get(projectRef);
|
|
@@ -2397,6 +2459,18 @@ var WhisperContext = class _WhisperContext {
|
|
|
2397
2459
|
if (isLikelyProjectId(projectRef)) {
|
|
2398
2460
|
return projectRef;
|
|
2399
2461
|
}
|
|
2462
|
+
const resolvedProject = await this.fetchResolvedProject(projectRef);
|
|
2463
|
+
if (resolvedProject) {
|
|
2464
|
+
this.projectRefToId.set(resolvedProject.id, resolvedProject.id);
|
|
2465
|
+
this.projectRefToId.set(resolvedProject.slug, resolvedProject.id);
|
|
2466
|
+
this.projectRefToId.set(resolvedProject.name, resolvedProject.id);
|
|
2467
|
+
this.projectCache = [
|
|
2468
|
+
...this.projectCache.filter((project) => project.id !== resolvedProject.id),
|
|
2469
|
+
resolvedProject
|
|
2470
|
+
];
|
|
2471
|
+
this.projectCacheExpiresAt = Date.now() + PROJECT_CACHE_TTL_MS;
|
|
2472
|
+
return resolvedProject.id;
|
|
2473
|
+
}
|
|
2400
2474
|
throw new WhisperError({
|
|
2401
2475
|
code: "PROJECT_NOT_FOUND",
|
|
2402
2476
|
message: `Project '${projectRef}' not found`
|
|
@@ -2452,6 +2526,26 @@ var WhisperContext = class _WhisperContext {
|
|
|
2452
2526
|
message: `Project '${projectRef}' not found`
|
|
2453
2527
|
});
|
|
2454
2528
|
}
|
|
2529
|
+
shouldRetryWithResolvedProjectId(error) {
|
|
2530
|
+
return error instanceof WhisperError && error.status === 404 && !this.isEndpointNotFoundError(error);
|
|
2531
|
+
}
|
|
2532
|
+
async withProjectPathFallback(projectRef, execute) {
|
|
2533
|
+
try {
|
|
2534
|
+
return await execute(projectRef);
|
|
2535
|
+
} catch (error) {
|
|
2536
|
+
if (!this.shouldRetryWithResolvedProjectId(error)) {
|
|
2537
|
+
throw error;
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
const resolvedProjectId = await this.resolveProjectId(projectRef);
|
|
2541
|
+
if (resolvedProjectId === projectRef) {
|
|
2542
|
+
throw new WhisperError({
|
|
2543
|
+
code: "PROJECT_NOT_FOUND",
|
|
2544
|
+
message: `Project '${projectRef}' not found`
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
return execute(resolvedProjectId);
|
|
2548
|
+
}
|
|
2455
2549
|
classifyError(status, message) {
|
|
2456
2550
|
if (status === 401 || /api key|unauthorized|forbidden/i.test(message)) {
|
|
2457
2551
|
return { code: "INVALID_API_KEY", retryable: false };
|
|
@@ -2567,29 +2661,42 @@ var WhisperContext = class _WhisperContext {
|
|
|
2567
2661
|
return projects;
|
|
2568
2662
|
}
|
|
2569
2663
|
async getProject(id) {
|
|
2570
|
-
|
|
2571
|
-
|
|
2664
|
+
return this.withProjectPathFallback(
|
|
2665
|
+
this.getRequiredProject(id),
|
|
2666
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}`)
|
|
2667
|
+
);
|
|
2668
|
+
}
|
|
2669
|
+
async listSources(project) {
|
|
2670
|
+
const projectRef = this.getRequiredProject(project);
|
|
2671
|
+
return this.withProjectRefFallback(
|
|
2672
|
+
projectRef,
|
|
2673
|
+
(resolvedProject) => this.request(`/v1/sources?project=${encodeURIComponent(resolvedProject)}`, { method: "GET" })
|
|
2674
|
+
);
|
|
2572
2675
|
}
|
|
2573
2676
|
async deleteProject(id) {
|
|
2574
2677
|
const projectId = await this.resolveProjectId(id);
|
|
2575
2678
|
return this.request(`/v1/projects/${projectId}`, { method: "DELETE" });
|
|
2576
2679
|
}
|
|
2577
2680
|
async addSource(projectId, params) {
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2681
|
+
return this.withProjectPathFallback(
|
|
2682
|
+
this.getRequiredProject(projectId),
|
|
2683
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/sources`, {
|
|
2684
|
+
method: "POST",
|
|
2685
|
+
body: JSON.stringify(params)
|
|
2686
|
+
})
|
|
2687
|
+
);
|
|
2583
2688
|
}
|
|
2584
2689
|
async syncSource(sourceId) {
|
|
2585
2690
|
return this.request(`/v1/sources/${sourceId}/sync`, { method: "POST" });
|
|
2586
2691
|
}
|
|
2587
2692
|
async addSourceByType(projectId, params) {
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2693
|
+
return this.withProjectPathFallback(
|
|
2694
|
+
this.getRequiredProject(projectId),
|
|
2695
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/add_source`, {
|
|
2696
|
+
method: "POST",
|
|
2697
|
+
body: JSON.stringify(params)
|
|
2698
|
+
})
|
|
2699
|
+
);
|
|
2593
2700
|
}
|
|
2594
2701
|
async getSourceStatus(sourceId) {
|
|
2595
2702
|
return this.request(`/v1/sources/${sourceId}/status`, { method: "GET" });
|
|
@@ -2651,14 +2758,16 @@ var WhisperContext = class _WhisperContext {
|
|
|
2651
2758
|
};
|
|
2652
2759
|
}
|
|
2653
2760
|
async ingest(projectId, documents) {
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2761
|
+
return this.withProjectPathFallback(
|
|
2762
|
+
this.getRequiredProject(projectId),
|
|
2763
|
+
(projectPathRef) => this.request(`/v1/projects/${encodeURIComponent(projectPathRef)}/ingest`, {
|
|
2764
|
+
method: "POST",
|
|
2765
|
+
body: JSON.stringify({ documents })
|
|
2766
|
+
})
|
|
2767
|
+
);
|
|
2659
2768
|
}
|
|
2660
2769
|
async addContext(params) {
|
|
2661
|
-
const projectId = await this.
|
|
2770
|
+
const projectId = (await this.resolveProject(this.getRequiredProject(params.project))).id;
|
|
2662
2771
|
return this.ingest(projectId, [
|
|
2663
2772
|
{
|
|
2664
2773
|
title: params.title || "Context",
|
|
@@ -3068,28 +3177,37 @@ var WhisperContext = class _WhisperContext {
|
|
|
3068
3177
|
});
|
|
3069
3178
|
}
|
|
3070
3179
|
async createSharedContext(params) {
|
|
3071
|
-
const
|
|
3072
|
-
return this.
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3180
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3181
|
+
return this.withProjectRefFallback(
|
|
3182
|
+
projectRef,
|
|
3183
|
+
(project) => this.request("/v1/context/share", {
|
|
3184
|
+
method: "POST",
|
|
3185
|
+
body: JSON.stringify({ ...params, project })
|
|
3186
|
+
})
|
|
3187
|
+
);
|
|
3076
3188
|
}
|
|
3077
3189
|
async loadSharedContext(shareId) {
|
|
3078
3190
|
return this.request(`/v1/context/shared/${shareId}`);
|
|
3079
3191
|
}
|
|
3080
3192
|
async resumeFromSharedContext(params) {
|
|
3081
|
-
const
|
|
3082
|
-
return this.
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3193
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3194
|
+
return this.withProjectRefFallback(
|
|
3195
|
+
projectRef,
|
|
3196
|
+
(project) => this.request("/v1/context/resume", {
|
|
3197
|
+
method: "POST",
|
|
3198
|
+
body: JSON.stringify({ ...params, project })
|
|
3199
|
+
})
|
|
3200
|
+
);
|
|
3086
3201
|
}
|
|
3087
3202
|
async consolidateMemories(params) {
|
|
3088
|
-
const
|
|
3089
|
-
return this.
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3203
|
+
const projectRef = this.getRequiredProject(params.project);
|
|
3204
|
+
return this.withProjectRefFallback(
|
|
3205
|
+
projectRef,
|
|
3206
|
+
(project) => this.request("/v1/memory/consolidate", {
|
|
3207
|
+
method: "POST",
|
|
3208
|
+
body: JSON.stringify({ ...params, project })
|
|
3209
|
+
})
|
|
3210
|
+
);
|
|
3093
3211
|
}
|
|
3094
3212
|
async updateImportanceDecay(params) {
|
|
3095
3213
|
const project = await this.resolveProjectId(this.getRequiredProject(params.project));
|