crewly 1.20.307 → 1.20.309

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 (93) hide show
  1. package/config/hooks/agent-status/report.sh +5 -5
  2. package/dist/backend/backend/src/constants.d.ts +80 -0
  3. package/dist/backend/backend/src/constants.d.ts.map +1 -1
  4. package/dist/backend/backend/src/constants.js +80 -0
  5. package/dist/backend/backend/src/constants.js.map +1 -1
  6. package/dist/backend/backend/src/index.d.ts +9 -0
  7. package/dist/backend/backend/src/index.d.ts.map +1 -1
  8. package/dist/backend/backend/src/index.js +161 -2
  9. package/dist/backend/backend/src/index.js.map +1 -1
  10. package/dist/backend/backend/src/services/board/board-activity.normalizer.d.ts +17 -0
  11. package/dist/backend/backend/src/services/board/board-activity.normalizer.d.ts.map +1 -1
  12. package/dist/backend/backend/src/services/board/board-activity.normalizer.js +8 -5
  13. package/dist/backend/backend/src/services/board/board-activity.normalizer.js.map +1 -1
  14. package/dist/backend/backend/src/services/board/board-activity.tracker.d.ts +5 -0
  15. package/dist/backend/backend/src/services/board/board-activity.tracker.d.ts.map +1 -1
  16. package/dist/backend/backend/src/services/board/board-activity.tracker.js +25 -1
  17. package/dist/backend/backend/src/services/board/board-activity.tracker.js.map +1 -1
  18. package/dist/backend/backend/src/services/board/board-interaction-hooks.d.ts +34 -0
  19. package/dist/backend/backend/src/services/board/board-interaction-hooks.d.ts.map +1 -0
  20. package/dist/backend/backend/src/services/board/board-interaction-hooks.js +60 -0
  21. package/dist/backend/backend/src/services/board/board-interaction-hooks.js.map +1 -0
  22. package/dist/backend/backend/src/services/board/board-interactions.d.ts +54 -0
  23. package/dist/backend/backend/src/services/board/board-interactions.d.ts.map +1 -0
  24. package/dist/backend/backend/src/services/board/board-interactions.js +92 -0
  25. package/dist/backend/backend/src/services/board/board-interactions.js.map +1 -0
  26. package/dist/backend/backend/src/services/board/board-links.d.ts +51 -0
  27. package/dist/backend/backend/src/services/board/board-links.d.ts.map +1 -0
  28. package/dist/backend/backend/src/services/board/board-links.js +168 -0
  29. package/dist/backend/backend/src/services/board/board-links.js.map +1 -0
  30. package/dist/backend/backend/src/services/board/board-push.service.d.ts +28 -3
  31. package/dist/backend/backend/src/services/board/board-push.service.d.ts.map +1 -1
  32. package/dist/backend/backend/src/services/board/board-push.service.js +108 -9
  33. package/dist/backend/backend/src/services/board/board-push.service.js.map +1 -1
  34. package/dist/backend/backend/src/services/board/board-snapshot.builder.d.ts +39 -2
  35. package/dist/backend/backend/src/services/board/board-snapshot.builder.d.ts.map +1 -1
  36. package/dist/backend/backend/src/services/board/board-snapshot.builder.js +85 -8
  37. package/dist/backend/backend/src/services/board/board-snapshot.builder.js.map +1 -1
  38. package/dist/backend/backend/src/services/board/board.sources.d.ts.map +1 -1
  39. package/dist/backend/backend/src/services/board/board.sources.js +27 -1
  40. package/dist/backend/backend/src/services/board/board.sources.js.map +1 -1
  41. package/dist/backend/backend/src/services/board/board.types.d.ts +48 -0
  42. package/dist/backend/backend/src/services/board/board.types.d.ts.map +1 -1
  43. package/dist/backend/backend/src/services/board/board.types.js +9 -1
  44. package/dist/backend/backend/src/services/board/board.types.js.map +1 -1
  45. package/dist/backend/backend/src/services/board/canvas/canvas-inbound.service.d.ts +122 -0
  46. package/dist/backend/backend/src/services/board/canvas/canvas-inbound.service.d.ts.map +1 -0
  47. package/dist/backend/backend/src/services/board/canvas/canvas-inbound.service.js +339 -0
  48. package/dist/backend/backend/src/services/board/canvas/canvas-inbound.service.js.map +1 -0
  49. package/dist/backend/backend/src/services/board/canvas/canvas-redact.d.ts +44 -0
  50. package/dist/backend/backend/src/services/board/canvas/canvas-redact.d.ts.map +1 -0
  51. package/dist/backend/backend/src/services/board/canvas/canvas-redact.js +161 -0
  52. package/dist/backend/backend/src/services/board/canvas/canvas-redact.js.map +1 -0
  53. package/dist/backend/backend/src/services/board/canvas/canvas-step.normalizer.d.ts +57 -0
  54. package/dist/backend/backend/src/services/board/canvas/canvas-step.normalizer.d.ts.map +1 -0
  55. package/dist/backend/backend/src/services/board/canvas/canvas-step.normalizer.js +164 -0
  56. package/dist/backend/backend/src/services/board/canvas/canvas-step.normalizer.js.map +1 -0
  57. package/dist/backend/backend/src/services/board/canvas/canvas-step.stream.d.ts +140 -0
  58. package/dist/backend/backend/src/services/board/canvas/canvas-step.stream.d.ts.map +1 -0
  59. package/dist/backend/backend/src/services/board/canvas/canvas-step.stream.js +300 -0
  60. package/dist/backend/backend/src/services/board/canvas/canvas-step.stream.js.map +1 -0
  61. package/dist/backend/backend/src/services/board/canvas/canvas-terminal.service.d.ts +99 -0
  62. package/dist/backend/backend/src/services/board/canvas/canvas-terminal.service.d.ts.map +1 -0
  63. package/dist/backend/backend/src/services/board/canvas/canvas-terminal.service.js +223 -0
  64. package/dist/backend/backend/src/services/board/canvas/canvas-terminal.service.js.map +1 -0
  65. package/dist/backend/backend/src/services/board/canvas/canvas-transcript.tail.d.ts +126 -0
  66. package/dist/backend/backend/src/services/board/canvas/canvas-transcript.tail.d.ts.map +1 -0
  67. package/dist/backend/backend/src/services/board/canvas/canvas-transcript.tail.js +385 -0
  68. package/dist/backend/backend/src/services/board/canvas/canvas-transcript.tail.js.map +1 -0
  69. package/dist/backend/backend/src/services/board/canvas/canvas-wiring.d.ts +103 -0
  70. package/dist/backend/backend/src/services/board/canvas/canvas-wiring.d.ts.map +1 -0
  71. package/dist/backend/backend/src/services/board/canvas/canvas-wiring.js +124 -0
  72. package/dist/backend/backend/src/services/board/canvas/canvas-wiring.js.map +1 -0
  73. package/dist/backend/backend/src/services/board/canvas/canvas.types.d.ts +88 -0
  74. package/dist/backend/backend/src/services/board/canvas/canvas.types.d.ts.map +1 -0
  75. package/dist/backend/backend/src/services/board/canvas/canvas.types.js +8 -0
  76. package/dist/backend/backend/src/services/board/canvas/canvas.types.js.map +1 -0
  77. package/dist/backend/backend/src/services/cloud/cloud-sync.types.d.ts +1 -1
  78. package/dist/backend/backend/src/services/cloud/cloud-sync.types.d.ts.map +1 -1
  79. package/dist/backend/backend/src/services/cloud/cloud-sync.types.js +1 -0
  80. package/dist/backend/backend/src/services/cloud/cloud-sync.types.js.map +1 -1
  81. package/dist/backend/backend/src/services/slack/slack-initializer.d.ts.map +1 -1
  82. package/dist/backend/backend/src/services/slack/slack-initializer.js +2 -1
  83. package/dist/backend/backend/src/services/slack/slack-initializer.js.map +1 -1
  84. package/dist/backend/build-info.json +2 -2
  85. package/dist/cli/backend/src/constants.d.ts +80 -0
  86. package/dist/cli/backend/src/constants.d.ts.map +1 -1
  87. package/dist/cli/backend/src/constants.js +80 -0
  88. package/dist/cli/backend/src/constants.js.map +1 -1
  89. package/dist/cli/backend/src/services/cloud/cloud-sync.types.d.ts +1 -1
  90. package/dist/cli/backend/src/services/cloud/cloud-sync.types.d.ts.map +1 -1
  91. package/dist/cli/backend/src/services/cloud/cloud-sync.types.js +1 -0
  92. package/dist/cli/backend/src/services/cloud/cloud-sync.types.js.map +1 -1
  93. package/package.json +1 -1
