@zackbart/connecta 0.25.0 → 0.26.1

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 (100) hide show
  1. package/AGENTS.md +6 -5
  2. package/CHANGELOG.md +387 -0
  3. package/README.md +32 -15
  4. package/SECURITY.md +6 -5
  5. package/bin/connecta.mjs +5 -1
  6. package/dist/activity.d.ts +10 -3
  7. package/dist/activity.js +10 -1
  8. package/dist/artifacts/connector.d.ts +55 -0
  9. package/dist/artifacts/connector.js +724 -0
  10. package/dist/artifacts/document.js +80 -0
  11. package/dist/artifacts/guide.js +140 -0
  12. package/dist/artifacts/html-scan.js +329 -0
  13. package/dist/artifacts/json.js +68 -0
  14. package/dist/artifacts/kv-store.d.ts +20 -0
  15. package/dist/artifacts/kv-store.js +140 -0
  16. package/dist/artifacts/markdown.js +478 -0
  17. package/dist/artifacts/module.d.ts +37 -0
  18. package/dist/artifacts/module.js +60 -0
  19. package/dist/artifacts/operations.d.ts +195 -0
  20. package/dist/artifacts/operations.js +944 -0
  21. package/dist/artifacts/refresh.d.ts +53 -0
  22. package/dist/artifacts/refresh.js +235 -0
  23. package/dist/artifacts/routes.js +217 -0
  24. package/dist/artifacts/types.d.ts +214 -0
  25. package/dist/artifacts/types.js +22 -0
  26. package/dist/artifacts/validate.d.ts +62 -0
  27. package/dist/artifacts/validate.js +653 -0
  28. package/dist/artifacts.d.ts +6 -0
  29. package/dist/artifacts.js +9 -0
  30. package/dist/auth/downstream-oauth.js +397 -48
  31. package/dist/auth/oauth-start-reset.js +20 -0
  32. package/dist/branding.d.ts +87 -0
  33. package/dist/branding.js +170 -1
  34. package/dist/catalog-service.js +39 -29
  35. package/dist/catalog.js +42 -8
  36. package/dist/connector-access.d.ts +18 -4
  37. package/dist/connector-access.js +65 -20
  38. package/dist/connector-caller.d.ts +8 -0
  39. package/dist/connector-caller.js +19 -0
  40. package/dist/connectors/remote-mcp.js +48 -9
  41. package/dist/errors.d.ts +16 -1
  42. package/dist/errors.js +28 -0
  43. package/dist/execute.js +431 -75
  44. package/dist/executor-admission.d.ts +11 -1
  45. package/dist/executor-admission.js +79 -14
  46. package/dist/executors/quickjs.js +4 -2
  47. package/dist/index.d.ts +62 -6
  48. package/dist/index.js +230 -6
  49. package/dist/invocation.js +56 -10
  50. package/dist/meta-tools.js +7 -2
  51. package/dist/module-contracts.d.ts +21 -1
  52. package/dist/oauth-callback-outcome.js +43 -18
  53. package/dist/operator-ui/generated.js +2 -2
  54. package/dist/operator-ui/model.d.ts +62 -5
  55. package/dist/operator-ui/view.js +372 -28
  56. package/dist/page-styles.js +7 -0
  57. package/dist/program-source.js +116 -0
  58. package/dist/registry.d.ts +42 -6
  59. package/dist/registry.js +164 -60
  60. package/dist/resumable.js +1291 -0
  61. package/dist/routes/activity.js +6 -69
  62. package/dist/routes/actor-labels.js +114 -0
  63. package/dist/routes/credentials.js +27 -5
  64. package/dist/routes/mcp.js +120 -59
  65. package/dist/routes/oauth-management.js +87 -20
  66. package/dist/routes/oauth.js +54 -87
  67. package/dist/routes/operator.js +1 -0
  68. package/dist/routes/shared.d.ts +23 -1
  69. package/dist/routes/shared.js +20 -2
  70. package/dist/routes/ui-data.js +2 -1
  71. package/dist/routes/ui.js +19 -4
  72. package/dist/run-journal.js +347 -0
  73. package/dist/runtime/shared-read.js +106 -0
  74. package/dist/server.js +30 -2
  75. package/dist/skills.js +30 -11
  76. package/dist/timeout.js +26 -0
  77. package/dist/tool-safety.d.ts +35 -0
  78. package/dist/tool-safety.js +31 -0
  79. package/dist/types.d.ts +23 -0
  80. package/dist/ui.d.ts +17 -5
  81. package/dist/ui.js +51 -68
  82. package/dist/version.d.ts +1 -1
  83. package/dist/version.js +1 -1
  84. package/documentation/architecture.md +214 -27
  85. package/documentation/auth.md +186 -2
  86. package/documentation/code-mode.md +236 -63
  87. package/documentation/meta-tools.md +55 -29
  88. package/ethos.md +12 -10
  89. package/examples/worker/AGENTS.md +6 -0
  90. package/examples/worker/README.md +174 -10
  91. package/examples/worker/src/d1-activity-row.ts +14 -2
  92. package/examples/worker/src/d1-activity.ts +4 -2
  93. package/examples/worker/src/index.ts +36 -1
  94. package/examples/worker/src/r2-artifact-blobs.ts +29 -0
  95. package/examples/worker/wrangler.jsonc +5 -1
  96. package/package.json +6 -2
  97. package/templates/node/AGENTS.md +9 -2
  98. package/templates/node/README.md +31 -3
  99. package/templates/node/package.json +1 -1
  100. package/templates/node/src/index.ts +27 -0
