@alpic-ai/api 0.0.0-dev.gda044d0 → 0.0.0-dev.gda47a5d

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.mjs CHANGED
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import * as z$1 from "zod/v4";
3
3
  import { oc } from "@orpc/contract";
4
4
  import ms from "ms";
5
- //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.30.0_supports-color@7.2.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
5
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.0_supports-color@7.2.0_zod@4.5.4/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
6
6
  /**
7
7
  * Reusable URL validation that disallows javascript: scheme
8
8
  */
@@ -119,7 +119,12 @@ z$1.object({
119
119
  token_type: z$1.string(),
120
120
  expires_in: z$1.coerce.number().optional(),
121
121
  scope: z$1.string().optional(),
122
- refresh_token: z$1.string().optional()
122
+ refresh_token: z$1.string().optional(),
123
+ /**
124
+ * Not part of the wire format: the authorization server this value was obtained from, added by
125
+ * the client's `auth()` before it is stored and compared when it is read back.
126
+ */
127
+ issuer: z$1.string().optional().catch(void 0)
123
128
  }).strip();
124
129
  z$1.object({
125
130
  error: z$1.string(),
@@ -158,7 +163,12 @@ const OAuthClientInformationSchema = z$1.object({
158
163
  client_id: z$1.string(),
159
164
  client_secret: z$1.string().optional(),
160
165
  client_id_issued_at: z$1.number().optional(),
161
- client_secret_expires_at: z$1.number().optional()
166
+ client_secret_expires_at: z$1.number().optional(),
167
+ /**
168
+ * Not part of the wire format: the authorization server this value was obtained from, added by
169
+ * the client's `auth()` before it is stored and compared when it is read back.
170
+ */
171
+ issuer: z$1.string().optional().catch(void 0)
162
172
  }).strip();
163
173
  OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
164
174
  z$1.object({
@@ -179,6 +189,7 @@ const PLATFORM_LABELS = {
179
189
  };
180
190
  const WAF_PLATFORMS = [
181
191
  "akamai",
192
+ "cato",
182
193
  "cloudflare",
183
194
  "fastly"
184
195
  ];
@@ -256,16 +267,25 @@ z.object({
256
267
  clientSecret: z.string(),
257
268
  clientScopes: z.array(z.string())
258
269
  });
259
- z.enum([
260
- "opening_balance",
270
+ const creditEntryReasonSchema = z.enum([
261
271
  "free_seed",
262
272
  "paid_conversion_floor",
263
273
  "top_up",
264
274
  "usage",
265
- "refund",
266
275
  "admin_adjustment"
267
276
  ]);
268
277
  z.enum(["playground"]);
278
+ z.number().int().min(500);
279
+ const creditActivityEntrySchema = z.object({
280
+ reason: creditEntryReasonSchema,
281
+ day: z.number(),
282
+ amountInNanoUSD: z.number(),
283
+ messageCount: z.number().nullable()
284
+ });
285
+ z.object({
286
+ balanceInNanoUSD: z.number(),
287
+ recentActivity: z.array(creditActivityEntrySchema)
288
+ });
269
289
  const deploymentStatusSchema$1 = z.enum([
270
290
  "ongoing",
271
291
  "deployed",
@@ -410,7 +430,8 @@ z.object({
410
430
  collectResponsePayload: z.boolean(),
411
431
  collectErrorMessage: z.boolean(),
412
432
  collectUserData: z.boolean(),
413
- identityTraitKey: z.string().min(1).max(200).nullable()
433
+ identityTraitKey: z.string().min(1).max(200).nullable(),
434
+ leadEventName: z.string().min(1).max(200).nullable()
414
435
  });
415
436
  const feedbackSchema = z.object({
416
437
  id: z.string(),
@@ -513,12 +534,30 @@ z.object({
513
534
  createdAt: z.coerce.date(),
514
535
  updatedAt: z.coerce.date()
515
536
  });
537
+ const alpicMcpRequestLogSchema = z.object({
538
+ type: z.literal("mcp_request"),
539
+ method: z.string()
540
+ });
541
+ const alpicMcpErrorLogSchema = z.object({
542
+ type: z.literal("mcp_error"),
543
+ method: z.string(),
544
+ error: z.string()
545
+ });
546
+ z.union([alpicMcpRequestLogSchema, alpicMcpErrorLogSchema]);
516
547
  z.enum([
517
548
  "INFO",
518
549
  "WARNING",
519
550
  "DEBUG",
520
551
  "ERROR"
521
552
  ]);
553
+ const LOG_SEARCH_MAX_ESCAPED_LENGTH = 960;
554
+ function escapeLogSearchTerm(search) {
555
+ return [...search].flatMap((character) => [...new TextEncoder().encode(character)]).map((byte) => {
556
+ const character = String.fromCharCode(byte);
557
+ return /^[a-zA-Z0-9]$/.test(character) ? character : `\\x${byte.toString(16).toUpperCase().padStart(2, "0")}`;
558
+ }).join("");
559
+ }
560
+ const logSearchSchema = z.string().max(240, `Search must be 240 characters or fewer`).refine((search) => escapeLogSearchTerm(search).length <= LOG_SEARCH_MAX_ESCAPED_LENGTH, "Search is too complex; shorten it or use fewer special characters");
522
561
  /** Only names a vendor actually ships belong here: lookalikes like `claude-code-test` are customers' own scripts. */
523
562
  const MCP_CLIENT_GROUPS = [
524
563
  {
@@ -844,6 +883,10 @@ const clampStringField = (field) => {
844
883
  const withMin = field.minLength === null ? clamped : clamped.min(field.minLength);
845
884
  return field.description ? withMin.describe(field.description) : withMin;
846
885
  };
886
+ const unboundedArrayField = (field) => {
887
+ const unbounded = z.array(field.element);
888
+ return field.description ? unbounded.describe(field.description) : unbounded;
889
+ };
847
890
  const toolDefinitionSchema = z.object({
848
891
  name: z.string(),
849
892
  title: z.string().optional().describe("Human-friendly name for the tool, used in the UI. If not provided, `name` will be used."),
@@ -856,11 +899,22 @@ const toolDefinitionSchema = z.object({
856
899
  }).optional()
857
900
  });
858
901
  const positiveTestCaseSchema = z.object({
859
- scenario: z.string().describe("Short label for what this case demonstrates."),
860
- userPrompt: z.string().describe("A realistic, standalone user message a reviewer can paste and run with no prior state or multi-turn setup. Vary phrasing and tone across cases."),
902
+ scenario: z.string().min(1).describe("Short label for what this case demonstrates."),
903
+ userPrompt: z.string().min(1).describe("A realistic, standalone user message a reviewer can paste and run with no prior state or multi-turn setup. Vary phrasing and tone across cases."),
861
904
  toolTriggered: z.string().optional().describe("The tool this prompt should invoke."),
862
905
  expectedOutput: z.string().optional().describe("What the user should see, including post-interaction behaviour where relevant.")
863
- }).partial().describe("Each case: Scenario, User prompt, Tool triggered, Expected output.");
906
+ }).describe("Each case: Scenario, User prompt, Tool triggered, Expected output.");
907
+ const positiveTestCaseDraftSchema = positiveTestCaseSchema.partial().extend({
908
+ scenario: z.string().optional(),
909
+ userPrompt: z.string().optional()
910
+ });
911
+ const blankPositiveTestCase = () => ({
912
+ scenario: "",
913
+ userPrompt: "",
914
+ toolTriggered: "",
915
+ expectedOutput: ""
916
+ });
917
+ const toFixedLength = (entries, length, blank) => Array.from({ length }, (_, index) => entries[index] ?? blank());
864
918
  const screenshotEntrySchema = z.object({
865
919
  prompt: z.string(),
866
920
  url: z.url()
@@ -1173,9 +1227,18 @@ const chatgptTranslationLocaleSchema = z.enum([
1173
1227
  "zh-TW"
1174
1228
  ]);
1175
1229
  const negativeTestCaseSchema = z.object({
1176
- scenario: z.string(),
1177
- userPrompt: z.string()
1178
- }).partial().describe("Each case: Scenario + User prompt (the app should NOT trigger).");
1230
+ scenario: z.string().min(1),
1231
+ userPrompt: z.string().min(1)
1232
+ }).describe("Each case: Scenario + User prompt (the plugin should NOT trigger).");
1233
+ const negativeTestCaseDraftSchema = negativeTestCaseSchema.partial().extend({
1234
+ scenario: z.string().optional(),
1235
+ userPrompt: z.string().optional()
1236
+ });
1237
+ const blankNegativeTestCase = () => ({
1238
+ scenario: "",
1239
+ userPrompt: ""
1240
+ });
1241
+ const chatgptSkillSchema = z.object({ name: z.string() }).describe("A skill discovered on the MCP server, by name.");
1179
1242
  const chatgptToolJustificationSchema = z.object({
1180
1243
  toolName: z.string(),
1181
1244
  readOnlyJustification: z.string().describe("One sentence on what the tool reads and returns."),
@@ -1195,27 +1258,28 @@ chatgptTranslationSchema.extend({ tagline: clampStringField(chatgptTaglineSchema
1195
1258
  const chatgptSubmissionFormDataSchema = z.object({
1196
1259
  logoLight: z.string().describe("Logo icon for light mode. Square PNG, no borders or rounded corners (clients apply circular cropping)."),
1197
1260
  logoDark: z.string().optional().describe("Optional dark-mode logo icon. Square PNG, same specs as the light icon. Leave empty if the light icon also works on dark backgrounds."),
1198
- appName: z.string().describe("The name users will see in ChatGPT and in the Apps Directory."),
1261
+ appName: z.string().describe("The name users will see in ChatGPT and in the Plugin Directory."),
1199
1262
  tagline: chatgptTaglineSchema.describe("Plain-language phrase focused on function and user value, 30 chars max. Avoid generic superlatives like \"the best …\"."),
1200
- description: chatgptDescriptionSchema.describe("Clear, engaging description highlighting what the app does and why people will love it. Appears publicly on the directory page. End it by naming the product categories or intents the app does NOT cover, so ChatGPT learns when not to route to it (define exclusions by absent categories or wrong intents, never by naming other brands)."),
1263
+ description: chatgptDescriptionSchema.describe("Clear, engaging description highlighting what the plugin does and why people will love it. Appears publicly on the directory page. End it by naming the product categories or intents the plugin does NOT cover, so ChatGPT learns when not to route to it (define exclusions by absent categories or wrong intents, never by naming other brands)."),
1201
1264
  category: chatgptCategorySchema.describe("Category from the OpenAI taxonomy."),
1202
- developerName: z.string().describe("Developer name shown publicly on the app's directory page."),
1265
+ developerName: z.string().describe("Developer name shown publicly on the plugin's directory page."),
1203
1266
  companyUrl: urlField.describe("Your company's main website URL."),
1204
1267
  supportChannel: supportChannelSchema.describe("Customer support URL or email address."),
1205
1268
  privacyPolicyUrl: urlField.describe("URL to your privacy policy."),
1206
- termsOfServiceUrl: urlField.describe("URL to the app's terms of service."),
1207
- demoRecordingUrl: urlField.describe("URL to a video demonstrating the app, recorded via OpenAI Developer Mode. Cover all main use cases on web, iOS, and Android."),
1208
- appCommerceAndPurchasing: z.boolean().describe("Checkbox: 'My app links or directs users out of ChatGPT to make purchases.' Defaults to false. Verify the app does not offer digital goods."),
1269
+ termsOfServiceUrl: urlField.describe("URL to the plugin's terms of service."),
1270
+ demoRecordingUrl: urlField.describe("URL to a video demonstrating the plugin, recorded via OpenAI Developer Mode. Cover all main use cases on web, iOS, and Android."),
1271
+ appCommerceAndPurchasing: z.boolean().describe("Checkbox: 'My plugin links or directs users out of ChatGPT to make purchases.' Defaults to false. Verify the plugin does not offer digital goods."),
1209
1272
  serverUrl: urlField.describe("URL of the MCP server."),
1210
1273
  authentication: chatgptAuthenticationSchema.describe("OAuth 2.0 or No auth. OAuth configuration is auto-discovered from the MCP server's metadata."),
1211
1274
  tools: z.array(toolDefinitionSchema).describe("List of tools exposed by the MCP server (auto-populated from the production server's manifest)."),
1212
1275
  toolJustifications: z.array(chatgptToolJustificationSchema).describe("Per-tool justification of `readOnlyHint`, `openWorldHint`, and `destructiveHint` annotation values. One short, specific sentence per hint describing what the tool actually does."),
1213
- testCases: z.array(positiveTestCaseSchema).describe("At least 5 positive test cases. Each: Scenario, User prompt, Tool triggered, Expected output. Collectively cover the full capability across different flow stages (initial search or browse, market or locale handling, post-interaction detail, an action ChatGPT performs on the user's behalf, and a conversion or secondary tool) rather than five variations of the same first step."),
1214
- negativeTestCases: z.array(negativeTestCaseSchema).describe("3 negative test cases: prompts where the app should NOT trigger but the model might think it is relevant. These become production routing metadata that teaches ChatGPT when to stay silent, so pick tight near-misses: a product category the app does not carry, the right brand or domain but an intent the app does not serve, or a boundary with a sibling app."),
1215
- screenshots: z.array(screenshotEntrySchema.extend({ prompt: z.string().max(75, { error: "Screenshot prompts are limited to 75 characters." }) })).max(3).describe("In-app screenshots paired with the user prompt that produced them (each prompt is 75 characters max). Widget apps must show the widget UI; non-widget apps show the model response. Min 1, max 3 entries, all public. Images: 706px wide, 400–860px tall, PNG."),
1276
+ skills: z.array(chatgptSkillSchema).optional().describe("Skills the server exposes over MCP (auto-populated from the production server's manifest). Left unset when the server does not advertise the skills extension, which is a different state from advertising it and exposing none."),
1277
+ testCases: z.array(positiveTestCaseSchema).length(5).describe("Exactly 5 positive test cases. Each: Scenario, User prompt, Tool triggered, Expected output. Collectively cover the full capability across different flow stages (initial search or browse, market or locale handling, post-interaction detail, an action ChatGPT performs on the user's behalf, and a conversion or secondary tool) rather than five variations of the same first step."),
1278
+ negativeTestCases: z.array(negativeTestCaseSchema).length(3).describe("Exactly 3 negative test cases: prompts where the plugin should NOT trigger but the model might think it is relevant. These become production routing metadata that teaches ChatGPT when to stay silent, so pick tight near-misses: a product category the plugin does not carry, the right brand or domain but an intent the plugin does not serve, or a boundary with a sibling plugin."),
1279
+ screenshots: z.array(screenshotEntrySchema.extend({ prompt: z.string().max(75, { error: "Screenshot prompts are limited to 75 characters." }) })).max(3).describe("In-plugin screenshots paired with the user prompt that produced them (each prompt is 75 characters max). Widget plugins must show the widget UI; non-widget plugins show the model response. Min 1, max 3 entries, all public. Images: 706px wide, 400–860px tall, PNG."),
1216
1280
  translations: z.array(chatgptTranslationSchema).describe("Per-locale translation of tagline + description. English (US) is the default."),
1217
1281
  allowedCountries: chatgptAllowedCountriesSchema.describe("Availability: all supported countries, or an allow-list / block-list of specific ones (ISO alpha-2)."),
1218
- releaseNotes: z.string().describe("Publicly displayed on the app details page.")
1282
+ releaseNotes: z.string().describe("Publicly displayed on the plugin details page.")
1219
1283
  });
1220
1284
  const chatgptSubmissionDraftSchema = chatgptSubmissionFormDataSchema.partial().extend({
1221
1285
  tagline: z.string().optional(),
@@ -1226,23 +1290,35 @@ const chatgptSubmissionDraftSchema = chatgptSubmissionFormDataSchema.partial().e
1226
1290
  demoRecordingUrl: z.string().optional(),
1227
1291
  serverUrl: z.string().optional(),
1228
1292
  screenshots: z.array(screenshotDraftEntrySchema).optional(),
1293
+ testCases: z.array(positiveTestCaseDraftSchema).optional(),
1294
+ negativeTestCases: z.array(negativeTestCaseDraftSchema).optional(),
1229
1295
  translations: z.array(chatgptTranslationSchema.extend({ tagline: z.string() })).optional()
1230
1296
  });
1231
- chatgptSubmissionFormDataSchema.pick({
1297
+ /** Source of truth for the fields `SubmissionPrefillService.prefill({ platform: "chatgpt" })` can populate. */
1298
+ const chatgptPrefillFormDataSchema = chatgptSubmissionFormDataSchema.pick({
1232
1299
  appName: true,
1233
1300
  developerName: true,
1234
1301
  serverUrl: true,
1235
1302
  tools: true,
1303
+ skills: true,
1236
1304
  authentication: true
1237
1305
  });
1238
- chatgptSubmissionFormDataSchema.pick({
1306
+ /** Source of truth for `SubmissionPrefillService.generate({ platform: "chatgpt" })`. */
1307
+ const chatgptAiGeneratedFormDataSchema = chatgptSubmissionFormDataSchema.pick({
1239
1308
  tagline: true,
1240
1309
  description: true,
1241
1310
  category: true,
1242
1311
  testCases: true,
1243
1312
  negativeTestCases: true,
1244
1313
  toolJustifications: true
1245
- }).extend({ tagline: clampStringField(chatgptSubmissionFormDataSchema.shape.tagline) });
1314
+ }).extend({
1315
+ testCases: unboundedArrayField(chatgptSubmissionFormDataSchema.shape.testCases),
1316
+ negativeTestCases: unboundedArrayField(chatgptSubmissionFormDataSchema.shape.negativeTestCases)
1317
+ }).extend({
1318
+ tagline: clampStringField(chatgptSubmissionFormDataSchema.shape.tagline),
1319
+ testCases: z.array(positiveTestCaseDraftSchema).transform((cases) => toFixedLength(cases, 5, blankPositiveTestCase)),
1320
+ negativeTestCases: z.array(negativeTestCaseDraftSchema).transform((cases) => toFixedLength(cases, 3, blankNegativeTestCase))
1321
+ });
1246
1322
  const claudeCategorySchema = z.enum([
1247
1323
  "Productivity",
1248
1324
  "Communication",
@@ -1365,7 +1441,8 @@ const claudeSubmissionDraftSchema = claudeSubmissionFormDataSchema.partial().ext
1365
1441
  categories: z.array(claudeCategorySchema).optional(),
1366
1442
  screenshots: z.array(screenshotDraftEntrySchema).optional()
1367
1443
  });
1368
- claudeSubmissionFormDataSchema.pick({
1444
+ /** Source of truth for the fields `SubmissionPrefillService.prefill({ platform: "claudeai" })` can populate. */
1445
+ const claudePrefillFormDataSchema = claudeSubmissionFormDataSchema.pick({
1369
1446
  serverUrl: true,
1370
1447
  name: true,
1371
1448
  slug: true,
@@ -1387,27 +1464,81 @@ const claudeAiGeneratedFormDataRawSchema = z.object({
1387
1464
  categories: z.array(claudeCategorySchema).describe(claudeCategoryDescription),
1388
1465
  primaryUseCases: claudeSubmissionFormDataSchema.shape.primaryUseCases
1389
1466
  });
1390
- claudeAiGeneratedFormDataRawSchema.extend({
1467
+ const claudeAiGeneratedFormDataSchema = claudeAiGeneratedFormDataRawSchema.extend({
1391
1468
  oneLiner: clampStringField(claudeSubmissionFormDataSchema.shape.oneLiner),
1392
1469
  categories: claudeAiGeneratedFormDataRawSchema.shape.categories.transform((categories) => categories.slice(0, 5))
1393
1470
  });
1471
+ function provenanceByField(prefillShape, aiGeneratedShape) {
1472
+ const byField = {};
1473
+ for (const field of Object.keys(prefillShape)) byField[field] = "prefilled";
1474
+ for (const field of Object.keys(aiGeneratedShape)) byField[field] = "ai-generated";
1475
+ return byField;
1476
+ }
1477
+ provenanceByField(claudePrefillFormDataSchema.shape, claudeAiGeneratedFormDataSchema.shape), provenanceByField(chatgptPrefillFormDataSchema.shape, chatgptAiGeneratedFormDataSchema.shape);
1478
+ const urlVerificationOutcomeSchema = z.enum([
1479
+ "pass",
1480
+ "fail",
1481
+ "unverified"
1482
+ ]);
1483
+ const VERIFIABLE_URL_FIELDS = {
1484
+ chatgpt: ["privacyPolicyUrl", "termsOfServiceUrl"],
1485
+ claudeai: ["privacyPolicy"]
1486
+ };
1487
+ const verifiableUrlFieldSchema = z.enum([...VERIFIABLE_URL_FIELDS.chatgpt, ...VERIFIABLE_URL_FIELDS.claudeai]);
1488
+ const policyDisclosureSchema = z.enum([
1489
+ "dataCategories",
1490
+ "purposesOfUse",
1491
+ "recipients",
1492
+ "retention"
1493
+ ]);
1494
+ const urlVerificationFieldResultSchema = z.object({
1495
+ field: verifiableUrlFieldSchema,
1496
+ url: z.string(),
1497
+ outcome: urlVerificationOutcomeSchema,
1498
+ reason: z.string(),
1499
+ concerns: z.array(z.string()).optional(),
1500
+ scrapedWith: z.enum(["fetch", "firecrawl"]).optional()
1501
+ });
1502
+ const urlVerificationSchema = z.object({
1503
+ verifiedAt: z.coerce.date(),
1504
+ results: z.array(urlVerificationFieldResultSchema)
1505
+ });
1506
+ const pageKindSchema = z.enum([
1507
+ "expectedDocument",
1508
+ "errorPage",
1509
+ "loginWall",
1510
+ "parkedDomain",
1511
+ "comingSoon",
1512
+ "marketingPage",
1513
+ "unrelatedDocument"
1514
+ ]);
1515
+ z.object({
1516
+ pageKind: pageKindSchema.describe("What the page actually is. Use 'expectedDocument' only when it is genuinely the document the field claims."),
1517
+ reason: z.string().max(200).describe("One sentence naming what the page is, addressed to the developer who entered the URL."),
1518
+ missingDisclosures: z.array(policyDisclosureSchema).describe("For a privacy policy only: which of the four required disclosures the text does not cover. Empty for every other page kind.")
1519
+ });
1394
1520
  const submissionMetaFieldsSchema = z.object({
1395
1521
  id: z.string(),
1396
1522
  environmentId: z.string(),
1397
1523
  auditId: z.string().nullable(),
1524
+ urlVerification: urlVerificationSchema.nullable().default(null),
1398
1525
  createdAt: z.coerce.date(),
1399
1526
  updatedAt: z.coerce.date()
1400
1527
  });
1401
1528
  const claudeSubmissionSchemaInternal = submissionMetaFieldsSchema.extend({
1402
1529
  platform: z.literal("claudeai"),
1403
- formData: claudeSubmissionDraftSchema
1530
+ formData: claudeSubmissionDraftSchema,
1531
+ prefillSnapshot: claudeSubmissionDraftSchema.nullable().default(null)
1404
1532
  });
1405
1533
  const chatgptSubmissionSchemaInternal = submissionMetaFieldsSchema.extend({
1406
1534
  platform: z.literal("chatgpt"),
1407
- formData: chatgptSubmissionDraftSchema
1535
+ formData: chatgptSubmissionDraftSchema,
1536
+ prefillSnapshot: chatgptSubmissionDraftSchema.nullable().default(null)
1408
1537
  });
1409
- z.discriminatedUnion("platform", [claudeSubmissionSchemaInternal, chatgptSubmissionSchemaInternal]);
1538
+ const submissionSchemaInternal = z.discriminatedUnion("platform", [claudeSubmissionSchemaInternal, chatgptSubmissionSchemaInternal]);
1410
1539
  z.union([claudeSubmissionDraftSchema, chatgptSubmissionDraftSchema]);
1540
+ /** Discriminated on `platform`, which pins the shape of `formData`: a Claude submission cannot carry chatgpt-only fields, and vice-versa. */
1541
+ const submissionSchema = submissionSchemaInternal;
1411
1542
  z.literal([
1412
1543
  100,
1413
1544
  75,
@@ -1424,18 +1555,32 @@ const customerCreditsSchema = z.object({
1424
1555
  expiresAt: z.number().nullable(),
1425
1556
  currency: z.string()
1426
1557
  });
1427
- const customerUsageSchema = z.object({
1428
- amountInCents: z.number(),
1429
- currency: z.string(),
1430
- periodEnd: z.number()
1431
- });
1432
1558
  const partnerDiscountSchema = z.object({ endsAt: z.number() });
1433
- z.object({ balanceInNanoUSD: z.number() });
1434
1559
  z.object({
1435
1560
  customerCredits: customerCreditsSchema.nullable(),
1436
- customerUsage: customerUsageSchema.nullable(),
1437
1561
  partnerDiscount: partnerDiscountSchema.nullable()
1438
1562
  });
1563
+ const metricsQueueEventSchema = z.object({
1564
+ ts: z.number().int(),
1565
+ method: z.string(),
1566
+ tool: z.string().nullable(),
1567
+ client: z.string(),
1568
+ sessionId: z.string().nullable(),
1569
+ durationMs: z.number().int(),
1570
+ outputTokens: z.number().int().nullable(),
1571
+ errorType: z.enum([
1572
+ "mcp_error",
1573
+ "tool_error",
1574
+ "timeout"
1575
+ ]).nullable(),
1576
+ errorCode: z.number().int().nullable()
1577
+ });
1578
+ z.object({
1579
+ v: z.literal(1),
1580
+ envId: z.string(),
1581
+ events: z.array(metricsQueueEventSchema)
1582
+ });
1583
+ z.object({ v: z.number() });
1439
1584
  const telemetrySignalSchema = z.enum([
1440
1585
  "logs",
1441
1586
  "metrics",
@@ -1443,11 +1588,36 @@ const telemetrySignalSchema = z.enum([
1443
1588
  ]);
1444
1589
  const otlpProtocolSchema = z.enum(["http/protobuf", "http/json"]);
1445
1590
  const otlpEndpointSchema = z.string().trim().min(1).max(2048);
1591
+ const OTLP_HEADER_VALUE_MAX_LENGTH = 2048;
1592
+ const otlpHeaderNameSchema = z.string().trim().min(1, "Enter a header name").max(128).regex(/^[A-Za-z0-9!#$%&'*+\-.^_`|~]+$/, "Use letters, digits and !#$%&'*+-.^_`|~ only");
1593
+ const otlpHeaderValueSchema = z.string().trim().max(OTLP_HEADER_VALUE_MAX_LENGTH).refine((value) => !/[\r\n]/.test(value), "Line breaks are not allowed in a header value");
1594
+ const telemetryDestinationHeaderSchema = z.object({
1595
+ id: z.string(),
1596
+ name: otlpHeaderNameSchema,
1597
+ value: otlpHeaderValueSchema,
1598
+ isSecret: z.boolean()
1599
+ });
1600
+ const otlpPushFailureReasonSchema = z.enum([
1601
+ "credentials",
1602
+ "wrong-path",
1603
+ "wrong-protocol",
1604
+ "invalid-payload",
1605
+ "partial-rejection",
1606
+ "blocked-target",
1607
+ "timeout",
1608
+ "unreachable",
1609
+ "receiver-error",
1610
+ "unexpected-status"
1611
+ ]);
1612
+ const telemetryDestinationStatusSchema = z.enum(["active", "suspended"]);
1446
1613
  z.object({
1447
1614
  id: z.string(),
1448
1615
  signal: telemetrySignalSchema,
1449
1616
  endpoint: otlpEndpointSchema,
1450
- protocol: otlpProtocolSchema
1617
+ protocol: otlpProtocolSchema,
1618
+ headers: z.array(telemetryDestinationHeaderSchema),
1619
+ status: telemetryDestinationStatusSchema,
1620
+ lastFailureReason: otlpPushFailureReasonSchema.nullable()
1451
1621
  });
1452
1622
  //#endregion
1453
1623
  //#region src/auth-scope.ts
@@ -1547,6 +1717,14 @@ const serverFieldsSchema = z.object({
1547
1717
  });
1548
1718
  //#endregion
1549
1719
  //#region src/api.contract.ts
1720
+ const isValidIanaTimeZone = (timeZone) => {
1721
+ try {
1722
+ new Intl.DateTimeFormat("en-US", { timeZone });
1723
+ return true;
1724
+ } catch {
1725
+ return false;
1726
+ }
1727
+ };
1550
1728
  const deploymentStatusSchema = z.enum([
1551
1729
  "ongoing",
1552
1730
  "deployed",
@@ -1617,6 +1795,14 @@ const getEnvironmentContractV1 = base.route({
1617
1795
  createdAt: z.coerce.date(),
1618
1796
  projectId: z.string()
1619
1797
  }));
1798
+ const deleteEnvironmentContractV1 = base.route({
1799
+ path: "/v1/environments/{environmentId}",
1800
+ method: "DELETE",
1801
+ summary: "Delete an environment",
1802
+ description: "All environments can be deleted except the production environment. This operation is not reversible: associated logs, analytics, and metrics are deleted as well.",
1803
+ tags: ["environments"],
1804
+ successDescription: "The environment has been deleted successfully"
1805
+ }).errors({ NOT_FOUND: {} }).input(z.object({ environmentId: z.string().describe("The ID of the environment") })).output(z.object({ success: z.literal(true) }));
1620
1806
  const domainSchema = z.object({
1621
1807
  domain: z.string(),
1622
1808
  status: z.enum([
@@ -1866,7 +2052,7 @@ const getLogsContractV1 = base.route({
1866
2052
  "WARNING",
1867
2053
  "DEBUG"
1868
2054
  ])).optional().describe("Filter by log level"),
1869
- search: z.string().optional().describe("Filter pattern to search for in log content"),
2055
+ search: logSearchSchema.optional().describe("Term to search for in log content"),
1870
2056
  nextToken: z.string().optional().describe("Pagination token from a previous response")
1871
2057
  })).output(z.object({
1872
2058
  logs: z.array(logEntrySchema),
@@ -1888,7 +2074,7 @@ const getLatestLogsContractV1 = base.route({
1888
2074
  "WARNING",
1889
2075
  "DEBUG"
1890
2076
  ])).optional().describe("Filter by log level"),
1891
- search: z.string().optional().describe("Filter pattern to search for in log content")
2077
+ search: logSearchSchema.optional().describe("Term to search for in log content")
1892
2078
  })).output(z.object({ logs: z.array(logEntrySchema) }));
1893
2079
  const getDeploymentLogsContractV1 = base.route({
1894
2080
  path: "/v1/deployments/{deploymentId}/logs",
@@ -1929,7 +2115,7 @@ const getProjectAnalyticsContractV1 = base.route({
1929
2115
  startTimestamp: z.coerce.number().describe("Start timestamp in milliseconds"),
1930
2116
  endTimestamp: z.coerce.number().describe("End timestamp in milliseconds"),
1931
2117
  timeZone: z.string().describe("IANA timezone (e.g. Europe/Paris)")
1932
- }).refine(({ startTimestamp, endTimestamp }) => endTimestamp - startTimestamp > 0, { message: "End date must be after start date" }).refine(({ startTimestamp, endTimestamp }) => endTimestamp - startTimestamp <= 744 * 60 * 60 * 1e3, { message: "Date range must be less than 1 month" }).refine(({ timeZone }) => Intl.supportedValuesOf("timeZone").includes(timeZone), { message: "Time zone must be a valid IANA timezone" })).output(z.object({
2118
+ }).refine(({ startTimestamp, endTimestamp }) => endTimestamp - startTimestamp > 0, { message: "End date must be after start date" }).refine(({ startTimestamp, endTimestamp }) => endTimestamp - startTimestamp <= 26784e5, { message: "Date range must be less than 1 month" }).refine(({ timeZone }) => isValidIanaTimeZone(timeZone), { message: "Time zone must be a valid IANA timezone" })).output(z.object({
1933
2119
  metadata: z.object({
1934
2120
  startTimestamp: z.number(),
1935
2121
  endTimestamp: z.number(),
@@ -2199,6 +2385,57 @@ const getBeaconContractV1 = base.route({
2199
2385
  createdAt: z.coerce.date(),
2200
2386
  report: auditReportWithScreenshotsSchema.nullable()
2201
2387
  }));
2388
+ const PLATFORM_DESCRIPTION = "The directory the package targets: `chatgpt` for the OpenAI App Directory, `claudeai` for the Anthropic MCP Directory";
2389
+ const submissionIdSchema = z.string().describe("The ID of the submission package");
2390
+ const claudeSubmissionUpdateSchema = claudeSubmissionDraftSchema.strict();
2391
+ const chatgptSubmissionUpdateSchema = chatgptSubmissionDraftSchema.strict();
2392
+ const createSubmissionContractV1 = base.route({
2393
+ path: "/v1/submissions",
2394
+ method: "POST",
2395
+ summary: "Create a submission package",
2396
+ description: "Create a submission package for an environment. Alpic reads the environment's live MCP server and prefills every field it can infer, so the response already carries the populated package. The environment must have a successful deployment and must not require authentication.",
2397
+ tags: ["submissions"],
2398
+ successDescription: "The created submission package, with its prefilled fields"
2399
+ }).errors({ NOT_FOUND: {} }).input(z.object({
2400
+ environmentId: z.string().describe("The ID of the environment to build the package from"),
2401
+ platform: platformSchema.describe(PLATFORM_DESCRIPTION)
2402
+ })).output(submissionSchema);
2403
+ const listSubmissionsContractV1 = base.route({
2404
+ path: "/v1/projects/{projectId}/submissions",
2405
+ method: "GET",
2406
+ summary: "List submission packages",
2407
+ description: "List the submission packages of a project, grouped by directory and most recently updated first, optionally narrowed to one environment or one directory",
2408
+ tags: ["submissions"],
2409
+ successDescription: "The list of submission packages"
2410
+ }).errors({ NOT_FOUND: {} }).input(z.object({
2411
+ projectId: z.string().describe("The ID of the project"),
2412
+ environmentId: z.string().optional().describe("Filter by environment ID"),
2413
+ platform: platformSchema.optional().describe(PLATFORM_DESCRIPTION)
2414
+ })).output(z.array(submissionSchema));
2415
+ const getSubmissionContractV1 = base.route({
2416
+ path: "/v1/submissions/{submissionId}",
2417
+ method: "GET",
2418
+ summary: "Get a submission package",
2419
+ description: "Get a submission package by ID, including its form data and the prefill it started from",
2420
+ tags: ["submissions"],
2421
+ successDescription: "The submission package"
2422
+ }).errors({ NOT_FOUND: {} }).input(z.object({ submissionId: submissionIdSchema })).output(submissionSchema);
2423
+ const updateSubmissionContractV1 = base.route({
2424
+ path: "/v1/submissions/{submissionId}",
2425
+ method: "PUT",
2426
+ summary: "Update a submission package",
2427
+ description: "Update the form data of a submission package. Only the fields you send are changed; the rest are left as they are. Unknown field names are rejected rather than ignored, so a typo fails the call. `platform` must match the package's own platform.",
2428
+ tags: ["submissions"],
2429
+ successDescription: "The updated submission package"
2430
+ }).errors({ NOT_FOUND: {} }).input(z.discriminatedUnion("platform", [z.object({
2431
+ submissionId: submissionIdSchema,
2432
+ platform: z.literal("claudeai").describe(PLATFORM_DESCRIPTION),
2433
+ formData: claudeSubmissionUpdateSchema
2434
+ }), z.object({
2435
+ submissionId: submissionIdSchema,
2436
+ platform: z.literal("chatgpt").describe(PLATFORM_DESCRIPTION),
2437
+ formData: chatgptSubmissionUpdateSchema
2438
+ })])).output(submissionSchema);
2202
2439
  const contract = {
2203
2440
  teams: {
2204
2441
  list: { v1: listTeamsContractV1 },
@@ -2224,6 +2461,7 @@ const contract = {
2224
2461
  environments: {
2225
2462
  create: { v1: createEnvironmentContractV1 },
2226
2463
  get: { v1: getEnvironmentContractV1 },
2464
+ delete: { v1: deleteEnvironmentContractV1 },
2227
2465
  deploy: { v1: deployEnvironmentContractV1 },
2228
2466
  getLogs: { v1: getLogsContractV1 },
2229
2467
  getLatestLogs: { v1: getLatestLogsContractV1 }
@@ -2253,6 +2491,12 @@ const contract = {
2253
2491
  beacon: {
2254
2492
  create: { v1: createBeaconContractV1 },
2255
2493
  get: { v1: getBeaconContractV1 }
2494
+ },
2495
+ submissions: {
2496
+ create: { v1: createSubmissionContractV1 },
2497
+ list: { v1: listSubmissionsContractV1 },
2498
+ get: { v1: getSubmissionContractV1 },
2499
+ update: { v1: updateSubmissionContractV1 }
2256
2500
  }
2257
2501
  };
2258
2502
  const { uploadArtifact: _discard, ...deploymentsForDocs } = contract.deployments;
@@ -2260,5 +2504,26 @@ const contractForDocs = {
2260
2504
  ...contract,
2261
2505
  deployments: deploymentsForDocs
2262
2506
  };
2507
+ /** Shared by the served `openapi.json` and the snapshot test that guards it, so the two cannot drift. */
2508
+ const OPENAPI_DOC_OPTIONS = {
2509
+ info: {
2510
+ title: "Alpic API",
2511
+ version: "1.0.0"
2512
+ },
2513
+ servers: [{ url: "https://api.alpic.ai" }],
2514
+ security: [{ bearerAuth: [] }],
2515
+ components: { securitySchemes: { bearerAuth: {
2516
+ type: "http",
2517
+ description: "Bearer token for authentication. Use an API key from the API Keys page in team settings, or an OAuth access token.",
2518
+ scheme: "bearer"
2519
+ } } },
2520
+ commonSchemas: {
2521
+ Submission: { schema: submissionSchema },
2522
+ ClaudeSubmissionFormData: { schema: claudeSubmissionDraftSchema },
2523
+ ChatgptSubmissionFormData: { schema: chatgptSubmissionDraftSchema },
2524
+ ClaudeSubmissionFormDataUpdate: { schema: claudeSubmissionUpdateSchema },
2525
+ ChatgptSubmissionFormDataUpdate: { schema: chatgptSubmissionUpdateSchema }
2526
+ }
2527
+ };
2263
2528
  //#endregion
2264
- export { AUTH_SCOPE_ANY, AUTH_SCOPE_USER, INTENT_CATEGORY_COLORS, PLATFORM_LABELS, buildSettingsSchema, contract, contractForDocs, createEnvironmentContractV1, deploymentStatusSchema, environmentVariableSchema, environmentVariablesSchema, intentCategoryColorSchema, playgroundExamplePromptSchema, playgroundHeaderSchema, runtimeSchema, serverFieldsSchema, transportSchema, updateEnvironmentVariableSchema };
2529
+ export { AI_PLATFORMS, AUTH_SCOPE_ANY, AUTH_SCOPE_USER, INTENT_CATEGORY_COLORS, OPENAPI_DOC_OPTIONS, PLATFORM_LABELS, buildSettingsSchema, chatgptSubmissionUpdateSchema, claudeSubmissionUpdateSchema, contract, contractForDocs, createEnvironmentContractV1, deploymentStatusSchema, environmentVariableSchema, environmentVariablesSchema, intentCategoryColorSchema, playgroundExamplePromptSchema, playgroundHeaderSchema, runtimeSchema, serverFieldsSchema, transportSchema, updateEnvironmentVariableSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpic-ai/api",
3
- "version": "0.0.0-dev.gda044d0",
3
+ "version": "0.0.0-dev.gda47a5d",
4
4
  "description": "Contract for the Alpic API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -33,20 +33,20 @@
33
33
  "author": "Alpic",
34
34
  "license": "ISC",
35
35
  "dependencies": {
36
- "@orpc/contract": "^1.15.0",
36
+ "@orpc/contract": "^1.15.4",
37
37
  "ms": "^2.1.3",
38
- "zod": "^4.4.3"
38
+ "zod": "^4.5.4"
39
39
  },
40
40
  "devDependencies": {
41
- "@orpc/openapi": "^1.15.0",
42
- "@orpc/zod": "^1.15.0",
41
+ "@alpic-ai/domains": "0.0.0",
42
+ "@orpc/openapi": "^1.15.4",
43
+ "@orpc/zod": "^1.15.4",
43
44
  "@total-typescript/tsconfig": "^1.0.4",
44
45
  "@types/ms": "^2.1.0",
45
46
  "shx": "^0.4.0",
46
- "tsdown": "^0.22.14",
47
+ "tsdown": "^0.23.0",
47
48
  "typescript": "^6.0.3",
48
- "vitest": "^4.1.10",
49
- "@alpic-ai/domains": "0.0.0"
49
+ "vitest": "^5.0.3"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "shx rm -rf dist && tsdown",