@pellux/goodvibes-daemon-sdk 0.18.3

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 (86) hide show
  1. package/README.md +32 -0
  2. package/dist/api-router.d.ts +3 -0
  3. package/dist/api-router.d.ts.map +1 -0
  4. package/dist/api-router.js +13 -0
  5. package/dist/automation.d.ts +3 -0
  6. package/dist/automation.d.ts.map +1 -0
  7. package/dist/automation.js +56 -0
  8. package/dist/channel-route-types.d.ts +78 -0
  9. package/dist/channel-route-types.d.ts.map +1 -0
  10. package/dist/channel-route-types.js +1 -0
  11. package/dist/channel-routes.d.ts +4 -0
  12. package/dist/channel-routes.d.ts.map +1 -0
  13. package/dist/channel-routes.js +264 -0
  14. package/dist/context.d.ts +207 -0
  15. package/dist/context.d.ts.map +1 -0
  16. package/dist/context.js +1 -0
  17. package/dist/control-routes.d.ts +57 -0
  18. package/dist/control-routes.d.ts.map +1 -0
  19. package/dist/control-routes.js +120 -0
  20. package/dist/error-response.d.ts +10 -0
  21. package/dist/error-response.d.ts.map +1 -0
  22. package/dist/error-response.js +84 -0
  23. package/dist/http-policy.d.ts +33 -0
  24. package/dist/http-policy.d.ts.map +1 -0
  25. package/dist/http-policy.js +30 -0
  26. package/dist/index.d.ts +30 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +20 -0
  29. package/dist/integration-route-types.d.ts +64 -0
  30. package/dist/integration-route-types.d.ts.map +1 -0
  31. package/dist/integration-route-types.js +1 -0
  32. package/dist/integration-routes.d.ts +4 -0
  33. package/dist/integration-routes.d.ts.map +1 -0
  34. package/dist/integration-routes.js +172 -0
  35. package/dist/knowledge-route-types.d.ts +114 -0
  36. package/dist/knowledge-route-types.d.ts.map +1 -0
  37. package/dist/knowledge-route-types.js +1 -0
  38. package/dist/knowledge-routes.d.ts +4 -0
  39. package/dist/knowledge-routes.d.ts.map +1 -0
  40. package/dist/knowledge-routes.js +582 -0
  41. package/dist/media-route-types.d.ts +66 -0
  42. package/dist/media-route-types.d.ts.map +1 -0
  43. package/dist/media-route-types.js +1 -0
  44. package/dist/media-routes.d.ts +4 -0
  45. package/dist/media-routes.d.ts.map +1 -0
  46. package/dist/media-routes.js +328 -0
  47. package/dist/operator.d.ts +3 -0
  48. package/dist/operator.d.ts.map +1 -0
  49. package/dist/operator.js +395 -0
  50. package/dist/remote-routes.d.ts +40 -0
  51. package/dist/remote-routes.d.ts.map +1 -0
  52. package/dist/remote-routes.js +238 -0
  53. package/dist/remote.d.ts +3 -0
  54. package/dist/remote.d.ts.map +1 -0
  55. package/dist/remote.js +35 -0
  56. package/dist/route-helpers.d.ts +11 -0
  57. package/dist/route-helpers.d.ts.map +1 -0
  58. package/dist/route-helpers.js +54 -0
  59. package/dist/runtime-automation-routes.d.ts +4 -0
  60. package/dist/runtime-automation-routes.d.ts.map +1 -0
  61. package/dist/runtime-automation-routes.js +165 -0
  62. package/dist/runtime-route-types.d.ts +240 -0
  63. package/dist/runtime-route-types.d.ts.map +1 -0
  64. package/dist/runtime-route-types.js +1 -0
  65. package/dist/runtime-routes.d.ts +5 -0
  66. package/dist/runtime-routes.d.ts.map +1 -0
  67. package/dist/runtime-routes.js +8 -0
  68. package/dist/runtime-session-routes.d.ts +4 -0
  69. package/dist/runtime-session-routes.d.ts.map +1 -0
  70. package/dist/runtime-session-routes.js +387 -0
  71. package/dist/sessions.d.ts +3 -0
  72. package/dist/sessions.d.ts.map +1 -0
  73. package/dist/sessions.js +37 -0
  74. package/dist/system-route-types.d.ts +124 -0
  75. package/dist/system-route-types.d.ts.map +1 -0
  76. package/dist/system-route-types.js +1 -0
  77. package/dist/system-routes.d.ts +4 -0
  78. package/dist/system-routes.d.ts.map +1 -0
  79. package/dist/system-routes.js +327 -0
  80. package/dist/tasks.d.ts +3 -0
  81. package/dist/tasks.d.ts.map +1 -0
  82. package/dist/tasks.js +22 -0
  83. package/dist/telemetry-routes.d.ts +44 -0
  84. package/dist/telemetry-routes.d.ts.map +1 -0
  85. package/dist/telemetry-routes.js +227 -0
  86. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @pellux/goodvibes-daemon-sdk
