@skydiveai/pi-server 0.1.0-beta.6 → 0.1.0-beta.635

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/dist/index.d.mts CHANGED
@@ -244,17 +244,17 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
244
244
  high: z.ZodOptional<z.ZodNullable<z.ZodString>>;
245
245
  xhigh: z.ZodOptional<z.ZodNullable<z.ZodString>>;
246
246
  }, "strip", z.ZodTypeAny, {
247
- medium?: string | null | undefined;
248
247
  off?: string | null | undefined;
249
248
  minimal?: string | null | undefined;
250
249
  low?: string | null | undefined;
250
+ medium?: string | null | undefined;
251
251
  high?: string | null | undefined;
252
252
  xhigh?: string | null | undefined;
253
253
  }, {
254
- medium?: string | null | undefined;
255
254
  off?: string | null | undefined;
256
255
  minimal?: string | null | undefined;
257
256
  low?: string | null | undefined;
257
+ medium?: string | null | undefined;
258
258
  high?: string | null | undefined;
259
259
  xhigh?: string | null | undefined;
260
260
  }>>;
@@ -272,7 +272,7 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
272
272
  api: "openai-completions";
273
273
  id: string;
274
274
  name: string;
275
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
275
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
276
276
  baseUrl: string;
277
277
  reasoning: boolean;
278
278
  input: ["text" | "image", ...("text" | "image")[]];
@@ -287,10 +287,10 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
287
287
  cacheControlFormat?: "anthropic" | undefined;
288
288
  } | undefined;
289
289
  thinkingLevelMap?: {
290
- medium?: string | null | undefined;
291
290
  off?: string | null | undefined;
292
291
  minimal?: string | null | undefined;
293
292
  low?: string | null | undefined;
293
+ medium?: string | null | undefined;
294
294
  high?: string | null | undefined;
295
295
  xhigh?: string | null | undefined;
296
296
  } | undefined;
@@ -299,7 +299,7 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
299
299
  api: "openai-completions";
300
300
  id: string;
301
301
  name: string;
302
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
302
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
303
303
  baseUrl: string;
304
304
  reasoning: boolean;
305
305
  input: ["text" | "image", ...("text" | "image")[]];
@@ -314,10 +314,10 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
314
314
  cacheControlFormat?: "anthropic" | undefined;
315
315
  } | undefined;
316
316
  thinkingLevelMap?: {
317
- medium?: string | null | undefined;
318
317
  off?: string | null | undefined;
319
318
  minimal?: string | null | undefined;
320
319
  low?: string | null | undefined;
320
+ medium?: string | null | undefined;
321
321
  high?: string | null | undefined;
322
322
  xhigh?: string | null | undefined;
323
323
  } | undefined;
@@ -347,17 +347,17 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
347
347
  high: z.ZodOptional<z.ZodNullable<z.ZodString>>;
348
348
  xhigh: z.ZodOptional<z.ZodNullable<z.ZodString>>;
349
349
  }, "strip", z.ZodTypeAny, {
350
- medium?: string | null | undefined;
351
350
  off?: string | null | undefined;
352
351
  minimal?: string | null | undefined;
353
352
  low?: string | null | undefined;
353
+ medium?: string | null | undefined;
354
354
  high?: string | null | undefined;
355
355
  xhigh?: string | null | undefined;
356
356
  }, {
357
- medium?: string | null | undefined;
358
357
  off?: string | null | undefined;
359
358
  minimal?: string | null | undefined;
360
359
  low?: string | null | undefined;
360
+ medium?: string | null | undefined;
361
361
  high?: string | null | undefined;
362
362
  xhigh?: string | null | undefined;
363
363
  }>>;
@@ -375,7 +375,7 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
375
375
  api: "anthropic-messages";
376
376
  id: string;
377
377
  name: string;
378
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
378
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
379
379
  baseUrl: string;
380
380
  reasoning: boolean;
381
381
  input: ["text" | "image", ...("text" | "image")[]];
@@ -386,10 +386,10 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
386
386
  supportsLongCacheRetention?: boolean | undefined;
387
387
  } | undefined;