@@ -0,0 +1,60 @@
1
+ // artifacts(): the typed module a deployment passes as `ConnectaConfig.artifacts`.
2
+ import { artifactsConnector } from "./connector.js";
3
+ import { ArtifactOperations } from "./operations.js";
4
+ import { artifactRoutes } from "./routes.js";
5
+ import { ArtifactRefreshService } from "./refresh.js";
6
+ import { resolveAllowlist, resolveLimits } from "./validate.js";
7
+ const STORE_METHODS = [
8
+ "head",
9
+ "swapHead",
10
+ "heads",
11
+ "putBody",
12
+ "body",
13
+ "putVersion",
14
+ "versions",
15
+ "putRun",
16
+ "runs",
17
+ "refreshScanCursor",
18
+ "setRefreshScanCursor",
19
+ ];
20
+ const OPTIONS = new Set(["store", "allowlist", "limits", "renderCheck"]);
21
+ export function artifacts(options) {
22
+ if (!options || typeof options !== "object") {
23
+ throw new TypeError("artifacts() needs options with a store");
24
+ }
25
+ for (const key of Object.keys(options)) {
26
+ if (!OPTIONS.has(key))
27
+ throw new TypeError(`artifacts(): unknown option "${key}"`);
28
+ }
29
+ const store = options.store;
30
+ if (!store ||
31
+ typeof store !== "object" ||
32
+ STORE_METHODS.some((method) => typeof store[method] !== "function")) {
33
+ throw new TypeError("artifacts(): store must be an ArtifactStore, e.g. kvArtifactStore(storage)");
34
+ }
35
+ if (options.renderCheck !== undefined && typeof options.renderCheck !== "function") {
36
+ throw new TypeError("artifacts(): renderCheck must be a function");
37
+ }
38
+ const allowlist = resolveAllowlist(options.allowlist);
39
+ const limits = resolveLimits(options.limits);
40
+ const operations = new ArtifactOperations({
41
+ store: options.store,
42
+ allowlist,
43
+ limits,
44
+ });
45
+ const refresh = new ArtifactRefreshService(operations);
46
+ const connector = artifactsConnector({
47
+ operations,
48
+ refresh,
49
+ allowlist,
50
+ limits,
51
+ ...(options.renderCheck ? { renderCheck: options.renderCheck } : {}),
52
+ });
53
+ return Object.freeze({
54
+ connector,
55
+ handle: artifactRoutes({ operations, allowlist }),
56
+ bindRefresh: (runtime) => refresh.bind(runtime),
57
+ refresh: (id, by) => refresh.run(id, { manual: by }),
58
+ runDue: () => refresh.runDue(),
59
+ });
60
+ }
@@ -0,0 +1,195 @@
1
+ import { type CheckContext } from "./validate.js";
2
+ import type { ArtifactActor, ArtifactHeadRecord, ArtifactIssue, ArtifactKind, ArtifactStore, ArtifactValidation, ArtifactVersionRecord, ArtifactRefreshSchedule, ArtifactRunRecord } from "./types.js";
3
+ type ArtifactFailureCode = "conflict" | "invalid_args" | "not_found" | "unavailable";
4
+ export interface ArtifactFailure {
5
+ ok: false;
6
+ code: ArtifactFailureCode;
7
+ message: string;
8
+ /** On a conflict: where each stream stands now. */
9
+ current?: Record<string, number>;
10
+ /** On invalid content: what validation found. */
11
+ validation?: ArtifactValidation;
12
+ }
13
+ type Result<T> = ({
14
+ ok: true;
15
+ } & T) | ArtifactFailure;
16
+ /**
17
+ * A deployment's render check, bound to one call: it gets the page as the
18
+ * write would leave it — the prospective head, its source, and every live
19
+ * document's stored JSON — and answers with warnings or a failure.
20
+ */
21
+ export type RenderPage = (page: {
22
+ id: string;
23
+ head: ArtifactHeadRecord;
24
+ source: string;
25
+ data: Record<string, string>;
26
+ }) => Promise<{
27
+ ok: true;
28
+ warnings: ArtifactIssue[];
29
+ } | ArtifactFailure>;
30
+ export interface OperationsOptions extends CheckContext {
31
+ store: ArtifactStore;
32
+ /** Epoch milliseconds. Default `Date.now`. */
33
+ now?: () => number;
34
+ }
35
+ /**
36
+ * A validation refusal. The message lists every finding — each names a line
37
+ * and a fix — so an agent can repair the page from the error alone; it stays
38
+ * under the guest error bound, pointing at `validate_artifact` for the rest.
39
+ */
40
+ export declare function invalidContent(what: string, validation: ArtifactValidation): ArtifactFailure;
41
+ export interface PatchEdit {
42
+ find: string;
43
+ replace: string;
44
+ }
45
+ export declare class ArtifactOperations {
46
+ #private;
47
+ constructor(options: OperationsOptions);
48
+ get store(): ArtifactStore;
49
+ get context(): CheckContext;
50
+ create(input: {
51
+ id: string;
52
+ title: string;
53
+ kind: ArtifactKind;
54
+ source: string;
55
+ documents?: Record<string, unknown>;
56
+ by: ArtifactActor;
57
+ render?: RenderPage;
58
+ }): Promise<Result<{
59
+ head: ArtifactHeadRecord;
60
+ warnings: ArtifactIssue[];
61
+ }>>;
62
+ update(input: {
63
+ id: string;
64
+ baseVersion: number;
65
+ source: string;
66
+ title?: string;
67
+ by: ArtifactActor;
68
+ render?: RenderPage;
69
+ }): Promise<Result<{
70
+ head: ArtifactHeadRecord;
71
+ warnings: ArtifactIssue[];
72
+ }>>;
73
+ patch(input: {
74
+ id: string;
75
+ baseVersion: number;
76
+ edits: PatchEdit[];
77
+ by: ArtifactActor;
78
+ render?: RenderPage;
79
+ }): Promise<Result<{
80
+ head: ArtifactHeadRecord;
81
+ warnings: ArtifactIssue[];
82
+ }>>;
83
+ setDocuments(input: {
84
+ id: string;
85
+ documents: Record<string, {
86
+ baseVersion: number;
87
+ value: unknown;
88
+ }>;
89
+ by: ArtifactActor;
90
+ op?: "set" | "refresh";
91
+ runId?: string;
92
+ /** A refresh result may publish only while its own claim still holds. */
93
+ programVersion?: number;
94
+ render?: RenderPage;
95
+ }): Promise<Result<{
96
+ head: ArtifactHeadRecord;
97
+ warnings: ArtifactIssue[];
98
+ }>>;
99
+ /** Configure one versioned program. A concurrent document edit is absorbed. */
100
+ setRefresh(input: {
101
+ id: string;
102
+ program: string;
103
+ document: string;
104
+ schedule: ArtifactRefreshSchedule;
105
+ baseVersion: number;
106
+ by: ArtifactActor;
107
+ owner?: {
108
+ identity: import("../types.js").AuthenticatedIdentity;
109
+ pool?: string;
110
+ };
111
+ }): Promise<Result<{
112
+ head: ArtifactHeadRecord;
113
+ }>>;
114
+ refreshConfig(id: string): Promise<Result<{
115
+ head: ArtifactHeadRecord;
116
+ program: string | undefined;
117
+ }>>;
118
+ claimRefresh(id: string, runId: string, trigger: ArtifactRunRecord["trigger"], dueOnly: boolean, claimMs: number): Promise<Result<{
119
+ head: ArtifactHeadRecord;
120
+ program: string;
121
+ run: ArtifactRunRecord;
122
+ }> | {
123
+ ok: false;
124
+ skipped: true;
125
+ }>;
126
+ finishRefresh(id: string, run: ArtifactRunRecord): Promise<void>;
127
+ rollback(input: {
128
+ id: string;
129
+ target: "view" | "document";
130
+ name?: string;
131
+ version: number;
132
+ baseVersion: number;
133
+ by: ArtifactActor;
134
+ render?: RenderPage;
135
+ }): Promise<Result<{
136
+ head: ArtifactHeadRecord;
137
+ warnings: ArtifactIssue[];
138
+ }>>;
139
+ setArchived(input: {
140
+ id: string;
141
+ baseRevision: number;
142
+ archived: boolean;
143
+ by: ArtifactActor;
144
+ }): Promise<Result<{
145
+ head: ArtifactHeadRecord;
146
+ warnings: ArtifactIssue[];
147
+ }>>;
148
+ get(id: string, options?: {
149
+ version?: number;
150
+ includeSource?: boolean;
151
+ }): Promise<Result<{
152
+ head: ArtifactHeadRecord;
153
+ view: ArtifactVersionRecord;
154
+ source?: string;
155
+ history: ArtifactVersionRecord[];
156
+ }>>;
157
+ getDocument(id: string, name: string, version?: number): Promise<Result<{
158
+ head: ArtifactHeadRecord;
159
+ record: ArtifactVersionRecord;
160
+ value: unknown;
161
+ history: ArtifactVersionRecord[];
162
+ }>>;
163
+ /** The page a viewer renders: a view version and exactly the documents asked for (all current ones by default). */
164
+ page(id: string, pin?: {
165
+ view?: number;
166
+ documents?: Record<string, number>;
167
+ }): Promise<Result<{
168
+ head: ArtifactHeadRecord;
169
+ view: ArtifactVersionRecord;
170
+ source: string;
171
+ documents: Record<string, {
172
+ record: ArtifactVersionRecord;
173
+ value: unknown;
174
+ }>;
175
+ }>>;
176
+ list(options: {
177
+ query?: string;
178
+ includeArchived?: boolean;
179
+ limit: number;
180
+ cursor?: string;
181
+ }): Promise<Result<{
182
+ items: {
183
+ id: string;
184
+ head: ArtifactHeadRecord;
185
+ }[];
186
+ nextCursor?: string;
187
+ }>>;
188
+ }
189
+ /**
190
+ * Apply every edit to `source` at once, each against the original text: every
191
+ * `find` must occur exactly once and no two may overlap. Returns the new text,
192
+ * or every reason it could not.
193
+ */
194
+ export declare function applyPatch(source: string, edits: readonly PatchEdit[]): string | string[];
195
+ export {};