@speakspec/astro 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -56,6 +56,34 @@ export const POST = aidpWebhookRoute()
56
56
  > (treats it as private). Use `api/aidp/...` (no leading underscore).
57
57
  > The path you register with the SpeakSpec dashboard must match.
58
58
 
59
+ ## Content inline vs directory (v0.4+)
60
+
61
+ AIDP v0.4 introduces per-type content strategy. The entity owner can decide, per content type, whether content appears:
62
+
63
+ - **Inline** (`inline`, default): full content envelopes appear inside `/.well-known/aidp.json`'s `content` array
64
+ - **Directory** (`directory`): the type is omitted from `aidp.json.content`; AI agents fetch `/.well-known/aidp/content/directory.json` for the index, and `/.well-known/aidp/content/{id}.json` for individual envelopes
65
+
66
+ The `content_index` field in `aidp.json` declares which types are inlined vs indexed:
67
+
68
+ ```json
69
+ {
70
+ "content_index": {
71
+ "url": "https://example.com/.well-known/aidp/content/directory.json",
72
+ "types_inlined": ["faq", "service"],
73
+ "types_indexed": ["article", "event"],
74
+ "total_by_type": { "article": 1240, "event": 387, "faq": 18, "service": 6 },
75
+ "pinned_count": 3,
76
+ "updated_at": "2026-05-12T10:00:00Z"
77
+ }
78
+ }
79
+ ```
80
+
81
+ The SDK proxies the upstream response transparently—no client code change is needed when an entity owner switches strategy. AI consumers should check `content_index.types_indexed` and pull `directory.json` when needed.
82
+
83
+ ### Pinned content
84
+
85
+ Any content can be marked `pinned: true`. Pinned content always appears in `aidp.json.content` regardless of the type's strategy, sorted first.
86
+
59
87
  ## Wire the bot-detection middleware
60
88
 
61
89
  ```ts
@@ -26,10 +26,22 @@ export interface CacheStorage {
26
26
  export declare function invalidateEntityCache(storage: CacheStorage, slug: string): Promise<void>;
27
27
  export declare function invalidateContentCache(storage: CacheStorage, slug: string, contentId: string): Promise<void>;
28
28
  /**
29
- * Build a JSON Response with cache headers, short-circuiting to 304
30
- * when the inbound `If-None-Match` matches the response ETag (per
31
- * AIDP §8.7 + RFC 7232 §2.3.2 weak comparison via `etagMatches`).
29
+ * Build a JSON Response with cache headers per AIDP §8.3 + §11.6,
30
+ * short-circuiting to 304 when the inbound `If-None-Match` matches the
31
+ * response ETag (per AIDP §8.7 + RFC 7232 §2.3.2 weak comparison via
32
+ * `etagMatches`).
32
33
  *
33
- * 304 responses still carry ETag + Cache-Control per RFC 7232 §4.1.
34
+ * 304 responses still carry ETag + Cache-Control per RFC 7232 §4.1, and
35
+ * we keep CORS on them so browser-side agents can revalidate cross-origin.
34
36
  */
35
37
  export declare function respondWithCache<T>(etag: string, payload: T, cacheControl: string, inboundIfNoneMatch: string | undefined | null): Response;
38
+ /**
39
+ * Project `directives.access_control` to an AIPREF-compatible
40
+ * `Content-Usage` header value per AIDP §11.6.
41
+ *
42
+ * Returns null when the payload is not an AIDP envelope (e.g. the
43
+ * directory listing has no `directives` field) or when `access_control`
44
+ * has no actionable flags — callers MUST NOT emit the header in that
45
+ * case rather than emitting an empty value.
46
+ */
47
+ export declare function buildContentUsage(payload: unknown): string | null;
@@ -55,26 +55,60 @@ export async function invalidateContentCache(storage, slug, contentId) {
55
55
  }
56
56
  }
57
57
  /**
58
- * Build a JSON Response with cache headers, short-circuiting to 304
59
- * when the inbound `If-None-Match` matches the response ETag (per
60
- * AIDP §8.7 + RFC 7232 §2.3.2 weak comparison via `etagMatches`).
58
+ * Build a JSON Response with cache headers per AIDP §8.3 + §11.6,
59
+ * short-circuiting to 304 when the inbound `If-None-Match` matches the
60
+ * response ETag (per AIDP §8.7 + RFC 7232 §2.3.2 weak comparison via
61
+ * `etagMatches`).
61
62
  *
62
- * 304 responses still carry ETag + Cache-Control per RFC 7232 §4.1.
63
+ * 304 responses still carry ETag + Cache-Control per RFC 7232 §4.1, and
64
+ * we keep CORS on them so browser-side agents can revalidate cross-origin.
63
65
  */
64
66
  export function respondWithCache(etag, payload, cacheControl, inboundIfNoneMatch) {
65
67
  const headers = {
66
68
  'cache-control': cacheControl,
69
+ 'access-control-allow-origin': '*',
67
70
  };
68
71
  if (etag)
69
72
  headers.etag = etag;
70
73
  if (etagMatches(inboundIfNoneMatch, etag)) {
71
74
  return new Response(null, { status: 304, headers });
72
75
  }
76
+ const usage = buildContentUsage(payload);
77
+ if (usage)
78
+ headers['content-usage'] = usage;
73
79
  return new Response(JSON.stringify(payload), {
74
80
  status: 200,
75
81
  headers: {
76
82
  ...headers,
77
- 'content-type': 'application/json; charset=utf-8',
83
+ 'content-type': 'application/aidp+json',
78
84
  },
79
85
  });
80
86
  }
87
+ /**
88
+ * Project `directives.access_control` to an AIPREF-compatible
89
+ * `Content-Usage` header value per AIDP §11.6.
90
+ *
91
+ * Returns null when the payload is not an AIDP envelope (e.g. the
92
+ * directory listing has no `directives` field) or when `access_control`
93
+ * has no actionable flags — callers MUST NOT emit the header in that
94
+ * case rather than emitting an empty value.
95
+ */
96
+ export function buildContentUsage(payload) {
97
+ if (!payload || typeof payload !== 'object')
98
+ return null;
99
+ const directives = payload.directives;
100
+ if (!directives || typeof directives !== 'object')
101
+ return null;
102
+ const ac = directives.access_control;
103
+ if (!ac || typeof ac !== 'object')
104
+ return null;
105
+ const flags = ac;
106
+ const parts = [];
107
+ if (flags.allow_training === true)
108
+ parts.push('allow=FoundationModelProduction');
109
+ else if (flags.allow_training === false)
110
+ parts.push('disallow=FoundationModelProduction');
111
+ if (flags.allow_derivative === true)
112
+ parts.push('allow=Search');
113
+ return parts.length > 0 ? parts.join(', ') : null;
114
+ }
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION: "0.0.1";
1
+ export declare const SDK_VERSION: "0.0.3";
2
2
  export declare const SDK_USER_AGENT: string;
@@ -1,2 +1,2 @@
1
- export const SDK_VERSION = "0.0.1";
1
+ export const SDK_VERSION = "0.0.3";
2
2
  export const SDK_USER_AGENT = `@speakspec/astro/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speakspec/astro",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "AIDP 0.3 publishing channel for Astro 5 — exposes /.well-known/aidp.json and friends, fetches signed content + pointer payloads from SpeakSpec, receives §8.10 cache-invalidation webhooks.",
5
5
  "repository": {
6
6
  "type": "git",