@honcho-ai/claude-honcho 0.3.4 → 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 +549 -615
- package/dist/hooks/pre-tool-honcho.js.map +11 -9
- package/dist/hooks/save-user-message.js +1721 -1066
- package/dist/hooks/save-user-message.js.map +24 -19
- package/dist/hooks/session-end.js +557 -628
- package/dist/hooks/session-end.js.map +11 -9
- package/dist/hooks/session-start.js +1925 -1313
- package/dist/hooks/session-start.js.map +31 -22
- package/dist/hooks/stop.js +1742 -1160
- package/dist/hooks/stop.js.map +25 -20
- package/dist/hooks/user-prompt.js +690 -16611
- package/dist/hooks/user-prompt.js.map +13 -90
- package/dist/mcp-server.js +1595 -1612
- package/dist/mcp-server.js.map +23 -20
- package/dist/skills/backfill-runner.js +1816 -919
- package/dist/skills/backfill-runner.js.map +27 -21
- package/dist/skills/{setup-runner.js → pane-runner.js} +1902 -1030
- package/dist/{hooks/pre-compact.js.map → skills/pane-runner.js.map} +28 -24
- package/dist/skills/status-runner.js +1567 -761
- package/dist/skills/status-runner.js.map +23 -19
- package/hooks/hooks.json +4 -36
- 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 -16924
- package/dist/hooks/post-tool-use.js.map +0 -97
- package/dist/hooks/pre-compact.js +0 -17111
- package/dist/skills/setup-runner.js.map +0 -96
- 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
package/dist/mcp-server.js
CHANGED
|
@@ -6499,8 +6499,9 @@ var require_dist = __commonJS(function(exports, module) {
|
|
|
6499
6499
|
// node_modules/@honcho-ai/sdk/dist/api-version.js
|
|
6500
6500
|
var require_api_version = __commonJS(function(exports) {
|
|
6501
6501
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6502
|
-
exports.API_VERSION = undefined;
|
|
6502
|
+
exports.VERSION = exports.API_VERSION = undefined;
|
|
6503
6503
|
exports.API_VERSION = "v3";
|
|
6504
|
+
exports.VERSION = "2.9.0";
|
|
6504
6505
|
});
|
|
6505
6506
|
|
|
6506
6507
|
// node_modules/@honcho-ai/sdk/dist/http/errors.js
|
|
@@ -6625,255 +6626,6 @@ var require_errors2 = __commonJS(function(exports) {
|
|
|
6625
6626
|
}
|
|
6626
6627
|
});
|
|
6627
6628
|
|
|
6628
|
-
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
6629
|
-
var require_client = __commonJS(function(exports) {
|
|
6630
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6631
|
-
exports.HonchoHTTPClient = undefined;
|
|
6632
|
-
var errors_1 = require_errors2();
|
|
6633
|
-
var DEFAULT_TIMEOUT = 60000;
|
|
6634
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
6635
|
-
var RETRY_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
6636
|
-
var INITIAL_RETRY_DELAY = 500;
|
|
6637
|
-
|
|
6638
|
-
class HonchoHTTPClient {
|
|
6639
|
-
constructor(config) {
|
|
6640
|
-
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
6641
|
-
this.apiKey = config.apiKey;
|
|
6642
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
6643
|
-
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
6644
|
-
this.defaultHeaders = {
|
|
6645
|
-
"Content-Type": "application/json",
|
|
6646
|
-
...config.defaultHeaders
|
|
6647
|
-
};
|
|
6648
|
-
this.defaultQuery = config.defaultQuery;
|
|
6649
|
-
}
|
|
6650
|
-
async request(method, path, options = {}) {
|
|
6651
|
-
const url = this.buildURL(path, options.query);
|
|
6652
|
-
const headers = this.buildHeaders(options.headers);
|
|
6653
|
-
const timeout = options.timeout ?? this.timeout;
|
|
6654
|
-
let lastError;
|
|
6655
|
-
let attempt = 0;
|
|
6656
|
-
while (attempt <= this.maxRetries) {
|
|
6657
|
-
try {
|
|
6658
|
-
const response = await this.fetchWithTimeout(url, {
|
|
6659
|
-
method,
|
|
6660
|
-
headers,
|
|
6661
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
6662
|
-
signal: options.signal
|
|
6663
|
-
}, timeout);
|
|
6664
|
-
if (response.ok) {
|
|
6665
|
-
const text = await response.text();
|
|
6666
|
-
if (!text) {
|
|
6667
|
-
return;
|
|
6668
|
-
}
|
|
6669
|
-
return JSON.parse(text);
|
|
6670
|
-
}
|
|
6671
|
-
const errorBody = await this.parseErrorBody(response);
|
|
6672
|
-
const retryAfter = this.parseRetryAfter(response);
|
|
6673
|
-
const error = (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody, retryAfter);
|
|
6674
|
-
if (RETRY_STATUS_CODES.includes(response.status) && attempt < this.maxRetries) {
|
|
6675
|
-
lastError = error;
|
|
6676
|
-
await this.sleep(this.getRetryDelay(attempt, retryAfter));
|
|
6677
|
-
attempt++;
|
|
6678
|
-
continue;
|
|
6679
|
-
}
|
|
6680
|
-
throw error;
|
|
6681
|
-
} catch (error) {
|
|
6682
|
-
if (error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
6683
|
-
if (attempt < this.maxRetries) {
|
|
6684
|
-
lastError = error;
|
|
6685
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
6686
|
-
attempt++;
|
|
6687
|
-
continue;
|
|
6688
|
-
}
|
|
6689
|
-
}
|
|
6690
|
-
if (error instanceof errors_1.RateLimitError || error instanceof errors_1.ServerError || error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
6691
|
-
throw error;
|
|
6692
|
-
}
|
|
6693
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
6694
|
-
const connError = new errors_1.ConnectionError(error.message);
|
|
6695
|
-
if (attempt < this.maxRetries) {
|
|
6696
|
-
lastError = connError;
|
|
6697
|
-
await this.sleep(this.getRetryDelay(attempt));
|
|
6698
|
-
attempt++;
|
|
6699
|
-
continue;
|
|
6700
|
-
}
|
|
6701
|
-
throw connError;
|
|
6702
|
-
}
|
|
6703
|
-
throw error;
|
|
6704
|
-
}
|
|
6705
|
-
}
|
|
6706
|
-
throw lastError || new Error("Request failed after retries");
|
|
6707
|
-
}
|
|
6708
|
-
async get(path, options) {
|
|
6709
|
-
return this.request("GET", path, options);
|
|
6710
|
-
}
|
|
6711
|
-
async post(path, options) {
|
|
6712
|
-
return this.request("POST", path, options);
|
|
6713
|
-
}
|
|
6714
|
-
async put(path, options) {
|
|
6715
|
-
return this.request("PUT", path, options);
|
|
6716
|
-
}
|
|
6717
|
-
async patch(path, options) {
|
|
6718
|
-
return this.request("PATCH", path, options);
|
|
6719
|
-
}
|
|
6720
|
-
async delete(path, options) {
|
|
6721
|
-
return this.request("DELETE", path, options);
|
|
6722
|
-
}
|
|
6723
|
-
async stream(method, path, options = {}) {
|
|
6724
|
-
const url = this.buildURL(path, options.query);
|
|
6725
|
-
const headers = {
|
|
6726
|
-
...this.buildHeaders(options.headers),
|
|
6727
|
-
Accept: "text/event-stream"
|
|
6728
|
-
};
|
|
6729
|
-
const timeout = options.timeout ?? this.timeout;
|
|
6730
|
-
const response = await this.fetchWithTimeout(url, {
|
|
6731
|
-
method,
|
|
6732
|
-
headers,
|
|
6733
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
6734
|
-
signal: options.signal
|
|
6735
|
-
}, timeout);
|
|
6736
|
-
if (!response.ok) {
|
|
6737
|
-
const errorBody = await this.parseErrorBody(response);
|
|
6738
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
6739
|
-
}
|
|
6740
|
-
return response;
|
|
6741
|
-
}
|
|
6742
|
-
async upload(path, formData, options = {}) {
|
|
6743
|
-
const url = this.buildURL(path, options.query);
|
|
6744
|
-
const headers = {};
|
|
6745
|
-
if (this.apiKey) {
|
|
6746
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
6747
|
-
}
|
|
6748
|
-
if (options.headers) {
|
|
6749
|
-
Object.assign(headers, options.headers);
|
|
6750
|
-
}
|
|
6751
|
-
const timeout = options.timeout ?? this.timeout;
|
|
6752
|
-
const response = await this.fetchWithTimeout(url, {
|
|
6753
|
-
method: "POST",
|
|
6754
|
-
headers,
|
|
6755
|
-
body: formData,
|
|
6756
|
-
signal: options.signal
|
|
6757
|
-
}, timeout);
|
|
6758
|
-
if (!response.ok) {
|
|
6759
|
-
const errorBody = await this.parseErrorBody(response);
|
|
6760
|
-
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
6761
|
-
}
|
|
6762
|
-
const text = await response.text();
|
|
6763
|
-
if (!text) {
|
|
6764
|
-
return;
|
|
6765
|
-
}
|
|
6766
|
-
return JSON.parse(text);
|
|
6767
|
-
}
|
|
6768
|
-
buildURL(path, query) {
|
|
6769
|
-
const url = new URL(path, this.baseURL);
|
|
6770
|
-
const mergedQuery = {
|
|
6771
|
-
...this.defaultQuery ?? {},
|
|
6772
|
-
...query ?? {}
|
|
6773
|
-
};
|
|
6774
|
-
for (const [key, value] of Object.entries(mergedQuery)) {
|
|
6775
|
-
if (value !== undefined) {
|
|
6776
|
-
url.searchParams.set(key, String(value));
|
|
6777
|
-
}
|
|
6778
|
-
}
|
|
6779
|
-
return url.toString();
|
|
6780
|
-
}
|
|
6781
|
-
buildHeaders(extra) {
|
|
6782
|
-
const headers = { ...this.defaultHeaders };
|
|
6783
|
-
if (this.apiKey) {
|
|
6784
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
6785
|
-
}
|
|
6786
|
-
if (extra) {
|
|
6787
|
-
Object.assign(headers, extra);
|
|
6788
|
-
}
|
|
6789
|
-
return headers;
|
|
6790
|
-
}
|
|
6791
|
-
async fetchWithTimeout(url, init, timeout) {
|
|
6792
|
-
const controller = new AbortController;
|
|
6793
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
6794
|
-
if (init.signal) {
|
|
6795
|
-
init.signal.addEventListener("abort", () => controller.abort());
|
|
6796
|
-
}
|
|
6797
|
-
try {
|
|
6798
|
-
const response = await fetch(url, {
|
|
6799
|
-
...init,
|
|
6800
|
-
signal: controller.signal
|
|
6801
|
-
});
|
|
6802
|
-
return response;
|
|
6803
|
-
} catch (error) {
|
|
6804
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
6805
|
-
throw new errors_1.TimeoutError(`Request timed out after ${timeout}ms`);
|
|
6806
|
-
}
|
|
6807
|
-
throw error;
|
|
6808
|
-
} finally {
|
|
6809
|
-
clearTimeout(timeoutId);
|
|
6810
|
-
}
|
|
6811
|
-
}
|
|
6812
|
-
async parseErrorBody(response) {
|
|
6813
|
-
try {
|
|
6814
|
-
const body = await response.json();
|
|
6815
|
-
return {
|
|
6816
|
-
message: body.detail || body.message || body.error,
|
|
6817
|
-
...body
|
|
6818
|
-
};
|
|
6819
|
-
} catch {
|
|
6820
|
-
return { message: `HTTP ${response.status}` };
|
|
6821
|
-
}
|
|
6822
|
-
}
|
|
6823
|
-
parseRetryAfter(response) {
|
|
6824
|
-
const header = response.headers.get("Retry-After");
|
|
6825
|
-
if (!header)
|
|
6826
|
-
return;
|
|
6827
|
-
const seconds = Number.parseInt(header, 10);
|
|
6828
|
-
if (!Number.isNaN(seconds)) {
|
|
6829
|
-
return seconds * 1000;
|
|
6830
|
-
}
|
|
6831
|
-
const date = Date.parse(header);
|
|
6832
|
-
if (!Number.isNaN(date)) {
|
|
6833
|
-
return Math.max(0, date - Date.now());
|
|
6834
|
-
}
|
|
6835
|
-
return;
|
|
6836
|
-
}
|
|
6837
|
-
getRetryDelay(attempt, retryAfter) {
|
|
6838
|
-
if (retryAfter) {
|
|
6839
|
-
return retryAfter;
|
|
6840
|
-
}
|
|
6841
|
-
return INITIAL_RETRY_DELAY * 2 ** attempt;
|
|
6842
|
-
}
|
|
6843
|
-
sleep(ms) {
|
|
6844
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6845
|
-
}
|
|
6846
|
-
}
|
|
6847
|
-
exports.HonchoHTTPClient = HonchoHTTPClient;
|
|
6848
|
-
});
|
|
6849
|
-
|
|
6850
|
-
// node_modules/@honcho-ai/sdk/dist/message.js
|
|
6851
|
-
var require_message = __commonJS(function(exports) {
|
|
6852
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6853
|
-
exports.Message = undefined;
|
|
6854
|
-
|
|
6855
|
-
class Message {
|
|
6856
|
-
constructor(id, content, peerId, sessionId, workspaceId, metadata, createdAt, tokenCount) {
|
|
6857
|
-
this.id = id;
|
|
6858
|
-
this.content = content;
|
|
6859
|
-
this.peerId = peerId;
|
|
6860
|
-
this.sessionId = sessionId;
|
|
6861
|
-
this.workspaceId = workspaceId;
|
|
6862
|
-
this.metadata = metadata;
|
|
6863
|
-
this.createdAt = createdAt;
|
|
6864
|
-
this.tokenCount = tokenCount;
|
|
6865
|
-
}
|
|
6866
|
-
static fromApiResponse(data) {
|
|
6867
|
-
return new Message(data.id, data.content, data.peer_id, data.session_id, data.workspace_id, data.metadata, data.created_at, data.token_count);
|
|
6868
|
-
}
|
|
6869
|
-
toString() {
|
|
6870
|
-
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
6871
|
-
return `Message(id='${this.id}', peerId='${this.peerId}', content='${truncatedContent}')`;
|
|
6872
|
-
}
|
|
6873
|
-
}
|
|
6874
|
-
exports.Message = Message;
|
|
6875
|
-
});
|
|
6876
|
-
|
|
6877
6629
|
// node_modules/@honcho-ai/sdk/dist/pagination.js
|
|
6878
6630
|
var require_pagination = __commonJS(function(exports) {
|
|
6879
6631
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -20153,9 +19905,10 @@ var require_zod = __commonJS(function(exports) {
|
|
|
20153
19905
|
// node_modules/@honcho-ai/sdk/dist/validation.js
|
|
20154
19906
|
var require_validation2 = __commonJS(function(exports) {
|
|
20155
19907
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20156
|
-
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;
|
|
19908
|
+
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;
|
|
20157
19909
|
exports.normalizeSearchQuery = normalizeSearchQuery;
|
|
20158
19910
|
exports.normalizeListOptions = normalizeListOptions;
|
|
19911
|
+
exports.scopeRecallFields = scopeRecallFields;
|
|
20159
19912
|
exports.peerConfigToApi = peerConfigToApi;
|
|
20160
19913
|
exports.peerConfigFromApi = peerConfigFromApi;
|
|
20161
19914
|
exports.workspaceConfigToApi = workspaceConfigToApi;
|
|
@@ -20165,7 +19918,7 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20165
19918
|
exports.messageConfigToApi = messageConfigToApi;
|
|
20166
19919
|
exports.messageConfigFromApi = messageConfigFromApi;
|
|
20167
19920
|
var zod_1 = require_zod();
|
|
20168
|
-
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(
|
|
19921
|
+
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");
|
|
20169
19922
|
exports.HonchoConfigSchema = zod_1.z.object({
|
|
20170
19923
|
apiKey: zod_1.z.string().optional(),
|
|
20171
19924
|
environment: zod_1.z.enum(["local", "production"]).optional(),
|
|
@@ -20180,7 +19933,7 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20180
19933
|
exports.PeerConfigSchema = zod_1.z.object({
|
|
20181
19934
|
observeMe: zod_1.z.boolean().nullable().optional()
|
|
20182
19935
|
}).strict();
|
|
20183
|
-
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(
|
|
19936
|
+
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");
|
|
20184
19937
|
var PeerIdObjectSchema = zod_1.z.object({ id: exports.PeerIdSchema });
|
|
20185
19938
|
exports.SessionMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
20186
19939
|
exports.ReasoningConfigSchema = zod_1.z.object({
|
|
@@ -20189,32 +19942,92 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20189
19942
|
}).strict();
|
|
20190
19943
|
exports.PeerCardConfigSchema = zod_1.z.object({
|
|
20191
19944
|
use: zod_1.z.boolean().nullable().optional(),
|
|
20192
|
-
create: zod_1.z.boolean().nullable().optional()
|
|
19945
|
+
create: zod_1.z.boolean().nullable().optional(),
|
|
19946
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
20193
19947
|
}).strict();
|
|
20194
19948
|
exports.SummaryConfigSchema = zod_1.z.object({
|
|
20195
19949
|
enabled: zod_1.z.boolean().nullable().optional(),
|
|
20196
19950
|
messagesPerShortSummary: zod_1.z.number().int().min(10).nullable().optional(),
|
|
20197
|
-
messagesPerLongSummary: zod_1.z.number().int().min(20).nullable().optional()
|
|
19951
|
+
messagesPerLongSummary: zod_1.z.number().int().min(20).nullable().optional(),
|
|
19952
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
20198
19953
|
}).strict();
|
|
20199
19954
|
exports.DreamConfigSchema = zod_1.z.object({
|
|
20200
|
-
enabled: zod_1.z.boolean().nullable().optional()
|
|
19955
|
+
enabled: zod_1.z.boolean().nullable().optional(),
|
|
19956
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
19957
|
+
}).strict();
|
|
19958
|
+
exports.DialecticConfigSchema = zod_1.z.object({
|
|
19959
|
+
customInstructions: zod_1.z.string().nullable().optional()
|
|
20201
19960
|
}).strict();
|
|
20202
19961
|
exports.SessionConfigSchema = zod_1.z.object({
|
|
19962
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
20203
19963
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
20204
19964
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
20205
19965
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
20206
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
19966
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
19967
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
20207
19968
|
}).strict();
|
|
20208
|
-
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(
|
|
19969
|
+
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");
|
|
20209
19970
|
var SessionIdObjectSchema = zod_1.z.object({ id: exports.SessionIdSchema });
|
|
20210
|
-
|
|
20211
|
-
|
|
20212
|
-
|
|
20213
|
-
|
|
20214
|
-
|
|
20215
|
-
|
|
20216
|
-
|
|
20217
|
-
|
|
19971
|
+
var SCOPE_PEER_PREFIX = "scope.";
|
|
19972
|
+
var SCOPE_ID_MAX_LENGTH = 512 - SCOPE_PEER_PREFIX.length;
|
|
19973
|
+
function scopeIdIssues(value) {
|
|
19974
|
+
if (value.length < 1) {
|
|
19975
|
+
return ["Scope ID must be a non-empty string"];
|
|
19976
|
+
}
|
|
19977
|
+
if (value.length > SCOPE_ID_MAX_LENGTH) {
|
|
19978
|
+
return [`Scope ID can be at most ${SCOPE_ID_MAX_LENGTH} characters`];
|
|
19979
|
+
}
|
|
19980
|
+
if (value.startsWith(SCOPE_PEER_PREFIX)) {
|
|
19981
|
+
return [
|
|
19982
|
+
`Scope ID must not start with the reserved prefix '${SCOPE_PEER_PREFIX}' (scope IDs are unprefixed)`
|
|
19983
|
+
];
|
|
19984
|
+
}
|
|
19985
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
|
|
19986
|
+
return [
|
|
19987
|
+
"Scope ID may only contain letters, numbers, underscores, and hyphens"
|
|
19988
|
+
];
|
|
19989
|
+
}
|
|
19990
|
+
return [];
|
|
19991
|
+
}
|
|
19992
|
+
function addScopeIdIssues(values, ctx) {
|
|
19993
|
+
for (const value of values) {
|
|
19994
|
+
for (const message of scopeIdIssues(value)) {
|
|
19995
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message });
|
|
19996
|
+
}
|
|
19997
|
+
}
|
|
19998
|
+
}
|
|
19999
|
+
exports.ScopeIdSchema = zod_1.z.string().superRefine((val, ctx) => {
|
|
20000
|
+
addScopeIdIssues([val], ctx);
|
|
20001
|
+
});
|
|
20002
|
+
var ScopeIdLikeSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.object({ id: zod_1.z.string() })]);
|
|
20003
|
+
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) => {
|
|
20004
|
+
if (Array.isArray(resolved)) {
|
|
20005
|
+
if (resolved.length === 0) {
|
|
20006
|
+
ctx.addIssue({
|
|
20007
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20008
|
+
message: "scope must name at least one scope"
|
|
20009
|
+
});
|
|
20010
|
+
}
|
|
20011
|
+
if (resolved.length > 100) {
|
|
20012
|
+
ctx.addIssue({
|
|
20013
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20014
|
+
message: "scope can name at most 100 scopes"
|
|
20015
|
+
});
|
|
20016
|
+
}
|
|
20017
|
+
}
|
|
20018
|
+
addScopeIdIssues(Array.isArray(resolved) ? resolved : [resolved], ctx);
|
|
20019
|
+
});
|
|
20020
|
+
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");
|
|
20021
|
+
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");
|
|
20022
|
+
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));
|
|
20023
|
+
exports.SessionPeerConfigSchema = zod_1.z.object({
|
|
20024
|
+
observeMe: zod_1.z.boolean().nullable().optional(),
|
|
20025
|
+
observeOthers: zod_1.z.boolean().nullable().optional()
|
|
20026
|
+
}).strict();
|
|
20027
|
+
exports.MessageContentSchema = zod_1.z.string().refine((content) => content === "" || content.trim().length > 0, "Message content cannot be only whitespace");
|
|
20028
|
+
exports.MessageMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional();
|
|
20029
|
+
exports.MessageConfigurationSchema = zod_1.z.object({
|
|
20030
|
+
reasoning: exports.ReasoningConfigSchema.nullable().optional()
|
|
20218
20031
|
}).strict().nullable().optional();
|
|
20219
20032
|
exports.MessageInputSchema = zod_1.z.object({
|
|
20220
20033
|
peerId: exports.PeerIdSchema,
|
|
@@ -20254,12 +20067,41 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20254
20067
|
}
|
|
20255
20068
|
return { filters: input };
|
|
20256
20069
|
}
|
|
20070
|
+
function scopeRecallFields(options) {
|
|
20071
|
+
return {
|
|
20072
|
+
scope: options.scope,
|
|
20073
|
+
filters: options.sessions ? { session_id: options.sessions } : undefined
|
|
20074
|
+
};
|
|
20075
|
+
}
|
|
20076
|
+
function scopeExclusivityIssues(data, ctx) {
|
|
20077
|
+
if (data.scope === undefined) {
|
|
20078
|
+
return;
|
|
20079
|
+
}
|
|
20080
|
+
if (data.sessions !== undefined) {
|
|
20081
|
+
ctx.addIssue({
|
|
20082
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20083
|
+
message: "scope and sessions are mutually exclusive",
|
|
20084
|
+
path: ["sessions"]
|
|
20085
|
+
});
|
|
20086
|
+
}
|
|
20087
|
+
if (data.session !== undefined) {
|
|
20088
|
+
ctx.addIssue({
|
|
20089
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20090
|
+
message: "scope and session are mutually exclusive",
|
|
20091
|
+
path: ["session"]
|
|
20092
|
+
});
|
|
20093
|
+
}
|
|
20094
|
+
}
|
|
20257
20095
|
exports.ChatQuerySchema = zod_1.z.object({
|
|
20258
20096
|
query: exports.SearchQuerySchema,
|
|
20259
20097
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
20260
20098
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined),
|
|
20261
|
-
|
|
20262
|
-
|
|
20099
|
+
scope: exports.ScopeOptionSchema.optional(),
|
|
20100
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
20101
|
+
reasoningLevel: zod_1.z.enum(["minimal", "low", "medium", "high", "max"]).optional(),
|
|
20102
|
+
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(),
|
|
20103
|
+
includeEvidence: zod_1.z.boolean().optional()
|
|
20104
|
+
}).strict().superRefine(scopeExclusivityIssues);
|
|
20263
20105
|
exports.RepresentationOptionsSchema = zod_1.z.object({
|
|
20264
20106
|
searchQuery: exports.SearchQueryLikeSchema.optional(),
|
|
20265
20107
|
searchTopK: zod_1.z.number().int().min(1, "searchTopK must be at least 1").max(100, "searchTopK must be at most 100").optional(),
|
|
@@ -20272,9 +20114,32 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20272
20114
|
tokens: zod_1.z.int("Token limit must be an integer").optional(),
|
|
20273
20115
|
peerTarget: exports.PeerIdSchema.optional(),
|
|
20274
20116
|
peerPerspective: exports.PeerIdSchema.optional(),
|
|
20117
|
+
scope: exports.ScopeIdSchema.optional(),
|
|
20118
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
20275
20119
|
limitToSession: zod_1.z.boolean().optional(),
|
|
20276
20120
|
representationOptions: exports.RepresentationOptionsSchema.optional()
|
|
20277
20121
|
}).strict().superRefine((data, ctx) => {
|
|
20122
|
+
if (data.sessions && !data.peerTarget) {
|
|
20123
|
+
ctx.addIssue({
|
|
20124
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20125
|
+
message: "peerTarget is required when sessions is provided",
|
|
20126
|
+
path: ["sessions"]
|
|
20127
|
+
});
|
|
20128
|
+
}
|
|
20129
|
+
if (data.sessions && data.scope) {
|
|
20130
|
+
ctx.addIssue({
|
|
20131
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20132
|
+
message: "sessions and scope are mutually exclusive",
|
|
20133
|
+
path: ["sessions"]
|
|
20134
|
+
});
|
|
20135
|
+
}
|
|
20136
|
+
if (data.sessions && data.limitToSession) {
|
|
20137
|
+
ctx.addIssue({
|
|
20138
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20139
|
+
message: "sessions and limitToSession are mutually exclusive",
|
|
20140
|
+
path: ["sessions"]
|
|
20141
|
+
});
|
|
20142
|
+
}
|
|
20278
20143
|
if (data.representationOptions?.searchQuery && !data.peerTarget) {
|
|
20279
20144
|
ctx.addIssue({
|
|
20280
20145
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -20289,6 +20154,20 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20289
20154
|
path: ["peerPerspective"]
|
|
20290
20155
|
});
|
|
20291
20156
|
}
|
|
20157
|
+
if (data.scope && !data.peerTarget) {
|
|
20158
|
+
ctx.addIssue({
|
|
20159
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20160
|
+
message: "peerTarget is required when scope is provided",
|
|
20161
|
+
path: ["scope"]
|
|
20162
|
+
});
|
|
20163
|
+
}
|
|
20164
|
+
if (data.scope && data.peerPerspective) {
|
|
20165
|
+
ctx.addIssue({
|
|
20166
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
20167
|
+
message: "scope and peerPerspective are mutually exclusive",
|
|
20168
|
+
path: ["scope"]
|
|
20169
|
+
});
|
|
20170
|
+
}
|
|
20292
20171
|
});
|
|
20293
20172
|
exports.QueueStatusOptionsSchema = zod_1.z.object({
|
|
20294
20173
|
observer: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
@@ -20317,9 +20196,11 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20317
20196
|
}).strict();
|
|
20318
20197
|
exports.PeerGetRepresentationParamsSchema = zod_1.z.object({
|
|
20319
20198
|
session: zod_1.z.union([exports.SessionIdSchema, SessionIdObjectSchema]).optional(),
|
|
20199
|
+
scope: exports.ScopeOptionSchema.optional(),
|
|
20200
|
+
sessions: exports.SessionAllowlistSchema.optional(),
|
|
20320
20201
|
target: zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional(),
|
|
20321
20202
|
options: exports.RepresentationOptionsSchema.optional()
|
|
20322
|
-
}).strict();
|
|
20203
|
+
}).strict().superRefine(scopeExclusivityIssues);
|
|
20323
20204
|
exports.CardTargetSchema = zod_1.z.union([exports.PeerIdSchema, PeerIdObjectSchema]).optional().transform((val) => val ? typeof val === "string" ? val : val.id : undefined);
|
|
20324
20205
|
exports.PeerCardContentSchema = zod_1.z.array(zod_1.z.string());
|
|
20325
20206
|
exports.PeerAdditionSchema = zod_1.z.union([
|
|
@@ -20380,7 +20261,8 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20380
20261
|
return;
|
|
20381
20262
|
return {
|
|
20382
20263
|
use: config.use,
|
|
20383
|
-
create: config.create
|
|
20264
|
+
create: config.create,
|
|
20265
|
+
custom_instructions: config.customInstructions
|
|
20384
20266
|
};
|
|
20385
20267
|
}
|
|
20386
20268
|
function peerCardConfigFromApi(config) {
|
|
@@ -20390,7 +20272,8 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20390
20272
|
return;
|
|
20391
20273
|
return {
|
|
20392
20274
|
use: config.use,
|
|
20393
|
-
create: config.create
|
|
20275
|
+
create: config.create,
|
|
20276
|
+
customInstructions: config.custom_instructions
|
|
20394
20277
|
};
|
|
20395
20278
|
}
|
|
20396
20279
|
function summaryConfigToApi(config) {
|
|
@@ -20401,7 +20284,8 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20401
20284
|
return {
|
|
20402
20285
|
enabled: config.enabled,
|
|
20403
20286
|
messages_per_short_summary: config.messagesPerShortSummary,
|
|
20404
|
-
messages_per_long_summary: config.messagesPerLongSummary
|
|
20287
|
+
messages_per_long_summary: config.messagesPerLongSummary,
|
|
20288
|
+
custom_instructions: config.customInstructions
|
|
20405
20289
|
};
|
|
20406
20290
|
}
|
|
20407
20291
|
function summaryConfigFromApi(config) {
|
|
@@ -20412,7 +20296,8 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20412
20296
|
return {
|
|
20413
20297
|
enabled: config.enabled,
|
|
20414
20298
|
messagesPerShortSummary: config.messages_per_short_summary,
|
|
20415
|
-
messagesPerLongSummary: config.messages_per_long_summary
|
|
20299
|
+
messagesPerLongSummary: config.messages_per_long_summary,
|
|
20300
|
+
customInstructions: config.custom_instructions
|
|
20416
20301
|
};
|
|
20417
20302
|
}
|
|
20418
20303
|
function dreamConfigToApi(config) {
|
|
@@ -20421,7 +20306,8 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20421
20306
|
if (config === undefined)
|
|
20422
20307
|
return;
|
|
20423
20308
|
return {
|
|
20424
|
-
enabled: config.enabled
|
|
20309
|
+
enabled: config.enabled,
|
|
20310
|
+
custom_instructions: config.customInstructions
|
|
20425
20311
|
};
|
|
20426
20312
|
}
|
|
20427
20313
|
function dreamConfigFromApi(config) {
|
|
@@ -20430,17 +20316,38 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20430
20316
|
if (config === undefined)
|
|
20431
20317
|
return;
|
|
20432
20318
|
return {
|
|
20433
|
-
enabled: config.enabled
|
|
20319
|
+
enabled: config.enabled,
|
|
20320
|
+
customInstructions: config.custom_instructions
|
|
20321
|
+
};
|
|
20322
|
+
}
|
|
20323
|
+
function dialecticConfigToApi(config) {
|
|
20324
|
+
if (config === null)
|
|
20325
|
+
return null;
|
|
20326
|
+
if (config === undefined)
|
|
20327
|
+
return;
|
|
20328
|
+
return {
|
|
20329
|
+
custom_instructions: config.customInstructions
|
|
20330
|
+
};
|
|
20331
|
+
}
|
|
20332
|
+
function dialecticConfigFromApi(config) {
|
|
20333
|
+
if (config === null)
|
|
20334
|
+
return null;
|
|
20335
|
+
if (config === undefined)
|
|
20336
|
+
return;
|
|
20337
|
+
return {
|
|
20338
|
+
customInstructions: config.custom_instructions
|
|
20434
20339
|
};
|
|
20435
20340
|
}
|
|
20436
20341
|
function workspaceConfigToApi(config) {
|
|
20437
20342
|
if (!config)
|
|
20438
20343
|
return;
|
|
20439
20344
|
return {
|
|
20345
|
+
custom_instructions: config.customInstructions,
|
|
20440
20346
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
20441
20347
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
20442
20348
|
summary: summaryConfigToApi(config.summary),
|
|
20443
|
-
dream: dreamConfigToApi(config.dream)
|
|
20349
|
+
dream: dreamConfigToApi(config.dream),
|
|
20350
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
20444
20351
|
};
|
|
20445
20352
|
}
|
|
20446
20353
|
function workspaceConfigFromApi(config) {
|
|
@@ -20448,20 +20355,24 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20448
20355
|
return;
|
|
20449
20356
|
const apiConfig = config;
|
|
20450
20357
|
return {
|
|
20358
|
+
customInstructions: apiConfig.custom_instructions,
|
|
20451
20359
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
20452
20360
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
20453
20361
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
20454
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
20362
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
20363
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
20455
20364
|
};
|
|
20456
20365
|
}
|
|
20457
20366
|
function sessionConfigToApi(config) {
|
|
20458
20367
|
if (!config)
|
|
20459
20368
|
return;
|
|
20460
20369
|
return {
|
|
20370
|
+
custom_instructions: config.customInstructions,
|
|
20461
20371
|
reasoning: reasoningConfigToApi(config.reasoning),
|
|
20462
20372
|
peer_card: peerCardConfigToApi(config.peerCard),
|
|
20463
20373
|
summary: summaryConfigToApi(config.summary),
|
|
20464
|
-
dream: dreamConfigToApi(config.dream)
|
|
20374
|
+
dream: dreamConfigToApi(config.dream),
|
|
20375
|
+
dialectic: dialecticConfigToApi(config.dialectic)
|
|
20465
20376
|
};
|
|
20466
20377
|
}
|
|
20467
20378
|
function sessionConfigFromApi(config) {
|
|
@@ -20469,10 +20380,12 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20469
20380
|
return;
|
|
20470
20381
|
const apiConfig = config;
|
|
20471
20382
|
return {
|
|
20383
|
+
customInstructions: apiConfig.custom_instructions,
|
|
20472
20384
|
reasoning: reasoningConfigFromApi(apiConfig.reasoning),
|
|
20473
20385
|
peerCard: peerCardConfigFromApi(apiConfig.peer_card),
|
|
20474
20386
|
summary: summaryConfigFromApi(apiConfig.summary),
|
|
20475
|
-
dream: dreamConfigFromApi(apiConfig.dream)
|
|
20387
|
+
dream: dreamConfigFromApi(apiConfig.dream),
|
|
20388
|
+
dialectic: dialecticConfigFromApi(apiConfig.dialectic)
|
|
20476
20389
|
};
|
|
20477
20390
|
}
|
|
20478
20391
|
function messageConfigToApi(config) {
|
|
@@ -20544,10 +20457,12 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20544
20457
|
});
|
|
20545
20458
|
exports.WorkspaceMetadataSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
|
|
20546
20459
|
exports.WorkspaceConfigSchema = zod_1.z.object({
|
|
20460
|
+
customInstructions: zod_1.z.string().nullable().optional(),
|
|
20547
20461
|
reasoning: exports.ReasoningConfigSchema.nullable().optional(),
|
|
20548
20462
|
peerCard: exports.PeerCardConfigSchema.nullable().optional(),
|
|
20549
20463
|
summary: exports.SummaryConfigSchema.nullable().optional(),
|
|
20550
|
-
dream: exports.DreamConfigSchema.nullable().optional()
|
|
20464
|
+
dream: exports.DreamConfigSchema.nullable().optional(),
|
|
20465
|
+
dialectic: exports.DialecticConfigSchema.nullable().optional()
|
|
20551
20466
|
}).strict();
|
|
20552
20467
|
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");
|
|
20553
20468
|
exports.ConclusionQueryParamsSchema = zod_1.z.object({
|
|
@@ -20561,22 +20476,46 @@ var require_validation2 = __commonJS(function(exports) {
|
|
|
20561
20476
|
// node_modules/@honcho-ai/sdk/dist/conclusions.js
|
|
20562
20477
|
var require_conclusions = __commonJS(function(exports) {
|
|
20563
20478
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20564
|
-
exports.
|
|
20479
|
+
exports.WorkspaceConclusions = exports.ConclusionsView = exports.Conclusion = undefined;
|
|
20565
20480
|
var api_version_1 = require_api_version();
|
|
20481
|
+
var errors_1 = require_errors2();
|
|
20566
20482
|
var pagination_1 = require_pagination();
|
|
20567
20483
|
var validation_1 = require_validation2();
|
|
20484
|
+
var LIST_PAGE_CAP = 100;
|
|
20485
|
+
var VIEW_RESERVED_KEYS = [
|
|
20486
|
+
"observer",
|
|
20487
|
+
"observed",
|
|
20488
|
+
"observer_id",
|
|
20489
|
+
"observed_id"
|
|
20490
|
+
];
|
|
20491
|
+
function rejectReservedFilterKeys(filters, reserved) {
|
|
20492
|
+
if (!filters)
|
|
20493
|
+
return;
|
|
20494
|
+
const clash = reserved.filter((k) => (k in filters)).sort();
|
|
20495
|
+
if (clash.length > 0) {
|
|
20496
|
+
let guidance = "Choose the peer pair via peer.conclusions / peer.conclusionsOf(target)";
|
|
20497
|
+
if (reserved.includes("session") || reserved.includes("session_id")) {
|
|
20498
|
+
guidance += "; use the session option to filter by session";
|
|
20499
|
+
}
|
|
20500
|
+
throw new Error(`Filter key(s) ${clash.join(", ")} are managed by this conclusions view ` + `and cannot be passed in filters. ${guidance}.`);
|
|
20501
|
+
}
|
|
20502
|
+
}
|
|
20568
20503
|
|
|
20569
20504
|
class Conclusion {
|
|
20570
|
-
constructor(id, content, observerId, observedId, sessionId, createdAt) {
|
|
20505
|
+
constructor(id, content, observerId, observedId, sessionId, createdAt, level = "explicit", sourceIds = null, timesDerived = 1, sourceMessageIds = null) {
|
|
20571
20506
|
this.id = id;
|
|
20572
20507
|
this.content = content;
|
|
20573
20508
|
this.observerId = observerId;
|
|
20574
20509
|
this.observedId = observedId;
|
|
20575
20510
|
this.sessionId = sessionId;
|
|
20511
|
+
this.level = level;
|
|
20512
|
+
this.sourceIds = sourceIds;
|
|
20513
|
+
this.timesDerived = timesDerived;
|
|
20514
|
+
this.sourceMessageIds = sourceMessageIds;
|
|
20576
20515
|
this.createdAt = createdAt;
|
|
20577
20516
|
}
|
|
20578
20517
|
static fromApiResponse(data) {
|
|
20579
|
-
return new Conclusion(data.id, data.content, data.observer_id, data.observed_id, data.session_id, data.created_at);
|
|
20518
|
+
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);
|
|
20580
20519
|
}
|
|
20581
20520
|
toString() {
|
|
20582
20521
|
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
@@ -20585,7 +20524,7 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
20585
20524
|
}
|
|
20586
20525
|
exports.Conclusion = Conclusion;
|
|
20587
20526
|
|
|
20588
|
-
class
|
|
20527
|
+
class ConclusionsView {
|
|
20589
20528
|
constructor(http, workspaceId, observer, observed, ensureWorkspace = async () => {
|
|
20590
20529
|
return;
|
|
20591
20530
|
}) {
|
|
@@ -20614,6 +20553,26 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
20614
20553
|
await this._ensureWorkspace();
|
|
20615
20554
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions`, { body: params });
|
|
20616
20555
|
}
|
|
20556
|
+
async _get(conclusionId) {
|
|
20557
|
+
await this._ensureWorkspace();
|
|
20558
|
+
const item = await this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
20559
|
+
if (item.observer_id !== this.observer || item.observed_id !== this.observed) {
|
|
20560
|
+
throw new errors_1.NotFoundError("Conclusion not found");
|
|
20561
|
+
}
|
|
20562
|
+
return item;
|
|
20563
|
+
}
|
|
20564
|
+
async _derived(conclusionId, params) {
|
|
20565
|
+
return this._list({
|
|
20566
|
+
filters: {
|
|
20567
|
+
source_ids: { contains: conclusionId },
|
|
20568
|
+
observer_id: this.observer,
|
|
20569
|
+
observed_id: this.observed
|
|
20570
|
+
},
|
|
20571
|
+
page: params.page,
|
|
20572
|
+
size: params.size,
|
|
20573
|
+
reverse: params.reverse
|
|
20574
|
+
});
|
|
20575
|
+
}
|
|
20617
20576
|
async _delete(conclusionId) {
|
|
20618
20577
|
await this._ensureWorkspace();
|
|
20619
20578
|
await this._http.delete(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
@@ -20623,14 +20582,18 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
20623
20582
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${peerId}/representation`, { body: params });
|
|
20624
20583
|
}
|
|
20625
20584
|
async list(options) {
|
|
20585
|
+
rejectReservedFilterKeys(options?.filters, [
|
|
20586
|
+
...VIEW_RESERVED_KEYS,
|
|
20587
|
+
"session",
|
|
20588
|
+
"session_id"
|
|
20589
|
+
]);
|
|
20626
20590
|
const resolvedSessionId = options?.session ? typeof options.session === "string" ? options.session : options.session.id : undefined;
|
|
20627
20591
|
const filters = {
|
|
20628
20592
|
observer_id: this.observer,
|
|
20629
|
-
observed_id: this.observed
|
|
20593
|
+
observed_id: this.observed,
|
|
20594
|
+
...resolvedSessionId ? { session_id: resolvedSessionId } : {},
|
|
20595
|
+
...options?.filters
|
|
20630
20596
|
};
|
|
20631
|
-
if (resolvedSessionId) {
|
|
20632
|
-
filters.session_id = resolvedSessionId;
|
|
20633
|
-
}
|
|
20634
20597
|
const reverse = options?.reverse;
|
|
20635
20598
|
const response = await this._list({
|
|
20636
20599
|
filters,
|
|
@@ -20643,19 +20606,55 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
20643
20606
|
};
|
|
20644
20607
|
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
20645
20608
|
}
|
|
20646
|
-
async query(query, topK = 10, distance) {
|
|
20647
|
-
|
|
20648
|
-
observer_id: this.observer,
|
|
20649
|
-
observed_id: this.observed
|
|
20650
|
-
};
|
|
20609
|
+
async query(query, topK = 10, distance, filters) {
|
|
20610
|
+
rejectReservedFilterKeys(filters, VIEW_RESERVED_KEYS);
|
|
20651
20611
|
const response = await this._query({
|
|
20652
20612
|
query,
|
|
20653
20613
|
top_k: topK,
|
|
20654
20614
|
distance,
|
|
20655
|
-
filters
|
|
20615
|
+
filters: {
|
|
20616
|
+
observer_id: this.observer,
|
|
20617
|
+
observed_id: this.observed,
|
|
20618
|
+
...filters
|
|
20619
|
+
}
|
|
20656
20620
|
});
|
|
20657
20621
|
return (response ?? []).map((item) => Conclusion.fromApiResponse(item));
|
|
20658
20622
|
}
|
|
20623
|
+
async get(conclusionId) {
|
|
20624
|
+
const response = await this._get(conclusionId);
|
|
20625
|
+
return Conclusion.fromApiResponse(response);
|
|
20626
|
+
}
|
|
20627
|
+
async getMany(conclusionIds) {
|
|
20628
|
+
if (conclusionIds.length === 0)
|
|
20629
|
+
return [];
|
|
20630
|
+
const conclusions = [];
|
|
20631
|
+
for (let start = 0;start < conclusionIds.length; start += LIST_PAGE_CAP) {
|
|
20632
|
+
const chunk = conclusionIds.slice(start, start + LIST_PAGE_CAP);
|
|
20633
|
+
const response = await this._list({
|
|
20634
|
+
filters: {
|
|
20635
|
+
id: { in: chunk },
|
|
20636
|
+
observer_id: this.observer,
|
|
20637
|
+
observed_id: this.observed
|
|
20638
|
+
},
|
|
20639
|
+
page: 1,
|
|
20640
|
+
size: chunk.length
|
|
20641
|
+
});
|
|
20642
|
+
conclusions.push(...(response.items ?? []).map((item) => Conclusion.fromApiResponse(item)));
|
|
20643
|
+
}
|
|
20644
|
+
return conclusions;
|
|
20645
|
+
}
|
|
20646
|
+
async derived(conclusionId, options) {
|
|
20647
|
+
const reverse = options?.reverse;
|
|
20648
|
+
const response = await this._derived(conclusionId, {
|
|
20649
|
+
page: options?.page ?? 1,
|
|
20650
|
+
size: options?.size ?? 50,
|
|
20651
|
+
reverse
|
|
20652
|
+
});
|
|
20653
|
+
const fetchNextPage = async (page, size) => {
|
|
20654
|
+
return this._derived(conclusionId, { page, size, reverse });
|
|
20655
|
+
};
|
|
20656
|
+
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
20657
|
+
}
|
|
20659
20658
|
async delete(conclusionId) {
|
|
20660
20659
|
await this._delete(conclusionId);
|
|
20661
20660
|
}
|
|
@@ -20690,10 +20689,300 @@ var require_conclusions = __commonJS(function(exports) {
|
|
|
20690
20689
|
return response.representation;
|
|
20691
20690
|
}
|
|
20692
20691
|
toString() {
|
|
20693
|
-
return `
|
|
20692
|
+
return `ConclusionsView(workspaceId='${this.workspaceId}', observer='${this.observer}', observed='${this.observed}')`;
|
|
20694
20693
|
}
|
|
20695
20694
|
}
|
|
20696
|
-
exports.
|
|
20695
|
+
exports.ConclusionsView = ConclusionsView;
|
|
20696
|
+
|
|
20697
|
+
class WorkspaceConclusions {
|
|
20698
|
+
constructor(http, workspaceId, ensureWorkspace = async () => {
|
|
20699
|
+
return;
|
|
20700
|
+
}) {
|
|
20701
|
+
this._http = http;
|
|
20702
|
+
this.workspaceId = workspaceId;
|
|
20703
|
+
this._ensureWorkspace = ensureWorkspace;
|
|
20704
|
+
}
|
|
20705
|
+
async _list(params) {
|
|
20706
|
+
await this._ensureWorkspace();
|
|
20707
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/list`, {
|
|
20708
|
+
body: params.filters ? { filters: params.filters } : undefined,
|
|
20709
|
+
query: {
|
|
20710
|
+
page: params.page,
|
|
20711
|
+
size: params.size,
|
|
20712
|
+
reverse: params.reverse ? "true" : undefined
|
|
20713
|
+
}
|
|
20714
|
+
});
|
|
20715
|
+
}
|
|
20716
|
+
async list(options) {
|
|
20717
|
+
const filters = options?.filters;
|
|
20718
|
+
const reverse = options?.reverse;
|
|
20719
|
+
const response = await this._list({
|
|
20720
|
+
filters,
|
|
20721
|
+
page: options?.page ?? 1,
|
|
20722
|
+
size: options?.size ?? 50,
|
|
20723
|
+
reverse
|
|
20724
|
+
});
|
|
20725
|
+
const fetchNextPage = async (page, size) => {
|
|
20726
|
+
return this._list({ filters, page, size, reverse });
|
|
20727
|
+
};
|
|
20728
|
+
return new pagination_1.Page(response, (item) => Conclusion.fromApiResponse(item), fetchNextPage);
|
|
20729
|
+
}
|
|
20730
|
+
async get(conclusionId) {
|
|
20731
|
+
await this._ensureWorkspace();
|
|
20732
|
+
const item = await this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/conclusions/${conclusionId}`);
|
|
20733
|
+
return Conclusion.fromApiResponse(item);
|
|
20734
|
+
}
|
|
20735
|
+
async getMany(conclusionIds) {
|
|
20736
|
+
if (conclusionIds.length === 0)
|
|
20737
|
+
return [];
|
|
20738
|
+
const conclusions = [];
|
|
20739
|
+
for (let start = 0;start < conclusionIds.length; start += LIST_PAGE_CAP) {
|
|
20740
|
+
const chunk = conclusionIds.slice(start, start + LIST_PAGE_CAP);
|
|
20741
|
+
const response = await this._list({
|
|
20742
|
+
filters: { id: { in: chunk } },
|
|
20743
|
+
page: 1,
|
|
20744
|
+
size: chunk.length
|
|
20745
|
+
});
|
|
20746
|
+
conclusions.push(...(response.items ?? []).map((item) => Conclusion.fromApiResponse(item)));
|
|
20747
|
+
}
|
|
20748
|
+
return conclusions;
|
|
20749
|
+
}
|
|
20750
|
+
toString() {
|
|
20751
|
+
return `WorkspaceConclusions(workspaceId='${this.workspaceId}')`;
|
|
20752
|
+
}
|
|
20753
|
+
}
|
|
20754
|
+
exports.WorkspaceConclusions = WorkspaceConclusions;
|
|
20755
|
+
});
|
|
20756
|
+
|
|
20757
|
+
// node_modules/@honcho-ai/sdk/dist/http/client.js
|
|
20758
|
+
var require_client = __commonJS(function(exports) {
|
|
20759
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20760
|
+
exports.HonchoHTTPClient = exports.HOST_HEADER = undefined;
|
|
20761
|
+
exports.defaultHostHeader = defaultHostHeader;
|
|
20762
|
+
var api_version_1 = require_api_version();
|
|
20763
|
+
var errors_1 = require_errors2();
|
|
20764
|
+
var DEFAULT_TIMEOUT = 60000;
|
|
20765
|
+
var DEFAULT_MAX_RETRIES = 2;
|
|
20766
|
+
var RETRY_STATUS_CODES = [429, 500, 502, 503, 504];
|
|
20767
|
+
var INITIAL_RETRY_DELAY = 500;
|
|
20768
|
+
exports.HOST_HEADER = "X-Honcho-Host";
|
|
20769
|
+
function defaultHostHeader() {
|
|
20770
|
+
const product = `honcho-typescript/${api_version_1.VERSION}`;
|
|
20771
|
+
const platform = typeof process !== "undefined" && typeof process.platform === "string" ? process.platform : undefined;
|
|
20772
|
+
return platform ? `${product} (${platform})` : product;
|
|
20773
|
+
}
|
|
20774
|
+
|
|
20775
|
+
class HonchoHTTPClient {
|
|
20776
|
+
constructor(config) {
|
|
20777
|
+
this.baseURL = config.baseURL.replace(/\/$/, "");
|
|
20778
|
+
this.apiKey = config.apiKey;
|
|
20779
|
+
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
20780
|
+
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
20781
|
+
this.defaultHeaders = {
|
|
20782
|
+
"Content-Type": "application/json",
|
|
20783
|
+
[exports.HOST_HEADER]: defaultHostHeader(),
|
|
20784
|
+
...config.defaultHeaders
|
|
20785
|
+
};
|
|
20786
|
+
this.defaultQuery = config.defaultQuery;
|
|
20787
|
+
}
|
|
20788
|
+
async request(method, path, options = {}) {
|
|
20789
|
+
const url = this.buildURL(path, options.query);
|
|
20790
|
+
const headers = this.buildHeaders(options.headers);
|
|
20791
|
+
const timeout = options.timeout ?? this.timeout;
|
|
20792
|
+
let lastError;
|
|
20793
|
+
let attempt = 0;
|
|
20794
|
+
while (attempt <= this.maxRetries) {
|
|
20795
|
+
try {
|
|
20796
|
+
const response = await this.fetchWithTimeout(url, {
|
|
20797
|
+
method,
|
|
20798
|
+
headers,
|
|
20799
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
20800
|
+
signal: options.signal
|
|
20801
|
+
}, timeout);
|
|
20802
|
+
if (response.ok) {
|
|
20803
|
+
const text = await response.text();
|
|
20804
|
+
if (!text) {
|
|
20805
|
+
return;
|
|
20806
|
+
}
|
|
20807
|
+
return JSON.parse(text);
|
|
20808
|
+
}
|
|
20809
|
+
const errorBody = await this.parseErrorBody(response);
|
|
20810
|
+
const retryAfter = this.parseRetryAfter(response);
|
|
20811
|
+
const error = (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody, retryAfter);
|
|
20812
|
+
if (RETRY_STATUS_CODES.includes(response.status) && attempt < this.maxRetries) {
|
|
20813
|
+
lastError = error;
|
|
20814
|
+
await this.sleep(this.getRetryDelay(attempt, retryAfter));
|
|
20815
|
+
attempt++;
|
|
20816
|
+
continue;
|
|
20817
|
+
}
|
|
20818
|
+
throw error;
|
|
20819
|
+
} catch (error) {
|
|
20820
|
+
if (error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
20821
|
+
if (attempt < this.maxRetries) {
|
|
20822
|
+
lastError = error;
|
|
20823
|
+
await this.sleep(this.getRetryDelay(attempt));
|
|
20824
|
+
attempt++;
|
|
20825
|
+
continue;
|
|
20826
|
+
}
|
|
20827
|
+
}
|
|
20828
|
+
if (error instanceof errors_1.RateLimitError || error instanceof errors_1.ServerError || error instanceof errors_1.TimeoutError || error instanceof errors_1.ConnectionError) {
|
|
20829
|
+
throw error;
|
|
20830
|
+
}
|
|
20831
|
+
throw error;
|
|
20832
|
+
}
|
|
20833
|
+
}
|
|
20834
|
+
throw lastError || new Error("Request failed after retries");
|
|
20835
|
+
}
|
|
20836
|
+
async get(path, options) {
|
|
20837
|
+
return this.request("GET", path, options);
|
|
20838
|
+
}
|
|
20839
|
+
async post(path, options) {
|
|
20840
|
+
return this.request("POST", path, options);
|
|
20841
|
+
}
|
|
20842
|
+
async put(path, options) {
|
|
20843
|
+
return this.request("PUT", path, options);
|
|
20844
|
+
}
|
|
20845
|
+
async patch(path, options) {
|
|
20846
|
+
return this.request("PATCH", path, options);
|
|
20847
|
+
}
|
|
20848
|
+
async delete(path, options) {
|
|
20849
|
+
return this.request("DELETE", path, options);
|
|
20850
|
+
}
|
|
20851
|
+
async stream(method, path, options = {}) {
|
|
20852
|
+
const url = this.buildURL(path, options.query);
|
|
20853
|
+
const headers = {
|
|
20854
|
+
...this.buildHeaders(options.headers),
|
|
20855
|
+
Accept: "text/event-stream"
|
|
20856
|
+
};
|
|
20857
|
+
const timeout = options.timeout ?? this.timeout;
|
|
20858
|
+
const response = await this.fetchWithTimeout(url, {
|
|
20859
|
+
method,
|
|
20860
|
+
headers,
|
|
20861
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
20862
|
+
signal: options.signal
|
|
20863
|
+
}, timeout);
|
|
20864
|
+
if (!response.ok) {
|
|
20865
|
+
const errorBody = await this.parseErrorBody(response);
|
|
20866
|
+
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
20867
|
+
}
|
|
20868
|
+
return response;
|
|
20869
|
+
}
|
|
20870
|
+
async upload(path, formData, options = {}) {
|
|
20871
|
+
const url = this.buildURL(path, options.query);
|
|
20872
|
+
const headers = {};
|
|
20873
|
+
if (this.apiKey) {
|
|
20874
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
20875
|
+
}
|
|
20876
|
+
if (options.headers) {
|
|
20877
|
+
Object.assign(headers, options.headers);
|
|
20878
|
+
}
|
|
20879
|
+
const timeout = options.timeout ?? this.timeout;
|
|
20880
|
+
const response = await this.fetchWithTimeout(url, {
|
|
20881
|
+
method: "POST",
|
|
20882
|
+
headers,
|
|
20883
|
+
body: formData,
|
|
20884
|
+
signal: options.signal
|
|
20885
|
+
}, timeout);
|
|
20886
|
+
if (!response.ok) {
|
|
20887
|
+
const errorBody = await this.parseErrorBody(response);
|
|
20888
|
+
throw (0, errors_1.createErrorFromResponse)(response.status, errorBody.message || `HTTP ${response.status}`, errorBody);
|
|
20889
|
+
}
|
|
20890
|
+
const text = await response.text();
|
|
20891
|
+
if (!text) {
|
|
20892
|
+
return;
|
|
20893
|
+
}
|
|
20894
|
+
return JSON.parse(text);
|
|
20895
|
+
}
|
|
20896
|
+
buildURL(path, query) {
|
|
20897
|
+
const url = new URL(path, this.baseURL);
|
|
20898
|
+
const mergedQuery = {
|
|
20899
|
+
...this.defaultQuery ?? {},
|
|
20900
|
+
...query ?? {}
|
|
20901
|
+
};
|
|
20902
|
+
for (const [key, value] of Object.entries(mergedQuery)) {
|
|
20903
|
+
if (value === undefined) {
|
|
20904
|
+
continue;
|
|
20905
|
+
}
|
|
20906
|
+
if (Array.isArray(value)) {
|
|
20907
|
+
for (const entry of value) {
|
|
20908
|
+
url.searchParams.append(key, String(entry));
|
|
20909
|
+
}
|
|
20910
|
+
continue;
|
|
20911
|
+
}
|
|
20912
|
+
url.searchParams.set(key, String(value));
|
|
20913
|
+
}
|
|
20914
|
+
return url.toString();
|
|
20915
|
+
}
|
|
20916
|
+
buildHeaders(extra) {
|
|
20917
|
+
const headers = { ...this.defaultHeaders };
|
|
20918
|
+
if (this.apiKey) {
|
|
20919
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
20920
|
+
}
|
|
20921
|
+
if (extra) {
|
|
20922
|
+
Object.assign(headers, extra);
|
|
20923
|
+
}
|
|
20924
|
+
return headers;
|
|
20925
|
+
}
|
|
20926
|
+
async fetchWithTimeout(url, init, timeout) {
|
|
20927
|
+
const controller = new AbortController;
|
|
20928
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
20929
|
+
if (init.signal) {
|
|
20930
|
+
init.signal.addEventListener("abort", () => controller.abort());
|
|
20931
|
+
}
|
|
20932
|
+
try {
|
|
20933
|
+
const response = await fetch(url, {
|
|
20934
|
+
...init,
|
|
20935
|
+
signal: controller.signal
|
|
20936
|
+
});
|
|
20937
|
+
return response;
|
|
20938
|
+
} catch (error) {
|
|
20939
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
20940
|
+
throw new errors_1.TimeoutError(`Request timed out after ${timeout}ms`);
|
|
20941
|
+
}
|
|
20942
|
+
if (error instanceof TypeError) {
|
|
20943
|
+
throw new errors_1.ConnectionError(error.message);
|
|
20944
|
+
}
|
|
20945
|
+
throw error;
|
|
20946
|
+
} finally {
|
|
20947
|
+
clearTimeout(timeoutId);
|
|
20948
|
+
}
|
|
20949
|
+
}
|
|
20950
|
+
async parseErrorBody(response) {
|
|
20951
|
+
try {
|
|
20952
|
+
const body = await response.json();
|
|
20953
|
+
return {
|
|
20954
|
+
message: body.detail || body.message || body.error,
|
|
20955
|
+
...body
|
|
20956
|
+
};
|
|
20957
|
+
} catch {
|
|
20958
|
+
return { message: `HTTP ${response.status}` };
|
|
20959
|
+
}
|
|
20960
|
+
}
|
|
20961
|
+
parseRetryAfter(response) {
|
|
20962
|
+
const header = response.headers.get("Retry-After");
|
|
20963
|
+
if (!header)
|
|
20964
|
+
return;
|
|
20965
|
+
const seconds = Number.parseInt(header, 10);
|
|
20966
|
+
if (!Number.isNaN(seconds)) {
|
|
20967
|
+
return seconds * 1000;
|
|
20968
|
+
}
|
|
20969
|
+
const date = Date.parse(header);
|
|
20970
|
+
if (!Number.isNaN(date)) {
|
|
20971
|
+
return Math.max(0, date - Date.now());
|
|
20972
|
+
}
|
|
20973
|
+
return;
|
|
20974
|
+
}
|
|
20975
|
+
getRetryDelay(attempt, retryAfter) {
|
|
20976
|
+
if (retryAfter) {
|
|
20977
|
+
return retryAfter;
|
|
20978
|
+
}
|
|
20979
|
+
return INITIAL_RETRY_DELAY * 2 ** attempt;
|
|
20980
|
+
}
|
|
20981
|
+
sleep(ms) {
|
|
20982
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20983
|
+
}
|
|
20984
|
+
}
|
|
20985
|
+
exports.HonchoHTTPClient = HonchoHTTPClient;
|
|
20697
20986
|
});
|
|
20698
20987
|
|
|
20699
20988
|
// node_modules/@honcho-ai/sdk/dist/http/streaming.js
|
|
@@ -20746,10 +21035,14 @@ var require_streaming = __commonJS(function(exports) {
|
|
|
20746
21035
|
}
|
|
20747
21036
|
|
|
20748
21037
|
class DialecticStreamResponse {
|
|
20749
|
-
constructor(generator) {
|
|
21038
|
+
constructor(generator, evidenceSource) {
|
|
20750
21039
|
this.chunks = [];
|
|
20751
21040
|
this.consumed = false;
|
|
20752
21041
|
this.generator = generator;
|
|
21042
|
+
this.evidenceSource = evidenceSource;
|
|
21043
|
+
}
|
|
21044
|
+
get evidence() {
|
|
21045
|
+
return this.evidenceSource?.() ?? null;
|
|
20753
21046
|
}
|
|
20754
21047
|
async* [Symbol.asyncIterator]() {
|
|
20755
21048
|
if (this.consumed) {
|
|
@@ -20779,9 +21072,11 @@ var require_streaming = __commonJS(function(exports) {
|
|
|
20779
21072
|
}
|
|
20780
21073
|
exports.DialecticStreamResponse = DialecticStreamResponse;
|
|
20781
21074
|
function createDialecticStream(response) {
|
|
21075
|
+
let evidence = null;
|
|
20782
21076
|
async function* streamContent() {
|
|
20783
21077
|
for await (const chunk of parseSSE(response)) {
|
|
20784
21078
|
if (chunk.done) {
|
|
21079
|
+
evidence = chunk.evidence ?? null;
|
|
20785
21080
|
return;
|
|
20786
21081
|
}
|
|
20787
21082
|
const content = chunk.delta?.content;
|
|
@@ -20790,10 +21085,37 @@ var require_streaming = __commonJS(function(exports) {
|
|
|
20790
21085
|
}
|
|
20791
21086
|
}
|
|
20792
21087
|
}
|
|
20793
|
-
return new DialecticStreamResponse(streamContent());
|
|
21088
|
+
return new DialecticStreamResponse(streamContent(), () => evidence);
|
|
20794
21089
|
}
|
|
20795
21090
|
});
|
|
20796
21091
|
|
|
21092
|
+
// node_modules/@honcho-ai/sdk/dist/message.js
|
|
21093
|
+
var require_message = __commonJS(function(exports) {
|
|
21094
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21095
|
+
exports.Message = undefined;
|
|
21096
|
+
|
|
21097
|
+
class Message {
|
|
21098
|
+
constructor(id, content, peerId, sessionId, workspaceId, metadata, createdAt, tokenCount) {
|
|
21099
|
+
this.id = id;
|
|
21100
|
+
this.content = content;
|
|
21101
|
+
this.peerId = peerId;
|
|
21102
|
+
this.sessionId = sessionId;
|
|
21103
|
+
this.workspaceId = workspaceId;
|
|
21104
|
+
this.metadata = metadata;
|
|
21105
|
+
this.createdAt = createdAt;
|
|
21106
|
+
this.tokenCount = tokenCount;
|
|
21107
|
+
}
|
|
21108
|
+
static fromApiResponse(data) {
|
|
21109
|
+
return new Message(data.id, data.content, data.peer_id, data.session_id, data.workspace_id, data.metadata, data.created_at, data.token_count);
|
|
21110
|
+
}
|
|
21111
|
+
toString() {
|
|
21112
|
+
const truncatedContent = this.content.length > 50 ? `${this.content.slice(0, 50)}...` : this.content;
|
|
21113
|
+
return `Message(id='${this.id}', peerId='${this.peerId}', content='${truncatedContent}')`;
|
|
21114
|
+
}
|
|
21115
|
+
}
|
|
21116
|
+
exports.Message = Message;
|
|
21117
|
+
});
|
|
21118
|
+
|
|
20797
21119
|
// node_modules/@honcho-ai/sdk/dist/session_context.js
|
|
20798
21120
|
var require_session_context = __commonJS(function(exports) {
|
|
20799
21121
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -20968,12 +21290,18 @@ var require_session = __commonJS(function(exports) {
|
|
|
20968
21290
|
get createdAt() {
|
|
20969
21291
|
return this._createdAt;
|
|
20970
21292
|
}
|
|
21293
|
+
get uid() {
|
|
21294
|
+
return this._uid;
|
|
21295
|
+
}
|
|
20971
21296
|
get isActive() {
|
|
20972
21297
|
return this._isActive;
|
|
20973
21298
|
}
|
|
21299
|
+
get scopes() {
|
|
21300
|
+
return this._scopes;
|
|
21301
|
+
}
|
|
20974
21302
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
20975
21303
|
return;
|
|
20976
|
-
}, createdAt, isActive) {
|
|
21304
|
+
}, createdAt, isActive, uid, scopes) {
|
|
20977
21305
|
this.id = id;
|
|
20978
21306
|
this.workspaceId = workspaceId;
|
|
20979
21307
|
this._http = http;
|
|
@@ -20982,12 +21310,15 @@ var require_session = __commonJS(function(exports) {
|
|
|
20982
21310
|
this._ensureWorkspace = ensureWorkspace;
|
|
20983
21311
|
this._createdAt = createdAt;
|
|
20984
21312
|
this._isActive = isActive;
|
|
21313
|
+
this._uid = uid;
|
|
21314
|
+
this._scopes = scopes;
|
|
20985
21315
|
}
|
|
20986
21316
|
_applySessionResponse(session) {
|
|
20987
21317
|
this._metadata = session.metadata || {};
|
|
20988
21318
|
this._configuration = (0, validation_1.sessionConfigFromApi)(session.configuration) || {};
|
|
20989
21319
|
this._createdAt = session.created_at;
|
|
20990
21320
|
this._isActive = session.is_active;
|
|
21321
|
+
this._uid = session.uid;
|
|
20991
21322
|
}
|
|
20992
21323
|
async _getOrCreate(params) {
|
|
20993
21324
|
await this._ensureWorkspace();
|
|
@@ -21111,7 +21442,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
21111
21442
|
}
|
|
21112
21443
|
async peers() {
|
|
21113
21444
|
const peersPage = await this._listPeers();
|
|
21114
|
-
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));
|
|
21445
|
+
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));
|
|
21115
21446
|
}
|
|
21116
21447
|
async getPeerConfiguration(peer) {
|
|
21117
21448
|
const peerId = typeof peer === "string" ? peer : peer.id;
|
|
@@ -21195,7 +21526,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
21195
21526
|
}
|
|
21196
21527
|
async clone(messageId) {
|
|
21197
21528
|
const clonedSessionData = await this._clone(messageId ? { message_id: messageId } : undefined);
|
|
21198
|
-
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);
|
|
21529
|
+
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);
|
|
21199
21530
|
}
|
|
21200
21531
|
async context(options) {
|
|
21201
21532
|
const opts = options || {};
|
|
@@ -21207,6 +21538,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
21207
21538
|
tokens: opts.tokens,
|
|
21208
21539
|
peerTarget: peerTargetId,
|
|
21209
21540
|
peerPerspective: peerPerspectiveId,
|
|
21541
|
+
scope: opts.scope !== undefined ? (0, utils_1.resolveId)(opts.scope) : undefined,
|
|
21542
|
+
sessions: opts.sessions,
|
|
21210
21543
|
limitToSession: opts.limitToSession,
|
|
21211
21544
|
representationOptions: opts.representationOptions ? {
|
|
21212
21545
|
...opts.representationOptions,
|
|
@@ -21219,6 +21552,8 @@ var require_session = __commonJS(function(exports) {
|
|
|
21219
21552
|
search_query: searchQuery,
|
|
21220
21553
|
peer_target: contextParams.peerTarget,
|
|
21221
21554
|
peer_perspective: contextParams.peerPerspective,
|
|
21555
|
+
scope: contextParams.scope,
|
|
21556
|
+
sessions: contextParams.sessions,
|
|
21222
21557
|
limit_to_session: contextParams.limitToSession,
|
|
21223
21558
|
search_top_k: contextParams.representationOptions?.searchTopK,
|
|
21224
21559
|
search_max_distance: contextParams.representationOptions?.searchMaxDistance,
|
|
@@ -21335,6 +21670,7 @@ var require_session = __commonJS(function(exports) {
|
|
|
21335
21670
|
var require_peer = __commonJS(function(exports) {
|
|
21336
21671
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21337
21672
|
exports.Peer = exports.PeerContext = undefined;
|
|
21673
|
+
var zod_1 = require_zod();
|
|
21338
21674
|
var api_version_1 = require_api_version();
|
|
21339
21675
|
var conclusions_1 = require_conclusions();
|
|
21340
21676
|
var streaming_1 = require_streaming();
|
|
@@ -21369,9 +21705,12 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21369
21705
|
get createdAt() {
|
|
21370
21706
|
return this._createdAt;
|
|
21371
21707
|
}
|
|
21708
|
+
get uid() {
|
|
21709
|
+
return this._uid;
|
|
21710
|
+
}
|
|
21372
21711
|
constructor(id, workspaceId, http, metadata, configuration, ensureWorkspace = async () => {
|
|
21373
21712
|
return;
|
|
21374
|
-
}, createdAt) {
|
|
21713
|
+
}, createdAt, uid) {
|
|
21375
21714
|
this.id = id;
|
|
21376
21715
|
this.workspaceId = workspaceId;
|
|
21377
21716
|
this._http = http;
|
|
@@ -21379,6 +21718,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21379
21718
|
this._configuration = configuration;
|
|
21380
21719
|
this._ensureWorkspace = ensureWorkspace;
|
|
21381
21720
|
this._createdAt = createdAt;
|
|
21721
|
+
this._uid = uid;
|
|
21382
21722
|
}
|
|
21383
21723
|
async _getOrCreate(params) {
|
|
21384
21724
|
await this._ensureWorkspace();
|
|
@@ -21399,6 +21739,15 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21399
21739
|
}
|
|
21400
21740
|
});
|
|
21401
21741
|
}
|
|
21742
|
+
static toResponseFormatSchema(responseFormat) {
|
|
21743
|
+
if (!responseFormat) {
|
|
21744
|
+
return;
|
|
21745
|
+
}
|
|
21746
|
+
if (responseFormat instanceof zod_1.ZodType) {
|
|
21747
|
+
return zod_1.z.toJSONSchema(responseFormat);
|
|
21748
|
+
}
|
|
21749
|
+
return responseFormat;
|
|
21750
|
+
}
|
|
21402
21751
|
async _chat(params) {
|
|
21403
21752
|
await this._ensureWorkspace();
|
|
21404
21753
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/peers/${this.id}/chat`, { body: params });
|
|
@@ -21440,19 +21789,28 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21440
21789
|
query,
|
|
21441
21790
|
target: targetId,
|
|
21442
21791
|
session: resolvedSessionId,
|
|
21443
|
-
|
|
21792
|
+
scope: options?.scope,
|
|
21793
|
+
sessions: options?.sessions,
|
|
21794
|
+
reasoningLevel: options?.reasoningLevel,
|
|
21795
|
+
responseFormat: options?.responseFormat,
|
|
21796
|
+
includeEvidence: options?.includeEvidence
|
|
21444
21797
|
});
|
|
21798
|
+
const zodSchema = options?.responseFormat instanceof zod_1.ZodType ? options.responseFormat : undefined;
|
|
21445
21799
|
const response = await this._chat({
|
|
21446
21800
|
query: chatParams.query,
|
|
21447
21801
|
stream: false,
|
|
21448
21802
|
target: chatParams.target,
|
|
21449
21803
|
session_id: chatParams.session,
|
|
21450
|
-
|
|
21804
|
+
...(0, validation_1.scopeRecallFields)(chatParams),
|
|
21805
|
+
reasoning_level: chatParams.reasoningLevel,
|
|
21806
|
+
response_format: Peer.toResponseFormatSchema(options?.responseFormat),
|
|
21807
|
+
include_evidence: chatParams.includeEvidence ? true : undefined
|
|
21451
21808
|
});
|
|
21452
|
-
|
|
21453
|
-
|
|
21809
|
+
const content = response.content ? zodSchema ? zodSchema.parse(JSON.parse(response.content)) : response.content : null;
|
|
21810
|
+
if (!chatParams.includeEvidence) {
|
|
21811
|
+
return content;
|
|
21454
21812
|
}
|
|
21455
|
-
return response.
|
|
21813
|
+
return { content, evidence: response.evidence ?? null };
|
|
21456
21814
|
}
|
|
21457
21815
|
async chatStream(query, options) {
|
|
21458
21816
|
const targetId = options?.target ? typeof options.target === "string" ? options.target : options.target.id : undefined;
|
|
@@ -21461,13 +21819,20 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21461
21819
|
query,
|
|
21462
21820
|
target: targetId,
|
|
21463
21821
|
session: resolvedSessionId,
|
|
21464
|
-
|
|
21822
|
+
scope: options?.scope,
|
|
21823
|
+
sessions: options?.sessions,
|
|
21824
|
+
reasoningLevel: options?.reasoningLevel,
|
|
21825
|
+
responseFormat: options?.responseFormat,
|
|
21826
|
+
includeEvidence: options?.includeEvidence
|
|
21465
21827
|
});
|
|
21466
21828
|
const response = await this._chatStream({
|
|
21467
21829
|
query: chatParams.query,
|
|
21468
21830
|
target: chatParams.target,
|
|
21469
21831
|
session_id: chatParams.session,
|
|
21470
|
-
|
|
21832
|
+
...(0, validation_1.scopeRecallFields)(chatParams),
|
|
21833
|
+
reasoning_level: chatParams.reasoningLevel,
|
|
21834
|
+
response_format: Peer.toResponseFormatSchema(options?.responseFormat),
|
|
21835
|
+
include_evidence: chatParams.includeEvidence ? true : undefined
|
|
21471
21836
|
});
|
|
21472
21837
|
return (0, streaming_1.createDialecticStream)(response);
|
|
21473
21838
|
}
|
|
@@ -21494,7 +21859,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21494
21859
|
reverse
|
|
21495
21860
|
});
|
|
21496
21861
|
};
|
|
21497
|
-
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);
|
|
21862
|
+
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);
|
|
21498
21863
|
}
|
|
21499
21864
|
message(content, options) {
|
|
21500
21865
|
const validatedContent = validation_1.MessageContentSchema.parse(content);
|
|
@@ -21513,6 +21878,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21513
21878
|
const peer = await this._getOrCreate({ id: this.id });
|
|
21514
21879
|
this._metadata = peer.metadata || {};
|
|
21515
21880
|
this._createdAt = peer.created_at;
|
|
21881
|
+
this._uid = peer.uid;
|
|
21516
21882
|
return this._metadata;
|
|
21517
21883
|
}
|
|
21518
21884
|
async setMetadata(metadata) {
|
|
@@ -21524,6 +21890,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21524
21890
|
const peer = await this._getOrCreate({ id: this.id });
|
|
21525
21891
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
21526
21892
|
this._createdAt = peer.created_at;
|
|
21893
|
+
this._uid = peer.uid;
|
|
21527
21894
|
return this._configuration;
|
|
21528
21895
|
}
|
|
21529
21896
|
async setConfiguration(configuration) {
|
|
@@ -21536,6 +21903,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21536
21903
|
this._metadata = peer.metadata || {};
|
|
21537
21904
|
this._configuration = (0, validation_1.peerConfigFromApi)(peer.configuration) || {};
|
|
21538
21905
|
this._createdAt = peer.created_at;
|
|
21906
|
+
this._uid = peer.uid;
|
|
21539
21907
|
}
|
|
21540
21908
|
async search(query, options) {
|
|
21541
21909
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
@@ -21571,6 +21939,8 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21571
21939
|
const searchQuery = (0, validation_1.normalizeSearchQuery)(options?.searchQuery);
|
|
21572
21940
|
const getRepresentationParams = validation_1.PeerGetRepresentationParamsSchema.parse({
|
|
21573
21941
|
session: options?.session,
|
|
21942
|
+
scope: options?.scope,
|
|
21943
|
+
sessions: options?.sessions,
|
|
21574
21944
|
target: options?.target,
|
|
21575
21945
|
options: {
|
|
21576
21946
|
searchQuery,
|
|
@@ -21584,6 +21954,7 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21584
21954
|
const targetId = getRepresentationParams.target ? typeof getRepresentationParams.target === "string" ? getRepresentationParams.target : getRepresentationParams.target.id : undefined;
|
|
21585
21955
|
const response = await this._getRepresentation({
|
|
21586
21956
|
session_id: sessionId,
|
|
21957
|
+
...(0, validation_1.scopeRecallFields)(getRepresentationParams),
|
|
21587
21958
|
target: targetId,
|
|
21588
21959
|
search_query: searchQuery,
|
|
21589
21960
|
search_top_k: getRepresentationParams.options?.searchTopK,
|
|
@@ -21614,17 +21985,124 @@ var require_peer = __commonJS(function(exports) {
|
|
|
21614
21985
|
return PeerContext.fromApiResponse(response);
|
|
21615
21986
|
}
|
|
21616
21987
|
get conclusions() {
|
|
21617
|
-
return new conclusions_1.
|
|
21988
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, this.id, () => this._ensureWorkspace());
|
|
21618
21989
|
}
|
|
21619
21990
|
conclusionsOf(target) {
|
|
21620
21991
|
const targetId = typeof target === "string" ? target : target.id;
|
|
21621
|
-
return new conclusions_1.
|
|
21992
|
+
return new conclusions_1.ConclusionsView(this._http, this.workspaceId, this.id, targetId, () => this._ensureWorkspace());
|
|
21993
|
+
}
|
|
21994
|
+
toString() {
|
|
21995
|
+
return `Peer(id='${this.id}')`;
|
|
21996
|
+
}
|
|
21997
|
+
}
|
|
21998
|
+
exports.Peer = Peer;
|
|
21999
|
+
});
|
|
22000
|
+
|
|
22001
|
+
// node_modules/@honcho-ai/sdk/dist/scope.js
|
|
22002
|
+
var require_scope2 = __commonJS(function(exports) {
|
|
22003
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22004
|
+
exports.Scope = undefined;
|
|
22005
|
+
var api_version_1 = require_api_version();
|
|
22006
|
+
var pagination_1 = require_pagination();
|
|
22007
|
+
var session_1 = require_session();
|
|
22008
|
+
var utils_1 = require_utils2();
|
|
22009
|
+
var validation_1 = require_validation2();
|
|
22010
|
+
|
|
22011
|
+
class Scope {
|
|
22012
|
+
get metadata() {
|
|
22013
|
+
return this._metadata;
|
|
22014
|
+
}
|
|
22015
|
+
get createdAt() {
|
|
22016
|
+
return this._createdAt;
|
|
22017
|
+
}
|
|
22018
|
+
get sessionCount() {
|
|
22019
|
+
return this._sessionCount;
|
|
22020
|
+
}
|
|
22021
|
+
constructor(id, workspaceId, http, metadata, ensureWorkspace = async () => {
|
|
22022
|
+
return;
|
|
22023
|
+
}, createdAt, sessionCount) {
|
|
22024
|
+
this.id = id;
|
|
22025
|
+
this.workspaceId = workspaceId;
|
|
22026
|
+
this._http = http;
|
|
22027
|
+
this._metadata = metadata;
|
|
22028
|
+
this._ensureWorkspace = ensureWorkspace;
|
|
22029
|
+
this._createdAt = createdAt;
|
|
22030
|
+
this._sessionCount = sessionCount;
|
|
22031
|
+
}
|
|
22032
|
+
get _basePath() {
|
|
22033
|
+
return `/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/scopes/${this.id}`;
|
|
22034
|
+
}
|
|
22035
|
+
async _addSessions(sessionIds) {
|
|
22036
|
+
await this._ensureWorkspace();
|
|
22037
|
+
await this._http.post(`${this._basePath}/sessions`, {
|
|
22038
|
+
body: { session_ids: sessionIds }
|
|
22039
|
+
});
|
|
22040
|
+
}
|
|
22041
|
+
async _removeSessions(sessionIds) {
|
|
22042
|
+
await this._ensureWorkspace();
|
|
22043
|
+
await this._http.post(`${this._basePath}/sessions/remove`, {
|
|
22044
|
+
body: { session_ids: sessionIds }
|
|
22045
|
+
});
|
|
22046
|
+
}
|
|
22047
|
+
async _removeSession(sessionId) {
|
|
22048
|
+
await this._ensureWorkspace();
|
|
22049
|
+
await this._http.delete(`${this._basePath}/sessions/${sessionId}`);
|
|
22050
|
+
}
|
|
22051
|
+
async _listSessions(params) {
|
|
22052
|
+
await this._ensureWorkspace();
|
|
22053
|
+
return this._http.post(`${this._basePath}/sessions/list`, {
|
|
22054
|
+
query: {
|
|
22055
|
+
page: params?.page,
|
|
22056
|
+
size: params?.size,
|
|
22057
|
+
reverse: params?.reverse ? "true" : undefined
|
|
22058
|
+
}
|
|
22059
|
+
});
|
|
22060
|
+
}
|
|
22061
|
+
async _getStatus() {
|
|
22062
|
+
await this._ensureWorkspace();
|
|
22063
|
+
return this._http.get(`${this._basePath}/status`);
|
|
22064
|
+
}
|
|
22065
|
+
async addSessions(sessions) {
|
|
22066
|
+
const sessionIds = validation_1.ScopeSessionsSchema.parse(sessions.map(utils_1.resolveId));
|
|
22067
|
+
await this._addSessions(sessionIds);
|
|
22068
|
+
}
|
|
22069
|
+
async removeSessions(sessions) {
|
|
22070
|
+
const sessionIds = validation_1.ScopeSessionsSchema.parse(sessions.map(utils_1.resolveId));
|
|
22071
|
+
await this._removeSessions(sessionIds);
|
|
22072
|
+
}
|
|
22073
|
+
async removeSession(session) {
|
|
22074
|
+
await this._removeSession(validation_1.SessionIdSchema.parse((0, utils_1.resolveId)(session)));
|
|
22075
|
+
}
|
|
22076
|
+
async sessions(options) {
|
|
22077
|
+
const reverse = options?.reverse;
|
|
22078
|
+
const sessionsPage = await this._listSessions({
|
|
22079
|
+
page: options?.page,
|
|
22080
|
+
size: options?.size,
|
|
22081
|
+
reverse
|
|
22082
|
+
});
|
|
22083
|
+
const fetchNextPage = async (page, size) => {
|
|
22084
|
+
return this._listSessions({ page, size, reverse });
|
|
22085
|
+
};
|
|
22086
|
+
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);
|
|
22087
|
+
}
|
|
22088
|
+
async status() {
|
|
22089
|
+
const response = await this._getStatus();
|
|
22090
|
+
return {
|
|
22091
|
+
backfillStatus: Object.fromEntries(Object.entries(response.backfill_status ?? {}).map(([sessionId, job]) => [
|
|
22092
|
+
sessionId,
|
|
22093
|
+
{
|
|
22094
|
+
state: job.state,
|
|
22095
|
+
updatedAt: job.updated_at,
|
|
22096
|
+
docsCopied: job.docs_copied
|
|
22097
|
+
}
|
|
22098
|
+
]))
|
|
22099
|
+
};
|
|
21622
22100
|
}
|
|
21623
22101
|
toString() {
|
|
21624
|
-
return `
|
|
22102
|
+
return `Scope(id='${this.id}', workspaceId='${this.workspaceId}')`;
|
|
21625
22103
|
}
|
|
21626
22104
|
}
|
|
21627
|
-
exports.
|
|
22105
|
+
exports.Scope = Scope;
|
|
21628
22106
|
});
|
|
21629
22107
|
|
|
21630
22108
|
// node_modules/@honcho-ai/sdk/dist/client.js
|
|
@@ -21632,10 +22110,13 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21632
22110
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21633
22111
|
exports.Honcho = undefined;
|
|
21634
22112
|
var api_version_1 = require_api_version();
|
|
22113
|
+
var conclusions_1 = require_conclusions();
|
|
21635
22114
|
var client_1 = require_client();
|
|
22115
|
+
var streaming_1 = require_streaming();
|
|
21636
22116
|
var message_1 = require_message();
|
|
21637
22117
|
var pagination_1 = require_pagination();
|
|
21638
22118
|
var peer_1 = require_peer();
|
|
22119
|
+
var scope_1 = require_scope2();
|
|
21639
22120
|
var session_1 = require_session();
|
|
21640
22121
|
var utils_1 = require_utils2();
|
|
21641
22122
|
var validation_1 = require_validation2();
|
|
@@ -21648,9 +22129,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21648
22129
|
get configuration() {
|
|
21649
22130
|
return this._configuration;
|
|
21650
22131
|
}
|
|
22132
|
+
get uid() {
|
|
22133
|
+
return this._uid;
|
|
22134
|
+
}
|
|
21651
22135
|
get http() {
|
|
21652
22136
|
return this._http;
|
|
21653
22137
|
}
|
|
22138
|
+
get conclusions() {
|
|
22139
|
+
return new conclusions_1.WorkspaceConclusions(this._http, this.workspaceId, () => this._ensureWorkspace());
|
|
22140
|
+
}
|
|
21654
22141
|
get baseURL() {
|
|
21655
22142
|
return this._http.baseURL;
|
|
21656
22143
|
}
|
|
@@ -21673,13 +22160,15 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21673
22160
|
});
|
|
21674
22161
|
}
|
|
21675
22162
|
async _getOrCreateWorkspace(id, params) {
|
|
21676
|
-
|
|
22163
|
+
const workspace = await this._http.post(`/${api_version_1.API_VERSION}/workspaces`, {
|
|
21677
22164
|
body: {
|
|
21678
22165
|
id,
|
|
21679
22166
|
metadata: params?.metadata,
|
|
21680
22167
|
configuration: (0, validation_1.workspaceConfigToApi)(params?.configuration)
|
|
21681
22168
|
}
|
|
21682
22169
|
});
|
|
22170
|
+
this._uid = workspace.uid;
|
|
22171
|
+
return workspace;
|
|
21683
22172
|
}
|
|
21684
22173
|
async _ensureWorkspace() {
|
|
21685
22174
|
if (!this._workspaceReady) {
|
|
@@ -21707,7 +22196,8 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21707
22196
|
},
|
|
21708
22197
|
query: {
|
|
21709
22198
|
page: params?.page,
|
|
21710
|
-
size: params?.size
|
|
22199
|
+
size: params?.size,
|
|
22200
|
+
reverse: params?.reverse ? "true" : undefined
|
|
21711
22201
|
}
|
|
21712
22202
|
});
|
|
21713
22203
|
}
|
|
@@ -21737,13 +22227,35 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21737
22227
|
async _getOrCreatePeer(workspaceId, params) {
|
|
21738
22228
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/peers`, { body: params });
|
|
21739
22229
|
}
|
|
22230
|
+
async _getOrCreateScope(workspaceId, params) {
|
|
22231
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes`, { body: params });
|
|
22232
|
+
}
|
|
22233
|
+
async _getScope(workspaceId, scopeId) {
|
|
22234
|
+
return this._http.get(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes/${scopeId}`);
|
|
22235
|
+
}
|
|
22236
|
+
async _listScopes(workspaceId, params) {
|
|
22237
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/scopes/list`, {
|
|
22238
|
+
body: { filters: params?.filters },
|
|
22239
|
+
query: {
|
|
22240
|
+
page: params?.page,
|
|
22241
|
+
size: params?.size,
|
|
22242
|
+
reverse: params?.reverse ? "true" : undefined,
|
|
22243
|
+
include_session_count: params?.includeSessionCount ? "true" : undefined
|
|
22244
|
+
}
|
|
22245
|
+
});
|
|
22246
|
+
}
|
|
21740
22247
|
async _listSessions(workspaceId, params) {
|
|
21741
22248
|
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/sessions/list`, {
|
|
21742
|
-
body: {
|
|
22249
|
+
body: {
|
|
22250
|
+
filters: params?.filters,
|
|
22251
|
+
scope: params?.scope,
|
|
22252
|
+
in_no_scope: params?.inNoScope ? true : undefined
|
|
22253
|
+
},
|
|
21743
22254
|
query: {
|
|
21744
22255
|
page: params?.page,
|
|
21745
22256
|
size: params?.size,
|
|
21746
|
-
reverse: params?.reverse ? "true" : undefined
|
|
22257
|
+
reverse: params?.reverse ? "true" : undefined,
|
|
22258
|
+
include_scopes: params?.includeScopes ? "true" : undefined
|
|
21747
22259
|
}
|
|
21748
22260
|
});
|
|
21749
22261
|
}
|
|
@@ -21752,7 +22264,22 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21752
22264
|
body: {
|
|
21753
22265
|
id: params.id,
|
|
21754
22266
|
metadata: params.metadata,
|
|
21755
|
-
configuration: (0, validation_1.sessionConfigToApi)(params.configuration)
|
|
22267
|
+
configuration: (0, validation_1.sessionConfigToApi)(params.configuration),
|
|
22268
|
+
peers: params.peers,
|
|
22269
|
+
scopes: params.scopes
|
|
22270
|
+
}
|
|
22271
|
+
});
|
|
22272
|
+
}
|
|
22273
|
+
async _workspaceChat(workspaceId, params) {
|
|
22274
|
+
await this._ensureWorkspace();
|
|
22275
|
+
return this._http.post(`/${api_version_1.API_VERSION}/workspaces/${workspaceId}/chat`, { body: params });
|
|
22276
|
+
}
|
|
22277
|
+
async _workspaceChatStream(workspaceId, params) {
|
|
22278
|
+
await this._ensureWorkspace();
|
|
22279
|
+
return this._http.stream("POST", `/${api_version_1.API_VERSION}/workspaces/${workspaceId}/chat`, {
|
|
22280
|
+
body: {
|
|
22281
|
+
...params,
|
|
22282
|
+
stream: true
|
|
21756
22283
|
}
|
|
21757
22284
|
});
|
|
21758
22285
|
}
|
|
@@ -21766,7 +22293,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21766
22293
|
configuration: (0, validation_1.peerConfigToApi)(validatedConfiguration),
|
|
21767
22294
|
metadata: validatedMetadata
|
|
21768
22295
|
});
|
|
21769
|
-
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);
|
|
22296
|
+
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);
|
|
21770
22297
|
}
|
|
21771
22298
|
async peers(options) {
|
|
21772
22299
|
await this._ensureWorkspace();
|
|
@@ -21792,19 +22319,55 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21792
22319
|
reverse
|
|
21793
22320
|
});
|
|
21794
22321
|
};
|
|
21795
|
-
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);
|
|
22322
|
+
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);
|
|
21796
22323
|
}
|
|
21797
22324
|
async session(id, options) {
|
|
21798
22325
|
await this._ensureWorkspace();
|
|
21799
22326
|
const validatedId = validation_1.SessionIdSchema.parse(id);
|
|
21800
22327
|
const validatedMetadata = options?.metadata ? validation_1.SessionMetadataSchema.parse(options.metadata) : undefined;
|
|
21801
22328
|
const validatedConfiguration = options?.configuration ? validation_1.SessionConfigSchema.parse(options.configuration) : undefined;
|
|
22329
|
+
const validatedPeers = options?.peers !== undefined ? validation_1.PeerAdditionToApiSchema.parse(options.peers) : undefined;
|
|
22330
|
+
const validatedScopes = options?.scopes !== undefined ? validation_1.SessionScopesSchema.parse(options.scopes.map(utils_1.resolveId)) : undefined;
|
|
21802
22331
|
const sessionData = await this._getOrCreateSession(this.workspaceId, {
|
|
21803
22332
|
id: validatedId,
|
|
21804
22333
|
configuration: validatedConfiguration,
|
|
21805
|
-
metadata: validatedMetadata
|
|
22334
|
+
metadata: validatedMetadata,
|
|
22335
|
+
peers: validatedPeers,
|
|
22336
|
+
scopes: validatedScopes
|
|
22337
|
+
});
|
|
22338
|
+
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);
|
|
22339
|
+
}
|
|
22340
|
+
async scope(id, options) {
|
|
22341
|
+
await this._ensureWorkspace();
|
|
22342
|
+
const validatedId = validation_1.ScopeIdSchema.parse(id);
|
|
22343
|
+
const scopeData = await this._getOrCreateScope(this.workspaceId, {
|
|
22344
|
+
id: validatedId,
|
|
22345
|
+
metadata: options?.metadata
|
|
22346
|
+
});
|
|
22347
|
+
return new scope_1.Scope(validatedId, this.workspaceId, this._http, scopeData.metadata ?? undefined, () => this._ensureWorkspace(), scopeData.created_at);
|
|
22348
|
+
}
|
|
22349
|
+
async getScope(id) {
|
|
22350
|
+
await this._ensureWorkspace();
|
|
22351
|
+
const validatedId = validation_1.ScopeIdSchema.parse(id);
|
|
22352
|
+
const scopeData = await this._getScope(this.workspaceId, validatedId);
|
|
22353
|
+
return new scope_1.Scope(validatedId, this.workspaceId, this._http, scopeData.metadata ?? undefined, () => this._ensureWorkspace(), scopeData.created_at);
|
|
22354
|
+
}
|
|
22355
|
+
async scopes(options) {
|
|
22356
|
+
await this._ensureWorkspace();
|
|
22357
|
+
const listOptions = {
|
|
22358
|
+
filters: options?.filters ? validation_1.FilterSchema.parse(options.filters) : undefined,
|
|
22359
|
+
reverse: options?.reverse,
|
|
22360
|
+
includeSessionCount: options?.includeSessionCount
|
|
22361
|
+
};
|
|
22362
|
+
const scopesPage = await this._listScopes(this.workspaceId, {
|
|
22363
|
+
...listOptions,
|
|
22364
|
+
page: options?.page,
|
|
22365
|
+
size: options?.size
|
|
21806
22366
|
});
|
|
21807
|
-
|
|
22367
|
+
const fetchNextPage = async (page, size) => {
|
|
22368
|
+
return this._listScopes(this.workspaceId, { ...listOptions, page, size });
|
|
22369
|
+
};
|
|
22370
|
+
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);
|
|
21808
22371
|
}
|
|
21809
22372
|
async sessions(options) {
|
|
21810
22373
|
await this._ensureWorkspace();
|
|
@@ -21812,25 +22375,32 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21812
22375
|
"filters",
|
|
21813
22376
|
"page",
|
|
21814
22377
|
"size",
|
|
21815
|
-
"reverse"
|
|
22378
|
+
"reverse",
|
|
22379
|
+
"scope",
|
|
22380
|
+
"inNoScope",
|
|
22381
|
+
"includeScopes"
|
|
21816
22382
|
]);
|
|
21817
22383
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
21818
|
-
const
|
|
21819
|
-
const sessionsPage = await this._listSessions(this.workspaceId, {
|
|
22384
|
+
const listOptions = {
|
|
21820
22385
|
filters: validatedFilter,
|
|
22386
|
+
reverse: normalizedOptions.reverse,
|
|
22387
|
+
scope: normalizedOptions.scope,
|
|
22388
|
+
inNoScope: normalizedOptions.inNoScope,
|
|
22389
|
+
includeScopes: normalizedOptions.includeScopes
|
|
22390
|
+
};
|
|
22391
|
+
const sessionsPage = await this._listSessions(this.workspaceId, {
|
|
22392
|
+
...listOptions,
|
|
21821
22393
|
page: normalizedOptions.page,
|
|
21822
|
-
size: normalizedOptions.size
|
|
21823
|
-
reverse
|
|
22394
|
+
size: normalizedOptions.size
|
|
21824
22395
|
});
|
|
21825
22396
|
const fetchNextPage = async (page, size) => {
|
|
21826
22397
|
return this._listSessions(this.workspaceId, {
|
|
21827
|
-
|
|
22398
|
+
...listOptions,
|
|
21828
22399
|
page,
|
|
21829
|
-
size
|
|
21830
|
-
reverse
|
|
22400
|
+
size
|
|
21831
22401
|
});
|
|
21832
22402
|
};
|
|
21833
|
-
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);
|
|
22403
|
+
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);
|
|
21834
22404
|
}
|
|
21835
22405
|
async getMetadata() {
|
|
21836
22406
|
await this._ensureWorkspace();
|
|
@@ -21870,19 +22440,23 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21870
22440
|
const normalizedOptions = (0, validation_1.normalizeListOptions)(options, [
|
|
21871
22441
|
"filters",
|
|
21872
22442
|
"page",
|
|
21873
|
-
"size"
|
|
22443
|
+
"size",
|
|
22444
|
+
"reverse"
|
|
21874
22445
|
]);
|
|
21875
22446
|
const validatedFilter = normalizedOptions.filters ? validation_1.FilterSchema.parse(normalizedOptions.filters) : undefined;
|
|
22447
|
+
const reverse = normalizedOptions.reverse;
|
|
21876
22448
|
const workspacesPage = await this._listWorkspaces({
|
|
21877
22449
|
filters: validatedFilter,
|
|
21878
22450
|
page: normalizedOptions.page,
|
|
21879
|
-
size: normalizedOptions.size
|
|
22451
|
+
size: normalizedOptions.size,
|
|
22452
|
+
reverse
|
|
21880
22453
|
});
|
|
21881
22454
|
const fetchNextPage = async (page, size) => {
|
|
21882
22455
|
return this._listWorkspaces({
|
|
21883
22456
|
filters: validatedFilter,
|
|
21884
22457
|
page,
|
|
21885
|
-
size
|
|
22458
|
+
size,
|
|
22459
|
+
reverse
|
|
21886
22460
|
});
|
|
21887
22461
|
};
|
|
21888
22462
|
return new pagination_1.Page(workspacesPage, (workspace) => workspace.id, fetchNextPage);
|
|
@@ -21894,14 +22468,47 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21894
22468
|
await this._ensureWorkspace();
|
|
21895
22469
|
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
21896
22470
|
const validatedFilters = options?.filters ? validation_1.FilterSchema.parse(options.filters) : undefined;
|
|
22471
|
+
const validatedScope = options?.scope !== undefined ? validation_1.ScopeIdSchema.parse((0, utils_1.resolveId)(options.scope)) : undefined;
|
|
21897
22472
|
const validatedLimit = options?.limit ? validation_1.LimitSchema.parse(options.limit) : undefined;
|
|
21898
22473
|
const response = await this._searchWorkspace(this.workspaceId, {
|
|
21899
22474
|
query: validatedQuery,
|
|
21900
22475
|
filters: validatedFilters,
|
|
22476
|
+
scope: validatedScope,
|
|
21901
22477
|
limit: validatedLimit
|
|
21902
22478
|
});
|
|
21903
22479
|
return response.map(message_1.Message.fromApiResponse);
|
|
21904
22480
|
}
|
|
22481
|
+
async chat(query, options) {
|
|
22482
|
+
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
22483
|
+
const resolvedSessionId = options?.session ? (0, utils_1.resolveId)(options.session) : undefined;
|
|
22484
|
+
const response = await this._workspaceChat(this.workspaceId, {
|
|
22485
|
+
query: validatedQuery,
|
|
22486
|
+
stream: false,
|
|
22487
|
+
session_id: resolvedSessionId,
|
|
22488
|
+
reasoning_level: options?.reasoningLevel,
|
|
22489
|
+
response_format: options?.responseFormat,
|
|
22490
|
+
scope: options?.scope,
|
|
22491
|
+
include_evidence: options?.includeEvidence ? true : undefined
|
|
22492
|
+
});
|
|
22493
|
+
const content = response.content || null;
|
|
22494
|
+
if (!options?.includeEvidence) {
|
|
22495
|
+
return content;
|
|
22496
|
+
}
|
|
22497
|
+
return { content, evidence: response.evidence ?? null };
|
|
22498
|
+
}
|
|
22499
|
+
async chatStream(query, options) {
|
|
22500
|
+
const validatedQuery = validation_1.SearchQuerySchema.parse(query);
|
|
22501
|
+
const resolvedSessionId = options?.session ? (0, utils_1.resolveId)(options.session) : undefined;
|
|
22502
|
+
const response = await this._workspaceChatStream(this.workspaceId, {
|
|
22503
|
+
query: validatedQuery,
|
|
22504
|
+
session_id: resolvedSessionId,
|
|
22505
|
+
reasoning_level: options?.reasoningLevel,
|
|
22506
|
+
response_format: options?.responseFormat,
|
|
22507
|
+
scope: options?.scope,
|
|
22508
|
+
include_evidence: options?.includeEvidence ? true : undefined
|
|
22509
|
+
});
|
|
22510
|
+
return (0, streaming_1.createDialecticStream)(response);
|
|
22511
|
+
}
|
|
21905
22512
|
async queueStatus(options) {
|
|
21906
22513
|
await this._ensureWorkspace();
|
|
21907
22514
|
const observerId = options?.observer ? (0, utils_1.resolveId)(options.observer) : undefined;
|
|
@@ -21931,6 +22538,20 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21931
22538
|
}
|
|
21932
22539
|
});
|
|
21933
22540
|
}
|
|
22541
|
+
async dreams(options) {
|
|
22542
|
+
await this._ensureWorkspace();
|
|
22543
|
+
const body = {};
|
|
22544
|
+
if (options?.observed)
|
|
22545
|
+
body.observed_id = (0, utils_1.resolveId)(options.observed);
|
|
22546
|
+
if (options?.observer)
|
|
22547
|
+
body.observer_id = (0, utils_1.resolveId)(options.observer);
|
|
22548
|
+
const fetchPage = (page, size) => this._http.post(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/dreams/list`, { body, query: { page, size } });
|
|
22549
|
+
return new pagination_1.Page(await fetchPage(options?.page, options?.size), undefined, fetchPage);
|
|
22550
|
+
}
|
|
22551
|
+
async getDream(runId) {
|
|
22552
|
+
await this._ensureWorkspace();
|
|
22553
|
+
return this._http.get(`/${api_version_1.API_VERSION}/workspaces/${this.workspaceId}/dreams/${runId}`);
|
|
22554
|
+
}
|
|
21934
22555
|
toString() {
|
|
21935
22556
|
return `Honcho(workspaceId='${this.workspaceId}', baseURL='${this._http.baseURL}')`;
|
|
21936
22557
|
}
|
|
@@ -21941,7 +22562,7 @@ var require_client2 = __commonJS(function(exports) {
|
|
|
21941
22562
|
// node_modules/@honcho-ai/sdk/dist/index.js
|
|
21942
22563
|
var require_dist2 = __commonJS(function(exports) {
|
|
21943
22564
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21944
|
-
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;
|
|
22565
|
+
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;
|
|
21945
22566
|
var client_1 = require_client2();
|
|
21946
22567
|
Object.defineProperty(exports, "Honcho", { enumerable: true, get: function() {
|
|
21947
22568
|
return client_1.Honcho;
|
|
@@ -21951,7 +22572,13 @@ var require_dist2 = __commonJS(function(exports) {
|
|
|
21951
22572
|
return conclusions_1.Conclusion;
|
|
21952
22573
|
} });
|
|
21953
22574
|
Object.defineProperty(exports, "ConclusionScope", { enumerable: true, get: function() {
|
|
21954
|
-
return conclusions_1.
|
|
22575
|
+
return conclusions_1.ConclusionsView;
|
|
22576
|
+
} });
|
|
22577
|
+
Object.defineProperty(exports, "ConclusionsView", { enumerable: true, get: function() {
|
|
22578
|
+
return conclusions_1.ConclusionsView;
|
|
22579
|
+
} });
|
|
22580
|
+
Object.defineProperty(exports, "WorkspaceConclusions", { enumerable: true, get: function() {
|
|
22581
|
+
return conclusions_1.WorkspaceConclusions;
|
|
21955
22582
|
} });
|
|
21956
22583
|
var errors_1 = require_errors2();
|
|
21957
22584
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function() {
|
|
@@ -22006,6 +22633,10 @@ var require_dist2 = __commonJS(function(exports) {
|
|
|
22006
22633
|
Object.defineProperty(exports, "PeerContext", { enumerable: true, get: function() {
|
|
22007
22634
|
return peer_1.PeerContext;
|
|
22008
22635
|
} });
|
|
22636
|
+
var scope_1 = require_scope2();
|
|
22637
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function() {
|
|
22638
|
+
return scope_1.Scope;
|
|
22639
|
+
} });
|
|
22009
22640
|
var session_1 = require_session();
|
|
22010
22641
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function() {
|
|
22011
22642
|
return session_1.Session;
|
|
@@ -27863,278 +28494,453 @@ class StdioServerTransport {
|
|
|
27863
28494
|
}
|
|
27864
28495
|
|
|
27865
28496
|
// src/mcp/server.ts
|
|
27866
|
-
var
|
|
27867
|
-
import { readFileSync as
|
|
28497
|
+
var import_sdk2 = __toESM(require_dist2(), 1);
|
|
28498
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
27868
28499
|
|
|
27869
28500
|
// src/config.ts
|
|
27870
|
-
import {
|
|
27871
|
-
import { join as join3, basename, dirname, resolve, sep } from "path";
|
|
28501
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
27872
28502
|
import { fileURLToPath } from "url";
|
|
27873
|
-
import {
|
|
27874
|
-
|
|
27875
|
-
//
|
|
27876
|
-
import {
|
|
27877
|
-
import {
|
|
27878
|
-
import { join } from "path";
|
|
27879
|
-
|
|
27880
|
-
|
|
28503
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
28504
|
+
|
|
28505
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
28506
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
28507
|
+
import { homedir } from "node:os";
|
|
28508
|
+
import { join as join2 } from "node:path";
|
|
28509
|
+
|
|
28510
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/v01.js
|
|
28511
|
+
var isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
28512
|
+
var str = (v) => typeof v === "string" && v ? v : undefined;
|
|
28513
|
+
function v01Reader(file, host) {
|
|
28514
|
+
const hosts = isObj(file.hosts) ? file.hosts : {};
|
|
28515
|
+
const v1 = typeof file.schemaVersion === "number" && file.schemaVersion >= 1;
|
|
28516
|
+
const pick = (b) => {
|
|
28517
|
+
const o = isObj(b) ? b : {};
|
|
28518
|
+
if (v1)
|
|
28519
|
+
return { apiKey: isObj(o.auth) ? str(o.auth.apiKey) : undefined, peerName: str(o.peerName), workspace: str(o.workspace), baseUrl: str(o.baseUrl) };
|
|
28520
|
+
return {
|
|
28521
|
+
apiKey: (isObj(o.auth) ? str(o.auth.apiKey) : undefined) ?? str(o.apiKey),
|
|
28522
|
+
peerName: str(o.peerName),
|
|
28523
|
+
workspace: str(o.workspace) ?? str(o.workspaceId),
|
|
28524
|
+
baseUrl: str(o.baseUrl) ?? str(o.environmentUrl) ?? (isObj(o.endpoint) ? str(o.endpoint.baseUrl) : undefined)
|
|
28525
|
+
};
|
|
28526
|
+
};
|
|
28527
|
+
const own = pick(hosts[host]);
|
|
28528
|
+
const top = pick(file);
|
|
28529
|
+
return {
|
|
28530
|
+
apiKey: own.apiKey ?? top.apiKey,
|
|
28531
|
+
peerName: own.peerName ?? top.peerName,
|
|
28532
|
+
workspace: own.workspace ?? top.workspace,
|
|
28533
|
+
aiPeer: isObj(hosts[host]) ? str(hosts[host].aiPeer) : undefined,
|
|
28534
|
+
baseUrl: own.baseUrl ?? top.baseUrl
|
|
28535
|
+
};
|
|
28536
|
+
}
|
|
28537
|
+
|
|
28538
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/oauth.js
|
|
28539
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
28540
|
+
import { dirname, join } from "node:path";
|
|
28541
|
+
var OAUTH_TOKEN_URL = "https://api.honcho.dev/oauth/token";
|
|
28542
|
+
var OAUTH_SCOPE = "write";
|
|
28543
|
+
var REQUEST_TIMEOUT_MS = 1e4;
|
|
28544
|
+
var REFRESH_SKEW_S = 60;
|
|
28545
|
+
var LOCK_STALE_MS = REQUEST_TIMEOUT_MS + 5000;
|
|
28546
|
+
var LOCK_WAIT_MS = LOCK_STALE_MS + 5000;
|
|
28547
|
+
var PERMANENT_ERRORS = new Set(["invalid_grant", "invalid_client", "unauthorized_client"]);
|
|
28548
|
+
|
|
28549
|
+
class OAuthError extends Error {
|
|
28550
|
+
code;
|
|
28551
|
+
constructor(code, description) {
|
|
28552
|
+
super(description || code);
|
|
28553
|
+
this.code = code;
|
|
28554
|
+
this.name = "OAuthError";
|
|
28555
|
+
}
|
|
28556
|
+
}
|
|
28557
|
+
function isCloud(baseUrl) {
|
|
28558
|
+
return normalizeBaseUrl(baseUrl || DEFAULT_BASE_URL) === DEFAULT_BASE_URL;
|
|
27881
28559
|
}
|
|
27882
|
-
function
|
|
28560
|
+
function accessValid(t, skewS = REFRESH_SKEW_S, nowS = Date.now() / 1000) {
|
|
28561
|
+
return !!t?.accessToken && nowS < t.accessExpiresAt - skewS;
|
|
28562
|
+
}
|
|
28563
|
+
async function post(url, form, t) {
|
|
28564
|
+
const f = t?.fetch ?? fetch;
|
|
28565
|
+
let res;
|
|
28566
|
+
try {
|
|
28567
|
+
res = await f(url, {
|
|
28568
|
+
method: "POST",
|
|
28569
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
28570
|
+
body: new URLSearchParams(form).toString(),
|
|
28571
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
28572
|
+
});
|
|
28573
|
+
} catch (e) {
|
|
28574
|
+
throw new OAuthError("connection_error", `could not reach ${url}: ${e.message}`);
|
|
28575
|
+
}
|
|
28576
|
+
let body = null;
|
|
27883
28577
|
try {
|
|
27884
|
-
|
|
28578
|
+
body = await res.json();
|
|
27885
28579
|
} catch {
|
|
27886
|
-
|
|
28580
|
+
body = null;
|
|
27887
28581
|
}
|
|
28582
|
+
return { status: res.status, body };
|
|
27888
28583
|
}
|
|
27889
|
-
function
|
|
27890
|
-
|
|
27891
|
-
|
|
28584
|
+
function errorOf(r) {
|
|
28585
|
+
const b = r.body;
|
|
28586
|
+
if (b && typeof b === "object" && typeof b.error === "string")
|
|
28587
|
+
return new OAuthError(b.error, b.error_description);
|
|
28588
|
+
return new OAuthError("invalid_response");
|
|
28589
|
+
}
|
|
28590
|
+
function tokensFrom(body, clientId, prev) {
|
|
28591
|
+
if (!body || typeof body.access_token !== "string" || !Number.isFinite(Number(body.expires_in))) {
|
|
28592
|
+
throw new OAuthError("invalid_response", "malformed token response");
|
|
27892
28593
|
}
|
|
27893
|
-
const branch = gitCommand(cwd, "rev-parse --abbrev-ref HEAD") || "unknown";
|
|
27894
|
-
const commit = gitCommand(cwd, "rev-parse --short HEAD") || "unknown";
|
|
27895
|
-
const commitMessage = gitCommand(cwd, "log -1 --format=%s") || "";
|
|
27896
|
-
const statusOutput = gitCommand(cwd, "status --porcelain") || "";
|
|
27897
|
-
const isDirty = statusOutput.length > 0;
|
|
27898
|
-
const dirtyFiles = isDirty ? statusOutput.split(`
|
|
27899
|
-
`).filter((line) => line.trim()).map((line) => line.slice(3).trim()).slice(0, 20) : [];
|
|
27900
28594
|
return {
|
|
27901
|
-
|
|
27902
|
-
|
|
27903
|
-
|
|
27904
|
-
|
|
27905
|
-
|
|
27906
|
-
timestamp: new Date().toISOString()
|
|
28595
|
+
accessToken: body.access_token,
|
|
28596
|
+
refreshToken: body.refresh_token || prev?.refreshToken || "",
|
|
28597
|
+
accessExpiresAt: Math.floor(Date.now() / 1000) + Number(body.expires_in),
|
|
28598
|
+
clientId,
|
|
28599
|
+
scope: body.scope || prev?.scope || OAUTH_SCOPE
|
|
27907
28600
|
};
|
|
27908
28601
|
}
|
|
27909
|
-
|
|
27910
|
-
|
|
27911
|
-
|
|
27912
|
-
|
|
27913
|
-
|
|
27914
|
-
var CACHE_DIR = join2(homedir(), ".honcho");
|
|
27915
|
-
var ID_CACHE_FILE = join2(CACHE_DIR, "cache.json");
|
|
27916
|
-
var CONTEXT_CACHE_FILE = join2(CACHE_DIR, "context-cache.json");
|
|
27917
|
-
function ensureCacheDir() {
|
|
27918
|
-
if (!existsSync2(CACHE_DIR)) {
|
|
27919
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
27920
|
-
}
|
|
28602
|
+
async function refreshAccessToken(prev, opts = {}) {
|
|
28603
|
+
const r = await post(opts.tokenUrl ?? OAUTH_TOKEN_URL, { grant_type: "refresh_token", refresh_token: prev.refreshToken, client_id: prev.clientId }, opts);
|
|
28604
|
+
if (r.status !== 200)
|
|
28605
|
+
throw errorOf(r);
|
|
28606
|
+
return tokensFrom(r.body, prev.clientId, prev);
|
|
27921
28607
|
}
|
|
27922
|
-
function
|
|
27923
|
-
|
|
27924
|
-
|
|
27925
|
-
|
|
27926
|
-
|
|
27927
|
-
|
|
27928
|
-
|
|
27929
|
-
|
|
28608
|
+
function isObj2(v) {
|
|
28609
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
28610
|
+
}
|
|
28611
|
+
function asTokens(v) {
|
|
28612
|
+
if (!isObj2(v) || typeof v.accessToken !== "string" || !v.accessToken)
|
|
28613
|
+
return;
|
|
28614
|
+
return {
|
|
28615
|
+
accessToken: v.accessToken,
|
|
28616
|
+
refreshToken: typeof v.refreshToken === "string" ? v.refreshToken : "",
|
|
28617
|
+
accessExpiresAt: Number(v.accessExpiresAt) || 0,
|
|
28618
|
+
clientId: typeof v.clientId === "string" ? v.clientId : "",
|
|
28619
|
+
scope: typeof v.scope === "string" ? v.scope : ""
|
|
28620
|
+
};
|
|
28621
|
+
}
|
|
28622
|
+
function readFile(path) {
|
|
28623
|
+
if (!existsSync(path))
|
|
27930
28624
|
return {};
|
|
27931
|
-
|
|
28625
|
+
const parsed = JSON.parse(readFileSync(path, "utf-8"));
|
|
28626
|
+
return isObj2(parsed) ? parsed : {};
|
|
27932
28627
|
}
|
|
27933
|
-
function
|
|
27934
|
-
|
|
27935
|
-
writeFileSync(ID_CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
28628
|
+
function readGrant(file, host, legacy) {
|
|
28629
|
+
return asTokens(effectiveBlock(file, host, legacy).oauth);
|
|
27936
28630
|
}
|
|
27937
|
-
function
|
|
27938
|
-
|
|
27939
|
-
|
|
27940
|
-
|
|
27941
|
-
|
|
27942
|
-
|
|
28631
|
+
function holderAlive(token, ageMs) {
|
|
28632
|
+
if (token === "")
|
|
28633
|
+
return ageMs < 1000;
|
|
28634
|
+
const pid = Number(token.split(":")[0]);
|
|
28635
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
28636
|
+
return true;
|
|
28637
|
+
try {
|
|
28638
|
+
process.kill(pid, 0);
|
|
28639
|
+
return true;
|
|
28640
|
+
} catch (e) {
|
|
28641
|
+
return e.code === "EPERM";
|
|
28642
|
+
}
|
|
27943
28643
|
}
|
|
27944
|
-
function
|
|
27945
|
-
const
|
|
27946
|
-
|
|
27947
|
-
|
|
27948
|
-
let
|
|
27949
|
-
|
|
27950
|
-
|
|
27951
|
-
|
|
28644
|
+
async function withConfigLock(path, fn) {
|
|
28645
|
+
const lock = `${path}.lock`;
|
|
28646
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
28647
|
+
const start = Date.now();
|
|
28648
|
+
let fd;
|
|
28649
|
+
while (fd === undefined) {
|
|
28650
|
+
try {
|
|
28651
|
+
fd = openSync(lock, "wx", 384);
|
|
28652
|
+
} catch (e) {
|
|
28653
|
+
if (e.code !== "EEXIST")
|
|
28654
|
+
throw e;
|
|
28655
|
+
try {
|
|
28656
|
+
const age = Date.now() - statSync(lock).mtimeMs;
|
|
28657
|
+
if (age > LOCK_STALE_MS || !holderAlive(readFileSync(lock, "utf-8"), age))
|
|
28658
|
+
unlinkSync(lock);
|
|
28659
|
+
} catch {}
|
|
28660
|
+
if (Date.now() - start > LOCK_WAIT_MS)
|
|
28661
|
+
throw new Error(`timed out waiting for ${lock}`);
|
|
28662
|
+
await new Promise((r) => setTimeout(r, 50 + Math.random() * 50));
|
|
27952
28663
|
}
|
|
27953
28664
|
}
|
|
27954
|
-
|
|
28665
|
+
const token = `${process.pid}:${Math.random().toString(36).slice(2)}`;
|
|
28666
|
+
try {
|
|
28667
|
+
writeFileSync(fd, token);
|
|
28668
|
+
return await fn();
|
|
28669
|
+
} finally {
|
|
28670
|
+
closeSync(fd);
|
|
28671
|
+
try {
|
|
28672
|
+
if (readFileSync(lock, "utf-8") === token)
|
|
28673
|
+
unlinkSync(lock);
|
|
28674
|
+
} catch {}
|
|
28675
|
+
}
|
|
27955
28676
|
}
|
|
27956
|
-
function
|
|
27957
|
-
const
|
|
27958
|
-
|
|
28677
|
+
function writeFileAtomic(path, data) {
|
|
28678
|
+
const tmp = join(dirname(path), `.${Date.now()}-${process.pid}-${Math.random().toString(36).slice(2)}.tmp`);
|
|
28679
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + `
|
|
28680
|
+
`, { mode: 384 });
|
|
28681
|
+
renameSync(tmp, path);
|
|
27959
28682
|
}
|
|
27960
|
-
function
|
|
27961
|
-
|
|
27962
|
-
|
|
27963
|
-
|
|
28683
|
+
async function updateConfigFile(path, mutate) {
|
|
28684
|
+
await withConfigLock(path, async () => {
|
|
28685
|
+
const file = readFile(path);
|
|
28686
|
+
mutate(file);
|
|
28687
|
+
writeFileAtomic(path, file);
|
|
28688
|
+
});
|
|
27964
28689
|
}
|
|
27965
|
-
function
|
|
27966
|
-
const
|
|
27967
|
-
|
|
28690
|
+
function setGrant(file, host, tokens) {
|
|
28691
|
+
const block = hostBlock(file, host);
|
|
28692
|
+
if (tokens)
|
|
28693
|
+
block.oauth = tokens;
|
|
28694
|
+
else
|
|
28695
|
+
delete block.oauth;
|
|
27968
28696
|
}
|
|
27969
|
-
|
|
27970
|
-
"
|
|
27971
|
-
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
|
|
27977
|
-
|
|
27978
|
-
|
|
28697
|
+
function serverOf(block, baseUrl, env) {
|
|
28698
|
+
return baseUrl ?? (env.HONCHO_BASE_URL || undefined) ?? (typeof block.baseUrl === "string" && block.baseUrl ? block.baseUrl : undefined);
|
|
28699
|
+
}
|
|
28700
|
+
function pickCredential(file, opts) {
|
|
28701
|
+
const env = opts.env ?? process.env;
|
|
28702
|
+
if (env.HONCHO_API_KEY)
|
|
28703
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
28704
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
28705
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
28706
|
+
if (g)
|
|
28707
|
+
return { token: g.accessToken, source: "oauth", expiresAt: g.accessExpiresAt, ...accessValid(g, 0) ? {} : { expired: true } };
|
|
28708
|
+
return typeof block.apiKey === "string" && block.apiKey ? { token: block.apiKey, source: "apiKey" } : null;
|
|
28709
|
+
}
|
|
28710
|
+
async function ensureFreshCredential(opts) {
|
|
28711
|
+
const env = opts.env ?? process.env;
|
|
28712
|
+
if (env.HONCHO_API_KEY)
|
|
28713
|
+
return { token: env.HONCHO_API_KEY, source: "env" };
|
|
28714
|
+
let file;
|
|
27979
28715
|
try {
|
|
27980
|
-
|
|
27981
|
-
let cleaned = false;
|
|
27982
|
-
for (const key of Object.keys(raw)) {
|
|
27983
|
-
if (!CONTEXT_CACHE_KNOWN_KEYS.has(key)) {
|
|
27984
|
-
delete raw[key];
|
|
27985
|
-
cleaned = true;
|
|
27986
|
-
}
|
|
27987
|
-
}
|
|
27988
|
-
if (cleaned) {
|
|
27989
|
-
writeFileSync(CONTEXT_CACHE_FILE, JSON.stringify(raw, null, 2));
|
|
27990
|
-
}
|
|
27991
|
-
return raw;
|
|
28716
|
+
file = readFile(opts.path);
|
|
27992
28717
|
} catch {
|
|
27993
|
-
|
|
28718
|
+
file = {};
|
|
28719
|
+
}
|
|
28720
|
+
const block = effectiveBlock(file, opts.host, opts.legacy);
|
|
28721
|
+
const g = isCloud(serverOf(block, opts.baseUrl, env)) ? asTokens(block.oauth) : undefined;
|
|
28722
|
+
if (!g || accessValid(g) || !g.refreshToken)
|
|
28723
|
+
return pickCredential(file, opts);
|
|
28724
|
+
let error;
|
|
28725
|
+
try {
|
|
28726
|
+
await withConfigLock(opts.path, async () => {
|
|
28727
|
+
const current = readGrant(readFile(opts.path), opts.host, opts.legacy);
|
|
28728
|
+
if (!current || accessValid(current))
|
|
28729
|
+
return;
|
|
28730
|
+
const next = await refreshAccessToken(current, opts);
|
|
28731
|
+
const latest = readFile(opts.path);
|
|
28732
|
+
setGrant(latest, opts.host, next);
|
|
28733
|
+
writeFileAtomic(opts.path, latest);
|
|
28734
|
+
});
|
|
28735
|
+
} catch (e) {
|
|
28736
|
+
error = e instanceof OAuthError ? e.code : e.message;
|
|
27994
28737
|
}
|
|
28738
|
+
try {
|
|
28739
|
+
file = readFile(opts.path);
|
|
28740
|
+
} catch {}
|
|
28741
|
+
const cred = pickCredential(file, opts);
|
|
28742
|
+
if (cred && error) {
|
|
28743
|
+
cred.error = error;
|
|
28744
|
+
if (PERMANENT_ERRORS.has(error))
|
|
28745
|
+
cred.reauthRequired = true;
|
|
28746
|
+
}
|
|
28747
|
+
return cred;
|
|
28748
|
+
}
|
|
28749
|
+
|
|
28750
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/config.js
|
|
28751
|
+
var DEFAULT_BASE_URL = "https://api.honcho.dev";
|
|
28752
|
+
var CONFIG_SCHEMA_VERSION = 2;
|
|
28753
|
+
function isObj3(v) {
|
|
28754
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
27995
28755
|
}
|
|
27996
|
-
function
|
|
27997
|
-
|
|
27998
|
-
writeFileSync(CONTEXT_CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
28756
|
+
function str2(v) {
|
|
28757
|
+
return typeof v === "string" && v ? v : undefined;
|
|
27999
28758
|
}
|
|
28000
|
-
function
|
|
28001
|
-
|
|
28002
|
-
|
|
28003
|
-
|
|
28004
|
-
|
|
28759
|
+
function normalizeBaseUrl(input) {
|
|
28760
|
+
let s = input.trim();
|
|
28761
|
+
if (!s)
|
|
28762
|
+
return s;
|
|
28763
|
+
if (!s.startsWith("http://") && !s.startsWith("https://")) {
|
|
28764
|
+
const host = s.split("/")[0].split(":")[0].toLowerCase();
|
|
28765
|
+
const local = host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
28766
|
+
s = `${local ? "http" : "https"}://${s}`;
|
|
28767
|
+
}
|
|
28768
|
+
try {
|
|
28769
|
+
const u = new URL(s);
|
|
28770
|
+
u.hostname = u.hostname.toLowerCase();
|
|
28771
|
+
const path = u.pathname === "/" ? "" : u.pathname.replace(/\/+$/, "");
|
|
28772
|
+
return `${u.protocol}//${u.host}${path}`;
|
|
28773
|
+
} catch {
|
|
28774
|
+
return s;
|
|
28775
|
+
}
|
|
28005
28776
|
}
|
|
28006
|
-
function
|
|
28007
|
-
const
|
|
28008
|
-
|
|
28777
|
+
function resolveConfig(file, opts) {
|
|
28778
|
+
const env = opts.env ?? process.env;
|
|
28779
|
+
const { host } = opts;
|
|
28780
|
+
const block = effectiveBlock(file, host, opts.legacy);
|
|
28781
|
+
return {
|
|
28782
|
+
host,
|
|
28783
|
+
peerName: str2(env.HONCHO_PEER_NAME) ?? str2(block.peerName) ?? str2(env.USER) ?? str2(env.USERNAME) ?? "user",
|
|
28784
|
+
workspace: str2(env.HONCHO_WORKSPACE) ?? str2(block.workspace) ?? opts.defaults?.workspace ?? host,
|
|
28785
|
+
aiPeer: str2(env.HONCHO_AI_PEER) ?? str2(block.aiPeer) ?? opts.defaults?.aiPeer ?? host,
|
|
28786
|
+
baseUrl: normalizeBaseUrl(str2(env.HONCHO_BASE_URL) ?? str2(block.baseUrl) ?? DEFAULT_BASE_URL),
|
|
28787
|
+
warnings: checkConfig(file).map((i) => i.message)
|
|
28788
|
+
};
|
|
28009
28789
|
}
|
|
28010
|
-
function
|
|
28011
|
-
|
|
28012
|
-
|
|
28013
|
-
|
|
28790
|
+
function configPath(env = process.env) {
|
|
28791
|
+
if (env.HONCHO_CONFIG_PATH)
|
|
28792
|
+
return env.HONCHO_CONFIG_PATH;
|
|
28793
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
28794
|
+
return join2(home, ".honcho", "config.json");
|
|
28014
28795
|
}
|
|
28015
|
-
|
|
28016
|
-
|
|
28017
|
-
|
|
28018
|
-
if (!existsSync2(GIT_STATE_FILE)) {
|
|
28796
|
+
function readConfigFile(env = process.env) {
|
|
28797
|
+
const path = configPath(env);
|
|
28798
|
+
if (!existsSync2(path))
|
|
28019
28799
|
return {};
|
|
28020
|
-
}
|
|
28021
28800
|
try {
|
|
28022
|
-
|
|
28801
|
+
const parsed = JSON.parse(readFileSync2(path, "utf-8"));
|
|
28802
|
+
return isObj3(parsed) ? parsed : {};
|
|
28023
28803
|
} catch {
|
|
28024
28804
|
return {};
|
|
28025
28805
|
}
|
|
28026
28806
|
}
|
|
28027
|
-
function
|
|
28028
|
-
|
|
28029
|
-
|
|
28807
|
+
async function saveHost(path, host, patch, legacy) {
|
|
28808
|
+
await updateConfigFile(path, (file) => {
|
|
28809
|
+
if (isNewer(file))
|
|
28810
|
+
throw new Error(`${path} was written by a newer Honcho plugin; update this one.`);
|
|
28811
|
+
const block = writeBlock(file, host, hostMigration(file, host, [], legacy));
|
|
28812
|
+
if ("baseUrl" in patch && !("apiKey" in patch) && !sameServer(patch.baseUrl, str2(block.baseUrl)))
|
|
28813
|
+
delete block.apiKey;
|
|
28814
|
+
for (const [k, v] of Object.entries(patch)) {
|
|
28815
|
+
if (v === undefined)
|
|
28816
|
+
delete block[k];
|
|
28817
|
+
else
|
|
28818
|
+
block[k] = v;
|
|
28819
|
+
}
|
|
28820
|
+
block.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
28821
|
+
});
|
|
28030
28822
|
}
|
|
28031
|
-
|
|
28032
|
-
|
|
28033
|
-
return
|
|
28823
|
+
var MOVABLE = ["apiKey", "peerName", "workspace", "aiPeer", "baseUrl"];
|
|
28824
|
+
function isNewer(file) {
|
|
28825
|
+
return isObj3(file) && typeof file.schemaVersion === "number" && file.schemaVersion > CONFIG_SCHEMA_VERSION;
|
|
28034
28826
|
}
|
|
28035
|
-
function
|
|
28036
|
-
|
|
28037
|
-
cache[cwd] = state;
|
|
28038
|
-
saveGitStateCache(cache);
|
|
28827
|
+
function isMigrated(block) {
|
|
28828
|
+
return isObj3(block) && typeof block.schemaVersion === "number" && block.schemaVersion >= CONFIG_SCHEMA_VERSION;
|
|
28039
28829
|
}
|
|
28040
|
-
function
|
|
28041
|
-
|
|
28042
|
-
if (!previous) {
|
|
28043
|
-
changes.push({
|
|
28044
|
-
type: "initial",
|
|
28045
|
-
description: `Session started on branch '${current.branch}' at ${current.commit}`
|
|
28046
|
-
});
|
|
28047
|
-
return changes;
|
|
28048
|
-
}
|
|
28049
|
-
if (previous.branch !== current.branch) {
|
|
28050
|
-
changes.push({
|
|
28051
|
-
type: "branch_switch",
|
|
28052
|
-
description: `Branch switched from '${previous.branch}' to '${current.branch}'`,
|
|
28053
|
-
from: previous.branch,
|
|
28054
|
-
to: current.branch
|
|
28055
|
-
});
|
|
28056
|
-
}
|
|
28057
|
-
if (previous.commit !== current.commit) {
|
|
28058
|
-
changes.push({
|
|
28059
|
-
type: "new_commits",
|
|
28060
|
-
description: `New commit: ${current.commit} - ${current.commitMessage}`,
|
|
28061
|
-
from: previous.commit,
|
|
28062
|
-
to: current.commit
|
|
28063
|
-
});
|
|
28064
|
-
}
|
|
28065
|
-
if (!previous.isDirty && current.isDirty) {
|
|
28066
|
-
changes.push({
|
|
28067
|
-
type: "files_changed",
|
|
28068
|
-
description: `Uncommitted changes detected: ${current.dirtyFiles.slice(0, 5).join(", ")}${current.dirtyFiles.length > 5 ? "..." : ""}`
|
|
28069
|
-
});
|
|
28070
|
-
}
|
|
28071
|
-
return changes;
|
|
28830
|
+
function sameServer(a, b) {
|
|
28831
|
+
return normalizeBaseUrl(a ?? DEFAULT_BASE_URL) === normalizeBaseUrl(b ?? DEFAULT_BASE_URL);
|
|
28072
28832
|
}
|
|
28073
|
-
var
|
|
28074
|
-
function
|
|
28075
|
-
|
|
28076
|
-
|
|
28077
|
-
|
|
28078
|
-
|
|
28079
|
-
|
|
28080
|
-
|
|
28081
|
-
|
|
28082
|
-
|
|
28083
|
-
|
|
28084
|
-
}
|
|
28085
|
-
|
|
28086
|
-
|
|
28087
|
-
|
|
28088
|
-
|
|
28089
|
-
|
|
28090
|
-
|
|
28091
|
-
|
|
28092
|
-
|
|
28093
|
-
|
|
28094
|
-
|
|
28833
|
+
var LEGACY_HOST_KEYS = ["auth", "endpoint", "environmentUrl", "workspaceId"];
|
|
28834
|
+
function isGrant(v) {
|
|
28835
|
+
return isObj3(v) && typeof v.accessToken === "string" && v.accessToken !== "";
|
|
28836
|
+
}
|
|
28837
|
+
function legacyGrantOf(b) {
|
|
28838
|
+
return !isGrant(b.oauth) && isObj3(b.auth) && isObj3(b.auth.oauth) ? b.auth.oauth : undefined;
|
|
28839
|
+
}
|
|
28840
|
+
function checkConfig(file) {
|
|
28841
|
+
if (!isObj3(file))
|
|
28842
|
+
return [];
|
|
28843
|
+
if (isNewer(file)) {
|
|
28844
|
+
return [{ path: "schemaVersion", message: `This file is schema version ${file.schemaVersion}, newer than this plugin understands; update the plugin.` }];
|
|
28845
|
+
}
|
|
28846
|
+
const issues = [];
|
|
28847
|
+
const hosts = isObj3(file.hosts) ? file.hosts : {};
|
|
28848
|
+
const byWorkspace = new Map;
|
|
28849
|
+
for (const h of Object.keys(hosts).filter((k) => isObj3(hosts[k]))) {
|
|
28850
|
+
const block = hosts[h];
|
|
28851
|
+
const peer = str2(block.peerName);
|
|
28852
|
+
if (!peer)
|
|
28853
|
+
continue;
|
|
28854
|
+
const ws = str2(block.workspace) ?? h;
|
|
28855
|
+
const peers = byWorkspace.get(ws) ?? new Map;
|
|
28856
|
+
peers.set(peer, [...peers.get(peer) ?? [], h]);
|
|
28857
|
+
byWorkspace.set(ws, peers);
|
|
28095
28858
|
}
|
|
28096
|
-
|
|
28097
|
-
|
|
28859
|
+
for (const [ws, peers] of byWorkspace) {
|
|
28860
|
+
if (peers.size < 2)
|
|
28861
|
+
continue;
|
|
28862
|
+
const list = [...peers].map(([p, hs]) => `${hs.join(", ")}: "${p}"`).join("; ");
|
|
28863
|
+
issues.push({ path: "hosts", message: `Hosts in workspace "${ws}" use different peerNames (${list}), so the user is split across peers.` });
|
|
28098
28864
|
}
|
|
28099
|
-
return
|
|
28865
|
+
return issues;
|
|
28100
28866
|
}
|
|
28101
|
-
|
|
28102
|
-
|
|
28103
|
-
|
|
28104
|
-
|
|
28105
|
-
|
|
28106
|
-
|
|
28107
|
-
|
|
28108
|
-
|
|
28109
|
-
|
|
28110
|
-
|
|
28111
|
-
|
|
28112
|
-
|
|
28113
|
-
|
|
28114
|
-
|
|
28867
|
+
function hostMigration(file, host, deadKeys = [], legacy = v01Reader) {
|
|
28868
|
+
if (isNewer(file))
|
|
28869
|
+
return { set: {}, remove: [] };
|
|
28870
|
+
const f = isObj3(file) ? file : {};
|
|
28871
|
+
const hosts = isObj3(f.hosts) ? f.hosts : {};
|
|
28872
|
+
const block = isObj3(hosts[host]) ? hosts[host] : {};
|
|
28873
|
+
const set = {};
|
|
28874
|
+
const drop = [];
|
|
28875
|
+
const grant = legacyGrantOf(block);
|
|
28876
|
+
if (grant)
|
|
28877
|
+
set.oauth = grant;
|
|
28878
|
+
if (!isMigrated(block)) {
|
|
28879
|
+
const old = { ...legacy(f, host) };
|
|
28880
|
+
const signedIn = isGrant(block.oauth) || grant !== undefined;
|
|
28881
|
+
if (old.baseUrl && sameServer(old.baseUrl, undefined))
|
|
28882
|
+
old.baseUrl = undefined;
|
|
28883
|
+
for (const key of MOVABLE) {
|
|
28884
|
+
if (signedIn && (key === "apiKey" || key === "baseUrl"))
|
|
28885
|
+
continue;
|
|
28886
|
+
if (old[key] !== undefined && block[key] !== old[key])
|
|
28887
|
+
set[key] = old[key];
|
|
28888
|
+
else if (old[key] === undefined && block[key] !== undefined)
|
|
28889
|
+
drop.push(key);
|
|
28115
28890
|
}
|
|
28891
|
+
set.schemaVersion = CONFIG_SCHEMA_VERSION;
|
|
28116
28892
|
}
|
|
28893
|
+
const remove = [...drop, ...LEGACY_HOST_KEYS, ...deadKeys].filter((k) => (k in block) && !(k in set));
|
|
28894
|
+
return { set, remove };
|
|
28117
28895
|
}
|
|
28118
|
-
function
|
|
28119
|
-
|
|
28120
|
-
writeFileSync(ID_CACHE_FILE, "{}");
|
|
28896
|
+
function effectiveBlock(file, host, legacy) {
|
|
28897
|
+
return writeBlock(structuredClone(isObj3(file) ? file : {}), host, hostMigration(file, host, [], legacy));
|
|
28121
28898
|
}
|
|
28122
|
-
function
|
|
28123
|
-
|
|
28124
|
-
|
|
28125
|
-
|
|
28899
|
+
function hostBlock(file, host) {
|
|
28900
|
+
if (host === "__proto__" || host === "constructor" || host === "prototype")
|
|
28901
|
+
throw new Error(`invalid host name: ${host}`);
|
|
28902
|
+
if (!isObj3(file.hosts))
|
|
28903
|
+
file.hosts = {};
|
|
28904
|
+
return isObj3(file.hosts[host]) ? file.hosts[host] : file.hosts[host] = {};
|
|
28126
28905
|
}
|
|
28127
|
-
function
|
|
28128
|
-
const
|
|
28129
|
-
|
|
28130
|
-
|
|
28906
|
+
function writeBlock(file, host, { set, remove }) {
|
|
28907
|
+
const block = hostBlock(file, host);
|
|
28908
|
+
Object.assign(block, set);
|
|
28909
|
+
for (const k of remove)
|
|
28910
|
+
delete block[k];
|
|
28911
|
+
return block;
|
|
28912
|
+
}
|
|
28913
|
+
async function migrateHost(path, host, deadKeys = [], legacy) {
|
|
28914
|
+
const peek = hostMigration(readConfigFile({ HONCHO_CONFIG_PATH: path }), host, deadKeys, legacy);
|
|
28915
|
+
if (!Object.keys(peek.set).length && !peek.remove.length)
|
|
28916
|
+
return [];
|
|
28917
|
+
let changed = [];
|
|
28918
|
+
await updateConfigFile(path, (file) => {
|
|
28919
|
+
const m = hostMigration(file, host, deadKeys, legacy);
|
|
28920
|
+
changed = [...Object.keys(m.set).filter((k) => k !== "schemaVersion"), ...m.remove.map((k) => `-${k}`)];
|
|
28921
|
+
if (Object.keys(m.set).length || m.remove.length)
|
|
28922
|
+
writeBlock(file, host, m);
|
|
28923
|
+
});
|
|
28924
|
+
return changed;
|
|
28131
28925
|
}
|
|
28132
|
-
|
|
28133
|
-
|
|
28134
|
-
|
|
28135
|
-
|
|
28926
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/legacy/claude-honcho.js
|
|
28927
|
+
var isObj4 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
28928
|
+
var str3 = (v) => typeof v === "string" && v ? v : undefined;
|
|
28929
|
+
function claudeHonchoReader(file, host) {
|
|
28930
|
+
const hosts = isObj4(file.hosts) ? file.hosts : {};
|
|
28931
|
+
const found = hosts[host] ?? hosts[host.replace(/_/g, "-")] ?? hosts[host.replace(/-/g, "_")];
|
|
28932
|
+
const block = isObj4(found) ? found : undefined;
|
|
28933
|
+
const endpoint = block?.endpoint ?? file.endpoint;
|
|
28934
|
+
const override = file.globalOverride === true;
|
|
28935
|
+
return {
|
|
28936
|
+
apiKey: str3(block?.apiKey) ?? str3(file.apiKey),
|
|
28937
|
+
baseUrl: str3(endpoint?.baseUrl)?.replace(/\/v3\/?$/, "") ?? (endpoint?.environment === "local" ? "http://localhost:8000" : undefined),
|
|
28938
|
+
peerName: str3(file.peerName),
|
|
28939
|
+
workspace: str3(override || !block ? file.workspace : block.workspace),
|
|
28940
|
+
aiPeer: str3(override ? file.aiPeer ?? block?.aiPeer : block ? block.aiPeer : file[host === "cursor" ? "cursorPeer" : "claudePeer"])
|
|
28941
|
+
};
|
|
28136
28942
|
}
|
|
28137
|
-
// node_modules/@honcho-ai/harness-plugin-core/
|
|
28943
|
+
// node_modules/@honcho-ai/harness-plugin-core/dist/telemetry.js
|
|
28138
28944
|
var HEADER_HOST = "X-Honcho-Host";
|
|
28139
28945
|
var HEADER_PLUGIN = "X-Honcho-Plugin";
|
|
28140
28946
|
var HEADER_AGENT_MODEL = "X-Honcho-Agent-Model";
|
|
@@ -28183,31 +28989,10 @@ function telemetryHeaders(id = {}, extra) {
|
|
|
28183
28989
|
return headers;
|
|
28184
28990
|
}
|
|
28185
28991
|
// src/config.ts
|
|
28992
|
+
var LEGACY = claudeHonchoReader;
|
|
28186
28993
|
function sanitizeForSessionName(s) {
|
|
28187
28994
|
return s.toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
28188
28995
|
}
|
|
28189
|
-
var SESSION_START_COMPONENTS = ["directives", "summary", "peerCard", "peerRepresentation", "briefing"];
|
|
28190
|
-
var PER_TURN_COMPONENTS = ["userContext", "assistantContext", "sessionContext", "dialectic"];
|
|
28191
|
-
function normalizePerTurn(components) {
|
|
28192
|
-
return components.map((c) => c === "context" ? "userContext" : c);
|
|
28193
|
-
}
|
|
28194
|
-
var DEFAULT_INJECTION = {
|
|
28195
|
-
sessionStart: ["directives", "summary", "peerCard"],
|
|
28196
|
-
perTurn: ["userContext"],
|
|
28197
|
-
showContents: [],
|
|
28198
|
-
searchTopK: 10,
|
|
28199
|
-
maxConclusions: 15,
|
|
28200
|
-
searchMaxDistance: 0.6,
|
|
28201
|
-
searchQuerySource: "prompt",
|
|
28202
|
-
sessionContextTokens: 1500,
|
|
28203
|
-
dialecticTemplate: "Return a compact, factual list of anything from the user's history — preferences, prior decisions, relevant past work — that would help with the following. Write in the third person as background notes; do not address the user, ask questions, or offer next steps. If nothing relevant exists, say so in one line. Relevant to: %{user_query}",
|
|
28204
|
-
dialecticReasoning: "medium"
|
|
28205
|
-
};
|
|
28206
|
-
var REASONING_LEVELS = ["minimal", "low", "medium", "high", "max"];
|
|
28207
|
-
var HONCHO_BASE_URLS = {
|
|
28208
|
-
production: "https://api.honcho.dev/v3",
|
|
28209
|
-
local: "http://localhost:8000/v3"
|
|
28210
|
-
};
|
|
28211
28996
|
var _detectedHost = null;
|
|
28212
28997
|
function setDetectedHost(host) {
|
|
28213
28998
|
_detectedHost = host;
|
|
@@ -28235,13 +29020,6 @@ var DEFAULT_AI_PEER = {
|
|
|
28235
29020
|
claude_code: "claude",
|
|
28236
29021
|
obsidian: "honcho"
|
|
28237
29022
|
};
|
|
28238
|
-
function coerceBoolean(value) {
|
|
28239
|
-
if (typeof value === "string") {
|
|
28240
|
-
const v = value.trim().toLowerCase();
|
|
28241
|
-
return v !== "false" && v !== "0" && v !== "";
|
|
28242
|
-
}
|
|
28243
|
-
return Boolean(value);
|
|
28244
|
-
}
|
|
28245
29023
|
var _stdinText = null;
|
|
28246
29024
|
function cacheStdin(text) {
|
|
28247
29025
|
_stdinText = text;
|
|
@@ -28268,373 +29046,159 @@ async function initHook() {
|
|
|
28268
29046
|
process.exit(0);
|
|
28269
29047
|
setDetectedHost(detectHost(input));
|
|
28270
29048
|
}
|
|
28271
|
-
function deepEqual(a, b) {
|
|
28272
|
-
if (a === b)
|
|
28273
|
-
return true;
|
|
28274
|
-
if (a == null || b == null)
|
|
28275
|
-
return a === b;
|
|
28276
|
-
if (typeof a !== typeof b)
|
|
28277
|
-
return false;
|
|
28278
|
-
if (typeof a !== "object")
|
|
28279
|
-
return false;
|
|
28280
|
-
const aObj = a;
|
|
28281
|
-
const bObj = b;
|
|
28282
|
-
const keys = new Set([...Object.keys(aObj), ...Object.keys(bObj)]);
|
|
28283
|
-
for (const key of keys) {
|
|
28284
|
-
if (!deepEqual(aObj[key], bObj[key]))
|
|
28285
|
-
return false;
|
|
28286
|
-
}
|
|
28287
|
-
return true;
|
|
28288
|
-
}
|
|
28289
|
-
var CONFIG_DIR = join3(homedir2(), ".honcho");
|
|
28290
|
-
var CONFIG_FILE = join3(CONFIG_DIR, "config.json");
|
|
28291
29049
|
function getConfigPath() {
|
|
28292
|
-
return
|
|
29050
|
+
return configPath();
|
|
29051
|
+
}
|
|
29052
|
+
function getConfigDir() {
|
|
29053
|
+
return dirname2(configPath());
|
|
28293
29054
|
}
|
|
28294
29055
|
function configExists() {
|
|
28295
|
-
return existsSync3(
|
|
29056
|
+
return existsSync3(configPath());
|
|
28296
29057
|
}
|
|
28297
29058
|
function getPluginVersion() {
|
|
28298
29059
|
const root = process.env.CLAUDE_PLUGIN_ROOT;
|
|
28299
29060
|
const candidates = [
|
|
28300
29061
|
...root ? [join3(root, ".claude-plugin", "plugin.json")] : [],
|
|
28301
29062
|
fileURLToPath(new URL("../.claude-plugin/plugin.json", import.meta.url))
|
|
28302
|
-
];
|
|
28303
|
-
for (const manifest of candidates) {
|
|
28304
|
-
try {
|
|
28305
|
-
const version = JSON.parse(
|
|
28306
|
-
if (typeof version === "string" && version)
|
|
28307
|
-
return version;
|
|
28308
|
-
} catch {}
|
|
28309
|
-
}
|
|
28310
|
-
return "unknown";
|
|
28311
|
-
}
|
|
28312
|
-
function loadConfig2(host) {
|
|
28313
|
-
const resolvedHost = host ?? getDetectedHost();
|
|
28314
|
-
if (configExists()) {
|
|
28315
|
-
try {
|
|
28316
|
-
const content = readFileSync2(CONFIG_FILE, "utf-8");
|
|
28317
|
-
const raw = JSON.parse(content);
|
|
28318
|
-
return resolveConfig2(raw, resolvedHost);
|
|
28319
|
-
} catch {}
|
|
28320
|
-
}
|
|
28321
|
-
return loadConfigFromEnv(resolvedHost);
|
|
28322
|
-
}
|
|
28323
|
-
function resolveConfig2(raw, host) {
|
|
28324
|
-
const hostBlock = raw.hosts?.[host] ?? raw.hosts?.[host.replace(/_/g, "-")] ?? raw.hosts?.[host.replace(/-/g, "_")];
|
|
28325
|
-
const apiKey = process.env.HONCHO_API_KEY || hostBlock?.apiKey || raw.apiKey;
|
|
28326
|
-
if (!apiKey)
|
|
28327
|
-
return null;
|
|
28328
|
-
const peerName = raw.peerName || process.env.HONCHO_PEER_NAME || process.env.USER || process.env.USERNAME || "user";
|
|
28329
|
-
let workspace;
|
|
28330
|
-
let aiPeer;
|
|
28331
|
-
if (raw.globalOverride === true) {
|
|
28332
|
-
workspace = raw.workspace ?? DEFAULT_WORKSPACE[host];
|
|
28333
|
-
aiPeer = raw.aiPeer ?? hostBlock?.aiPeer ?? DEFAULT_AI_PEER[host];
|
|
28334
|
-
} else if (hostBlock) {
|
|
28335
|
-
workspace = hostBlock.workspace ?? DEFAULT_WORKSPACE[host];
|
|
28336
|
-
aiPeer = hostBlock.aiPeer ?? DEFAULT_AI_PEER[host];
|
|
28337
|
-
} else {
|
|
28338
|
-
workspace = process.env.HONCHO_WORKSPACE ?? raw.workspace ?? DEFAULT_WORKSPACE[host];
|
|
28339
|
-
if (host === "cursor") {
|
|
28340
|
-
aiPeer = raw.cursorPeer ?? DEFAULT_AI_PEER["cursor"];
|
|
28341
|
-
} else {
|
|
28342
|
-
aiPeer = raw.claudePeer ?? DEFAULT_AI_PEER["claude_code"];
|
|
28343
|
-
}
|
|
28344
|
-
}
|
|
28345
|
-
const config = {
|
|
28346
|
-
apiKey,
|
|
28347
|
-
peerName,
|
|
28348
|
-
workspace,
|
|
28349
|
-
aiPeer,
|
|
28350
|
-
sessionStrategy: hostBlock?.sessionStrategy ?? raw.sessionStrategy,
|
|
28351
|
-
sessionPeerPrefix: hostBlock?.sessionPeerPrefix ?? raw.sessionPeerPrefix,
|
|
28352
|
-
sessions: raw.sessions,
|
|
28353
|
-
saveMessages: hostBlock?.saveMessages ?? raw.saveMessages,
|
|
28354
|
-
saveToolUse: hostBlock?.saveToolUse ?? raw.saveToolUse,
|
|
28355
|
-
saveGitEvents: hostBlock?.saveGitEvents ?? raw.saveGitEvents,
|
|
28356
|
-
reasoningLevel: hostBlock?.reasoningLevel ?? raw.reasoningLevel,
|
|
28357
|
-
observationMode: hostBlock?.observationMode ?? raw.observationMode,
|
|
28358
|
-
messageUpload: hostBlock?.messageUpload ?? raw.messageUpload,
|
|
28359
|
-
contextRefresh: hostBlock?.contextRefresh ?? raw.contextRefresh,
|
|
28360
|
-
endpoint: hostBlock?.endpoint ?? raw.endpoint,
|
|
28361
|
-
redactPatterns: hostBlock?.redactPatterns ?? raw.redactPatterns,
|
|
28362
|
-
injection: hostBlock?.injection ?? raw.injection,
|
|
28363
|
-
rememberTool: hostBlock?.rememberTool ?? raw.rememberTool,
|
|
28364
|
-
enabled: hostBlock?.enabled ?? raw.enabled,
|
|
28365
|
-
logging: hostBlock?.logging ?? raw.logging,
|
|
28366
|
-
globalOverride: raw.globalOverride
|
|
28367
|
-
};
|
|
28368
|
-
return mergeWithEnvVars(config);
|
|
28369
|
-
}
|
|
28370
|
-
function loadConfigFromEnv(host) {
|
|
28371
|
-
const apiKey = process.env.HONCHO_API_KEY;
|
|
28372
|
-
if (!apiKey) {
|
|
28373
|
-
return null;
|
|
28374
|
-
}
|
|
28375
|
-
const resolvedHost = host ?? getDetectedHost();
|
|
28376
|
-
const peerName = process.env.HONCHO_PEER_NAME || process.env.USER || process.env.USERNAME || "user";
|
|
28377
|
-
const workspace = process.env.HONCHO_WORKSPACE || DEFAULT_WORKSPACE[resolvedHost];
|
|
28378
|
-
const hostPeerEnv = resolvedHost === "cursor" ? process.env.HONCHO_CURSOR_PEER : process.env.HONCHO_CLAUDE_PEER;
|
|
28379
|
-
const aiPeer = process.env.HONCHO_AI_PEER || hostPeerEnv || DEFAULT_AI_PEER[resolvedHost];
|
|
28380
|
-
const endpoint = process.env.HONCHO_ENDPOINT;
|
|
28381
|
-
const config = {
|
|
28382
|
-
apiKey,
|
|
28383
|
-
peerName,
|
|
28384
|
-
workspace,
|
|
28385
|
-
aiPeer,
|
|
28386
|
-
saveMessages: process.env.HONCHO_SAVE_MESSAGES !== "false",
|
|
28387
|
-
saveToolUse: process.env.HONCHO_SAVE_TOOL_USE === "true",
|
|
28388
|
-
saveGitEvents: process.env.HONCHO_SAVE_GIT_EVENTS === "true",
|
|
28389
|
-
enabled: process.env.HONCHO_ENABLED !== "false",
|
|
28390
|
-
logging: process.env.HONCHO_LOGGING !== "false"
|
|
28391
|
-
};
|
|
28392
|
-
if (endpoint) {
|
|
28393
|
-
if (endpoint === "local") {
|
|
28394
|
-
config.endpoint = { environment: "local" };
|
|
28395
|
-
} else if (endpoint.startsWith("http")) {
|
|
28396
|
-
config.endpoint = { baseUrl: endpoint };
|
|
28397
|
-
}
|
|
28398
|
-
}
|
|
28399
|
-
return config;
|
|
28400
|
-
}
|
|
28401
|
-
function mergeWithEnvVars(config) {
|
|
28402
|
-
if (process.env.HONCHO_API_KEY) {
|
|
28403
|
-
config.apiKey = process.env.HONCHO_API_KEY;
|
|
28404
|
-
}
|
|
28405
|
-
if (process.env.HONCHO_PEER_NAME) {
|
|
28406
|
-
config.peerName = process.env.HONCHO_PEER_NAME;
|
|
28407
|
-
}
|
|
28408
|
-
if (process.env.HONCHO_ENABLED === "false") {
|
|
28409
|
-
config.enabled = false;
|
|
28410
|
-
}
|
|
28411
|
-
if (process.env.HONCHO_LOGGING === "false") {
|
|
28412
|
-
config.logging = false;
|
|
28413
|
-
}
|
|
28414
|
-
if (process.env.HONCHO_SAVE_MESSAGES === "false") {
|
|
28415
|
-
config.saveMessages = false;
|
|
28416
|
-
}
|
|
28417
|
-
if (process.env.HONCHO_SAVE_TOOL_USE !== undefined) {
|
|
28418
|
-
config.saveToolUse = process.env.HONCHO_SAVE_TOOL_USE === "true";
|
|
28419
|
-
}
|
|
28420
|
-
if (process.env.HONCHO_SAVE_GIT_EVENTS !== undefined) {
|
|
28421
|
-
config.saveGitEvents = process.env.HONCHO_SAVE_GIT_EVENTS === "true";
|
|
28422
|
-
}
|
|
28423
|
-
return config;
|
|
28424
|
-
}
|
|
28425
|
-
function writeConfigFile(data) {
|
|
28426
|
-
if (existsSync3(CONFIG_FILE))
|
|
28427
|
-
chmodSync(CONFIG_FILE, 384);
|
|
28428
|
-
writeFileSync2(CONFIG_FILE, JSON.stringify(data, null, 2), { mode: 384 });
|
|
28429
|
-
}
|
|
28430
|
-
function saveConfig(config) {
|
|
28431
|
-
if (!existsSync3(CONFIG_DIR)) {
|
|
28432
|
-
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
28433
|
-
}
|
|
28434
|
-
let existing = {};
|
|
28435
|
-
if (existsSync3(CONFIG_FILE)) {
|
|
28436
|
-
try {
|
|
28437
|
-
existing = JSON.parse(readFileSync2(CONFIG_FILE, "utf-8"));
|
|
28438
|
-
} catch {}
|
|
28439
|
-
}
|
|
28440
|
-
if (config.sessions !== undefined) {
|
|
28441
|
-
existing.sessions = config.sessions;
|
|
28442
|
-
}
|
|
28443
|
-
const host = getDetectedHost();
|
|
28444
|
-
if (!existing.hosts)
|
|
28445
|
-
existing.hosts = {};
|
|
28446
|
-
const existingHost = existing.hosts[host] ?? {};
|
|
28447
|
-
const hostEntry = {};
|
|
28448
|
-
const setHostIfExplicit = (key, value, rootValue) => {
|
|
28449
|
-
if (value === undefined)
|
|
28450
|
-
return;
|
|
28451
|
-
const hasHostOverride = Object.prototype.hasOwnProperty.call(existingHost, key);
|
|
28452
|
-
if (hasHostOverride || !deepEqual(value, rootValue)) {
|
|
28453
|
-
hostEntry[key] = value;
|
|
28454
|
-
}
|
|
28455
|
-
};
|
|
28456
|
-
setHostIfExplicit("workspace", config.workspace, existing.workspace ?? DEFAULT_WORKSPACE[host]);
|
|
28457
|
-
setHostIfExplicit("aiPeer", config.aiPeer, existing.aiPeer ?? DEFAULT_AI_PEER[host]);
|
|
28458
|
-
const enabledForSave = process.env.HONCHO_ENABLED === "false" && config.enabled === false ? existingHost.enabled : config.enabled;
|
|
28459
|
-
const loggingForSave = process.env.HONCHO_LOGGING === "false" && config.logging === false ? existingHost.logging : config.logging;
|
|
28460
|
-
const saveMessagesForSave = process.env.HONCHO_SAVE_MESSAGES === "false" && config.saveMessages === false ? existingHost.saveMessages : config.saveMessages;
|
|
28461
|
-
setHostIfExplicit("enabled", enabledForSave, existing.enabled);
|
|
28462
|
-
setHostIfExplicit("logging", loggingForSave, existing.logging);
|
|
28463
|
-
setHostIfExplicit("saveMessages", saveMessagesForSave, existing.saveMessages);
|
|
28464
|
-
setHostIfExplicit("sessionStrategy", config.sessionStrategy, existing.sessionStrategy);
|
|
28465
|
-
setHostIfExplicit("sessionPeerPrefix", config.sessionPeerPrefix, existing.sessionPeerPrefix);
|
|
28466
|
-
setHostIfExplicit("reasoningLevel", config.reasoningLevel, existing.reasoningLevel);
|
|
28467
|
-
setHostIfExplicit("observationMode", config.observationMode, existing.observationMode);
|
|
28468
|
-
setHostIfExplicit("messageUpload", config.messageUpload, existing.messageUpload);
|
|
28469
|
-
setHostIfExplicit("contextRefresh", config.contextRefresh, existing.contextRefresh);
|
|
28470
|
-
setHostIfExplicit("redactPatterns", config.redactPatterns, existing.redactPatterns);
|
|
28471
|
-
setHostIfExplicit("endpoint", config.endpoint, existing.endpoint);
|
|
28472
|
-
setHostIfExplicit("injection", config.injection, existing.injection);
|
|
28473
|
-
setHostIfExplicit("rememberTool", config.rememberTool, existing.rememberTool);
|
|
28474
|
-
if (existingHost.apiKey !== undefined) {
|
|
28475
|
-
hostEntry.apiKey = existingHost.apiKey;
|
|
28476
|
-
}
|
|
28477
|
-
existing.hosts[host] = hostEntry;
|
|
28478
|
-
writeConfigFile(existing);
|
|
28479
|
-
}
|
|
28480
|
-
function saveRootField(field, value) {
|
|
28481
|
-
if (!existsSync3(CONFIG_DIR)) {
|
|
28482
|
-
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
28483
|
-
}
|
|
28484
|
-
let existing = {};
|
|
28485
|
-
if (existsSync3(CONFIG_FILE)) {
|
|
28486
|
-
try {
|
|
28487
|
-
existing = JSON.parse(readFileSync2(CONFIG_FILE, "utf-8"));
|
|
28488
|
-
} catch {}
|
|
28489
|
-
}
|
|
28490
|
-
existing[field] = value;
|
|
28491
|
-
writeConfigFile(existing);
|
|
28492
|
-
}
|
|
28493
|
-
function resolveWorktreeMainRoot(dir) {
|
|
28494
|
-
try {
|
|
28495
|
-
const gitPath = join3(dir, ".git");
|
|
28496
|
-
if (!statSync(gitPath).isFile())
|
|
28497
|
-
return null;
|
|
28498
|
-
const match = readFileSync2(gitPath, "utf-8").match(/^gitdir:\s*(.+?)\s*$/m);
|
|
28499
|
-
if (!match)
|
|
28500
|
-
return null;
|
|
28501
|
-
const gitdir = resolve(dir, match[1]);
|
|
28502
|
-
const idx = gitdir.lastIndexOf(`${sep}worktrees${sep}`);
|
|
28503
|
-
if (idx === -1)
|
|
28504
|
-
return null;
|
|
28505
|
-
const gitContainer = gitdir.slice(0, idx);
|
|
28506
|
-
if (basename(gitContainer) === ".git")
|
|
28507
|
-
return dirname(gitContainer);
|
|
28508
|
-
if (gitContainer.endsWith(".git"))
|
|
28509
|
-
return gitContainer;
|
|
28510
|
-
return null;
|
|
28511
|
-
} catch {
|
|
28512
|
-
return null;
|
|
29063
|
+
];
|
|
29064
|
+
for (const manifest of candidates) {
|
|
29065
|
+
try {
|
|
29066
|
+
const version = JSON.parse(readFileSync3(manifest, "utf-8")).version;
|
|
29067
|
+
if (typeof version === "string" && version)
|
|
29068
|
+
return version;
|
|
29069
|
+
} catch {}
|
|
28513
29070
|
}
|
|
29071
|
+
return "unknown";
|
|
28514
29072
|
}
|
|
28515
|
-
|
|
28516
|
-
|
|
28517
|
-
|
|
28518
|
-
|
|
28519
|
-
|
|
28520
|
-
|
|
28521
|
-
return resolveWorktreeMainRoot(dir);
|
|
28522
|
-
const parent = dirname(dir);
|
|
28523
|
-
if (parent === dir)
|
|
28524
|
-
break;
|
|
28525
|
-
dir = parent;
|
|
28526
|
-
}
|
|
28527
|
-
} catch {}
|
|
28528
|
-
return null;
|
|
29073
|
+
function legacyEndpoint(value) {
|
|
29074
|
+
if (value === "local")
|
|
29075
|
+
return "http://localhost:8000";
|
|
29076
|
+
if (value?.startsWith("http"))
|
|
29077
|
+
return value.replace(/\/v3\/?$/, "");
|
|
29078
|
+
return;
|
|
28529
29079
|
}
|
|
28530
|
-
function
|
|
28531
|
-
const
|
|
28532
|
-
|
|
28533
|
-
|
|
28534
|
-
|
|
28535
|
-
|
|
28536
|
-
|
|
28537
|
-
|
|
28538
|
-
|
|
28539
|
-
|
|
29080
|
+
function legacyEnv(host = getDetectedHost()) {
|
|
29081
|
+
const env = process.env;
|
|
29082
|
+
const peerVar = host === "cursor" ? "HONCHO_CURSOR_PEER" : "HONCHO_CLAUDE_PEER";
|
|
29083
|
+
const candidates = [
|
|
29084
|
+
["HONCHO_BASE_URL", "baseUrl", "HONCHO_ENDPOINT", legacyEndpoint(env.HONCHO_ENDPOINT)],
|
|
29085
|
+
["HONCHO_AI_PEER", "aiPeer", peerVar, env[peerVar] || undefined]
|
|
29086
|
+
];
|
|
29087
|
+
const set = candidates.filter(([newVar, , , value]) => value && !env[newVar]);
|
|
29088
|
+
if (!set.length)
|
|
29089
|
+
return {};
|
|
29090
|
+
const block = effectiveBlock(readConfigFile(), host, LEGACY);
|
|
29091
|
+
if (block.apiKey || block.oauth)
|
|
29092
|
+
return {};
|
|
29093
|
+
return Object.fromEntries(set.filter(([, setting]) => !block[setting]).map(([newVar, , oldVar, value]) => [newVar, [oldVar, value]]));
|
|
28540
29094
|
}
|
|
28541
|
-
function
|
|
28542
|
-
const
|
|
28543
|
-
|
|
28544
|
-
|
|
28545
|
-
|
|
28546
|
-
switch (strategy) {
|
|
28547
|
-
case "git-branch": {
|
|
28548
|
-
if (opts.branch) {
|
|
28549
|
-
const branchPart = sanitizeForSessionName(opts.branch);
|
|
28550
|
-
return `${base}-${branchPart}`;
|
|
28551
|
-
}
|
|
28552
|
-
return base;
|
|
28553
|
-
}
|
|
28554
|
-
case "chat-instance": {
|
|
28555
|
-
if (opts.instanceId) {
|
|
28556
|
-
return usePrefix ? `${peerPart}-chat-${opts.instanceId}` : `chat-${opts.instanceId}`;
|
|
28557
|
-
}
|
|
28558
|
-
return base;
|
|
28559
|
-
}
|
|
28560
|
-
case "per-directory":
|
|
28561
|
-
default:
|
|
28562
|
-
return base;
|
|
28563
|
-
}
|
|
29095
|
+
function honchoEnv(host) {
|
|
29096
|
+
const legacy = Object.entries(legacyEnv(host));
|
|
29097
|
+
if (!legacy.length)
|
|
29098
|
+
return process.env;
|
|
29099
|
+
return { ...process.env, ...Object.fromEntries(legacy.map(([k, [, value]]) => [k, value])) };
|
|
28564
29100
|
}
|
|
28565
|
-
function
|
|
28566
|
-
|
|
28567
|
-
|
|
28568
|
-
|
|
28569
|
-
|
|
28570
|
-
|
|
28571
|
-
if (configuredSession) {
|
|
28572
|
-
return configuredSession;
|
|
28573
|
-
}
|
|
28574
|
-
}
|
|
28575
|
-
let branch;
|
|
28576
|
-
if (strategy === "git-branch") {
|
|
28577
|
-
branch = captureGitState(cwd)?.branch;
|
|
28578
|
-
}
|
|
28579
|
-
let resolvedInstanceId;
|
|
28580
|
-
if (strategy === "chat-instance") {
|
|
28581
|
-
resolvedInstanceId = instanceId || getInstanceIdForCwd(cwd) || getClaudeInstanceId() || undefined;
|
|
28582
|
-
}
|
|
28583
|
-
return deriveSessionName(strategy, mainRoot ?? cwd, {
|
|
28584
|
-
peerName: config?.peerName,
|
|
28585
|
-
sessionPeerPrefix: config?.sessionPeerPrefix,
|
|
28586
|
-
branch,
|
|
28587
|
-
instanceId: resolvedInstanceId
|
|
29101
|
+
function resolveHost(host) {
|
|
29102
|
+
return resolveConfig(readConfigFile(), {
|
|
29103
|
+
host,
|
|
29104
|
+
env: honchoEnv(host),
|
|
29105
|
+
defaults: { workspace: DEFAULT_WORKSPACE[host], aiPeer: DEFAULT_AI_PEER[host] },
|
|
29106
|
+
legacy: LEGACY
|
|
28588
29107
|
});
|
|
28589
29108
|
}
|
|
28590
|
-
function
|
|
28591
|
-
|
|
28592
|
-
|
|
28593
|
-
|
|
28594
|
-
|
|
28595
|
-
|
|
28596
|
-
|
|
28597
|
-
|
|
28598
|
-
|
|
29109
|
+
function isLoggingEnabled(host = getDetectedHost()) {
|
|
29110
|
+
if (process.env.HONCHO_LOGGING === "false")
|
|
29111
|
+
return false;
|
|
29112
|
+
const file = readConfigFile();
|
|
29113
|
+
const hosts = file.hosts && typeof file.hosts === "object" ? file.hosts : {};
|
|
29114
|
+
const own = [hosts[host], hosts[host.replace(/_/g, "-")]].map((block) => block && typeof block === "object" ? block.logging : undefined).find((v) => v !== undefined);
|
|
29115
|
+
return (own ?? file.logging) !== false;
|
|
29116
|
+
}
|
|
29117
|
+
function loadConfig2(host = getDetectedHost()) {
|
|
29118
|
+
const cfg = resolveHost(host);
|
|
29119
|
+
const cred = pickCredential(readConfigFile(), { host, baseUrl: cfg.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
29120
|
+
if (!cred)
|
|
29121
|
+
return null;
|
|
29122
|
+
const { token, ...authState } = cred;
|
|
29123
|
+
return {
|
|
29124
|
+
apiKey: token,
|
|
29125
|
+
auth: { ...authState, host },
|
|
29126
|
+
peerName: cfg.peerName,
|
|
29127
|
+
workspace: cfg.workspace,
|
|
29128
|
+
aiPeer: cfg.aiPeer,
|
|
29129
|
+
baseUrl: cfg.baseUrl
|
|
29130
|
+
};
|
|
28599
29131
|
}
|
|
28600
|
-
function
|
|
28601
|
-
const
|
|
28602
|
-
const
|
|
28603
|
-
|
|
28604
|
-
|
|
28605
|
-
|
|
29132
|
+
async function saveConfig(config, field) {
|
|
29133
|
+
const host = getDetectedHost();
|
|
29134
|
+
const env = honchoEnv(host);
|
|
29135
|
+
const write = (key, envVar) => key === field || !env[envVar];
|
|
29136
|
+
const patch = {};
|
|
29137
|
+
if (write("peerName", "HONCHO_PEER_NAME"))
|
|
29138
|
+
patch.peerName = config.peerName;
|
|
29139
|
+
if (write("workspace", "HONCHO_WORKSPACE"))
|
|
29140
|
+
patch.workspace = config.workspace === DEFAULT_WORKSPACE[host] ? undefined : config.workspace;
|
|
29141
|
+
if (write("aiPeer", "HONCHO_AI_PEER"))
|
|
29142
|
+
patch.aiPeer = config.aiPeer === DEFAULT_AI_PEER[host] ? undefined : config.aiPeer;
|
|
29143
|
+
if (write("baseUrl", "HONCHO_BASE_URL"))
|
|
29144
|
+
patch.baseUrl = config.baseUrl === DEFAULT_BASE_URL ? undefined : config.baseUrl;
|
|
29145
|
+
await saveHost(configPath(), host, patch, LEGACY);
|
|
28606
29146
|
}
|
|
28607
|
-
function
|
|
28608
|
-
|
|
28609
|
-
return config?.logging !== false;
|
|
29147
|
+
function getConfigIssues(host = getDetectedHost()) {
|
|
29148
|
+
return checkConfig(readConfigFile()).filter((i) => i.path === "schemaVersion" || i.path === "hosts" && i.message.includes(host)).map((i) => i.message);
|
|
28610
29149
|
}
|
|
28611
|
-
|
|
28612
|
-
|
|
28613
|
-
|
|
29150
|
+
var DEAD_HOST_KEYS = [
|
|
29151
|
+
"sessionStrategy",
|
|
29152
|
+
"sessionPeerPrefix",
|
|
29153
|
+
"sessions",
|
|
29154
|
+
"injection",
|
|
29155
|
+
"contextRefresh",
|
|
29156
|
+
"messageUpload",
|
|
29157
|
+
"reasoningLevel",
|
|
29158
|
+
"statusline",
|
|
29159
|
+
"saveToolUse",
|
|
29160
|
+
"saveGitEvents",
|
|
29161
|
+
"redactPatterns",
|
|
29162
|
+
"rememberTool",
|
|
29163
|
+
"observationMode",
|
|
29164
|
+
"saveMessages",
|
|
29165
|
+
"enabled",
|
|
29166
|
+
"globalOverride",
|
|
29167
|
+
"linkedHosts"
|
|
29168
|
+
];
|
|
29169
|
+
async function migrateConfig(host = getDetectedHost()) {
|
|
29170
|
+
try {
|
|
29171
|
+
const changed = await migrateHost(configPath(), host, DEAD_HOST_KEYS, LEGACY);
|
|
29172
|
+
if (changed.length)
|
|
29173
|
+
return `[honcho] Moved your Honcho settings into hosts.${host} in ~/.honcho/config.json.`;
|
|
29174
|
+
} catch {}
|
|
29175
|
+
return;
|
|
29176
|
+
}
|
|
29177
|
+
function getSessionName(sessionId) {
|
|
29178
|
+
const id = sessionId || process.env.CLAUDE_CODE_SESSION_ID;
|
|
29179
|
+
return id ? sanitizeForSessionName(id) : null;
|
|
28614
29180
|
}
|
|
28615
29181
|
function getKnownHosts() {
|
|
28616
|
-
const
|
|
28617
|
-
|
|
28618
|
-
return [];
|
|
28619
|
-
try {
|
|
28620
|
-
const raw = JSON.parse(readFileSync2(cfgPath, "utf-8"));
|
|
28621
|
-
return raw.hosts ? Object.keys(raw.hosts) : [];
|
|
28622
|
-
} catch {
|
|
28623
|
-
return [];
|
|
28624
|
-
}
|
|
29182
|
+
const hosts = readConfigFile().hosts;
|
|
29183
|
+
return hosts && typeof hosts === "object" ? Object.keys(hosts) : [];
|
|
28625
29184
|
}
|
|
28626
|
-
function
|
|
28627
|
-
|
|
28628
|
-
|
|
28629
|
-
|
|
28630
|
-
|
|
28631
|
-
|
|
28632
|
-
|
|
29185
|
+
async function refreshCredential(config) {
|
|
29186
|
+
const host = config.auth?.host ?? getDetectedHost();
|
|
29187
|
+
const cred = await ensureFreshCredential({ path: configPath(), host, baseUrl: config.baseUrl, env: honchoEnv(host), legacy: LEGACY });
|
|
29188
|
+
if (!cred)
|
|
29189
|
+
return;
|
|
29190
|
+
const { token, ...authState } = cred;
|
|
29191
|
+
config.apiKey = token;
|
|
29192
|
+
config.auth = { ...authState, host };
|
|
29193
|
+
}
|
|
29194
|
+
function getAuthNotice(config) {
|
|
29195
|
+
if (config.auth?.reauthRequired) {
|
|
29196
|
+
return "[honcho] Your Honcho sign-in has expired. Run /honcho setup to sign in again.";
|
|
28633
29197
|
}
|
|
28634
|
-
return
|
|
29198
|
+
return;
|
|
28635
29199
|
}
|
|
28636
29200
|
function getHonchoBaseUrl(config) {
|
|
28637
|
-
return
|
|
29201
|
+
return `${config.baseUrl}/v3`;
|
|
28638
29202
|
}
|
|
28639
29203
|
function getTelemetryHeaders(host = getDetectedHost()) {
|
|
28640
29204
|
return telemetryHeaders({
|
|
@@ -28654,66 +29218,20 @@ function getHonchoClientOptions(config) {
|
|
|
28654
29218
|
};
|
|
28655
29219
|
}
|
|
28656
29220
|
function isProductionEndpoint(config) {
|
|
28657
|
-
return
|
|
29221
|
+
return config.baseUrl === DEFAULT_BASE_URL;
|
|
28658
29222
|
}
|
|
28659
29223
|
function getEndpointInfo(config) {
|
|
28660
|
-
|
|
28661
|
-
return { type: "custom", url: config.endpoint.baseUrl };
|
|
28662
|
-
}
|
|
28663
|
-
if (config.endpoint?.environment === "local") {
|
|
28664
|
-
return { type: "local", url: HONCHO_BASE_URLS.local };
|
|
28665
|
-
}
|
|
28666
|
-
return { type: "production", url: HONCHO_BASE_URLS.production };
|
|
28667
|
-
}
|
|
28668
|
-
var VALID_ENVIRONMENTS = new Set(["production", "local"]);
|
|
28669
|
-
function getObservationMode(config) {
|
|
28670
|
-
return config.observationMode ?? "unified";
|
|
29224
|
+
return { type: isProductionEndpoint(config) ? "production" : "custom", url: config.baseUrl };
|
|
28671
29225
|
}
|
|
28672
29226
|
|
|
28673
|
-
// src/
|
|
28674
|
-
var
|
|
28675
|
-
|
|
28676
|
-
|
|
28677
|
-
|
|
28678
|
-
},
|
|
28679
|
-
{
|
|
28680
|
-
pattern: /(--(?:password|passwd|pwd|token|api-?key|secret|auth)[= ])(?:"[^"]*"|'[^']*'|[^\s;|&"']+)/gi,
|
|
28681
|
-
replacement: "$1***"
|
|
28682
|
-
},
|
|
28683
|
-
{
|
|
28684
|
-
pattern: /(authorization:\s*(?:bearer|basic|token)\s+)[^\s"']+/gi,
|
|
28685
|
-
replacement: "$1***"
|
|
28686
|
-
},
|
|
28687
|
-
{
|
|
28688
|
-
pattern: /([a-z][a-z0-9+.-]*:\/\/[^/\s:@]+:)[^@\s]+@/gi,
|
|
28689
|
-
replacement: "$1***@"
|
|
28690
|
-
},
|
|
28691
|
-
{
|
|
28692
|
-
pattern: /\b(?:hch[_-]?[A-Za-z0-9_-]{16,}|AKIA[0-9A-Z]{16}|sk-[A-Za-z0-9_-]{16,}|(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|glpat-[A-Za-z0-9_-]{20,}|npm_[A-Za-z0-9]{36})\b/g,
|
|
28693
|
-
replacement: "***"
|
|
28694
|
-
}
|
|
28695
|
-
];
|
|
28696
|
-
function validateRedactPattern(source) {
|
|
28697
|
-
try {
|
|
28698
|
-
new RegExp(source);
|
|
28699
|
-
return null;
|
|
28700
|
-
} catch (e) {
|
|
28701
|
-
return `Invalid regex ${JSON.stringify(source)}: ${e instanceof Error ? e.message : String(e)}`;
|
|
28702
|
-
}
|
|
29227
|
+
// src/honcho-client.ts
|
|
29228
|
+
var import_sdk = __toESM(require_dist2(), 1);
|
|
29229
|
+
async function createHonchoClient(config, overrides = {}) {
|
|
29230
|
+
await refreshCredential(config);
|
|
29231
|
+
return new import_sdk.Honcho({ ...getHonchoClientOptions(config), ...overrides });
|
|
28703
29232
|
}
|
|
28704
|
-
function
|
|
28705
|
-
|
|
28706
|
-
for (const rule of DEFAULT_RULES) {
|
|
28707
|
-
result = result.replace(rule.pattern, rule.replacement);
|
|
28708
|
-
}
|
|
28709
|
-
for (const source of extraPatterns ?? []) {
|
|
28710
|
-
try {
|
|
28711
|
-
result = result.replace(new RegExp(source, "gi"), "***");
|
|
28712
|
-
} catch {
|
|
28713
|
-
continue;
|
|
28714
|
-
}
|
|
28715
|
-
}
|
|
28716
|
-
return result;
|
|
29233
|
+
function setClientApiKey(honcho, token) {
|
|
29234
|
+
honcho.http.apiKey = token;
|
|
28717
29235
|
}
|
|
28718
29236
|
|
|
28719
29237
|
// src/styles.ts
|
|
@@ -28739,23 +29257,14 @@ var ENV_SHADOW_MAP = {
|
|
|
28739
29257
|
peerName: "HONCHO_PEER_NAME",
|
|
28740
29258
|
workspace: "HONCHO_WORKSPACE",
|
|
28741
29259
|
aiPeer: "HONCHO_AI_PEER",
|
|
28742
|
-
|
|
28743
|
-
logging: "HONCHO_LOGGING",
|
|
28744
|
-
saveMessages: "HONCHO_SAVE_MESSAGES",
|
|
28745
|
-
"endpoint.baseUrl": "HONCHO_ENDPOINT",
|
|
28746
|
-
"endpoint.environment": "HONCHO_ENDPOINT"
|
|
29260
|
+
baseUrl: "HONCHO_BASE_URL"
|
|
28747
29261
|
};
|
|
28748
|
-
var DANGEROUS_FIELDS = new Set(["workspace", "
|
|
29262
|
+
var DANGEROUS_FIELDS = new Set(["workspace", "baseUrl"]);
|
|
28749
29263
|
var SESSION_AFFECTING_FIELDS = new Set([
|
|
28750
29264
|
"workspace",
|
|
28751
29265
|
"aiPeer",
|
|
28752
29266
|
"peerName",
|
|
28753
|
-
"
|
|
28754
|
-
"sessionPeerPrefix",
|
|
28755
|
-
"endpoint.environment",
|
|
28756
|
-
"endpoint.baseUrl",
|
|
28757
|
-
"globalOverride",
|
|
28758
|
-
"observationMode"
|
|
29267
|
+
"baseUrl"
|
|
28759
29268
|
]);
|
|
28760
29269
|
function renderCard(rows, title) {
|
|
28761
29270
|
const labelWidth = 12;
|
|
@@ -28772,7 +29281,7 @@ function renderCard(rows, title) {
|
|
|
28772
29281
|
return [top, blank, ...body, blank, bot].join(`
|
|
28773
29282
|
`);
|
|
28774
29283
|
}
|
|
28775
|
-
function handleGetConfig(
|
|
29284
|
+
function handleGetConfig() {
|
|
28776
29285
|
const cfg = loadConfig2();
|
|
28777
29286
|
const host = getDetectedHost();
|
|
28778
29287
|
const cfgPath = getConfigPath();
|
|
@@ -28780,32 +29289,16 @@ function handleGetConfig(cwd) {
|
|
|
28780
29289
|
let rawFile = {};
|
|
28781
29290
|
if (cfgExists) {
|
|
28782
29291
|
try {
|
|
28783
|
-
rawFile = JSON.parse(
|
|
29292
|
+
rawFile = JSON.parse(readFileSync4(cfgPath, "utf-8"));
|
|
28784
29293
|
} catch {}
|
|
28785
29294
|
}
|
|
28786
|
-
const globalOverride = rawFile.globalOverride === true;
|
|
28787
29295
|
const resolved = cfg ? {
|
|
28788
29296
|
peerName: cfg.peerName,
|
|
28789
29297
|
aiPeer: cfg.aiPeer,
|
|
28790
29298
|
workspace: cfg.workspace,
|
|
28791
|
-
endpoint: getEndpointInfo(cfg)
|
|
28792
|
-
globalOverride,
|
|
28793
|
-
sessionStrategy: cfg.sessionStrategy ?? "per-directory",
|
|
28794
|
-
sessionPeerPrefix: cfg.sessionPeerPrefix !== false,
|
|
28795
|
-
sessions: cfg.sessions ?? {},
|
|
28796
|
-
messageUpload: cfg.messageUpload ?? {},
|
|
28797
|
-
contextRefresh: cfg.contextRefresh ?? {},
|
|
28798
|
-
reasoningLevel: cfg.reasoningLevel ?? "medium",
|
|
28799
|
-
observationMode: cfg.observationMode ?? "unified",
|
|
28800
|
-
statusline: cfg.statusline ?? "on",
|
|
28801
|
-
redactPatterns: cfg.redactPatterns ?? [],
|
|
28802
|
-
injection: cfg.injection ?? {},
|
|
28803
|
-
rememberTool: cfg.rememberTool === true,
|
|
28804
|
-
enabled: cfg.enabled !== false,
|
|
28805
|
-
logging: cfg.logging !== false,
|
|
28806
|
-
saveMessages: cfg.saveMessages !== false
|
|
29299
|
+
endpoint: getEndpointInfo(cfg)
|
|
28807
29300
|
} : null;
|
|
28808
|
-
const sessionName = cfg ? getSessionName(
|
|
29301
|
+
const sessionName = cfg ? getSessionName() : null;
|
|
28809
29302
|
const endpointInfo = cfg ? getEndpointInfo(cfg) : null;
|
|
28810
29303
|
const endpointLabel = endpointInfo ? endpointInfo.type === "production" ? "platform" : endpointInfo.type : null;
|
|
28811
29304
|
const sessionUrl = cfg && sessionName ? honchoSessionUrl(cfg, sessionName) : null;
|
|
@@ -28831,47 +29324,32 @@ function handleGetConfig(cwd) {
|
|
|
28831
29324
|
otherHosts
|
|
28832
29325
|
};
|
|
28833
29326
|
const warnings = [];
|
|
28834
|
-
const hasHostsBlock = !!rawFile.hosts?.[host];
|
|
28835
|
-
const hostSpecificFields = new Set(["workspace", "aiPeer"]);
|
|
28836
29327
|
for (const [field, envVar] of Object.entries(ENV_SHADOW_MAP)) {
|
|
28837
29328
|
const envVal = process.env[envVar];
|
|
28838
|
-
if (
|
|
28839
|
-
continue;
|
|
28840
|
-
if (hasHostsBlock && hostSpecificFields.has(field)) {
|
|
28841
|
-
warnings.push(`env var ${envVar}="${envVal}" is set but ignored (hosts block takes precedence). Remove it from your shell config.`);
|
|
28842
|
-
} else {
|
|
29329
|
+
if (envVal)
|
|
28843
29330
|
warnings.push(`${field} is shadowed by env var ${envVar}="${envVal}"`);
|
|
28844
|
-
|
|
29331
|
+
}
|
|
29332
|
+
for (const [envVar, [oldVar, value]] of Object.entries(legacyEnv(host))) {
|
|
29333
|
+
const field = Object.keys(ENV_SHADOW_MAP).find((f) => ENV_SHADOW_MAP[f] === envVar);
|
|
29334
|
+
warnings.push(`${field} comes from the older env var ${oldVar}="${value}"; setting ${field} with set_config replaces it.`);
|
|
28845
29335
|
}
|
|
28846
29336
|
const envApiKey = process.env.HONCHO_API_KEY;
|
|
28847
|
-
|
|
29337
|
+
const fileApiKey = rawFile.hosts?.[host]?.apiKey;
|
|
29338
|
+
if (envApiKey && fileApiKey) {
|
|
28848
29339
|
const mask = (k) => `${k.slice(0, 10)}…${k.slice(-4)}`;
|
|
28849
|
-
if (envApiKey !==
|
|
28850
|
-
warnings.push(`HONCHO_API_KEY env var (${mask(envApiKey)}) overrides config.json apiKey (${mask(
|
|
29340
|
+
if (envApiKey !== fileApiKey) {
|
|
29341
|
+
warnings.push(`HONCHO_API_KEY env var (${mask(envApiKey)}) overrides config.json apiKey (${mask(fileApiKey)}) and is the key actually in use. ` + `An API key selects the Honcho environment, so reads/writes go to the env var's environment, NOT the one config.json names. ` + `Unset HONCHO_API_KEY in your shell to use config.json's key.`);
|
|
28851
29342
|
} else {
|
|
28852
29343
|
warnings.push(`apiKey is also set via HONCHO_API_KEY env var (identical value). The env var takes precedence at runtime.`);
|
|
28853
29344
|
}
|
|
28854
29345
|
}
|
|
28855
|
-
|
|
28856
|
-
|
|
28857
|
-
}
|
|
28858
|
-
if (cfgExists && rawFile.hosts && rawFile.workspace && rawFile.globalOverride === undefined) {
|
|
28859
|
-
warnings.push("Config has flat 'workspace' alongside hosts block but no 'globalOverride' set. The flat field is unused. Set globalOverride=true to apply it globally, or remove it.");
|
|
28860
|
-
}
|
|
28861
|
-
const strategyLabels = {
|
|
28862
|
-
"per-directory": "per directory",
|
|
28863
|
-
"git-branch": "per git branch",
|
|
28864
|
-
"chat-instance": "per chat"
|
|
28865
|
-
};
|
|
28866
|
-
const hostLabel = endpointInfo ? endpointInfo.type === "production" ? `platform (app.honcho.dev)` : endpointInfo.type === "local" ? `local (${endpointInfo.url})` : endpointInfo.url : "unknown";
|
|
29346
|
+
warnings.push(...getConfigIssues(host));
|
|
29347
|
+
const hostLabel = endpointInfo ? endpointInfo.type === "production" ? `platform (app.honcho.dev)` : endpointInfo.url : "unknown";
|
|
28867
29348
|
const card = cfg ? renderCard([
|
|
28868
29349
|
["workspace", cfg.workspace],
|
|
28869
29350
|
["session", sessionName ?? "unknown"],
|
|
28870
|
-
["mapping", strategyLabels[cfg.sessionStrategy ?? "per-directory"] ?? cfg.sessionStrategy ?? "per directory"],
|
|
28871
29351
|
["peer", `${cfg.peerName} / ${cfg.aiPeer}`],
|
|
28872
|
-
["host", hostLabel]
|
|
28873
|
-
["messages", cfg.saveMessages !== false ? "saving enabled" : "saving disabled"],
|
|
28874
|
-
["obs mode", cfg.observationMode ?? "unified"]
|
|
29352
|
+
["host", hostLabel]
|
|
28875
29353
|
], "current honcho config") : null;
|
|
28876
29354
|
return {
|
|
28877
29355
|
content: [{
|
|
@@ -28880,32 +29358,7 @@ function handleGetConfig(cwd) {
|
|
|
28880
29358
|
}]
|
|
28881
29359
|
};
|
|
28882
29360
|
}
|
|
28883
|
-
function
|
|
28884
|
-
let v = value;
|
|
28885
|
-
if (typeof v === "string") {
|
|
28886
|
-
try {
|
|
28887
|
-
v = JSON.parse(v);
|
|
28888
|
-
} catch {
|
|
28889
|
-
return null;
|
|
28890
|
-
}
|
|
28891
|
-
}
|
|
28892
|
-
return Array.isArray(v) ? v.map(String) : null;
|
|
28893
|
-
}
|
|
28894
|
-
function validateComponentArray(value, allowed, field) {
|
|
28895
|
-
const example = JSON.stringify(allowed.slice(0, 2));
|
|
28896
|
-
const err = (msg) => ({
|
|
28897
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: msg }, null, 2) }],
|
|
28898
|
-
isError: true
|
|
28899
|
-
});
|
|
28900
|
-
const arr = coerceStringArray(value);
|
|
28901
|
-
if (!arr)
|
|
28902
|
-
return err(`${field} must be an array of component names, e.g. ${example}`);
|
|
28903
|
-
const bad = arr.filter((v) => !allowed.includes(v));
|
|
28904
|
-
if (bad.length)
|
|
28905
|
-
return err(`${field} entries must be one of: ${allowed.join(", ")} (got: ${bad.join(", ")})`);
|
|
28906
|
-
return arr;
|
|
28907
|
-
}
|
|
28908
|
-
function handleSetConfig(args) {
|
|
29361
|
+
async function handleSetConfig(args) {
|
|
28909
29362
|
const field = args.field;
|
|
28910
29363
|
if (typeof field !== "string" || !field) {
|
|
28911
29364
|
return {
|
|
@@ -28918,8 +29371,7 @@ function handleSetConfig(args) {
|
|
|
28918
29371
|
if (DANGEROUS_FIELDS.has(field) && !confirm) {
|
|
28919
29372
|
const descriptions = {
|
|
28920
29373
|
workspace: "Switches to a different workspace.",
|
|
28921
|
-
|
|
28922
|
-
"endpoint.baseUrl": "Switches the Honcho backend URL."
|
|
29374
|
+
baseUrl: "Switches the Honcho backend URL."
|
|
28923
29375
|
};
|
|
28924
29376
|
return {
|
|
28925
29377
|
content: [{
|
|
@@ -28944,7 +29396,6 @@ function handleSetConfig(args) {
|
|
|
28944
29396
|
};
|
|
28945
29397
|
}
|
|
28946
29398
|
let previousValue;
|
|
28947
|
-
let cacheInvalidation = null;
|
|
28948
29399
|
const warnings = [];
|
|
28949
29400
|
const shadowEnv = ENV_SHADOW_MAP[field];
|
|
28950
29401
|
if (shadowEnv && process.env[shadowEnv]) {
|
|
@@ -28954,301 +29405,19 @@ function handleSetConfig(args) {
|
|
|
28954
29405
|
case "peerName":
|
|
28955
29406
|
previousValue = cfg.peerName;
|
|
28956
29407
|
cfg.peerName = String(value);
|
|
28957
|
-
saveRootField("peerName", cfg.peerName);
|
|
28958
|
-
clearPeerCache();
|
|
28959
|
-
clearUserContextOnly();
|
|
28960
|
-
if (String(value) !== String(previousValue) && Object.keys(cfg.sessions ?? {}).length > 0) {
|
|
28961
|
-
warnings.push(`${Object.keys(cfg.sessions ?? {}).length} session override(s) kept under their existing names; only newly created sessions use the new naming. Use sessions.set/sessions.remove to adjust individual mappings.`);
|
|
28962
|
-
}
|
|
28963
|
-
cacheInvalidation = { cleared: ["peer IDs", "user context"], reason: "Peer name changed" };
|
|
28964
29408
|
break;
|
|
28965
29409
|
case "aiPeer":
|
|
28966
29410
|
previousValue = cfg.aiPeer;
|
|
28967
29411
|
cfg.aiPeer = String(value);
|
|
28968
|
-
clearPeerCache();
|
|
28969
|
-
clearClaudeContextOnly();
|
|
28970
|
-
cacheInvalidation = { cleared: ["peer IDs", "claude context"], reason: "AI peer changed" };
|
|
28971
29412
|
break;
|
|
28972
29413
|
case "workspace":
|
|
28973
29414
|
previousValue = cfg.workspace;
|
|
28974
29415
|
cfg.workspace = String(value);
|
|
28975
|
-
if (String(value) !== String(previousValue)) {
|
|
28976
|
-
clearIdCache();
|
|
28977
|
-
clearUserContextOnly();
|
|
28978
|
-
clearClaudeContextOnly();
|
|
28979
|
-
cacheInvalidation = { cleared: ["all IDs", "all context"], reason: "Workspace changed" };
|
|
28980
|
-
}
|
|
28981
|
-
break;
|
|
28982
|
-
case "endpoint.environment": {
|
|
28983
|
-
previousValue = cfg.endpoint?.environment;
|
|
28984
|
-
if (!cfg.endpoint)
|
|
28985
|
-
cfg.endpoint = {};
|
|
28986
|
-
const envVal = String(value) === "platform" ? "production" : String(value);
|
|
28987
|
-
cfg.endpoint.environment = envVal;
|
|
28988
|
-
cfg.endpoint.baseUrl = undefined;
|
|
28989
|
-
saveRootField("endpoint", cfg.endpoint);
|
|
28990
|
-
clearIdCache();
|
|
28991
|
-
clearUserContextOnly();
|
|
28992
|
-
clearClaudeContextOnly();
|
|
28993
|
-
cacheInvalidation = { cleared: ["all IDs", "all context"], reason: "Endpoint changed" };
|
|
28994
|
-
break;
|
|
28995
|
-
}
|
|
28996
|
-
case "endpoint.baseUrl":
|
|
28997
|
-
previousValue = cfg.endpoint?.baseUrl;
|
|
28998
|
-
if (!cfg.endpoint)
|
|
28999
|
-
cfg.endpoint = {};
|
|
29000
|
-
cfg.endpoint.baseUrl = String(value);
|
|
29001
|
-
cfg.endpoint.environment = undefined;
|
|
29002
|
-
saveRootField("endpoint", cfg.endpoint);
|
|
29003
|
-
clearIdCache();
|
|
29004
|
-
clearUserContextOnly();
|
|
29005
|
-
clearClaudeContextOnly();
|
|
29006
|
-
cacheInvalidation = { cleared: ["all IDs", "all context"], reason: "Endpoint URL changed" };
|
|
29007
|
-
break;
|
|
29008
|
-
case "sessionStrategy": {
|
|
29009
|
-
const prevStrategy = cfg.sessionStrategy ?? "per-directory";
|
|
29010
|
-
previousValue = prevStrategy;
|
|
29011
|
-
cfg.sessionStrategy = String(value);
|
|
29012
|
-
if (String(value) !== prevStrategy && String(value) !== "per-directory" && Object.keys(cfg.sessions ?? {}).length > 0) {
|
|
29013
|
-
warnings.push(`${Object.keys(cfg.sessions ?? {}).length} session override(s) kept but inactive: overrides only apply under the per-directory strategy.`);
|
|
29014
|
-
}
|
|
29015
|
-
break;
|
|
29016
|
-
}
|
|
29017
|
-
case "sessionPeerPrefix": {
|
|
29018
|
-
const prevPrefix = cfg.sessionPeerPrefix !== false;
|
|
29019
|
-
previousValue = prevPrefix;
|
|
29020
|
-
cfg.sessionPeerPrefix = coerceBoolean(value);
|
|
29021
|
-
if (cfg.sessionPeerPrefix !== prevPrefix && Object.keys(cfg.sessions ?? {}).length > 0) {
|
|
29022
|
-
warnings.push(`${Object.keys(cfg.sessions ?? {}).length} session override(s) kept under their existing names; only newly created sessions use the new naming. Use sessions.set/sessions.remove to adjust individual mappings.`);
|
|
29023
|
-
}
|
|
29024
|
-
break;
|
|
29025
|
-
}
|
|
29026
|
-
case "globalOverride":
|
|
29027
|
-
previousValue = cfg.globalOverride ?? false;
|
|
29028
|
-
cfg.globalOverride = coerceBoolean(value);
|
|
29029
|
-
saveRootField("globalOverride", cfg.globalOverride);
|
|
29030
|
-
break;
|
|
29031
|
-
case "enabled":
|
|
29032
|
-
previousValue = cfg.enabled;
|
|
29033
|
-
cfg.enabled = coerceBoolean(value);
|
|
29034
|
-
break;
|
|
29035
|
-
case "logging":
|
|
29036
|
-
previousValue = cfg.logging;
|
|
29037
|
-
cfg.logging = coerceBoolean(value);
|
|
29038
|
-
break;
|
|
29039
|
-
case "saveMessages":
|
|
29040
|
-
previousValue = cfg.saveMessages;
|
|
29041
|
-
cfg.saveMessages = coerceBoolean(value);
|
|
29042
|
-
break;
|
|
29043
|
-
case "messageUpload.maxUserTokens":
|
|
29044
|
-
previousValue = cfg.messageUpload?.maxUserTokens;
|
|
29045
|
-
if (!cfg.messageUpload)
|
|
29046
|
-
cfg.messageUpload = {};
|
|
29047
|
-
cfg.messageUpload.maxUserTokens = value === null ? undefined : Number(value);
|
|
29048
|
-
break;
|
|
29049
|
-
case "messageUpload.maxAssistantTokens":
|
|
29050
|
-
previousValue = cfg.messageUpload?.maxAssistantTokens;
|
|
29051
|
-
if (!cfg.messageUpload)
|
|
29052
|
-
cfg.messageUpload = {};
|
|
29053
|
-
cfg.messageUpload.maxAssistantTokens = value === null ? undefined : Number(value);
|
|
29054
|
-
break;
|
|
29055
|
-
case "messageUpload.summarizeAssistant":
|
|
29056
|
-
previousValue = cfg.messageUpload?.summarizeAssistant;
|
|
29057
|
-
if (!cfg.messageUpload)
|
|
29058
|
-
cfg.messageUpload = {};
|
|
29059
|
-
cfg.messageUpload.summarizeAssistant = coerceBoolean(value);
|
|
29060
|
-
break;
|
|
29061
|
-
case "contextRefresh.messageThreshold":
|
|
29062
|
-
previousValue = cfg.contextRefresh?.messageThreshold;
|
|
29063
|
-
if (!cfg.contextRefresh)
|
|
29064
|
-
cfg.contextRefresh = {};
|
|
29065
|
-
cfg.contextRefresh.messageThreshold = Number(value);
|
|
29066
|
-
break;
|
|
29067
|
-
case "contextRefresh.ttlSeconds":
|
|
29068
|
-
previousValue = cfg.contextRefresh?.ttlSeconds;
|
|
29069
|
-
if (!cfg.contextRefresh)
|
|
29070
|
-
cfg.contextRefresh = {};
|
|
29071
|
-
cfg.contextRefresh.ttlSeconds = Number(value);
|
|
29072
|
-
break;
|
|
29073
|
-
case "contextRefresh.skipDialectic":
|
|
29074
|
-
previousValue = cfg.contextRefresh?.skipDialectic;
|
|
29075
|
-
if (!cfg.contextRefresh)
|
|
29076
|
-
cfg.contextRefresh = {};
|
|
29077
|
-
cfg.contextRefresh.skipDialectic = coerceBoolean(value);
|
|
29078
|
-
break;
|
|
29079
|
-
case "reasoningLevel":
|
|
29080
|
-
previousValue = cfg.reasoningLevel ?? "medium";
|
|
29081
|
-
cfg.reasoningLevel = String(value);
|
|
29082
|
-
break;
|
|
29083
|
-
case "observationMode":
|
|
29084
|
-
previousValue = cfg.observationMode ?? "unified";
|
|
29085
|
-
cfg.observationMode = String(value);
|
|
29086
|
-
break;
|
|
29087
|
-
case "statusline": {
|
|
29088
|
-
const mode = String(value).toLowerCase();
|
|
29089
|
-
if (mode !== "on" && mode !== "off") {
|
|
29090
|
-
return {
|
|
29091
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: "statusline must be one of: on, off" }, null, 2) }],
|
|
29092
|
-
isError: true
|
|
29093
|
-
};
|
|
29094
|
-
}
|
|
29095
|
-
previousValue = cfg.statusline ?? "on";
|
|
29096
|
-
cfg.statusline = mode;
|
|
29097
|
-
saveRootField("statusline", cfg.statusline);
|
|
29098
|
-
break;
|
|
29099
|
-
}
|
|
29100
|
-
case "redactPatterns": {
|
|
29101
|
-
const arr = coerceStringArray(value);
|
|
29102
|
-
if (!arr) {
|
|
29103
|
-
return {
|
|
29104
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: "redactPatterns must be an array of regex strings" }, null, 2) }],
|
|
29105
|
-
isError: true
|
|
29106
|
-
};
|
|
29107
|
-
}
|
|
29108
|
-
for (const source of arr) {
|
|
29109
|
-
const err = validateRedactPattern(source);
|
|
29110
|
-
if (err) {
|
|
29111
|
-
return {
|
|
29112
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: err }, null, 2) }],
|
|
29113
|
-
isError: true
|
|
29114
|
-
};
|
|
29115
|
-
}
|
|
29116
|
-
}
|
|
29117
|
-
previousValue = cfg.redactPatterns;
|
|
29118
|
-
cfg.redactPatterns = arr;
|
|
29119
|
-
break;
|
|
29120
|
-
}
|
|
29121
|
-
case "injection.sessionStart": {
|
|
29122
|
-
const arr = validateComponentArray(value, SESSION_START_COMPONENTS, field);
|
|
29123
|
-
if (!Array.isArray(arr))
|
|
29124
|
-
return arr;
|
|
29125
|
-
previousValue = cfg.injection?.sessionStart;
|
|
29126
|
-
if (!cfg.injection)
|
|
29127
|
-
cfg.injection = {};
|
|
29128
|
-
cfg.injection.sessionStart = arr;
|
|
29129
|
-
break;
|
|
29130
|
-
}
|
|
29131
|
-
case "injection.perTurn": {
|
|
29132
|
-
const raw = coerceStringArray(value);
|
|
29133
|
-
const arr = validateComponentArray(raw ? normalizePerTurn(raw) : value, PER_TURN_COMPONENTS, field);
|
|
29134
|
-
if (!Array.isArray(arr))
|
|
29135
|
-
return arr;
|
|
29136
|
-
previousValue = cfg.injection?.perTurn;
|
|
29137
|
-
if (!cfg.injection)
|
|
29138
|
-
cfg.injection = {};
|
|
29139
|
-
cfg.injection.perTurn = arr;
|
|
29140
|
-
break;
|
|
29141
|
-
}
|
|
29142
|
-
case "injection.showContents": {
|
|
29143
|
-
const raw = coerceStringArray(value);
|
|
29144
|
-
const arr = validateComponentArray(raw ? normalizePerTurn(raw) : value, PER_TURN_COMPONENTS, field);
|
|
29145
|
-
if (!Array.isArray(arr))
|
|
29146
|
-
return arr;
|
|
29147
|
-
previousValue = cfg.injection?.showContents;
|
|
29148
|
-
if (!cfg.injection)
|
|
29149
|
-
cfg.injection = {};
|
|
29150
|
-
cfg.injection.showContents = arr;
|
|
29151
|
-
break;
|
|
29152
|
-
}
|
|
29153
|
-
case "injection.searchTopK":
|
|
29154
|
-
previousValue = cfg.injection?.searchTopK;
|
|
29155
|
-
if (!cfg.injection)
|
|
29156
|
-
cfg.injection = {};
|
|
29157
|
-
cfg.injection.searchTopK = Number(value);
|
|
29158
|
-
break;
|
|
29159
|
-
case "injection.maxConclusions":
|
|
29160
|
-
previousValue = cfg.injection?.maxConclusions;
|
|
29161
|
-
if (!cfg.injection)
|
|
29162
|
-
cfg.injection = {};
|
|
29163
|
-
cfg.injection.maxConclusions = Number(value);
|
|
29164
|
-
break;
|
|
29165
|
-
case "injection.searchMaxDistance":
|
|
29166
|
-
previousValue = cfg.injection?.searchMaxDistance;
|
|
29167
|
-
if (!cfg.injection)
|
|
29168
|
-
cfg.injection = {};
|
|
29169
|
-
cfg.injection.searchMaxDistance = Number(value);
|
|
29170
|
-
break;
|
|
29171
|
-
case "injection.sessionContextTokens": {
|
|
29172
|
-
const tokens = Number(value);
|
|
29173
|
-
if (!Number.isFinite(tokens) || tokens <= 0) {
|
|
29174
|
-
return {
|
|
29175
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: "injection.sessionContextTokens must be a positive number" }, null, 2) }],
|
|
29176
|
-
isError: true
|
|
29177
|
-
};
|
|
29178
|
-
}
|
|
29179
|
-
previousValue = cfg.injection?.sessionContextTokens;
|
|
29180
|
-
if (!cfg.injection)
|
|
29181
|
-
cfg.injection = {};
|
|
29182
|
-
cfg.injection.sessionContextTokens = tokens;
|
|
29183
|
-
break;
|
|
29184
|
-
}
|
|
29185
|
-
case "rememberTool":
|
|
29186
|
-
previousValue = cfg.rememberTool;
|
|
29187
|
-
cfg.rememberTool = coerceBoolean(value);
|
|
29188
|
-
break;
|
|
29189
|
-
case "injection.searchQuerySource":
|
|
29190
|
-
if (value !== "topics" && value !== "prompt") {
|
|
29191
|
-
return {
|
|
29192
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: `injection.searchQuerySource must be "topics" or "prompt"` }, null, 2) }],
|
|
29193
|
-
isError: true
|
|
29194
|
-
};
|
|
29195
|
-
}
|
|
29196
|
-
previousValue = cfg.injection?.searchQuerySource;
|
|
29197
|
-
if (!cfg.injection)
|
|
29198
|
-
cfg.injection = {};
|
|
29199
|
-
cfg.injection.searchQuerySource = value;
|
|
29200
|
-
break;
|
|
29201
|
-
case "injection.dialecticTemplate":
|
|
29202
|
-
previousValue = cfg.injection?.dialecticTemplate;
|
|
29203
|
-
if (!cfg.injection)
|
|
29204
|
-
cfg.injection = {};
|
|
29205
|
-
cfg.injection.dialecticTemplate = String(value);
|
|
29206
|
-
break;
|
|
29207
|
-
case "injection.dialecticReasoning": {
|
|
29208
|
-
const level = String(value);
|
|
29209
|
-
if (!REASONING_LEVELS.includes(level)) {
|
|
29210
|
-
return {
|
|
29211
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: `injection.dialecticReasoning must be one of: ${REASONING_LEVELS.join(", ")}` }, null, 2) }],
|
|
29212
|
-
isError: true
|
|
29213
|
-
};
|
|
29214
|
-
}
|
|
29215
|
-
previousValue = cfg.injection?.dialecticReasoning;
|
|
29216
|
-
if (!cfg.injection)
|
|
29217
|
-
cfg.injection = {};
|
|
29218
|
-
cfg.injection.dialecticReasoning = level;
|
|
29219
|
-
break;
|
|
29220
|
-
}
|
|
29221
|
-
case "sessions.set": {
|
|
29222
|
-
const obj = value;
|
|
29223
|
-
const path = obj?.path;
|
|
29224
|
-
const sName = obj?.name;
|
|
29225
|
-
if (typeof path !== "string" || !path || typeof sName !== "string" || !sName) {
|
|
29226
|
-
return {
|
|
29227
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: "sessions.set requires {path: string, name: string}" }, null, 2) }],
|
|
29228
|
-
isError: true
|
|
29229
|
-
};
|
|
29230
|
-
}
|
|
29231
|
-
if (!cfg.sessions)
|
|
29232
|
-
cfg.sessions = {};
|
|
29233
|
-
previousValue = cfg.sessions[path] ?? null;
|
|
29234
|
-
cfg.sessions[path] = sName;
|
|
29235
29416
|
break;
|
|
29236
|
-
|
|
29237
|
-
|
|
29238
|
-
|
|
29239
|
-
const rPath = obj?.path;
|
|
29240
|
-
if (typeof rPath !== "string" || !rPath) {
|
|
29241
|
-
return {
|
|
29242
|
-
content: [{ type: "text", text: JSON.stringify({ success: false, error: "sessions.remove requires {path: string}" }, null, 2) }],
|
|
29243
|
-
isError: true
|
|
29244
|
-
};
|
|
29245
|
-
}
|
|
29246
|
-
if (!cfg.sessions)
|
|
29247
|
-
cfg.sessions = {};
|
|
29248
|
-
previousValue = cfg.sessions[rPath] ?? null;
|
|
29249
|
-
delete cfg.sessions[rPath];
|
|
29417
|
+
case "baseUrl":
|
|
29418
|
+
previousValue = cfg.baseUrl;
|
|
29419
|
+
cfg.baseUrl = String(value);
|
|
29250
29420
|
break;
|
|
29251
|
-
}
|
|
29252
29421
|
default:
|
|
29253
29422
|
return {
|
|
29254
29423
|
content: [{
|
|
@@ -29258,31 +29427,19 @@ function handleSetConfig(args) {
|
|
|
29258
29427
|
isError: true
|
|
29259
29428
|
};
|
|
29260
29429
|
}
|
|
29261
|
-
saveConfig(cfg);
|
|
29430
|
+
await saveConfig(cfg, field);
|
|
29431
|
+
if (!loadConfig2()) {
|
|
29432
|
+
warnings.push(`No credential is saved for ${cfg.baseUrl} (an API key is dropped when the server changes). Run /honcho setup to add one.`);
|
|
29433
|
+
}
|
|
29262
29434
|
const endpointInfo = getEndpointInfo(cfg);
|
|
29263
29435
|
const resolved = {
|
|
29264
29436
|
peerName: cfg.peerName,
|
|
29265
29437
|
aiPeer: cfg.aiPeer,
|
|
29266
29438
|
workspace: cfg.workspace,
|
|
29267
|
-
endpoint: endpointInfo
|
|
29268
|
-
sessionStrategy: cfg.sessionStrategy ?? "per-directory",
|
|
29269
|
-
sessionPeerPrefix: cfg.sessionPeerPrefix !== false,
|
|
29270
|
-
sessions: cfg.sessions ?? {},
|
|
29271
|
-
messageUpload: cfg.messageUpload ?? {},
|
|
29272
|
-
contextRefresh: cfg.contextRefresh ?? {},
|
|
29273
|
-
reasoningLevel: cfg.reasoningLevel ?? "medium",
|
|
29274
|
-
observationMode: cfg.observationMode ?? "unified",
|
|
29275
|
-
statusline: cfg.statusline ?? "on",
|
|
29276
|
-
redactPatterns: cfg.redactPatterns ?? [],
|
|
29277
|
-
injection: cfg.injection ?? {},
|
|
29278
|
-
rememberTool: cfg.rememberTool === true,
|
|
29279
|
-
enabled: cfg.enabled !== false,
|
|
29280
|
-
logging: cfg.logging !== false,
|
|
29281
|
-
saveMessages: cfg.saveMessages !== false
|
|
29439
|
+
endpoint: endpointInfo
|
|
29282
29440
|
};
|
|
29283
29441
|
const restartWarning = SESSION_AFFECTING_FIELDS.has(field) ? "Close and restart all active Claude Code sessions. Open sessions still use the previous config and will write to the wrong Honcho session." : undefined;
|
|
29284
|
-
const
|
|
29285
|
-
const newSessionName = SESSION_AFFECTING_FIELDS.has(field) ? getSessionName(cwd) : undefined;
|
|
29442
|
+
const newSessionName = SESSION_AFFECTING_FIELDS.has(field) ? getSessionName() : undefined;
|
|
29286
29443
|
const sessionUrl = newSessionName ? honchoSessionUrl(cfg, newSessionName) ?? undefined : undefined;
|
|
29287
29444
|
return {
|
|
29288
29445
|
content: [{
|
|
@@ -29292,7 +29449,6 @@ function handleSetConfig(args) {
|
|
|
29292
29449
|
field,
|
|
29293
29450
|
previousValue,
|
|
29294
29451
|
newValue: value,
|
|
29295
|
-
cacheInvalidation,
|
|
29296
29452
|
restartWarning,
|
|
29297
29453
|
sessionUrl,
|
|
29298
29454
|
warnings: warnings.length ? warnings : undefined,
|
|
@@ -29302,32 +29458,15 @@ function handleSetConfig(args) {
|
|
|
29302
29458
|
};
|
|
29303
29459
|
}
|
|
29304
29460
|
var DIALECTIC_TIMEOUT_MS = 120000;
|
|
29305
|
-
var
|
|
29306
|
-
|
|
29307
|
-
|
|
29308
|
-
|
|
29309
|
-
|
|
29310
|
-
|
|
29311
|
-
|
|
29312
|
-
properties: {
|
|
29313
|
-
queries: {
|
|
29314
|
-
type: "array",
|
|
29315
|
-
items: { type: "string" },
|
|
29316
|
-
minItems: 1,
|
|
29317
|
-
maxItems: REMEMBER_MAX_QUERIES,
|
|
29318
|
-
description: `1–${REMEMBER_MAX_QUERIES} natural-language questions about the user, dispatched concurrently.`
|
|
29319
|
-
},
|
|
29320
|
-
reasoning_level: {
|
|
29321
|
-
type: "string",
|
|
29322
|
-
enum: [...REMEMBER_REASONING_LEVELS],
|
|
29323
|
-
description: "Reasoning budget applied to every query in this call. 'low' = quick lookups, " + "'medium' = general recall, 'high' = complex reasoning over the user's context."
|
|
29324
|
-
}
|
|
29325
|
-
},
|
|
29326
|
-
required: ["queries", "reasoning_level"]
|
|
29327
|
-
}
|
|
29328
|
-
};
|
|
29461
|
+
var DERIVED_ONLY = { level: { in: ["deductive", "inductive", "contradiction"] } };
|
|
29462
|
+
function parseScope(value) {
|
|
29463
|
+
const names = (Array.isArray(value) ? value : [value]).filter((v) => typeof v === "string" && v.trim() !== "").map((v) => v.trim());
|
|
29464
|
+
if (names.length === 0)
|
|
29465
|
+
return;
|
|
29466
|
+
return names.length === 1 ? names[0] : names;
|
|
29467
|
+
}
|
|
29329
29468
|
var NOT_CONFIGURED_RESULT = {
|
|
29330
|
-
content: [{ type: "text", text: "Honcho isn't configured; run /honcho
|
|
29469
|
+
content: [{ type: "text", text: "Honcho isn't configured; run /honcho setup to connect it, then try again." }],
|
|
29331
29470
|
isError: true
|
|
29332
29471
|
};
|
|
29333
29472
|
function createClients() {
|
|
@@ -29336,8 +29475,8 @@ function createClients() {
|
|
|
29336
29475
|
return null;
|
|
29337
29476
|
return {
|
|
29338
29477
|
config,
|
|
29339
|
-
honcho: new
|
|
29340
|
-
honchoDialectic: new
|
|
29478
|
+
honcho: new import_sdk2.Honcho(getHonchoClientOptions(config)),
|
|
29479
|
+
honchoDialectic: new import_sdk2.Honcho({
|
|
29341
29480
|
...getHonchoClientOptions(config),
|
|
29342
29481
|
timeout: DIALECTIC_TIMEOUT_MS,
|
|
29343
29482
|
maxRetries: 0
|
|
@@ -29348,7 +29487,7 @@ async function runMcpServer() {
|
|
|
29348
29487
|
setDetectedHost("claude_code");
|
|
29349
29488
|
let clients = createClients();
|
|
29350
29489
|
if (!clients) {
|
|
29351
|
-
console.error("[honcho-mcp] Not configured. Run /honcho
|
|
29490
|
+
console.error("[honcho-mcp] Not configured. Run /honcho setup");
|
|
29352
29491
|
}
|
|
29353
29492
|
const server = new Server({
|
|
29354
29493
|
name: "honcho",
|
|
@@ -29358,14 +29497,12 @@ async function runMcpServer() {
|
|
|
29358
29497
|
tools: {}
|
|
29359
29498
|
}
|
|
29360
29499
|
});
|
|
29361
|
-
const rememberEnabled = clients?.config.rememberTool === true;
|
|
29362
29500
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
29363
29501
|
return {
|
|
29364
29502
|
tools: [
|
|
29365
|
-
...rememberEnabled ? [REMEMBER_TOOL] : [],
|
|
29366
29503
|
{
|
|
29367
29504
|
name: "search",
|
|
29368
|
-
description: "Semantic search across messages and
|
|
29505
|
+
description: "Semantic search across messages and derived conclusions. Messages are searched across all sessions by default; use scope='session' for this chat's session only. Conclusions are always searched workspace-wide.",
|
|
29369
29506
|
inputSchema: {
|
|
29370
29507
|
type: "object",
|
|
29371
29508
|
properties: {
|
|
@@ -29381,8 +29518,8 @@ async function runMcpServer() {
|
|
|
29381
29518
|
scope: {
|
|
29382
29519
|
type: "string",
|
|
29383
29520
|
enum: ["session", "workspace"],
|
|
29384
|
-
description: "Search scope. '
|
|
29385
|
-
default: "
|
|
29521
|
+
description: "Search scope. 'workspace' (default) searches all sessions. 'session' searches only this Claude Code chat's session.",
|
|
29522
|
+
default: "workspace"
|
|
29386
29523
|
}
|
|
29387
29524
|
},
|
|
29388
29525
|
required: ["query"]
|
|
@@ -29390,18 +29527,27 @@ async function runMcpServer() {
|
|
|
29390
29527
|
},
|
|
29391
29528
|
{
|
|
29392
29529
|
name: "chat",
|
|
29393
|
-
description: "
|
|
29530
|
+
description: "Ask Honcho a question and get a reasoned answer from memory. By default it answers about the user from everything Honcho knows about them. " + "Pass `scope` to answer only from the sessions in one or more scopes (each Claude Code chat is in a scope for its git repository and one for its machine). " + "Pass `workspace: true` to ask about the whole workspace — every peer, not just the user.",
|
|
29394
29531
|
inputSchema: {
|
|
29395
29532
|
type: "object",
|
|
29396
29533
|
properties: {
|
|
29397
29534
|
query: {
|
|
29398
29535
|
type: "string",
|
|
29399
|
-
description: "Natural language question
|
|
29536
|
+
description: "Natural language question"
|
|
29537
|
+
},
|
|
29538
|
+
scope: {
|
|
29539
|
+
anyOf: [{ type: "string" }, { type: "array", items: { type: "string" } }],
|
|
29540
|
+
description: "Scope name, or several, to limit the answer to (e.g. a repository or machine name)."
|
|
29541
|
+
},
|
|
29542
|
+
workspace: {
|
|
29543
|
+
type: "boolean",
|
|
29544
|
+
description: "Ask across the whole workspace instead of about the user. Combine with `scope` to limit it.",
|
|
29545
|
+
default: false
|
|
29400
29546
|
},
|
|
29401
29547
|
reasoning_level: {
|
|
29402
29548
|
type: "string",
|
|
29403
29549
|
enum: ["minimal", "low", "medium", "high", "max"],
|
|
29404
|
-
description: "Reasoning budget for this query. Use 'low' for simple lookups, 'medium' for general questions, 'high'/'max' for complex reasoning
|
|
29550
|
+
description: "Reasoning budget for this query. Use 'low' for simple lookups, 'medium' for general questions, 'high'/'max' for complex reasoning. Defaults to 'medium'."
|
|
29405
29551
|
}
|
|
29406
29552
|
},
|
|
29407
29553
|
required: ["query"]
|
|
@@ -29423,7 +29569,7 @@ async function runMcpServer() {
|
|
|
29423
29569
|
},
|
|
29424
29570
|
{
|
|
29425
29571
|
name: "list_conclusions",
|
|
29426
|
-
description: "List conclusions Honcho has
|
|
29572
|
+
description: "List conclusions Honcho has derived about the user (explicit conclusions are excluded). Use this to review what is remembered before creating duplicates, or to find IDs for deletion.",
|
|
29427
29573
|
inputSchema: {
|
|
29428
29574
|
type: "object",
|
|
29429
29575
|
properties: {
|
|
@@ -29442,7 +29588,7 @@ async function runMcpServer() {
|
|
|
29442
29588
|
},
|
|
29443
29589
|
{
|
|
29444
29590
|
name: "query_conclusions",
|
|
29445
|
-
description: "Semantically search conclusions Honcho has
|
|
29591
|
+
description: "Semantically search conclusions Honcho has derived about the user (explicit conclusions are excluded). Returns IDs usable with delete_conclusion — much faster than paging list_conclusions when looking for something specific.",
|
|
29446
29592
|
inputSchema: {
|
|
29447
29593
|
type: "object",
|
|
29448
29594
|
properties: {
|
|
@@ -29473,36 +29619,6 @@ async function runMcpServer() {
|
|
|
29473
29619
|
required: ["id"]
|
|
29474
29620
|
}
|
|
29475
29621
|
},
|
|
29476
|
-
{
|
|
29477
|
-
name: "get_briefing",
|
|
29478
|
-
description: "Load the session briefing: the stored long summary of this session plus the user's peer card (identity/attribute profile). " + "Call this once at the start of a session when the session-start directives ask for it, or any time you need to catch up on where the session left off.",
|
|
29479
|
-
inputSchema: {
|
|
29480
|
-
type: "object",
|
|
29481
|
-
properties: {}
|
|
29482
|
-
}
|
|
29483
|
-
},
|
|
29484
|
-
{
|
|
29485
|
-
name: "get_context",
|
|
29486
|
-
description: "Retrieve the full context object (representation + peer card) from Honcho for the current user. Scoped by observation mode.",
|
|
29487
|
-
inputSchema: {
|
|
29488
|
-
type: "object",
|
|
29489
|
-
properties: {
|
|
29490
|
-
max_conclusions: {
|
|
29491
|
-
type: "number",
|
|
29492
|
-
description: "Max conclusions to include (default: 25)",
|
|
29493
|
-
default: 25
|
|
29494
|
-
}
|
|
29495
|
-
}
|
|
29496
|
-
}
|
|
29497
|
-
},
|
|
29498
|
-
{
|
|
29499
|
-
name: "get_representation",
|
|
29500
|
-
description: "Retrieve the user's representation string from Honcho. Lighter-weight than get_context.",
|
|
29501
|
-
inputSchema: {
|
|
29502
|
-
type: "object",
|
|
29503
|
-
properties: {}
|
|
29504
|
-
}
|
|
29505
|
-
},
|
|
29506
29622
|
{
|
|
29507
29623
|
name: "get_config",
|
|
29508
29624
|
description: "Get the current Honcho plugin configuration, cache state, and diagnostic warnings",
|
|
@@ -29513,7 +29629,7 @@ async function runMcpServer() {
|
|
|
29513
29629
|
},
|
|
29514
29630
|
{
|
|
29515
29631
|
name: "set_config",
|
|
29516
|
-
description: "Update a Honcho plugin configuration field. Dangerous changes (workspace,
|
|
29632
|
+
description: "Update a Honcho plugin configuration field. Dangerous changes (workspace, baseUrl) require confirm=true.",
|
|
29517
29633
|
inputSchema: {
|
|
29518
29634
|
type: "object",
|
|
29519
29635
|
properties: {
|
|
@@ -29524,44 +29640,15 @@ async function runMcpServer() {
|
|
|
29524
29640
|
"peerName",
|
|
29525
29641
|
"aiPeer",
|
|
29526
29642
|
"workspace",
|
|
29527
|
-
"
|
|
29528
|
-
"endpoint.environment",
|
|
29529
|
-
"endpoint.baseUrl",
|
|
29530
|
-
"sessionStrategy",
|
|
29531
|
-
"sessionPeerPrefix",
|
|
29532
|
-
"enabled",
|
|
29533
|
-
"logging",
|
|
29534
|
-
"saveMessages",
|
|
29535
|
-
"messageUpload.maxUserTokens",
|
|
29536
|
-
"messageUpload.maxAssistantTokens",
|
|
29537
|
-
"messageUpload.summarizeAssistant",
|
|
29538
|
-
"contextRefresh.messageThreshold",
|
|
29539
|
-
"contextRefresh.ttlSeconds",
|
|
29540
|
-
"contextRefresh.skipDialectic",
|
|
29541
|
-
"reasoningLevel",
|
|
29542
|
-
"observationMode",
|
|
29543
|
-
"redactPatterns",
|
|
29544
|
-
"injection.sessionStart",
|
|
29545
|
-
"injection.perTurn",
|
|
29546
|
-
"injection.showContents",
|
|
29547
|
-
"injection.searchTopK",
|
|
29548
|
-
"injection.maxConclusions",
|
|
29549
|
-
"injection.searchMaxDistance",
|
|
29550
|
-
"injection.searchQuerySource",
|
|
29551
|
-
"injection.sessionContextTokens",
|
|
29552
|
-
"injection.dialecticTemplate",
|
|
29553
|
-
"injection.dialecticReasoning",
|
|
29554
|
-
"rememberTool",
|
|
29555
|
-
"sessions.set",
|
|
29556
|
-
"sessions.remove"
|
|
29643
|
+
"baseUrl"
|
|
29557
29644
|
]
|
|
29558
29645
|
},
|
|
29559
29646
|
value: {
|
|
29560
|
-
description:
|
|
29647
|
+
description: "New value."
|
|
29561
29648
|
},
|
|
29562
29649
|
confirm: {
|
|
29563
29650
|
type: "boolean",
|
|
29564
|
-
description: "Required true for dangerous changes (workspace,
|
|
29651
|
+
description: "Required true for dangerous changes (workspace, baseUrl). Without it, returns a warning instead of applying."
|
|
29565
29652
|
}
|
|
29566
29653
|
},
|
|
29567
29654
|
required: ["field", "value"]
|
|
@@ -29572,27 +29659,28 @@ async function runMcpServer() {
|
|
|
29572
29659
|
});
|
|
29573
29660
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
29574
29661
|
const { name, arguments: args } = request.params;
|
|
29575
|
-
const cwd = getLastActiveCwd() || process.cwd();
|
|
29576
29662
|
clients ??= createClients();
|
|
29577
29663
|
if (!clients) {
|
|
29578
29664
|
return NOT_CONFIGURED_RESULT;
|
|
29579
29665
|
}
|
|
29580
29666
|
const { config, honcho, honchoDialectic } = clients;
|
|
29667
|
+
await refreshCredential(config);
|
|
29668
|
+
setClientApiKey(honcho, config.apiKey);
|
|
29669
|
+
setClientApiKey(honchoDialectic, config.apiKey);
|
|
29581
29670
|
if (name === "get_config") {
|
|
29582
|
-
return handleGetConfig(
|
|
29671
|
+
return handleGetConfig();
|
|
29583
29672
|
}
|
|
29584
29673
|
if (name === "set_config") {
|
|
29585
29674
|
return handleSetConfig(args);
|
|
29586
29675
|
}
|
|
29587
29676
|
if (name === "list_conclusions" || name === "delete_conclusion" || name === "query_conclusions") {
|
|
29588
29677
|
try {
|
|
29589
|
-
const
|
|
29590
|
-
const
|
|
29591
|
-
const conclusionScope = scopePeer.conclusionsOf(config.peerName);
|
|
29678
|
+
const userPeer = await honcho.peer(config.peerName);
|
|
29679
|
+
const conclusionScope = userPeer.conclusionsOf(config.peerName);
|
|
29592
29680
|
if (name === "list_conclusions") {
|
|
29593
29681
|
const page = args?.page ?? 1;
|
|
29594
29682
|
const size = Math.min(args?.size ?? 20, 100);
|
|
29595
|
-
const result = await conclusionScope.list({ page, size });
|
|
29683
|
+
const result = await conclusionScope.list({ page, size, filters: DERIVED_ONLY });
|
|
29596
29684
|
const items = result.items.map((c) => ({
|
|
29597
29685
|
id: c.id,
|
|
29598
29686
|
content: c.content,
|
|
@@ -29608,7 +29696,7 @@ async function runMcpServer() {
|
|
|
29608
29696
|
if (name === "query_conclusions") {
|
|
29609
29697
|
const query = args?.query;
|
|
29610
29698
|
const topK = Math.min(args?.top_k ?? 10, 50);
|
|
29611
|
-
const conclusions = await conclusionScope.query(query, topK);
|
|
29699
|
+
const conclusions = await conclusionScope.query(query, topK, undefined, DERIVED_ONLY);
|
|
29612
29700
|
const items = conclusions.map((c) => ({
|
|
29613
29701
|
id: c.id,
|
|
29614
29702
|
content: c.content,
|
|
@@ -29630,23 +29718,25 @@ async function runMcpServer() {
|
|
|
29630
29718
|
};
|
|
29631
29719
|
}
|
|
29632
29720
|
}
|
|
29633
|
-
const sessionName = getSessionName(
|
|
29721
|
+
const sessionName = getSessionName();
|
|
29722
|
+
const needsSession = name === "create_conclusion" || name === "search" && args?.scope === "session";
|
|
29723
|
+
if (!sessionName && needsSession) {
|
|
29724
|
+
return {
|
|
29725
|
+
content: [{ type: "text", text: "Error: no Claude Code session id available" }],
|
|
29726
|
+
isError: true
|
|
29727
|
+
};
|
|
29728
|
+
}
|
|
29634
29729
|
try {
|
|
29635
|
-
const session = await honcho.session(sessionName);
|
|
29636
|
-
const observationMode = getObservationMode(config);
|
|
29730
|
+
const session = needsSession && sessionName ? await honcho.session(sessionName) : undefined;
|
|
29637
29731
|
const userPeer = await honcho.peer(config.peerName);
|
|
29638
|
-
const
|
|
29639
|
-
const activePeer = observationMode === "unified" ? userPeer : aiPeer;
|
|
29640
|
-
const chatTarget = observationMode === "unified" ? undefined : config.peerName;
|
|
29641
|
-
const contextTarget = observationMode === "unified" ? undefined : config.peerName;
|
|
29732
|
+
const scope = parseScope(args?.scope);
|
|
29642
29733
|
switch (name) {
|
|
29643
29734
|
case "search": {
|
|
29644
29735
|
const query = args?.query;
|
|
29645
29736
|
const limit = args?.limit ?? 10;
|
|
29646
|
-
const scope = args?.scope ?? "session";
|
|
29647
29737
|
const [messages, conclusions] = await Promise.all([
|
|
29648
|
-
|
|
29649
|
-
|
|
29738
|
+
session ? session.search(query, { limit }) : honcho.search(query, { limit }),
|
|
29739
|
+
userPeer.conclusionsOf(config.peerName).query(query, limit, undefined, DERIVED_ONLY).catch(() => [])
|
|
29650
29740
|
]);
|
|
29651
29741
|
const results = {
|
|
29652
29742
|
messages: messages.map((msg) => ({
|
|
@@ -29671,16 +29761,21 @@ async function runMcpServer() {
|
|
|
29671
29761
|
}
|
|
29672
29762
|
case "chat": {
|
|
29673
29763
|
const query = args?.query;
|
|
29674
|
-
const reasoningLevel = args?.reasoning_level ??
|
|
29764
|
+
const reasoningLevel = args?.reasoning_level ?? "medium";
|
|
29675
29765
|
let deadlineTimer;
|
|
29676
29766
|
const deadline = new Promise((_, reject) => {
|
|
29677
29767
|
deadlineTimer = setTimeout(() => reject(new Error(`Dialectic call exceeded ${DIALECTIC_TIMEOUT_MS}ms`)), DIALECTIC_TIMEOUT_MS);
|
|
29678
29768
|
});
|
|
29679
29769
|
const chatFlow = (async () => {
|
|
29680
|
-
|
|
29770
|
+
if (args?.workspace === true) {
|
|
29771
|
+
return honchoDialectic.chat(query, {
|
|
29772
|
+
...scope ? { scope } : {},
|
|
29773
|
+
reasoningLevel
|
|
29774
|
+
});
|
|
29775
|
+
}
|
|
29776
|
+
const dialecticPeer = await honchoDialectic.peer(userPeer.id);
|
|
29681
29777
|
return dialecticPeer.chat(query, {
|
|
29682
|
-
...
|
|
29683
|
-
session,
|
|
29778
|
+
...scope ? { scope } : {},
|
|
29684
29779
|
reasoningLevel
|
|
29685
29780
|
});
|
|
29686
29781
|
})();
|
|
@@ -29699,77 +29794,9 @@ async function runMcpServer() {
|
|
|
29699
29794
|
chatFlow.catch(() => {});
|
|
29700
29795
|
}
|
|
29701
29796
|
}
|
|
29702
|
-
case "honcho_remember": {
|
|
29703
|
-
const queries = Array.isArray(args?.queries) ? args.queries.map(String).map((q) => q.trim()).filter(Boolean) : [];
|
|
29704
|
-
const reasoningLevel = args?.reasoning_level;
|
|
29705
|
-
if (queries.length === 0) {
|
|
29706
|
-
return {
|
|
29707
|
-
content: [{ type: "text", text: "honcho_remember requires a non-empty `queries` array." }],
|
|
29708
|
-
isError: true
|
|
29709
|
-
};
|
|
29710
|
-
}
|
|
29711
|
-
if (queries.length > REMEMBER_MAX_QUERIES) {
|
|
29712
|
-
return {
|
|
29713
|
-
content: [{ type: "text", text: `honcho_remember accepts at most ${REMEMBER_MAX_QUERIES} queries (got ${queries.length}).` }],
|
|
29714
|
-
isError: true
|
|
29715
|
-
};
|
|
29716
|
-
}
|
|
29717
|
-
if (!REMEMBER_REASONING_LEVELS.includes(reasoningLevel)) {
|
|
29718
|
-
return {
|
|
29719
|
-
content: [{ type: "text", text: `reasoning_level must be one of: ${REMEMBER_REASONING_LEVELS.join(", ")}` }],
|
|
29720
|
-
isError: true
|
|
29721
|
-
};
|
|
29722
|
-
}
|
|
29723
|
-
let deadlineTimer;
|
|
29724
|
-
const deadline = new Promise((_, reject) => {
|
|
29725
|
-
deadlineTimer = setTimeout(() => reject(new Error(`honcho_remember exceeded ${DIALECTIC_TIMEOUT_MS}ms`)), DIALECTIC_TIMEOUT_MS);
|
|
29726
|
-
});
|
|
29727
|
-
const batchStart = Date.now();
|
|
29728
|
-
const fanOut = (async () => {
|
|
29729
|
-
const dialecticPeer = await honchoDialectic.peer(activePeer.id);
|
|
29730
|
-
return Promise.allSettled(queries.map(async (q) => {
|
|
29731
|
-
const qStart = Date.now();
|
|
29732
|
-
const answer = await dialecticPeer.chat(q, {
|
|
29733
|
-
...chatTarget ? { target: chatTarget } : {},
|
|
29734
|
-
session,
|
|
29735
|
-
reasoningLevel
|
|
29736
|
-
});
|
|
29737
|
-
return { answer, ms: Date.now() - qStart };
|
|
29738
|
-
}));
|
|
29739
|
-
})();
|
|
29740
|
-
try {
|
|
29741
|
-
const settled = await Promise.race([fanOut, deadline]);
|
|
29742
|
-
const totalMs = Date.now() - batchStart;
|
|
29743
|
-
const secs = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
29744
|
-
const hits = settled.filter((r) => r.status === "fulfilled" && r.value.answer).length;
|
|
29745
|
-
const header = `recalled ${hits} insight${hits === 1 ? "" : "s"} · ` + `${queries.length} dialectic${queries.length === 1 ? "" : "s"} @ ${reasoningLevel} · ${secs(totalMs)}`;
|
|
29746
|
-
const blocks = settled.map((r, i) => {
|
|
29747
|
-
const label = `q${i + 1} "${queries[i]}"`;
|
|
29748
|
-
if (r.status === "rejected") {
|
|
29749
|
-
const msg = r.reason instanceof Error ? r.reason.message : String(r.reason);
|
|
29750
|
-
return `${label} — failed
|
|
29751
|
-
→ (error: ${msg})`;
|
|
29752
|
-
}
|
|
29753
|
-
const { answer, ms } = r.value;
|
|
29754
|
-
const body = answer && answer.trim() ? answer.trim() : "(no memory found)";
|
|
29755
|
-
return `${label} — ${secs(ms)}
|
|
29756
|
-
→ ${body}`;
|
|
29757
|
-
});
|
|
29758
|
-
return {
|
|
29759
|
-
content: [{ type: "text", text: `${header}
|
|
29760
|
-
|
|
29761
|
-
${blocks.join(`
|
|
29762
|
-
|
|
29763
|
-
`)}` }]
|
|
29764
|
-
};
|
|
29765
|
-
} finally {
|
|
29766
|
-
clearTimeout(deadlineTimer);
|
|
29767
|
-
fanOut.catch(() => {});
|
|
29768
|
-
}
|
|
29769
|
-
}
|
|
29770
29797
|
case "create_conclusion": {
|
|
29771
29798
|
const content = args?.content;
|
|
29772
|
-
const conclusions = await
|
|
29799
|
+
const conclusions = await userPeer.conclusionsOf(config.peerName).create({
|
|
29773
29800
|
content,
|
|
29774
29801
|
sessionId: session.id
|
|
29775
29802
|
});
|
|
@@ -29782,50 +29809,6 @@ ${blocks.join(`
|
|
|
29782
29809
|
]
|
|
29783
29810
|
};
|
|
29784
29811
|
}
|
|
29785
|
-
case "get_briefing": {
|
|
29786
|
-
const [summariesResult, ctxResult] = await Promise.allSettled([
|
|
29787
|
-
session.summaries(),
|
|
29788
|
-
activePeer.context({
|
|
29789
|
-
...contextTarget ? { target: contextTarget } : {},
|
|
29790
|
-
maxConclusions: 25,
|
|
29791
|
-
includeMostFrequent: true
|
|
29792
|
-
})
|
|
29793
|
-
]);
|
|
29794
|
-
const summary = summariesResult.status === "fulfilled" ? summariesResult.value?.longSummary?.content?.trim() : null;
|
|
29795
|
-
const card = ctxResult.status === "fulfilled" ? (ctxResult.value?.peerCard ?? []).filter((item) => item?.trim()) : [];
|
|
29796
|
-
const parts = [];
|
|
29797
|
-
if (summary)
|
|
29798
|
-
parts.push(`## Session summary
|
|
29799
|
-
${summary}`);
|
|
29800
|
-
if (card.length)
|
|
29801
|
-
parts.push(`## Peer card (${card.length} items)
|
|
29802
|
-
${card.map((item) => `- ${item}`).join(`
|
|
29803
|
-
`)}`);
|
|
29804
|
-
if (parts.length === 0)
|
|
29805
|
-
parts.push("No briefing available yet — no stored session summary or peer card.");
|
|
29806
|
-
return {
|
|
29807
|
-
content: [{ type: "text", text: parts.join(`
|
|
29808
|
-
|
|
29809
|
-
`) }]
|
|
29810
|
-
};
|
|
29811
|
-
}
|
|
29812
|
-
case "get_context": {
|
|
29813
|
-
const maxConclusions = args?.max_conclusions ?? 25;
|
|
29814
|
-
const ctx = await activePeer.context({
|
|
29815
|
-
...contextTarget ? { target: contextTarget } : {},
|
|
29816
|
-
maxConclusions,
|
|
29817
|
-
includeMostFrequent: true
|
|
29818
|
-
});
|
|
29819
|
-
return {
|
|
29820
|
-
content: [{ type: "text", text: JSON.stringify(ctx, null, 2) }]
|
|
29821
|
-
};
|
|
29822
|
-
}
|
|
29823
|
-
case "get_representation": {
|
|
29824
|
-
const rep = await activePeer.representation(contextTarget ? { target: contextTarget } : undefined);
|
|
29825
|
-
return {
|
|
29826
|
-
content: [{ type: "text", text: typeof rep === "string" ? rep : JSON.stringify(rep, null, 2) }]
|
|
29827
|
-
};
|
|
29828
|
-
}
|
|
29829
29812
|
default:
|
|
29830
29813
|
return {
|
|
29831
29814
|
content: [
|
|
@@ -29856,5 +29839,5 @@ ${card.map((item) => `- ${item}`).join(`
|
|
|
29856
29839
|
// mcp-server.ts
|
|
29857
29840
|
await runMcpServer();
|
|
29858
29841
|
|
|
29859
|
-
//# debugId=
|
|
29842
|
+
//# debugId=1E81E5A00B44292F64756E2164756E21
|
|
29860
29843
|
//# sourceMappingURL=mcp-server.js.map
|