@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,143 @@
1
+ export interface Condition {
2
+ field: string;
3
+ op: "eq" | "neq" | "in" | "gt" | "lt" | "filled" | "empty";
4
+ value?: string | number | string[];
5
+ }
6
+ export type FieldPrefill = {
7
+ source: "auth";
8
+ column: string;
9
+ } | {
10
+ source: "url";
11
+ param: string;
12
+ } | {
13
+ source: "db";
14
+ table: string;
15
+ column: string;
16
+ match: {
17
+ column: string;
18
+ field?: string;
19
+ param?: string;
20
+ };
21
+ };
22
+ export interface ValidationRule {
23
+ rule: "min" | "max" | "minLength" | "maxLength" | "pattern";
24
+ value: number | string;
25
+ message: string;
26
+ }
27
+ export interface BaseField {
28
+ name: string;
29
+ label: string;
30
+ required?: boolean;
31
+ placeholder?: string;
32
+ showWhen?: Condition[];
33
+ default?: string | number | boolean;
34
+ prefill?: FieldPrefill;
35
+ locked?: boolean;
36
+ helpText?: string;
37
+ validate?: ValidationRule[];
38
+ }
39
+ export interface TextField extends BaseField {
40
+ type: "text" | "email" | "phone";
41
+ pattern?: string;
42
+ }
43
+ export interface NumberField extends BaseField {
44
+ type: "number";
45
+ min?: number;
46
+ max?: number;
47
+ step?: number;
48
+ }
49
+ export interface SelectField extends BaseField {
50
+ type: "select" | "multiselect";
51
+ options: {
52
+ label: string;
53
+ value: string;
54
+ }[];
55
+ }
56
+ export interface DateField extends BaseField {
57
+ type: "date";
58
+ min?: string;
59
+ max?: string;
60
+ }
61
+ export interface TextareaField extends BaseField {
62
+ type: "textarea";
63
+ rows?: number;
64
+ maxLength?: number;
65
+ }
66
+ export interface FileField extends BaseField {
67
+ type: "file";
68
+ accept?: string;
69
+ maxSizeMb?: number;
70
+ }
71
+ export interface CalculatedField {
72
+ name: string;
73
+ type: "calculated";
74
+ label: string;
75
+ expression: string;
76
+ format?: "number" | "currency" | "percent";
77
+ showWhen?: Condition[];
78
+ }
79
+ export interface HiddenField {
80
+ name: string;
81
+ type: "hidden";
82
+ default?: string | number | boolean;
83
+ prefill?: FieldPrefill;
84
+ locked?: boolean;
85
+ }
86
+ export type FormField = TextField | NumberField | SelectField | DateField | TextareaField | FileField | CalculatedField | HiddenField;
87
+ export interface PageBranch {
88
+ when: Condition[];
89
+ goto: string;
90
+ }
91
+ export interface FormPage {
92
+ id: string;
93
+ title?: string;
94
+ description?: string;
95
+ fields: FormField[];
96
+ showWhen?: Condition[];
97
+ nextPage?: string | {
98
+ conditions: PageBranch[];
99
+ default: string;
100
+ };
101
+ }
102
+ export interface EditMode {
103
+ table: string;
104
+ recordParam: string;
105
+ matchColumn: string;
106
+ }
107
+ export interface FormAccessPublic {
108
+ mode: "public";
109
+ }
110
+ export interface FormAccessIdentify {
111
+ mode: "identify";
112
+ method: "email" | "phone";
113
+ sessionDuration: string;
114
+ }
115
+ export interface FormAccessAuth {
116
+ mode: "auth";
117
+ method: "email" | "phone";
118
+ table: string;
119
+ matchColumn: string;
120
+ sessionDuration: string;
121
+ query?: string;
122
+ }
123
+ export type FormAccess = FormAccessPublic | FormAccessIdentify | FormAccessAuth;
124
+ export interface FormSchema {
125
+ title: string;
126
+ description?: string;
127
+ submitText?: string;
128
+ pages: FormPage[];
129
+ access: FormAccess;
130
+ editMode?: EditMode;
131
+ workflow: string;
132
+ }
133
+ export interface CollectOptions {
134
+ id?: string;
135
+ title: string;
136
+ description?: string;
137
+ submitText?: string;
138
+ fields?: FormField[];
139
+ pages?: FormPage[];
140
+ access?: FormAccess;
141
+ editMode?: EditMode;
142
+ workflow: string;
143
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export { workflow } from "./workflow.js";
2
+ export type { WorkflowContext, WorkflowOptions, WorkflowHandler, WorkflowDef, TriggerConfig, AgentInvokeOptions, AgentResult, WaitForOptions, WaitForResult, HttpOptions, HttpResult, HttpError, StepRecord, WorkflowResult, WebhookResponse, ActionResult, } from "./workflow.js";
3
+ export { source, connector } from "./source.js";
4
+ export type { SourceDef, SourceContext, TableDef, PaginationConfig, RateLimitConfig, SyncConfig, ErrorRetryConfig, ConnectorDef, ConnectorTableDef, TableActions, } from "./source.js";
5
+ export type { ActionType } from "./source-types.js";
6
+ export { agent } from "./agent-types.js";
7
+ export type { AgentConfig, AgentModel, AgentTierRouting, AgentMemory, AgentToolGrant, AgentCaps, } from "./agent-types.js";
8
+ export { WorkspaceDatabase } from "./do/workspace-database.js";
9
+ export { default } from "./app.js";
@@ -0,0 +1,7 @@
1
+ // Public API for Mug workspaces — import { workflow, source, agent } from "@mugwork/mug"
2
+ export { workflow } from "./workflow.js";
3
+ export { source, connector } from "./source.js";
4
+ export { agent } from "./agent-types.js";
5
+ // Framework internals — used by deploy-generated entrypoint
6
+ export { WorkspaceDatabase } from "./do/workspace-database.js";
7
+ export { default } from "./app.js";
@@ -0,0 +1,15 @@
1
+ export interface SourceAuth {
2
+ type: "bearer" | "api-key" | "basic" | "oauth2";
3
+ value: string;
4
+ }
5
+ export interface SyncEntry {
6
+ database: string;
7
+ schedule?: string;
8
+ }
9
+ export interface SourceConfig {
10
+ auth?: SourceAuth;
11
+ baseUrl?: string;
12
+ syncs: Record<string, SyncEntry>;
13
+ }
14
+ export type SourcesConfig = Record<string, SourceConfig>;
15
+ export type ActionType = "read" | "create" | "update" | "delete" | "upsert";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ export interface SourceContext {
2
+ credential: (name: string) => Promise<string>;
3
+ lastSync: string | null;
4
+ fetch: (url: string, init?: RequestInit) => Promise<Response>;
5
+ }
6
+ export interface PaginationConfig {
7
+ style: "cursor" | "offset" | "page" | "link-header";
8
+ cursorParam?: string;
9
+ cursorPath?: string;
10
+ offsetParam?: string;
11
+ pageParam?: string;
12
+ pageSizeParam?: string;
13
+ defaultPageSize?: number;
14
+ maxPageSize?: number;
15
+ }
16
+ export interface RateLimitConfig {
17
+ requestsPerSecond?: number;
18
+ requestsPerMinute?: number;
19
+ }
20
+ export interface SyncConfig {
21
+ filterParam?: string;
22
+ filterFormat?: "iso8601" | "unix" | "epoch_ms";
23
+ updatedAtField?: string;
24
+ deletedAtField?: string;
25
+ isDeletedField?: string;
26
+ deletionStrategy?: "soft-delete-field" | "tombstone-endpoint" | "full-sync-only";
27
+ }
28
+ export interface ErrorRetryConfig {
29
+ maxRetries?: number;
30
+ retryOn5xx?: boolean;
31
+ retryOn429?: boolean;
32
+ backoffMs?: number;
33
+ }
34
+ export interface TableDef {
35
+ name: string;
36
+ primaryKey: string;
37
+ endpoint?: string;
38
+ fetch: (ctx: SourceContext) => Promise<Record<string, unknown>[]>;
39
+ extractItems?: (body: unknown) => Record<string, unknown>[];
40
+ pagination?: PaginationConfig;
41
+ sync?: SyncConfig;
42
+ }
43
+ export interface SourceDef {
44
+ name: string;
45
+ description?: string;
46
+ database: string;
47
+ syncSchedule?: string;
48
+ tables: TableDef[];
49
+ baseUrl?: string;
50
+ rateLimits?: RateLimitConfig;
51
+ errorRetry?: ErrorRetryConfig;
52
+ }
53
+ export interface TableActions {
54
+ create?: (ctx: SourceContext, fields: Record<string, unknown>) => Promise<Record<string, unknown>>;
55
+ update?: (ctx: SourceContext, recordId: string, fields: Record<string, unknown>) => Promise<Record<string, unknown>>;
56
+ delete?: (ctx: SourceContext, recordId: string) => Promise<Record<string, unknown>>;
57
+ upsert?: (ctx: SourceContext, recordId: string, fields: Record<string, unknown>) => Promise<Record<string, unknown>>;
58
+ }
59
+ export interface ConnectorTableDef extends TableDef {
60
+ get?: (ctx: SourceContext, recordId: string) => Promise<Record<string, unknown> | null>;
61
+ actions?: TableActions;
62
+ }
63
+ export interface ConnectorDef extends Omit<SourceDef, "tables"> {
64
+ tables: ConnectorTableDef[];
65
+ }
66
+ export declare function source(def: SourceDef): SourceDef;
67
+ export declare function connector(def: ConnectorDef): ConnectorDef;
68
+ export declare function getSource(name: string): SourceDef | undefined;
69
+ export declare function getConnector(name: string): ConnectorDef | undefined;
70
+ export declare function allSources(): SourceDef[];
@@ -0,0 +1,21 @@
1
+ const registry = new Map();
2
+ export function source(def) {
3
+ registry.set(def.name, def);
4
+ return def;
5
+ }
6
+ export function connector(def) {
7
+ registry.set(def.name, def);
8
+ return def;
9
+ }
10
+ export function getSource(name) {
11
+ return registry.get(name);
12
+ }
13
+ export function getConnector(name) {
14
+ const def = registry.get(name);
15
+ if (!def)
16
+ return undefined;
17
+ return def;
18
+ }
19
+ export function allSources() {
20
+ return [...registry.values()];
21
+ }
@@ -0,0 +1,10 @@
1
+ import type { SourceDef, SourceContext, TableDef } from "./source.js";
2
+ export interface SyncResult {
3
+ table: string;
4
+ rows: Record<string, unknown>[];
5
+ syncedAt: string;
6
+ incremental: boolean;
7
+ pages?: number;
8
+ }
9
+ export declare function syncTable(def: SourceDef, table: TableDef, ctx: SourceContext): Promise<SyncResult>;
10
+ export declare function syncAll(def: SourceDef, ctx: SourceContext): Promise<SyncResult[]>;
@@ -0,0 +1,185 @@
1
+ export async function syncTable(def, table, ctx) {
2
+ const syncedAt = new Date().toISOString();
3
+ if (table.endpoint && table.pagination) {
4
+ const rows = await fetchWithPagination(def, table, ctx);
5
+ return { table: table.name, rows, syncedAt, incremental: !!table.sync?.filterParam && !!ctx.lastSync };
6
+ }
7
+ const rows = await fetchWithRetry(def, table, ctx);
8
+ return { table: table.name, rows, syncedAt, incremental: false };
9
+ }
10
+ export async function syncAll(def, ctx) {
11
+ const results = [];
12
+ for (const table of def.tables) {
13
+ results.push(await syncTable(def, table, ctx));
14
+ await rateLimitDelay(def.rateLimits);
15
+ }
16
+ return results;
17
+ }
18
+ async function fetchWithPagination(def, table, ctx) {
19
+ const baseUrl = def.baseUrl ?? "";
20
+ const endpoint = table.endpoint ?? "";
21
+ const pagination = table.pagination;
22
+ const extract = table.extractItems ?? defaultExtractItems;
23
+ let url = buildSyncUrl(baseUrl + endpoint, table, ctx);
24
+ const all = [];
25
+ let pages = 0;
26
+ while (url) {
27
+ const body = await authedFetchJson(url, ctx, def.errorRetry);
28
+ all.push(...extract(body));
29
+ pages++;
30
+ url = getNextPageUrl(body, url, pagination);
31
+ if (url)
32
+ await rateLimitDelay(def.rateLimits);
33
+ }
34
+ return all;
35
+ }
36
+ async function fetchWithRetry(def, table, ctx) {
37
+ const config = def.errorRetry ?? { maxRetries: 3, retryOn5xx: true, retryOn429: true, backoffMs: 1000 };
38
+ const maxRetries = config.maxRetries ?? 3;
39
+ let attempt = 0;
40
+ while (true) {
41
+ try {
42
+ return await table.fetch(ctx);
43
+ }
44
+ catch (err) {
45
+ attempt++;
46
+ if (attempt >= maxRetries)
47
+ throw err;
48
+ if (!isRetryable(err, config))
49
+ throw err;
50
+ await sleep((config.backoffMs ?? 1000) * Math.pow(2, attempt - 1));
51
+ }
52
+ }
53
+ }
54
+ async function authedFetchJson(url, ctx, retryConfig) {
55
+ const config = retryConfig ?? { maxRetries: 3, retryOn5xx: true, retryOn429: true, backoffMs: 1000 };
56
+ const maxRetries = config.maxRetries ?? 3;
57
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
58
+ const token = await ctx.credential("token");
59
+ const res = await ctx.fetch(url, {
60
+ headers: { Authorization: `Bearer ${token}` },
61
+ });
62
+ if (res.ok)
63
+ return res.json();
64
+ if (res.status === 429 && config.retryOn429 !== false) {
65
+ const retryAfter = parseRetryAfter(res.headers.get("retry-after"));
66
+ await sleep(retryAfter ?? (config.backoffMs ?? 1000) * Math.pow(2, attempt));
67
+ continue;
68
+ }
69
+ if (res.status >= 500 && config.retryOn5xx !== false && attempt < maxRetries) {
70
+ await sleep((config.backoffMs ?? 1000) * Math.pow(2, attempt));
71
+ continue;
72
+ }
73
+ throw new Error(`${res.status} ${res.statusText}: ${url}`);
74
+ }
75
+ throw new Error(`Max retries exceeded: ${url}`);
76
+ }
77
+ function buildSyncUrl(base, table, ctx) {
78
+ const sync = table.sync;
79
+ if (!sync?.filterParam || !ctx.lastSync)
80
+ return base;
81
+ const sep = base.includes("?") ? "&" : "?";
82
+ let value = ctx.lastSync;
83
+ if (sync.filterFormat === "unix") {
84
+ value = String(Math.floor(new Date(ctx.lastSync).getTime() / 1000));
85
+ }
86
+ else if (sync.filterFormat === "epoch_ms") {
87
+ value = String(new Date(ctx.lastSync).getTime());
88
+ }
89
+ return `${base}${sep}${sync.filterParam}=${encodeURIComponent(value)}`;
90
+ }
91
+ function getNextPageUrl(body, currentUrl, pagination) {
92
+ if (typeof body !== "object" || body === null)
93
+ return null;
94
+ const obj = body;
95
+ switch (pagination.style) {
96
+ case "cursor": {
97
+ const path = pagination.cursorPath ?? "next_cursor";
98
+ const cursor = deepGet(obj, path);
99
+ if (!cursor)
100
+ return null;
101
+ const u = new URL(currentUrl);
102
+ u.searchParams.set(pagination.cursorParam ?? "cursor", String(cursor));
103
+ return u.toString();
104
+ }
105
+ case "offset": {
106
+ const items = defaultExtractItems(body);
107
+ const pageSize = pagination.defaultPageSize ?? 100;
108
+ if (items.length < pageSize)
109
+ return null;
110
+ const u = new URL(currentUrl);
111
+ const current = parseInt(u.searchParams.get(pagination.offsetParam ?? "offset") ?? "0");
112
+ u.searchParams.set(pagination.offsetParam ?? "offset", String(current + pageSize));
113
+ return u.toString();
114
+ }
115
+ case "page": {
116
+ const u = new URL(currentUrl);
117
+ const current = parseInt(u.searchParams.get(pagination.pageParam ?? "page") ?? "1");
118
+ const total = (obj.total_pages ?? obj.totalPages);
119
+ if (total && current >= total)
120
+ return null;
121
+ const items = defaultExtractItems(body);
122
+ if (items.length === 0)
123
+ return null;
124
+ u.searchParams.set(pagination.pageParam ?? "page", String(current + 1));
125
+ return u.toString();
126
+ }
127
+ case "link-header":
128
+ return null;
129
+ }
130
+ }
131
+ function defaultExtractItems(body) {
132
+ if (Array.isArray(body))
133
+ return body;
134
+ if (typeof body !== "object" || body === null)
135
+ return [];
136
+ const obj = body;
137
+ for (const key of ["data", "results", "records", "items", "entries"]) {
138
+ if (Array.isArray(obj[key]))
139
+ return obj[key];
140
+ }
141
+ return [];
142
+ }
143
+ function deepGet(obj, path) {
144
+ const parts = path.split(".");
145
+ let current = obj;
146
+ for (const part of parts) {
147
+ if (current === null || current === undefined || typeof current !== "object")
148
+ return undefined;
149
+ current = current[part];
150
+ }
151
+ return current;
152
+ }
153
+ async function rateLimitDelay(config) {
154
+ if (!config)
155
+ return;
156
+ const delay = config.requestsPerSecond
157
+ ? Math.ceil(1000 / config.requestsPerSecond)
158
+ : config.requestsPerMinute
159
+ ? Math.ceil(60000 / config.requestsPerMinute)
160
+ : 0;
161
+ if (delay > 0)
162
+ await sleep(delay);
163
+ }
164
+ function parseRetryAfter(header) {
165
+ if (!header)
166
+ return null;
167
+ const num = parseInt(header);
168
+ if (!isNaN(num)) {
169
+ return num > 1_000_000_000 ? (num * 1000 - Date.now()) : num * 1000;
170
+ }
171
+ const date = new Date(header);
172
+ if (!isNaN(date.getTime()))
173
+ return Math.max(0, date.getTime() - Date.now());
174
+ return null;
175
+ }
176
+ function isRetryable(err, config) {
177
+ if (err instanceof Error && err.message.includes("429") && config.retryOn429 !== false)
178
+ return true;
179
+ if (err instanceof Error && /^5\d\d/.test(err.message) && config.retryOn5xx !== false)
180
+ return true;
181
+ return false;
182
+ }
183
+ function sleep(ms) {
184
+ return new Promise((r) => setTimeout(r, ms));
185
+ }
@@ -0,0 +1,21 @@
1
+ export interface Env {
2
+ WORKSPACE_ID: string;
3
+ ENVIRONMENT: string;
4
+ MUG_DATA: Fetcher;
5
+ MUG_AI: Fetcher;
6
+ MUG_NOTIFY: Fetcher;
7
+ MUG_DISPATCH: Fetcher;
8
+ MUG_INTERNAL_SECRET: string;
9
+ MUG_AGENT: DurableObjectNamespace;
10
+ MUG_SOURCES?: string;
11
+ MUG_BRANDING?: string;
12
+ MUG_AI_ROUTING?: string;
13
+ MUG_AI_BILLING?: string;
14
+ SLACK_BOT_TOKEN?: string;
15
+ TELNYX_API_KEY?: string;
16
+ TELNYX_PHONE_NUMBER?: string;
17
+ TWILIO_ACCOUNT_SID?: string;
18
+ TWILIO_AUTH_TOKEN?: string;
19
+ TWILIO_PHONE_NUMBER?: string;
20
+ WORKSPACE_DB?: DurableObjectNamespace;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from "cloudflare:workers";
2
+ interface MugWorkflowEnv {
3
+ WORKFLOWS: unknown;
4
+ WORKSPACE_ID: string;
5
+ MUG_INTERNAL_SECRET: string;
6
+ MUG_DATA?: Fetcher;
7
+ MUG_AI?: Fetcher;
8
+ MUG_NOTIFY?: Fetcher;
9
+ MUG_DISPATCH?: Fetcher;
10
+ MUG_AI_ROUTING?: string;
11
+ MUG_AI_BILLING?: string;
12
+ MUG_BRANDING?: string;
13
+ SLACK_BOT_TOKEN?: string;
14
+ TELNYX_API_KEY?: string;
15
+ TELNYX_PHONE_NUMBER?: string;
16
+ TWILIO_ACCOUNT_SID?: string;
17
+ TWILIO_AUTH_TOKEN?: string;
18
+ TWILIO_PHONE_NUMBER?: string;
19
+ }
20
+ interface MugWorkflowParams {
21
+ workspace: string;
22
+ workflow: string;
23
+ [key: string]: unknown;
24
+ }
25
+ export declare class MugWorkflow extends WorkflowEntrypoint<MugWorkflowEnv, MugWorkflowParams> {
26
+ run(event: WorkflowEvent<MugWorkflowParams>, step: WorkflowStep): Promise<unknown>;
27
+ }
28
+ declare const _default: {
29
+ fetch(request: Request, env: MugWorkflowEnv): Promise<Response>;
30
+ };
31
+ export default _default;