@creature-ai/sdk 0.1.7 → 0.1.8

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.
@@ -100,15 +100,27 @@ interface ResourceConfig {
100
100
  displayModes: DisplayMode[];
101
101
  /**
102
102
  * HTML content for the resource.
103
- * Can be a string path (resolved relative to the server file's directory),
104
- * or a function that returns the HTML content.
103
+ *
104
+ * Accepts three formats:
105
+ * 1. **File path** (local development): `"ui/main.html"` - loaded from filesystem
106
+ * 2. **Raw HTML** (serverless-safe): `"<!DOCTYPE html>..."` - used directly
107
+ * 3. **Function** (lazy loading): `() => htmlContent` - called when needed
108
+ *
109
+ * The SDK auto-detects HTML content (starts with `<`) vs file paths.
110
+ * For serverless (Vercel, Lambda), use raw HTML or a function.
105
111
  *
106
112
  * @example
107
- * // Simple path (recommended)
113
+ * // Local development - file path
108
114
  * html: "ui/main.html"
109
115
  *
110
- * // Function for dynamic content
111
- * html: () => loadHtml("./ui/main.html")
116
+ * @example
117
+ * // Serverless - bundled HTML (import at build time)
118
+ * import { BUNDLED_HTML } from "./ui-bundle.js";
119
+ * html: BUNDLED_HTML
120
+ *
121
+ * @example
122
+ * // Serverless - function (lazy)
123
+ * html: () => fs.readFileSync("./dist/ui/main.html", "utf-8")
112
124
  */
113
125
  html: string | (() => string | Promise<string>);
114
126
  /** Optional icon for pips */
@@ -607,10 +619,29 @@ declare function svgToDataUri(svg: string): string;
607
619
  */
608
620
  declare function loadHtml(filePath: string, basePath?: string): string;
609
621
  /**
610
- * Create an HTML loader function for a file path.
611
- * Useful for defining resources with lazy-loaded HTML.
622
+ * Check if a string is HTML content (vs a file path).
623
+ *
624
+ * HTML content detection:
625
+ * - Starts with `<` (with optional whitespace/BOM)
626
+ * - Starts with `<!DOCTYPE` (case-insensitive)
627
+ *
628
+ * This enables serverless deployments where HTML is bundled at build time
629
+ * and passed directly as a string, rather than loaded from the filesystem.
630
+ */
631
+ declare function isHtmlContent(str: string): boolean;
632
+ /**
633
+ * Create an HTML loader function for a file path or HTML content.
634
+ *
635
+ * For serverless environments (Vercel, Lambda), developers can:
636
+ * 1. Pass HTML content directly: `html: "<!DOCTYPE html>..."`
637
+ * 2. Use a function: `html: () => BUNDLED_HTML`
638
+ * 3. Import bundled HTML: `html: await import("./ui-bundle.js").then(m => m.HTML)`
639
+ *
640
+ * The SDK automatically detects whether the string is:
641
+ * - HTML content (starts with `<`) → returns as-is
642
+ * - File path → loads via filesystem (local dev only)
612
643
  */
613
- declare function htmlLoader(filePath: string, basePath?: string): () => string;
644
+ declare function htmlLoader(htmlOrPath: string, basePath?: string): () => string;
614
645
 
615
646
  /**
616
647
  * Middleware for adding cross-platform compatibility to the official MCP SDK.
@@ -784,4 +815,4 @@ interface VerifyConfig {
784
815
  */
785
816
  declare const verifyCreatureToken: (tokenOrHeader: string | undefined | null, config?: VerifyConfig) => Promise<CreatureIdentity>;
786
817
 
787
- export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, type CreatureOrganization, type CreatureProject, type CreatureSession, CreatureTokenError, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, htmlLoader, loadHtml, svgToDataUri, verifyCreatureToken, wrapServer };
818
+ export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, type CreatureOrganization, type CreatureProject, type CreatureSession, CreatureTokenError, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, verifyCreatureToken, wrapServer };
@@ -13401,7 +13401,7 @@ import path from "path";
13401
13401
 
13402
13402
  // src/vite/index.ts
13403
13403
  import { resolve, join, relative } from "path";
13404
- import { readdirSync, statSync, existsSync, writeFileSync, mkdirSync, rmSync } from "fs";
13404
+ import { readdirSync, statSync, existsSync, writeFileSync, mkdirSync, rmSync, readFileSync } from "fs";
13405
13405
  import { createServer as createNetServer } from "net";
13406
13406
  import { createServer as createHttpServer } from "http";
13407
13407
  import { createHash } from "crypto";
@@ -13554,8 +13554,15 @@ function loadHtml(filePath, basePath) {
13554
13554
  <p>Run <code>npm run build</code> to build the UI.</p>
13555
13555
  </body></html>`;
13556
13556
  }
13557
- function htmlLoader(filePath, basePath) {
13558
- return () => loadHtml(filePath, basePath);
13557
+ function isHtmlContent(str) {
13558
+ const trimmed = str.trimStart();
13559
+ return trimmed.startsWith("<") || trimmed.toLowerCase().startsWith("<!doctype");
13560
+ }
13561
+ function htmlLoader(htmlOrPath, basePath) {
13562
+ if (isHtmlContent(htmlOrPath)) {
13563
+ return () => htmlOrPath;
13564
+ }
13565
+ return () => loadHtml(htmlOrPath, basePath);
13559
13566
  }
13560
13567
  function isInitializeRequest2(body) {
13561
13568
  if (typeof body !== "object" || body === null) return false;
@@ -14856,6 +14863,7 @@ export {
14856
14863
  MIME_TYPES,
14857
14864
  createApp,
14858
14865
  htmlLoader,
14866
+ isHtmlContent,
14859
14867
  loadHtml,
14860
14868
  svgToDataUri,
14861
14869
  verifyCreatureToken,