@insta-dev01/insta-plugin-openclaw 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/index.d.ts +9 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +171 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/src/channel/config.d.ts +9 -0
  6. package/dist/src/channel/config.d.ts.map +1 -0
  7. package/dist/src/channel/config.js +10 -0
  8. package/dist/src/channel/config.js.map +1 -0
  9. package/dist/src/channel/connection.d.ts +34 -0
  10. package/dist/src/channel/connection.d.ts.map +1 -0
  11. package/dist/src/channel/connection.js +281 -0
  12. package/dist/src/channel/connection.js.map +1 -0
  13. package/dist/src/channel/dispatcher.d.ts +43 -0
  14. package/dist/src/channel/dispatcher.d.ts.map +1 -0
  15. package/dist/src/channel/dispatcher.js +324 -0
  16. package/dist/src/channel/dispatcher.js.map +1 -0
  17. package/dist/src/channel/index.d.ts +5 -0
  18. package/dist/src/channel/index.d.ts.map +1 -0
  19. package/dist/src/channel/index.js +135 -0
  20. package/dist/src/channel/index.js.map +1 -0
  21. package/dist/src/channel/logger.d.ts +10 -0
  22. package/dist/src/channel/logger.d.ts.map +1 -0
  23. package/dist/src/channel/logger.js +30 -0
  24. package/dist/src/channel/logger.js.map +1 -0
  25. package/dist/src/channel/protocol.d.ts +15 -0
  26. package/dist/src/channel/protocol.d.ts.map +1 -0
  27. package/dist/src/channel/protocol.js +204 -0
  28. package/dist/src/channel/protocol.js.map +1 -0
  29. package/dist/src/channel/registrar.d.ts +21 -0
  30. package/dist/src/channel/registrar.d.ts.map +1 -0
  31. package/dist/src/channel/registrar.js +115 -0
  32. package/dist/src/channel/registrar.js.map +1 -0
  33. package/dist/src/channel/registration-store.d.ts +21 -0
  34. package/dist/src/channel/registration-store.d.ts.map +1 -0
  35. package/{src/channel/registration-store.ts → dist/src/channel/registration-store.js} +21 -46
  36. package/dist/src/channel/registration-store.js.map +1 -0
  37. package/dist/src/channel/types.d.ts +80 -0
  38. package/dist/src/channel/types.d.ts.map +1 -0
  39. package/dist/src/channel/types.js +3 -0
  40. package/dist/src/channel/types.js.map +1 -0
  41. package/dist/src/core/index.d.ts +5 -0
  42. package/dist/src/core/index.d.ts.map +1 -0
  43. package/dist/src/core/index.js +3 -0
  44. package/dist/src/core/index.js.map +1 -0
  45. package/dist/src/core/register-identity.d.ts +58 -0
  46. package/dist/src/core/register-identity.d.ts.map +1 -0
  47. package/dist/src/core/register-identity.js +251 -0
  48. package/dist/src/core/register-identity.js.map +1 -0
  49. package/dist/src/core/task-api.d.ts +31 -0
  50. package/dist/src/core/task-api.d.ts.map +1 -0
  51. package/dist/src/core/task-api.js +116 -0
  52. package/dist/src/core/task-api.js.map +1 -0
  53. package/dist/src/core/urls.d.ts +33 -0
  54. package/dist/src/core/urls.d.ts.map +1 -0
  55. package/dist/src/core/urls.js +40 -0
  56. package/dist/src/core/urls.js.map +1 -0
  57. package/dist/src/tools/get-plugin-profile.d.ts +7 -0
  58. package/dist/src/tools/get-plugin-profile.d.ts.map +1 -0
  59. package/dist/src/tools/get-plugin-profile.js +132 -0
  60. package/dist/src/tools/get-plugin-profile.js.map +1 -0
  61. package/dist/src/tools/grab-task.d.ts +7 -0
  62. package/dist/src/tools/grab-task.d.ts.map +1 -0
  63. package/dist/src/tools/grab-task.js +100 -0
  64. package/dist/src/tools/grab-task.js.map +1 -0
  65. package/dist/src/tools/list-tasks.d.ts +7 -0
  66. package/dist/src/tools/list-tasks.d.ts.map +1 -0
  67. package/dist/src/tools/list-tasks.js +92 -0
  68. package/dist/src/tools/list-tasks.js.map +1 -0
  69. package/dist/src/tools/propose-registration.d.ts +14 -0
  70. package/dist/src/tools/propose-registration.d.ts.map +1 -0
  71. package/dist/src/tools/propose-registration.js +103 -0
  72. package/dist/src/tools/propose-registration.js.map +1 -0
  73. package/dist/src/tools/register-identity.d.ts +11 -0
  74. package/dist/src/tools/register-identity.d.ts.map +1 -0
  75. package/dist/src/tools/register-identity.js +101 -0
  76. package/dist/src/tools/register-identity.js.map +1 -0
  77. package/dist/src/tools/submit-deliverable.d.ts +17 -0
  78. package/dist/src/tools/submit-deliverable.d.ts.map +1 -0
  79. package/dist/src/tools/submit-deliverable.js +215 -0
  80. package/dist/src/tools/submit-deliverable.js.map +1 -0
  81. package/dist/src/tools/upload-artifact.d.ts +14 -0
  82. package/dist/src/tools/upload-artifact.d.ts.map +1 -0
  83. package/dist/src/tools/upload-artifact.js +166 -0
  84. package/dist/src/tools/upload-artifact.js.map +1 -0
  85. package/dist/src/utils/file-lock.d.ts +4 -0
  86. package/dist/src/utils/file-lock.d.ts.map +1 -0
  87. package/dist/src/utils/file-lock.js +43 -0
  88. package/dist/src/utils/file-lock.js.map +1 -0
  89. package/dist/src/utils/profile.d.ts +17 -0
  90. package/dist/src/utils/profile.d.ts.map +1 -0
  91. package/dist/src/utils/profile.js +26 -0
  92. package/dist/src/utils/profile.js.map +1 -0
  93. package/dist/src/utils/session.d.ts +3 -0
  94. package/dist/src/utils/session.d.ts.map +1 -0
  95. package/dist/src/utils/session.js +26 -0
  96. package/dist/src/utils/session.js.map +1 -0
  97. package/package.json +17 -5
  98. package/.env.example +0 -23
  99. package/channel/346/265/201/347/250/213/345/233/276.md +0 -477
  100. package/index.ts +0 -198
  101. package/src/channel/config.ts +0 -27
  102. package/src/channel/connection.ts +0 -341
  103. package/src/channel/dispatcher.ts +0 -374
  104. package/src/channel/index.ts +0 -173
  105. package/src/channel/logger.ts +0 -36
  106. package/src/channel/protocol.ts +0 -265
  107. package/src/channel/registrar.ts +0 -172
  108. package/src/channel/types.ts +0 -102
  109. package/src/core/index.ts +0 -13
  110. package/src/core/register-identity.ts +0 -326
  111. package/src/core/task-api.ts +0 -168
  112. package/src/core/urls.ts +0 -52
  113. package/src/prompt/job.md +0 -21
  114. package/src/tools/get-plugin-profile.ts +0 -152
  115. package/src/tools/grab-task.ts +0 -133
  116. package/src/tools/list-tasks.ts +0 -135
  117. package/src/tools/propose-registration.ts +0 -116
  118. package/src/tools/register-identity.ts +0 -121
  119. package/src/tools/submit-deliverable.ts +0 -268
  120. package/src/tools/upload-artifact.ts +0 -222
  121. package/src/utils/file-lock.ts +0 -43
  122. package/src/utils/profile.ts +0 -45
  123. package/src/utils/session.ts +0 -30
  124. package/tests/profile.test.ts +0 -70
  125. package/tests/session.test.ts +0 -53
  126. package/tsconfig.json +0 -49
  127. package/vitest.config.ts +0 -26
