@mugwork/mug 0.1.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 (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -0
  3. package/dist/explorer.js +3 -0
  4. package/dist/packages/email-template/src/email-template.d.ts +18 -0
  5. package/dist/packages/email-template/src/email-template.js +74 -0
  6. package/dist/packages/email-template/src/index.d.ts +1 -0
  7. package/dist/packages/email-template/src/index.js +1 -0
  8. package/dist/packages/surface-renderer/src/form-renderer.d.ts +117 -0
  9. package/dist/packages/surface-renderer/src/form-renderer.js +719 -0
  10. package/dist/packages/surface-renderer/src/index.d.ts +4 -0
  11. package/dist/packages/surface-renderer/src/index.js +2 -0
  12. package/dist/packages/surface-renderer/src/portal-renderer.d.ts +177 -0
  13. package/dist/packages/surface-renderer/src/portal-renderer.js +1089 -0
  14. package/dist/packages/surface-renderer/src/workspace-home.d.ts +46 -0
  15. package/dist/packages/surface-renderer/src/workspace-home.js +345 -0
  16. package/dist/runtime/agent-types.d.ts +48 -0
  17. package/dist/runtime/agent-types.js +3 -0
  18. package/dist/runtime/ai-router.d.ts +32 -0
  19. package/dist/runtime/ai-router.js +112 -0
  20. package/dist/runtime/app.d.ts +6 -0
  21. package/dist/runtime/app.js +399 -0
  22. package/dist/runtime/chunker.d.ts +6 -0
  23. package/dist/runtime/chunker.js +30 -0
  24. package/dist/runtime/context.d.ts +115 -0
  25. package/dist/runtime/context.js +440 -0
  26. package/dist/runtime/do/workspace-database.d.ts +10 -0
  27. package/dist/runtime/do/workspace-database.js +199 -0
  28. package/dist/runtime/form-types.d.ts +143 -0
  29. package/dist/runtime/form-types.js +1 -0
  30. package/dist/runtime/runtime.d.ts +9 -0
  31. package/dist/runtime/runtime.js +7 -0
  32. package/dist/runtime/source-types.d.ts +15 -0
  33. package/dist/runtime/source-types.js +1 -0
  34. package/dist/runtime/source.d.ts +70 -0
  35. package/dist/runtime/source.js +21 -0
  36. package/dist/runtime/sync-runtime.d.ts +10 -0
  37. package/dist/runtime/sync-runtime.js +185 -0
  38. package/dist/runtime/types.d.ts +21 -0
  39. package/dist/runtime/types.js +1 -0
  40. package/dist/runtime/workflow-entrypoint.d.ts +31 -0
  41. package/dist/runtime/workflow-entrypoint.js +1297 -0
  42. package/dist/runtime/workflow.d.ts +285 -0
  43. package/dist/runtime/workflow.js +1008 -0
  44. package/dist/src/cli.d.ts +2 -0
  45. package/dist/src/cli.js +44116 -0
  46. package/dist/src/commands/ai-gateway-route.d.ts +24 -0
  47. package/dist/src/commands/ai-gateway-route.js +192 -0
  48. package/dist/src/commands/auth.d.ts +1 -0
  49. package/dist/src/commands/auth.js +42 -0
  50. package/dist/src/commands/billing.d.ts +6 -0
  51. package/dist/src/commands/billing.js +76 -0
  52. package/dist/src/commands/brain.d.ts +1 -0
  53. package/dist/src/commands/brain.js +194 -0
  54. package/dist/src/commands/demo.d.ts +12 -0
  55. package/dist/src/commands/demo.js +147 -0
  56. package/dist/src/commands/deploy.d.ts +1 -0
  57. package/dist/src/commands/deploy.js +1052 -0
  58. package/dist/src/commands/dev.d.ts +14 -0
  59. package/dist/src/commands/dev.js +2818 -0
  60. package/dist/src/commands/form.d.ts +8 -0
  61. package/dist/src/commands/form.js +396 -0
  62. package/dist/src/commands/init.d.ts +1 -0
  63. package/dist/src/commands/init.js +139 -0
  64. package/dist/src/commands/issue.d.ts +7 -0
  65. package/dist/src/commands/issue.js +191 -0
  66. package/dist/src/commands/login.d.ts +9 -0
  67. package/dist/src/commands/login.js +163 -0
  68. package/dist/src/commands/logs.d.ts +8 -0
  69. package/dist/src/commands/logs.js +113 -0
  70. package/dist/src/commands/portal.d.ts +2 -0
  71. package/dist/src/commands/portal.js +111 -0
  72. package/dist/src/commands/pull.d.ts +3 -0
  73. package/dist/src/commands/pull.js +184 -0
  74. package/dist/src/commands/push.d.ts +4 -0
  75. package/dist/src/commands/push.js +183 -0
  76. package/dist/src/commands/run.d.ts +6 -0
  77. package/dist/src/commands/run.js +91 -0
  78. package/dist/src/commands/secret.d.ts +7 -0
  79. package/dist/src/commands/secret.js +105 -0
  80. package/dist/src/commands/shutdown.d.ts +1 -0
  81. package/dist/src/commands/shutdown.js +46 -0
  82. package/dist/src/commands/sql.d.ts +8 -0
  83. package/dist/src/commands/sql.js +142 -0
  84. package/dist/src/commands/status.d.ts +5 -0
  85. package/dist/src/commands/status.js +39 -0
  86. package/dist/src/commands/sync.d.ts +7 -0
  87. package/dist/src/commands/sync.js +991 -0
  88. package/dist/src/commands/usage.d.ts +6 -0
  89. package/dist/src/commands/usage.js +78 -0
  90. package/dist/src/commands/webhooks.d.ts +1 -0
  91. package/dist/src/commands/webhooks.js +102 -0
  92. package/dist/src/commands/workspace.d.ts +23 -0
  93. package/dist/src/commands/workspace.js +590 -0
  94. package/dist/src/connector-migration.d.ts +20 -0
  95. package/dist/src/connector-migration.js +43 -0
  96. package/dist/src/connector-parser.d.ts +14 -0
  97. package/dist/src/connector-parser.js +94 -0
  98. package/dist/src/connector-service/discover.d.ts +37 -0
  99. package/dist/src/connector-service/discover.js +79 -0
  100. package/dist/src/connector-service/gather.d.ts +22 -0
  101. package/dist/src/connector-service/gather.js +89 -0
  102. package/dist/src/connector-service/init.d.ts +14 -0
  103. package/dist/src/connector-service/init.js +109 -0
  104. package/dist/src/connector-service/scaffold.d.ts +17 -0
  105. package/dist/src/connector-service/scaffold.js +194 -0
  106. package/dist/src/connector-service/spec-storage.d.ts +8 -0
  107. package/dist/src/connector-service/spec-storage.js +48 -0
  108. package/dist/src/connector-service/types.d.ts +57 -0
  109. package/dist/src/connector-service/types.js +2 -0
  110. package/dist/src/connector-service/verify.d.ts +24 -0
  111. package/dist/src/connector-service/verify.js +575 -0
  112. package/dist/src/email-template.d.ts +2 -0
  113. package/dist/src/email-template.js +1 -0
  114. package/dist/src/manifest.d.ts +31 -0
  115. package/dist/src/manifest.js +25 -0
  116. package/dist/src/mug-icon.d.ts +1 -0
  117. package/dist/src/mug-icon.js +12 -0
  118. package/dist/src/slack-manifest.d.ts +119 -0
  119. package/dist/src/slack-manifest.js +163 -0
  120. package/dist/src/source-migration.d.ts +20 -0
  121. package/dist/src/source-migration.js +43 -0
  122. package/dist/src/surface-renderer.d.ts +5 -0
  123. package/dist/src/surface-renderer.js +3 -0
  124. package/dist/src/templates.d.ts +3 -0
  125. package/dist/src/templates.js +48 -0
  126. package/dist/src/version-check.d.ts +1 -0
  127. package/dist/src/version-check.js +28 -0
  128. package/dist/src/workflow-parser.d.ts +95 -0
  129. package/dist/src/workflow-parser.js +526 -0
  130. package/dist/worker/src/agent-types.d.ts +27 -0
  131. package/dist/worker/src/agent-types.js +3 -0
  132. package/dist/worker/src/source-types.d.ts +14 -0
  133. package/dist/worker/src/source-types.js +1 -0
  134. package/package.json +90 -0
  135. package/src/data/model-capabilities.json +171 -0
@@ -0,0 +1,285 @@
1
+ import type { SearchOptions, SearchResult, AskOptions, AskResult } from "./context.js";
2
+ import type { Env } from "./types.js";
3
+ import type { CollectOptions } from "./form-types.js";
4
+ import type { RoutingConfig } from "./ai-router.js";
5
+ import type { AgentCaps } from "./agent-types.js";
6
+ import { type SourceContext, type ConnectorDef } from "./source.js";
7
+ import type { ActionType } from "./source-types.js";
8
+ export interface AgentInvokeOptions {
9
+ goal: string;
10
+ context?: Record<string, unknown>;
11
+ sessionKey?: string;
12
+ caps?: Partial<AgentCaps>;
13
+ }
14
+ export interface AgentResult {
15
+ response: string;
16
+ output?: Record<string, unknown>;
17
+ usage: {
18
+ credits: number;
19
+ turns: number;
20
+ duration: number;
21
+ };
22
+ capped?: boolean;
23
+ cappedReason?: string;
24
+ pendingApproval?: {
25
+ tool: string;
26
+ args: Record<string, unknown>;
27
+ sessionKey: string;
28
+ };
29
+ }
30
+ export interface WaitForOptions {
31
+ timeout?: string | number;
32
+ message?: string;
33
+ }
34
+ export interface WaitForResult<T = unknown> {
35
+ payload: T;
36
+ type: string;
37
+ timedOut: boolean;
38
+ }
39
+ interface AiOptions {
40
+ prompt: string;
41
+ system?: string;
42
+ maxTokens?: number;
43
+ routing?: RoutingConfig;
44
+ billing?: string;
45
+ }
46
+ interface AiResponse {
47
+ text: string;
48
+ model: string;
49
+ usage: {
50
+ input_tokens: number;
51
+ output_tokens: number;
52
+ };
53
+ routing?: {
54
+ tier: string;
55
+ model: string;
56
+ provider: string;
57
+ reason: string;
58
+ };
59
+ }
60
+ interface NotifyOptions {
61
+ to: string;
62
+ message: string;
63
+ subject?: string;
64
+ fromName?: string;
65
+ cta?: {
66
+ label: string;
67
+ url: string;
68
+ };
69
+ blocks?: unknown[];
70
+ thread_ts?: string;
71
+ unfurl_links?: boolean;
72
+ unfurl_media?: boolean;
73
+ }
74
+ export interface HttpOptions {
75
+ method?: string;
76
+ headers?: Record<string, string>;
77
+ body?: unknown;
78
+ throwOnError?: boolean;
79
+ retry?: {
80
+ attempts?: number;
81
+ } | false;
82
+ timeout?: number;
83
+ sign?: {
84
+ secret: string;
85
+ header?: string;
86
+ };
87
+ }
88
+ export interface HttpResult {
89
+ status: number;
90
+ headers: Record<string, string>;
91
+ body: string;
92
+ json: unknown;
93
+ ok: boolean;
94
+ }
95
+ export declare class HttpError extends Error {
96
+ status: number;
97
+ result: HttpResult;
98
+ constructor(result: HttpResult);
99
+ }
100
+ export interface ActionResult<T = Record<string, unknown>> {
101
+ connector: string;
102
+ table: string;
103
+ operation: ActionType;
104
+ recordId?: string;
105
+ data: T;
106
+ snapshot?: Record<string, unknown>;
107
+ operationId: string;
108
+ }
109
+ export interface StepRecord {
110
+ name: string;
111
+ type: string;
112
+ billable: boolean;
113
+ startedAt: number;
114
+ completedAt?: number;
115
+ durationMs?: number;
116
+ input?: string;
117
+ output?: string;
118
+ error?: string;
119
+ tokensUsed?: number;
120
+ }
121
+ export interface WorkflowResult {
122
+ workflow: string;
123
+ runId: string;
124
+ status: "complete" | "errored";
125
+ startedAt: string;
126
+ completedAt: string;
127
+ durationMs: number;
128
+ stepCount: number;
129
+ steps: StepRecord[];
130
+ result?: unknown;
131
+ error?: string;
132
+ webhookResponse?: WebhookResponse;
133
+ }
134
+ export interface WebhookResponse {
135
+ body: unknown;
136
+ status: number;
137
+ }
138
+ export declare class WorkflowContext {
139
+ private ctx;
140
+ private env;
141
+ private stepCounter;
142
+ private workflowBilling?;
143
+ private operationCount;
144
+ private maxOperations;
145
+ readonly steps: StepRecord[];
146
+ params: Record<string, unknown>;
147
+ changesetId?: string;
148
+ changesetSource?: string;
149
+ instanceId?: string;
150
+ _webhookResponse?: WebhookResponse;
151
+ get isDemo(): boolean;
152
+ private get demoNotify();
153
+ private resolveDemoRecipient;
154
+ constructor(env: Env, options?: WorkflowOptions);
155
+ secret(name: string): string;
156
+ /** @internal */
157
+ _nextStep(type: string, target: string): string;
158
+ /** @internal */
159
+ _recordStep(name: string, type: string, startedAt: number, opts?: {
160
+ input?: unknown;
161
+ output?: unknown;
162
+ error?: string;
163
+ tokensUsed?: number;
164
+ }): StepRecord;
165
+ query(database: string, sql: string, params?: (string | number | null)[]): Promise<Record<string, unknown>[]>;
166
+ exec(database: string, sql: string, params?: (string | number | null)[]): Promise<number>;
167
+ ai(model: string, options: AiOptions): Promise<AiResponse>;
168
+ search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
169
+ ask(question: string, options?: AskOptions): Promise<AskResult>;
170
+ get notify(): {
171
+ sms: (options: NotifyOptions) => Promise<string>;
172
+ email: (options: NotifyOptions) => Promise<string>;
173
+ slack: (options: NotifyOptions) => Promise<string>;
174
+ channel: (name: string, options: NotifyOptions) => Promise<string>;
175
+ };
176
+ private sendNotification;
177
+ get slack(): {
178
+ updateMessage: (options: {
179
+ channel: string;
180
+ ts: string;
181
+ text?: string;
182
+ blocks?: unknown[];
183
+ }) => Promise<void>;
184
+ openModal: (options: {
185
+ triggerId: string;
186
+ view: Record<string, unknown>;
187
+ }) => Promise<void>;
188
+ updateModal: (options: {
189
+ viewId: string;
190
+ view: Record<string, unknown>;
191
+ }) => Promise<void>;
192
+ };
193
+ private slackUpdateMessage;
194
+ private slackOpenModal;
195
+ private slackUpdateModal;
196
+ file(path: string): Promise<ArrayBuffer>;
197
+ fileText(path: string): Promise<string>;
198
+ embed(texts: string[]): Promise<number[][]>;
199
+ slackApiCall(method: string, body: Record<string, unknown>): Promise<Record<string, unknown>>;
200
+ surfaceUrl(surfaceId: string, path?: string): string;
201
+ respond(body: unknown, status?: number): Promise<void>;
202
+ agent(name: string, options: AgentInvokeOptions): Promise<AgentResult>;
203
+ collect(options: CollectOptions): Promise<string>;
204
+ waitFor<T = unknown>(eventName: string, options?: WaitForOptions): Promise<WaitForResult<T>>;
205
+ waitForUrl(eventName: string): Promise<string>;
206
+ http(url: string, options?: HttpOptions): Promise<HttpResult>;
207
+ action(connectorName: string): ConnectorHandle;
208
+ rollback(actionId: string): Promise<ActionResult>;
209
+ rollbackRun(workflowRunId: string): Promise<{
210
+ rolledBack: ActionResult[];
211
+ failed: {
212
+ actionId: string;
213
+ error: string;
214
+ }[];
215
+ }>;
216
+ /** @internal */
217
+ _checkOpsCap(): void;
218
+ /** @internal */
219
+ _logAction(result: ActionResult, afterPayload?: unknown): Promise<void>;
220
+ /** @internal */
221
+ _makeSourceCtx(connectorName: string): SourceContext;
222
+ }
223
+ declare class ConnectorHandle {
224
+ private wfCtx;
225
+ private def;
226
+ private connectorName;
227
+ constructor(wfCtx: WorkflowContext, def: ConnectorDef, connectorName: string);
228
+ private resolveTable;
229
+ read(tableName: string, recordId: string): Promise<ActionResult>;
230
+ create(tableName: string, fields: Record<string, unknown>): Promise<ActionResult>;
231
+ update(tableName: string, recordId: string, fields: Record<string, unknown>): Promise<ActionResult>;
232
+ delete(tableName: string, recordId: string): Promise<ActionResult>;
233
+ upsert(tableName: string, recordId: string, fields: Record<string, unknown>): Promise<ActionResult>;
234
+ }
235
+ export interface TriggerConfig {
236
+ type?: "slack_command" | "slack_event" | "slack_shortcut" | "data";
237
+ source?: string;
238
+ table?: string;
239
+ on?: "insert" | "update" | "delete" | "change";
240
+ includeInitialSync?: boolean;
241
+ command?: string;
242
+ event?: string;
243
+ }
244
+ export type Weekday = "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday" | "sunday";
245
+ export interface ScheduleConfig {
246
+ cron?: string;
247
+ weekday?: Weekday;
248
+ nth?: number;
249
+ time?: string;
250
+ interval?: string;
251
+ between?: [string, string];
252
+ skipHolidays?: boolean | string;
253
+ skipDates?: string[];
254
+ timezone?: string;
255
+ }
256
+ export interface WorkflowOptions {
257
+ description?: string;
258
+ billing?: string;
259
+ schedule?: string | ScheduleConfig;
260
+ webhook?: boolean | {
261
+ auth: "none" | "hmac" | "bearer";
262
+ secret?: string;
263
+ };
264
+ inbound?: "sms" | "email" | "slack";
265
+ trigger?: TriggerConfig;
266
+ maxOperations?: number;
267
+ }
268
+ export type WorkflowHandler = (ctx: WorkflowContext) => Promise<unknown>;
269
+ export interface WorkflowDef {
270
+ name: string;
271
+ handler: WorkflowHandler;
272
+ options?: WorkflowOptions;
273
+ }
274
+ export declare function workflow(name: string, handler: WorkflowHandler, options?: WorkflowOptions): WorkflowDef;
275
+ export declare function getWorkflow(name: string): WorkflowDef | undefined;
276
+ export declare function allWorkflows(): WorkflowDef[];
277
+ export declare function findTriggeredWorkflows(sourceName: string, tableName: string, event: "insert" | "update" | "delete", isInitialSync: boolean): WorkflowDef[];
278
+ export declare function runWorkflow(name: string, env: Env, params?: Record<string, unknown>): Promise<WorkflowResult>;
279
+ export declare function queryLogs(env: Env, workflowName?: string, limit?: number): Promise<unknown>;
280
+ export declare function queryActions(env: Env, filters?: {
281
+ workflowRunId?: string;
282
+ connector?: string;
283
+ operation?: string;
284
+ }, limit?: number): Promise<Record<string, unknown>[]>;
285
+ export {};