@allbluecn/web-app 0.28.11 → 0.28.12

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 (110) hide show
  1. package/package.json +5 -5
  2. package/public/dev-gallery.html +19 -0
  3. package/src/__tests__/bench/baselines/format-timestamp.json +44 -0
  4. package/src/__typeprobe__.d.ts +4 -0
  5. package/src/components/harness/extension-panel/panels/terminal/__tests__/terminal-instance.test.tsx +93 -4
  6. package/src/components/harness/extension-panel/panels/terminal/sse-transport.ts +28 -5
  7. package/src/components/harness/extension-panel/panels/terminal/terminal-instance.tsx +53 -10
  8. package/src/components/harness/extension-panel/panels/terminal/transport.ts +10 -3
  9. package/src/components/harness/extension-panel/panels/terminal/ws-transport.ts +13 -2
  10. package/src/components/settings/harness/connectors-card.tsx +5 -0
  11. package/src/dev/gallery-entry.tsx +38 -0
  12. package/src/dev/gallery.tsx +610 -0
  13. package/src/lib/changelog/sdk-versions.ts +3 -3
  14. package/src/paraglide/README.md +1 -1
  15. package/src/paraglide/messages/_index.d.ts +9 -0
  16. package/src/paraglide/messages/_index.js +9 -0
  17. package/src/paraglide/messages/capabilities_webhook.d.ts +16 -0
  18. package/src/paraglide/messages/capabilities_webhook.js +29 -0
  19. package/src/paraglide/messages/capabilities_workflow.d.ts +16 -0
  20. package/src/paraglide/messages/capabilities_workflow.js +29 -0
  21. package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.d.ts +17 -0
  22. package/src/paraglide/messages/harness_panel_terminal_exitedrecycled1.js +30 -0
  23. package/src/paraglide/messages/harness_panel_terminal_restarted.d.ts +16 -0
  24. package/src/paraglide/messages/harness_panel_terminal_restarted.js +29 -0
  25. package/src/paraglide/messages/settings_harness_connectors_needsauth1.d.ts +17 -0
  26. package/src/paraglide/messages/settings_harness_connectors_needsauth1.js +30 -0
  27. package/src/paraglide/messages/settings_harness_ralphenabled1.d.ts +17 -0
  28. package/src/paraglide/messages/settings_harness_ralphenabled1.js +30 -0
  29. package/src/paraglide/messages/settings_harness_ralphenabled_description1.d.ts +17 -0
  30. package/src/paraglide/messages/settings_harness_ralphenabled_description1.js +30 -0
  31. package/src/paraglide/messages/settings_harness_ralphmaxrounds2.d.ts +17 -0
  32. package/src/paraglide/messages/settings_harness_ralphmaxrounds2.js +30 -0
  33. package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.d.ts +17 -0
  34. package/src/paraglide/messages/settings_harness_ralphmaxrounds_description2.js +30 -0
  35. package/src/routeTree.gen.ts +21 -0
  36. package/src/routes/api/harness/terminal/$.ts +32 -13
  37. package/src/routes/api/harness/terminal/__tests__/route.test.ts +41 -0
  38. package/src/routes/api/harness/webhook/$token.ts +23 -0
  39. package/src/routes/api/sync/__tests__/bootstrap.test.ts +32 -1
  40. package/src/routes/api/sync/bootstrap.ts +11 -0
  41. package/src/server/ai-gateway/durability/__tests__/sse-resume-frames.test.ts +123 -0
  42. package/src/server/harness/__tests__/agent-terminal-sandbox.test.ts +23 -4
  43. package/src/server/harness/__tests__/agent-terminal.server.test.ts +118 -2
  44. package/src/server/harness/__tests__/credentials.server.test.ts +25 -2
  45. package/src/server/harness/__tests__/host-schedule-worker.test.ts +43 -0
  46. package/src/server/harness/__tests__/runtime-without-providers.test.ts +11 -0
  47. package/src/server/harness/__tests__/sticky-route.test.ts +86 -0
  48. package/src/server/harness/__tests__/terminal-foreground.server.test.ts +80 -0
  49. package/src/server/harness/__tests__/terminal-manager.server.test.ts +75 -1
  50. package/src/server/harness/__tests__/tool-entitlements.test.ts +6 -2
  51. package/src/server/harness/agent-terminal.server.ts +25 -4
  52. package/src/server/harness/agents/__tests__/agent-control.test.ts +1 -0
  53. package/src/server/harness/agents/run-view.server.ts +55 -2
  54. package/src/server/harness/capabilities/__tests__/__snapshots__/matrix.test.ts.snap +92 -0
  55. package/src/server/harness/capabilities/__tests__/execution-plane-denials.test.ts +3 -1
  56. package/src/server/harness/capabilities/__tests__/p3-matrix.test.ts +3 -3
  57. package/src/server/harness/capabilities/__tests__/p5-matrix.test.ts +293 -0
  58. package/src/server/harness/capabilities/__tests__/validate.test.ts +8 -2
  59. package/src/server/harness/capabilities/execution-plane-denials.ts +9 -3
  60. package/src/server/harness/capabilities/manifests/agent-terminal.ts +3 -2
  61. package/src/server/harness/capabilities/manifests/webhook.ts +45 -0
  62. package/src/server/harness/capabilities/manifests/workflow.ts +40 -0
  63. package/src/server/harness/capabilities/registry.ts +4 -0
  64. package/src/server/harness/connectors/__tests__/connector-accounts.test.ts +22 -1
  65. package/src/server/harness/connectors/connector-accounts.server.ts +7 -0
  66. package/src/server/harness/credentials.server.ts +3 -1
  67. package/src/server/harness/define.server.ts +11 -0
  68. package/src/server/harness/mcp/mcp-config.server.ts +3 -1
  69. package/src/server/harness/outbox/outbox-dispatcher.server.ts +9 -0
  70. package/src/server/harness/outbox/outbox-store.server.ts +7 -0
  71. package/src/server/harness/persistence/__tests__/log-store.server.test.ts +4 -1
  72. package/src/server/harness/plugins/__tests__/tool-risk-audit.test.ts +5 -1
  73. package/src/server/harness/plugins/builtin/agent-terminal.plugin.ts +12 -2
  74. package/src/server/harness/providers/contracts.ts +16 -0
  75. package/src/server/harness/schedule/schedule-dispatcher.server.ts +3 -0
  76. package/src/server/harness/search/__tests__/indexer.test.ts +4 -1
  77. package/src/server/harness/search/__tests__/lifecycle.test.ts +4 -1
  78. package/src/server/harness/search/__tests__/search.test.ts +4 -1
  79. package/src/server/harness/sticky-route.server.ts +72 -0
  80. package/src/server/harness/terminal-foreground.server.ts +90 -0
  81. package/src/server/harness/terminal-manager.server.ts +78 -3
  82. package/src/server/harness/tool-entitlements.server.ts +5 -0
  83. package/src/server/harness/webhook/__tests__/body.test.ts +73 -0
  84. package/src/server/harness/webhook/__tests__/payload.test.ts +215 -0
  85. package/src/server/harness/webhook/__tests__/signature.test.ts +170 -0
  86. package/src/server/harness/webhook/__tests__/webhook-dispatcher.test.ts +212 -0
  87. package/src/server/harness/webhook/__tests__/webhook.plugin.test.ts +195 -0
  88. package/src/server/harness/webhook/__tests__/webhook.service.test.ts +354 -0
  89. package/src/server/harness/webhook/body.server.ts +56 -0
  90. package/src/server/harness/webhook/payload.server.ts +169 -0
  91. package/src/server/harness/webhook/signature.server.ts +118 -0
  92. package/src/server/harness/webhook/types.ts +57 -0
  93. package/src/server/harness/webhook/webhook-dispatcher.server.ts +495 -0
  94. package/src/server/harness/webhook/webhook-store.server.ts +115 -0
  95. package/src/server/harness/webhook/webhook.plugin.ts +273 -0
  96. package/src/server/harness/webhook/webhook.service.server.ts +577 -0
  97. package/src/server/harness/worker/__tests__/worker-http.test.ts +8 -1
  98. package/src/server/harness/worker/worker-health.server.ts +4 -1
  99. package/src/server/harness/worker/worker-runtime.server.ts +43 -1
  100. package/src/server/harness/workflow/__tests__/engine.test.ts +195 -0
  101. package/src/server/harness/workflow/__tests__/settings.test.ts +125 -0
  102. package/src/server/harness/workflow/__tests__/validate.test.ts +151 -0
  103. package/src/server/harness/workflow/engine.server.ts +155 -0
  104. package/src/server/harness/workflow/settings.ts +84 -0
  105. package/src/server/harness/workflow/store.server.ts +147 -0
  106. package/src/server/harness/workflow/types.ts +80 -0
  107. package/src/server/harness/workflow/validate.ts +130 -0
  108. package/src/server/harness/workflow/workflow.plugin.ts +261 -0
  109. package/src/server/serverFns/harness/__tests__/fork-thread.test.ts +14 -1
  110. package/src/server/serverFns/harness/fork-thread.ts +17 -0
