skedyul 1.2.43 → 1.2.48

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 (54) hide show
  1. package/dist/cli/commands/workflows.d.ts +1 -0
  2. package/dist/cli/index.js +3682 -9076
  3. package/dist/cli/utils/auth.d.ts +4 -1
  4. package/dist/cli/utils/auth.js +32 -8
  5. package/dist/cli/utils/config.d.ts +23 -0
  6. package/dist/cli/utils/env-sync.d.ts +46 -0
  7. package/dist/cli/utils/mcp-http-client.d.ts +74 -0
  8. package/dist/cli/utils/migration-approval.d.ts +39 -0
  9. package/dist/cli/utils/mock-context.d.ts +19 -9
  10. package/dist/cli/utils/sse.d.ts +33 -0
  11. package/dist/cli/utils.d.ts +5 -1
  12. package/dist/compiler/types.d.ts +11 -9
  13. package/dist/config/schema-loader.d.ts +15 -2
  14. package/dist/config/types/model.d.ts +2 -0
  15. package/dist/config/types/page.d.ts +9 -0
  16. package/dist/context/index.d.ts +2 -2
  17. package/dist/context/resolver.d.ts +29 -28
  18. package/dist/context/types.d.ts +195 -37
  19. package/dist/core/client.d.ts +189 -233
  20. package/dist/dedicated/server.js +264 -166
  21. package/dist/esm/index.mjs +1161 -7674
  22. package/dist/index.d.ts +11 -6
  23. package/dist/index.js +1206 -7672
  24. package/dist/scheduling/calculateWaitTime.d.ts +16 -0
  25. package/dist/scheduling/index.d.ts +11 -0
  26. package/dist/scheduling/index.js +334 -0
  27. package/dist/scheduling/index.mjs +305 -0
  28. package/dist/scheduling/isTimeInWindow.d.ts +15 -0
  29. package/dist/scheduling/types-workflow.d.ts +54 -0
  30. package/dist/scheduling/types.d.ts +166 -0
  31. package/dist/schemas/agent-schema-v3.d.ts +406 -60
  32. package/dist/schemas/agent-schema-v3.js +248 -75
  33. package/dist/schemas/agent-schema-v3.mjs +234 -73
  34. package/dist/schemas/agent-schema.js +3 -7295
  35. package/dist/schemas/agent-schema.mjs +3 -7323
  36. package/dist/schemas/crm-schema.d.ts +53 -19
  37. package/dist/schemas/index.d.ts +1 -1
  38. package/dist/schemas.d.ts +128 -40
  39. package/dist/server/route-handlers/handlers.d.ts +7 -0
  40. package/dist/server/utils/env.d.ts +9 -0
  41. package/dist/server/utils/index.d.ts +1 -0
  42. package/dist/server/utils/mcp-response.d.ts +11 -0
  43. package/dist/server.js +264 -166
  44. package/dist/serverless/server.mjs +264 -166
  45. package/dist/skills/index.d.ts +1 -1
  46. package/dist/skills/types.d.ts +34 -23
  47. package/dist/skills/types.js +8 -17
  48. package/dist/skills/types.mjs +7 -16
  49. package/dist/types/index.d.ts +3 -3
  50. package/dist/types/server.d.ts +1 -0
  51. package/dist/types/tool-context.d.ts +31 -4
  52. package/dist/types/tool-response.d.ts +2 -0
  53. package/dist/types/tool.d.ts +35 -1
  54. package/package.json +8 -1
@@ -87,5 +87,8 @@ export interface ApiClientOptions {
87
87
  serverUrl: string;
88
88
  token?: string;
89
89
  }
90
- export declare function callCliApi<T>(options: ApiClientOptions, endpoint: string, body?: Record<string, unknown>): Promise<T>;
90
+ export declare function callCliApi<T>(options: ApiClientOptions, endpoint: string, body?: Record<string, unknown>, init?: {
91
+ method?: 'GET' | 'POST';
92
+ query?: Record<string, string | undefined>;
93
+ }): Promise<T>;
91
94
  export {};
@@ -442,31 +442,55 @@ async function openBrowser(url) {
442
442
  });
443
443
  }
444
444
  }