@@ -1,326 +0,0 @@
1
- import type { Profile } from "../utils/profile.js";
2
- import { readProfile, writeProfile } from "../utils/profile.js";
3
- import { getInstaUrl } from "./urls.js";
4
-
5
- // ──────────────────────────────────────────────────────────────────────────────
6
- // 场景标签(Scene Tags)合法值集合
7
- // 注册时 scene_tags 必须从以下二级分类 ID 中选取
8
- // ──────────────────────────────────────────────────────────────────────────────
9
-
10
- export const SCENE_TAGS: Record<string, { label: string; children: Record<string, string> }> = {
11
- "01": {
12
- label: "技术开发",
13
- children: {
14
- "01001": "前端",
15
- "01002": "后端/架构",
16
- "01003": "AI/算法",
17
- "01004": "运维",
18
- "01005": "产品设计",
19
- },
20
- },
21
- "02": {
22
- label: "内容创作",
23
- children: {
24
- "02001": "文本创作",
25
- "02002": "翻译与本地化",
26
- "02003": "剧本/创意",
27
- },
28
- },
29
- "03": {
30
- label: "视觉设计",
31
- children: {
32
- "03001": "平面/视觉",
33
- "03002": "UI/交互",
34
- "03003": "三维/多媒体",
35
- },
36
- },
37
- "04": {
38
- label: "企业办公",
39
- children: {
40
- "04001": "行政管理",
41
- "04002": "商务汇报",
42
- "04003": "人力资源",
43
- },
44
- },
45
- "05": {
46
- label: "数据市场",
47
- children: {
48
- "05001": "数据处理",
49
- "05002": "分析调研",
50
- },
51
- },
52
- "06": {
53
- label: "电商营销",
54
- children: {
55
- "06001": "电商运营",
56
- "06002": "私域增长",
57
- },
58
- },
59
- "07": {
60
- label: "法律咨询",
61
- children: {
62
- "07001": "学术/教育",
63
- "07002": "法律/金融",
64
- "07003": "心理/生活",
65
- },
66
- },
67
- "08": {
68
- label: "生活娱乐",
69
- children: {
70
- "08001": "生活决策",
71
- "08002": "娱乐互动",
72
- },
73
- },
74
- };
75
-
76
- /** 所有合法的二级分类 ID 集合,用于校验 */
77
- export const VALID_SCENE_TAG_IDS: ReadonlySet<string> = new Set(
78
- Object.values(SCENE_TAGS).flatMap((g) => Object.keys(g.children)),
79
- );
80
-
81
- // ──────────────────────────────────────────────────────────────────────────────
82
- // instance_type 合法值
83
- // ──────────────────────────────────────────────────────────────────────────────
84
-
85
- const VALID_INSTANCE_TYPES = new Set([0, 1]);
86
-
87
- // ──────────────────────────────────────────────────────────────────────────────
88
- // 类型定义
89
- // ──────────────────────────────────────────────────────────────────────────────
90
-
91
- /** 注册档案的请求参数 */
92
- export interface RegisterIdentityParams {
93
- /** 档案名称(必填) */
94
- name: string;
95
- /** 头像 URL(必填) */
96
- avatar: string;
97
- /** 场景标签 ID 数组(必填,必须从合法值中选取) */
98
- scene_tags: string[];
99
- /** 自定义标签列表(可选) */
100
- custom_tags?: string[];
101
- /** 描述信息(必填) */
102
- description: string;
103
- /** 时薪(必填,必须 > 0) */
104
- hourly_rate: number;
105
- /** 实例类型:0=本地实例, 1=影子实例 */
106
- instance_type: 0 | 1;
107
- }
108
-
109
- /** 注册成功后服务端返回的数据 */
110
- export interface RegisterIdentityResponse {
111
- /** 档案主键 ID (BigInt string) */
112
- id: string;
113
- /** 唯一业务标识 (UUID) */
114
- claw_id: string;
115
- /** 访问 Key (ak_ 开头) */
116
- app_key: string;
117
- /** 访问密钥 Secret */
118
- app_secret: string;
119
- }
120
-
121
- /** 注册函数的返回值 */
122
- export interface RegisterIdentityResult {
123
- /** 服务端注册是否成功 */
124
- success: boolean;
125
- data?: RegisterIdentityResponse;
126
- error?: string;
127
- /** 本地 profile 文件是否写入成功 */
128
- saved: boolean;
129
- /** 服务端原始响应体(无论成功/失败均透传,便于调用方做后续处理) */
130
- rawBody?: unknown;
131
- }
132
-
133
- // ──────────────────────────────────────────────────────────────────────────────
134
- // 参数校验
135
- // ──────────────────────────────────────────────────────────────────────────────
136
-
137
- /**
138
- * 校验 URL 格式是否合法
139
- */
140
- function isValidUrl(value: string): boolean {
141
- try {
142
- new URL(value);
143
- return true;
144
- } catch {
145
- return false;
146
- }
147
- }
148
-
149
- /**
150
- * 校验注册参数,返回错误信息数组。为空则校验通过。
151
- */
152
- function validateParams(params: RegisterIdentityParams): string[] {
153
- const errors: string[] = [];
154
-
155
- // name
156
- if (!params.name?.trim()) {
157
- errors.push("name 不能为空");
158
- }
159
-
160
- // avatar
161
- if (!params.avatar?.trim()) {
162
- errors.push("avatar 不能为空");
163
- } else if (!isValidUrl(params.avatar)) {
164
- errors.push("avatar 必须是合法的 URL");
165
- }
166
-
167
- // scene_tags
168
- if (!Array.isArray(params.scene_tags) || params.scene_tags.length === 0) {
169
- errors.push("scene_tags 必须为非空数组");
170
- } else {
171
- const invalid = params.scene_tags.filter((t) => !VALID_SCENE_TAG_IDS.has(t));
172
- if (invalid.length > 0) {
173
- errors.push(`scene_tags 包含非法标签 ID: ${invalid.join(", ")},请参照 SCENE_TAGS 选取`);
174
- }
175
- }
176
-
177
- // custom_tags(可选,但如果传了必须是字符串数组)
178
- if (params.custom_tags !== undefined) {
179
- if (!Array.isArray(params.custom_tags)) {
180
- errors.push("custom_tags 必须为数组");
181
- } else if (!params.custom_tags.every((t) => typeof t === "string")) {
182
- errors.push("custom_tags 中的每一项必须为字符串");
183
- }
184
- }
185
-
186
- // description
187
- if (!params.description?.trim()) {
188
- errors.push("description 不能为空");
189
- }
190
-
191
- // hourly_rate
192
- if (typeof params.hourly_rate !== "number" || params.hourly_rate <= 0) {
193
- errors.push("hourly_rate 必须为大于 0 的数字");
194
- }
195
-
196
- // instance_type
197
- if (!VALID_INSTANCE_TYPES.has(params.instance_type)) {
198
- errors.push("instance_type 只能是 0(本地实例)或 1(影子实例)");
199
- }
200
-
201
- return errors;
202
- }
203
-
204
- // ──────────────────────────────────────────────────────────────────────────────
205
- // 核心注册方法
206
- // ──────────────────────────────────────────────────────────────────────────────
207
-
208
- /**
209
- * 向 InstaClaw 服务端注册档案。
210
- *
211
- * 1. 校验入参
212
- * 2. 调用 POST /profiles/create
213
- * 3. 成功后将 profile 写入本地文件
214
- *
215
- * @param params - 注册参数
216
- * @param baseDir - 本地配置文件存储根目录
217
- * @returns 注册结果
218
- */
219
- export async function registerIdentity(
220
- params: RegisterIdentityParams,
221
- baseDir: string,
222
- ): Promise<RegisterIdentityResult> {
223
- // ── 参数校验 ──
224
- const errors = validateParams(params);
225
- if (errors.length > 0) {
226
- return { success: false, error: errors.join("; "), saved: false };
227
- }
228
-
229
- // ── 重复注册检查 ──
230
- const existingProfile = await readProfile(baseDir);
231
- if (existingProfile?.app_key && existingProfile?.app_secret) {
232
- return {
233
- success: false,
234
- saved: false,
235
- error: "当前环境已注册档案,不允许重复注册。如需重新注册请先前往 Insta 开发者后台吊销当前档案。",
236
- };
237
- }
238
-
239
- // ── 构建请求(URL 从集中配置读取,支持环境变量覆盖) ──
240
- const url = getInstaUrl("profileCreate");
241
-
242
- let response: Response;
243
- try {
244
- response = await fetch(url, {
245
- method: "POST",
246
- headers: { "Content-Type": "application/json" },
247
- body: JSON.stringify({
248
- name: params.name.trim(),
249
- avatar: params.avatar.trim(),
250
- scene_tags: params.scene_tags,
251
- custom_tags: params.custom_tags ?? [],
252
- description: params.description.trim(),
253
- hourly_rate: params.hourly_rate,
254
- instance_type: params.instance_type,
255
- }),
256
- });
257
- } catch (err) {
258
- const msg = err instanceof Error ? err.message : String(err);
259
- return { success: false, error: `网络请求失败: ${msg}`, saved: false };
260
- }
261
-
262
- // ── 解析响应 ──
263
- let body: unknown;
264
- try {
265
- body = await response.json();
266
- } catch {
267
- return {
268
- success: false,
269
- error: `服务端返回非 JSON 响应 (HTTP ${response.status})`,
270
- saved: false,
271
- };
272
- }
273
-
274
- // HTTP 错误
275
- if (!response.ok) {
276
- const message =
277
- typeof body === "object" && body !== null && "message" in body
278
- ? String((body as { message: unknown }).message)
279
- : `HTTP ${response.status}`;
280
- return { success: false, error: `注册失败: ${message}`, saved: false, rawBody: body };
281
- }
282
-
283
- // 校验返回结构
284
- if (
285
- typeof body !== "object" ||
286
- body === null ||
287
- !("id" in body) ||
288
- !("claw_id" in body) ||
289
- !("app_key" in body) ||
290
- !("app_secret" in body)
291
- ) {
292
- return { success: false, error: "服务端返回数据结构异常,缺少必要字段", saved: false, rawBody: body };
293
- }
294
-
295
- const data = body as RegisterIdentityResponse;
296
-
297
- // ── 写入本地 profile ──
298
- const profile: Profile = {
299
- app_key: data.app_key,
300
- app_secret: data.app_secret,
301
- name: params.name.trim(),
302
- description: params.description.trim(),
303
- claw_id: data.claw_id,
304
- hourly_rate: params.hourly_rate,
305
- enable_commissioned: false,
306
- enable_hired: false,
307
- scene_tags: params.scene_tags,
308
- custom_tags: params.custom_tags ?? [],
309
- avatar: params.avatar.trim(),
310
- instance_type: params.instance_type,
311
- };
312
-
313
- try {
314
- await writeProfile(baseDir, profile);
315
- } catch (err) {
316
- const msg = err instanceof Error ? err.message : String(err);
317
- return {
318
- success: true,
319
- data,
320
- saved: false,
321
- error: `注册成功但本地配置写入失败: ${msg}。请手动保存 app_key / app_secret。`,
322
- };
323
- }
324
-
325
- return { success: true, data, saved: true };
326
- }
@@ -1,168 +0,0 @@
1
- // ──────────────────────────────────────────────────────────────────────────────
2
- // 任务池 Bot API 认证请求辅助模块
3
- //
4
- // 所有任务相关工具通过此模块发起 HTTP 请求。
5
- // 认证方式:从 profile.json 读取 app_key / app_secret,
6
- // 分别作为 X-API-Key / X-API-Secret 请求头。
7
- // ──────────────────────────────────────────────────────────────────────────────
8
-
9
- import { readProfile } from "../utils/profile.js";
10
- import { getInstaUrl } from "./urls.js";
11
-
12
- // ──────────────────────────────────────────────────────────────────────────────
13
- // 类型定义
14
- // ──────────────────────────────────────────────────────────────────────────────
15
-
16
- /** 服务端通用响应结构 */
17
- export interface TaskApiResponse<T = unknown> {
18
- code: number;
19
- message: string;
20
- data: T | null;
21
- }
22
-
23
- /** 构建认证请求头时所需的凭据 */
24
- interface AuthCredentials {
25
- apiKey: string;
26
- apiSecret: string;
27
- }
28
-
29
- // ──────────────────────────────────────────────────────────────────────────────
30
- // 内部辅助:认证头与 URL
31
- // ──────────────────────────────────────────────────────────────────────────────
32
-
33
- /** 从 profile 中读取 app_key / app_secret,返回认证凭据。*/
34
- async function loadCredentials(baseDir: string): Promise<AuthCredentials> {
35
- const profile = await readProfile(baseDir);
36
- if (!profile) {
37
- throw new Error(
38
- "未找到插件配置文件(.insta/config/profile.json),无法读取认证信息。" +
39
- "请先通过引态平台完成初始化配置。",
40
- );
41
- }
42
- if (!profile.app_key || !profile.app_secret) {
43
- throw new Error(
44
- "profile.json 中缺少 app_key 或 app_secret,无法完成认证。",
45
- );
46
- }
47
- return { apiKey: profile.app_key, apiSecret: profile.app_secret };
48
- }
49
-
50
- /** 生成 JSON 请求头(含认证)。*/
51
- function buildJsonHeaders(creds: AuthCredentials): Record<string, string> {
52
- return {
53
- "Content-Type": "application/json",
54
- "X-API-Key": creds.apiKey,
55
- "X-API-Secret": creds.apiSecret,
56
- };
57
- }
58
-
59
- /** 生成 multipart 请求头(含认证,不带 Content-Type 让 fetch 自动添加 boundary)。*/
60
- function buildMultipartHeaders(creds: AuthCredentials): Record<string, string> {
61
- return {
62
- "X-API-Key": creds.apiKey,
63
- "X-API-Secret": creds.apiSecret,
64
- };
65
- }
66
-
67
- /** 拼接完整 API URL:taskApiBase + path。*/
68
- function buildUrl(path: string): string {
69
- const base = getInstaUrl("taskApiBase").replace(/\/$/, "");
70
- return `${base}${path}`;
71
- }
72
-
73
- // ──────────────────────────────────────────────────────────────────────────────
74
- // 公开 API:GET / POST (JSON) / POST (multipart)
75
- // ──────────────────────────────────────────────────────────────────────────────
76
-
77
- /**
78
- * 发起带认证的 GET 请求。
79
- *
80
- * @param baseDir 插件工作目录(用于定位 profile.json)
81
- * @param path API 路径,如 "/bots/tasks/available"
82
- * @param params 可选 query 参数
83
- */
84
- export async function taskApiGet<T = unknown>(
85
- baseDir: string,
86
- path: string,
87
- params?: Record<string, string | number>,
88
- ): Promise<TaskApiResponse<T>> {
89
- const creds = await loadCredentials(baseDir);
90
- const url = buildUrl(path);
91
-
92
- const urlObj = new URL(url);
93
- if (params) {
94
- for (const [k, v] of Object.entries(params)) {
95
- urlObj.searchParams.set(k, String(v));
96
- }
97
- }
98
-
99
- const response = await fetch(urlObj.toString(), {
100
- method: "GET",
101
- headers: buildJsonHeaders(creds),
102
- });
103
-
104
- if (!response.ok) {
105
- const errText = await response.text().catch(() => `HTTP ${response.status}`);
106
- throw new Error(`请求失败:HTTP ${response.status} ${errText}`);
107
- }
108
-
109
- return (await response.json()) as TaskApiResponse<T>;
110
- }
111
-
112
- /**
113
- * 发起带认证的 POST 请求(JSON body)。
114
- *
115
- * @param baseDir 插件工作目录
116
- * @param path API 路径
117
- * @param body 请求体对象(可选)
118
- */
119
- export async function taskApiPost<T = unknown>(
120
- baseDir: string,
121
- path: string,
122
- body?: Record<string, unknown>,
123
- ): Promise<TaskApiResponse<T>> {
124
- const creds = await loadCredentials(baseDir);
125
- const url = buildUrl(path);
126
-
127
- const response = await fetch(url, {
128
- method: "POST",
129
- headers: buildJsonHeaders(creds),
130
- body: body !== undefined ? JSON.stringify(body) : undefined,
131
- });
132
-
133
- if (!response.ok) {
134
- const errText = await response.text().catch(() => `HTTP ${response.status}`);
135
- throw new Error(`请求失败:HTTP ${response.status} ${errText}`);
136
- }
137
-
138
- return (await response.json()) as TaskApiResponse<T>;
139
- }
140
-
141
- /**
142
- * 发起带认证的 multipart/form-data POST 请求。
143
- *
144
- * @param baseDir 插件工作目录
145
- * @param path API 路径
146
- * @param formData FormData 对象
147
- */
148
- export async function taskApiPostMultipart<T = unknown>(
149
- baseDir: string,
150
- path: string,
151
- formData: FormData,
152
- ): Promise<TaskApiResponse<T>> {
153
- const creds = await loadCredentials(baseDir);
154
- const url = buildUrl(path);
155
-
156
- const response = await fetch(url, {
157
- method: "POST",
158
- headers: buildMultipartHeaders(creds),
159
- body: formData,
160
- });
161
-
162
- if (!response.ok) {
163
- const errText = await response.text().catch(() => `HTTP ${response.status}`);
164
- throw new Error(`请求失败:HTTP ${response.status} ${errText}`);
165
- }
166
-
167
- return (await response.json()) as TaskApiResponse<T>;
168
- }
package/src/core/urls.ts DELETED
@@ -1,52 +0,0 @@
1
- // ──────────────────────────────────────────────────────────────────────────────
2
- // InstaClaw 服务端 URL 集中管理
3
- //
4
- // 每个 URL 优先读取对应环境变量,未配置时使用默认值。
5
- // 新增接口时只需在 URL_REGISTRY 中追加一条记录即可。
6
- // ──────────────────────────────────────────────────────────────────────────────
7
-
8
- type UrlEntry = {
9
- /** 环境变量名 */
10
- envKey: string;
11
- /** 环境变量未配置时的默认值 */
12
- defaultValue: string;
13
- /** 用途说明(便于维护) */
14
- description: string;
15
- };
16
-
17
- const URL_REGISTRY = {
18
- /** WebSocket 聊天通道 */
19
- wsChat: {
20
- envKey: "INSTACLAW_WS_URL",
21
- defaultValue: "wss://claw.int-os.com/ws/chat",
22
- description: "WebSocket 聊天通道",
23
- },
24
- /** 注册档案 */
25
- profileCreate: {
26
- envKey: "INSTACLAW_PROFILE_CREATE_URL",
27
- defaultValue: "https://claw.int-os.com/profiles/create",
28
- description: "注册档案接口",
29
- },
30
- /** 制品上传并绑定 */
31
- artifactUploadAndBind: {
32
- envKey: "INSTACLAW_ARTIFACT_UPLOAD_AND_BIND_URL",
33
- defaultValue: "http://claw.int-os.com/artifact/upload-and-bind",
34
- description: "制品上传并绑定接口",
35
- },
36
- /** 任务池 Bot API 基础地址 */
37
- taskApiBase: {
38
- envKey: "INSTACLAW_TASK_API_BASE_URL",
39
- defaultValue: "https://claw.int-os.com",
40
- description: "任务池 Bot API 基础地址(/bots/tasks/...)",
41
- },
42
- } as const satisfies Record<string, UrlEntry>;
43
-
44
- export type UrlKey = keyof typeof URL_REGISTRY;
45
-
46
- /**
47
- * 获取指定接口的 URL:优先读环境变量,否则返回默认值。
48
- */
49
- export function getInstaUrl(key: UrlKey): string {
50
- const entry = URL_REGISTRY[key];
51
- return process.env[entry.envKey]?.trim() || entry.defaultValue;
52
- }
package/src/prompt/job.md DELETED
@@ -1,21 +0,0 @@
1
- 帮我创建一个 OpenClaw Cron Job 定时任务,默认每 60 秒执行一次。
2
-
3
- 下面内容为该 Cron Job 的具体执行逻辑:
4
-
5
- 使用 insta(引态)相关工具或技能,自动承接并完成悬赏任务。
6
-
7
- 执行流程:
8
- 1. 查询可承接任务(使用对应工具或技能)
9
- 2. 执行接单(使用对应工具或技能)
10
- 3. 严格按照任务要求真实执行任务
11
- 4. 必须确保任务需求已经成功完成后,才允许进入下一步
12
- 5. 生成任务产物
13
- 6. 提交任务产物并完成任务(使用对应工具或技能)
14
-
15
- 执行要求:
16
- - 禁止伪造执行结果
17
- - 禁止未完成任务就提前提交
18
- - 必须真实执行任务内容
19
- - 必须按照任务要求提交正确产物
20
- - 任务未成功完成时,不允许结束流程
21
- - 所有流程需自动循环执行