@superpanel-sdk/runtime 0.2.2 → 0.5.0

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 (274) hide show
  1. package/README.md +28 -8
  2. package/dist/builder/codegen/emit.d.ts +29 -11
  3. package/dist/builder/codegen/emit.js +328 -61
  4. package/dist/builder/codegen/generate.d.ts +21 -0
  5. package/dist/builder/codegen/generate.js +152 -20
  6. package/dist/builder/company-import-graph.d.ts +2 -0
  7. package/dist/builder/company-import-graph.js +40 -8
  8. package/dist/builder/company-imports.d.ts +24 -0
  9. package/dist/builder/company-imports.js +114 -0
  10. package/dist/builder/compile/compile-sequence.d.ts +59 -8
  11. package/dist/builder/compile/compile-sequence.js +279 -77
  12. package/dist/builder/compile/function-code.d.ts +12 -2
  13. package/dist/builder/compile/function-code.js +87 -39
  14. package/dist/builder/compile/registry.d.ts +7 -3
  15. package/dist/builder/compile/registry.js +24 -23
  16. package/dist/builder/load.d.ts +70 -10
  17. package/dist/builder/load.js +250 -61
  18. package/dist/builder/paths.d.ts +3 -0
  19. package/dist/builder/paths.js +16 -0
  20. package/dist/builder/schedules.d.ts +23 -0
  21. package/dist/builder/schedules.js +102 -0
  22. package/dist/builder/slot-schema-validation.d.ts +4 -0
  23. package/dist/builder/slot-schema-validation.js +10 -0
  24. package/dist/builder/typecheck.d.ts +8 -0
  25. package/dist/builder/typecheck.js +105 -0
  26. package/dist/builder/types.d.ts +91 -19
  27. package/dist/builder/types.js +2 -1
  28. package/dist/cli/auth/auth.d.ts +37 -0
  29. package/dist/cli/auth/auth.js +211 -0
  30. package/dist/cli/auth/backend-url.d.ts +5 -0
  31. package/dist/cli/auth/backend-url.js +25 -0
  32. package/dist/cli/auth/clipboard.d.ts +9 -0
  33. package/dist/cli/auth/clipboard.js +38 -0
  34. package/dist/cli/auth/http.d.ts +20 -0
  35. package/dist/cli/auth/http.js +27 -0
  36. package/dist/cli/auth/index.d.ts +10 -0
  37. package/dist/cli/auth/index.js +27 -0
  38. package/dist/cli/auth/progress.d.ts +12 -0
  39. package/dist/cli/auth/progress.js +15 -0
  40. package/dist/cli/auth/serve-login.d.ts +8 -0
  41. package/dist/cli/auth/serve-login.js +24 -0
  42. package/dist/cli/compile/index.js +3 -0
  43. package/dist/cli/config.d.ts +10 -0
  44. package/dist/cli/config.js +52 -0
  45. package/dist/cli/index.js +28 -8
  46. package/dist/cli/serve/index.d.ts +73 -3
  47. package/dist/cli/serve/index.js +410 -113
  48. package/dist/cli/type-gen/index.js +9 -8
  49. package/dist/compiler.d.ts +7 -0
  50. package/dist/compiler.js +7 -0
  51. package/dist/compute-host/compute-host.d.ts +15 -23
  52. package/dist/compute-host/compute-host.js +25 -28
  53. package/dist/compute-host/index.d.ts +2 -2
  54. package/dist/compute-host/index.js +1 -1
  55. package/dist/compute-host/source-compute-host.d.ts +11 -9
  56. package/dist/compute-host/source-compute-host.js +50 -31
  57. package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
  58. package/dist/core/case-orchestrator/contact-hours.js +108 -0
  59. package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
  60. package/dist/core/case-orchestrator/follow-ups.js +103 -0
  61. package/dist/core/case-orchestrator/index.d.ts +6 -0
  62. package/dist/core/case-orchestrator/index.js +6 -0
  63. package/dist/core/case-orchestrator/render.d.ts +75 -0
  64. package/dist/core/case-orchestrator/render.js +239 -0
  65. package/dist/core/case-orchestrator/time.d.ts +11 -0
  66. package/dist/core/case-orchestrator/time.js +29 -0
  67. package/dist/core/case-orchestrator/tools.d.ts +29 -0
  68. package/dist/core/case-orchestrator/tools.js +31 -0
  69. package/dist/core/case-orchestrator/types.d.ts +753 -0
  70. package/dist/core/case-orchestrator/types.js +46 -0
  71. package/dist/core/case-orchestrator/validate.d.ts +11 -0
  72. package/dist/core/case-orchestrator/validate.js +63 -0
  73. package/dist/core/context/call.d.ts +291 -0
  74. package/dist/core/context/call.js +94 -0
  75. package/dist/core/context/channels.d.ts +60 -0
  76. package/dist/core/context/channels.js +35 -0
  77. package/dist/core/context/contact.d.ts +96 -6
  78. package/dist/core/context/contact.js +48 -2
  79. package/dist/core/context/email-message.d.ts +159 -0
  80. package/dist/core/context/email-message.js +59 -0
  81. package/dist/core/context/email.d.ts +97 -0
  82. package/dist/core/context/email.js +91 -0
  83. package/dist/core/context/exchanges.d.ts +142 -0
  84. package/dist/core/context/exchanges.js +63 -0
  85. package/dist/core/context/instances.d.ts +278 -0
  86. package/dist/core/context/instances.js +123 -0
  87. package/dist/core/context/kv.d.ts +113 -0
  88. package/dist/core/context/kv.js +60 -0
  89. package/dist/core/context/platform-registry.d.ts +509 -4
  90. package/dist/core/context/platform-registry.js +14 -2
  91. package/dist/core/context/platform.d.ts +2 -1
  92. package/dist/core/context/sms.d.ts +147 -0
  93. package/dist/core/context/sms.js +57 -0
  94. package/dist/core/context/types.d.ts +51 -30
  95. package/dist/core/context/types.js +1 -7
  96. package/dist/core/conversation/index.d.ts +31 -0
  97. package/dist/core/conversation/index.js +14 -0
  98. package/dist/core/functions/define/bind.d.ts +25 -0
  99. package/dist/core/functions/define/bind.js +14 -0
  100. package/dist/core/functions/define/case.d.ts +9 -0
  101. package/dist/core/functions/define/case.js +13 -0
  102. package/dist/core/functions/define/events.d.ts +20 -0
  103. package/dist/core/functions/define/events.js +21 -0
  104. package/dist/core/functions/define/no-case.d.ts +4 -0
  105. package/dist/core/functions/define/no-case.js +9 -0
  106. package/dist/core/functions/events.d.ts +247 -0
  107. package/dist/core/functions/events.js +32 -0
  108. package/dist/core/functions/func-ref.d.ts +11 -2
  109. package/dist/core/functions/schedules.d.ts +51 -0
  110. package/dist/core/functions/schedules.js +20 -0
  111. package/dist/core/functions/types.d.ts +62 -51
  112. package/dist/core/functions/types.js +6 -1
  113. package/dist/core/office-hours/index.d.ts +39 -0
  114. package/dist/core/office-hours/index.js +187 -0
  115. package/dist/core/page/define.d.ts +834 -0
  116. package/dist/core/page/define.js +477 -0
  117. package/dist/core/page/ops.d.ts +58 -0
  118. package/dist/core/page/ops.js +220 -0
  119. package/dist/core/page/render.d.ts +253 -0
  120. package/dist/core/page/render.js +840 -0
  121. package/dist/core/page/time-format.d.ts +19 -0
  122. package/dist/core/page/time-format.js +41 -0
  123. package/dist/core/page/timeline.d.ts +40 -0
  124. package/dist/core/page/timeline.js +2 -0
  125. package/dist/core/page/typed.d.ts +642 -0
  126. package/dist/core/page/typed.js +2 -0
  127. package/dist/core/page/workspace.d.ts +33 -0
  128. package/dist/core/page/workspace.js +231 -0
  129. package/dist/core/party/index.d.ts +3 -0
  130. package/dist/core/party/index.js +3 -0
  131. package/dist/core/party/schema.d.ts +137 -0
  132. package/dist/core/party/schema.js +80 -0
  133. package/dist/core/party/types.d.ts +40 -0
  134. package/dist/core/party/types.js +15 -0
  135. package/dist/core/sequence/define.d.ts +57 -0
  136. package/dist/core/sequence/define.js +10 -0
  137. package/dist/core/sequence/index.d.ts +63 -0
  138. package/dist/core/sequence/index.js +231 -0
  139. package/dist/core/slot/binding.d.ts +40 -0
  140. package/dist/core/slot/binding.js +2 -0
  141. package/dist/core/slot/company-metadata.d.ts +113 -0
  142. package/dist/core/slot/company-metadata.js +563 -0
  143. package/dist/core/slot/compile-schema.d.ts +19 -13
  144. package/dist/core/slot/compile-schema.js +51 -248
  145. package/dist/core/slot/contact-timezone.d.ts +110 -0
  146. package/dist/core/slot/contact-timezone.js +186 -0
  147. package/dist/core/slot/field.d.ts +2 -24
  148. package/dist/core/slot/field.js +0 -69
  149. package/dist/core/slot/id-ref.d.ts +17 -2
  150. package/dist/core/slot/id-ref.js +16 -8
  151. package/dist/core/slot/index.d.ts +12 -13
  152. package/dist/core/slot/index.js +11 -12
  153. package/dist/core/slot/naming.d.ts +15 -0
  154. package/dist/core/slot/naming.js +96 -0
  155. package/dist/core/slot/platform-fields.d.ts +119 -0
  156. package/dist/core/slot/platform-fields.js +121 -0
  157. package/dist/core/slot/ref.d.ts +16 -0
  158. package/dist/core/slot/ref.js +14 -0
  159. package/dist/core/slot/row.d.ts +2 -9
  160. package/dist/core/slot/row.js +13 -23
  161. package/dist/core/slot/schema-compat.d.ts +16 -0
  162. package/dist/core/slot/schema-compat.js +112 -0
  163. package/dist/core/slot/schema.d.ts +409 -76
  164. package/dist/core/slot/schema.js +178 -10
  165. package/dist/core/slot/types.d.ts +27 -92
  166. package/dist/core/slot/value.d.ts +26 -3
  167. package/dist/core/slot/value.js +89 -57
  168. package/dist/dev-overlay/protocol.d.ts +41 -8
  169. package/dist/fn-context/build-context.d.ts +3 -1
  170. package/dist/fn-context/build-context.js +20 -10
  171. package/dist/fn-context/fake/empty-api.js +9 -28
  172. package/dist/fn-context/fake/index.d.ts +11 -4
  173. package/dist/fn-context/fake/index.js +27 -2
  174. package/dist/fn-context/fn-params.d.ts +6 -0
  175. package/dist/fn-context/fn-params.js +13 -0
  176. package/dist/fn-context/index.d.ts +5 -5
  177. package/dist/fn-context/index.js +4 -4
  178. package/dist/fn-context/log.js +2 -2
  179. package/dist/fn-context/make-ctx.d.ts +11 -0
  180. package/dist/fn-context/make-ctx.js +18 -8
  181. package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
  182. package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
  183. package/dist/fn-context/rpc/index.d.ts +3 -1
  184. package/dist/fn-context/rpc/index.js +3 -1
  185. package/dist/fn-context/rpc/integration/index.d.ts +4 -4
  186. package/dist/fn-context/rpc/integration/index.js +1 -1
  187. package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
  188. package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
  189. package/dist/fn-context/rpc/platform.d.ts +2 -2
  190. package/dist/fn-context/rpc/platform.js +1 -1
  191. package/dist/fn-context/rpc/records.d.ts +78 -0
  192. package/dist/fn-context/rpc/records.js +26 -0
  193. package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
  194. package/dist/fn-context/rpc/trpc-client.js +89 -5
  195. package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
  196. package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
  197. package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
  198. package/dist/fn-context/run-scope.d.ts +4 -0
  199. package/dist/fn-context/run-scope.js +9 -0
  200. package/dist/fn-context/types.d.ts +36 -3
  201. package/dist/index.d.ts +37 -46
  202. package/dist/index.js +33 -33
  203. package/dist/logger.d.ts +7 -0
  204. package/dist/logger.js +41 -0
  205. package/dist/platform.d.ts +76 -0
  206. package/dist/platform.js +56 -0
  207. package/dist/voice-service/actions.d.ts +71 -4
  208. package/dist/voice-service/types.d.ts +42 -2
  209. package/dist/worker.d.ts +10 -0
  210. package/dist/worker.js +10 -0
  211. package/package.json +38 -19
  212. package/dist/builder/compile/compile-agenda.d.ts +0 -15
  213. package/dist/builder/compile/compile-agenda.js +0 -59
  214. package/dist/builder/merge.d.ts +0 -4
  215. package/dist/builder/merge.js +0 -19
  216. package/dist/core/context/db.d.ts +0 -69
  217. package/dist/core/context/db.js +0 -44
  218. package/dist/core/context/docusign.d.ts +0 -134
  219. package/dist/core/context/docusign.js +0 -108
  220. package/dist/core/context/filevine.d.ts +0 -323
  221. package/dist/core/context/filevine.js +0 -254
  222. package/dist/core/context/http.d.ts +0 -9
  223. package/dist/core/context/http.js +0 -4
  224. package/dist/core/context/hubspot.d.ts +0 -250
  225. package/dist/core/context/hubspot.js +0 -191
  226. package/dist/core/context/twilio.d.ts +0 -50
  227. package/dist/core/context/twilio.js +0 -42
  228. package/dist/core/functions/define/case-context.d.ts +0 -14
  229. package/dist/core/functions/define/case-context.js +0 -15
  230. package/dist/core/functions/define/compute.d.ts +0 -7
  231. package/dist/core/functions/define/compute.js +0 -17
  232. package/dist/core/functions/define/custom.d.ts +0 -4
  233. package/dist/core/functions/define/custom.js +0 -8
  234. package/dist/core/functions/define/system.d.ts +0 -7
  235. package/dist/core/functions/define/system.js +0 -12
  236. package/dist/core/slot/deps.d.ts +0 -15
  237. package/dist/core/slot/deps.js +0 -88
  238. package/dist/core/slot/derived.d.ts +0 -32
  239. package/dist/core/slot/derived.js +0 -115
  240. package/dist/core/slot/platform-session-fields.d.ts +0 -38
  241. package/dist/core/slot/platform-session-fields.js +0 -48
  242. package/dist/core/slot/sf-schema.d.ts +0 -23
  243. package/dist/core/slot/sf-schema.js +0 -125
  244. package/dist/core/slot/sf-validate.d.ts +0 -14
  245. package/dist/core/slot/sf-validate.js +0 -132
  246. package/dist/core/slot/snapshot.d.ts +0 -18
  247. package/dist/core/slot/snapshot.js +0 -138
  248. package/dist/core/slot/write.d.ts +0 -41
  249. package/dist/core/slot/write.js +0 -319
  250. package/dist/core/stage/builders.d.ts +0 -36
  251. package/dist/core/stage/builders.js +0 -28
  252. package/dist/core/stage/condition.d.ts +0 -17
  253. package/dist/core/stage/condition.js +0 -198
  254. package/dist/core/stage/drive.d.ts +0 -43
  255. package/dist/core/stage/drive.js +0 -77
  256. package/dist/core/stage/finish-when.d.ts +0 -20
  257. package/dist/core/stage/finish-when.js +0 -82
  258. package/dist/core/stage/flatten.d.ts +0 -27
  259. package/dist/core/stage/flatten.js +0 -464
  260. package/dist/core/stage/index.d.ts +0 -11
  261. package/dist/core/stage/index.js +0 -10
  262. package/dist/core/stage/simulate.d.ts +0 -24
  263. package/dist/core/stage/simulate.js +0 -33
  264. package/dist/core/stage/transfer-fields.d.ts +0 -14
  265. package/dist/core/stage/transfer-fields.js +0 -88
  266. package/dist/core/stage/types.d.ts +0 -177
  267. package/dist/core/stage/types.js +0 -2
  268. package/dist/core/stage/validate.d.ts +0 -11
  269. package/dist/core/stage/validate.js +0 -226
  270. package/dist/core/stage/walk.d.ts +0 -34
  271. package/dist/core/stage/walk.js +0 -96
  272. package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
  273. package/dist/fn-context/system-args.d.ts +0 -6
  274. package/dist/fn-context/system-args.js +0 -14
