@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
|
@@ -36,8 +36,9 @@ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports,
|
|
|
36
36
|
// node_modules/@honcho-ai/sdk/dist/api-version.js
|
|
37
37
|
var require_api_version = __commonJS(function(exports) {
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.API_VERSION = undefined;
|
|
39
|
+
exports.VERSION = exports.API_VERSION = undefined;
|
|
40
40
|
exports.API_VERSION = "v3";
|
|
41
|
+
exports.VERSION = "2.9.0";
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
// node_modules/@honcho-ai/sdk/dist/http/errors.js
|
|
@@ -162,255 +163,6 @@ var require_errors = __commonJS(function(exports) {
|
|
|
162
163
|
}
|
|
163
164
|
});
|
|
164
165
|
|
|
165
|
-
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
166
|
-
var require_client = __commonJS(function(exports) {
|
|
167
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
168
|
-
exports.HonchoHTTPClient = undefined;
|
|
169
|
-
var errors_1 = require_errors();
|
|
170
|
-
var DEFAULT_TIMEOUT = 60000;
|
|
171
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
172
|
-
var RETRY_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
173
|
-
var INITIAL_RETRY_DELAY = 500;
|
|
174
|
-
|
|
175
|
-
class HonchoHTTPClient {
|
|
176
|
-
constructor(config) {
|
|
177
|
-
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
178
|
-
this.apiKey = config.apiKey;
|
|
179
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
180
|
-
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
181
|
-
this.defaultHeaders = {
|
|
182
|
-
"Content-Type": "application/json",
|
|
183
|
-
...config.defaultHeaders
|
|
184
|
-
};
|
|
185
|
-
this.defaultQuery = config.defaultQuery;
|
|
186
|
-
}
|
|
187
|
-
async request(method, path, options = {}) {
|
|
188
|
-
const url = this.buildURL(path, options.query);
|
|
189
|
-
const headers = this.buildHeaders(options.headers);
|
|
190
|
-
const timeout = options.timeout ?? this.timeout;
|
|
191
|
-
let lastError;
|
|
192
|
-
let attempt = 0;
|
|
193
|
-
while (attempt <= this.maxRetries) {
|
|
194
|
-
try {
|
|
195
|
-
const response = await this.fetchWithTimeout(url, {
|
|
196
|
-
method,
|
|
197
|
-
headers,
|
|
198
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
199
|
-
signal: options.signal
|
|
200
|
-
}, timeout);
|
|
201
|
-
if (response.ok) {
|
|
202
|
-
const text = await response.text();
|
|
203
|
-
if (!text) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
return JSON.parse(text);
|
|
207
|
-
}
|
|
208
|
-
const errorBody = await this.parseErrorBody(response);
|
|
209
|
-
const retryAfter = this.parseRetryAfter(response);
|
|
210
|
-
const error = (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody, retryAfter);
|
|
211
|
-
if (RETRY_STATUS_CODES.includes(response.status) && attempt < this.maxRetries) {
|
|
212
|
-
lastError = error;
|
|
213
|
-
await this.sleep(this.getRetryDelay(attempt, retryAfter));
|
|
214
|
-
attempt++;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
throw error;
|
|
218
|
-
} catch (error) {
|
|
219
|
-
if (error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
220
|
-
if (attempt < this.maxRetries) {
|
|
221
|
-
lastError = error;
|
|
222
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
223
|
-
attempt++;
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (error instanceof errors_1.RateLimitError || error instanceof errors_1.ServerError || error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
228
|
-
throw error;
|
|
229
|
-
}
|
|
230
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
231
|
-
const connError = new errors_1.ConnectionError(error.message);
|
|
232
|
-
if (attempt < this.maxRetries) {
|
|
233
|
-
lastError = connError;
|
|
234
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
235
|
-
attempt++;
|
|
236
|
-
continue;
|
|
237
|
-
}
|
|
238
|
-
throw connError;
|
|
239
|
-
}
|
|
240
|
-
throw error;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
throw lastError || new Error("Request failed after retries");
|
|
244
|
-
}
|
|
245
|
-
async get(path, options) {
|
|
246
|
-
return this.request("GET", path, options);
|
|
247
|
-
}
|
|
248
|
-
async post(path, options) {
|
|
249
|
-
return this.request("POST", path, options);
|
|
250
|
-
}
|
|
251
|
-
async put(path, options) {
|
|
252
|
-
return this.request("PUT", path, options);
|
|
253
|
-
}
|
|
254
|
-
async patch(path, options) {
|
|
255
|
-
return this.request("PATCH", path, options);
|
|
256
|
-
}
|
|
257
|
-
async delete(path, options) {
|
|
258
|
-
return this.request("DELETE", path, options);
|
|
259
|
-
}
|
|
260
|
-
async stream(method, path, options = {}) {
|
|
261
|
-
const url = this.buildURL(path, options.query);
|
|
262
|
-
const headers = {
|
|
263
|
-
...this.buildHeaders(options.headers),
|
|
264
|
-
Accept: "text/event-stream"
|
|
265
|
-
};
|
|
266
|
-
const timeout = options.timeout ?? this.timeout;
|
|
267
|
-
const response = await this.fetchWithTimeout(url, {
|
|
268
|
-
method,
|
|
269
|
-
headers,
|
|
270
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
271
|
-
signal: options.signal
|
|
272
|
-
}, timeout);
|
|
273
|
-
if (!response.ok) {
|
|
274
|
-
const errorBody = await this.parseErrorBody(response);
|
|
275
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
276
|
-
}
|
|
277
|
-
return response;
|
|
278
|
-
}
|
|
279
|
-
async upload(path, formData, options = {}) {
|
|
280
|
-
const url = this.buildURL(path, options.query);
|
|
281
|
-
const headers = {};
|
|
282
|
-
if (this.apiKey) {
|
|
283
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
284
|
-
}
|
|
285
|
-
if (options.headers) {
|
|
286
|
-
Object.assign(headers, options.headers);
|
|
287
|
-
}
|
|
288
|
-
const timeout = options.timeout ?? this.timeout;
|
|
289
|
-
const response = await this.fetchWithTimeout(url, {
|
|
290
|
-
method: "POST",
|
|
291
|
-
headers,
|
|
292
|
-
body: formData,
|
|
293
|
-
signal: options.signal
|
|
294
|
-
}, timeout);
|
|
295
|
-
if (!response.ok) {
|
|
296
|
-
const errorBody = await this.parseErrorBody(response);
|
|
297
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
298
|
-
}
|
|
299
|
-
const text = await response.text();
|
|
300
|
-
if (!text) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
return JSON.parse(text);
|
|
304
|
-
}
|
|
305
|
-
buildURL(path, query) {
|
|
306
|
-
const url = new URL(path, this.baseURL);
|
|
307
|
-
const mergedQuery = {
|
|
308
|
-
...this.defaultQuery ?? {},
|
|
309
|
-
...query ?? {}
|
|
310
|
-
};
|
|
311
|
-
for (const [key, value] of Object.entries(mergedQuery)) {
|
|
312
|
-
if (value !== undefined) {
|
|
313
|
-
url.searchParams.set(key, String(value));
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
return url.toString();
|
|
317
|
-
}
|
|
318
|
-
buildHeaders(extra) {
|
|
319
|
-
const headers = { ...this.defaultHeaders };
|
|
320
|
-
if (this.apiKey) {
|
|
321
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
322
|
-
}
|
|
323
|
-
if (extra) {
|
|
324
|
-
Object.assign(headers, extra);
|
|
325
|
-
}
|
|
326
|
-
return headers;
|
|
327
|
-
}
|
|
328
|
-
async fetchWithTimeout(url, init, timeout) {
|
|
329
|
-
const controller = new AbortController;
|
|
330
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
331
|
-
if (init.signal) {
|
|
332
|
-
init.signal.addEventListener("abort", () => controller.abort());
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
const response = await fetch(url, {
|
|
336
|
-
...init,
|
|
337
|
-
signal: controller.signal
|
|
338
|
-
});
|
|
339
|
-
return response;
|
|
340
|
-
} catch (error) {
|
|
341
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
342
|
-
throw new errors_1.TimeoutError(`Request timed out after ${timeout}ms`);
|
|
343
|
-
}
|
|
344
|
-
throw error;
|
|
345
|
-
} finally {
|
|
346
|
-
clearTimeout(timeoutId);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
async parseErrorBody(response) {
|
|
350
|
-
try {
|
|
351
|
-
const body = await response.json();
|
|
352
|
-
return {
|
|
353
|
-
message: body.detail || body.message || body.error,
|
|
354
|
-
...body
|
|
355
|
-
};
|
|
356
|
-
} catch {
|
|
357
|
-
return { message: `HTTP ${response.status}` };
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
parseRetryAfter(response) {
|
|
361
|
-
const header = response.headers.get("Retry-After");
|
|
362
|
-
if (!header)
|
|
363
|
-
return;
|
|
364
|
-
const seconds = Number.parseInt(header, 10);
|
|
365
|
-
if (!Number.isNaN(seconds)) {
|
|
366
|
-
return seconds * 1000;
|
|
367
|
-
}
|
|
368
|
-
const date = Date.parse(header);
|
|
369
|
-
if (!Number.isNaN(date)) {
|
|
370
|
-
return Math.max(0, date - Date.now());
|
|
371
|
-
}
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
getRetryDelay(attempt, retryAfter) {
|
|
375
|
-
if (retryAfter) {
|
|
376
|
-
return retryAfter;
|
|
377
|
-
}
|
|
378
|
-
return INITIAL_RETRY_DELAY * 2 ** attempt;
|
|
379
|
-
}
|
|
380
|
-
sleep(ms) {
|
|
381
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
exports.HonchoHTTPClient = HonchoHTTPClient;
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// node_modules/@honcho-ai/sdk/dist/message.js
|
|
388
|
-
var require_message = __commonJS(function(exports) {
|
|
389
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
390
|
-
exports.Message = undefined;
|
|
391
|
-
|
|
392
|
-
class Message {
|
|
393
|
-
constructor(id, content, peerId, sessionId, workspaceId, metadata, createdAt, tokenCount) {
|
|
394
|
-
this.id = id;
|
|
395
|
-
this.content = content;
|
|
396
|
-
this.peerId = peerId;
|
|
397
|
-
this.sessionId = sessionId;
|
|
398
|
-
this.workspaceId = workspaceId;
|
|
399
|
-
this.metadata = metadata;
|
|
400
|
-
this.createdAt = createdAt;
|
|
401
|
-
this.tokenCount = tokenCount;
|
|
402
|
-
}
|
|
403
|
-
static fromApiResponse(data) {
|
|
404
|
-
return new Message(data.id, data.content, data.peer_id, data.session_id, data.workspace_id, data.metadata, data.created_at, data.token_count);
|
|
405
|
-
}
|
|
406
|
-
toString() {
|
|
407
|
-
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
408
|
-
return `Message(id='${this.id}', peerId='${this.peerId}', content='${truncatedContent}')`;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
exports.Message = Message;
|
|
412
|
-
});
|
|
413
|
-
|
|
414
166
|
// node_modules/@honcho-ai/sdk/dist/pagination.js
|
|
415
167
|
var require_pagination = __commonJS(function(exports) {
|
|
416
168
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -13690,9 +13442,10 @@ var require_zod = __commonJS(function(exports) {
|
|
|
13690
13442
|
// node_modules/@honcho-ai/sdk/dist/validation.js
|
|
13691
13443
|
var require_validation = __commonJS(function(exports) {
|
|
13692
13444
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13693
|
-
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;
|
|
13694
13446
|
exports.normalizeSearchQuery = normalizeSearchQuery;
|
|
13695
13447
|
exports.normalizeListOptions = normalizeListOptions;
|
|
13448
|
+
exports.scopeRecallFields = scopeRecallFields;
|
|
13696
13449
|
exports.peerConfigToApi = peerConfigToApi;
|
|
13697
13450
|
exports.peerConfigFromApi = peerConfigFromApi;
|
|
13698
13451
|
exports.workspaceConfigToApi = workspaceConfigToApi;
|
|
@@ -13702,7 +13455,7 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13702
13455
|
exports.messageConfigToApi = messageConfigToApi;
|
|
13703
13456
|
exports.messageConfigFromApi = messageConfigFromApi;
|
|
13704
13457
|
var zod_1 = require_zod();
|
|
13705
|
-
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");
|
|
13706
13459
|
exports.HonchoConfigSchema = zod_1.z.object({
|
|
13707
13460
|
apiKey: zod_1.z.string().optional(),
|
|
13708
13461
|
environment: zod_1.z.enum(["local", "production"]).optional(),
|
|
@@ -13717,7 +13470,7 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13717
13470
|
exports.PeerConfigSchema = zod_1.z.object({
|
|
13718
13471
|
observeMe: zod_1.z.boolean().nullable().optional()
|
|
13719
13472
|
}).strict();
|
|
13720
|
-
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");
|
|
13721
13474
|
var PeerIdObjectSchema = zod_1.z.object({ id: exports.PeerIdSchema });
|
|
13722
13475
|
exports.SessionMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
13723
13476
|
exports.ReasoningConfigSchema = zod_1.z.object({
|
|
@@ -13726,32 +13479,92 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13726
13479
|
}).strict();
|
|
13727
13480
|
exports.PeerCardConfigSchema = zod_1.z.object({
|
|
13728
13481
|
use: zod_1.z.boolean().nullable().optional(),
|
|
13729
|
-
create: zod_1.z.boolean().nullable().optional()
|
|
13482
|
+
create: zod_1.z.boolean().nullable().optional(),
|
|
13483
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
13730
13484
|
}).strict();
|
|
13731
13485
|
exports.SummaryConfigSchema = zod_1.z.object({
|
|
13732
13486
|
enabled: zod_1.z.boolean().nullable().optional(),
|
|
13733
13487
|
messagesPerShortSummary: zod_1.z.number().int().min(10).nullable().optional(),
|
|
13734
|
-
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()
|
|
13735
13490
|
}).strict();
|
|
13736
13491
|
exports.DreamConfigSchema = zod_1.z.object({
|
|
13737
|
-
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()
|
|
13738
13497
|
}).strict();
|
|
13739
13498
|
exports.SessionConfigSchema = zod_1.z.object({
|
|
13499
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
13740
13500
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
13741
13501
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
13742
13502
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
13743
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
13503
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
13504
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
13744
13505
|
}).strict();
|
|
13745
|
-
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");
|
|
13746
13507
|
var SessionIdObjectSchema = zod_1.z.object({ id: exports.SessionIdSchema });
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
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()
|
|
13755
13568
|
}).strict().nullable().optional();
|
|
13756
13569
|
exports.MessageInputSchema = zod_1.z.object({
|
|
13757
13570
|
peerId: exports.PeerIdSchema,
|
|
@@ -13791,12 +13604,41 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13791
13604
|
}
|
|
13792
13605
|
return { filters: input };
|
|
13793
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
|
+
}
|
|
13794
13632
|
exports.ChatQuerySchema = zod_1.z.object({
|
|
13795
13633
|
query: exports.SearchQuerySchema,
|
|
13796
13634
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
13797
13635
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
13798
|
-
|
|
13799
|
-
|
|
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);
|
|
13800
13642
|
exports.RepresentationOptionsSchema = zod_1.z.object({
|
|
13801
13643
|
searchQuery: exports.SearchQueryLikeSchema.optional(),
|
|
13802
13644
|
searchTopK: zod_1.z.number().int().min(1, "searchTopK must be at least 1").max(100, "searchTopK must be at most 100").optional(),
|
|
@@ -13809,9 +13651,32 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13809
13651
|
tokens: zod_1.z.int("Token limit must be an integer").optional(),
|
|
13810
13652
|
peerTarget: exports.PeerIdSchema.optional(),
|
|
13811
13653
|
peerPerspective: exports.PeerIdSchema.optional(),
|
|
13654
|
+
scope: exports.ScopeIdSchema.optional(),
|
|
13655
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
13812
13656
|
limitToSession: zod_1.z.boolean().optional(),
|
|
13813
13657
|
representationOptions: exports.RepresentationOptionsSchema.optional()
|
|
13814
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
|
+
}
|
|
13815
13680
|
if (data.representationOptions?.searchQuery && !data.peerTarget) {
|
|
13816
13681
|
ctx.addIssue({
|
|
13817
13682
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -13826,6 +13691,20 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13826
13691
|
path: ["peerPerspective"]
|
|
13827
13692
|
});
|
|
13828
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
|
+
}
|
|
13829
13708
|
});
|
|
13830
13709
|
exports.QueueStatusOptionsSchema = zod_1.z.object({
|
|
13831
13710
|
observer: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
@@ -13854,9 +13733,11 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13854
13733
|
}).strict();
|
|
13855
13734
|
exports.PeerGetRepresentationParamsSchema = zod_1.z.object({
|
|
13856
13735
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional(),
|
|
13736
|
+
scope: exports.ScopeOptionSchema.optional(),
|
|
13737
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
13857
13738
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
13858
13739
|
options: exports.RepresentationOptionsSchema.optional()
|
|
13859
|
-
}).strict();
|
|
13740
|
+
}).strict().superRefine(scopeExclusivityIssues);
|
|
13860
13741
|
exports.CardTargetSchema = zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined);
|
|
13861
13742
|
exports.PeerCardContentSchema = zod_1.z.array(zod_1.z.string());
|
|
13862
13743
|
exports.PeerAdditionSchema = zod_1.z.union([
|
|
@@ -13917,7 +13798,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13917
13798
|
return;
|
|
13918
13799
|
return {
|
|
13919
13800
|
use: config.use,
|
|
13920
|
-
create: config.create
|
|
13801
|
+
create: config.create,
|
|
13802
|
+
custom_instructions: config.customInstructions
|
|
13921
13803
|
};
|
|
13922
13804
|
}
|
|
13923
13805
|
function peerCardConfigFromApi(config) {
|
|
@@ -13927,7 +13809,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13927
13809
|
return;
|
|
13928
13810
|
return {
|
|
13929
13811
|
use: config.use,
|
|
13930
|
-
create: config.create
|
|
13812
|
+
create: config.create,
|
|
13813
|
+
customInstructions: config.custom_instructions
|
|
13931
13814
|
};
|
|
13932
13815
|
}
|
|
13933
13816
|
function summaryConfigToApi(config) {
|
|
@@ -13938,7 +13821,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13938
13821
|
return {
|
|
13939
13822
|
enabled: config.enabled,
|
|
13940
13823
|
messages_per_short_summary: config.messagesPerShortSummary,
|
|
13941
|
-
messages_per_long_summary: config.messagesPerLongSummary
|
|
13824
|
+
messages_per_long_summary: config.messagesPerLongSummary,
|
|
13825
|
+
custom_instructions: config.customInstructions
|
|
13942
13826
|
};
|
|
13943
13827
|
}
|
|
13944
13828
|
function summaryConfigFromApi(config) {
|
|
@@ -13949,7 +13833,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13949
13833
|
return {
|
|
13950
13834
|
enabled: config.enabled,
|
|
13951
13835
|
messagesPerShortSummary: config.messages_per_short_summary,
|
|
13952
|
-
messagesPerLongSummary: config.messages_per_long_summary
|
|
13836
|
+
messagesPerLongSummary: config.messages_per_long_summary,
|
|
13837
|
+
customInstructions: config.custom_instructions
|
|
13953
13838
|
};
|
|
13954
13839
|
}
|
|
13955
13840
|
function dreamConfigToApi(config) {
|
|
@@ -13958,7 +13843,8 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13958
13843
|
if (config === undefined)
|
|
13959
13844
|
return;
|
|
13960
13845
|
return {
|
|
13961
|
-
enabled: config.enabled
|
|
13846
|
+
enabled: config.enabled,
|
|
13847
|
+
custom_instructions: config.customInstructions
|
|
13962
13848
|
};
|
|
13963
13849
|
}
|
|
13964
13850
|
function dreamConfigFromApi(config) {
|
|
@@ -13967,17 +13853,38 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13967
13853
|
if (config === undefined)
|
|
13968
13854
|
return;
|
|
13969
13855
|
return {
|
|
13970
|
-
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
|
|
13971
13876
|
};
|
|
13972
13877
|
}
|
|
13973
13878
|
function workspaceConfigToApi(config) {
|
|
13974
13879
|
if (!config)
|
|
13975
13880
|
return;
|
|
13976
13881
|
return {
|
|
13882
|
+
custom_instructions: config.customInstructions,
|
|
13977
13883
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
13978
13884
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
13979
13885
|
summary: summaryConfigToApi(config.summary),
|
|
13980
|
-
dream: dreamConfigToApi(config.dream)
|
|
13886
|
+
dream: dreamConfigToApi(config.dream),
|
|
13887
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
13981
13888
|
};
|
|
13982
13889
|
}
|
|
13983
13890
|
function workspaceConfigFromApi(config) {
|
|
@@ -13985,20 +13892,24 @@ var require_validation = __commonJS(function(exports) {
|
|
|
13985
13892
|
return;
|
|
13986
13893
|
const apiConfig = config;
|
|
13987
13894
|
return {
|
|
13895
|
+
customInstructions: apiConfig.custom_instructions,
|
|
13988
13896
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
13989
13897
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
13990
13898
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
13991
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
13899
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
13900
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
13992
13901
|
};
|
|
13993
13902
|
}
|
|
13994
13903
|
function sessionConfigToApi(config) {
|
|
13995
13904
|
if (!config)
|
|
13996
13905
|
return;
|
|
13997
13906
|
return {
|
|
13907
|
+
custom_instructions: config.customInstructions,
|
|
13998
13908
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
13999
13909
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
14000
13910
|
summary: summaryConfigToApi(config.summary),
|
|
14001
|
-
dream: dreamConfigToApi(config.dream)
|
|
13911
|
+
dream: dreamConfigToApi(config.dream),
|
|
13912
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
14002
13913
|
};
|
|
14003
13914
|
}
|
|
14004
13915
|
function sessionConfigFromApi(config) {
|
|
@@ -14006,10 +13917,12 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14006
13917
|
return;
|
|
14007
13918
|
const apiConfig = config;
|
|
14008
13919
|
return {
|
|
13920
|
+
customInstructions: apiConfig.custom_instructions,
|
|
14009
13921
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
14010
13922
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
14011
13923
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
14012
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
13924
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
13925
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
14013
13926
|
};
|
|
14014
13927
|
}
|
|
14015
13928
|
function messageConfigToApi(config) {
|
|
@@ -14081,10 +13994,12 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14081
13994
|
});
|
|
14082
13995
|
exports.WorkspaceMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
14083
13996
|
exports.WorkspaceConfigSchema = zod_1.z.object({
|
|
13997
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
14084
13998
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
14085
13999
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
14086
14000
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
14087
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
14001
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
14002
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
14088
14003
|
}).strict();
|
|
14089
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");
|
|
14090
14005
|
exports.ConclusionQueryParamsSchema = zod_1.z.object({
|
|
@@ -14098,22 +14013,46 @@ var require_validation = __commonJS(function(exports) {
|
|
|
14098
14013
|
// node_modules/@honcho-ai/sdk/dist/conclusions.js
|
|
14099
14014
|
var require_conclusions = __commonJS(function(exports) {
|
|
14100
14015
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14101
|
-
exports.
|
|
14016
|
+
exports.WorkspaceConclusions = exports.ConclusionsView = exports.Conclusion = undefined;
|
|
14102
14017
|
var api_version_1 = require_api_version();
|
|
14018
|
+
var errors_1 = require_errors();
|
|
14103
14019
|
var pagination_1 = require_pagination();
|
|
14104
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
|
+
}
|
|
14105
14040
|
|
|
14106
14041
|
class Conclusion {
|
|
14107
|
-
constructor(id, content, observerId, observedId, sessionId, createdAt) {
|
|
14042
|
+
constructor(id, content, observerId, observedId, sessionId, createdAt, level = "explicit", sourceIds = null, timesDerived = 1, sourceMessageIds = null) {
|
|
14108
14043
|
this.id = id;
|
|
14109
14044
|
this.content = content;
|
|
14110
14045
|
this.observerId = observerId;
|
|
14111
14046
|
this.observedId = observedId;
|
|
14112
14047
|
this.sessionId = sessionId;
|
|
14048
|
+
this.level = level;
|
|
14049
|
+
this.sourceIds = sourceIds;
|
|
14050
|
+
this.timesDerived = timesDerived;
|
|
14051
|
+
this.sourceMessageIds = sourceMessageIds;
|
|
14113
14052
|
this.createdAt = createdAt;
|
|
14114
14053
|
}
|
|
14115
14054
|
static fromApiResponse(data) {
|
|
14116
|
-
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);
|
|
14117
14056
|
}
|
|
14118
14057
|
toString() {
|
|
14119
14058
|
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
@@ -14122,7 +14061,7 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14122
14061
|
}
|
|
14123
14062
|
exports.Conclusion = Conclusion;
|
|
14124
14063
|
|
|
14125
|
-
class
|
|
14064
|
+
class ConclusionsView {
|
|
14126
14065
|
constructor(http, workspaceId, observer, observed, ensureWorkspace = async () => {
|
|
14127
14066
|
return;
|
|
14128
14067
|
}) {
|
|
@@ -14151,6 +14090,26 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14151
14090
|
await this._ensureWorkspace();
|
|
14152
14091
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions`, { body: params });
|
|
14153
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
|
+
}
|
|
14154
14113
|
async _delete(conclusionId) {
|
|
14155
14114
|
await this._ensureWorkspace();
|
|
14156
14115
|
await this._http.delete(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
@@ -14160,14 +14119,18 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14160
14119
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${peerId}/representation`, { body: params });
|
|
14161
14120
|
}
|
|
14162
14121
|
async list(options) {
|
|
14122
|
+
rejectReservedFilterKeys(options?.filters, [
|
|
14123
|
+
...VIEW_RESERVED_KEYS,
|
|
14124
|
+
"session",
|
|
14125
|
+
"session_id"
|
|
14126
|
+
]);
|
|
14163
14127
|
const resolvedSessionId = options?.session ? typeof options.session === "string" ? options.session : options.session.id : undefined;
|
|
14164
14128
|
const filters = {
|
|
14165
14129
|
observer_id: this.observer,
|
|
14166
|
-
observed_id: this.observed
|
|
14130
|
+
observed_id: this.observed,
|
|
14131
|
+
...resolvedSessionId ? { session_id: resolvedSessionId } : {},
|
|
14132
|
+
...options?.filters
|
|
14167
14133
|
};
|
|
14168
|
-
if (resolvedSessionId) {
|
|
14169
|
-
filters.session_id = resolvedSessionId;
|
|
14170
|
-
}
|
|
14171
14134
|
const reverse = options?.reverse;
|
|
14172
14135
|
const response = await this._list({
|
|
14173
14136
|
filters,
|
|
@@ -14180,19 +14143,55 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14180
14143
|
};
|
|
14181
14144
|
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
14182
14145
|
}
|
|
14183
|
-
async query(query, topK = 10, distance) {
|
|
14184
|
-
|
|
14185
|
-
observer_id: this.observer,
|
|
14186
|
-
observed_id: this.observed
|
|
14187
|
-
};
|
|
14146
|
+
async query(query, topK = 10, distance, filters) {
|
|
14147
|
+
rejectReservedFilterKeys(filters, VIEW_RESERVED_KEYS);
|
|
14188
14148
|
const response = await this._query({
|
|
14189
14149
|
query,
|
|
14190
14150
|
top_k: topK,
|
|
14191
14151
|
distance,
|
|
14192
|
-
filters
|
|
14152
|
+
filters: {
|
|
14153
|
+
observer_id: this.observer,
|
|
14154
|
+
observed_id: this.observed,
|
|
14155
|
+
...filters
|
|
14156
|
+
}
|
|
14193
14157
|
});
|
|
14194
14158
|
return (response ?? []).map((item) => Conclusion.fromApiResponse(item));
|
|
14195
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
|
+
}
|
|
14196
14195
|
async delete(conclusionId) {
|
|
14197
14196
|
await this._delete(conclusionId);
|
|
14198
14197
|
}
|
|
@@ -14227,129 +14226,452 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
14227
14226
|
return response.representation;
|
|
14228
14227
|
}
|
|
14229
14228
|
toString() {
|
|
14230
|
-
return `
|
|
14231
|
-
}
|
|
14232
|
-
}
|
|
14233
|
-
exports.ConclusionScope = ConclusionScope;
|
|
14234
|
-
});
|
|
14235
|
-
|
|
14236
|
-
// node_modules/@honcho-ai/sdk/dist/http/streaming.js
|
|
14237
|
-
var require_streaming = __commonJS(function(exports) {
|
|
14238
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14239
|
-
exports.DialecticStreamResponse = undefined;
|
|
14240
|
-
exports.parseSSE = parseSSE;
|
|
14241
|
-
exports.createDialecticStream = createDialecticStream;
|
|
14242
|
-
async function* parseSSE(response) {
|
|
14243
|
-
if (!response.body) {
|
|
14244
|
-
throw new Error("Response body is null");
|
|
14245
|
-
}
|
|
14246
|
-
const reader = response.body.getReader();
|
|
14247
|
-
const decoder = new TextDecoder;
|
|
14248
|
-
let buffer = "";
|
|
14249
|
-
try {
|
|
14250
|
-
while (true) {
|
|
14251
|
-
const { done, value } = await reader.read();
|
|
14252
|
-
if (done)
|
|
14253
|
-
break;
|
|
14254
|
-
buffer += decoder.decode(value, { stream: true });
|
|
14255
|
-
const lines = buffer.split(`
|
|
14256
|
-
`);
|
|
14257
|
-
buffer = lines.pop() || "";
|
|
14258
|
-
for (const line of lines) {
|
|
14259
|
-
if (line.startsWith("data: ")) {
|
|
14260
|
-
const jsonStr = line.slice(6);
|
|
14261
|
-
if (jsonStr.trim() === "[DONE]") {
|
|
14262
|
-
return;
|
|
14263
|
-
}
|
|
14264
|
-
try {
|
|
14265
|
-
const data = JSON.parse(jsonStr);
|
|
14266
|
-
yield data;
|
|
14267
|
-
} catch {}
|
|
14268
|
-
}
|
|
14269
|
-
}
|
|
14270
|
-
}
|
|
14271
|
-
if (buffer.startsWith("data: ")) {
|
|
14272
|
-
const jsonStr = buffer.slice(6);
|
|
14273
|
-
if (jsonStr.trim() !== "[DONE]") {
|
|
14274
|
-
try {
|
|
14275
|
-
const data = JSON.parse(jsonStr);
|
|
14276
|
-
yield data;
|
|
14277
|
-
} catch {}
|
|
14278
|
-
}
|
|
14279
|
-
}
|
|
14280
|
-
} finally {
|
|
14281
|
-
reader.releaseLock();
|
|
14229
|
+
return `ConclusionsView(workspaceId='${this.workspaceId}', observer='${this.observer}', observed='${this.observed}')`;
|
|
14282
14230
|
}
|
|
14283
14231
|
}
|
|
14232
|
+
exports.ConclusionsView = ConclusionsView;
|
|
14284
14233
|
|
|
14285
|
-
class
|
|
14286
|
-
constructor(
|
|
14287
|
-
|
|
14288
|
-
|
|
14289
|
-
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;
|
|
14290
14241
|
}
|
|
14291
|
-
async
|
|
14292
|
-
|
|
14293
|
-
|
|
14294
|
-
|
|
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
|
|
14295
14250
|
}
|
|
14296
|
-
|
|
14297
|
-
}
|
|
14298
|
-
for await (const chunk of this.generator) {
|
|
14299
|
-
this.chunks.push(chunk);
|
|
14300
|
-
yield chunk;
|
|
14301
|
-
}
|
|
14302
|
-
this.consumed = true;
|
|
14251
|
+
});
|
|
14303
14252
|
}
|
|
14304
|
-
async
|
|
14305
|
-
|
|
14306
|
-
|
|
14307
|
-
|
|
14308
|
-
|
|
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);
|
|
14309
14266
|
}
|
|
14310
|
-
async
|
|
14311
|
-
|
|
14312
|
-
|
|
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)));
|
|
14313
14284
|
}
|
|
14314
|
-
return
|
|
14285
|
+
return conclusions;
|
|
14315
14286
|
}
|
|
14316
|
-
|
|
14317
|
-
|
|
14318
|
-
function createDialecticStream(response) {
|
|
14319
|
-
async function* streamContent() {
|
|
14320
|
-
for await (const chunk of parseSSE(response)) {
|
|
14321
|
-
if (chunk.done) {
|
|
14322
|
-
return;
|
|
14323
|
-
}
|
|
14324
|
-
const content = chunk.delta?.content;
|
|
14325
|
-
if (content) {
|
|
14326
|
-
yield content;
|
|
14327
|
-
}
|
|
14328
|
-
}
|
|
14287
|
+
toString() {
|
|
14288
|
+
return `WorkspaceConclusions(workspaceId='${this.workspaceId}')`;
|
|
14329
14289
|
}
|
|
14330
|
-
return new DialecticStreamResponse(streamContent());
|
|
14331
14290
|
}
|
|
14291
|
+
exports.WorkspaceConclusions = WorkspaceConclusions;
|
|
14332
14292
|
});
|
|
14333
14293
|
|
|
14334
|
-
// node_modules/@honcho-ai/sdk/dist/
|
|
14335
|
-
var
|
|
14294
|
+
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
14295
|
+
var require_client = __commonJS(function(exports) {
|
|
14336
14296
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14337
|
-
exports.
|
|
14338
|
-
|
|
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
|
+
}
|
|
14339
14311
|
|
|
14340
|
-
class
|
|
14341
|
-
constructor(
|
|
14342
|
-
this.
|
|
14343
|
-
this.
|
|
14344
|
-
this.
|
|
14345
|
-
this.
|
|
14346
|
-
this.
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
|
|
14352
|
-
|
|
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,
|
|
14353
14675
|
createdAt: data.created_at,
|
|
14354
14676
|
tokenCount: data.token_count
|
|
14355
14677
|
});
|
|
@@ -14505,12 +14827,18 @@ var require_session = __commonJS(function(exports) {
|
|
|
14505
14827
|
get createdAt() {
|
|
14506
14828
|
return this._createdAt;
|
|
14507
14829
|
}
|
|
14830
|
+
get uid() {
|
|
14831
|
+
return this._uid;
|
|
14832
|
+
}
|
|
14508
14833
|
get isActive() {
|
|
14509
14834
|
return this._isActive;
|
|
14510
14835
|
}
|
|
14836
|
+
get scopes() {
|
|
14837
|
+
return this._scopes;
|
|
14838
|
+
}
|
|
14511
14839
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
14512
14840
|
return;
|
|
14513
|
-
}, createdAt, isActive) {
|
|
14841
|
+
}, createdAt, isActive, uid, scopes) {
|
|
14514
14842
|
this.id = id;
|
|
14515
14843
|
this.workspaceId = workspaceId;
|
|
14516
14844
|
this._http = http;
|
|
@@ -14519,12 +14847,15 @@ var require_session = __commonJS(function(exports) {
|
|
|
14519
14847
|
this._ensureWorkspace = ensureWorkspace;
|
|
14520
14848
|
this._createdAt = createdAt;
|
|
14521
14849
|
this._isActive = isActive;
|
|
14850
|
+
this._uid = uid;
|
|
14851
|
+
this._scopes = scopes;
|
|
14522
14852
|
}
|
|
14523
14853
|
_applySessionResponse(session) {
|
|
14524
14854
|
this._metadata = session.metadata || {};
|
|
14525
14855
|
this._configuration = (0, validation_1.sessionConfigFromApi)(session.configuration) || {};
|
|
14526
14856
|
this._createdAt = session.created_at;
|
|
14527
14857
|
this._isActive = session.is_active;
|
|
14858
|
+
this._uid = session.uid;
|
|
14528
14859
|
}
|
|
14529
14860
|
async _getOrCreate(params) {
|
|
14530
14861
|
await this._ensureWorkspace();
|
|
@@ -14648,7 +14979,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14648
14979
|
}
|
|
14649
14980
|
async peers() {
|
|
14650
14981
|
const peersPage = await this._listPeers();
|
|
14651
|
-
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));
|
|
14652
14983
|
}
|
|
14653
14984
|
async getPeerConfiguration(peer) {
|
|
14654
14985
|
const peerId = typeof peer === "string" ? peer : peer.id;
|
|
@@ -14732,7 +15063,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14732
15063
|
}
|
|
14733
15064
|
async clone(messageId) {
|
|
14734
15065
|
const clonedSessionData = await this._clone(messageId ? { message_id: messageId } : undefined);
|
|
14735
|
-
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);
|
|
14736
15067
|
}
|
|
14737
15068
|
async context(options) {
|
|
14738
15069
|
const opts = options || {};
|
|
@@ -14744,6 +15075,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
14744
15075
|
tokens: opts.tokens,
|
|
14745
15076
|
peerTarget: peerTargetId,
|
|
14746
15077
|
peerPerspective: peerPerspectiveId,
|
|
15078
|
+
scope: opts.scope !== undefined ? (0, utils_1.resolveId)(opts.scope) : undefined,
|
|
15079
|
+
sessions: opts.sessions,
|
|
14747
15080
|
limitToSession: opts.limitToSession,
|
|
14748
15081
|
representationOptions: opts.representationOptions ? {
|
|
14749
15082
|
...opts.representationOptions,
|
|
@@ -14756,6 +15089,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
14756
15089
|
search_query: searchQuery,
|
|
14757
15090
|
peer_target: contextParams.peerTarget,
|
|
14758
15091
|
peer_perspective: contextParams.peerPerspective,
|
|
15092
|
+
scope: contextParams.scope,
|
|
15093
|
+
sessions: contextParams.sessions,
|
|
14759
15094
|
limit_to_session: contextParams.limitToSession,
|
|
14760
15095
|
search_top_k: contextParams.representationOptions?.searchTopK,
|
|
14761
15096
|
search_max_distance: contextParams.representationOptions?.searchMaxDistance,
|
|
@@ -14872,6 +15207,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
14872
15207
|
var require_peer = __commonJS(function(exports) {
|
|
14873
15208
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14874
15209
|
exports.Peer = exports.PeerContext = undefined;
|
|
15210
|
+
var zod_1 = require_zod();
|
|
14875
15211
|
var api_version_1 = require_api_version();
|
|
14876
15212
|
var conclusions_1 = require_conclusions();
|
|
14877
15213
|
var streaming_1 = require_streaming();
|
|
@@ -14906,9 +15242,12 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14906
15242
|
get createdAt() {
|
|
14907
15243
|
return this._createdAt;
|
|
14908
15244
|
}
|
|
15245
|
+
get uid() {
|
|
15246
|
+
return this._uid;
|
|
15247
|
+
}
|
|
14909
15248
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
14910
15249
|
return;
|
|
14911
|
-
}, createdAt) {
|
|
15250
|
+
}, createdAt, uid) {
|
|
14912
15251
|
this.id = id;
|
|
14913
15252
|
this.workspaceId = workspaceId;
|
|
14914
15253
|
this._http = http;
|
|
@@ -14916,6 +15255,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14916
15255
|
this._configuration = configuration;
|
|
14917
15256
|
this._ensureWorkspace = ensureWorkspace;
|
|
14918
15257
|
this._createdAt = createdAt;
|
|
15258
|
+
this._uid = uid;
|
|
14919
15259
|
}
|
|
14920
15260
|
async _getOrCreate(params) {
|
|
14921
15261
|
await this._ensureWorkspace();
|
|
@@ -14936,6 +15276,15 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14936
15276
|
}
|
|
14937
15277
|
});
|
|
14938
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
|
+
}
|
|
14939
15288
|
async _chat(params) {
|
|
14940
15289
|
await this._ensureWorkspace();
|
|
14941
15290
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${this.id}/chat`, { body: params });
|
|
@@ -14977,19 +15326,28 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14977
15326
|
query,
|
|
14978
15327
|
target: targetId,
|
|
14979
15328
|
session: resolvedSessionId,
|
|
14980
|
-
|
|
15329
|
+
scope: options?.scope,
|
|
15330
|
+
sessions: options?.sessions,
|
|
15331
|
+
reasoningLevel: options?.reasoningLevel,
|
|
15332
|
+
responseFormat: options?.responseFormat,
|
|
15333
|
+
includeEvidence: options?.includeEvidence
|
|
14981
15334
|
});
|
|
15335
|
+
const zodSchema = options?.responseFormat instanceof zod_1.ZodType ? options.responseFormat : undefined;
|
|
14982
15336
|
const response = await this._chat({
|
|
14983
15337
|
query: chatParams.query,
|
|
14984
15338
|
stream: false,
|
|
14985
15339
|
target: chatParams.target,
|
|
14986
15340
|
session_id: chatParams.session,
|
|
14987
|
-
|
|
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
|
|
14988
15345
|
});
|
|
14989
|
-
|
|
14990
|
-
|
|
15346
|
+
const content = response.content ? zodSchema ? zodSchema.parse(JSON.parse(response.content)) : response.content : null;
|
|
15347
|
+
if (!chatParams.includeEvidence) {
|
|
15348
|
+
return content;
|
|
14991
15349
|
}
|
|
14992
|
-
return response.
|
|
15350
|
+
return { content, evidence: response.evidence ?? null };
|
|
14993
15351
|
}
|
|
14994
15352
|
async chatStream(query, options) {
|
|
14995
15353
|
const targetId = options?.target ? typeof options.target === "string" ? options.target : options.target.id : undefined;
|
|
@@ -14998,13 +15356,20 @@ var require_peer = __commonJS(function(exports) {
|
|
|
14998
15356
|
query,
|
|
14999
15357
|
target: targetId,
|
|
15000
15358
|
session: resolvedSessionId,
|
|
15001
|
-
|
|
15359
|
+
scope: options?.scope,
|
|
15360
|
+
sessions: options?.sessions,
|
|
15361
|
+
reasoningLevel: options?.reasoningLevel,
|
|
15362
|
+
responseFormat: options?.responseFormat,
|
|
15363
|
+
includeEvidence: options?.includeEvidence
|
|
15002
15364
|
});
|
|
15003
15365
|
const response = await this._chatStream({
|
|
15004
15366
|
query: chatParams.query,
|
|
15005
15367
|
target: chatParams.target,
|
|
15006
15368
|
session_id: chatParams.session,
|
|
15007
|
-
|
|
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
|
|
15008
15373
|
});
|
|
15009
15374
|
return (0, streaming_1.createDialecticStream)(response);
|
|
15010
15375
|
}
|
|
@@ -15031,7 +15396,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15031
15396
|
reverse
|
|
15032
15397
|
});
|
|
15033
15398
|
};
|
|
15034
|
-
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);
|
|
15035
15400
|
}
|
|
15036
15401
|
message(content, options) {
|
|
15037
15402
|
const validatedContent = validation_1.MessageContentSchema.parse(content);
|
|
@@ -15050,6 +15415,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15050
15415
|
const peer = await this._getOrCreate({ id: this.id });
|
|
15051
15416
|
this._metadata = peer.metadata || {};
|
|
15052
15417
|
this._createdAt = peer.created_at;
|
|
15418
|
+
this._uid = peer.uid;
|
|
15053
15419
|
return this._metadata;
|
|
15054
15420
|
}
|
|
15055
15421
|
async setMetadata(metadata) {
|
|
@@ -15061,6 +15427,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15061
15427
|
const peer = await this._getOrCreate({ id: this.id });
|
|
15062
15428
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
15063
15429
|
this._createdAt = peer.created_at;
|
|
15430
|
+
this._uid = peer.uid;
|
|
15064
15431
|
return this._configuration;
|
|
15065
15432
|
}
|
|
15066
15433
|
async setConfiguration(configuration) {
|
|
@@ -15073,6 +15440,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15073
15440
|
this._metadata = peer.metadata || {};
|
|
15074
15441
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
15075
15442
|
this._createdAt = peer.created_at;
|
|
15443
|
+
this._uid = peer.uid;
|
|
15076
15444
|
}
|
|
15077
15445
|
async search(query, options) {
|
|
15078
15446
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
@@ -15108,6 +15476,8 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15108
15476
|
const searchQuery = (0, validation_1.normalizeSearchQuery)(options?.searchQuery);
|
|
15109
15477
|
const getRepresentationParams = validation_1.PeerGetRepresentationParamsSchema.parse({
|
|
15110
15478
|
session: options?.session,
|
|
15479
|
+
scope: options?.scope,
|
|
15480
|
+
sessions: options?.sessions,
|
|
15111
15481
|
target: options?.target,
|
|
15112
15482
|
options: {
|
|
15113
15483
|
searchQuery,
|
|
@@ -15121,6 +15491,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15121
15491
|
const targetId = getRepresentationParams.target ? typeof getRepresentationParams.target === "string" ? getRepresentationParams.target : getRepresentationParams.target.id : undefined;
|
|
15122
15492
|
const response = await this._getRepresentation({
|
|
15123
15493
|
session_id: sessionId,
|
|
15494
|
+
...(0, validation_1.scopeRecallFields)(getRepresentationParams),
|
|
15124
15495
|
target: targetId,
|
|
15125
15496
|
search_query: searchQuery,
|
|
15126
15497
|
search_top_k: getRepresentationParams.options?.searchTopK,
|
|
@@ -15151,11 +15522,11 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15151
15522
|
return PeerContext.fromApiResponse(response);
|
|
15152
15523
|
}
|
|
15153
15524
|
get conclusions() {
|
|
15154
|
-
return new conclusions_1.
|
|
15525
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, this.id, () => this._ensureWorkspace());
|
|
15155
15526
|
}
|
|
15156
15527
|
conclusionsOf(target) {
|
|
15157
15528
|
const targetId = typeof target === "string" ? target : target.id;
|
|
15158
|
-
return new conclusions_1.
|
|
15529
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, targetId, () => this._ensureWorkspace());
|
|
15159
15530
|
}
|
|
15160
15531
|
toString() {
|
|
15161
15532
|
return `Peer(id='${this.id}')`;
|
|
@@ -15164,15 +15535,125 @@ var require_peer = __commonJS(function(exports) {
|
|
|
15164
15535
|
exports.Peer = Peer;
|
|
15165
15536
|
});
|
|
15166
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
|
+
|
|
15167
15645
|
// node_modules/@honcho-ai/sdk/dist/client.js
|
|
15168
15646
|
var require_client2 = __commonJS(function(exports) {
|
|
15169
15647
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15170
15648
|
exports.Honcho = undefined;
|
|
15171
15649
|
var api_version_1 = require_api_version();
|
|
15650
|
+
var conclusions_1 = require_conclusions();
|
|
15172
15651
|
var client_1 = require_client();
|
|
15652
|
+
var streaming_1 = require_streaming();
|
|
15173
15653
|
var message_1 = require_message();
|
|
15174
15654
|
var pagination_1 = require_pagination();
|
|
15175
15655
|
var peer_1 = require_peer();
|
|
15656
|
+
var scope_1 = require_scope();
|
|
15176
15657
|
var session_1 = require_session();
|
|
15177
15658
|
var utils_1 = require_utils();
|
|
15178
15659
|
var validation_1 = require_validation();
|
|
@@ -15185,9 +15666,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15185
15666
|
get configuration() {
|
|
15186
15667
|
return this._configuration;
|
|
15187
15668
|
}
|
|
15669
|
+
get uid() {
|
|
15670
|
+
return this._uid;
|
|
15671
|
+
}
|
|
15188
15672
|
get http() {
|
|
15189
15673
|
return this._http;
|
|
15190
15674
|
}
|
|
15675
|
+
get conclusions() {
|
|
15676
|
+
return new conclusions_1.WorkspaceConclusions(this._http, this.workspaceId, () => this._ensureWorkspace());
|
|
15677
|
+
}
|
|
15191
15678
|
get baseURL() {
|
|
15192
15679
|
return this._http.baseURL;
|
|
15193
15680
|
}
|
|
@@ -15210,13 +15697,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15210
15697
|
});
|
|
15211
15698
|
}
|
|
15212
15699
|
async _getOrCreateWorkspace(id, params) {
|
|
15213
|
-
|
|
15700
|
+
const workspace = await this._http.post(`/${api_version_1.API_VERSION}/workspaces`, {
|
|
15214
15701
|
body: {
|
|
15215
15702
|
id,
|
|
15216
15703
|
metadata: params?.metadata,
|
|
15217
15704
|
configuration: (0, validation_1.workspaceConfigToApi)(params?.configuration)
|
|
15218
15705
|
}
|
|
15219
15706
|
});
|
|
15707
|
+
this._uid = workspace.uid;
|
|
15708
|
+
return workspace;
|
|
15220
15709
|
}
|
|
15221
15710
|
async _ensureWorkspace() {
|
|
15222
15711
|
if (!this._workspaceReady) {
|
|
@@ -15244,7 +15733,8 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15244
15733
|
},
|
|
15245
15734
|
query: {
|
|
15246
15735
|
page: params?.page,
|
|
15247
|
-
size: params?.size
|
|
15736
|
+
size: params?.size,
|
|
15737
|
+
reverse: params?.reverse ? "true" : undefined
|
|
15248
15738
|
}
|
|
15249
15739
|
});
|
|
15250
15740
|
}
|
|
@@ -15274,13 +15764,35 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15274
15764
|
async _getOrCreatePeer(workspaceId, params) {
|
|
15275
15765
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/peers`, { body: params });
|
|
15276
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
|
+
}
|
|
15277
15784
|
async _listSessions(workspaceId, params) {
|
|
15278
15785
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/sessions/list`, {
|
|
15279
|
-
body: {
|
|
15786
|
+
body: {
|
|
15787
|
+
filters: params?.filters,
|
|
15788
|
+
scope: params?.scope,
|
|
15789
|
+
in_no_scope: params?.inNoScope ? true : undefined
|
|
15790
|
+
},
|
|
15280
15791
|
query: {
|
|
15281
15792
|
page: params?.page,
|
|
15282
15793
|
size: params?.size,
|
|
15283
|
-
reverse: params?.reverse ? "true" : undefined
|
|
15794
|
+
reverse: params?.reverse ? "true" : undefined,
|
|
15795
|
+
include_scopes: params?.includeScopes ? "true" : undefined
|
|
15284
15796
|
}
|
|
15285
15797
|
});
|
|
15286
15798
|
}
|
|
@@ -15289,7 +15801,22 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15289
15801
|
body: {
|
|
15290
15802
|
id: params.id,
|
|
15291
15803
|
metadata: params.metadata,
|
|
15292
|
-
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
|
|
15293
15820
|
}
|
|
15294
15821
|
});
|
|
15295
15822
|
}
|
|
@@ -15303,7 +15830,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15303
15830
|
configuration: (0, validation_1.peerConfigToApi)(validatedConfiguration),
|
|
15304
15831
|
metadata: validatedMetadata
|
|
15305
15832
|
});
|
|
15306
|
-
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);
|
|
15307
15834
|
}
|
|
15308
15835
|
async peers(options) {
|
|
15309
15836
|
await this._ensureWorkspace();
|
|
@@ -15329,19 +15856,55 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15329
15856
|
reverse
|
|
15330
15857
|
});
|
|
15331
15858
|
};
|
|
15332
|
-
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);
|
|
15333
15860
|
}
|
|
15334
15861
|
async session(id, options) {
|
|
15335
15862
|
await this._ensureWorkspace();
|
|
15336
15863
|
const validatedId = validation_1.SessionIdSchema.parse(id);
|
|
15337
15864
|
const validatedMetadata = options?.metadata ? validation_1.SessionMetadataSchema.parse(options.metadata) : undefined;
|
|
15338
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;
|
|
15339
15868
|
const sessionData = await this._getOrCreateSession(this.workspaceId, {
|
|
15340
15869
|
id: validatedId,
|
|
15341
15870
|
configuration: validatedConfiguration,
|
|
15342
|
-
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
|
|
15343
15903
|
});
|
|
15344
|
-
|
|
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);
|
|
15345
15908
|
}
|
|
15346
15909
|
async sessions(options) {
|
|
15347
15910
|
await this._ensureWorkspace();
|
|
@@ -15349,25 +15912,32 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15349
15912
|
"filters",
|
|
15350
15913
|
"page",
|
|
15351
15914
|
"size",
|
|
15352
|
-
"reverse"
|
|
15915
|
+
"reverse",
|
|
15916
|
+
"scope",
|
|
15917
|
+
"inNoScope",
|
|
15918
|
+
"includeScopes"
|
|
15353
15919
|
]);
|
|
15354
15920
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
15355
|
-
const
|
|
15356
|
-
const sessionsPage = await this._listSessions(this.workspaceId, {
|
|
15921
|
+
const listOptions = {
|
|
15357
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,
|
|
15358
15930
|
page: normalizedOptions.page,
|
|
15359
|
-
size: normalizedOptions.size
|
|
15360
|
-
reverse
|
|
15931
|
+
size: normalizedOptions.size
|
|
15361
15932
|
});
|
|
15362
15933
|
const fetchNextPage = async (page, size) => {
|
|
15363
15934
|
return this._listSessions(this.workspaceId, {
|
|
15364
|
-
|
|
15935
|
+
...listOptions,
|
|
15365
15936
|
page,
|
|
15366
|
-
size
|
|
15367
|
-
reverse
|
|
15937
|
+
size
|
|
15368
15938
|
});
|
|
15369
15939
|
};
|
|
15370
|
-
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);
|
|
15371
15941
|
}
|
|
15372
15942
|
async getMetadata() {
|
|
15373
15943
|
await this._ensureWorkspace();
|
|
@@ -15407,19 +15977,23 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15407
15977
|
const normalizedOptions = (0, validation_1.normalizeListOptions)(options, [
|
|
15408
15978
|
"filters",
|
|
15409
15979
|
"page",
|
|
15410
|
-
"size"
|
|
15980
|
+
"size",
|
|
15981
|
+
"reverse"
|
|
15411
15982
|
]);
|
|
15412
15983
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
15984
|
+
const reverse = normalizedOptions.reverse;
|
|
15413
15985
|
const workspacesPage = await this._listWorkspaces({
|
|
15414
15986
|
filters: validatedFilter,
|
|
15415
15987
|
page: normalizedOptions.page,
|
|
15416
|
-
size: normalizedOptions.size
|
|
15988
|
+
size: normalizedOptions.size,
|
|
15989
|
+
reverse
|
|
15417
15990
|
});
|
|
15418
15991
|
const fetchNextPage = async (page, size) => {
|
|
15419
15992
|
return this._listWorkspaces({
|
|
15420
15993
|
filters: validatedFilter,
|
|
15421
15994
|
page,
|
|
15422
|
-
size
|
|
15995
|
+
size,
|
|
15996
|
+
reverse
|
|
15423
15997
|
});
|
|
15424
15998
|
};
|
|
15425
15999
|
return new pagination_1.Page(workspacesPage, (workspace) => workspace.id, fetchNextPage);
|
|
@@ -15431,14 +16005,47 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15431
16005
|
await this._ensureWorkspace();
|
|
15432
16006
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
15433
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;
|
|
15434
16009
|
const validatedLimit = options?.limit ? validation_1.LimitSchema.parse(options.limit) : undefined;
|
|
15435
16010
|
const response = await this._searchWorkspace(this.workspaceId, {
|
|
15436
16011
|
query: validatedQuery,
|
|
15437
16012
|
filters: validatedFilters,
|
|
16013
|
+
scope: validatedScope,
|
|
15438
16014
|
limit: validatedLimit
|
|
15439
16015
|
});
|
|
15440
16016
|
return response.map(message_1.Message.fromApiResponse);
|
|
15441
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
|
+
}
|
|
15442
16049
|
async queueStatus(options) {
|
|
15443
16050
|
await this._ensureWorkspace();
|
|
15444
16051
|
const observerId = options?.observer ? (0, utils_1.resolveId)(options.observer) : undefined;
|
|
@@ -15468,6 +16075,20 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15468
16075
|
}
|
|
15469
16076
|
});
|
|
15470
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
|
+
}
|
|
15471
16092
|
toString() {
|
|
15472
16093
|
return `Honcho(workspaceId='${this.workspaceId}', baseURL='${this._http.baseURL}')`;
|
|
15473
16094
|
}
|
|
@@ -15478,7 +16099,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
15478
16099
|
// node_modules/@honcho-ai/sdk/dist/index.js
|
|
15479
16100
|
var require_dist = __commonJS(function(exports) {
|
|
15480
16101
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15481
|
-
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;
|
|
15482
16103
|
var client_1 = require_client2();
|
|
15483
16104
|
Object.defineProperty(exports, "Honcho", { enumerable: true, get: function() {
|
|
15484
16105
|
return client_1.Honcho;
|
|
@@ -15488,7 +16109,13 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15488
16109
|
return conclusions_1.Conclusion;
|
|
15489
16110
|
} });
|
|
15490
16111
|
Object.defineProperty(exports, "ConclusionScope", { enumerable: true, get: function() {
|
|
15491
|
-
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;
|
|
15492
16119
|
} });
|
|
15493
16120
|
var errors_1 = require_errors();
|
|
15494
16121
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function() {
|
|
@@ -15543,6 +16170,10 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15543
16170
|
Object.defineProperty(exports, "PeerContext", { enumerable: true, get: function() {
|
|
15544
16171
|
return peer_1.PeerContext;
|
|
15545
16172
|
} });
|
|
16173
|
+
var scope_1 = require_scope();
|
|
16174
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
|
|
16175
|
+
return scope_1.Scope;
|
|
16176
|
+
} });
|
|
15546
16177
|
var session_1 = require_session();
|
|
15547
16178
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function() {
|
|
15548
16179
|
return session_1.Session;
|
|
@@ -15559,133 +16190,510 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15559
16190
|
} });
|
|
15560
16191
|
});
|
|
15561
16192
|
|
|
15562
|
-
// src/skills/
|
|
15563
|
-
var
|
|
16193
|
+
// src/skills/pane.ts
|
|
16194
|
+
var import_sdk2 = __toESM(require_dist(), 1);
|
|
15564
16195
|
|
|
15565
16196
|
// src/config.ts
|
|
15566
|
-
import {
|
|
15567
|
-
import { join as join3, basename, dirname, resolve, sep } from "path";
|
|
16197
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
15568
16198
|
import { fileURLToPath } from "url";
|
|
15569
|
-
import { existsSync as existsSync3,
|
|
16199
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
16200
|
+
|
|
16201
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
16202
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
16203
|
+
import { homedir } from "node:os";
|
|
16204
|
+
import { join as join2 } from "node:path";
|
|
16205
|
+
|
|
16206
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/v01.js
|
|
16207
|
+
var isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16208
|
+
var str = (v) => typeof v === "string" && v ? v : undefined;
|
|
16209
|
+
function v01Reader(file, host) {
|
|
16210
|
+
const hosts = isObj(file.hosts) ? file.hosts : {};
|
|
16211
|
+
const v1 = typeof file.schemaVersion === "number" && file.schemaVersion >= 1;
|
|
16212
|
+
const pick = (b) => {
|
|
16213
|
+
const o = isObj(b) ? b : {};
|
|
16214
|
+
if (v1)
|
|
16215
|
+
return { apiKey: isObj(o.auth) ? str(o.auth.apiKey) : undefined, peerName: str(o.peerName), workspace: str(o.workspace), baseUrl: str(o.baseUrl) };
|
|
16216
|
+
return {
|
|
16217
|
+
apiKey: (isObj(o.auth) ? str(o.auth.apiKey) : undefined) ?? str(o.apiKey),
|
|
16218
|
+
peerName: str(o.peerName),
|
|
16219
|
+
workspace: str(o.workspace) ?? str(o.workspaceId),
|
|
16220
|
+
baseUrl: str(o.baseUrl) ?? str(o.environmentUrl) ?? (isObj(o.endpoint) ? str(o.endpoint.baseUrl) : undefined)
|
|
16221
|
+
};
|
|
16222
|
+
};
|
|
16223
|
+
const own = pick(hosts[host]);
|
|
16224
|
+
const top = pick(file);
|
|
16225
|
+
return {
|
|
16226
|
+
apiKey: own.apiKey ?? top.apiKey,
|
|
16227
|
+
peerName: own.peerName ?? top.peerName,
|
|
16228
|
+
workspace: own.workspace ?? top.workspace,
|
|
16229
|
+
aiPeer: isObj(hosts[host]) ? str(hosts[host].aiPeer) : undefined,
|
|
16230
|
+
baseUrl: own.baseUrl ?? top.baseUrl
|
|
16231
|
+
};
|
|
16232
|
+
}
|
|
15570
16233
|
|
|
15571
|
-
//
|
|
15572
|
-
import {
|
|
15573
|
-
import {
|
|
15574
|
-
|
|
15575
|
-
|
|
15576
|
-
|
|
16234
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/oauth.js
|
|
16235
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
16236
|
+
import { dirname, join } from "node:path";
|
|
16237
|
+
var OAUTH_DEVICE_URL = "https://api.honcho.dev/oauth/device_authorization";
|
|
16238
|
+
var OAUTH_TOKEN_URL = "https://api.honcho.dev/oauth/token";
|
|
16239
|
+
var OAUTH_SCOPE = "write";
|
|
16240
|
+
var DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
16241
|
+
var SLOW_DOWN_STEP_S = 5;
|
|
16242
|
+
var DEFAULT_DEVICE_EXPIRES_S = 600;
|
|
16243
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
16244
|
+
var REFRESH_SKEW_S = 60;
|
|
16245
|
+
var LOCK_STALE_MS = REQUEST_TIMEOUT_MS + 5000;
|
|
16246
|
+
var LOCK_WAIT_MS = LOCK_STALE_MS + 5000;
|
|
16247
|
+
var PERMANENT_ERRORS = new Set(["invalid_grant", "invalid_client", "unauthorized_client"]);
|
|
16248
|
+
|
|
16249
|
+
class OAuthError extends Error {
|
|
16250
|
+
code;
|
|
16251
|
+
constructor(code, description) {
|
|
16252
|
+
super(description || code);
|
|
16253
|
+
this.code = code;
|
|
16254
|
+
this.name = "OAuthError";
|
|
16255
|
+
}
|
|
16256
|
+
}
|
|
16257
|
+
function isCloud(baseUrl) {
|
|
16258
|
+
return normalizeBaseUrl(baseUrl || DEFAULT_BASE_URL) === DEFAULT_BASE_URL;
|
|
16259
|
+
}
|
|
16260
|
+
function accessValid(t, skewS = REFRESH_SKEW_S, nowS = Date.now() / 1000) {
|
|
16261
|
+
return !!t?.accessToken && nowS < t.accessExpiresAt - skewS;
|
|
16262
|
+
}
|
|
16263
|
+
async function post(url, form, t) {
|
|
16264
|
+
const f = t?.fetch ?? fetch;
|
|
16265
|
+
let res;
|
|
16266
|
+
try {
|
|
16267
|
+
res = await f(url, {
|
|
16268
|
+
method: "POST",
|
|
16269
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
16270
|
+
body: new URLSearchParams(form).toString(),
|
|
16271
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
16272
|
+
});
|
|
16273
|
+
} catch (e) {
|
|
16274
|
+
throw new OAuthError("connection_error", `could not reach ${url}: ${e.message}`);
|
|
16275
|
+
}
|
|
16276
|
+
let body = null;
|
|
16277
|
+
try {
|
|
16278
|
+
body = await res.json();
|
|
16279
|
+
} catch {
|
|
16280
|
+
body = null;
|
|
16281
|
+
}
|
|
16282
|
+
return { status: res.status, body };
|
|
16283
|
+
}
|
|
16284
|
+
function errorOf(r) {
|
|
16285
|
+
const b = r.body;
|
|
16286
|
+
if (b && typeof b === "object" && typeof b.error === "string")
|
|
16287
|
+
return new OAuthError(b.error, b.error_description);
|
|
16288
|
+
return new OAuthError("invalid_response");
|
|
16289
|
+
}
|
|
16290
|
+
function tokensFrom(body, clientId, prev) {
|
|
16291
|
+
if (!body || typeof body.access_token !== "string" || !Number.isFinite(Number(body.expires_in))) {
|
|
16292
|
+
throw new OAuthError("invalid_response", "malformed token response");
|
|
16293
|
+
}
|
|
16294
|
+
return {
|
|
16295
|
+
accessToken: body.access_token,
|
|
16296
|
+
refreshToken: body.refresh_token || prev?.refreshToken || "",
|
|
16297
|
+
accessExpiresAt: Math.floor(Date.now() / 1000) + Number(body.expires_in),
|
|
16298
|
+
clientId,
|
|
16299
|
+
scope: body.scope || prev?.scope || OAUTH_SCOPE
|
|
16300
|
+
};
|
|
16301
|
+
}
|
|
16302
|
+
async function requestDeviceCode(opts) {
|
|
16303
|
+
const r = await post(opts.deviceUrl ?? OAUTH_DEVICE_URL, { client_id: opts.clientId, scope: OAUTH_SCOPE, source: opts.source }, opts);
|
|
16304
|
+
if (r.status !== 200)
|
|
16305
|
+
throw errorOf(r);
|
|
16306
|
+
const b = r.body;
|
|
16307
|
+
if (!b?.device_code || !b?.user_code || !b?.verification_uri) {
|
|
16308
|
+
throw new OAuthError("invalid_response", "malformed device authorization response");
|
|
16309
|
+
}
|
|
16310
|
+
return {
|
|
16311
|
+
deviceCode: b.device_code,
|
|
16312
|
+
userCode: b.user_code,
|
|
16313
|
+
verificationUri: b.verification_uri,
|
|
16314
|
+
verificationUriComplete: b.verification_uri_complete || b.verification_uri,
|
|
16315
|
+
expiresIn: Number(b.expires_in) > 0 ? Number(b.expires_in) : DEFAULT_DEVICE_EXPIRES_S,
|
|
16316
|
+
interval: Number(b.interval) || 5
|
|
16317
|
+
};
|
|
15577
16318
|
}
|
|
15578
|
-
function
|
|
16319
|
+
async function pollForToken(device, opts) {
|
|
16320
|
+
const clientId = opts.clientId;
|
|
16321
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
16322
|
+
const deadline = Date.now() + device.expiresIn * 1000;
|
|
16323
|
+
let interval = device.interval;
|
|
16324
|
+
while (true) {
|
|
16325
|
+
if (Date.now() >= deadline)
|
|
16326
|
+
throw new OAuthError("expired_token", "timed out waiting for approval");
|
|
16327
|
+
await sleep(interval * 1000);
|
|
16328
|
+
let r;
|
|
16329
|
+
try {
|
|
16330
|
+
r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: DEVICE_GRANT_TYPE, device_code: device.deviceCode, client_id: clientId }, opts);
|
|
16331
|
+
} catch (e) {
|
|
16332
|
+
if (e instanceof OAuthError && e.code === "connection_error")
|
|
16333
|
+
continue;
|
|
16334
|
+
throw e;
|
|
16335
|
+
}
|
|
16336
|
+
if (r.status === 200)
|
|
16337
|
+
return tokensFrom(r.body, clientId);
|
|
16338
|
+
if (r.status >= 500)
|
|
16339
|
+
continue;
|
|
16340
|
+
const err = errorOf(r);
|
|
16341
|
+
if (err.code === "authorization_pending")
|
|
16342
|
+
continue;
|
|
16343
|
+
if (err.code === "slow_down") {
|
|
16344
|
+
interval += SLOW_DOWN_STEP_S;
|
|
16345
|
+
continue;
|
|
16346
|
+
}
|
|
16347
|
+
throw err;
|
|
16348
|
+
}
|
|
16349
|
+
}
|
|
16350
|
+
async function refreshAccessToken(prev, opts = {}) {
|
|
16351
|
+
const r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: "refresh_token", refresh_token: prev.refreshToken, client_id: prev.clientId }, opts);
|
|
16352
|
+
if (r.status !== 200)
|
|
16353
|
+
throw errorOf(r);
|
|
16354
|
+
return tokensFrom(r.body, prev.clientId, prev);
|
|
16355
|
+
}
|
|
16356
|
+
function isObj2(v) {
|
|
16357
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16358
|
+
}
|
|
16359
|
+
function asTokens(v) {
|
|
16360
|
+
if (!isObj2(v) || typeof v.accessToken !== "string" || !v.accessToken)
|
|
16361
|
+
return;
|
|
16362
|
+
return {
|
|
16363
|
+
accessToken: v.accessToken,
|
|
16364
|
+
refreshToken: typeof v.refreshToken === "string" ? v.refreshToken : "",
|
|
16365
|
+
accessExpiresAt: Number(v.accessExpiresAt) || 0,
|
|
16366
|
+
clientId: typeof v.clientId === "string" ? v.clientId : "",
|
|
16367
|
+
scope: typeof v.scope === "string" ? v.scope : ""
|
|
16368
|
+
};
|
|
16369
|
+
}
|
|
16370
|
+
function readFile(path) {
|
|
16371
|
+
if (!existsSync(path))
|
|
16372
|
+
return {};
|
|
16373
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
16374
|
+
return isObj2(parsed) ? parsed : {};
|
|
16375
|
+
}
|
|
16376
|
+
function readGrant(file, host, legacy) {
|
|
16377
|
+
return asTokens(effectiveBlock(file, host, legacy).oauth);
|
|
16378
|
+
}
|
|
16379
|
+
function holderAlive(token, ageMs) {
|
|
16380
|
+
if (token === "")
|
|
16381
|
+
return ageMs < 1000;
|
|
16382
|
+
const pid = Number(token.split(":")[0]);
|
|
16383
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
16384
|
+
return true;
|
|
16385
|
+
try {
|
|
16386
|
+
process.kill(pid, 0);
|
|
16387
|
+
return true;
|
|
16388
|
+
} catch (e) {
|
|
16389
|
+
return e.code === "EPERM";
|
|
16390
|
+
}
|
|
16391
|
+
}
|
|
16392
|
+
async function withConfigLock(path, fn) {
|
|
16393
|
+
const lock = `${path}.lock`;
|
|
16394
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
16395
|
+
const start = Date.now();
|
|
16396
|
+
let fd;
|
|
16397
|
+
while (fd === undefined) {
|
|
16398
|
+
try {
|
|
16399
|
+
fd = openSync(lock, "wx", 384);
|
|
16400
|
+
} catch (e) {
|
|
16401
|
+
if (e.code !== "EEXIST")
|
|
16402
|
+
throw e;
|
|
16403
|
+
try {
|
|
16404
|
+
const age = Date.now() - statSync(lock).mtimeMs;
|
|
16405
|
+
if (age > LOCK_STALE_MS || !holderAlive(readFileSync(lock, "utf-8"), age))
|
|
16406
|
+
unlinkSync(lock);
|
|
16407
|
+
} catch {}
|
|
16408
|
+
if (Date.now() - start > LOCK_WAIT_MS)
|
|
16409
|
+
throw new Error(`timed out waiting for ${lock}`);
|
|
16410
|
+
await new Promise((r) => setTimeout(r, 50 + Math.random() * 50));
|
|
16411
|
+
}
|
|
16412
|
+
}
|
|
16413
|
+
const token = `${process.pid}:${Math.random().toString(36).slice(2)}`;
|
|
16414
|
+
try {
|
|
16415
|
+
writeFileSync(fd, token);
|
|
16416
|
+
return await fn();
|
|
16417
|
+
} finally {
|
|
16418
|
+
closeSync(fd);
|
|
16419
|
+
try {
|
|
16420
|
+
if (readFileSync(lock, "utf-8") === token)
|
|
16421
|
+
unlinkSync(lock);
|
|
16422
|
+
} catch {}
|
|
16423
|
+
}
|
|
16424
|
+
}
|
|
16425
|
+
function writeFileAtomic(path, data) {
|
|
16426
|
+
const tmp = join(dirname(path), `.${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
16427
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + `
|
|
16428
|
+
`, { mode: 384 });
|
|
16429
|
+
renameSync(tmp, path);
|
|
16430
|
+
}
|
|
16431
|
+
async function updateConfigFile(path, mutate) {
|
|
16432
|
+
await withConfigLock(path, async () => {
|
|
16433
|
+
const file = readFile(path);
|
|
16434
|
+
mutate(file);
|
|
16435
|
+
writeFileAtomic(path, file);
|
|
16436
|
+
});
|
|
16437
|
+
}
|
|
16438
|
+
function setGrant(file, host, tokens) {
|
|
16439
|
+
const block = hostBlock(file, host);
|
|
16440
|
+
if (tokens)
|
|
16441
|
+
block.oauth = tokens;
|
|
16442
|
+
else
|
|
16443
|
+
delete block.oauth;
|
|
16444
|
+
}
|
|
16445
|
+
async function saveGrant(path, host, tokens) {
|
|
16446
|
+
await updateConfigFile(path, (file) => {
|
|
16447
|
+
setGrant(file, host, tokens);
|
|
16448
|
+
if (tokens) {
|
|
16449
|
+
const block = hostBlock(file, host);
|
|
16450
|
+
delete block.apiKey;
|
|
16451
|
+
delete block.baseUrl;
|
|
16452
|
+
}
|
|
16453
|
+
});
|
|
16454
|
+
}
|
|
16455
|
+
function serverOf(block, baseUrl, env) {
|
|
16456
|
+
return baseUrl ?? (env.HONCHO_BASE_URL || undefined) ?? (typeof block.baseUrl === "string" && block.baseUrl ? block.baseUrl : undefined);
|
|
16457
|
+
}
|
|
16458
|
+
function pickCredential(file, opts) {
|
|
16459
|
+
const env = opts.env ?? process.env;
|
|
16460
|
+
if (env.HONCHO_API_KEY)
|
|
16461
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
16462
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
16463
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
16464
|
+
if (g)
|
|
16465
|
+
return { token: g.accessToken, source: "oauth", expiresAt: g.accessExpiresAt, ...accessValid(g, 0) ? {} : { expired: true } };
|
|
16466
|
+
return typeof block.apiKey === "string" && block.apiKey ? { token: block.apiKey, source: "apiKey" } : null;
|
|
16467
|
+
}
|
|
16468
|
+
async function ensureFreshCredential(opts) {
|
|
16469
|
+
const env = opts.env ?? process.env;
|
|
16470
|
+
if (env.HONCHO_API_KEY)
|
|
16471
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
16472
|
+
let file;
|
|
15579
16473
|
try {
|
|
15580
|
-
|
|
16474
|
+
file = readFile(opts.path);
|
|
15581
16475
|
} catch {
|
|
15582
|
-
|
|
16476
|
+
file = {};
|
|
16477
|
+
}
|
|
16478
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
16479
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
16480
|
+
if (!g || accessValid(g) || !g.refreshToken)
|
|
16481
|
+
return pickCredential(file, opts);
|
|
16482
|
+
let error;
|
|
16483
|
+
try {
|
|
16484
|
+
await withConfigLock(opts.path, async () => {
|
|
16485
|
+
const current = readGrant(readFile(opts.path), opts.host, opts.legacy);
|
|
16486
|
+
if (!current || accessValid(current))
|
|
16487
|
+
return;
|
|
16488
|
+
const next = await refreshAccessToken(current, opts);
|
|
16489
|
+
const latest = readFile(opts.path);
|
|
16490
|
+
setGrant(latest, opts.host, next);
|
|
16491
|
+
writeFileAtomic(opts.path, latest);
|
|
16492
|
+
});
|
|
16493
|
+
} catch (e) {
|
|
16494
|
+
error = e instanceof OAuthError ? e.code : e.message;
|
|
16495
|
+
}
|
|
16496
|
+
try {
|
|
16497
|
+
file = readFile(opts.path);
|
|
16498
|
+
} catch {}
|
|
16499
|
+
const cred = pickCredential(file, opts);
|
|
16500
|
+
if (cred && error) {
|
|
16501
|
+
cred.error = error;
|
|
16502
|
+
if (PERMANENT_ERRORS.has(error))
|
|
16503
|
+
cred.reauthRequired = true;
|
|
15583
16504
|
}
|
|
16505
|
+
return cred;
|
|
15584
16506
|
}
|
|
15585
|
-
|
|
15586
|
-
|
|
15587
|
-
|
|
16507
|
+
|
|
16508
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
16509
|
+
var DEFAULT_BASE_URL = "https://api.honcho.dev";
|
|
16510
|
+
var CONFIG_SCHEMA_VERSION = 2;
|
|
16511
|
+
function isObj3(v) {
|
|
16512
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16513
|
+
}
|
|
16514
|
+
function str2(v) {
|
|
16515
|
+
return typeof v === "string" && v ? v : undefined;
|
|
16516
|
+
}
|
|
16517
|
+
function normalizeBaseUrl(input) {
|
|
16518
|
+
let s = input.trim();
|
|
16519
|
+
if (!s)
|
|
16520
|
+
return s;
|
|
16521
|
+
if (!s.startsWith("http://") && !s.startsWith("https://")) {
|
|
16522
|
+
const host = s.split("/")[0].split(":")[0].toLowerCase();
|
|
16523
|
+
const local = host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
16524
|
+
s = `${local ? "http" : "https"}://${s}`;
|
|
16525
|
+
}
|
|
16526
|
+
try {
|
|
16527
|
+
const u = new URL(s);
|
|
16528
|
+
u.hostname = u.hostname.toLowerCase();
|
|
16529
|
+
const path = u.pathname === "/" ? "" : u.pathname.replace(/\/+$/, "");
|
|
16530
|
+
return `${u.protocol}//${u.host}${path}`;
|
|
16531
|
+
} catch {
|
|
16532
|
+
return s;
|
|
15588
16533
|
}
|
|
15589
|
-
|
|
15590
|
-
|
|
15591
|
-
const
|
|
15592
|
-
const
|
|
15593
|
-
const
|
|
15594
|
-
const dirtyFiles = isDirty ? statusOutput.split(`
|
|
15595
|
-
`).filter((line) => line.trim()).map((line) => line.slice(3).trim()).slice(0, 20) : [];
|
|
16534
|
+
}
|
|
16535
|
+
function resolveConfig(file, opts) {
|
|
16536
|
+
const env = opts.env ?? process.env;
|
|
16537
|
+
const { host } = opts;
|
|
16538
|
+
const block = effectiveBlock(file, host, opts.legacy);
|
|
15596
16539
|
return {
|
|
15597
|
-
|
|
15598
|
-
|
|
15599
|
-
|
|
15600
|
-
|
|
15601
|
-
|
|
15602
|
-
|
|
16540
|
+
host,
|
|
16541
|
+
peerName: str2(env.HONCHO_PEER_NAME) ?? str2(block.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user",
|
|
16542
|
+
workspace: str2(env.HONCHO_WORKSPACE) ?? str2(block.workspace) ?? opts.defaults?.workspace ?? host,
|
|
16543
|
+
aiPeer: str2(env.HONCHO_AI_PEER) ?? str2(block.aiPeer) ?? opts.defaults?.aiPeer ?? host,
|
|
16544
|
+
baseUrl: normalizeBaseUrl(str2(env.HONCHO_BASE_URL) ?? str2(block.baseUrl) ?? DEFAULT_BASE_URL),
|
|
16545
|
+
warnings: checkConfig(file).map((i) => i.message)
|
|
15603
16546
|
};
|
|
15604
16547
|
}
|
|
15605
|
-
|
|
15606
|
-
|
|
15607
|
-
|
|
15608
|
-
|
|
15609
|
-
|
|
15610
|
-
|
|
15611
|
-
|
|
15612
|
-
|
|
15613
|
-
function
|
|
15614
|
-
if (
|
|
15615
|
-
|
|
15616
|
-
|
|
16548
|
+
function suggestPeerName(file, env = process.env) {
|
|
16549
|
+
const f = isObj3(file) ? file : {};
|
|
16550
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
16551
|
+
const names = new Set(Object.values(hosts).map((b) => isObj3(b) ? str2(b.peerName) : undefined).filter(Boolean));
|
|
16552
|
+
if (names.size === 1)
|
|
16553
|
+
return [...names][0];
|
|
16554
|
+
return str2(f.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user";
|
|
16555
|
+
}
|
|
16556
|
+
function configPath(env = process.env) {
|
|
16557
|
+
if (env.HONCHO_CONFIG_PATH)
|
|
16558
|
+
return env.HONCHO_CONFIG_PATH;
|
|
16559
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
16560
|
+
return join2(home, ".honcho", "config.json");
|
|
15617
16561
|
}
|
|
15618
|
-
function
|
|
15619
|
-
|
|
15620
|
-
if (!existsSync2(
|
|
16562
|
+
function readConfigFile(env = process.env) {
|
|
16563
|
+
const path = configPath(env);
|
|
16564
|
+
if (!existsSync2(path))
|
|
15621
16565
|
return {};
|
|
15622
|
-
}
|
|
15623
16566
|
try {
|
|
15624
|
-
|
|
16567
|
+
const parsed = JSON.parse(readFileSync2(path, "utf-8"));
|
|
16568
|
+
return isObj3(parsed) ? parsed : {};
|
|
15625
16569
|
} catch {
|
|
15626
16570
|
return {};
|
|
15627
16571
|
}
|
|
15628
16572
|
}
|
|
15629
|
-
function
|
|
15630
|
-
|
|
15631
|
-
|
|
16573
|
+
async function saveHost(path, host, patch, legacy) {
|
|
16574
|
+
await updateConfigFile(path, (file) => {
|
|
16575
|
+
if (isNewer(file))
|
|
16576
|
+
throw new Error(`${path} was written by a newer Honcho plugin; update this one.`);
|
|
16577
|
+
const block = writeBlock(file, host, hostMigration(file, host, [], legacy));
|
|
16578
|
+
if ("baseUrl" in patch && !("apiKey" in patch) && !sameServer(patch.baseUrl, str2(block.baseUrl)))
|
|
16579
|
+
delete block.apiKey;
|
|
16580
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
16581
|
+
if (v === undefined)
|
|
16582
|
+
delete block[k];
|
|
16583
|
+
else
|
|
16584
|
+
block[k] = v;
|
|
16585
|
+
}
|
|
16586
|
+
block.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
16587
|
+
});
|
|
16588
|
+
}
|
|
16589
|
+
var MOVABLE = ["apiKey", "peerName", "workspace", "aiPeer", "baseUrl"];
|
|
16590
|
+
function isNewer(file) {
|
|
16591
|
+
return isObj3(file) && typeof file.schemaVersion === "number" && file.schemaVersion > CONFIG_SCHEMA_VERSION;
|
|
15632
16592
|
}
|
|
15633
|
-
function
|
|
15634
|
-
|
|
15635
|
-
return cache.sessions?.[cwd]?.instanceId ?? null;
|
|
16593
|
+
function isMigrated(block) {
|
|
16594
|
+
return isObj3(block) && typeof block.schemaVersion === "number" && block.schemaVersion >= CONFIG_SCHEMA_VERSION;
|
|
15636
16595
|
}
|
|
15637
|
-
|
|
15638
|
-
|
|
15639
|
-
"summaries",
|
|
15640
|
-
"messageCount"
|
|
15641
|
-
]);
|
|
15642
|
-
var GIT_STATE_FILE = join2(CACHE_DIR, "git-state.json");
|
|
15643
|
-
var MAX_MESSAGE_SIZE = 24000;
|
|
15644
|
-
function chunkContent(content, maxSize = MAX_MESSAGE_SIZE) {
|
|
15645
|
-
if (content.length <= maxSize) {
|
|
15646
|
-
return [content];
|
|
15647
|
-
}
|
|
15648
|
-
const chunks = [];
|
|
15649
|
-
let remaining = content;
|
|
15650
|
-
while (remaining.length > 0) {
|
|
15651
|
-
if (remaining.length <= maxSize) {
|
|
15652
|
-
chunks.push(remaining);
|
|
15653
|
-
break;
|
|
15654
|
-
}
|
|
15655
|
-
let splitIndex = remaining.lastIndexOf(`
|
|
15656
|
-
`, maxSize);
|
|
15657
|
-
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
15658
|
-
splitIndex = remaining.lastIndexOf(" ", maxSize);
|
|
15659
|
-
}
|
|
15660
|
-
if (splitIndex <= 0 || splitIndex < maxSize * 0.25) {
|
|
15661
|
-
splitIndex = maxSize;
|
|
15662
|
-
}
|
|
15663
|
-
chunks.push(remaining.slice(0, splitIndex));
|
|
15664
|
-
remaining = remaining.slice(splitIndex).trimStart();
|
|
15665
|
-
}
|
|
15666
|
-
if (chunks.length > 1) {
|
|
15667
|
-
return chunks.map((chunk, i) => `[Part ${i + 1}/${chunks.length}] ${chunk}`);
|
|
15668
|
-
}
|
|
15669
|
-
return chunks;
|
|
16596
|
+
function sameServer(a, b) {
|
|
16597
|
+
return normalizeBaseUrl(a ?? DEFAULT_BASE_URL) === normalizeBaseUrl(b ?? DEFAULT_BASE_URL);
|
|
15670
16598
|
}
|
|
15671
|
-
var
|
|
15672
|
-
|
|
15673
|
-
|
|
15674
|
-
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
16599
|
+
var LEGACY_HOST_KEYS = ["auth", "endpoint", "environmentUrl", "workspaceId"];
|
|
16600
|
+
function isGrant(v) {
|
|
16601
|
+
return isObj3(v) && typeof v.accessToken === "string" && v.accessToken !== "";
|
|
16602
|
+
}
|
|
16603
|
+
function legacyGrantOf(b) {
|
|
16604
|
+
return !isGrant(b.oauth) && isObj3(b.auth) && isObj3(b.auth.oauth) ? b.auth.oauth : undefined;
|
|
16605
|
+
}
|
|
16606
|
+
function checkConfig(file) {
|
|
16607
|
+
if (!isObj3(file))
|
|
16608
|
+
return [];
|
|
16609
|
+
if (isNewer(file)) {
|
|
16610
|
+
return [{ path: "schemaVersion", message: `This file is schema version ${file.schemaVersion}, newer than this plugin understands; update the plugin.` }];
|
|
16611
|
+
}
|
|
16612
|
+
const issues = [];
|
|
16613
|
+
const hosts = isObj3(file.hosts) ? file.hosts : {};
|
|
16614
|
+
const byWorkspace = new Map;
|
|
16615
|
+
for (const h of Object.keys(hosts).filter((k) => isObj3(hosts[k]))) {
|
|
16616
|
+
const block = hosts[h];
|
|
16617
|
+
const peer = str2(block.peerName);
|
|
16618
|
+
if (!peer)
|
|
16619
|
+
continue;
|
|
16620
|
+
const ws = str2(block.workspace) ?? h;
|
|
16621
|
+
const peers = byWorkspace.get(ws) ?? new Map;
|
|
16622
|
+
peers.set(peer, [...peers.get(peer) ?? [], h]);
|
|
16623
|
+
byWorkspace.set(ws, peers);
|
|
16624
|
+
}
|
|
16625
|
+
for (const [ws, peers] of byWorkspace) {
|
|
16626
|
+
if (peers.size < 2)
|
|
16627
|
+
continue;
|
|
16628
|
+
const list = [...peers].map(([p, hs]) => `${hs.join(", ")}: "${p}"`).join("; ");
|
|
16629
|
+
issues.push({ path: "hosts", message: `Hosts in workspace "${ws}" use different peerNames (${list}), so the user is split across peers.` });
|
|
16630
|
+
}
|
|
16631
|
+
return issues;
|
|
16632
|
+
}
|
|
16633
|
+
function hostMigration(file, host, deadKeys = [], legacy = v01Reader) {
|
|
16634
|
+
if (isNewer(file))
|
|
16635
|
+
return { set: {}, remove: [] };
|
|
16636
|
+
const f = isObj3(file) ? file : {};
|
|
16637
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
16638
|
+
const block = isObj3(hosts[host]) ? hosts[host] : {};
|
|
16639
|
+
const set = {};
|
|
16640
|
+
const drop = [];
|
|
16641
|
+
const grant = legacyGrantOf(block);
|
|
16642
|
+
if (grant)
|
|
16643
|
+
set.oauth = grant;
|
|
16644
|
+
if (!isMigrated(block)) {
|
|
16645
|
+
const old = { ...legacy(f, host) };
|
|
16646
|
+
const signedIn = isGrant(block.oauth) || grant !== undefined;
|
|
16647
|
+
if (old.baseUrl && sameServer(old.baseUrl, undefined))
|
|
16648
|
+
old.baseUrl = undefined;
|
|
16649
|
+
for (const key of MOVABLE) {
|
|
16650
|
+
if (signedIn && (key === "apiKey" || key === "baseUrl"))
|
|
16651
|
+
continue;
|
|
16652
|
+
if (old[key] !== undefined && block[key] !== old[key])
|
|
16653
|
+
set[key] = old[key];
|
|
16654
|
+
else if (old[key] === undefined && block[key] !== undefined)
|
|
16655
|
+
drop.push(key);
|
|
15685
16656
|
}
|
|
16657
|
+
set.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
15686
16658
|
}
|
|
16659
|
+
const remove = [...drop, ...LEGACY_HOST_KEYS, ...deadKeys].filter((k) => (k in block) && !(k in set));
|
|
16660
|
+
return { set, remove };
|
|
16661
|
+
}
|
|
16662
|
+
function effectiveBlock(file, host, legacy) {
|
|
16663
|
+
return writeBlock(structuredClone(isObj3(file) ? file : {}), host, hostMigration(file, host, [], legacy));
|
|
16664
|
+
}
|
|
16665
|
+
function hostBlock(file, host) {
|
|
16666
|
+
if (host === "__proto__" || host === "constructor" || host === "prototype")
|
|
16667
|
+
throw new Error(`invalid host name: ${host}`);
|
|
16668
|
+
if (!isObj3(file.hosts))
|
|
16669
|
+
file.hosts = {};
|
|
16670
|
+
return isObj3(file.hosts[host]) ? file.hosts[host] : file.hosts[host] = {};
|
|
16671
|
+
}
|
|
16672
|
+
function writeBlock(file, host, { set, remove }) {
|
|
16673
|
+
const block = hostBlock(file, host);
|
|
16674
|
+
Object.assign(block, set);
|
|
16675
|
+
for (const k of remove)
|
|
16676
|
+
delete block[k];
|
|
16677
|
+
return block;
|
|
15687
16678
|
}
|
|
15688
|
-
// node_modules/@honcho-ai/harness-plugin-core/
|
|
16679
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/claude-honcho.js
|
|
16680
|
+
var isObj4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
16681
|
+
var str3 = (v) => typeof v === "string" && v ? v : undefined;
|
|
16682
|
+
function claudeHonchoReader(file, host) {
|
|
16683
|
+
const hosts = isObj4(file.hosts) ? file.hosts : {};
|
|
16684
|
+
const found = hosts[host] ?? hosts[host.replace(/_/g, "-")] ?? hosts[host.replace(/-/g, "_")];
|
|
16685
|
+
const block = isObj4(found) ? found : undefined;
|
|
16686
|
+
const endpoint = block?.endpoint ?? file.endpoint;
|
|
16687
|
+
const override = file.globalOverride === true;
|
|
16688
|
+
return {
|
|
16689
|
+
apiKey: str3(block?.apiKey) ?? str3(file.apiKey),
|
|
16690
|
+
baseUrl: str3(endpoint?.baseUrl)?.replace(/\/v3\/?$/, "") ?? (endpoint?.environment === "local" ? "http://localhost:8000" : undefined),
|
|
16691
|
+
peerName: str3(file.peerName),
|
|
16692
|
+
workspace: str3(override || !block ? file.workspace : block.workspace),
|
|
16693
|
+
aiPeer: str3(override ? file.aiPeer ?? block?.aiPeer : block ? block.aiPeer : file[host === "cursor" ? "cursorPeer" : "claudePeer"])
|
|
16694
|
+
};
|
|
16695
|
+
}
|
|
16696
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/telemetry.js
|
|
15689
16697
|
var HEADER_HOST = "X-Honcho-Host";
|
|
15690
16698
|
var HEADER_PLUGIN = "X-Honcho-Plugin";
|
|
15691
16699
|
var HEADER_AGENT_MODEL = "X-Honcho-Agent-Model";
|
|
@@ -15734,13 +16742,10 @@ function telemetryHeaders(id = {}, extra) {
|
|
|
15734
16742
|
return headers;
|
|
15735
16743
|
}
|
|
15736
16744
|
// src/config.ts
|
|
16745
|
+
var LEGACY = claudeHonchoReader;
|
|
15737
16746
|
function sanitizeForSessionName(s) {
|
|
15738
16747
|
return s.toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
15739
16748
|
}
|
|
15740
|
-
var HONCHO_BASE_URLS = {
|
|
15741
|
-
production: "https://api.honcho.dev/v3",
|
|
15742
|
-
local: "http://localhost:8000/v3"
|
|
15743
|
-
};
|
|
15744
16749
|
var _detectedHost = null;
|
|
15745
16750
|
function setDetectedHost(host) {
|
|
15746
16751
|
_detectedHost = host;
|
|
@@ -15758,34 +16763,14 @@ var DEFAULT_AI_PEER = {
|
|
|
15758
16763
|
claude_code: "claude",
|
|
15759
16764
|
obsidian: "honcho"
|
|
15760
16765
|
};
|
|
15761
|
-
function
|
|
15762
|
-
|
|
15763
|
-
return true;
|
|
15764
|
-
if (a == null || b == null)
|
|
15765
|
-
return a === b;
|
|
15766
|
-
if (typeof a !== typeof b)
|
|
15767
|
-
return false;
|
|
15768
|
-
if (typeof a !== "object")
|
|
15769
|
-
return false;
|
|
15770
|
-
const aObj = a;
|
|
15771
|
-
const bObj = b;
|
|
15772
|
-
const keys = new Set([...Object.keys(aObj), ...Object.keys(bObj)]);
|
|
15773
|
-
for (const key of keys) {
|
|
15774
|
-
if (!deepEqual(aObj[key], bObj[key]))
|
|
15775
|
-
return false;
|
|
15776
|
-
}
|
|
15777
|
-
return true;
|
|
16766
|
+
function getConfigPath() {
|
|
16767
|
+
return configPath();
|
|
15778
16768
|
}
|
|
15779
|
-
var CONFIG_DIR = join3(homedir2(), ".honcho");
|
|
15780
|
-
var CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
15781
16769
|
function getConfigDir() {
|
|
15782
|
-
return
|
|
15783
|
-
}
|
|
15784
|
-
function getConfigPath() {
|
|
15785
|
-
return CONFIG_FILE;
|
|
16770
|
+
return dirname2(configPath());
|
|
15786
16771
|
}
|
|
15787
16772
|
function configExists() {
|
|
15788
|
-
return existsSync3(
|
|
16773
|
+
return existsSync3(configPath());
|
|
15789
16774
|
}
|
|
15790
16775
|
function getPluginVersion() {
|
|
15791
16776
|
const root = process.env.CLAUDE_PLUGIN_ROOT;
|
|
@@ -15795,300 +16780,123 @@ function getPluginVersion() {
|
|
|
15795
16780
|
];
|
|
15796
16781
|
for (const manifest of candidates) {
|
|
15797
16782
|
try {
|
|
15798
|
-
const version = JSON.parse(
|
|
16783
|
+
const version = JSON.parse(readFileSync3(manifest, "utf-8")).version;
|
|
15799
16784
|
if (typeof version === "string" && version)
|
|
15800
16785
|
return version;
|
|
15801
16786
|
} catch {}
|
|
15802
16787
|
}
|
|
15803
16788
|
return "unknown";
|
|
15804
16789
|
}
|
|
15805
|
-
function
|
|
15806
|
-
|
|
15807
|
-
|
|
15808
|
-
|
|
15809
|
-
|
|
15810
|
-
|
|
15811
|
-
return resolveConfig2(raw, resolvedHost);
|
|
15812
|
-
} catch {}
|
|
15813
|
-
}
|
|
15814
|
-
return loadConfigFromEnv(resolvedHost);
|
|
16790
|
+
function legacyEndpoint(value) {
|
|
16791
|
+
if (value === "local")
|
|
16792
|
+
return "http://localhost:8000";
|
|
16793
|
+
if (value?.startsWith("http"))
|
|
16794
|
+
return value.replace(/\/v3\/?$/, "");
|
|
16795
|
+
return;
|
|
15815
16796
|
}
|
|
15816
|
-
function
|
|
15817
|
-
const
|
|
15818
|
-
const
|
|
15819
|
-
|
|
15820
|
-
|
|
15821
|
-
|
|
15822
|
-
|
|
15823
|
-
|
|
15824
|
-
if (
|
|
15825
|
-
|
|
15826
|
-
|
|
15827
|
-
|
|
15828
|
-
|
|
15829
|
-
|
|
15830
|
-
} else {
|
|
15831
|
-
workspace = process.env.HONCHO_WORKSPACE ?? raw.workspace ?? DEFAULT_WORKSPACE[host];
|
|
15832
|
-
if (host === "cursor") {
|
|
15833
|
-
aiPeer = raw.cursorPeer ?? DEFAULT_AI_PEER["cursor"];
|
|
15834
|
-
} else {
|
|
15835
|
-
aiPeer = raw.claudePeer ?? DEFAULT_AI_PEER["claude_code"];
|
|
15836
|
-
}
|
|
15837
|
-
}
|
|
15838
|
-
const config = {
|
|
15839
|
-
apiKey,
|
|
15840
|
-
peerName,
|
|
15841
|
-
workspace,
|
|
15842
|
-
aiPeer,
|
|
15843
|
-
sessionStrategy: hostBlock?.sessionStrategy ?? raw.sessionStrategy,
|
|
15844
|
-
sessionPeerPrefix: hostBlock?.sessionPeerPrefix ?? raw.sessionPeerPrefix,
|
|
15845
|
-
sessions: raw.sessions,
|
|
15846
|
-
saveMessages: hostBlock?.saveMessages ?? raw.saveMessages,
|
|
15847
|
-
saveToolUse: hostBlock?.saveToolUse ?? raw.saveToolUse,
|
|
15848
|
-
saveGitEvents: hostBlock?.saveGitEvents ?? raw.saveGitEvents,
|
|
15849
|
-
reasoningLevel: hostBlock?.reasoningLevel ?? raw.reasoningLevel,
|
|
15850
|
-
observationMode: hostBlock?.observationMode ?? raw.observationMode,
|
|
15851
|
-
messageUpload: hostBlock?.messageUpload ?? raw.messageUpload,
|
|
15852
|
-
contextRefresh: hostBlock?.contextRefresh ?? raw.contextRefresh,
|
|
15853
|
-
endpoint: hostBlock?.endpoint ?? raw.endpoint,
|
|
15854
|
-
redactPatterns: hostBlock?.redactPatterns ?? raw.redactPatterns,
|
|
15855
|
-
injection: hostBlock?.injection ?? raw.injection,
|
|
15856
|
-
rememberTool: hostBlock?.rememberTool ?? raw.rememberTool,
|
|
15857
|
-
enabled: hostBlock?.enabled ?? raw.enabled,
|
|
15858
|
-
logging: hostBlock?.logging ?? raw.logging,
|
|
15859
|
-
globalOverride: raw.globalOverride
|
|
15860
|
-
};
|
|
15861
|
-
return mergeWithEnvVars(config);
|
|
16797
|
+
function legacyEnv(host = getDetectedHost()) {
|
|
16798
|
+
const env = process.env;
|
|
16799
|
+
const peerVar = host === "cursor" ? "HONCHO_CURSOR_PEER" : "HONCHO_CLAUDE_PEER";
|
|
16800
|
+
const candidates = [
|
|
16801
|
+
["HONCHO_BASE_URL", "baseUrl", "HONCHO_ENDPOINT", legacyEndpoint(env.HONCHO_ENDPOINT)],
|
|
16802
|
+
["HONCHO_AI_PEER", "aiPeer", peerVar, env[peerVar] || undefined]
|
|
16803
|
+
];
|
|
16804
|
+
const set = candidates.filter(([newVar, , , value]) => value && !env[newVar]);
|
|
16805
|
+
if (!set.length)
|
|
16806
|
+
return {};
|
|
16807
|
+
const block = effectiveBlock(readConfigFile(), host, LEGACY);
|
|
16808
|
+
if (block.apiKey || block.oauth)
|
|
16809
|
+
return {};
|
|
16810
|
+
return Object.fromEntries(set.filter(([, setting]) => !block[setting]).map(([newVar, , oldVar, value]) => [newVar, [oldVar, value]]));
|
|
15862
16811
|
}
|
|
15863
|
-
function
|
|
15864
|
-
const
|
|
15865
|
-
if (!
|
|
15866
|
-
return
|
|
15867
|
-
}
|
|
15868
|
-
const resolvedHost = host ?? getDetectedHost();
|
|
15869
|
-
const peerName = process.env.HONCHO_PEER_NAME || process.env.USER || process.env.USERNAME || "user";
|
|
15870
|
-
const workspace = process.env.HONCHO_WORKSPACE || DEFAULT_WORKSPACE[resolvedHost];
|
|
15871
|
-
const hostPeerEnv = resolvedHost === "cursor" ? process.env.HONCHO_CURSOR_PEER : process.env.HONCHO_CLAUDE_PEER;
|
|
15872
|
-
const aiPeer = process.env.HONCHO_AI_PEER || hostPeerEnv || DEFAULT_AI_PEER[resolvedHost];
|
|
15873
|
-
const endpoint = process.env.HONCHO_ENDPOINT;
|
|
15874
|
-
const config = {
|
|
15875
|
-
apiKey,
|
|
15876
|
-
peerName,
|
|
15877
|
-
workspace,
|
|
15878
|
-
aiPeer,
|
|
15879
|
-
saveMessages: process.env.HONCHO_SAVE_MESSAGES !== "false",
|
|
15880
|
-
saveToolUse: process.env.HONCHO_SAVE_TOOL_USE === "true",
|
|
15881
|
-
saveGitEvents: process.env.HONCHO_SAVE_GIT_EVENTS === "true",
|
|
15882
|
-
enabled: process.env.HONCHO_ENABLED !== "false",
|
|
15883
|
-
logging: process.env.HONCHO_LOGGING !== "false"
|
|
15884
|
-
};
|
|
15885
|
-
if (endpoint) {
|
|
15886
|
-
if (endpoint === "local") {
|
|
15887
|
-
config.endpoint = { environment: "local" };
|
|
15888
|
-
} else if (endpoint.startsWith("http")) {
|
|
15889
|
-
config.endpoint = { baseUrl: endpoint };
|
|
15890
|
-
}
|
|
15891
|
-
}
|
|
15892
|
-
return config;
|
|
16812
|
+
function honchoEnv(host) {
|
|
16813
|
+
const legacy = Object.entries(legacyEnv(host));
|
|
16814
|
+
if (!legacy.length)
|
|
16815
|
+
return process.env;
|
|
16816
|
+
return { ...process.env, ...Object.fromEntries(legacy.map(([k, [, value]]) => [k, value])) };
|
|
15893
16817
|
}
|
|
15894
|
-
function
|
|
15895
|
-
|
|
15896
|
-
|
|
15897
|
-
|
|
15898
|
-
|
|
15899
|
-
|
|
15900
|
-
}
|
|
15901
|
-
if (process.env.HONCHO_ENABLED === "false") {
|
|
15902
|
-
config.enabled = false;
|
|
15903
|
-
}
|
|
15904
|
-
if (process.env.HONCHO_LOGGING === "false") {
|
|
15905
|
-
config.logging = false;
|
|
15906
|
-
}
|
|
15907
|
-
if (process.env.HONCHO_SAVE_TOOL_USE !== undefined) {
|
|
15908
|
-
config.saveToolUse = process.env.HONCHO_SAVE_TOOL_USE === "true";
|
|
15909
|
-
}
|
|
15910
|
-
if (process.env.HONCHO_SAVE_GIT_EVENTS !== undefined) {
|
|
15911
|
-
config.saveGitEvents = process.env.HONCHO_SAVE_GIT_EVENTS === "true";
|
|
15912
|
-
}
|
|
15913
|
-
return config;
|
|
16818
|
+
function resolveHost(host) {
|
|
16819
|
+
return resolveConfig(readConfigFile(), {
|
|
16820
|
+
host,
|
|
16821
|
+
env: honchoEnv(host),
|
|
16822
|
+
defaults: { workspace: DEFAULT_WORKSPACE[host], aiPeer: DEFAULT_AI_PEER[host] },
|
|
16823
|
+
legacy: LEGACY
|
|
16824
|
+
});
|
|
15914
16825
|
}
|
|
15915
|
-
function
|
|
15916
|
-
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
|
|
15923
|
-
|
|
15924
|
-
|
|
15925
|
-
|
|
15926
|
-
|
|
15927
|
-
|
|
15928
|
-
const host = getDetectedHost();
|
|
15929
|
-
if (!existing.hosts)
|
|
15930
|
-
existing.hosts = {};
|
|
15931
|
-
const existingHost = existing.hosts[host] ?? {};
|
|
15932
|
-
const hostEntry = {};
|
|
15933
|
-
const setHostIfExplicit = (key, value, rootValue) => {
|
|
15934
|
-
if (value === undefined)
|
|
15935
|
-
return;
|
|
15936
|
-
const hasHostOverride = Object.prototype.hasOwnProperty.call(existingHost, key);
|
|
15937
|
-
if (hasHostOverride || !deepEqual(value, rootValue)) {
|
|
15938
|
-
hostEntry[key] = value;
|
|
15939
|
-
}
|
|
16826
|
+
function loadConfig2(host = getDetectedHost()) {
|
|
16827
|
+
const cfg = resolveHost(host);
|
|
16828
|
+
const cred = pickCredential(readConfigFile(), { host, baseUrl: cfg.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
16829
|
+
if (!cred)
|
|
16830
|
+
return null;
|
|
16831
|
+
const { token, ...authState } = cred;
|
|
16832
|
+
return {
|
|
16833
|
+
apiKey: token,
|
|
16834
|
+
auth: { ...authState, host },
|
|
16835
|
+
peerName: cfg.peerName,
|
|
16836
|
+
workspace: cfg.workspace,
|
|
16837
|
+
aiPeer: cfg.aiPeer,
|
|
16838
|
+
baseUrl: cfg.baseUrl
|
|
15940
16839
|
};
|
|
15941
|
-
setHostIfExplicit("workspace", config.workspace, existing.workspace ?? DEFAULT_WORKSPACE[host]);
|
|
15942
|
-
setHostIfExplicit("aiPeer", config.aiPeer, existing.aiPeer ?? DEFAULT_AI_PEER[host]);
|
|
15943
|
-
const enabledForSave = process.env.HONCHO_ENABLED === "false" && config.enabled === false ? existingHost.enabled : config.enabled;
|
|
15944
|
-
const loggingForSave = process.env.HONCHO_LOGGING === "false" && config.logging === false ? existingHost.logging : config.logging;
|
|
15945
|
-
setHostIfExplicit("enabled", enabledForSave, existing.enabled);
|
|
15946
|
-
setHostIfExplicit("logging", loggingForSave, existing.logging);
|
|
15947
|
-
setHostIfExplicit("saveMessages", config.saveMessages, existing.saveMessages);
|
|
15948
|
-
setHostIfExplicit("sessionStrategy", config.sessionStrategy, existing.sessionStrategy);
|
|
15949
|
-
setHostIfExplicit("sessionPeerPrefix", config.sessionPeerPrefix, existing.sessionPeerPrefix);
|
|
15950
|
-
setHostIfExplicit("reasoningLevel", config.reasoningLevel, existing.reasoningLevel);
|
|
15951
|
-
setHostIfExplicit("observationMode", config.observationMode, existing.observationMode);
|
|
15952
|
-
setHostIfExplicit("messageUpload", config.messageUpload, existing.messageUpload);
|
|
15953
|
-
setHostIfExplicit("contextRefresh", config.contextRefresh, existing.contextRefresh);
|
|
15954
|
-
setHostIfExplicit("redactPatterns", config.redactPatterns, existing.redactPatterns);
|
|
15955
|
-
setHostIfExplicit("endpoint", config.endpoint, existing.endpoint);
|
|
15956
|
-
setHostIfExplicit("injection", config.injection, existing.injection);
|
|
15957
|
-
setHostIfExplicit("rememberTool", config.rememberTool, existing.rememberTool);
|
|
15958
|
-
if (existingHost.apiKey !== undefined) {
|
|
15959
|
-
hostEntry.apiKey = existingHost.apiKey;
|
|
15960
|
-
}
|
|
15961
|
-
existing.hosts[host] = hostEntry;
|
|
15962
|
-
writeFileSync2(CONFIG_FILE, JSON.stringify(existing, null, 2));
|
|
15963
16840
|
}
|
|
15964
|
-
function
|
|
15965
|
-
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
|
|
15969
|
-
if (
|
|
15970
|
-
|
|
15971
|
-
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
|
|
15977
|
-
|
|
15978
|
-
return join3(homedir2(), ".claude", "settings.json");
|
|
16841
|
+
async function saveConfig(config, field) {
|
|
16842
|
+
const host = getDetectedHost();
|
|
16843
|
+
const env = honchoEnv(host);
|
|
16844
|
+
const write = (key, envVar) => key === field || !env[envVar];
|
|
16845
|
+
const patch = {};
|
|
16846
|
+
if (write("peerName", "HONCHO_PEER_NAME"))
|
|
16847
|
+
patch.peerName = config.peerName;
|
|
16848
|
+
if (write("workspace", "HONCHO_WORKSPACE"))
|
|
16849
|
+
patch.workspace = config.workspace === DEFAULT_WORKSPACE[host] ? undefined : config.workspace;
|
|
16850
|
+
if (write("aiPeer", "HONCHO_AI_PEER"))
|
|
16851
|
+
patch.aiPeer = config.aiPeer === DEFAULT_AI_PEER[host] ? undefined : config.aiPeer;
|
|
16852
|
+
if (write("baseUrl", "HONCHO_BASE_URL"))
|
|
16853
|
+
patch.baseUrl = config.baseUrl === DEFAULT_BASE_URL ? undefined : config.baseUrl;
|
|
16854
|
+
await saveHost(configPath(), host, patch, LEGACY);
|
|
15979
16855
|
}
|
|
15980
|
-
function
|
|
15981
|
-
|
|
16856
|
+
async function saveHostApiKey(key) {
|
|
16857
|
+
await saveHost(configPath(), getDetectedHost(), { apiKey: key }, LEGACY);
|
|
15982
16858
|
}
|
|
15983
|
-
function
|
|
15984
|
-
|
|
15985
|
-
const gitPath = join3(dir, ".git");
|
|
15986
|
-
if (!statSync(gitPath).isFile())
|
|
15987
|
-
return null;
|
|
15988
|
-
const match = readFileSync2(gitPath, "utf-8").match(/^gitdir:\s*(.+?)\s*$/m);
|
|
15989
|
-
if (!match)
|
|
15990
|
-
return null;
|
|
15991
|
-
const gitdir = resolve(dir, match[1]);
|
|
15992
|
-
const idx = gitdir.lastIndexOf(`${sep}worktrees${sep}`);
|
|
15993
|
-
if (idx === -1)
|
|
15994
|
-
return null;
|
|
15995
|
-
const gitContainer = gitdir.slice(0, idx);
|
|
15996
|
-
if (basename(gitContainer) === ".git")
|
|
15997
|
-
return dirname(gitContainer);
|
|
15998
|
-
if (gitContainer.endsWith(".git"))
|
|
15999
|
-
return gitContainer;
|
|
16000
|
-
return null;
|
|
16001
|
-
} catch {
|
|
16002
|
-
return null;
|
|
16003
|
-
}
|
|
16859
|
+
function getConfiguredOrigin(host = getDetectedHost()) {
|
|
16860
|
+
return resolveHost(host).baseUrl;
|
|
16004
16861
|
}
|
|
16005
|
-
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
let dir = resolve(cwd);
|
|
16009
|
-
for (let i = 0;i < MAX_GIT_WALK_UP; i++) {
|
|
16010
|
-
if (existsSync3(join3(dir, ".git")))
|
|
16011
|
-
return resolveWorktreeMainRoot(dir);
|
|
16012
|
-
const parent = dirname(dir);
|
|
16013
|
-
if (parent === dir)
|
|
16014
|
-
break;
|
|
16015
|
-
dir = parent;
|
|
16016
|
-
}
|
|
16017
|
-
} catch {}
|
|
16018
|
-
return null;
|
|
16862
|
+
function getSessionName(sessionId) {
|
|
16863
|
+
const id = sessionId || process.env.CLAUDE_CODE_SESSION_ID;
|
|
16864
|
+
return id ? sanitizeForSessionName(id) : null;
|
|
16019
16865
|
}
|
|
16020
|
-
function
|
|
16021
|
-
const
|
|
16022
|
-
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
|
|
16027
|
-
|
|
16028
|
-
return config.sessions[mr];
|
|
16029
|
-
return null;
|
|
16866
|
+
async function refreshCredential(config) {
|
|
16867
|
+
const host = config.auth?.host ?? getDetectedHost();
|
|
16868
|
+
const cred = await ensureFreshCredential({ path: configPath(), host, baseUrl: config.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
16869
|
+
if (!cred)
|
|
16870
|
+
return;
|
|
16871
|
+
const { token, ...authState } = cred;
|
|
16872
|
+
config.apiKey = token;
|
|
16873
|
+
config.auth = { ...authState, host };
|
|
16030
16874
|
}
|
|
16031
|
-
function
|
|
16032
|
-
const
|
|
16033
|
-
const
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16043
|
-
|
|
16044
|
-
case "chat-instance": {
|
|
16045
|
-
if (opts.instanceId) {
|
|
16046
|
-
return usePrefix ? `${peerPart}-chat-${opts.instanceId}` : `chat-${opts.instanceId}`;
|
|
16047
|
-
}
|
|
16048
|
-
return base;
|
|
16049
|
-
}
|
|
16050
|
-
case "per-directory":
|
|
16875
|
+
function describeAuth(config) {
|
|
16876
|
+
const a = config.auth;
|
|
16877
|
+
const expiry = () => {
|
|
16878
|
+
if (!a?.expiresAt)
|
|
16879
|
+
return "";
|
|
16880
|
+
const mins = Math.round((a.expiresAt - Date.now() / 1000) / 60);
|
|
16881
|
+
return mins > 0 ? ` (token refreshes in ${mins}m)` : " (token expired)";
|
|
16882
|
+
};
|
|
16883
|
+
switch (a?.source) {
|
|
16884
|
+
case "env":
|
|
16885
|
+
return "HONCHO_API_KEY env var";
|
|
16886
|
+
case "oauth":
|
|
16887
|
+
return `signed in with Honcho${expiry()}`;
|
|
16051
16888
|
default:
|
|
16052
|
-
return
|
|
16053
|
-
}
|
|
16054
|
-
}
|
|
16055
|
-
function getSessionName(cwd, instanceId) {
|
|
16056
|
-
const config = loadConfig2();
|
|
16057
|
-
const strategy = config?.sessionStrategy ?? "per-directory";
|
|
16058
|
-
const mainRoot = worktreeMainRootFor(cwd);
|
|
16059
|
-
if (strategy === "per-directory") {
|
|
16060
|
-
const configuredSession = getSessionForPath(cwd, mainRoot);
|
|
16061
|
-
if (configuredSession) {
|
|
16062
|
-
return configuredSession;
|
|
16063
|
-
}
|
|
16064
|
-
}
|
|
16065
|
-
let branch;
|
|
16066
|
-
if (strategy === "git-branch") {
|
|
16067
|
-
branch = captureGitState(cwd)?.branch;
|
|
16889
|
+
return "API key";
|
|
16068
16890
|
}
|
|
16069
|
-
let resolvedInstanceId;
|
|
16070
|
-
if (strategy === "chat-instance") {
|
|
16071
|
-
resolvedInstanceId = instanceId || getInstanceIdForCwd(cwd) || getClaudeInstanceId() || undefined;
|
|
16072
|
-
}
|
|
16073
|
-
return deriveSessionName(strategy, mainRoot ?? cwd, {
|
|
16074
|
-
peerName: config?.peerName,
|
|
16075
|
-
sessionPeerPrefix: config?.sessionPeerPrefix,
|
|
16076
|
-
branch,
|
|
16077
|
-
instanceId: resolvedInstanceId
|
|
16078
|
-
});
|
|
16079
16891
|
}
|
|
16080
|
-
function
|
|
16081
|
-
if (
|
|
16082
|
-
|
|
16083
|
-
return url.endsWith("/v3") ? url : `${url}/v3`;
|
|
16892
|
+
function getAuthNotice(config) {
|
|
16893
|
+
if (config.auth?.reauthRequired) {
|
|
16894
|
+
return "[honcho] Your Honcho sign-in has expired. Run /honcho setup to sign in again.";
|
|
16084
16895
|
}
|
|
16085
|
-
|
|
16086
|
-
return HONCHO_BASE_URLS.local;
|
|
16087
|
-
}
|
|
16088
|
-
return HONCHO_BASE_URLS.production;
|
|
16896
|
+
return;
|
|
16089
16897
|
}
|
|
16090
16898
|
function getHonchoBaseUrl(config) {
|
|
16091
|
-
return
|
|
16899
|
+
return `${config.baseUrl}/v3`;
|
|
16092
16900
|
}
|
|
16093
16901
|
function getTelemetryHeaders(host = getDetectedHost()) {
|
|
16094
16902
|
return telemetryHeaders({
|
|
@@ -16107,18 +16915,18 @@ function getHonchoClientOptions(config) {
|
|
|
16107
16915
|
defaultHeaders: getTelemetryHeaders()
|
|
16108
16916
|
};
|
|
16109
16917
|
}
|
|
16918
|
+
function isProductionEndpoint(config) {
|
|
16919
|
+
return config.baseUrl === DEFAULT_BASE_URL;
|
|
16920
|
+
}
|
|
16110
16921
|
function getEndpointInfo(config) {
|
|
16111
|
-
|
|
16112
|
-
return { type: "custom", url: config.endpoint.baseUrl };
|
|
16113
|
-
}
|
|
16114
|
-
if (config.endpoint?.environment === "local") {
|
|
16115
|
-
return { type: "local", url: HONCHO_BASE_URLS.local };
|
|
16116
|
-
}
|
|
16117
|
-
return { type: "production", url: HONCHO_BASE_URLS.production };
|
|
16922
|
+
return { type: isProductionEndpoint(config) ? "production" : "custom", url: config.baseUrl };
|
|
16118
16923
|
}
|
|
16119
|
-
|
|
16120
|
-
|
|
16121
|
-
|
|
16924
|
+
|
|
16925
|
+
// src/honcho-client.ts
|
|
16926
|
+
var import_sdk = __toESM(require_dist(), 1);
|
|
16927
|
+
async function createHonchoClient(config, overrides = {}) {
|
|
16928
|
+
await refreshCredential(config);
|
|
16929
|
+
return new import_sdk.Honcho({ ...getHonchoClientOptions(config), ...overrides });
|
|
16122
16930
|
}
|
|
16123
16931
|
|
|
16124
16932
|
// src/styles.ts
|
|
@@ -16178,21 +16986,120 @@ function listItem(text, indent = 0) {
|
|
|
16178
16986
|
const padding = " ".repeat(indent);
|
|
16179
16987
|
return `${padding}${colors.dim}${symbols.bullet}${colors.reset} ${text}`;
|
|
16180
16988
|
}
|
|
16989
|
+
function honchoSessionUrl(config, sessionName) {
|
|
16990
|
+
if (!isProductionEndpoint(config))
|
|
16991
|
+
return null;
|
|
16992
|
+
return `https://app.honcho.dev/explore?workspace=${encodeURIComponent(config.workspace)}&view=sessions&session=${encodeURIComponent(sessionName)}`;
|
|
16993
|
+
}
|
|
16181
16994
|
|
|
16182
|
-
// src/skills/
|
|
16183
|
-
import {
|
|
16184
|
-
|
|
16995
|
+
// src/skills/setup.ts
|
|
16996
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
16997
|
+
|
|
16998
|
+
// src/skills/login.ts
|
|
16999
|
+
import { spawn } from "child_process";
|
|
17000
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync4, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
16185
17001
|
import { join as join4 } from "path";
|
|
17002
|
+
var HOST = "claude_code";
|
|
17003
|
+
var CLIENT_ID = "claude-honcho";
|
|
17004
|
+
var SOURCE = "claude-code";
|
|
17005
|
+
var CHECK_SECONDS = 15;
|
|
17006
|
+
var pendingPath = () => join4(getConfigDir(), "claude-honcho-signin.json");
|
|
17007
|
+
function readPending() {
|
|
17008
|
+
try {
|
|
17009
|
+
const p = JSON.parse(readFileSync4(pendingPath(), "utf-8"));
|
|
17010
|
+
return p.expiresAt > Date.now() / 1000 ? p : null;
|
|
17011
|
+
} catch {
|
|
17012
|
+
return null;
|
|
17013
|
+
}
|
|
17014
|
+
}
|
|
17015
|
+
function clearPending() {
|
|
17016
|
+
if (existsSync4(pendingPath()))
|
|
17017
|
+
unlinkSync2(pendingPath());
|
|
17018
|
+
}
|
|
17019
|
+
function openBrowser(url) {
|
|
17020
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "explorer" : "xdg-open";
|
|
17021
|
+
try {
|
|
17022
|
+
spawn(cmd, [url], { stdio: "ignore", detached: true }).on("error", () => {}).unref();
|
|
17023
|
+
} catch {}
|
|
17024
|
+
}
|
|
17025
|
+
async function startSignIn() {
|
|
17026
|
+
const device = await requestDeviceCode({ clientId: CLIENT_ID, source: SOURCE });
|
|
17027
|
+
const pending = { ...device, expiresAt: Math.floor(Date.now() / 1000) + device.expiresIn };
|
|
17028
|
+
mkdirSync2(getConfigDir(), { recursive: true });
|
|
17029
|
+
writeFileSync2(pendingPath(), JSON.stringify(pending), { mode: 384 });
|
|
17030
|
+
openBrowser(device.verificationUriComplete);
|
|
17031
|
+
return { url: device.verificationUriComplete, code: device.userCode, expiresIn: device.expiresIn };
|
|
17032
|
+
}
|
|
17033
|
+
async function checkSignIn() {
|
|
17034
|
+
const pending = readPending();
|
|
17035
|
+
if (!pending)
|
|
17036
|
+
return "none";
|
|
17037
|
+
const remaining = pending.expiresAt - Math.floor(Date.now() / 1000);
|
|
17038
|
+
try {
|
|
17039
|
+
const tokens = await pollForToken({ ...pending, expiresIn: Math.min(remaining, CHECK_SECONDS) }, { clientId: CLIENT_ID });
|
|
17040
|
+
await saveGrant(getConfigPath(), HOST, tokens);
|
|
17041
|
+
} catch (e) {
|
|
17042
|
+
if (!(e instanceof OAuthError))
|
|
17043
|
+
return "error";
|
|
17044
|
+
const code = e.code;
|
|
17045
|
+
if (code === "expired_token" && remaining > CHECK_SECONDS)
|
|
17046
|
+
return "waiting";
|
|
17047
|
+
clearPending();
|
|
17048
|
+
return code === "access_denied" ? "denied" : "expired";
|
|
17049
|
+
}
|
|
17050
|
+
clearPending();
|
|
17051
|
+
return "approved";
|
|
17052
|
+
}
|
|
17053
|
+
|
|
17054
|
+
// src/skills/transcript-parse.ts
|
|
17055
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5, readdirSync, statSync as statSync2 } from "fs";
|
|
17056
|
+
import { homedir as homedir2 } from "os";
|
|
17057
|
+
import { join as join5 } from "path";
|
|
17058
|
+
|
|
17059
|
+
// src/prompt-filters.ts
|
|
17060
|
+
import { existsSync as existsSync5 } from "fs";
|
|
17061
|
+
var HARNESS_INJECTED_PATTERNS = [
|
|
17062
|
+
/^<task-notification(?=[\s/>])/,
|
|
17063
|
+
/^<cross-session-message(?=[\s/>])/,
|
|
17064
|
+
/^<agent-message(?=[\s/>])/,
|
|
17065
|
+
/^<channel(?=[\s/>])/,
|
|
17066
|
+
/^<local-command-caveat(?=[\s/>])/,
|
|
17067
|
+
/^<local-command-stdout>/,
|
|
17068
|
+
/^<command-name>/,
|
|
17069
|
+
/^<command-message>/,
|
|
17070
|
+
/^<system-reminder(?=[\s/>])/,
|
|
17071
|
+
/^<bash-(stdout|stderr|input)>/,
|
|
17072
|
+
/^<<[\w-]+>>$/
|
|
17073
|
+
];
|
|
17074
|
+
var LEADING_REMINDERS = /^(?:\s*<system-reminder(?=[\s>])[^>]*>[\s\S]*?<\/system-reminder>)+\s*/;
|
|
17075
|
+
function stripLeadingReminders(prompt) {
|
|
17076
|
+
return prompt.replace(LEADING_REMINDERS, "");
|
|
17077
|
+
}
|
|
17078
|
+
var SLASH_COMMAND_ENVELOPE = /^<command-(name|message)>/;
|
|
17079
|
+
function isHarnessInjected(prompt) {
|
|
17080
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
17081
|
+
return !trimmed || HARNESS_INJECTED_PATTERNS.some((p) => p.test(trimmed));
|
|
17082
|
+
}
|
|
17083
|
+
var SLASH_COMMAND = /^\/([\w:-]+)(?:\s|$)/;
|
|
17084
|
+
function isSlashCommand(prompt) {
|
|
17085
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
17086
|
+
if (SLASH_COMMAND_ENVELOPE.test(trimmed))
|
|
17087
|
+
return true;
|
|
17088
|
+
const name = SLASH_COMMAND.exec(trimmed)?.[1];
|
|
17089
|
+
if (!name)
|
|
17090
|
+
return false;
|
|
17091
|
+
return name.includes(":") || !existsSync5(`/${name}`);
|
|
17092
|
+
}
|
|
17093
|
+
|
|
17094
|
+
// src/skills/transcript-parse.ts
|
|
16186
17095
|
function entryType(entry) {
|
|
16187
17096
|
return entry.type || entry.role;
|
|
16188
17097
|
}
|
|
16189
17098
|
function isRealUserPrompt(entry) {
|
|
16190
17099
|
if (entry.isMeta)
|
|
16191
17100
|
return false;
|
|
16192
|
-
const
|
|
16193
|
-
|
|
16194
|
-
const trimmed = text.trim();
|
|
16195
|
-
return trimmed.length > 0 && !trimmed.startsWith("<");
|
|
17101
|
+
const text = userText(entry);
|
|
17102
|
+
return !isHarnessInjected(text) && !isSlashCommand(text);
|
|
16196
17103
|
}
|
|
16197
17104
|
function userText(entry) {
|
|
16198
17105
|
const mc = entry.message?.content ?? entry.content;
|
|
@@ -16214,10 +17121,10 @@ function assistantText(entry) {
|
|
|
16214
17121
|
return "";
|
|
16215
17122
|
}
|
|
16216
17123
|
function readLines(transcriptPath) {
|
|
16217
|
-
if (!transcriptPath || !
|
|
17124
|
+
if (!transcriptPath || !existsSync6(transcriptPath))
|
|
16218
17125
|
return [];
|
|
16219
17126
|
try {
|
|
16220
|
-
return
|
|
17127
|
+
return readFileSync5(transcriptPath, "utf-8").split(`
|
|
16221
17128
|
`).filter((line) => line.trim());
|
|
16222
17129
|
} catch {
|
|
16223
17130
|
return [];
|
|
@@ -16225,9 +17132,8 @@ function readLines(transcriptPath) {
|
|
|
16225
17132
|
}
|
|
16226
17133
|
function parseTranscriptForBackfill(transcriptPath) {
|
|
16227
17134
|
const messages = [];
|
|
16228
|
-
let cwd;
|
|
16229
|
-
let gitBranch;
|
|
16230
17135
|
let sessionId;
|
|
17136
|
+
let cwd;
|
|
16231
17137
|
for (const line of readLines(transcriptPath)) {
|
|
16232
17138
|
let entry;
|
|
16233
17139
|
try {
|
|
@@ -16235,26 +17141,24 @@ function parseTranscriptForBackfill(transcriptPath) {
|
|
|
16235
17141
|
} catch {
|
|
16236
17142
|
continue;
|
|
16237
17143
|
}
|
|
16238
|
-
if (entry.cwd)
|
|
16239
|
-
cwd = entry.cwd;
|
|
16240
|
-
if (entry.gitBranch)
|
|
16241
|
-
gitBranch = entry.gitBranch;
|
|
16242
17144
|
if (entry.sessionId)
|
|
16243
17145
|
sessionId = entry.sessionId;
|
|
17146
|
+
if (!cwd && entry.cwd)
|
|
17147
|
+
cwd = entry.cwd;
|
|
16244
17148
|
if (entry.isMeta || entry.isSidechain)
|
|
16245
17149
|
continue;
|
|
16246
17150
|
const type = entryType(entry);
|
|
16247
17151
|
if (type === "user") {
|
|
16248
17152
|
if (!isRealUserPrompt(entry))
|
|
16249
17153
|
continue;
|
|
16250
|
-
const content = userText(entry).trim();
|
|
17154
|
+
const content = stripLeadingReminders(userText(entry)).trim();
|
|
16251
17155
|
if (content) {
|
|
16252
|
-
messages.push({ role: "user", content, timestamp: entry.timestamp
|
|
17156
|
+
messages.push({ role: "user", content, timestamp: entry.timestamp });
|
|
16253
17157
|
}
|
|
16254
17158
|
} else if (type === "assistant") {
|
|
16255
17159
|
const content = assistantText(entry).trim();
|
|
16256
17160
|
if (content) {
|
|
16257
|
-
messages.push({ role: "assistant", content, timestamp: entry.timestamp
|
|
17161
|
+
messages.push({ role: "assistant", content, timestamp: entry.timestamp });
|
|
16258
17162
|
}
|
|
16259
17163
|
}
|
|
16260
17164
|
}
|
|
@@ -16264,16 +17168,16 @@ function parseTranscriptForBackfill(transcriptPath) {
|
|
|
16264
17168
|
const next = messages[i + 1];
|
|
16265
17169
|
messages[i].isResponse = !next || next.role === "user";
|
|
16266
17170
|
}
|
|
16267
|
-
return { messages,
|
|
17171
|
+
return { messages, sessionId, cwd };
|
|
16268
17172
|
}
|
|
16269
|
-
var PROJECTS_DIR =
|
|
17173
|
+
var PROJECTS_DIR = join5(homedir2(), ".claude", "projects");
|
|
16270
17174
|
function findTranscripts(days) {
|
|
16271
|
-
if (!
|
|
17175
|
+
if (!existsSync6(PROJECTS_DIR))
|
|
16272
17176
|
return [];
|
|
16273
17177
|
const cutoff = Date.now() - days * 24 * 60 * 60 * 1000;
|
|
16274
17178
|
const out = [];
|
|
16275
17179
|
for (const dir of readdirSync(PROJECTS_DIR)) {
|
|
16276
|
-
const dirPath =
|
|
17180
|
+
const dirPath = join5(PROJECTS_DIR, dir);
|
|
16277
17181
|
let entries;
|
|
16278
17182
|
try {
|
|
16279
17183
|
if (!statSync2(dirPath).isDirectory())
|
|
@@ -16285,7 +17189,7 @@ function findTranscripts(days) {
|
|
|
16285
17189
|
for (const file of entries) {
|
|
16286
17190
|
if (!file.endsWith(".jsonl"))
|
|
16287
17191
|
continue;
|
|
16288
|
-
const path =
|
|
17192
|
+
const path = join5(dirPath, file);
|
|
16289
17193
|
try {
|
|
16290
17194
|
const st = statSync2(path);
|
|
16291
17195
|
if (st.mtimeMs >= cutoff)
|
|
@@ -16299,166 +17203,152 @@ function findTranscripts(days) {
|
|
|
16299
17203
|
}
|
|
16300
17204
|
|
|
16301
17205
|
// src/skills/setup.ts
|
|
16302
|
-
|
|
16303
|
-
import { dirname as dirname2, join as join5 } from "path";
|
|
16304
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
16305
|
-
function installStatusline() {
|
|
16306
|
-
console.log(section("Installing memory statusLine"));
|
|
16307
|
-
const src = join5(dirname2(fileURLToPath2(import.meta.url)), "..", "..", "scripts", "honcho-statusline.sh");
|
|
16308
|
-
const dest = join5(getConfigDir(), "honcho-statusline.sh");
|
|
16309
|
-
try {
|
|
16310
|
-
if (!existsSync5(getConfigDir()))
|
|
16311
|
-
mkdirSync3(getConfigDir(), { recursive: true });
|
|
16312
|
-
copyFileSync(src, dest);
|
|
16313
|
-
chmodSync(dest, 493);
|
|
16314
|
-
console.log(success(`Renderer installed at ${dest}`));
|
|
16315
|
-
} catch (err) {
|
|
16316
|
-
console.log(warn(`Could not install renderer: ${err instanceof Error ? err.message : String(err)}`));
|
|
16317
|
-
return;
|
|
16318
|
-
}
|
|
16319
|
-
try {
|
|
16320
|
-
const raw = existsSync5(getConfigPath()) ? JSON.parse(readFileSync4(getConfigPath(), "utf-8")) : {};
|
|
16321
|
-
if (raw.statusline === undefined)
|
|
16322
|
-
saveRootField("statusline", "on");
|
|
16323
|
-
} catch {}
|
|
16324
|
-
const settingsPath = getClaudeSettingsPath();
|
|
16325
|
-
let settings = {};
|
|
17206
|
+
function configHasOnlyGrants() {
|
|
16326
17207
|
try {
|
|
16327
|
-
|
|
16328
|
-
|
|
17208
|
+
const file = JSON.parse(readFileSync6(getConfigPath(), "utf-8"));
|
|
17209
|
+
const hosts = file.hosts ?? {};
|
|
17210
|
+
return Object.keys(file).every((k) => k === "hosts" || k === "oauth") && Object.values(hosts).every((b) => Object.keys(b ?? {}).every((k) => k === "oauth" || k === "apiKey"));
|
|
16329
17211
|
} catch {
|
|
16330
|
-
|
|
16331
|
-
console.log(dim(` "statusLine": { "type": "command", "command": "${dest}" }`));
|
|
16332
|
-
return;
|
|
17212
|
+
return false;
|
|
16333
17213
|
}
|
|
16334
|
-
|
|
16335
|
-
|
|
16336
|
-
|
|
16337
|
-
|
|
16338
|
-
|
|
16339
|
-
|
|
16340
|
-
|
|
16341
|
-
|
|
16342
|
-
|
|
16343
|
-
writeFileSync3(settingsPath, JSON.stringify(settings, null, 2));
|
|
16344
|
-
console.log(success("statusLine refreshInterval enabled — memory glyph now animates"));
|
|
16345
|
-
} catch (err) {
|
|
16346
|
-
console.log(warn(`Could not update settings.json: ${err instanceof Error ? err.message : String(err)}`));
|
|
17214
|
+
}
|
|
17215
|
+
async function validate(config) {
|
|
17216
|
+
try {
|
|
17217
|
+
await (await createHonchoClient(config)).workspaces();
|
|
17218
|
+
return null;
|
|
17219
|
+
} catch (e) {
|
|
17220
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
17221
|
+
if (/401|auth|invalid api key/i.test(msg)) {
|
|
17222
|
+
return config.auth?.source === "oauth" ? "Your Honcho sign-in was rejected. Sign in again." : "That API key was rejected.";
|
|
16347
17223
|
}
|
|
16348
|
-
return
|
|
16349
|
-
}
|
|
16350
|
-
if (existing) {
|
|
16351
|
-
console.log(warn("A different statusLine is already configured — leaving it untouched."));
|
|
16352
|
-
console.log(dim(" To use honcho's instead, set settings.json statusLine.command to:"));
|
|
16353
|
-
console.log(dim(` ${dest}`));
|
|
16354
|
-
console.log(dim(` and add "refreshInterval": ${REFRESH} so the glyph animates.`));
|
|
16355
|
-
return;
|
|
17224
|
+
return `Could not reach Honcho: ${msg.slice(0, 200)}`;
|
|
16356
17225
|
}
|
|
16357
|
-
|
|
17226
|
+
}
|
|
17227
|
+
async function finish(config) {
|
|
17228
|
+
const problem = await validate(config);
|
|
17229
|
+
if (problem)
|
|
17230
|
+
return { ok: false, error: problem };
|
|
17231
|
+
if (!configExists() || configHasOnlyGrants()) {
|
|
17232
|
+
if (config.auth?.source === "env")
|
|
17233
|
+
await saveHostApiKey(config.apiKey);
|
|
17234
|
+
}
|
|
17235
|
+
return { ok: true, ...await state() };
|
|
17236
|
+
}
|
|
17237
|
+
async function state() {
|
|
17238
|
+
setDetectedHost("claude_code");
|
|
17239
|
+
const config = loadConfig2();
|
|
17240
|
+
let transcripts = 0;
|
|
16358
17241
|
try {
|
|
16359
|
-
|
|
16360
|
-
|
|
16361
|
-
|
|
16362
|
-
|
|
16363
|
-
|
|
16364
|
-
|
|
16365
|
-
|
|
16366
|
-
|
|
17242
|
+
transcripts = findTranscripts(30).length;
|
|
17243
|
+
} catch {}
|
|
17244
|
+
const file = readConfigFile();
|
|
17245
|
+
const hosts = file.hosts ?? {};
|
|
17246
|
+
const others = Object.entries(hosts).filter(([h, b]) => h !== "claude_code" && typeof b?.peerName === "string").map(([h, b]) => ({ host: h, peerName: b.peerName }));
|
|
17247
|
+
return {
|
|
17248
|
+
connected: !!config,
|
|
17249
|
+
canSignIn: isCloud(getConfiguredOrigin()),
|
|
17250
|
+
hasName: typeof hosts.claude_code?.peerName === "string" || !!process.env.HONCHO_PEER_NAME,
|
|
17251
|
+
suggestedName: suggestPeerName(file),
|
|
17252
|
+
others,
|
|
17253
|
+
auth: config ? describeAuth(config) : null,
|
|
17254
|
+
workspace: config?.workspace ?? null,
|
|
17255
|
+
peer: config?.peerName ?? null,
|
|
17256
|
+
transcripts
|
|
17257
|
+
};
|
|
16367
17258
|
}
|
|
16368
|
-
async function
|
|
17259
|
+
async function connectExisting() {
|
|
16369
17260
|
setDetectedHost("claude_code");
|
|
16370
|
-
|
|
16371
|
-
|
|
16372
|
-
|
|
16373
|
-
|
|
16374
|
-
|
|
16375
|
-
|
|
16376
|
-
|
|
16377
|
-
|
|
16378
|
-
const configData = JSON.parse(configRaw);
|
|
16379
|
-
apiKey = configData.apiKey;
|
|
16380
|
-
keySource = "config";
|
|
16381
|
-
} catch {}
|
|
16382
|
-
}
|
|
16383
|
-
if (!apiKey) {
|
|
16384
|
-
console.log(warn("No API key found (checked env and config)"));
|
|
16385
|
-
console.log("");
|
|
16386
|
-
console.log(" 1. Get a free key at https://app.honcho.dev");
|
|
16387
|
-
if (process.platform === "win32") {
|
|
16388
|
-
console.log(" 2. Set it in PowerShell:");
|
|
16389
|
-
console.log(dim(' setx HONCHO_API_KEY "your-key-here"'));
|
|
16390
|
-
} else {
|
|
16391
|
-
console.log(" 2. Add to ~/.zshrc or ~/.bashrc:");
|
|
16392
|
-
console.log(dim(' export HONCHO_API_KEY="your-key-here"'));
|
|
16393
|
-
}
|
|
16394
|
-
console.log(" 3. Restart Claude Code and run /honcho:setup");
|
|
16395
|
-
process.exit(1);
|
|
17261
|
+
const config = loadConfig2();
|
|
17262
|
+
return config ? finish(config) : { ok: false, error: "Not connected." };
|
|
17263
|
+
}
|
|
17264
|
+
async function beginSignIn() {
|
|
17265
|
+
try {
|
|
17266
|
+
return { ok: true, ...await startSignIn() };
|
|
17267
|
+
} catch (e) {
|
|
17268
|
+
return { ok: false, error: `Could not start sign-in: ${e instanceof Error ? e.message : String(e)}` };
|
|
16396
17269
|
}
|
|
16397
|
-
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
const
|
|
16401
|
-
if (
|
|
16402
|
-
|
|
16403
|
-
|
|
17270
|
+
}
|
|
17271
|
+
async function pollSignIn() {
|
|
17272
|
+
setDetectedHost("claude_code");
|
|
17273
|
+
const status = await checkSignIn();
|
|
17274
|
+
if (status !== "approved")
|
|
17275
|
+
return { ok: true, status };
|
|
17276
|
+
const config = loadConfig2();
|
|
17277
|
+
if (!config)
|
|
17278
|
+
return { ok: false, error: "Signed in, but the config could not be read." };
|
|
17279
|
+
return { ...await finish(config), status };
|
|
17280
|
+
}
|
|
17281
|
+
async function saveName(name) {
|
|
17282
|
+
setDetectedHost("claude_code");
|
|
17283
|
+
name = name.trim();
|
|
17284
|
+
if (!name)
|
|
17285
|
+
return { ok: false, error: "Enter a name." };
|
|
17286
|
+
const config = loadConfig2();
|
|
17287
|
+
if (!config)
|
|
17288
|
+
return { ok: false, error: "Not connected." };
|
|
17289
|
+
await saveConfig({ ...config, peerName: name });
|
|
17290
|
+
return { ok: true, ...await state() };
|
|
17291
|
+
}
|
|
17292
|
+
async function saveApiKey(key) {
|
|
17293
|
+
setDetectedHost("claude_code");
|
|
17294
|
+
key = key.trim();
|
|
17295
|
+
if (!key)
|
|
17296
|
+
return { ok: false, error: "Enter an API key." };
|
|
17297
|
+
let previous;
|
|
17298
|
+
try {
|
|
17299
|
+
previous = JSON.parse(readFileSync6(getConfigPath(), "utf-8")).hosts?.claude_code?.apiKey;
|
|
17300
|
+
} catch {}
|
|
17301
|
+
await saveHostApiKey(key);
|
|
17302
|
+
const config = loadConfig2();
|
|
17303
|
+
const problem = config ? await validate(config) : "Could not read the config.";
|
|
17304
|
+
if (problem) {
|
|
17305
|
+
await saveHostApiKey(previous);
|
|
17306
|
+
return { ok: false, error: problem };
|
|
16404
17307
|
}
|
|
17308
|
+
return finish(config);
|
|
17309
|
+
}
|
|
17310
|
+
|
|
17311
|
+
// src/skills/pane.ts
|
|
17312
|
+
async function overview() {
|
|
17313
|
+
const config = loadConfig2();
|
|
17314
|
+
if (!config)
|
|
17315
|
+
return { ok: false, error: "Honcho is not configured; run /honcho setup" };
|
|
17316
|
+
const sessionName = getSessionName();
|
|
16405
17317
|
try {
|
|
16406
|
-
const
|
|
16407
|
-
await
|
|
16408
|
-
|
|
16409
|
-
|
|
16410
|
-
|
|
16411
|
-
|
|
16412
|
-
|
|
16413
|
-
|
|
16414
|
-
|
|
16415
|
-
|
|
16416
|
-
|
|
16417
|
-
|
|
16418
|
-
|
|
16419
|
-
|
|
16420
|
-
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
|
|
16424
|
-
saveRootField("apiKey", config.apiKey);
|
|
16425
|
-
saveRootField("peerName", config.peerName);
|
|
16426
|
-
saveConfig({
|
|
16427
|
-
apiKey: config.apiKey,
|
|
16428
|
-
peerName: config.peerName,
|
|
16429
|
-
workspace: config.workspace,
|
|
16430
|
-
aiPeer: config.aiPeer,
|
|
16431
|
-
saveMessages: true,
|
|
16432
|
-
enabled: true,
|
|
16433
|
-
logging: true
|
|
16434
|
-
});
|
|
16435
|
-
console.log(success(`Written to ${getConfigPath()}`));
|
|
16436
|
-
} catch (err) {
|
|
16437
|
-
console.log(warn(`Failed to write config: ${err instanceof Error ? err.message : String(err)}`));
|
|
16438
|
-
process.exit(1);
|
|
16439
|
-
}
|
|
16440
|
-
console.log("");
|
|
16441
|
-
} else {
|
|
16442
|
-
console.log(dim(`Config already exists at ${getConfigPath()}`));
|
|
16443
|
-
console.log("");
|
|
16444
|
-
}
|
|
16445
|
-
installStatusline();
|
|
16446
|
-
console.log("");
|
|
17318
|
+
const peer = await (await createHonchoClient(config)).peer(config.peerName);
|
|
17319
|
+
const card = await peer.getCard().catch(() => null);
|
|
17320
|
+
return {
|
|
17321
|
+
ok: true,
|
|
17322
|
+
session: sessionName,
|
|
17323
|
+
sessionUrl: sessionName ? honchoSessionUrl(config, sessionName) : null,
|
|
17324
|
+
card: card ?? []
|
|
17325
|
+
};
|
|
17326
|
+
} catch (err) {
|
|
17327
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
17328
|
+
const status = Number(message.match(/\b([45]\d\d)\b/)?.[1]) || undefined;
|
|
17329
|
+
return { ok: false, status, error: message.slice(0, 300) };
|
|
17330
|
+
}
|
|
17331
|
+
}
|
|
17332
|
+
async function dreams(read) {
|
|
17333
|
+
const config = loadConfig2();
|
|
17334
|
+
if (!config)
|
|
17335
|
+
return { ok: false, error: "Honcho is not configured; run /honcho setup" };
|
|
16447
17336
|
try {
|
|
16448
|
-
const
|
|
16449
|
-
|
|
16450
|
-
|
|
16451
|
-
|
|
16452
|
-
|
|
16453
|
-
|
|
16454
|
-
|
|
16455
|
-
|
|
16456
|
-
|
|
16457
|
-
|
|
17337
|
+
const data = await read(await createHonchoClient(config, { timeout: 15000 }));
|
|
17338
|
+
return { ok: true, workspace: config.workspace, peer: config.peerName, data };
|
|
17339
|
+
} catch (err) {
|
|
17340
|
+
const status = err instanceof import_sdk2.HonchoError && err.status > 0 ? err.status : undefined;
|
|
17341
|
+
return { ok: false, status, error: (err instanceof Error ? err.message : String(err)).slice(0, 300) };
|
|
17342
|
+
}
|
|
17343
|
+
}
|
|
17344
|
+
async function run(cmd, arg) {
|
|
17345
|
+
const peerName = loadConfig2()?.peerName;
|
|
17346
|
+
const reply = cmd === "overview" ? await overview() : cmd === "dreams-list" ? await dreams(async (honcho) => ({ items: (await honcho.dreams({ observed: peerName, page: 1, size: 20 })).items })) : cmd === "dreams-get" && arg ? await dreams((honcho) => honcho.getDream(arg)) : cmd === "setup-state" ? { ok: true, ...await state() } : cmd === "setup-connect" ? await connectExisting() : cmd === "signin-start" ? await beginSignIn() : cmd === "signin-check" ? await pollSignIn() : cmd === "setup-key" ? await saveApiKey(await new Response(process.stdin).text()) : cmd === "setup-name" ? await saveName(await new Response(process.stdin).text()) : { ok: false, error: `unknown command: ${cmd ?? ""}` };
|
|
17347
|
+
console.log(JSON.stringify(reply));
|
|
16458
17348
|
}
|
|
16459
17349
|
|
|
16460
|
-
// src/skills/
|
|
16461
|
-
await
|
|
17350
|
+
// src/skills/pane-runner.ts
|
|
17351
|
+
await run(process.argv[2], process.argv[3]);
|
|
16462
17352
|
|
|
16463
|
-
//# debugId=
|
|
16464
|
-
//# sourceMappingURL=
|
|
17353
|
+
//# debugId=E2164D412E8EC4A164756E2164756E21
|
|
17354
|
+
//# sourceMappingURL=pane-runner.js.map
|