445
- async function callCliApi(options, endpoint, body) {
446
- const url = `${options.serverUrl}/api/cli${endpoint}`;
445
+ async function callCliApi(options, endpoint, body, init) {
446
+ let url = `${options.serverUrl}/api/cli${endpoint}`;
447
+ if (init?.query) {
448
+ const params = new URLSearchParams();
449
+ for (const [key, value] of Object.entries(init.query)) {
450
+ if (value !== void 0) {
451
+ params.set(key, value);
452
+ }
453
+ }
454
+ const queryString = params.toString();
455
+ if (queryString) {
456
+ url += `?${queryString}`;
457
+ }
458
+ }
447
459
  const headers = {
448
460
  "Content-Type": "application/json"
449
461
  };
450
462
  if (options.token) {
451
463
  headers["Authorization"] = `Bearer ${options.token}`;
452
464
  }
465
+ const method = init?.method ?? (body !== void 0 ? "POST" : "GET");
453
466
  const response = await fetch(url, {
454
- method: "POST",
467
+ method,
455
468
  headers,
456
- body: body ? JSON.stringify(body) : void 0
469
+ body: method === "POST" && body ? JSON.stringify(body) : void 0
457
470
  });
458
471
  if (!response.ok) {
459
- const text = await response.text();
472
+ const text2 = await response.text();
460
473
  let message = `API error: ${response.status}`;
461
474
  try {
462
- const json = JSON.parse(text);
475
+ const json = JSON.parse(text2);
463
476
  if (json.error) message = json.error;
464
477
  } catch {
465
- if (text) message = text;
478
+ if (text2.startsWith("<!DOCTYPE") || text2.startsWith("<html")) {
479
+ message = `API error: ${response.status} (received HTML instead of JSON \u2014 is the route registered and allowed in proxy.ts?)`;
480
+ } else if (text2) {
481
+ message = text2.slice(0, 200);
482
+ }
466
483
  }
467
484
  throw new Error(message);
468
485
  }
469
- return response.json();
486
+ const text = await response.text();
487
+ try {
488
+ return JSON.parse(text);
489
+ } catch {
490
+ throw new Error(
491
+ `Invalid JSON response from ${url} \u2014 received HTML or malformed body. Restart the web server if you added a new CLI route.`
492
+ );
493
+ }
470
494
  }
471
495
  // Annotate the CommonJS export names for ESM import in node:
472
496
  0 && (module.exports = {
@@ -1,4 +1,6 @@
1
1
  import type { ModelDefinition, RelationshipDefinition } from '../../config/types';
2
+ import type { ProvisionConfig } from '../../config/app-config';
3
+ import type { ToolRegistry, WebhookRegistry } from '../../types';
2
4
  export interface SkedyulAppConfig {
3
5
  name: string;
4
6
  handle: string;
@@ -20,6 +22,7 @@ export interface InstallEnvField {
20
22
  visibility?: 'visible' | 'encrypted';
21
23
  placeholder?: string;
22
24
  description?: string;
25
+ scope?: 'provision' | 'install';
23
26
  }
24
27
  export interface InstallConfigData {
25
28
  env?: Record<string, InstallEnvField>;
@@ -29,9 +32,29 @@ export interface InstallConfigData {
29
32
  relationships?: RelationshipDefinition[];
30
33
  }
31
34
  export declare function loadInstallConfig(projectDir?: string, debug?: boolean): Promise<InstallConfigData | null>;
35
+ /**
36
+ * Load env from legacy install.config files only (not provision/env.ts).
37
+ */
38
+ export declare function loadLegacyInstallConfig(projectDir?: string, debug?: boolean): Promise<InstallConfigData | null>;
32
39
  /**
33
40
  * Find and load the install handler from the project directory.
34
41
  * Returns the default export (install handler function) or null if not found.
35
42
  */
36
43
  export declare function loadInstallHandler(projectDir?: string): Promise<((ctx: unknown) => Promise<unknown>) | null>;
44
+ /** Exclude provision-scoped vars mistakenly stored in install.env (legacy sync bug). */
45
+ export declare function filterInstallScopedEnv(env: Record<string, InstallEnvField & {
46
+ scope?: string;
47
+ }>): Record<string, InstallEnvField>;
48
+ /** Env vars passed to the install workflow (install-scoped only). */
49
+ export declare function filterEnvForInstallWorkflow(env: Record<string, string>, installConfig: InstallConfigData | null): Record<string, string>;
50
+ /**
51
+ * Load provision config (env, models, pages) directly from src/provision/index.ts.
52
+ * Avoids resolving skedyul.config.ts dynamic imports which fail under the compiled CLI.
53
+ */
54
+ export declare function loadProvisionConfig(projectDir?: string): Promise<ProvisionConfig | null>;
55
+ /**
56
+ * Build the executable.config payload synced to Skedyul during dev serve.
57
+ * Includes full provision (env, models, pages) so Developer Console and install UI work.
58
+ */
59
+ export declare function buildExecutableSyncConfig(registry: ToolRegistry, inputSchemaToJson: (schema: unknown) => unknown, projectDir?: string, webhookRegistry?: WebhookRegistry): Promise<Record<string, unknown>>;
37
60
  export declare function findRegistryPath(projectDir?: string): string | null;
@@ -0,0 +1,46 @@
1
+ import { type LinkConfig } from './link';
2
+ import { type InstallEnvField } from './config';
3
+ export type EnvConfigField = InstallEnvField;
4
+ export declare function isInstallScopedField(field: EnvConfigField): boolean;
5
+ export declare function isProvisionScopedField(field: EnvConfigField): boolean;
6
+ export declare function applyEnvToProcess(env: Record<string, string>): void;
7
+ export declare function buildProvisionEnvFields(): Promise<Array<{
8
+ key: string;
9
+ field: EnvConfigField;
10
+ }>>;
11
+ export declare function buildInstallScopedEnvFields(): Promise<Array<{
12
+ key: string;
13
+ field: EnvConfigField;
14
+ }>>;
15
+ /**
16
+ * Fetch env vars from Skedyul DB (decrypted) for the given scope.
17
+ */
18
+ export declare function fetchEnvFromPlatform(linkConfig: LinkConfig, token: string, scope: 'provision' | 'install'): Promise<Record<string, string>>;
19
+ /**
20
+ * Upsert provision-scoped env vars to Skedyul (APP_VERSION level).
21
+ */
22
+ export declare function syncProvisionEnvToPlatform(linkConfig: LinkConfig, token: string, env: Record<string, string>, envFields?: Array<{
23
+ key: string;
24
+ field: EnvConfigField;
25
+ }>, options?: {
26
+ quiet?: boolean;
27
+ }): Promise<void>;
28
+ /**
29
+ * Upsert install-scoped env vars to Skedyul (APP_INSTALL level).
30
+ */
31
+ export declare function syncInstallEnvToPlatform(linkConfig: LinkConfig, token: string, env: Record<string, string>, envFields?: Array<{
32
+ key: string;
33
+ field: EnvConfigField;
34
+ }>): Promise<void>;
35
+ /** @deprecated Use fetchEnvFromPlatform with scope 'install' */
36
+ export declare function buildInstallEnvFields(): Promise<Array<{
37
+ key: string;
38
+ field: EnvConfigField;
39
+ }>>;
40
+ /** Load install-scoped vars from local file (dev install cache). */
41
+ export declare function loadLocalInstallEnv(workplaceSubdomain: string): Record<string, string>;
42
+ /**
43
+ * Remove provision-scoped keys from the local .env file.
44
+ * Provision vars live in Skedyul DB — the local file is for install-scoped vars only.
45
+ */
46
+ export declare function pruneProvisionKeysFromLocalEnv(workplaceSubdomain: string): Promise<string[]>;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * MCP HTTP Client utilities for CLI commands.
3
+ *
4
+ * Provides helpers for making JSON-RPC calls to local MCP servers,
5
+ * matching the payload format used by the worker-compute activities.
6
+ */
7
+ export interface McpJsonRpcResponse {
8
+ jsonrpc: string;
9
+ id: unknown;
10
+ result?: {
11
+ content?: Array<{
12
+ type?: string;
13
+ text?: unknown;
14
+ }>;
15
+ structuredContent?: Record<string, unknown>;
16
+ isError?: boolean;
17
+ tools?: unknown[];
18
+ cursor?: unknown;
19
+ billing?: unknown;
20
+ };
21
+ error?: {
22
+ code?: number;
23
+ message?: string;
24
+ };
25
+ }
26
+ export interface McpToolCallResult {
27
+ success: boolean;
28
+ output: unknown;
29
+ error?: string;
30
+ billing?: unknown;
31
+ cursor?: unknown;
32
+ isError?: boolean;
33
+ }
34
+ export interface McpToolCallOptions {
35
+ baseUrl: string;
36
+ toolName: string;
37
+ inputs?: Record<string, unknown>;
38
+ context?: Record<string, unknown>;
39
+ env?: Record<string, string>;
40
+ timeoutMs?: number;
41
+ }
42
+ /**
43
+ * Make an HTTP request to a local server.
44
+ */
45
+ export declare function makeHttpRequest(hostname: string, port: number, path: string, method: string, body?: unknown, timeoutMs?: number): Promise<{
46
+ status: number;
47
+ body: unknown;
48
+ }>;
49
+ /**
50
+ * POST a JSON-RPC request to an MCP server.
51
+ */
52
+ export declare function postJsonRpc(baseUrl: string, method: string, params: unknown, timeoutMs?: number): Promise<McpJsonRpcResponse>;
53
+ /**
54
+ * Check if a local MCP server is healthy.
55
+ */
56
+ export declare function checkHealth(baseUrl: string, timeoutMs?: number): Promise<boolean>;
57
+ /**
58
+ * Call tools/list on an MCP server.
59
+ */
60
+ export declare function listMcpTools(baseUrl: string, timeoutMs?: number): Promise<{
61
+ success: boolean;
62
+ tools?: unknown[];
63
+ error?: string;
64
+ }>;
65
+ /**
66
+ * Call tools/call on an MCP server with the Skedyul payload format.
67
+ *
68
+ * Builds the same payload structure as worker-compute/src/activities/mcp-http.ts
69
+ */
70
+ export declare function callMcpTool(options: McpToolCallOptions): Promise<McpToolCallResult>;
71
+ /**
72
+ * Parse the MCP tools/call response into a structured result.
73
+ */
74
+ export declare function parseMcpToolCallResult(response: McpJsonRpcResponse): McpToolCallResult;
@@ -0,0 +1,39 @@
1
+ import type { LinkConfig } from './link';
2
+ export type MigrationImpact = {
3
+ operationType: string;
4
+ resourceType: string;
5
+ resourceHandle: string;
6
+ affectedRecords?: number;
7
+ message?: string;
8
+ isDestructive?: boolean;
9
+ };
10
+ export type PendingMigrationInfo = {
11
+ migrationId: string;
12
+ impacts: MigrationImpact[];
13
+ timeoutMinutes: number;
14
+ createdAt: string;
15
+ };
16
+ export type SyncResourcesResult = {
17
+ tools?: {
18
+ synced: number;
19
+ disabled: number;
20
+ };
21
+ webhooks?: {
22
+ synced: number;
23
+ disabled: number;
24
+ };
25
+ internalModels?: {
26
+ modelsCreated: number;
27
+ modelsUpdated: number;
28
+ fieldsCreated: number;
29
+ relationshipsCreated: number;
30
+ };
31
+ };
32
+ export declare function promptForMigrationApproval(impacts: MigrationImpact[]): Promise<boolean>;
33
+ export declare function approveMigrationViaCli(serverUrl: string, token: string, migrationId: string): Promise<void>;
34
+ export declare function waitForMigrationCompletion(serverUrl: string, token: string, migrationId: string, timeoutMs?: number): Promise<{
35
+ completed: boolean;
36
+ timedOut: boolean;
37
+ denied: boolean;
38
+ }>;
39
+ export declare function syncResourcesWithMigrationApproval(linkConfig: LinkConfig, token: string, config: Record<string, unknown>): Promise<SyncResourcesResult>;
@@ -1,22 +1,32 @@
1
- import { type MockContext } from '../../context/types';
1
+ import { type AgentContext } from '../../context/types';
2
2
  /**
3
- * Load mock context from a JSON file
3
+ * Load agent context from a JSON file
4
4
  */
5
- export declare function loadMockContext(filePath: string): MockContext;
5
+ export declare function loadContext(filePath: string): AgentContext;
6
+ /** @deprecated Use loadContext instead */
7
+ export declare const loadMockContext: typeof loadContext;
8
+ /** Read prospect CRM data from context (associations shape or legacy contexts). */
9
+ export declare function getProspectData(context: AgentContext | null | undefined): Record<string, unknown> | undefined;
6
10
  /**
7
- * Parse a quick mock sender string
11
+ * Parse a quick sender string
8
12
  * Format: "Display Name:kind" or "Display Name:kind:model"
9
13
  * Examples:
10
14
  * "John Smith:contact"
11
15
  * "John Smith:contact:customer"
12
16
  * "Sarah Jones:member"
13
17
  */
14
- export declare function parseMockSender(input: string): MockContext['sender'];
18
+ export declare function parseSender(input: string): AgentContext['sender'];
19
+ /** @deprecated Use parseSender instead */
20
+ export declare const parseMockSender: typeof parseSender;
15
21
  /**
16
- * Build a complete mock context from sender and optional contexts
22
+ * Build a complete context from sender and optional contexts
17
23
  */
18
- export declare function buildMockContext(sender: MockContext['sender'], contexts?: MockContext['contexts']): MockContext;
24
+ export declare function buildContext(sender: AgentContext['sender'], contexts?: AgentContext['contexts']): AgentContext;
25
+ /** @deprecated Use buildContext instead */
26
+ export declare const buildMockContext: typeof buildContext;
19
27
  /**
20
- * Merge mock context with defaults
28
+ * Merge context with defaults
21
29
  */
22
- export declare function mergeMockContext(base: Partial<MockContext>, overrides: Partial<MockContext>): MockContext;
30
+ export declare function mergeContext(base: Partial<AgentContext>, overrides: Partial<AgentContext>): AgentContext;
31
+ /** @deprecated Use mergeContext instead */
32
+ export declare const mergeMockContext: typeof mergeContext;
@@ -96,5 +96,38 @@ export interface ChatEvent {
96
96
  result: unknown;
97
97
  /** Provider-specific options (e.g., Gemini's thought_signature for tool call replay) */
98
98
  providerOptions?: Record<string, unknown>;
99
+ /** AI SDK tool handle (e.g., "load_skill" for "system:skill:load") - needed for correct message replay */
100
+ handle?: string;
99
101
  }>;
102
+ /** Sent message event (explicit message mode) */
103
+ sentMessage?: {
104
+ messageId: string;
105
+ content: string;
106
+ type: 'intermediate' | 'final' | 'scheduled';
107
+ scheduledFor?: string;
108
+ };
109
+ /** All messages sent during this turn (for explicit message mode) */
110
+ sentMessages?: Array<{
111
+ id: string;
112
+ rawContent: string;
113
+ transformedContent: string;
114
+ type: 'intermediate' | 'final' | 'scheduled';
115
+ scheduledFor?: string;
116
+ timestamp?: string;
117
+ index?: number;
118
+ /** Structured sendAt object from the agent tool */
119
+ sendAt?: {
120
+ mode: 'relative' | 'absolute';
121
+ amount?: number;
122
+ unit?: string;
123
+ timeWindow?: string;
124
+ scheduleAt?: string;
125
+ };
126
+ }>;
127
+ /** Scheduling defaults from agent config (sandbox mode only) */
128
+ schedulingDefaults?: {
129
+ cancelOnActivity?: boolean;
130
+ requiresApproval?: boolean;
131
+ timeWindow?: string;
132
+ };
100
133
  }
@@ -1,4 +1,4 @@
1
- import type { ToolRegistry } from '../types';
1
+ import type { ToolRegistry, WebhookRegistry } from '../types';
2
2
  export interface ParsedArgs {
3
3
  flags: Record<string, string | boolean>;
4
4
  positional: string[];
@@ -23,6 +23,10 @@ export declare function loadTypeScriptFile(absolutePath: string): Promise<unknow
23
23
  * Load a registry from a JS/TS file
24
24
  */
25
25
  export declare function loadRegistry(registryPath: string): Promise<ToolRegistry>;
26
+ /**
27
+ * Load webhook registry from the same module as the tool registry.
28
+ */
29
+ export declare function loadWebhookRegistry(registryPath: string): Promise<WebhookRegistry>;
26
30
  /**
27
31
  * Format JSON for console output with optional color
28
32
  */
@@ -79,22 +79,24 @@ export interface IRMemoryConfig {
79
79
  * Policy configuration
80
80
  */
81
81
  export interface PolicyConfig {
82
- response?: {
83
- requiresApproval: boolean;
84
- conditions?: string[];
82
+ messages?: {
83
+ send?: {
84
+ requiresApproval?: boolean;
85
+ };
86
+ schedule?: {
87
+ requiresApproval?: boolean;
88
+ };
89
+ };
90
+ tools?: {
91
+ externalRequiresApproval?: boolean;
92
+ systemRequiresApproval?: boolean;
85
93
  };
86
- rules: string[];
87
94
  }
88
95
  /**
89
96
  * Runtime configuration
90
97
  */
91
98
  export interface IRRuntimeConfig {
92
99
  model: string;
93
- timeout: string;
94
- retry?: {
95
- attempts?: number;
96
- backoff?: 'linear' | 'exponential';
97
- };
98
100
  }
99
101
  /**
100
102
  * Agent Intermediate Representation (IR)
@@ -50,6 +50,15 @@ export interface BackendModelDefinition {
50
50
  icon?: string;
51
51
  fields?: BackendFieldDefinition[];
52
52
  }
53
+ /**
54
+ * Backend-compatible field appearance.
55
+ */
56
+ export interface BackendFieldAppearance {
57
+ leftIcon?: string;
58
+ rightIcon?: string;
59
+ placeholder?: string;
60
+ helpText?: string;
61
+ }
53
62
  /**
54
63
  * Backend-compatible field definition.
55
64
  */
@@ -57,7 +66,8 @@ export interface BackendFieldDefinition {
57
66
  handle: string;
58
67
  label: string;
59
68
  type: string;
60
- helpText?: string | null;
69
+ description?: string;
70
+ appearance?: BackendFieldAppearance;
61
71
  isList?: boolean;
62
72
  isUnique?: boolean;
63
73
  requirement?: string;
@@ -71,6 +81,7 @@ export interface BackendFieldDefinition {
71
81
  label: string;
72
82
  color?: string | null;
73
83
  }>;
84
+ limitChoices?: number;
74
85
  };
75
86
  }
76
87
  /**
@@ -118,8 +129,10 @@ export interface BackendPageDefinition {
118
129
  export interface BackendNavigationItemDefinition {
119
130
  label: string;
120
131
  icon?: string;
121
- path: string;
132
+ path?: string;
133
+ kind?: 'section' | 'group';
122
134
  sortIndex?: number;
135
+ children?: BackendNavigationItemDefinition[];
123
136
  }
124
137
  /**
125
138
  * Backend-compatible navigation definition.
@@ -158,6 +158,8 @@ export interface ModelDefinition extends BaseDefinition {
158
158
  addDefaultPages?: boolean;
159
159
  /** Whether to create a navigation item for this model (default: false for provisioning) */
160
160
  addNavigation?: boolean;
161
+ /** Root path for developer resource UI (e.g., '/access_requests'). Links internal model to a provision.pages entry. */
162
+ page?: string;
161
163
  }
162
164
  /**
163
165
  * One side of a relationship link.
@@ -14,6 +14,13 @@ import type { NavigationConfig } from './navigation';
14
14
  * - 'list': Shows multiple records (e.g., /phone-numbers)
15
15
  */
16
16
  export type PageType = 'instance' | 'list';
17
+ /**
18
+ * Page audience - who can view this page.
19
+ * - 'install': Visible only to app installers (default)
20
+ * - 'developer': Visible only to app developers/owners in Developer Console
21
+ * - 'both': Visible in both contexts
22
+ */
23
+ export type PageAudience = 'install' | 'developer' | 'both';
17
24
  /**
18
25
  * Page filter for list pages.
19
26
  * Defines which model and optional filter criteria to use.
@@ -34,6 +41,8 @@ export interface PageDefinition extends BaseDefinition {
34
41
  path: string;
35
42
  /** When true, this page is the default landing page for the app */
36
43
  default?: boolean;
44
+ /** Page audience: 'install' (default), 'developer', or 'both' */
45
+ audience?: PageAudience;
37
46
  /**
38
47
  * Navigation configuration:
39
48
  * - true/false: show/hide in auto-generated navigation
@@ -1,2 +1,2 @@
1
- export { CRMContextSchema, SenderContextSchema, ThreadContextItemSchema, ThreadInfoSchema, AgentContextSchema, MockSenderContextSchema, MockThreadContextSchema, MockContextSchema, SandboxConfigSchema, type CRMContext, type SenderContext, type ThreadContextItem, type ThreadInfo, type AgentContext, type MockSenderContext, type MockThreadContext, type MockContext, type SandboxConfig, } from './types';
2
- export { buildAgentContext, buildContextFromMock, formatContextForPrompt, getContextByHandle, getContextByModel, } from './resolver';
1
+ export { CRMContextSchema, SenderContextSchema, ThreadContextItemSchema, ThreadInfoSchema, SandboxConfigSchema, SubscriptionSchema, AssociationSchema, ContactSchema, AgentSenderContextSchema, AgentThreadContextSchema, AgentContextSchema, ContextIssueSeveritySchema, ContextIssueTypeSchema, ContextIssueSchema, ContextValidationResultSchema, MockSubscriptionSchema, MockAssociationSchema, MockContactSchema, MockSenderContextSchema, MockThreadContextSchema, MockContextSchema, type CRMContext, type SenderContext, type ThreadContextItem, type ThreadInfo, type SandboxConfig, type Subscription, type Association, type Contact, type AgentSenderContext, type AgentThreadContext, type AgentContext, type ContextIssueSeverity, type ContextIssueType, type ContextIssue, type ContextValidationResult, type MockSubscription, type MockAssociation, type MockContact, type MockSenderContext, type MockThreadContext, type MockContext, } from './types';
2
+ export { buildAgentContext, formatContextForPrompt, getContextByHandle, getContextByModel, getAssociationByModel, } from './resolver';
@@ -1,51 +1,52 @@
1
- import type { AgentContext, ThreadContextItem, MockContext } from './types';
1
+ import type { AgentContext, AgentThreadContext } from './types';
2
2
  /**
3
- * Build agent context from thread data
4
- * This is a utility for building the context object that gets passed to agents
3
+ * Build agent context from thread participant data.
4
+ *
5
+ * This creates the unified AgentContext shape used by both sandbox and production.
5
6
  */
6
7
  export declare function buildAgentContext(params: {
7
- thread: {
8
- id: string;
9
- title?: string;
10
- status?: string;
11
- kind?: string;
12
- };
13
8
  sender: {
14
- kind: 'CONTACT' | 'MEMBER' | 'AGENT' | 'WORKFLOW';
9
+ kind: 'contact' | 'member';
15
10
  displayName?: string;
16
- email?: string;
17
11
  role?: string;
18
12
  permissions?: string[];
19
- crm?: {
20
- model: string;
21
- instanceId: string;
22
- data: Record<string, unknown>;
13
+ contact?: {
14
+ id?: string;
15
+ name?: string;
16
+ subscription?: {
17
+ identifierValue: string;
18
+ channelHandle?: string;
19
+ };
20
+ associations?: Record<string, {
21
+ id?: string;
22
+ data: Record<string, unknown>;
23
+ }>;
23
24
  };
24
25
  };
25
26
  contexts?: Array<{
26
27
  handle: string;
27
28
  model: string;
28
- instanceId: string;
29
- data?: Record<string, unknown>;
29
+ data: Record<string, unknown>;
30
30
  }>;
31
- workplace?: {
32
- id: string;
33
- name?: string;
34
- };
35
31
  }): AgentContext;
36
32
  /**
37
- * Build agent context from mock context (for sandbox testing)
38
- */
39
- export declare function buildContextFromMock(mockContext: MockContext, threadId: string, workplaceId?: string): AgentContext;
40
- /**
41
- * Format context for system prompt injection
33
+ * Format context for system prompt injection.
34
+ *
35
+ * This creates the "Current Context" section that gets injected into the system prompt.
42
36
  */
43
37
  export declare function formatContextForPrompt(context: AgentContext): string;
44
38
  /**
45
39
  * Get CRM data from context by model handle
46
40
  */
47
- export declare function getContextByHandle(context: AgentContext, handle: string): ThreadContextItem | undefined;
41
+ export declare function getContextByHandle(context: AgentContext, handle: string): AgentThreadContext | undefined;
48
42
  /**
49
43
  * Get CRM data from context by model type
50
44
  */
51
- export declare function getContextByModel(context: AgentContext, model: string): ThreadContextItem | undefined;
45
+ export declare function getContextByModel(context: AgentContext, model: string): AgentThreadContext | undefined;
46
+ /**
47
+ * Get an association from the sender's contact by model handle
48
+ */
49
+ export declare function getAssociationByModel(context: AgentContext, model: string): {
50
+ id?: string;
51
+ data: Record<string, unknown>;
52
+ } | undefined;