@ekanos/harness 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -990,6 +990,10 @@ triggerMocks: {
990
990
  respond: () => Response.json({ payments: [], totalCount: 0 }),
991
991
  },
992
992
  ],
993
+ // Optional: run on a Source connection, scoped to the values routed to the
994
+ // team (plan 241). `routing` needs `connection: { owner: 'source' }`.
995
+ connection: { owner: 'source' },
996
+ routing: { key: 'organization', values: ['360001234567'] },
993
997
  },
994
998
  ```
995
999
 
@@ -1,7 +1,32 @@
1
1
  import {
2
2
  MAX_AGENT_EVENT_DEDUPE_KEY_LENGTH,
3
- MAX_RAISED_AGENT_EVENTS
3
+ MAX_RAISED_AGENT_EVENTS,
4
+ MAX_ROUTE_VALUE_LENGTH
4
5
  } from "@ekanos/sdk/integration";
6
+ function checkRoutes(declaration, payload) {
7
+ return Object.entries(declaration.routeKeys ?? {}).map(([key, routeKey]) => {
8
+ let result;
9
+ try {
10
+ result = routeKey(payload);
11
+ } catch (error) {
12
+ return {
13
+ key,
14
+ value: null,
15
+ problem: `routeKeys.${key} threw: ${error instanceof Error ? error.message : String(error)} \u2014 the host leaves the event unrouted.`
16
+ };
17
+ }
18
+ if (result === null) return { key, value: null };
19
+ const route = result;
20
+ if (typeof route === "object" && typeof route.value === "string" && route.value.length > 0 && route.value.length <= MAX_ROUTE_VALUE_LENGTH && (route.label === void 0 || typeof route.label === "string")) {
21
+ return route.label === void 0 ? { key, value: route.value } : { key, value: route.value, label: route.label };
22
+ }
23
+ return {
24
+ key,
25
+ value: null,
26
+ problem: `routeKeys.${key} must return { value, label? } with a non-empty value of at most ${MAX_ROUTE_VALUE_LENGTH} characters, or null \u2014 the host leaves the event unrouted.`
27
+ };
28
+ });
29
+ }
5
30
  async function checkRaisedAgentEvents(definition, raised) {
6
31
  if (raised === void 0) return void 0;
7
32
  if (!Array.isArray(raised)) {
@@ -63,10 +88,12 @@ async function checkRaisedAgentEvents(definition, raised) {
63
88
  };
64
89
  }
65
90
  const conversation = declaration.conversation?.(validated.value) ?? null;
91
+ const routes = checkRoutes(declaration, validated.value);
66
92
  return {
67
93
  ...base,
68
94
  payload: validated.value,
69
- ...conversation ? { conversation } : {}
95
+ ...conversation ? { conversation } : {},
96
+ ...routes.length > 0 ? { routes } : {}
70
97
  };
71
98
  } catch (error) {
72
99
  return {
@@ -22,6 +22,8 @@ function useDefinitionMockContext(integration, variant) {
22
22
  storage: mocks.storage
23
23
  } : {},
24
24
  ...mocks.secrets ? { secrets: mocks.secrets } : {},
25
+ ...mocks.connection ? { connection: mocks.connection } : {},
26
+ ...mocks.routing ? { routing: mocks.routing } : {},
25
27
  fetchHandlers: [
26
28
  ...mocks.fetchHandlers ?? [],
27
29
  ...fixturesToMockHandlers(
@@ -32,6 +32,20 @@ export interface RaisedAgentEventCheck {
32
32
  key: string;
33
33
  target: Record<string, unknown>;
34
34
  };
35
+ /**
36
+ * The event's value per routing key, when it declares `routeKeys` (plan
37
+ * 241). Used only on a Source connection's endpoint: the host routes the
38
+ * event to the team mapped to the value, and a `null` value leaves it
39
+ * unrouted.
40
+ */
41
+ routes?: RaisedAgentEventRoute[];
42
+ problem?: string;
43
+ }
44
+ export interface RaisedAgentEventRoute {
45
+ key: string;
46
+ value: string | null;
47
+ label?: string;
48
+ /** Why the host would read no value here (a throw, a malformed result). */
35
49
  problem?: string;
36
50
  }
37
51
  /** The outcome of one webhook delivery or schedule run. */
@@ -81,6 +81,29 @@ function RaisedAgentEvents({ events }) {
81
81
  "A run it starts answers in ",
82
82
  /* @__PURE__ */ jsx("code", { children: event.conversation.key })
83
83
  ] }) : null,
84
+ event.routes?.map((route) => /* @__PURE__ */ jsxs(
85
+ "p",
86
+ {
87
+ className: route.problem ? "text-destructive text-fine" : "text-muted-foreground text-fine",
88
+ "data-test": `raised-agent-event-route-${route.key}`,
89
+ children: [
90
+ route.value === null ? /* @__PURE__ */ jsxs(Fragment, { children: [
91
+ "On a Source connection: no ",
92
+ /* @__PURE__ */ jsx("code", { children: route.key }),
93
+ " value, so it stays unrouted."
94
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
95
+ "On a Source connection: routes by ",
96
+ /* @__PURE__ */ jsx("code", { children: route.key }),
97
+ " to the team mapped to ",
98
+ /* @__PURE__ */ jsx("code", { children: route.value }),
99
+ route.label ? ` (${route.label})` : "",
100
+ "."
101
+ ] }),
102
+ route.problem ? ` ${route.problem}` : null
103
+ ]
104
+ },
105
+ route.key
106
+ )),
84
107
  /* @__PURE__ */ jsx("pre", { className: "bg-muted text-fine max-h-40 overflow-auto rounded-md p-2", children: JSON.stringify(event.payload, null, 2) })
85
108
  ]
86
109
  },
@@ -106,13 +129,31 @@ function AgentEventsCard({
106
129
  channel ? /* @__PURE__ */ jsxs(Badge, { variant: "secondary", children: [
107
130
  "replies with ",
108
131
  /* @__PURE__ */ jsx("code", { children: channel.replyTool.name })
109
- ] }) : /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: "no channel \u2014 runs answer in Ekanos" })
132
+ ] }) : /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: "no channel \u2014 runs answer in Ekanos" }),
133
+ definition.sourceConnection ? /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: "Source connection" }) : null
110
134
  ] }),
111
135
  /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-meta", children: [
112
136
  "A team picks one of these as an agent trigger and fills in its filter. Your webhooks raise them through ",
113
137
  /* @__PURE__ */ jsx("code", { children: "WebhookResult.events" }),
114
138
  "; deliver a webhook above to see what it raises."
115
139
  ] }),
140
+ definition.routing ? /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground text-meta", children: [
141
+ "On a Source connection, events are routed to a team by",
142
+ " ",
143
+ definition.routing.keys.map((key, index) => /* @__PURE__ */ jsxs("span", { children: [
144
+ index > 0 ? " or " : "",
145
+ /* @__PURE__ */ jsx("code", { children: key.id }),
146
+ " (",
147
+ key.label,
148
+ ")"
149
+ ] }, key.id)),
150
+ ". Set ",
151
+ /* @__PURE__ */ jsx("code", { children: "triggerMocks.connection" }),
152
+ " and",
153
+ " ",
154
+ /* @__PURE__ */ jsx("code", { children: "triggerMocks.routing" }),
155
+ " to run these handlers the way a provided agent does."
156
+ ] }) : null,
116
157
  events.map((event) => /* @__PURE__ */ jsxs(
117
158
  "div",
118
159
  {
@@ -122,7 +163,11 @@ function AgentEventsCard({
122
163
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
123
164
  /* @__PURE__ */ jsx("span", { className: "font-medium", children: event.label }),
124
165
  /* @__PURE__ */ jsx("code", { className: "text-muted-foreground text-fine", children: event.id }),
125
- event.conversation ? /* @__PURE__ */ jsx(Badge, { variant: "outline", children: "answers in place" }) : null
166
+ event.conversation ? /* @__PURE__ */ jsx(Badge, { variant: "outline", children: "answers in place" }) : null,
167
+ Object.keys(event.routeKeys ?? {}).map((key) => /* @__PURE__ */ jsxs(Badge, { variant: "outline", children: [
168
+ "routes by ",
169
+ /* @__PURE__ */ jsx("code", { children: key })
170
+ ] }, key))
126
171
  ] }),
127
172
  /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-meta", children: event.description }),
128
173
  event.filter?.fields.length ? /* @__PURE__ */ jsx("ul", { className: "text-muted-foreground text-fine list-disc pl-5", children: event.filter.fields.map((field) => /* @__PURE__ */ jsxs("li", { children: [
@@ -32,6 +32,7 @@ function getLiveState(input) {
32
32
  );
33
33
  }
34
34
  const definition = input.definition;
35
+ const mocks = input.integration.triggerMocks;
35
36
  const ctx = createMockContext({
36
37
  accountId: HARNESS_ACCOUNT_ID,
37
38
  integration: { slug: definition.slug },
@@ -41,6 +42,8 @@ function getLiveState(input) {
41
42
  admin: input.adminSecrets,
42
43
  account: input.accountSecrets ?? {}
43
44
  },
45
+ ...mocks?.connection ? { connection: mocks.connection } : {},
46
+ ...mocks?.routing ? { routing: mocks.routing } : {},
44
47
  fetchHandlers: [
45
48
  ...input.integration.triggerMocks?.fetchHandlers ?? [],
46
49
  createNetworkPassthrough(input.networkFetch)
@@ -1,6 +1,5 @@
1
1
  import type { ComponentType, ReactNode } from 'react';
2
- import type { ActivationFormProps, IntegrationComponentProps, IntegrationFetch, MarketplaceTileProps } from '@ekanos/sdk';
3
- import type { StorageSchemas } from '@ekanos/sdk';
2
+ import type { ActivationFormProps, IntegrationComponentProps, IntegrationConnection, IntegrationFetch, IntegrationRouting, MarketplaceTileProps, StorageSchemas } from '@ekanos/sdk';
4
3
  import type { IntegrationDefinition } from '@ekanos/sdk/integration';
5
4
  import type { MockFetchHandler } from '@ekanos/sdk/testing';
6
5
  /**
@@ -314,6 +313,17 @@ export interface HarnessTriggerMocks {
314
313
  };
315
314
  /** Programmed responses for the handlers' `ctx.fetch` calls. */
316
315
  fetchHandlers?: MockFetchHandler[];
316
+ /**
317
+ * Run the Triggers and Activation handlers on a Source connection
318
+ * (`{ owner: 'source' }`) instead of the team's own (plan 241).
319
+ */
320
+ connection?: IntegrationConnection;
321
+ /**
322
+ * The routed values a Source connection's call may touch, e.g.
323
+ * `{ key: 'organization', values: ['360001'] }`. Needs
324
+ * `connection: { owner: 'source' }`.
325
+ */
326
+ routing?: IntegrationRouting;
317
327
  }
318
328
  /**
319
329
  * The harness-only half of a widget entry — everything
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/harness",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "private": false,
5
5
  "description": "The Ekanos integration dev harness — every surface of an integration rendered in real Ekanos chrome, from fixtures, with no Supabase or auth; and, in live mode, a real localhost OAuth loop over your own dev-app credentials.",
6
6
  "homepage": "https://sdk.ekanos.dev/harness/overview",
@@ -65,8 +65,8 @@
65
65
  "tw-animate-css": "1.4.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@ekanos/sdk": "0.14.0",
69
- "@ekanos/ui": "0.14.0",
68
+ "@ekanos/sdk": "0.15.1",
69
+ "@ekanos/ui": "0.15.1",
70
70
  "@kit/tsconfig": "0.1.0",
71
71
  "@tailwindcss/postcss": "4.3.3",
72
72
  "@tanstack/react-query": "5.103.2",
@@ -85,8 +85,8 @@
85
85
  "zod": "4.6.5"
86
86
  },
87
87
  "peerDependencies": {
88
- "@ekanos/sdk": "^0.14.0",
89
- "@ekanos/ui": "^0.14.0",
88
+ "@ekanos/sdk": "^0.15.1",
89
+ "@ekanos/ui": "^0.15.1",
90
90
  "@tanstack/react-query": "^5.101.4",
91
91
  "next": "^16.0.0",
92
92
  "next-intl": "^4.14.7",