@xopcai/xopc 0.0.273 → 0.0.274
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/dist/browser-ext/dist/assets/{auth-DkwOUI6_.js → auth-O8RiOF3l.js} +198 -81
- package/dist/browser-ext/dist/background.js +1 -1
- package/dist/browser-ext/dist/sidepanel.html +1 -1
- package/dist/browser-ext/dist/sidepanel.js +46 -16
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-cF7IX2RP.js → activity-store-SJZ5fS17.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BrgxX8nG.js → agent-avatar-dicebear-BckaANxj.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-DvhuRCLA.js → agent-defaults-settings-panel-B8eyC6K1.js} +1 -1
- package/dist/gateway/static/root/assets/agents-CSWj_yo1.js +1 -0
- package/dist/gateway/static/root/assets/{api-CYkdUpkx.js → api-CnJAVHBu.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-DfoNzWIa.js → app-management-settings-panel-DY-Zbgmt.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-czbLdCqj.js → appearance-settings-CoJR7ZRl.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-BSJXKWcE.js → apps-page-CSMvkuot.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-D14P13mX.js → archive-plugin-BwAlRT53.js} +1 -1
- package/dist/gateway/static/root/assets/attachment-load-R835uxgL.js +1 -0
- package/dist/gateway/static/root/assets/{attachment-preview-renderer-BDTD8YUe.js → attachment-preview-renderer-CfEDFYPE.js} +1 -1
- package/dist/gateway/static/root/assets/attachment-process-heavy-C5CqLCsX.js +5 -0
- package/dist/gateway/static/root/assets/{automations-page-DM7ZEewI.js → automations-page-BEZy0P_u.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-CpaI13J7.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-CxNg6InF.js → binary-plugins-CESFx3yb.js} +2 -2
- package/dist/gateway/static/root/assets/{block-editor-D22VcYnC.js → block-editor-DDJcf2wR.js} +3 -3
- package/dist/gateway/static/root/assets/{browser-automation-inputs-6NWTLEpd.js → browser-automation-inputs-DGCqIPXT.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-BrqySdbW.js → browser-automations-page-BH4lSfr5.js} +2 -2
- package/dist/gateway/static/root/assets/browser-settings-page-CbTooPd2.js +8 -0
- package/dist/gateway/static/root/assets/capabilities-settings-panel-C4LZWHhv.js +8 -0
- package/dist/gateway/static/root/assets/channels-settings-BAljmSa7.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-BUZimNmp.js → channels-status-swr-BTT2sIGg.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-CZPBNpMI.js → chat-terminal-dock-D8U97O95.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-CVRMjNNr.js +2 -0
- package/dist/gateway/static/root/assets/{date-picker-Da_0QyLe.js → date-picker-7sDSMswL.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-D_djqzy7.js → dependency-picker-DMIC86ZW.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-Celmbw-T.js → desktop-pet-BtdiY5jK.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-CqNNgF45.js → desktop-pet-settings-D_B8azDH.js} +1 -1
- package/dist/gateway/static/root/assets/device-pairing-wizard-Dmh3Nh4d.js +1 -0
- package/dist/gateway/static/root/assets/excel-worksheet-utils-DpdB-DjU.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-ku3kCjvH.js → extension-debug-page-CoFKb01d.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-C7FpHwL4.js → extension-page-CEkNsCAY.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-OMj2tU2_.js → extension-settings-page-Bi2R8P5j.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-6eb1vKE1.js → gateway-config-swr-cd8owslz.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-q9p3sduo.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DUFFCU8H.js → gateway-startup-retry-CVTa5HSS.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-CSFzOACM.js → heartbeat-settings-DQtelFiU.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-COpGnTFZ.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-C1cHRBRp.js → image-generation-api-DtMRG1oF.js} +1 -1
- package/dist/gateway/static/root/assets/{index-C6OWYFtQ.js → index-SxqsTD4i.js} +35 -35
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BuvD3iv8.js → keyboard-shortcuts-settings-BuYmZS1K.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-DV_17Zxc.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DdJ8zwBp.js → local-apps-page-CExnZyGZ.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-BBSCIl4I.js → locale-store-BkJ7g35d.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-BaR2he0K.js → logs-page-CA5ArMoN.js} +2 -2
- package/dist/gateway/static/root/assets/management-settings-1UiJPrkX.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-c5vtnYe8.js → markdown-view-B2IR4E2r.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-D_a6GDY6.js → media-plugins-nNFOk9HL.js} +1 -1
- package/dist/gateway/static/root/assets/{messages-DjuBdDCn.js → messages-BGc-OJWg.js} +2 -2
- package/dist/gateway/static/root/assets/note-detail-panel-B5OQ0fBY.js +5 -0
- package/dist/gateway/static/root/assets/notes-page-CVPPMVDl.js +8 -0
- package/dist/gateway/static/root/assets/{page-tabs-C7Le9bSI.js → page-tabs-CRombigq.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-B2pOxJBK.js → preview-open-alternatives-Bcuj43lk.js} +1 -1
- package/dist/gateway/static/root/assets/{proactive-card-BlQ1vCtV.js → proactive-card-Cb3Xeoyx.js} +1 -1
- package/dist/gateway/static/root/assets/{proactive-page-CghKTfYa.js → proactive-page-TbF9KVpm.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-DpjiHgwu.js → product-open-page-DsQcgZkI.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-B9OQ2l9x.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-DCqSTNkY.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-CyQ4k1Ux.js → registry-api-CTq8EECj.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-d9Fg70gX.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Bl4ArLHf.js → runtime-tools-settings-panel-BudlvBu-.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-KQFmfWd4.js → schema-form-Ch3MEX4h.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-D8RiQ-ag.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-DVH_l6Hr.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-Dbnls9ty.js → settings-form-section-CIA1AA-A.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-CDKirYRG.js → settings-page-B0Khoduh.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-SQmtWoOs.js → setup-status-panel-COJFl4N_.js} +1 -1
- package/dist/gateway/static/root/assets/share-preview-page-Cj9XWg-X.js +2 -0
- package/dist/gateway/static/root/assets/shares-settings-_OuE6A0G.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BM4Ezjbx.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-Bd0_ED_p.js → skills-page-Dyh1kf9t.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-rA-XT-YG.js → skills-page.utils-DsQZkMti.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CSkMrHLz.js → system-settings-panel-BSho_Tpk.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-B5HWM12k.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-DWpIEWen.js → theme-store-mV6Cm2vj.js} +1 -1
- package/dist/gateway/static/root/assets/tunnel-api-4DUHxSQG.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-DkQAIAuB.js → use-autosave-BG8Yx7hj.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-IjVyv5jj.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-BrqcH0P-.js → voice-api-key-field-DYXwDhHq.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-BJ95Z3pT.js → voice-config-api-D3DdcH4H.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-vfTWKm13.js → work-discovery-overlay-CQqjzaRo.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CHdr_ng9.js → workflow-run-setup-panel-C5H-Fd-U.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-D1hMyPsY.js +6 -0
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/device-pairing.js +41 -2
- package/dist/src/agent/service.js +20 -16
- package/dist/src/browser/native-messaging-host.d.ts +1 -1
- package/dist/src/browser/native-messaging-host.js +3 -2
- package/dist/src/gateway/hono/app.js +5 -2
- package/dist/src/gateway/hono/routes/agent-stream.js +1 -1
- package/dist/src/gateway/hono/routes/device-pairing-approval.d.ts +9 -2
- package/dist/src/gateway/hono/routes/device-pairing-approval.js +50 -10
- package/dist/src/gateway/hono/routes/devices.d.ts +2 -1
- package/dist/src/gateway/hono/routes/devices.js +33 -16
- package/dist/src/gateway/hono/routes/session-input-handler.d.ts +1 -1
- package/dist/src/gateway/hono/routes/session-input-handler.js +1 -1
- package/dist/src/gateway/hono/routes/side-chats.js +1 -1
- package/dist/src/gateway/hono/routes/tunnel.js +34 -2
- package/dist/src/gateway/rate-limit/buckets.js +2 -1
- package/dist/src/gateway/service/run-gateway-agent.js +1 -1
- package/dist/src/storage/sqlite/device-pairing-approval.js +3 -1
- package/dist/src/tui/tui.js +1 -1
- package/dist/src/tunnel/xopc-cloud-registration.d.ts +5 -0
- package/dist/src/tunnel/xopc-cloud-registration.js +17 -11
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agents-C0By2FIo.js +0 -1
- package/dist/gateway/static/root/assets/attachment-load-Dok_B1Gv.js +0 -2
- package/dist/gateway/static/root/assets/attachment-process-heavy-B2_kr5EA.js +0 -11
- package/dist/gateway/static/root/assets/automations-workspace--1TsZf3O.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-DOHgQer_.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Bpse_5K-.js +0 -8
- package/dist/gateway/static/root/assets/channels-settings-yHsY174W.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-B_wLKGnH.js +0 -2
- package/dist/gateway/static/root/assets/device-pairing-wizard-B5_w9qlm.js +0 -1
- package/dist/gateway/static/root/assets/excel-worksheet-utils-EyvwNT4X.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-CH-6vkgN.js +0 -1
- package/dist/gateway/static/root/assets/home-page-BJebAKB-.js +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CaC4-THD.js +0 -2
- package/dist/gateway/static/root/assets/management-settings-r-iYWZFY.js +0 -1
- package/dist/gateway/static/root/assets/note-detail-panel-BV6nbgac.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-BmLKoWwi.js +0 -8
- package/dist/gateway/static/root/assets/project-detail-page-CV8Lh296.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-COweOaJP.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-ChPPGVU5.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-DgmHibOK.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DV7kMco2.js +0 -1
- package/dist/gateway/static/root/assets/share-preview-page-DwgLjS1m.js +0 -2
- package/dist/gateway/static/root/assets/shares-settings-Cs5bUrYw.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DyKrjq7F.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-CEQU-L_G.js +0 -1
- package/dist/gateway/static/root/assets/tunnel-api-COJcGnEi.js +0 -1
- package/dist/gateway/static/root/assets/user-model-page-BQAU55lf.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-hwRJD7vR.js +0 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closeXopcDatabase, openXopcDatabase } from "../storage/sqlite/connection.js";
|
|
2
|
+
import { devicePairingInvitationPayloadSchema, formatBrowserPairingInvitation } from "../../packages/gateway-contract/src/device-pairing.js";
|
|
2
3
|
import { getGatewayIdentityPublicKeyRaw, getOrCreateGatewayIdentity } from "../storage/sqlite/gateway-identity-repository.js";
|
|
3
4
|
import { createDevicePairingSetup } from "../storage/sqlite/device-pairing-repository.js";
|
|
4
5
|
import { init_loader, loadConfig } from "../config/loader.js";
|
|
@@ -49,7 +50,7 @@ function createBrowserNativeBootstrap(configPath, request) {
|
|
|
49
50
|
return {
|
|
50
51
|
ok: true,
|
|
51
52
|
gatewayUrl,
|
|
52
|
-
|
|
53
|
+
invitation: formatBrowserPairingInvitation(Buffer.from(JSON.stringify(devicePairingInvitationPayloadSchema.parse({
|
|
53
54
|
version: 3,
|
|
54
55
|
pairingToken: setup.token,
|
|
55
56
|
gatewayId: identity.id,
|
|
@@ -58,7 +59,7 @@ function createBrowserNativeBootstrap(configPath, request) {
|
|
|
58
59
|
routes: [route],
|
|
59
60
|
targetKind: setup.targetKind,
|
|
60
61
|
expiresAt: setup.expiresAt
|
|
61
|
-
})).toString("base64url")
|
|
62
|
+
}))).toString("base64url")),
|
|
62
63
|
expiresAt: setup.expiresAt
|
|
63
64
|
};
|
|
64
65
|
} finally {
|
|
@@ -5,8 +5,8 @@ import { resolveAllowedBrowserOrigins, resolveGatewayServiceListenPort } from ".
|
|
|
5
5
|
import { resolveGatewayEffectiveHost } from "../../config/gateway-bind.js";
|
|
6
6
|
import { loadTunnelState } from "../../tunnel/tunnel-state.js";
|
|
7
7
|
import { resolveReverseProxyPublicUrl } from "../public-url.js";
|
|
8
|
-
import { BROWSER_EXTENSION_ID } from "../../browser/extension-identity.js";
|
|
9
8
|
import { maxSessionInputRequestBodyBytes } from "../chat-limits.js";
|
|
9
|
+
import { BROWSER_EXTENSION_ID } from "../../browser/extension-identity.js";
|
|
10
10
|
import { isLoopbackIpAddress, isTrustedProxyAddress } from "../client-ip.js";
|
|
11
11
|
import { buildGatewayConsoleCspHeader } from "../security/csp.js";
|
|
12
12
|
import { checkBrowserOrigin, isChromeExtensionOrigin } from "../security/origin-check.js";
|
|
@@ -217,7 +217,10 @@ function createHonoApp(config) {
|
|
|
217
217
|
});
|
|
218
218
|
registerPublicGatewayRoutes(app, service);
|
|
219
219
|
registerPublicHtmlPreviewRoute(app);
|
|
220
|
-
registerDeviceAuthPublicRoutes(app)
|
|
220
|
+
registerDeviceAuthPublicRoutes(app, { getTrustedProxyContext: () => ({
|
|
221
|
+
trustedProxies: service.currentConfig.gateway?.trustedProxies,
|
|
222
|
+
allowRealIpFallback: service.currentConfig.gateway?.allowRealIpFallback === true
|
|
223
|
+
}) });
|
|
221
224
|
registerPublicExtensionAssetRoutes(app, service);
|
|
222
225
|
registerPublicLocalAppPreviewRoutes(app, service);
|
|
223
226
|
const authenticated = new Hono();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { parseTurnContextRefs } from "../../../agent/source-context/types.js";
|
|
2
1
|
import { validateWebchatAttachments, validateWebchatContent } from "../../chat-limits.js";
|
|
2
|
+
import { parseTurnContextRefs } from "../../../agent/source-context/types.js";
|
|
3
3
|
import { replaceLatestSessionTurn, submitSessionInput } from "./session-input-handler.js";
|
|
4
4
|
//#region src/gateway/hono/routes/agent-stream.ts
|
|
5
5
|
function registerAgentStreamRoutes(authenticated, deps) {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type { Hono } from 'hono';
|
|
2
|
-
export
|
|
1
|
+
import type { Context, Hono } from 'hono';
|
|
2
|
+
export type PairingPublicRouteOptions = {
|
|
3
|
+
getTrustedProxyContext?: () => {
|
|
4
|
+
trustedProxies?: string[];
|
|
5
|
+
allowRealIpFallback?: boolean;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function pairingClientKey(c: Context, options?: PairingPublicRouteOptions): string;
|
|
9
|
+
export declare function registerPairingApprovalPublicRoutes(app: Hono, options?: PairingPublicRouteOptions): void;
|
|
3
10
|
export declare function registerPairingApprovalAdminRoutes(app: Hono): void;
|
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
import { devicePairingCompleteSchema, devicePairingProofSchema, devicePairingRequestSchema } from "../../../../packages/gateway-contract/src/device-pairing.js";
|
|
2
2
|
import { getOrCreateGatewayIdentity, signGatewayPayload } from "../../../storage/sqlite/gateway-identity-repository.js";
|
|
3
|
+
import { resolveClientIpFromRequest } from "../../client-ip.js";
|
|
4
|
+
import { buckets } from "../../rate-limit/buckets.js";
|
|
5
|
+
import "../../rate-limit/index.js";
|
|
3
6
|
import { DevicePairingError, cancelDevicePairingSetup, decideDevicePairingRequest, operateDevicePairingRequest, readDevicePairingSetup, submitDevicePairingRequest } from "../../../storage/sqlite/device-pairing-approval.js";
|
|
4
7
|
import os from "node:os";
|
|
5
8
|
import { z } from "zod";
|
|
9
|
+
import { bodyLimit } from "hono/body-limit";
|
|
10
|
+
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
6
11
|
//#region src/gateway/hono/routes/device-pairing-approval.ts
|
|
12
|
+
function pairingClientKey(c, options) {
|
|
13
|
+
let remoteAddress;
|
|
14
|
+
try {
|
|
15
|
+
remoteAddress = getConnInfo(c).remote.address;
|
|
16
|
+
} catch {
|
|
17
|
+
remoteAddress = void 0;
|
|
18
|
+
}
|
|
19
|
+
const proxy = options?.getTrustedProxyContext?.();
|
|
20
|
+
return resolveClientIpFromRequest({
|
|
21
|
+
remoteAddress,
|
|
22
|
+
getHeader: (name) => c.req.header(name),
|
|
23
|
+
trustedProxies: proxy?.trustedProxies,
|
|
24
|
+
allowRealIpFallback: proxy?.allowRealIpFallback
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function pairingBlocked(c, key) {
|
|
28
|
+
const blocked = buckets.pairingExchange().check(key);
|
|
29
|
+
if (!blocked.blocked) return void 0;
|
|
30
|
+
c.header("Retry-After", String(blocked.retryAfterSec));
|
|
31
|
+
return c.json({
|
|
32
|
+
ok: false,
|
|
33
|
+
error: {
|
|
34
|
+
code: "PAIRING_RATE_LIMITED",
|
|
35
|
+
message: "Too many failed pairing attempts"
|
|
36
|
+
}
|
|
37
|
+
}, 429);
|
|
38
|
+
}
|
|
7
39
|
function pairingError(c, error) {
|
|
8
40
|
if (error instanceof DevicePairingError) return c.json({
|
|
9
41
|
ok: false,
|
|
@@ -20,7 +52,7 @@ function pairingError(c, error) {
|
|
|
20
52
|
}
|
|
21
53
|
}, 500);
|
|
22
54
|
}
|
|
23
|
-
function registerPairingApprovalPublicRoutes(app) {
|
|
55
|
+
function registerPairingApprovalPublicRoutes(app, options) {
|
|
24
56
|
for (const action of [
|
|
25
57
|
"request",
|
|
26
58
|
"status",
|
|
@@ -28,15 +60,21 @@ function registerPairingApprovalPublicRoutes(app) {
|
|
|
28
60
|
"cancel"
|
|
29
61
|
]) {
|
|
30
62
|
const path = action === "request" ? "/api/device-pairing/requests" : `/api/device-pairing/requests/:id/${action}`;
|
|
31
|
-
app.post(path, async (c) => {
|
|
63
|
+
app.post(path, bodyLimit({ maxSize: 4 * 1024 }), async (c) => {
|
|
64
|
+
const clientKey = pairingClientKey(c, options);
|
|
65
|
+
const blocked = pairingBlocked(c, clientKey);
|
|
66
|
+
if (blocked) return blocked;
|
|
32
67
|
const parsed = (action === "request" ? devicePairingRequestSchema : action === "complete" ? devicePairingCompleteSchema : devicePairingProofSchema).safeParse(await c.req.json().catch(() => null));
|
|
33
|
-
if (!parsed.success || action !== "request" && parsed.data.requestId !== c.req.param("id"))
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
68
|
+
if (!parsed.success || action !== "request" && parsed.data.requestId !== c.req.param("id")) {
|
|
69
|
+
buckets.pairingExchange().fail(clientKey);
|
|
70
|
+
return c.json({
|
|
71
|
+
ok: false,
|
|
72
|
+
error: {
|
|
73
|
+
code: "BAD_REQUEST",
|
|
74
|
+
message: "Invalid pairing request"
|
|
75
|
+
}
|
|
76
|
+
}, 400);
|
|
77
|
+
}
|
|
40
78
|
try {
|
|
41
79
|
const result = action === "request" ? { request: submitDevicePairingRequest(parsed.data) } : operateDevicePairingRequest(action, parsed.data);
|
|
42
80
|
const signedPayload = Buffer.from(JSON.stringify({
|
|
@@ -48,12 +86,14 @@ function registerPairingApprovalPublicRoutes(app) {
|
|
|
48
86
|
nonce: parsed.data.nonce,
|
|
49
87
|
issuedAt: Date.now()
|
|
50
88
|
})).toString("base64url");
|
|
89
|
+
buckets.pairingExchange().succeed(clientKey);
|
|
51
90
|
return c.json({
|
|
52
91
|
ok: true,
|
|
53
92
|
signedPayload,
|
|
54
93
|
signature: signGatewayPayload(signedPayload)
|
|
55
94
|
});
|
|
56
95
|
} catch (error) {
|
|
96
|
+
buckets.pairingExchange().fail(clientKey);
|
|
57
97
|
return pairingError(c, error);
|
|
58
98
|
}
|
|
59
99
|
});
|
|
@@ -97,4 +137,4 @@ function registerPairingApprovalAdminRoutes(app) {
|
|
|
97
137
|
});
|
|
98
138
|
}
|
|
99
139
|
//#endregion
|
|
100
|
-
export { registerPairingApprovalAdminRoutes, registerPairingApprovalPublicRoutes };
|
|
140
|
+
export { pairingClientKey, registerPairingApprovalAdminRoutes, registerPairingApprovalPublicRoutes };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
2
|
import type { AuthenticatedRouteDeps } from './deps.js';
|
|
3
|
-
|
|
3
|
+
import { type PairingPublicRouteOptions } from './device-pairing-approval.js';
|
|
4
|
+
export declare function registerDeviceAuthPublicRoutes(app: Hono, options?: PairingPublicRouteOptions): void;
|
|
4
5
|
export declare function registerDeviceRoutes(authenticated: Hono, deps: AuthenticatedRouteDeps): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { devicePairingTargetKindSchema } from "../../../../packages/gateway-contract/src/device-pairing.js";
|
|
1
|
+
import { devicePairingInvitationPayloadSchema, devicePairingTargetKindSchema, formatBrowserPairingInvitation } from "../../../../packages/gateway-contract/src/device-pairing.js";
|
|
2
2
|
import { listDevices, revokeDevice, rotateDeviceRefreshToken } from "../../../storage/sqlite/device-access-repository.js";
|
|
3
3
|
import { getGatewayIdentityPublicKeyRaw, getOrCreateGatewayIdentity, signGatewayPayload } from "../../../storage/sqlite/gateway-identity-repository.js";
|
|
4
4
|
import { createDevicePairingSetup, isDevicePairingSetupActive } from "../../../storage/sqlite/device-pairing-repository.js";
|
|
@@ -6,7 +6,7 @@ import { resolveSecureDeviceRoutes } from "../../device-routes.js";
|
|
|
6
6
|
import { buckets } from "../../rate-limit/buckets.js";
|
|
7
7
|
import "../../rate-limit/index.js";
|
|
8
8
|
import { getGatewayPrincipal } from "../../security/gateway-principal.js";
|
|
9
|
-
import { registerPairingApprovalAdminRoutes, registerPairingApprovalPublicRoutes } from "./device-pairing-approval.js";
|
|
9
|
+
import { pairingClientKey, registerPairingApprovalAdminRoutes, registerPairingApprovalPublicRoutes } from "./device-pairing-approval.js";
|
|
10
10
|
import os from "node:os";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { bodyLimit } from "hono/body-limit";
|
|
@@ -21,10 +21,10 @@ const refreshRequestSchema = z.strictObject({
|
|
|
21
21
|
});
|
|
22
22
|
const pairingProbeSchema = z.strictObject({ pairingId: z.string().uuid() });
|
|
23
23
|
const pairingSetupSchema = z.strictObject({ targetKind: devicePairingTargetKindSchema });
|
|
24
|
-
function
|
|
25
|
-
return Buffer.from(JSON.stringify(input)).toString("base64url");
|
|
24
|
+
function pairingPayload(input) {
|
|
25
|
+
return Buffer.from(JSON.stringify(devicePairingInvitationPayloadSchema.parse(input))).toString("base64url");
|
|
26
26
|
}
|
|
27
|
-
function registerDeviceAuthPublicRoutes(app) {
|
|
27
|
+
function registerDeviceAuthPublicRoutes(app, options) {
|
|
28
28
|
app.post("/api/gateway-identity/challenge", bodyLimit({ maxSize: 512 }), async (c) => {
|
|
29
29
|
const budget = buckets.identityChallenge().consume("gateway");
|
|
30
30
|
if (!budget.allowed) {
|
|
@@ -46,7 +46,7 @@ function registerDeviceAuthPublicRoutes(app) {
|
|
|
46
46
|
signature: signGatewayPayload(signedPayload)
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
registerPairingApprovalPublicRoutes(app);
|
|
49
|
+
registerPairingApprovalPublicRoutes(app, options);
|
|
50
50
|
app.post("/api/device-auth/refresh", async (c) => {
|
|
51
51
|
const parsed = refreshRequestSchema.safeParse(await c.req.json().catch(() => null));
|
|
52
52
|
if (!parsed.success) return c.json({
|
|
@@ -81,21 +81,37 @@ function registerDeviceAuthPublicRoutes(app) {
|
|
|
81
81
|
}, 401);
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
-
app.post("/api/device-pairing/probe", async (c) => {
|
|
84
|
+
app.post("/api/device-pairing/probe", bodyLimit({ maxSize: 512 }), async (c) => {
|
|
85
|
+
const clientKey = pairingClientKey(c, options);
|
|
86
|
+
const blocked = buckets.pairingExchange().check(clientKey);
|
|
87
|
+
if (blocked.blocked) {
|
|
88
|
+
c.header("Retry-After", String(blocked.retryAfterSec));
|
|
89
|
+
return c.json({
|
|
90
|
+
ok: false,
|
|
91
|
+
error: {
|
|
92
|
+
code: "PAIRING_RATE_LIMITED",
|
|
93
|
+
message: "Too many failed pairing attempts"
|
|
94
|
+
}
|
|
95
|
+
}, 429);
|
|
96
|
+
}
|
|
85
97
|
const parsed = pairingProbeSchema.safeParse(await c.req.json().catch(() => null));
|
|
86
|
-
if (!parsed.success || !isDevicePairingSetupActive(parsed.data.pairingId))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
if (!parsed.success || !isDevicePairingSetupActive(parsed.data.pairingId)) {
|
|
99
|
+
buckets.pairingExchange().fail(clientKey);
|
|
100
|
+
return c.json({
|
|
101
|
+
ok: false,
|
|
102
|
+
error: {
|
|
103
|
+
code: "PAIRING_NOT_FOUND",
|
|
104
|
+
message: "Pairing setup not found"
|
|
105
|
+
}
|
|
106
|
+
}, 404);
|
|
107
|
+
}
|
|
93
108
|
const identity = getOrCreateGatewayIdentity();
|
|
94
109
|
const payload = Buffer.from(JSON.stringify({
|
|
95
110
|
gatewayId: identity.id,
|
|
96
111
|
pairingId: parsed.data.pairingId,
|
|
97
112
|
issuedAt: Date.now()
|
|
98
113
|
})).toString("base64url");
|
|
114
|
+
buckets.pairingExchange().succeed(clientKey);
|
|
99
115
|
return c.json({
|
|
100
116
|
ok: true,
|
|
101
117
|
signedPayload: payload,
|
|
@@ -136,7 +152,7 @@ function registerDeviceRoutes(authenticated, deps) {
|
|
|
136
152
|
}, 409);
|
|
137
153
|
const setup = createDevicePairingSetup(routes, Date.now(), { targetKind: parsed.data.targetKind });
|
|
138
154
|
const identity = getOrCreateGatewayIdentity();
|
|
139
|
-
const encoded =
|
|
155
|
+
const encoded = pairingPayload({
|
|
140
156
|
version: 3,
|
|
141
157
|
pairingToken: setup.token,
|
|
142
158
|
gatewayId: identity.id,
|
|
@@ -146,11 +162,12 @@ function registerDeviceRoutes(authenticated, deps) {
|
|
|
146
162
|
targetKind: setup.targetKind,
|
|
147
163
|
expiresAt: setup.expiresAt
|
|
148
164
|
});
|
|
165
|
+
const invitation = setup.targetKind === "mobile" ? { universalLink: `https://link.xopc.ai/connect#p=${encoded}` } : { browserInvitation: formatBrowserPairingInvitation(encoded) };
|
|
149
166
|
return c.json({
|
|
150
167
|
ok: true,
|
|
151
168
|
setup: {
|
|
152
169
|
id: setup.id,
|
|
153
|
-
|
|
170
|
+
...invitation,
|
|
154
171
|
expiresAt: setup.expiresAt,
|
|
155
172
|
routes,
|
|
156
173
|
protocolVersion: 3,
|
|
@@ -136,7 +136,7 @@ export declare function replaceLatestSessionTurn(c: Context, deps: Authenticated
|
|
|
136
136
|
code: "TARGET_NOT_FOUND" | "NOT_LATEST" | "SESSION_BUSY" | "BAD_REQUEST" | "CONTEXT_UNAVAILABLE";
|
|
137
137
|
message: string;
|
|
138
138
|
};
|
|
139
|
-
},
|
|
139
|
+
}, 404 | 400 | 409, "json">) | (Response & import("hono").TypedResponse<{
|
|
140
140
|
ok: true;
|
|
141
141
|
payload: {
|
|
142
142
|
sessionKey: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { browserPageContextsInputSchema } from "../../../../packages/gateway-contract/src/browser-page-context.js";
|
|
2
2
|
import { endpointTurnClaimSchema } from "../../../../packages/endpoint-tools-protocol/src/index.js";
|
|
3
3
|
import { init_providers, resolveModel } from "../../../providers/index.js";
|
|
4
|
+
import { validateWebchatAttachments, validateWebchatContent } from "../../chat-limits.js";
|
|
4
5
|
import { parseTurnContextRefs } from "../../../agent/source-context/types.js";
|
|
5
6
|
import { getModelThinking } from "../../../providers/model-thinking.js";
|
|
6
|
-
import { validateWebchatAttachments, validateWebchatContent } from "../../chat-limits.js";
|
|
7
7
|
import { withModelConfigLock } from "../../../session/model-config-lock.js";
|
|
8
8
|
import { browserPageContextToAgentContext } from "../../../agent/source-context/browser-page.js";
|
|
9
9
|
//#region src/gateway/hono/routes/session-input-handler.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { chooseModelThinking } from "../../../../packages/gateway-contract/src/model-selection.js";
|
|
2
2
|
import { init_providers, resolveModel } from "../../../providers/index.js";
|
|
3
|
-
import { getModelThinking } from "../../../providers/model-thinking.js";
|
|
4
3
|
import { validateWebchatAttachments, validateWebchatContent } from "../../chat-limits.js";
|
|
4
|
+
import { getModelThinking } from "../../../providers/model-thinking.js";
|
|
5
5
|
import { validateSideChatSelections } from "../../side-chat/context-snapshot.js";
|
|
6
6
|
import { SideChatError, parseThinkingLevel } from "../../side-chat/manager.js";
|
|
7
7
|
import "../../side-chat/index.js";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createLogger } from "../../../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../../../utils/logger.js";
|
|
1
3
|
import { init_public_url, validatePublicUrl } from "../../../config/public-url.js";
|
|
2
4
|
import { TUNNEL_REGISTRATION_SECRET_REQUIRED_CODE, TunnelRegistrationSecretError, getTunnelRegistrationSecretMeta, readTunnelRegistrationSecretFromConfigOnly, resolveTunnelBrokerUrl } from "../../../tunnel/env.js";
|
|
3
5
|
import { logTunnelAudit } from "../../../tunnel/tunnel-audit.js";
|
|
@@ -9,9 +11,11 @@ import { applyTunnelConsentToConfig, mergeTunnelConfigPatch, setTunnelEnabledInC
|
|
|
9
11
|
import { getGatewayPrincipal } from "../../security/gateway-principal.js";
|
|
10
12
|
import { consumeTunnelMutationLimit } from "../../../tunnel/tunnel-rate-limit.js";
|
|
11
13
|
import "../../../tunnel/index.js";
|
|
12
|
-
import { provisionTunnelRegistrationKey } from "../../../tunnel/xopc-cloud-registration.js";
|
|
14
|
+
import { TunnelRegistrationProvisionError, provisionTunnelRegistrationKey } from "../../../tunnel/xopc-cloud-registration.js";
|
|
13
15
|
//#region src/gateway/hono/routes/tunnel.ts
|
|
16
|
+
init_logger();
|
|
14
17
|
init_public_url();
|
|
18
|
+
const log = createLogger("Gateway:Tunnel");
|
|
15
19
|
async function configureTunnelFromService(deps, opts) {
|
|
16
20
|
await configureTunnelFromGatewayConfig(deps.service.currentConfig, opts);
|
|
17
21
|
}
|
|
@@ -161,6 +165,10 @@ function registerTunnelRoutes(authenticated, deps) {
|
|
|
161
165
|
});
|
|
162
166
|
authenticated.post("/api/tunnel/registration-key", tunnelMutationLimit, async (c) => {
|
|
163
167
|
const config = deps.service.currentConfig;
|
|
168
|
+
if (readTunnelRegistrationSecretFromConfigOnly(config)) return c.json({
|
|
169
|
+
ok: true,
|
|
170
|
+
reused: true
|
|
171
|
+
});
|
|
164
172
|
try {
|
|
165
173
|
const merged = mergeTunnelConfigPatch(config, { registrationSecret: await provisionTunnelRegistrationKey() });
|
|
166
174
|
if (merged.ok === false) return c.json({
|
|
@@ -176,9 +184,33 @@ function registerTunnelRoutes(authenticated, deps) {
|
|
|
176
184
|
return c.json({ ok: true });
|
|
177
185
|
} catch (error) {
|
|
178
186
|
const message = error instanceof Error ? error.message : String(error);
|
|
187
|
+
if (error instanceof TunnelRegistrationProvisionError) {
|
|
188
|
+
const status = error.code === "tunnel_key_limit_reached" ? 409 : error.code === "tunnel_oauth_required" ? 403 : 502;
|
|
189
|
+
log.warn({
|
|
190
|
+
err: error,
|
|
191
|
+
code: error.code,
|
|
192
|
+
upstreamStatus: error.status,
|
|
193
|
+
phase: "registration_key"
|
|
194
|
+
}, `Tunnel registration key failed: ${message}`);
|
|
195
|
+
return c.json({
|
|
196
|
+
ok: false,
|
|
197
|
+
error: {
|
|
198
|
+
code: error.code,
|
|
199
|
+
message
|
|
200
|
+
}
|
|
201
|
+
}, status);
|
|
202
|
+
}
|
|
203
|
+
log.warn({
|
|
204
|
+
err: error,
|
|
205
|
+
errorMessage: message,
|
|
206
|
+
phase: "registration_key"
|
|
207
|
+
}, `Tunnel registration key failed: ${message}`);
|
|
179
208
|
return c.json({
|
|
180
209
|
ok: false,
|
|
181
|
-
error:
|
|
210
|
+
error: {
|
|
211
|
+
code: "tunnel_registration_failed",
|
|
212
|
+
message
|
|
213
|
+
}
|
|
182
214
|
}, 502);
|
|
183
215
|
}
|
|
184
216
|
});
|
|
@@ -144,7 +144,8 @@ var BucketRegistry = class {
|
|
|
144
144
|
if (!this.pairingExchangeLimiter) this.pairingExchangeLimiter = new FailureLimiter({
|
|
145
145
|
maxFailures: 30,
|
|
146
146
|
windowMs: 5 * 6e4,
|
|
147
|
-
blockDurationMs: 5 * 6e4
|
|
147
|
+
blockDurationMs: 5 * 6e4,
|
|
148
|
+
burstCoalesceMs: 0
|
|
148
149
|
});
|
|
149
150
|
return this.pairingExchangeLimiter;
|
|
150
151
|
}
|
|
@@ -9,8 +9,8 @@ import { init_session_key, parseSessionKey } from "../../routing/session-key.js"
|
|
|
9
9
|
import { resolveExecutionContext } from "../../tasks/execution-context.js";
|
|
10
10
|
import { TaskRunCoordinator } from "../../tasks/task-run-coordinator.js";
|
|
11
11
|
import { formatAgentRunErrorForClient } from "../../agent/client-error-format.js";
|
|
12
|
-
import { prependEnvelopeTimestamp } from "../../channels/envelope-timestamp.js";
|
|
13
12
|
import "../chat-limits.js";
|
|
13
|
+
import { prependEnvelopeTimestamp } from "../../channels/envelope-timestamp.js";
|
|
14
14
|
import { ChatStreamMapper } from "../chat-stream/mapper.js";
|
|
15
15
|
import { resolveWebchatSessionKey } from "../resolve-webchat-session-key.js";
|
|
16
16
|
import { recordExplicitRelationshipFollowUp } from "../../user-context/relationship-continuity.js";
|
|
@@ -48,6 +48,7 @@ function requestRow(id, now) {
|
|
|
48
48
|
}
|
|
49
49
|
function statusFromRow(row, now) {
|
|
50
50
|
const device = devicePairingDeviceSchema.parse(JSON.parse(row.device_json));
|
|
51
|
+
const connectedAt = row.device_id ? getDevice(row.device_id)?.lastSeenAt : void 0;
|
|
51
52
|
return {
|
|
52
53
|
requestId: row.request_id,
|
|
53
54
|
setupId: row.pairing_id,
|
|
@@ -58,7 +59,8 @@ function statusFromRow(row, now) {
|
|
|
58
59
|
confirmationCode: row.confirmation_code,
|
|
59
60
|
expiresAt: row.expires_at,
|
|
60
61
|
serverTime: now,
|
|
61
|
-
...row.device_id ? { deviceId: row.device_id } : {}
|
|
62
|
+
...row.device_id ? { deviceId: row.device_id } : {},
|
|
63
|
+
...connectedAt ? { connectedAt } : {}
|
|
62
64
|
};
|
|
63
65
|
}
|
|
64
66
|
function verifiedSetup(token, now) {
|
package/dist/src/tui/tui.js
CHANGED
|
@@ -7,10 +7,10 @@ import { init_paths } from "../config/paths.js";
|
|
|
7
7
|
import { loadConfig } from "../config/loader.js";
|
|
8
8
|
import { getAllModels, getAllProviders, getApiKey, init_providers, isProviderConfiguredSync } from "../providers/index.js";
|
|
9
9
|
import { ProjectTrustStore, hasTrustRequiringProjectResources } from "../project-trust/trust-store.js";
|
|
10
|
+
import { MAX_WEBCHAT_ATTACHMENT_FILE_BYTES } from "../gateway/chat-limits.js";
|
|
10
11
|
import { renderWorkflowFinalSummary, renderWorkflowPanel } from "../agent/workflow/snapshot.js";
|
|
11
12
|
import { ensureStarterAgentsInitialized } from "../agent/starter-agents.js";
|
|
12
13
|
import "../config/index.js";
|
|
13
|
-
import { MAX_WEBCHAT_ATTACHMENT_FILE_BYTES } from "../gateway/chat-limits.js";
|
|
14
14
|
import { isTerminalWorkflowRunStatus } from "../workflows/domain/run.js";
|
|
15
15
|
import "../workflows/domain/index.js";
|
|
16
16
|
import { runViewToSnapshot } from "../workflows/service/run-view-to-snapshot.js";
|
|
@@ -4,6 +4,11 @@ type ProvisionOptions = {
|
|
|
4
4
|
resolveAccessToken?: () => Promise<string | null>;
|
|
5
5
|
deviceName?: string;
|
|
6
6
|
};
|
|
7
|
+
export declare class TunnelRegistrationProvisionError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly status: number;
|
|
10
|
+
constructor(message: string, code: string, status: number);
|
|
11
|
+
}
|
|
7
12
|
/** Exchange a narrowly scoped XOPC OAuth grant for a tunnel registration key. */
|
|
8
13
|
export declare function provisionTunnelRegistrationKey(options?: ProvisionOptions): Promise<string>;
|
|
9
14
|
export {};
|
|
@@ -6,20 +6,26 @@ import { z } from "zod";
|
|
|
6
6
|
init_credentials();
|
|
7
7
|
init_xopc_cloud_config();
|
|
8
8
|
const registrationResponseSchema = z.object({ key: z.string().min(1) });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const registrationErrorSchema = z.object({ error: z.object({
|
|
10
|
+
code: z.string().min(1).optional(),
|
|
11
|
+
message: z.string().min(1).optional()
|
|
12
|
+
}) });
|
|
13
|
+
var TunnelRegistrationProvisionError = class extends Error {
|
|
14
|
+
constructor(message, code, status) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.name = "TunnelRegistrationProvisionError";
|
|
16
19
|
}
|
|
17
|
-
|
|
20
|
+
};
|
|
21
|
+
function responseError(body, status) {
|
|
22
|
+
const parsed = registrationErrorSchema.safeParse(body);
|
|
23
|
+
return new TunnelRegistrationProvisionError(parsed.success ? parsed.data.error.message ?? `Tunnel registration failed (${status})` : `Tunnel registration failed (${status})`, parsed.success ? parsed.data.error.code ?? "tunnel_registration_failed" : "tunnel_registration_failed", status);
|
|
18
24
|
}
|
|
19
25
|
/** Exchange a narrowly scoped XOPC OAuth grant for a tunnel registration key. */
|
|
20
26
|
async function provisionTunnelRegistrationKey(options = {}) {
|
|
21
27
|
const accessToken = await (options.resolveAccessToken ?? (() => new CredentialResolver().resolveApiKey("xopc-tunnel")))();
|
|
22
|
-
if (!accessToken) throw new
|
|
28
|
+
if (!accessToken) throw new TunnelRegistrationProvisionError("Authorize XOPC Public Tunnel before creating a registration key", "tunnel_oauth_required", 401);
|
|
23
29
|
const routerUrl = resolveXopcModelRouterUrl(options.routerUrl);
|
|
24
30
|
const deviceName = options.deviceName?.trim() || hostname() || "XOPC gateway";
|
|
25
31
|
const response = await (options.fetchImpl ?? fetch)(`${routerUrl}/tunnel/registration-key`, {
|
|
@@ -33,10 +39,10 @@ async function provisionTunnelRegistrationKey(options = {}) {
|
|
|
33
39
|
signal: AbortSignal.timeout(3e4)
|
|
34
40
|
});
|
|
35
41
|
const body = await response.json().catch(() => null);
|
|
36
|
-
if (!response.ok) throw
|
|
42
|
+
if (!response.ok) throw responseError(body, response.status);
|
|
37
43
|
const parsed = registrationResponseSchema.safeParse(body);
|
|
38
44
|
if (!parsed.success) throw new Error("Tunnel registration returned an invalid response");
|
|
39
45
|
return parsed.data.key;
|
|
40
46
|
}
|
|
41
47
|
//#endregion
|
|
42
|
-
export { provisionTunnelRegistrationKey };
|
|
48
|
+
export { TunnelRegistrationProvisionError, provisionTunnelRegistrationKey };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xopcai/xopc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.274",
|
|
4
4
|
"description": "Local-first personal AI assistant with reviewable user understanding, durable tasks, workflows, automations, and local or cloud models.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -166,10 +166,10 @@
|
|
|
166
166
|
"vitest": "4.1.5",
|
|
167
167
|
"vue": "^3.5.35",
|
|
168
168
|
"@xopcai/browser-control-contract": "0.1.0",
|
|
169
|
-
"@xopcai/gateway-contract": "0.0.0",
|
|
170
169
|
"@xopcai/endpoint-tools-protocol": "0.0.0",
|
|
171
170
|
"@xopcai/realtime-client": "0.0.0",
|
|
172
|
-
"@xopcai/realtime-protocol": "0.0.0"
|
|
171
|
+
"@xopcai/realtime-protocol": "0.0.0",
|
|
172
|
+
"@xopcai/gateway-contract": "0.0.0"
|
|
173
173
|
},
|
|
174
174
|
"scripts": {
|
|
175
175
|
"assets:brand": "node scripts/generate-brand-assets.mjs",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,p as a}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{a as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./dist-CpzYSoz7.js";import{t as p}from"./plus-Q2yW6OE7.js";import{t as m}from"./x-B_N4OPjy.js";import{t as h}from"./messages-DjuBdDCn.js";import{c as g,n as _}from"./locale-store-BBSCIl4I.js";import{t as v}from"./cn-JdwAhgNB.js";import{i as y}from"./vendor-swr-BIWyz7Rc.js";import{t as b}from"./button-B11EPpor.js";import{t as x}from"./skeleton-BwbyijEw.js";import{i as S,o as C}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{t as w}from"./settings-shell-layer-context-DCp6ykjQ.js";import{El as T,Gc as E,P as D,Ra as O,Rs as k,Us as A,an as j,cn as M,ic as N,in as P,ln as F,lo as I,on as ee,sn as L,vu as R,yc as z}from"./index-C6OWYFtQ.js";import{r as B}from"./settings-page-layout-DYelDcMV.js";var V=n(),H=e(t(),1),U=r(),te=[`fast`,`reasoning`,`coding`,`review`,`vision`,`understanding`],W=`w-full rounded-xl border border-edge bg-surface-base px-3 py-2.5 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/15`;function G(e){return[...new Set(e.split(`,`).map(e=>e.trim()).filter(Boolean))]}function K(e){let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:void 0}function q(e){let t=(0,V.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,U.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[10px] font-medium text-accent`,children:n}),t[0]=n,t[1]=r),r}function J(e){let t=(0,V.c)(10),{title:n,description:r,action:i}=e,a;t[0]===n?a=t[1]:(a=(0,U.jsx)(`h3`,{className:`text-base font-semibold text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=r?(0,U.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-fg-muted`,children:r}):null,t[2]=r,t[3]=o);let s;t[4]!==a||t[5]!==o?(s=(0,U.jsxs)(`div`,{children:[a,o]}),t[4]=a,t[5]=o,t[6]=s):s=t[6];let c;return t[7]!==i||t[8]!==s?(c=(0,U.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[s,i]}),t[7]=i,t[8]=s,t[9]=c):c=t[9],c}function Y(e){let t=(0,V.c)(10),{label:n,value:r,detail:i}=e,a;t[0]===n?a=t[1]:(a=(0,U.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,U.jsx)(`p`,{className:`mt-2 truncate text-sm font-semibold text-fg`,title:r,children:r}),t[2]=r,t[3]=o);let s;t[4]===i?s=t[5]:(s=(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:i}),t[4]=i,t[5]=s);let c;return t[6]!==a||t[7]!==o||t[8]!==s?(c=(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4`,children:[a,o,s]}),t[6]=a,t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function X(e){let t=(0,V.c)(56),{label:n,inherited:r,value:i,zh:a,allowChatFallback:o,allowDisabled:s,onChange:c}=e,l=o===void 0?!1:o,u=s===void 0?!1:s,d=i!=null,f;t[0]===n?f=t[1]:(f=(0,U.jsx)(`h4`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=f);let p;t[2]!==i||t[3]!==a?(p=i===void 0?(0,U.jsx)(q,{children:a?`继承`:`Inherited`}):null,t[2]=i,t[3]=a,t[4]=p):p=t[4];let m;t[5]!==u||t[6]!==i||t[7]!==a?(m=i===null?(0,U.jsx)(q,{children:u?a?`已禁用`:`Disabled`:a?`使用 Chat`:`Uses Chat`}):null,t[5]=u,t[6]=i,t[7]=a,t[8]=m):m=t[8];let h;t[9]!==f||t[10]!==p||t[11]!==m?(h=(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[f,p,m]}),t[9]=f,t[10]=p,t[11]=m,t[12]=h):h=t[12];let g;t[13]!==r?.primary||t[14]!==i||t[15]!==a?(g=i===void 0?(0,U.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-muted`,children:r?.primary??(a?`全局未配置`:`Not configured globally`)}):null,t[13]=r?.primary,t[14]=i,t[15]=a,t[16]=g):g=t[16];let _;t[17]!==h||t[18]!==g?(_=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[h,g]}),t[17]=h,t[18]=g,t[19]=_):_=t[19];let v;t[20]!==c||t[21]!==i||t[22]!==a?(v=i===void 0?null:(0,U.jsx)(b,{variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>c(void 0),children:a?`继承`:`Inherit`}),t[20]=c,t[21]=i,t[22]=a,t[23]=v):v=t[23];let y;t[24]!==l||t[25]!==c||t[26]!==i||t[27]!==a?(y=l&&i!==null?(0,U.jsx)(b,{variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>c(null),children:a?`使用 Chat`:`Use Chat`}):null,t[24]=l,t[25]=c,t[26]=i,t[27]=a,t[28]=y):y=t[28];let x;t[29]!==u||t[30]!==c||t[31]!==i||t[32]!==a?(x=u&&i!==null?(0,U.jsx)(b,{variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>c(null),children:a?`禁用`:`Disable`}):null,t[29]=u,t[30]=c,t[31]=i,t[32]=a,t[33]=x):x=t[33];let S;t[34]!==d||t[35]!==r?.fallbacks||t[36]!==r?.primary||t[37]!==c||t[38]!==a?(S=d?null:(0,U.jsx)(b,{className:`px-2 py-1 text-xs`,onClick:()=>c({primary:r?.primary??``,fallbacks:[...r?.fallbacks??[]]}),children:a?`自定义`:`Customize`}),t[34]=d,t[35]=r?.fallbacks,t[36]=r?.primary,t[37]=c,t[38]=a,t[39]=S):S=t[39];let C;t[40]!==y||t[41]!==x||t[42]!==S||t[43]!==v?(C=(0,U.jsxs)(`div`,{className:`flex gap-1`,children:[v,y,x,S]}),t[40]=y,t[41]=x,t[42]=S,t[43]=v,t[44]=C):C=t[44];let w;t[45]!==C||t[46]!==_?(w=(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[_,C]}),t[45]=C,t[46]=_,t[47]=w):w=t[47];let T;t[48]!==d||t[49]!==c||t[50]!==i||t[51]!==a?(T=d?(0,U.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(0,0.8fr)]`,children:[(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[a?`主模型`:`Primary model`,(0,U.jsx)(`input`,{className:`${W} mt-1.5 font-mono`,value:i.primary,onChange:e=>c({...i,primary:e.target.value})})]}),(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[a?`回退模型`:`Fallbacks`,(0,U.jsx)(`input`,{className:`${W} mt-1.5 font-mono`,value:i.fallbacks.join(`, `),onChange:e=>c({...i,fallbacks:G(e.target.value)}),placeholder:a?`逗号分隔`:`Comma separated`})]})]}):null,t[48]=d,t[49]=c,t[50]=i,t[51]=a,t[52]=T):T=t[52];let E;return t[53]!==w||t[54]!==T?(E=(0,U.jsxs)(`div`,{className:`rounded-2xl border border-edge bg-surface-base p-4`,children:[w,T]}),t[53]=w,t[54]=T,t[55]=E):E=t[55],E}function Z(e){return Object.values(e).some(e=>e!==void 0)?e:void 0}function Q({agent:e,toolIds:t,zh:n,messages:r,externalError:i,onDirtyChange:a,onClose:o,onOpenDefaults:s,onChat:c,onDelete:l}){let[u,d]=(0,H.useState)(`overview`),[f,p]=(0,H.useState)(()=>structuredClone(e.override)),[m,h]=(0,H.useState)(!1),[g,_]=(0,H.useState)(null),y=JSON.stringify(f)!==JSON.stringify(e.override),x=[f.models?.chat,...Object.values(f.models?.intents??{}),f.models?.imageUnderstanding,f.models?.imageGeneration].some(e=>e!=null&&!e.primary.trim());(0,H.useEffect)(()=>a(y),[y,a]);let S=(0,H.useMemo)(()=>[...new Set([...t,...Object.keys(e.effective.tools),...Object.keys(f.tools??{})])].sort(),[e.effective.tools,f.tools,t]),C=[f.models?n?`模型`:`Models`:null,f.skills?n?`技能`:`Skills`:null,f.tools?n?`工具权限`:`Tool access`:null,f.runtime||f.workflows?n?`运行限制`:`Runtime`:null].filter(e=>!!e),w=Object.values(e.effective.tools).filter(e=>e.mode===`deny`).length,D=e.effective.skills.mode===`selected`?n?`${e.effective.skills.include.length} 个已选技能`:`${e.effective.skills.include.length} selected skills`:n?`所有已启用技能`:`All enabled skills`,O=j({id:e.id,name:f.profile?.name??e.name},r),M={fast:r.editorIntentFast,reasoning:r.editorIntentReasoning,coding:r.editorIntentCoding,review:r.editorIntentReview,vision:r.editorIntentVision,understanding:r.editorIntentUnderstanding},P={inherit:r.editorToolModeInherit,allow:r.editorToolModeAllow,ask:r.editorToolModeAsk,deny:r.editorToolModeDeny},I=async()=>{h(!0),_(null);try{let t=(await F(e.id,{workspace:f.workspace??null,profile:f.profile,models:f.models??null,skills:f.skills??null,tools:f.tools??null,workflows:f.workflows??null,runtime:f.runtime??null})).agents.find(t=>t.id===e.id);t&&p(structuredClone(t.override))}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}},ee=async()=>{h(!0),_(null);try{await F(e.id,{setDefault:!0})}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}},L=(e,t)=>{let n={...f.tools??{}};t===`inherit`?delete n[e]:n[e]={...n[e],mode:t},p({...f,tools:Object.keys(n).length>0?n:void 0})},B=(e,t)=>{let n={...f.models??{}},r={...n.intents??{}};t===void 0?delete r[e]:r[e]=t,Object.keys(r).length>0?n.intents=r:delete n.intents,p({...f,models:Object.keys(n).length>0?n:void 0})};return(0,U.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col sm:flex-row`,children:[(0,U.jsx)(`aside`,{className:`shrink-0 overflow-x-auto border-b border-edge px-3 py-3 sm:w-52 sm:overflow-y-auto sm:border-b-0 sm:border-r sm:px-3 sm:py-4`,children:(0,U.jsx)(`nav`,{className:`flex gap-1 sm:flex-col`,children:[{id:`overview`,label:n?`概览`:`Overview`,icon:T},{id:`profile`,label:n?`个性`:`Profile`,icon:k},{id:`models`,label:n?`模型`:`Models`,icon:N},{id:`capabilities`,label:n?`技能与工具`:`Skills & tools`,icon:R},{id:`runtime`,label:n?`运行限制`:`Runtime`,icon:T},{id:`danger`,label:n?`危险区`:`Danger zone`,icon:A}].map(({id:e,label:t,icon:n})=>(0,U.jsxs)(`button`,{type:`button`,onClick:()=>d(e),className:v(`flex shrink-0 items-center gap-2.5 rounded-xl px-3 py-2 text-left text-sm font-medium transition-colors`,u===e?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),children:[(0,U.jsx)(n,{className:`size-4`}),t]},e))})}),(0,U.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,U.jsxs)(`main`,{className:`min-h-0 flex-1 overflow-y-auto p-5 sm:p-6`,children:[g||i?(0,U.jsx)(`p`,{className:`mb-4 rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:g??i}):null,u===`overview`?(0,U.jsxs)(`div`,{className:`space-y-6`,children:[(0,U.jsx)(J,{title:n?`配置概览`:`Configuration overview`,description:n?`查看当前真正生效的配置。未覆盖的部分会持续跟随全局默认值。`:`Review what actually takes effect. Anything not overridden keeps following global defaults.`,action:(0,U.jsxs)(b,{onClick:c,children:[(0,U.jsx)(E,{className:`size-4`}),n?`开始对话`:`Start chat`]})}),(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 rounded-2xl border border-accent/20 bg-accent/5 p-4`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:C.length>0?n?`已自定义:${C.join(`、`)}`:`Customized: ${C.join(`, `)}`:n?`能力配置使用全局默认`:`Capabilities use global defaults`}),(0,U.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:C.length>0?n?`其他能力会继续跟随全局默认配置。`:`All other capabilities continue to follow global defaults.`:n?`修改全局默认配置后,这个智能体会自动同步。`:`This agent updates automatically when global defaults change.`})]}),(0,U.jsx)(b,{onClick:s,children:n?`查看全局默认配置`:`View global defaults`})]}),(0,U.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,U.jsx)(Y,{label:n?`对话模型`:`Chat model`,value:e.effective.models.chat.primary,detail:f.models?.chat?n?`单独设置`:`Agent override`:n?`继承全局`:`Inherited globally`}),(0,U.jsx)(Y,{label:n?`技能`:`Skills`,value:D,detail:f.skills?n?`单独设置`:`Agent override`:n?`继承全局`:`Inherited globally`}),(0,U.jsx)(Y,{label:n?`工具权限`:`Tool access`,value:w>0?n?`${w} 个禁用`:`${w} denied`:n?`全部可用`:`All available`,detail:f.tools?n?`${Object.keys(f.tools).length} 个本地覆盖`:`${Object.keys(f.tools).length} local overrides`:n?`继承全局`:`Inherited globally`}),(0,U.jsx)(Y,{label:n?`工作区`:`Workspace`,value:e.effective.workspace,detail:f.workspace?n?`单独设置`:`Agent specific`:n?`自动工作区`:`Automatic workspace`})]}),e.isDefault?null:(0,U.jsx)(b,{onClick:()=>void ee(),disabled:m,children:n?`设为默认智能体`:`Make default agent`})]}):null,u===`profile`?(0,U.jsxs)(`div`,{className:`space-y-6`,children:[(0,U.jsx)(J,{title:n?`个性与工作区`:`Profile and workspace`,description:n?`只设置这个智能体独有的身份、表达方式和工作目录。`:`Keep only this agent’s identity, behavior, and workspace here.`}),(0,U.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`名称`:`Name`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:O,onChange:e=>p({...f,profile:{name:e.target.value,...f.profile?.instructions?{instructions:f.profile.instructions}:{}}})})]}),(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[(0,U.jsxs)(`span`,{className:`flex items-center gap-2`,children:[n?`工作区`:`Workspace`,f.workspace?null:(0,U.jsx)(q,{children:n?`自动`:`Automatic`})]}),(0,U.jsx)(`input`,{className:`${W} mt-1.5 font-mono`,value:f.workspace??``,placeholder:e.effective.workspace,onChange:e=>p({...f,workspace:e.target.value||void 0})})]})]}),(0,U.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[n?`个性指令`:`Personality instructions`,(0,U.jsx)(`textarea`,{rows:10,className:`${W} mt-1.5 resize-y leading-6`,value:f.profile?.instructions??``,onChange:t=>p({...f,profile:{name:f.profile?.name||e.name,instructions:t.target.value||void 0}}),placeholder:n?`描述角色、语气、判断偏好和工作方式`:`Describe the role, tone, judgment preferences, and working style`})]})]}):null,u===`models`?(0,U.jsxs)(`div`,{className:`space-y-6`,children:[(0,U.jsx)(J,{title:n?`模型路由`:`Model routing`,description:n?`日常对话使用 Chat;固定意图只在对应任务中生效。默认继承全局。`:`Chat handles normal turns; fixed intents apply only to matching work. Everything inherits by default.`,action:f.models?(0,U.jsxs)(b,{variant:`ghost`,onClick:()=>p({...f,models:void 0}),children:[(0,U.jsx)(z,{className:`size-4`}),n?`全部继承`:`Inherit all`]}):void 0}),(0,U.jsx)(X,{label:r.editorChatModel,inherited:e.effective.models.chat,value:f.models?.chat,zh:n,onChange:e=>{let t={...f.models??{}};e?t.chat=e:delete t.chat,p({...f,models:Object.keys(t).length>0?t:void 0})}}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`mb-3 text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:n?`固定意图`:`Fixed intents`}),(0,U.jsx)(`div`,{className:`space-y-3`,children:te.map(t=>(0,U.jsx)(X,{label:M[t],inherited:e.effective.models.intents[t]??e.effective.models.chat,value:f.models?.intents?.[t],zh:n,allowChatFallback:!0,onChange:e=>B(t,e)},t))})]}),(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`mb-3 text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:n?`图片能力`:`Image capabilities`}),(0,U.jsxs)(`div`,{className:`space-y-3`,children:[(0,U.jsx)(X,{label:n?`图片理解`:`Image understanding`,inherited:e.effective.models.imageUnderstanding,value:f.models?.imageUnderstanding,zh:n,allowDisabled:!0,onChange:e=>{let t={...f.models??{}};e===void 0?delete t.imageUnderstanding:t.imageUnderstanding=e,p({...f,models:Object.keys(t).length>0?t:void 0})}}),(0,U.jsx)(X,{label:n?`图片生成`:`Image generation`,inherited:e.effective.models.imageGeneration,value:f.models?.imageGeneration,zh:n,allowDisabled:!0,onChange:t=>{let n={...f.models??{}};t===void 0?delete n.imageGeneration:t===null?n.imageGeneration=null:n.imageGeneration={...t,timeoutMs:f.models?.imageGeneration?.timeoutMs??e.effective.models.imageGeneration?.timeoutMs,autoProviderFallback:f.models?.imageGeneration?.autoProviderFallback??e.effective.models.imageGeneration?.autoProviderFallback??!0},p({...f,models:Object.keys(n).length>0?n:void 0})}}),f.models?.imageGeneration?(0,U.jsxs)(`div`,{className:`grid gap-4 rounded-2xl border border-edge bg-surface-base p-4 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`生成超时(毫秒)`:`Generation timeout (ms)`,(0,U.jsx)(`input`,{type:`number`,min:1,className:`${W} mt-1.5`,value:f.models.imageGeneration.timeoutMs??``,onChange:e=>p({...f,models:{...f.models,imageGeneration:{...f.models.imageGeneration,timeoutMs:K(e.target.value)}}})})]}),(0,U.jsxs)(`div`,{className:`text-xs font-medium text-fg-muted`,children:[(0,U.jsx)(`span`,{children:n?`提供商自动回退`:`Automatic provider fallback`}),(0,U.jsx)(`div`,{className:`mt-1.5 flex rounded-xl bg-surface-hover p-1`,children:[!0,!1].map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>p({...f,models:{...f.models,imageGeneration:{...f.models.imageGeneration,autoProviderFallback:e}}}),className:v(`flex-1 rounded-lg px-3 py-2 text-xs font-medium`,f.models?.imageGeneration?.autoProviderFallback===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted`),children:e?n?`开启`:`On`:n?`关闭`:`Off`},String(e)))})]})]}):null]})]})]}):null,u===`capabilities`?(0,U.jsxs)(`div`,{className:`space-y-7`,children:[(0,U.jsx)(J,{title:n?`技能与工具`:`Skills and tools`,description:n?`默认继承全局能力;只设置确实不同的部分。`:`Keep inheritance for global capabilities; override only agents that genuinely differ.`}),(0,U.jsxs)(`section`,{className:`rounded-2xl border border-edge bg-surface-base p-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:n?`技能策略`:`Skill policy`}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:f.skills?n?`当前使用单独设置`:`Using an agent override`:n?`当前继承全局`:`Currently inherited globally`})]}),f.skills?(0,U.jsxs)(b,{variant:`ghost`,onClick:()=>p({...f,skills:void 0}),children:[(0,U.jsx)(z,{className:`size-4`}),n?`继承`:`Inherit`]}):null]}),(0,U.jsxs)(`div`,{className:`mt-4 flex gap-2`,children:[(0,U.jsx)(b,{variant:f.skills?.mode===`merge`?`primary`:`secondary`,onClick:()=>p({...f,skills:{mode:`merge`,add:[],remove:[]}}),children:r.editorSkillModeMerge}),(0,U.jsx)(b,{variant:f.skills?.mode===`replace`?`primary`:`secondary`,onClick:()=>p({...f,skills:{mode:`replace`,include:[]}}),children:r.editorSkillModeReplace})]}),f.skills?.mode===`merge`?(0,U.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`新增技能`:`Add skills`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:f.skills.add.join(`, `),onChange:e=>p({...f,skills:{mode:`merge`,add:G(e.target.value),remove:f.skills?.mode===`merge`?f.skills.remove:[]}})})]}),(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`移除技能`:`Remove skills`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:f.skills.remove.join(`, `),onChange:e=>p({...f,skills:{mode:`merge`,add:f.skills?.mode===`merge`?f.skills.add:[],remove:G(e.target.value)}})})]})]}):null,f.skills?.mode===`replace`?(0,U.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[n?`仅启用这些技能`:`Enable only these skills`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:f.skills.include.join(`, `),onChange:e=>p({...f,skills:{mode:`replace`,include:G(e.target.value)}})})]}):null]}),(0,U.jsxs)(`section`,{children:[(0,U.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:n?`工具权限`:`Tool permissions`}),f.tools?(0,U.jsxs)(b,{variant:`ghost`,onClick:()=>p({...f,tools:void 0}),children:[(0,U.jsx)(z,{className:`size-4`}),n?`全部继承`:`Inherit all`]}):null]}),(0,U.jsx)(`div`,{className:`divide-y divide-edge overflow-hidden rounded-2xl border border-edge bg-surface-base`,children:S.map(t=>{let r=f.tools?.[t]?.mode,i=e.effective.tools[t]?.mode??`allow`;return(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 px-4 py-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`code`,{className:`text-xs text-fg`,children:t}),(0,U.jsx)(`p`,{className:`mt-1 text-[11px] text-fg-muted`,children:r?n?`单独设置`:`Agent override`:`${n?`继承`:`Inherits`} ${P[i]}`})]}),(0,U.jsx)(`div`,{className:`flex rounded-xl bg-surface-hover p-1`,children:[`inherit`,`allow`,`ask`,`deny`].map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>L(t,e),className:v(`rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors`,(e===`inherit`?!r:r===e)?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),children:P[e]},e))})]},t)})})]})]}):null,u===`runtime`?(0,U.jsxs)(`div`,{className:`space-y-6`,children:[(0,U.jsx)(J,{title:n?`运行限制`:`Runtime limits`,description:n?`留空即继承全局限制。`:`Leave blank to inherit global limits. Use overrides only to tighten or relax a specialist agent.`,action:f.runtime||f.workflows?(0,U.jsxs)(b,{variant:`ghost`,onClick:()=>p({...f,runtime:void 0,workflows:void 0}),children:[(0,U.jsx)(z,{className:`size-4`}),n?`全部继承`:`Inherit all`]}):void 0}),(0,U.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[[`maxTurns`,n?`单次最大轮数`:`Maximum turns`],[`timeoutMs`,n?`单轮超时(毫秒)`:`Turn timeout (ms)`],[`maxToolFailuresPerTurn`,n?`最大工具失败次数`:`Maximum tool failures`]].map(([t,r])=>(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[(0,U.jsxs)(`span`,{className:`flex items-center gap-2`,children:[r,f.runtime?.[t]===void 0?(0,U.jsx)(q,{children:n?`继承`:`Inherited`}):null]}),(0,U.jsx)(`input`,{type:`number`,min:1,className:`${W} mt-1.5`,value:f.runtime?.[t]??``,placeholder:String(e.effective.runtime[t]??``),onChange:e=>{let n=Z({...f.runtime??{},[t]:K(e.target.value)});p({...f,runtime:n})}})]},t))}),(0,U.jsxs)(`section`,{className:`rounded-2xl border border-edge bg-surface-base p-4`,children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:n?`工作流`:`Workflows`}),(0,U.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2`,children:[(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`默认工作流`:`Default workflow`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:f.workflows?.default??``,placeholder:e.effective.workflows.default,onChange:e=>{let t=Z({...f.workflows??{},default:e.target.value||void 0});p({...f,workflows:t})}})]}),(0,U.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[n?`允许的工作流`:`Allowed workflows`,(0,U.jsx)(`input`,{className:`${W} mt-1.5`,value:f.workflows?.allowed?.join(`, `)??``,placeholder:e.effective.workflows.allowed?.join(`, `),onChange:e=>{let t=G(e.target.value),n=Z({...f.workflows??{},allowed:t.length>0?t:void 0});p({...f,workflows:n})}})]})]})]}),(0,U.jsxs)(`section`,{className:`rounded-2xl border border-edge bg-surface-base p-4`,children:[(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:n?`提示词缓存`:`Prompt cache`}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:f.runtime?.promptCache?n?`使用单独设置`:`Using agent override`:n?`继承全局`:`Inherited globally`})]}),f.runtime?.promptCache?(0,U.jsxs)(b,{variant:`ghost`,onClick:()=>{let e=Z({...f.runtime??{},promptCache:void 0});p({...f,runtime:e})},children:[(0,U.jsx)(z,{className:`size-4`}),n?`继承`:`Inherit`]}):null]}),f.runtime?.promptCache?(0,U.jsxs)(`div`,{className:`mt-4 grid gap-4 sm:grid-cols-2`,children:[(0,U.jsxs)(`div`,{className:`text-xs font-medium text-fg-muted`,children:[(0,U.jsx)(`span`,{children:n?`模式`:`Mode`}),(0,U.jsx)(`div`,{className:`mt-1.5 flex rounded-xl bg-surface-hover p-1`,children:[`auto`,`off`].map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>p({...f,runtime:{...f.runtime,promptCache:{...f.runtime.promptCache,mode:e}}}),className:v(`flex-1 rounded-lg px-3 py-2 text-xs font-medium`,f.runtime?.promptCache?.mode===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted`),children:e===`auto`?r.editorCacheModeAuto:r.editorCacheModeOff},e))})]}),(0,U.jsxs)(`div`,{className:`text-xs font-medium text-fg-muted`,children:[(0,U.jsx)(`span`,{children:n?`缓存周期`:`Lifetime`}),(0,U.jsx)(`div`,{className:`mt-1.5 flex rounded-xl bg-surface-hover p-1`,children:[`short`,`long`].map(e=>(0,U.jsx)(`button`,{type:`button`,onClick:()=>p({...f,runtime:{...f.runtime,promptCache:{...f.runtime.promptCache,lifetime:e}}}),className:v(`flex-1 rounded-lg px-3 py-2 text-xs font-medium`,f.runtime?.promptCache?.lifetime===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted`),children:e===`short`?r.editorCacheLifetimeShort:r.editorCacheLifetimeLong},e))})]})]}):(0,U.jsx)(b,{className:`mt-4`,onClick:()=>p({...f,runtime:{...f.runtime,promptCache:{...e.effective.runtime.promptCache??{mode:`auto`,lifetime:`short`}}}}),children:n?`自定义缓存策略`:`Customize cache policy`})]})]}):null,u===`danger`?(0,U.jsxs)(`div`,{className:`space-y-6`,children:[(0,U.jsx)(J,{title:n?`危险区`:`Danger zone`,description:n?`这些操作会改变默认路由或移除智能体。`:`These actions change default routing or remove the agent.`}),e.isDefault?null:(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-2xl border border-edge bg-surface-base p-4`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:n?`设为默认智能体`:`Make default agent`}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n?`新会话和未指定路由将使用这个智能体。`:`New sessions and unspecified routes will use this agent.`})]}),(0,U.jsx)(b,{disabled:m,onClick:()=>void ee(),children:n?`设为默认`:`Make default`})]}),e.isDefault?(0,U.jsx)(`p`,{className:`rounded-2xl bg-surface-base p-4 text-sm text-fg-muted`,children:n?`默认智能体不能删除,请先将其他智能体设为默认。`:`The default agent cannot be deleted. Make another agent the default first.`}):(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-4 rounded-2xl border border-red-500/25 bg-red-500/5 p-4`,children:[(0,U.jsxs)(`div`,{children:[(0,U.jsx)(`h4`,{className:`text-sm font-semibold text-red-600`,children:n?`删除智能体`:`Delete agent`}),(0,U.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n?`配置条目会被移除,删除前仍会再次确认。`:`The configuration entry will be removed after confirmation.`})]}),(0,U.jsxs)(b,{variant:`ghost`,className:`text-red-600`,onClick:l,children:[(0,U.jsx)(A,{className:`size-4`}),n?`删除`:`Delete`]})]})]}):null]}),(0,U.jsxs)(`footer`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-edge bg-surface-panel px-5 py-3`,children:[(0,U.jsx)(`p`,{className:`text-xs text-fg-muted`,children:x?n?`请补全自定义模型`:`Complete the custom model reference`:y?n?`有未保存的更改`:`Unsaved changes`:n?`所有更改已保存`:`All changes saved`}),(0,U.jsxs)(`div`,{className:`flex gap-2`,children:[(0,U.jsx)(b,{onClick:o,children:n?`关闭`:`Close`}),(0,U.jsx)(b,{variant:`primary`,disabled:m||!y||x||f.profile!==void 0&&!f.profile.name.trim(),onClick:()=>void I(),children:m?n?`保存中…`:`Saving…`:n?`保存更改`:`Save changes`})]})]})]})]})}function $(e){let t=(0,V.c)(36),{agent:n,messages:r,open:i,onOpenChange:a,children:p}=e,[h,g]=(0,H.useState)(null),_;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,U.jsx)(o,{className:v(`xopc-dialog-overlay fixed inset-0 bg-scrim`,C)}),t[0]=_):_=t[0];let y;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(y=v(`xopc-dialog-content fixed flex flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover`,S,`inset-3 h-[calc(100dvh-1.5rem)] min-h-0 sm:inset-auto sm:left-1/2 sm:top-1/2`,`sm:h-[min(88vh,48rem)] sm:w-[min(94vw,62rem)] sm:-translate-x-1/2 sm:-translate-y-1/2`),t[1]=y):y=t[1];let b;t[2]!==n.avatar||t[3]!==n.id?(b=(0,U.jsx)(D,{agentId:n.id,avatar:n.avatar,size:42,className:`size-11 shrink-0`}),t[2]=n.avatar,t[3]=n.id,t[4]=b):b=t[4];let x;t[5]!==n||t[6]!==r?(x=j(n,r),t[5]=n,t[6]=r,t[7]=x):x=t[7];let T;t[8]===x?T=t[9]:(T=(0,U.jsx)(d,{className:`truncate text-base font-semibold text-fg`,children:x}),t[8]=x,t[9]=T);let E;t[10]===n.id?E=t[11]:(E=(0,U.jsx)(s,{className:`mt-0.5 truncate font-mono text-xs text-fg-muted`,children:n.id}),t[10]=n.id,t[11]=E);let O;t[12]!==T||t[13]!==E?(O=(0,U.jsxs)(`div`,{className:`min-w-0`,children:[T,E]}),t[12]=T,t[13]=E,t[14]=O):O=t[14];let k;t[15]!==n.isDefault||t[16]!==r.listDefaultBadge?(k=n.isDefault?(0,U.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent`,children:r.listDefaultBadge}):null,t[15]=n.isDefault,t[16]=r.listDefaultBadge,t[17]=k):k=t[17];let A;t[18]!==b||t[19]!==O||t[20]!==k?(A=(0,U.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[b,O,k]}),t[18]=b,t[19]=O,t[20]=k,t[21]=A):A=t[21];let M;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,U.jsx)(m,{className:`size-4`}),t[22]=M):M=t[22];let N;t[23]===r.closeDialogAria?N=t[24]:(N=(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:`rounded-lg p-2 text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":r.closeDialogAria,children:M})}),t[23]=r.closeDialogAria,t[24]=N);let P;t[25]!==N||t[26]!==A?(P=(0,U.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between gap-4 border-b border-edge px-5 py-4`,children:[A,N]}),t[25]=N,t[26]=A,t[27]=P):P=t[27];let F;t[28]!==p||t[29]!==h||t[30]!==P?(F=(0,U.jsxs)(l,{children:[_,(0,U.jsx)(u,{ref:g,className:y,onOpenAutoFocus:ne,children:(0,U.jsxs)(w,{layer:`modal`,portalContainer:h,children:[P,p]})})]}),t[28]=p,t[29]=h,t[30]=P,t[31]=F):F=t[31];let I;return t[32]!==a||t[33]!==i||t[34]!==F?(I=(0,U.jsx)(f,{open:i,onOpenChange:a,children:F}),t[32]=a,t[33]=i,t[34]=F,t[35]=I):I=t[35],I}function ne(e){return e.preventDefault()}function re(e){let t=(0,V.c)(13),{agents:n,busy:r,messages:i,onOpen:a,onChat:o}=e,s;if(t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==o||t[4]!==a){let e;t[6]!==r||t[7]!==i||t[8]!==o||t[9]!==a?(e=e=>{let t=j(e,i),n=P(e,i);return(0,U.jsx)(`li`,{className:`min-h-0`,children:(0,U.jsxs)(`article`,{className:v(`group relative flex min-h-52 flex-col rounded-2xl border border-edge bg-surface-panel p-4 shadow-surface`,`transition-[transform,background-color,border-color] duration-200 ease-out hover:-translate-y-0.5 hover:border-accent/30 hover:bg-surface-hover/35 active:scale-[0.99] motion-reduce:transform-none`),children:[(0,U.jsx)(`button`,{type:`button`,disabled:r,"aria-label":i.listConfigureAgent.replace(`{{name}}`,t),onClick:()=>a(e.id),className:`absolute inset-0 z-0 rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),(0,U.jsxs)(`div`,{className:`pointer-events-none relative z-10 flex items-start justify-between gap-3`,children:[(0,U.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,U.jsx)(D,{agentId:e.id,avatar:e.avatar,size:48,className:`size-12 shrink-0`}),(0,U.jsx)(`div`,{className:`min-w-0`,children:(0,U.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:t})})]}),(0,U.jsx)(`span`,{className:v(`rounded-full px-2 py-0.5 text-[11px] font-medium`,e.isDefault?`bg-accent-soft text-accent`:`bg-surface-hover text-fg-muted`),children:e.isDefault?i.listDefaultBadge:i.listCustomBadge})]}),(0,U.jsx)(`p`,{className:`pointer-events-none relative z-10 mt-5 line-clamp-2 min-h-10 text-sm leading-5 text-fg-muted`,children:n||e.override.profile?.instructions||i.listUsesGlobalSettings}),(0,U.jsxs)(`div`,{className:`pointer-events-none relative z-10 mt-4 rounded-xl bg-surface-base px-3 py-2.5`,children:[(0,U.jsx)(`p`,{className:`text-[11px] font-medium uppercase tracking-wide text-fg-subtle`,children:i.listCurrentModelLabel}),(0,U.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg`,children:e.effective.models.chat.primary})]}),(0,U.jsx)(`div`,{className:`relative z-10 mt-auto pt-4`,children:(0,U.jsxs)(b,{className:`w-full`,disabled:r,onClick:t=>{t.stopPropagation(),o(e.id)},children:[(0,U.jsx)(E,{className:`size-4`}),i.listChatWithAgent]})})]})},e.id)},t[6]=r,t[7]=i,t[8]=o,t[9]=a,t[10]=e):e=t[10],s=n.map(e),t[0]=n,t[1]=r,t[2]=i,t[3]=o,t[4]=a,t[5]=s}else s=t[5];let c;return t[11]===s?c=t[12]:(c=(0,U.jsx)(`ul`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:s}),t[11]=s,t[12]=c),c}var ie=`w-full rounded-xl border border-edge bg-surface-base px-3 py-2.5 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/15`;function ae(e){let t=(0,V.c)(59),{open:n,busy:r,error:i,name:a,instructions:p,zh:h,onNameChange:g,onInstructionsChange:_,onCreate:y,onOpenChange:x}=e,w;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,U.jsx)(o,{className:v(`xopc-dialog-overlay fixed inset-0 bg-scrim`,C)}),t[0]=w):w=t[0];let T;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(T=v(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(92vw,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover`,S),t[1]=T):T=t[1];let E=h?`新建智能体`:`Create agent`,D;t[2]===E?D=t[3]:(D=(0,U.jsx)(d,{className:`text-base font-semibold text-fg`,children:E}),t[2]=E,t[3]=D);let O=h?`只设置身份即可开始,所有能力自动继承全局配置。`:`Set its identity and start. Every capability inherits globally.`,k;t[4]===O?k=t[5]:(k=(0,U.jsx)(s,{className:`mt-1 text-sm text-fg-muted`,children:O}),t[4]=O,t[5]=k);let A;t[6]!==D||t[7]!==k?(A=(0,U.jsxs)(`div`,{children:[D,k]}),t[6]=D,t[7]=k,t[8]=A):A=t[8];let j;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(`button`,{type:`button`,className:`rounded-lg p-2 text-fg-muted hover:bg-surface-hover`,"aria-label":`Close`,children:(0,U.jsx)(m,{className:`size-4`})})}),t[9]=j):j=t[9];let M;t[10]===A?M=t[11]:(M=(0,U.jsxs)(`header`,{className:`flex items-start justify-between gap-4 border-b border-edge px-5 py-4`,children:[A,j]}),t[10]=A,t[11]=M);let N;t[12]===i?N=t[13]:(N=i?(0,U.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:i}):null,t[12]=i,t[13]=N);let P=h?`名称`:`Name`,F=h?`智能体名称`:`Agent name`,I;t[14]===g?I=t[15]:(I=e=>g(e.target.value),t[14]=g,t[15]=I);let ee=h?`例如:数据分析师`:`For example: Data analyst`,L;t[16]!==a||t[17]!==F||t[18]!==I||t[19]!==ee?(L=(0,U.jsx)(`input`,{id:`create-agent-name`,"aria-label":F,className:`${ie} mt-1.5`,value:a,onChange:I,placeholder:ee}),t[16]=a,t[17]=F,t[18]=I,t[19]=ee,t[20]=L):L=t[20];let R;t[21]!==P||t[22]!==L?(R=(0,U.jsxs)(`label`,{htmlFor:`create-agent-name`,className:`block text-xs font-medium text-fg-muted`,children:[P,L]}),t[21]=P,t[22]=L,t[23]=R):R=t[23];let z=h?`个性与工作方式(可选)`:`Personality and working style (optional)`,B=h?`个性与工作方式`:`Personality and working style`,H;t[24]===_?H=t[25]:(H=e=>_(e.target.value),t[24]=_,t[25]=H);let te=h?`描述角色、语气和偏好的工作方式`:`Describe its role, tone, and preferred way of working`,W;t[26]!==p||t[27]!==B||t[28]!==H||t[29]!==te?(W=(0,U.jsx)(`textarea`,{id:`create-agent-instructions`,"aria-label":B,rows:4,className:`${ie} mt-1.5 resize-none`,value:p,onChange:H,placeholder:te}),t[26]=p,t[27]=B,t[28]=H,t[29]=te,t[30]=W):W=t[30];let G;t[31]!==z||t[32]!==W?(G=(0,U.jsxs)(`label`,{htmlFor:`create-agent-instructions`,className:`block text-xs font-medium text-fg-muted`,children:[z,W]}),t[31]=z,t[32]=W,t[33]=G):G=t[33];let K;t[34]!==N||t[35]!==R||t[36]!==G?(K=(0,U.jsxs)(`div`,{className:`space-y-4 p-5`,children:[N,R,G]}),t[34]=N,t[35]=R,t[36]=G,t[37]=K):K=t[37];let q=h?`取消`:`Cancel`,J;t[38]!==r||t[39]!==q?(J=(0,U.jsx)(c,{asChild:!0,children:(0,U.jsx)(b,{disabled:r,children:q})}),t[38]=r,t[39]=q,t[40]=J):J=t[40];let Y;t[41]!==r||t[42]!==a?(Y=r||!a.trim(),t[41]=r,t[42]=a,t[43]=Y):Y=t[43];let X=r?h?`创建中…`:`Creating…`:h?`创建智能体`:`Create agent`,Z;t[44]!==y||t[45]!==Y||t[46]!==X?(Z=(0,U.jsx)(b,{variant:`primary`,disabled:Y,onClick:y,children:X}),t[44]=y,t[45]=Y,t[46]=X,t[47]=Z):Z=t[47];let Q;t[48]!==J||t[49]!==Z?(Q=(0,U.jsxs)(`footer`,{className:`flex justify-end gap-2 border-t border-edge px-5 py-4`,children:[J,Z]}),t[48]=J,t[49]=Z,t[50]=Q):Q=t[50];let $;t[51]!==K||t[52]!==Q||t[53]!==M?($=(0,U.jsxs)(l,{children:[w,(0,U.jsxs)(u,{className:T,children:[M,K,Q]})]}),t[51]=K,t[52]=Q,t[53]=M,t[54]=$):$=t[54];let ne;return t[55]!==x||t[56]!==n||t[57]!==$?(ne=(0,U.jsx)(f,{open:n,onOpenChange:x,children:$}),t[55]=x,t[56]=n,t[57]=$,t[58]=ne):ne=t[58],ne}function oe(){let e=(0,V.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,U.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,U.jsxs)(`div`,{className:`space-y-2`,children:[(0,U.jsx)(x,{className:`h-7 w-28`}),(0,U.jsx)(x,{className:`h-4 w-80 max-w-full`})]}),(0,U.jsx)(x,{className:`h-9 w-28`})]}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,U.jsxs)(B,{gap:`gap-5`,children:[t,(0,U.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:[0,1,2].map(se)})]}),e[1]=n):n=e[1],n}function se(e){return(0,U.jsx)(x,{className:`h-64 rounded-2xl`},e)}function ce(){let e=g(e=>e.sessionKey),t=_(e=>e.language),n=t===`zh`,r=h(t).agentsSettings,o=i(),{agentId:s}=a(),{data:c,error:l,isLoading:u,mutate:d}=y(e?`settings-gateway-agents`:null,M),f=I(e=>e.setPageHeader),m=I(e=>e.clearPageHeader),[v,x]=(0,H.useState)({open:!1,name:``,instructions:``}),[S,C]=(0,H.useState)(!1),[w,T]=(0,H.useState)(null),E=(0,H.useRef)(!1),D=c?.agents.find(e=>e.id===s),k=(0,H.useMemo)(()=>(0,U.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,U.jsx)(b,{onClick:()=>o(`/settings/agent-defaults`),children:n?`全局默认配置`:`Global defaults`}),(0,U.jsxs)(b,{variant:`primary`,onClick:()=>{T(null),x(e=>({...e,open:!0}))},children:[(0,U.jsx)(p,{className:`size-4`}),n?`新建智能体`:`New agent`]})]}),[o,n]);(0,H.useLayoutEffect)(()=>(f({startExtra:null,main:(0,U.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:n?`智能体`:`Agents`}),end:k}),()=>m()),[m,k,f,n]);let A=async()=>{C(!0),T(null);try{let e=await ee({profile:{name:v.name.trim(),...v.instructions.trim()?{instructions:v.instructions.trim()}:{}}});x({open:!1,name:``,instructions:``}),o(`/agents/${e.createdAgentId}`)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1)}},N=async e=>{let t=j(e,r);if(window.confirm(n?`删除 ${t}?此操作无法撤销。`:`Delete ${t}? This cannot be undone.`)){C(!0),T(null);try{await L(e.id),o(`/agents`)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1)}}},P=e=>{O(e),o(`/chat/new`)},F=e=>{E.current=!1,window.setTimeout(()=>o(`/agents/${e}`),0)},R=()=>{E.current&&!window.confirm(n?`放弃未保存的更改?`:`Discard unsaved changes?`)||(E.current=!1,o(`/agents`))},z=()=>{E.current&&!window.confirm(n?`放弃未保存的更改?`:`Discard unsaved changes?`)||(E.current=!1,o(`/settings/agent-defaults`))},V=(0,H.useCallback)(e=>{E.current=e},[]);return e?l&&!c?(0,U.jsxs)(B,{children:[(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:String(l)}),(0,U.jsx)(b,{onClick:()=>void d(),children:n?`重试`:`Retry`})]}):u||!c?(0,U.jsx)(oe,{}):(0,U.jsxs)(B,{gap:`gap-5`,className:`max-w-6xl`,padding:`px-4 py-7 sm:px-6 lg:px-8 lg:py-9`,children:[(l||w)&&!D?(0,U.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:w??String(l)}):null,(0,U.jsx)(re,{agents:c.agents,busy:S,messages:r,onOpen:F,onChat:P}),D?(0,U.jsx)($,{agent:D,messages:r,open:!0,onOpenChange:e=>{e||R()},children:(0,U.jsx)(Q,{agent:D,toolIds:c.builtinToolIds,zh:n,messages:r,externalError:w,onDirtyChange:V,onClose:R,onOpenDefaults:z,onChat:()=>P(D.id),onDelete:()=>void N(D)},D.id)}):null,(0,U.jsx)(ae,{open:v.open,busy:S,error:w,name:v.name,instructions:v.instructions,zh:n,onNameChange:e=>x(t=>({...t,name:e})),onInstructionsChange:e=>x(t=>({...t,instructions:e})),onCreate:()=>void A(),onOpenChange:e=>{S||(x(t=>({...t,open:e})),e||T(null))}})]}):(0,U.jsx)(B,{children:(0,U.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n?`需要本机服务令牌。`:`Local service token required.`})})}export{ce as AgentsSettingsPanel};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/attachment-process-heavy-B2_kr5EA.js","assets/rolldown-runtime-aKtaBQYM.js","assets/preload-helper-zJ_50EbN.js","assets/excel-worksheet-utils-EyvwNT4X.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{t as e}from"./preload-helper-zJ_50EbN.js";import{na as t}from"./index-C6OWYFtQ.js";async function n(n,r){let i,a=r||`unnamed`,o=`application/octet-stream`,s=0;if(typeof n==`string`){let e=await fetch(n);if(!e.ok)throw Error(`Failed to fetch file`);if(i=await e.arrayBuffer(),s=i.byteLength,o=e.headers.get(`content-type`)||o,!r){let e=n.split(`/`);a=e[e.length-1]||`document`}}else if(n instanceof File)i=await n.arrayBuffer(),s=n.size,o=n.type||o,a=r||n.name;else if(n instanceof Blob)i=await n.arrayBuffer(),s=n.size,o=n.type||o;else if(n instanceof ArrayBuffer)i=n,s=n.byteLength;else throw Error(`Invalid source type`);let c=new Uint8Array(i),l=``,u=32768;for(let e=0;e<c.length;e+=u){let t=c.slice(e,e+u);l+=String.fromCharCode(...t)}let d=btoa(l),f=`${a}_${Date.now()}_${Math.random()}`;if(o===`application/pdf`||a.toLowerCase().endsWith(`.pdf`)){let{processPdf:t}=await e(async()=>{let{processPdf:e}=await import(`./attachment-process-heavy-B2_kr5EA.js`);return{processPdf:e}},__vite__mapDeps([0,1,2,3])),{extractedText:n,preview:r}=await t(i,a);return{id:f,type:`document`,name:a,mimeType:`application/pdf`,size:s,content:d,extractedText:n,preview:r}}if(o===`application/vnd.openxmlformats-officedocument.wordprocessingml.document`||a.toLowerCase().endsWith(`.docx`)){let{processDocx:t}=await e(async()=>{let{processDocx:e}=await import(`./attachment-process-heavy-B2_kr5EA.js`);return{processDocx:e}},__vite__mapDeps([0,1,2,3])),{extractedText:n}=await t(i,a);return{id:f,type:`document`,name:a,mimeType:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,size:s,content:d,extractedText:n}}if(o===`application/vnd.openxmlformats-officedocument.presentationml.presentation`||a.toLowerCase().endsWith(`.pptx`)){let{processPptx:t}=await e(async()=>{let{processPptx:e}=await import(`./attachment-process-heavy-B2_kr5EA.js`);return{processPptx:e}},__vite__mapDeps([0,1,2,3])),{extractedText:n}=await t(i,a);return{id:f,type:`document`,name:a,mimeType:`application/vnd.openxmlformats-officedocument.presentationml.presentation`,size:s,content:d,extractedText:n}}if([`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,`application/vnd.ms-excel`].includes(o)||a.toLowerCase().endsWith(`.xlsx`)||a.toLowerCase().endsWith(`.xls`)){let{processExcel:t}=await e(async()=>{let{processExcel:e}=await import(`./attachment-process-heavy-B2_kr5EA.js`);return{processExcel:e}},__vite__mapDeps([0,1,2,3])),{extractedText:n}=await t(i,a);return{id:f,type:`document`,name:a,mimeType:o&&o.startsWith(`application/vnd`)?o:`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`,size:s,content:d,extractedText:n}}if(o?.startsWith(`image/`))return{id:f,type:`image`,name:a,mimeType:o,size:s,content:d,preview:d};if(o?.startsWith(`audio/`))return{id:f,type:`voice`,name:a,mimeType:o,size:s,content:d};if(t(a,o??``)){let e=new TextDecoder().decode(i);return{id:f,type:`document`,name:a,mimeType:o?.startsWith(`text/`)?o:`text/plain`,size:s,content:d,extractedText:e}}throw Error(`Unsupported file type: ${o}`)}export{n as loadAttachment};
|