@@ -1,9 +1,17 @@
1
- import { createTRPCClient, httpLink } from '@trpc/client';
1
+ import { createTRPCClient, httpLink, retryLink } from '@trpc/client';
2
2
  import { platformSurfaces } from '../../core/context/platform-registry.js';
3
- import { defaultHttpApi } from '../../core/context/http.js';
4
3
  import { integrationSurfaceKeys, } from '../../core/context/types.js';
5
4
  import { bindEnvService } from '../../core/context/env.js';
6
- import { REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, formatRuntimeVersion, } from './request-id.js';
5
+ import { CASE_ORCHESTRATOR_TOOL_NAMES, } from '../../core/case-orchestrator/types.js';
6
+ import { getLogger } from '../../logger.js';
7
+ import { REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, formatRuntimeVersion } from './request-id.js';
8
+ const logger = getLogger(['runtime', 'rpc']);
9
+ /**
10
+ * A call the platform turned away before doing anything (its company over the rate, or no free slot:
11
+ * `TOO_MANY_REQUESTS`) is sent again after a growing pause, long enough together to outlast a rate window.
12
+ */
13
+ const BUSY_RETRIES = 5;
14
+ const busyDelayMs = (attempt) => Math.min(500 * 2 ** attempt, 5_000) + Math.floor(Math.random() * 250);
7
15
  function rpcLogger(c, getTags, waitUntil) {
8
16
  const emit = (level, message, extra) => {
9
17
  const pending = c.log.emit.mutate({ level, message, extra, tags: getTags?.() }).catch(() => { });
@@ -48,6 +56,13 @@ function stubSurface(c, meta) {
48
56
  if (meta.surfaceKey === 'envs') {
49
57
  return bindEnvService(stub);
50
58
  }
59
+ if (meta.surfaceKey === 'emails') {
60
+ return {
61
+ ...stub,
62
+ address: typeof meta.config.address === 'string' ? meta.config.address : meta.name,
63
+ provider: meta.config.provider === 'hotmail' ? 'hotmail' : 'gmail',
64
+ };
65
+ }
51
66
  return stub;
52
67
  }
53
68
  function buildSurfaces(c, metas) {
@@ -74,6 +89,56 @@ function buildPlatformApis(c) {
74
89
  // The registry is what guarantees the shape; TS cannot follow it through Object.fromEntries.
75
90
  return Object.fromEntries(surfaces);
76
91
  }
92
+ /** Every Case Orchestrator tool routes through one procedure; the platform validates and executes it. */
93
+ function buildCaseOrchestratorTools(c) {
94
+ const tools = CASE_ORCHESTRATOR_TOOL_NAMES.map((tool) => [
95
+ tool,
96
+ (input, callOptions) => rpcSafe(c.caseOrchestratorTools.invoke.mutate({ tool, input, callKey: callOptions.callKey })),
97
+ ]);
98
+ // The tool registry guarantees the shape; TS cannot follow it through Object.fromEntries.
99
+ return Object.fromEntries(tools);
100
+ }
101
+ /** A records answer: its value, or the error it was refused with (a write's with its code). */
102
+ function unwrapRecords(result) {
103
+ if (result.ok)
104
+ return result.value;
105
+ const error = new Error(result.error.message);
106
+ error.code = result.error.code;
107
+ throw error;
108
+ }
109
+ /**
110
+ * `ctx.api.db` of every function and the Orchestrator (15 §10.15 task 4, §10.16): every table, as a
111
+ * page script and its actions see them, one request per call. Writes are numbered in the order this
112
+ * run makes them; for an Orchestrator Run the same request sent again (a retried request) carries the
113
+ * same key and is not made twice.
114
+ */
115
+ function buildDbApi(c) {
116
+ let writes = 0;
117
+ const db = new Proxy({}, {
118
+ get(_, table) {
119
+ if (typeof table !== 'string')
120
+ return undefined;
121
+ const read = (method) => async (args) => unwrapRecords(await rpcSafe(c.records.read.mutate({ table, method, args: args ?? {} })));
122
+ const write = (method) => async (args) => {
123
+ writes += 1;
124
+ const callKey = `write:${writes}`;
125
+ return unwrapRecords(await rpcSafe(c.records.write.mutate({ table, method, args: args ?? {}, callKey })));
126
+ };
127
+ return {
128
+ $table: table,
129
+ findUnique: read('findUnique'),
130
+ findFirst: read('findFirst'),
131
+ findMany: read('findMany'),
132
+ count: read('count'),
133
+ create: write('create'),
134
+ update: write('update'),
135
+ upsert: write('upsert'),
136
+ delete: write('delete'),
137
+ };
138
+ },
139
+ });
140
+ return { db };
141
+ }
77
142
  export function createRpcApiHost(options) {
78
143
  let client;
79
144
  let lastBaseUrl;
@@ -81,6 +146,10 @@ export function createRpcApiHost(options) {
81
146
  if (!client || lastBaseUrl !== baseUrl) {
82
147
  client = createTRPCClient({
83
148
  links: [
149
+ retryLink({
150
+ retry: ({ error, attempts }) => error.data?.code === 'TOO_MANY_REQUESTS' && attempts <= BUSY_RETRIES,
151
+ retryDelayMs: busyDelayMs,
152
+ }),
84
153
  httpLink({
85
154
  url: baseUrl,
86
155
  headers: async () => {
@@ -103,12 +172,27 @@ export function createRpcApiHost(options) {
103
172
  return {
104
173
  async buildApi(_run) {
105
174
  const c = getClient(options.baseUrl);
106
- const metas = await rpcSafe(c.integration.listBindings.query());
175
+ const started = Date.now();
176
+ logger.info('integration.listSurfaces start', { url: options.baseUrl });
177
+ const metas = await rpcSafe(c.integration.listSurfaces.query());
178
+ logger.info('integration.listSurfaces ok', { durationMs: Date.now() - started, count: metas.length });
179
+ return {
180
+ ...buildPlatformApis(c),
181
+ integration: buildSurfaces(c, metas),
182
+ log: rpcLogger(c, options.getTags, options.waitUntil),
183
+ ...buildDbApi(c),
184
+ };
185
+ },
186
+ async buildCaseOrchestratorApi(_run) {
187
+ const c = getClient(options.baseUrl);
188
+ // A function's api (25 §7), so a function called from the Orchestrator with its ctx works the same.
189
+ const metas = await rpcSafe(c.integration.listSurfaces.query());
107
190
  return {
108
191
  ...buildPlatformApis(c),
109
192
  integration: buildSurfaces(c, metas),
110
193
  log: rpcLogger(c, options.getTags, options.waitUntil),
111
- http: defaultHttpApi(),
194
+ tools: buildCaseOrchestratorTools(c),
195
+ ...buildDbApi(c),
112
196
  };
113
197
  },
114
198
  };
@@ -1,6 +1,6 @@
1
- import type { RunScope } from '../types.js';
1
+ import type { RunClaims } from '../types.js';
2
2
  export type RpcContext = {
3
- run: RunScope;
3
+ run: RunClaims;
4
4
  requestId?: string;
5
5
  runtimeVersion?: string;
6
6
  };
@@ -1,10 +1,14 @@
1
1
  import { createIntegrationRouter } from './integration/index.js';
2
2
  import { createLogRouter } from './log.js';
3
3
  import { createPlatformRouter } from './platform.js';
4
+ import { createRecordsRouter } from './records.js';
5
+ import { createCaseOrchestratorToolsRouter } from './case-orchestrator-tools.js';
4
6
  export declare function createAppRouter(modules: {
5
7
  integration: ReturnType<typeof createIntegrationRouter>;
6
8
  platform: ReturnType<typeof createPlatformRouter>;
7
9
  log: ReturnType<typeof createLogRouter>;
10
+ caseOrchestratorTools: ReturnType<typeof createCaseOrchestratorToolsRouter>;
11
+ records: ReturnType<typeof createRecordsRouter>;
8
12
  }): import("@trpc/server").TRPCBuiltRouter<{
9
13
  ctx: import("./trpc-init.js").RpcContext;
10
14
  meta: object;
@@ -17,10 +21,10 @@ export declare function createAppRouter(modules: {
17
21
  errorShape: import("@trpc/server").TRPCDefaultErrorShape;
18
22
  transformer: false;
19
23
  }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
20
- listBindings: import("@trpc/server").TRPCQueryProcedure<{
24
+ listSurfaces: import("@trpc/server").TRPCQueryProcedure<{
21
25
  input: void;
22
26
  output: {
23
- surfaceKey: "docusigns" | "envs" | "filevines" | "hubspots" | "twilios";
27
+ surfaceKey: "emails" | "envs";
24
28
  target: {
25
29
  kind: "account" | "resource";
26
30
  id: string;
@@ -55,7 +59,7 @@ export declare function createAppRouter(modules: {
55
59
  input: {
56
60
  surface: string;
57
61
  method: string;
58
- params?: Record<string, unknown> | undefined;
62
+ params?: unknown;
59
63
  };
60
64
  output: unknown;
61
65
  meta: object;
@@ -80,6 +84,48 @@ export declare function createAppRouter(modules: {
80
84
  meta: object;
81
85
  }>;
82
86
  }>>;
87
+ caseOrchestratorTools: import("@trpc/server").TRPCBuiltRouter<{
88
+ ctx: import("./trpc-init.js").RpcContext;
89
+ meta: object;
90
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
91
+ transformer: false;
92
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
93
+ invoke: import("@trpc/server").TRPCMutationProcedure<{
94
+ input: {
95
+ tool: string;
96
+ input: unknown;
97
+ callKey: string;
98
+ };
99
+ output: unknown;
100
+ meta: object;
101
+ }>;
102
+ }>>;
103
+ records: import("@trpc/server").TRPCBuiltRouter<{
104
+ ctx: import("./trpc-init.js").RpcContext;
105
+ meta: object;
106
+ errorShape: import("@trpc/server").TRPCDefaultErrorShape;
107
+ transformer: false;
108
+ }, import("@trpc/server").TRPCDecorateCreateRouterOptions<{
109
+ read: import("@trpc/server").TRPCMutationProcedure<{
110
+ input: {
111
+ table: string;
112
+ method: "count" | "findFirst" | "findMany" | "findUnique";
113
+ args: unknown;
114
+ };
115
+ output: import("./records.js").RecordsResult;
116
+ meta: object;
117
+ }>;
118
+ write: import("@trpc/server").TRPCMutationProcedure<{
119
+ input: {
120
+ table: string;
121
+ method: "create" | "delete" | "update" | "upsert";
122
+ args: unknown;
123
+ callKey: string;
124
+ };
125
+ output: import("./records.js").RecordsResult;
126
+ meta: object;
127
+ }>;
128
+ }>>;
83
129
  }>>;
84
130
  export type AppRouter = ReturnType<typeof createAppRouter>;
85
131
  //# sourceMappingURL=trpc-router-factory.d.ts.map
@@ -4,6 +4,8 @@ export function createAppRouter(modules) {
4
4
  integration: modules.integration,
5
5
  platform: modules.platform,
6
6
  log: modules.log,
7
+ caseOrchestratorTools: modules.caseOrchestratorTools,
8
+ records: modules.records,
7
9
  });
8
10
  }
9
11
  //# sourceMappingURL=trpc-router-factory.js.map
@@ -0,0 +1,4 @@
1
+ import type { CaseOrchestratorRunScope, RunClaims } from './types.js';
2
+ /** The Case Orchestrator scope of a run, or null when it is not a complete Case Orchestrator run. */
3
+ export declare function asCaseOrchestratorRun(run: RunClaims): CaseOrchestratorRunScope | null;
4
+ //# sourceMappingURL=run-scope.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { ORCHESTRATOR_ENTRY } from '../core/case-orchestrator/types.js';
2
+ /** The Case Orchestrator scope of a run, or null when it is not a complete Case Orchestrator run. */
3
+ export function asCaseOrchestratorRun(run) {
4
+ const scoped = run;
5
+ if (run.entry !== ORCHESTRATOR_ENTRY || !scoped.instanceId || !scoped.agentRunId)
6
+ return null;
7
+ return run;
8
+ }
9
+ //# sourceMappingURL=run-scope.js.map
@@ -1,17 +1,50 @@
1
+ import type { ORCHESTRATOR_ENTRY, CaseOrchestratorApi, CaseOrchestratorContext } from '../core/case-orchestrator/types.js';
1
2
  import type { SystemContext } from '../core/context/types.js';
2
3
  /** Alias for {@link SystemContext} (08 ActionContext shape). */
3
4
  export type ActionContext = SystemContext;
4
- /** JSON-serializable data slice of ActionContext (no `api`). */
5
- export type ActionDataSlice = Pick<ActionContext, 'time' | 'meta' | 'config'>;
5
+ /**
6
+ * JSON-serializable data slice of ActionContext (no `api`, no `time.format` / `time.day`: added where the
7
+ * function runs). Its ids are plain strings on the wire; the function's `ctx.meta` types them.
8
+ */
9
+ export type ActionDataSlice = Pick<ActionContext, 'config'> & {
10
+ time: Omit<ActionContext['time'], 'format' | 'day'>;
11
+ meta: ActionContext['meta'];
12
+ };
6
13
  /** Identity / scope for a single function invocation (ApiHost may key caches on this). */
7
14
  export type RunScope = {
8
15
  companyId: string;
9
16
  environmentId: string;
10
- sequenceId: string;
11
17
  entry: string;
18
+ /** The instance a case-bound run works on; absent on nocase runs. */
19
+ instanceId?: string;
20
+ /**
21
+ * The AI run (`AgentRun`) that called the function, with `instanceId` the case it is on (21 §6.5): what
22
+ * the function writes back through the platform is that run's. Set by the platform only.
23
+ */
24
+ agentRunId?: string;
25
+ /**
26
+ * The published company build (`ReleaseBuildBatch`) the run started on: one run uses one build (22 §5),
27
+ * so `ctx.api` reads the schema from it, not from whatever release is live by then. Absent on the serve
28
+ * overlay, which is not pinned. Set by the platform only.
29
+ */
30
+ buildId?: string;
12
31
  };
13
32
  /** Who fulfills `ctx.api` (Fake local vs Rpc remote). */
14
33
  export type ApiHost = {
15
34
  buildApi(run: RunScope): Promise<ActionContext['api']>;
16
35
  };
36
+ /** `ctx` of `orchestrator` before the host adds `params`. */
37
+ export type CaseOrchestratorActionContext = Omit<CaseOrchestratorContext, 'params'>;
38
+ /** Who fulfills the Case Orchestrator's `ctx.api` (Fake local vs Rpc remote). */
39
+ export type CaseOrchestratorApiHost = {
40
+ buildCaseOrchestratorApi(run: RunScope): Promise<CaseOrchestratorApi>;
41
+ };
42
+ /** Run scope of an Orchestrator call: the instance it is limited to and its active run (`AgentRun`). */
43
+ export type CaseOrchestratorRunScope = RunScope & {
44
+ entry: typeof ORCHESTRATOR_ENTRY;
45
+ instanceId: string;
46
+ agentRunId: string;
47
+ };
48
+ /** A verified run token's scope; narrow with {@link asCaseOrchestratorRun}. */
49
+ export type RunClaims = RunScope | CaseOrchestratorRunScope;
17
50
  //# sourceMappingURL=types.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,47 +1,38 @@
1
- export type { CompanyDerivedFieldDef, CompanyFieldDef, CompanyNormalFieldDef, CompanySchema, CompanyTableDef, DataType, EffectiveFieldDef, EffectiveSchema, EffectiveTableDef, FieldOverride, SequenceCompanyTableView, SequenceSlots, NormalFieldCore, SessionTableDef, } from './core/slot/schema.js';
2
- export { ROW_ID_FIELD, idField, idFieldCore } from './core/slot/schema.js';
3
- export { integrationSurfaceKeys } from './core/context/types.js';
4
- export { idRef } from './core/slot/id-ref.js';
5
- export type { HubspotApi, HubspotAssociationListOutput, HubspotCreateContactInput, HubspotCreateContactOutput, HubspotCreateDealInput, HubspotCreateDealOutput, HubspotCreateNoteInput, HubspotCreateTaskInput, HubspotEngagementOutput, HubspotGetAssociatedContactsInput, HubspotGetAssociatedDealsInput, HubspotGetContactInput, HubspotGetContactOutput, HubspotGetCrmUrlInput, HubspotGetCrmUrlOutput, HubspotGetDealInput, HubspotGetDealOutput, HubspotGetOwnerInput, HubspotGetOwnerOutput, HubspotLogCallInput, HubspotLogEmailInput, HubspotLogSmsInput, HubspotRecord, HubspotSearchContactsInput, HubspotSearchContactsOutput, HubspotService, HubspotUpdateContactInput, HubspotUpdateContactOutput, HubspotUpdateDealInput, HubspotUpdateDealOutput, HubspotUpsertContactInput, HubspotUpsertContactOutput, } from './core/context/hubspot.js';
6
- export type { DocusignApi, DocusignCreateEnvelopeFromTemplateInput, DocusignCreateEnvelopeFromTemplateOutput, DocusignCreateRecipientViewFromTemplateInput, DocusignCreateRecipientViewFromTemplateOutput, DocusignEnvelopeIdInput, DocusignGetEnvelopeRecipientsOutput, DocusignGetEnvelopeSigningStatusOutput, DocusignGetEnvelopeStatusOutput, DocusignListRecentEnvelopesInput, DocusignListRecentEnvelopesOutput, DocusignListTemplatesOutput, DocusignRecentEnvelope, DocusignRecipient, DocusignSearchEnvelopesByEmailInput, DocusignSearchEnvelopesByEmailOutput, DocusignService, } from './core/context/docusign.js';
7
- export type { FilevineAddHashtagToProjectInput, FilevineAddHashtagToProjectOutput, FilevineApi, FilevineCollectionItemInput, FilevineCommentOutput, FilevineCreateCommentInput, FilevineCreateContactInput, FilevineCreateContactOutput, FilevineCreateNoteInput, FilevineCreateNoteWithCommentInput, FilevineCreateNoteWithCommentOutput, FilevineCreateProjectCollectionItemInput, FilevineCreateProjectCollectionItemOutput, FilevineCreateProjectInput, FilevineCreateProjectOutput, FilevineDeleteProjectCollectionItemInput, FilevineDeleteProjectCollectionItemOutput, FilevineFolder, FilevineGetAssociatedProjectsInput, FilevineGetAssociatedProjectsOutput, FilevineGetContactInput, FilevineGetContactOutput, FilevineGetCrmUrlInput, FilevineGetCrmUrlOutput, FilevineGetProjectCollectionItemInput, FilevineGetProjectCollectionItemOutput, FilevineGetProjectCollectionItemsInput, FilevineGetProjectCollectionItemsOutput, FilevineGetProjectFoldersInput, FilevineGetProjectFoldersOutput, FilevineGetProjectInput, FilevineGetProjectOutput, FilevineLogCallInput, FilevineLogEmailInput, FilevineLogSmsInput, FilevineNoteOutput, FilevineProperties, FilevineRecord, FilevineSearchContactsInput, FilevineSearchContactsOutput, FilevineService, FilevineUpdateContactInput, FilevineUpdateContactOutput, FilevineUpdateProjectCollectionItemInput, FilevineUpdateProjectCollectionItemOutput, FilevineUpdateProjectInput, FilevineUpdateProjectOutput, FilevineUploadDocumentInput, FilevineUploadDocumentOutput, } from './core/context/filevine.js';
8
- export type { CaseContext, ContactApi, BoundIntegrationMeta, EnvApi, EnvService, FieldState, HttpApi, IntegrationAccountFields, IntegrationApi, IntegrationStub, IntegrationSurfaceKey, IntegrationTarget, TwilioApi, TwilioCreateCallInput, TwilioCreateCallOutput, TwilioIncomingNumber, TwilioListIncomingNumbersOutput, TwilioSendSmsInput, TwilioSendSmsOutput, TwilioService, Logger, MakeCtxOverrides, Slots, SystemContext, Writes, } from './core/context/types.js';
9
- export { CONTACT_PAGE_LIMIT_MAX, contactListInput, contactListOutput, contactMockService, contactSummary, contactSurface, type ContactListParams, type ContactListResult, type ContactSummary, } from './core/context/contact.js';
10
- export { dbDelInput, dbDelOutput, dbGetInput, dbGetOutput, dbMockService, dbSetInput, dbSetOutput, dbSurface, KV_KEY_MAX, KV_TTL_SECONDS_MAX, KV_VALUE_MAX, type DbApi, type DbDelInput, type DbDelOutput, type DbGetInput, type DbGetOutput, type DbSetInput, type DbSetOutput, } from './core/context/db.js';
11
- export { bindEnvService, envMockService, readEnvGet } from './core/context/env.js';
12
- export type { AnyPlatformSurface, PlatformApiShape, PlatformImpl, PlatformSurface } from './core/context/platform.js';
13
- export { platformSurfaces, type PlatformApis, type PlatformSurfaceKey } from './core/context/platform-registry.js';
14
- export { defaultHttpApi } from './core/context/http.js';
15
- export { hubspotAssociationListOutput, hubspotCreateContactInput, hubspotCreateContactOutput, hubspotCreateDealInput, hubspotCreateDealOutput, hubspotCreateNoteInput, hubspotCreateTaskInput, hubspotEngagementOutput, hubspotGetAssociatedContactsInput, hubspotGetAssociatedDealsInput, hubspotGetContactInput, hubspotGetContactOutput, hubspotGetCrmUrlInput, hubspotGetCrmUrlOutput, hubspotGetDealInput, hubspotGetDealOutput, hubspotGetOwnerInput, hubspotGetOwnerOutput, hubspotLogCallInput, hubspotLogEmailInput, hubspotLogSmsInput, hubspotMockService, hubspotSearchContactsInput, hubspotSearchContactsOutput, hubspotUpdateContactInput, hubspotUpdateContactOutput, hubspotUpdateDealInput, hubspotUpdateDealOutput, hubspotUpsertContactInput, hubspotUpsertContactOutput, } from './core/context/hubspot.js';
16
- export { docusignCreateEnvelopeFromTemplateInput, docusignCreateEnvelopeFromTemplateOutput, docusignCreateRecipientViewFromTemplateInput, docusignCreateRecipientViewFromTemplateOutput, docusignEnvelopeIdInput, docusignGetEnvelopeRecipientsOutput, docusignGetEnvelopeSigningStatusOutput, docusignGetEnvelopeStatusOutput, docusignListRecentEnvelopesInput, docusignListRecentEnvelopesOutput, docusignListTemplatesOutput, docusignMockService, docusignSearchEnvelopesByEmailInput, docusignSearchEnvelopesByEmailOutput, } from './core/context/docusign.js';
17
- export { filevineAddHashtagToProjectInput, filevineAddHashtagToProjectOutput, filevineCollectionItemInput, filevineCommentOutput, filevineCreateCommentInput, filevineCreateContactInput, filevineCreateContactOutput, filevineCreateNoteInput, filevineCreateNoteWithCommentInput, filevineCreateNoteWithCommentOutput, filevineCreateProjectCollectionItemInput, filevineCreateProjectCollectionItemOutput, filevineCreateProjectInput, filevineCreateProjectOutput, filevineDeleteProjectCollectionItemInput, filevineDeleteProjectCollectionItemOutput, filevineGetAssociatedProjectsInput, filevineGetAssociatedProjectsOutput, filevineGetContactInput, filevineGetContactOutput, filevineGetCrmUrlInput, filevineGetCrmUrlOutput, filevineGetProjectCollectionItemInput, filevineGetProjectCollectionItemOutput, filevineGetProjectCollectionItemsInput, filevineGetProjectCollectionItemsOutput, filevineGetProjectFoldersInput, filevineGetProjectFoldersOutput, filevineGetProjectInput, filevineGetProjectOutput, filevineLogCallInput, filevineLogEmailInput, filevineLogSmsInput, filevineMockService, filevineNoteOutput, filevineSearchContactsInput, filevineSearchContactsOutput, filevineUpdateContactInput, filevineUpdateContactOutput, filevineUpdateProjectCollectionItemInput, filevineUpdateProjectCollectionItemOutput, filevineUpdateProjectInput, filevineUpdateProjectOutput, filevineUploadDocumentInput, filevineUploadDocumentOutput, } from './core/context/filevine.js';
18
- export { twilioCreateCallInput, twilioCreateCallOutput, twilioIncomingNumber, twilioListIncomingNumbersOutput, twilioMockService, twilioSendSmsInput, twilioSendSmsOutput, } from './core/context/twilio.js';
19
- export type { ApplyWritesOptions, ApplyWritesResult, CompiledSlotSchema, ExtractedField, FieldHistoryEntry, FieldValue, HistoryAppend, MultiRowProjection, MultiRowRecord, MultiRowTableData, RecomputeResult, RuntimeDerivedFieldDef, RuntimeFieldDef, RuntimeNormalFieldDef, RuntimeSlotsSnapshot, RuntimeTableDef, SingleRowProjection, SingleRowTableData, SlotCurrent, SlotFillingOutput, SlotFillingValidateResult, TableData, UpdatedBy, ValidationIssue, ValidationResult, WriteSource, } from './core/slot/types.js';
20
- export type { FuncRef } from './core/functions/func-ref.js';
21
- export { resolveFuncName } from './core/functions/func-ref.js';
22
- export type { RuntimePackageSource, SequenceBuild } from './builder/types.js';
23
- export type { CaseContextViewRegistryEntry, ComputeFn, CustomFn, DefinedFunc, FuncMap, FuncOptions, FuncRegistration, FunctionCall, FunctionCtx, FunctionRegistry, FunctionRegistryEntry, GetFirstMessageFunction, GetFirstMessageParams, SystemFuncMap, WebHookFunction, WebHookFunctionParams, } from './core/functions/types.js';
24
- export { toFuncRegistrations } from './core/functions/types.js';
25
- export { toCaseContextViewRegistry, toFunctionRegistry } from './builder/compile/registry.js';
26
- export { compileFunctionCode } from './builder/compile/function-code.js';
27
- export { compileAll, compileSequence, runtimePackageSource, runtimePackageVersion, snapshotCompanySchema, type CompileSequenceOptions, type CompileSequenceResult, } from './builder/compile/compile-sequence.js';
28
- export { compileSequenceAgendas, fatalAgendaIssues } from './builder/compile/compile-agenda.js';
29
- export { loadSequenceCaseContextView, loadSequenceFunctions } from './builder/load.js';
30
- export { findTsModule } from './builder/paths.js';
31
- export type { OverlayClientMessage, OverlayExecuteMessage, OverlayExecuteResultMessage, OverlayAuthErrorMessage, OverlayAuthMessage, OverlayAuthOkMessage, OverlayMessage, OverlayPushMessage, OverlayReplacedMessage, OverlayServerMessage, } from './dev-overlay/protocol.js';
32
- export { encodeOverlayMessage, OVERLAY_REPLACED_CLOSE_CODE, parseOverlayMessage } from './dev-overlay/protocol.js';
33
- export { buildActionContext, bindLogMeta, createFakeApiHost, defaultPlatformApis, emptyIntegration, createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, makeCtx, makeCtxAsync, noopLog, type ActionContext, type ActionDataSlice, type ApiHost, type FakeApiHostOptions, type RunScope, } from './fn-context/index.js';
34
- export { createAppRouter, createIntegrationRouter, createListBindingsProcedure, createLogRouter, createPlatformRouter, isRpcCodedError, parseScriptInput, ScriptInputError, type AppRouter, type RpcCodedError, type RpcErrorCode, type IntegrationInvokeHandler, type LogEmitHandler, type PlatformInvokeHandler, type RpcContext, } from './fn-context/rpc/index.js';
35
- export * from './compute-host/index.js';
36
- export { defineBoolComputeFunc, defineComputeFunc } from './core/functions/define/compute.js';
37
- export { defineCaseContext, resolveCaseContextViewFn, type CaseContextOf, type CaseContextViewFn, type DefinedCaseContextView, } from './core/functions/define/case-context.js';
38
- export { defineCustomFunc } from './core/functions/define/custom.js';
39
- export { defineSystemFunc } from './core/functions/define/system.js';
40
- export { mergeEffectiveSchema } from './builder/merge.js';
41
- export { emitCaseContextSource, emitSlotsSource } from './builder/codegen/emit.js';
42
- export { affectedDerivedFields, applyFieldPatch, applyFieldPatchAndRecompute, applySlotFilling, applySlotFillingAndRecompute, applyWrites, applyWritesAndRecompute, buildDependencyGraph, buildFieldCatalog, buildSlotFillingJsonSchema, cloneSnapshot, commitFieldWrite, compiledTableEntries, compileSlotSchema, emptyFieldValue, emptyMultiRow, emptySlotRow, fieldChanged, formatFieldPath, getCompiledTable, getFieldState, getFieldValue, getLastThreeValues, getRowField, getSingleField, getSnapshotTable, isFieldValue, isReservedTableName, isResolved, isRowIdField, mintRowId, SNAPSHOT_CURRENT_KEY, isSnapshotSingleRow, isValidDataTypeValue, listConversationFields, makeFieldValue, markAskedUnknown, parseFieldPath, recomputeDerived, requireFieldPath, rowValueEntries, slotFieldEntries, slotFieldNames, snapshotFrom, toEffectiveSchema, toHistoryEntry, validateBareValue, validateExtractedField, validateFieldRefs, validateSlotFillingOutput, } from './core/slot/index.js';
43
- export type { ApplySlotFillingOptions, DependencyGraphResult, FieldPatchInput, FieldPath, ParsedFieldPath, RecomputeOptions, SfSchemaOptions, SlotRow, SnapshotSeed, ValidateSlotFillingOptions, } from './core/slot/index.js';
44
- export type { ActionBlock, ActionNode, AgendaBlock, AgendaConfig, AgendaHeader, AgendaTree, ApplyWhen, AuthoringNode, AuthoringWhen, BranchNode, Channel, CompiledActionBlock, CompiledAgenda, CompiledAgendaBlock, CompiledTopicBlock, CompiledTransferBlock, CompiledWhen, Condition, ConditionEval, FirstMessage, FinishWhen, FinishWhenEval, FlatActionItem, FlatAgendaItem, FlatNodePlacement, FlatTopicItem, FlatTransferItem, FlattenOptions, FlattenResult, Interrupt, SequenceAgendas, JsonRulesCondition, NodePlacement, OnNoProgress, OtherwiseSentinel, Placement, SectionNode, SectionPlacement, SimulateResult, SimulatedItem, SimulatedItemStatus, SwitchOnNode, TopicBlock, TopicNode, TransferBlock, TransferNode, ValidateAgendaOptions, WalkDecision, WalkHitReason, WalkOptions, WalkResult, WalkSkip, WalkSkipReason, When, WhenEval, AdvanceResult, StageDriveHooks, StageDriveResult, StageDriveState, } from './core/stage/index.js';
45
- export { DEFAULT_MAX_ACTIONS_PER_TURN, LAST_TRANSFER_RESULT_FIELD, action, advanceAgenda, agenda, andCompiledWhen, branch, collectJsonRulesFacts, collectTransferBlocks, compileAuthoringWhen, compileFinishWhen, compileWhen, driveAgenda, evaluateFinishWhen, evaluateJsonRules, evaluateWhen, extractBlocksFromTree, extractTemplateFields, finishWhenFields, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, isAgendaTree, isSequenceAgendas, isOtherwise, jsonRules, looksLikeJsonRules, normalizeJsonRules, normalizeSequenceAgendas, notAnyWhen, otherwise, parseJsonRules, registerTransferSessionFields, section, simulateAgenda, switchOn, topic, transfer, transferFieldKey, transferResultField, transferWrites, treeToPlacements, unresolvedFinishWhenFields, validateCompiledAgenda, walkAgenda, watchdogHint, whenFields, } from './core/stage/index.js';
46
- export * from './voice-service/index.js';
1
+ /**
2
+ * The company API: everything company code may import from `@superpanel-sdk/runtime`, and nothing else
3
+ * (09-runtime-compat §6). Company code runs in three places: the compile's Node, the Worker, and the
4
+ * page's QuickJS sandbox. So what is here behaves the same in all three: it imports no package and no
5
+ * Node module, and no module it reaches does work at load. The compile bundles it into each code string
6
+ * as it is; there is no stand-in.
7
+ *
8
+ * Named exports only, from the module that defines each: an `export *` lets whatever a module adds
9
+ * reach company code. `company-api.test.ts` holds the list and checks the entry stays pure. The
10
+ * platform imports `./platform` (`platform.ts`), which this package resolves only under the
11
+ * `superpanel-platform` condition.
12
+ */
13
+ export { defineSequence, defineVariables, json, type JsonVariableType, type SequenceDefinition, type VariableDecl, type VariableDecls, type VariablesOf, } from './core/sequence/define.js';
14
+ export { defineCaseFunc } from './core/functions/define/case.js';
15
+ export { defineNoCaseFunc } from './core/functions/define/no-case.js';
16
+ export { bindDefines, type BoundDefines } from './core/functions/define/bind.js';
17
+ export { defineEvents, defineWebhook } from './core/functions/define/events.js';
18
+ export { defineSchedules, type Schedules } from './core/functions/schedules.js';
19
+ export type { FunctionCtx } from './core/functions/types.js';
20
+ export type { WebhookHandler } from './core/functions/events.js';
21
+ export { choose, createRow, defineAction, definePage, deleteRow, end, field, refField, lastActionRun, perform, runFunction, schemaField, tried, type PageChannel, type PageFaqEntry, type PageRuns, } from './core/page/define.js';
22
+ export type { Id, RowOf, TypedDb, TypedPageContext, TypedPageModule, TypedReadDb, } from './core/page/typed.js';
23
+ export { followUps } from './core/case-orchestrator/follow-ups.js';
24
+ export { render } from './core/case-orchestrator/render.js';
25
+ export { tools } from './core/case-orchestrator/tools.js';
26
+ export type { CaseActivity, CaseInput, CaseOrchestrator, CaseOrchestratorContacts, ContactActionView, RunTrigger, ScheduledActionView, } from './core/case-orchestrator/types.js';
27
+ export type { CompanyResolve, Resolve } from './core/party/types.js';
28
+ export { contactScheduleHours, everyDay, nextContactTime, withinContactHours, type ContactHours, type ContactHoursRange, type ContactHoursWeekday, } from './core/case-orchestrator/contact-hours.js';
29
+ export { randomTimeBetween } from './core/case-orchestrator/time.js';
30
+ export { contactTimezone } from './core/slot/contact-timezone.js';
31
+ export type { OfficeHours } from './core/office-hours/index.js';
32
+ export { PLATFORM_CONTACT_FIELDS, PLATFORM_SESSION_FIELDS } from './core/slot/platform-fields.js';
33
+ export { lookupRef, parentRef } from './core/slot/id-ref.js';
34
+ export type { CompanySchema, ContactSchedule, SessionSchema } from './core/slot/schema.js';
35
+ export type { CellBinding, RowRef } from './core/slot/binding.js';
36
+ export type { FieldValue } from './core/slot/types.js';
37
+ export type { EnvApi } from './core/context/env.js';
47
38
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,34 +1,34 @@
1
- export { ROW_ID_FIELD, idField, idFieldCore } from './core/slot/schema.js';
2
- export { integrationSurfaceKeys } from './core/context/types.js';
3
- export { idRef } from './core/slot/id-ref.js';
4
- export { CONTACT_PAGE_LIMIT_MAX, contactListInput, contactListOutput, contactMockService, contactSummary, contactSurface, } from './core/context/contact.js';
5
- export { dbDelInput, dbDelOutput, dbGetInput, dbGetOutput, dbMockService, dbSetInput, dbSetOutput, dbSurface, KV_KEY_MAX, KV_TTL_SECONDS_MAX, KV_VALUE_MAX, } from './core/context/db.js';
6
- export { bindEnvService, envMockService, readEnvGet } from './core/context/env.js';
7
- export { platformSurfaces } from './core/context/platform-registry.js';
8
- export { defaultHttpApi } from './core/context/http.js';
9
- export { hubspotAssociationListOutput, hubspotCreateContactInput, hubspotCreateContactOutput, hubspotCreateDealInput, hubspotCreateDealOutput, hubspotCreateNoteInput, hubspotCreateTaskInput, hubspotEngagementOutput, hubspotGetAssociatedContactsInput, hubspotGetAssociatedDealsInput, hubspotGetContactInput, hubspotGetContactOutput, hubspotGetCrmUrlInput, hubspotGetCrmUrlOutput, hubspotGetDealInput, hubspotGetDealOutput, hubspotGetOwnerInput, hubspotGetOwnerOutput, hubspotLogCallInput, hubspotLogEmailInput, hubspotLogSmsInput, hubspotMockService, hubspotSearchContactsInput, hubspotSearchContactsOutput, hubspotUpdateContactInput, hubspotUpdateContactOutput, hubspotUpdateDealInput, hubspotUpdateDealOutput, hubspotUpsertContactInput, hubspotUpsertContactOutput, } from './core/context/hubspot.js';
10
- export { docusignCreateEnvelopeFromTemplateInput, docusignCreateEnvelopeFromTemplateOutput, docusignCreateRecipientViewFromTemplateInput, docusignCreateRecipientViewFromTemplateOutput, docusignEnvelopeIdInput, docusignGetEnvelopeRecipientsOutput, docusignGetEnvelopeSigningStatusOutput, docusignGetEnvelopeStatusOutput, docusignListRecentEnvelopesInput, docusignListRecentEnvelopesOutput, docusignListTemplatesOutput, docusignMockService, docusignSearchEnvelopesByEmailInput, docusignSearchEnvelopesByEmailOutput, } from './core/context/docusign.js';
11
- export { filevineAddHashtagToProjectInput, filevineAddHashtagToProjectOutput, filevineCollectionItemInput, filevineCommentOutput, filevineCreateCommentInput, filevineCreateContactInput, filevineCreateContactOutput, filevineCreateNoteInput, filevineCreateNoteWithCommentInput, filevineCreateNoteWithCommentOutput, filevineCreateProjectCollectionItemInput, filevineCreateProjectCollectionItemOutput, filevineCreateProjectInput, filevineCreateProjectOutput, filevineDeleteProjectCollectionItemInput, filevineDeleteProjectCollectionItemOutput, filevineGetAssociatedProjectsInput, filevineGetAssociatedProjectsOutput, filevineGetContactInput, filevineGetContactOutput, filevineGetCrmUrlInput, filevineGetCrmUrlOutput, filevineGetProjectCollectionItemInput, filevineGetProjectCollectionItemOutput, filevineGetProjectCollectionItemsInput, filevineGetProjectCollectionItemsOutput, filevineGetProjectFoldersInput, filevineGetProjectFoldersOutput, filevineGetProjectInput, filevineGetProjectOutput, filevineLogCallInput, filevineLogEmailInput, filevineLogSmsInput, filevineMockService, filevineNoteOutput, filevineSearchContactsInput, filevineSearchContactsOutput, filevineUpdateContactInput, filevineUpdateContactOutput, filevineUpdateProjectCollectionItemInput, filevineUpdateProjectCollectionItemOutput, filevineUpdateProjectInput, filevineUpdateProjectOutput, filevineUploadDocumentInput, filevineUploadDocumentOutput, } from './core/context/filevine.js';
12
- export { twilioCreateCallInput, twilioCreateCallOutput, twilioIncomingNumber, twilioListIncomingNumbersOutput, twilioMockService, twilioSendSmsInput, twilioSendSmsOutput, } from './core/context/twilio.js';
13
- export { resolveFuncName } from './core/functions/func-ref.js';
14
- export { toFuncRegistrations } from './core/functions/types.js';
15
- export { toCaseContextViewRegistry, toFunctionRegistry } from './builder/compile/registry.js';
16
- export { compileFunctionCode } from './builder/compile/function-code.js';
17
- export { compileAll, compileSequence, runtimePackageSource, runtimePackageVersion, snapshotCompanySchema, } from './builder/compile/compile-sequence.js';
18
- export { compileSequenceAgendas, fatalAgendaIssues } from './builder/compile/compile-agenda.js';
19
- export { loadSequenceCaseContextView, loadSequenceFunctions } from './builder/load.js';
20
- export { findTsModule } from './builder/paths.js';
21
- export { encodeOverlayMessage, OVERLAY_REPLACED_CLOSE_CODE, parseOverlayMessage } from './dev-overlay/protocol.js';
22
- export { buildActionContext, bindLogMeta, createFakeApiHost, defaultPlatformApis, emptyIntegration, createRpcApiHost, LOG_TAGS_HEADER, REQUEST_ID_HEADER, RUNTIME_VERSION_HEADER, encodeLogTagsHeader, formatRuntimeVersion, readLogTagsHeader, readRequestIdHeader, readRuntimeVersionHeader, makeCtx, makeCtxAsync, noopLog, } from './fn-context/index.js';
23
- export { createAppRouter, createIntegrationRouter, createListBindingsProcedure, createLogRouter, createPlatformRouter, isRpcCodedError, parseScriptInput, ScriptInputError, } from './fn-context/rpc/index.js';
24
- export * from './compute-host/index.js';
25
- export { defineBoolComputeFunc, defineComputeFunc } from './core/functions/define/compute.js';
26
- export { defineCaseContext, resolveCaseContextViewFn, } from './core/functions/define/case-context.js';
27
- export { defineCustomFunc } from './core/functions/define/custom.js';
28
- export { defineSystemFunc } from './core/functions/define/system.js';
29
- export { mergeEffectiveSchema } from './builder/merge.js';
30
- export { emitCaseContextSource, emitSlotsSource } from './builder/codegen/emit.js';
31
- export { affectedDerivedFields, applyFieldPatch, applyFieldPatchAndRecompute, applySlotFilling, applySlotFillingAndRecompute, applyWrites, applyWritesAndRecompute, buildDependencyGraph, buildFieldCatalog, buildSlotFillingJsonSchema, cloneSnapshot, commitFieldWrite, compiledTableEntries, compileSlotSchema, emptyFieldValue, emptyMultiRow, emptySlotRow, fieldChanged, formatFieldPath, getCompiledTable, getFieldState, getFieldValue, getLastThreeValues, getRowField, getSingleField, getSnapshotTable, isFieldValue, isReservedTableName, isResolved, isRowIdField, mintRowId, SNAPSHOT_CURRENT_KEY, isSnapshotSingleRow, isValidDataTypeValue, listConversationFields, makeFieldValue, markAskedUnknown, parseFieldPath, recomputeDerived, requireFieldPath, rowValueEntries, slotFieldEntries, slotFieldNames, snapshotFrom, toEffectiveSchema, toHistoryEntry, validateBareValue, validateExtractedField, validateFieldRefs, validateSlotFillingOutput, } from './core/slot/index.js';
32
- export { DEFAULT_MAX_ACTIONS_PER_TURN, LAST_TRANSFER_RESULT_FIELD, action, advanceAgenda, agenda, andCompiledWhen, branch, collectJsonRulesFacts, collectTransferBlocks, compileAuthoringWhen, compileFinishWhen, compileWhen, driveAgenda, evaluateFinishWhen, evaluateJsonRules, evaluateWhen, extractBlocksFromTree, extractTemplateFields, finishWhenFields, flattenAgendaConfig, flattenAgendaPlacements, flattenAgendaTree, isAgendaTree, isSequenceAgendas, isOtherwise, jsonRules, looksLikeJsonRules, normalizeJsonRules, normalizeSequenceAgendas, notAnyWhen, otherwise, parseJsonRules, registerTransferSessionFields, section, simulateAgenda, switchOn, topic, transfer, transferFieldKey, transferResultField, transferWrites, treeToPlacements, unresolvedFinishWhenFields, validateCompiledAgenda, walkAgenda, watchdogHint, whenFields, } from './core/stage/index.js';
33
- export * from './voice-service/index.js';
1
+ /**
2
+ * The company API: everything company code may import from `@superpanel-sdk/runtime`, and nothing else
3
+ * (09-runtime-compat §6). Company code runs in three places: the compile's Node, the Worker, and the
4
+ * page's QuickJS sandbox. So what is here behaves the same in all three: it imports no package and no
5
+ * Node module, and no module it reaches does work at load. The compile bundles it into each code string
6
+ * as it is; there is no stand-in.
7
+ *
8
+ * Named exports only, from the module that defines each: an `export *` lets whatever a module adds
9
+ * reach company code. `company-api.test.ts` holds the list and checks the entry stays pure. The
10
+ * platform imports `./platform` (`platform.ts`), which this package resolves only under the
11
+ * `superpanel-platform` condition.
12
+ */
13
+ // Sequence declarations: `index.ts`, `variables.ts`.
14
+ export { defineSequence, defineVariables, json, } from './core/sequence/define.js';
15
+ // Functions, events, the webhook and schedules (the sequence's `__gen` binds them to its tables).
16
+ export { defineCaseFunc } from './core/functions/define/case.js';
17
+ export { defineNoCaseFunc } from './core/functions/define/no-case.js';
18
+ export { bindDefines } from './core/functions/define/bind.js';
19
+ export { defineEvents, defineWebhook } from './core/functions/define/events.js';
20
+ export { defineSchedules } from './core/functions/schedules.js';
21
+ // The page (the sequence's `__gen` binds them to its tables).
22
+ export { choose, createRow, defineAction, definePage, deleteRow, end, field, refField, lastActionRun, perform, runFunction, schemaField, tried, } from './core/page/define.js';
23
+ // The Orchestrator.
24
+ export { followUps } from './core/case-orchestrator/follow-ups.js';
25
+ export { render } from './core/case-orchestrator/render.js';
26
+ export { tools } from './core/case-orchestrator/tools.js';
27
+ // When a contact may be reached, and in which time zone.
28
+ export { contactScheduleHours, everyDay, nextContactTime, withinContactHours, } from './core/case-orchestrator/contact-hours.js';
29
+ export { randomTimeBetween } from './core/case-orchestrator/time.js';
30
+ export { contactTimezone } from './core/slot/contact-timezone.js';
31
+ // The company schema: `schema/`.
32
+ export { PLATFORM_CONTACT_FIELDS, PLATFORM_SESSION_FIELDS } from './core/slot/platform-fields.js';
33
+ export { lookupRef, parentRef } from './core/slot/id-ref.js';
34
34
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ export declare function getLogger(tags?: readonly string[]): {
2
+ log(...args: unknown[]): void;
3
+ info(...args: unknown[]): void;
4
+ warn(...args: unknown[]): void;
5
+ error(...args: unknown[]): void;
6
+ };
7
+ //# sourceMappingURL=logger.d.ts.map
package/dist/logger.js ADDED
@@ -0,0 +1,41 @@
1
+ function formatArgument(value) {
2
+ if (value instanceof Error)
3
+ return value.stack ?? value.message;
4
+ if (typeof value === 'string')
5
+ return value;
6
+ if (typeof value !== 'object' || value === null)
7
+ return String(value);
8
+ try {
9
+ return JSON.stringify(value);
10
+ }
11
+ catch {
12
+ return '[unserializable]';
13
+ }
14
+ }
15
+ function write(level, tags, args) {
16
+ const label = tags.length > 0 ? `[${tags.join(',')}] ` : '';
17
+ const line = `${new Date().toISOString()} ${level.padEnd(5)} ${label}${args.map(formatArgument).join(' ')}`;
18
+ if (level === 'ERROR')
19
+ console.error(line);
20
+ else if (level === 'WARN')
21
+ console.warn(line);
22
+ else
23
+ console.info(line);
24
+ }
25
+ export function getLogger(tags = []) {
26
+ return {
27
+ log(...args) {
28
+ write('INFO', tags, args);
29
+ },
30
+ info(...args) {
31
+ write('INFO', tags, args);
32
+ },
33
+ warn(...args) {
34
+ write('WARN', tags, args);
35
+ },
36
+ error(...args) {
37
+ write('ERROR', tags, args);
38
+ },
39
+ };
40
+ }
41
+ //# sourceMappingURL=logger.js.map