@tinkerlandai/longplay-sdk 0.10.23 → 0.10.25-rc.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.
- package/CHANGELOG.md +1 -0
- package/README.md +79 -0
- package/README.zh-CN.md +31 -0
- package/dist/{ai-usage-WFwbPTiq.d.ts → ai-usage-B6RepnmH.d.ts} +1 -1
- package/dist/{api-rZ_QoNQi.d.ts → api-C9P338XT.d.ts} +1547 -6
- package/dist/{chunk-5SHVM4AF.js → chunk-2KI63SPJ.js} +2 -2
- package/dist/chunk-34I23EKZ.js +1 -0
- package/dist/{chunk-KZ63ANBP.js → chunk-ASQ6USAC.js} +1 -1
- package/dist/chunk-BYLU5UY5.js +6 -0
- package/dist/chunk-EEHL2BP6.js +1 -0
- package/dist/chunk-FSQ75ZCZ.js +1 -0
- package/dist/chunk-GYHN5L6I.js +1 -0
- package/dist/chunk-KFU36IHL.js +1 -0
- package/dist/{chunk-7MF2YMN4.js → chunk-LLS7GT4C.js} +1 -1
- package/dist/chunk-M5XMYNVW.js +1 -0
- package/dist/{chunk-HDVLCRC6.js → chunk-MHEYMXGZ.js} +2 -2
- package/dist/{chunk-XFO4FBFG.js → chunk-NHQBONYJ.js} +1 -1
- package/dist/chunk-RKREEPCT.js +1 -0
- package/dist/chunk-RN3WAJ36.js +1 -0
- package/dist/{chunk-QVGTHPWT.js → chunk-SJNF6JDJ.js} +1 -1
- package/dist/{chunk-EZLLTGV3.js → chunk-T52ZHJ5D.js} +1 -1
- package/dist/{chunk-PKLLZXNM.js → chunk-ZGXRFGOK.js} +1 -1
- package/dist/chunk-ZRAKYJZB.js +1 -0
- package/dist/chunk-ZX2RWS3T.js +1 -0
- package/dist/content-H7TUH23I.js +1 -0
- package/dist/{coupon-Btz_KFKp.d.ts → coupon-DyKA-BRG.d.ts} +8 -0
- package/dist/funnel-host-purchase-4SH4YYZ5.js +1 -0
- package/dist/{funnel-local-client-BYdKGnMb.d.ts → funnel-local-client-CSA9XoC4.d.ts} +3270 -32
- package/dist/{funnel-node-evaluation-eLMEZIFz.d.ts → funnel-node-evaluation-Cg-4tcAs.d.ts} +88 -0
- package/dist/funnel-process-client-RXgS2i-R.d.ts +23184 -0
- package/dist/funnel-runtime-host-E3GKPRXF.js +1 -0
- package/dist/index.d.ts +1219 -31
- package/dist/index.js +1 -1
- package/dist/native-shell.js +1 -1
- package/dist/openrouter.d.ts +2 -2
- package/dist/openrouter.js +1 -1
- package/dist/page.js +1 -1
- package/dist/paywall-ENKCZXDE.js +1 -0
- package/dist/popup.d.ts +3 -3
- package/dist/popup.js +1 -1
- package/dist/{presentation-loading-Ctk1djAi.d.ts → presentation-loading-D0A9G_kT.d.ts} +16 -2
- package/dist/react-native.d.ts +6 -6
- package/dist/react-native.js +1 -1
- package/dist/screen-renderer-WOMWOEYL.js +1 -0
- package/dist/server.d.ts +2402 -17
- package/dist/server.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3J24TUO7.js +0 -1
- package/dist/chunk-6DTGBDYG.js +0 -1
- package/dist/chunk-DUZ2E7BK.js +0 -1
- package/dist/chunk-IIYIIXNB.js +0 -1
- package/dist/chunk-KRQESEG2.js +0 -6
- package/dist/chunk-WMIDEJTZ.js +0 -1
- package/dist/chunk-YAVWELIV.js +0 -1
- package/dist/content-FM52HLRX.js +0 -1
- package/dist/funnel-process-client-C87pmLC9.d.ts +0 -64499
- package/dist/funnel-runtime-host-MZKLVLC4.js +0 -1
- package/dist/paywall-JL4SXFXT.js +0 -1
- package/dist/screen-renderer-TEVGVUT5.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
- JavaScript, React Native, iOS and Android no longer reopen a merchant Checkout after payment has succeeded or when payment is not required while fulfillment is still pending. They continue observing the original purchase until its result is accepted.
|
|
6
6
|
- Show quote preparation and recoverable quote failures inside the Paywall, keep the original error callback and retry, and avoid turning a quote failure into a Funnel presentation failure. An unavailable or unconfigured capability does not offer a futile retry. Wire protocol remains `0.10`.
|
|
7
|
+
- Align the Python and Go package versions at `0.10.23`; their APIs and behavior are unchanged from `0.10.22`.
|
|
7
8
|
|
|
8
9
|
## 0.10.22
|
|
9
10
|
|
package/README.md
CHANGED
|
@@ -188,6 +188,70 @@ When a customer dismisses a Funnel Paywall, the Web host keeps the dialog open u
|
|
|
188
188
|
|
|
189
189
|
Each Funnel chooses local or remote evaluation. `createFunnelDecisionClient` supports `configuration()`, `features()`, submission, and result reads. `createFeatureClient` identifies configuration by `generation`. Downloaded local rules are visible to clients; use remote evaluation and verified business facts for sensitive decisions.
|
|
190
190
|
|
|
191
|
+
### Managed Funnel purchase recovery (source API, not yet published)
|
|
192
|
+
|
|
193
|
+
`createFunnelPurchaseClient` adds durable purchase ownership to the existing `funnel-run/1` Controller and Host. It requires the full backend-issued Customer Session in the shared `session`; it does not use merchant user IDs as proof. The browser default uses Web Locks and localStorage revision CAS, partitioned by API origin, App/environment and Customer. A non-browser host supplies `FunnelPurchaseStorage` with atomic compare-and-swap semantics. Neither adapter stores Customer access/refresh tokens or Run Tokens. Start inputs and purchase references are durable business data.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import {
|
|
197
|
+
createLongplay,
|
|
198
|
+
createFunnelPurchaseClient,
|
|
199
|
+
showFunnelPurchase,
|
|
200
|
+
} from "@tinkerlandai/longplay-sdk";
|
|
201
|
+
|
|
202
|
+
const customer = createLongplay({ baseUrl, scope });
|
|
203
|
+
customer.identify(customerSession); // Issued by your backend; memory only.
|
|
204
|
+
const purchase = createFunnelPurchaseClient({
|
|
205
|
+
baseUrl,
|
|
206
|
+
scope,
|
|
207
|
+
session: customer.session,
|
|
208
|
+
executionPolicy: { allowed: ["merchant", "record_only"] },
|
|
209
|
+
onRecovery: renderPurchaseRecovery, // status, mode, actions, purchases, confirmation
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Call on the admitted merchant purchase entry. Concurrent opens share one host.
|
|
213
|
+
await showFunnelPurchase(container, {
|
|
214
|
+
client: purchase,
|
|
215
|
+
start: { funnelId, locale: "en", parameters: merchantParameters },
|
|
216
|
+
resolveOfferId: (selection, original) =>
|
|
217
|
+
chooseMerchantOffer({
|
|
218
|
+
selection,
|
|
219
|
+
requestId: original.requestId,
|
|
220
|
+
parameters: original.parameters,
|
|
221
|
+
}),
|
|
222
|
+
onCheckoutUrl: openAllowedCheckout,
|
|
223
|
+
onOpenUrl: openAllowedBusinessPage,
|
|
224
|
+
onComplete: refreshSubscriptionAndCredits,
|
|
225
|
+
onPresentationState: updateLoading,
|
|
226
|
+
onDismiss: releaseMerchantPresentation,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// On return, read the original attempt; this creates no replacement Run.
|
|
230
|
+
await purchase.refresh();
|
|
231
|
+
// Bind these to explicit recovery-page clicks, using recovery.actions.
|
|
232
|
+
const recoveryActions = {
|
|
233
|
+
refresh: () => purchase.refresh(),
|
|
234
|
+
confirm: () => purchase.confirm(),
|
|
235
|
+
retry: () => purchase.retry(),
|
|
236
|
+
continue_checkout: () => purchase.continueCheckout(openAllowedCheckout),
|
|
237
|
+
};
|
|
238
|
+
renderRecoveryButtons(purchase.recovery.actions, recoveryActions);
|
|
239
|
+
// On unmount/logout. Changing the shared identity also stops the old consumer.
|
|
240
|
+
purchase.destroy();
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`start()` persists the complete original request before dispatch. An unresolved attempt retains its request ID, locale, parameters and execution policy even if later calls supply different inputs; another Funnel is refused. `refresh()` allocates nothing. The Controller's existing command journal shares the purchase CAS row, so unknown confirmation/Close results retain their original identities. A new attempt is permitted only after the original Run is terminal, its commands are settled and all retained purchases have server-confirmed outcomes. An untouched quote can be cancelled through the existing Customer API after confirmed Run termination. Clearing browser storage cannot prove an unknown purchase absent and is not a fallback procedure.
|
|
244
|
+
|
|
245
|
+
After `start()` or `refresh()`, `purchase.attempt` supplies a detached, read-only snapshot of the retained `requestId`, `funnelId`, `locale` and `parameters`, including when the Start result is unknown. It is `null` before recovery loads an attempt. `resolveOfferId(selection, original)` receives this same original context, so merchant coupon claims can reuse the original request identity after a reload or a new Customer session. Changing a returned snapshot cannot change the durable input. Keep any merchant choices needed on recovery in the original `parameters`; the SDK does not reconstruct them from current configuration. A dismissed presentation, changed identity or superseded attempt rejects a late offer result before quoting.
|
|
246
|
+
|
|
247
|
+
`showFunnelPurchase` uses the existing Paywall's `after_confirmation` navigation policy. An active explicit confirmation can open its Checkout once, including when that original URL arrives on a later observation. Reopening, restoring, polling or retrying a recovery read never automatically navigates: a verified unfinished Checkout offers **Continue checkout**. That action reads the original Operation again before navigation; a paid, expired or uncertain result is observed without opening the old URL. Recovery pages can also call `purchase.continueCheckout(openAllowedCheckout)`. Neither path creates a new quote or confirms another purchase. Standalone Paywalls and low-level Funnel hosts retain their existing `automatic` default unless explicitly configured otherwise.
|
|
248
|
+
|
|
249
|
+
`mode` distinguishes `run`, `operation`, `blocked` and `idle`; `status` is `ready`, `waiting_result`, `checkout`, `fulfillment`, `recording`, `complete`, `blocked` or `idle`. `actions` names allowed SDK actions. `confirmation` supplies the original quote when Operation-only confirmation is possible. The `purchases` entries reuse `PaywallRecovery`. Original purchase reads use `recover_purchase` with the retained Run/Receipt/Operation reference and server `canReselect` decision. Confirmation uses the legal original Customer, original Operation ID and existing subscriptions API; an outstanding Run command prevents a separate Operation confirmation. A lost Operation-confirmation reply retains its original Operation command, and reads settle it from server acceptance. Commercial completion in Operation-only mode does not silently settle an unknown Run/Close command or authorize a replacement attempt.
|
|
250
|
+
|
|
251
|
+
`merchant` permits merchant-provider quotes; `record_only` permits Stripe quotes executed by the merchant; `indiana` permits platform execution; `native` permits Apple/Google execution. The original and current policies are intersected. The Controller checks the original quote before confirmation, including Host automatic confirmation and log retry; a policy refusal sends no commercial command. Checkout URLs and external business destinations remain merchant policy. The existing Host owns Run observation and loading/ready/dismissal; one recovery observer handles Operation-only or post-termination work. `onDismiss` releases presentation ownership before merchant code runs, so immediate reopening does not wait on a merchant lock.
|
|
252
|
+
|
|
253
|
+
The matching [Customer-session recovery protocol](../../docs/funnel-storage-design.md#customer-session-recovery-protocol) uses the current original Customer's access token, including a new login session, without issuing another Run Token. For an unknown Start, `refresh()` only performs `recover_start` with `intent: "lookup"`; a missing result remains blocked. Initial `start()` and explicit `retry()` use `intent: "resume"` with the retained original ID and full input. Known Runs use `recover_run`; exact retained commands use `settle_command`, and the same Controller continues through `run_command`. Operation-only recovery retains original references and unresolved commands, and reads `recover_purchase` for the existing SQL reselection decision. A false decision is preserved even when the Operation reports failure or cancellation; commercial completion does not mark recovery complete while an original command remains unsettled. A missing receipt never authorizes replacement. This unpublished source API requires matching GOP and SQL functions. Offline simulated results do not establish deployment, native RLS, concurrent SQL locking or Sandbox acceptance.
|
|
254
|
+
|
|
191
255
|
### Guest entry and same-Run login
|
|
192
256
|
|
|
193
257
|
Publish a Version with `executionContract: "funnel-process/1"` and use the managed process entry points. Existing Versions and `/funnels` retain their execution contract. This addition uses wire protocol `0.10` and requires the matching runtime and SQL deployment.
|
|
@@ -517,6 +581,21 @@ export async function showBanner(
|
|
|
517
581
|
|
|
518
582
|
Provide every declared action handler. `onContinue` uses `intent.requestId` as its backend idempotency key; `retryAction()` reuses that intent after a failure. Call `destroy()` on unmount, sign-out or account change. The host renders content and emits intents; your backend still authorizes and executes business actions.
|
|
519
583
|
|
|
584
|
+
For live display values, explicitly list the declared inputs that may change. Other inputs stay frozen for that presentation:
|
|
585
|
+
|
|
586
|
+
```ts
|
|
587
|
+
const host = await mountContent(container, {
|
|
588
|
+
content, // Its contract declares balance and purchaseTerms.
|
|
589
|
+
inputs: { balance: 100, purchaseTerms: originalTerms },
|
|
590
|
+
mutableInputs: ["balance"],
|
|
591
|
+
actions: { continue: onContinue },
|
|
592
|
+
onError: console.error,
|
|
593
|
+
});
|
|
594
|
+
host.updateInputs({ balance: 90 });
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
`updateInputs()` validates the complete merged input before applying a patch and throws if a changed field is undeclared, frozen or invalid. Empty and unchanged patches do nothing. It preserves the renderer, local selection, entered answers, focus and timers; a pending action keeps its original intent and retry identity. `prepareContent` supports the same API. Changing the Customer, scope, content version or purchase terms requires destroying the old presentation and preparing a new one after reconciling any pending business operation. Display input updates do not authorize a purchase or settle an operation.
|
|
598
|
+
|
|
520
599
|
To remove module loading, document preparation and iframe startup from the opening click, resolve the current Customer's content earlier and prepare it explicitly:
|
|
521
600
|
|
|
522
601
|
```ts
|
package/README.zh-CN.md
CHANGED
|
@@ -200,6 +200,22 @@ Web 宿主可以用独立的第一方安装 cookie 保留信号。清除 cookie
|
|
|
200
200
|
|
|
201
201
|
Local/Remote 求值策略由每个 Funnel 决定。`createFunnelDecisionClient` 支持当前 `configuration()`、`features()`、提交和结果读取;`createFeatureClient` 以 `generation` 标识配置。Local 下载的规则对客户端可见;敏感决策应使用 Remote 和可信业务事实。
|
|
202
202
|
|
|
203
|
+
### Funnel 购买托管恢复(源码 API,尚未发布)
|
|
204
|
+
|
|
205
|
+
使用 `createFunnelPurchaseClient({ baseUrl, scope, session: customer.session, executionPolicy: { allowed: ["merchant", "record_only"] }, onRecovery })`,再通过 `showFunnelPurchase(container, { client: purchase, start: { funnelId, locale, parameters }, ...页面回调 })` 打开或恢复。`session` 必须持有后端签发的完整 Customer Session;商户用户 ID 不能代替身份证明。完整公开用法及协议边界见[英文 API 说明](README.md#managed-funnel-purchase-recovery-source-api-not-yet-published)。
|
|
206
|
+
|
|
207
|
+
SDK 在首次派发前保存原 Start 请求 ID 和完整输入;同一未决尝试忽略后续输入变化,拒绝换 Funnel。浏览器默认复用 Web Locks 与 revision CAS,按 API 地址、App/环境和 Customer 隔离,Start、购买引用和现有 Controller 命令日志共用一条记录。持久记录不保存 Customer access/refresh token 或 Run Token;非浏览器宿主提供原子 CAS 存储适配器。只有原 Run 已到终态、命令已结算且所有购买都有服务端终态时,才允许下一次新建;确认 Run 终止后的未执行报价由 SDK 通过原 Customer API 取消。
|
|
208
|
+
|
|
209
|
+
`start()`/`refresh()` 后,`purchase.attempt` 提供原 `requestId / funnelId / locale / parameters` 的独立只读快照;加载前为 null。`resolveOfferId(selection, original)` 的第二参数提供同一原尝试上下文,领券可复用原请求身份,无需另存日志。恢复所需的商户选择应保存在首次 `parameters` 中,不能用当前配置猜回旧输入。回调结果返回时若展示已关闭、身份或尝试已变化,则拒绝继续报价。
|
|
210
|
+
|
|
211
|
+
购买 Host 复用 Paywall 的 `after_confirmation` 跳转策略:当前明确确认后可以打开原 Checkout 一次;重开、恢复和查询不会自动跳转。界面提供“继续付款”,点击后重读原 Operation,再决定是否打开;付款已完成、已过期或结果未知时不会打开旧地址。恢复页也可使用 `continueCheckout()`。原低层 Host 的默认行为保持兼容,完整用法见英文说明。
|
|
212
|
+
|
|
213
|
+
`recovery.mode` 明确区分可恢复 Run、仅恢复 Operation、受阻和无原单;`status` 给出 `ready`、`waiting_result`、`checkout`、`fulfillment`、`recording`、`complete` 等状态,`actions` 给出允许动作,`confirmation` 提供可确认的原报价,`purchases` 复用 `PaywallRecovery`。恢复页可以直接调用 `refresh()`、`confirm()`、`retry()`、`continueCheckout(商户地址校验与跳转回调)`;不需要解析终态字段组合或维护锁/命令标记。退出或卸载调用 `destroy()`;共享身份切换也会终止旧消费者。
|
|
214
|
+
|
|
215
|
+
`merchant` 允许 merchant Provider,`record_only` 允许商户执行的 Stripe 报价,`indiana` 允许平台执行,`native` 允许 Apple/Google。首次确认、Host 自动流程和原日志重试共用 Controller 派发边界检查;恢复时取原策略与当前策略的交集。展示继续使用现有 loading/ready/dismissed/error 生命周期,`onDismiss` 前已释放展示入口,未知 Close 和未决购买保留原单保护。Operation 购买完成不替代未知 Run/Close 的服务端结算。
|
|
216
|
+
|
|
217
|
+
配套的 [Customer Session 恢复协议](../../docs/funnel-storage-design.md#customer-session-recovery-protocol)使用当前原 Customer 的 Access Token;新登录会话可恢复同一原 Run,不补发 Run Token。`refresh()` 对未知 Start 只执行 `recover_start/lookup`,查不到仍受阻;首次 `start()` 和显式 `retry()` 才以原 ID、原完整输入执行 `resume`。已知 Run 使用 `recover_run`,原日志经 `settle_command` 结算后,由同一 Controller 通过 `run_command` 继续。仅可恢复 Operation 时,通过 `recover_purchase` 读取原 Receipt/Operation 及服务端重选裁决,保留原引用和未决命令;失败/取消状态不能覆盖 `canReselect: false`,命令未结算时也不提前报告完成;没有服务端负证明便不能开启替代购买。此源码要求配套 GOP 和函数迁移,尚未发布或执行远端安装;离线模拟不代表真实 Sandbox、原生 RLS 或事务锁并发验收。
|
|
218
|
+
|
|
203
219
|
### 独立消费方的分桶身份
|
|
204
220
|
|
|
205
221
|
Funnel、独立 Feature 和页面实验各自求值、各自使用结果。App/环境、实验定义、属性、分桶身份及 Sticky 状态相同时结果应一致;刷新时间或输入不同时允许不同组。Remote Funnel 引用允许 Local 定义投递的代码 Experiment 时,仍由 Longplay 计算。已接受的 Funnel 决定保留原结果,不做跨功能结果同步。
|
|
@@ -377,6 +393,21 @@ export async function showBanner(
|
|
|
377
393
|
|
|
378
394
|
每个声明动作都需要同名 handler。`onContinue` 用 `intent.requestId` 作为业务后端的幂等键;失败后 `retryAction()` 重用原意图。卸载、退出或换号时调用 `destroy()`。宿主只渲染和发出意图,业务后端仍负责鉴权与执行。
|
|
379
395
|
|
|
396
|
+
需要刷新展示数据时,显式列出允许更新的已声明 inputs,其余字段在本次展示中保持冻结:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
const host = await mountContent(container, {
|
|
400
|
+
content, // contract 已声明 balance 和 purchaseTerms。
|
|
401
|
+
inputs: { balance: 100, purchaseTerms: originalTerms },
|
|
402
|
+
mutableInputs: ["balance"],
|
|
403
|
+
actions: { continue: onContinue },
|
|
404
|
+
onError: console.error,
|
|
405
|
+
});
|
|
406
|
+
host.updateInputs({ balance: 90 });
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`updateInputs()` 先校验合并后的完整输入,再一次性应用补丁;字段未声明、被冻结或值不合法时同步抛错。空补丁及相同值不触发更新。更新保留原渲染器、用户选择、已填答案、焦点和计时器;待重试动作仍使用原意图与请求身份。`prepareContent` 支持同一接口。切换 Customer、scope、内容版本或购买条款时,先对账未决业务操作,再销毁旧展示并重新准备。更新展示 inputs 不代表授权购买或确认操作结算。
|
|
410
|
+
|
|
380
411
|
需要加快点击打开时,可提前为当前 Customer 读取内容,再调用根入口的 `prepareContent(container, options)`,参数与 `mountContent` 相同。它提前加载展示模块、校验文档并启动 iframe,等首次渲染后返回句柄;点击时同步调用 `handle.show()`,直接显示同一个 iframe。准备期间不打开弹窗、不抢焦点、不执行动作。句柄用于一次展示,重复 `show()` 不重复挂载;下一次展示需重新准备。
|
|
381
412
|
|
|
382
413
|
可传入 `signal: abortController.signal`,在卸载、退出或切换 Customer/App/环境时 `abortController.abort()`,连同仍在等待的准备一起取消并释放资源。预渲染不代替业务鉴权,也不保证图片已完成解码。直接持有已授权 ScreenDocument 的低层接入可使用 `/popup` 的 `preparePopup(document, options)`;句柄立即返回,提供 `ready`、`show()` 和 `destroy()`。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV4Usage, LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
2
|
-
import { F as FoundationApi, A as ApiInput } from './api-
|
|
2
|
+
import { F as FoundationApi, A as ApiInput } from './api-C9P338XT.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const tokenCounts: z.ZodObject<{
|