@withgateway/sdk 0.1.4 → 0.1.5

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 (41) hide show
  1. package/dist/index-DnowA8MG.d.mts +447 -0
  2. package/dist/index-DnowA8MG.d.ts +447 -0
  3. package/dist/index.d.mts +6 -1
  4. package/dist/index.d.ts +6 -1
  5. package/dist/index.js +1544 -23
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1504 -17
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/personas/index.d.mts +102 -0
  10. package/dist/personas/index.d.ts +102 -0
  11. package/dist/personas/index.js +205 -0
  12. package/dist/personas/index.js.map +1 -0
  13. package/dist/personas/index.mjs +180 -0
  14. package/dist/personas/index.mjs.map +1 -0
  15. package/dist/replay/index.d.mts +351 -0
  16. package/dist/replay/index.d.ts +351 -0
  17. package/dist/replay/index.js +1094 -0
  18. package/dist/replay/index.js.map +1 -0
  19. package/dist/replay/index.mjs +1057 -0
  20. package/dist/replay/index.mjs.map +1 -0
  21. package/dist/sessions/index.d.mts +143 -0
  22. package/dist/sessions/index.d.ts +143 -0
  23. package/dist/sessions/index.js +320 -0
  24. package/dist/sessions/index.js.map +1 -0
  25. package/dist/sessions/index.mjs +288 -0
  26. package/dist/sessions/index.mjs.map +1 -0
  27. package/dist/tracing/index.d.mts +3 -1
  28. package/dist/tracing/index.d.ts +3 -1
  29. package/dist/tracing/index.js +270 -21
  30. package/dist/tracing/index.js.map +1 -1
  31. package/dist/tracing/index.mjs +259 -16
  32. package/dist/tracing/index.mjs.map +1 -1
  33. package/dist/users/index.d.mts +81 -0
  34. package/dist/users/index.d.ts +81 -0
  35. package/dist/users/index.js +168 -0
  36. package/dist/users/index.js.map +1 -0
  37. package/dist/users/index.mjs +144 -0
  38. package/dist/users/index.mjs.map +1 -0
  39. package/package.json +21 -1
  40. package/dist/index-yJgb8wh6.d.mts +0 -273
  41. package/dist/index-yJgb8wh6.d.ts +0 -273
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Personas — simulated users served by the Gateway platform.
3
+ *
4
+ * A persona is a crafted user profile (usually derived from real sessions on
5
+ * the platform) that Gateway serves as an endpoint. Use it to drive your agent
6
+ * in tests: the persona plays the user, your agent plays itself.
7
+ *
8
+ * Example:
9
+ * ```ts
10
+ * import { PersonasClient } from "@withgateway/sdk/personas";
11
+ *
12
+ * const personas = PersonasClient.fromEnv();
13
+ * const persona = await personas.get("persona_id");
14
+ *
15
+ * const messages: PersonaMessage[] = [];
16
+ * let reply = await persona.respond(messages); // persona opens the conversation
17
+ * while (!reply.done) {
18
+ * messages.push({ role: "user", content: reply.content });
19
+ * const agentAnswer = await myAgent(messages); // your agent under test
20
+ * messages.push({ role: "assistant", content: agentAnswer });
21
+ * reply = await persona.respond(messages);
22
+ * }
23
+ * ```
24
+ *
25
+ * Message roles are from YOUR agent's perspective: `user` = the simulated
26
+ * user's turns, `assistant` = your agent's turns.
27
+ */
28
+ type PersonaMessage = {
29
+ role: "user" | "assistant";
30
+ content: string;
31
+ };
32
+ /** One simulated-user turn. */
33
+ type PersonaReply = {
34
+ content: string;
35
+ done: boolean;
36
+ };
37
+ type PersonasClientConfig = {
38
+ host: string;
39
+ publicKey: string;
40
+ secretKey: string;
41
+ timeoutSeconds?: number;
42
+ debug?: boolean;
43
+ };
44
+ type PersonasClientFromEnvConfig = Partial<PersonasClientConfig>;
45
+ /** Raised when the Gateway personas API cannot complete a request. */
46
+ declare class PersonaError extends Error {
47
+ constructor(message: string, options?: {
48
+ cause?: unknown;
49
+ });
50
+ }
51
+ /** A persona definition plus a bound `respond` helper. */
52
+ declare class Persona {
53
+ readonly id: string;
54
+ readonly name: string;
55
+ readonly description: string | null;
56
+ readonly version: number;
57
+ readonly instructions: string;
58
+ readonly examples: string[];
59
+ private readonly client;
60
+ constructor(fields: {
61
+ id: string;
62
+ name: string;
63
+ description: string | null;
64
+ version: number;
65
+ instructions: string;
66
+ examples?: string[];
67
+ client?: PersonasClient | null;
68
+ });
69
+ /**
70
+ * Get the persona's next user message for a conversation.
71
+ *
72
+ * `messages` use your agent's perspective: role `user` for the simulated
73
+ * user's prior turns, `assistant` for your agent's turns.
74
+ * `done` is true when the persona considers its goal met.
75
+ */
76
+ respond(messages: PersonaMessage[]): Promise<PersonaReply>;
77
+ }
78
+ /** Client for Gateway's persona endpoints (HTTP Basic project keys). */
79
+ declare class PersonasClient {
80
+ private readonly host;
81
+ private readonly publicKey;
82
+ private readonly secretKey;
83
+ private readonly timeoutSeconds;
84
+ private readonly debug;
85
+ constructor(config: PersonasClientConfig);
86
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
87
+ static fromEnv(config?: PersonasClientFromEnvConfig): PersonasClient;
88
+ /** List the project's personas (without full instructions). */
89
+ list(): Promise<Persona[]>;
90
+ /** Fetch a persona (full definition) bound to this client. */
91
+ get(personaId: string): Promise<Persona>;
92
+ /** Play one persona turn. See {@link Persona.respond}. */
93
+ chat(personaId: string, messages: PersonaMessage[]): Promise<PersonaReply>;
94
+ private requestJson;
95
+ private authHeader;
96
+ private log;
97
+ }
98
+ declare const personas: {
99
+ fromEnv: typeof PersonasClient.fromEnv;
100
+ };
101
+
102
+ export { Persona, PersonaError, type PersonaMessage, type PersonaReply, PersonasClient, type PersonasClientConfig, type PersonasClientFromEnvConfig, personas };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Personas — simulated users served by the Gateway platform.
3
+ *
4
+ * A persona is a crafted user profile (usually derived from real sessions on
5
+ * the platform) that Gateway serves as an endpoint. Use it to drive your agent
6
+ * in tests: the persona plays the user, your agent plays itself.
7
+ *
8
+ * Example:
9
+ * ```ts
10
+ * import { PersonasClient } from "@withgateway/sdk/personas";
11
+ *
12
+ * const personas = PersonasClient.fromEnv();
13
+ * const persona = await personas.get("persona_id");
14
+ *
15
+ * const messages: PersonaMessage[] = [];
16
+ * let reply = await persona.respond(messages); // persona opens the conversation
17
+ * while (!reply.done) {
18
+ * messages.push({ role: "user", content: reply.content });
19
+ * const agentAnswer = await myAgent(messages); // your agent under test
20
+ * messages.push({ role: "assistant", content: agentAnswer });
21
+ * reply = await persona.respond(messages);
22
+ * }
23
+ * ```
24
+ *
25
+ * Message roles are from YOUR agent's perspective: `user` = the simulated
26
+ * user's turns, `assistant` = your agent's turns.
27
+ */
28
+ type PersonaMessage = {
29
+ role: "user" | "assistant";
30
+ content: string;
31
+ };
32
+ /** One simulated-user turn. */
33
+ type PersonaReply = {
34
+ content: string;
35
+ done: boolean;
36
+ };
37
+ type PersonasClientConfig = {
38
+ host: string;
39
+ publicKey: string;
40
+ secretKey: string;
41
+ timeoutSeconds?: number;
42
+ debug?: boolean;
43
+ };
44
+ type PersonasClientFromEnvConfig = Partial<PersonasClientConfig>;
45
+ /** Raised when the Gateway personas API cannot complete a request. */
46
+ declare class PersonaError extends Error {
47
+ constructor(message: string, options?: {
48
+ cause?: unknown;
49
+ });
50
+ }
51
+ /** A persona definition plus a bound `respond` helper. */
52
+ declare class Persona {
53
+ readonly id: string;
54
+ readonly name: string;
55
+ readonly description: string | null;
56
+ readonly version: number;
57
+ readonly instructions: string;
58
+ readonly examples: string[];
59
+ private readonly client;
60
+ constructor(fields: {
61
+ id: string;
62
+ name: string;
63
+ description: string | null;
64
+ version: number;
65
+ instructions: string;
66
+ examples?: string[];
67
+ client?: PersonasClient | null;
68
+ });
69
+ /**
70
+ * Get the persona's next user message for a conversation.
71
+ *
72
+ * `messages` use your agent's perspective: role `user` for the simulated
73
+ * user's prior turns, `assistant` for your agent's turns.
74
+ * `done` is true when the persona considers its goal met.
75
+ */
76
+ respond(messages: PersonaMessage[]): Promise<PersonaReply>;
77
+ }
78
+ /** Client for Gateway's persona endpoints (HTTP Basic project keys). */
79
+ declare class PersonasClient {
80
+ private readonly host;
81
+ private readonly publicKey;
82
+ private readonly secretKey;
83
+ private readonly timeoutSeconds;
84
+ private readonly debug;
85
+ constructor(config: PersonasClientConfig);
86
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
87
+ static fromEnv(config?: PersonasClientFromEnvConfig): PersonasClient;
88
+ /** List the project's personas (without full instructions). */
89
+ list(): Promise<Persona[]>;
90
+ /** Fetch a persona (full definition) bound to this client. */
91
+ get(personaId: string): Promise<Persona>;
92
+ /** Play one persona turn. See {@link Persona.respond}. */
93
+ chat(personaId: string, messages: PersonaMessage[]): Promise<PersonaReply>;
94
+ private requestJson;
95
+ private authHeader;
96
+ private log;
97
+ }
98
+ declare const personas: {
99
+ fromEnv: typeof PersonasClient.fromEnv;
100
+ };
101
+
102
+ export { Persona, PersonaError, type PersonaMessage, type PersonaReply, PersonasClient, type PersonasClientConfig, type PersonasClientFromEnvConfig, personas };
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/personas/index.ts
21
+ var personas_exports = {};
22
+ __export(personas_exports, {
23
+ Persona: () => Persona,
24
+ PersonaError: () => PersonaError,
25
+ PersonasClient: () => PersonasClient,
26
+ personas: () => personas
27
+ });
28
+ module.exports = __toCommonJS(personas_exports);
29
+ var PersonaError = class extends Error {
30
+ constructor(message, options) {
31
+ super(message);
32
+ this.name = "PersonaError";
33
+ this.cause = options?.cause;
34
+ }
35
+ };
36
+ var Persona = class {
37
+ id;
38
+ name;
39
+ description;
40
+ version;
41
+ instructions;
42
+ examples;
43
+ client;
44
+ constructor(fields) {
45
+ this.id = fields.id;
46
+ this.name = fields.name;
47
+ this.description = fields.description;
48
+ this.version = fields.version;
49
+ this.instructions = fields.instructions;
50
+ this.examples = fields.examples ?? [];
51
+ this.client = fields.client ?? null;
52
+ }
53
+ /**
54
+ * Get the persona's next user message for a conversation.
55
+ *
56
+ * `messages` use your agent's perspective: role `user` for the simulated
57
+ * user's prior turns, `assistant` for your agent's turns.
58
+ * `done` is true when the persona considers its goal met.
59
+ */
60
+ respond(messages) {
61
+ if (this.client === null) {
62
+ throw new PersonaError("Persona is not bound to a client.");
63
+ }
64
+ return this.client.chat(this.id, messages);
65
+ }
66
+ };
67
+ var PersonasClient = class _PersonasClient {
68
+ host;
69
+ publicKey;
70
+ secretKey;
71
+ timeoutSeconds;
72
+ debug;
73
+ constructor(config) {
74
+ this.host = config.host.replace(/\/$/, "");
75
+ this.publicKey = config.publicKey;
76
+ this.secretKey = config.secretKey;
77
+ this.timeoutSeconds = config.timeoutSeconds ?? 120;
78
+ this.debug = config.debug ?? false;
79
+ }
80
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
81
+ static fromEnv(config = {}) {
82
+ const host = config.host ?? process.env.GATEWAY_HOST;
83
+ const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
84
+ const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;
85
+ const missing = [
86
+ ["host", host],
87
+ ["publicKey", publicKey],
88
+ ["secretKey", secretKey]
89
+ ].filter(([, value]) => !value).map(([name]) => name);
90
+ if (missing.length > 0) {
91
+ throw new PersonaError(
92
+ `Missing Gateway persona configuration: ${missing.join(", ")}`
93
+ );
94
+ }
95
+ return new _PersonasClient({
96
+ ...config,
97
+ host,
98
+ publicKey,
99
+ secretKey
100
+ });
101
+ }
102
+ /** List the project's personas (without full instructions). */
103
+ async list() {
104
+ const payload = await this.requestJson("GET", "/api/public/personas");
105
+ const items = Array.isArray(payload.data) ? payload.data : [];
106
+ return items.filter(isRecord).map(
107
+ (item) => new Persona({
108
+ id: String(item.id),
109
+ name: String(item.name),
110
+ description: item.description ?? null,
111
+ version: typeof item.version === "number" ? item.version : 1,
112
+ instructions: "",
113
+ client: this
114
+ })
115
+ );
116
+ }
117
+ /** Fetch a persona (full definition) bound to this client. */
118
+ async get(personaId) {
119
+ const item = await this.requestJson(
120
+ "GET",
121
+ `/api/public/personas/${encodeURIComponent(personaId)}/chat`
122
+ );
123
+ return new Persona({
124
+ id: String(item.id),
125
+ name: String(item.name),
126
+ description: item.description ?? null,
127
+ version: typeof item.version === "number" ? item.version : 1,
128
+ instructions: typeof item.instructions === "string" ? item.instructions : "",
129
+ examples: Array.isArray(item.examples) ? item.examples.map((example) => String(example)) : [],
130
+ client: this
131
+ });
132
+ }
133
+ /** Play one persona turn. See {@link Persona.respond}. */
134
+ async chat(personaId, messages) {
135
+ const payload = await this.requestJson(
136
+ "POST",
137
+ `/api/public/personas/${encodeURIComponent(personaId)}/chat`,
138
+ { messages }
139
+ );
140
+ return {
141
+ content: typeof payload.content === "string" ? payload.content : "",
142
+ done: Boolean(payload.done)
143
+ };
144
+ }
145
+ async requestJson(method, path, payload) {
146
+ let response;
147
+ try {
148
+ response = await fetch(`${this.host}${path}`, {
149
+ method,
150
+ headers: {
151
+ Authorization: this.authHeader(),
152
+ "Content-Type": "application/json"
153
+ },
154
+ ...payload ? { body: JSON.stringify(payload) } : {},
155
+ signal: AbortSignal.timeout(this.timeoutSeconds * 1e3)
156
+ });
157
+ } catch (error) {
158
+ const reason = error instanceof Error ? error.message : String(error);
159
+ throw new PersonaError(`${method} ${path} failed: ${reason}`, {
160
+ cause: error
161
+ });
162
+ }
163
+ const text = await response.text();
164
+ if (!response.ok) {
165
+ const detail = text.slice(0, 500);
166
+ throw new PersonaError(
167
+ `${method} ${path} failed (${response.status}): ${detail}`
168
+ );
169
+ }
170
+ this.log("%s %s -> %s", method, path, response.status);
171
+ return safeJson(text);
172
+ }
173
+ authHeader() {
174
+ return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
175
+ "base64"
176
+ )}`;
177
+ }
178
+ log(message, ...args) {
179
+ if (this.debug) {
180
+ console.log(`[gateway.personas] ${message}`, ...args);
181
+ }
182
+ }
183
+ };
184
+ function isRecord(value) {
185
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
186
+ }
187
+ function safeJson(value) {
188
+ try {
189
+ const parsed = JSON.parse(value);
190
+ return isRecord(parsed) ? parsed : {};
191
+ } catch {
192
+ return {};
193
+ }
194
+ }
195
+ var personas = {
196
+ fromEnv: PersonasClient.fromEnv
197
+ };
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ Persona,
201
+ PersonaError,
202
+ PersonasClient,
203
+ personas
204
+ });
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/personas/index.ts"],"sourcesContent":["/**\n * Personas — simulated users served by the Gateway platform.\n *\n * A persona is a crafted user profile (usually derived from real sessions on\n * the platform) that Gateway serves as an endpoint. Use it to drive your agent\n * in tests: the persona plays the user, your agent plays itself.\n *\n * Example:\n * ```ts\n * import { PersonasClient } from \"@withgateway/sdk/personas\";\n *\n * const personas = PersonasClient.fromEnv();\n * const persona = await personas.get(\"persona_id\");\n *\n * const messages: PersonaMessage[] = [];\n * let reply = await persona.respond(messages); // persona opens the conversation\n * while (!reply.done) {\n * messages.push({ role: \"user\", content: reply.content });\n * const agentAnswer = await myAgent(messages); // your agent under test\n * messages.push({ role: \"assistant\", content: agentAnswer });\n * reply = await persona.respond(messages);\n * }\n * ```\n *\n * Message roles are from YOUR agent's perspective: `user` = the simulated\n * user's turns, `assistant` = your agent's turns.\n */\n\ntype PersonaMessage = {\n role: \"user\" | \"assistant\";\n content: string;\n};\n\n/** One simulated-user turn. */\ntype PersonaReply = {\n content: string;\n done: boolean;\n};\n\ntype PersonasClientConfig = {\n host: string;\n publicKey: string;\n secretKey: string;\n timeoutSeconds?: number;\n debug?: boolean;\n};\n\ntype PersonasClientFromEnvConfig = Partial<PersonasClientConfig>;\n\n/** Raised when the Gateway personas API cannot complete a request. */\nexport class PersonaError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = \"PersonaError\";\n this.cause = options?.cause;\n }\n}\n\n/** A persona definition plus a bound `respond` helper. */\nexport class Persona {\n readonly id: string;\n readonly name: string;\n readonly description: string | null;\n readonly version: number;\n readonly instructions: string;\n readonly examples: string[];\n private readonly client: PersonasClient | null;\n\n constructor(fields: {\n id: string;\n name: string;\n description: string | null;\n version: number;\n instructions: string;\n examples?: string[];\n client?: PersonasClient | null;\n }) {\n this.id = fields.id;\n this.name = fields.name;\n this.description = fields.description;\n this.version = fields.version;\n this.instructions = fields.instructions;\n this.examples = fields.examples ?? [];\n this.client = fields.client ?? null;\n }\n\n /**\n * Get the persona's next user message for a conversation.\n *\n * `messages` use your agent's perspective: role `user` for the simulated\n * user's prior turns, `assistant` for your agent's turns.\n * `done` is true when the persona considers its goal met.\n */\n respond(messages: PersonaMessage[]): Promise<PersonaReply> {\n if (this.client === null) {\n throw new PersonaError(\"Persona is not bound to a client.\");\n }\n return this.client.chat(this.id, messages);\n }\n}\n\n/** Client for Gateway's persona endpoints (HTTP Basic project keys). */\nexport class PersonasClient {\n private readonly host: string;\n private readonly publicKey: string;\n private readonly secretKey: string;\n private readonly timeoutSeconds: number;\n private readonly debug: boolean;\n\n constructor(config: PersonasClientConfig) {\n this.host = config.host.replace(/\\/$/, \"\");\n this.publicKey = config.publicKey;\n this.secretKey = config.secretKey;\n this.timeoutSeconds = config.timeoutSeconds ?? 120;\n this.debug = config.debug ?? false;\n }\n\n /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */\n static fromEnv(config: PersonasClientFromEnvConfig = {}) {\n const host = config.host ?? process.env.GATEWAY_HOST;\n const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;\n\n const missing = [\n [\"host\", host],\n [\"publicKey\", publicKey],\n [\"secretKey\", secretKey],\n ]\n .filter(([, value]) => !value)\n .map(([name]) => name);\n\n if (missing.length > 0) {\n throw new PersonaError(\n `Missing Gateway persona configuration: ${missing.join(\", \")}`,\n );\n }\n\n return new PersonasClient({\n ...config,\n host: host!,\n publicKey: publicKey!,\n secretKey: secretKey!,\n });\n }\n\n /** List the project's personas (without full instructions). */\n async list(): Promise<Persona[]> {\n const payload = await this.requestJson(\"GET\", \"/api/public/personas\");\n const items = Array.isArray(payload.data) ? payload.data : [];\n return items\n .filter(isRecord)\n .map(\n (item) =>\n new Persona({\n id: String(item.id),\n name: String(item.name),\n description: (item.description as string | null | undefined) ?? null,\n version: typeof item.version === \"number\" ? item.version : 1,\n instructions: \"\",\n client: this,\n }),\n );\n }\n\n /** Fetch a persona (full definition) bound to this client. */\n async get(personaId: string): Promise<Persona> {\n const item = await this.requestJson(\n \"GET\",\n `/api/public/personas/${encodeURIComponent(personaId)}/chat`,\n );\n return new Persona({\n id: String(item.id),\n name: String(item.name),\n description: (item.description as string | null | undefined) ?? null,\n version: typeof item.version === \"number\" ? item.version : 1,\n instructions: typeof item.instructions === \"string\" ? item.instructions : \"\",\n examples: Array.isArray(item.examples)\n ? item.examples.map((example) => String(example))\n : [],\n client: this,\n });\n }\n\n /** Play one persona turn. See {@link Persona.respond}. */\n async chat(\n personaId: string,\n messages: PersonaMessage[],\n ): Promise<PersonaReply> {\n const payload = await this.requestJson(\n \"POST\",\n `/api/public/personas/${encodeURIComponent(personaId)}/chat`,\n { messages },\n );\n return {\n content: typeof payload.content === \"string\" ? payload.content : \"\",\n done: Boolean(payload.done),\n };\n }\n\n private async requestJson(\n method: \"GET\" | \"POST\",\n path: string,\n payload?: Record<string, unknown>,\n ): Promise<Record<string, unknown>> {\n let response: Response;\n try {\n response = await fetch(`${this.host}${path}`, {\n method,\n headers: {\n Authorization: this.authHeader(),\n \"Content-Type\": \"application/json\",\n },\n ...(payload ? { body: JSON.stringify(payload) } : {}),\n signal: AbortSignal.timeout(this.timeoutSeconds * 1000),\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new PersonaError(`${method} ${path} failed: ${reason}`, {\n cause: error,\n });\n }\n\n const text = await response.text();\n if (!response.ok) {\n const detail = text.slice(0, 500);\n throw new PersonaError(\n `${method} ${path} failed (${response.status}): ${detail}`,\n );\n }\n\n this.log(\"%s %s -> %s\", method, path, response.status);\n return safeJson(text);\n }\n\n private authHeader() {\n return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(\n \"base64\",\n )}`;\n }\n\n private log(message: string, ...args: unknown[]) {\n if (this.debug) {\n console.log(`[gateway.personas] ${message}`, ...args);\n }\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction safeJson(value: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(value);\n return isRecord(parsed) ? parsed : {};\n } catch {\n return {};\n }\n}\n\nexport const personas = {\n fromEnv: PersonasClient.fromEnv,\n};\n\nexport type {\n PersonaMessage,\n PersonaReply,\n PersonasClientConfig,\n PersonasClientFromEnvConfig,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ,SAAS;AAAA,EACxB;AACF;AAGO,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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AQ,IAAI,sBAAsB,OAAO,IAAI,GAAG,IAAI;AAAA,IACtD;AAAA,EACF;AACF;AAEA,SAAS,SAAS,OAAkD;AAClE,SAAO,QAAQ,KAAK,KAAK,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,SAAS,OAAwC;AACxD,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,WAAO,SAAS,MAAM,IAAI,SAAS,CAAC;AAAA,EACtC,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEO,IAAM,WAAW;AAAA,EACtB,SAAS,eAAe;AAC1B;","names":[]}
@@ -0,0 +1,180 @@
1
+ import { createRequire as __gatewayCreateRequire } from "module";
2
+ const require = __gatewayCreateRequire(import.meta.url);
3
+
4
+ // src/personas/index.ts
5
+ var PersonaError = class extends Error {
6
+ constructor(message, options) {
7
+ super(message);
8
+ this.name = "PersonaError";
9
+ this.cause = options?.cause;
10
+ }
11
+ };
12
+ var Persona = class {
13
+ id;
14
+ name;
15
+ description;
16
+ version;
17
+ instructions;
18
+ examples;
19
+ client;
20
+ constructor(fields) {
21
+ this.id = fields.id;
22
+ this.name = fields.name;
23
+ this.description = fields.description;
24
+ this.version = fields.version;
25
+ this.instructions = fields.instructions;
26
+ this.examples = fields.examples ?? [];
27
+ this.client = fields.client ?? null;
28
+ }
29
+ /**
30
+ * Get the persona's next user message for a conversation.
31
+ *
32
+ * `messages` use your agent's perspective: role `user` for the simulated
33
+ * user's prior turns, `assistant` for your agent's turns.
34
+ * `done` is true when the persona considers its goal met.
35
+ */
36
+ respond(messages) {
37
+ if (this.client === null) {
38
+ throw new PersonaError("Persona is not bound to a client.");
39
+ }
40
+ return this.client.chat(this.id, messages);
41
+ }
42
+ };
43
+ var PersonasClient = class _PersonasClient {
44
+ host;
45
+ publicKey;
46
+ secretKey;
47
+ timeoutSeconds;
48
+ debug;
49
+ constructor(config) {
50
+ this.host = config.host.replace(/\/$/, "");
51
+ this.publicKey = config.publicKey;
52
+ this.secretKey = config.secretKey;
53
+ this.timeoutSeconds = config.timeoutSeconds ?? 120;
54
+ this.debug = config.debug ?? false;
55
+ }
56
+ /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */
57
+ static fromEnv(config = {}) {
58
+ const host = config.host ?? process.env.GATEWAY_HOST;
59
+ const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;
60
+ const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;
61
+ const missing = [
62
+ ["host", host],
63
+ ["publicKey", publicKey],
64
+ ["secretKey", secretKey]
65
+ ].filter(([, value]) => !value).map(([name]) => name);
66
+ if (missing.length > 0) {
67
+ throw new PersonaError(
68
+ `Missing Gateway persona configuration: ${missing.join(", ")}`
69
+ );
70
+ }
71
+ return new _PersonasClient({
72
+ ...config,
73
+ host,
74
+ publicKey,
75
+ secretKey
76
+ });
77
+ }
78
+ /** List the project's personas (without full instructions). */
79
+ async list() {
80
+ const payload = await this.requestJson("GET", "/api/public/personas");
81
+ const items = Array.isArray(payload.data) ? payload.data : [];
82
+ return items.filter(isRecord).map(
83
+ (item) => new Persona({
84
+ id: String(item.id),
85
+ name: String(item.name),
86
+ description: item.description ?? null,
87
+ version: typeof item.version === "number" ? item.version : 1,
88
+ instructions: "",
89
+ client: this
90
+ })
91
+ );
92
+ }
93
+ /** Fetch a persona (full definition) bound to this client. */
94
+ async get(personaId) {
95
+ const item = await this.requestJson(
96
+ "GET",
97
+ `/api/public/personas/${encodeURIComponent(personaId)}/chat`
98
+ );
99
+ return new Persona({
100
+ id: String(item.id),
101
+ name: String(item.name),
102
+ description: item.description ?? null,
103
+ version: typeof item.version === "number" ? item.version : 1,
104
+ instructions: typeof item.instructions === "string" ? item.instructions : "",
105
+ examples: Array.isArray(item.examples) ? item.examples.map((example) => String(example)) : [],
106
+ client: this
107
+ });
108
+ }
109
+ /** Play one persona turn. See {@link Persona.respond}. */
110
+ async chat(personaId, messages) {
111
+ const payload = await this.requestJson(
112
+ "POST",
113
+ `/api/public/personas/${encodeURIComponent(personaId)}/chat`,
114
+ { messages }
115
+ );
116
+ return {
117
+ content: typeof payload.content === "string" ? payload.content : "",
118
+ done: Boolean(payload.done)
119
+ };
120
+ }
121
+ async requestJson(method, path, payload) {
122
+ let response;
123
+ try {
124
+ response = await fetch(`${this.host}${path}`, {
125
+ method,
126
+ headers: {
127
+ Authorization: this.authHeader(),
128
+ "Content-Type": "application/json"
129
+ },
130
+ ...payload ? { body: JSON.stringify(payload) } : {},
131
+ signal: AbortSignal.timeout(this.timeoutSeconds * 1e3)
132
+ });
133
+ } catch (error) {
134
+ const reason = error instanceof Error ? error.message : String(error);
135
+ throw new PersonaError(`${method} ${path} failed: ${reason}`, {
136
+ cause: error
137
+ });
138
+ }
139
+ const text = await response.text();
140
+ if (!response.ok) {
141
+ const detail = text.slice(0, 500);
142
+ throw new PersonaError(
143
+ `${method} ${path} failed (${response.status}): ${detail}`
144
+ );
145
+ }
146
+ this.log("%s %s -> %s", method, path, response.status);
147
+ return safeJson(text);
148
+ }
149
+ authHeader() {
150
+ return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(
151
+ "base64"
152
+ )}`;
153
+ }
154
+ log(message, ...args) {
155
+ if (this.debug) {
156
+ console.log(`[gateway.personas] ${message}`, ...args);
157
+ }
158
+ }
159
+ };
160
+ function isRecord(value) {
161
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
162
+ }
163
+ function safeJson(value) {
164
+ try {
165
+ const parsed = JSON.parse(value);
166
+ return isRecord(parsed) ? parsed : {};
167
+ } catch {
168
+ return {};
169
+ }
170
+ }
171
+ var personas = {
172
+ fromEnv: PersonasClient.fromEnv
173
+ };
174
+ export {
175
+ Persona,
176
+ PersonaError,
177
+ PersonasClient,
178
+ personas
179
+ };
180
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/personas/index.ts"],"sourcesContent":["/**\n * Personas — simulated users served by the Gateway platform.\n *\n * A persona is a crafted user profile (usually derived from real sessions on\n * the platform) that Gateway serves as an endpoint. Use it to drive your agent\n * in tests: the persona plays the user, your agent plays itself.\n *\n * Example:\n * ```ts\n * import { PersonasClient } from \"@withgateway/sdk/personas\";\n *\n * const personas = PersonasClient.fromEnv();\n * const persona = await personas.get(\"persona_id\");\n *\n * const messages: PersonaMessage[] = [];\n * let reply = await persona.respond(messages); // persona opens the conversation\n * while (!reply.done) {\n * messages.push({ role: \"user\", content: reply.content });\n * const agentAnswer = await myAgent(messages); // your agent under test\n * messages.push({ role: \"assistant\", content: agentAnswer });\n * reply = await persona.respond(messages);\n * }\n * ```\n *\n * Message roles are from YOUR agent's perspective: `user` = the simulated\n * user's turns, `assistant` = your agent's turns.\n */\n\ntype PersonaMessage = {\n role: \"user\" | \"assistant\";\n content: string;\n};\n\n/** One simulated-user turn. */\ntype PersonaReply = {\n content: string;\n done: boolean;\n};\n\ntype PersonasClientConfig = {\n host: string;\n publicKey: string;\n secretKey: string;\n timeoutSeconds?: number;\n debug?: boolean;\n};\n\ntype PersonasClientFromEnvConfig = Partial<PersonasClientConfig>;\n\n/** Raised when the Gateway personas API cannot complete a request. */\nexport class PersonaError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = \"PersonaError\";\n this.cause = options?.cause;\n }\n}\n\n/** A persona definition plus a bound `respond` helper. */\nexport class Persona {\n readonly id: string;\n readonly name: string;\n readonly description: string | null;\n readonly version: number;\n readonly instructions: string;\n readonly examples: string[];\n private readonly client: PersonasClient | null;\n\n constructor(fields: {\n id: string;\n name: string;\n description: string | null;\n version: number;\n instructions: string;\n examples?: string[];\n client?: PersonasClient | null;\n }) {\n this.id = fields.id;\n this.name = fields.name;\n this.description = fields.description;\n this.version = fields.version;\n this.instructions = fields.instructions;\n this.examples = fields.examples ?? [];\n this.client = fields.client ?? null;\n }\n\n /**\n * Get the persona's next user message for a conversation.\n *\n * `messages` use your agent's perspective: role `user` for the simulated\n * user's prior turns, `assistant` for your agent's turns.\n * `done` is true when the persona considers its goal met.\n */\n respond(messages: PersonaMessage[]): Promise<PersonaReply> {\n if (this.client === null) {\n throw new PersonaError(\"Persona is not bound to a client.\");\n }\n return this.client.chat(this.id, messages);\n }\n}\n\n/** Client for Gateway's persona endpoints (HTTP Basic project keys). */\nexport class PersonasClient {\n private readonly host: string;\n private readonly publicKey: string;\n private readonly secretKey: string;\n private readonly timeoutSeconds: number;\n private readonly debug: boolean;\n\n constructor(config: PersonasClientConfig) {\n this.host = config.host.replace(/\\/$/, \"\");\n this.publicKey = config.publicKey;\n this.secretKey = config.secretKey;\n this.timeoutSeconds = config.timeoutSeconds ?? 120;\n this.debug = config.debug ?? false;\n }\n\n /** Create a client from GATEWAY_HOST / GATEWAY_PUBLIC_KEY / GATEWAY_SECRET_KEY. */\n static fromEnv(config: PersonasClientFromEnvConfig = {}) {\n const host = config.host ?? process.env.GATEWAY_HOST;\n const publicKey = config.publicKey ?? process.env.GATEWAY_PUBLIC_KEY;\n const secretKey = config.secretKey ?? process.env.GATEWAY_SECRET_KEY;\n\n const missing = [\n [\"host\", host],\n [\"publicKey\", publicKey],\n [\"secretKey\", secretKey],\n ]\n .filter(([, value]) => !value)\n .map(([name]) => name);\n\n if (missing.length > 0) {\n throw new PersonaError(\n `Missing Gateway persona configuration: ${missing.join(\", \")}`,\n );\n }\n\n return new PersonasClient({\n ...config,\n host: host!,\n publicKey: publicKey!,\n secretKey: secretKey!,\n });\n }\n\n /** List the project's personas (without full instructions). */\n async list(): Promise<Persona[]> {\n const payload = await this.requestJson(\"GET\", \"/api/public/personas\");\n const items = Array.isArray(payload.data) ? payload.data : [];\n return items\n .filter(isRecord)\n .map(\n (item) =>\n new Persona({\n id: String(item.id),\n name: String(item.name),\n description: (item.description as string | null | undefined) ?? null,\n version: typeof item.version === \"number\" ? item.version : 1,\n instructions: \"\",\n client: this,\n }),\n );\n }\n\n /** Fetch a persona (full definition) bound to this client. */\n async get(personaId: string): Promise<Persona> {\n const item = await this.requestJson(\n \"GET\",\n `/api/public/personas/${encodeURIComponent(personaId)}/chat`,\n );\n return new Persona({\n id: String(item.id),\n name: String(item.name),\n description: (item.description as string | null | undefined) ?? null,\n version: typeof item.version === \"number\" ? item.version : 1,\n instructions: typeof item.instructions === \"string\" ? item.instructions : \"\",\n examples: Array.isArray(item.examples)\n ? item.examples.map((example) => String(example))\n : [],\n client: this,\n });\n }\n\n /** Play one persona turn. See {@link Persona.respond}. */\n async chat(\n personaId: string,\n messages: PersonaMessage[],\n ): Promise<PersonaReply> {\n const payload = await this.requestJson(\n \"POST\",\n `/api/public/personas/${encodeURIComponent(personaId)}/chat`,\n { messages },\n );\n return {\n content: typeof payload.content === \"string\" ? payload.content : \"\",\n done: Boolean(payload.done),\n };\n }\n\n private async requestJson(\n method: \"GET\" | \"POST\",\n path: string,\n payload?: Record<string, unknown>,\n ): Promise<Record<string, unknown>> {\n let response: Response;\n try {\n response = await fetch(`${this.host}${path}`, {\n method,\n headers: {\n Authorization: this.authHeader(),\n \"Content-Type\": \"application/json\",\n },\n ...(payload ? { body: JSON.stringify(payload) } : {}),\n signal: AbortSignal.timeout(this.timeoutSeconds * 1000),\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw new PersonaError(`${method} ${path} failed: ${reason}`, {\n cause: error,\n });\n }\n\n const text = await response.text();\n if (!response.ok) {\n const detail = text.slice(0, 500);\n throw new PersonaError(\n `${method} ${path} failed (${response.status}): ${detail}`,\n );\n }\n\n this.log(\"%s %s -> %s\", method, path, response.status);\n return safeJson(text);\n }\n\n private authHeader() {\n return `Basic ${Buffer.from(`${this.publicKey}:${this.secretKey}`).toString(\n \"base64\",\n )}`;\n }\n\n private log(message: string, ...args: unknown[]) {\n if (this.debug) {\n console.log(`[gateway.personas] ${message}`, ...args);\n }\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction safeJson(value: string): Record<string, unknown> {\n try {\n const parsed = JSON.parse(value);\n return isRecord(parsed) ? parsed : {};\n } catch {\n return {};\n }\n}\n\nexport const personas = {\n fromEnv: PersonasClient.fromEnv,\n};\n\nexport type {\n PersonaMessage,\n PersonaReply,\n PersonasClientConfig,\n PersonasClientFromEnvConfig,\n};\n"],"mappings":";;;;AAkDO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YAAY,SAAiB,SAA+B;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,QAAQ,SAAS;AAAA,EACxB;AACF;AAGO,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EAEjB,YAAY,QAQT;AACD,SAAK,KAAK,OAAO;AACjB,SAAK,OAAO,OAAO;AACnB,SAAK,cAAc,OAAO;AAC1B,SAAK,UAAU,OAAO;AACtB,SAAK,eAAe,OAAO;AAC3B,SAAK,WAAW,OAAO,YAAY,CAAC;AACpC,SAAK,SAAS,OAAO,UAAU;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,QAAQ,UAAmD;AACzD,QAAI,KAAK,WAAW,MAAM;AACxB,YAAM,IAAI,aAAa,mCAAmC;AAAA,IAC5D;AACA,WAAO,KAAK,OAAO,KAAK,KAAK,IAAI,QAAQ;AAAA,EAC3C;AACF;AAGO,IAAM,iBAAN,MAAM,gBAAe;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,QAA8B;AACxC,SAAK,OAAO,OAAO,KAAK,QAAQ,OAAO,EAAE;AACzC,SAAK,YAAY,OAAO;AACxB,SAAK,YAAY,OAAO;AACxB,SAAK,iBAAiB,OAAO,kBAAkB;AAC/C,SAAK,QAAQ,OAAO,SAAS;AAAA,EAC/B;AAAA;AAAA,EAGA,OAAO,QA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