@ftai/plugin-host-api 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +4 -2
- package/lib/attachments.d.ts +38 -0
- package/lib/attachments.js +26 -0
- package/lib/fs.d.ts +53 -0
- package/lib/fs.js +14 -0
- package/lib/generated.d.ts +579 -0
- package/lib/generated.js +20 -0
- package/lib/index.d.ts +369 -0
- package/lib/index.js +110 -0
- package/lib/llm.d.ts +152 -0
- package/lib/llm.js +102 -0
- package/lib/porting.d.ts +35 -0
- package/lib/porting.js +127 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Non-Convex Tech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ftai/plugin-host-api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
FtAi Desktop 插件后端的接口。插件经 `@ftai/plugin-sdk/host` 使用,不用直接依赖本包。
|
|
4
|
+
|
|
5
|
+
开发文档见 <https://ftai.chat/desktop/docs/plugins/>。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 附件(0.12 的 `ctx.attachments`,0.12 的 `attachment` 包):把图片存进宿主的附件存储,引用可以放进工具结果与
|
|
3
|
+
* 模型请求。名字、引用的字段与错误码照 0.12;引用的形状由扩展点表生成(`ImageRef`、`FileRef`)。
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { FileRef, ImageMediaType, ImageRef } from './generated.ts';
|
|
7
|
+
/** 0.12 的名字:存下的一张图片(会话日志里也是这个形状),缩小过的带 `originalDimensions`。 */
|
|
8
|
+
export type ImageAttachmentRef = ImageRef;
|
|
9
|
+
/** 0.12 的名字:存下的一个文件。 */
|
|
10
|
+
export type FileAttachmentRef = FileRef;
|
|
11
|
+
export interface SaveImageAttachment {
|
|
12
|
+
readonly data: Uint8Array;
|
|
13
|
+
readonly mediaType: ImageMediaType;
|
|
14
|
+
readonly name?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const IMAGE_ADMISSION_ERROR_CODES: readonly ["TOO_MANY_IMAGES", "IMAGES_TOO_LARGE", "UNSUPPORTED_IMAGE_TYPE", "INVALID_IMAGE_BASE64", "INVALID_IMAGE", "IMAGE_TYPE_MISMATCH", "IMAGE_TOO_LARGE", "IMAGE_TOO_MANY_PIXELS", "IMAGE_DIMENSION_TOO_LARGE"];
|
|
17
|
+
export declare const ATTACHMENT_ERROR_CODES: readonly ["TOO_MANY_IMAGES", "IMAGES_TOO_LARGE", "UNSUPPORTED_IMAGE_TYPE", "INVALID_IMAGE_BASE64", "INVALID_IMAGE", "IMAGE_TYPE_MISMATCH", "IMAGE_TOO_LARGE", "IMAGE_TOO_MANY_PIXELS", "IMAGE_DIMENSION_TOO_LARGE", "INVALID_FILE_BASE64", "INVALID_ATTACHMENT_REF", "ATTACHMENT_CORRUPT", "ATTACHMENT_WRITE_FAILED", "ATTACHMENT_NOT_FOUND", "ATTACHMENT_READ_FAILED", "ATTACHMENT_PROJECTION_UNSUPPORTED", "ATTACHMENT_FILES_UNSUPPORTED"];
|
|
18
|
+
/** 图片准入的错误码:图片本身不合要求(个数、大小、格式、像素、边长)。 */
|
|
19
|
+
export type ImageAdmissionErrorCode = typeof IMAGE_ADMISSION_ERROR_CODES[number];
|
|
20
|
+
export type AttachmentErrorCode = typeof ATTACHMENT_ERROR_CODES[number];
|
|
21
|
+
/** 附件存储的失败(同 0.12):错误码与 0.12 原文的说明。 */
|
|
22
|
+
export declare class AttachmentError extends Error {
|
|
23
|
+
readonly code: AttachmentErrorCode;
|
|
24
|
+
constructor(message: string, code: AttachmentErrorCode, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
export declare function isAttachmentError(error: unknown): error is AttachmentError;
|
|
27
|
+
/** 图片本身不合要求:调用方可以把说明交给模型,换一句替代的文字(同 0.12)。 */
|
|
28
|
+
export declare function isImageAdmissionError(error: unknown): error is AttachmentError & {
|
|
29
|
+
readonly code: ImageAdmissionErrorCode;
|
|
30
|
+
};
|
|
31
|
+
export interface AttachmentStoreService {
|
|
32
|
+
/**
|
|
33
|
+
* 存一批图片:先整批检查个数、总大小与格式,再逐张准入与规范化,全部通过才写入。
|
|
34
|
+
* @returns 与输入同序的引用。
|
|
35
|
+
* @throws AttachmentError
|
|
36
|
+
*/
|
|
37
|
+
saveImages(inputs: readonly SaveImageAttachment[]): Promise<readonly ImageAttachmentRef[]>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const IMAGE_ADMISSION_ERROR_CODES = [
|
|
2
|
+
'TOO_MANY_IMAGES', 'IMAGES_TOO_LARGE', 'UNSUPPORTED_IMAGE_TYPE', 'INVALID_IMAGE_BASE64', 'INVALID_IMAGE', 'IMAGE_TYPE_MISMATCH',
|
|
3
|
+
'IMAGE_TOO_LARGE', 'IMAGE_TOO_MANY_PIXELS', 'IMAGE_DIMENSION_TOO_LARGE',
|
|
4
|
+
];
|
|
5
|
+
export const ATTACHMENT_ERROR_CODES = [
|
|
6
|
+
...IMAGE_ADMISSION_ERROR_CODES,
|
|
7
|
+
'INVALID_FILE_BASE64', 'INVALID_ATTACHMENT_REF', 'ATTACHMENT_CORRUPT', 'ATTACHMENT_WRITE_FAILED', 'ATTACHMENT_NOT_FOUND',
|
|
8
|
+
'ATTACHMENT_READ_FAILED', 'ATTACHMENT_PROJECTION_UNSUPPORTED', 'ATTACHMENT_FILES_UNSUPPORTED',
|
|
9
|
+
];
|
|
10
|
+
/** 附件存储的失败(同 0.12):错误码与 0.12 原文的说明。 */
|
|
11
|
+
export class AttachmentError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
constructor(message, code, options) {
|
|
14
|
+
super(message, options);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.name = 'AttachmentError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function isAttachmentError(error) {
|
|
20
|
+
return error instanceof AttachmentError;
|
|
21
|
+
}
|
|
22
|
+
/** 图片本身不合要求:调用方可以把说明交给模型,换一句替代的文字(同 0.12)。 */
|
|
23
|
+
export function isImageAdmissionError(error) {
|
|
24
|
+
return isAttachmentError(error) && IMAGE_ADMISSION_ERROR_CODES.includes(error.code);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=attachments.js.map
|
package/lib/fs.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件(0.12 的 `ctx.fs`,0.12 的 `fs` 包):与文件工具同一套路径解析、读取与写入,名字与参数照 0.12。
|
|
3
|
+
*
|
|
4
|
+
* 插件进程本来就能用 `node:fs` 读写本机文件,`ctx.fs` 不是权限边界。用它是为了与 read、write 工具对同一个路径得到同一个
|
|
5
|
+
* 文件,写入先经本轮改动记录(`fs/write-intent`,改动面板据此显示与撤销),并受会话的沙箱约束。
|
|
6
|
+
*
|
|
7
|
+
* 与 0.12 不同的地方:
|
|
8
|
+
* - 二进制文件由宿主写(`writeBytes`,0.12 没有),插件不再自己写、自己围沙箱;
|
|
9
|
+
* - 宿主上的操作中途取消不了:`signal` 在调用前后各查一次,已中止时抛 `signal.reason`;
|
|
10
|
+
* - `targetKey` 与 `version` 是普通字符串,不是 0.12 的品牌类型;目标、元数据与写入条件的形状由扩展点表生成(`FsTarget`、
|
|
11
|
+
* `FsInfo`、`FsWriteIntent`),`FsInfo.size` 总是有。
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import type { FsInfo, FsTarget, FsWriteIntent, FsWritten } from './generated.ts';
|
|
15
|
+
import type { ToolExecution } from './index.ts';
|
|
16
|
+
export interface FsWriteBytesOptions {
|
|
17
|
+
/** 发起写入的工具调用:本轮改动记录据此先存下原文件。给了但调用已经结束时宿主拒绝写入。 */
|
|
18
|
+
readonly execution?: ToolExecution;
|
|
19
|
+
/** 写入条件;不给即无条件新建或覆盖。 */
|
|
20
|
+
readonly expected?: FsWriteIntent;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
export declare const FS_ERROR_CODES: readonly ["FS_NOT_FOUND", "FS_NOT_DIRECTORY", "FS_NOT_TEXT", "FS_NOT_REGULAR_FILE", "FS_TOO_LARGE", "FS_PERMISSION_DENIED", "FS_SANDBOX_DENIED", "FS_IO_ERROR", "FS_STALE_VERSION", "FS_NOT_OBSERVED", "FS_AMBIGUOUS_EDIT", "FS_EDIT_NOT_FOUND", "FS_ABORTED"];
|
|
24
|
+
export type FsErrorCode = typeof FS_ERROR_CODES[number];
|
|
25
|
+
/** 文件服务的失败(同 0.12):稳定的错误码与给模型看的说明。 */
|
|
26
|
+
export declare class FsError extends Error {
|
|
27
|
+
readonly code: FsErrorCode;
|
|
28
|
+
constructor(message: string, code: FsErrorCode, options?: ErrorOptions);
|
|
29
|
+
}
|
|
30
|
+
export interface FileSystemService {
|
|
31
|
+
/**
|
|
32
|
+
* 解析路径;相对路径按 `cwd`(不给时用宿主的默认目录),不存在的路径也能定位。
|
|
33
|
+
* @returns 目标;同一个文件得到同一个 `targetKey`。
|
|
34
|
+
*/
|
|
35
|
+
resolve(path: string, opts?: {
|
|
36
|
+
readonly cwd?: string;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
}): Promise<FsTarget>;
|
|
39
|
+
/**
|
|
40
|
+
* 给子进程或别的系统能力用的绝对路径(同步)。
|
|
41
|
+
* @param target - 本进程 `resolve` 得到的目标。
|
|
42
|
+
*/
|
|
43
|
+
processPath(target: FsTarget): string;
|
|
44
|
+
/** 元数据;不存在时为 undefined。 */
|
|
45
|
+
stat(target: FsTarget, signal?: AbortSignal): Promise<FsInfo | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* 读出整份文件。
|
|
48
|
+
* @param maxBytes - 上限(含);超过时报 `FS_TOO_LARGE`,不返回截断的内容。
|
|
49
|
+
*/
|
|
50
|
+
readBytes(target: FsTarget, signal: AbortSignal | undefined, maxBytes: number): Promise<Uint8Array>;
|
|
51
|
+
/** 写入整份二进制:在目标目录里原子发布,沿用原文件的权限,缺的父目录一并建。 */
|
|
52
|
+
writeBytes(target: FsTarget, data: Uint8Array, options?: FsWriteBytesOptions): Promise<FsWritten>;
|
|
53
|
+
}
|
package/lib/fs.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const FS_ERROR_CODES = [
|
|
2
|
+
'FS_NOT_FOUND', 'FS_NOT_DIRECTORY', 'FS_NOT_TEXT', 'FS_NOT_REGULAR_FILE', 'FS_TOO_LARGE', 'FS_PERMISSION_DENIED', 'FS_SANDBOX_DENIED',
|
|
3
|
+
'FS_IO_ERROR', 'FS_STALE_VERSION', 'FS_NOT_OBSERVED', 'FS_AMBIGUOUS_EDIT', 'FS_EDIT_NOT_FOUND', 'FS_ABORTED',
|
|
4
|
+
];
|
|
5
|
+
/** 文件服务的失败(同 0.12):稳定的错误码与给模型看的说明。 */
|
|
6
|
+
export class FsError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(message, code, options) {
|
|
9
|
+
super(message, options);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.name = 'FsError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=fs.js.map
|