@siglume/api-sdk 0.10.6 → 0.10.8

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.js CHANGED
@@ -1537,6 +1537,56 @@ var init_operations = __esm({
1537
1537
  });
1538
1538
 
1539
1539
  // src/client.ts
1540
+ function validateManifestPersistenceContract(payload) {
1541
+ const vertical = String(payload.store_vertical ?? "").trim().toLowerCase();
1542
+ const persistence = payload.persistence;
1543
+ if (persistence === void 0 || persistence === null) {
1544
+ return;
1545
+ }
1546
+ if (!isRecord2(persistence)) {
1547
+ throw new SiglumeClientError("AppManifest.persistence must be an object.");
1548
+ }
1549
+ const mode = String(persistence.mode ?? (vertical === "game" ? "platform" : "none")).trim().toLowerCase();
1550
+ if (!["none", "local", "platform", "developer_server"].includes(mode)) {
1551
+ throw new SiglumeClientError(
1552
+ "AppManifest.persistence.mode must be one of: none, local, platform, developer_server."
1553
+ );
1554
+ }
1555
+ const schema = persistence.save_data_schema;
1556
+ if (vertical === "game" && mode !== "none" && schema === void 0) {
1557
+ throw new SiglumeClientError(
1558
+ "AppManifest.persistence.save_data_schema is required when store_vertical='game' and persistence.mode is not 'none'."
1559
+ );
1560
+ }
1561
+ if (schema !== void 0) {
1562
+ validateSaveDataSchema(schema, "AppManifest.persistence.save_data_schema");
1563
+ }
1564
+ }
1565
+ function validateSaveDataSchema(schema, fieldName) {
1566
+ if (!isRecord2(schema)) {
1567
+ throw new SiglumeClientError(`${fieldName} must be a JSON Schema object.`);
1568
+ }
1569
+ const schemaSize = new TextEncoder().encode(JSON.stringify(schema)).length;
1570
+ if (schemaSize > 8192) {
1571
+ throw new SiglumeClientError(`${fieldName} must be at most 8192 bytes.`);
1572
+ }
1573
+ if (schema.type !== "object") {
1574
+ throw new SiglumeClientError(`${fieldName}.type must be 'object'.`);
1575
+ }
1576
+ const properties = schema.properties;
1577
+ if (!isRecord2(properties) || Object.keys(properties).length === 0) {
1578
+ throw new SiglumeClientError(`${fieldName}.properties must be a non-empty object.`);
1579
+ }
1580
+ if (schema.required !== void 0) {
1581
+ if (!Array.isArray(schema.required) || !schema.required.every((item) => typeof item === "string")) {
1582
+ throw new SiglumeClientError(`${fieldName}.required must be an array of strings when provided.`);
1583
+ }
1584
+ const missing = schema.required.filter((item) => !(item in properties));
1585
+ if (missing.length > 0) {
1586
+ throw new SiglumeClientError(`${fieldName}.required references undefined properties: ${missing.join(", ")}.`);
1587
+ }
1588
+ }
1589
+ }
1540
1590
  function buildToolManualQualityReport(payload) {
1541
1591
  const qualityBlock = isRecord2(payload.quality) ? payload.quality : payload;
1542
1592
  const issues = [];
@@ -1611,6 +1661,8 @@ function buildUrl(baseUrl, path, params) {
1611
1661
  return url.toString();
1612
1662
  }
1613
1663
  function parseListing(data) {
1664
+ const metadata = isRecord2(data.metadata) ? data.metadata : {};
1665
+ const persistence = isRecord2(data.persistence) ? data.persistence : isRecord2(metadata.persistence) ? metadata.persistence : {};
1614
1666
  return {
1615
1667
  listing_id: String(data.listing_id ?? data.id ?? ""),
1616
1668
  capability_key: String(data.capability_key ?? ""),
@@ -1624,6 +1676,8 @@ function parseListing(data) {
1624
1676
  price_model: stringOrNull2(data.price_model),
1625
1677
  price_value_minor: Number(data.price_value_minor ?? 0),
1626
1678
  currency: String(data.currency ?? "USD"),
1679
+ allow_free_trial: Boolean(data.allow_free_trial ?? false),
1680
+ free_trial_duration_days: Number(data.free_trial_duration_days ?? 30),
1627
1681
  short_description: stringOrNull2(data.short_description),
1628
1682
  description: stringOrNull2(data.description),
1629
1683
  docs_url: stringOrNull2(data.docs_url),
@@ -1631,14 +1685,59 @@ function parseListing(data) {
1631
1685
  seller_display_name: stringOrNull2(data.seller_display_name),
1632
1686
  seller_homepage_url: stringOrNull2(data.seller_homepage_url),
1633
1687
  seller_social_url: stringOrNull2(data.seller_social_url),
1688
+ publisher_type: stringOrNull2(data.publisher_type),
1689
+ publisher_company_id: stringOrNull2(data.publisher_company_id),
1690
+ company_id: stringOrNull2(data.company_id),
1691
+ company_name: stringOrNull2(data.company_name),
1692
+ company_publish_status: stringOrNull2(data.company_publish_status),
1693
+ company_terms_version: stringOrNull2(data.company_terms_version),
1634
1694
  review_status: stringOrNull2(data.review_status),
1635
1695
  review_note: stringOrNull2(data.review_note),
1636
1696
  submission_blockers: Array.isArray(data.submission_blockers) ? data.submission_blockers.filter((item) => typeof item === "string") : [],
1697
+ persistence: { ...persistence },
1637
1698
  created_at: stringOrNull2(data.created_at),
1638
1699
  updated_at: stringOrNull2(data.updated_at),
1639
1700
  raw: { ...data }
1640
1701
  };
1641
1702
  }
1703
+ function parseCompanyPublisher(data) {
1704
+ const wallets = Array.isArray(data.settlement_wallets) ? data.settlement_wallets.filter((item) => isRecord2(item)) : [];
1705
+ return {
1706
+ company_id: String(data.company_id ?? data.id ?? ""),
1707
+ name: String(data.name ?? ""),
1708
+ status: String(data.status ?? ""),
1709
+ description: stringOrNull2(data.description),
1710
+ is_founder: Boolean(data.is_founder ?? false),
1711
+ membership_role: stringOrNull2(data.membership_role),
1712
+ membership_status: stringOrNull2(data.membership_status),
1713
+ can_publish: Boolean(data.can_publish ?? true),
1714
+ can_approve: Boolean(data.can_approve ?? false),
1715
+ approval_required: Boolean(data.approval_required ?? false),
1716
+ paid_listing_allowed: Boolean(data.paid_listing_allowed ?? false),
1717
+ disabled_reasons: Array.isArray(data.disabled_reasons) ? data.disabled_reasons.filter((item) => typeof item === "string") : [],
1718
+ company_terms_version: stringOrNull2(data.company_terms_version),
1719
+ active_listing_count: Number(data.active_listing_count ?? 0),
1720
+ pending_approval_count: Number(data.pending_approval_count ?? 0),
1721
+ settlement_wallet_ready: Boolean(data.settlement_wallet_ready ?? false),
1722
+ settlement_wallets: wallets.map((item) => ({ ...item })),
1723
+ raw: { ...data }
1724
+ };
1725
+ }
1726
+ function parseCapabilitySaveState(data) {
1727
+ return {
1728
+ capability_key: String(data.capability_key ?? ""),
1729
+ save_key: String(data.save_key ?? ""),
1730
+ schema_version: String(data.schema_version ?? "1"),
1731
+ revision: Number(data.revision ?? 0),
1732
+ payload: toRecord2(data.payload),
1733
+ metadata: toRecord2(data.metadata),
1734
+ checksum: stringOrNull2(data.checksum),
1735
+ updated_at: stringOrNull2(data.updated_at),
1736
+ created_at: stringOrNull2(data.created_at),
1737
+ exists: Boolean(data.exists ?? false),
1738
+ raw: { ...data }
1739
+ };
1740
+ }
1642
1741
  function parseBundleMember(data) {
1643
1742
  return {
1644
1743
  capability_listing_id: String(data.capability_listing_id ?? ""),
@@ -2818,17 +2917,23 @@ var init_client = __esm({
2818
2917
  "support_contact",
2819
2918
  "seller_homepage_url",
2820
2919
  "seller_social_url",
2920
+ "publisher_type",
2921
+ "company_id",
2922
+ "publisher_company_id",
2821
2923
  "store_vertical",
2822
2924
  "jurisdiction",
2823
2925
  "price_model",
2824
2926
  "price_value_minor",
2825
2927
  "currency",
2928
+ "allow_free_trial",
2929
+ "free_trial_duration_days",
2826
2930
  "permission_class",
2827
2931
  "approval_mode",
2828
2932
  "dry_run_supported",
2829
2933
  "required_connected_accounts",
2830
2934
  "permission_scopes",
2831
- "compatibility_tags"
2935
+ "compatibility_tags",
2936
+ "persistence"
2832
2937
  ]) {
2833
2938
  const value = manifestPayload[fieldName];
2834
2939
  if (value !== void 0 && value !== null) {
@@ -2850,6 +2955,44 @@ var init_client = __esm({
2850
2955
  throw new SiglumeClientError(`AppManifest.currency must be 'USD' or 'JPY'. Got ${String(payload.currency)}.`);
2851
2956
  }
2852
2957
  payload.currency = currency;
2958
+ if (payload.allow_free_trial === void 0 || payload.allow_free_trial === null) {
2959
+ throw new SiglumeClientError(
2960
+ "AppManifest.allow_free_trial is required. Pass true to offer a Plus/Pro buyer free trial or false to disable trials."
2961
+ );
2962
+ }
2963
+ if (Boolean(payload.allow_free_trial)) {
2964
+ const duration = payload.free_trial_duration_days ?? 30;
2965
+ if (typeof duration !== "number" || !Number.isInteger(duration)) {
2966
+ throw new SiglumeClientError(
2967
+ "AppManifest.free_trial_duration_days must be an integer when allow_free_trial=true."
2968
+ );
2969
+ }
2970
+ if (duration < 1 || duration > 90) {
2971
+ throw new SiglumeClientError(
2972
+ `AppManifest.free_trial_duration_days must be between 1 and 90 when allow_free_trial=true, got: ${duration}.`
2973
+ );
2974
+ }
2975
+ }
2976
+ const explicitPublisherType = payload.publisher_type !== void 0 && payload.publisher_type !== null;
2977
+ const companyId = String(payload.company_id ?? "").trim() || String(payload.publisher_company_id ?? "").trim();
2978
+ const publisherType = String(payload.publisher_type ?? "user").trim().toLowerCase();
2979
+ if (publisherType !== "user" && publisherType !== "company") {
2980
+ throw new SiglumeClientError("AppManifest.publisher_type must be 'user' or 'company'.");
2981
+ }
2982
+ if (publisherType === "company" && !companyId) {
2983
+ throw new SiglumeClientError("AppManifest.company_id is required when publisher_type='company'.");
2984
+ }
2985
+ if (publisherType === "user" && companyId) {
2986
+ throw new SiglumeClientError("AppManifest.company_id cannot be combined with publisher_type='user'.");
2987
+ }
2988
+ if (explicitPublisherType || companyId) {
2989
+ payload.publisher_type = publisherType;
2990
+ }
2991
+ if (companyId) {
2992
+ payload.company_id = companyId;
2993
+ payload.publisher_company_id = companyId;
2994
+ }
2995
+ validateManifestPersistenceContract(payload);
2853
2996
  if (payload.manifest && typeof payload.manifest === "object") {
2854
2997
  delete payload.manifest.version;
2855
2998
  }
@@ -2957,6 +3100,45 @@ var init_client = __esm({
2957
3100
  const [data] = await this.request("GET", `/market/capabilities/${listing_id}`);
2958
3101
  return parseListing(data);
2959
3102
  }
3103
+ async list_company_publishers() {
3104
+ const [data] = await this.request("GET", "/market/company-publishers");
3105
+ return Array.isArray(data.items) ? data.items.filter((item) => isRecord2(item)).map(parseCompanyPublisher) : [];
3106
+ }
3107
+ async request_company_publish_approval(listing_id, note) {
3108
+ const [data] = await this.request("POST", `/market/capabilities/${listing_id}/company-publish-approval`, {
3109
+ json_body: note ? { note } : {}
3110
+ });
3111
+ return parseListing(data);
3112
+ }
3113
+ async decide_company_publish_approval(listing_id, options) {
3114
+ const [data] = await this.request("POST", `/market/capabilities/${listing_id}/company-publish-approval/decision`, {
3115
+ json_body: {
3116
+ decision: options.decision,
3117
+ ...options.reason ? { reason: options.reason } : {}
3118
+ }
3119
+ });
3120
+ return parseListing(data);
3121
+ }
3122
+ async get_capability_state(capability_key, save_key = "default") {
3123
+ const [data] = await this.request("GET", `/market/capability-state/${capability_key}/${save_key}`);
3124
+ return parseCapabilitySaveState(data);
3125
+ }
3126
+ async put_capability_state(capability_key, save_key = "default", payload = {}, options = {}) {
3127
+ const body = {
3128
+ payload: toRecord2(payload),
3129
+ schema_version: options.schema_version ?? "1",
3130
+ metadata: toRecord2(options.metadata)
3131
+ };
3132
+ if (options.expected_revision !== void 0 && options.expected_revision !== null) {
3133
+ body.expected_revision = Math.trunc(options.expected_revision);
3134
+ }
3135
+ const [data] = await this.request("PUT", `/market/capability-state/${capability_key}/${save_key}`, { json_body: body });
3136
+ return parseCapabilitySaveState(data);
3137
+ }
3138
+ async delete_capability_state(capability_key, save_key = "default") {
3139
+ const [data] = await this.request("DELETE", `/market/capability-state/${capability_key}/${save_key}`);
3140
+ return parseCapabilitySaveState(data);
3141
+ }
2960
3142
  // ----- Capability bundles (v0.7 track 2) ---------------------------------
2961
3143
  async list_bundles(options = {}) {
2962
3144
  const params = {
@@ -5248,6 +5430,55 @@ var SiglumeBuyerClient = class {
5248
5430
  }
5249
5431
  };
5250
5432
  }
5433
+ async start_trial(options) {
5434
+ const listing = await this.get_listing(options.capability_key);
5435
+ const [data, meta] = await this.request("POST", `/market/capabilities/${listing.listing_id}/start-trial`, {
5436
+ json_body: {}
5437
+ });
5438
+ const accessGrant = parseAccessGrant2(toRecord2(data.access_grant));
5439
+ if (!accessGrant.access_grant_id) {
5440
+ const purchaseStatus = String(data.purchase_status ?? "trial_started");
5441
+ throw new SiglumeExperimentalError(
5442
+ `Trial started with status '${purchaseStatus}' but did not return an access grant. Buyer-side trial flows are still experimental on the public API.`
5443
+ );
5444
+ }
5445
+ const targetAgentId = resolveAgentId(options.agent_id, this.default_agent_id);
5446
+ const shouldBind = options.bind_agent ?? Boolean(targetAgentId);
5447
+ let binding = null;
5448
+ let trace_id = meta.trace_id ?? void 0;
5449
+ let request_id = meta.request_id ?? void 0;
5450
+ if (shouldBind) {
5451
+ if (!targetAgentId) {
5452
+ throw new SiglumeClientError("agent_id is required to bind a trial access grant.");
5453
+ }
5454
+ const grantBinding = await this.client.bind_agent_to_grant(accessGrant.access_grant_id, {
5455
+ agent_id: targetAgentId,
5456
+ binding_status: options.binding_status ?? "active"
5457
+ });
5458
+ binding = grantBinding.binding;
5459
+ trace_id = grantBinding.trace_id ?? trace_id;
5460
+ request_id = grantBinding.request_id ?? request_id;
5461
+ }
5462
+ return {
5463
+ access_grant_id: accessGrant.access_grant_id,
5464
+ capability_listing_id: accessGrant.capability_listing_id ?? listing.listing_id,
5465
+ capability_key: listing.capability_key,
5466
+ purchase_status: String(data.purchase_status ?? "trial_started"),
5467
+ grant_status: accessGrant.grant_status,
5468
+ agent_id: binding?.agent_id ?? targetAgentId ?? null,
5469
+ binding_id: binding?.binding_id ?? null,
5470
+ binding_status: binding?.binding_status ?? null,
5471
+ access_grant: accessGrant,
5472
+ binding,
5473
+ trace_id,
5474
+ request_id,
5475
+ raw: { trial: { ...data }, binding }
5476
+ };
5477
+ }
5478
+ async get_trial_quota() {
5479
+ const [data] = await this.request("GET", "/market/me/trial-quota");
5480
+ return { ...data };
5481
+ }
5251
5482
  async invoke(options) {
5252
5483
  if (!this.allow_internal_execute) {
5253
5484
  throw new SiglumeExperimentalError(
@@ -5975,10 +6206,14 @@ function appendValueChange(changes, emittedKeys, level, key, oldValue, newValue,
5975
6206
  }
5976
6207
  function normalizeManifest(value) {
5977
6208
  const payload = coerceMapping(value, "manifest");
6209
+ const rawDuration = payload.free_trial_duration_days;
6210
+ const duration = rawDuration === void 0 || rawDuration === null ? 30 : Number(rawDuration);
5978
6211
  return {
5979
6212
  ...payload,
5980
6213
  price_model: payload.price_model ?? "free",
5981
6214
  currency: payload.currency ?? "USD",
6215
+ allow_free_trial: Boolean(payload.allow_free_trial ?? false),
6216
+ free_trial_duration_days: Number.isFinite(duration) ? Math.trunc(duration) : 30,
5982
6217
  // AppManifest defaults permission_class to "read-only" (hyphen form,
5983
6218
  // PermissionClass.READ_ONLY). Without this default, a legacy / minimal
5984
6219
  // manifest without permission_class compared against an upgraded one
@@ -6390,6 +6625,12 @@ var ListingCurrency = {
6390
6625
  USD: "USD",
6391
6626
  JPY: "JPY"
6392
6627
  };
6628
+ var PersistenceMode = {
6629
+ NONE: "none",
6630
+ LOCAL: "local",
6631
+ PLATFORM: "platform",
6632
+ DEVELOPER_SERVER: "developer_server"
6633
+ };
6393
6634
  var ToolManualPermissionClass = {
6394
6635
  READ_ONLY: "read_only",
6395
6636
  ACTION: "action",
@@ -8714,6 +8955,7 @@ export {
8714
8955
  MeterClient,
8715
8956
  OpenAIProvider,
8716
8957
  PermissionClass,
8958
+ PersistenceMode,
8717
8959
  PriceModel,
8718
8960
  RecordMode,
8719
8961
  Recorder,