388
388
  thinkingLevelMap?: {
389
- medium?: string | null | undefined;
390
389
  off?: string | null | undefined;
391
390
  minimal?: string | null | undefined;
392
391
  low?: string | null | undefined;
392
+ medium?: string | null | undefined;
393
393
  high?: string | null | undefined;
394
394
  xhigh?: string | null | undefined;
395
395
  } | undefined;
@@ -398,7 +398,7 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
398
398
  api: "anthropic-messages";
399
399
  id: string;
400
400
  name: string;
401
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
401
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
402
402
  baseUrl: string;
403
403
  reasoning: boolean;
404
404
  input: ["text" | "image", ...("text" | "image")[]];
@@ -409,10 +409,10 @@ declare const modelSpecSchema: z.ZodDiscriminatedUnion<"api", [z.ZodObject<{
409
409
  supportsLongCacheRetention?: boolean | undefined;
410
410
  } | undefined;
411
411
  thinkingLevelMap?: {
412
- medium?: string | null | undefined;
413
412
  off?: string | null | undefined;
414
413
  minimal?: string | null | undefined;
415
414
  low?: string | null | undefined;
415
+ medium?: string | null | undefined;
416
416
  high?: string | null | undefined;
417
417
  xhigh?: string | null | undefined;
418
418
  } | undefined;
@@ -445,16 +445,16 @@ declare function buildModelFromSpec(spec: ModelSpec): {
445
445
  contextWindow: number;
446
446
  maxTokens: number;
447
447
  thinkingLevelMap?: {
448
- medium?: string | null | undefined;
449
448
  off?: string | null | undefined;
450
449
  minimal?: string | null | undefined;
451
450
  low?: string | null | undefined;
451
+ medium?: string | null | undefined;
452
452
  high?: string | null | undefined;
453
453
  xhigh?: string | null | undefined;
454
454
  } | undefined;
455
455
  id: string;
456
456
  name: string;
457
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
457
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
458
458
  baseUrl: string;
459
459
  reasoning: boolean;
460
460
  } | {
@@ -473,16 +473,16 @@ declare function buildModelFromSpec(spec: ModelSpec): {
473
473
  contextWindow: number;
474
474
  maxTokens: number;
475
475
  thinkingLevelMap?: {
476
- medium?: string | null | undefined;
477
476
  off?: string | null | undefined;
478
477
  minimal?: string | null | undefined;
479
478
  low?: string | null | undefined;
479
+ medium?: string | null | undefined;
480
480
  high?: string | null | undefined;
481
481
  xhigh?: string | null | undefined;
482
482
  } | undefined;
483
483
  id: string;
484
484
  name: string;
485
- provider: "anthropic" | "amazon-bedrock" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
485
+ provider: "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "deepseek" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "moonshotai" | "moonshotai-cn" | "huggingface" | "fireworks" | "opencode" | "opencode-go" | "kimi-coding" | "cloudflare-workers-ai" | "cloudflare-ai-gateway" | "xiaomi" | "xiaomi-token-plan-cn" | "xiaomi-token-plan-ams" | "xiaomi-token-plan-sgp";
486
486
  baseUrl: string;
487
487
  reasoning: boolean;
488
488
  };
@@ -542,4 +542,27 @@ declare function getCurrentTraceparent(): string | null;
542
542
  /** Extract the trace id (second segment) from a `traceparent` value. */
543
543
  declare function parseTraceId(traceparent: string | null): string | null;
544
544
  //#endregion
545
- export { type A2AOptions, type AnthropicMessagesOptions, type ChatCompletionsOptions, type CreateSessionArgs, DEFAULT_MODEL, DEFAULT_PROVIDER, DEFAULT_THINKING_LEVEL, KNOWN_PI_PROVIDERS, type Middleware, type ModelSpec, PI_AGENT_DIR, type PostPromptCallback, type ProtocolHandler, type ProtocolsOptions, type ResponsesOptions, type SessionFactory, type SessionSetupCallback, type TraceContext, VALID_THINKING_LEVELS, type WebHandler, buildAgentCard, buildModelFromSpec, chainMiddleware, composeHandlers, createAgentExecutor, createMapSessionRegistry, createPrewarm, createProtocolHandlers, createProtocols, deriveTraceContext, getCurrentTraceparent, logger, modelSpecSchema, mountAt, newTraceContext, parseModelSpec, parseTraceId, requestHeaders, requestLogger, requestUrl, resolveRequestModel, runInTraceContext, setCurrentTraceparent, webHandlerToMiddleware, withSpecApiKey };
545
+ //#region src/billing-blocked-provider-signal.d.ts
546
+ /**
547
+ * Duplicated from the billing gate's `BlockReason` (apps/anyone/billing
548
+ * gate/block-reason.ts): pi-server runs inside the sandbox and must not
549
+ * depend on platform packages. A reason the proxy sends that predates this
550
+ * build fails the enum and degrades to the untyped `billing_blocked`
551
+ * handling — never a crash. Exported so agent-lifecycle's chat.test.ts can
552
+ * pin this copy against its own (which billing's block-reason.test.ts in
553
+ * turn pins against the gate), keeping every copy drift-checked.
554
+ */
555
+ declare const BILLING_BLOCK_REASONS: readonly ["insufficient_balance", "payment_failed", "hard_spend_limit_reached"];
556
+ declare const payloadSchema: z.ZodObject<{
557
+ blockReason: z.ZodEnum<["insufficient_balance", "payment_failed", "hard_spend_limit_reached"]>;
558
+ message: z.ZodString;
559
+ }, "strict", z.ZodTypeAny, {
560
+ blockReason: "insufficient_balance" | "payment_failed" | "hard_spend_limit_reached";
561
+ message: string;
562
+ }, {
563
+ blockReason: "insufficient_balance" | "payment_failed" | "hard_spend_limit_reached";
564
+ message: string;
565
+ }>;
566
+ type BillingBlockedProviderSignal = z.infer<typeof payloadSchema>;
567
+ //#endregion
568
+ export { type A2AOptions, type AnthropicMessagesOptions, BILLING_BLOCK_REASONS, type BillingBlockedProviderSignal, type ChatCompletionsOptions, type CreateSessionArgs, DEFAULT_MODEL, DEFAULT_PROVIDER, DEFAULT_THINKING_LEVEL, KNOWN_PI_PROVIDERS, type Middleware, type ModelSpec, PI_AGENT_DIR, type PostPromptCallback, type ProtocolHandler, type ProtocolsOptions, type ResponsesOptions, type SessionFactory, type SessionSetupCallback, type TraceContext, VALID_THINKING_LEVELS, type WebHandler, buildAgentCard, buildModelFromSpec, chainMiddleware, composeHandlers, createAgentExecutor, createMapSessionRegistry, createPrewarm, createProtocolHandlers, createProtocols, deriveTraceContext, getCurrentTraceparent, logger, modelSpecSchema, mountAt, newTraceContext, parseModelSpec, parseTraceId, requestHeaders, requestLogger, requestUrl, resolveRequestModel, runInTraceContext, setCurrentTraceparent, webHandlerToMiddleware, withSpecApiKey };
package/dist/index.mjs CHANGED
@@ -1379,6 +1379,65 @@ function create$2(options) {
1379
1379
  };
1380
1380
  }
1381
1381
  //#endregion
1382
+ //#region src/billing-blocked-provider-signal.ts
1383
+ const BILLING_BLOCKED_PROVIDER_SIGNAL_PREFIX = "ANYONE_BILLING_BLOCKED_V1:";
1384
+ /**
1385
+ * Duplicated from the billing gate's `BlockReason` (apps/anyone/billing
1386
+ * gate/block-reason.ts): pi-server runs inside the sandbox and must not
1387
+ * depend on platform packages. A reason the proxy sends that predates this
1388
+ * build fails the enum and degrades to the untyped `billing_blocked`
1389
+ * handling — never a crash. Exported so agent-lifecycle's chat.test.ts can
1390
+ * pin this copy against its own (which billing's block-reason.test.ts in
1391
+ * turn pins against the gate), keeping every copy drift-checked.
1392
+ */
1393
+ const BILLING_BLOCK_REASONS = [
1394
+ "insufficient_balance",
1395
+ "payment_failed",
1396
+ "hard_spend_limit_reached"
1397
+ ];
1398
+ const payloadSchema = z.object({
1399
+ blockReason: z.enum(BILLING_BLOCK_REASONS),
1400
+ message: z.string()
1401
+ }).strict();
1402
+ const nestedProxyEnvelopeSchema = z.object({
1403
+ error: z.object({
1404
+ type: z.literal("billing_blocked"),
1405
+ code: z.literal("billing_blocked"),
1406
+ message: z.string()
1407
+ }).strict(),
1408
+ blockReason: z.enum(BILLING_BLOCK_REASONS),
1409
+ message: z.string()
1410
+ }).strict();
1411
+ function parsePrefixedSignal(message) {
1412
+ const normalized = message.startsWith("402 ") ? message.slice(4) : message;
1413
+ if (!normalized.startsWith(BILLING_BLOCKED_PROVIDER_SIGNAL_PREFIX)) return null;
1414
+ try {
1415
+ const parsed = payloadSchema.safeParse(JSON.parse(normalized.slice(26)));
1416
+ return parsed.success ? parsed.data : null;
1417
+ } catch {
1418
+ return null;
1419
+ }
1420
+ }
1421
+ /**
1422
+ * Decode only the versioned platform envelope. Anthropic and OpenAI prefix the
1423
+ * nested error message with HTTP 402. Google's SDK instead preserves the full
1424
+ * proxy response as JSON, so that outer shape is validated separately.
1425
+ */
1426
+ function parseBillingBlockedProviderSignal(message) {
1427
+ const direct = parsePrefixedSignal(message);
1428
+ if (direct) return direct;
1429
+ try {
1430
+ const envelope = nestedProxyEnvelopeSchema.safeParse(JSON.parse(message));
1431
+ if (!envelope.success) return null;
1432
+ const nested = parsePrefixedSignal(envelope.data.error.message);
1433
+ const topLevel = parsePrefixedSignal(envelope.data.message);
1434
+ if (!nested || nested.blockReason !== envelope.data.blockReason || envelope.data.message !== nested.message && (!topLevel || topLevel.blockReason !== nested.blockReason || topLevel.message !== nested.message)) return null;
1435
+ return nested;
1436
+ } catch {
1437
+ return null;
1438
+ }
1439
+ }
1440
+ //#endregion
1382
1441
  //#region src/protocols/chat-completions.ts
1383
1442
  /**
1384
1443
  * OpenAI Chat Completions–compatible protocol handler.
@@ -1605,6 +1664,10 @@ async function loadHistoryIntoSession({ sm, messages, upToIdxExclusive, modelNam
1605
1664
  }
1606
1665
  }
1607
1666
  }
1667
+ function messageTimestampMs(m) {
1668
+ const ts = m?.timestamp;
1669
+ return typeof ts === "number" && Number.isFinite(ts) ? ts : null;
1670
+ }
1608
1671
  function piMessagesToOpenAI(messages) {
1609
1672
  const out = [];
1610
1673
  for (const m of messages) {
@@ -1633,6 +1696,8 @@ function piMessagesToOpenAI(messages) {
1633
1696
  };
1634
1697
  if (toolCalls.length) msg.tool_calls = toolCalls;
1635
1698
  if (thinking.length) msg.x_thinking = thinking;
1699
+ const createdAtMs = messageTimestampMs(m);
1700
+ if (createdAtMs !== null) msg.x_created_at = createdAtMs;
1636
1701
  out.push(msg);
1637
1702
  continue;
1638
1703
  }
@@ -1644,6 +1709,8 @@ function piMessagesToOpenAI(messages) {
1644
1709
  content: text
1645
1710
  };
1646
1711
  if (m.isError) tm.x_is_error = true;
1712
+ const createdAtMs = messageTimestampMs(m);
1713
+ if (createdAtMs !== null) tm.x_created_at = createdAtMs;
1647
1714
  out.push(tm);
1648
1715
  continue;
1649
1716
  }
@@ -1922,6 +1989,22 @@ function runStream$1({ session, sm, prompt, images, sessionId, created, reqStart
1922
1989
  postPrompt
1923
1990
  });
1924
1991
  if (capturedModelError !== null) {
1992
+ const billingBlocked = parseBillingBlockedProviderSignal(capturedModelError);
1993
+ if (billingBlocked) {
1994
+ log.warn({
1995
+ event: "billing_blocked",
1996
+ chatcmpl_id: sessionId,
1997
+ source: "stop_reason_error"
1998
+ }, "forwarding platform billing block to client");
1999
+ emitBillingBlocked({
2000
+ writer,
2001
+ sessionId,
2002
+ created,
2003
+ billingBlocked
2004
+ });
2005
+ writer.write("data: [DONE]\n\n");
2006
+ return;
2007
+ }
1925
2008
  const providerError = toModelProviderError(new Error(capturedModelError));
1926
2009
  log.warn({
1927
2010
  event: "model_provider_error",
@@ -1957,6 +2040,17 @@ function runStream$1({ session, sm, prompt, images, sessionId, created, reqStart
1957
2040
  err
1958
2041
  }, "chat error");
1959
2042
  if (isModelProviderError(err)) {
2043
+ const billingBlocked = parseBillingBlockedProviderSignal(err instanceof Error ? err.message : String(err));
2044
+ if (billingBlocked) {
2045
+ emitBillingBlocked({
2046
+ writer,
2047
+ sessionId,
2048
+ created,
2049
+ billingBlocked
2050
+ });
2051
+ writer.write("data: [DONE]\n\n");
2052
+ return;
2053
+ }
1960
2054
  const providerError = toModelProviderError(err);
1961
2055
  log.warn({
1962
2056
  event: "model_provider_error",
@@ -2030,6 +2124,23 @@ function emitModelProviderError({ writer, sessionId, created, providerError }) {
2030
2124
  };
2031
2125
  writer.write(`data: ${JSON.stringify(chunk)}\n\n`);
2032
2126
  }
2127
+ function emitBillingBlocked({ writer, sessionId, created, billingBlocked }) {
2128
+ const chunk = {
2129
+ id: sessionId,
2130
+ object: "chat.completion.chunk",
2131
+ created,
2132
+ choices: [{
2133
+ index: 0,
2134
+ delta: {},
2135
+ finish_reason: "stop"
2136
+ }],
2137
+ x_billing_blocked: {
2138
+ block_reason: billingBlocked.blockReason,
2139
+ message: billingBlocked.message
2140
+ }
2141
+ };
2142
+ writer.write(`data: ${JSON.stringify(chunk)}\n\n`);
2143
+ }
2033
2144
  async function runBlocking$1({ session, sm, prompt, images, sessionId, created, reqStart, upstreamStartMs, log, postPrompt, registry, pendingSteerIds }) {
2034
2145
  const baselineMessageCount = sm.buildSessionContext().messages.length;
2035
2146
  let content = "";
@@ -2851,4 +2962,4 @@ function chainMiddleware(middlewares) {
2851
2962
  };
2852
2963
  }
2853
2964
  //#endregion
2854
- export { DEFAULT_MODEL, DEFAULT_PROVIDER, DEFAULT_THINKING_LEVEL, KNOWN_PI_PROVIDERS, PI_AGENT_DIR, VALID_THINKING_LEVELS, buildAgentCard, buildModelFromSpec, chainMiddleware, composeHandlers, createAgentExecutor, createMapSessionRegistry, createPrewarm, createProtocolHandlers, createProtocols, deriveTraceContext, getCurrentTraceparent, logger, modelSpecSchema, mountAt, newTraceContext, parseModelSpec, parseTraceId, requestHeaders, requestLogger, requestUrl, resolveRequestModel, runInTraceContext, setCurrentTraceparent, webHandlerToMiddleware, withSpecApiKey };
2965
+ export { BILLING_BLOCK_REASONS, DEFAULT_MODEL, DEFAULT_PROVIDER, DEFAULT_THINKING_LEVEL, KNOWN_PI_PROVIDERS, PI_AGENT_DIR, VALID_THINKING_LEVELS, buildAgentCard, buildModelFromSpec, chainMiddleware, composeHandlers, createAgentExecutor, createMapSessionRegistry, createPrewarm, createProtocolHandlers, createProtocols, deriveTraceContext, getCurrentTraceparent, logger, modelSpecSchema, mountAt, newTraceContext, parseModelSpec, parseTraceId, requestHeaders, requestLogger, requestUrl, resolveRequestModel, runInTraceContext, setCurrentTraceparent, webHandlerToMiddleware, withSpecApiKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-server",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.635",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",