2
+
3
+ Embeddable daemon and control-plane route contracts, dispatchers, and handler builders for GoodVibes.
4
+
5
+ Install:
6
+
7
+ ```bash
8
+ npm install @pellux/goodvibes-daemon-sdk
9
+ ```
10
+
11
+ Use this package to:
12
+ - embed daemon routes in another host
13
+ - dispatch operator, automation, session, task, or remote API calls
14
+ - reuse shared daemon auth/error helpers
15
+
16
+ Typical entrypoints:
17
+
18
+ ```ts
19
+ import {
20
+ createDaemonControlRouteHandlers,
21
+ createDaemonTelemetryRouteHandlers,
22
+ dispatchDaemonApiRoutes,
23
+ } from '@pellux/goodvibes-daemon-sdk';
24
+ ```
25
+
26
+ This package gives you reusable route modules, but your host still owns:
27
+ - request routing
28
+ - concrete services
29
+ - auth/session storage
30
+ - runtime bootstrapping
31
+
32
+ Use this package when you are embedding GoodVibes into another TypeScript server. Do not use it for normal client-side integrations.
@@ -0,0 +1,3 @@
1
+ import type { DaemonApiRouteHandlers } from './context.js';
2
+ export declare function dispatchDaemonApiRoutes(req: Request, handlers: DaemonApiRouteHandlers): Promise<Response | null>;
3
+ //# sourceMappingURL=api-router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-router.d.ts","sourceRoot":"","sources":["../src/api-router.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAQtH"}
@@ -0,0 +1,13 @@
1
+ // Synced from goodvibes-tui/src/control-plane/routes/api-router.ts
2
+ import { dispatchAutomationRoutes } from './automation.js';
3
+ import { dispatchOperatorRoutes } from './operator.js';
4
+ import { dispatchRemoteRoutes } from './remote.js';
5
+ import { dispatchSessionRoutes } from './sessions.js';
6
+ import { dispatchTaskRoutes } from './tasks.js';
7
+ export async function dispatchDaemonApiRoutes(req, handlers) {
8
+ return (await dispatchRemoteRoutes(req, handlers)
9
+ ?? await dispatchOperatorRoutes(req, handlers)
10
+ ?? await dispatchAutomationRoutes(req, handlers)
11
+ ?? await dispatchSessionRoutes(req, handlers)
12
+ ?? await dispatchTaskRoutes(req, handlers));
13
+ }
@@ -0,0 +1,3 @@
1
+ import type { DaemonApiRouteHandlers } from './context.js';
2
+ export declare function dispatchAutomationRoutes(req: Request, handlers: Pick<DaemonApiRouteHandlers, 'getReview' | 'getIntegrationSession' | 'getIntegrationAutomation' | 'getAutomationJobs' | 'postAutomationJob' | 'getAutomationRuns' | 'getAutomationRun' | 'automationRunAction' | 'patchAutomationJob' | 'deleteAutomationJob' | 'setAutomationJobEnabled' | 'runAutomationJobNow' | 'getDeliveries' | 'getDelivery' | 'getSchedules' | 'postSchedule' | 'deleteSchedule' | 'setScheduleEnabled' | 'runScheduleNow'>): Promise<Response | null>;
3
+ //# sourceMappingURL=automation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation.d.ts","sourceRoot":"","sources":["../src/automation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,IAAI,CACZ,sBAAsB,EACpB,WAAW,GACX,uBAAuB,GACvB,0BAA0B,GAC1B,mBAAmB,GACnB,mBAAmB,GACnB,mBAAmB,GACnB,kBAAkB,GAClB,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,GACrB,yBAAyB,GACzB,qBAAqB,GACrB,eAAe,GACf,aAAa,GACb,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,oBAAoB,GACpB,gBAAgB,CACnB,GACA,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CA+C1B"}
@@ -0,0 +1,56 @@
1
+ export async function dispatchAutomationRoutes(req, handlers) {
2
+ const url = new URL(req.url);
3
+ const { pathname } = url;
4
+ const method = req.method;
5
+ if (pathname === '/api/review' && method === 'GET')
6
+ return handlers.getReview();
7
+ if (pathname === '/api/session' && method === 'GET')
8
+ return handlers.getIntegrationSession();
9
+ if (pathname === '/api/automation' && method === 'GET')
10
+ return handlers.getIntegrationAutomation();
11
+ if (pathname === '/api/automation/jobs' && method === 'GET')
12
+ return handlers.getAutomationJobs();
13
+ if (pathname === '/api/automation/jobs' && method === 'POST')
14
+ return handlers.postAutomationJob(req);
15
+ if (pathname === '/api/automation/runs' && method === 'GET')
16
+ return handlers.getAutomationRuns();
17
+ const automationRunMatch = pathname.match(/^\/api\/automation\/runs\/([^/]+)$/);
18
+ if (automationRunMatch && method === 'GET')
19
+ return handlers.getAutomationRun(automationRunMatch[1]);
20
+ const automationRunActionMatch = pathname.match(/^\/api\/automation\/runs\/([^/]+)\/(cancel|retry)$/);
21
+ if (automationRunActionMatch && method === 'POST') {
22
+ return handlers.automationRunAction(automationRunActionMatch[1], automationRunActionMatch[2], req);
23
+ }
24
+ const automationJobMatch = pathname.match(/^\/api\/automation\/jobs\/([^/]+)$/);
25
+ if (automationJobMatch && method === 'PATCH')
26
+ return handlers.patchAutomationJob(automationJobMatch[1], req);
27
+ if (automationJobMatch && method === 'DELETE')
28
+ return handlers.deleteAutomationJob(automationJobMatch[1]);
29
+ const automationJobActionMatch = pathname.match(/^\/api\/automation\/jobs\/([^/]+)\/(enable|disable|pause|resume|run)$/);
30
+ if (automationJobActionMatch && method === 'POST') {
31
+ const [, jobId, action] = automationJobActionMatch;
32
+ if (action === 'run')
33
+ return handlers.runAutomationJobNow(jobId);
34
+ return handlers.setAutomationJobEnabled(jobId, action === 'enable' || action === 'resume');
35
+ }
36
+ if (pathname === '/api/deliveries' && method === 'GET')
37
+ return handlers.getDeliveries();
38
+ const deliveryMatch = pathname.match(/^\/api\/deliveries\/([^/]+)$/);
39
+ if (deliveryMatch && method === 'GET')
40
+ return handlers.getDelivery(deliveryMatch[1]);
41
+ if (pathname === '/schedules' && method === 'GET')
42
+ return handlers.getSchedules();
43
+ if (pathname === '/schedules' && method === 'POST')
44
+ return handlers.postSchedule(req);
45
+ const scheduleIdMatch = pathname.match(/^\/schedules\/([^/]+)$/);
46
+ if (scheduleIdMatch && method === 'DELETE')
47
+ return handlers.deleteSchedule(scheduleIdMatch[1]);
48
+ const scheduleActionMatch = pathname.match(/^\/schedules\/([^/]+)\/(enable|disable|run)$/);
49
+ if (scheduleActionMatch && method === 'POST') {
50
+ const [, scheduleId, action] = scheduleActionMatch;
51
+ if (action === 'run')
52
+ return handlers.runScheduleNow(scheduleId);
53
+ return handlers.setScheduleEnabled(scheduleId, action === 'enable');
54
+ }
55
+ return null;
56
+ }
@@ -0,0 +1,78 @@
1
+ import type { ChannelConversationKind, ChannelLifecycleAction, JsonRecord } from './route-helpers.js';
2
+ export type ChannelSurface = string;
3
+ export type ChannelDirectoryScope = string;
4
+ export interface ChannelAgentToolDefinitionLike {
5
+ readonly definition: unknown;
6
+ }
7
+ export interface ChannelTargetResolutionInput {
8
+ readonly input: string;
9
+ readonly accountId?: string;
10
+ readonly preferredKind?: ChannelConversationKind;
11
+ readonly threadId?: string;
12
+ readonly sessionId?: string;
13
+ readonly createIfMissing?: boolean;
14
+ readonly live?: boolean;
15
+ readonly metadata?: Record<string, unknown>;
16
+ }
17
+ export interface ChannelAuthorizeActionInput {
18
+ readonly actionId: string;
19
+ readonly actorId?: string;
20
+ readonly accountId?: string;
21
+ readonly target?: unknown;
22
+ readonly metadata?: Record<string, unknown>;
23
+ }
24
+ export interface ChannelAllowlistInput {
25
+ readonly add?: readonly string[];
26
+ readonly remove?: readonly string[];
27
+ readonly groupId?: string;
28
+ readonly channelId?: string;
29
+ readonly workspaceId?: string;
30
+ readonly kind?: 'user' | 'channel' | 'group';
31
+ readonly metadata?: Record<string, unknown>;
32
+ }
33
+ export interface ChannelDirectoryQuery {
34
+ readonly query: string;
35
+ readonly scope?: ChannelDirectoryScope;
36
+ readonly groupId?: string;
37
+ readonly limit?: number;
38
+ readonly live?: boolean;
39
+ }
40
+ export interface ChannelPluginServiceLike {
41
+ listAccounts(surface?: ChannelSurface): Promise<readonly unknown[]>;
42
+ getAccount(surface: ChannelSurface, accountId: string): Promise<unknown | null>;
43
+ getSetupSchema(surface: ChannelSurface, accountId?: string): Promise<unknown | null>;
44
+ doctor(surface: ChannelSurface, accountId?: string): Promise<unknown | null>;
45
+ listRepairActions(surface: ChannelSurface, accountId?: string): Promise<readonly unknown[]>;
46
+ getLifecycleState(surface: ChannelSurface, accountId?: string): Promise<unknown | null>;
47
+ migrateLifecycle(surface: ChannelSurface, accountId?: string, input?: JsonRecord | null): Promise<unknown | null>;
48
+ runAccountAction(surface: ChannelSurface, action: ChannelLifecycleAction, accountId: string | undefined, input?: JsonRecord): Promise<unknown | null>;
49
+ listCapabilities(surface?: ChannelSurface): Promise<readonly unknown[]>;
50
+ listTools(surface?: ChannelSurface): Promise<readonly unknown[]>;
51
+ listAgentTools(surface?: ChannelSurface): readonly ChannelAgentToolDefinitionLike[];
52
+ runTool(surface: ChannelSurface, toolId: string, input?: JsonRecord): Promise<unknown | null>;
53
+ listOperatorActions(surface?: ChannelSurface): Promise<readonly unknown[]>;
54
+ runOperatorAction(surface: ChannelSurface, actionId: string, input?: JsonRecord): Promise<unknown | null>;
55
+ resolveTarget(surface: ChannelSurface, input: ChannelTargetResolutionInput): Promise<unknown | null>;
56
+ authorizeActorAction(surface: ChannelSurface, input: ChannelAuthorizeActionInput): Promise<unknown | null>;
57
+ resolveAllowlist(surface: ChannelSurface, input: ChannelAllowlistInput): Promise<unknown | null>;
58
+ editAllowlist(surface: ChannelSurface, input: ChannelAllowlistInput): Promise<unknown | null>;
59
+ listStatus(): Promise<readonly unknown[]>;
60
+ queryDirectory(surface: ChannelSurface, query: ChannelDirectoryQuery): Promise<readonly unknown[]>;
61
+ }
62
+ export interface ChannelPolicyServiceLike {
63
+ listPolicies(): readonly unknown[];
64
+ upsertPolicy(surface: ChannelSurface, input: Record<string, unknown>): Promise<unknown>;
65
+ listAudit(limit: number): readonly unknown[];
66
+ }
67
+ export interface SurfaceRegistryLike {
68
+ list(): readonly unknown[];
69
+ }
70
+ export interface DaemonChannelRouteContext {
71
+ readonly channelPlugins: ChannelPluginServiceLike;
72
+ readonly channelPolicy: ChannelPolicyServiceLike;
73
+ readonly parseJsonBody: (req: Request) => Promise<JsonRecord | Response>;
74
+ readonly parseOptionalJsonBody: (req: Request) => Promise<JsonRecord | null | Response>;
75
+ readonly requireAdmin: (req: Request) => Response | null;
76
+ readonly surfaceRegistry: SurfaceRegistryLike;
77
+ }
78
+ //# sourceMappingURL=channel-route-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel-route-types.d.ts","sourceRoot":"","sources":["../src/channel-route-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEtG,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAE3C,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,CAAC,EAAE,uBAAuB,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAA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IAAI,SAAS,OAAO,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,cAAc,EAAE,wBAAwB,CAAC;IAClD,QAAQ,CAAC,aAAa,EAAE,wBAAwB,CAAC;IACjD,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAC;IACzE,QAAQ,CAAC,qBAAqB,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC;IACxF,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,CAAC;IACzD,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC;CAC/C"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { DaemonApiRouteHandlers } from './context.js';
2
+ import type { DaemonChannelRouteContext } from './channel-route-types.js';
3
+ export declare function createDaemonChannelRouteHandlers(context: DaemonChannelRouteContext): Pick<DaemonApiRouteHandlers, 'getSurfaces' | 'getChannelAccounts' | 'getChannelSurfaceAccounts' | 'getChannelAccount' | 'getChannelSetupSchema' | 'getChannelDoctor' | 'getChannelRepairActions' | 'getChannelLifecycle' | 'postChannelLifecycleMigrate' | 'postChannelAccountAction' | 'getChannelCapabilities' | 'getChannelSurfaceCapabilities' | 'getChannelTools' | 'getChannelSurfaceTools' | 'getChannelAgentTools' | 'getChannelSurfaceAgentTools' | 'postChannelTool' | 'getChannelActions' | 'getChannelSurfaceActions' | 'postChannelAction' | 'postChannelResolveTarget' | 'postChannelAuthorize' | 'postChannelAllowlistResolve' | 'postChannelAllowlistEdit' | 'getChannelPolicies' | 'postChannelPolicy' | 'getChannelPolicyAudit' | 'getChannelStatus' | 'getChannelDirectory'>;
4
+ //# sourceMappingURL=channel-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel-routes.d.ts","sourceRoot":"","sources":["../src/channel-routes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,KAAK,EAAyC,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAEjH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,yBAAyB,GACjC,IAAI,CACL,sBAAsB,EACpB,aAAa,GACb,oBAAoB,GACpB,2BAA2B,GAC3B,mBAAmB,GACnB,uBAAuB,GACvB,kBAAkB,GAClB,yBAAyB,GACzB,qBAAqB,GACrB,6BAA6B,GAC7B,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,GAC/B,iBAAiB,GACjB,wBAAwB,GACxB,sBAAsB,GACtB,6BAA6B,GAC7B,iBAAiB,GACjB,mBAAmB,GACnB,0BAA0B,GAC1B,mBAAmB,GACnB,0BAA0B,GAC1B,sBAAsB,GACtB,6BAA6B,GAC7B,0BAA0B,GAC1B,oBAAoB,GACpB,mBAAmB,GACnB,uBAAuB,GACvB,kBAAkB,GAClB,qBAAqB,CACxB,CAySA"}
@@ -0,0 +1,264 @@
1
+ import { readChannelConversationKind, readChannelLifecycleAction } from './route-helpers.js';
2
+ export function createDaemonChannelRouteHandlers(context) {
3
+ return {
4
+ getSurfaces: () => Response.json({ surfaces: context.surfaceRegistry.list() }),
5
+ getChannelAccounts: () => context.channelPlugins.listAccounts().then((accounts) => Response.json({ accounts })),
6
+ getChannelSurfaceAccounts: (surface) => context.channelPlugins
7
+ .listAccounts(surface)
8
+ .then((accounts) => Response.json({ accounts })),
9
+ getChannelAccount: async (surface, accountId) => {
10
+ const account = await context.channelPlugins.getAccount(surface, accountId);
11
+ return account
12
+ ? Response.json(account)
13
+ : Response.json({ error: 'Unknown channel account' }, { status: 404 });
14
+ },
15
+ getChannelSetupSchema: async (surface, url) => {
16
+ const schema = await context.channelPlugins.getSetupSchema(surface, url.searchParams.get('accountId') ?? undefined);
17
+ return schema
18
+ ? Response.json(schema)
19
+ : Response.json({ error: 'Unknown channel setup schema' }, { status: 404 });
20
+ },
21
+ getChannelDoctor: async (surface, url) => {
22
+ const report = await context.channelPlugins.doctor(surface, url.searchParams.get('accountId') ?? undefined);
23
+ return report
24
+ ? Response.json(report)
25
+ : Response.json({ error: 'Unknown channel doctor surface' }, { status: 404 });
26
+ },
27
+ getChannelRepairActions: async (surface, url) => Response.json({
28
+ actions: await context.channelPlugins.listRepairActions(surface, url.searchParams.get('accountId') ?? undefined),
29
+ }),
30
+ getChannelLifecycle: async (surface, url) => {
31
+ const state = await context.channelPlugins.getLifecycleState(surface, url.searchParams.get('accountId') ?? undefined);
32
+ return state
33
+ ? Response.json(state)
34
+ : Response.json({ error: 'Unknown channel lifecycle surface' }, { status: 404 });
35
+ },
36
+ postChannelLifecycleMigrate: async (surface, req) => {
37
+ const admin = context.requireAdmin(req);
38
+ if (admin)
39
+ return admin;
40
+ const body = await context.parseOptionalJsonBody(req);
41
+ if (body instanceof Response)
42
+ return body;
43
+ const state = await context.channelPlugins.migrateLifecycle(surface, typeof body?.accountId === 'string' ? body.accountId : undefined, body ?? undefined);
44
+ return state
45
+ ? Response.json(state)
46
+ : Response.json({ error: 'Unknown channel lifecycle surface' }, { status: 404 });
47
+ },
48
+ postChannelAccountAction: async (surface, accountId, action, req) => {
49
+ const admin = context.requireAdmin(req);
50
+ if (admin)
51
+ return admin;
52
+ const body = await context.parseJsonBody(req);
53
+ const input = body instanceof Response ? undefined : body;
54
+ if (body instanceof Response && req.headers.get('content-length') && req.headers.get('content-length') !== '0') {
55
+ return body;
56
+ }
57
+ const lifecycleAction = readChannelLifecycleAction(action);
58
+ if (!lifecycleAction) {
59
+ return Response.json({ error: 'Unknown channel account action' }, { status: 400 });
60
+ }
61
+ const result = await context.channelPlugins.runAccountAction(surface, lifecycleAction, accountId ?? (typeof input?.accountId === 'string' ? input.accountId : undefined), input);
62
+ return result !== null
63
+ ? Response.json({ surface, accountId, action: lifecycleAction, result })
64
+ : Response.json({ error: 'Unknown channel account action' }, { status: 404 });
65
+ },
66
+ getChannelCapabilities: () => context.channelPlugins.listCapabilities().then((capabilities) => Response.json({ capabilities })),
67
+ getChannelSurfaceCapabilities: (surface) => context.channelPlugins
68
+ .listCapabilities(surface)
69
+ .then((capabilities) => Response.json({ capabilities })),
70
+ getChannelTools: () => context.channelPlugins.listTools().then((tools) => Response.json({ tools })),
71
+ getChannelSurfaceTools: (surface) => context.channelPlugins
72
+ .listTools(surface)
73
+ .then((tools) => Response.json({ tools })),
74
+ getChannelAgentTools: () => Response.json({ tools: context.channelPlugins.listAgentTools().map((tool) => tool.definition) }),
75
+ getChannelSurfaceAgentTools: (surface) => Response.json({
76
+ tools: context.channelPlugins
77
+ .listAgentTools(surface)
78
+ .map((tool) => tool.definition),
79
+ }),
80
+ postChannelTool: async (surface, toolId, req) => {
81
+ const admin = context.requireAdmin(req);
82
+ if (admin)
83
+ return admin;
84
+ const body = await context.parseJsonBody(req);
85
+ const input = body instanceof Response ? undefined : body;
86
+ if (body instanceof Response && req.headers.get('content-length') && req.headers.get('content-length') !== '0') {
87
+ return body;
88
+ }
89
+ const result = await context.channelPlugins.runTool(surface, toolId, input);
90
+ return result !== null
91
+ ? Response.json({ toolId, surface, result })
92
+ : Response.json({ error: 'Unknown channel tool' }, { status: 404 });
93
+ },
94
+ getChannelActions: () => context.channelPlugins.listOperatorActions().then((actions) => Response.json({ actions })),
95
+ getChannelSurfaceActions: (surface) => context.channelPlugins
96
+ .listOperatorActions(surface)
97
+ .then((actions) => Response.json({ actions })),
98
+ postChannelAction: async (surface, actionId, req) => {
99
+ const admin = context.requireAdmin(req);
100
+ if (admin)
101
+ return admin;
102
+ const body = await context.parseJsonBody(req);
103
+ const input = body instanceof Response ? undefined : body;
104
+ if (body instanceof Response && req.headers.get('content-length') && req.headers.get('content-length') !== '0') {
105
+ return body;
106
+ }
107
+ const result = await context.channelPlugins.runOperatorAction(surface, actionId, input);
108
+ return result !== null
109
+ ? Response.json({ actionId, surface, result })
110
+ : Response.json({ error: 'Unknown channel action' }, { status: 404 });
111
+ },
112
+ postChannelResolveTarget: async (surface, req) => {
113
+ const admin = context.requireAdmin(req);
114
+ if (admin)
115
+ return admin;
116
+ const body = await context.parseJsonBody(req);
117
+ if (body instanceof Response)
118
+ return body;
119
+ const targetInput = typeof body.target === 'string'
120
+ ? body.target
121
+ : typeof body.input === 'string'
122
+ ? body.input
123
+ : typeof body.query === 'string'
124
+ ? body.query
125
+ : '';
126
+ if (!targetInput.trim()) {
127
+ return Response.json({ error: 'Target resolution requires target, input, or query.' }, { status: 400 });
128
+ }
129
+ const preferredKind = readChannelConversationKind(body.preferredKind);
130
+ const target = await context.channelPlugins.resolveTarget(surface, {
131
+ input: targetInput,
132
+ ...(typeof body.accountId === 'string' ? { accountId: body.accountId } : {}),
133
+ ...(preferredKind ? { preferredKind } : {}),
134
+ ...(typeof body.threadId === 'string' ? { threadId: body.threadId } : {}),
135
+ ...(typeof body.sessionId === 'string' ? { sessionId: body.sessionId } : {}),
136
+ ...(typeof body.createIfMissing === 'boolean' ? { createIfMissing: body.createIfMissing } : {}),
137
+ ...(typeof body.live === 'boolean' ? { live: body.live } : {}),
138
+ ...(typeof body.metadata === 'object' && body.metadata !== null ? { metadata: body.metadata } : {}),
139
+ });
140
+ return target
141
+ ? Response.json({ surface, target })
142
+ : Response.json({ error: 'Unable to resolve channel target' }, { status: 404 });
143
+ },
144
+ postChannelAuthorize: async (surface, req) => {
145
+ const admin = context.requireAdmin(req);
146
+ if (admin)
147
+ return admin;
148
+ const body = await context.parseJsonBody(req);
149
+ if (body instanceof Response)
150
+ return body;
151
+ const target = typeof body.target === 'string' && body.target.trim()
152
+ ? await context.channelPlugins.resolveTarget(surface, {
153
+ input: body.target,
154
+ ...(typeof body.accountId === 'string' ? { accountId: body.accountId } : {}),
155
+ createIfMissing: true,
156
+ })
157
+ : null;
158
+ const result = await context.channelPlugins.authorizeActorAction(surface, {
159
+ actionId: typeof body.actionId === 'string' ? body.actionId : 'unknown',
160
+ ...(typeof body.actorId === 'string' ? { actorId: body.actorId } : {}),
161
+ ...(typeof body.accountId === 'string' ? { accountId: body.accountId } : {}),
162
+ ...(target ? { target } : {}),
163
+ ...(typeof body.metadata === 'object' && body.metadata !== null ? { metadata: body.metadata } : {}),
164
+ });
165
+ return result
166
+ ? Response.json({ surface, result })
167
+ : Response.json({ error: 'Unable to authorize channel action' }, { status: 404 });
168
+ },
169
+ postChannelAllowlistResolve: async (surface, req) => {
170
+ const admin = context.requireAdmin(req);
171
+ if (admin)
172
+ return admin;
173
+ const body = await context.parseJsonBody(req);
174
+ if (body instanceof Response)
175
+ return body;
176
+ const result = await context.channelPlugins.resolveAllowlist(surface, {
177
+ ...(Array.isArray(body.add) ? { add: body.add.filter((value) => typeof value === 'string') } : {}),
178
+ ...(Array.isArray(body.remove) ? { remove: body.remove.filter((value) => typeof value === 'string') } : {}),
179
+ ...(typeof body.groupId === 'string' ? { groupId: body.groupId } : {}),
180
+ ...(typeof body.channelId === 'string' ? { channelId: body.channelId } : {}),
181
+ ...(typeof body.workspaceId === 'string' ? { workspaceId: body.workspaceId } : {}),
182
+ ...(body.kind === 'user' || body.kind === 'channel' || body.kind === 'group' ? { kind: body.kind } : {}),
183
+ ...(typeof body.metadata === 'object' && body.metadata !== null ? { metadata: body.metadata } : {}),
184
+ });
185
+ return result
186
+ ? Response.json(result)
187
+ : Response.json({ error: 'Unknown channel allowlist surface' }, { status: 404 });
188
+ },
189
+ postChannelAllowlistEdit: async (surface, req) => {
190
+ const admin = context.requireAdmin(req);
191
+ if (admin)
192
+ return admin;
193
+ const body = await context.parseJsonBody(req);
194
+ if (body instanceof Response)
195
+ return body;
196
+ const result = await context.channelPlugins.editAllowlist(surface, {
197
+ ...(Array.isArray(body.add) ? { add: body.add.filter((value) => typeof value === 'string') } : {}),
198
+ ...(Array.isArray(body.remove) ? { remove: body.remove.filter((value) => typeof value === 'string') } : {}),
199
+ ...(typeof body.groupId === 'string' ? { groupId: body.groupId } : {}),
200
+ ...(typeof body.channelId === 'string' ? { channelId: body.channelId } : {}),
201
+ ...(typeof body.workspaceId === 'string' ? { workspaceId: body.workspaceId } : {}),
202
+ ...(body.kind === 'user' || body.kind === 'channel' || body.kind === 'group' ? { kind: body.kind } : {}),
203
+ ...(typeof body.metadata === 'object' && body.metadata !== null ? { metadata: body.metadata } : {}),
204
+ });
205
+ return result
206
+ ? Response.json(result)
207
+ : Response.json({ error: 'Unknown channel allowlist surface' }, { status: 404 });
208
+ },
209
+ getChannelPolicies: () => Response.json({ policies: context.channelPolicy.listPolicies() }),
210
+ postChannelPolicy: async (surface, req) => {
211
+ const admin = context.requireAdmin(req);
212
+ if (admin)
213
+ return admin;
214
+ const body = await context.parseJsonBody(req);
215
+ if (body instanceof Response)
216
+ return body;
217
+ const updated = await context.channelPolicy.upsertPolicy(surface, {
218
+ ...(body.enabled !== undefined ? { enabled: Boolean(body.enabled) } : {}),
219
+ ...(body.requireMention !== undefined ? { requireMention: Boolean(body.requireMention) } : {}),
220
+ ...(body.allowDirectMessages !== undefined ? { allowDirectMessages: Boolean(body.allowDirectMessages) } : {}),
221
+ ...(body.allowGroupMessages !== undefined ? { allowGroupMessages: Boolean(body.allowGroupMessages) } : {}),
222
+ ...(body.allowThreadMessages !== undefined ? { allowThreadMessages: Boolean(body.allowThreadMessages) } : {}),
223
+ ...(body.dmPolicy === 'allow' || body.dmPolicy === 'deny' || body.dmPolicy === 'inherit' ? { dmPolicy: body.dmPolicy } : {}),
224
+ ...(body.groupPolicy === 'allow' || body.groupPolicy === 'deny' || body.groupPolicy === 'inherit' ? { groupPolicy: body.groupPolicy } : {}),
225
+ ...(body.allowTextCommandsWithoutMention !== undefined ? { allowTextCommandsWithoutMention: Boolean(body.allowTextCommandsWithoutMention) } : {}),
226
+ ...(Array.isArray(body.allowlistUserIds) ? { allowlistUserIds: body.allowlistUserIds.filter((value) => typeof value === 'string') } : {}),
227
+ ...(Array.isArray(body.allowlistChannelIds) ? { allowlistChannelIds: body.allowlistChannelIds.filter((value) => typeof value === 'string') } : {}),
228
+ ...(Array.isArray(body.allowlistGroupIds) ? { allowlistGroupIds: body.allowlistGroupIds.filter((value) => typeof value === 'string') } : {}),
229
+ ...(Array.isArray(body.allowedCommands) ? { allowedCommands: body.allowedCommands.filter((value) => typeof value === 'string') } : {}),
230
+ ...(Array.isArray(body.groupPolicies) ? {
231
+ groupPolicies: body.groupPolicies
232
+ .filter((value) => typeof value === 'object' && value !== null)
233
+ .map((value) => ({
234
+ id: typeof value.id === 'string' ? value.id : `group-policy-${Math.random().toString(36).slice(2, 8)}`,
235
+ ...(typeof value.label === 'string' ? { label: value.label } : {}),
236
+ ...(typeof value.groupId === 'string' ? { groupId: value.groupId } : {}),
237
+ ...(typeof value.channelId === 'string' ? { channelId: value.channelId } : {}),
238
+ ...(typeof value.workspaceId === 'string' ? { workspaceId: value.workspaceId } : {}),
239
+ ...(value.requireMention !== undefined ? { requireMention: Boolean(value.requireMention) } : {}),
240
+ ...(value.allowGroupMessages !== undefined ? { allowGroupMessages: Boolean(value.allowGroupMessages) } : {}),
241
+ ...(value.allowThreadMessages !== undefined ? { allowThreadMessages: Boolean(value.allowThreadMessages) } : {}),
242
+ ...(value.allowTextCommandsWithoutMention !== undefined ? { allowTextCommandsWithoutMention: Boolean(value.allowTextCommandsWithoutMention) } : {}),
243
+ ...(Array.isArray(value.allowlistUserIds) ? { allowlistUserIds: value.allowlistUserIds.filter((entry) => typeof entry === 'string') } : {}),
244
+ ...(Array.isArray(value.allowlistChannelIds) ? { allowlistChannelIds: value.allowlistChannelIds.filter((entry) => typeof entry === 'string') } : {}),
245
+ ...(Array.isArray(value.allowlistGroupIds) ? { allowlistGroupIds: value.allowlistGroupIds.filter((entry) => typeof entry === 'string') } : {}),
246
+ ...(Array.isArray(value.allowedCommands) ? { allowedCommands: value.allowedCommands.filter((entry) => typeof entry === 'string') } : {}),
247
+ ...(typeof value.metadata === 'object' && value.metadata !== null ? { metadata: value.metadata } : {}),
248
+ })),
249
+ } : {}),
250
+ ...(typeof body.metadata === 'object' && body.metadata !== null ? { metadata: body.metadata } : {}),
251
+ });
252
+ return Response.json(updated);
253
+ },
254
+ getChannelPolicyAudit: (limit) => Response.json({ audit: context.channelPolicy.listAudit(limit) }),
255
+ getChannelStatus: () => context.channelPlugins.listStatus().then((channels) => Response.json({ channels })),
256
+ getChannelDirectory: (surface, url) => context.channelPlugins.queryDirectory(surface, {
257
+ query: url.searchParams.get('q') ?? '',
258
+ ...(url.searchParams.get('scope') ? { scope: url.searchParams.get('scope') } : {}),
259
+ ...(url.searchParams.get('groupId') ? { groupId: url.searchParams.get('groupId') } : {}),
260
+ ...(url.searchParams.get('limit') ? { limit: Number(url.searchParams.get('limit')) } : {}),
261
+ ...(url.searchParams.get('live') ? { live: url.searchParams.get('live') === 'true' } : {}),
262
+ }).then((entries) => Response.json({ entries })),
263
+ };
264
+ }