@ekanos/sdk 0.1.1 → 0.1.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 (53) hide show
  1. package/README.md +1093 -140
  2. package/api-report.md +202 -0
  3. package/dist/components/index.d.ts +3 -2
  4. package/dist/components/index.js +3 -2
  5. package/dist/components/index.js.map +1 -1
  6. package/dist/components/widgets/widget-context.js.map +1 -1
  7. package/dist/context/index.d.ts +1 -1
  8. package/dist/context/index.js +1 -1
  9. package/dist/context/index.js.map +1 -1
  10. package/dist/context/types.d.ts +1 -1
  11. package/dist/context/types.js.map +1 -1
  12. package/dist/hooks/activation-actions-context.d.ts +4 -4
  13. package/dist/hooks/activation-actions-context.js +1 -1
  14. package/dist/hooks/activation-actions-context.js.map +1 -1
  15. package/dist/hooks/index.d.ts +2 -2
  16. package/dist/hooks/index.js +2 -2
  17. package/dist/hooks/index.js.map +1 -1
  18. package/dist/hooks/use-oauth-connection-status.d.ts +18 -72
  19. package/dist/hooks/use-oauth-connection-status.js +1 -1
  20. package/dist/hooks/use-oauth-connection-status.js.map +1 -1
  21. package/dist/index.d.ts +3 -2
  22. package/dist/index.js +3 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/integration/define-integration.d.ts +2 -3
  25. package/dist/integration/define-integration.js +2 -3
  26. package/dist/integration/define-integration.js.map +1 -1
  27. package/dist/integration/index.d.ts +2 -2
  28. package/dist/integration/index.js +2 -2
  29. package/dist/integration/index.js.map +1 -1
  30. package/dist/testing/index.d.ts +1 -1
  31. package/dist/testing/index.js +1 -1
  32. package/dist/testing/index.js.map +1 -1
  33. package/dist/types/index.d.ts +3 -4
  34. package/dist/types/index.js +3 -4
  35. package/dist/types/index.js.map +1 -1
  36. package/dist/types/integration.d.ts +2 -2
  37. package/dist/types/integration.js.map +1 -1
  38. package/dist/types/widget-ask-context.d.ts +1 -1
  39. package/dist/types/widget-ask-context.js.map +1 -1
  40. package/eslint.preset.mjs +373 -0
  41. package/package.json +18 -18
  42. package/dist/mcp/guards.d.ts +0 -40
  43. package/dist/mcp/guards.js +0 -99
  44. package/dist/mcp/guards.js.map +0 -1
  45. package/dist/mcp/index.d.ts +0 -22
  46. package/dist/mcp/index.js +0 -22
  47. package/dist/mcp/index.js.map +0 -1
  48. package/dist/mcp/ownership.d.ts +0 -74
  49. package/dist/mcp/ownership.js +0 -83
  50. package/dist/mcp/ownership.js.map +0 -1
  51. package/dist/mcp/types.d.ts +0 -145
  52. package/dist/mcp/types.js +0 -2
  53. package/dist/mcp/types.js.map +0 -1
