@agent-native/core 0.98.5 → 0.98.6
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/corpus/README.md +2 -2
- package/corpus/core/CHANGELOG.md +12 -0
- package/corpus/core/docs/content/external-agents.mdx +62 -7
- package/corpus/core/docs/content/locales/ar-SA/external-agents.mdx +38 -7
- package/corpus/core/docs/content/locales/de-DE/external-agents.mdx +39 -7
- package/corpus/core/docs/content/locales/es-ES/external-agents.mdx +39 -7
- package/corpus/core/docs/content/locales/fr-FR/external-agents.mdx +39 -7
- package/corpus/core/docs/content/locales/hi-IN/external-agents.mdx +38 -7
- package/corpus/core/docs/content/locales/ja-JP/external-agents.mdx +38 -7
- package/corpus/core/docs/content/locales/ko-KR/external-agents.mdx +38 -7
- package/corpus/core/docs/content/locales/pt-BR/external-agents.mdx +39 -7
- package/corpus/core/docs/content/locales/zh-CN/external-agents.mdx +37 -7
- package/corpus/core/docs/content/locales/zh-TW/external-agents.mdx +37 -7
- package/corpus/core/package.json +1 -1
- package/corpus/core/src/a2a/handlers.ts +95 -21
- package/corpus/core/src/a2a/task-store.ts +65 -3
- package/corpus/core/src/integrations/adapters/slack.ts +123 -13
- package/corpus/core/src/integrations/identity-links-store.ts +210 -0
- package/corpus/core/src/integrations/identity.ts +132 -0
- package/corpus/core/src/integrations/index.ts +6 -0
- package/corpus/core/src/integrations/plugin.ts +58 -1
- package/corpus/core/src/integrations/types.ts +7 -0
- package/corpus/core/src/mcp/build-server.ts +127 -22
- package/corpus/core/src/mcp/external-agent-policy.ts +18 -0
- package/corpus/core/src/mcp/index.ts +1 -0
- package/corpus/core/src/server/agent-chat/plugin-options.ts +12 -1
- package/corpus/core/src/server/agent-chat/script-entries.ts +20 -3
- package/corpus/core/src/server/agent-chat-plugin.ts +3 -0
- package/corpus/core/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +34 -5
- package/corpus/templates/analytics/AGENTS.md +20 -5
- package/corpus/templates/analytics/actions/create-session-replay-agent-link.ts +0 -1
- package/corpus/templates/analytics/actions/get-session-replay-events.ts +0 -1
- package/corpus/templates/analytics/actions/get-session-replay-timeline.ts +40 -0
- package/corpus/templates/analytics/actions/list-error-issues.ts +12 -0
- package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +4 -1
- package/corpus/templates/analytics/app/pages/sessions/SessionsPage.tsx +48 -17
- package/corpus/templates/analytics/changelog/2026-07-12-connected-external-agents-can-now-look-up-sessions-error-iss.md +6 -0
- package/corpus/templates/analytics/changelog/2026-07-12-session-identities-stay-visible-when-demo-mode-is-off.md +6 -0
- package/corpus/templates/analytics/server/lib/analytics-connector-catalog.ts +2 -2
- package/corpus/templates/analytics/server/lib/error-capture.ts +47 -5
- package/corpus/templates/analytics/server/lib/session-replay-agent-context.ts +49 -17
- package/corpus/templates/analytics/server/lib/session-replay.ts +16 -7
- package/corpus/templates/analytics/server/plugins/agent-chat.ts +4 -0
- package/corpus/templates/analytics/server/plugins/db.ts +15 -0
- package/corpus/templates/forms/app/global.css +54 -8
- package/corpus/templates/forms/app/pages/AskPage.tsx +35 -13
- package/corpus/templates/forms/app/pages/FormBuilderPage.tsx +11 -17
- package/corpus/templates/forms/app/pages/ResponsesPage.tsx +8 -5
- package/corpus/templates/forms/changelog/2026-07-12-ask-forms-suggestions-now-sit-beneath-the-composer-for-a-tig.md +6 -0
- package/corpus/templates/forms/changelog/2026-07-12-builder-response-tables-now-fill-the-view-without-a-redundan.md +6 -0
- package/corpus/templates/forms/changelog/2026-07-12-response-tables-now-fill-the-available-pane-with-a-flexible-.md +6 -0
- package/corpus/templates/mail/AGENTS.md +3 -1
- package/corpus/templates/mail/server/lib/mail-integrations.ts +3 -0
- package/dist/a2a/handlers.d.ts.map +1 -1
- package/dist/a2a/handlers.js +84 -15
- package/dist/a2a/handlers.js.map +1 -1
- package/dist/a2a/task-store.d.ts +20 -1
- package/dist/a2a/task-store.d.ts.map +1 -1
- package/dist/a2a/task-store.js +57 -4
- package/dist/a2a/task-store.js.map +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/file-upload/actions/upload-image.d.ts +1 -1
- package/dist/integrations/adapters/slack.d.ts.map +1 -1
- package/dist/integrations/adapters/slack.js +98 -13
- package/dist/integrations/adapters/slack.js.map +1 -1
- package/dist/integrations/identity-links-store.d.ts +23 -0
- package/dist/integrations/identity-links-store.d.ts.map +1 -0
- package/dist/integrations/identity-links-store.js +158 -0
- package/dist/integrations/identity-links-store.js.map +1 -0
- package/dist/integrations/identity.d.ts +11 -0
- package/dist/integrations/identity.d.ts.map +1 -0
- package/dist/integrations/identity.js +100 -0
- package/dist/integrations/identity.js.map +1 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/index.d.ts.map +1 -1
- package/dist/integrations/index.js +2 -0
- package/dist/integrations/index.js.map +1 -1
- package/dist/integrations/plugin.d.ts.map +1 -1
- package/dist/integrations/plugin.js +43 -1
- package/dist/integrations/plugin.js.map +1 -1
- package/dist/integrations/types.d.ts +6 -0
- package/dist/integrations/types.d.ts.map +1 -1
- package/dist/integrations/types.js.map +1 -1
- package/dist/mcp/build-server.d.ts +9 -2
- package/dist/mcp/build-server.d.ts.map +1 -1
- package/dist/mcp/build-server.js +97 -20
- package/dist/mcp/build-server.js.map +1 -1
- package/dist/mcp/external-agent-policy.d.ts +19 -0
- package/dist/mcp/external-agent-policy.d.ts.map +1 -0
- package/dist/mcp/external-agent-policy.js +2 -0
- package/dist/mcp/external-agent-policy.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/notifications/routes.d.ts +1 -1
- package/dist/progress/routes.d.ts +1 -1
- package/dist/provider-api/corpus-jobs.d.ts +2 -2
- package/dist/resources/handlers.d.ts +3 -3
- package/dist/server/agent-chat/plugin-options.d.ts +11 -1
- package/dist/server/agent-chat/plugin-options.d.ts.map +1 -1
- package/dist/server/agent-chat/plugin-options.js.map +1 -1
- package/dist/server/agent-chat/script-entries.d.ts.map +1 -1
- package/dist/server/agent-chat/script-entries.js +16 -2
- package/dist/server/agent-chat/script-entries.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +3 -0
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-engine-api-key-route.d.ts +1 -1
- package/dist/server/transcribe-voice.d.ts +1 -1
- package/dist/templates/workspace-core/.agents/skills/external-agents/SKILL.md +34 -5
- package/docs/content/external-agents.mdx +62 -7
- package/docs/content/locales/ar-SA/external-agents.mdx +38 -7
- package/docs/content/locales/de-DE/external-agents.mdx +39 -7
- package/docs/content/locales/es-ES/external-agents.mdx +39 -7
- package/docs/content/locales/fr-FR/external-agents.mdx +39 -7
- package/docs/content/locales/hi-IN/external-agents.mdx +38 -7
- package/docs/content/locales/ja-JP/external-agents.mdx +38 -7
- package/docs/content/locales/ko-KR/external-agents.mdx +38 -7
- package/docs/content/locales/pt-BR/external-agents.mdx +39 -7
- package/docs/content/locales/zh-CN/external-agents.mdx +37 -7
- package/docs/content/locales/zh-TW/external-agents.mdx +37 -7
- package/package.json +1 -1
- package/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +34 -5
package/dist/a2a/task-store.js
CHANGED
|
@@ -165,7 +165,7 @@ export async function getA2ATaskDispatchState(id) {
|
|
|
165
165
|
await ensureTable();
|
|
166
166
|
const client = getDbExec();
|
|
167
167
|
const { rows } = await client.execute({
|
|
168
|
-
sql: `SELECT id, status_state, metadata, updated_at FROM a2a_tasks WHERE id = ?`,
|
|
168
|
+
sql: `SELECT id, status_state, metadata, created_at, updated_at FROM a2a_tasks WHERE id = ?`,
|
|
169
169
|
args: [id],
|
|
170
170
|
});
|
|
171
171
|
const row = rows[0];
|
|
@@ -176,6 +176,7 @@ export async function getA2ATaskDispatchState(id) {
|
|
|
176
176
|
statusState: row.status_state,
|
|
177
177
|
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
178
178
|
updatedAt: Number(row.updated_at ?? 0),
|
|
179
|
+
createdAt: Number(row.created_at ?? 0),
|
|
179
180
|
};
|
|
180
181
|
}
|
|
181
182
|
export async function touchQueuedA2ATaskDispatch(id) {
|
|
@@ -224,7 +225,17 @@ export async function resetStuckA2ATaskForRetry(id, processingCutoff) {
|
|
|
224
225
|
const affected = getAffectedRowCount(result);
|
|
225
226
|
return affected !== 0;
|
|
226
227
|
}
|
|
227
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Fail a processing task once it is stuck. Two independent conditions can
|
|
230
|
+
* trigger this, either of which alone is sufficient:
|
|
231
|
+
* - `updated_at <= processingCutoff`: no heartbeat/progress touch in a
|
|
232
|
+
* while — the processor likely died.
|
|
233
|
+
* - `created_at <= createdAtCutoff` — a hard wall on total run time. A
|
|
234
|
+
* hung await inside a still-alive process keeps `updated_at` fresh via
|
|
235
|
+
* the liveness heartbeat forever, so staleness alone never trips; age
|
|
236
|
+
* since creation is the only bound that catches it.
|
|
237
|
+
*/
|
|
238
|
+
export async function failStuckA2ATask(id, processingCutoff, reason, createdAtCutoff) {
|
|
228
239
|
await ensureTable();
|
|
229
240
|
const client = getDbExec();
|
|
230
241
|
const now = Date.now();
|
|
@@ -233,6 +244,9 @@ export async function failStuckA2ATask(id, processingCutoff, reason) {
|
|
|
233
244
|
role: "agent",
|
|
234
245
|
parts: [{ type: "text", text: reason }],
|
|
235
246
|
};
|
|
247
|
+
const ageCondition = createdAtCutoff !== undefined
|
|
248
|
+
? `AND (updated_at <= ? OR created_at <= ?)`
|
|
249
|
+
: `AND updated_at <= ?`;
|
|
236
250
|
const result = await client.execute({
|
|
237
251
|
sql: `UPDATE a2a_tasks
|
|
238
252
|
SET status_state = 'failed',
|
|
@@ -241,8 +255,47 @@ export async function failStuckA2ATask(id, processingCutoff, reason) {
|
|
|
241
255
|
updated_at = ?
|
|
242
256
|
WHERE id = ?
|
|
243
257
|
AND status_state = 'processing'
|
|
244
|
-
|
|
245
|
-
args:
|
|
258
|
+
${ageCondition}`,
|
|
259
|
+
args: createdAtCutoff !== undefined
|
|
260
|
+
? [
|
|
261
|
+
JSON.stringify(message),
|
|
262
|
+
timestamp,
|
|
263
|
+
now,
|
|
264
|
+
id,
|
|
265
|
+
processingCutoff,
|
|
266
|
+
createdAtCutoff,
|
|
267
|
+
]
|
|
268
|
+
: [JSON.stringify(message), timestamp, now, id, processingCutoff],
|
|
269
|
+
});
|
|
270
|
+
const affected = getAffectedRowCount(result);
|
|
271
|
+
return affected !== 0;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Fail a queued (submitted/working) task whose age since creation exceeds
|
|
275
|
+
* `createdAtCutoff` — the dispatch-retry loop kept throttling/refiring
|
|
276
|
+
* without ever reaching `processing`. Mirrors `failStuckA2ATask` but is
|
|
277
|
+
* gated on the queued state set and on `created_at` (queued tasks have no
|
|
278
|
+
* heartbeat, so staleness of `updated_at` isn't a meaningful signal here).
|
|
279
|
+
*/
|
|
280
|
+
export async function failStuckQueuedA2ATask(id, createdAtCutoff, reason) {
|
|
281
|
+
await ensureTable();
|
|
282
|
+
const client = getDbExec();
|
|
283
|
+
const now = Date.now();
|
|
284
|
+
const timestamp = new Date().toISOString();
|
|
285
|
+
const message = {
|
|
286
|
+
role: "agent",
|
|
287
|
+
parts: [{ type: "text", text: reason }],
|
|
288
|
+
};
|
|
289
|
+
const result = await client.execute({
|
|
290
|
+
sql: `UPDATE a2a_tasks
|
|
291
|
+
SET status_state = 'failed',
|
|
292
|
+
status_message = ?,
|
|
293
|
+
status_timestamp = ?,
|
|
294
|
+
updated_at = ?
|
|
295
|
+
WHERE id = ?
|
|
296
|
+
AND status_state IN ('submitted', 'working')
|
|
297
|
+
AND created_at <= ?`,
|
|
298
|
+
args: [JSON.stringify(message), timestamp, now, id, createdAtCutoff],
|
|
246
299
|
});
|
|
247
300
|
const affected = getAffectedRowCount(result);
|
|
248
301
|
return affected !== 0;
|
|
@@ -1 +1 @@
|
|
|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AAI,SAAS,EAAE,CAAC;QACd,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YACpC,GAAG,EAAE,uEAAuE;YAC5E,IAAI,EAAE,CAAC,SAAS,CAAC;SAClB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,kDAAkD,CACnD,CAAC;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import crypto from \"crypto\";\n\nimport { getDbExec, intType, isPostgres } from \"../db/client.js\";\nimport { ensureTableExists, ensureColumnExists } from \"../db/ddl-guard.js\";\nimport type { Task, Message, TaskState, Artifact } from \"./types.js\";\n\nlet _initPromise: Promise<void> | undefined;\n\nasync function ensureTable(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n const createSql = `\n CREATE TABLE IF NOT EXISTS a2a_tasks (\n id TEXT PRIMARY KEY,\n context_id TEXT,\n status_state TEXT NOT NULL DEFAULT 'submitted',\n status_message TEXT,\n status_timestamp TEXT NOT NULL,\n history TEXT NOT NULL DEFAULT '[]',\n artifacts TEXT NOT NULL DEFAULT '[]',\n metadata TEXT,\n created_at ${intType()} NOT NULL,\n updated_at ${intType()} NOT NULL\n )\n `;\n\n if (isPostgres()) {\n // PG-guard: probe information_schema before issuing DDL to avoid ACCESS\n // EXCLUSIVE lock contention in fresh background-worker processes.\n await ensureTableExists(\"a2a_tasks\", createSql);\n // Additive migration: owner_email column. Bound to the JWT-verified\n // caller at task-creation time so handleGet / handleCancel can reject\n // mismatched callers (the IDOR class fixed in PR #369). Existing rows\n // have NULL owner_email and remain accessible to legacy callers via\n // the legacy-token apiKeyEnv path; new rows are scoped from this point\n // forward.\n await ensureColumnExists(\n \"a2a_tasks\",\n \"owner_email\",\n `ALTER TABLE a2a_tasks ADD COLUMN IF NOT EXISTS owner_email TEXT`,\n );\n return;\n }\n\n // SQLite (local dev): no lock problem — keep the original behaviour.\n await client.execute(createSql);\n // Additive migration: owner_email column. Bound to the JWT-verified\n // caller at task-creation time so handleGet / handleCancel can reject\n // mismatched callers (the IDOR class fixed in PR #369). Existing rows\n // have NULL owner_email and remain accessible to legacy callers via\n // the legacy-token apiKeyEnv path; new rows are scoped from this point\n // forward.\n try {\n await client.execute(\n `ALTER TABLE a2a_tasks ADD COLUMN owner_email TEXT`,\n );\n } catch {\n // Column already exists — expected on every restart after first run.\n }\n })().catch((err) => {\n // Retry init on the next call after a failed startup.\n _initPromise = undefined;\n throw err;\n });\n }\n return _initPromise;\n}\n\nfunction taskFromRow(row: any): Task & { ownerEmail?: string | null } {\n return {\n id: row.id as string,\n contextId: (row.context_id as string) || undefined,\n status: {\n state: row.status_state as TaskState,\n message: row.status_message\n ? JSON.parse(row.status_message as string)\n : undefined,\n timestamp: row.status_timestamp as string,\n },\n history: JSON.parse(row.history as string),\n artifacts: JSON.parse(row.artifacts as string),\n metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,\n ownerEmail: (row.owner_email as string | null) ?? null,\n };\n}\n\nfunction getAffectedRowCount(result: unknown): number | undefined {\n const resultRecord = result as\n | {\n rowsAffected?: number;\n rowCount?: number;\n count?: number;\n }\n | undefined;\n return (\n resultRecord?.rowsAffected ?? resultRecord?.rowCount ?? resultRecord?.count\n );\n}\n\nexport async function createTask(\n message: Message,\n contextId?: string,\n metadata?: Record<string, unknown>,\n ownerEmail?: string | null,\n): Promise<Task> {\n await ensureTable();\n const client = getDbExec();\n const id = crypto.randomUUID();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n\n const task: Task = {\n id,\n contextId,\n status: { state: \"submitted\", timestamp },\n history: [message],\n artifacts: [],\n metadata,\n };\n\n await client.execute({\n sql: `INSERT INTO a2a_tasks (id, context_id, status_state, status_timestamp, history, artifacts, metadata, owner_email, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n args: [\n id,\n contextId ?? null,\n \"submitted\",\n timestamp,\n JSON.stringify([message]),\n \"[]\",\n metadata ? JSON.stringify(metadata) : null,\n ownerEmail ?? null,\n now,\n now,\n ],\n });\n\n return task;\n}\n\n/**\n * Fetch the verified owner email recorded against a task at creation time.\n * Returns null when the task has no owner (legacy rows or unauthenticated\n * deployments) or when the task is missing.\n *\n * Used by `handleGet` / `handleCancel` to reject IDOR access — the JWT-\n * verified caller's email must match `owner_email` to read or cancel.\n */\nexport async function getTaskOwner(id: string): Promise<string | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT owner_email FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n const ownerEmail = (rows[0] as any).owner_email;\n return typeof ownerEmail === \"string\" && ownerEmail ? ownerEmail : null;\n}\n\n/**\n * Atomically claim a task for processing. Only succeeds when the task is in\n * state 'submitted' or 'working' — flipping it to 'processing' so concurrent\n * processors can't pick it up twice. Returns the task if claimed, null if it\n * was already claimed/completed/missing.\n *\n * Used by the cross-platform async processor (`_process-task` route) to avoid\n * duplicate handler runs when retries fire.\n */\nexport async function claimA2ATaskForProcessing(\n id: string,\n): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'processing',\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working')`,\n args: [timestamp, now, id],\n });\n const affected = getAffectedRowCount(result);\n if (affected === 0) return null;\n\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n return taskFromRow(rows[0]);\n}\n\nexport async function getA2ATaskDispatchState(id: string): Promise<{\n id: string;\n statusState: string;\n metadata: Record<string, unknown> | undefined;\n updatedAt: number;\n} | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT id, status_state, metadata, updated_at FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n const row = rows[0] as any;\n if (!row) return null;\n return {\n id: row.id as string,\n statusState: row.status_state as string,\n metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,\n updatedAt: Number(row.updated_at ?? 0),\n };\n}\n\nexport async function touchQueuedA2ATaskDispatch(id: string): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working')`,\n args: [now, id],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function touchProcessingA2ATask(id: string): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'`,\n args: [now, id],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function resetStuckA2ATaskForRetry(\n id: string,\n processingCutoff: number,\n): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'working',\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'\n AND updated_at <= ?`,\n args: [timestamp, now, id, processingCutoff],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function failStuckA2ATask(\n id: string,\n processingCutoff: number,\n reason: string,\n): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n const message: Message = {\n role: \"agent\",\n parts: [{ type: \"text\", text: reason }],\n };\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'failed',\n status_message = ?,\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'\n AND updated_at <= ?`,\n args: [JSON.stringify(message), timestamp, now, id, processingCutoff],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function getTask(id: string): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n return taskFromRow(rows[0]);\n}\n\nexport async function updateTask(\n id: string,\n update: {\n state?: TaskState;\n message?: Message;\n artifacts?: Artifact[];\n },\n): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n\n // Read current task\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n\n const task = taskFromRow(rows[0]);\n const now = Date.now();\n\n if (update.state) {\n task.status = {\n state: update.state,\n message: update.message ?? task.status.message,\n timestamp: new Date().toISOString(),\n };\n }\n\n if (update.message && task.history) {\n task.history.push(update.message);\n }\n\n if (update.artifacts) {\n task.artifacts = [...(task.artifacts ?? []), ...update.artifacts];\n }\n\n await client.execute({\n sql: `UPDATE a2a_tasks SET status_state = ?, status_message = ?, status_timestamp = ?, history = ?, artifacts = ?, updated_at = ? WHERE id = ?`,\n args: [\n task.status.state,\n task.status.message ? JSON.stringify(task.status.message) : null,\n task.status.timestamp,\n JSON.stringify(task.history),\n JSON.stringify(task.artifacts),\n now,\n id,\n ],\n });\n\n return task;\n}\n\nexport async function updateTaskStatusMessage(\n id: string,\n message: Message,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_message = ?,\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working', 'processing')`,\n args: [JSON.stringify(message), timestamp, now, id],\n });\n}\n\nexport async function listTasks(contextId?: string): Promise<Task[]> {\n await ensureTable();\n const client = getDbExec();\n\n if (contextId) {\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE context_id = ? ORDER BY created_at DESC`,\n args: [contextId],\n });\n return rows.map(taskFromRow);\n }\n\n const { rows } = await client.execute(\n `SELECT * FROM a2a_tasks ORDER BY created_at DESC`,\n );\n return rows.map(taskFromRow);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"task-store.js","sourceRoot":"","sources":["../../src/a2a/task-store.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG3E,IAAI,YAAuC,CAAC;AAE5C,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,CAAC,KAAK,IAAI,EAAE;YACzB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG;;;;;;;;;;uBAUD,OAAO,EAAE;uBACT,OAAO,EAAE;;OAEzB,CAAC;YAEF,IAAI,UAAU,EAAE,EAAE,CAAC;gBACjB,wEAAwE;gBACxE,kEAAkE;gBAClE,MAAM,iBAAiB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;gBAChD,oEAAoE;gBACpE,sEAAsE;gBACtE,sEAAsE;gBACtE,oEAAoE;gBACpE,uEAAuE;gBACvE,WAAW;gBACX,MAAM,kBAAkB,CACtB,WAAW,EACX,aAAa,EACb,iEAAiE,CAClE,CAAC;gBACF,OAAO;YACT,CAAC;YAED,qEAAqE;YACrE,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,oEAAoE;YACpE,sEAAsE;YACtE,sEAAsE;YACtE,oEAAoE;YACpE,uEAAuE;YACvE,WAAW;YACX,IAAI,CAAC;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C;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,SAAkB;IAChD,MAAM,WAAW,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YACpC,GAAG,EAAE,uEAAuE;YAC5E,IAAI,EAAE,CAAC,SAAS,CAAC;SAClB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,kDAAkD,CACnD,CAAC;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import crypto from \"crypto\";\n\nimport { getDbExec, intType, isPostgres } from \"../db/client.js\";\nimport { ensureTableExists, ensureColumnExists } from \"../db/ddl-guard.js\";\nimport type { Task, Message, TaskState, Artifact } from \"./types.js\";\n\nlet _initPromise: Promise<void> | undefined;\n\nasync function ensureTable(): Promise<void> {\n if (!_initPromise) {\n _initPromise = (async () => {\n const client = getDbExec();\n const createSql = `\n CREATE TABLE IF NOT EXISTS a2a_tasks (\n id TEXT PRIMARY KEY,\n context_id TEXT,\n status_state TEXT NOT NULL DEFAULT 'submitted',\n status_message TEXT,\n status_timestamp TEXT NOT NULL,\n history TEXT NOT NULL DEFAULT '[]',\n artifacts TEXT NOT NULL DEFAULT '[]',\n metadata TEXT,\n created_at ${intType()} NOT NULL,\n updated_at ${intType()} NOT NULL\n )\n `;\n\n if (isPostgres()) {\n // PG-guard: probe information_schema before issuing DDL to avoid ACCESS\n // EXCLUSIVE lock contention in fresh background-worker processes.\n await ensureTableExists(\"a2a_tasks\", createSql);\n // Additive migration: owner_email column. Bound to the JWT-verified\n // caller at task-creation time so handleGet / handleCancel can reject\n // mismatched callers (the IDOR class fixed in PR #369). Existing rows\n // have NULL owner_email and remain accessible to legacy callers via\n // the legacy-token apiKeyEnv path; new rows are scoped from this point\n // forward.\n await ensureColumnExists(\n \"a2a_tasks\",\n \"owner_email\",\n `ALTER TABLE a2a_tasks ADD COLUMN IF NOT EXISTS owner_email TEXT`,\n );\n return;\n }\n\n // SQLite (local dev): no lock problem — keep the original behaviour.\n await client.execute(createSql);\n // Additive migration: owner_email column. Bound to the JWT-verified\n // caller at task-creation time so handleGet / handleCancel can reject\n // mismatched callers (the IDOR class fixed in PR #369). Existing rows\n // have NULL owner_email and remain accessible to legacy callers via\n // the legacy-token apiKeyEnv path; new rows are scoped from this point\n // forward.\n try {\n await client.execute(\n `ALTER TABLE a2a_tasks ADD COLUMN owner_email TEXT`,\n );\n } catch {\n // Column already exists — expected on every restart after first run.\n }\n })().catch((err) => {\n // Retry init on the next call after a failed startup.\n _initPromise = undefined;\n throw err;\n });\n }\n return _initPromise;\n}\n\nfunction taskFromRow(row: any): Task & { ownerEmail?: string | null } {\n return {\n id: row.id as string,\n contextId: (row.context_id as string) || undefined,\n status: {\n state: row.status_state as TaskState,\n message: row.status_message\n ? JSON.parse(row.status_message as string)\n : undefined,\n timestamp: row.status_timestamp as string,\n },\n history: JSON.parse(row.history as string),\n artifacts: JSON.parse(row.artifacts as string),\n metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,\n ownerEmail: (row.owner_email as string | null) ?? null,\n };\n}\n\nfunction getAffectedRowCount(result: unknown): number | undefined {\n const resultRecord = result as\n | {\n rowsAffected?: number;\n rowCount?: number;\n count?: number;\n }\n | undefined;\n return (\n resultRecord?.rowsAffected ?? resultRecord?.rowCount ?? resultRecord?.count\n );\n}\n\nexport async function createTask(\n message: Message,\n contextId?: string,\n metadata?: Record<string, unknown>,\n ownerEmail?: string | null,\n): Promise<Task> {\n await ensureTable();\n const client = getDbExec();\n const id = crypto.randomUUID();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n\n const task: Task = {\n id,\n contextId,\n status: { state: \"submitted\", timestamp },\n history: [message],\n artifacts: [],\n metadata,\n };\n\n await client.execute({\n sql: `INSERT INTO a2a_tasks (id, context_id, status_state, status_timestamp, history, artifacts, metadata, owner_email, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,\n args: [\n id,\n contextId ?? null,\n \"submitted\",\n timestamp,\n JSON.stringify([message]),\n \"[]\",\n metadata ? JSON.stringify(metadata) : null,\n ownerEmail ?? null,\n now,\n now,\n ],\n });\n\n return task;\n}\n\n/**\n * Fetch the verified owner email recorded against a task at creation time.\n * Returns null when the task has no owner (legacy rows or unauthenticated\n * deployments) or when the task is missing.\n *\n * Used by `handleGet` / `handleCancel` to reject IDOR access — the JWT-\n * verified caller's email must match `owner_email` to read or cancel.\n */\nexport async function getTaskOwner(id: string): Promise<string | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT owner_email FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n const ownerEmail = (rows[0] as any).owner_email;\n return typeof ownerEmail === \"string\" && ownerEmail ? ownerEmail : null;\n}\n\n/**\n * Atomically claim a task for processing. Only succeeds when the task is in\n * state 'submitted' or 'working' — flipping it to 'processing' so concurrent\n * processors can't pick it up twice. Returns the task if claimed, null if it\n * was already claimed/completed/missing.\n *\n * Used by the cross-platform async processor (`_process-task` route) to avoid\n * duplicate handler runs when retries fire.\n */\nexport async function claimA2ATaskForProcessing(\n id: string,\n): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'processing',\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working')`,\n args: [timestamp, now, id],\n });\n const affected = getAffectedRowCount(result);\n if (affected === 0) return null;\n\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n return taskFromRow(rows[0]);\n}\n\nexport async function getA2ATaskDispatchState(id: string): Promise<{\n id: string;\n statusState: string;\n metadata: Record<string, unknown> | undefined;\n updatedAt: number;\n createdAt: number;\n} | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT id, status_state, metadata, created_at, updated_at FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n const row = rows[0] as any;\n if (!row) return null;\n return {\n id: row.id as string,\n statusState: row.status_state as string,\n metadata: row.metadata ? JSON.parse(row.metadata as string) : undefined,\n updatedAt: Number(row.updated_at ?? 0),\n createdAt: Number(row.created_at ?? 0),\n };\n}\n\nexport async function touchQueuedA2ATaskDispatch(id: string): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working')`,\n args: [now, id],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function touchProcessingA2ATask(id: string): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'`,\n args: [now, id],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function resetStuckA2ATaskForRetry(\n id: string,\n processingCutoff: number,\n): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'working',\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'\n AND updated_at <= ?`,\n args: [timestamp, now, id, processingCutoff],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\n/**\n * Fail a processing task once it is stuck. Two independent conditions can\n * trigger this, either of which alone is sufficient:\n * - `updated_at <= processingCutoff`: no heartbeat/progress touch in a\n * while — the processor likely died.\n * - `created_at <= createdAtCutoff` — a hard wall on total run time. A\n * hung await inside a still-alive process keeps `updated_at` fresh via\n * the liveness heartbeat forever, so staleness alone never trips; age\n * since creation is the only bound that catches it.\n */\nexport async function failStuckA2ATask(\n id: string,\n processingCutoff: number,\n reason: string,\n createdAtCutoff?: number,\n): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n const message: Message = {\n role: \"agent\",\n parts: [{ type: \"text\", text: reason }],\n };\n const ageCondition =\n createdAtCutoff !== undefined\n ? `AND (updated_at <= ? OR created_at <= ?)`\n : `AND updated_at <= ?`;\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'failed',\n status_message = ?,\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state = 'processing'\n ${ageCondition}`,\n args:\n createdAtCutoff !== undefined\n ? [\n JSON.stringify(message),\n timestamp,\n now,\n id,\n processingCutoff,\n createdAtCutoff,\n ]\n : [JSON.stringify(message), timestamp, now, id, processingCutoff],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\n/**\n * Fail a queued (submitted/working) task whose age since creation exceeds\n * `createdAtCutoff` — the dispatch-retry loop kept throttling/refiring\n * without ever reaching `processing`. Mirrors `failStuckA2ATask` but is\n * gated on the queued state set and on `created_at` (queued tasks have no\n * heartbeat, so staleness of `updated_at` isn't a meaningful signal here).\n */\nexport async function failStuckQueuedA2ATask(\n id: string,\n createdAtCutoff: number,\n reason: string,\n): Promise<boolean> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n const message: Message = {\n role: \"agent\",\n parts: [{ type: \"text\", text: reason }],\n };\n const result = await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_state = 'failed',\n status_message = ?,\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working')\n AND created_at <= ?`,\n args: [JSON.stringify(message), timestamp, now, id, createdAtCutoff],\n });\n const affected = getAffectedRowCount(result);\n return affected !== 0;\n}\n\nexport async function getTask(id: string): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n return taskFromRow(rows[0]);\n}\n\nexport async function updateTask(\n id: string,\n update: {\n state?: TaskState;\n message?: Message;\n artifacts?: Artifact[];\n },\n): Promise<Task | null> {\n await ensureTable();\n const client = getDbExec();\n\n // Read current task\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE id = ?`,\n args: [id],\n });\n if (rows.length === 0) return null;\n\n const task = taskFromRow(rows[0]);\n const now = Date.now();\n\n if (update.state) {\n task.status = {\n state: update.state,\n message: update.message ?? task.status.message,\n timestamp: new Date().toISOString(),\n };\n }\n\n if (update.message && task.history) {\n task.history.push(update.message);\n }\n\n if (update.artifacts) {\n task.artifacts = [...(task.artifacts ?? []), ...update.artifacts];\n }\n\n await client.execute({\n sql: `UPDATE a2a_tasks SET status_state = ?, status_message = ?, status_timestamp = ?, history = ?, artifacts = ?, updated_at = ? WHERE id = ?`,\n args: [\n task.status.state,\n task.status.message ? JSON.stringify(task.status.message) : null,\n task.status.timestamp,\n JSON.stringify(task.history),\n JSON.stringify(task.artifacts),\n now,\n id,\n ],\n });\n\n return task;\n}\n\nexport async function updateTaskStatusMessage(\n id: string,\n message: Message,\n): Promise<void> {\n await ensureTable();\n const client = getDbExec();\n const now = Date.now();\n const timestamp = new Date().toISOString();\n await client.execute({\n sql: `UPDATE a2a_tasks\n SET status_message = ?,\n status_timestamp = ?,\n updated_at = ?\n WHERE id = ?\n AND status_state IN ('submitted', 'working', 'processing')`,\n args: [JSON.stringify(message), timestamp, now, id],\n });\n}\n\nexport async function listTasks(contextId?: string): Promise<Task[]> {\n await ensureTable();\n const client = getDbExec();\n\n if (contextId) {\n const { rows } = await client.execute({\n sql: `SELECT * FROM a2a_tasks WHERE context_id = ? ORDER BY created_at DESC`,\n args: [contextId],\n });\n return rows.map(taskFromRow);\n }\n\n const { rows } = await client.execute(\n `SELECT * FROM a2a_tasks ORDER BY created_at DESC`,\n );\n return rows.map(taskFromRow);\n}\n"]}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* Body: { json: any, fieldName?: string, type?: "map"|"array", requestSource?: string }
|
|
14
14
|
*/
|
|
15
15
|
export declare const postCollabJson: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
16
|
-
ok?: undefined;
|
|
17
16
|
error: string;
|
|
17
|
+
ok?: undefined;
|
|
18
18
|
} | {
|
|
19
19
|
error?: undefined;
|
|
20
20
|
ok: boolean;
|
|
@@ -17,12 +17,12 @@ declare const _default: import("../../action.js").ActionDefinition<{
|
|
|
17
17
|
id?: undefined;
|
|
18
18
|
provider?: undefined;
|
|
19
19
|
} | {
|
|
20
|
-
error?: undefined;
|
|
21
20
|
configured?: undefined;
|
|
22
21
|
connectPath?: undefined;
|
|
23
22
|
url: string;
|
|
24
23
|
id: string;
|
|
25
24
|
provider: string;
|
|
25
|
+
error?: undefined;
|
|
26
26
|
}>;
|
|
27
27
|
export default _default;
|
|
28
28
|
//# sourceMappingURL=upload-image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../../src/integrations/adapters/slack.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAQhB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../../src/integrations/adapters/slack.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAQhB,MAAM,aAAa,CAAC;AA+BrB,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7E,kEAAkE;IAClE,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjE,oEAAoE;IACpE,oBAAoB,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC1B,OAAO,GAAE,mBAAwB,GAChC,eAAe,CAmgBjB"}
|
|
@@ -18,6 +18,13 @@ const SLACK_PERMALINK_TIMEOUT_MS = 1_000;
|
|
|
18
18
|
const SLACK_CONTEXT_MESSAGE_LIMIT = 15;
|
|
19
19
|
const SLACK_CONTEXT_TEXT_LIMIT = 2_000;
|
|
20
20
|
const SLACK_CALM_PROGRESS_THRESHOLD_SECONDS = 30;
|
|
21
|
+
const SLACK_IDENTITY_TIMEOUT_MS = 1_000;
|
|
22
|
+
const SLACK_IDENTITY_CACHE_TTL_MS = 10 * 60 * 1_000;
|
|
23
|
+
// Failed users.info lookups only get a short negative TTL: a transient Slack
|
|
24
|
+
// API blip must not fail-close a sender's identity (and DMs) for 10 minutes.
|
|
25
|
+
const SLACK_IDENTITY_NEGATIVE_CACHE_TTL_MS = 30 * 1_000;
|
|
26
|
+
const SLACK_IDENTITY_CACHE_MAX_ENTRIES = 1_000;
|
|
27
|
+
const slackIdentityCache = new Map();
|
|
21
28
|
/**
|
|
22
29
|
* Create a Slack platform adapter.
|
|
23
30
|
*
|
|
@@ -283,6 +290,12 @@ export function slackAdapter(options = {}) {
|
|
|
283
290
|
return incoming;
|
|
284
291
|
return hydrateSlackContext(token, incoming);
|
|
285
292
|
},
|
|
293
|
+
async hydrateIncomingIdentity(incoming) {
|
|
294
|
+
const token = await resolveBotToken(incoming);
|
|
295
|
+
if (!token)
|
|
296
|
+
return incoming;
|
|
297
|
+
return hydrateSlackIdentity(token, incoming);
|
|
298
|
+
},
|
|
286
299
|
async startRunProgress(incoming) {
|
|
287
300
|
const token = await resolveBotToken(incoming);
|
|
288
301
|
if (!token)
|
|
@@ -873,6 +886,81 @@ async function slackJson(token, method, params, timeoutMs = 2_000) {
|
|
|
873
886
|
return null;
|
|
874
887
|
}
|
|
875
888
|
}
|
|
889
|
+
function slackIdentityCacheKey(incoming) {
|
|
890
|
+
const teamId = incoming.platformContext.teamId;
|
|
891
|
+
const senderId = incoming.senderId;
|
|
892
|
+
if (typeof senderId !== "string" || !senderId.trim())
|
|
893
|
+
return null;
|
|
894
|
+
return `${typeof teamId === "string" && teamId ? teamId : "unknown"}:${senderId}`;
|
|
895
|
+
}
|
|
896
|
+
async function resolveSlackUserIdentity(token, incoming) {
|
|
897
|
+
const cacheKey = slackIdentityCacheKey(incoming);
|
|
898
|
+
if (!cacheKey)
|
|
899
|
+
return null;
|
|
900
|
+
const cached = slackIdentityCache.get(cacheKey);
|
|
901
|
+
if (cached && cached.expiresAt > Date.now())
|
|
902
|
+
return cached.identity;
|
|
903
|
+
if (cached)
|
|
904
|
+
slackIdentityCache.delete(cacheKey);
|
|
905
|
+
const user = await slackJson(token, "users.info", { user: incoming.senderId }, SLACK_IDENTITY_TIMEOUT_MS);
|
|
906
|
+
const profile = user?.user?.profile;
|
|
907
|
+
const identity = user?.user
|
|
908
|
+
? {
|
|
909
|
+
email: typeof profile?.email === "string" && profile.email.trim()
|
|
910
|
+
? profile.email.trim().toLowerCase()
|
|
911
|
+
: null,
|
|
912
|
+
name: typeof profile?.real_name === "string" && profile.real_name.trim()
|
|
913
|
+
? profile.real_name.trim()
|
|
914
|
+
: typeof profile?.display_name === "string" &&
|
|
915
|
+
profile.display_name.trim()
|
|
916
|
+
? profile.display_name.trim()
|
|
917
|
+
: typeof user.user.real_name === "string" &&
|
|
918
|
+
user.user.real_name.trim()
|
|
919
|
+
? user.user.real_name.trim()
|
|
920
|
+
: typeof user.user.name === "string" && user.user.name.trim()
|
|
921
|
+
? user.user.name.trim()
|
|
922
|
+
: null,
|
|
923
|
+
memberType: user.user.is_ultra_restricted
|
|
924
|
+
? "external"
|
|
925
|
+
: user.user.is_restricted
|
|
926
|
+
? "guest"
|
|
927
|
+
: user.user.is_owner
|
|
928
|
+
? "owner"
|
|
929
|
+
: user.user.is_admin
|
|
930
|
+
? "admin"
|
|
931
|
+
: "member",
|
|
932
|
+
}
|
|
933
|
+
: null;
|
|
934
|
+
if (slackIdentityCache.size >= SLACK_IDENTITY_CACHE_MAX_ENTRIES) {
|
|
935
|
+
const oldestKey = slackIdentityCache.keys().next().value;
|
|
936
|
+
if (oldestKey)
|
|
937
|
+
slackIdentityCache.delete(oldestKey);
|
|
938
|
+
}
|
|
939
|
+
slackIdentityCache.set(cacheKey, {
|
|
940
|
+
identity,
|
|
941
|
+
expiresAt: Date.now() +
|
|
942
|
+
(identity
|
|
943
|
+
? SLACK_IDENTITY_CACHE_TTL_MS
|
|
944
|
+
: SLACK_IDENTITY_NEGATIVE_CACHE_TTL_MS),
|
|
945
|
+
});
|
|
946
|
+
return identity;
|
|
947
|
+
}
|
|
948
|
+
async function hydrateSlackIdentity(token, incoming) {
|
|
949
|
+
const identity = await resolveSlackUserIdentity(token, incoming);
|
|
950
|
+
if (!identity)
|
|
951
|
+
return incoming;
|
|
952
|
+
return {
|
|
953
|
+
...incoming,
|
|
954
|
+
...(identity.name ? { senderName: identity.name } : {}),
|
|
955
|
+
...(identity.email
|
|
956
|
+
? { senderEmail: identity.email, senderVerified: true }
|
|
957
|
+
: { senderVerified: false }),
|
|
958
|
+
actorTrust: {
|
|
959
|
+
memberType: identity.memberType,
|
|
960
|
+
verified: true,
|
|
961
|
+
},
|
|
962
|
+
};
|
|
963
|
+
}
|
|
876
964
|
async function hydrateSlackContext(token, incoming) {
|
|
877
965
|
const channelId = incoming.platformContext.channelId;
|
|
878
966
|
const threadTs = incoming.platformContext.threadTs;
|
|
@@ -880,7 +968,7 @@ async function hydrateSlackContext(token, incoming) {
|
|
|
880
968
|
if (typeof channelId !== "string" || typeof threadTs !== "string") {
|
|
881
969
|
return incoming;
|
|
882
970
|
}
|
|
883
|
-
const [thread, history, pins, conversation,
|
|
971
|
+
const [thread, history, pins, conversation, identity] = await Promise.all([
|
|
884
972
|
slackJson(token, "conversations.replies", {
|
|
885
973
|
channel: channelId,
|
|
886
974
|
ts: threadTs,
|
|
@@ -894,7 +982,7 @@ async function hydrateSlackContext(token, incoming) {
|
|
|
894
982
|
}),
|
|
895
983
|
slackJson(token, "pins.list", { channel: channelId }),
|
|
896
984
|
slackJson(token, "conversations.info", { channel: channelId }),
|
|
897
|
-
senderId ?
|
|
985
|
+
senderId ? resolveSlackUserIdentity(token, incoming) : null,
|
|
898
986
|
]);
|
|
899
987
|
// Agent View can attach the Slack surface the user is currently viewing to
|
|
900
988
|
// a DM. Treat it only as a context hint: Slack requires us to prove the bot
|
|
@@ -968,9 +1056,9 @@ async function hydrateSlackContext(token, incoming) {
|
|
|
968
1056
|
};
|
|
969
1057
|
})
|
|
970
1058
|
: [];
|
|
971
|
-
const profile =
|
|
972
|
-
const isGuest =
|
|
973
|
-
const isExternal =
|
|
1059
|
+
const profile = identity;
|
|
1060
|
+
const isGuest = identity?.memberType === "guest";
|
|
1061
|
+
const isExternal = identity?.memberType === "external";
|
|
974
1062
|
const isPrivate = conversation?.channel?.is_private === true;
|
|
975
1063
|
const isExternalShared = conversation?.channel?.is_ext_shared === true;
|
|
976
1064
|
const isMpim = conversation?.channel?.is_mpim === true;
|
|
@@ -1006,17 +1094,14 @@ async function hydrateSlackContext(token, incoming) {
|
|
|
1006
1094
|
const hydratedFiles = hydratedMessages.flatMap((message) => message.files ?? []);
|
|
1007
1095
|
return {
|
|
1008
1096
|
...incoming,
|
|
1009
|
-
...(
|
|
1010
|
-
|
|
1011
|
-
: typeof profile?.real_name === "string" && profile.real_name
|
|
1012
|
-
? { senderName: profile.real_name }
|
|
1013
|
-
: {}),
|
|
1014
|
-
...(typeof profile?.email === "string"
|
|
1097
|
+
...(profile?.name ? { senderName: profile.name } : {}),
|
|
1098
|
+
...(profile?.email
|
|
1015
1099
|
? { senderEmail: profile.email, senderVerified: true }
|
|
1016
|
-
: {}),
|
|
1100
|
+
: { senderVerified: false }),
|
|
1017
1101
|
conversationType,
|
|
1018
1102
|
actorTrust: {
|
|
1019
|
-
memberType:
|
|
1103
|
+
memberType: identity?.memberType ??
|
|
1104
|
+
(isExternal ? "external" : isGuest ? "guest" : "member"),
|
|
1020
1105
|
verified: true,
|
|
1021
1106
|
},
|
|
1022
1107
|
contextMessages: hydratedMessages,
|