@bobannomi/app-host 0.8.0 → 0.8.1
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/README.md +5 -5
- package/dist/index.d.ts +16 -31
- package/dist/index.js +84 -66
- package/dist/index.js.map +3 -3
- package/dist/protocol.d.ts +16 -48
- package/dist/protocol.js +27 -53
- package/dist/protocol.js.map +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
应用页面使用的浏览器接入库,无运行时依赖。`connectAppHost({ hostApi: "^0.1.0" })` 等待宿主页面端口并核对接口版本,返回 `AppHost`。页面通过 `hasFeature()` 判断当前文档协商的能力,实际操作由宿主再次校验权限。
|
|
6
6
|
|
|
7
|
-
用户选中的本机目录从 `host.workspace.pick()` 取得,文件由 Main 读取。获准的桌面目标用 `host.desktop.files` 和 `host.desktop.terminals
|
|
7
|
+
用户选中的本机目录从 `host.workspace.pick()` 取得,文件由 Main 读取。获准的桌面目标用 `host.desktop.files` 和 `host.desktop.terminals`。页面可直接调用 `connectAgent()`,将返回的 `clientOptions` 传给 `BobanNomiClient`,再用 `client.sessions.byId(id)` 操作会话。 [页面示例](../../apps/client-docs/examples/browser/README.md)
|
|
8
8
|
|
|
9
9
|
`host.sessions.preparation` 用 `create` 提交会话创建,用 `getResult` 查询完整原请求。`host.sessions.auxiliary` 用 `getOptions` 读取原会话可用配置,再用同一个请求执行 `open`、`get` 和 `close`。临时会话与打开它的页面相绑定。
|
|
10
10
|
|
|
@@ -58,19 +58,19 @@ JSON 方法使用非空键,文件方法使用宿主签发的文件 ID;页面
|
|
|
58
58
|
|
|
59
59
|
SDK 兼容只有 `code` 和 `message` 的错误回复。每次连接都核对版本,同一文档共用一次功能协商。若旧宿主拒绝协商并返回 `invalid_request`,`connectAppHost` 会失败,存储和登录也无法通过这次连接使用。连接成功后的普通业务错误不会断开连接。Desktop 在协商 `extended-errors-v1` 前使用旧错误字段和错误码。功能协商与授权分开,Agent 和应用服务仍需要对应批准及实际运行适配器。`createPageFetchClient({send,onMessage,onClose})` 用宿主给出的连接信息构造可注入标准 Client SDK 的 fetch。
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
页面通过 `connectAgent()` 取得 `clientOptions` 后,可用 Client SDK 的 `client.models.list()`、`client.agents.list()` 和 `client.skills.list()` 读取模型、角色和技能。审批和提问由会话内入口处理,已接纳的 Run 在关页后继续沿原配置执行。
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
用户点击「选择目录」时,调用 `host.workspace.pick()` 打开 Nomi 的本机目录选择器。取消返回 `null`。选中的目录提供 `listFiles()` 和 `readText(path)`,默认列根目录,路径相对于所选目录。可用 `host.workspace.open(id)` 重新取得已选目录。Electron 主进程处理本机读操作并逐次核对授权。需要在页面刷新后核对原选择时,先保存 `requestId`,再调用 `pick({ requestId })`。用 `getSelection({ requestId })` 查询原回执,完成后按回执中的目录 ID 调用 `open(id)`。选择操作不自动重试。
|
|
64
64
|
|
|
65
65
|
## 应用提供模型目录
|
|
66
66
|
|
|
67
|
-
页面用 `
|
|
67
|
+
页面用 `connectAgent()` 取得 `clientOptions`,再用 `new BobanNomiClient({ ...clientOptions, providers })` 传入应用自己的供应商。每个供应商提供模型列表和包含模型服务地址与 API key 的 `connection`。应用用 `client.models.list()` 展示选项,按用户选中的供应商和模型 ID 创建会话和发消息。 [应用内 Agent 示例](../../apps/client-docs/src/content/docs/guides/app-agent.mdx)
|
|
68
68
|
|
|
69
69
|
## Desktop tools
|
|
70
70
|
|
|
71
71
|
根入口提供 `parsePluginAppComposerContexts`,校验插件输入框上下文。历史交互和 MCP 工具结果从各自的合同包读取。
|
|
72
72
|
|
|
73
|
-
`
|
|
73
|
+
`connectAgent()` 由包的根入口导出,可以直接打开当前产品的 daemon 连接。将返回的 `clientOptions` 交给 Client SDK,按会话 ID 读取历史、订阅事件,或继续有执行权限的用户会话。Daemon 按每次访问的会话及操作核对授权。调用附件、辅助会话和原生文件工具时,通过 `connectAppHost()` 打开对应的宿主入口。执行目录是创建请求的业务参数。
|
|
74
74
|
|
|
75
75
|
`host.desktop` fixes an explicit target (scope, draft revision, optional actual root and session), then exposes typed files, Git, terminal, window, browser annotation/capture and MCP App operations. `host.attachments.getConnection` also supports a draft-only target. `host.sessions.auxiliary` exposes options, open, query and close using the original standard connection. Each wire method validates both request and reply. Connections are recorded in a per-document WeakMap, and a fabricated or foreign document connection cannot be bound. The three negotiated features are only available when their actual host services are assembled. Recovery methods query original request receipts.
|
|
76
76
|
|
package/dist/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ declare class AppHostError extends Error {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
declare const APP_HOST_FEATURES: readonly ["fetch-v1", "fetch-inline-body-v1", "fetch-target-close-v1", "service-v1", "extended-errors-v1", "workspace-v1", "session-
|
|
50
|
+
declare const APP_HOST_FEATURES: readonly ["fetch-v1", "fetch-inline-body-v1", "fetch-target-close-v1", "service-v1", "extended-errors-v1", "workspace-v1", "session-controls-v1", "conversation-creation-session-v1", "trusted-desktop-v1", "attachments-v1", "auxiliary-sessions-v1", "system-ui-v1", "lifecycle-v1", "commands-v1", "resource-catalog-v1", "file-content-v1", "window-chrome-v1", "window-updates-v1", "window-update-check-v1", "embedded-browser-v1", "browser-binding-invalidation-v1", "browser-capture-preview-v1", "workbench-computer-v1"];
|
|
51
51
|
type AppHostFeature = (typeof APP_HOST_FEATURES)[number];
|
|
52
52
|
type FetchDirection = "upload" | "download";
|
|
53
53
|
type PageFetchFrame = {
|
|
@@ -416,7 +416,9 @@ interface ConnectionStreams {
|
|
|
416
416
|
fetchFor(id: string, base: string): typeof fetch;
|
|
417
417
|
isClosed?(id: string): boolean;
|
|
418
418
|
}
|
|
419
|
-
/**
|
|
419
|
+
/** Opens the product daemon through fixed preload IPC, independently of desktop tool messages. */
|
|
420
|
+
declare function connectAgent(): Promise<AgentConnection>;
|
|
421
|
+
/** A Client transport. Pass an AbortSignal to cancel an individual request. */
|
|
420
422
|
interface AgentConnection {
|
|
421
423
|
/** Optional location hint. Execution always uses the Session/Run's persisted root. */
|
|
422
424
|
readonly cwd?: string;
|
|
@@ -425,7 +427,7 @@ interface AgentConnection {
|
|
|
425
427
|
readonly baseUrl: string;
|
|
426
428
|
readonly fetch: typeof fetch;
|
|
427
429
|
};
|
|
428
|
-
/** True once
|
|
430
|
+
/** True once this connection can no longer accept requests. */
|
|
429
431
|
isClosed?(): boolean;
|
|
430
432
|
}
|
|
431
433
|
|
|
@@ -1182,16 +1184,9 @@ type Project = Scope & {
|
|
|
1182
1184
|
projectId: string;
|
|
1183
1185
|
workspaceId: string;
|
|
1184
1186
|
};
|
|
1185
|
-
type ProjectRequest = {
|
|
1186
|
-
action: "list";
|
|
1187
|
-
} | Scope & {
|
|
1187
|
+
type ProjectRequest = Scope & {
|
|
1188
1188
|
action: "register";
|
|
1189
1189
|
workspaceId: string;
|
|
1190
|
-
} | Project & {
|
|
1191
|
-
action: "setDefaultShell";
|
|
1192
|
-
shell: string | null;
|
|
1193
|
-
} | Project & {
|
|
1194
|
-
action: "archive";
|
|
1195
1190
|
} | Project & {
|
|
1196
1191
|
action: "rebind";
|
|
1197
1192
|
previousWorkspaceId: string;
|
|
@@ -1247,6 +1242,7 @@ type Entry<Input, Result> = {
|
|
|
1247
1242
|
input: Input;
|
|
1248
1243
|
result: Result;
|
|
1249
1244
|
};
|
|
1245
|
+
type GitRead<M extends "desktop.git.changes" | "desktop.git.diff"> = Entry<Root & Omit<DesktopMethodMap[M]["params"], "targetId">, DesktopMethodMap[M]["result"]>;
|
|
1250
1246
|
type LocalWorkspaceActions = {
|
|
1251
1247
|
pick: Entry<{}, Required<Root> & {
|
|
1252
1248
|
workspaceId: string;
|
|
@@ -1274,6 +1270,8 @@ type LocalWorkspaceActions = {
|
|
|
1274
1270
|
webPreview: Entry<File, {
|
|
1275
1271
|
url: string;
|
|
1276
1272
|
}>;
|
|
1273
|
+
gitChanges: GitRead<"desktop.git.changes">;
|
|
1274
|
+
gitDiff: GitRead<"desktop.git.diff">;
|
|
1277
1275
|
};
|
|
1278
1276
|
type Action = keyof LocalWorkspaceActions;
|
|
1279
1277
|
type LocalWorkspaceRequest = {
|
|
@@ -1403,7 +1401,7 @@ type SystemEvent = {
|
|
|
1403
1401
|
type: "git-preferences-changed";
|
|
1404
1402
|
defaultTaskLocation: "current" | "worktree";
|
|
1405
1403
|
};
|
|
1406
|
-
declare const SYSTEM_METHODS: readonly ["system.projects", "system.workspace", "system.
|
|
1404
|
+
declare const SYSTEM_METHODS: readonly ["system.projects", "system.workspace", "system.open", "system.getPresentationPreferences", "system.setTheme", "system.setWindowMaterial", "system.copyText", "system.openExternal", "system.navigationReady", "system.completeNavigation"];
|
|
1407
1405
|
interface SystemMethodMap {
|
|
1408
1406
|
"system.projects": {
|
|
1409
1407
|
params: ProjectRequest;
|
|
@@ -1413,15 +1411,6 @@ interface SystemMethodMap {
|
|
|
1413
1411
|
params: LocalWorkspaceRequest;
|
|
1414
1412
|
result: LocalWorkspaceResult;
|
|
1415
1413
|
};
|
|
1416
|
-
"system.pickFile": {
|
|
1417
|
-
params: {
|
|
1418
|
-
filters?: {
|
|
1419
|
-
name: string;
|
|
1420
|
-
extensions: string[];
|
|
1421
|
-
}[];
|
|
1422
|
-
};
|
|
1423
|
-
result: string | null;
|
|
1424
|
-
};
|
|
1425
1414
|
"system.open": {
|
|
1426
1415
|
params: SystemOpenWireInput;
|
|
1427
1416
|
result: {
|
|
@@ -1484,8 +1473,6 @@ interface AppHostSystem {
|
|
|
1484
1473
|
workspace<A extends LocalWorkspaceRequest["action"]>(input: Extract<LocalWorkspaceRequest, {
|
|
1485
1474
|
action: A;
|
|
1486
1475
|
}>): Promise<LocalWorkspaceResult<A>>;
|
|
1487
|
-
/** Opens the file picker for the built-in workbench and returns the selected local path. */
|
|
1488
|
-
pickFile(input?: SystemMethodMap["system.pickFile"]["params"]): Promise<string | null>;
|
|
1489
1476
|
open(input: SystemOpenInput): Promise<{
|
|
1490
1477
|
opened: true;
|
|
1491
1478
|
}>;
|
|
@@ -1684,11 +1671,6 @@ declare function createAppAuxiliarySessionsApi(rpc: {
|
|
|
1684
1671
|
request<M extends AuxiliaryMethod>(method: M, params: AuxiliaryMethodMap[M]["params"]): Promise<AuxiliaryMethodMap[M]["result"]>;
|
|
1685
1672
|
}, streams: ConnectionStreams): AuxiliarySessionsGroup;
|
|
1686
1673
|
|
|
1687
|
-
interface AppHostSessions {
|
|
1688
|
-
preparation: ConversationPreparationGroup;
|
|
1689
|
-
auxiliary: AuxiliarySessionsGroup;
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
1674
|
interface ServiceConnection {
|
|
1693
1675
|
readonly baseUrl: string;
|
|
1694
1676
|
readonly apiVersion: string;
|
|
@@ -1928,6 +1910,11 @@ interface NativeWindowControls {
|
|
|
1928
1910
|
}
|
|
1929
1911
|
declare function createAppWindowApi(requester: WindowRequester, native?: NativeWindowControls): AppHostWindow;
|
|
1930
1912
|
|
|
1913
|
+
interface AppHostSessions {
|
|
1914
|
+
preparation: ConversationPreparationGroup;
|
|
1915
|
+
auxiliary: AuxiliarySessionsGroup;
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1931
1918
|
interface AppHostStorage {
|
|
1932
1919
|
get(key: string): Promise<StorageGetResult>;
|
|
1933
1920
|
set(key: string, value: JsonValue$1): Promise<void>;
|
|
@@ -1942,8 +1929,6 @@ interface AppHost {
|
|
|
1942
1929
|
lifecycle: AppHostLifecycle;
|
|
1943
1930
|
system: AppHostSystem;
|
|
1944
1931
|
window: AppHostWindow;
|
|
1945
|
-
/** Get the host-managed Agent connection authorized for the current page. */
|
|
1946
|
-
getAuthorizedAgentConnection(): Promise<AgentConnection>;
|
|
1947
1932
|
sessions: AppHostSessions;
|
|
1948
1933
|
desktop: AppHostDesktop;
|
|
1949
1934
|
attachments: AppHostAttachments;
|
|
@@ -2003,5 +1988,5 @@ interface PluginAppConversationInput {
|
|
|
2003
1988
|
|
|
2004
1989
|
declare function parsePluginAppComposerContexts(value: unknown): PluginAppConversationInput[];
|
|
2005
1990
|
|
|
2006
|
-
export { ATTACHMENTS_METHODS, AUXILIARY_METHODS, AppHostError, BROWSER_CAPTURE_PREVIEW_MAX_BYTES, COMMANDS_METHODS, DESKTOP_METHODS, RESOURCE_CATALOG_METHODS, SYSTEM_METHODS, SYSTEM_SETTINGS_SECTIONS, SYSTEM_SHORTCUT_IDS, WINDOW_METHODS, canonicalDesktopRequest, connectAppHost, createAppAttachmentsApi, createAppAuxiliarySessionsApi, createAppCommandsApi, createAppDesktopApi, createAppSystemApi, createAppWindowApi, createPageFetchClient, createResourceCatalogApi, isAuxiliaryMethod, isCommandsMethod, isDesktopMethod, isResourceCatalogMethod, isSystemMethod, isWindowMethod, parsePluginAppComposerContexts, validAppCommandSnapshot, validAppWindowState, validAttachmentsInput, validAttachmentsResult, validAuxiliaryInput, validAuxiliaryResult, validBrowserSnapshot, validCommandInvocation, validCommandReceipt, validCommandsInput, validDesktopEvent, validDesktopInput, validDesktopNavigationTarget, validDesktopResult, validDesktopResultForInput, validDesktopTarget, validPresentationSnapshot, validProjectRequest, validProjectSnapshot, validResourceCatalogInput, validResourceCatalogResult, validResourceChanged, validSessionSettingsTarget, validSystemEvent, validSystemInput, validSystemResult, validWindowEvent, validWindowInput, validWindowResult, validWorkspaceOperation };
|
|
1991
|
+
export { ATTACHMENTS_METHODS, AUXILIARY_METHODS, AppHostError, BROWSER_CAPTURE_PREVIEW_MAX_BYTES, COMMANDS_METHODS, DESKTOP_METHODS, RESOURCE_CATALOG_METHODS, SYSTEM_METHODS, SYSTEM_SETTINGS_SECTIONS, SYSTEM_SHORTCUT_IDS, WINDOW_METHODS, canonicalDesktopRequest, connectAgent, connectAppHost, createAppAttachmentsApi, createAppAuxiliarySessionsApi, createAppCommandsApi, createAppDesktopApi, createAppSystemApi, createAppWindowApi, createPageFetchClient, createResourceCatalogApi, isAuxiliaryMethod, isCommandsMethod, isDesktopMethod, isResourceCatalogMethod, isSystemMethod, isWindowMethod, parsePluginAppComposerContexts, validAppCommandSnapshot, validAppWindowState, validAttachmentsInput, validAttachmentsResult, validAuxiliaryInput, validAuxiliaryResult, validBrowserSnapshot, validCommandInvocation, validCommandReceipt, validCommandsInput, validDesktopEvent, validDesktopInput, validDesktopNavigationTarget, validDesktopResult, validDesktopResultForInput, validDesktopTarget, validPresentationSnapshot, validProjectRequest, validProjectSnapshot, validResourceCatalogInput, validResourceCatalogResult, validResourceChanged, validSessionSettingsTarget, validSystemEvent, validSystemInput, validSystemResult, validWindowEvent, validWindowInput, validWindowResult, validWorkspaceOperation };
|
|
2007
1992
|
export type { AgentConnection, AnnotationMode, AnnotationRect, AnnotationTarget, AppCommandRegistration, AppCommandSnapshot, AppContext, AppHost, AppHostAttachments, AppHostCommands, AppHostDesktop, AppHostErrorCode, AppHostErrorInfo, AppHostEvent, AppHostFileOperations, AppHostGitOperations, AppHostLifecycle, AppHostRetry, AppHostService, AppHostSessions, AppHostStorage, AppHostSystem, AppHostTerminalOperations, AppHostWindow, AppHostWorkspace, AppUnloadHandler, AppUnloadReason, AppUnloadRequest, AppWindowMaterialState, AppWindowOpenHostInput, AppWindowStartupResult, AppWindowState, AppWindowUpdateCheckResult, AppWindowUpdateState, AppearancePreferences, AttachmentsMethod, AttachmentsMethodMap, AuxiliaryMethod, AuxiliaryMethodMap, AuxiliaryOptions, AuxiliaryReceipt, AuxiliaryRequest, AuxiliarySelection, AuxiliarySessionsGroup, AuxiliaryWireRequest, BindDesktopTarget, BrowserAnnotationRecord, BrowserAnnotationSnapshot, BrowserPage, ClientConnection, CommandInvocation, CommandReceipt, CommandsMethod, CommandsMethodMap, ConnectParams, ConversationPreparationGroup, DesktopGitChange, DesktopMethod, DesktopMethodMap, DesktopNavigationTarget, DesktopOpener, DesktopRoot, DesktopSearch, DesktopTarget, DesktopTerminal, DesktopTerminalInfo, DesktopTerminalRequestOriginal, DesktopTerminalRequestReceipt, DesktopTerminalSnapshot, DesktopText, DesktopToolEvent, DesktopWindow, FileOperationOriginal, GitOperationOriginal, JsonValue$1 as JsonValue, LocalWorkspaceRequest, LocalWorkspaceResult, LoginResult, NavigationCompletionStatus, PluginAppActionReceipt, PluginAppActionResponse, PluginAppCatalog, PluginAppComposerContext, PluginAppHostState, PluginAppModelContext, PluginAppMount, PluginAppPreparedMessage, PluginAppPreparedTool, PluginAppRecord, PluginAppSource$1 as PluginAppSource, PluginAppSubmissionReceipt, PluginAppToolPolicy, PresentationSnapshot, ProjectRequest, ProjectSnapshot, ResourceCatalogMethod, ResourceCatalogMethodMap, ResourceChanged, ServiceConnection, ServiceConnectionDescriptor, ServiceStatus, ServiceWork, ServiceWorkState, SessionSettingsTarget, SessionSettingsWireTarget, StorageGetResult, StoredFile, SystemEvent, SystemMethod, SystemMethodMap, SystemOpenInput, SystemOpenWireInput, SystemProject, SystemRequester, SystemShortcutId, WindowMethod, WindowMethodMap, WindowRequester, WindowStateChanged, WorkspaceConversationCreation, WorkspaceConversationResult, WorkspaceDirectory, WorkspaceDirectoryPage, WorkspaceFilePage, WorkspaceOperation, WorkspaceOperationKind, WorkspaceOperationOriginal, WorkspaceRef, WorkspaceSelection, WorkspaceText };
|
package/dist/index.js
CHANGED
|
@@ -233,7 +233,6 @@ var APP_HOST_FEATURES = [
|
|
|
233
233
|
"service-v1",
|
|
234
234
|
"extended-errors-v1",
|
|
235
235
|
"workspace-v1",
|
|
236
|
-
"session-resources-v1",
|
|
237
236
|
"session-controls-v1",
|
|
238
237
|
"conversation-creation-session-v1",
|
|
239
238
|
"trusted-desktop-v1",
|
|
@@ -261,7 +260,7 @@ var FETCH_HEADERS_TIMEOUT_MS = 3e4;
|
|
|
261
260
|
var FETCH_IDLE_TIMEOUT_MS = 12e4;
|
|
262
261
|
function pageFetchHeadersTimeout(method, target2) {
|
|
263
262
|
const path = target2.split("?", 1)[0];
|
|
264
|
-
const preparesExtension = method === "GET" ? path === "/skills/marketplace" || path === "/plugins/marketplace/catalog" : method === "POST" && /^\/(?:skills\/marketplace\/install|plugins\/(?:archive|git|marketplace)\/(?:preview|install))$/.test(path ?? "");
|
|
263
|
+
const preparesExtension = method === "GET" ? path === "/skills/marketplace" || path === "/plugins/marketplace/catalog" : method === "POST" && /^\/(?:skills\/marketplace\/install|plugins\/(?:archive|git|marketplace)\/(?:preview|install)|plugins\/archive\/uploads(?:\/install)?)$/.test(path ?? "");
|
|
265
264
|
return preparesExtension ? 33e4 : FETCH_HEADERS_TIMEOUT_MS;
|
|
266
265
|
}
|
|
267
266
|
function isPageFetchFrame(value) {
|
|
@@ -285,17 +284,17 @@ function isPageFetchFrame(value) {
|
|
|
285
284
|
return size <= FETCH_METADATA_BYTES;
|
|
286
285
|
}
|
|
287
286
|
if (!entry || typeof entry !== "object") return false;
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
287
|
+
const array3 = Array.isArray(entry);
|
|
288
|
+
if (array3 ? Object.getPrototypeOf(entry) !== Array.prototype : ![Object.prototype, null].includes(Object.getPrototypeOf(entry)))
|
|
290
289
|
return false;
|
|
291
290
|
const keys3 = Reflect.ownKeys(entry);
|
|
292
|
-
if (keys3.length > FETCH_METADATA_BYTES ||
|
|
291
|
+
if (keys3.length > FETCH_METADATA_BYTES || array3 && keys3.length !== entry.length + 1)
|
|
293
292
|
return false;
|
|
294
293
|
return keys3.every((key) => {
|
|
295
|
-
if (
|
|
294
|
+
if (array3 && key === "length") return true;
|
|
296
295
|
const d = Object.getOwnPropertyDescriptor(entry, key);
|
|
297
296
|
size += typeof key === "string" ? key.length + 3 : 0;
|
|
298
|
-
return typeof key === "string" && d.enumerable && Object.hasOwn(d, "value") && (!
|
|
297
|
+
return typeof key === "string" && d.enumerable && Object.hasOwn(d, "value") && (!array3 || /^(0|[1-9][0-9]*)$/.test(key) && Number(key) < entry.length) && visit(d.value, depth + 1, depth === 0 && key === "bytes") && size <= FETCH_METADATA_BYTES;
|
|
299
298
|
});
|
|
300
299
|
};
|
|
301
300
|
if (!visit(value, 0) || !value || typeof value !== "object" || Array.isArray(value))
|
|
@@ -455,14 +454,14 @@ function json2(value, ancestors = /* @__PURE__ */ new Set(), depth = 0) {
|
|
|
455
454
|
return true;
|
|
456
455
|
if (typeof value === "number") return Number.isFinite(value);
|
|
457
456
|
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
457
|
+
const array3 = Array.isArray(value);
|
|
458
|
+
if (array3 ? Object.getPrototypeOf(value) !== Array.prototype || Reflect.ownKeys(value).length !== value.length + 1 : ![Object.prototype, null].includes(Object.getPrototypeOf(value)))
|
|
460
459
|
return false;
|
|
461
460
|
ancestors.add(value);
|
|
462
461
|
const result = Reflect.ownKeys(value).every((k) => {
|
|
463
|
-
if (
|
|
462
|
+
if (array3 && k === "length") return true;
|
|
464
463
|
const d = Object.getOwnPropertyDescriptor(value, k);
|
|
465
|
-
return typeof k === "string" && (!
|
|
464
|
+
return typeof k === "string" && (!array3 || /^(0|[1-9]\d*)$/.test(k) && Number(k) < value.length) && d.enumerable && Object.hasOwn(d, "value") && json2(d.value, ancestors, depth + 1);
|
|
466
465
|
});
|
|
467
466
|
ancestors.delete(value);
|
|
468
467
|
return result;
|
|
@@ -882,9 +881,68 @@ function createClientConnection(wire, streams) {
|
|
|
882
881
|
connections.set(connection, { owner: streams, id: connectionId });
|
|
883
882
|
return connection;
|
|
884
883
|
}
|
|
884
|
+
async function connectAgent() {
|
|
885
|
+
const page2 = typeof window === "undefined" ? void 0 : window;
|
|
886
|
+
if (!page2?.nomiNative?.agentConnection) throw new AppHostError("host_unavailable");
|
|
887
|
+
const readDescriptor = page2.nomiNative.agentConnection.bind(page2.nomiNative);
|
|
888
|
+
const descriptor = await readDescriptor().catch(() => {
|
|
889
|
+
throw new AppHostError("host_unavailable");
|
|
890
|
+
});
|
|
891
|
+
if (!descriptor || typeof descriptor.baseUrl !== "string" || typeof descriptor.token !== "string" || !descriptor.token || typeof descriptor.connectionId !== "string" || !/^[a-z0-9-]+$/i.test(descriptor.connectionId) || descriptor.defaultTaskLocation !== void 0 && descriptor.defaultTaskLocation !== "current" && descriptor.defaultTaskLocation !== "worktree")
|
|
892
|
+
throw new AppHostError("host_unavailable");
|
|
893
|
+
const { baseUrl, token, connectionId, defaultTaskLocation } = descriptor;
|
|
894
|
+
const endpoint = URL.parse(baseUrl);
|
|
895
|
+
if (!endpoint || endpoint.protocol !== "http:" || !["127.0.0.1", "[::1]"].includes(endpoint.hostname) || endpoint.username || endpoint.password || endpoint.pathname !== "/" || endpoint.search || endpoint.hash)
|
|
896
|
+
throw new AppHostError("host_unavailable");
|
|
897
|
+
let closed = false;
|
|
898
|
+
const fetchDaemon = async (input, init) => {
|
|
899
|
+
if (closed) throw new AppHostError("connection_revoked");
|
|
900
|
+
const original = input instanceof Request ? input : void 0;
|
|
901
|
+
const target2 = URL.parse(original?.url ?? String(input), endpoint);
|
|
902
|
+
if (!target2 || target2.origin !== endpoint.origin || target2.username || target2.password)
|
|
903
|
+
throw new AppHostError("invalid_request");
|
|
904
|
+
const headers = new Headers(init?.headers ?? original?.headers);
|
|
905
|
+
headers.set("authorization", "Bearer " + token);
|
|
906
|
+
headers.set("x-nomi-connection-id", connectionId);
|
|
907
|
+
const signal = init?.signal ?? original?.signal;
|
|
908
|
+
signal?.throwIfAborted();
|
|
909
|
+
let response;
|
|
910
|
+
try {
|
|
911
|
+
response = await fetch(original ?? target2, {
|
|
912
|
+
...init,
|
|
913
|
+
headers,
|
|
914
|
+
signal,
|
|
915
|
+
redirect: "error",
|
|
916
|
+
credentials: "omit",
|
|
917
|
+
cache: "no-store"
|
|
918
|
+
});
|
|
919
|
+
} catch (error) {
|
|
920
|
+
if (signal?.aborted) throw error;
|
|
921
|
+
const current = await readDescriptor().catch(() => void 0);
|
|
922
|
+
signal?.throwIfAborted();
|
|
923
|
+
if (!current || current.baseUrl !== baseUrl || current.connectionId !== connectionId || current.token !== token) closed = true;
|
|
924
|
+
throw new AppHostError("host_unavailable");
|
|
925
|
+
}
|
|
926
|
+
if (response.status === 401 || response.status === 403 && (await response.clone().json().catch(() => void 0))?.error === "connection_revoked") {
|
|
927
|
+
closed = true;
|
|
928
|
+
await response.body?.cancel().catch(() => {
|
|
929
|
+
});
|
|
930
|
+
throw new AppHostError("connection_revoked");
|
|
931
|
+
}
|
|
932
|
+
return response;
|
|
933
|
+
};
|
|
934
|
+
const connection = {
|
|
935
|
+
clientOptions: { baseUrl: endpoint.origin, fetch: fetchDaemon },
|
|
936
|
+
...defaultTaskLocation ? { defaultTaskLocation } : {},
|
|
937
|
+
isClosed: () => closed
|
|
938
|
+
};
|
|
939
|
+
connections.set(connection, { owner: page2, id: connectionId });
|
|
940
|
+
return connection;
|
|
941
|
+
}
|
|
885
942
|
function resolveClientConnection(connection, owner) {
|
|
886
943
|
const record4 = connections.get(connection);
|
|
887
|
-
if (!record4 || record4.owner !== owner
|
|
944
|
+
if (!record4 || record4.owner !== owner && record4.owner !== globalThis.window || connection.isClosed?.())
|
|
945
|
+
throw new AppHostError("connection_revoked");
|
|
888
946
|
return record4.id;
|
|
889
947
|
}
|
|
890
948
|
|
|
@@ -1109,14 +1167,8 @@ var project = { ...scope, projectId: id2, workspaceId: id2 };
|
|
|
1109
1167
|
function validProjectRequest(value) {
|
|
1110
1168
|
const action2 = value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1111
1169
|
switch (action2) {
|
|
1112
|
-
case "list":
|
|
1113
|
-
return object({ action: (v) => v === "list" })(value);
|
|
1114
1170
|
case "register":
|
|
1115
1171
|
return object({ action: (v) => v === "register", ...scope, workspaceId: id2 })(value);
|
|
1116
|
-
case "setDefaultShell":
|
|
1117
|
-
return object({ action: (v) => v === "setDefaultShell", ...project, shell: (v) => v === null || text(4096)(v) })(value);
|
|
1118
|
-
case "archive":
|
|
1119
|
-
return object({ action: (v) => v === "archive", ...project })(value);
|
|
1120
1172
|
case "rebind":
|
|
1121
1173
|
return object({ action: (v) => v === "rebind", ...project, previousWorkspaceId: id2, expectedPath: text(32768) })(value);
|
|
1122
1174
|
default:
|
|
@@ -1136,6 +1188,7 @@ var root2 = { rootPath: text(32768) };
|
|
|
1136
1188
|
var identity = { identity: object({ dev: text(32), ino: text(32) }) };
|
|
1137
1189
|
var file = { ...root2, path: text(32768) };
|
|
1138
1190
|
var write = { ...file, requestId: id, content: text(125e4, true), originalContent: text(125e4, true) };
|
|
1191
|
+
var gitRead = { ...identity, range: enumeration("uncommitted", "working", "staged"), ignoreWhitespace: bool };
|
|
1139
1192
|
var actionOf = (value) => value && typeof value === "object" ? Object.getOwnPropertyDescriptor(value, "action")?.value : void 0;
|
|
1140
1193
|
function validLocalWorkspaceRequest(value) {
|
|
1141
1194
|
const action2 = actionOf(value);
|
|
@@ -1148,6 +1201,10 @@ function validLocalWorkspaceRequest(value) {
|
|
|
1148
1201
|
return object({ ...field, ...root2 }, { ...identity, path: text(32768, true) })(value);
|
|
1149
1202
|
case "find":
|
|
1150
1203
|
return object({ ...field, ...root2, query: text(1024) }, identity)(value);
|
|
1204
|
+
case "gitChanges":
|
|
1205
|
+
return object({ ...field, ...root2 }, gitRead)(value);
|
|
1206
|
+
case "gitDiff":
|
|
1207
|
+
return object({ ...field, ...root2 }, { ...gitRead, path: text(32768), base: text(512), head: text(512) })(value);
|
|
1151
1208
|
case "write":
|
|
1152
1209
|
case "getWrite":
|
|
1153
1210
|
return object({ ...field, ...write }, identity)(value);
|
|
@@ -1201,7 +1258,9 @@ var checks = {
|
|
|
1201
1258
|
openWith: empty,
|
|
1202
1259
|
copyPath: empty,
|
|
1203
1260
|
listOpeners: openers,
|
|
1204
|
-
webPreview: url
|
|
1261
|
+
webPreview: url,
|
|
1262
|
+
gitChanges: (value) => validDesktopResult("desktop.git.changes", value),
|
|
1263
|
+
gitDiff: (value) => validDesktopResult("desktop.git.diff", value)
|
|
1205
1264
|
};
|
|
1206
1265
|
function validLocalWorkspaceResult(value, action2) {
|
|
1207
1266
|
return action2 ? checks[action2](value) : Object.values(checks).some((check) => check(value));
|
|
@@ -1247,7 +1306,6 @@ var SYSTEM_SHORTCUT_IDS = [
|
|
|
1247
1306
|
var SYSTEM_METHODS = [
|
|
1248
1307
|
"system.projects",
|
|
1249
1308
|
"system.workspace",
|
|
1250
|
-
"system.pickFile",
|
|
1251
1309
|
"system.open",
|
|
1252
1310
|
"system.getPresentationPreferences",
|
|
1253
1311
|
"system.setTheme",
|
|
@@ -1348,13 +1406,6 @@ function validSystemInput(method, value) {
|
|
|
1348
1406
|
return validProjectRequest(value);
|
|
1349
1407
|
case "system.workspace":
|
|
1350
1408
|
return validLocalWorkspaceRequest(value);
|
|
1351
|
-
case "system.pickFile":
|
|
1352
|
-
return object({}, {
|
|
1353
|
-
filters: array(object({
|
|
1354
|
-
name: text(100),
|
|
1355
|
-
extensions: array((extension) => typeof extension === "string" && /^[a-z0-9][a-z0-9.-]{0,15}$/i.test(extension), 16)
|
|
1356
|
-
}), 16)
|
|
1357
|
-
})(value);
|
|
1358
1409
|
case "system.setTheme":
|
|
1359
1410
|
return object({ theme: themeMode })(value);
|
|
1360
1411
|
case "system.setWindowMaterial":
|
|
@@ -1397,8 +1448,6 @@ function validSystemResult(method, value) {
|
|
|
1397
1448
|
return validProjectSnapshot(value);
|
|
1398
1449
|
case "system.workspace":
|
|
1399
1450
|
return validLocalWorkspaceResult(value);
|
|
1400
|
-
case "system.pickFile":
|
|
1401
|
-
return nullable(text(4096))(value);
|
|
1402
1451
|
case "system.open":
|
|
1403
1452
|
return object({ opened: enumeration(true) })(value);
|
|
1404
1453
|
case "system.getPresentationPreferences":
|
|
@@ -1438,7 +1487,6 @@ function createAppSystemApi(requester, connectionOwner) {
|
|
|
1438
1487
|
if (!validLocalWorkspaceResult(result, input.action)) throw new AppHostError("host_unavailable");
|
|
1439
1488
|
return result;
|
|
1440
1489
|
}),
|
|
1441
|
-
pickFile: (input = {}) => send("system.pickFile", input),
|
|
1442
1490
|
open: (input) => {
|
|
1443
1491
|
if (input.page !== "session-settings") return send("system.open", input);
|
|
1444
1492
|
const { target: target2 } = input;
|
|
@@ -1690,27 +1738,6 @@ function createAppWorkspaceApi(input) {
|
|
|
1690
1738
|
};
|
|
1691
1739
|
}
|
|
1692
1740
|
|
|
1693
|
-
// src/session-resources.ts
|
|
1694
|
-
function resourceFields(v, required, optional = []) {
|
|
1695
|
-
if (!v || typeof v !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(v))) return false;
|
|
1696
|
-
return required.every((k) => Object.hasOwn(v, k)) && Reflect.ownKeys(v).every((k) => {
|
|
1697
|
-
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
1698
|
-
return typeof k === "string" && [...required, ...optional].includes(k) && d.enumerable && Object.hasOwn(d, "value");
|
|
1699
|
-
});
|
|
1700
|
-
}
|
|
1701
|
-
var str2 = (v, max = 256) => typeof v === "string" && v.length > 0 && v.length <= max;
|
|
1702
|
-
function validSessionResourceResult(_method, v) {
|
|
1703
|
-
return resourceFields(v, ["connectionId", "baseUrl"], ["defaultTaskLocation"]) && (!Object.hasOwn(v, "defaultTaskLocation") || v.defaultTaskLocation === "current" || v.defaultTaskLocation === "worktree") && str2(v.connectionId) && /^[A-Za-z0-9-]+$/.test(v.connectionId) && v.baseUrl === `https://app-host.invalid/connections/${v.connectionId}`;
|
|
1704
|
-
}
|
|
1705
|
-
function bindAuthorizedAgentConnection(input, streams) {
|
|
1706
|
-
return async (...args) => {
|
|
1707
|
-
if (args.length !== 0) throw new AppHostError("invalid_request");
|
|
1708
|
-
input.requireFeature();
|
|
1709
|
-
const wire = await input.request("getAuthorizedAgentConnection", {});
|
|
1710
|
-
return createClientConnection(wire, streams);
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
1741
|
// src/service.ts
|
|
1715
1742
|
function createAppServiceApi(rpc, streams) {
|
|
1716
1743
|
const request = async (method, params) => rpc.request(method, params);
|
|
@@ -1829,7 +1856,6 @@ var APP_HOST_METHODS = [
|
|
|
1829
1856
|
"storage.get",
|
|
1830
1857
|
"storage.set",
|
|
1831
1858
|
"storage.delete",
|
|
1832
|
-
"getAuthorizedAgentConnection",
|
|
1833
1859
|
"service.getStatus",
|
|
1834
1860
|
"service.getConnection",
|
|
1835
1861
|
"service.listWork",
|
|
@@ -2313,8 +2339,6 @@ function validResult(method, value) {
|
|
|
2313
2339
|
if (isAuxiliaryMethod(method)) return validAuxiliaryResult(method, value);
|
|
2314
2340
|
if (isConversationPreparationMethod(method))
|
|
2315
2341
|
return validConversationPreparationResult(method, value);
|
|
2316
|
-
if (method === "getAuthorizedAgentConnection")
|
|
2317
|
-
return validSessionResourceResult(method, value);
|
|
2318
2342
|
if (method.startsWith("workspace."))
|
|
2319
2343
|
return validWorkspaceResult(method, value);
|
|
2320
2344
|
if (method.startsWith("service."))
|
|
@@ -2649,13 +2673,6 @@ var DocumentConnection = class {
|
|
|
2649
2673
|
},
|
|
2650
2674
|
this.fetchClient
|
|
2651
2675
|
),
|
|
2652
|
-
getAuthorizedAgentConnection: bindAuthorizedAgentConnection(
|
|
2653
|
-
{
|
|
2654
|
-
requireFeature: () => this.requireFeature("session-resources-v1"),
|
|
2655
|
-
request: (method, params2) => this.request(method, params2)
|
|
2656
|
-
},
|
|
2657
|
-
this.fetchClient
|
|
2658
|
-
),
|
|
2659
2676
|
sessions: {
|
|
2660
2677
|
preparation: conversationPreparation,
|
|
2661
2678
|
auxiliary: createAppAuxiliarySessionsApi(
|
|
@@ -2756,7 +2773,7 @@ var DocumentConnection = class {
|
|
|
2756
2773
|
const selectionRequestId = method === "workspace.select" ? params.requestId : void 0;
|
|
2757
2774
|
let timeout = APP_HOST_REQUEST_TIMEOUT_MS;
|
|
2758
2775
|
if (method === "workbench.computer.stopLocal") timeout = 1e3;
|
|
2759
|
-
if (method === "auth.openLogin" || method === "workspace.select" || method === "
|
|
2776
|
+
if (method === "auth.openLogin" || method === "workspace.select" || method === "workbench.computer.shareWindow" || method === "system.workspace" && "action" in params && params.action === "pick")
|
|
2760
2777
|
timeout = APP_HOST_LOGIN_TRANSPORT_TIMEOUT_MS;
|
|
2761
2778
|
return new Promise((resolve, reject) => {
|
|
2762
2779
|
const id3 = String(++this.nextId);
|
|
@@ -2825,14 +2842,14 @@ function copyBoundedJson(value, options) {
|
|
|
2825
2842
|
return item;
|
|
2826
2843
|
}
|
|
2827
2844
|
if (typeof item !== "object" || item === null || depth >= maxDepth || ancestors.has(item)) throw new JsonCopyError("invalid_json");
|
|
2828
|
-
const
|
|
2829
|
-
if (!
|
|
2845
|
+
const array3 = Array.isArray(item);
|
|
2846
|
+
if (!array3 && Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null) throw new JsonCopyError("invalid_json");
|
|
2830
2847
|
const descriptors = Object.getOwnPropertyDescriptors(item);
|
|
2831
2848
|
if (Object.getOwnPropertySymbols(item).length || Object.values(descriptors).some((descriptor) => descriptor.get || descriptor.set)) throw new JsonCopyError("invalid_json");
|
|
2832
2849
|
ancestors.add(item);
|
|
2833
|
-
spend(
|
|
2850
|
+
spend(array3 ? "[]" : "{}");
|
|
2834
2851
|
try {
|
|
2835
|
-
if (
|
|
2852
|
+
if (array3) {
|
|
2836
2853
|
const result2 = [];
|
|
2837
2854
|
if (Object.keys(item).length !== item.length) throw new JsonCopyError("invalid_json");
|
|
2838
2855
|
for (let index = 0; index < item.length; index++) {
|
|
@@ -2987,6 +3004,7 @@ export {
|
|
|
2987
3004
|
AppHostError,
|
|
2988
3005
|
WINDOW_METHODS,
|
|
2989
3006
|
canonicalDesktopRequest,
|
|
3007
|
+
connectAgent,
|
|
2990
3008
|
connectAppHost,
|
|
2991
3009
|
createAppWindowApi,
|
|
2992
3010
|
createPageFetchClient,
|