@polpo-ai/server 0.11.1 → 0.12.1

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 (51) hide show
  1. package/dist/deps.d.ts +4 -4
  2. package/dist/deps.d.ts.map +1 -1
  3. package/dist/routes/completions/agent-step-runner.d.ts +49 -0
  4. package/dist/routes/completions/agent-step-runner.d.ts.map +1 -0
  5. package/dist/routes/completions/agent-step-runner.js +166 -0
  6. package/dist/routes/completions/agent-step-runner.js.map +1 -0
  7. package/dist/routes/completions/chat-handler.d.ts +51 -0
  8. package/dist/routes/completions/chat-handler.d.ts.map +1 -0
  9. package/dist/routes/completions/chat-handler.js +710 -0
  10. package/dist/routes/completions/chat-handler.js.map +1 -0
  11. package/dist/routes/completions/message-mapping.d.ts +21 -0
  12. package/dist/routes/completions/message-mapping.d.ts.map +1 -0
  13. package/dist/routes/completions/message-mapping.js +156 -0
  14. package/dist/routes/completions/message-mapping.js.map +1 -0
  15. package/dist/routes/completions/project-loop-runner.d.ts +65 -0
  16. package/dist/routes/completions/project-loop-runner.d.ts.map +1 -0
  17. package/dist/routes/completions/project-loop-runner.js +482 -0
  18. package/dist/routes/completions/project-loop-runner.js.map +1 -0
  19. package/dist/routes/completions/schemas.d.ts +242 -0
  20. package/dist/routes/completions/schemas.d.ts.map +1 -0
  21. package/dist/routes/completions/schemas.js +148 -0
  22. package/dist/routes/completions/schemas.js.map +1 -0
  23. package/dist/routes/completions/sse.d.ts +57 -0
  24. package/dist/routes/completions/sse.d.ts.map +1 -0
  25. package/dist/routes/completions/sse.js +96 -0
  26. package/dist/routes/completions/sse.js.map +1 -0
  27. package/dist/routes/completions/tool-mapping.d.ts +44 -0
  28. package/dist/routes/completions/tool-mapping.d.ts.map +1 -0
  29. package/dist/routes/completions/tool-mapping.js +154 -0
  30. package/dist/routes/completions/tool-mapping.js.map +1 -0
  31. package/dist/routes/completions.d.ts +13 -20
  32. package/dist/routes/completions.d.ts.map +1 -1
  33. package/dist/routes/completions.js +49 -1882
  34. package/dist/routes/completions.js.map +1 -1
  35. package/dist/routes/missions.d.ts +2 -2
  36. package/dist/routes/missions.d.ts.map +1 -1
  37. package/dist/routes/missions.js +2 -2
  38. package/dist/routes/missions.js.map +1 -1
  39. package/dist/routes/playbooks.d.ts +1 -1
  40. package/dist/routes/playbooks.d.ts.map +1 -1
  41. package/dist/routes/playbooks.js +1 -1
  42. package/dist/routes/playbooks.js.map +1 -1
  43. package/dist/routes/tasks.d.ts +1 -1
  44. package/dist/routes/tasks.d.ts.map +1 -1
  45. package/dist/routes/tasks.js +3 -3
  46. package/dist/routes/tasks.js.map +1 -1
  47. package/dist/schemas.d.ts +0 -13
  48. package/dist/schemas.d.ts.map +1 -1
  49. package/dist/schemas.js +1 -11
  50. package/dist/schemas.js.map +1 -1
  51. package/package.json +3 -3
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Zod request/response schemas + OpenAPI route definition for the
3
+ * OpenAI-compatible chat completions endpoint.
4
+ */
5
+ import { z } from "@hono/zod-openapi";
6
+ /** OpenAI-compatible content part (text, image_url, or file reference). */
7
+ export declare const contentPartSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
8
+ type: z.ZodLiteral<"text">;
9
+ text: z.ZodString;
10
+ }, z.core.$strip>, z.ZodObject<{
11
+ type: z.ZodLiteral<"image_url">;
12
+ image_url: z.ZodObject<{
13
+ url: z.ZodString;
14
+ detail: z.ZodOptional<z.ZodEnum<{
15
+ low: "low";
16
+ high: "high";
17
+ auto: "auto";
18
+ }>>;
19
+ }, z.core.$strip>;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"file">;
22
+ file_id: z.ZodString;
23
+ }, z.core.$strip>], "type">;
24
+ export declare const messageSchema: z.ZodObject<{
25
+ role: z.ZodEnum<{
26
+ user: "user";
27
+ tool: "tool";
28
+ assistant: "assistant";
29
+ system: "system";
30
+ }>;
31
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
32
+ type: z.ZodLiteral<"text">;
33
+ text: z.ZodString;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ type: z.ZodLiteral<"image_url">;
36
+ image_url: z.ZodObject<{
37
+ url: z.ZodString;
38
+ detail: z.ZodOptional<z.ZodEnum<{
39
+ low: "low";
40
+ high: "high";
41
+ auto: "auto";
42
+ }>>;
43
+ }, z.core.$strip>;
44
+ }, z.core.$strip>, z.ZodObject<{
45
+ type: z.ZodLiteral<"file">;
46
+ file_id: z.ZodString;
47
+ }, z.core.$strip>], "type">>]>;
48
+ tool_call_id: z.ZodOptional<z.ZodString>;
49
+ name: z.ZodOptional<z.ZodString>;
50
+ }, z.core.$strip>;
51
+ export declare const completionRequestSchema: z.ZodObject<{
52
+ messages: z.ZodArray<z.ZodObject<{
53
+ role: z.ZodEnum<{
54
+ user: "user";
55
+ tool: "tool";
56
+ assistant: "assistant";
57
+ system: "system";
58
+ }>;
59
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
60
+ type: z.ZodLiteral<"text">;
61
+ text: z.ZodString;
62
+ }, z.core.$strip>, z.ZodObject<{
63
+ type: z.ZodLiteral<"image_url">;
64
+ image_url: z.ZodObject<{
65
+ url: z.ZodString;
66
+ detail: z.ZodOptional<z.ZodEnum<{
67
+ low: "low";
68
+ high: "high";
69
+ auto: "auto";
70
+ }>>;
71
+ }, z.core.$strip>;
72
+ }, z.core.$strip>, z.ZodObject<{
73
+ type: z.ZodLiteral<"file">;
74
+ file_id: z.ZodString;
75
+ }, z.core.$strip>], "type">>]>;
76
+ tool_call_id: z.ZodOptional<z.ZodString>;
77
+ name: z.ZodOptional<z.ZodString>;
78
+ }, z.core.$strip>>;
79
+ stream: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
80
+ model: z.ZodOptional<z.ZodString>;
81
+ temperature: z.ZodOptional<z.ZodNumber>;
82
+ max_tokens: z.ZodOptional<z.ZodNumber>;
83
+ agent: z.ZodOptional<z.ZodString>;
84
+ loop: z.ZodOptional<z.ZodString>;
85
+ project: z.ZodOptional<z.ZodString>;
86
+ user: z.ZodOptional<z.ZodString>;
87
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
88
+ }, z.core.$strip>;
89
+ /** Parsed request body shape (post-validation, defaults applied). */
90
+ export type CompletionRequestBody = z.infer<typeof completionRequestSchema>;
91
+ export declare const completionResponseSchema: z.ZodObject<{
92
+ id: z.ZodString;
93
+ object: z.ZodLiteral<"chat.completion">;
94
+ created: z.ZodNumber;
95
+ model: z.ZodLiteral<"polpo">;
96
+ choices: z.ZodArray<z.ZodObject<{
97
+ index: z.ZodNumber;
98
+ message: z.ZodObject<{
99
+ role: z.ZodLiteral<"assistant">;
100
+ content: z.ZodString;
101
+ }, z.core.$strip>;
102
+ finish_reason: z.ZodEnum<{
103
+ length: "length";
104
+ stop: "stop";
105
+ ask_user: "ask_user";
106
+ mission_preview: "mission_preview";
107
+ vault_preview: "vault_preview";
108
+ }>;
109
+ }, z.core.$strip>>;
110
+ usage: z.ZodObject<{
111
+ prompt_tokens: z.ZodNumber;
112
+ completion_tokens: z.ZodNumber;
113
+ total_tokens: z.ZodNumber;
114
+ }, z.core.$strip>;
115
+ loop_trace: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
116
+ }, z.core.$strip>;
117
+ export declare const errorResponseSchema: z.ZodObject<{
118
+ error: z.ZodObject<{
119
+ message: z.ZodString;
120
+ type: z.ZodString;
121
+ code: z.ZodOptional<z.ZodString>;
122
+ }, z.core.$strip>;
123
+ }, z.core.$strip>;
124
+ export declare const chatCompletionsRoute: {
125
+ method: "post";
126
+ path: "/";
127
+ tags: string[];
128
+ summary: string;
129
+ description: string;
130
+ request: {
131
+ body: {
132
+ content: {
133
+ "application/json": {
134
+ schema: z.ZodObject<{
135
+ messages: z.ZodArray<z.ZodObject<{
136
+ role: z.ZodEnum<{
137
+ user: "user";
138
+ tool: "tool";
139
+ assistant: "assistant";
140
+ system: "system";
141
+ }>;
142
+ content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
143
+ type: z.ZodLiteral<"text">;
144
+ text: z.ZodString;
145
+ }, z.core.$strip>, z.ZodObject<{
146
+ type: z.ZodLiteral<"image_url">;
147
+ image_url: z.ZodObject<{
148
+ url: z.ZodString;
149
+ detail: z.ZodOptional<z.ZodEnum<{
150
+ low: "low";
151
+ high: "high";
152
+ auto: "auto";
153
+ }>>;
154
+ }, z.core.$strip>;
155
+ }, z.core.$strip>, z.ZodObject<{
156
+ type: z.ZodLiteral<"file">;
157
+ file_id: z.ZodString;
158
+ }, z.core.$strip>], "type">>]>;
159
+ tool_call_id: z.ZodOptional<z.ZodString>;
160
+ name: z.ZodOptional<z.ZodString>;
161
+ }, z.core.$strip>>;
162
+ stream: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
163
+ model: z.ZodOptional<z.ZodString>;
164
+ temperature: z.ZodOptional<z.ZodNumber>;
165
+ max_tokens: z.ZodOptional<z.ZodNumber>;
166
+ agent: z.ZodOptional<z.ZodString>;
167
+ loop: z.ZodOptional<z.ZodString>;
168
+ project: z.ZodOptional<z.ZodString>;
169
+ user: z.ZodOptional<z.ZodString>;
170
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
171
+ }, z.core.$strip>;
172
+ };
173
+ };
174
+ };
175
+ };
176
+ responses: {
177
+ 200: {
178
+ content: {
179
+ "application/json": {
180
+ schema: z.ZodObject<{
181
+ id: z.ZodString;
182
+ object: z.ZodLiteral<"chat.completion">;
183
+ created: z.ZodNumber;
184
+ model: z.ZodLiteral<"polpo">;
185
+ choices: z.ZodArray<z.ZodObject<{
186
+ index: z.ZodNumber;
187
+ message: z.ZodObject<{
188
+ role: z.ZodLiteral<"assistant">;
189
+ content: z.ZodString;
190
+ }, z.core.$strip>;
191
+ finish_reason: z.ZodEnum<{
192
+ length: "length";
193
+ stop: "stop";
194
+ ask_user: "ask_user";
195
+ mission_preview: "mission_preview";
196
+ vault_preview: "vault_preview";
197
+ }>;
198
+ }, z.core.$strip>>;
199
+ usage: z.ZodObject<{
200
+ prompt_tokens: z.ZodNumber;
201
+ completion_tokens: z.ZodNumber;
202
+ total_tokens: z.ZodNumber;
203
+ }, z.core.$strip>;
204
+ loop_trace: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
205
+ }, z.core.$strip>;
206
+ };
207
+ };
208
+ description: string;
209
+ };
210
+ 400: {
211
+ content: {
212
+ "application/json": {
213
+ schema: z.ZodObject<{
214
+ error: z.ZodObject<{
215
+ message: z.ZodString;
216
+ type: z.ZodString;
217
+ code: z.ZodOptional<z.ZodString>;
218
+ }, z.core.$strip>;
219
+ }, z.core.$strip>;
220
+ };
221
+ };
222
+ description: string;
223
+ };
224
+ 401: {
225
+ content: {
226
+ "application/json": {
227
+ schema: z.ZodObject<{
228
+ error: z.ZodObject<{
229
+ message: z.ZodString;
230
+ type: z.ZodString;
231
+ code: z.ZodOptional<z.ZodString>;
232
+ }, z.core.$strip>;
233
+ }, z.core.$strip>;
234
+ };
235
+ };
236
+ description: string;
237
+ };
238
+ };
239
+ } & {
240
+ getRoutingPath(): "/";
241
+ };
242
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/routes/completions/schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAInD,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;2BAa5B,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;iBAcxB,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0ClC,CAAC;AAEH,qEAAqE;AACrE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;iBAmBnC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;iBAM9B,CAAC;AAIH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyC/B,CAAC"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Zod request/response schemas + OpenAPI route definition for the
3
+ * OpenAI-compatible chat completions endpoint.
4
+ */
5
+ import { createRoute, z } from "@hono/zod-openapi";
6
+ // ── Zod Schemas ────────────────────────────────────────────────────────
7
+ /** OpenAI-compatible content part (text, image_url, or file reference). */
8
+ export const contentPartSchema = z.discriminatedUnion("type", [
9
+ z.object({ type: z.literal("text"), text: z.string() }),
10
+ z.object({
11
+ type: z.literal("image_url"),
12
+ image_url: z.object({
13
+ url: z.string().openapi({ description: "Data URL (data:image/…;base64,…) or HTTPS URL" }),
14
+ detail: z.enum(["auto", "low", "high"]).optional(),
15
+ }),
16
+ }),
17
+ z.object({
18
+ type: z.literal("file"),
19
+ file_id: z.string().openapi({ description: "Attachment ID from a previous upload" }),
20
+ }),
21
+ ]);
22
+ export const messageSchema = z.object({
23
+ role: z.enum(["system", "user", "assistant", "tool"]).openapi({
24
+ description: "Message role. System messages are appended as additional context. Tool messages carry results of client-side tool calls.",
25
+ }),
26
+ content: z.union([
27
+ z.string(),
28
+ z.array(contentPartSchema),
29
+ ]).openapi({ description: "Message content — plain string or array of content parts (text / image_url)" }),
30
+ tool_call_id: z.string().optional().openapi({
31
+ description: "ID of the tool call this message responds to (required for role=tool)",
32
+ }),
33
+ name: z.string().optional().openapi({
34
+ description: "Tool name (for role=tool messages)",
35
+ }),
36
+ });
37
+ export const completionRequestSchema = z.object({
38
+ messages: z.array(messageSchema).min(1).openapi({
39
+ description: "Conversation messages in OpenAI format",
40
+ }),
41
+ stream: z.boolean().optional().default(false).openapi({
42
+ description: "If true, returns an SSE stream of OpenAI-format chunks. If false, returns a complete response.",
43
+ }),
44
+ model: z.string().optional().openapi({
45
+ description: "Ignored. Polpo uses its configured orchestrator model (or the agent's model in agent-direct mode).",
46
+ }),
47
+ temperature: z.number().optional().openapi({
48
+ description: "Ignored. Reserved for future use.",
49
+ }),
50
+ max_tokens: z.number().int().optional().openapi({
51
+ description: "Ignored. Reserved for future use.",
52
+ }),
53
+ agent: z.string().optional().openapi({
54
+ description: "Target a specific agent by name for direct conversation. Uses the agent's own model, system prompt, and coding tools instead of the orchestrator. Omit to talk to the orchestrator (default).",
55
+ }),
56
+ loop: z.string().optional().openapi({
57
+ description: "Optional configurable loop name for agent-direct mode. Applies that loop's prompt, tools, model, reasoning, and maxTurns overrides.",
58
+ }),
59
+ project: z.string().optional().openapi({
60
+ description: "Deprecated. Ignored.",
61
+ }),
62
+ // OpenAI-compat identity fields. Persisted on the Session row and exposed
63
+ // via GET /v1/chat/sessions filters. Polpo does NOT verify `user`; the
64
+ // caller's API key is the trust anchor — `user` is purely opaque scoping.
65
+ user: z.string().optional().openapi({
66
+ description: "Opaque end-user identifier (OpenAI-compat). Persisted on the session and used for filtering, per-user analytics, and pass-through to billing integrations (e.g. Autumn customer_id). Polpo does not verify this — set it from your authenticated end-user id.",
67
+ }),
68
+ metadata: z
69
+ .record(z.string(), z.string())
70
+ .refine((m) => Object.keys(m).length <= 16, { message: "metadata: max 16 keys" })
71
+ .refine((m) => Object.keys(m).every((k) => k.length <= 64), { message: "metadata: key max 64 chars" })
72
+ .refine((m) => Object.values(m).every((v) => v.length <= 512), { message: "metadata: value max 512 chars" })
73
+ .optional()
74
+ .openapi({
75
+ description: "Arbitrary key/value tags (OpenAI-compat). Up to 16 keys, key ≤64 chars, value ≤512 chars. Persisted on the session for filtering and analytics. Use for tenant_id, plan, identity_provider, ab_variant, etc.",
76
+ }),
77
+ });
78
+ export const completionResponseSchema = z.object({
79
+ id: z.string().openapi({ description: "Unique completion ID (chatcmpl-...)" }),
80
+ object: z.literal("chat.completion"),
81
+ created: z.number().int().openapi({ description: "Unix timestamp" }),
82
+ model: z.literal("polpo"),
83
+ choices: z.array(z.object({
84
+ index: z.number().int(),
85
+ message: z.object({
86
+ role: z.literal("assistant"),
87
+ content: z.string(),
88
+ }),
89
+ finish_reason: z.enum(["stop", "length", "ask_user", "mission_preview", "vault_preview"]),
90
+ })),
91
+ usage: z.object({
92
+ prompt_tokens: z.number().int(),
93
+ completion_tokens: z.number().int(),
94
+ total_tokens: z.number().int(),
95
+ }),
96
+ loop_trace: z.array(z.unknown()).optional(),
97
+ });
98
+ export const errorResponseSchema = z.object({
99
+ error: z.object({
100
+ message: z.string(),
101
+ type: z.string(),
102
+ code: z.string().optional(),
103
+ }),
104
+ });
105
+ // ── Route definition ───────────────────────────────────────────────────
106
+ export const chatCompletionsRoute = createRoute({
107
+ method: "post",
108
+ path: "/",
109
+ tags: ["Chat Completions"],
110
+ summary: "Chat completions",
111
+ description: "Polpo's primary conversational interface. Send messages in OpenAI format, receive responses in OpenAI format. Polpo runs its full 37-tool agentic loop internally — you describe what you need, Polpo handles the rest. Supports streaming (SSE) and non-streaming modes.",
112
+ request: {
113
+ body: {
114
+ content: {
115
+ "application/json": {
116
+ schema: completionRequestSchema,
117
+ },
118
+ },
119
+ },
120
+ },
121
+ responses: {
122
+ 200: {
123
+ content: {
124
+ "application/json": {
125
+ schema: completionResponseSchema,
126
+ },
127
+ },
128
+ description: "Chat completion response (non-streaming). When stream=true, returns text/event-stream with OpenAI-format chunks ending with data: [DONE].",
129
+ },
130
+ 400: {
131
+ content: {
132
+ "application/json": {
133
+ schema: errorResponseSchema,
134
+ },
135
+ },
136
+ description: "Invalid request (missing messages or no project available)",
137
+ },
138
+ 401: {
139
+ content: {
140
+ "application/json": {
141
+ schema: errorResponseSchema,
142
+ },
143
+ },
144
+ description: "Invalid API key",
145
+ },
146
+ },
147
+ });
148
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/routes/completions/schemas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEnD,0EAA0E;AAE1E,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC5D,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACvD,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QAC5B,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,+CAA+C,EAAE,CAAC;YACzF,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE;SACnD,CAAC;KACH,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACvB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,sCAAsC,EAAE,CAAC;KACrF,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EA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MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAC5B,CAAC;CACH,CAAC,CAAC;AAEH,0EAA0E;AAE1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC;IAC9C,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,CAAC,kBAAkB,CAAC;IAC1B,OAAO,EAAE,kBAAkB;IAC3B,WAAW,EAAE,2QAA2Q;IACxR,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,OAAO,EAAE;gBACP,kBAAkB,EAAE;oBAClB,MAAM,EAAE,uBAAuB;iBAChC;aACF;SACF;KACF;IACD,SAAS,EAAE;QACT,GAAG,EAAE;YACH,OAAO,EAAE;gBACP,kBAAkB,EAAE;oBAClB,MAAM,EAAE,wBAAwB;iBACjC;aACF;YACD,WAAW,EAAE,2IAA2I;SACzJ;QACD,GAAG,EAAE;YACH,OAAO,EAAE;gBACP,kBAAkB,EAAE;oBAClB,MAAM,EAAE,mBAAmB;iBAC5B;aACF;YACD,WAAW,EAAE,4DAA4D;SAC1E;QACD,GAAG,EAAE;YACH,OAAO,EAAE;gBACP,kBAAkB,EAAE;oBAClB,MAAM,EAAE,mBAAmB;iBAC5B;aACF;YACD,WAAW,EAAE,iBAAiB;SAC/B;KACF;CACF,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * SSE chunk formatting, error envelopes, and the non-streaming response
3
+ * shape for the chat completions endpoint.
4
+ */
5
+ import type { LanguageModelUsage } from "ai";
6
+ export declare function sseChunk(id: string, delta: {
7
+ content?: string;
8
+ role?: string;
9
+ }, finishReason?: string | null, extra?: Record<string, unknown>): string;
10
+ /**
11
+ * Detect Vercel AI Gateway "model not found" errors so callers see a
12
+ * clean 400 (with the offending model id + agent name) instead of a
13
+ * generic 500 surfaced by Hono's default error handler.
14
+ *
15
+ * Triggers on:
16
+ * - `GatewayModelNotFoundError` constructor name from `@ai-sdk/gateway`
17
+ * - any 404 response whose body mentions `model_not_found` (covers
18
+ * custom gateways that don't ship the typed error class)
19
+ *
20
+ * Returns the error envelope to send back, or null if the error isn't a
21
+ * model-not-found and should propagate untouched.
22
+ */
23
+ export declare function modelNotFoundEnvelope(err: unknown, fallbackModelId: string | undefined, agent: string | undefined): {
24
+ message: string;
25
+ type: "model_not_found";
26
+ param: {
27
+ modelId: string;
28
+ agent?: string;
29
+ };
30
+ } | null;
31
+ export declare function loopRuntimeErrorEnvelope(err: unknown): {
32
+ message: string;
33
+ type: "loop_runtime_error";
34
+ code: "loop_policy_blocked" | "loop_permission_blocked" | "loop_approval_required" | "loop_hook_failed";
35
+ approvalRequestId?: string;
36
+ loopRunId?: string;
37
+ } | null;
38
+ export declare function completionResponse(id: string, content: string, usage: LanguageModelUsage, extra?: Record<string, unknown>): {
39
+ id: string;
40
+ object: "chat.completion";
41
+ created: number;
42
+ model: "polpo";
43
+ choices: {
44
+ index: number;
45
+ message: {
46
+ role: "assistant";
47
+ content: string;
48
+ };
49
+ finish_reason: "stop";
50
+ }[];
51
+ usage: {
52
+ prompt_tokens: number;
53
+ completion_tokens: number;
54
+ total_tokens: number;
55
+ };
56
+ };
57
+ //# sourceMappingURL=sse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/routes/completions/sse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAE7C,wBAAgB,QAAQ,CACtB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAC1C,YAAY,GAAE,MAAM,GAAG,IAAW,EAClC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAaR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,OAAO,EACZ,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,IAAI,CAkBjG;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,OAAO,GACX;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,qBAAqB,GAAG,yBAAyB,GAAG,wBAAwB,GAAG,kBAAkB,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAwBjN;AAED,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;;;;;;;;;EAkBzH"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * SSE chunk formatting, error envelopes, and the non-streaming response
3
+ * shape for the chat completions endpoint.
4
+ */
5
+ import { LoopApprovalRequiredError, LoopPermissionApprovalRequiredError, LoopPermissionDeniedError, LoopPolicyDeniedError, } from "@polpo-ai/core";
6
+ export function sseChunk(id, delta, finishReason = null, extra) {
7
+ return JSON.stringify({
8
+ id,
9
+ object: "chat.completion.chunk",
10
+ created: Math.floor(Date.now() / 1000),
11
+ model: "polpo",
12
+ choices: [{
13
+ index: 0,
14
+ delta,
15
+ finish_reason: finishReason,
16
+ ...extra,
17
+ }],
18
+ });
19
+ }
20
+ /**
21
+ * Detect Vercel AI Gateway "model not found" errors so callers see a
22
+ * clean 400 (with the offending model id + agent name) instead of a
23
+ * generic 500 surfaced by Hono's default error handler.
24
+ *
25
+ * Triggers on:
26
+ * - `GatewayModelNotFoundError` constructor name from `@ai-sdk/gateway`
27
+ * - any 404 response whose body mentions `model_not_found` (covers
28
+ * custom gateways that don't ship the typed error class)
29
+ *
30
+ * Returns the error envelope to send back, or null if the error isn't a
31
+ * model-not-found and should propagate untouched.
32
+ */
33
+ export function modelNotFoundEnvelope(err, fallbackModelId, agent) {
34
+ if (!err || typeof err !== "object")
35
+ return null;
36
+ const e = err;
37
+ const isGatewayNotFound = e.name === "GatewayModelNotFoundError" ||
38
+ e.constructor?.name === "GatewayModelNotFoundError" ||
39
+ (e.statusCode === 404 &&
40
+ typeof e.responseBody === "string" &&
41
+ e.responseBody.includes("model_not_found"));
42
+ if (!isGatewayNotFound)
43
+ return null;
44
+ const modelId = e.modelId ?? fallbackModelId ?? "unknown";
45
+ return {
46
+ message: `Model "${modelId}" is not available on the gateway. ` +
47
+ `It may have been renamed or deprecated — update the agent config (or the orchestrator default).`,
48
+ type: "model_not_found",
49
+ param: { modelId, ...(agent ? { agent } : {}) },
50
+ };
51
+ }
52
+ export function loopRuntimeErrorEnvelope(err) {
53
+ const message = err instanceof Error ? err.message : String(err);
54
+ if (err instanceof LoopApprovalRequiredError || err instanceof LoopPermissionApprovalRequiredError) {
55
+ return {
56
+ message,
57
+ type: "loop_runtime_error",
58
+ code: "loop_approval_required",
59
+ approvalRequestId: err.approvalRequestId,
60
+ loopRunId: err.loopRunId,
61
+ };
62
+ }
63
+ if (err instanceof LoopPermissionDeniedError) {
64
+ return { message, type: "loop_runtime_error", code: "loop_permission_blocked", loopRunId: err.loopRunId };
65
+ }
66
+ if (err instanceof LoopPolicyDeniedError) {
67
+ return { message, type: "loop_runtime_error", code: "loop_policy_blocked", loopRunId: err.loopRunId };
68
+ }
69
+ if (message.startsWith("Loop policy ")) {
70
+ return { message, type: "loop_runtime_error", code: "loop_policy_blocked" };
71
+ }
72
+ if (message.startsWith("Loop hook ")) {
73
+ return { message, type: "loop_runtime_error", code: "loop_hook_failed" };
74
+ }
75
+ return null;
76
+ }
77
+ export function completionResponse(id, content, usage, extra) {
78
+ return {
79
+ id,
80
+ object: "chat.completion",
81
+ created: Math.floor(Date.now() / 1000),
82
+ model: "polpo",
83
+ choices: [{
84
+ index: 0,
85
+ message: { role: "assistant", content },
86
+ finish_reason: "stop",
87
+ }],
88
+ usage: {
89
+ prompt_tokens: usage.inputTokens ?? 0,
90
+ completion_tokens: usage.outputTokens ?? 0,
91
+ total_tokens: usage.totalTokens ?? 0,
92
+ },
93
+ ...extra,
94
+ };
95
+ }
96
+ //# sourceMappingURL=sse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/routes/completions/sse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,UAAU,QAAQ,CACtB,EAAU,EACV,KAA0C,EAC1C,eAA8B,IAAI,EAClC,KAA+B;IAE/B,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,EAAE;QACF,MAAM,EAAE,uBAAuB;QAC/B,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QACtC,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,CAAC;gBACR,KAAK,EAAE,CAAC;gBACR,KAAK;gBACL,aAAa,EAAE,YAAY;gBAC3B,GAAG,KAAK;aACT,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UA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,CAAC;SACrC;QACD,GAAG,KAAK;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Polpo tool → AI SDK tool mapping for the chat completions endpoint,
3
+ * plus tool-call side effects shared by the chat loop and the loop
4
+ * runtimes: file:changed events, vault credential redaction, and
5
+ * provider-executed tool-call bookkeeping.
6
+ */
7
+ /** A tool call event surfaced by the loop runtimes (SSE + persistence). */
8
+ export type LoopRuntimeToolCall = {
9
+ id: string;
10
+ name: string;
11
+ arguments?: Record<string, unknown>;
12
+ result?: string;
13
+ state: "preparing" | "calling" | "completed" | "error" | "interrupted";
14
+ };
15
+ /** Emit file:changed if a file-writing tool succeeded */
16
+ export declare function emitFileChanged(toolName: string, args: Record<string, unknown>, result: string, emit: (event: string, data: any) => void): void;
17
+ /**
18
+ * Redact sensitive credential values from vault tool call arguments before persistence.
19
+ * Returns a sanitized copy — original is NOT mutated.
20
+ */
21
+ export declare function redactVaultToolCalls(toolCalls: any[]): any[];
22
+ export declare function indexToolResultsByCallId(toolResults: any[] | undefined): Map<string, any>;
23
+ export declare function providerToolCallEvent(call: any, toolResults: Map<string, any>): LoopRuntimeToolCall & {
24
+ providerExecuted: true;
25
+ };
26
+ export declare function recordProviderToolCall(toolCallsAccum: any[], call: any, toolResults: Map<string, any>): void;
27
+ /**
28
+ * Convert Polpo tools to AI SDK tool format (without execute functions).
29
+ *
30
+ * AI SDK tools: Record<string, { description, inputSchema }>
31
+ * Tools without execute are "manual" — tool calls are returned but not auto-executed.
32
+ */
33
+ export declare function toAITools(tools: any[]): Record<string, {
34
+ description?: string;
35
+ inputSchema: any;
36
+ }>;
37
+ export declare function toAIToolChoice(choice: unknown): unknown | undefined;
38
+ export declare const CLIENT_SIDE_TOOLS: Record<string, {
39
+ description: string;
40
+ inputSchema: any;
41
+ }>;
42
+ /** Set of tool names that are client-side (no server execute). */
43
+ export declare const CLIENT_SIDE_TOOL_NAMES: Set<string>;
44
+ //# sourceMappingURL=tool-mapping.d.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