@@ -4,5 +4,13 @@
4
4
  *
5
5
  * @module services/board/board.types
6
6
  */
7
- export {};
7
+ /**
8
+ * The identity of a link.
9
+ *
10
+ * @param link - Link (or its identity parts)
11
+ * @returns `kind|from|to`
12
+ */
13
+ export function linkKey(link) {
14
+ return `${link.kind}|${link.from}|${link.to}`;
15
+ }
8
16
  //# sourceMappingURL=board.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"board.types.js","sourceRoot":"","sources":["../../../../../../backend/src/services/board/board.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
1
+ {"version":3,"file":"board.types.js","sourceRoot":"","sources":["../../../../../../backend/src/services/board/board.types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2CH;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,IAA6C;IACpE,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * CanvasInboundService - the machine side of the owner actions on the Crewly
3
+ * Canvas (crewly#1247 v2).
4
+ *
5
+ * The owner uses the canvas in the Crewly Cloud portal: message an agent, stop
6
+ * an agent, open / renew / close an agent's terminal. Cloud stores the action
7
+ * and pushes a `canvas_action` relay message with only ids in it
8
+ * (`{actionId, instanceId, session, kind}`) - the same secure pattern as Cloud
9
+ * Talk and "waiting on you". This service:
10
+ *
11
+ * 1. checks the push is for this machine and names an agent that exists here;
12
+ * 2. fetches the action from Cloud with this machine's own token
13
+ * (`GET /api/cloud/canvas/actions/:actionId?instanceId=`). Cloud answers
14
+ * only for an action stored by the OWNER of the token's account for this
15
+ * machine, so a push anybody else dropped in the relay queue (or one from a
16
+ * member / guest of the account) is never run; the fetched ids and kind
17
+ * must match the push;
18
+ * 3. runs it: a message is recorded in the agent's DM as an owner message and
19
+ * handed to the agent exactly like a Talk / Crewly Chat message (replies
20
+ * route as usual); a stop is the dashboard's stop; terminal actions drive
21
+ * {@link CanvasTerminalService};
22
+ * 4. reports the result (`POST .../actions/:actionId/result`).
23
+ *
24
+ * Idempotent: an action carried out is not run again when Cloud re-pushes it
25
+ * (it only re-reports); a message is also keyed by `clientMessageId` in the DM.
26
+ *
27
+ * Older OSS versions ignore `canvas_action` (every relay listener filters on
28
+ * its own `type`), and Cloud only sends it to machines advertising the
29
+ * `canvas_actions` capability, which this service turns on when it starts.
30
+ *
31
+ * @module services/board/canvas/canvas-inbound.service
32
+ */
33
+ import { type ComponentLogger } from '../../core/logger.service.js';
34
+ import type { ChatChannelDTO, ChatMessageDTO } from '../../chat-v2/types.js';
35
+ import type { IncomingMessage } from '../../cloud/cloud-sync.types.js';
36
+ import type { CloudTalkCloud, CloudTalkFetch, CloudTalkInboundChat, CloudTalkSource } from '../../cloud/cloud-talk-inbound.service.js';
37
+ import type { CanvasTerminalService } from './canvas-terminal.service.js';
38
+ import type { CanvasActionFetchResponse, CanvasActionRelayData } from './canvas.types.js';
39
+ /**
40
+ * Validate the relay push. Never throws.
41
+ *
42
+ * @param raw - `msg.payload`
43
+ * @returns The ids, or null when malformed
44
+ */
45
+ export declare function parseCanvasRelayData(raw: unknown): CanvasActionRelayData | null;
46
+ /**
47
+ * Validate Cloud's answer to the action fetch (`{success, data: {...}}`). Never throws.
48
+ *
49
+ * @param raw - Parsed JSON body
50
+ * @returns The action, or null when unusable
51
+ */
52
+ export declare function parseCanvasFetchResponse(raw: unknown): CanvasActionFetchResponse | null;
53
+ /** Constructor dependencies. */
54
+ export interface CanvasInboundDeps {
55
+ source: CloudTalkSource;
56
+ cloud: CloudTalkCloud;
57
+ chat: CloudTalkInboundChat;
58
+ identity: () => Promise<{
59
+ instanceId: string;
60
+ deviceName?: string;
61
+ }>;
62
+ /** Hand the recorded message to the agent (ticket intake + dispatcher), as Cloud Talk does. */
63
+ deliver: (channel: ChatChannelDTO, message: ChatMessageDTO) => Promise<void>;
64
+ /** Whether the agent exists on this machine */
65
+ agentExists: (session: string) => Promise<boolean>;
66
+ /** Stop the agent (the dashboard's stop). */
67
+ stopAgent: (session: string) => Promise<{
68
+ ok: boolean;
69
+ error?: string;
70
+ }>;
71
+ terminal: Pick<CanvasTerminalService, 'open' | 'renew' | 'close'>;
72
+ /** An owner action arrived: someone is watching */
73
+ onAction?: () => void;
74
+ ownerUserId?: string;
75
+ fetchImpl?: CloudTalkFetch;
76
+ sleep?: (ms: number) => Promise<void>;
77
+ now?: () => number;
78
+ logger?: ComponentLogger;
79
+ }
80
+ /** What {@link CanvasInboundService.handle} did (tests, logs). */
81
+ export type CanvasActionOutcome = 'done' | 'refused' | 'duplicate' | 'ignored' | 'not_for_this_machine' | 'unverified' | 'fetch_failed';
82
+ /**
83
+ * Capabilities to advertise to Cloud (heartbeat and uploads).
84
+ *
85
+ * @returns `['canvas_actions']` while the handler runs, else `[]`
86
+ */
87
+ export declare function canvasCapabilities(): string[];
88
+ /** Runs the owner's canvas actions pushed from Crewly Cloud - see module docs. */
89
+ export declare class CanvasInboundService {
90
+ private readonly deps;
91
+ private readonly logger;
92
+ private readonly fetchImpl;
93
+ private readonly sleep;
94
+ private readonly now;
95
+ private readonly ownerUserId;
96
+ private readonly inFlight;
97
+ private readonly done;
98
+ private readonly listener;
99
+ private started;
100
+ constructor(deps: CanvasInboundDeps);
101
+ /** Subscribe to relay messages and advertise the capability. Idempotent. */
102
+ start(): void;
103
+ /** Unsubscribe; the capability is no longer advertised. */
104
+ stop(): void;
105
+ /**
106
+ * Handle one relay message. Anything but a well-formed `canvas_action` is
107
+ * ignored. Never throws.
108
+ *
109
+ * @param msg - Relay message from CloudSyncService
110
+ * @returns What was done
111
+ */
112
+ handle(msg: IncomingMessage): Promise<CanvasActionOutcome>;
113
+ private process;
114
+ private run;
115
+ private pruneDone;
116
+ private url;
117
+ /** Fetch the action from Cloud with this machine's token; one refresh on 401, a few retries on network / 5xx. */
118
+ private fetchAction;
119
+ /** Report the result to Cloud (best effort; a re-push re-reports). */
120
+ private report;
121
+ }
122
+ //# sourceMappingURL=canvas-inbound.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas-inbound.service.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/board/canvas/canvas-inbound.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEnF,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AACvI,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EACX,yBAAyB,EAEzB,qBAAqB,EAErB,MAAM,mBAAmB,CAAC;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AM,MAAM,mBAAmB,GAC5B,MAAM,GACN,SAAS,GACT,WAAW,GACX,SAAS,GACT,sBAAsB,GACtB,YAAY,GACZ,cAAc,CAAC;AAMlB;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED,kFAAkF;AAClF,qBAAa,oBAAoB;IAapB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAZjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwE;IAC7F,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAEvB;IACF,OAAO,CAAC,OAAO,CAAS;gBAEK,IAAI,EAAE,iBAAiB;IAQpD,4EAA4E;IAC5E,KAAK,IAAI,IAAI;IAQb,2DAA2D;IAC3D,IAAI,IAAI,IAAI;IAOZ;;;;;;OAMG;IACG,MAAM,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAmBlD,OAAO;YA4CP,GAAG;IAgDjB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,GAAG;IAKX,iHAAiH;YACnG,WAAW;IAqCzB,sEAAsE;YACxD,MAAM;CAepB"}
@@ -0,0 +1,339 @@
1
+ /**
2
+ * CanvasInboundService - the machine side of the owner actions on the Crewly
3
+ * Canvas (crewly#1247 v2).
4
+ *
5
+ * The owner uses the canvas in the Crewly Cloud portal: message an agent, stop
6
+ * an agent, open / renew / close an agent's terminal. Cloud stores the action
7
+ * and pushes a `canvas_action` relay message with only ids in it
8
+ * (`{actionId, instanceId, session, kind}`) - the same secure pattern as Cloud
9
+ * Talk and "waiting on you". This service:
10
+ *
11
+ * 1. checks the push is for this machine and names an agent that exists here;
12
+ * 2. fetches the action from Cloud with this machine's own token
13
+ * (`GET /api/cloud/canvas/actions/:actionId?instanceId=`). Cloud answers
14
+ * only for an action stored by the OWNER of the token's account for this
15
+ * machine, so a push anybody else dropped in the relay queue (or one from a
16
+ * member / guest of the account) is never run; the fetched ids and kind
17
+ * must match the push;
18
+ * 3. runs it: a message is recorded in the agent's DM as an owner message and
19
+ * handed to the agent exactly like a Talk / Crewly Chat message (replies
20
+ * route as usual); a stop is the dashboard's stop; terminal actions drive
21
+ * {@link CanvasTerminalService};
22
+ * 4. reports the result (`POST .../actions/:actionId/result`).
23
+ *
24
+ * Idempotent: an action carried out is not run again when Cloud re-pushes it
25
+ * (it only re-reports); a message is also keyed by `clientMessageId` in the DM.
26
+ *
27
+ * Older OSS versions ignore `canvas_action` (every relay listener filters on
28
+ * its own `type`), and Cloud only sends it to machines advertising the
29
+ * `canvas_actions` capability, which this service turns on when it starts.
30
+ *
31
+ * @module services/board/canvas/canvas-inbound.service
32
+ */
33
+ import { CANVAS_CONSTANTS, ORCHESTRATOR_SESSION_NAME, SLACK_AGENT_DM_CONSTANTS } from '../../../constants.js';
34
+ import { LoggerService } from '../../core/logger.service.js';
35
+ import { recordCloudTalkTurn } from '../../chat-v2/owner-inbound.utils.js';
36
+ const C = CANVAS_CONSTANTS;
37
+ /** Session names; `@` only for the orchestrator spelled per machine (`crewly-orc@<instance>`). */
38
+ const SESSION_PATTERN = /^[A-Za-z0-9._@-]{1,128}$/;
39
+ const ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
40
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
41
+ const isKind = (v) => typeof v === 'string' && C.ACTION_KINDS.includes(v);
42
+ /**
43
+ * Validate the relay push. Never throws.
44
+ *
45
+ * @param raw - `msg.payload`
46
+ * @returns The ids, or null when malformed
47
+ */
48
+ export function parseCanvasRelayData(raw) {
49
+ if (!isRecord(raw))
50
+ return null;
51
+ const { actionId, instanceId, session, kind } = raw;
52
+ if (typeof actionId !== 'string' || !ID_PATTERN.test(actionId))
53
+ return null;
54
+ if (typeof instanceId !== 'string' || instanceId.length === 0 || instanceId.length > 128)
55
+ return null;
56
+ if (typeof session !== 'string' || !SESSION_PATTERN.test(session))
57
+ return null;
58
+ if (!isKind(kind))
59
+ return null;
60
+ return { actionId, instanceId, session, kind };
61
+ }
62
+ /**
63
+ * Validate Cloud's answer to the action fetch (`{success, data: {...}}`). Never throws.
64
+ *
65
+ * @param raw - Parsed JSON body
66
+ * @returns The action, or null when unusable
67
+ */
68
+ export function parseCanvasFetchResponse(raw) {
69
+ const data = isRecord(raw) && isRecord(raw['data']) ? raw['data'] : null;
70
+ if (!data)
71
+ return null;
72
+ const { actionId, instanceId, session, kind, text, clientMessageId } = data;
73
+ if (typeof actionId !== 'string' || !ID_PATTERN.test(actionId))
74
+ return null;
75
+ if (typeof instanceId !== 'string' || !instanceId)
76
+ return null;
77
+ if (typeof session !== 'string' || !SESSION_PATTERN.test(session))
78
+ return null;
79
+ if (!isKind(kind))
80
+ return null;
81
+ return {
82
+ actionId,
83
+ instanceId,
84
+ session,
85
+ kind,
86
+ ...(typeof text === 'string' ? { text } : {}),
87
+ ...(typeof clientMessageId === 'string' && ID_PATTERN.test(clientMessageId) ? { clientMessageId } : {}),
88
+ };
89
+ }
90
+ let active = false;
91
+ /**
92
+ * Capabilities to advertise to Cloud (heartbeat and uploads).
93
+ *
94
+ * @returns `['canvas_actions']` while the handler runs, else `[]`
95
+ */
96
+ export function canvasCapabilities() {
97
+ return active ? [C.CAPABILITY] : [];
98
+ }
99
+ /** Runs the owner's canvas actions pushed from Crewly Cloud - see module docs. */
100
+ export class CanvasInboundService {
101
+ deps;
102
+ logger;
103
+ fetchImpl;
104
+ sleep;
105
+ now;
106
+ ownerUserId;
107
+ inFlight = new Set();
108
+ done = new Map();
109
+ listener = (msg) => {
110
+ void this.handle(msg);
111
+ };
112
+ started = false;
113
+ constructor(deps) {
114
+ this.deps = deps;
115
+ this.logger = deps.logger ?? LoggerService.getInstance().createComponentLogger('CanvasInbound');
116
+ this.fetchImpl = deps.fetchImpl ?? ((input, init) => fetch(input, init));
117
+ this.sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
118
+ this.now = deps.now ?? Date.now;
119
+ this.ownerUserId = deps.ownerUserId ?? SLACK_AGENT_DM_CONSTANTS.OWNER_USER_ID;
120
+ }
121
+ /** Subscribe to relay messages and advertise the capability. Idempotent. */
122
+ start() {
123
+ if (this.started)
124
+ return;
125
+ this.started = true;
126
+ this.deps.source.on('message', this.listener);
127
+ active = true;
128
+ this.logger.info('Canvas action handler started');
129
+ }
130
+ /** Unsubscribe; the capability is no longer advertised. */
131
+ stop() {
132
+ if (!this.started)
133
+ return;
134
+ this.started = false;
135
+ this.deps.source.off('message', this.listener);
136
+ active = false;
137
+ }
138
+ /**
139
+ * Handle one relay message. Anything but a well-formed `canvas_action` is
140
+ * ignored. Never throws.
141
+ *
142
+ * @param msg - Relay message from CloudSyncService
143
+ * @returns What was done
144
+ */
145
+ async handle(msg) {
146
+ if (msg?.type !== C.RELAY_MESSAGE_TYPE)
147
+ return 'ignored';
148
+ const data = parseCanvasRelayData(msg.payload);
149
+ if (!data) {
150
+ this.logger.warn('Ignored a malformed canvas_action relay message');
151
+ return 'ignored';
152
+ }
153
+ if (this.inFlight.has(data.actionId))
154
+ return 'duplicate';
155
+ this.inFlight.add(data.actionId);
156
+ try {
157
+ return await this.process(data);
158
+ }
159
+ catch (error) {
160
+ this.logger.warn('Canvas action failed', { actionId: data.actionId, error: error instanceof Error ? error.message : String(error) });
161
+ return 'fetch_failed';
162
+ }
163
+ finally {
164
+ this.inFlight.delete(data.actionId);
165
+ }
166
+ }
167
+ async process(data) {
168
+ const { instanceId, deviceName } = await this.deps.identity();
169
+ if (data.instanceId !== instanceId) {
170
+ this.logger.warn('Ignored a canvas_action addressed to another machine', { target: data.instanceId });
171
+ return 'not_for_this_machine';
172
+ }
173
+ this.pruneDone();
174
+ const earlier = this.done.get(data.actionId);
175
+ if (earlier) {
176
+ await this.report(data.actionId, earlier.result);
177
+ return 'duplicate';
178
+ }
179
+ const fetched = await this.fetchAction(data, instanceId);
180
+ if (fetched.kind === 'not_found') {
181
+ // Not an action the account's owner stored for this machine: not from Cloud
182
+ this.logger.warn('Ignored a canvas_action Crewly Cloud does not know for this machine', { actionId: data.actionId });
183
+ return 'unverified';
184
+ }
185
+ if (fetched.kind === 'expired')
186
+ return 'duplicate';
187
+ if (fetched.kind === 'error') {
188
+ this.logger.warn('Could not fetch a canvas action; Cloud will push it again', { actionId: data.actionId, error: fetched.error });
189
+ return 'fetch_failed';
190
+ }
191
+ const action = fetched.action;
192
+ if (action.actionId !== data.actionId || action.instanceId !== instanceId || action.session !== data.session || action.kind !== data.kind) {
193
+ this.logger.warn('Ignored a canvas_action that does not match what Cloud stored', { actionId: data.actionId });
194
+ return 'unverified';
195
+ }
196
+ this.deps.onAction?.();
197
+ const device = deviceName || 'this machine';
198
+ const session = action.session.startsWith(`${ORCHESTRATOR_SESSION_NAME}@`) ? ORCHESTRATOR_SESSION_NAME : action.session;
199
+ let result;
200
+ if (!(await this.deps.agentExists(session))) {
201
+ result = { instanceId, ok: false, code: 'no_agent', error: `No agent named "${session}" on ${device}` };
202
+ }
203
+ else {
204
+ result = await this.run(action, session, instanceId, device);
205
+ }
206
+ this.done.set(data.actionId, { at: this.now(), result });
207
+ await this.report(data.actionId, result);
208
+ return result.ok ? 'done' : 'refused';
209
+ }
210
+ async run(action, session, instanceId, device) {
211
+ const fail = (code, error) => ({ instanceId, ok: false, code, error });
212
+ switch (action.kind) {
213
+ case 'message': {
214
+ const text = (action.text ?? '').trim();
215
+ if (!text)
216
+ return fail('empty', 'The message is empty');
217
+ if (text.length > C.MESSAGE_MAX)
218
+ return fail('too_long', `The message is longer than ${C.MESSAGE_MAX} characters`);
219
+ let recorded;
220
+ try {
221
+ recorded = recordCloudTalkTurn(this.deps.chat, {
222
+ agentSession: session,
223
+ text,
224
+ clientMessageId: action.clientMessageId ?? `canvas-${action.actionId}`,
225
+ ownerUserId: this.ownerUserId,
226
+ });
227
+ }
228
+ catch (error) {
229
+ return fail('record_failed', `Could not record the message on ${device}: ${error instanceof Error ? error.message : String(error)}`);
230
+ }
231
+ if (recorded.deduped)
232
+ return { instanceId, ok: true };
233
+ try {
234
+ const channel = this.deps.chat.getChannel(recorded.channelId, { userId: this.ownerUserId, source: 'oss' });
235
+ await this.deps.deliver(channel, recorded.message);
236
+ }
237
+ catch (error) {
238
+ // Recorded, but the agent was not paged: it reads the DM when it next looks
239
+ this.logger.warn('Canvas message recorded but not handed to the agent', { session, error: error instanceof Error ? error.message : String(error) });
240
+ }
241
+ this.logger.info('Canvas message received', { session });
242
+ return { instanceId, ok: true };
243
+ }
244
+ case 'stop': {
245
+ if (session === ORCHESTRATOR_SESSION_NAME)
246
+ return fail('not_allowed', 'The orchestrator is stopped on the machine itself');
247
+ const r = await this.deps.stopAgent(session);
248
+ this.logger.info('Canvas stop', { session, ok: r.ok });
249
+ return r.ok ? { instanceId, ok: true } : fail('stop_failed', r.error ?? 'Could not stop the agent');
250
+ }
251
+ case 'terminal_open':
252
+ case 'terminal_renew': {
253
+ if (action.kind === 'terminal_renew' && this.deps.terminal.renew(session))
254
+ return { instanceId, ok: true };
255
+ // A renew after a restart opens again: the viewer is still there
256
+ const r = this.deps.terminal.open(session);
257
+ return r.ok ? { instanceId, ok: true } : fail(r.code, r.code === 'too_many_streams' ? 'Too many terminals are open' : r.code === 'no_session' ? 'The agent has no terminal right now' : 'Not signed in to Crewly Cloud');
258
+ }
259
+ case 'terminal_close':
260
+ this.deps.terminal.close(session, 'closed');
261
+ return { instanceId, ok: true };
262
+ }
263
+ }
264
+ pruneDone() {
265
+ const cutoff = this.now() - C.DONE_ACTIONS_TTL_MS;
266
+ for (const [id, entry] of this.done)
267
+ if (entry.at < cutoff)
268
+ this.done.delete(id);
269
+ while (this.done.size > C.DONE_ACTIONS_MAX)
270
+ this.done.delete(this.done.keys().next().value);
271
+ }
272
+ url(suffix) {
273
+ const base = this.deps.cloud.getCloudUrl();
274
+ return base ? `${base.replace(/\/$/, '')}${C.ACTIONS_PATH}${suffix}` : null;
275
+ }
276
+ /** Fetch the action from Cloud with this machine's token; one refresh on 401, a few retries on network / 5xx. */
277
+ async fetchAction(data, instanceId) {
278
+ const url = this.url(`/${encodeURIComponent(data.actionId)}?instanceId=${encodeURIComponent(instanceId)}`);
279
+ if (!url)
280
+ return { kind: 'error', error: 'not signed in to Crewly Cloud' };
281
+ const delays = C.FETCH_RETRY_DELAYS_MS;
282
+ let refreshed = false;
283
+ let lastError = 'unknown';
284
+ for (let attempt = 0; attempt <= delays.length; attempt++) {
285
+ if (attempt > 0)
286
+ await this.sleep(delays[attempt - 1] ?? 0);
287
+ const token = this.deps.cloud.getToken();
288
+ if (!token)
289
+ return { kind: 'error', error: 'not signed in to Crewly Cloud' };
290
+ let response;
291
+ try {
292
+ response = await this.fetchImpl(url, { method: 'GET', headers: { Authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(C.REQUEST_TIMEOUT_MS) });
293
+ }
294
+ catch (error) {
295
+ lastError = error instanceof Error ? error.message : String(error);
296
+ continue;
297
+ }
298
+ if (response.status === 401 && !refreshed && this.deps.cloud.tryRefreshToken) {
299
+ refreshed = true;
300
+ if (await this.deps.cloud.tryRefreshToken().catch(() => false)) {
301
+ attempt--;
302
+ continue;
303
+ }
304
+ }
305
+ // 403: the token's account is not the owner of this action (a member / guest)
306
+ if (response.status === 404 || response.status === 403)
307
+ return { kind: 'not_found' };
308
+ if (response.status === 410)
309
+ return { kind: 'expired' };
310
+ if (response.ok) {
311
+ const parsed = parseCanvasFetchResponse(await response.json().catch(() => null));
312
+ return parsed ? { kind: 'ok', action: parsed } : { kind: 'error', error: 'unusable response from Crewly Cloud' };
313
+ }
314
+ lastError = `HTTP ${response.status}`;
315
+ if (response.status >= 400 && response.status < 500 && response.status !== 429)
316
+ break;
317
+ }
318
+ return { kind: 'error', error: lastError };
319
+ }
320
+ /** Report the result to Cloud (best effort; a re-push re-reports). */
321
+ async report(actionId, body) {
322
+ const url = this.url(`/${encodeURIComponent(actionId)}/result`);
323
+ const token = this.deps.cloud.getToken();
324
+ if (!url || !token)
325
+ return;
326
+ try {
327
+ await this.fetchImpl(url, {
328
+ method: 'POST',
329
+ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
330
+ body: JSON.stringify(body),
331
+ signal: AbortSignal.timeout(C.REQUEST_TIMEOUT_MS),
332
+ });
333
+ }
334
+ catch (error) {
335
+ this.logger.debug('Could not report a canvas action result', { actionId, error: error instanceof Error ? error.message : String(error) });
336
+ }
337
+ }
338
+ }
339
+ //# sourceMappingURL=canvas-inbound.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas-inbound.service.js","sourceRoot":"","sources":["../../../../../../../backend/src/services/board/canvas/canvas-inbound.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAwB,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAY3E,MAAM,CAAC,GAAG,gBAAgB,CAAC;AAE3B,kGAAkG;AAClG,MAAM,eAAe,GAAG,0BAA0B,CAAC;AACnD,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAE5C,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxH,MAAM,MAAM,GAAG,CAAC,CAAU,EAAyB,EAAE,CAAC,OAAO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MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3I,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Redaction for what the canvas shows (crewly#1247 v2), on the machine, before
3
+ * anything leaves it:
4
+ *
5
+ * - {@link shortAgentLine}: the agent's own words from a transcript, reduced
6
+ * to one short line (at most 280 characters), no code blocks, no secrets;
7
+ * - {@link maskTerminalText}: a terminal tail with every secret, token, email
8
+ * and URL query masked.
9
+ *
10
+ * Both reuse the board's {@link scrubText} and the secret redactor that guards
11
+ * the session logs; this file only adds what those do not cover (zero-width
12
+ * characters, base64 blobs, spaced `key = value` secrets, ANSI).
13
+ *
14
+ * Pure (no I/O).
15
+ *
16
+ * @module services/board/canvas/canvas-redact
17
+ */
18
+ import type { SecretEnvValue } from '../../../utils/secret-env.js';
19
+ /**
20
+ * Reduce an assistant message block to one short, safe line.
21
+ *
22
+ * Takes the first paragraph outside code fences (a list item or heading loses
23
+ * its marker), removes markdown emphasis, masks secrets / emails / URL
24
+ * queries / phone numbers, and cuts at 280 characters. Anything that is
25
+ * markup (`<system-reminder>`), an interrupt notice, or empty after masking
26
+ * gives null.
27
+ *
28
+ * @param raw - Text of a `text` block
29
+ * @param secrets - Exact secret values to mask (backend env)
30
+ * @returns The line, or null when nothing worth showing is left
31
+ */
32
+ export declare function shortAgentLine(raw: unknown, secrets?: readonly SecretEnvValue[]): string | null;
33
+ /**
34
+ * Mask a terminal tail for the canvas: ANSI and control characters removed,
35
+ * then secrets (by value, by `NAME=value`, by shape), emails, URL queries and
36
+ * credentials, bearer tokens, password prompts and long token-like words.
37
+ *
38
+ * @param text - Raw tail (the PTY capture)
39
+ * @param secrets - Exact secret values to mask (backend env)
40
+ * @param maxLines - Keep this many lines from the end
41
+ * @returns Lines, oldest first, each at most {@link CANVAS_CONSTANTS.TERMINAL_MAX_LINE_CHARS} characters
42
+ */
43
+ export declare function maskTerminalText(text: string, secrets?: readonly SecretEnvValue[], maxLines?: number): string[];
44
+ //# sourceMappingURL=canvas-redact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canvas-redact.d.ts","sourceRoot":"","sources":["../../../../../../../backend/src/services/board/canvas/canvas-redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAgEnE;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,SAAS,cAAc,EAAO,GAAG,MAAM,GAAG,IAAI,CAsBnG;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,SAAS,cAAc,EAAO,EAAE,QAAQ,GAAE,MAA8B,GAAG,MAAM,EAAE,CA6B1I"}