@xiashe/sdk 0.1.0 → 0.1.2
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/index.mjs +48 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -38,6 +38,7 @@ const CONFIG_DIR = process.env.XIASHE_CONFIG_DIR || path.join(os.homedir(), DEFA
|
|
|
38
38
|
const CONFIG_PATH = process.env.XIASHE_CONFIG_PATH || path.join(CONFIG_DIR, 'config.json');
|
|
39
39
|
const DEFAULT_PROFILE = 'default';
|
|
40
40
|
const HTTP_TIMEOUT_MS = 20_000;
|
|
41
|
+
const DEFAULT_MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
|
|
41
42
|
|
|
42
43
|
export class XiasheError extends Error {
|
|
43
44
|
constructor(message, options = {}) {
|
|
@@ -529,6 +530,16 @@ export class XiasheClient {
|
|
|
529
530
|
return this.query(api.agentGateway.listForUser, this.authArgs({ limit }));
|
|
530
531
|
}
|
|
531
532
|
|
|
533
|
+
async revokeAgent(agentConnectionId, options = {}) {
|
|
534
|
+
return this.mutation(
|
|
535
|
+
api.agentGateway.revokeConnection,
|
|
536
|
+
this.authArgs({
|
|
537
|
+
agentConnectionId,
|
|
538
|
+
idempotencyKey: options.idempotencyKey || createIdempotencyKey('cli-agent-revoke', [agentConnectionId])
|
|
539
|
+
})
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
|
|
532
543
|
async createAgentChatTask(options = {}) {
|
|
533
544
|
return this.mutation(
|
|
534
545
|
api.agentGateway.createChatTask,
|
|
@@ -598,6 +609,12 @@ export class XiasheClient {
|
|
|
598
609
|
if (!info.isFile()) {
|
|
599
610
|
throw new XiasheError(`Not a file: ${absolutePath}`, { code: 'UPLOAD_NOT_FILE' });
|
|
600
611
|
}
|
|
612
|
+
if (info.size > DEFAULT_MAX_UPLOAD_BYTES) {
|
|
613
|
+
throw new XiasheError(`File too large. Max ${DEFAULT_MAX_UPLOAD_BYTES} bytes.`, {
|
|
614
|
+
code: 'UPLOAD_FILE_TOO_LARGE',
|
|
615
|
+
details: { maxBytes: DEFAULT_MAX_UPLOAD_BYTES, size: info.size }
|
|
616
|
+
});
|
|
617
|
+
}
|
|
601
618
|
const fileName = options.fileName || path.basename(absolutePath);
|
|
602
619
|
const mime = options.mime || inferMime(absolutePath);
|
|
603
620
|
const source = options.source || 'manual_upload';
|
|
@@ -701,6 +718,28 @@ export class XiasheClient {
|
|
|
701
718
|
});
|
|
702
719
|
}
|
|
703
720
|
|
|
721
|
+
async agentListTransfers(options = {}) {
|
|
722
|
+
return this.agentRest('/agent-gateway/transfers/list', {
|
|
723
|
+
limit: options.limit || 20
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
async agentAcceptTransfer(transferId, options = {}) {
|
|
728
|
+
return this.agentRest('/agent-gateway/transfers/accept', {
|
|
729
|
+
transferId,
|
|
730
|
+
idempotencyKey: options.idempotencyKey || undefined
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async agentCompleteTransfer(transferId, options = {}) {
|
|
735
|
+
return this.agentRest('/agent-gateway/transfers/complete', {
|
|
736
|
+
transferId,
|
|
737
|
+
status: options.status || 'completed',
|
|
738
|
+
error: options.error || undefined,
|
|
739
|
+
idempotencyKey: options.idempotencyKey || undefined
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
|
|
704
743
|
async agentAckTask(taskId, state = 'running') {
|
|
705
744
|
return this.agentRest('/agent-gateway/tasks/ack', { taskId, state });
|
|
706
745
|
}
|
|
@@ -716,6 +755,7 @@ export class XiasheClient {
|
|
|
716
755
|
async agentCreateTask(options = {}) {
|
|
717
756
|
return this.agentRest('/agent-gateway/tasks/create', {
|
|
718
757
|
targetAgentConnectionId: options.targetAgentConnectionId,
|
|
758
|
+
targetAgentName: options.targetAgentName,
|
|
719
759
|
chatId: options.chatId,
|
|
720
760
|
content: options.content,
|
|
721
761
|
attachments: options.attachments || undefined,
|
|
@@ -787,7 +827,7 @@ export function printableAgentPrompt(issue) {
|
|
|
787
827
|
{
|
|
788
828
|
token: issue.token,
|
|
789
829
|
agentName: '<your agent name>',
|
|
790
|
-
agentKind: '<
|
|
830
|
+
agentKind: '<mcp|http|npx|local|other>',
|
|
791
831
|
transport: '<mcp|http|npx|manual>',
|
|
792
832
|
agentRef: '<optional: device, workspace, or instance id>'
|
|
793
833
|
},
|
|
@@ -795,7 +835,7 @@ export function printableAgentPrompt(issue) {
|
|
|
795
835
|
2
|
|
796
836
|
),
|
|
797
837
|
'',
|
|
798
|
-
'After claiming, save the returned runtimeToken and
|
|
838
|
+
'After claiming, save the returned runtimeToken. Persistent Agents should run a lightweight receiver loop: send heartbeat only, and do not reason or call a model unless pendingTaskCount or pendingTransferCount is greater than 0. Use the heartbeat response recommendedNextHeartbeatMs with jitter/backoff. Temporary sandbox Agents should not run a loop; claim once, finish the task, then exit.',
|
|
799
839
|
'',
|
|
800
840
|
'If you support MCP, add the MCP URL as a tool server and use the runtimeToken as a Bearer token.',
|
|
801
841
|
'',
|
|
@@ -819,7 +859,7 @@ export function printableAgentPrompt(issue) {
|
|
|
819
859
|
{
|
|
820
860
|
token: issue.token,
|
|
821
861
|
agentName: '<你的 Agent 名称>',
|
|
822
|
-
agentKind: '<
|
|
862
|
+
agentKind: '<mcp|http|npx|local|other>',
|
|
823
863
|
transport: '<mcp|http|npx|manual>',
|
|
824
864
|
agentRef: '<可选:设备名、工作区或实例标识>'
|
|
825
865
|
},
|
|
@@ -827,7 +867,7 @@ export function printableAgentPrompt(issue) {
|
|
|
827
867
|
2
|
|
828
868
|
),
|
|
829
869
|
'',
|
|
830
|
-
'成功后保存返回的 runtimeToken
|
|
870
|
+
'成功后保存返回的 runtimeToken,并运行任务接收循环:发送心跳;当 pendingTaskCount > 0 时拉取任务;把任务确认成 running;执行任务;最后把结果 complete 回虾舍。',
|
|
831
871
|
'',
|
|
832
872
|
'如果你支持 MCP,请把下面的 MCP URL 加为工具服务,并在调用时使用 runtimeToken 作为 Bearer Token。',
|
|
833
873
|
'',
|
|
@@ -836,7 +876,10 @@ export function printableAgentPrompt(issue) {
|
|
|
836
876
|
`MCP URL: ${issue.mcpUrl}`,
|
|
837
877
|
`REST Base URL: ${issue.restBaseUrl}`,
|
|
838
878
|
'',
|
|
839
|
-
'连接完成后,你会出现在虾舍的 Agent 工作台里,可以接收 @提及、任务和文件。'
|
|
879
|
+
'连接完成后,你会出现在虾舍的 Agent 工作台里,可以接收 @提及、任务和文件。',
|
|
880
|
+
'',
|
|
881
|
+
'常驻 Agent:只发送轻量 heartbeat;只有 pendingTaskCount 或 pendingTransferCount 大于 0 时才拉取任务、确认 running、执行并 complete。请使用 heartbeat 返回的 recommendedNextHeartbeatMs,并加入 jitter/backoff。',
|
|
882
|
+
'临时 sandbox:不要跑 receiver loop。只做一次性连接/任务,执行完就结束;如果无法常驻,请明确说明需要用户重新连接。'
|
|
840
883
|
].join('\n');
|
|
841
884
|
}
|
|
842
885
|
|