@@ -1,74 +0,0 @@
1
- /**
2
- * Ownership guards for member-facing MCP tools.
3
- *
4
- * The LLM controls tool arguments. Any member-facing tool that accepts an
5
- * external per-user identifier (a Wild Apricot contactId, a Discourse
6
- * username, a LearnWorlds learner id, etc.) is a cross-member data-exposure
7
- * risk: the caller can pass *someone else's* id and read or act on their
8
- * data. The org-membership gate (`ensureAccountMembership`) does not catch
9
- * this — it answers "is this person in the org?", never "is this person's
10
- * own data?".
11
- *
12
- * These helpers make the safe path the default. A tool author reaches for
13
- * `resolveSelfOnly` instead of writing a bespoke "default to me" resolver,
14
- * and gets ownership enforcement for free.
15
- *
16
- * Resolving "who am I" is integration-specific (each integration maps the
17
- * Supabase user to its own id space), so the caller supplies `resolveSelf`.
18
- */
19
- /**
20
- * Thrown when a tool caller attempts to access or act on another user's
21
- * data. Tool `run` bodies should let this propagate (or convert it to a
22
- * `{ error }` result) — the assistant surfaces a "not permitted" message
23
- * rather than the forbidden data.
24
- */
25
- export declare class ToolOwnershipError extends Error {
26
- readonly code = "FORBIDDEN_OWNERSHIP";
27
- constructor(resourceLabel?: string);
28
- }
29
- /**
30
- * Self-only identity resolution for member-facing tools.
31
- *
32
- * - caller supplied no id → returns the caller's own id
33
- * - caller supplied their own id → returns it
34
- * - caller supplied a different id → throws ToolOwnershipError
35
- *
36
- * @example
37
- * // In a Wild Apricot read tool:
38
- * const contactId = await resolveSelfOnly({
39
- * requestedId: args.contactId,
40
- * resolveSelf: () => resolveWaContactId(accountId),
41
- * resourceLabel: 'member data',
42
- * });
43
- */
44
- export declare function resolveSelfOnly<TId extends string | number>(params: {
45
- /** The identifier the LLM supplied as a tool argument, if any. */
46
- requestedId?: TId | null;
47
- /** Integration-specific resolver for the calling user's own id. */
48
- resolveSelf: () => Promise<TId>;
49
- /** Human-readable noun for the error message, e.g. 'member profile'. */
50
- resourceLabel?: string;
51
- }): Promise<TId>;
52
- /**
53
- * Ownership verification for tools that act on an opaque resource id (an
54
- * event registration, a saved document, an invoice) where ownership cannot
55
- * be inferred from the id itself. Resolves the resource's owner and the
56
- * caller's own id and throws if they differ (or if the resource has no
57
- * resolvable owner — fail closed).
58
- *
59
- * @example
60
- * // In a Wild Apricot cancel tool:
61
- * await assertResourceOwnership({
62
- * resolveSelf: () => resolveWaContactId(accountId),
63
- * resolveOwner: async () => {
64
- * const regs = await getContactRegistrations(accountId, await resolveWaContactId(accountId));
65
- * return regs.find((r) => r.Id === registrationId)?.Contact.Id;
66
- * },
67
- * resourceLabel: 'event registration',
68
- * });
69
- */
70
- export declare function assertResourceOwnership<TId extends string | number>(params: {
71
- resolveSelf: () => Promise<TId>;
72
- resolveOwner: () => Promise<TId | null | undefined>;
73
- resourceLabel?: string;
74
- }): Promise<void>;
@@ -1,83 +0,0 @@
1
- /**
2
- * Ownership guards for member-facing MCP tools.
3
- *
4
- * The LLM controls tool arguments. Any member-facing tool that accepts an
5
- * external per-user identifier (a Wild Apricot contactId, a Discourse
6
- * username, a LearnWorlds learner id, etc.) is a cross-member data-exposure
7
- * risk: the caller can pass *someone else's* id and read or act on their
8
- * data. The org-membership gate (`ensureAccountMembership`) does not catch
9
- * this — it answers "is this person in the org?", never "is this person's
10
- * own data?".
11
- *
12
- * These helpers make the safe path the default. A tool author reaches for
13
- * `resolveSelfOnly` instead of writing a bespoke "default to me" resolver,
14
- * and gets ownership enforcement for free.
15
- *
16
- * Resolving "who am I" is integration-specific (each integration maps the
17
- * Supabase user to its own id space), so the caller supplies `resolveSelf`.
18
- */
19
- /**
20
- * Thrown when a tool caller attempts to access or act on another user's
21
- * data. Tool `run` bodies should let this propagate (or convert it to a
22
- * `{ error }` result) — the assistant surfaces a "not permitted" message
23
- * rather than the forbidden data.
24
- */
25
- export class ToolOwnershipError extends Error {
26
- constructor(resourceLabel = 'data') {
27
- super(`Forbidden: you can only access your own ${resourceLabel}.`);
28
- this.code = 'FORBIDDEN_OWNERSHIP';
29
- this.name = 'ToolOwnershipError';
30
- }
31
- }
32
- /**
33
- * Self-only identity resolution for member-facing tools.
34
- *
35
- * - caller supplied no id → returns the caller's own id
36
- * - caller supplied their own id → returns it
37
- * - caller supplied a different id → throws ToolOwnershipError
38
- *
39
- * @example
40
- * // In a Wild Apricot read tool:
41
- * const contactId = await resolveSelfOnly({
42
- * requestedId: args.contactId,
43
- * resolveSelf: () => resolveWaContactId(accountId),
44
- * resourceLabel: 'member data',
45
- * });
46
- */
47
- export async function resolveSelfOnly(params) {
48
- const selfId = await params.resolveSelf();
49
- if (params.requestedId !== undefined &&
50
- params.requestedId !== null &&
51
- params.requestedId !== selfId) {
52
- throw new ToolOwnershipError(params.resourceLabel);
53
- }
54
- return selfId;
55
- }
56
- /**
57
- * Ownership verification for tools that act on an opaque resource id (an
58
- * event registration, a saved document, an invoice) where ownership cannot
59
- * be inferred from the id itself. Resolves the resource's owner and the
60
- * caller's own id and throws if they differ (or if the resource has no
61
- * resolvable owner — fail closed).
62
- *
63
- * @example
64
- * // In a Wild Apricot cancel tool:
65
- * await assertResourceOwnership({
66
- * resolveSelf: () => resolveWaContactId(accountId),
67
- * resolveOwner: async () => {
68
- * const regs = await getContactRegistrations(accountId, await resolveWaContactId(accountId));
69
- * return regs.find((r) => r.Id === registrationId)?.Contact.Id;
70
- * },
71
- * resourceLabel: 'event registration',
72
- * });
73
- */
74
- export async function assertResourceOwnership(params) {
75
- const [selfId, ownerId] = await Promise.all([
76
- params.resolveSelf(),
77
- params.resolveOwner(),
78
- ]);
79
- if (ownerId === null || ownerId === undefined || ownerId !== selfId) {
80
- throw new ToolOwnershipError(params.resourceLabel);
81
- }
82
- }
83
- //# sourceMappingURL=ownership.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ownership.js","sourceRoot":"","sources":["../../src/mcp/ownership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;GAKG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAG3C,YAAY,aAAa,GAAG,MAAM;QAChC,KAAK,CAAC,2CAA2C,aAAa,GAAG,CAAC,CAAC;QAH5D,SAAI,GAAG,qBAAqB,CAAC;QAIpC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAA8B,MAOlE;IACC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;IAE1C,IACE,MAAM,CAAC,WAAW,KAAK,SAAS;QAChC,MAAM,CAAC,WAAW,KAAK,IAAI;QAC3B,MAAM,CAAC,WAAW,KAAK,MAAM,EAC7B,CAAC;QACD,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAE3C,MAID;IACC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC1C,MAAM,CAAC,WAAW,EAAE;QACpB,MAAM,CAAC,YAAY,EAAE;KACtB,CAAC,CAAC;IAEH,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACpE,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACrD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Ownership guards for member-facing MCP tools.\n *\n * The LLM controls tool arguments. Any member-facing tool that accepts an\n * external per-user identifier (a Wild Apricot contactId, a Discourse\n * username, a LearnWorlds learner id, etc.) is a cross-member data-exposure\n * risk: the caller can pass *someone else's* id and read or act on their\n * data. The org-membership gate (`ensureAccountMembership`) does not catch\n * this — it answers \"is this person in the org?\", never \"is this person's\n * own data?\".\n *\n * These helpers make the safe path the default. A tool author reaches for\n * `resolveSelfOnly` instead of writing a bespoke \"default to me\" resolver,\n * and gets ownership enforcement for free.\n *\n * Resolving \"who am I\" is integration-specific (each integration maps the\n * Supabase user to its own id space), so the caller supplies `resolveSelf`.\n */\n\n/**\n * Thrown when a tool caller attempts to access or act on another user's\n * data. Tool `run` bodies should let this propagate (or convert it to a\n * `{ error }` result) — the assistant surfaces a \"not permitted\" message\n * rather than the forbidden data.\n */\nexport class ToolOwnershipError extends Error {\n readonly code = 'FORBIDDEN_OWNERSHIP';\n\n constructor(resourceLabel = 'data') {\n super(`Forbidden: you can only access your own ${resourceLabel}.`);\n this.name = 'ToolOwnershipError';\n }\n}\n\n/**\n * Self-only identity resolution for member-facing tools.\n *\n * - caller supplied no id → returns the caller's own id\n * - caller supplied their own id → returns it\n * - caller supplied a different id → throws ToolOwnershipError\n *\n * @example\n * // In a Wild Apricot read tool:\n * const contactId = await resolveSelfOnly({\n * requestedId: args.contactId,\n * resolveSelf: () => resolveWaContactId(accountId),\n * resourceLabel: 'member data',\n * });\n */\nexport async function resolveSelfOnly<TId extends string | number>(params: {\n /** The identifier the LLM supplied as a tool argument, if any. */\n requestedId?: TId | null;\n /** Integration-specific resolver for the calling user's own id. */\n resolveSelf: () => Promise<TId>;\n /** Human-readable noun for the error message, e.g. 'member profile'. */\n resourceLabel?: string;\n}): Promise<TId> {\n const selfId = await params.resolveSelf();\n\n if (\n params.requestedId !== undefined &&\n params.requestedId !== null &&\n params.requestedId !== selfId\n ) {\n throw new ToolOwnershipError(params.resourceLabel);\n }\n\n return selfId;\n}\n\n/**\n * Ownership verification for tools that act on an opaque resource id (an\n * event registration, a saved document, an invoice) where ownership cannot\n * be inferred from the id itself. Resolves the resource's owner and the\n * caller's own id and throws if they differ (or if the resource has no\n * resolvable owner — fail closed).\n *\n * @example\n * // In a Wild Apricot cancel tool:\n * await assertResourceOwnership({\n * resolveSelf: () => resolveWaContactId(accountId),\n * resolveOwner: async () => {\n * const regs = await getContactRegistrations(accountId, await resolveWaContactId(accountId));\n * return regs.find((r) => r.Id === registrationId)?.Contact.Id;\n * },\n * resourceLabel: 'event registration',\n * });\n */\nexport async function assertResourceOwnership<\n TId extends string | number,\n>(params: {\n resolveSelf: () => Promise<TId>;\n resolveOwner: () => Promise<TId | null | undefined>;\n resourceLabel?: string;\n}): Promise<void> {\n const [selfId, ownerId] = await Promise.all([\n params.resolveSelf(),\n params.resolveOwner(),\n ]);\n\n if (ownerId === null || ownerId === undefined || ownerId !== selfId) {\n throw new ToolOwnershipError(params.resourceLabel);\n }\n}\n"]}
@@ -1,145 +0,0 @@
1
- import type { SupabaseClient } from '@supabase/supabase-js';
2
- import type { IntegrationContext } from '@ekanos/integration-schema';
3
- export type ToolParamsSchema = {
4
- type: 'object';
5
- properties?: Record<string, unknown>;
6
- required?: string[];
7
- additionalProperties?: boolean;
8
- };
9
- export type ToolContext = {
10
- req: Request;
11
- /**
12
- * Admin Supabase client for in-process MCP execution.
13
- * This bypasses RLS; tools must perform their own authorization checks before
14
- * reading or mutating protected data.
15
- */
16
- supabase: SupabaseClient;
17
- user: {
18
- id: string;
19
- } & Record<string, unknown>;
20
- /** The resolved account slug from the workspace context (injected by MCP route) */
21
- accountSlug?: string;
22
- /** The resolved account ID (UUID) from the workspace context (injected by MCP route) */
23
- accountId?: string;
24
- /** The resolved source ID (UUID) for the current tenant/workspace */
25
- sourceId?: string | null;
26
- /** The user's resolved IANA timezone (e.g. 'America/New_York') */
27
- timezone?: string;
28
- /** Whether the authenticated user is a platform super-admin */
29
- isSuperAdmin?: boolean;
30
- /**
31
- * Who is executing this tool call.
32
- *
33
- * Undefined (the default for every user-facing MCP path) is treated as
34
- * `'user'` — the historical behavior. `'machine'` marks a non-interactive
35
- * caller (the Workflow Gateway) whose identity IS the account-bound gateway
36
- * token, not a signed-in session. See machineGrant below and the
37
- * "Machine-principal design" section of context/N8N_INTEGRATION_PLAN.md.
38
- */
39
- principal?: 'user' | 'machine';
40
- /**
41
- * Present only when `principal === 'machine'`. Carries the account the
42
- * gateway token is bound to (the sole source of account identity for a
43
- * machine call), the token row id, and the token creator for audit
44
- * attribution. `getAccountId` / `ensureAccountMembership` read this instead
45
- * of doing a DB membership lookup — the token itself is the authorization.
46
- */
47
- machineGrant?: {
48
- accountId: string;
49
- tokenId: string;
50
- createdBy: string | null;
51
- };
52
- /**
53
- * The host-built capability context
54
- * (docs/devex/capability-context-proposal.md), attached ADDITIVELY by the
55
- * MCP route after authorization. This is the CANONICAL `IntegrationContext`
56
- * from `@ekanos/integration-schema` — the same declaration `@ekanos/sdk`
57
- * re-exports, so there is no structural twin to drift and no core→SDK
58
- * package cycle. Migrated tools may still narrow it with
59
- * `requireContext(ctx)` from `@ekanos/sdk/context`; existing tools that
60
- * never touch this field are unaffected.
61
- */
62
- integrationContext?: IntegrationContext;
63
- };
64
- export type ToolRunResult = unknown;
65
- /**
66
- * The partner execution channel — the ONLY way partner-authored tool code
67
- * runs (capability-context proposal §3 + sdk-export-map.md adversarial
68
- * review outcomes 1–2).
69
- *
70
- * The first argument is the host-built capability context — the canonical
71
- * `IntegrationContext` from `@ekanos/integration-schema`, the one declaration
72
- * both `@ekanos/sdk` (authoring) and this package (host) import. The
73
- * client-bearing `ToolContext` (req, admin supabase, identity fields) is
74
- * structurally absent from this signature — a partner tool cannot reach it.
75
- */
76
- export type PartnerToolRun = (integrationContext: IntegrationContext, args: Record<string, unknown>) => Promise<ToolRunResult>;
77
- export type ToolModule = {
78
- name: string;
79
- description?: string;
80
- parameters?: ToolParamsSchema;
81
- run: (ctx: ToolContext, args: Record<string, unknown>) => Promise<ToolRunResult>;
82
- /**
83
- * Partner EXECUTION function. Set by host adapter code
84
- * (`registerPartnerIntegration`'s tool adapter) alongside the host BRAND
85
- * (`brandPartnerTool`, mcp/helpers.ts) — never by first-party tool modules.
86
- *
87
- * IMPORTANT: this property is NOT the partner classification authority
88
- * (that is the module-private WeakSet brand — a property can be forged,
89
- * stripped, or varied between reads). For a host-branded tool the executor:
90
- * - invokes `partnerRun(integrationContext, args)` with the host-built
91
- * capability context and NOTHING else (no ToolContext, no prepareArgs,
92
- * no toUi);
93
- * - FAILS CLOSED if the capability context or this function is missing —
94
- * there is no legacy-context fallback for a branded tool.
95
- *
96
- * An UNBRANDED object carrying this property is treated as first-party and
97
- * can never reach the partner path — so a partner cannot escape into, and a
98
- * spoofed property cannot fake, the capability-only channel.
99
- */
100
- partnerRun?: PartnerToolRun;
101
- prepareArgs?: (ctx: ToolContext, rawArgs: unknown) => Promise<Record<string, unknown>>;
102
- ui?: UiComponentMeta | UiComponentMeta[];
103
- toUi?: (ctx: ToolContext, result: unknown) => Promise<null | RenderInstruction | RenderInstruction[]>;
104
- /**
105
- * Side-effect classification — used by the SOC 2 audit log to decide
106
- * whether the call is recorded. When omitted, the audit layer derives
107
- * it from the tool name (read-verb prefixes → 'read', otherwise 'write').
108
- * Tool authors should set this explicitly when the heuristic would be
109
- * wrong (e.g. a `generate_*` tool that materially mutates server state).
110
- * See packages/agents/src/security/tool-effect.ts.
111
- */
112
- effect?: 'read' | 'write';
113
- /**
114
- * Data classification of what this tool exposes. Mirror of
115
- * `Sensitivity` in packages/agents/src/security/redact.ts — kept inline
116
- * here to avoid a backwards dependency from integrations-core onto agents.
117
- * Reads that expose 'pii' or 'financial' data are recorded in the audit
118
- * log even though they are not writes. Defaults to undefined (treated
119
- * as 'internal' by the audit filter, 'pii' by the redaction layer).
120
- */
121
- sensitivity?: 'public' | 'internal' | 'pii' | 'financial';
122
- /**
123
- * A REPRESENTATIVE example of this tool's SUCCESS return value (top-level
124
- * shape, minimal realistic values, arrays trimmed to one element). Consumed
125
- * by the workflow authoring layer two ways:
126
- * 1. Codegen grounding — the example is embedded in the workflow-generation
127
- * prompt so the model wires `{{stepId.field}}` refs against the tool's
128
- * REAL output keys instead of guessing (`deals` vs `contacts`,
129
- * `contact_id` vs `contactId` — observed failure class).
130
- * 2. Ref linting — a workflow ref into this tool's output whose first path
131
- * segment is not a key of this example is rejected at authoring time.
132
- * Keep it SMALL (it ships in prompts), faithful to the actual run() return,
133
- * and free of real customer data. Omitting it just skips both uses.
134
- */
135
- outputExample?: Record<string, unknown>;
136
- };
137
- export type UiComponentMeta = {
138
- component: string;
139
- propsSchema: ToolParamsSchema;
140
- doc?: string;
141
- };
142
- export type RenderInstruction = {
143
- component: string;
144
- props: unknown;
145
- };
package/dist/mcp/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SupabaseClient } from '@supabase/supabase-js';\n\nimport type { IntegrationContext } from '@ekanos/integration-schema';\n\nexport type ToolParamsSchema = {\n type: 'object';\n properties?: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n};\n\nexport type ToolContext = {\n req: Request;\n /**\n * Admin Supabase client for in-process MCP execution.\n * This bypasses RLS; tools must perform their own authorization checks before\n * reading or mutating protected data.\n */\n supabase: SupabaseClient;\n user: { id: string } & Record<string, unknown>;\n /** The resolved account slug from the workspace context (injected by MCP route) */\n accountSlug?: string;\n /** The resolved account ID (UUID) from the workspace context (injected by MCP route) */\n accountId?: string;\n /** The resolved source ID (UUID) for the current tenant/workspace */\n sourceId?: string | null;\n /** The user's resolved IANA timezone (e.g. 'America/New_York') */\n timezone?: string;\n /** Whether the authenticated user is a platform super-admin */\n isSuperAdmin?: boolean;\n /**\n * Who is executing this tool call.\n *\n * Undefined (the default for every user-facing MCP path) is treated as\n * `'user'` — the historical behavior. `'machine'` marks a non-interactive\n * caller (the Workflow Gateway) whose identity IS the account-bound gateway\n * token, not a signed-in session. See machineGrant below and the\n * \"Machine-principal design\" section of context/N8N_INTEGRATION_PLAN.md.\n */\n principal?: 'user' | 'machine';\n /**\n * Present only when `principal === 'machine'`. Carries the account the\n * gateway token is bound to (the sole source of account identity for a\n * machine call), the token row id, and the token creator for audit\n * attribution. `getAccountId` / `ensureAccountMembership` read this instead\n * of doing a DB membership lookup — the token itself is the authorization.\n */\n machineGrant?: {\n accountId: string;\n tokenId: string;\n createdBy: string | null;\n };\n /**\n * The host-built capability context\n * (docs/devex/capability-context-proposal.md), attached ADDITIVELY by the\n * MCP route after authorization. This is the CANONICAL `IntegrationContext`\n * from `@ekanos/integration-schema` — the same declaration `@ekanos/sdk`\n * re-exports, so there is no structural twin to drift and no core→SDK\n * package cycle. Migrated tools may still narrow it with\n * `requireContext(ctx)` from `@ekanos/sdk/context`; existing tools that\n * never touch this field are unaffected.\n */\n integrationContext?: IntegrationContext;\n};\n\nexport type ToolRunResult = unknown;\n\n/**\n * The partner execution channel — the ONLY way partner-authored tool code\n * runs (capability-context proposal §3 + sdk-export-map.md adversarial\n * review outcomes 1–2).\n *\n * The first argument is the host-built capability context — the canonical\n * `IntegrationContext` from `@ekanos/integration-schema`, the one declaration\n * both `@ekanos/sdk` (authoring) and this package (host) import. The\n * client-bearing `ToolContext` (req, admin supabase, identity fields) is\n * structurally absent from this signature — a partner tool cannot reach it.\n */\nexport type PartnerToolRun = (\n integrationContext: IntegrationContext,\n args: Record<string, unknown>,\n) => Promise<ToolRunResult>;\n\nexport type ToolModule = {\n name: string;\n description?: string;\n parameters?: ToolParamsSchema;\n run: (\n ctx: ToolContext,\n args: Record<string, unknown>,\n ) => Promise<ToolRunResult>;\n\n /**\n * Partner EXECUTION function. Set by host adapter code\n * (`registerPartnerIntegration`'s tool adapter) alongside the host BRAND\n * (`brandPartnerTool`, mcp/helpers.ts) — never by first-party tool modules.\n *\n * IMPORTANT: this property is NOT the partner classification authority\n * (that is the module-private WeakSet brand — a property can be forged,\n * stripped, or varied between reads). For a host-branded tool the executor:\n * - invokes `partnerRun(integrationContext, args)` with the host-built\n * capability context and NOTHING else (no ToolContext, no prepareArgs,\n * no toUi);\n * - FAILS CLOSED if the capability context or this function is missing —\n * there is no legacy-context fallback for a branded tool.\n *\n * An UNBRANDED object carrying this property is treated as first-party and\n * can never reach the partner path — so a partner cannot escape into, and a\n * spoofed property cannot fake, the capability-only channel.\n */\n partnerRun?: PartnerToolRun;\n\n // Optional advanced features\n // Compute/override arguments from context so the model doesn't need to supply them\n prepareArgs?: (\n ctx: ToolContext,\n rawArgs: unknown,\n ) => Promise<Record<string, unknown>>;\n\n // UI rendering support: declare components and map results to render instructions\n ui?: UiComponentMeta | UiComponentMeta[];\n toUi?: (\n ctx: ToolContext,\n result: unknown,\n ) => Promise<null | RenderInstruction | RenderInstruction[]>;\n\n /**\n * Side-effect classification — used by the SOC 2 audit log to decide\n * whether the call is recorded. When omitted, the audit layer derives\n * it from the tool name (read-verb prefixes → 'read', otherwise 'write').\n * Tool authors should set this explicitly when the heuristic would be\n * wrong (e.g. a `generate_*` tool that materially mutates server state).\n * See packages/agents/src/security/tool-effect.ts.\n */\n effect?: 'read' | 'write';\n\n /**\n * Data classification of what this tool exposes. Mirror of\n * `Sensitivity` in packages/agents/src/security/redact.ts — kept inline\n * here to avoid a backwards dependency from integrations-core onto agents.\n * Reads that expose 'pii' or 'financial' data are recorded in the audit\n * log even though they are not writes. Defaults to undefined (treated\n * as 'internal' by the audit filter, 'pii' by the redaction layer).\n */\n sensitivity?: 'public' | 'internal' | 'pii' | 'financial';\n\n /**\n * A REPRESENTATIVE example of this tool's SUCCESS return value (top-level\n * shape, minimal realistic values, arrays trimmed to one element). Consumed\n * by the workflow authoring layer two ways:\n * 1. Codegen grounding — the example is embedded in the workflow-generation\n * prompt so the model wires `{{stepId.field}}` refs against the tool's\n * REAL output keys instead of guessing (`deals` vs `contacts`,\n * `contact_id` vs `contactId` — observed failure class).\n * 2. Ref linting — a workflow ref into this tool's output whose first path\n * segment is not a key of this example is rejected at authoring time.\n * Keep it SMALL (it ships in prompts), faithful to the actual run() return,\n * and free of real customer data. Omitting it just skips both uses.\n */\n outputExample?: Record<string, unknown>;\n};\n\nexport type UiComponentMeta = {\n component: string;\n propsSchema: ToolParamsSchema;\n doc?: string;\n};\n\nexport type RenderInstruction = {\n component: string;\n props: unknown;\n};\n"]}