@celljs/ta-offer 0.0.0-stage → 4.39.0

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/README.en.md ADDED
@@ -0,0 +1,16 @@
1
+ # @celljs/ta-offer
2
+
3
+ English | [简体中文](./README.md)
4
+
5
+ Ta's Open to others: an agent of yours opened by a link. Others open it in a browser and use it, running on your computer on the agent's model and role, within plans you set; they pay you offline or by your payment code, and you confirm. Design: `docs/design/ta-offer.md`.
6
+
7
+ - **Opening**: Discover → Open to others → Open an agent. Pick the agent, a name and a few words, the plans (trial, pack, monthly; each with a price, tokens in all, a cap a day, days), the free plan new users get, and whether you let in each one. You get a link (a year; renew it any time).
8
+ - **Users**: the link joins through the web page of Members (`/j`) with the role User: each has a home of their own (`temporary/guests/<member>`), where this package opens their conversations; they see none of your conversations, files or memory nor each other's, start no conversation of their own and run no commands. Many use it at once, none waiting for another.
9
+ - **Allowance**: each reply counts the tokens the model reported (cache reads a tenth), the day resetting at midnight of your computer; once used up, the next message does not reach the model and the conversation says why.
10
+ - **Payment**: upload your WeChat payment code (a business one is best). Picking a plan, a user gets a check code of four digits for the note, pays, and taps I paid; you are told, look at what came in and tap Received. Money taken offline, or a plan given free, is Open a plan on the user. No money goes through Ta; the ledger, append-only, is `<agent directory>/offer/ledger.jsonl`.
11
+ - **Subscriptions**: an agent on a model signed in by an account (a subscription, another coding agent) gets no paid plans, which such accounts rarely allow; keep free plans or use an API key of your own.
12
+ - **Mini program**: inside WeChat's mini program the payment code is not shown; users are told to ask you.
13
+
14
+ Methods of its host (`ta call @celljs/ta-offer <method> [json...]`): the owner's `overview`, `agents`, `save`, `renewLink`, `setPaused`, `remove`, `answerJoin`, `answerPayment`, `grant`, `setUserPaused`, `removeUser`, `setPayee`; a user's `mine`, `start`, `pay`, `cancelPay`, `payee`. Each checks who calls (`host.team.current()`).
15
+
16
+ It works with other packages only through their hosts' methods: ta-team (`createInvite` and the like; users are its members), ta-channels (`listAgents`), ta-notify (`notify`). Turned off, every offer stops; nothing is lost.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @celljs/ta-offer
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English](./README.en.md) | 简体中文
4
+
5
+ Ta 的"开放给别人用":把你的一个智能体用链接开放出去,别人在浏览器里打开就能用,跑在你的电脑上、用这个智能体的模型和说明;按你定的方案计量,线下或扫你的收款码付款,你确认后开通。设计见 `docs/design/ta-offer.md`。
6
+
7
+ - **开放**:发现 → 开放给别人用 → 开放一个智能体。选智能体、对外名字和介绍,定方案(试用 / 按量包 / 包月,每个方案可设价格、总额度、每天上限、有效期),选新使用者先得到哪个免费方案,选是否每个申请都要你同意。得到一个链接(一年有效,可随时换新)。
8
+ - **使用者**:链接走协作者的网页加入(`/j`),角色是"使用者":每人一个自己的家(`temporary/guests/<成员>`),对话由本包替他开在家里,看不到你的对话、文件、记忆和别人的对话,也不能自己新建对话或运行命令。多人同时用互不排队。
9
+ - **额度**:每条回复按模型报的用量计 token(缓存读取按十分之一),每天按你电脑的 0 点重置;用完后下一条消息不会发给模型,对话里提示原因。
10
+ - **收款**:上传微信收款码(建议经营收款码)。使用者选方案后拿到 4 位核对码,扫码付款时写进备注,点"我付好了";你收到提醒,对一下收款记录点"已收到,开通"。线下收的钱或免费送也可以在使用者那里"开通方案"。钱不经过 Ta;账本在 `<agent 目录>/offer/ledger.jsonl`,只追加。
11
+ - **订阅类模型**:智能体用账号登录的模型(订阅、外部 Agent)时,不能开放收费方案(这类账号一般不允许转给别人收费),只能留免费方案或换成自己的 API Key。
12
+ - **小程序**:在微信小程序 web-view 里不显示收款码,只提示联系提供者开通。
13
+
14
+ 包宿主的方法(`ta call @celljs/ta-offer <方法> [json...]`):主人的 `overview`、`agents`、`save`、`renewLink`、`setPaused`、`remove`、`answerJoin`、`answerPayment`、`grant`、`setUserPaused`、`removeUser`、`setPayee`;使用者的 `mine`、`start`、`pay`、`cancelPay`、`payee`。每个方法自己检查调用者(`host.team.current()`)。
15
+
16
+ 它只经别的包的宿主方法协作:ta-team(`createInvite` 等,使用者就是它的成员)、ta-channels(`listAgents`)、ta-notify(`notify`)。关掉本包,开放全部停用,数据保留。
@@ -0,0 +1,108 @@
1
+ // ../ta-protocol/esm/common/ta-extension-host.js
2
+ var TA_CLOUD_OUTPUT_BYTES = 1024 * 1024;
3
+ var TA_HOST_EVENT = "ta:host";
4
+ var TaHostUtil;
5
+ (function(TaHostUtil2) {
6
+ TaHostUtil2.WAIT_MS = 1000;
7
+ function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
8
+ return new Promise((resolve) => {
9
+ let heard = false;
10
+ let answered = false;
11
+ const timer = setTimeout(() => resolve(undefined), waitMs);
12
+ const request = {
13
+ name,
14
+ heard: () => {
15
+ heard = true;
16
+ },
17
+ resolve: (answer) => {
18
+ answered = true;
19
+ clearTimeout(timer);
20
+ resolve(answer);
21
+ }
22
+ };
23
+ events.emit(TA_HOST_EVENT, request);
24
+ if (!heard && !answered) {
25
+ clearTimeout(timer);
26
+ resolve(undefined);
27
+ }
28
+ });
29
+ }
30
+ TaHostUtil2.reach = reach;
31
+ function marked(systemPrompt, mark) {
32
+ return role(systemPrompt).includes(mark);
33
+ }
34
+ TaHostUtil2.marked = marked;
35
+ function role(systemPrompt) {
36
+ if (!systemPrompt) {
37
+ return "";
38
+ }
39
+ const open = `<addendum>
40
+ `;
41
+ const start = systemPrompt.indexOf(open);
42
+ const context = systemPrompt.indexOf(`<project_context>
43
+ `);
44
+ if (start < 0 || context >= 0 && context < start) {
45
+ return "";
46
+ }
47
+ const end = systemPrompt.indexOf(`
48
+ </addendum>`, start);
49
+ return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
50
+ }
51
+ TaHostUtil2.role = role;
52
+ })(TaHostUtil || (TaHostUtil = {}));
53
+ var TA_DOUBLE_LOOK = {
54
+ name: "@celljs/ta-web",
55
+ key: "assistant.species",
56
+ given: ["trex", "triceratops", "stegosaurus", "brachiosaurus", "velociraptor", "ankylosaurus", "pteranodon", "parasaurolophus"]
57
+ };
58
+ var TaDoubleLookUtil;
59
+ (function(TaDoubleLookUtil2) {
60
+ function given(id) {
61
+ let hash = 2166136261;
62
+ for (let i = 0;i < id.length; i++) {
63
+ hash = Math.imul(hash ^ id.charCodeAt(i), 16777619);
64
+ }
65
+ return TA_DOUBLE_LOOK.given[(hash >>> 0) % TA_DOUBLE_LOOK.given.length];
66
+ }
67
+ TaDoubleLookUtil2.given = given;
68
+ })(TaDoubleLookUtil || (TaDoubleLookUtil = {}));
69
+
70
+ // web-src/offer-protocol.ts
71
+ var NAME = "@celljs/ta-offer";
72
+ var OFFERS_VIEW = `${NAME}/offers`;
73
+ var OFFER_MARK = "[ta:offer]";
74
+
75
+ // web-src/extension.ts
76
+ function activate(pi) {
77
+ let reached;
78
+ const service = () => reached ??= TaHostUtil.reach(pi.events, NAME).then((answer) => answer?.service?._offer);
79
+ const marked = (ctx) => TaHostUtil.marked(ctx.getSystemPrompt?.(), OFFER_MARK);
80
+ pi.on("input", async (_event, ctx) => {
81
+ const offer = await service();
82
+ const file = ctx.sessionManager.getSessionFile();
83
+ const refused = offer ? offer.meters.gate(file, marked(ctx)) : marked(ctx) ? "This conversation runs only under the Ta service." : undefined;
84
+ if (!refused) {
85
+ return { action: "continue" };
86
+ }
87
+ offer?.turns.refused(file, refused);
88
+ ctx.ui?.notify?.(refused, "warning");
89
+ return { action: "handled" };
90
+ });
91
+ pi.on("message_end", async (event, ctx) => {
92
+ if (event.message?.role !== "assistant" || !event.message.usage) {
93
+ return;
94
+ }
95
+ const offer = await service();
96
+ offer?.turns.message(ctx.sessionManager.getSessionFile(), event.message.usage);
97
+ await offer?.meters.meter(ctx.sessionManager.getSessionFile(), event.message.usage);
98
+ });
99
+ pi.on("message_update", async (event, ctx) => {
100
+ const update = event.assistantMessageEvent;
101
+ if (update?.type === "text_delta" && typeof update.delta === "string" && marked(ctx)) {
102
+ (await service())?.turns.delta(ctx.sessionManager.getSessionFile(), update.delta);
103
+ }
104
+ });
105
+ }
106
+ export {
107
+ activate as default
108
+ };