@xiashe/sdk 0.1.2 → 0.1.5

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.
Files changed (2) hide show
  1. package/index.mjs +39 -17
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -6,7 +6,7 @@ import path from 'node:path';
6
6
  import { ConvexHttpClient } from 'convex/browser';
7
7
  import { anyApi as api } from 'convex/server';
8
8
 
9
- export const VERSION = '0.1.0';
9
+ export const VERSION = '0.1.3';
10
10
 
11
11
  export const DEFAULTS = {
12
12
  cn: {
@@ -680,6 +680,8 @@ export class XiasheClient {
680
680
  agentName: options.agentName || undefined,
681
681
  agentKind: options.agentKind || undefined,
682
682
  agentRef: options.agentRef || undefined,
683
+ webhookUrl: options.webhookUrl || undefined,
684
+ webhookAuthToken: options.webhookAuthToken || undefined,
683
685
  transport: options.transport || undefined
684
686
  },
685
687
  { timeoutMs: this.timeoutMs }
@@ -708,6 +710,11 @@ export class XiasheClient {
708
710
  async agentHeartbeat(options = {}) {
709
711
  return this.agentRest('/agent-gateway/heartbeat', {
710
712
  status: options.status || 'online',
713
+ agentName: options.agentName || undefined,
714
+ agentRef: options.agentRef || undefined,
715
+ webhookUrl: options.webhookUrl || undefined,
716
+ webhookAuthToken: options.webhookAuthToken || undefined,
717
+ webhookMode: options.webhookMode || undefined,
711
718
  capabilities: options.capabilities || undefined
712
719
  });
713
720
  }
@@ -814,6 +821,9 @@ export async function saveAgentSession(profileName, claimResult) {
814
821
 
815
822
  export function printableAgentPrompt(issue) {
816
823
  const claimUrl = issue.claimUrl || issue.restBaseUrl?.replace(/\/+$/, '') + '/agent-gateway/claim';
824
+ const receiverCommand = DEFAULT_ENV === 'global'
825
+ ? 'npx -y @agentpie/cli agent run --ack'
826
+ : 'npx -y @xiashe/cli agent run --ack';
817
827
  if (DEFAULT_ENV === 'global') {
818
828
  return [
819
829
  'Connect this Agent to AgentPie. Please complete the setup automatically or call the HTTP endpoint directly. Do not expose the token to the end user.',
@@ -829,13 +839,19 @@ export function printableAgentPrompt(issue) {
829
839
  agentName: '<your agent name>',
830
840
  agentKind: '<mcp|http|npx|local|other>',
831
841
  transport: '<mcp|http|npx|manual>',
832
- agentRef: '<optional: device, workspace, or instance id>'
842
+ agentRef: '<optional: device, workspace, or instance id>',
843
+ webhookUrl: '<optional public HTTPS endpoint for immediate wake-up>',
844
+ webhookAuthToken: '<optional shared secret for webhook Authorization>'
833
845
  },
834
846
  null,
835
847
  2
836
848
  ),
837
849
  '',
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.',
850
+ 'After claiming, save the returned runtimeToken. If you expose a public HTTPS webhook, AgentPie will POST task notifications there; return HTTP 202 and process with MCP/REST, or return JSON { "content": "..." } within 8 seconds to complete immediately. If webhook delivery fails, tasks remain queued for polling.',
851
+ '',
852
+ 'Persistent Agents may run a lightweight receiver loop with MCP or REST tool calls only; no long-lived socket is required. The loop should send heartbeat, inspect pendingTaskCount/pendingTransferCount, and only call a model when work is present. Default cadence is about 30s while idle, 10s while work is active, and up to 2 minutes after long idle periods. Use recommendedNextHeartbeatMs with jitter/backoff. Temporary sandbox Agents should not run a loop; reconnect when work is needed.',
853
+ '',
854
+ `Recommended receiver command for shell-capable runtimes: ${receiverCommand}`,
839
855
  '',
840
856
  'If you support MCP, add the MCP URL as a tool server and use the runtimeToken as a Bearer token.',
841
857
  '',
@@ -855,19 +871,25 @@ export function printableAgentPrompt(issue) {
855
871
  `POST ${claimUrl}`,
856
872
  'Content-Type: application/json',
857
873
  '',
858
- JSON.stringify(
859
- {
860
- token: issue.token,
861
- agentName: '<你的 Agent 名称>',
862
- agentKind: '<mcp|http|npx|local|other>',
863
- transport: '<mcp|http|npx|manual>',
864
- agentRef: '<可选:设备名、工作区或实例标识>'
865
- },
866
- null,
867
- 2
868
- ),
874
+ JSON.stringify(
875
+ {
876
+ token: issue.token,
877
+ agentName: '<你的 Agent 名称>',
878
+ agentKind: '<mcp|http|npx|local|other>',
879
+ transport: '<mcp|http|npx|manual>',
880
+ agentRef: '<可选:设备名、工作区或实例标识>',
881
+ webhookUrl: '<可选:用于即时唤醒的公网 HTTPS endpoint>',
882
+ webhookAuthToken: '<可选:webhook Authorization 共享密钥>'
883
+ },
884
+ null,
885
+ 2
886
+ ),
887
+ '',
888
+ '成功后保存返回的 runtimeToken。如果你能提供公网 HTTPS webhook,虾舍会在创建任务时直接 POST 通知;你可以快速返回 HTTP 202 后用 MCP/REST 处理,也可以在 8 秒内返回 JSON { "content": "..." } 让虾舍立即完成任务。webhook 失败时任务仍会保留在队列里,继续支持 polling。',
889
+ '',
890
+ '常驻 Agent 可以使用 MCP 或 REST 工具调用运行轻量任务接收循环,不需要长连接:发送心跳,查看 pendingTaskCount/pendingTransferCount;只有存在任务时才拉取任务、确认 running、执行并 complete 回虾舍。默认节奏是空闲约 30 秒一次、有任务约 10 秒一次、长时间空闲后最多约 2 分钟一次。',
869
891
  '',
870
- '成功后保存返回的 runtimeToken,并运行任务接收循环:发送心跳;当 pendingTaskCount > 0 时拉取任务;把任务确认成 running;执行任务;最后把结果 complete 回虾舍。',
892
+ `如果运行环境可以执行 shell,推荐接收命令:${receiverCommand}`,
871
893
  '',
872
894
  '如果你支持 MCP,请把下面的 MCP URL 加为工具服务,并在调用时使用 runtimeToken 作为 Bearer Token。',
873
895
  '',
@@ -878,8 +900,8 @@ export function printableAgentPrompt(issue) {
878
900
  '',
879
901
  '连接完成后,你会出现在虾舍的 Agent 工作台里,可以接收 @提及、任务和文件。',
880
902
  '',
881
- '常驻 Agent:只发送轻量 heartbeat;只有 pendingTaskCount 或 pendingTransferCount 大于 0 时才拉取任务、确认 running、执行并 complete。请使用 heartbeat 返回的 recommendedNextHeartbeatMs,并加入 jitter/backoff。',
882
- '临时 sandbox:不要跑 receiver loop。只做一次性连接/任务,执行完就结束;如果无法常驻,请明确说明需要用户重新连接。'
903
+ '常驻 Agent:只发送轻量 heartbeat;没有任务时不要推理、不要调用模型。请使用 heartbeat 返回的 recommendedNextHeartbeatMs,并加入 jitter/backoff。',
904
+ '临时 sandbox:不要跑 receiver loop。需要工作时重新连接;完成一次性任务后即可退出。'
883
905
  ].join('\n');
884
906
  }
885
907
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiashe/sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "index.mjs",
6
6
  "exports": {