agent-cms 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.
- package/LICENSE +21 -0
- package/PROMPT.md +55 -0
- package/README.md +220 -0
- package/dist/handler-ClOW1ldA.mjs +5703 -0
- package/dist/http-transport-DbFCI6Cs.mjs +993 -0
- package/dist/index.d.mts +213 -0
- package/dist/index.mjs +1170 -0
- package/dist/structured-text-service-B4xSlUg_.mjs +1952 -0
- package/dist/token-service-BDjccMmz.mjs +3820 -0
- package/migrations/0000_genesis.sql +118 -0
- package/package.json +98 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Context, Effect, Option } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/search/vectorize.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Minimal structural type for Workers AI binding.
|
|
6
|
+
* Compatible with Cloudflare's `Ai` type from `wrangler types` — no cast needed.
|
|
7
|
+
*/
|
|
8
|
+
interface AiBinding {
|
|
9
|
+
run(model: string, input: {
|
|
10
|
+
text: string[];
|
|
11
|
+
}): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Minimal structural type for Vectorize binding.
|
|
15
|
+
* Compatible with Cloudflare's `VectorizeIndex` type from `wrangler types` — no cast needed.
|
|
16
|
+
*/
|
|
17
|
+
interface VectorizeBinding {
|
|
18
|
+
upsert(vectors: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
values: number[];
|
|
21
|
+
metadata?: Record<string, string>;
|
|
22
|
+
}>): Promise<unknown>;
|
|
23
|
+
deleteByIds(ids: string[]): Promise<unknown>;
|
|
24
|
+
query(vector: number[], options: {
|
|
25
|
+
topK: number;
|
|
26
|
+
returnMetadata?: "all" | "none";
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/hooks.d.ts
|
|
31
|
+
interface CmsHooks {
|
|
32
|
+
readonly onRecordCreate?: (event: {
|
|
33
|
+
modelApiKey: string;
|
|
34
|
+
recordId: string;
|
|
35
|
+
}) => void | Promise<void>;
|
|
36
|
+
readonly onRecordUpdate?: (event: {
|
|
37
|
+
modelApiKey: string;
|
|
38
|
+
recordId: string;
|
|
39
|
+
}) => void | Promise<void>;
|
|
40
|
+
readonly onRecordDelete?: (event: {
|
|
41
|
+
modelApiKey: string;
|
|
42
|
+
recordId: string;
|
|
43
|
+
}) => void | Promise<void>;
|
|
44
|
+
readonly onPublish?: (event: {
|
|
45
|
+
modelApiKey: string;
|
|
46
|
+
recordId: string;
|
|
47
|
+
}) => void | Promise<void>;
|
|
48
|
+
readonly onUnpublish?: (event: {
|
|
49
|
+
modelApiKey: string;
|
|
50
|
+
recordId: string;
|
|
51
|
+
}) => void | Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/admin-client.d.ts
|
|
55
|
+
interface CmsAdminClientConfig {
|
|
56
|
+
readonly endpoint: string;
|
|
57
|
+
readonly writeKey: string;
|
|
58
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
59
|
+
}
|
|
60
|
+
interface CreateEditorTokenRequest {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly expiresIn?: number;
|
|
63
|
+
}
|
|
64
|
+
interface CreateEditorTokenResponse {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly token: string;
|
|
67
|
+
readonly tokenPrefix: string;
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly createdAt: string;
|
|
70
|
+
readonly expiresAt: string | null;
|
|
71
|
+
}
|
|
72
|
+
interface EditorTokenListItem {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly token_prefix: string;
|
|
76
|
+
readonly created_at: string;
|
|
77
|
+
readonly last_used_at: string | null;
|
|
78
|
+
readonly expires_at: string | null;
|
|
79
|
+
}
|
|
80
|
+
declare function createCmsAdminClient(config: CmsAdminClientConfig): {
|
|
81
|
+
createEditorToken(input: CreateEditorTokenRequest): Promise<CreateEditorTokenResponse>;
|
|
82
|
+
listEditorTokens(): Promise<EditorTokenListItem[]>;
|
|
83
|
+
revokeEditorToken(id: string): Promise<{
|
|
84
|
+
ok: true;
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/editor-mcp-proxy.d.ts
|
|
89
|
+
interface EditorMcpPrincipal {
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly name: string;
|
|
92
|
+
}
|
|
93
|
+
interface EditorMcpProxyConfig {
|
|
94
|
+
readonly appBaseUrl: string;
|
|
95
|
+
readonly cmsBaseUrl: string;
|
|
96
|
+
readonly cmsWriteKey: string;
|
|
97
|
+
readonly oauthSecret: string;
|
|
98
|
+
readonly getEditor: (request: Request) => Promise<EditorMcpPrincipal | null>;
|
|
99
|
+
readonly getLoginUrl: (request: Request) => string | URL;
|
|
100
|
+
readonly mountPath?: string;
|
|
101
|
+
readonly oauthTokenTtlSeconds?: number;
|
|
102
|
+
readonly cmsTokenTtlSeconds?: number;
|
|
103
|
+
readonly resourceName?: string;
|
|
104
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
105
|
+
}
|
|
106
|
+
interface EditorMcpProxyPaths {
|
|
107
|
+
readonly mountPath: string;
|
|
108
|
+
readonly issuer: string;
|
|
109
|
+
readonly mcpPath: string;
|
|
110
|
+
readonly authorizationPath: string;
|
|
111
|
+
readonly tokenPath: string;
|
|
112
|
+
readonly registrationPath: string;
|
|
113
|
+
readonly oauthAuthorizationServerMetadataPath: string;
|
|
114
|
+
readonly protectedResourceMetadataPath: string;
|
|
115
|
+
}
|
|
116
|
+
interface EditorMcpProxy {
|
|
117
|
+
readonly paths: EditorMcpProxyPaths;
|
|
118
|
+
fetch(request: Request): Promise<Response>;
|
|
119
|
+
}
|
|
120
|
+
declare function createEditorMcpProxy(config: EditorMcpProxyConfig): EditorMcpProxy;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/index.d.ts
|
|
123
|
+
/** Explicit runtime bindings/config passed to agent-cms */
|
|
124
|
+
interface CmsBindings {
|
|
125
|
+
db: D1Database;
|
|
126
|
+
assets?: R2Bucket;
|
|
127
|
+
environment?: "production" | "development";
|
|
128
|
+
/** Public URL base for assets (e.g. "https://my-cms.workers.dev") */
|
|
129
|
+
assetBaseUrl?: string;
|
|
130
|
+
/** Write API key — required for REST writes, MCP, publish/unpublish.
|
|
131
|
+
* Like DatoCMS CMA token. Use any string for local dev (e.g. "dev"). */
|
|
132
|
+
writeKey?: string;
|
|
133
|
+
/** Workers AI binding for embedding generation (optional — enables vector search) */
|
|
134
|
+
ai?: AiBinding;
|
|
135
|
+
/** Vectorize index binding (optional — enables semantic search) */
|
|
136
|
+
vectorize?: VectorizeBinding;
|
|
137
|
+
/** R2 API token access key ID — enables presigned upload URLs */
|
|
138
|
+
r2AccessKeyId?: string;
|
|
139
|
+
/** R2 API token secret access key — enables presigned upload URLs */
|
|
140
|
+
r2SecretAccessKey?: string;
|
|
141
|
+
/** R2 bucket name — needed for presigned upload URLs */
|
|
142
|
+
r2BucketName?: string;
|
|
143
|
+
/** Cloudflare account ID — needed for the R2 S3-compatible endpoint */
|
|
144
|
+
cfAccountId?: string;
|
|
145
|
+
}
|
|
146
|
+
interface CmsHandlerConfig {
|
|
147
|
+
bindings: CmsBindings;
|
|
148
|
+
/** Lifecycle hooks fired on content events */
|
|
149
|
+
hooks?: CmsHooks;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create the agent-cms fetch handler.
|
|
153
|
+
*
|
|
154
|
+
* Usage in your Worker's src/index.ts:
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import { createCMSHandler } from "agent-cms";
|
|
157
|
+
*
|
|
158
|
+
* export default {
|
|
159
|
+
* fetch: (request, env) => getHandler(env).fetch(request),
|
|
160
|
+
* scheduled: (_controller, env) => getHandler(env).runScheduledTransitions(),
|
|
161
|
+
* };
|
|
162
|
+
*
|
|
163
|
+
* let cachedHandler: ReturnType<typeof createCMSHandler> | null = null;
|
|
164
|
+
*
|
|
165
|
+
* function getHandler(env: Env) {
|
|
166
|
+
* if (!cachedHandler) {
|
|
167
|
+
* cachedHandler = createCMSHandler({
|
|
168
|
+
* bindings: {
|
|
169
|
+
* db: env.DB,
|
|
170
|
+
* assets: env.ASSETS,
|
|
171
|
+
* environment: env.ENVIRONMENT,
|
|
172
|
+
* assetBaseUrl: env.ASSET_BASE_URL,
|
|
173
|
+
* writeKey: env.CMS_WRITE_KEY,
|
|
174
|
+
* ai: env.AI,
|
|
175
|
+
* vectorize: env.VECTORIZE,
|
|
176
|
+
* },
|
|
177
|
+
* });
|
|
178
|
+
* }
|
|
179
|
+
* return cachedHandler;
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function createCMSHandler(config: CmsHandlerConfig): {
|
|
184
|
+
fetch: (request: Request) => Promise<Response>;
|
|
185
|
+
/**
|
|
186
|
+
* Execute a GraphQL query directly, without HTTP serialization.
|
|
187
|
+
* For in-process queries when CMS and site share a Worker.
|
|
188
|
+
* Skips CORS, auth, and request logging — caller is trusted.
|
|
189
|
+
*/
|
|
190
|
+
execute: (query: string, variables?: Record<string, unknown>, context?: {
|
|
191
|
+
includeDrafts?: boolean;
|
|
192
|
+
excludeInvalid?: boolean;
|
|
193
|
+
}) => Promise<{
|
|
194
|
+
data: unknown;
|
|
195
|
+
errors?: ReadonlyArray<{
|
|
196
|
+
message: string;
|
|
197
|
+
}>;
|
|
198
|
+
}>; /** Run due scheduled publish/unpublish transitions. Safe to call from a cron trigger. */
|
|
199
|
+
runScheduledTransitions: (now?: Date) => Promise<{
|
|
200
|
+
now: string;
|
|
201
|
+
published: {
|
|
202
|
+
modelApiKey: string;
|
|
203
|
+
recordId: string;
|
|
204
|
+
}[];
|
|
205
|
+
unpublished: {
|
|
206
|
+
modelApiKey: string;
|
|
207
|
+
recordId: string;
|
|
208
|
+
}[];
|
|
209
|
+
}>;
|
|
210
|
+
};
|
|
211
|
+
//#endregion
|
|
212
|
+
export { type CmsAdminClientConfig, CmsBindings, CmsHandlerConfig, type CmsHooks, type CreateEditorTokenRequest, type CreateEditorTokenResponse, type EditorMcpPrincipal, type EditorMcpProxy, type EditorMcpProxyConfig, type EditorMcpProxyPaths, type EditorTokenListItem, createCMSHandler, createCmsAdminClient, createEditorMcpProxy };
|
|
213
|
+
//# sourceMappingURL=index.d.mts.map
|