@honcho-ai/claude-honcho 0.3.3 → 0.4.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/.claude-plugin/plugin.json +1 -1
- package/README.md +111 -335
- package/dist/hooks/pre-tool-honcho.js +551 -605
- package/dist/hooks/pre-tool-honcho.js.map +11 -9
- package/dist/hooks/save-user-message.js +1741 -1057
- package/dist/hooks/save-user-message.js.map +24 -19
- package/dist/hooks/session-end.js +559 -617
- package/dist/hooks/session-end.js.map +11 -9
- package/dist/hooks/session-start.js +1938 -1304
- package/dist/hooks/session-start.js.map +31 -22
- package/dist/hooks/stop.js +1785 -1157
- package/dist/hooks/stop.js.map +25 -19
- package/dist/hooks/user-prompt.js +696 -16571
- package/dist/hooks/user-prompt.js.map +13 -90
- package/dist/mcp-server.js +1689 -1676
- package/dist/mcp-server.js.map +23 -20
- package/dist/skills/backfill-runner.js +1824 -911
- package/dist/skills/backfill-runner.js.map +27 -20
- package/dist/skills/{setup-runner.js → pane-runner.js} +1910 -1020
- package/dist/{hooks/pre-compact.js.map → skills/pane-runner.js.map} +28 -24
- package/dist/skills/status-runner.js +1568 -753
- package/dist/skills/status-runner.js.map +23 -19
- package/hooks/hooks.json +10 -42
- package/hooks/register.tsx +574 -0
- package/package.json +1 -1
- package/skills/insights/SKILL.md +3 -7
- package/dist/hooks/post-tool-use.js +0 -16905
- package/dist/hooks/post-tool-use.js.map +0 -97
- package/dist/hooks/pre-compact.js +0 -17087
- package/dist/skills/setup-runner.js.map +0 -95
- package/scripts/honcho-statusline.sh +0 -101
- package/skills/briefing/SKILL.md +0 -20
- package/skills/config/SKILL.md +0 -288
- package/skills/import/SKILL.md +0 -73
- package/skills/setup/SKILL.md +0 -60
- package/skills/status/SKILL.md +0 -30
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
// @bun
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -37,8 +36,9 @@ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports,
|
|
|
37
36
|
// node_modules/@honcho-ai/sdk/dist/api-version.js
|
|
38
37
|
var require_api_version = __commonJS(function(exports) {
|
|
39
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.API_VERSION = undefined;
|
|
39
|
+
exports.VERSION = exports.API_VERSION = undefined;
|
|
41
40
|
exports.API_VERSION = "v3";
|
|
41
|
+
exports.VERSION = "2.9.0";
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// node_modules/@honcho-ai/sdk/dist/http/errors.js
|
|
@@ -163,255 +163,6 @@ var require_errors = __commonJS(function(exports) {
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
167
|
-
var require_client = __commonJS(function(exports) {
|
|
168
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
169
|
-
exports.HonchoHTTPClient = undefined;
|
|
170
|
-
var errors_1 = require_errors();
|
|
171
|
-
var DEFAULT_TIMEOUT = 60000;
|
|
172
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
173
|
-
var RETRY_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
174
|
-
var INITIAL_RETRY_DELAY = 500;
|
|
175
|
-
|
|
176
|
-
class HonchoHTTPClient {
|
|
177
|
-
constructor(config) {
|
|
178
|
-
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
179
|
-
this.apiKey = config.apiKey;
|
|
180
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
181
|
-
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
182
|
-
this.defaultHeaders = {
|
|
183
|
-
"Content-Type": "application/json",
|
|
184
|
-
...config.defaultHeaders
|
|
185
|
-
};
|
|
186
|
-
this.defaultQuery = config.defaultQuery;
|
|
187
|
-
}
|
|
188
|
-
async request(method, path, options = {}) {
|
|
189
|
-
const url = this.buildURL(path, options.query);
|
|
190
|
-
const headers = this.buildHeaders(options.headers);
|
|
191
|
-
const timeout = options.timeout ?? this.timeout;
|
|
192
|
-
let lastError;
|
|
193
|
-
let attempt = 0;
|
|
194
|
-
while (attempt <= this.maxRetries) {
|
|
195
|
-
try {
|
|
196
|
-
const response = await this.fetchWithTimeout(url, {
|
|
197
|
-
method,
|
|
198
|
-
headers,
|
|
199
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
200
|
-
signal: options.signal
|
|
201
|
-
}, timeout);
|
|
202
|
-
if (response.ok) {
|
|
203
|
-
const text = await response.text();
|
|
204
|
-
if (!text) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
return JSON.parse(text);
|
|
208
|
-
}
|
|
209
|
-
const errorBody = await this.parseErrorBody(response);
|
|
210
|
-
const retryAfter = this.parseRetryAfter(response);
|
|
211
|
-
const error = (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody, retryAfter);
|
|
212
|
-
if (RETRY_STATUS_CODES.includes(response.status) && attempt < this.maxRetries) {
|
|
213
|
-
lastError = error;
|
|
214
|
-
await this.sleep(this.getRetryDelay(attempt, retryAfter));
|
|
215
|
-
attempt++;
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
throw error;
|
|
219
|
-
} catch (error) {
|
|
220
|
-
if (error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
221
|
-
if (attempt < this.maxRetries) {
|
|
222
|
-
lastError = error;
|
|
223
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
224
|
-
attempt++;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (error instanceof errors_1.RateLimitError || error instanceof errors_1.ServerError || error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
229
|
-
throw error;
|
|
230
|
-
}
|
|
231
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
232
|
-
const connError = new errors_1.ConnectionError(error.message);
|
|
233
|
-
if (attempt < this.maxRetries) {
|
|
234
|
-
lastError = connError;
|
|
235
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
236
|
-
attempt++;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
throw connError;
|
|
240
|
-
}
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
throw lastError || new Error("Request failed after retries");
|
|
245
|
-
}
|
|
246
|
-
async get(path, options) {
|
|
247
|
-
return this.request("GET", path, options);
|
|
248
|
-
}
|
|
249
|
-
async post(path, options) {
|
|
250
|
-
return this.request("POST", path, options);
|
|
251
|
-
}
|
|
252
|
-
async put(path, options) {
|
|
253
|
-
return this.request("PUT", path, options);
|
|
254
|
-
}
|
|
255
|
-
async patch(path, options) {
|
|
256
|
-
return this.request("PATCH", path, options);
|
|
257
|
-
}
|
|
258
|
-
async delete(path, options) {
|
|
259
|
-
return this.request("DELETE", path, options);
|
|
260
|
-
}
|
|
261
|
-
async stream(method, path, options = {}) {
|
|
262
|
-
const url = this.buildURL(path, options.query);
|
|
263
|
-
const headers = {
|
|
264
|
-
...this.buildHeaders(options.headers),
|
|
265
|
-
Accept: "text/event-stream"
|
|
266
|
-
};
|
|
267
|
-
const timeout = options.timeout ?? this.timeout;
|
|
268
|
-
const response = await this.fetchWithTimeout(url, {
|
|
269
|
-
method,
|
|
270
|
-
headers,
|
|
271
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
272
|
-
signal: options.signal
|
|
273
|
-
}, timeout);
|
|
274
|
-
if (!response.ok) {
|
|
275
|
-
const errorBody = await this.parseErrorBody(response);
|
|
276
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
277
|
-
}
|
|
278
|
-
return response;
|
|
279
|
-
}
|
|
280
|
-
async upload(path, formData, options = {}) {
|
|
281
|
-
const url = this.buildURL(path, options.query);
|
|
282
|
-
const headers = {};
|
|
283
|
-
if (this.apiKey) {
|
|
284
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
285
|
-
}
|
|
286
|
-
if (options.headers) {
|
|
287
|
-
Object.assign(headers, options.headers);
|
|
288
|
-
}
|
|
289
|
-
const timeout = options.timeout ?? this.timeout;
|
|
290
|
-
const response = await this.fetchWithTimeout(url, {
|
|
291
|
-
method: "POST",
|
|
292
|
-
headers,
|
|
293
|
-
body: formData,
|
|
294
|
-
signal: options.signal
|
|
295
|
-
}, timeout);
|
|
296
|
-
if (!response.ok) {
|
|
297
|
-
const errorBody = await this.parseErrorBody(response);
|
|
298
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
299
|
-
}
|
|
300
|
-
const text = await response.text();
|
|
301
|
-
if (!text) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
return JSON.parse(text);
|
|
305
|
-
}
|
|
306
|
-
buildURL(path, query) {
|
|
307
|
-
const url = new URL(path, this.baseURL);
|
|
308
|
-
const mergedQuery = {
|
|
309
|
-
...this.defaultQuery ?? {},
|
|
310
|
-
...query ?? {}
|
|
311
|
-
};
|
|
312
|
-
for (const [key, value] of Object.entries(mergedQuery)) {
|
|
313
|
-
if (value !== undefined) {
|
|
314
|
-
url.searchParams.set(key, String(value));
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return url.toString();
|
|
318
|
-
}
|
|
319
|
-
buildHeaders(extra) {
|
|
320
|
-
const headers = { ...this.defaultHeaders };
|
|
321
|
-
if (this.apiKey) {
|
|
322
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
323
|
-
}
|
|
324
|
-
if (extra) {
|
|
325
|
-
Object.assign(headers, extra);
|
|
326
|
-
}
|
|
327
|
-
return headers;
|
|
328
|
-
}
|
|
329
|
-
async fetchWithTimeout(url, init, timeout) {
|
|
330
|
-
const controller = new AbortController;
|
|
331
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
332
|
-
if (init.signal) {
|
|
333
|
-
init.signal.addEventListener("abort", () => controller.abort());
|
|
334
|
-
}
|
|
335
|
-
try {
|
|
336
|
-
const response = await fetch(url, {
|
|
337
|
-
...init,
|
|
338
|
-
signal: controller.signal
|
|
339
|
-
});
|
|
340
|
-
return response;
|
|
341
|
-
} catch (error) {
|
|
342
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
343
|
-
throw new errors_1.TimeoutError(`Request timed out after ${timeout}ms`);
|
|
344
|
-
}
|
|
345
|
-
throw error;
|
|
346
|
-
} finally {
|
|
347
|
-
clearTimeout(timeoutId);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
async parseErrorBody(response) {
|
|
351
|
-
try {
|
|
352
|
-
const body = await response.json();
|
|
353
|
-
return {
|
|
354
|
-
message: body.detail || body.message || body.error,
|
|
355
|
-
...body
|
|
356
|
-
};
|
|
357
|
-
} catch {
|
|
358
|
-
return { message: `HTTP ${response.status}` };
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
parseRetryAfter(response) {
|
|
362
|
-
const header = response.headers.get("Retry-After");
|
|
363
|
-
if (!header)
|
|
364
|
-
return;
|
|
365
|
-
const seconds = Number.parseInt(header, 10);
|
|
366
|
-
if (!Number.isNaN(seconds)) {
|
|
367
|
-
return seconds * 1000;
|
|
368
|
-
}
|
|
369
|
-
const date = Date.parse(header);
|
|
370
|
-
if (!Number.isNaN(date)) {
|
|
371
|
-
return Math.max(0, date - Date.now());
|
|
372
|
-
}
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
getRetryDelay(attempt, retryAfter) {
|
|
376
|
-
if (retryAfter) {
|
|
377
|
-
return retryAfter;
|
|
378
|
-
}
|
|
379
|
-
return INITIAL_RETRY_DELAY * 2 ** attempt;
|
|
380
|
-
}
|
|
381
|
-
sleep(ms) {
|
|
382
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
exports.HonchoHTTPClient = HonchoHTTPClient;
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// node_modules/@honcho-ai/sdk/dist/message.js
|
|
389
|
-
var require_message = __commonJS(function(exports) {
|
|
390
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
391
|
-
exports.Message = undefined;
|
|
392
|
-
|
|
393
|
-
class Message {
|
|
394
|
-
constructor(id, content, peerId, sessionId, workspaceId, metadata, createdAt, tokenCount) {
|
|
395
|
-
this.id = id;
|
|
396
|
-
this.content = content;
|
|
397
|
-
this.peerId = peerId;
|
|
398
|
-
this.sessionId = sessionId;
|
|
399
|
-
this.workspaceId = workspaceId;
|
|
400
|
-
this.metadata = metadata;
|
|
401
|
-
this.createdAt = createdAt;
|
|
402
|
-
this.tokenCount = tokenCount;
|
|
403
|
-
}
|
|
404
|
-
static fromApiResponse(data) {
|
|
405
|
-
return new Message(data.id, data.content, data.peer_id, data.session_id, data.workspace_id, data.metadata, data.created_at, data.token_count);
|
|
406
|
-
}
|
|
407
|
-
toString() {
|
|
408
|
-
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
409
|
-
return `Message(id='${this.id}', peerId='${this.peerId}', content='${truncatedContent}')`;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
exports.Message = Message;
|
|
413
|
-
});
|
|
414
|
-
|
|
415
166
|
// node_modules/@honcho-ai/sdk/dist/pagination.js
|
|
416
167
|
var require_pagination = __commonJS(function(exports) {
|
|
417
168
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -13691,9 +13442,10 @@ var require_zod = __commonJS(function(exports) {
|
|
|
13691
13442
|
// node_modules/@honcho-ai/sdk/dist/validation.js
|
|
13692
13443
|
var require_validation = __commonJS(function(exports) {
|
|
13693
13444
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13694
|
-
exports.ConclusionQueryParamsSchema = exports.LimitSchema = exports.WorkspaceConfigSchema = exports.WorkspaceMetadataSchema = exports.MessageAdditionToApiSchema = exports.MessageAdditionSchema = exports.PeerRemovalSchema = exports.PeerAdditionToApiSchema = exports.PeerAdditionSchema = exports.PeerCardContentSchema = exports.CardTargetSchema = exports.PeerGetRepresentationParamsSchema = exports.GetRepresentationParamsSchema = exports.FileUploadSchema = exports.QueueStatusOptionsSchema = exports.ContextParamsSchema = exports.RepresentationOptionsSchema = exports.ChatQuerySchema = exports.FilterSchema = exports.SearchQueryLikeSchema = exports.SearchQueryObjectSchema = exports.SearchQuerySchema = exports.MessageInputSchema = exports.MessageConfigurationSchema = exports.MessageMetadataSchema = exports.MessageContentSchema = exports.SessionPeerConfigSchema = exports.SessionIdSchema = exports.SessionConfigSchema = exports.DreamConfigSchema = exports.SummaryConfigSchema = exports.PeerCardConfigSchema = exports.ReasoningConfigSchema = exports.SessionMetadataSchema = exports.PeerIdSchema = exports.PeerConfigSchema = exports.PeerMetadataSchema = exports.HonchoConfigSchema = exports.WorkspaceIdSchema = undefined;
|
|
13445
|
+
exports.ConclusionQueryParamsSchema = exports.LimitSchema = exports.WorkspaceConfigSchema = exports.WorkspaceMetadataSchema = exports.MessageAdditionToApiSchema = exports.MessageAdditionSchema = exports.PeerRemovalSchema = exports.PeerAdditionToApiSchema = exports.PeerAdditionSchema = exports.PeerCardContentSchema = exports.CardTargetSchema = exports.PeerGetRepresentationParamsSchema = exports.GetRepresentationParamsSchema = exports.FileUploadSchema = exports.QueueStatusOptionsSchema = exports.ContextParamsSchema = exports.RepresentationOptionsSchema = exports.ChatQuerySchema = exports.FilterSchema = exports.SearchQueryLikeSchema = exports.SearchQueryObjectSchema = exports.SearchQuerySchema = exports.MessageInputSchema = exports.MessageConfigurationSchema = exports.MessageMetadataSchema = exports.MessageContentSchema = exports.SessionPeerConfigSchema = exports.SessionAllowlistSchema = exports.SessionScopesSchema = exports.ScopeSessionsSchema = exports.ScopeOptionSchema = exports.ScopeIdSchema = exports.SessionIdSchema = exports.SessionConfigSchema = exports.DialecticConfigSchema = exports.DreamConfigSchema = exports.SummaryConfigSchema = exports.PeerCardConfigSchema = exports.ReasoningConfigSchema = exports.SessionMetadataSchema = exports.PeerIdSchema = exports.PeerConfigSchema = exports.PeerMetadataSchema = exports.HonchoConfigSchema = exports.WorkspaceIdSchema = undefined;
|
|
13695
13446
|
exports.normalizeSearchQuery = normalizeSearchQuery;
|
|
13696
13447
|
exports.normalizeListOptions = normalizeListOptions;
|
|
13448
|
+
exports.scopeRecallFields = scopeRecallFields;
|
|
13697
13449
|
exports.peerConfigToApi = peerConfigToApi;
|
|
13698
13450
|
exports.peerConfigFromApi = peerConfigFromApi;
|
|
13699
13451
|
exports.workspaceConfigToApi = workspaceConfigToApi;
|
|
@@ -13703,7 +13455,7 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13703
13455
|
exports.messageConfigToApi = messageConfigToApi;
|
|
13704
13456
|
exports.messageConfigFromApi = messageConfigFromApi;
|
|
13705
13457
|
var zod_1 = require_zod();
|
|
13706
|
-
exports.WorkspaceIdSchema = zod_1.z.string().min(1, "Workspace ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Workspace ID may only contain letters, numbers, underscores, and hyphens").max(
|
|
13458
|
+
exports.WorkspaceIdSchema = zod_1.z.string().min(1, "Workspace ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Workspace ID may only contain letters, numbers, underscores, and hyphens").max(512, "Workspace ID can be at most 512 characters");
|
|
13707
13459
|
exports.HonchoConfigSchema = zod_1.z.object({
|
|
13708
13460
|
apiKey: zod_1.z.string().optional(),
|
|
13709
13461
|
environment: zod_1.z.enum(["local", "production"]).optional(),
|
|
@@ -13718,7 +13470,7 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13718
13470
|
exports.PeerConfigSchema = zod_1.z.object({
|
|
13719
13471
|
observeMe: zod_1.z.boolean().nullable().optional()
|
|
13720
13472
|
}).strict();
|
|
13721
|
-
exports.PeerIdSchema = zod_1.z.string().min(1, "Peer ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Peer ID may only contain letters, numbers, underscores, and hyphens").max(
|
|
13473
|
+
exports.PeerIdSchema = zod_1.z.string().min(1, "Peer ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Peer ID may only contain letters, numbers, underscores, and hyphens").max(512, "Peer ID can be at most 512 characters");
|
|
13722
13474
|
var PeerIdObjectSchema = zod_1.z.object({ id: exports.PeerIdSchema });
|
|
13723
13475
|
exports.SessionMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
13724
13476
|
exports.ReasoningConfigSchema = zod_1.z.object({
|
|
@@ -13727,32 +13479,92 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13727
13479
|
}).strict();
|
|
13728
13480
|
exports.PeerCardConfigSchema = zod_1.z.object({
|
|
13729
13481
|
use: zod_1.z.boolean().nullable().optional(),
|
|
13730
|
-
create: zod_1.z.boolean().nullable().optional()
|
|
13482
|
+
create: zod_1.z.boolean().nullable().optional(),
|
|
13483
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
13731
13484
|
}).strict();
|
|
13732
13485
|
exports.SummaryConfigSchema = zod_1.z.object({
|
|
13733
13486
|
enabled: zod_1.z.boolean().nullable().optional(),
|
|
13734
13487
|
messagesPerShortSummary: zod_1.z.number().int().min(10).nullable().optional(),
|
|
13735
|
-
messagesPerLongSummary: zod_1.z.number().int().min(20).nullable().optional()
|
|
13488
|
+
messagesPerLongSummary: zod_1.z.number().int().min(20).nullable().optional(),
|
|
13489
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
13736
13490
|
}).strict();
|
|
13737
13491
|
exports.DreamConfigSchema = zod_1.z.object({
|
|
13738
|
-
enabled: zod_1.z.boolean().nullable().optional()
|
|
13492
|
+
enabled: zod_1.z.boolean().nullable().optional(),
|
|
13493
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
13494
|
+
}).strict();
|
|
13495
|
+
exports.DialecticConfigSchema = zod_1.z.object({
|
|
13496
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
13739
13497
|
}).strict();
|
|
13740
13498
|
exports.SessionConfigSchema = zod_1.z.object({
|
|
13499
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
13741
13500
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
13742
13501
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
13743
13502
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
13744
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
13503
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
13504
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
13745
13505
|
}).strict();
|
|
13746
|
-
exports.SessionIdSchema = zod_1.z.string().min(1, "Session ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Session ID may only contain letters, numbers, underscores, and hyphens").max(
|
|
13506
|
+
exports.SessionIdSchema = zod_1.z.string().min(1, "Session ID must be a non-empty string").regex(/^[a-zA-Z0-9_-]+$/, "Session ID may only contain letters, numbers, underscores, and hyphens").max(512, "Session ID can be at most 512 characters");
|
|
13747
13507
|
var SessionIdObjectSchema = zod_1.z.object({ id: exports.SessionIdSchema });
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
|
|
13508
|
+
var SCOPE_PEER_PREFIX = "scope.";
|
|
13509
|
+
var SCOPE_ID_MAX_LENGTH = 512 - SCOPE_PEER_PREFIX.length;
|
|
13510
|
+
function scopeIdIssues(value) {
|
|
13511
|
+
if (value.length < 1) {
|
|
13512
|
+
return ["Scope ID must be a non-empty string"];
|
|
13513
|
+
}
|
|
13514
|
+
if (value.length > SCOPE_ID_MAX_LENGTH) {
|
|
13515
|
+
return [`Scope ID can be at most ${SCOPE_ID_MAX_LENGTH} characters`];
|
|
13516
|
+
}
|
|
13517
|
+
if (value.startsWith(SCOPE_PEER_PREFIX)) {
|
|
13518
|
+
return [
|
|
13519
|
+
`Scope ID must not start with the reserved prefix '${SCOPE_PEER_PREFIX}' (scope IDs are unprefixed)`
|
|
13520
|
+
];
|
|
13521
|
+
}
|
|
13522
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
|
|
13523
|
+
return [
|
|
13524
|
+
"Scope ID may only contain letters, numbers, underscores, and hyphens"
|
|
13525
|
+
];
|
|
13526
|
+
}
|
|
13527
|
+
return [];
|
|
13528
|
+
}
|
|
13529
|
+
function addScopeIdIssues(values, ctx) {
|
|
13530
|
+
for (const value of values) {
|
|
13531
|
+
for (const message of scopeIdIssues(value)) {
|
|
13532
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message });
|
|
13533
|
+
}
|
|
13534
|
+
}
|
|
13535
|
+
}
|
|
13536
|
+
exports.ScopeIdSchema = zod_1.z.string().superRefine((val, ctx) => {
|
|
13537
|
+
addScopeIdIssues([val], ctx);
|
|
13538
|
+
});
|
|
13539
|
+
var ScopeIdLikeSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.object({ id: zod_1.z.string() })]);
|
|
13540
|
+
exports.ScopeOptionSchema = zod_1.z.union([ScopeIdLikeSchema, zod_1.z.array(ScopeIdLikeSchema)]).transform((val) => Array.isArray(val) ? val.map((entry) => typeof entry === "string" ? entry : entry.id) : typeof val === "string" ? val : val.id).superRefine((resolved, ctx) => {
|
|
13541
|
+
if (Array.isArray(resolved)) {
|
|
13542
|
+
if (resolved.length === 0) {
|
|
13543
|
+
ctx.addIssue({
|
|
13544
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13545
|
+
message: "scope must name at least one scope"
|
|
13546
|
+
});
|
|
13547
|
+
}
|
|
13548
|
+
if (resolved.length > 100) {
|
|
13549
|
+
ctx.addIssue({
|
|
13550
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13551
|
+
message: "scope can name at most 100 scopes"
|
|
13552
|
+
});
|
|
13553
|
+
}
|
|
13554
|
+
}
|
|
13555
|
+
addScopeIdIssues(Array.isArray(resolved) ? resolved : [resolved], ctx);
|
|
13556
|
+
});
|
|
13557
|
+
exports.ScopeSessionsSchema = zod_1.z.array(exports.SessionIdSchema).min(1, "At least one session must be given").max(100, "At most 100 sessions can be given per call");
|
|
13558
|
+
exports.SessionScopesSchema = zod_1.z.array(exports.ScopeIdSchema).min(1, "scopes must name at least one scope").max(100, "scopes can name at most 100 scopes");
|
|
13559
|
+
exports.SessionAllowlistSchema = zod_1.z.array(zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema])).min(1, "sessions must name at least one session").max(1000, "sessions can name at most 1000 sessions").transform((vals) => vals.map((v) => typeof v === "string" ? v : v.id));
|
|
13560
|
+
exports.SessionPeerConfigSchema = zod_1.z.object({
|
|
13561
|
+
observeMe: zod_1.z.boolean().nullable().optional(),
|
|
13562
|
+
observeOthers: zod_1.z.boolean().nullable().optional()
|
|
13563
|
+
}).strict();
|
|
13564
|
+
exports.MessageContentSchema = zod_1.z.string().refine((content) => content === "" || content.trim().length > 0, "Message content cannot be only whitespace");
|
|
13565
|
+
exports.MessageMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional();
|
|
13566
|
+
exports.MessageConfigurationSchema = zod_1.z.object({
|
|
13567
|
+
reasoning: exports.ReasoningConfigSchema.nullable().optional()
|
|
13756
13568
|
}).strict().nullable().optional();
|
|
13757
13569
|
exports.MessageInputSchema = zod_1.z.object({
|
|
13758
13570
|
peerId: exports.PeerIdSchema,
|
|
@@ -13792,12 +13604,41 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13792
13604
|
}
|
|
13793
13605
|
return { filters: input };
|
|
13794
13606
|
}
|
|
13607
|
+
function scopeRecallFields(options) {
|
|
13608
|
+
return {
|
|
13609
|
+
scope: options.scope,
|
|
13610
|
+
filters: options.sessions ? { session_id: options.sessions } : undefined
|
|
13611
|
+
};
|
|
13612
|
+
}
|
|
13613
|
+
function scopeExclusivityIssues(data, ctx) {
|
|
13614
|
+
if (data.scope === undefined) {
|
|
13615
|
+
return;
|
|
13616
|
+
}
|
|
13617
|
+
if (data.sessions !== undefined) {
|
|
13618
|
+
ctx.addIssue({
|
|
13619
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13620
|
+
message: "scope and sessions are mutually exclusive",
|
|
13621
|
+
path: ["sessions"]
|
|
13622
|
+
});
|
|
13623
|
+
}
|
|
13624
|
+
if (data.session !== undefined) {
|
|
13625
|
+
ctx.addIssue({
|
|
13626
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13627
|
+
message: "scope and session are mutually exclusive",
|
|
13628
|
+
path: ["session"]
|
|
13629
|
+
});
|
|
13630
|
+
}
|
|
13631
|
+
}
|
|
13795
13632
|
exports.ChatQuerySchema = zod_1.z.object({
|
|
13796
13633
|
query: exports.SearchQuerySchema,
|
|
13797
13634
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
13798
13635
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
13799
|
-
|
|
13800
|
-
|
|
13636
|
+
scope: exports.ScopeOptionSchema.optional(),
|
|
13637
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
13638
|
+
reasoningLevel: zod_1.z.enum(["minimal", "low", "medium", "high", "max"]).optional(),
|
|
13639
|
+
responseFormat: zod_1.z.union([zod_1.z.instanceof(zod_1.z.ZodType), zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())]).optional(),
|
|
13640
|
+
includeEvidence: zod_1.z.boolean().optional()
|
|
13641
|
+
}).strict().superRefine(scopeExclusivityIssues);
|
|
13801
13642
|
exports.RepresentationOptionsSchema = zod_1.z.object({
|
|
13802
13643
|
searchQuery: exports.SearchQueryLikeSchema.optional(),
|
|
13803
13644
|
searchTopK: zod_1.z.number().int().min(1, "searchTopK must be at least 1").max(100, "searchTopK must be at most 100").optional(),
|
|
@@ -13810,9 +13651,32 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13810
13651
|
tokens: zod_1.z.int("Token limit must be an integer").optional(),
|
|
13811
13652
|
peerTarget: exports.PeerIdSchema.optional(),
|
|
13812
13653
|
peerPerspective: exports.PeerIdSchema.optional(),
|
|
13654
|
+
scope: exports.ScopeIdSchema.optional(),
|
|
13655
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
13813
13656
|
limitToSession: zod_1.z.boolean().optional(),
|
|
13814
13657
|
representationOptions: exports.RepresentationOptionsSchema.optional()
|
|
13815
13658
|
}).strict().superRefine((data, ctx) => {
|
|
13659
|
+
if (data.sessions && !data.peerTarget) {
|
|
13660
|
+
ctx.addIssue({
|
|
13661
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13662
|
+
message: "peerTarget is required when sessions is provided",
|
|
13663
|
+
path: ["sessions"]
|
|
13664
|
+
});
|
|
13665
|
+
}
|
|
13666
|
+
if (data.sessions && data.scope) {
|
|
13667
|
+
ctx.addIssue({
|
|
13668
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13669
|
+
message: "sessions and scope are mutually exclusive",
|
|
13670
|
+
path: ["sessions"]
|
|
13671
|
+
});
|
|
13672
|
+
}
|
|
13673
|
+
if (data.sessions && data.limitToSession) {
|
|
13674
|
+
ctx.addIssue({
|
|
13675
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13676
|
+
message: "sessions and limitToSession are mutually exclusive",
|
|
13677
|
+
path: ["sessions"]
|
|
13678
|
+
});
|
|
13679
|
+
}
|
|
13816
13680
|
if (data.representationOptions?.searchQuery && !data.peerTarget) {
|
|
13817
13681
|
ctx.addIssue({
|
|
13818
13682
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -13827,6 +13691,20 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13827
13691
|
path: ["peerPerspective"]
|
|
13828
13692
|
});
|
|
13829
13693
|
}
|
|
13694
|
+
if (data.scope && !data.peerTarget) {
|
|
13695
|
+
ctx.addIssue({
|
|
13696
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13697
|
+
message: "peerTarget is required when scope is provided",
|
|
13698
|
+
path: ["scope"]
|
|
13699
|
+
});
|
|
13700
|
+
}
|
|
13701
|
+
if (data.scope && data.peerPerspective) {
|
|
13702
|
+
ctx.addIssue({
|
|
13703
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
13704
|
+
message: "scope and peerPerspective are mutually exclusive",
|
|
13705
|
+
path: ["scope"]
|
|
13706
|
+
});
|
|
13707
|
+
}
|
|
13830
13708
|
});
|
|
13831
13709
|
exports.QueueStatusOptionsSchema = zod_1.z.object({
|
|
13832
13710
|
observer: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
@@ -13855,9 +13733,11 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13855
13733
|
}).strict();
|
|
13856
13734
|
exports.PeerGetRepresentationParamsSchema = zod_1.z.object({
|
|
13857
13735
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional(),
|
|
13736
|
+
scope: exports.ScopeOptionSchema.optional(),
|
|
13737
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
13858
13738
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
13859
13739
|
options: exports.RepresentationOptionsSchema.optional()
|
|
13860
|
-
}).strict();
|
|
13740
|
+
}).strict().superRefine(scopeExclusivityIssues);
|
|
13861
13741
|
exports.CardTargetSchema = zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined);
|
|
13862
13742
|
exports.PeerCardContentSchema = zod_1.z.array(zod_1.z.string());
|
|
13863
13743
|
exports.PeerAdditionSchema = zod_1.z.union([
|
|
@@ -13918,7 +13798,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13918
13798
|
return;
|
|
13919
13799
|
return {
|
|
13920
13800
|
use: config.use,
|
|
13921
|
-
create: config.create
|
|
13801
|
+
create: config.create,
|
|
13802
|
+
custom_instructions: config.customInstructions
|
|
13922
13803
|
};
|
|
13923
13804
|
}
|
|
13924
13805
|
function peerCardConfigFromApi(config) {
|
|
@@ -13928,7 +13809,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13928
13809
|
return;
|
|
13929
13810
|
return {
|
|
13930
13811
|
use: config.use,
|
|
13931
|
-
create: config.create
|
|
13812
|
+
create: config.create,
|
|
13813
|
+
customInstructions: config.custom_instructions
|
|
13932
13814
|
};
|
|
13933
13815
|
}
|
|
13934
13816
|
function summaryConfigToApi(config) {
|
|
@@ -13939,7 +13821,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13939
13821
|
return {
|
|
13940
13822
|
enabled: config.enabled,
|
|
13941
13823
|
messages_per_short_summary: config.messagesPerShortSummary,
|
|
13942
|
-
messages_per_long_summary: config.messagesPerLongSummary
|
|
13824
|
+
messages_per_long_summary: config.messagesPerLongSummary,
|
|
13825
|
+
custom_instructions: config.customInstructions
|
|
13943
13826
|
};
|
|
13944
13827
|
}
|
|
13945
13828
|
function summaryConfigFromApi(config) {
|
|
@@ -13950,7 +13833,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13950
13833
|
return {
|
|
13951
13834
|
enabled: config.enabled,
|
|
13952
13835
|
messagesPerShortSummary: config.messages_per_short_summary,
|
|
13953
|
-
messagesPerLongSummary: config.messages_per_long_summary
|
|
13836
|
+
messagesPerLongSummary: config.messages_per_long_summary,
|
|
13837
|
+
customInstructions: config.custom_instructions
|
|
13954
13838
|
};
|
|
13955
13839
|
}
|
|
13956
13840
|
function dreamConfigToApi(config) {
|
|
@@ -13959,7 +13843,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13959
13843
|
if (config === undefined)
|
|
13960
13844
|
return;
|
|
13961
13845
|
return {
|
|
13962
|
-
enabled: config.enabled
|
|
13846
|
+
enabled: config.enabled,
|
|
13847
|
+
custom_instructions: config.customInstructions
|
|
13963
13848
|
};
|
|
13964
13849
|
}
|
|
13965
13850
|
function dreamConfigFromApi(config) {
|
|
@@ -13968,17 +13853,38 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13968
13853
|
if (config === undefined)
|
|
13969
13854
|
return;
|
|
13970
13855
|
return {
|
|
13971
|
-
enabled: config.enabled
|
|
13856
|
+
enabled: config.enabled,
|
|
13857
|
+
customInstructions: config.custom_instructions
|
|
13858
|
+
};
|
|
13859
|
+
}
|
|
13860
|
+
function dialecticConfigToApi(config) {
|
|
13861
|
+
if (config === null)
|
|
13862
|
+
return null;
|
|
13863
|
+
if (config === undefined)
|
|
13864
|
+
return;
|
|
13865
|
+
return {
|
|
13866
|
+
custom_instructions: config.customInstructions
|
|
13867
|
+
};
|
|
13868
|
+
}
|
|
13869
|
+
function dialecticConfigFromApi(config) {
|
|
13870
|
+
if (config === null)
|
|
13871
|
+
return null;
|
|
13872
|
+
if (config === undefined)
|
|
13873
|
+
return;
|
|
13874
|
+
return {
|
|
13875
|
+
customInstructions: config.custom_instructions
|
|
13972
13876
|
};
|
|
13973
13877
|
}
|
|
13974
13878
|
function workspaceConfigToApi(config) {
|
|
13975
13879
|
if (!config)
|
|
13976
13880
|
return;
|
|
13977
13881
|
return {
|
|
13882
|
+
custom_instructions: config.customInstructions,
|
|
13978
13883
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
13979
13884
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
13980
13885
|
summary: summaryConfigToApi(config.summary),
|
|
13981
|
-
dream: dreamConfigToApi(config.dream)
|
|
13886
|
+
dream: dreamConfigToApi(config.dream),
|
|
13887
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
13982
13888
|
};
|
|
13983
13889
|
}
|
|
13984
13890
|
function workspaceConfigFromApi(config) {
|
|
@@ -13986,20 +13892,24 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13986
13892
|
return;
|
|
13987
13893
|
const apiConfig = config;
|
|
13988
13894
|
return {
|
|
13895
|
+
customInstructions: apiConfig.custom_instructions,
|
|
13989
13896
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
13990
13897
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
13991
13898
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
13992
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
13899
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
13900
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
13993
13901
|
};
|
|
13994
13902
|
}
|
|
13995
13903
|
function sessionConfigToApi(config) {
|
|
13996
13904
|
if (!config)
|
|
13997
13905
|
return;
|
|
13998
13906
|
return {
|
|
13907
|
+
custom_instructions: config.customInstructions,
|
|
13999
13908
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
14000
13909
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
14001
13910
|
summary: summaryConfigToApi(config.summary),
|
|
14002
|
-
dream: dreamConfigToApi(config.dream)
|
|
13911
|
+
dream: dreamConfigToApi(config.dream),
|
|
13912
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
14003
13913
|
};
|
|
14004
13914
|
}
|
|
14005
13915
|
function sessionConfigFromApi(config) {
|
|
@@ -14007,10 +13917,12 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14007
13917
|
return;
|
|
14008
13918
|
const apiConfig = config;
|
|
14009
13919
|
return {
|
|
13920
|
+
customInstructions: apiConfig.custom_instructions,
|
|
14010
13921
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
14011
13922
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
14012
13923
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
14013
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
13924
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
13925
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
14014
13926
|
};
|
|
14015
13927
|
}
|
|
14016
13928
|
function messageConfigToApi(config) {
|
|
@@ -14082,10 +13994,12 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14082
13994
|
});
|
|
14083
13995
|
exports.WorkspaceMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
14084
13996
|
exports.WorkspaceConfigSchema = zod_1.z.object({
|
|
13997
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
14085
13998
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
14086
13999
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
14087
14000
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
14088
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
14001
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
14002
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
14089
14003
|
}).strict();
|
|
14090
14004
|
exports.LimitSchema = zod_1.z.number().int().min(1, "Limit must be a positive integer").max(100, "Limit must be less than or equal to 100");
|
|
14091
14005
|
exports.ConclusionQueryParamsSchema = zod_1.z.object({
|
|
@@ -14099,22 +14013,46 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14099
14013
|
// node_modules/@honcho-ai/sdk/dist/conclusions.js
|
|
14100
14014
|
var require_conclusions = __commonJS(function(exports) {
|
|
14101
14015
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14102
|
-
exports.
|
|
14016
|
+
exports.WorkspaceConclusions = exports.ConclusionsView = exports.Conclusion = undefined;
|
|
14103
14017
|
var api_version_1 = require_api_version();
|
|
14018
|
+
var errors_1 = require_errors();
|
|
14104
14019
|
var pagination_1 = require_pagination();
|
|
14105
14020
|
var validation_1 = require_validation();
|
|
14021
|
+
var LIST_PAGE_CAP = 100;
|
|
14022
|
+
var VIEW_RESERVED_KEYS = [
|
|
14023
|
+
"observer",
|
|
14024
|
+
"observed",
|
|
14025
|
+
"observer_id",
|
|
14026
|
+
"observed_id"
|
|
14027
|
+
];
|
|
14028
|
+
function rejectReservedFilterKeys(filters, reserved) {
|
|
14029
|
+
if (!filters)
|
|
14030
|
+
return;
|
|
14031
|
+
const clash = reserved.filter((k) => (k in filters)).sort();
|
|
14032
|
+
if (clash.length > 0) {
|
|
14033
|
+
let guidance = "Choose the peer pair via peer.conclusions / peer.conclusionsOf(target)";
|
|
14034
|
+
if (reserved.includes("session") || reserved.includes("session_id")) {
|
|
14035
|
+
guidance += "; use the session option to filter by session";
|
|
14036
|
+
}
|
|
14037
|
+
throw new Error(`Filter key(s) ${clash.join(", ")} are managed by this conclusions view ` + `and cannot be passed in filters. ${guidance}.`);
|
|
14038
|
+
}
|
|
14039
|
+
}
|
|
14106
14040
|
|
|
14107
14041
|
class Conclusion {
|
|
14108
|
-
constructor(id, content, observerId, observedId, sessionId, createdAt) {
|
|
14042
|
+
constructor(id, content, observerId, observedId, sessionId, createdAt, level = "explicit", sourceIds = null, timesDerived = 1, sourceMessageIds = null) {
|
|
14109
14043
|
this.id = id;
|
|
14110
14044
|
this.content = content;
|
|
14111
14045
|
this.observerId = observerId;
|
|
14112
14046
|
this.observedId = observedId;
|
|
14113
14047
|
this.sessionId = sessionId;
|
|
14048
|
+
this.level = level;
|
|
14049
|
+
this.sourceIds = sourceIds;
|
|
14050
|
+
this.timesDerived = timesDerived;
|
|
14051
|
+
this.sourceMessageIds = sourceMessageIds;
|
|
14114
14052
|
this.createdAt = createdAt;
|
|
14115
14053
|
}
|
|
14116
14054
|
static fromApiResponse(data) {
|
|
14117
|
-
return new Conclusion(data.id, data.content, data.observer_id, data.observed_id, data.session_id, data.created_at);
|
|
14055
|
+
return new Conclusion(data.id, data.content, data.observer_id, data.observed_id, data.session_id, data.created_at, data.level, data.source_ids ?? null, data.times_derived ?? 1, data.source_message_ids ?? null);
|
|
14118
14056
|
}
|
|
14119
14057
|
toString() {
|
|
14120
14058
|
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
@@ -14123,7 +14061,7 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14123
14061
|
}
|
|
14124
14062
|
exports.Conclusion = Conclusion;
|
|
14125
14063
|
|
|
14126
|
-
class
|
|
14064
|
+
class ConclusionsView {
|
|
14127
14065
|
constructor(http, workspaceId, observer, observed, ensureWorkspace = async () => {
|
|
14128
14066
|
return;
|
|
14129
14067
|
}) {
|
|
@@ -14152,6 +14090,26 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14152
14090
|
await this._ensureWorkspace();
|
|
14153
14091
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions`, { body: params });
|
|
14154
14092
|
}
|
|
14093
|
+
async _get(conclusionId) {
|
|
14094
|
+
await this._ensureWorkspace();
|
|
14095
|
+
const item = await this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
14096
|
+
if (item.observer_id !== this.observer || item.observed_id !== this.observed) {
|
|
14097
|
+
throw new errors_1.NotFoundError("Conclusion not found");
|
|
14098
|
+
}
|
|
14099
|
+
return item;
|
|
14100
|
+
}
|
|
14101
|
+
async _derived(conclusionId, params) {
|
|
14102
|
+
return this._list({
|
|
14103
|
+
filters: {
|
|
14104
|
+
source_ids: { contains: conclusionId },
|
|
14105
|
+
observer_id: this.observer,
|
|
14106
|
+
observed_id: this.observed
|
|
14107
|
+
},
|
|
14108
|
+
page: params.page,
|
|
14109
|
+
size: params.size,
|
|
14110
|
+
reverse: params.reverse
|
|
14111
|
+
});
|
|
14112
|
+
}
|
|
14155
14113
|
async _delete(conclusionId) {
|
|
14156
14114
|
await this._ensureWorkspace();
|
|
14157
14115
|
await this._http.delete(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
@@ -14161,14 +14119,18 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14161
14119
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${peerId}/representation`, { body: params });
|
|
14162
14120
|
}
|
|
14163
14121
|
async list(options) {
|
|
14122
|
+
rejectReservedFilterKeys(options?.filters, [
|
|
14123
|
+
...VIEW_RESERVED_KEYS,
|
|
14124
|
+
"session",
|
|
14125
|
+
"session_id"
|
|
14126
|
+
]);
|
|
14164
14127
|
const resolvedSessionId = options?.session ? typeof options.session === "string" ? options.session : options.session.id : undefined;
|
|
14165
14128
|
const filters = {
|
|
14166
14129
|
observer_id: this.observer,
|
|
14167
|
-
observed_id: this.observed
|
|
14130
|
+
observed_id: this.observed,
|
|
14131
|
+
...resolvedSessionId ? { session_id: resolvedSessionId } : {},
|
|
14132
|
+
...options?.filters
|
|
14168
14133
|
};
|
|
14169
|
-
if (resolvedSessionId) {
|
|
14170
|
-
filters.session_id = resolvedSessionId;
|
|
14171
|
-
}
|
|
14172
14134
|
const reverse = options?.reverse;
|
|
14173
14135
|
const response = await this._list({
|
|
14174
14136
|
filters,
|
|
@@ -14181,19 +14143,55 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14181
14143
|
};
|
|
14182
14144
|
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
14183
14145
|
}
|
|
14184
|
-
async query(query, topK = 10, distance) {
|
|
14185
|
-
|
|
14186
|
-
observer_id: this.observer,
|
|
14187
|
-
observed_id: this.observed
|
|
14188
|
-
};
|
|
14146
|
+
async query(query, topK = 10, distance, filters) {
|
|
14147
|
+
rejectReservedFilterKeys(filters, VIEW_RESERVED_KEYS);
|
|
14189
14148
|
const response = await this._query({
|
|
14190
14149
|
query,
|
|
14191
14150
|
top_k: topK,
|
|
14192
14151
|
distance,
|
|
14193
|
-
filters
|
|
14152
|
+
filters: {
|
|
14153
|
+
observer_id: this.observer,
|
|
14154
|
+
observed_id: this.observed,
|
|
14155
|
+
...filters
|
|
14156
|
+
}
|
|
14194
14157
|
});
|
|
14195
14158
|
return (response ?? []).map((item) => Conclusion.fromApiResponse(item));
|
|
14196
14159
|
}
|
|
14160
|
+
async get(conclusionId) {
|
|
14161
|
+
const response = await this._get(conclusionId);
|
|
14162
|
+
return Conclusion.fromApiResponse(response);
|
|
14163
|
+
}
|
|
14164
|
+
async getMany(conclusionIds) {
|
|
14165
|
+
if (conclusionIds.length === 0)
|
|
14166
|
+
return [];
|
|
14167
|
+
const conclusions = [];
|
|
14168
|
+
for (let start = 0;start < conclusionIds.length; start += LIST_PAGE_CAP) {
|
|
14169
|
+
const chunk = conclusionIds.slice(start, start + LIST_PAGE_CAP);
|
|
14170
|
+
const response = await this._list({
|
|
14171
|
+
filters: {
|
|
14172
|
+
id: { in: chunk },
|
|
14173
|
+
observer_id: this.observer,
|
|
14174
|
+
observed_id: this.observed
|
|
14175
|
+
},
|
|
14176
|
+
page: 1,
|
|
14177
|
+
size: chunk.length
|
|
14178
|
+
});
|
|
14179
|
+
conclusions.push(...(response.items ?? []).map((item) => Conclusion.fromApiResponse(item)));
|
|
14180
|
+
}
|
|
14181
|
+
return conclusions;
|
|
14182
|
+
}
|
|
14183
|
+
async derived(conclusionId, options) {
|
|
14184
|
+
const reverse = options?.reverse;
|
|
14185
|
+
const response = await this._derived(conclusionId, {
|
|
14186
|
+
page: options?.page ?? 1,
|
|
14187
|
+
size: options?.size ?? 50,
|
|
14188
|
+
reverse
|
|
14189
|
+
});
|
|
14190
|
+
const fetchNextPage = async (page, size) => {
|
|
14191
|
+
return this._derived(conclusionId, { page, size, reverse });
|
|
14192
|
+
};
|
|
14193
|
+
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
14194
|
+
}
|
|
14197
14195
|
async delete(conclusionId) {
|
|
14198
14196
|
await this._delete(conclusionId);
|
|
14199
14197
|
}
|
|
@@ -14228,129 +14226,452 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14228
14226
|
return response.representation;
|
|
14229
14227
|
}
|
|
14230
14228
|
toString() {
|
|
14231
|
-
return `
|
|
14232
|
-
}
|
|
14233
|
-
}
|
|
14234
|
-
exports.ConclusionScope = ConclusionScope;
|
|
14235
|
-
});
|
|
14236
|
-
|
|
14237
|
-
// node_modules/@honcho-ai/sdk/dist/http/streaming.js
|
|
14238
|
-
var require_streaming = __commonJS(function(exports) {
|
|
14239
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14240
|
-
exports.DialecticStreamResponse = undefined;
|
|
14241
|
-
exports.parseSSE = parseSSE;
|
|
14242
|
-
exports.createDialecticStream = createDialecticStream;
|
|
14243
|
-
async function* parseSSE(response) {
|
|
14244
|
-
if (!response.body) {
|
|
14245
|
-
throw new Error("Response body is null");
|
|
14246
|
-
}
|
|
14247
|
-
const reader = response.body.getReader();
|
|
14248
|
-
const decoder = new TextDecoder;
|
|
14249
|
-
let buffer = "";
|
|
14250
|
-
try {
|
|
14251
|
-
while (true) {
|
|
14252
|
-
const { done, value } = await reader.read();
|
|
14253
|
-
if (done)
|
|
14254
|
-
break;
|
|
14255
|
-
buffer += decoder.decode(value, { stream: true });
|
|
14256
|
-
const lines = buffer.split(`
|
|
14257
|
-
`);
|
|
14258
|
-
buffer = lines.pop() || "";
|
|
14259
|
-
for (const line of lines) {
|
|
14260
|
-
if (line.startsWith("data: ")) {
|
|
14261
|
-
const jsonStr = line.slice(6);
|
|
14262
|
-
if (jsonStr.trim() === "[DONE]") {
|
|
14263
|
-
return;
|
|
14264
|
-
}
|
|
14265
|
-
try {
|
|
14266
|
-
const data = JSON.parse(jsonStr);
|
|
14267
|
-
yield data;
|
|
14268
|
-
} catch {}
|
|
14269
|
-
}
|
|
14270
|
-
}
|
|
14271
|
-
}
|
|
14272
|
-
if (buffer.startsWith("data: ")) {
|
|
14273
|
-
const jsonStr = buffer.slice(6);
|
|
14274
|
-
if (jsonStr.trim() !== "[DONE]") {
|
|
14275
|
-
try {
|
|
14276
|
-
const data = JSON.parse(jsonStr);
|
|
14277
|
-
yield data;
|
|
14278
|
-
} catch {}
|
|
14279
|
-
}
|
|
14280
|
-
}
|
|
14281
|
-
} finally {
|
|
14282
|
-
reader.releaseLock();
|
|
14229
|
+
return `ConclusionsView(workspaceId='${this.workspaceId}', observer='${this.observer}', observed='${this.observed}')`;
|
|
14283
14230
|
}
|
|
14284
14231
|
}
|
|
14232
|
+
exports.ConclusionsView = ConclusionsView;
|
|
14285
14233
|
|
|
14286
|
-
class
|
|
14287
|
-
constructor(
|
|
14288
|
-
|
|
14289
|
-
|
|
14290
|
-
this.
|
|
14234
|
+
class WorkspaceConclusions {
|
|
14235
|
+
constructor(http, workspaceId, ensureWorkspace = async () => {
|
|
14236
|
+
return;
|
|
14237
|
+
}) {
|
|
14238
|
+
this._http = http;
|
|
14239
|
+
this.workspaceId = workspaceId;
|
|
14240
|
+
this._ensureWorkspace = ensureWorkspace;
|
|
14291
14241
|
}
|
|
14292
|
-
async
|
|
14293
|
-
|
|
14294
|
-
|
|
14295
|
-
|
|
14242
|
+
async _list(params) {
|
|
14243
|
+
await this._ensureWorkspace();
|
|
14244
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/list`, {
|
|
14245
|
+
body: params.filters ? { filters: params.filters } : undefined,
|
|
14246
|
+
query: {
|
|
14247
|
+
page: params.page,
|
|
14248
|
+
size: params.size,
|
|
14249
|
+
reverse: params.reverse ? "true" : undefined
|
|
14296
14250
|
}
|
|
14297
|
-
|
|
14298
|
-
}
|
|
14299
|
-
for await (const chunk of this.generator) {
|
|
14300
|
-
this.chunks.push(chunk);
|
|
14301
|
-
yield chunk;
|
|
14302
|
-
}
|
|
14303
|
-
this.consumed = true;
|
|
14251
|
+
});
|
|
14304
14252
|
}
|
|
14305
|
-
async
|
|
14306
|
-
|
|
14307
|
-
|
|
14308
|
-
|
|
14309
|
-
|
|
14253
|
+
async list(options) {
|
|
14254
|
+
const filters = options?.filters;
|
|
14255
|
+
const reverse = options?.reverse;
|
|
14256
|
+
const response = await this._list({
|
|
14257
|
+
filters,
|
|
14258
|
+
page: options?.page ?? 1,
|
|
14259
|
+
size: options?.size ?? 50,
|
|
14260
|
+
reverse
|
|
14261
|
+
});
|
|
14262
|
+
const fetchNextPage = async (page, size) => {
|
|
14263
|
+
return this._list({ filters, page, size, reverse });
|
|
14264
|
+
};
|
|
14265
|
+
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
14310
14266
|
}
|
|
14311
|
-
async
|
|
14312
|
-
|
|
14313
|
-
|
|
14267
|
+
async get(conclusionId) {
|
|
14268
|
+
await this._ensureWorkspace();
|
|
14269
|
+
const item = await this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
14270
|
+
return Conclusion.fromApiResponse(item);
|
|
14271
|
+
}
|
|
14272
|
+
async getMany(conclusionIds) {
|
|
14273
|
+
if (conclusionIds.length === 0)
|
|
14274
|
+
return [];
|
|
14275
|
+
const conclusions = [];
|
|
14276
|
+
for (let start = 0;start < conclusionIds.length; start += LIST_PAGE_CAP) {
|
|
14277
|
+
const chunk = conclusionIds.slice(start, start + LIST_PAGE_CAP);
|
|
14278
|
+
const response = await this._list({
|
|
14279
|
+
filters: { id: { in: chunk } },
|
|
14280
|
+
page: 1,
|
|
14281
|
+
size: chunk.length
|
|
14282
|
+
});
|
|
14283
|
+
conclusions.push(...(response.items ?? []).map((item) => Conclusion.fromApiResponse(item)));
|
|
14314
14284
|
}
|
|
14315
|
-
return
|
|
14285
|
+
return conclusions;
|
|
14316
14286
|
}
|
|
14317
|
-
|
|
14318
|
-
|
|
14319
|
-
function createDialecticStream(response) {
|
|
14320
|
-
async function* streamContent() {
|
|
14321
|
-
for await (const chunk of parseSSE(response)) {
|
|
14322
|
-
if (chunk.done) {
|
|
14323
|
-
return;
|
|
14324
|
-
}
|
|
14325
|
-
const content = chunk.delta?.content;
|
|
14326
|
-
if (content) {
|
|
14327
|
-
yield content;
|
|
14328
|
-
}
|
|
14329
|
-
}
|
|
14287
|
+
toString() {
|
|
14288
|
+
return `WorkspaceConclusions(workspaceId='${this.workspaceId}')`;
|
|
14330
14289
|
}
|
|
14331
|
-
return new DialecticStreamResponse(streamContent());
|
|
14332
14290
|
}
|
|
14291
|
+
exports.WorkspaceConclusions = WorkspaceConclusions;
|
|
14333
14292
|
});
|
|
14334
14293
|
|
|
14335
|
-
// node_modules/@honcho-ai/sdk/dist/
|
|
14336
|
-
var
|
|
14294
|
+
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
14295
|
+
var require_client = __commonJS(function(exports) {
|
|
14337
14296
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14338
|
-
exports.
|
|
14339
|
-
|
|
14297
|
+
exports.HonchoHTTPClient = exports.HOST_HEADER = undefined;
|
|
14298
|
+
exports.defaultHostHeader = defaultHostHeader;
|
|
14299
|
+
var api_version_1 = require_api_version();
|
|
14300
|
+
var errors_1 = require_errors();
|
|
14301
|
+
var DEFAULT_TIMEOUT = 60000;
|
|
14302
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
14303
|
+
var RETRY_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
14304
|
+
var INITIAL_RETRY_DELAY = 500;
|
|
14305
|
+
exports.HOST_HEADER = "X-Honcho-Host";
|
|
14306
|
+
function defaultHostHeader() {
|
|
14307
|
+
const product = `honcho-typescript/${api_version_1.VERSION}`;
|
|
14308
|
+
const platform = typeof process !== "undefined" && typeof process.platform === "string" ? process.platform : undefined;
|
|
14309
|
+
return platform ? `${product} (${platform})` : product;
|
|
14310
|
+
}
|
|
14340
14311
|
|
|
14341
|
-
class
|
|
14342
|
-
constructor(
|
|
14343
|
-
this.
|
|
14344
|
-
this.
|
|
14345
|
-
this.
|
|
14346
|
-
this.
|
|
14347
|
-
this.
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14312
|
+
class HonchoHTTPClient {
|
|
14313
|
+
constructor(config) {
|
|
14314
|
+
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
14315
|
+
this.apiKey = config.apiKey;
|
|
14316
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
14317
|
+
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
14318
|
+
this.defaultHeaders = {
|
|
14319
|
+
"Content-Type": "application/json",
|
|
14320
|
+
[exports.HOST_HEADER]: defaultHostHeader(),
|
|
14321
|
+
...config.defaultHeaders
|
|
14322
|
+
};
|
|
14323
|
+
this.defaultQuery = config.defaultQuery;
|
|
14324
|
+
}
|
|
14325
|
+
async request(method, path, options = {}) {
|
|
14326
|
+
const url = this.buildURL(path, options.query);
|
|
14327
|
+
const headers = this.buildHeaders(options.headers);
|
|
14328
|
+
const timeout = options.timeout ?? this.timeout;
|
|
14329
|
+
let lastError;
|
|
14330
|
+
let attempt = 0;
|
|
14331
|
+
while (attempt <= this.maxRetries) {
|
|
14332
|
+
try {
|
|
14333
|
+
const response = await this.fetchWithTimeout(url, {
|
|
14334
|
+
method,
|
|
14335
|
+
headers,
|
|
14336
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
14337
|
+
signal: options.signal
|
|
14338
|
+
}, timeout);
|
|
14339
|
+
if (response.ok) {
|
|
14340
|
+
const text = await response.text();
|
|
14341
|
+
if (!text) {
|
|
14342
|
+
return;
|
|
14343
|
+
}
|
|
14344
|
+
return JSON.parse(text);
|
|
14345
|
+
}
|
|
14346
|
+
const errorBody = await this.parseErrorBody(response);
|
|
14347
|
+
const retryAfter = this.parseRetryAfter(response);
|
|
14348
|
+
const error = (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody, retryAfter);
|
|
14349
|
+
if (RETRY_STATUS_CODES.includes(response.status) && attempt < this.maxRetries) {
|
|
14350
|
+
lastError = error;
|
|
14351
|
+
await this.sleep(this.getRetryDelay(attempt, retryAfter));
|
|
14352
|
+
attempt++;
|
|
14353
|
+
continue;
|
|
14354
|
+
}
|
|
14355
|
+
throw error;
|
|
14356
|
+
} catch (error) {
|
|
14357
|
+
if (error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
14358
|
+
if (attempt < this.maxRetries) {
|
|
14359
|
+
lastError = error;
|
|
14360
|
+
await this.sleep(this.getRetryDelay(attempt));
|
|
14361
|
+
attempt++;
|
|
14362
|
+
continue;
|
|
14363
|
+
}
|
|
14364
|
+
}
|
|
14365
|
+
if (error instanceof errors_1.RateLimitError || error instanceof errors_1.ServerError || error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
14366
|
+
throw error;
|
|
14367
|
+
}
|
|
14368
|
+
throw error;
|
|
14369
|
+
}
|
|
14370
|
+
}
|
|
14371
|
+
throw lastError || new Error("Request failed after retries");
|
|
14372
|
+
}
|
|
14373
|
+
async get(path, options) {
|
|
14374
|
+
return this.request("GET", path, options);
|
|
14375
|
+
}
|
|
14376
|
+
async post(path, options) {
|
|
14377
|
+
return this.request("POST", path, options);
|
|
14378
|
+
}
|
|
14379
|
+
async put(path, options) {
|
|
14380
|
+
return this.request("PUT", path, options);
|
|
14381
|
+
}
|
|
14382
|
+
async patch(path, options) {
|
|
14383
|
+
return this.request("PATCH", path, options);
|
|
14384
|
+
}
|
|
14385
|
+
async delete(path, options) {
|
|
14386
|
+
return this.request("DELETE", path, options);
|
|
14387
|
+
}
|
|
14388
|
+
async stream(method, path, options = {}) {
|
|
14389
|
+
const url = this.buildURL(path, options.query);
|
|
14390
|
+
const headers = {
|
|
14391
|
+
...this.buildHeaders(options.headers),
|
|
14392
|
+
Accept: "text/event-stream"
|
|
14393
|
+
};
|
|
14394
|
+
const timeout = options.timeout ?? this.timeout;
|
|
14395
|
+
const response = await this.fetchWithTimeout(url, {
|
|
14396
|
+
method,
|
|
14397
|
+
headers,
|
|
14398
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
14399
|
+
signal: options.signal
|
|
14400
|
+
}, timeout);
|
|
14401
|
+
if (!response.ok) {
|
|
14402
|
+
const errorBody = await this.parseErrorBody(response);
|
|
14403
|
+
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
14404
|
+
}
|
|
14405
|
+
return response;
|
|
14406
|
+
}
|
|
14407
|
+
async upload(path, formData, options = {}) {
|
|
14408
|
+
const url = this.buildURL(path, options.query);
|
|
14409
|
+
const headers = {};
|
|
14410
|
+
if (this.apiKey) {
|
|
14411
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
14412
|
+
}
|
|
14413
|
+
if (options.headers) {
|
|
14414
|
+
Object.assign(headers, options.headers);
|
|
14415
|
+
}
|
|
14416
|
+
const timeout = options.timeout ?? this.timeout;
|
|
14417
|
+
const response = await this.fetchWithTimeout(url, {
|
|
14418
|
+
method: "POST",
|
|
14419
|
+
headers,
|
|
14420
|
+
body: formData,
|
|
14421
|
+
signal: options.signal
|
|
14422
|
+
}, timeout);
|
|
14423
|
+
if (!response.ok) {
|
|
14424
|
+
const errorBody = await this.parseErrorBody(response);
|
|
14425
|
+
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
14426
|
+
}
|
|
14427
|
+
const text = await response.text();
|
|
14428
|
+
if (!text) {
|
|
14429
|
+
return;
|
|
14430
|
+
}
|
|
14431
|
+
return JSON.parse(text);
|
|
14432
|
+
}
|
|
14433
|
+
buildURL(path, query) {
|
|
14434
|
+
const url = new URL(path, this.baseURL);
|
|
14435
|
+
const mergedQuery = {
|
|
14436
|
+
...this.defaultQuery ?? {},
|
|
14437
|
+
...query ?? {}
|
|
14438
|
+
};
|
|
14439
|
+
for (const [key, value] of Object.entries(mergedQuery)) {
|
|
14440
|
+
if (value === undefined) {
|
|
14441
|
+
continue;
|
|
14442
|
+
}
|
|
14443
|
+
if (Array.isArray(value)) {
|
|
14444
|
+
for (const entry of value) {
|
|
14445
|
+
url.searchParams.append(key, String(entry));
|
|
14446
|
+
}
|
|
14447
|
+
continue;
|
|
14448
|
+
}
|
|
14449
|
+
url.searchParams.set(key, String(value));
|
|
14450
|
+
}
|
|
14451
|
+
return url.toString();
|
|
14452
|
+
}
|
|
14453
|
+
buildHeaders(extra) {
|
|
14454
|
+
const headers = { ...this.defaultHeaders };
|
|
14455
|
+
if (this.apiKey) {
|
|
14456
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
14457
|
+
}
|
|
14458
|
+
if (extra) {
|
|
14459
|
+
Object.assign(headers, extra);
|
|
14460
|
+
}
|
|
14461
|
+
return headers;
|
|
14462
|
+
}
|
|
14463
|
+
async fetchWithTimeout(url, init, timeout) {
|
|
14464
|
+
const controller = new AbortController;
|
|
14465
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
14466
|
+
if (init.signal) {
|
|
14467
|
+
init.signal.addEventListener("abort", () => controller.abort());
|
|
14468
|
+
}
|
|
14469
|
+
try {
|
|
14470
|
+
const response = await fetch(url, {
|
|
14471
|
+
...init,
|
|
14472
|
+
signal: controller.signal
|
|
14473
|
+
});
|
|
14474
|
+
return response;
|
|
14475
|
+
} catch (error) {
|
|
14476
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
14477
|
+
throw new errors_1.TimeoutError(`Request timed out after ${timeout}ms`);
|
|
14478
|
+
}
|
|
14479
|
+
if (error instanceof TypeError) {
|
|
14480
|
+
throw new errors_1.ConnectionError(error.message);
|
|
14481
|
+
}
|
|
14482
|
+
throw error;
|
|
14483
|
+
} finally {
|
|
14484
|
+
clearTimeout(timeoutId);
|
|
14485
|
+
}
|
|
14486
|
+
}
|
|
14487
|
+
async parseErrorBody(response) {
|
|
14488
|
+
try {
|
|
14489
|
+
const body = await response.json();
|
|
14490
|
+
return {
|
|
14491
|
+
message: body.detail || body.message || body.error,
|
|
14492
|
+
...body
|
|
14493
|
+
};
|
|
14494
|
+
} catch {
|
|
14495
|
+
return { message: `HTTP ${response.status}` };
|
|
14496
|
+
}
|
|
14497
|
+
}
|
|
14498
|
+
parseRetryAfter(response) {
|
|
14499
|
+
const header = response.headers.get("Retry-After");
|
|
14500
|
+
if (!header)
|
|
14501
|
+
return;
|
|
14502
|
+
const seconds = Number.parseInt(header, 10);
|
|
14503
|
+
if (!Number.isNaN(seconds)) {
|
|
14504
|
+
return seconds * 1000;
|
|
14505
|
+
}
|
|
14506
|
+
const date = Date.parse(header);
|
|
14507
|
+
if (!Number.isNaN(date)) {
|
|
14508
|
+
return Math.max(0, date - Date.now());
|
|
14509
|
+
}
|
|
14510
|
+
return;
|
|
14511
|
+
}
|
|
14512
|
+
getRetryDelay(attempt, retryAfter) {
|
|
14513
|
+
if (retryAfter) {
|
|
14514
|
+
return retryAfter;
|
|
14515
|
+
}
|
|
14516
|
+
return INITIAL_RETRY_DELAY * 2 ** attempt;
|
|
14517
|
+
}
|
|
14518
|
+
sleep(ms) {
|
|
14519
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
14520
|
+
}
|
|
14521
|
+
}
|
|
14522
|
+
exports.HonchoHTTPClient = HonchoHTTPClient;
|
|
14523
|
+
});
|
|
14524
|
+
|
|
14525
|
+
// node_modules/@honcho-ai/sdk/dist/http/streaming.js
|
|
14526
|
+
var require_streaming = __commonJS(function(exports) {
|
|
14527
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14528
|
+
exports.DialecticStreamResponse = undefined;
|
|
14529
|
+
exports.parseSSE = parseSSE;
|
|
14530
|
+
exports.createDialecticStream = createDialecticStream;
|
|
14531
|
+
async function* parseSSE(response) {
|
|
14532
|
+
if (!response.body) {
|
|
14533
|
+
throw new Error("Response body is null");
|
|
14534
|
+
}
|
|
14535
|
+
const reader = response.body.getReader();
|
|
14536
|
+
const decoder = new TextDecoder;
|
|
14537
|
+
let buffer = "";
|
|
14538
|
+
try {
|
|
14539
|
+
while (true) {
|
|
14540
|
+
const { done, value } = await reader.read();
|
|
14541
|
+
if (done)
|
|
14542
|
+
break;
|
|
14543
|
+
buffer += decoder.decode(value, { stream: true });
|
|
14544
|
+
const lines = buffer.split(`
|
|
14545
|
+
`);
|
|
14546
|
+
buffer = lines.pop() || "";
|
|
14547
|
+
for (const line of lines) {
|
|
14548
|
+
if (line.startsWith("data: ")) {
|
|
14549
|
+
const jsonStr = line.slice(6);
|
|
14550
|
+
if (jsonStr.trim() === "[DONE]") {
|
|
14551
|
+
return;
|
|
14552
|
+
}
|
|
14553
|
+
try {
|
|
14554
|
+
const data = JSON.parse(jsonStr);
|
|
14555
|
+
yield data;
|
|
14556
|
+
} catch {}
|
|
14557
|
+
}
|
|
14558
|
+
}
|
|
14559
|
+
}
|
|
14560
|
+
if (buffer.startsWith("data: ")) {
|
|
14561
|
+
const jsonStr = buffer.slice(6);
|
|
14562
|
+
if (jsonStr.trim() !== "[DONE]") {
|
|
14563
|
+
try {
|
|
14564
|
+
const data = JSON.parse(jsonStr);
|
|
14565
|
+
yield data;
|
|
14566
|
+
} catch {}
|
|
14567
|
+
}
|
|
14568
|
+
}
|
|
14569
|
+
} finally {
|
|
14570
|
+
reader.releaseLock();
|
|
14571
|
+
}
|
|
14572
|
+
}
|
|
14573
|
+
|
|
14574
|
+
class DialecticStreamResponse {
|
|
14575
|
+
constructor(generator, evidenceSource) {
|
|
14576
|
+
this.chunks = [];
|
|
14577
|
+
this.consumed = false;
|
|
14578
|
+
this.generator = generator;
|
|
14579
|
+
this.evidenceSource = evidenceSource;
|
|
14580
|
+
}
|
|
14581
|
+
get evidence() {
|
|
14582
|
+
return this.evidenceSource?.() ?? null;
|
|
14583
|
+
}
|
|
14584
|
+
async* [Symbol.asyncIterator]() {
|
|
14585
|
+
if (this.consumed) {
|
|
14586
|
+
for (const chunk of this.chunks) {
|
|
14587
|
+
yield chunk;
|
|
14588
|
+
}
|
|
14589
|
+
return;
|
|
14590
|
+
}
|
|
14591
|
+
for await (const chunk of this.generator) {
|
|
14592
|
+
this.chunks.push(chunk);
|
|
14593
|
+
yield chunk;
|
|
14594
|
+
}
|
|
14595
|
+
this.consumed = true;
|
|
14596
|
+
}
|
|
14597
|
+
async getFinalResponse() {
|
|
14598
|
+
if (!this.consumed) {
|
|
14599
|
+
for await (const _ of this) {}
|
|
14600
|
+
}
|
|
14601
|
+
return this.chunks.join("");
|
|
14602
|
+
}
|
|
14603
|
+
async toArray() {
|
|
14604
|
+
if (!this.consumed) {
|
|
14605
|
+
for await (const _ of this) {}
|
|
14606
|
+
}
|
|
14607
|
+
return [...this.chunks];
|
|
14608
|
+
}
|
|
14609
|
+
}
|
|
14610
|
+
exports.DialecticStreamResponse = DialecticStreamResponse;
|
|
14611
|
+
function createDialecticStream(response) {
|
|
14612
|
+
let evidence = null;
|
|
14613
|
+
async function* streamContent() {
|
|
14614
|
+
for await (const chunk of parseSSE(response)) {
|
|
14615
|
+
if (chunk.done) {
|
|
14616
|
+
evidence = chunk.evidence ?? null;
|
|
14617
|
+
return;
|
|
14618
|
+
}
|
|
14619
|
+
const content = chunk.delta?.content;
|
|
14620
|
+
if (content) {
|
|
14621
|
+
yield content;
|
|
14622
|
+
}
|
|
14623
|
+
}
|
|
14624
|
+
}
|
|
14625
|
+
return new DialecticStreamResponse(streamContent(), () => evidence);
|
|
14626
|
+
}
|
|
14627
|
+
});
|
|
14628
|
+
|
|
14629
|
+
// node_modules/@honcho-ai/sdk/dist/message.js
|
|
14630
|
+
var require_message = __commonJS(function(exports) {
|
|
14631
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14632
|
+
exports.Message = undefined;
|
|
14633
|
+
|
|
14634
|
+
class Message {
|
|
14635
|
+
constructor(id, content, peerId, sessionId, workspaceId, metadata, createdAt, tokenCount) {
|
|
14636
|
+
this.id = id;
|
|
14637
|
+
this.content = content;
|
|
14638
|
+
this.peerId = peerId;
|
|
14639
|
+
this.sessionId = sessionId;
|
|
14640
|
+
this.workspaceId = workspaceId;
|
|
14641
|
+
this.metadata = metadata;
|
|
14642
|
+
this.createdAt = createdAt;
|
|
14643
|
+
this.tokenCount = tokenCount;
|
|
14644
|
+
}
|
|
14645
|
+
static fromApiResponse(data) {
|
|
14646
|
+
return new Message(data.id, data.content, data.peer_id, data.session_id, data.workspace_id, data.metadata, data.created_at, data.token_count);
|
|
14647
|
+
}
|
|
14648
|
+
toString() {
|
|
14649
|
+
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
14650
|
+
return `Message(id='${this.id}', peerId='${this.peerId}', content='${truncatedContent}')`;
|
|
14651
|
+
}
|
|
14652
|
+
}
|
|
14653
|
+
exports.Message = Message;
|
|
14654
|
+
});
|
|
14655
|
+
|
|
14656
|
+
// node_modules/@honcho-ai/sdk/dist/session_context.js
|
|
14657
|
+
var require_session_context = __commonJS(function(exports) {
|
|
14658
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14659
|
+
exports.SessionContext = exports.SessionSummaries = exports.Summary = undefined;
|
|
14660
|
+
var message_1 = require_message();
|
|
14661
|
+
|
|
14662
|
+
class Summary {
|
|
14663
|
+
constructor(data) {
|
|
14664
|
+
this.content = data.content;
|
|
14665
|
+
this.messageId = data.messageId;
|
|
14666
|
+
this.summaryType = data.summaryType;
|
|
14667
|
+
this.createdAt = data.createdAt;
|
|
14668
|
+
this.tokenCount = data.tokenCount;
|
|
14669
|
+
}
|
|
14670
|
+
static fromApiResponse(data) {
|
|
14671
|
+
return new Summary({
|
|
14672
|
+
content: data.content,
|
|
14673
|
+
messageId: data.message_id,
|
|
14674
|
+
summaryType: data.summary_type,
|
|
14354
14675
|
createdAt: data.created_at,
|
|
14355
14676
|
tokenCount: data.token_count
|
|
14356
14677
|
});
|
|
@@ -14506,12 +14827,18 @@ var require_session = __commonJS(function(exports) {
|
|
|
14506
14827
|
get createdAt() {
|
|
14507
14828
|
return this._createdAt;
|
|
14508
14829
|
}
|
|
14830
|
+
get uid() {
|
|
14831
|
+
return this._uid;
|
|
14832
|
+
}
|
|
14509
14833
|
get isActive() {
|
|
14510
14834
|
return this._isActive;
|
|
14511
14835
|
}
|
|
14836
|
+
get scopes() {
|
|
14837
|
+
return this._scopes;
|
|
14838
|
+
}
|
|
14512
14839
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
14513
14840
|
return;
|
|
14514
|
-
}, createdAt, isActive) {
|
|
14841
|
+
}, createdAt, isActive, uid, scopes) {
|
|
14515
14842
|
this.id = id;
|
|
14516
14843
|
this.workspaceId = workspaceId;
|
|
14517
14844
|
this._http = http;
|
|
@@ -14520,12 +14847,15 @@ var require_session = __commonJS(function(exports) {
|
|
|
14520
14847
|
this._ensureWorkspace = ensureWorkspace;
|
|
14521
14848
|
this._createdAt = createdAt;
|
|
14522
14849
|
this._isActive = isActive;
|
|
14850
|
+
this._uid = uid;
|
|
14851
|
+
this._scopes = scopes;
|
|
14523
14852
|
}
|
|
14524
14853
|
_applySessionResponse(session) {
|
|
14525
14854
|
this._metadata = session.metadata || {};
|
|
14526
14855
|
this._configuration = (0, validation_1.sessionConfigFromApi)(session.configuration) || {};
|
|
14527
14856
|
this._createdAt = session.created_at;
|
|
14528
14857
|
this._isActive = session.is_active;
|
|
14858
|
+
this._uid = session.uid;
|
|
14529
14859
|
}
|
|
14530
14860
|
async _getOrCreate(params) {
|
|
14531
14861
|
await this._ensureWorkspace();
|
|
@@ -14649,7 +14979,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14649
14979
|
}
|
|
14650
14980
|
async peers() {
|
|
14651
14981
|
const peersPage = await this._listPeers();
|
|
14652
|
-
return peersPage.items.map((peer) => new peer_1.Peer(peer.id, this.workspaceId, this._http, peer.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peer.configuration) ?? undefined, () => this._ensureWorkspace(), peer.created_at));
|
|
14982
|
+
return peersPage.items.map((peer) => new peer_1.Peer(peer.id, this.workspaceId, this._http, peer.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peer.configuration) ?? undefined, () => this._ensureWorkspace(), peer.created_at, peer.uid));
|
|
14653
14983
|
}
|
|
14654
14984
|
async getPeerConfiguration(peer) {
|
|
14655
14985
|
const peerId = typeof peer === "string" ? peer : peer.id;
|
|
@@ -14733,7 +15063,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14733
15063
|
}
|
|
14734
15064
|
async clone(messageId) {
|
|
14735
15065
|
const clonedSessionData = await this._clone(messageId ? { message_id: messageId } : undefined);
|
|
14736
|
-
return new Session(clonedSessionData.id, this.workspaceId, this._http, clonedSessionData.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(clonedSessionData.configuration) ?? undefined, () => this._ensureWorkspace(), clonedSessionData.created_at, clonedSessionData.is_active);
|
|
15066
|
+
return new Session(clonedSessionData.id, this.workspaceId, this._http, clonedSessionData.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(clonedSessionData.configuration) ?? undefined, () => this._ensureWorkspace(), clonedSessionData.created_at, clonedSessionData.is_active, clonedSessionData.uid);
|
|
14737
15067
|
}
|
|
14738
15068
|
async context(options) {
|
|
14739
15069
|
const opts = options || {};
|
|
@@ -14745,6 +15075,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
14745
15075
|
tokens: opts.tokens,
|
|
14746
15076
|
peerTarget: peerTargetId,
|
|
14747
15077
|
peerPerspective: peerPerspectiveId,
|
|
15078
|
+
scope: opts.scope !== undefined ? (0, utils_1.resolveId)(opts.scope) : undefined,
|
|
15079
|
+
sessions: opts.sessions,
|
|
14748
15080
|
limitToSession: opts.limitToSession,
|
|
14749
15081
|
representationOptions: opts.representationOptions ? {
|
|
14750
15082
|
...opts.representationOptions,
|
|
@@ -14757,6 +15089,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
14757
15089
|
search_query: searchQuery,
|
|
14758
15090
|
peer_target: contextParams.peerTarget,
|
|
14759
15091
|
peer_perspective: contextParams.peerPerspective,
|
|
15092
|
+
scope: contextParams.scope,
|
|
15093
|
+
sessions: contextParams.sessions,
|
|
14760
15094
|
limit_to_session: contextParams.limitToSession,
|
|
14761
15095
|
search_top_k: contextParams.representationOptions?.searchTopK,
|
|
14762
15096
|
search_max_distance: contextParams.representationOptions?.searchMaxDistance,
|
|
@@ -14873,6 +15207,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14873
15207
|
var require_peer = __commonJS(function(exports) {
|
|
14874
15208
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14875
15209
|
exports.Peer = exports.PeerContext = undefined;
|
|
15210
|
+
var zod_1 = require_zod();
|
|
14876
15211
|
var api_version_1 = require_api_version();
|
|
14877
15212
|
var conclusions_1 = require_conclusions();
|
|
14878
15213
|
var streaming_1 = require_streaming();
|
|
@@ -14907,9 +15242,12 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14907
15242
|
get createdAt() {
|
|
14908
15243
|
return this._createdAt;
|
|
14909
15244
|
}
|
|
15245
|
+
get uid() {
|
|
15246
|
+
return this._uid;
|
|
15247
|
+
}
|
|
14910
15248
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
14911
15249
|
return;
|
|
14912
|
-
}, createdAt) {
|
|
15250
|
+
}, createdAt, uid) {
|
|
14913
15251
|
this.id = id;
|
|
14914
15252
|
this.workspaceId = workspaceId;
|
|
14915
15253
|
this._http = http;
|
|
@@ -14917,6 +15255,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14917
15255
|
this._configuration = configuration;
|
|
14918
15256
|
this._ensureWorkspace = ensureWorkspace;
|
|
14919
15257
|
this._createdAt = createdAt;
|
|
15258
|
+
this._uid = uid;
|
|
14920
15259
|
}
|
|
14921
15260
|
async _getOrCreate(params) {
|
|
14922
15261
|
await this._ensureWorkspace();
|
|
@@ -14937,6 +15276,15 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14937
15276
|
}
|
|
14938
15277
|
});
|
|
14939
15278
|
}
|
|
15279
|
+
static toResponseFormatSchema(responseFormat) {
|
|
15280
|
+
if (!responseFormat) {
|
|
15281
|
+
return;
|
|
15282
|
+
}
|
|
15283
|
+
if (responseFormat instanceof zod_1.ZodType) {
|
|
15284
|
+
return zod_1.z.toJSONSchema(responseFormat);
|
|
15285
|
+
}
|
|
15286
|
+
return responseFormat;
|
|
15287
|
+
}
|
|
14940
15288
|
async _chat(params) {
|
|
14941
15289
|
await this._ensureWorkspace();
|
|
14942
15290
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${this.id}/chat`, { body: params });
|
|
@@ -14978,19 +15326,28 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14978
15326
|
query,
|
|
14979
15327
|
target: targetId,
|
|
14980
15328
|
session: resolvedSessionId,
|
|
14981
|
-
|
|
15329
|
+
scope: options?.scope,
|
|
15330
|
+
sessions: options?.sessions,
|
|
15331
|
+
reasoningLevel: options?.reasoningLevel,
|
|
15332
|
+
responseFormat: options?.responseFormat,
|
|
15333
|
+
includeEvidence: options?.includeEvidence
|
|
14982
15334
|
});
|
|
15335
|
+
const zodSchema = options?.responseFormat instanceof zod_1.ZodType ? options.responseFormat : undefined;
|
|
14983
15336
|
const response = await this._chat({
|
|
14984
15337
|
query: chatParams.query,
|
|
14985
15338
|
stream: false,
|
|
14986
15339
|
target: chatParams.target,
|
|
14987
15340
|
session_id: chatParams.session,
|
|
14988
|
-
|
|
15341
|
+
...(0, validation_1.scopeRecallFields)(chatParams),
|
|
15342
|
+
reasoning_level: chatParams.reasoningLevel,
|
|
15343
|
+
response_format: Peer.toResponseFormatSchema(options?.responseFormat),
|
|
15344
|
+
include_evidence: chatParams.includeEvidence ? true : undefined
|
|
14989
15345
|
});
|
|
14990
|
-
|
|
14991
|
-
|
|
15346
|
+
const content = response.content ? zodSchema ? zodSchema.parse(JSON.parse(response.content)) : response.content : null;
|
|
15347
|
+
if (!chatParams.includeEvidence) {
|
|
15348
|
+
return content;
|
|
14992
15349
|
}
|
|
14993
|
-
return response.
|
|
15350
|
+
return { content, evidence: response.evidence ?? null };
|
|
14994
15351
|
}
|
|
14995
15352
|
async chatStream(query, options) {
|
|
14996
15353
|
const targetId = options?.target ? typeof options.target === "string" ? options.target : options.target.id : undefined;
|
|
@@ -14999,13 +15356,20 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14999
15356
|
query,
|
|
15000
15357
|
target: targetId,
|
|
15001
15358
|
session: resolvedSessionId,
|
|
15002
|
-
|
|
15359
|
+
scope: options?.scope,
|
|
15360
|
+
sessions: options?.sessions,
|
|
15361
|
+
reasoningLevel: options?.reasoningLevel,
|
|
15362
|
+
responseFormat: options?.responseFormat,
|
|
15363
|
+
includeEvidence: options?.includeEvidence
|
|
15003
15364
|
});
|
|
15004
15365
|
const response = await this._chatStream({
|
|
15005
15366
|
query: chatParams.query,
|
|
15006
15367
|
target: chatParams.target,
|
|
15007
15368
|
session_id: chatParams.session,
|
|
15008
|
-
|
|
15369
|
+
...(0, validation_1.scopeRecallFields)(chatParams),
|
|
15370
|
+
reasoning_level: chatParams.reasoningLevel,
|
|
15371
|
+
response_format: Peer.toResponseFormatSchema(options?.responseFormat),
|
|
15372
|
+
include_evidence: chatParams.includeEvidence ? true : undefined
|
|
15009
15373
|
});
|
|
15010
15374
|
return (0, streaming_1.createDialecticStream)(response);
|
|
15011
15375
|
}
|
|
@@ -15032,7 +15396,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15032
15396
|
reverse
|
|
15033
15397
|
});
|
|
15034
15398
|
};
|
|
15035
|
-
return new pagination_1.Page(sessionsPage, (session) => new session_1.Session(session.id, this.workspaceId, this._http, session.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(session.configuration) ?? undefined, () => this._ensureWorkspace(), session.created_at, session.is_active), fetchNextPage);
|
|
15399
|
+
return new pagination_1.Page(sessionsPage, (session) => new session_1.Session(session.id, this.workspaceId, this._http, session.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(session.configuration) ?? undefined, () => this._ensureWorkspace(), session.created_at, session.is_active, session.uid), fetchNextPage);
|
|
15036
15400
|
}
|
|
15037
15401
|
message(content, options) {
|
|
15038
15402
|
const validatedContent = validation_1.MessageContentSchema.parse(content);
|
|
@@ -15051,6 +15415,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15051
15415
|
const peer = await this._getOrCreate({ id: this.id });
|
|
15052
15416
|
this._metadata = peer.metadata || {};
|
|
15053
15417
|
this._createdAt = peer.created_at;
|
|
15418
|
+
this._uid = peer.uid;
|
|
15054
15419
|
return this._metadata;
|
|
15055
15420
|
}
|
|
15056
15421
|
async setMetadata(metadata) {
|
|
@@ -15062,6 +15427,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15062
15427
|
const peer = await this._getOrCreate({ id: this.id });
|
|
15063
15428
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
15064
15429
|
this._createdAt = peer.created_at;
|
|
15430
|
+
this._uid = peer.uid;
|
|
15065
15431
|
return this._configuration;
|
|
15066
15432
|
}
|
|
15067
15433
|
async setConfiguration(configuration) {
|
|
@@ -15074,6 +15440,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15074
15440
|
this._metadata = peer.metadata || {};
|
|
15075
15441
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
15076
15442
|
this._createdAt = peer.created_at;
|
|
15443
|
+
this._uid = peer.uid;
|
|
15077
15444
|
}
|
|
15078
15445
|
async search(query, options) {
|
|
15079
15446
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
@@ -15109,6 +15476,8 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15109
15476
|
const searchQuery = (0, validation_1.normalizeSearchQuery)(options?.searchQuery);
|
|
15110
15477
|
const getRepresentationParams = validation_1.PeerGetRepresentationParamsSchema.parse({
|
|
15111
15478
|
session: options?.session,
|
|
15479
|
+
scope: options?.scope,
|
|
15480
|
+
sessions: options?.sessions,
|
|
15112
15481
|
target: options?.target,
|
|
15113
15482
|
options: {
|
|
15114
15483
|
searchQuery,
|
|
@@ -15122,6 +15491,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15122
15491
|
const targetId = getRepresentationParams.target ? typeof getRepresentationParams.target === "string" ? getRepresentationParams.target : getRepresentationParams.target.id : undefined;
|
|
15123
15492
|
const response = await this._getRepresentation({
|
|
15124
15493
|
session_id: sessionId,
|
|
15494
|
+
...(0, validation_1.scopeRecallFields)(getRepresentationParams),
|
|
15125
15495
|
target: targetId,
|
|
15126
15496
|
search_query: searchQuery,
|
|
15127
15497
|
search_top_k: getRepresentationParams.options?.searchTopK,
|
|
@@ -15152,11 +15522,11 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15152
15522
|
return PeerContext.fromApiResponse(response);
|
|
15153
15523
|
}
|
|
15154
15524
|
get conclusions() {
|
|
15155
|
-
return new conclusions_1.
|
|
15525
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, this.id, () => this._ensureWorkspace());
|
|
15156
15526
|
}
|
|
15157
15527
|
conclusionsOf(target) {
|
|
15158
15528
|
const targetId = typeof target === "string" ? target : target.id;
|
|
15159
|
-
return new conclusions_1.
|
|
15529
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, targetId, () => this._ensureWorkspace());
|
|
15160
15530
|
}
|
|
15161
15531
|
toString() {
|
|
15162
15532
|
return `Peer(id='${this.id}')`;
|
|
@@ -15165,15 +15535,125 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15165
15535
|
exports.Peer = Peer;
|
|
15166
15536
|
});
|
|
15167
15537
|
|
|
15538
|
+
// node_modules/@honcho-ai/sdk/dist/scope.js
|
|
15539
|
+
var require_scope = __commonJS(function(exports) {
|
|
15540
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15541
|
+
exports.Scope = undefined;
|
|
15542
|
+
var api_version_1 = require_api_version();
|
|
15543
|
+
var pagination_1 = require_pagination();
|
|
15544
|
+
var session_1 = require_session();
|
|
15545
|
+
var utils_1 = require_utils();
|
|
15546
|
+
var validation_1 = require_validation();
|
|
15547
|
+
|
|
15548
|
+
class Scope {
|
|
15549
|
+
get metadata() {
|
|
15550
|
+
return this._metadata;
|
|
15551
|
+
}
|
|
15552
|
+
get createdAt() {
|
|
15553
|
+
return this._createdAt;
|
|
15554
|
+
}
|
|
15555
|
+
get sessionCount() {
|
|
15556
|
+
return this._sessionCount;
|
|
15557
|
+
}
|
|
15558
|
+
constructor(id, workspaceId, http, metadata, ensureWorkspace = async () => {
|
|
15559
|
+
return;
|
|
15560
|
+
}, createdAt, sessionCount) {
|
|
15561
|
+
this.id = id;
|
|
15562
|
+
this.workspaceId = workspaceId;
|
|
15563
|
+
this._http = http;
|
|
15564
|
+
this._metadata = metadata;
|
|
15565
|
+
this._ensureWorkspace = ensureWorkspace;
|
|
15566
|
+
this._createdAt = createdAt;
|
|
15567
|
+
this._sessionCount = sessionCount;
|
|
15568
|
+
}
|
|
15569
|
+
get _basePath() {
|
|
15570
|
+
return `/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/scopes/${this.id}`;
|
|
15571
|
+
}
|
|
15572
|
+
async _addSessions(sessionIds) {
|
|
15573
|
+
await this._ensureWorkspace();
|
|
15574
|
+
await this._http.post(`${this._basePath}/sessions`, {
|
|
15575
|
+
body: { session_ids: sessionIds }
|
|
15576
|
+
});
|
|
15577
|
+
}
|
|
15578
|
+
async _removeSessions(sessionIds) {
|
|
15579
|
+
await this._ensureWorkspace();
|
|
15580
|
+
await this._http.post(`${this._basePath}/sessions/remove`, {
|
|
15581
|
+
body: { session_ids: sessionIds }
|
|
15582
|
+
});
|
|
15583
|
+
}
|
|
15584
|
+
async _removeSession(sessionId) {
|
|
15585
|
+
await this._ensureWorkspace();
|
|
15586
|
+
await this._http.delete(`${this._basePath}/sessions/${sessionId}`);
|
|
15587
|
+
}
|
|
15588
|
+
async _listSessions(params) {
|
|
15589
|
+
await this._ensureWorkspace();
|
|
15590
|
+
return this._http.post(`${this._basePath}/sessions/list`, {
|
|
15591
|
+
query: {
|
|
15592
|
+
page: params?.page,
|
|
15593
|
+
size: params?.size,
|
|
15594
|
+
reverse: params?.reverse ? "true" : undefined
|
|
15595
|
+
}
|
|
15596
|
+
});
|
|
15597
|
+
}
|
|
15598
|
+
async _getStatus() {
|
|
15599
|
+
await this._ensureWorkspace();
|
|
15600
|
+
return this._http.get(`${this._basePath}/status`);
|
|
15601
|
+
}
|
|
15602
|
+
async addSessions(sessions) {
|
|
15603
|
+
const sessionIds = validation_1.ScopeSessionsSchema.parse(sessions.map(utils_1.resolveId));
|
|
15604
|
+
await this._addSessions(sessionIds);
|
|
15605
|
+
}
|
|
15606
|
+
async removeSessions(sessions) {
|
|
15607
|
+
const sessionIds = validation_1.ScopeSessionsSchema.parse(sessions.map(utils_1.resolveId));
|
|
15608
|
+
await this._removeSessions(sessionIds);
|
|
15609
|
+
}
|
|
15610
|
+
async removeSession(session) {
|
|
15611
|
+
await this._removeSession(validation_1.SessionIdSchema.parse((0, utils_1.resolveId)(session)));
|
|
15612
|
+
}
|
|
15613
|
+
async sessions(options) {
|
|
15614
|
+
const reverse = options?.reverse;
|
|
15615
|
+
const sessionsPage = await this._listSessions({
|
|
15616
|
+
page: options?.page,
|
|
15617
|
+
size: options?.size,
|
|
15618
|
+
reverse
|
|
15619
|
+
});
|
|
15620
|
+
const fetchNextPage = async (page, size) => {
|
|
15621
|
+
return this._listSessions({ page, size, reverse });
|
|
15622
|
+
};
|
|
15623
|
+
return new pagination_1.Page(sessionsPage, (session) => new session_1.Session(session.id, this.workspaceId, this._http, session.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(session.configuration) ?? undefined, () => this._ensureWorkspace(), session.created_at, session.is_active, session.uid), fetchNextPage);
|
|
15624
|
+
}
|
|
15625
|
+
async status() {
|
|
15626
|
+
const response = await this._getStatus();
|
|
15627
|
+
return {
|
|
15628
|
+
backfillStatus: Object.fromEntries(Object.entries(response.backfill_status ?? {}).map(([sessionId, job]) => [
|
|
15629
|
+
sessionId,
|
|
15630
|
+
{
|
|
15631
|
+
state: job.state,
|
|
15632
|
+
updatedAt: job.updated_at,
|
|
15633
|
+
docsCopied: job.docs_copied
|
|
15634
|
+
}
|
|
15635
|
+
]))
|
|
15636
|
+
};
|
|
15637
|
+
}
|
|
15638
|
+
toString() {
|
|
15639
|
+
return `Scope(id='${this.id}', workspaceId='${this.workspaceId}')`;
|
|
15640
|
+
}
|
|
15641
|
+
}
|
|
15642
|
+
exports.Scope = Scope;
|
|
15643
|
+
});
|
|
15644
|
+
|
|
15168
15645
|
// node_modules/@honcho-ai/sdk/dist/client.js
|
|
15169
15646
|
var require_client2 = __commonJS(function(exports) {
|
|
15170
15647
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15171
15648
|
exports.Honcho = undefined;
|
|
15172
15649
|
var api_version_1 = require_api_version();
|
|
15650
|
+
var conclusions_1 = require_conclusions();
|
|
15173
15651
|
var client_1 = require_client();
|
|
15652
|
+
var streaming_1 = require_streaming();
|
|
15174
15653
|
var message_1 = require_message();
|
|
15175
15654
|
var pagination_1 = require_pagination();
|
|
15176
15655
|
var peer_1 = require_peer();
|
|
15656
|
+
var scope_1 = require_scope();
|
|
15177
15657
|
var session_1 = require_session();
|
|
15178
15658
|
var utils_1 = require_utils();
|
|
15179
15659
|
var validation_1 = require_validation();
|
|
@@ -15186,9 +15666,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15186
15666
|
get configuration() {
|
|
15187
15667
|
return this._configuration;
|
|
15188
15668
|
}
|
|
15669
|
+
get uid() {
|
|
15670
|
+
return this._uid;
|
|
15671
|
+
}
|
|
15189
15672
|
get http() {
|
|
15190
15673
|
return this._http;
|
|
15191
15674
|
}
|
|
15675
|
+
get conclusions() {
|
|
15676
|
+
return new conclusions_1.WorkspaceConclusions(this._http, this.workspaceId, () => this._ensureWorkspace());
|
|
15677
|
+
}
|
|
15192
15678
|
get baseURL() {
|
|
15193
15679
|
return this._http.baseURL;
|
|
15194
15680
|
}
|
|
@@ -15211,13 +15697,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15211
15697
|
});
|
|
15212
15698
|
}
|
|
15213
15699
|
async _getOrCreateWorkspace(id, params) {
|
|
15214
|
-
|
|
15700
|
+
const workspace = await this._http.post(`/${api_version_1.API_VERSION}/workspaces`, {
|
|
15215
15701
|
body: {
|
|
15216
15702
|
id,
|
|
15217
15703
|
metadata: params?.metadata,
|
|
15218
15704
|
configuration: (0, validation_1.workspaceConfigToApi)(params?.configuration)
|
|
15219
15705
|
}
|
|
15220
15706
|
});
|
|
15707
|
+
this._uid = workspace.uid;
|
|
15708
|
+
return workspace;
|
|
15221
15709
|
}
|
|
15222
15710
|
async _ensureWorkspace() {
|
|
15223
15711
|
if (!this._workspaceReady) {
|
|
@@ -15245,7 +15733,8 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15245
15733
|
},
|
|
15246
15734
|
query: {
|
|
15247
15735
|
page: params?.page,
|
|
15248
|
-
size: params?.size
|
|
15736
|
+
size: params?.size,
|
|
15737
|
+
reverse: params?.reverse ? "true" : undefined
|
|
15249
15738
|
}
|
|
15250
15739
|
});
|
|
15251
15740
|
}
|
|
@@ -15275,13 +15764,35 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15275
15764
|
async _getOrCreatePeer(workspaceId, params) {
|
|
15276
15765
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/peers`, { body: params });
|
|
15277
15766
|
}
|
|
15767
|
+
async _getOrCreateScope(workspaceId, params) {
|
|
15768
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes`, { body: params });
|
|
15769
|
+
}
|
|
15770
|
+
async _getScope(workspaceId, scopeId) {
|
|
15771
|
+
return this._http.get(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes/${scopeId}`);
|
|
15772
|
+
}
|
|
15773
|
+
async _listScopes(workspaceId, params) {
|
|
15774
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes/list`, {
|
|
15775
|
+
body: { filters: params?.filters },
|
|
15776
|
+
query: {
|
|
15777
|
+
page: params?.page,
|
|
15778
|
+
size: params?.size,
|
|
15779
|
+
reverse: params?.reverse ? "true" : undefined,
|
|
15780
|
+
include_session_count: params?.includeSessionCount ? "true" : undefined
|
|
15781
|
+
}
|
|
15782
|
+
});
|
|
15783
|
+
}
|
|
15278
15784
|
async _listSessions(workspaceId, params) {
|
|
15279
15785
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/sessions/list`, {
|
|
15280
|
-
body: {
|
|
15786
|
+
body: {
|
|
15787
|
+
filters: params?.filters,
|
|
15788
|
+
scope: params?.scope,
|
|
15789
|
+
in_no_scope: params?.inNoScope ? true : undefined
|
|
15790
|
+
},
|
|
15281
15791
|
query: {
|
|
15282
15792
|
page: params?.page,
|
|
15283
15793
|
size: params?.size,
|
|
15284
|
-
reverse: params?.reverse ? "true" : undefined
|
|
15794
|
+
reverse: params?.reverse ? "true" : undefined,
|
|
15795
|
+
include_scopes: params?.includeScopes ? "true" : undefined
|
|
15285
15796
|
}
|
|
15286
15797
|
});
|
|
15287
15798
|
}
|
|
@@ -15290,7 +15801,22 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15290
15801
|
body: {
|
|
15291
15802
|
id: params.id,
|
|
15292
15803
|
metadata: params.metadata,
|
|
15293
|
-
configuration: (0, validation_1.sessionConfigToApi)(params.configuration)
|
|
15804
|
+
configuration: (0, validation_1.sessionConfigToApi)(params.configuration),
|
|
15805
|
+
peers: params.peers,
|
|
15806
|
+
scopes: params.scopes
|
|
15807
|
+
}
|
|
15808
|
+
});
|
|
15809
|
+
}
|
|
15810
|
+
async _workspaceChat(workspaceId, params) {
|
|
15811
|
+
await this._ensureWorkspace();
|
|
15812
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/chat`, { body: params });
|
|
15813
|
+
}
|
|
15814
|
+
async _workspaceChatStream(workspaceId, params) {
|
|
15815
|
+
await this._ensureWorkspace();
|
|
15816
|
+
return this._http.stream("POST", `/${api_version_1.API_VERSION}/workspaces/${workspaceId}/chat`, {
|
|
15817
|
+
body: {
|
|
15818
|
+
...params,
|
|
15819
|
+
stream: true
|
|
15294
15820
|
}
|
|
15295
15821
|
});
|
|
15296
15822
|
}
|
|
@@ -15304,7 +15830,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15304
15830
|
configuration: (0, validation_1.peerConfigToApi)(validatedConfiguration),
|
|
15305
15831
|
metadata: validatedMetadata
|
|
15306
15832
|
});
|
|
15307
|
-
return new peer_1.Peer(validatedId, this.workspaceId, this._http, peerData.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peerData.configuration) ?? undefined, () => this._ensureWorkspace(), peerData.created_at);
|
|
15833
|
+
return new peer_1.Peer(validatedId, this.workspaceId, this._http, peerData.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peerData.configuration) ?? undefined, () => this._ensureWorkspace(), peerData.created_at, peerData.uid);
|
|
15308
15834
|
}
|
|
15309
15835
|
async peers(options) {
|
|
15310
15836
|
await this._ensureWorkspace();
|
|
@@ -15330,19 +15856,55 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15330
15856
|
reverse
|
|
15331
15857
|
});
|
|
15332
15858
|
};
|
|
15333
|
-
return new pagination_1.Page(peersPage, (peer) => new peer_1.Peer(peer.id, this.workspaceId, this._http, peer.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peer.configuration) ?? undefined, () => this._ensureWorkspace(), peer.created_at), fetchNextPage);
|
|
15859
|
+
return new pagination_1.Page(peersPage, (peer) => new peer_1.Peer(peer.id, this.workspaceId, this._http, peer.metadata ?? undefined, (0, validation_1.peerConfigFromApi)(peer.configuration) ?? undefined, () => this._ensureWorkspace(), peer.created_at, peer.uid), fetchNextPage);
|
|
15334
15860
|
}
|
|
15335
15861
|
async session(id, options) {
|
|
15336
15862
|
await this._ensureWorkspace();
|
|
15337
15863
|
const validatedId = validation_1.SessionIdSchema.parse(id);
|
|
15338
15864
|
const validatedMetadata = options?.metadata ? validation_1.SessionMetadataSchema.parse(options.metadata) : undefined;
|
|
15339
15865
|
const validatedConfiguration = options?.configuration ? validation_1.SessionConfigSchema.parse(options.configuration) : undefined;
|
|
15866
|
+
const validatedPeers = options?.peers !== undefined ? validation_1.PeerAdditionToApiSchema.parse(options.peers) : undefined;
|
|
15867
|
+
const validatedScopes = options?.scopes !== undefined ? validation_1.SessionScopesSchema.parse(options.scopes.map(utils_1.resolveId)) : undefined;
|
|
15340
15868
|
const sessionData = await this._getOrCreateSession(this.workspaceId, {
|
|
15341
15869
|
id: validatedId,
|
|
15342
15870
|
configuration: validatedConfiguration,
|
|
15343
|
-
metadata: validatedMetadata
|
|
15871
|
+
metadata: validatedMetadata,
|
|
15872
|
+
peers: validatedPeers,
|
|
15873
|
+
scopes: validatedScopes
|
|
15874
|
+
});
|
|
15875
|
+
return new session_1.Session(validatedId, this.workspaceId, this._http, sessionData.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(sessionData.configuration) ?? undefined, () => this._ensureWorkspace(), sessionData.created_at, sessionData.is_active, sessionData.uid);
|
|
15876
|
+
}
|
|
15877
|
+
async scope(id, options) {
|
|
15878
|
+
await this._ensureWorkspace();
|
|
15879
|
+
const validatedId = validation_1.ScopeIdSchema.parse(id);
|
|
15880
|
+
const scopeData = await this._getOrCreateScope(this.workspaceId, {
|
|
15881
|
+
id: validatedId,
|
|
15882
|
+
metadata: options?.metadata
|
|
15883
|
+
});
|
|
15884
|
+
return new scope_1.Scope(validatedId, this.workspaceId, this._http, scopeData.metadata ?? undefined, () => this._ensureWorkspace(), scopeData.created_at);
|
|
15885
|
+
}
|
|
15886
|
+
async getScope(id) {
|
|
15887
|
+
await this._ensureWorkspace();
|
|
15888
|
+
const validatedId = validation_1.ScopeIdSchema.parse(id);
|
|
15889
|
+
const scopeData = await this._getScope(this.workspaceId, validatedId);
|
|
15890
|
+
return new scope_1.Scope(validatedId, this.workspaceId, this._http, scopeData.metadata ?? undefined, () => this._ensureWorkspace(), scopeData.created_at);
|
|
15891
|
+
}
|
|
15892
|
+
async scopes(options) {
|
|
15893
|
+
await this._ensureWorkspace();
|
|
15894
|
+
const listOptions = {
|
|
15895
|
+
filters: options?.filters ? validation_1.FilterSchema.parse(options.filters) : undefined,
|
|
15896
|
+
reverse: options?.reverse,
|
|
15897
|
+
includeSessionCount: options?.includeSessionCount
|
|
15898
|
+
};
|
|
15899
|
+
const scopesPage = await this._listScopes(this.workspaceId, {
|
|
15900
|
+
...listOptions,
|
|
15901
|
+
page: options?.page,
|
|
15902
|
+
size: options?.size
|
|
15344
15903
|
});
|
|
15345
|
-
|
|
15904
|
+
const fetchNextPage = async (page, size) => {
|
|
15905
|
+
return this._listScopes(this.workspaceId, { ...listOptions, page, size });
|
|
15906
|
+
};
|
|
15907
|
+
return new pagination_1.Page(scopesPage, (scope) => new scope_1.Scope(scope.id, this.workspaceId, this._http, scope.metadata ?? undefined, () => this._ensureWorkspace(), scope.created_at, scope.session_count), fetchNextPage);
|
|
15346
15908
|
}
|
|
15347
15909
|
async sessions(options) {
|
|
15348
15910
|
await this._ensureWorkspace();
|
|
@@ -15350,25 +15912,32 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15350
15912
|
"filters",
|
|
15351
15913
|
"page",
|
|
15352
15914
|
"size",
|
|
15353
|
-
"reverse"
|
|
15915
|
+
"reverse",
|
|
15916
|
+
"scope",
|
|
15917
|
+
"inNoScope",
|
|
15918
|
+
"includeScopes"
|
|
15354
15919
|
]);
|
|
15355
15920
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
15356
|
-
const
|
|
15357
|
-
const sessionsPage = await this._listSessions(this.workspaceId, {
|
|
15921
|
+
const listOptions = {
|
|
15358
15922
|
filters: validatedFilter,
|
|
15923
|
+
reverse: normalizedOptions.reverse,
|
|
15924
|
+
scope: normalizedOptions.scope,
|
|
15925
|
+
inNoScope: normalizedOptions.inNoScope,
|
|
15926
|
+
includeScopes: normalizedOptions.includeScopes
|
|
15927
|
+
};
|
|
15928
|
+
const sessionsPage = await this._listSessions(this.workspaceId, {
|
|
15929
|
+
...listOptions,
|
|
15359
15930
|
page: normalizedOptions.page,
|
|
15360
|
-
size: normalizedOptions.size
|
|
15361
|
-
reverse
|
|
15931
|
+
size: normalizedOptions.size
|
|
15362
15932
|
});
|
|
15363
15933
|
const fetchNextPage = async (page, size) => {
|
|
15364
15934
|
return this._listSessions(this.workspaceId, {
|
|
15365
|
-
|
|
15935
|
+
...listOptions,
|
|
15366
15936
|
page,
|
|
15367
|
-
size
|
|
15368
|
-
reverse
|
|
15937
|
+
size
|
|
15369
15938
|
});
|
|
15370
15939
|
};
|
|
15371
|
-
return new pagination_1.Page(sessionsPage, (session) => new session_1.Session(session.id, this.workspaceId, this._http, session.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(session.configuration) ?? undefined, () => this._ensureWorkspace(), session.created_at, session.is_active), fetchNextPage);
|
|
15940
|
+
return new pagination_1.Page(sessionsPage, (session) => new session_1.Session(session.id, this.workspaceId, this._http, session.metadata ?? undefined, (0, validation_1.sessionConfigFromApi)(session.configuration) ?? undefined, () => this._ensureWorkspace(), session.created_at, session.is_active, session.uid, session.scopes), fetchNextPage);
|
|
15372
15941
|
}
|
|
15373
15942
|
async getMetadata() {
|
|
15374
15943
|
await this._ensureWorkspace();
|
|
@@ -15408,19 +15977,23 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15408
15977
|
const normalizedOptions = (0, validation_1.normalizeListOptions)(options, [
|
|
15409
15978
|
"filters",
|
|
15410
15979
|
"page",
|
|
15411
|
-
"size"
|
|
15980
|
+
"size",
|
|
15981
|
+
"reverse"
|
|
15412
15982
|
]);
|
|
15413
15983
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
15984
|
+
const reverse = normalizedOptions.reverse;
|
|
15414
15985
|
const workspacesPage = await this._listWorkspaces({
|
|
15415
15986
|
filters: validatedFilter,
|
|
15416
15987
|
page: normalizedOptions.page,
|
|
15417
|
-
size: normalizedOptions.size
|
|
15988
|
+
size: normalizedOptions.size,
|
|
15989
|
+
reverse
|
|
15418
15990
|
});
|
|
15419
15991
|
const fetchNextPage = async (page, size) => {
|
|
15420
15992
|
return this._listWorkspaces({
|
|
15421
15993
|
filters: validatedFilter,
|
|
15422
15994
|
page,
|
|
15423
|
-
size
|
|
15995
|
+
size,
|
|
15996
|
+
reverse
|
|
15424
15997
|
});
|
|
15425
15998
|
};
|
|
15426
15999
|
return new pagination_1.Page(workspacesPage, (workspace) => workspace.id, fetchNextPage);
|
|
@@ -15432,14 +16005,47 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15432
16005
|
await this._ensureWorkspace();
|
|
15433
16006
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
15434
16007
|
const validatedFilters = options?.filters ? validation_1.FilterSchema.parse(options.filters) : undefined;
|
|
16008
|
+
const validatedScope = options?.scope !== undefined ? validation_1.ScopeIdSchema.parse((0, utils_1.resolveId)(options.scope)) : undefined;
|
|
15435
16009
|
const validatedLimit = options?.limit ? validation_1.LimitSchema.parse(options.limit) : undefined;
|
|
15436
16010
|
const response = await this._searchWorkspace(this.workspaceId, {
|
|
15437
16011
|
query: validatedQuery,
|
|
15438
16012
|
filters: validatedFilters,
|
|
16013
|
+
scope: validatedScope,
|
|
15439
16014
|
limit: validatedLimit
|
|
15440
16015
|
});
|
|
15441
16016
|
return response.map(message_1.Message.fromApiResponse);
|
|
15442
16017
|
}
|
|
16018
|
+
async chat(query, options) {
|
|
16019
|
+
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
16020
|
+
const resolvedSessionId = options?.session ? (0, utils_1.resolveId)(options.session) : undefined;
|
|
16021
|
+
const response = await this._workspaceChat(this.workspaceId, {
|
|
16022
|
+
query: validatedQuery,
|
|
16023
|
+
stream: false,
|
|
16024
|
+
session_id: resolvedSessionId,
|
|
16025
|
+
reasoning_level: options?.reasoningLevel,
|
|
16026
|
+
response_format: options?.responseFormat,
|
|
16027
|
+
scope: options?.scope,
|
|
16028
|
+
include_evidence: options?.includeEvidence ? true : undefined
|
|
16029
|
+
});
|
|
16030
|
+
const content = response.content || null;
|
|
16031
|
+
if (!options?.includeEvidence) {
|
|
16032
|
+
return content;
|
|
16033
|
+
}
|
|
16034
|
+
return { content, evidence: response.evidence ?? null };
|
|
16035
|
+
}
|
|
16036
|
+
async chatStream(query, options) {
|
|
16037
|
+
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
16038
|
+
const resolvedSessionId = options?.session ? (0, utils_1.resolveId)(options.session) : undefined;
|
|
16039
|
+
const response = await this._workspaceChatStream(this.workspaceId, {
|
|
16040
|
+
query: validatedQuery,
|
|
16041
|
+
session_id: resolvedSessionId,
|
|
16042
|
+
reasoning_level: options?.reasoningLevel,
|
|
16043
|
+
response_format: options?.responseFormat,
|
|
16044
|
+
scope: options?.scope,
|
|
16045
|
+
include_evidence: options?.includeEvidence ? true : undefined
|
|
16046
|
+
});
|
|
16047
|
+
return (0, streaming_1.createDialecticStream)(response);
|
|
16048
|
+
}
|
|
15443
16049
|
async queueStatus(options) {
|
|
15444
16050
|
await this._ensureWorkspace();
|
|
15445
16051
|
const observerId = options?.observer ? (0, utils_1.resolveId)(options.observer) : undefined;
|
|
@@ -15469,6 +16075,20 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15469
16075
|
}
|
|
15470
16076
|
});
|
|
15471
16077
|
}
|
|
16078
|
+
async dreams(options) {
|
|
16079
|
+
await this._ensureWorkspace();
|
|
16080
|
+
const body = {};
|
|
16081
|
+
if (options?.observed)
|
|
16082
|
+
body.observed_id = (0, utils_1.resolveId)(options.observed);
|
|
16083
|
+
if (options?.observer)
|
|
16084
|
+
body.observer_id = (0, utils_1.resolveId)(options.observer);
|
|
16085
|
+
const fetchPage = (page, size) => this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/dreams/list`, { body, query: { page, size } });
|
|
16086
|
+
return new pagination_1.Page(await fetchPage(options?.page, options?.size), undefined, fetchPage);
|
|
16087
|
+
}
|
|
16088
|
+
async getDream(runId) {
|
|
16089
|
+
await this._ensureWorkspace();
|
|
16090
|
+
return this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/dreams/${runId}`);
|
|
16091
|
+
}
|
|
15472
16092
|
toString() {
|
|
15473
16093
|
return `Honcho(workspaceId='${this.workspaceId}', baseURL='${this._http.baseURL}')`;
|
|
15474
16094
|
}
|
|
@@ -15479,7 +16099,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15479
16099
|
// node_modules/@honcho-ai/sdk/dist/index.js
|
|
15480
16100
|
var require_dist = __commonJS(function(exports) {
|
|
15481
16101
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15482
|
-
exports.Summary = exports.SessionSummaries = exports.SessionContext = exports.Session = exports.PeerContext = exports.Peer = exports.Page = exports.Message = exports.DialecticStreamResponse = exports.UnprocessableEntityError = exports.TimeoutError = exports.ServerError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.HonchoError = exports.ConnectionError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.ConclusionScope = exports.Conclusion = exports.Honcho = undefined;
|
|
16102
|
+
exports.Summary = exports.SessionSummaries = exports.SessionContext = exports.Session = exports.Scope = exports.PeerContext = exports.Peer = exports.Page = exports.Message = exports.DialecticStreamResponse = exports.UnprocessableEntityError = exports.TimeoutError = exports.ServerError = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.HonchoError = exports.ConnectionError = exports.ConflictError = exports.BadRequestError = exports.AuthenticationError = exports.WorkspaceConclusions = exports.ConclusionsView = exports.ConclusionScope = exports.Conclusion = exports.Honcho = undefined;
|
|
15483
16103
|
var client_1 = require_client2();
|
|
15484
16104
|
Object.defineProperty(exports, "Honcho", { enumerable: true, get: function() {
|
|
15485
16105
|
return client_1.Honcho;
|
|
@@ -15489,7 +16109,13 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15489
16109
|
return conclusions_1.Conclusion;
|
|
15490
16110
|
} });
|
|
15491
16111
|
Object.defineProperty(exports, "ConclusionScope", { enumerable: true, get: function() {
|
|
15492
|
-
return conclusions_1.
|
|
16112
|
+
return conclusions_1.ConclusionsView;
|
|
16113
|
+
} });
|
|
16114
|
+
Object.defineProperty(exports, "ConclusionsView", { enumerable: true, get: function() {
|
|
16115
|
+
return conclusions_1.ConclusionsView;
|
|
16116
|
+
} });
|
|
16117
|
+
Object.defineProperty(exports, "WorkspaceConclusions", { enumerable: true, get: function() {
|
|
16118
|
+
return conclusions_1.WorkspaceConclusions;
|
|
15493
16119
|
} });
|
|
15494
16120
|
var errors_1 = require_errors();
|
|
15495
16121
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function() {
|
|
@@ -15544,6 +16170,10 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15544
16170
|
Object.defineProperty(exports, "PeerContext", { enumerable: true, get: function() {
|
|
15545
16171
|
return peer_1.PeerContext;
|
|
15546
16172
|
} });
|
|
16173
|
+
var scope_1 = require_scope();
|
|
16174
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
|
|
16175
|
+
return scope_1.Scope;
|
|
16176
|
+
} });
|
|
15547
16177
|
var session_1 = require_session();
|
|
15548
16178
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function() {
|
|
15549
16179
|
return session_1.Session;
|
|
@@ -15560,133 +16190,507 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15560
16190
|
} });
|
|
15561
16191
|
});
|
|
15562
16192
|
|
|
15563
|
-
// src/skills/backfill.ts
|
|
15564
|
-
var import_sdk = __toESM(require_dist(), 1);
|
|
15565
|
-
|
|
15566
16193
|
// src/config.ts
|
|
15567
|
-
import {
|
|
15568
|
-
import { join as join3, basename, dirname, resolve, sep } from "path";
|
|
16194
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
15569
16195
|
import { fileURLToPath } from "url";
|
|
15570
|
-
import { existsSync as existsSync3,
|
|
16196
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
15571
16197
|
|
|
15572
|
-
//
|
|
15573
|
-
import {
|
|
15574
|
-
import {
|
|
15575
|
-
import { join } from "path";
|
|
15576
|
-
|
|
15577
|
-
|
|
16198
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
16199
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
16200
|
+
import { homedir } from "node:os";
|
|
16201
|
+
import { join as join2 } from "node:path";
|
|
16202
|
+
|
|
16203
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/v01.js
|
|
16204
|
+
var isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16205
|
+
var str = (v) => typeof v === "string" && v ? v : undefined;
|
|
16206
|
+
function v01Reader(file, host) {
|
|
16207
|
+
const hosts = isObj(file.hosts) ? file.hosts : {};
|
|
16208
|
+
const v1 = typeof file.schemaVersion === "number" && file.schemaVersion >= 1;
|
|
16209
|
+
const pick = (b) => {
|
|
16210
|
+
const o = isObj(b) ? b : {};
|
|
16211
|
+
if (v1)
|
|
16212
|
+
return { apiKey: isObj(o.auth) ? str(o.auth.apiKey) : undefined, peerName: str(o.peerName), workspace: str(o.workspace), baseUrl: str(o.baseUrl) };
|
|
16213
|
+
return {
|
|
16214
|
+
apiKey: (isObj(o.auth) ? str(o.auth.apiKey) : undefined) ?? str(o.apiKey),
|
|
16215
|
+
peerName: str(o.peerName),
|
|
16216
|
+
workspace: str(o.workspace) ?? str(o.workspaceId),
|
|
16217
|
+
baseUrl: str(o.baseUrl) ?? str(o.environmentUrl) ?? (isObj(o.endpoint) ? str(o.endpoint.baseUrl) : undefined)
|
|
16218
|
+
};
|
|
16219
|
+
};
|
|
16220
|
+
const own = pick(hosts[host]);
|
|
16221
|
+
const top = pick(file);
|
|
16222
|
+
return {
|
|
16223
|
+
apiKey: own.apiKey ?? top.apiKey,
|
|
16224
|
+
peerName: own.peerName ?? top.peerName,
|
|
16225
|
+
workspace: own.workspace ?? top.workspace,
|
|
16226
|
+
aiPeer: isObj(hosts[host]) ? str(hosts[host].aiPeer) : undefined,
|
|
16227
|
+
baseUrl: own.baseUrl ?? top.baseUrl
|
|
16228
|
+
};
|
|
16229
|
+
}
|
|
16230
|
+
|
|
16231
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/oauth.js
|
|
16232
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
16233
|
+
import { dirname, join } from "node:path";
|
|
16234
|
+
var OAUTH_DEVICE_URL = "https://api.honcho.dev/oauth/device_authorization";
|
|
16235
|
+
var OAUTH_TOKEN_URL = "https://api.honcho.dev/oauth/token";
|
|
16236
|
+
var OAUTH_SCOPE = "write";
|
|
16237
|
+
var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
16238
|
+
var SLOW_DOWN_STEP_S = 5;
|
|
16239
|
+
var DEFAULT_DEVICE_EXPIRES_S = 600;
|
|
16240
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
16241
|
+
var REFRESH_SKEW_S = 60;
|
|
16242
|
+
var LOCK_STALE_MS = REQUEST_TIMEOUT_MS + 5000;
|
|
16243
|
+
var LOCK_WAIT_MS = LOCK_STALE_MS + 5000;
|
|
16244
|
+
var PERMANENT_ERRORS = new Set(["invalid_grant", "invalid_client", "unauthorized_client"]);
|
|
16245
|
+
|
|
16246
|
+
class OAuthError extends Error {
|
|
16247
|
+
code;
|
|
16248
|
+
constructor(code, description) {
|
|
16249
|
+
super(description || code);
|
|
16250
|
+
this.code = code;
|
|
16251
|
+
this.name = "OAuthError";
|
|
16252
|
+
}
|
|
16253
|
+
}
|
|
16254
|
+
function isCloud(baseUrl) {
|
|
16255
|
+
return normalizeBaseUrl(baseUrl || DEFAULT_BASE_URL) === DEFAULT_BASE_URL;
|
|
16256
|
+
}
|
|
16257
|
+
function accessValid(t, skewS = REFRESH_SKEW_S, nowS = Date.now() / 1000) {
|
|
16258
|
+
return !!t?.accessToken && nowS < t.accessExpiresAt - skewS;
|
|
16259
|
+
}
|
|
16260
|
+
async function post(url, form, t) {
|
|
16261
|
+
const f = t?.fetch ?? fetch;
|
|
16262
|
+
let res;
|
|
16263
|
+
try {
|
|
16264
|
+
res = await f(url, {
|
|
16265
|
+
method: "POST",
|
|
16266
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
16267
|
+
body: new URLSearchParams(form).toString(),
|
|
16268
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
16269
|
+
});
|
|
16270
|
+
} catch (e) {
|
|
16271
|
+
throw new OAuthError("connection_error", `could not reach ${url}: ${e.message}`);
|
|
16272
|
+
}
|
|
16273
|
+
let body = null;
|
|
16274
|
+
try {
|
|
16275
|
+
body = await res.json();
|
|
16276
|
+
} catch {
|
|
16277
|
+
body = null;
|
|
16278
|
+
}
|
|
16279
|
+
return { status: res.status, body };
|
|
16280
|
+
}
|
|
16281
|
+
function errorOf(r) {
|
|
16282
|
+
const b = r.body;
|
|
16283
|
+
if (b && typeof b === "object" && typeof b.error === "string")
|
|
16284
|
+
return new OAuthError(b.error, b.error_description);
|
|
16285
|
+
return new OAuthError("invalid_response");
|
|
16286
|
+
}
|
|
16287
|
+
function tokensFrom(body, clientId, prev) {
|
|
16288
|
+
if (!body || typeof body.access_token !== "string" || !Number.isFinite(Number(body.expires_in))) {
|
|
16289
|
+
throw new OAuthError("invalid_response", "malformed token response");
|
|
16290
|
+
}
|
|
16291
|
+
return {
|
|
16292
|
+
accessToken: body.access_token,
|
|
16293
|
+
refreshToken: body.refresh_token || prev?.refreshToken || "",
|
|
16294
|
+
accessExpiresAt: Math.floor(Date.now() / 1000) + Number(body.expires_in),
|
|
16295
|
+
clientId,
|
|
16296
|
+
scope: body.scope || prev?.scope || OAUTH_SCOPE
|
|
16297
|
+
};
|
|
16298
|
+
}
|
|
16299
|
+
async function requestDeviceCode(opts) {
|
|
16300
|
+
const r = await post(opts.deviceUrl ?? OAUTH_DEVICE_URL, { client_id: opts.clientId, scope: OAUTH_SCOPE, source: opts.source }, opts);
|
|
16301
|
+
if (r.status !== 200)
|
|
16302
|
+
throw errorOf(r);
|
|
16303
|
+
const b = r.body;
|
|
16304
|
+
if (!b?.device_code || !b?.user_code || !b?.verification_uri) {
|
|
16305
|
+
throw new OAuthError("invalid_response", "malformed device authorization response");
|
|
16306
|
+
}
|
|
16307
|
+
return {
|
|
16308
|
+
deviceCode: b.device_code,
|
|
16309
|
+
userCode: b.user_code,
|
|
16310
|
+
verificationUri: b.verification_uri,
|
|
16311
|
+
verificationUriComplete: b.verification_uri_complete || b.verification_uri,
|
|
16312
|
+
expiresIn: Number(b.expires_in) > 0 ? Number(b.expires_in) : DEFAULT_DEVICE_EXPIRES_S,
|
|
16313
|
+
interval: Number(b.interval) || 5
|
|
16314
|
+
};
|
|
16315
|
+
}
|
|
16316
|
+
async function pollForToken(device, opts) {
|
|
16317
|
+
const clientId = opts.clientId;
|
|
16318
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
16319
|
+
const deadline = Date.now() + device.expiresIn * 1000;
|
|
16320
|
+
let interval = device.interval;
|
|
16321
|
+
while (true) {
|
|
16322
|
+
if (Date.now() >= deadline)
|
|
16323
|
+
throw new OAuthError("expired_token", "timed out waiting for approval");
|
|
16324
|
+
await sleep(interval * 1000);
|
|
16325
|
+
let r;
|
|
16326
|
+
try {
|
|
16327
|
+
r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: DEVICE_GRANT_TYPE, device_code: device.deviceCode, client_id: clientId }, opts);
|
|
16328
|
+
} catch (e) {
|
|
16329
|
+
if (e instanceof OAuthError && e.code === "connection_error")
|
|
16330
|
+
continue;
|
|
16331
|
+
throw e;
|
|
16332
|
+
}
|
|
16333
|
+
if (r.status === 200)
|
|
16334
|
+
return tokensFrom(r.body, clientId);
|
|
16335
|
+
if (r.status >= 500)
|
|
16336
|
+
continue;
|
|
16337
|
+
const err = errorOf(r);
|
|
16338
|
+
if (err.code === "authorization_pending")
|
|
16339
|
+
continue;
|
|
16340
|
+
if (err.code === "slow_down") {
|
|
16341
|
+
interval += SLOW_DOWN_STEP_S;
|
|
16342
|
+
continue;
|
|
16343
|
+
}
|
|
16344
|
+
throw err;
|
|
16345
|
+
}
|
|
16346
|
+
}
|
|
16347
|
+
async function refreshAccessToken(prev, opts = {}) {
|
|
16348
|
+
const r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: "refresh_token", refresh_token: prev.refreshToken, client_id: prev.clientId }, opts);
|
|
16349
|
+
if (r.status !== 200)
|
|
16350
|
+
throw errorOf(r);
|
|
16351
|
+
return tokensFrom(r.body, prev.clientId, prev);
|
|
16352
|
+
}
|
|
16353
|
+
function isObj2(v) {
|
|
16354
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16355
|
+
}
|
|
16356
|
+
function asTokens(v) {
|
|
16357
|
+
if (!isObj2(v) || typeof v.accessToken !== "string" || !v.accessToken)
|
|
16358
|
+
return;
|
|
16359
|
+
return {
|
|
16360
|
+
accessToken: v.accessToken,
|
|
16361
|
+
refreshToken: typeof v.refreshToken === "string" ? v.refreshToken : "",
|
|
16362
|
+
accessExpiresAt: Number(v.accessExpiresAt) || 0,
|
|
16363
|
+
clientId: typeof v.clientId === "string" ? v.clientId : "",
|
|
16364
|
+
scope: typeof v.scope === "string" ? v.scope : ""
|
|
16365
|
+
};
|
|
16366
|
+
}
|
|
16367
|
+
function readFile(path) {
|
|
16368
|
+
if (!existsSync(path))
|
|
16369
|
+
return {};
|
|
16370
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
16371
|
+
return isObj2(parsed) ? parsed : {};
|
|
16372
|
+
}
|
|
16373
|
+
function readGrant(file, host, legacy) {
|
|
16374
|
+
return asTokens(effectiveBlock(file, host, legacy).oauth);
|
|
16375
|
+
}
|
|
16376
|
+
function holderAlive(token, ageMs) {
|
|
16377
|
+
if (token === "")
|
|
16378
|
+
return ageMs < 1000;
|
|
16379
|
+
const pid = Number(token.split(":")[0]);
|
|
16380
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
16381
|
+
return true;
|
|
16382
|
+
try {
|
|
16383
|
+
process.kill(pid, 0);
|
|
16384
|
+
return true;
|
|
16385
|
+
} catch (e) {
|
|
16386
|
+
return e.code === "EPERM";
|
|
16387
|
+
}
|
|
16388
|
+
}
|
|
16389
|
+
async function withConfigLock(path, fn) {
|
|
16390
|
+
const lock = `${path}.lock`;
|
|
16391
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
16392
|
+
const start = Date.now();
|
|
16393
|
+
let fd;
|
|
16394
|
+
while (fd === undefined) {
|
|
16395
|
+
try {
|
|
16396
|
+
fd = openSync(lock, "wx", 384);
|
|
16397
|
+
} catch (e) {
|
|
16398
|
+
if (e.code !== "EEXIST")
|
|
16399
|
+
throw e;
|
|
16400
|
+
try {
|
|
16401
|
+
const age = Date.now() - statSync(lock).mtimeMs;
|
|
16402
|
+
if (age > LOCK_STALE_MS || !holderAlive(readFileSync(lock, "utf-8"), age))
|
|
16403
|
+
unlinkSync(lock);
|
|
16404
|
+
} catch {}
|
|
16405
|
+
if (Date.now() - start > LOCK_WAIT_MS)
|
|
16406
|
+
throw new Error(`timed out waiting for ${lock}`);
|
|
16407
|
+
await new Promise((r) => setTimeout(r, 50 + Math.random() * 50));
|
|
16408
|
+
}
|
|
16409
|
+
}
|
|
16410
|
+
const token = `${process.pid}:${Math.random().toString(36).slice(2)}`;
|
|
16411
|
+
try {
|
|
16412
|
+
writeFileSync(fd, token);
|
|
16413
|
+
return await fn();
|
|
16414
|
+
} finally {
|
|
16415
|
+
closeSync(fd);
|
|
16416
|
+
try {
|
|
16417
|
+
if (readFileSync(lock, "utf-8") === token)
|
|
16418
|
+
unlinkSync(lock);
|
|
16419
|
+
} catch {}
|
|
16420
|
+
}
|
|
15578
16421
|
}
|
|
15579
|
-
function
|
|
16422
|
+
function writeFileAtomic(path, data) {
|
|
16423
|
+
const tmp = join(dirname(path), `.${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
16424
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + `
|
|
16425
|
+
`, { mode: 384 });
|
|
16426
|
+
renameSync(tmp, path);
|
|
16427
|
+
}
|
|
16428
|
+
async function updateConfigFile(path, mutate) {
|
|
16429
|
+
await withConfigLock(path, async () => {
|
|
16430
|
+
const file = readFile(path);
|
|
16431
|
+
mutate(file);
|
|
16432
|
+
writeFileAtomic(path, file);
|
|
16433
|
+
});
|
|
16434
|
+
}
|
|
16435
|
+
function setGrant(file, host, tokens) {
|
|
16436
|
+
const block = hostBlock(file, host);
|
|
16437
|
+
if (tokens)
|
|
16438
|
+
block.oauth = tokens;
|
|
16439
|
+
else
|
|
16440
|
+
delete block.oauth;
|
|
16441
|
+
}
|
|
16442
|
+
async function saveGrant(path, host, tokens) {
|
|
16443
|
+
await updateConfigFile(path, (file) => {
|
|
16444
|
+
setGrant(file, host, tokens);
|
|
16445
|
+
if (tokens) {
|
|
16446
|
+
const block = hostBlock(file, host);
|
|
16447
|
+
delete block.apiKey;
|
|
16448
|
+
delete block.baseUrl;
|
|
16449
|
+
}
|
|
16450
|
+
});
|
|
16451
|
+
}
|
|
16452
|
+
function serverOf(block, baseUrl, env) {
|
|
16453
|
+
return baseUrl ?? (env.HONCHO_BASE_URL || undefined) ?? (typeof block.baseUrl === "string" && block.baseUrl ? block.baseUrl : undefined);
|
|
16454
|
+
}
|
|
16455
|
+
function pickCredential(file, opts) {
|
|
16456
|
+
const env = opts.env ?? process.env;
|
|
16457
|
+
if (env.HONCHO_API_KEY)
|
|
16458
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
16459
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
16460
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
16461
|
+
if (g)
|
|
16462
|
+
return { token: g.accessToken, source: "oauth", expiresAt: g.accessExpiresAt, ...accessValid(g, 0) ? {} : { expired: true } };
|
|
16463
|
+
return typeof block.apiKey === "string" && block.apiKey ? { token: block.apiKey, source: "apiKey" } : null;
|
|
16464
|
+
}
|
|
16465
|
+
async function ensureFreshCredential(opts) {
|
|
16466
|
+
const env = opts.env ?? process.env;
|
|
16467
|
+
if (env.HONCHO_API_KEY)
|
|
16468
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
16469
|
+
let file;
|
|
15580
16470
|
try {
|
|
15581
|
-
|
|
16471
|
+
file = readFile(opts.path);
|
|
15582
16472
|
} catch {
|
|
15583
|
-
|
|
16473
|
+
file = {};
|
|
16474
|
+
}
|
|
16475
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
16476
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
16477
|
+
if (!g || accessValid(g) || !g.refreshToken)
|
|
16478
|
+
return pickCredential(file, opts);
|
|
16479
|
+
let error;
|
|
16480
|
+
try {
|
|
16481
|
+
await withConfigLock(opts.path, async () => {
|
|
16482
|
+
const current = readGrant(readFile(opts.path), opts.host, opts.legacy);
|
|
16483
|
+
if (!current || accessValid(current))
|
|
16484
|
+
return;
|
|
16485
|
+
const next = await refreshAccessToken(current, opts);
|
|
16486
|
+
const latest = readFile(opts.path);
|
|
16487
|
+
setGrant(latest, opts.host, next);
|
|
16488
|
+
writeFileAtomic(opts.path, latest);
|
|
16489
|
+
});
|
|
16490
|
+
} catch (e) {
|
|
16491
|
+
error = e instanceof OAuthError ? e.code : e.message;
|
|
16492
|
+
}
|
|
16493
|
+
try {
|
|
16494
|
+
file = readFile(opts.path);
|
|
16495
|
+
} catch {}
|
|
16496
|
+
const cred = pickCredential(file, opts);
|
|
16497
|
+
if (cred && error) {
|
|
16498
|
+
cred.error = error;
|
|
16499
|
+
if (PERMANENT_ERRORS.has(error))
|
|
16500
|
+
cred.reauthRequired = true;
|
|
15584
16501
|
}
|
|
16502
|
+
return cred;
|
|
15585
16503
|
}
|
|
15586
|
-
|
|
15587
|
-
|
|
15588
|
-
|
|
16504
|
+
|
|
16505
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
16506
|
+
var DEFAULT_BASE_URL = "https://api.honcho.dev";
|
|
16507
|
+
var CONFIG_SCHEMA_VERSION = 2;
|
|
16508
|
+
function isObj3(v) {
|
|
16509
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16510
|
+
}
|
|
16511
|
+
function str2(v) {
|
|
16512
|
+
return typeof v === "string" && v ? v : undefined;
|
|
16513
|
+
}
|
|
16514
|
+
function normalizeBaseUrl(input) {
|
|
16515
|
+
let s = input.trim();
|
|
16516
|
+
if (!s)
|
|
16517
|
+
return s;
|
|
16518
|
+
if (!s.startsWith("http://") && !s.startsWith("https://")) {
|
|
16519
|
+
const host = s.split("/")[0].split(":")[0].toLowerCase();
|
|
16520
|
+
const local = host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
16521
|
+
s = `${local ? "http" : "https"}://${s}`;
|
|
15589
16522
|
}
|
|
15590
|
-
|
|
15591
|
-
|
|
15592
|
-
|
|
15593
|
-
|
|
15594
|
-
|
|
15595
|
-
|
|
15596
|
-
|
|
16523
|
+
try {
|
|
16524
|
+
const u = new URL(s);
|
|
16525
|
+
u.hostname = u.hostname.toLowerCase();
|
|
16526
|
+
const path = u.pathname === "/" ? "" : u.pathname.replace(/\/+$/, "");
|
|
16527
|
+
return `${u.protocol}//${u.host}${path}`;
|
|
16528
|
+
} catch {
|
|
16529
|
+
return s;
|
|
16530
|
+
}
|
|
16531
|
+
}
|
|
16532
|
+
function resolveConfig(file, opts) {
|
|
16533
|
+
const env = opts.env ?? process.env;
|
|
16534
|
+
const { host } = opts;
|
|
16535
|
+
const block = effectiveBlock(file, host, opts.legacy);
|
|
15597
16536
|
return {
|
|
15598
|
-
|
|
15599
|
-
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
|
|
15603
|
-
|
|
16537
|
+
host,
|
|
16538
|
+
peerName: str2(env.HONCHO_PEER_NAME) ?? str2(block.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user",
|
|
16539
|
+
workspace: str2(env.HONCHO_WORKSPACE) ?? str2(block.workspace) ?? opts.defaults?.workspace ?? host,
|
|
16540
|
+
aiPeer: str2(env.HONCHO_AI_PEER) ?? str2(block.aiPeer) ?? opts.defaults?.aiPeer ?? host,
|
|
16541
|
+
baseUrl: normalizeBaseUrl(str2(env.HONCHO_BASE_URL) ?? str2(block.baseUrl) ?? DEFAULT_BASE_URL),
|
|
16542
|
+
warnings: checkConfig(file).map((i) => i.message)
|
|
15604
16543
|
};
|
|
15605
16544
|
}
|
|
15606
|
-
|
|
15607
|
-
|
|
15608
|
-
|
|
15609
|
-
|
|
15610
|
-
|
|
15611
|
-
|
|
15612
|
-
|
|
15613
|
-
|
|
15614
|
-
function
|
|
15615
|
-
if (
|
|
15616
|
-
|
|
15617
|
-
|
|
16545
|
+
function suggestPeerName(file, env = process.env) {
|
|
16546
|
+
const f = isObj3(file) ? file : {};
|
|
16547
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
16548
|
+
const names = new Set(Object.values(hosts).map((b) => isObj3(b) ? str2(b.peerName) : undefined).filter(Boolean));
|
|
16549
|
+
if (names.size === 1)
|
|
16550
|
+
return [...names][0];
|
|
16551
|
+
return str2(f.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user";
|
|
16552
|
+
}
|
|
16553
|
+
function configPath(env = process.env) {
|
|
16554
|
+
if (env.HONCHO_CONFIG_PATH)
|
|
16555
|
+
return env.HONCHO_CONFIG_PATH;
|
|
16556
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
16557
|
+
return join2(home, ".honcho", "config.json");
|
|
15618
16558
|
}
|
|
15619
|
-
function
|
|
15620
|
-
|
|
15621
|
-
if (!existsSync2(
|
|
16559
|
+
function readConfigFile(env = process.env) {
|
|
16560
|
+
const path = configPath(env);
|
|
16561
|
+
if (!existsSync2(path))
|
|
15622
16562
|
return {};
|
|
15623
|
-
}
|
|
15624
16563
|
try {
|
|
15625
|
-
|
|
16564
|
+
const parsed = JSON.parse(readFileSync2(path, "utf-8"));
|
|
16565
|
+
return isObj3(parsed) ? parsed : {};
|
|
15626
16566
|
} catch {
|
|
15627
16567
|
return {};
|
|
15628
16568
|
}
|
|
15629
16569
|
}
|
|
15630
|
-
function
|
|
15631
|
-
|
|
15632
|
-
|
|
16570
|
+
async function saveHost(path, host, patch, legacy) {
|
|
16571
|
+
await updateConfigFile(path, (file) => {
|
|
16572
|
+
if (isNewer(file))
|
|
16573
|
+
throw new Error(`${path} was written by a newer Honcho plugin; update this one.`);
|
|
16574
|
+
const block = writeBlock(file, host, hostMigration(file, host, [], legacy));
|
|
16575
|
+
if ("baseUrl" in patch && !("apiKey" in patch) && !sameServer(patch.baseUrl, str2(block.baseUrl)))
|
|
16576
|
+
delete block.apiKey;
|
|
16577
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
16578
|
+
if (v === undefined)
|
|
16579
|
+
delete block[k];
|
|
16580
|
+
else
|
|
16581
|
+
block[k] = v;
|
|
16582
|
+
}
|
|
16583
|
+
block.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
16584
|
+
});
|
|
15633
16585
|
}
|
|
15634
|
-
|
|
15635
|
-
|
|
15636
|
-
return
|
|
16586
|
+
var MOVABLE = ["apiKey", "peerName", "workspace", "aiPeer", "baseUrl"];
|
|
16587
|
+
function isNewer(file) {
|
|
16588
|
+
return isObj3(file) && typeof file.schemaVersion === "number" && file.schemaVersion > CONFIG_SCHEMA_VERSION;
|
|
15637
16589
|
}
|
|
15638
|
-
|
|
15639
|
-
"
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
var
|
|
15645
|
-
function
|
|
15646
|
-
|
|
15647
|
-
|
|
15648
|
-
|
|
15649
|
-
|
|
15650
|
-
|
|
15651
|
-
|
|
15652
|
-
|
|
15653
|
-
|
|
15654
|
-
|
|
15655
|
-
}
|
|
15656
|
-
|
|
15657
|
-
|
|
15658
|
-
|
|
15659
|
-
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
16590
|
+
function isMigrated(block) {
|
|
16591
|
+
return isObj3(block) && typeof block.schemaVersion === "number" && block.schemaVersion >= CONFIG_SCHEMA_VERSION;
|
|
16592
|
+
}
|
|
16593
|
+
function sameServer(a, b) {
|
|
16594
|
+
return normalizeBaseUrl(a ?? DEFAULT_BASE_URL) === normalizeBaseUrl(b ?? DEFAULT_BASE_URL);
|
|
16595
|
+
}
|
|
16596
|
+
var LEGACY_HOST_KEYS = ["auth", "endpoint", "environmentUrl", "workspaceId"];
|
|
16597
|
+
function isGrant(v) {
|
|
16598
|
+
return isObj3(v) && typeof v.accessToken === "string" && v.accessToken !== "";
|
|
16599
|
+
}
|
|
16600
|
+
function legacyGrantOf(b) {
|
|
16601
|
+
return !isGrant(b.oauth) && isObj3(b.auth) && isObj3(b.auth.oauth) ? b.auth.oauth : undefined;
|
|
16602
|
+
}
|
|
16603
|
+
function checkConfig(file) {
|
|
16604
|
+
if (!isObj3(file))
|
|
16605
|
+
return [];
|
|
16606
|
+
if (isNewer(file)) {
|
|
16607
|
+
return [{ path: "schemaVersion", message: `This file is schema version ${file.schemaVersion}, newer than this plugin understands; update the plugin.` }];
|
|
16608
|
+
}
|
|
16609
|
+
const issues = [];
|
|
16610
|
+
const hosts = isObj3(file.hosts) ? file.hosts : {};
|
|
16611
|
+
const byWorkspace = new Map;
|
|
16612
|
+
for (const h of Object.keys(hosts).filter((k) => isObj3(hosts[k]))) {
|
|
16613
|
+
const block = hosts[h];
|
|
16614
|
+
const peer = str2(block.peerName);
|
|
16615
|
+
if (!peer)
|
|
16616
|
+
continue;
|
|
16617
|
+
const ws = str2(block.workspace) ?? h;
|
|
16618
|
+
const peers = byWorkspace.get(ws) ?? new Map;
|
|
16619
|
+
peers.set(peer, [...peers.get(peer) ?? [], h]);
|
|
16620
|
+
byWorkspace.set(ws, peers);
|
|
15666
16621
|
}
|
|
15667
|
-
|
|
15668
|
-
|
|
16622
|
+
for (const [ws, peers] of byWorkspace) {
|
|
16623
|
+
if (peers.size < 2)
|
|
16624
|
+
continue;
|
|
16625
|
+
const list = [...peers].map(([p, hs]) => `${hs.join(", ")}: "${p}"`).join("; ");
|
|
16626
|
+
issues.push({ path: "hosts", message: `Hosts in workspace "${ws}" use different peerNames (${list}), so the user is split across peers.` });
|
|
15669
16627
|
}
|
|
15670
|
-
return
|
|
16628
|
+
return issues;
|
|
15671
16629
|
}
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
|
|
16630
|
+
function hostMigration(file, host, deadKeys = [], legacy = v01Reader) {
|
|
16631
|
+
if (isNewer(file))
|
|
16632
|
+
return { set: {}, remove: [] };
|
|
16633
|
+
const f = isObj3(file) ? file : {};
|
|
16634
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
16635
|
+
const block = isObj3(hosts[host]) ? hosts[host] : {};
|
|
16636
|
+
const set = {};
|
|
16637
|
+
const drop = [];
|
|
16638
|
+
const grant = legacyGrantOf(block);
|
|
16639
|
+
if (grant)
|
|
16640
|
+
set.oauth = grant;
|
|
16641
|
+
if (!isMigrated(block)) {
|
|
16642
|
+
const old = { ...legacy(f, host) };
|
|
16643
|
+
const signedIn = isGrant(block.oauth) || grant !== undefined;
|
|
16644
|
+
if (old.baseUrl && sameServer(old.baseUrl, undefined))
|
|
16645
|
+
old.baseUrl = undefined;
|
|
16646
|
+
for (const key of MOVABLE) {
|
|
16647
|
+
if (signedIn && (key === "apiKey" || key === "baseUrl"))
|
|
16648
|
+
continue;
|
|
16649
|
+
if (old[key] !== undefined && block[key] !== old[key])
|
|
16650
|
+
set[key] = old[key];
|
|
16651
|
+
else if (old[key] === undefined && block[key] !== undefined)
|
|
16652
|
+
drop.push(key);
|
|
15686
16653
|
}
|
|
16654
|
+
set.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
15687
16655
|
}
|
|
16656
|
+
const remove = [...drop, ...LEGACY_HOST_KEYS, ...deadKeys].filter((k) => (k in block) && !(k in set));
|
|
16657
|
+
return { set, remove };
|
|
16658
|
+
}
|
|
16659
|
+
function effectiveBlock(file, host, legacy) {
|
|
16660
|
+
return writeBlock(structuredClone(isObj3(file) ? file : {}), host, hostMigration(file, host, [], legacy));
|
|
16661
|
+
}
|
|
16662
|
+
function hostBlock(file, host) {
|
|
16663
|
+
if (host === "__proto__" || host === "constructor" || host === "prototype")
|
|
16664
|
+
throw new Error(`invalid host name: ${host}`);
|
|
16665
|
+
if (!isObj3(file.hosts))
|
|
16666
|
+
file.hosts = {};
|
|
16667
|
+
return isObj3(file.hosts[host]) ? file.hosts[host] : file.hosts[host] = {};
|
|
16668
|
+
}
|
|
16669
|
+
function writeBlock(file, host, { set, remove }) {
|
|
16670
|
+
const block = hostBlock(file, host);
|
|
16671
|
+
Object.assign(block, set);
|
|
16672
|
+
for (const k of remove)
|
|
16673
|
+
delete block[k];
|
|
16674
|
+
return block;
|
|
16675
|
+
}
|
|
16676
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/claude-honcho.js
|
|
16677
|
+
var isObj4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16678
|
+
var str3 = (v) => typeof v === "string" && v ? v : undefined;
|
|
16679
|
+
function claudeHonchoReader(file, host) {
|
|
16680
|
+
const hosts = isObj4(file.hosts) ? file.hosts : {};
|
|
16681
|
+
const found = hosts[host] ?? hosts[host.replace(/_/g, "-")] ?? hosts[host.replace(/-/g, "_")];
|
|
16682
|
+
const block = isObj4(found) ? found : undefined;
|
|
16683
|
+
const endpoint = block?.endpoint ?? file.endpoint;
|
|
16684
|
+
const override = file.globalOverride === true;
|
|
16685
|
+
return {
|
|
16686
|
+
apiKey: str3(block?.apiKey) ?? str3(file.apiKey),
|
|
16687
|
+
baseUrl: str3(endpoint?.baseUrl)?.replace(/\/v3\/?$/, "") ?? (endpoint?.environment === "local" ? "http://localhost:8000" : undefined),
|
|
16688
|
+
peerName: str3(file.peerName),
|
|
16689
|
+
workspace: str3(override || !block ? file.workspace : block.workspace),
|
|
16690
|
+
aiPeer: str3(override ? file.aiPeer ?? block?.aiPeer : block ? block.aiPeer : file[host === "cursor" ? "cursorPeer" : "claudePeer"])
|
|
16691
|
+
};
|
|
15688
16692
|
}
|
|
15689
|
-
// node_modules/@honcho-ai/harness-plugin-core/
|
|
16693
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/telemetry.js
|
|
15690
16694
|
var HEADER_HOST = "X-Honcho-Host";
|
|
15691
16695
|
var HEADER_PLUGIN = "X-Honcho-Plugin";
|
|
15692
16696
|
var HEADER_AGENT_MODEL = "X-Honcho-Agent-Model";
|
|
@@ -15735,13 +16739,10 @@ function telemetryHeaders(id = {}, extra) {
|
|
|
15735
16739
|
return headers;
|
|
15736
16740
|
}
|
|
15737
16741
|
// src/config.ts
|
|
16742
|
+
var LEGACY = claudeHonchoReader;
|
|
15738
16743
|
function sanitizeForSessionName(s) {
|
|
15739
16744
|
return s.toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
15740
16745
|
}
|
|
15741
|
-
var HONCHO_BASE_URLS = {
|
|
15742
|
-
production: "https://api.honcho.dev/v3",
|
|
15743
|
-
local: "http://localhost:8000/v3"
|
|
15744
|
-
};
|
|
15745
16746
|
var _detectedHost = null;
|
|
15746
16747
|
function setDetectedHost(host) {
|
|
15747
16748
|
_detectedHost = host;
|
|
@@ -15759,34 +16760,14 @@ var DEFAULT_AI_PEER = {
|
|
|
15759
16760
|
claude_code: "claude",
|
|
15760
16761
|
obsidian: "honcho"
|
|
15761
16762
|
};
|
|
15762
|
-
function
|
|
15763
|
-
|
|
15764
|
-
return true;
|
|
15765
|
-
if (a == null || b == null)
|
|
15766
|
-
return a === b;
|
|
15767
|
-
if (typeof a !== typeof b)
|
|
15768
|
-
return false;
|
|
15769
|
-
if (typeof a !== "object")
|
|
15770
|
-
return false;
|
|
15771
|
-
const aObj = a;
|
|
15772
|
-
const bObj = b;
|
|
15773
|
-
const keys = new Set([...Object.keys(aObj), ...Object.keys(bObj)]);
|
|
15774
|
-
for (const key of keys) {
|
|
15775
|
-
if (!deepEqual(aObj[key], bObj[key]))
|
|
15776
|
-
return false;
|
|
15777
|
-
}
|
|
15778
|
-
return true;
|
|
16763
|
+
function getConfigPath() {
|
|
16764
|
+
return configPath();
|
|
15779
16765
|
}
|
|
15780
|
-
var CONFIG_DIR = join3(homedir2(), ".honcho");
|
|
15781
|
-
var CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
15782
16766
|
function getConfigDir() {
|
|
15783
|
-
return
|
|
15784
|
-
}
|
|
15785
|
-
function getConfigPath() {
|
|
15786
|
-
return CONFIG_FILE;
|
|
16767
|
+
return dirname2(configPath());
|
|
15787
16768
|
}
|
|
15788
16769
|
function configExists() {
|
|
15789
|
-
return existsSync3(
|
|
16770
|
+
return existsSync3(configPath());
|
|
15790
16771
|
}
|
|
15791
16772
|
function getPluginVersion() {
|
|
15792
16773
|
const root = process.env.CLAUDE_PLUGIN_ROOT;
|
|
@@ -15796,300 +16777,123 @@ function getPluginVersion() {
|
|
|
15796
16777
|
];
|
|
15797
16778
|
for (const manifest of candidates) {
|
|
15798
16779
|
try {
|
|
15799
|
-
const version = JSON.parse(
|
|
16780
|
+
const version = JSON.parse(readFileSync3(manifest, "utf-8")).version;
|
|
15800
16781
|
if (typeof version === "string" && version)
|
|
15801
16782
|
return version;
|
|
15802
16783
|
} catch {}
|
|
15803
16784
|
}
|
|
15804
16785
|
return "unknown";
|
|
15805
16786
|
}
|
|
15806
|
-
function
|
|
15807
|
-
|
|
15808
|
-
|
|
15809
|
-
|
|
15810
|
-
|
|
15811
|
-
|
|
15812
|
-
return resolveConfig2(raw, resolvedHost);
|
|
15813
|
-
} catch {}
|
|
15814
|
-
}
|
|
15815
|
-
return loadConfigFromEnv(resolvedHost);
|
|
16787
|
+
function legacyEndpoint(value) {
|
|
16788
|
+
if (value === "local")
|
|
16789
|
+
return "http://localhost:8000";
|
|
16790
|
+
if (value?.startsWith("http"))
|
|
16791
|
+
return value.replace(/\/v3\/?$/, "");
|
|
16792
|
+
return;
|
|
15816
16793
|
}
|
|
15817
|
-
function
|
|
15818
|
-
const
|
|
15819
|
-
const
|
|
15820
|
-
|
|
15821
|
-
|
|
15822
|
-
|
|
15823
|
-
|
|
15824
|
-
|
|
15825
|
-
if (
|
|
15826
|
-
|
|
15827
|
-
|
|
15828
|
-
|
|
15829
|
-
|
|
15830
|
-
|
|
15831
|
-
} else {
|
|
15832
|
-
workspace = process.env.HONCHO_WORKSPACE ?? raw.workspace ?? DEFAULT_WORKSPACE[host];
|
|
15833
|
-
if (host === "cursor") {
|
|
15834
|
-
aiPeer = raw.cursorPeer ?? DEFAULT_AI_PEER["cursor"];
|
|
15835
|
-
} else {
|
|
15836
|
-
aiPeer = raw.claudePeer ?? DEFAULT_AI_PEER["claude_code"];
|
|
15837
|
-
}
|
|
15838
|
-
}
|
|
15839
|
-
const config = {
|
|
15840
|
-
apiKey,
|
|
15841
|
-
peerName,
|
|
15842
|
-
workspace,
|
|
15843
|
-
aiPeer,
|
|
15844
|
-
sessionStrategy: hostBlock?.sessionStrategy ?? raw.sessionStrategy,
|
|
15845
|
-
sessionPeerPrefix: hostBlock?.sessionPeerPrefix ?? raw.sessionPeerPrefix,
|
|
15846
|
-
sessions: raw.sessions,
|
|
15847
|
-
saveMessages: hostBlock?.saveMessages ?? raw.saveMessages,
|
|
15848
|
-
saveToolUse: hostBlock?.saveToolUse ?? raw.saveToolUse,
|
|
15849
|
-
saveGitEvents: hostBlock?.saveGitEvents ?? raw.saveGitEvents,
|
|
15850
|
-
reasoningLevel: hostBlock?.reasoningLevel ?? raw.reasoningLevel,
|
|
15851
|
-
observationMode: hostBlock?.observationMode ?? raw.observationMode,
|
|
15852
|
-
messageUpload: hostBlock?.messageUpload ?? raw.messageUpload,
|
|
15853
|
-
contextRefresh: hostBlock?.contextRefresh ?? raw.contextRefresh,
|
|
15854
|
-
endpoint: hostBlock?.endpoint ?? raw.endpoint,
|
|
15855
|
-
redactPatterns: hostBlock?.redactPatterns ?? raw.redactPatterns,
|
|
15856
|
-
injection: hostBlock?.injection ?? raw.injection,
|
|
15857
|
-
rememberTool: hostBlock?.rememberTool ?? raw.rememberTool,
|
|
15858
|
-
enabled: hostBlock?.enabled ?? raw.enabled,
|
|
15859
|
-
logging: hostBlock?.logging ?? raw.logging,
|
|
15860
|
-
globalOverride: raw.globalOverride
|
|
15861
|
-
};
|
|
15862
|
-
return mergeWithEnvVars(config);
|
|
16794
|
+
function legacyEnv(host = getDetectedHost()) {
|
|
16795
|
+
const env = process.env;
|
|
16796
|
+
const peerVar = host === "cursor" ? "HONCHO_CURSOR_PEER" : "HONCHO_CLAUDE_PEER";
|
|
16797
|
+
const candidates = [
|
|
16798
|
+
["HONCHO_BASE_URL", "baseUrl", "HONCHO_ENDPOINT", legacyEndpoint(env.HONCHO_ENDPOINT)],
|
|
16799
|
+
["HONCHO_AI_PEER", "aiPeer", peerVar, env[peerVar] || undefined]
|
|
16800
|
+
];
|
|
16801
|
+
const set = candidates.filter(([newVar, , , value]) => value && !env[newVar]);
|
|
16802
|
+
if (!set.length)
|
|
16803
|
+
return {};
|
|
16804
|
+
const block = effectiveBlock(readConfigFile(), host, LEGACY);
|
|
16805
|
+
if (block.apiKey || block.oauth)
|
|
16806
|
+
return {};
|
|
16807
|
+
return Object.fromEntries(set.filter(([, setting]) => !block[setting]).map(([newVar, , oldVar, value]) => [newVar, [oldVar, value]]));
|
|
15863
16808
|
}
|
|
15864
|
-
function
|
|
15865
|
-
const
|
|
15866
|
-
if (!
|
|
15867
|
-
return
|
|
15868
|
-
}
|
|
15869
|
-
const resolvedHost = host ?? getDetectedHost();
|
|
15870
|
-
const peerName = process.env.HONCHO_PEER_NAME || process.env.USER || process.env.USERNAME || "user";
|
|
15871
|
-
const workspace = process.env.HONCHO_WORKSPACE || DEFAULT_WORKSPACE[resolvedHost];
|
|
15872
|
-
const hostPeerEnv = resolvedHost === "cursor" ? process.env.HONCHO_CURSOR_PEER : process.env.HONCHO_CLAUDE_PEER;
|
|
15873
|
-
const aiPeer = process.env.HONCHO_AI_PEER || hostPeerEnv || DEFAULT_AI_PEER[resolvedHost];
|
|
15874
|
-
const endpoint = process.env.HONCHO_ENDPOINT;
|
|
15875
|
-
const config = {
|
|
15876
|
-
apiKey,
|
|
15877
|
-
peerName,
|
|
15878
|
-
workspace,
|
|
15879
|
-
aiPeer,
|
|
15880
|
-
saveMessages: process.env.HONCHO_SAVE_MESSAGES !== "false",
|
|
15881
|
-
saveToolUse: process.env.HONCHO_SAVE_TOOL_USE === "true",
|
|
15882
|
-
saveGitEvents: process.env.HONCHO_SAVE_GIT_EVENTS === "true",
|
|
15883
|
-
enabled: process.env.HONCHO_ENABLED !== "false",
|
|
15884
|
-
logging: process.env.HONCHO_LOGGING !== "false"
|
|
15885
|
-
};
|
|
15886
|
-
if (endpoint) {
|
|
15887
|
-
if (endpoint === "local") {
|
|
15888
|
-
config.endpoint = { environment: "local" };
|
|
15889
|
-
} else if (endpoint.startsWith("http")) {
|
|
15890
|
-
config.endpoint = { baseUrl: endpoint };
|
|
15891
|
-
}
|
|
15892
|
-
}
|
|
15893
|
-
return config;
|
|
16809
|
+
function honchoEnv(host) {
|
|
16810
|
+
const legacy = Object.entries(legacyEnv(host));
|
|
16811
|
+
if (!legacy.length)
|
|
16812
|
+
return process.env;
|
|
16813
|
+
return { ...process.env, ...Object.fromEntries(legacy.map(([k, [, value]]) => [k, value])) };
|
|
15894
16814
|
}
|
|
15895
|
-
function
|
|
15896
|
-
|
|
15897
|
-
|
|
15898
|
-
|
|
15899
|
-
|
|
15900
|
-
|
|
15901
|
-
}
|
|
15902
|
-
if (process.env.HONCHO_ENABLED === "false") {
|
|
15903
|
-
config.enabled = false;
|
|
15904
|
-
}
|
|
15905
|
-
if (process.env.HONCHO_LOGGING === "false") {
|
|
15906
|
-
config.logging = false;
|
|
15907
|
-
}
|
|
15908
|
-
if (process.env.HONCHO_SAVE_TOOL_USE !== undefined) {
|
|
15909
|
-
config.saveToolUse = process.env.HONCHO_SAVE_TOOL_USE === "true";
|
|
15910
|
-
}
|
|
15911
|
-
if (process.env.HONCHO_SAVE_GIT_EVENTS !== undefined) {
|
|
15912
|
-
config.saveGitEvents = process.env.HONCHO_SAVE_GIT_EVENTS === "true";
|
|
15913
|
-
}
|
|
15914
|
-
return config;
|
|
16815
|
+
function resolveHost(host) {
|
|
16816
|
+
return resolveConfig(readConfigFile(), {
|
|
16817
|
+
host,
|
|
16818
|
+
env: honchoEnv(host),
|
|
16819
|
+
defaults: { workspace: DEFAULT_WORKSPACE[host], aiPeer: DEFAULT_AI_PEER[host] },
|
|
16820
|
+
legacy: LEGACY
|
|
16821
|
+
});
|
|
15915
16822
|
}
|
|
15916
|
-
function
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
|
|
15923
|
-
|
|
15924
|
-
|
|
15925
|
-
|
|
15926
|
-
|
|
15927
|
-
|
|
15928
|
-
|
|
15929
|
-
const host = getDetectedHost();
|
|
15930
|
-
if (!existing.hosts)
|
|
15931
|
-
existing.hosts = {};
|
|
15932
|
-
const existingHost = existing.hosts[host] ?? {};
|
|
15933
|
-
const hostEntry = {};
|
|
15934
|
-
const setHostIfExplicit = (key, value, rootValue) => {
|
|
15935
|
-
if (value === undefined)
|
|
15936
|
-
return;
|
|
15937
|
-
const hasHostOverride = Object.prototype.hasOwnProperty.call(existingHost, key);
|
|
15938
|
-
if (hasHostOverride || !deepEqual(value, rootValue)) {
|
|
15939
|
-
hostEntry[key] = value;
|
|
15940
|
-
}
|
|
16823
|
+
function loadConfig2(host = getDetectedHost()) {
|
|
16824
|
+
const cfg = resolveHost(host);
|
|
16825
|
+
const cred = pickCredential(readConfigFile(), { host, baseUrl: cfg.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
16826
|
+
if (!cred)
|
|
16827
|
+
return null;
|
|
16828
|
+
const { token, ...authState } = cred;
|
|
16829
|
+
return {
|
|
16830
|
+
apiKey: token,
|
|
16831
|
+
auth: { ...authState, host },
|
|
16832
|
+
peerName: cfg.peerName,
|
|
16833
|
+
workspace: cfg.workspace,
|
|
16834
|
+
aiPeer: cfg.aiPeer,
|
|
16835
|
+
baseUrl: cfg.baseUrl
|
|
15941
16836
|
};
|
|
15942
|
-
setHostIfExplicit("workspace", config.workspace, existing.workspace ?? DEFAULT_WORKSPACE[host]);
|
|
15943
|
-
setHostIfExplicit("aiPeer", config.aiPeer, existing.aiPeer ?? DEFAULT_AI_PEER[host]);
|
|
15944
|
-
const enabledForSave = process.env.HONCHO_ENABLED === "false" && config.enabled === false ? existingHost.enabled : config.enabled;
|
|
15945
|
-
const loggingForSave = process.env.HONCHO_LOGGING === "false" && config.logging === false ? existingHost.logging : config.logging;
|
|
15946
|
-
setHostIfExplicit("enabled", enabledForSave, existing.enabled);
|
|
15947
|
-
setHostIfExplicit("logging", loggingForSave, existing.logging);
|
|
15948
|
-
setHostIfExplicit("saveMessages", config.saveMessages, existing.saveMessages);
|
|
15949
|
-
setHostIfExplicit("sessionStrategy", config.sessionStrategy, existing.sessionStrategy);
|
|
15950
|
-
setHostIfExplicit("sessionPeerPrefix", config.sessionPeerPrefix, existing.sessionPeerPrefix);
|
|
15951
|
-
setHostIfExplicit("reasoningLevel", config.reasoningLevel, existing.reasoningLevel);
|
|
15952
|
-
setHostIfExplicit("observationMode", config.observationMode, existing.observationMode);
|
|
15953
|
-
setHostIfExplicit("messageUpload", config.messageUpload, existing.messageUpload);
|
|
15954
|
-
setHostIfExplicit("contextRefresh", config.contextRefresh, existing.contextRefresh);
|
|
15955
|
-
setHostIfExplicit("redactPatterns", config.redactPatterns, existing.redactPatterns);
|
|
15956
|
-
setHostIfExplicit("endpoint", config.endpoint, existing.endpoint);
|
|
15957
|
-
setHostIfExplicit("injection", config.injection, existing.injection);
|
|
15958
|
-
setHostIfExplicit("rememberTool", config.rememberTool, existing.rememberTool);
|
|
15959
|
-
if (existingHost.apiKey !== undefined) {
|
|
15960
|
-
hostEntry.apiKey = existingHost.apiKey;
|
|
15961
|
-
}
|
|
15962
|
-
existing.hosts[host] = hostEntry;
|
|
15963
|
-
writeFileSync2(CONFIG_FILE, JSON.stringify(existing, null, 2));
|
|
15964
|
-
}
|
|
15965
|
-
function saveRootField(field, value) {
|
|
15966
|
-
if (!existsSync3(CONFIG_DIR)) {
|
|
15967
|
-
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
15968
|
-
}
|
|
15969
|
-
let existing = {};
|
|
15970
|
-
if (existsSync3(CONFIG_FILE)) {
|
|
15971
|
-
try {
|
|
15972
|
-
existing = JSON.parse(readFileSync2(CONFIG_FILE, "utf-8"));
|
|
15973
|
-
} catch {}
|
|
15974
|
-
}
|
|
15975
|
-
existing[field] = value;
|
|
15976
|
-
writeFileSync2(CONFIG_FILE, JSON.stringify(existing, null, 2));
|
|
15977
16837
|
}
|
|
15978
|
-
function
|
|
15979
|
-
|
|
16838
|
+
async function saveConfig(config, field) {
|
|
16839
|
+
const host = getDetectedHost();
|
|
16840
|
+
const env = honchoEnv(host);
|
|
16841
|
+
const write = (key, envVar) => key === field || !env[envVar];
|
|
16842
|
+
const patch = {};
|
|
16843
|
+
if (write("peerName", "HONCHO_PEER_NAME"))
|
|
16844
|
+
patch.peerName = config.peerName;
|
|
16845
|
+
if (write("workspace", "HONCHO_WORKSPACE"))
|
|
16846
|
+
patch.workspace = config.workspace === DEFAULT_WORKSPACE[host] ? undefined : config.workspace;
|
|
16847
|
+
if (write("aiPeer", "HONCHO_AI_PEER"))
|
|
16848
|
+
patch.aiPeer = config.aiPeer === DEFAULT_AI_PEER[host] ? undefined : config.aiPeer;
|
|
16849
|
+
if (write("baseUrl", "HONCHO_BASE_URL"))
|
|
16850
|
+
patch.baseUrl = config.baseUrl === DEFAULT_BASE_URL ? undefined : config.baseUrl;
|
|
16851
|
+
await saveHost(configPath(), host, patch, LEGACY);
|
|
15980
16852
|
}
|
|
15981
|
-
function
|
|
15982
|
-
|
|
16853
|
+
async function saveHostApiKey(key) {
|
|
16854
|
+
await saveHost(configPath(), getDetectedHost(), { apiKey: key }, LEGACY);
|
|
15983
16855
|
}
|
|
15984
|
-
function
|
|
15985
|
-
|
|
15986
|
-
const gitPath = join3(dir, ".git");
|
|
15987
|
-
if (!statSync(gitPath).isFile())
|
|
15988
|
-
return null;
|
|
15989
|
-
const match = readFileSync2(gitPath, "utf-8").match(/^gitdir:\s*(.+?)\s*$/m);
|
|
15990
|
-
if (!match)
|
|
15991
|
-
return null;
|
|
15992
|
-
const gitdir = resolve(dir, match[1]);
|
|
15993
|
-
const idx = gitdir.lastIndexOf(`${sep}worktrees${sep}`);
|
|
15994
|
-
if (idx === -1)
|
|
15995
|
-
return null;
|
|
15996
|
-
const gitContainer = gitdir.slice(0, idx);
|
|
15997
|
-
if (basename(gitContainer) === ".git")
|
|
15998
|
-
return dirname(gitContainer);
|
|
15999
|
-
if (gitContainer.endsWith(".git"))
|
|
16000
|
-
return gitContainer;
|
|
16001
|
-
return null;
|
|
16002
|
-
} catch {
|
|
16003
|
-
return null;
|
|
16004
|
-
}
|
|
16856
|
+
function getConfiguredOrigin(host = getDetectedHost()) {
|
|
16857
|
+
return resolveHost(host).baseUrl;
|
|
16005
16858
|
}
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
let dir = resolve(cwd);
|
|
16010
|
-
for (let i = 0;i < MAX_GIT_WALK_UP; i++) {
|
|
16011
|
-
if (existsSync3(join3(dir, ".git")))
|
|
16012
|
-
return resolveWorktreeMainRoot(dir);
|
|
16013
|
-
const parent = dirname(dir);
|
|
16014
|
-
if (parent === dir)
|
|
16015
|
-
break;
|
|
16016
|
-
dir = parent;
|
|
16017
|
-
}
|
|
16018
|
-
} catch {}
|
|
16019
|
-
return null;
|
|
16859
|
+
function getSessionName(sessionId) {
|
|
16860
|
+
const id = sessionId || process.env.CLAUDE_CODE_SESSION_ID;
|
|
16861
|
+
return id ? sanitizeForSessionName(id) : null;
|
|
16020
16862
|
}
|
|
16021
|
-
function
|
|
16022
|
-
const
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
return config.sessions[mr];
|
|
16030
|
-
return null;
|
|
16863
|
+
async function refreshCredential(config) {
|
|
16864
|
+
const host = config.auth?.host ?? getDetectedHost();
|
|
16865
|
+
const cred = await ensureFreshCredential({ path: configPath(), host, baseUrl: config.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
16866
|
+
if (!cred)
|
|
16867
|
+
return;
|
|
16868
|
+
const { token, ...authState } = cred;
|
|
16869
|
+
config.apiKey = token;
|
|
16870
|
+
config.auth = { ...authState, host };
|
|
16031
16871
|
}
|
|
16032
|
-
function
|
|
16033
|
-
const
|
|
16034
|
-
const
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16043
|
-
|
|
16044
|
-
|
|
16045
|
-
case "chat-instance": {
|
|
16046
|
-
if (opts.instanceId) {
|
|
16047
|
-
return usePrefix ? `${peerPart}-chat-${opts.instanceId}` : `chat-${opts.instanceId}`;
|
|
16048
|
-
}
|
|
16049
|
-
return base;
|
|
16050
|
-
}
|
|
16051
|
-
case "per-directory":
|
|
16872
|
+
function describeAuth(config) {
|
|
16873
|
+
const a = config.auth;
|
|
16874
|
+
const expiry = () => {
|
|
16875
|
+
if (!a?.expiresAt)
|
|
16876
|
+
return "";
|
|
16877
|
+
const mins = Math.round((a.expiresAt - Date.now() / 1000) / 60);
|
|
16878
|
+
return mins > 0 ? ` (token refreshes in ${mins}m)` : " (token expired)";
|
|
16879
|
+
};
|
|
16880
|
+
switch (a?.source) {
|
|
16881
|
+
case "env":
|
|
16882
|
+
return "HONCHO_API_KEY env var";
|
|
16883
|
+
case "oauth":
|
|
16884
|
+
return `signed in with Honcho${expiry()}`;
|
|
16052
16885
|
default:
|
|
16053
|
-
return
|
|
16054
|
-
}
|
|
16055
|
-
}
|
|
16056
|
-
function getSessionName(cwd, instanceId) {
|
|
16057
|
-
const config = loadConfig2();
|
|
16058
|
-
const strategy = config?.sessionStrategy ?? "per-directory";
|
|
16059
|
-
const mainRoot = worktreeMainRootFor(cwd);
|
|
16060
|
-
if (strategy === "per-directory") {
|
|
16061
|
-
const configuredSession = getSessionForPath(cwd, mainRoot);
|
|
16062
|
-
if (configuredSession) {
|
|
16063
|
-
return configuredSession;
|
|
16064
|
-
}
|
|
16065
|
-
}
|
|
16066
|
-
let branch;
|
|
16067
|
-
if (strategy === "git-branch") {
|
|
16068
|
-
branch = captureGitState(cwd)?.branch;
|
|
16886
|
+
return "API key";
|
|
16069
16887
|
}
|
|
16070
|
-
let resolvedInstanceId;
|
|
16071
|
-
if (strategy === "chat-instance") {
|
|
16072
|
-
resolvedInstanceId = instanceId || getInstanceIdForCwd(cwd) || getClaudeInstanceId() || undefined;
|
|
16073
|
-
}
|
|
16074
|
-
return deriveSessionName(strategy, mainRoot ?? cwd, {
|
|
16075
|
-
peerName: config?.peerName,
|
|
16076
|
-
sessionPeerPrefix: config?.sessionPeerPrefix,
|
|
16077
|
-
branch,
|
|
16078
|
-
instanceId: resolvedInstanceId
|
|
16079
|
-
});
|
|
16080
16888
|
}
|
|
16081
|
-
function
|
|
16082
|
-
if (
|
|
16083
|
-
|
|
16084
|
-
return url.endsWith("/v3") ? url : `${url}/v3`;
|
|
16889
|
+
function getAuthNotice(config) {
|
|
16890
|
+
if (config.auth?.reauthRequired) {
|
|
16891
|
+
return "[honcho] Your Honcho sign-in has expired. Run /honcho setup to sign in again.";
|
|
16085
16892
|
}
|
|
16086
|
-
|
|
16087
|
-
return HONCHO_BASE_URLS.local;
|
|
16088
|
-
}
|
|
16089
|
-
return HONCHO_BASE_URLS.production;
|
|
16893
|
+
return;
|
|
16090
16894
|
}
|
|
16091
16895
|
function getHonchoBaseUrl(config) {
|
|
16092
|
-
return
|
|
16896
|
+
return `${config.baseUrl}/v3`;
|
|
16093
16897
|
}
|
|
16094
16898
|
function getTelemetryHeaders(host = getDetectedHost()) {
|
|
16095
16899
|
return telemetryHeaders({
|
|
@@ -16108,34 +16912,121 @@ function getHonchoClientOptions(config) {
|
|
|
16108
16912
|
defaultHeaders: getTelemetryHeaders()
|
|
16109
16913
|
};
|
|
16110
16914
|
}
|
|
16915
|
+
function isProductionEndpoint(config) {
|
|
16916
|
+
return config.baseUrl === DEFAULT_BASE_URL;
|
|
16917
|
+
}
|
|
16111
16918
|
function getEndpointInfo(config) {
|
|
16112
|
-
|
|
16113
|
-
|
|
16919
|
+
return { type: isProductionEndpoint(config) ? "production" : "custom", url: config.baseUrl };
|
|
16920
|
+
}
|
|
16921
|
+
|
|
16922
|
+
// src/cache.ts
|
|
16923
|
+
import { homedir as homedir2 } from "os";
|
|
16924
|
+
import { join as join4 } from "path";
|
|
16925
|
+
var CACHE_DIR = join4(homedir2(), ".honcho");
|
|
16926
|
+
var CONTEXT_CACHE_FILE = join4(CACHE_DIR, "context-cache.json");
|
|
16927
|
+
var CONTEXT_CACHE_KNOWN_KEYS = new Set(["messageCount"]);
|
|
16928
|
+
var MAX_MESSAGE_SIZE = 24000;
|
|
16929
|
+
function chunkContent(content, maxSize = MAX_MESSAGE_SIZE) {
|
|
16930
|
+
if (content.length <= maxSize) {
|
|
16931
|
+
return [content];
|
|
16932
|
+
}
|
|
16933
|
+
const chunks = [];
|
|
16934
|
+
let remaining = content;
|
|
16935
|
+
while (remaining.length > 0) {
|
|
16936
|
+
if (remaining.length <= maxSize) {
|
|
16937
|
+
chunks.push(remaining);
|
|
16938
|
+
break;
|
|
16939
|
+
}
|
|
16940
|
+
let splitIndex = remaining.lastIndexOf(`
|
|
16941
|
+
`, maxSize);
|
|
16942
|
+
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
16943
|
+
splitIndex = remaining.lastIndexOf(" ", maxSize);
|
|
16944
|
+
}
|
|
16945
|
+
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
16946
|
+
splitIndex = maxSize;
|
|
16947
|
+
}
|
|
16948
|
+
chunks.push(remaining.slice(0, splitIndex));
|
|
16949
|
+
remaining = remaining.slice(splitIndex).trimStart();
|
|
16950
|
+
}
|
|
16951
|
+
if (chunks.length > 1) {
|
|
16952
|
+
return chunks.map((chunk, i) => `[Part ${i + 1}/${chunks.length}] ${chunk}`);
|
|
16114
16953
|
}
|
|
16115
|
-
|
|
16116
|
-
|
|
16954
|
+
return chunks;
|
|
16955
|
+
}
|
|
16956
|
+
var HONCHO_MAX_BATCH = 100;
|
|
16957
|
+
async function addMessagesBatched(session, messages, resolveFallback) {
|
|
16958
|
+
let active = session;
|
|
16959
|
+
let usedFallback = false;
|
|
16960
|
+
for (let i = 0;i < messages.length; i += HONCHO_MAX_BATCH) {
|
|
16961
|
+
const batch = messages.slice(i, i + HONCHO_MAX_BATCH);
|
|
16962
|
+
try {
|
|
16963
|
+
await active.addMessages(batch);
|
|
16964
|
+
} catch (e) {
|
|
16965
|
+
if (usedFallback || !resolveFallback)
|
|
16966
|
+
throw e;
|
|
16967
|
+
active = await resolveFallback(e);
|
|
16968
|
+
usedFallback = true;
|
|
16969
|
+
await active.addMessages(batch);
|
|
16970
|
+
}
|
|
16117
16971
|
}
|
|
16118
|
-
return { type: "production", url: HONCHO_BASE_URLS.production };
|
|
16119
16972
|
}
|
|
16120
|
-
|
|
16121
|
-
|
|
16122
|
-
|
|
16973
|
+
|
|
16974
|
+
// src/honcho-client.ts
|
|
16975
|
+
var import_sdk = __toESM(require_dist(), 1);
|
|
16976
|
+
async function createHonchoClient(config, overrides = {}) {
|
|
16977
|
+
await refreshCredential(config);
|
|
16978
|
+
return new import_sdk.Honcho({ ...getHonchoClientOptions(config), ...overrides });
|
|
16123
16979
|
}
|
|
16124
16980
|
|
|
16125
16981
|
// src/skills/transcript-parse.ts
|
|
16126
|
-
import { existsSync as
|
|
16982
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, readdirSync, statSync as statSync2 } from "fs";
|
|
16127
16983
|
import { homedir as homedir3 } from "os";
|
|
16128
|
-
import { join as
|
|
16984
|
+
import { join as join5 } from "path";
|
|
16985
|
+
|
|
16986
|
+
// src/prompt-filters.ts
|
|
16987
|
+
import { existsSync as existsSync4 } from "fs";
|
|
16988
|
+
var HARNESS_INJECTED_PATTERNS = [
|
|
16989
|
+
/^<task-notification(?=[\s/>])/,
|
|
16990
|
+
/^<cross-session-message(?=[\s/>])/,
|
|
16991
|
+
/^<agent-message(?=[\s/>])/,
|
|
16992
|
+
/^<channel(?=[\s/>])/,
|
|
16993
|
+
/^<local-command-caveat(?=[\s/>])/,
|
|
16994
|
+
/^<local-command-stdout>/,
|
|
16995
|
+
/^<command-name>/,
|
|
16996
|
+
/^<command-message>/,
|
|
16997
|
+
/^<system-reminder(?=[\s/>])/,
|
|
16998
|
+
/^<bash-(stdout|stderr|input)>/,
|
|
16999
|
+
/^<<[\w-]+>>$/
|
|
17000
|
+
];
|
|
17001
|
+
var LEADING_REMINDERS = /^(?:\s*<system-reminder(?=[\s>])[^>]*>[\s\S]*?<\/system-reminder>)+\s*/;
|
|
17002
|
+
function stripLeadingReminders(prompt) {
|
|
17003
|
+
return prompt.replace(LEADING_REMINDERS, "");
|
|
17004
|
+
}
|
|
17005
|
+
var SLASH_COMMAND_ENVELOPE = /^<command-(name|message)>/;
|
|
17006
|
+
function isHarnessInjected(prompt) {
|
|
17007
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
17008
|
+
return !trimmed || HARNESS_INJECTED_PATTERNS.some((p) => p.test(trimmed));
|
|
17009
|
+
}
|
|
17010
|
+
var SLASH_COMMAND = /^\/([\w:-]+)(?:\s|$)/;
|
|
17011
|
+
function isSlashCommand(prompt) {
|
|
17012
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
17013
|
+
if (SLASH_COMMAND_ENVELOPE.test(trimmed))
|
|
17014
|
+
return true;
|
|
17015
|
+
const name = SLASH_COMMAND.exec(trimmed)?.[1];
|
|
17016
|
+
if (!name)
|
|
17017
|
+
return false;
|
|
17018
|
+
return name.includes(":") || !existsSync4(`/${name}`);
|
|
17019
|
+
}
|
|
17020
|
+
|
|
17021
|
+
// src/skills/transcript-parse.ts
|
|
16129
17022
|
function entryType(entry) {
|
|
16130
17023
|
return entry.type || entry.role;
|
|
16131
17024
|
}
|
|
16132
17025
|
function isRealUserPrompt(entry) {
|
|
16133
17026
|
if (entry.isMeta)
|
|
16134
17027
|
return false;
|
|
16135
|
-
const
|
|
16136
|
-
|
|
16137
|
-
const trimmed = text.trim();
|
|
16138
|
-
return trimmed.length > 0 && !trimmed.startsWith("<");
|
|
17028
|
+
const text = userText(entry);
|
|
17029
|
+
return !isHarnessInjected(text) && !isSlashCommand(text);
|
|
16139
17030
|
}
|
|
16140
17031
|
function userText(entry) {
|
|
16141
17032
|
const mc = entry.message?.content ?? entry.content;
|
|
@@ -16157,10 +17048,10 @@ function assistantText(entry) {
|
|
|
16157
17048
|
return "";
|
|
16158
17049
|
}
|
|
16159
17050
|
function readLines(transcriptPath) {
|
|
16160
|
-
if (!transcriptPath || !
|
|
17051
|
+
if (!transcriptPath || !existsSync5(transcriptPath))
|
|
16161
17052
|
return [];
|
|
16162
17053
|
try {
|
|
16163
|
-
return
|
|
17054
|
+
return readFileSync4(transcriptPath, "utf-8").split(`
|
|
16164
17055
|
`).filter((line) => line.trim());
|
|
16165
17056
|
} catch {
|
|
16166
17057
|
return [];
|
|
@@ -16168,9 +17059,8 @@ function readLines(transcriptPath) {
|
|
|
16168
17059
|
}
|
|
16169
17060
|
function parseTranscriptForBackfill(transcriptPath) {
|
|
16170
17061
|
const messages = [];
|
|
16171
|
-
let cwd;
|
|
16172
|
-
let gitBranch;
|
|
16173
17062
|
let sessionId;
|
|
17063
|
+
let cwd;
|
|
16174
17064
|
for (const line of readLines(transcriptPath)) {
|
|
16175
17065
|
let entry;
|
|
16176
17066
|
try {
|
|
@@ -16178,26 +17068,24 @@ function parseTranscriptForBackfill(transcriptPath) {
|
|
|
16178
17068
|
} catch {
|
|
16179
17069
|
continue;
|
|
16180
17070
|
}
|
|
16181
|
-
if (entry.cwd)
|
|
16182
|
-
cwd = entry.cwd;
|
|
16183
|
-
if (entry.gitBranch)
|
|
16184
|
-
gitBranch = entry.gitBranch;
|
|
16185
17071
|
if (entry.sessionId)
|
|
16186
17072
|
sessionId = entry.sessionId;
|
|
17073
|
+
if (!cwd && entry.cwd)
|
|
17074
|
+
cwd = entry.cwd;
|
|
16187
17075
|
if (entry.isMeta || entry.isSidechain)
|
|
16188
17076
|
continue;
|
|
16189
17077
|
const type = entryType(entry);
|
|
16190
17078
|
if (type === "user") {
|
|
16191
17079
|
if (!isRealUserPrompt(entry))
|
|
16192
17080
|
continue;
|
|
16193
|
-
const content = userText(entry).trim();
|
|
17081
|
+
const content = stripLeadingReminders(userText(entry)).trim();
|
|
16194
17082
|
if (content) {
|
|
16195
|
-
messages.push({ role: "user", content, timestamp: entry.timestamp
|
|
17083
|
+
messages.push({ role: "user", content, timestamp: entry.timestamp });
|
|
16196
17084
|
}
|
|
16197
17085
|
} else if (type === "assistant") {
|
|
16198
17086
|
const content = assistantText(entry).trim();
|
|
16199
17087
|
if (content) {
|
|
16200
|
-
messages.push({ role: "assistant", content, timestamp: entry.timestamp
|
|
17088
|
+
messages.push({ role: "assistant", content, timestamp: entry.timestamp });
|
|
16201
17089
|
}
|
|
16202
17090
|
}
|
|
16203
17091
|
}
|
|
@@ -16207,16 +17095,16 @@ function parseTranscriptForBackfill(transcriptPath) {
|
|
|
16207
17095
|
const next = messages[i + 1];
|
|
16208
17096
|
messages[i].isResponse = !next || next.role === "user";
|
|
16209
17097
|
}
|
|
16210
|
-
return { messages,
|
|
17098
|
+
return { messages, sessionId, cwd };
|
|
16211
17099
|
}
|
|
16212
|
-
var PROJECTS_DIR =
|
|
17100
|
+
var PROJECTS_DIR = join5(homedir3(), ".claude", "projects");
|
|
16213
17101
|
function findTranscripts(days) {
|
|
16214
|
-
if (!
|
|
17102
|
+
if (!existsSync5(PROJECTS_DIR))
|
|
16215
17103
|
return [];
|
|
16216
17104
|
const cutoff = Date.now() - days * 24 * 60 * 60 * 1000;
|
|
16217
17105
|
const out = [];
|
|
16218
17106
|
for (const dir of readdirSync(PROJECTS_DIR)) {
|
|
16219
|
-
const dirPath =
|
|
17107
|
+
const dirPath = join5(PROJECTS_DIR, dir);
|
|
16220
17108
|
let entries;
|
|
16221
17109
|
try {
|
|
16222
17110
|
if (!statSync2(dirPath).isDirectory())
|
|
@@ -16228,7 +17116,7 @@ function findTranscripts(days) {
|
|
|
16228
17116
|
for (const file of entries) {
|
|
16229
17117
|
if (!file.endsWith(".jsonl"))
|
|
16230
17118
|
continue;
|
|
16231
|
-
const path =
|
|
17119
|
+
const path = join5(dirPath, file);
|
|
16232
17120
|
try {
|
|
16233
17121
|
const st = statSync2(path);
|
|
16234
17122
|
if (st.mtimeMs >= cutoff)
|
|
@@ -16241,6 +17129,29 @@ function findTranscripts(days) {
|
|
|
16241
17129
|
return out;
|
|
16242
17130
|
}
|
|
16243
17131
|
|
|
17132
|
+
// src/git.ts
|
|
17133
|
+
import { execSync } from "child_process";
|
|
17134
|
+
import { hostname } from "os";
|
|
17135
|
+
import { basename, dirname as dirname3, resolve } from "path";
|
|
17136
|
+
function gitCommand(cwd, args) {
|
|
17137
|
+
try {
|
|
17138
|
+
return execSync(`git ${args}`, { cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
17139
|
+
} catch {
|
|
17140
|
+
return null;
|
|
17141
|
+
}
|
|
17142
|
+
}
|
|
17143
|
+
function getRepoName(cwd) {
|
|
17144
|
+
const common = gitCommand(cwd, "rev-parse --git-common-dir");
|
|
17145
|
+
if (!common)
|
|
17146
|
+
return basename(resolve(cwd));
|
|
17147
|
+
const dir = resolve(cwd, common);
|
|
17148
|
+
return basename(dir) === ".git" ? basename(dirname3(dir)) : basename(dir).replace(/\.git$/, "");
|
|
17149
|
+
}
|
|
17150
|
+
function getSessionScopes(cwd) {
|
|
17151
|
+
const scopes = [getRepoName(cwd), hostname().split(".")[0]].map(sanitizeForSessionName).filter((s) => /[a-z0-9]/.test(s));
|
|
17152
|
+
return [...new Set(scopes)];
|
|
17153
|
+
}
|
|
17154
|
+
|
|
16244
17155
|
// src/styles.ts
|
|
16245
17156
|
var colors = {
|
|
16246
17157
|
reset: "\x1B[0m",
|
|
@@ -16298,10 +17209,15 @@ function listItem(text, indent = 0) {
|
|
|
16298
17209
|
const padding = " ".repeat(indent);
|
|
16299
17210
|
return `${padding}${colors.dim}${symbols.bullet}${colors.reset} ${text}`;
|
|
16300
17211
|
}
|
|
17212
|
+
function honchoSessionUrl(config, sessionName) {
|
|
17213
|
+
if (!isProductionEndpoint(config))
|
|
17214
|
+
return null;
|
|
17215
|
+
return `https://app.honcho.dev/explore?workspace=${encodeURIComponent(config.workspace)}&view=sessions&session=${encodeURIComponent(sessionName)}`;
|
|
17216
|
+
}
|
|
16301
17217
|
|
|
16302
17218
|
// src/skills/backfill.ts
|
|
16303
|
-
import { join as
|
|
16304
|
-
import { existsSync as
|
|
17219
|
+
import { join as join6, basename as basename2 } from "path";
|
|
17220
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
16305
17221
|
function parseArgs(argv) {
|
|
16306
17222
|
const args = { days: 30, dryRun: false };
|
|
16307
17223
|
for (let i = 0;i < argv.length; i++) {
|
|
@@ -16319,48 +17235,42 @@ function parseArgs(argv) {
|
|
|
16319
17235
|
}
|
|
16320
17236
|
return args;
|
|
16321
17237
|
}
|
|
16322
|
-
var STATE_FILE =
|
|
17238
|
+
var STATE_FILE = join6(getConfigDir(), "backfill-state.json");
|
|
17239
|
+
function isLiveSession(workspace, sessionName, state = loadState()) {
|
|
17240
|
+
return !!state.live?.[`${workspace}::${sessionName}`];
|
|
17241
|
+
}
|
|
16323
17242
|
function loadState() {
|
|
16324
17243
|
try {
|
|
16325
|
-
return JSON.parse(
|
|
17244
|
+
return JSON.parse(readFileSync5(STATE_FILE, "utf-8"));
|
|
16326
17245
|
} catch {
|
|
16327
17246
|
return { imported: {} };
|
|
16328
17247
|
}
|
|
16329
17248
|
}
|
|
16330
17249
|
function saveState(state) {
|
|
16331
|
-
if (!
|
|
16332
|
-
|
|
16333
|
-
|
|
17250
|
+
if (!existsSync6(getConfigDir()))
|
|
17251
|
+
mkdirSync2(getConfigDir(), { recursive: true });
|
|
17252
|
+
writeFileSync2(STATE_FILE, JSON.stringify(state, null, 2));
|
|
16334
17253
|
}
|
|
16335
|
-
function groupIntoSessions(transcripts
|
|
17254
|
+
function groupIntoSessions(transcripts) {
|
|
16336
17255
|
const groups = new Map;
|
|
16337
17256
|
let parsed = 0;
|
|
16338
17257
|
let empty = 0;
|
|
16339
17258
|
for (const { path } of transcripts) {
|
|
16340
|
-
const { messages,
|
|
17259
|
+
const { messages, sessionId, cwd } = parseTranscriptForBackfill(path);
|
|
16341
17260
|
if (messages.length === 0) {
|
|
16342
17261
|
empty++;
|
|
16343
17262
|
continue;
|
|
16344
17263
|
}
|
|
16345
17264
|
parsed++;
|
|
16346
17265
|
const source = basename2(path);
|
|
16347
|
-
|
|
16348
|
-
|
|
16349
|
-
|
|
16350
|
-
|
|
16351
|
-
|
|
16352
|
-
peerName,
|
|
16353
|
-
sessionPeerPrefix,
|
|
16354
|
-
branch: msg.gitBranch || tBranch,
|
|
16355
|
-
instanceId: sessionId
|
|
16356
|
-
});
|
|
16357
|
-
let group = groups.get(name);
|
|
16358
|
-
if (!group) {
|
|
16359
|
-
group = { name, messages: [] };
|
|
16360
|
-
groups.set(name, group);
|
|
16361
|
-
}
|
|
16362
|
-
group.messages.push({ ...msg, sourceTranscript: source });
|
|
17266
|
+
const name = sanitizeForSessionName(sessionId || basename2(path, ".jsonl"));
|
|
17267
|
+
let group = groups.get(name);
|
|
17268
|
+
if (!group) {
|
|
17269
|
+
group = { name, scopes: cwd ? getSessionScopes(cwd) : [], messages: [] };
|
|
17270
|
+
groups.set(name, group);
|
|
16363
17271
|
}
|
|
17272
|
+
for (const msg of messages)
|
|
17273
|
+
group.messages.push({ ...msg, sourceTranscript: source });
|
|
16364
17274
|
}
|
|
16365
17275
|
return { groups, parsed, empty };
|
|
16366
17276
|
}
|
|
@@ -16372,13 +17282,11 @@ async function run() {
|
|
|
16372
17282
|
console.log("");
|
|
16373
17283
|
const config = loadConfig2();
|
|
16374
17284
|
if (!config) {
|
|
16375
|
-
console.log(warn("No Honcho config found — run /honcho
|
|
17285
|
+
console.log(warn("No Honcho config found — run /honcho setup first."));
|
|
16376
17286
|
process.exit(1);
|
|
16377
17287
|
}
|
|
16378
17288
|
const targetWorkspace = args.workspace || config.workspace;
|
|
16379
|
-
const strategy = config.sessionStrategy ?? "per-directory";
|
|
16380
17289
|
console.log(` ${label("Workspace")}: ${targetWorkspace}${args.workspace ? dim(" (override)") : ""}`);
|
|
16381
|
-
console.log(` ${label("Strategy")}: ${strategy}`);
|
|
16382
17290
|
console.log(` ${label("Window")}: last ${args.days} days`);
|
|
16383
17291
|
console.log(` ${label("User peer")}: ${config.peerName}`);
|
|
16384
17292
|
console.log(` ${label("AI peer")}: ${config.aiPeer}`);
|
|
@@ -16397,9 +17305,20 @@ async function run() {
|
|
|
16397
17305
|
console.log(success("Nothing new to import."));
|
|
16398
17306
|
process.exit(0);
|
|
16399
17307
|
}
|
|
16400
|
-
const { groups, parsed, empty } = groupIntoSessions(todo
|
|
17308
|
+
const { groups, parsed, empty } = groupIntoSessions(todo);
|
|
17309
|
+
const live = [...groups.keys()].filter((name) => isLiveSession(targetWorkspace, name, state));
|
|
17310
|
+
for (const name of live)
|
|
17311
|
+
groups.delete(name);
|
|
16401
17312
|
const totalMessages = [...groups.values()].reduce((n, g) => n + g.messages.length, 0);
|
|
16402
17313
|
console.log(listItem(`${parsed} transcript(s) with content${empty ? dim(` (${empty} empty, skipped)`) : ""}`));
|
|
17314
|
+
if (live.length > 0) {
|
|
17315
|
+
console.log(listItem(dim(`${live.length} chat(s) the plugin already saved as they happened — skipping`)));
|
|
17316
|
+
}
|
|
17317
|
+
if (groups.size === 0) {
|
|
17318
|
+
console.log("");
|
|
17319
|
+
console.log(success("Nothing new to import."));
|
|
17320
|
+
process.exit(0);
|
|
17321
|
+
}
|
|
16403
17322
|
console.log(listItem(`${groups.size} session(s), ${totalMessages} message(s) to upload`));
|
|
16404
17323
|
console.log("");
|
|
16405
17324
|
console.log(section("Sessions"));
|
|
@@ -16414,12 +17333,7 @@ async function run() {
|
|
|
16414
17333
|
console.log(success("Dry run — no messages uploaded."));
|
|
16415
17334
|
process.exit(0);
|
|
16416
17335
|
}
|
|
16417
|
-
const
|
|
16418
|
-
opts.workspaceId = targetWorkspace;
|
|
16419
|
-
opts.timeout = 60000;
|
|
16420
|
-
opts.maxRetries = 3;
|
|
16421
|
-
const honcho = new import_sdk.Honcho(opts);
|
|
16422
|
-
const observationMode = getObservationMode(config);
|
|
17336
|
+
const honcho = await createHonchoClient(config, { workspaceId: targetWorkspace, timeout: 60000, maxRetries: 3 });
|
|
16423
17337
|
console.log(section(`Uploading to ${targetWorkspace}`));
|
|
16424
17338
|
let uploadedSessions = 0;
|
|
16425
17339
|
let uploadedMessages = 0;
|
|
@@ -16427,12 +17341,11 @@ async function run() {
|
|
|
16427
17341
|
for (const g of sorted) {
|
|
16428
17342
|
try {
|
|
16429
17343
|
const [session, userPeer, aiPeer] = await Promise.all([
|
|
16430
|
-
honcho.session(g.name),
|
|
17344
|
+
g.scopes.length ? honcho.session(g.name, { scopes: g.scopes }) : honcho.session(g.name),
|
|
16431
17345
|
honcho.peer(config.peerName),
|
|
16432
17346
|
honcho.peer(config.aiPeer)
|
|
16433
17347
|
]);
|
|
16434
|
-
|
|
16435
|
-
await session.addPeers(peers);
|
|
17348
|
+
await session.addPeers([userPeer, aiPeer]);
|
|
16436
17349
|
const fallbackTs = new Date().toISOString();
|
|
16437
17350
|
const messages = g.messages.flatMap((m) => {
|
|
16438
17351
|
const peer = m.role === "user" ? userPeer : aiPeer;
|
|
@@ -16441,7 +17354,6 @@ async function run() {
|
|
|
16441
17354
|
metadata: {
|
|
16442
17355
|
backfill: true,
|
|
16443
17356
|
source_transcript: m.sourceTranscript,
|
|
16444
|
-
session_affinity: g.name,
|
|
16445
17357
|
type: m.role === "assistant" ? m.isResponse ? "assistant_response" : "assistant_intermediate" : undefined
|
|
16446
17358
|
}
|
|
16447
17359
|
}));
|
|
@@ -16457,10 +17369,11 @@ async function run() {
|
|
|
16457
17369
|
}
|
|
16458
17370
|
}
|
|
16459
17371
|
if (errors.length === 0) {
|
|
17372
|
+
const latest = loadState();
|
|
16460
17373
|
for (const t of todo) {
|
|
16461
|
-
|
|
17374
|
+
latest.imported[`${targetWorkspace}::${t.path}`] = t.mtimeMs;
|
|
16462
17375
|
}
|
|
16463
|
-
saveState(
|
|
17376
|
+
saveState(latest);
|
|
16464
17377
|
}
|
|
16465
17378
|
console.log("");
|
|
16466
17379
|
console.log(success(`Imported ${uploadedMessages} message(s) across ${uploadedSessions} session(s) into ${targetWorkspace}.`));
|
|
@@ -16481,5 +17394,5 @@ async function main() {
|
|
|
16481
17394
|
// src/skills/backfill-runner.ts
|
|
16482
17395
|
await main();
|
|
16483
17396
|
|
|
16484
|
-
//# debugId=
|
|
17397
|
+
//# debugId=159D55DF562158D764756E2164756E21
|
|
16485
17398
|
//# sourceMappingURL=backfill-runner.js.map
|