@@ -0,0 +1,273 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // webhook 工具面(P5 任务 3)。五工具与 schedule 对齐(create/list/view/edit/delete)。
6
+ //
7
+ // 安全纪律:**工具结果零密钥**——创建/轮换只返回 secretHint(末 4 位)。明文密钥只在
8
+ // 设置页的 serverFn 路径返回一次;工具结果会进官方 transcript/log,绝不能携带密钥
9
+ // (母规格 §8:密钥不进 log/搜索索引)。
10
+
11
+ import { toolDefinition, type AnyTool } from '@tanstack/ai'
12
+ import { definePlugin, type HarnessPlugin } from '@tanstack/ai-harness'
13
+ import { z } from 'zod'
14
+
15
+ import { assertSamePlane } from '../schedule/schedule.service.server'
16
+ import type { TrustedIdentityContext } from '../tool-identity.server'
17
+ import {
18
+ createWebhookRule,
19
+ deleteWebhookRule,
20
+ editWebhookRule,
21
+ getWebhookRule,
22
+ listWebhookRules,
23
+ toRuleSummary,
24
+ WebhookServiceError,
25
+ } from './webhook.service.server'
26
+ import type { WebhookRuleSummary } from './types'
27
+
28
+ const repoPattern = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/
29
+ const ownerPattern = /^[A-Za-z0-9_.-]+$/
30
+ const eventPattern = /^[a-z][a-z0-9_]*$/
31
+
32
+ const executionPlaneSchema = z.enum(['local', 'cloud']).optional()
33
+ const nameSchema = z.string().trim().min(1).max(120)
34
+ const promptSchema = z.string().trim().min(1).max(8_000)
35
+ const repoWhitelistSchema = z.array(z.string().trim().regex(repoPattern)).max(50).optional()
36
+ const ownerWhitelistSchema = z.array(z.string().trim().regex(ownerPattern)).max(50).optional()
37
+ const eventsSchema = z.array(z.string().trim().regex(eventPattern)).max(50).optional()
38
+
39
+ const webhookRuleSummarySchema = z.object({
40
+ id: z.string(),
41
+ name: z.string(),
42
+ provider: z.string(),
43
+ status: z.string(),
44
+ path: z.string(),
45
+ secretHint: z.string(),
46
+ /** 密钥是否在本设备可用(P5 任务 5:跨端同步只带定义,密钥需在本机重新录入)。 */
47
+ hasSecret: z.boolean(),
48
+ events: z.array(z.string()).nullable(),
49
+ repoWhitelist: z.array(z.string()).nullable(),
50
+ ownerWhitelist: z.array(z.string()).nullable(),
51
+ threadId: z.string(),
52
+ lastDeliveryAt: z.date().nullable(),
53
+ revision: z.number(),
54
+ })
55
+
56
+ const webhookErrorSchema = z.object({
57
+ code: z.string(),
58
+ message: z.string(),
59
+ })
60
+
61
+ type WebhookRuleSummaryOut = z.infer<typeof webhookRuleSummarySchema>
62
+ type WebhookToolError = z.infer<typeof webhookErrorSchema>
63
+
64
+ const webhookCreateInput = z.object({
65
+ name: nameSchema,
66
+ prompt: promptSchema,
67
+ repo_whitelist: repoWhitelistSchema,
68
+ owner_whitelist: ownerWhitelistSchema,
69
+ events: eventsSchema,
70
+ provider: z.enum(['github', 'generic']).optional(),
71
+ execution_plane: executionPlaneSchema,
72
+ }).strict().superRefine((value, ctx) => {
73
+ const repos = value.repo_whitelist ?? []
74
+ const owners = value.owner_whitelist ?? []
75
+ if (repos.length === 0 && owners.length === 0) {
76
+ ctx.addIssue({
77
+ code: 'custom',
78
+ message: 'webhook_create requires repo_whitelist or owner_whitelist',
79
+ path: ['repo_whitelist'],
80
+ })
81
+ }
82
+ })
83
+
84
+ const webhookEditInput = z.object({
85
+ id: z.string().min(1),
86
+ revision: z.number().int().nonnegative().optional(),
87
+ status: z.enum(['active', 'paused']).optional(),
88
+ name: nameSchema.optional(),
89
+ prompt: promptSchema.optional(),
90
+ repo_whitelist: repoWhitelistSchema,
91
+ owner_whitelist: ownerWhitelistSchema,
92
+ events: eventsSchema,
93
+ execution_plane: executionPlaneSchema,
94
+ }).strict().superRefine((value, ctx) => {
95
+ const touched = value.status !== undefined
96
+ || value.name !== undefined
97
+ || value.prompt !== undefined
98
+ || value.repo_whitelist !== undefined
99
+ || value.owner_whitelist !== undefined
100
+ || value.events !== undefined
101
+ if (!touched) {
102
+ ctx.addIssue({
103
+ code: 'custom',
104
+ message: 'webhook_edit requires at least one changed field',
105
+ path: ['status'],
106
+ })
107
+ }
108
+ })
109
+
110
+ function requireTrustedContext(context: TrustedIdentityContext): { userId: string; threadId: string } {
111
+ const run = context.run
112
+ const userId = run?.user?.id
113
+ const threadId = run?.threadId
114
+ if (!userId || !threadId) {
115
+ throw new Error('[webhook] missing trusted run user or thread context')
116
+ }
117
+ return { userId, threadId }
118
+ }
119
+
120
+ async function runWebhook<T>(operation: () => Promise<T>): Promise<T | WebhookToolError> {
121
+ try {
122
+ return await operation()
123
+ } catch (error) {
124
+ if (error instanceof WebhookServiceError) {
125
+ return { code: error.code, message: error.message }
126
+ }
127
+ throw error
128
+ }
129
+ }
130
+
131
+ /** 工具面只允许操作「当前线程下的规则」,跨线程不可见(与 schedule 同口径)。 */
132
+ async function requireOwnedThreadRule(input: {
133
+ userId: string
134
+ threadId: string
135
+ id: string
136
+ }): Promise<WebhookRuleSummary> {
137
+ const rule = await getWebhookRule({ userId: input.userId, id: input.id })
138
+ if (!rule || rule.threadId !== input.threadId) {
139
+ throw new WebhookServiceError('webhook_not_found', 'Webhook rule was not found for this thread')
140
+ }
141
+ return toRuleSummary(rule)
142
+ }
143
+
144
+ const webhookCreateDef = toolDefinition({
145
+ name: 'webhook_create',
146
+ description:
147
+ '为当前线程创建入站 webhook 触发器(GitHub 或通用)。必须提供 repo_whitelist 或 owner_whitelist。'
148
+ + '返回端点路径与密钥末 4 位;完整密钥需在设置页轮换获取(密钥不进对话记录)。',
149
+ inputSchema: webhookCreateInput,
150
+ outputSchema: z.union([webhookRuleSummarySchema, webhookErrorSchema]),
151
+ })
152
+
153
+ const webhookCreateTool = webhookCreateDef.server<TrustedIdentityContext>(async (args, ctx) => runWebhook(async () => {
154
+ const { userId, threadId } = requireTrustedContext(ctx.context)
155
+ const executionPlane = assertSamePlane(args.execution_plane)
156
+ const { rule } = await createWebhookRule({
157
+ userId,
158
+ threadId,
159
+ name: args.name,
160
+ prompt: args.prompt,
161
+ repoWhitelist: args.repo_whitelist,
162
+ ownerWhitelist: args.owner_whitelist,
163
+ events: args.events,
164
+ provider: args.provider,
165
+ executionPlane,
166
+ })
167
+ return toRuleSummary(rule)
168
+ }))
169
+
170
+ const webhookListDef = toolDefinition({
171
+ name: 'webhook_list',
172
+ description: '列出当前线程的入站 webhook 触发器(不含密钥)。',
173
+ inputSchema: z.object({ execution_plane: executionPlaneSchema }).strict(),
174
+ outputSchema: z.object({
175
+ webhooks: z.array(webhookRuleSummarySchema),
176
+ }).or(webhookErrorSchema),
177
+ })
178
+
179
+ const webhookListTool = webhookListDef.server<TrustedIdentityContext>(async (args, ctx) => runWebhook(async () => {
180
+ const { userId, threadId } = requireTrustedContext(ctx.context)
181
+ assertSamePlane(args.execution_plane)
182
+ const rules = await listWebhookRules({ userId, threadId })
183
+ return { webhooks: rules.map(toRuleSummary) }
184
+ }))
185
+
186
+ const webhookViewDef = toolDefinition({
187
+ name: 'webhook_view',
188
+ description: '查看当前线程的一个入站 webhook 触发器(不含密钥)。',
189
+ inputSchema: z.object({
190
+ id: z.string().min(1),
191
+ execution_plane: executionPlaneSchema,
192
+ }).strict(),
193
+ outputSchema: z.union([webhookRuleSummarySchema, webhookErrorSchema]),
194
+ })
195
+
196
+ const webhookViewTool = webhookViewDef.server<TrustedIdentityContext>(async (args, ctx) => runWebhook(async () => {
197
+ const { userId, threadId } = requireTrustedContext(ctx.context)
198
+ assertSamePlane(args.execution_plane)
199
+ return requireOwnedThreadRule({ userId, threadId, id: args.id })
200
+ }))
201
+
202
+ const webhookEditDef = toolDefinition({
203
+ name: 'webhook_edit',
204
+ description: '编辑、暂停或恢复当前线程的入站 webhook 触发器;可改名称、prompt、订阅事件与白名单。',
205
+ inputSchema: webhookEditInput,
206
+ outputSchema: z.union([webhookRuleSummarySchema, webhookErrorSchema]),
207
+ })
208
+
209
+ const webhookEditTool = webhookEditDef.server<TrustedIdentityContext>(async (args, ctx) => runWebhook(async () => {
210
+ const { userId, threadId } = requireTrustedContext(ctx.context)
211
+ assertSamePlane(args.execution_plane)
212
+ await requireOwnedThreadRule({ userId, threadId, id: args.id })
213
+ const rule = await editWebhookRule({
214
+ userId,
215
+ id: args.id,
216
+ revision: args.revision,
217
+ status: args.status,
218
+ name: args.name,
219
+ prompt: args.prompt,
220
+ events: args.events,
221
+ repoWhitelist: args.repo_whitelist,
222
+ ownerWhitelist: args.owner_whitelist,
223
+ })
224
+ return toRuleSummary(rule)
225
+ }))
226
+
227
+ const webhookDeleteDef = toolDefinition({
228
+ name: 'webhook_delete',
229
+ description: '删除当前线程的入站 webhook 触发器,并取消尚未投递的 delivery。',
230
+ inputSchema: z.object({
231
+ id: z.string().min(1),
232
+ revision: z.number().int().nonnegative().optional(),
233
+ execution_plane: executionPlaneSchema,
234
+ }).strict(),
235
+ outputSchema: z.union([webhookRuleSummarySchema, webhookErrorSchema]),
236
+ })
237
+
238
+ const webhookDeleteTool = webhookDeleteDef.server<TrustedIdentityContext>(async (args, ctx) => runWebhook(async () => {
239
+ const { userId, threadId } = requireTrustedContext(ctx.context)
240
+ assertSamePlane(args.execution_plane)
241
+ const existing = await requireOwnedThreadRule({ userId, threadId, id: args.id })
242
+ await deleteWebhookRule({ userId, id: args.id, revision: args.revision ?? existing.revision })
243
+ return existing
244
+ }))
245
+
246
+ export const webhookTools: ReadonlyArray<AnyTool> = [
247
+ webhookCreateTool,
248
+ webhookListTool,
249
+ webhookViewTool,
250
+ webhookEditTool,
251
+ webhookDeleteTool,
252
+ ]
253
+
254
+ export const webhookToolNames: ReadonlyArray<string> = [
255
+ 'webhook_create',
256
+ 'webhook_list',
257
+ 'webhook_view',
258
+ 'webhook_edit',
259
+ 'webhook_delete',
260
+ ]
261
+
262
+ export function createWebhookPlugin(provider: { available?: boolean } | null | undefined): HarnessPlugin | null {
263
+ if (!provider || provider.available === false) return null
264
+ return definePlugin({
265
+ name: 'allblue/webhook',
266
+ description: '当前线程的入站 webhook 触发器创建、查询、编辑、暂停与删除',
267
+ lifetime: 'session',
268
+ setup: () => ({ tools: [...webhookTools] }),
269
+ })
270
+ }
271
+
272
+ /** 工具输出类型(供设置页/测试复用)。 */
273
+ export type { WebhookRuleSummaryOut as WebhookToolSummary }