string-sdk
Version:
JavaScript/TypeScript client for the String SmartLink platform (Context OS)
39 lines (38 loc) • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptSurfacesClient = void 0;
const cross_fetch_1 = __importDefault(require("cross-fetch"));
class PromptSurfacesClient {
constructor(opts) {
this.opts = opts;
}
/**
* Generates or retrieves a dynamic prompt surface for a given key & context.
*/
async generate(payload) {
const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/rewrite_prompt_surface`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}),
},
body: JSON.stringify(payload),
});
if (!res.ok)
throw new Error(`generatePromptSurface failed: ${await res.text()}`);
return res.json();
}
/** List recent prompt surfaces (admin/debug). */
async list(limit = 20) {
const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/rest/v1/prompt_surfaces?order=created_at.desc&limit=${limit}`, {
headers: { apikey: this.opts.anonKey || '' },
});
if (!res.ok)
throw new Error(`listPromptSurfaces failed: ${await res.text()}`);
return res.json();
}
}
exports.PromptSurfacesClient = PromptSurfacesClient;