@appgrowstack/app-contract 0.0.0-stage → 0.1.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/dist/http.js ADDED
@@ -0,0 +1,349 @@
1
+ /**
2
+ * 本文がファイルそのもので、core が読まずに流したまま渡す管理のパス(coreEndpoints の名前)。
3
+ * guard は本文を読まない(監査の request_sha256 は null)。大きなファイルを Worker の記憶に載せないため
4
+ */
5
+ export const STREAMED_BODY_ENDPOINTS = new Set(["putCaptureFile", "putReferenceFile", "putAssetFile"]);
6
+ /** 外に出る・設定の操作をエージェントが呼んだときの 202 の本文(AC-3) */
7
+ export const pendingApprovalBody = ["access/approval.schema.json", "pendingApproval"];
8
+ /** 組の取得の頭(K2-5)。人を見分ける値は入れない。api は set_served を数えるだけで、答えを変えない */
9
+ export const APPGROWSTACK_CLIENT_HEADER = "AppGrowStack-Client";
10
+ /** <platform>/<app_version>/<sdk の名前>/<sdk の版>(ios/3.3.0/swift-app-campaign/0.3.0) */
11
+ export const APPGROWSTACK_CLIENT_PATTERN = /^(ios|android)\/\d+\.\d+(\.\d+)?\/[a-z][a-z0-9-]{1,40}\/\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
12
+ /**
13
+ * 端末の SDK が api への全部の要求に付ける頭(docs/design/people.md 6節)。値は DeviceHash(sha256(公開キー + ":" + 端末の id) の16進64文字)。
14
+ * api は答えを変えず、AppGrowStack-Install と一緒に core の observeDevice へ渡す(人の見分けと本人の端末のマークのため)
15
+ */
16
+ export const APPGROWSTACK_DEVICE_HEADER = "AppGrowStack-Device";
17
+ /** 端末の SDK が api への全部の要求に付ける install_id(AppGrowStack-Device と組で読む) */
18
+ export const APPGROWSTACK_INSTALL_HEADER = "AppGrowStack-Install";
19
+ export const DEVICE_HASH_PATTERN = /^[0-9a-f]{64}$/;
20
+ /**
21
+ * api が Analytics Engine(appgrowstack_api_signals)に書く信号の名前。blob2 は道、blob3 はプロジェクト。
22
+ * set_served(K2-5)は blob4 に "<version>:<200|304>:<platform>:<sdk の名前>/<sdk の版>"。頭が無い・形が違う取得は platform を unknown にする
23
+ */
24
+ export const apiSignalNames = ["http_5xx", "set_invalid", "core_error", "rate_limited", "set_served"];
25
+ /** api.appgrowstack.com(appgrowstack-api)。端末が呼ぶのはここだけ。回数の制限とキャッシュをここに置く */
26
+ export const apiEndpoints = {
27
+ getCampaignSet: {
28
+ method: "GET",
29
+ path: "/v1/campaigns/sets/:key",
30
+ auth: "public_key_path",
31
+ request: null,
32
+ response: { status: 200, body: ["inapp/set.schema.json"] },
33
+ note: "If-None-Match で 304。ETag は \"v<version>\"(止めている間は \"v<version>-paused\")。Cache-Control: public, max-age=60。知らないキーは 404 unknown_key。人の値を受け取らない(クエリも読まない)。頭 AppGrowStack-Client(K2-5)を読んで set_served を数える",
34
+ },
35
+ getConfigSet: {
36
+ method: "GET",
37
+ path: "/v1/config/sets/:key",
38
+ auth: "public_key_path",
39
+ request: null,
40
+ response: { status: 200, body: ["config/set.schema.json"] },
41
+ note: "K6-3。R9 の組。取り方は getCampaignSet と同じ(ETag \"v<version>\"・304・max-age=60・回数の制限・人の値を受けない)。config が off・paused の間は今のバージョンの番号のまま空の組(ETag \"v<version>-paused\")。set_served・set_invalid は道(blob2)で組の取得と分ける",
42
+ },
43
+ recordAttribution: {
44
+ method: "POST",
45
+ path: "/v1/links/attributions",
46
+ auth: "public_key",
47
+ request: ["links/attribution.schema.json"],
48
+ response: { status: 200, body: ["links/attribution.schema.json", "response"] },
49
+ note: "同じ install_id の2回目は最初の答え",
50
+ },
51
+ createTicket: {
52
+ method: "POST",
53
+ path: "/v1/support/tickets",
54
+ auth: "public_key",
55
+ request: ["support/ticket.schema.json"],
56
+ response: { status: 201, body: ["support/ticket.schema.json", "createResponse"] },
57
+ note: "install_id ごとに1時間に5件まで(429 rate_limited)",
58
+ },
59
+ listTickets: {
60
+ method: "GET",
61
+ path: "/v1/support/tickets",
62
+ auth: "public_key_and_support_token",
63
+ request: null,
64
+ response: { status: 200, body: ["support/ticket.schema.json", "listResponse"] },
65
+ note: "その owner_token の問い合わせを新しい順に50件まで",
66
+ },
67
+ postTicketMessage: {
68
+ method: "POST",
69
+ path: "/v1/support/tickets/:ticket_id/messages",
70
+ auth: "public_key_and_support_token",
71
+ request: ["support/ticket.schema.json", "postMessageRequest"],
72
+ response: { status: 201, body: ["support/ticket.schema.json", "message"] },
73
+ note: "owner_token が違えば 404 not_found",
74
+ },
75
+ uploadAttachment: {
76
+ method: "POST",
77
+ path: "/v1/support/tickets/:ticket_id/attachments",
78
+ auth: "public_key_and_support_token",
79
+ request: null,
80
+ response: { status: 201, body: ["support/ticket.schema.json", "attachment"] },
81
+ note: "本文は画像そのもの(Content-Type は AttachmentContentType)。1枚5MB・1件に4枚まで(超えたら 413・409)",
82
+ },
83
+ createFeedback: {
84
+ method: "POST",
85
+ path: "/v1/support/feedback",
86
+ auth: "public_key",
87
+ request: ["support/feedback.schema.json"],
88
+ response: { status: 201, body: ["support/feedback.schema.json", "createResponse"] },
89
+ note: "アンケートで書いた文・設定から送った声。返事はしない。install_id ごとに1時間に5件まで(429 rate_limited)。support が off なら 404",
90
+ },
91
+ listArticles: {
92
+ method: "GET",
93
+ path: "/v1/support/articles",
94
+ auth: "public_key",
95
+ request: null,
96
+ response: { status: 200, body: ["support/article.schema.json", "listResponse"] },
97
+ note: "?lang=<札>。Cache-Control: public, max-age=300",
98
+ },
99
+ notifyOpened: {
100
+ method: "POST",
101
+ path: "/v1/notify/opened",
102
+ auth: "public_key",
103
+ request: ["notify/opened.schema.json"],
104
+ response: { status: 204, body: null },
105
+ note: "知らない send_id でも 204(端末は送り直さない)",
106
+ },
107
+ shortLink: {
108
+ method: "GET",
109
+ path: "/l/:code",
110
+ auth: "none",
111
+ request: null,
112
+ response: { status: 302, body: null },
113
+ note: "製品のドメイン(registry_project.web_domain)の Workers のルートで受ける。links_click に1行足して行き先へ。知らない・止めたリンクは製品のトップへ 302",
114
+ },
115
+ namedLink: {
116
+ method: "GET",
117
+ path: "/go/:code",
118
+ auth: "none",
119
+ request: null,
120
+ response: { status: 302, body: null },
121
+ note: "/l/:code と同じ。名前を付けたリンク",
122
+ },
123
+ openOwnerClaim: {
124
+ method: "GET",
125
+ path: "/v1/registry/owner-claims/:token",
126
+ auth: "none",
127
+ request: null,
128
+ response: { status: 200, body: null },
129
+ note: "本人が自分の端末のブラウザで開く HTML のページ(console が作る10分のリンク)。開いた IP と OS を core に残し、この後10分の間に同じ IP・同じ OS から AppGrowStack-Device を付けて届いた最初の端末に owner のマークを付ける(docs/design/people.md 6.3節)。知らない・切れた token も 200 で、そう書いたページを返す",
130
+ },
131
+ postSessionBatch: {
132
+ method: "POST",
133
+ path: "/v1/sessions/batches",
134
+ auth: "public_key",
135
+ request: ["sessions/batch.schema.json"],
136
+ response: { status: 200, body: ["sessions/batch.schema.json", "answer"] },
137
+ note: "R8(K3)。gzip 可・1回 256KB・出来事500件まで。install_id ごとに5秒に1回(429 と Retry-After)。sessions が off・paused なら 204(端末は溜めた物を消す)",
138
+ },
139
+ putSessionSegment: {
140
+ method: "PUT",
141
+ path: "/v1/sessions/:session_id/segments/:seq",
142
+ auth: "public_key_and_upload_token",
143
+ request: null,
144
+ response: { status: 204, body: null },
145
+ note: "頭 X-Session-Install(install_id)と X-Session-Upload(upload_token。verifySessionUploadToken)。本文は .agsr の塊そのもの(application/vnd.appgrowstack.replay-segment・1MB まで・頭は ReplaySegmentHeader)。同じ seq の2回目は 204 で捨てる。install_id ごとに1分に 4MB・プロジェクトの1日 daily_bytes",
146
+ },
147
+ sessionLive: {
148
+ method: "GET",
149
+ path: "/v1/sessions/live",
150
+ auth: "public_key_and_live_token",
151
+ request: null,
152
+ response: { status: 101, body: null },
153
+ note: "WebSocket(通は sessions/live.schema.json)。頭 X-Session-Install と Sec-WebSocket-Protocol の live の token。api が until と HMAC を確かめ(verifySessionLiveToken。違えば 403)、core の DO SessionLive に X-AppGrowStack-Project と X-Session-Install を付けて渡す。見る人がいるかは DO が確かめる",
154
+ },
155
+ };
156
+ const m = (permission) => ({ kind: "member", permission });
157
+ const anyPrincipal = { kind: "principal" };
158
+ /**
159
+ * admin.appgrowstack.com(appgrowstack-core)。CLI(app-growth)・console(Service Binding)・app-playbook が呼ぶ。
160
+ * 全部の道に操作の名前を書く(AC-3)。表は access.ts、確かめは core の中間の層(P1)。サーバーキー(sk_)と binding はどの道も通さない
161
+ */
162
+ export const coreEndpoints = {
163
+ createProject: { method: "POST", path: "/v1/registry/projects", auth: m("registry.project.create"), request: ["registry/admin.schema.json"], response: { status: 201, body: ["registry/admin.schema.json", "createResponse"] }, note: "同じ id は 409 conflict" },
164
+ listProjects: { method: "GET", path: "/v1/registry/projects", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "projectList"] }, note: "" },
165
+ getProject: { method: "GET", path: "/v1/registry/projects/:project", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "projectDetail"] }, note: "" },
166
+ updateProject: { method: "PATCH", path: "/v1/registry/projects/:project", auth: m("registry.project.update"), request: ["registry/admin.schema.json", "updateProjectRequest"], response: { status: 200, body: ["registry/project.schema.json"] }, note: "" },
167
+ exportProject: { method: "GET", path: "/v1/registry/projects/:project/export", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "projectDetail"] }, note: "app-growth project export が app-playbook の config/products.toml の登録の値に書き出す(逆向きには書かない)" },
168
+ putApp: { method: "PUT", path: "/v1/registry/projects/:project/apps/:platform", auth: m("registry.app.write"), request: ["registry/admin.schema.json", "putAppRequest"], response: { status: 200, body: ["registry/app.schema.json"] }, note: "" },
169
+ createKey: { method: "POST", path: "/v1/registry/projects/:project/keys", auth: m("keys.create"), request: ["registry/admin.schema.json", "createKeyRequest"], response: { status: 201, body: ["registry/admin.schema.json", "createKeyResponse"] }, note: "" },
170
+ revokeKey: { method: "POST", path: "/v1/registry/projects/:project/keys/:key_id/revoke", auth: m("keys.revoke"), request: null, response: { status: 200, body: ["registry/key.schema.json"] }, note: "最後の active な公開キーは 409 conflict" },
171
+ listInternalMarks: { method: "GET", path: "/v1/registry/projects/:project/internal", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "internalMarkList"] }, note: "本人とテスターのマークと、見分けごとの人数。app-growth registry internal list" },
172
+ putInternalMark: { method: "PUT", path: "/v1/registry/projects/:project/internal/:match/:value", auth: m("registry.device.write"), request: ["registry/admin.schema.json", "putInternalMarkRequest"], response: { status: 200, body: ["registry/admin.schema.json", "internalMarkResult"] }, note: ":match は uid・install・device。当たる人と、その人の出来事の audience をその場で書き換える。app-growth registry internal add" },
173
+ deleteInternalMark: { method: "DELETE", path: "/v1/registry/projects/:project/internal/:match/:value", auth: m("registry.device.write"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "internalMarkResult"] }, note: "外したマークにだけ当たっていた人を、自動の見分け(channel・ネットワーク)に戻す。無いマークは 404。app-growth registry internal remove" },
174
+ createOwnerClaim: { method: "POST", path: "/v1/registry/projects/:project/owner-claims", auth: m("registry.device.write"), request: null, response: { status: 201, body: ["registry/admin.schema.json", "ownerClaim"] }, note: "端末に本人のマークを付ける10分のリンク(docs/design/people.md 6.3節)。console の「この端末は自分」と app-growth registry internal claim" },
175
+ doctor: { method: "GET", path: "/v1/registry/doctor", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "doctorReport"] }, note: "app-growth doctor。?project=<id> でそのプロジェクトだけ(KD-6)。呼んだ主体が見られるプロジェクトだけ" },
176
+ health: { method: "GET", path: "/v1/registry/health", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "healthReport"] }, note: "K2-7。core の Cron が5分ごとに数えた物(inapp_health)。app-playbook が5分ごとに読んで知らせる" },
177
+ listPending: { method: "GET", path: "/v1/registry/pending", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "pendingList"] }, note: "KD-1。呼んだ主体が見られる全部のプロジェクトの承認待ち(案・下書き・承認の依頼)。1件ごとに can_decide。app-growth pending" },
178
+ getGlobalHoldout: { method: "GET", path: "/v1/registry/projects/:project/global-holdout", auth: m("people.aggregate.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "globalHoldoutReport"] }, note: "R10。製品全体の holdout とほかの人の差(7日の継続・30日の課金・通知を切った率)。console の概要" },
179
+ getMetrics: { method: "GET", path: "/v1/registry/metrics", auth: m("registry.read"), request: null, response: { status: 200, body: ["registry/admin.schema.json", "metricsReport"] }, note: "直近30日の日ごとの数(開いた人・初めての人・キャンペーンの表示・問い合わせ・リンクのクリック)と7日・30日の合計。?project=<id> でそのプロジェクトだけ。数ごとに段階1の操作が無ければ null。console のホームと概要" },
180
+ putTouchBudget: { method: "PUT", path: "/v1/registry/projects/:project/touch-budget", auth: m("registry.budget.write"), request: ["registry/admin.schema.json", "putTouchBudgetRequest"], response: { status: 200, body: ["registry/touch-budget.schema.json"] }, note: "" },
181
+ pushSet: { method: "POST", path: "/v1/campaigns/projects/:project/sets", auth: m("campaigns.push"), request: ["inapp/admin.schema.json"], response: { status: 201, body: ["inapp/admin.schema.json", "pushResponse"] }, note: "形が合わない・送ったことのある id の holdout・triggers・audience を変えた・target が R1 に無い は 400 invalid(problems つき)" },
182
+ listSets: { method: "GET", path: "/v1/campaigns/projects/:project/sets", auth: m("campaigns.read"), request: null, response: { status: 200, body: ["inapp/admin.schema.json", "setHistory"] }, note: "?limit=20" },
183
+ stop: { method: "POST", path: "/v1/campaigns/projects/:project/stop", auth: m("campaigns.stop"), request: ["inapp/admin.schema.json", "stopRequest"], response: { status: 201, body: ["inapp/admin.schema.json", "pushResponse"] }, note: "" },
184
+ resume: { method: "POST", path: "/v1/campaigns/projects/:project/resume", auth: m("campaigns.resume"), request: null, response: { status: 200, body: ["inapp/admin.schema.json", "pushResponse"] }, note: "inapp_state.paused を戻す" },
185
+ rollback: { method: "POST", path: "/v1/campaigns/projects/:project/rollback", auth: m("campaigns.rollback"), request: ["inapp/admin.schema.json", "rollbackRequest"], response: { status: 200, body: ["inapp/admin.schema.json", "rollbackResponse"] }, note: "dry_run で差だけ" },
186
+ simulate: { method: "POST", path: "/v1/campaigns/projects/:project/simulate", auth: m("campaigns.read"), request: ["inapp/admin.schema.json", "simulateRequest"], response: { status: 200, body: ["inapp/admin.schema.json", "simulateReport"] }, note: "K2-7。app-growth campaigns simulate。人ごとの出来事を返さず、数と例の person_id だけ" },
187
+ explainPerson: { method: "GET", path: "/v1/campaigns/projects/:project/people/:person/explain", auth: m("people.person.read"), request: null, response: { status: 200, body: ["inapp/admin.schema.json", "explainReport"] }, note: "K2-7。?event=&at=。app-growth campaigns explain。段階2(監査に残す)" },
188
+ getCampaignReport: { method: "GET", path: "/v1/campaigns/projects/:project/campaigns/:campaign/report", auth: m("campaigns.read"), request: null, response: { status: 200, body: ["inapp/admin.schema.json", "campaignReport"] }, note: "KD-2。?since=&until=。app-growth campaigns report・console" },
189
+ listNotifyVariants: { method: "GET", path: "/v1/notify/projects/:project/variants", auth: m("notify.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "variantList"] }, note: "?campaign=&status=proposed|live|retired。content は入れない。notify が知らないプロジェクトは 404" },
190
+ getNotifyVariant: { method: "GET", path: "/v1/notify/projects/:project/variants/:variant_id", auth: m("notify.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "variant"] }, note: "content(全部の言語)つき" },
191
+ approveNotifyVariant: { method: "POST", path: "/v1/notify/projects/:project/variants/:variant_id/approve", auth: m("notify.variant.approve"), request: ["notify/admin.schema.json"], response: { status: 200, body: ["notify/admin.schema.json", "approveResponse"] }, note: "proposed でない・live の上限を超える(retire が要る)・retire が同じ施策の live でない は 409 conflict" },
192
+ rejectNotifyVariant: { method: "POST", path: "/v1/notify/projects/:project/variants/:variant_id/reject", auth: m("notify.variant.reject"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "variant"] }, note: "proposed の案を retired(rejected)に。ほかは 409" },
193
+ retireNotifyVariant: { method: "POST", path: "/v1/notify/projects/:project/variants/:variant_id/retire", auth: m("notify.variant.retire"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "variant"] }, note: "live の案を retired(retired_by_hand)に。ほかは 409" },
194
+ listNotifyCampaigns: { method: "GET", path: "/v1/notify/projects/:project/campaigns", auth: m("notify.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "campaignStateList"] }, note: "" },
195
+ stopNotifyCampaign: { method: "POST", path: "/v1/notify/projects/:project/campaigns/:campaign/stop", auth: m("notify.campaign.stop"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "campaignState"] }, note: "入りの記録は続ける。アプリに無い施策は 404" },
196
+ resumeNotifyCampaign: { method: "POST", path: "/v1/notify/projects/:project/campaigns/:campaign/resume", auth: m("notify.campaign.resume"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "campaignState"] }, note: "" },
197
+ listNotifyRuns: { method: "GET", path: "/v1/notify/runs", auth: m("notify.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "runList"] }, note: "?limit=1(1〜20)。全部のプロジェクトの物" },
198
+ previewNotify: { method: "POST", path: "/v1/notify/projects/:project/campaigns/:campaign/preview", auth: m("notify.read"), request: ["notify/admin.schema.json", "previewRequest"], response: { status: 200, body: ["notify/admin.schema.json", "preview"] }, note: "K2-8。core → NOTIFY_ADMIN.preview。書き込まない。app-growth notify preview" },
199
+ explainNotifyPerson: { method: "GET", path: "/v1/notify/projects/:project/people/:person", auth: m("people.person.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "explain"] }, note: "K2-8。core → NOTIFY_ADMIN.explain。app-growth notify explain。段階2" },
200
+ getNotifyStats: { method: "GET", path: "/v1/notify/projects/:project/campaigns/:campaign/stats", auth: m("notify.read"), request: null, response: { status: 200, body: ["notify/admin.schema.json", "stats"] }, note: "KD-3。?days=7(1〜90)。core → NOTIFY_ADMIN.stats" },
201
+ createLink: { method: "POST", path: "/v1/links/projects/:project/links", auth: m("links.create"), request: ["links/link.schema.json", "createInput"], response: { status: 201, body: ["links/link.schema.json"] }, note: "本文の project は道と同じでなければ 400" },
202
+ listLinks: { method: "GET", path: "/v1/links/projects/:project/links", auth: m("links.read"), request: null, response: { status: 200, body: ["links/link.schema.json", "listResponse"] }, note: "?limit=50(200まで)" },
203
+ getLink: { method: "GET", path: "/v1/links/projects/:project/links/:code", auth: m("links.read"), request: null, response: { status: 200, body: ["links/link.schema.json", "detail"] }, note: "app-growth links show。押された回数と流入元が付いた数" },
204
+ listLinkSources: { method: "GET", path: "/v1/links/projects/:project/sources", auth: m("links.read"), request: null, response: { status: 200, body: ["links/link.schema.json", "sourceList"] }, note: "KD-5・MG-3。?since=(既定は28日前)。入れた人の7日後・28日後に開いた数と払った数つき" },
205
+ listTickets: { method: "GET", path: "/v1/support/projects/:project/tickets", auth: m("support.ticket.list"), request: null, response: { status: 200, body: ["support/ticket.schema.json", "adminListResponse"] }, note: "?status=drafted(app-growth inbox)" },
206
+ approveDraft: { method: "POST", path: "/v1/support/tickets/:ticket_id/drafts/:draft_id/approve", auth: m("support.reply"), request: ["support/ticket.schema.json", "approveRequest"], response: { status: 201, body: ["support/ticket.schema.json", "message"] }, note: "返事を送り、support_ticket_answered を track し、R5 で知らせる" },
207
+ getTicket: { method: "GET", path: "/v1/support/tickets/:ticket_id", auth: m("support.ticket.read"), request: null, response: { status: 200, body: ["support/ticket.schema.json", "adminTicket"] }, note: "app-growth inbox show" },
208
+ replyTicket: { method: "POST", path: "/v1/support/tickets/:ticket_id/messages", auth: m("support.reply"), request: ["support/ticket.schema.json", "replyRequest"], response: { status: 201, body: ["support/ticket.schema.json", "message"] }, note: "下書きを使わない返事。待っている下書きは rejected にする" },
209
+ redraftTicket: { method: "POST", path: "/v1/support/tickets/:ticket_id/drafts", auth: m("support.redraft"), request: ["support/ticket.schema.json", "redraftRequest"], response: { status: 204, body: null }, note: "AI の下書きを作り直す(Queue)" },
210
+ getAttachment: { method: "GET", path: "/v1/support/tickets/:ticket_id/attachments/:attachment_id", auth: m("support.attachment.read"), request: null, response: { status: 200, body: null }, note: "画像そのもの" },
211
+ rejectDraft: { method: "POST", path: "/v1/support/tickets/:ticket_id/drafts/:draft_id/reject", auth: m("support.draft.reject"), request: null, response: { status: 200, body: ["support/ticket.schema.json", "draft"] }, note: "" },
212
+ resolveTicket: { method: "POST", path: "/v1/support/tickets/:ticket_id/resolve", auth: m("support.resolve"), request: null, response: { status: 204, body: null }, note: "" },
213
+ listReviews: { method: "GET", path: "/v1/support/projects/:project/reviews", auth: m("support.review.read"), request: null, response: { status: 200, body: ["support/review.schema.json", "list"] }, note: "?status=received,drafted(既定)|all・?store=app_store|google_play(app-growth reviews list)。下書きを含む" },
214
+ approveReviewDraft: { method: "POST", path: "/v1/support/projects/:project/reviews/:review_id/drafts/:draft_id/approve", auth: m("support.review.reply"), request: ["support/review.schema.json", "approveRequest"], response: { status: 201, body: ["support/review.schema.json"] }, note: "ストアに返事を送る(customerReviewResponses・reviews.reply)。字数は reply_limit まで。送れない・キーが無いときは 503 で、下書きは pending のまま" },
215
+ rejectReviewDraft: { method: "POST", path: "/v1/support/projects/:project/reviews/:review_id/drafts/:draft_id/reject", auth: m("support.draft.reject"), request: null, response: { status: 200, body: ["support/review.schema.json", "draft"] }, note: "" },
216
+ redraftReview: { method: "POST", path: "/v1/support/projects/:project/reviews/:review_id/drafts", auth: m("support.redraft"), request: ["support/review.schema.json", "redraftRequest"], response: { status: 204, body: null }, note: "AI の下書きを作り直す(Queue)" },
217
+ getFeedbackSummary: { method: "GET", path: "/v1/support/projects/:project/feedback/summary", auth: m("support.feedback.read"), request: null, response: { status: 200, body: ["support/feedback.schema.json", "summary"] }, note: "?days=28(1〜365)&campaign=<件の id>。AI が付けた話題ごとの数と例(app-growth feedback summary・数字の仕組み)" },
218
+ pushArticles: { method: "PUT", path: "/v1/support/projects/:project/articles", auth: m("help.push"), request: ["support/article.schema.json", "pushRequest"], response: { status: 204, body: null }, note: "app-growth help push。索引を全部置き換える" },
219
+ getSupportSummary: { method: "GET", path: "/v1/support/projects/:project/summary", auth: m("support.aggregate.read"), request: null, response: { status: 200, body: ["support/ticket.schema.json", "summary"] }, note: "MG-5。?since=(既定は28日前)。数だけ(段階1)" },
220
+ getPeopleSummary: { method: "GET", path: "/v1/people/projects/:project/summary", auth: m("people.aggregate.read"), request: null, response: { status: 200, body: ["people/admin.schema.json"] }, note: "KD-4。段階1" },
221
+ findPerson: { method: "GET", path: "/v1/people/projects/:project/find", auth: m("people.person.read"), request: null, response: { status: 200, body: ["people/admin.schema.json", "personView"] }, note: "KD-4。?q=<person_id・install_id・uid>。1人だけ・見つからなければ 404。段階2(監査に残す)" },
222
+ forgetPerson: { method: "POST", path: "/v1/people/projects/:project/people/:person/forget", auth: m("people.forget"), request: null, response: { status: 204, body: null }, note: "管理の道からの手での削除(本人の確認)。中身は RPC の forget と同じ" },
223
+ listSessions: { method: "GET", path: "/v1/sessions/projects/:project/sessions", auth: m("sessions.person.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json"] }, note: "K3。?person=&since=&end=&has=rage|dead|replay|ticket|summary&campaign=&side=&screen=&limit=20&cursor=。app-growth sessions list" },
224
+ getSession: { method: "GET", path: "/v1/sessions/projects/:project/sessions/:session_id", auth: m("sessions.person.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "detail"] }, note: "行・出来事の列をつないだ物・マーク・塊の一覧・要約。app-growth sessions show" },
225
+ getSessionFrame: { method: "GET", path: "/v1/sessions/projects/:project/sessions/:session_id/segments/:seq", auth: m("sessions.replay.read"), request: null, response: { status: 200, body: null }, note: "塊の本文(.agsr)か、?frame=<n> で1コマの画像(R2 の Range)。段階3・1回ごとに監査" },
226
+ summarizeSession: { method: "POST", path: "/v1/sessions/projects/:project/sessions/:session_id/summarize", auth: m("sessions.summarize"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "summary"] }, note: "その場で作る(Batches を使わない)。お金がかかる" },
227
+ keepSession: { method: "POST", path: "/v1/sessions/projects/:project/sessions/:session_id/keep", auth: m("sessions.keep"), request: ["sessions/admin.schema.json", "keepRequest"], response: { status: 200, body: ["sessions/admin.schema.json", "keepResponse"] }, note: "既定180日" },
228
+ listScreenStats: { method: "GET", path: "/v1/sessions/projects/:project/screens", auth: m("sessions.aggregate.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "screenStatsList"] }, note: "?since=&platform=" },
229
+ getScreenMap: { method: "GET", path: "/v1/sessions/projects/:project/screens/:screen/map", auth: m("sessions.aggregate.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "screenMap"] }, note: "?since=&platform=&kind=。代表のコマの道は sessions.replay.read を持つ主体にだけ入れる" },
230
+ getScreenRef: { method: "GET", path: "/v1/sessions/projects/:project/screens/:screen/ref", auth: m("sessions.replay.read"), request: null, response: { status: 200, body: null }, note: "?platform=&app_version=。画面の代表のコマの画像(ScreenMap.ref_frame.path)。段階3・1回ごとに監査" },
231
+ getFlows: { method: "GET", path: "/v1/sessions/projects/:project/flows", auth: m("sessions.aggregate.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "flowReport"] }, note: "?since=&from=&depth=" },
232
+ getSessionDigest: { method: "GET", path: "/v1/sessions/projects/:project/digest", auth: m("sessions.aggregate.read"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "digest"] }, note: "?week=YYYY-Www" },
233
+ rebuildSessionDigest: { method: "POST", path: "/v1/sessions/projects/:project/digest", auth: m("sessions.summarize"), request: null, response: { status: 200, body: ["sessions/admin.schema.json", "digest"] }, note: "?week=。app-growth sessions summarize --week。週のまとめを作り直す" },
234
+ pushSessionPolicy: { method: "PUT", path: "/v1/sessions/projects/:project/policy", auth: m("sessions.policy.push"), request: ["sessions/manifest.schema.json"], response: { status: 200, body: ["sessions/manifest.schema.json", "policy"] }, note: "app-growth sessions push。エージェントが呼ぶと 202 PendingApproval" },
235
+ watchLive: { method: "POST", path: "/v1/sessions/projects/:project/live", auth: m("sessions.live.watch"), request: ["sessions/admin.schema.json", "watchLiveRequest"], response: { status: 200, body: ["sessions/admin.schema.json", "liveWatch"] }, note: "sessions_live_watch に until = 今 + 30分。段階3・1回ごとに監査" },
236
+ watchLiveSocket: { method: "GET", path: "/v1/sessions/projects/:project/live/:install_id", auth: m("sessions.live.watch"), request: null, response: { status: 101, body: null }, note: "見る人の WebSocket(console が Service Binding の fetch でそのまま渡す)" },
237
+ whoami: { method: "GET", path: "/v1/access/whoami", auth: anyPrincipal, request: null, response: { status: 200, body: ["access/principal.schema.json", "whoAmI"] }, note: "主体・証・所属の組織と役割。console の上の帯が要求ごとに1回読む" },
238
+ listMembers: { method: "GET", path: "/v1/access/orgs/:org/members", auth: m("access.member.read"), request: null, response: { status: 200, body: ["access/membership.schema.json", "memberList"] }, note: "" },
239
+ putMember: { method: "PUT", path: "/v1/access/orgs/:org/members/:principal_id", auth: m("access.member.write"), request: ["access/membership.schema.json", "putMemberRequest"], response: { status: 200, body: ["access/membership.schema.json"] }, note: "本人の確認" },
240
+ deleteMember: { method: "DELETE", path: "/v1/access/orgs/:org/members/:principal_id", auth: m("access.member.write"), request: null, response: { status: 204, body: null }, note: "?role=(要る。無い・知らない役割は 400)&project=。本人の確認" },
241
+ listAgents: { method: "GET", path: "/v1/access/orgs/:org/agents", auth: m("access.agent.read"), request: null, response: { status: 200, body: ["access/principal.schema.json", "agentList"] }, note: "" },
242
+ createAgent: { method: "POST", path: "/v1/access/orgs/:org/agents", auth: m("access.agent.write"), request: ["access/principal.schema.json", "createAgentRequest"], response: { status: 201, body: ["access/principal.schema.json", "agentPrincipal"] }, note: "本人の確認。オーナーの人つき" },
243
+ issueToken: { method: "POST", path: "/v1/access/tokens", auth: m("access.token.issue"), request: ["access/token.schema.json", "issueTokenRequest"], response: { status: 201, body: ["access/token.schema.json", "issueTokenResponse"] }, note: "値は答えの1回だけ。エージェント(app-growth tokens request)は自分のトークンの回しだけを依頼でき、202" },
244
+ listTokens: { method: "GET", path: "/v1/access/tokens", auth: anyPrincipal, request: null, response: { status: 200, body: ["access/token.schema.json", "tokenList"] }, note: "自分のトークン。owner は組織の全部" },
245
+ revokeToken: { method: "POST", path: "/v1/access/tokens/:token_id/revoke", auth: m("access.token.revoke"), request: null, response: { status: 200, body: ["access/token.schema.json"] }, note: "エージェントは自分のトークンだけ。次の要求から止まる" },
246
+ pushConfig: { method: "POST", path: "/v1/config/projects/:project/sets", auth: m("config.push"), request: ["config/admin.schema.json"], response: { status: 201, body: ["config/admin.schema.json", "pushResponse"] }, note: "K6-3。app-growth config push。形が合わない・manifest に無い key・型の違い・送ったことのある実験の固定する項目を変えた・最初の案の割合が holdout_min 未満 は 400 invalid(problems つき)" },
247
+ listConfigSets: { method: "GET", path: "/v1/config/projects/:project/sets", auth: m("config.read"), request: null, response: { status: 200, body: ["config/admin.schema.json", "setHistory"] }, note: "?limit=20" },
248
+ stopConfigExperiment: { method: "POST", path: "/v1/config/projects/:project/stop", auth: m("config.stop"), request: ["config/admin.schema.json", "stopRequest"], response: { status: 201, body: ["config/admin.schema.json", "pushResponse"] }, note: "実験を外した新しいバージョン。今の組に無い実験は 404" },
249
+ getConfigReport: { method: "GET", path: "/v1/config/projects/:project/experiments/:experiment/report", auth: m("config.read"), request: null, response: { status: 200, body: ["config/admin.schema.json", "report"] }, note: "?at=(既定は今)。app-growth config report・console。送ったことの無い実験は 404" },
250
+ listApprovals: { method: "GET", path: "/v1/access/approvals", auth: m("access.approval.read"), request: null, response: { status: 200, body: ["access/approval.schema.json", "approvalList"] }, note: "?status=pending&project=。app-playbook が5分ごとに読んで Web Push(URL は console)" },
251
+ getApproval: { method: "GET", path: "/v1/access/approvals/:approval_id", auth: m("access.approval.read"), request: null, response: { status: 200, body: ["access/approval.schema.json"] }, note: "app-growth approvals show(--wait で実行の結果まで)" },
252
+ approveApproval: { method: "POST", path: "/v1/access/approvals/:approval_id/approve", auth: m("access.approval.decide"), request: ["access/approval.schema.json", "decideApprovalRequest"], response: { status: 200, body: ["access/approval.schema.json"] }, note: "本人の確認つきの人だけ・依頼の操作の権限も要る・依頼した主体と別。依頼に残した本文で実行する。24時間を過ぎた・前提が変わったら 409 approval_expired" },
253
+ rejectApproval: { method: "POST", path: "/v1/access/approvals/:approval_id/reject", auth: m("access.approval.decide"), request: ["access/approval.schema.json", "decideApprovalRequest"], response: { status: 200, body: ["access/approval.schema.json"] }, note: "" },
254
+ listAudit: { method: "GET", path: "/v1/access/audit", auth: m("audit.read"), request: null, response: { status: 200, body: ["access/audit-event.schema.json", "auditEventList"] }, note: "?project=&principal=&action=&since=&until=&limit=。app-growth audit list" },
255
+ getPolicy: { method: "GET", path: "/v1/access/projects/:project/policy", auth: m("registry.read"), request: null, response: { status: 200, body: ["access/policy.schema.json"] }, note: "プロジェクトの上書きが無ければ組織の既定" },
256
+ putPolicy: { method: "PUT", path: "/v1/access/projects/:project/policy", auth: m("access.policy.write"), request: ["access/policy.schema.json", "putAccessPolicyRequest"], response: { status: 200, body: ["access/policy.schema.json"] }, note: "本人の確認" },
257
+ // R11 リリース(docs/design/releases.md 9節)。どの操作も外に出ないので、エージェントも承認なしで呼べる。書く操作は監査に残す
258
+ listReleases: { method: "GET", path: "/v1/releases/projects/:project/versions", auth: m("releases.read"), request: null, response: { status: 200, body: ["releases/admin.schema.json"] }, note: "?platform=&state=&limit=50。app-growth releases list・console・insights" },
259
+ getRelease: { method: "GET", path: "/v1/releases/projects/:project/apps/:platform/versions/:version", auth: m("releases.read"), request: null, response: { status: 200, body: ["releases/admin.schema.json", "releaseDetail"] }, note: "状態の変化・ストアの新機能の文・マニフェスト・つながる変更。core の知らないバージョンは 404。app-growth releases show" },
260
+ getReleaseTimeline: { method: "GET", path: "/v1/releases/projects/:project/timeline", auth: m("releases.read"), request: null, response: { status: 200, body: ["releases/admin.schema.json", "timeline"] }, note: "?since=。無ければ90日前から。console のタイムライン" },
261
+ getReleaseReport: { method: "GET", path: "/v1/releases/projects/:project/apps/:platform/versions/:version/report", auth: m("people.aggregate.read"), request: null, response: { status: 200, body: ["releases/admin.schema.json", "releaseReport"] }, note: "数だけ。公開していないバージョンは 409 not_released。app-growth releases report・console・insights" },
262
+ syncReleases: { method: "POST", path: "/v1/releases/projects/:project/sync", auth: m("releases.sync"), request: null, response: { status: 200, body: ["releases/admin.schema.json", "syncResult"] }, note: "Cron と同じ同期をすぐ回す。app-growth releases sync・app-release ship submit" },
263
+ pushManifest: { method: "PUT", path: "/v1/releases/projects/:project/apps/:platform/versions/:version/manifest", auth: m("releases.manifest.push"), request: ["releases/manifest.schema.json"], response: { status: 200, body: ["releases/admin.schema.json", "manifestResult"] }, note: "本文の project・platform・version がパスと違えば 400 invalid。固定の後に違う本文は 409 manifest_locked、同じ sha256 は 200 で何もしない。app-growth releases manifest push" },
264
+ resolveRequires: { method: "POST", path: "/v1/releases/projects/:project/resolve", auth: m("releases.read"), request: ["releases/admin.schema.json", "resolveRequest"], response: { status: 200, body: ["releases/admin.schema.json", "resolveResult"] }, note: "campaigns check・config check・core の push が同じ解決を使う。誤りと警告は答えの problems に入れる" },
265
+ listChanges: { method: "GET", path: "/v1/releases/projects/:project/changes", auth: m("releases.read"), request: null, response: { status: 200, body: ["releases/admin.schema.json", "changeList"] }, note: "?platform=&version=&feature=&status=&kind=。app-growth changes list・app-playbook・insights" },
266
+ putChange: { method: "PUT", path: "/v1/releases/projects/:project/changes/:change", auth: m("releases.change.write"), request: ["releases/change.schema.json"], response: { status: 200, body: ["releases/change.schema.json"] }, note: "作るか置き換える。本文の id がパスと違えば 400 invalid。platforms に core の知らないバージョンがあれば 400 unknown_app_version。app-growth changes add" },
267
+ judgeChange: { method: "POST", path: "/v1/releases/projects/:project/changes/:change/judge", auth: m("releases.change.write"), request: ["releases/change.schema.json", "judgeRequest"], response: { status: 200, body: ["releases/change.schema.json"] }, note: "判定の結果を書く。無い変更は 404。app-growth changes judge" },
268
+ deleteChange: { method: "DELETE", path: "/v1/releases/projects/:project/changes/:change", auth: m("releases.change.write"), request: null, response: { status: 204, body: null }, note: "書き間違いを消す。出した物を戻したときは消さず judgeChange で reverted にする。app-growth changes remove" },
269
+ // R12 ストアの素材(docs/design/creatives.md 15節)。core が受け、CREATIVE_ADMIN(appgrowstack-creative の CreativeAdminRpc)に渡す
270
+ createCaptureSet: { method: "POST", path: "/v1/creatives/projects/:project/captures", auth: m("creatives.capture.write"), request: ["creative/capture.schema.json", "createCaptureSetRequest"], response: { status: 201, body: ["creative/capture.schema.json", "createCaptureSetResult"] }, note: "組を uploading で作り、ファイルごとに putCaptureFile のパスを返す。署名付きの URL は使わない(ADR 0028)。app-growth creatives captures push" },
271
+ putCaptureFile: { method: "PUT", path: "/v1/creatives/projects/:project/captures/:set/files/:locale/:device/:screen/:kind", auth: m("creatives.capture.write"), request: null, response: { status: 204, body: null }, note: "本文はファイルそのもの(image は image/png、video は video/mp4)。Content-Length が要る。1つ 90MB まで(超えたら 413)。R2 が受けた中身を、組を作った時の sha256 と照らす(違えば 409 capture_mismatch)。core が本文を流したまま CREATIVE_ADMIN に渡し、creative が R2 の binding で書く。組が uploading でなければ 409 conflict" },
272
+ getCaptureFile: { method: "GET", path: "/v1/creatives/projects/:project/captures/:set/files/:locale/:device/:screen/:kind", auth: m("creatives.read"), request: null, response: { status: 200, body: null }, note: "撮った画面か録画のファイルそのもの。R2 は公開の URL を持たないので、console と CLI はここで読む。組に無いファイル・まだ R2 に無いファイルは 404" },
273
+ completeCaptureSet: { method: "POST", path: "/v1/creatives/projects/:project/captures/:set/complete", auth: m("creatives.capture.write"), request: null, response: { status: 200, body: ["creative/capture.schema.json"] }, note: "sha256 と寸法を R2 の物と照らし、合えば ready。合わないファイルがあれば failed にして 409 capture_mismatch(problems にファイルの名前)" },
274
+ listCaptureSets: { method: "GET", path: "/v1/creatives/projects/:project/captures", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json"] }, note: "?platform=&version=。新しい順。app-growth creatives captures list" },
275
+ getBrand: { method: "GET", path: "/v1/creatives/projects/:project/brand", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/brand.schema.json"] }, note: "新しい rev。まだ無ければ 404。app-growth creatives brand show" },
276
+ putBrand: { method: "PUT", path: "/v1/creatives/projects/:project/brand", auth: m("creatives.brand.write"), request: ["creative/brand.schema.json", "brandBody"], response: { status: 200, body: ["creative/brand.schema.json"] }, note: "rev を1つ上げて足す。同じ sha256 は 200 で何もしない。app-growth creatives brand push" },
277
+ createAssetUpload: { method: "POST", path: "/v1/creatives/projects/:project/assets", auth: m("creatives.brand.write"), request: ["creative/admin.schema.json", "assetUploadRequest"], response: { status: 201, body: ["creative/admin.schema.json", "assetUploadResult"] }, note: "フォント・端末の枠・背景の素材を足し、putAssetFile のパスを返す。R2 に同じ sha256 の物が既にあれば upload は null。app-growth creatives assets push" },
278
+ putAssetFile: { method: "PUT", path: "/v1/creatives/projects/:project/assets/:asset", auth: m("creatives.brand.write"), request: null, response: { status: 204, body: null }, note: "本文はファイルそのもの(createAssetUpload の content_type)。Content-Length が要る。1つ 20MB まで(超えたら 413)。R2 が受けた中身を createAssetUpload の sha256 と照らす(違えば 409 capture_mismatch)。core が本文を流したまま CREATIVE_ADMIN に渡す" },
279
+ listAssets: { method: "GET", path: "/v1/creatives/projects/:project/assets", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "assetList"] }, note: "フォント・端末の枠・背景の素材。R2 のキーごとに新しい行だけ。console の素材の画面" },
280
+ getAssetFile: { method: "GET", path: "/v1/creatives/projects/:project/assets/:asset", auth: m("creatives.read"), request: null, response: { status: 200, body: null }, note: "素材のファイルそのもの。R2 は公開の URL を持たないので、console と CLI はここで読む。同じキーの新しい素材に置き換わった物・まだ R2 に無い物は 404" },
281
+ listPages: { method: "GET", path: "/v1/creatives/projects/:project/pages", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "pageList"] }, note: "app-growth creatives pages list" },
282
+ putPage: { method: "PUT", path: "/v1/creatives/projects/:project/pages/:platform/:page", auth: m("creatives.page.write"), request: ["creative/page.schema.json", "putPageRequest"], response: { status: 200, body: ["creative/page.schema.json"] }, note: "作るか置き換える。app-growth creatives pages put" },
283
+ listStoreTexts: { method: "GET", path: "/v1/creatives/projects/:project/texts", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "textList"] }, note: "?platform=&page=&locale=&field=&status=。app-growth creatives texts list" },
284
+ getStoreTextHistory: { method: "GET", path: "/v1/creatives/projects/:project/texts/:platform/:page/:locale/:field", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "textList"] }, note: "1つの欄の全部の行。新しい順。app-growth creatives texts history" },
285
+ proposeStoreText: { method: "POST", path: "/v1/creatives/projects/:project/texts/:platform/:page/:locale/:field", auth: m("creatives.text.write"), request: ["creative/text.schema.json", "proposeStoreTextRequest"], response: { status: 201, body: ["creative/text.schema.json"] }, note: "proposed で足す。長さが creativeFields の上限を超えれば 400 invalid。app-growth creatives texts propose" },
286
+ approveStoreText: { method: "POST", path: "/v1/creatives/projects/:project/texts/revisions/:revision/approve", auth: m("creatives.text.approve"), request: null, response: { status: 200, body: ["creative/text.schema.json"] }, note: "proposed でない行は 409 conflict。審査の要らない欄はすぐ公開、要る欄は次のバージョンで公開(無ければ waiting_version)。app-growth creatives texts approve" },
287
+ rejectStoreText: { method: "POST", path: "/v1/creatives/projects/:project/texts/revisions/:revision/reject", auth: m("creatives.text.write"), request: null, response: { status: 200, body: ["creative/text.schema.json"] }, note: "proposed の行を rejected に。ほかは 409。app-growth creatives texts reject" },
288
+ generateVariant: { method: "POST", path: "/v1/creatives/projects/:project/variants", auth: m("creatives.variant.generate"), request: ["creative/variant.schema.json", "generateVariantRequest"], response: { status: 200, body: ["creative/metrics.schema.json", "run"] }, note: "変える所の一覧を作る。changes があればそのまま案にして done の回を、無ければ LLM のワークフローを始めて running の回を返す。202 は承認の依頼に使うので使わない。今の掲載が無ければ 409 conflict、予算で止めている時は 409 budget_stop。app-growth creatives variants generate" },
289
+ listVariants: { method: "GET", path: "/v1/creatives/projects/:project/variants", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "variantList"] }, note: "?platform=&page=&surface=&status=。app-growth creatives variants list" },
290
+ getVariant: { method: "GET", path: "/v1/creatives/projects/:project/variants/:variant", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/variant.schema.json"] }, note: "変える所の一覧と、基準にした今の掲載の参考の素材の id。app-growth creatives variants show" },
291
+ acceptVariant: { method: "POST", path: "/v1/creatives/projects/:project/variants/:variant/accept", auth: m("creatives.variant.approve"), request: null, response: { status: 200, body: ["creative/variant.schema.json"] }, note: "本人が案を採る。外には何も出さない。採った案は手元で作り込んでストアに出す。proposed でない案は 409 conflict。console の案の画面・app-growth creatives variants accept" },
292
+ rejectVariant: { method: "POST", path: "/v1/creatives/projects/:project/variants/:variant/reject", auth: m("creatives.variant.approve"), request: ["creative/variant.schema.json", "decideRequest"], response: { status: 200, body: ["creative/variant.schema.json"] }, note: "本人が案を断る。reason は任意。proposed でない案は 409 conflict。console の案の画面・app-growth creatives variants reject" },
293
+ withdrawVariant: { method: "POST", path: "/v1/creatives/projects/:project/variants/:variant/withdraw", auth: m("creatives.variant.write"), request: ["creative/variant.schema.json", "decideRequest"], response: { status: 200, body: ["creative/variant.schema.json"] }, note: "AI か作った人が案を取り下げる。reason が要る。generating・proposed でない案は 409 conflict。app-growth creatives variants withdraw" },
294
+ submitCreatives: { method: "POST", path: "/v1/creatives/projects/:project/submissions", auth: m("creatives.submit"), request: ["creative/admin.schema.json", "submitRequest"], response: { status: 200, body: ["creative/admin.schema.json", "submitResult"] }, note: "CPP・イベント・素材・PPO の treatment を1つの reviewSubmission にまとめて審査に出す。本人の確認。app-growth creatives submit" },
295
+ registerTest: { method: "PUT", path: "/v1/creatives/projects/:project/tests/:test", auth: m("creatives.test.write"), request: ["creative/test.schema.json", "registerTestRequest"], response: { status: 200, body: ["creative/test.schema.json"] }, note: "決めて始める。同じアプリの PPO が動いている時は 409 test_running。見分けられる差が足りない PPO は 409 underpowered。app-growth creatives tests register" },
296
+ stopTest: { method: "POST", path: "/v1/creatives/projects/:project/tests/:test/stop", auth: m("creatives.test.stop"), request: null, response: { status: 200, body: ["creative/test.schema.json"] }, note: "止める。勝ち負けは決めない。app-growth creatives tests stop" },
297
+ listTests: { method: "GET", path: "/v1/creatives/projects/:project/tests", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "testList"] }, note: "?status=。app-growth creatives tests list" },
298
+ getTest: { method: "GET", path: "/v1/creatives/projects/:project/tests/:test", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/test.schema.json", "testDetail"] }, note: "日ごとの配分つき。app-growth creatives tests show" },
299
+ listCreativeMetrics: { method: "GET", path: "/v1/creatives/projects/:project/metrics", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "metricList"] }, note: "?page=&variant=&since=&country=&source=。app-growth creatives metrics・insights" },
300
+ getTagEffects: { method: "GET", path: "/v1/creatives/effects", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/metrics.schema.json", "snapshot"] }, note: "?snapshot=。無ければ新しい物。全部の製品をまとめた値。app-growth creatives effects" },
301
+ listKeywords: { method: "GET", path: "/v1/creatives/projects/:project/keywords", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "keywordList"] }, note: "?country=&week=。app-growth creatives keywords list" },
302
+ syncKeywords: { method: "POST", path: "/v1/creatives/projects/:project/keywords/sync", auth: m("creatives.keyword.sync"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "keywordSyncResult"] }, note: "週に1回の取り込みをすぐ回す。app-growth creatives keywords sync" },
303
+ listSteps: { method: "GET", path: "/v1/creatives/projects/:project/steps", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "stepList"] }, note: "?status=waiting。app-growth creatives steps list" },
304
+ completeStep: { method: "POST", path: "/v1/creatives/projects/:project/steps/:step/complete", auth: m("creatives.step.complete"), request: ["creative/metrics.schema.json", "completeStepRequest"], response: { status: 200, body: ["creative/metrics.schema.json", "step"] }, note: "waiting でない手順は 409 conflict。app-growth creatives steps complete" },
305
+ runCreativeWeekly: { method: "POST", path: "/v1/creatives/runs", auth: m("creatives.run"), request: ["creative/metrics.schema.json", "runWeeklyRequest"], response: { status: 200, body: ["creative/metrics.schema.json", "run"] }, note: "週の流れをすぐ回し、running の回を返す。app-growth creatives runs weekly" },
306
+ createReference: { method: "POST", path: "/v1/creatives/references", auth: m("creatives.reference.write"), request: ["creative/reference.schema.json", "createReferenceRequest"], response: { status: 201, body: ["creative/reference.schema.json", "createReferenceResult"] }, note: "files か url。同じ sha256 のファイル1つの件があれば 200 で前の件(created: false)。URL が読めない・ログインが要れば 422 fetch_failed。Web のページを撮るキーが無ければ 501 browser_unavailable。app-growth creatives refs add" },
307
+ putReferenceFile: { method: "PUT", path: "/v1/creatives/references/:reference/files/:digest", auth: m("creatives.reference.write"), request: null, response: { status: 204, body: null }, note: ":digest はファイルの sha256。本文はファイルそのもの。Content-Length が要る。1つ 90MB まで(超えたら 413)。中身が sha256 と合わなければ 409 reference_mismatch。core が本文を流したまま CREATIVE_ADMIN に渡す" },
308
+ completeReference: { method: "POST", path: "/v1/creatives/references/:reference/complete", auth: m("creatives.reference.write"), request: null, response: { status: 200, body: ["creative/reference.schema.json"] }, note: "全部のファイルが R2 にあれば ready。無ければ 409 reference_mismatch" },
309
+ listReferences: { method: "GET", path: "/v1/creatives/references", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/reference.schema.json", "referenceList"] }, note: "?project=&subject=&tag=&source=&origin=&since=&q=&cursor=。新しい順に50件。app-growth creatives refs list" },
310
+ getReference: { method: "GET", path: "/v1/creatives/references/:reference", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/reference.schema.json"] }, note: "app-growth creatives refs show" },
311
+ updateReference: { method: "PATCH", path: "/v1/creatives/references/:reference", auth: m("creatives.reference.write"), request: ["creative/reference.schema.json", "updateReferenceRequest"], response: { status: 200, body: ["creative/reference.schema.json"] }, note: "書いた欄だけ変え、仮説をつなぐ。app-growth creatives refs update" },
312
+ getReferenceFile: { method: "GET", path: "/v1/creatives/references/:reference/files/:digest", auth: m("creatives.read"), request: null, response: { status: 200, body: null }, note: "ファイルそのもの。R2 は公開の URL を持たないので、console と CLI はここで読む" },
313
+ listCreativeRuns: { method: "GET", path: "/v1/creatives/runs", auth: m("creatives.read"), request: null, response: { status: 200, body: ["creative/admin.schema.json", "runList"] }, note: "?limit=1(1〜20)。app-growth creatives runs list" },
314
+ // R13 分析(docs/design/insights.md 13節)。core が受け、INSIGHTS_ADMIN(appgrowstack-insights の InsightsAdminRpc)に渡す。
315
+ // 製品をまたぐパス(signals・findings・portfolio・ledger)は、core が呼び手の組織と権限で見えるプロジェクトに絞って渡す
316
+ getInsightsMetric: { method: "GET", path: "/v1/insights/metrics/:project/:metric", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/metric.schema.json"] }, note: "?from=&to=(YYYY-MM-DD・既定は前の日までの28日)&dims=(カンマで3つまで)&audience=(real が既定・all・カンマの一覧)。metrics.toml に無い指標は 404。app-growth insights metric" },
317
+ compareInsightsMetric: { method: "GET", path: "/v1/insights/metrics/:project/:metric/compare", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/metric.schema.json", "compare"] }, note: "?at=(YYYY-MM-DD)&weeks=(1〜12・既定4)。前後 N 週と95%の幅・流入元の内訳。app-growth insights compare" },
318
+ runInsightsSql: { method: "POST", path: "/v1/insights/sql", auth: m("insights.sql"), request: ["insights/admin.schema.json"], response: { status: 200, body: ["insights/admin.schema.json", "sqlResult"] }, note: "データレイクへの1つの SELECT。決まりに合わなければ 400 sql_refused、スキャンの上限は 429 scan_limit。全部を insights_query に残す。app-growth insights sql" },
319
+ listInsightsSignals: { method: "GET", path: "/v1/insights/signals", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/signal.schema.json", "list"] }, note: "?project=&kind=&since=(YYYY-MM-DD)。app-growth insights signals" },
320
+ listInsightsFindings: { method: "GET", path: "/v1/insights/findings", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/finding.schema.json", "list"] }, note: "?project=&status=&since=。app-growth insights findings" },
321
+ getInsightsFinding: { method: "GET", path: "/v1/insights/findings/:finding", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/finding.schema.json", "detail"] }, note: "根拠の数ごとの SQL の文と結果つき。見えないプロジェクトの指摘は 404。app-growth insights findings show" },
322
+ decideInsightsFinding: { method: "POST", path: "/v1/insights/findings/:finding/decide", auth: m("insights.finding.decide"), request: ["insights/finding.schema.json", "decideRequest"], response: { status: 200, body: ["insights/finding.schema.json"] }, note: "採る・却下・後で。採ると仮説(open・出どころ finding)を作る。却下は note が要る。proposed と later でない指摘は 409 conflict。承認待ちの種類は insights_finding。app-growth insights findings decide" },
323
+ getInsightsPortfolio: { method: "GET", path: "/v1/insights/portfolio", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/portfolio.schema.json"] }, note: "?week=(月曜の日付)。無ければ新しい物。まだ1回も作っていなければ 404。app-growth insights portfolio" },
324
+ getCompetitors: { method: "GET", path: "/v1/insights/competitors/:project", auth: m("insights.read"), request: null, response: { status: 200, body: ["insights/competitors.schema.json"] }, note: "競合と自分のアプリの評価・評価の数・今のバージョン、集めた競合のレビュー(新しい順に200件)、自分の検索の順位。competitor-reviews の取り込みが書いた D1 を読む。app-growth insights competitors" },
325
+ collectInsights: { method: "POST", path: "/v1/insights/collect", auth: m("insights.collect"), request: ["insights/admin.schema.json", "collectRequest"], response: { status: 200, body: ["insights/admin.schema.json", "collectResult"] }, note: "取り込みの step だけをすぐ回し、step ごとの結果を返す。app-growth insights collect" },
326
+ listLedgerHypotheses: { method: "GET", path: "/v1/ledger/hypotheses", auth: m("ledger.read"), request: null, response: { status: 200, body: ["insights/ledger.schema.json", "hypothesisList"] }, note: "?project=&surface=&status=&outcome=。app-growth ledger list" },
327
+ addLedgerHypothesis: { method: "POST", path: "/v1/ledger/hypotheses", auth: m("ledger.write"), request: ["insights/ledger.schema.json", "hypothesisInput"], response: { status: 201, body: ["insights/ledger.schema.json"] }, note: "open で足す。source は呼び手の主体で決める(usr_ は owner・agt_ は agent)。app-growth ledger add" },
328
+ getLedgerHypothesis: { method: "GET", path: "/v1/ledger/hypotheses/:hypothesis", auth: m("ledger.read"), request: null, response: { status: 200, body: ["insights/ledger.schema.json", "hypothesisDetail"] }, note: "つながる物・学んだこと・広げた子の仮説つき。app-growth ledger show" },
329
+ updateLedgerHypothesis: { method: "PATCH", path: "/v1/ledger/hypotheses/:hypothesis", auth: m("ledger.write"), request: ["insights/ledger.schema.json", "hypothesisUpdate"], response: { status: 200, body: ["insights/ledger.schema.json"] }, note: "書いた項目だけ変える。outcome は書けない。できない状態の変え方は 409 conflict。app-growth ledger set" },
330
+ markLedgerApplied: { method: "POST", path: "/v1/ledger/hypotheses/:hypothesis/applied", auth: m("ledger.write"), request: ["insights/ledger.schema.json", "appliedRequest"], response: { status: 200, body: ["insights/ledger.schema.json"] }, note: "基盤に無い打ち手を当てた日を書き、testing にして確認の日を決める。open でなければ 409 conflict。app-growth ledger applied" },
331
+ listLedgerLearnings: { method: "GET", path: "/v1/ledger/learnings", auth: m("ledger.read"), request: null, response: { status: 200, body: ["insights/ledger.schema.json", "learningList"] }, note: "?project=&surface=&since=。app-growth ledger learnings" },
332
+ addLedgerLearning: { method: "POST", path: "/v1/ledger/learnings", auth: m("ledger.write"), request: ["insights/ledger.schema.json", "learningInput"], response: { status: 201, body: ["insights/ledger.schema.json", "learning"] }, note: "追記だけ。source は呼び手の主体で決める。app-growth ledger learn" },
333
+ searchLedger: { method: "GET", path: "/v1/ledger/search", auth: m("ledger.read"), request: null, response: { status: 200, body: ["insights/ledger.schema.json", "searchResult"] }, note: "?q=(3文字以上)&project=&surface=&kind=&limit=(1〜100・既定20)。仮説・結論・学んだこと・参考の素材のメモを1つの問いで探す。app-growth ledger search" },
334
+ };
335
+ /** core の Worker の変数(KD-7)。Access の JWT の aud として受ける値をカンマでつないだ物(admin と console の Access のアプリの AUD) */
336
+ export const CORE_ACCESS_AUDS_VAR = "ACCESS_AUDS";
337
+ /** Worker・ドメインの名前(設計 1.5節)。staging は後ろに -staging、ドメインは api-staging. のように1階層 */
338
+ export const workers = {
339
+ api: { name: "appgrowstack-api", host: "api.appgrowstack.com", stagingHost: "api-staging.appgrowstack.com" },
340
+ core: { name: "appgrowstack-core", host: "admin.appgrowstack.com", stagingHost: "admin-staging.appgrowstack.com", d1: "appgrowstack-core" },
341
+ notify: { name: "appgrowstack-notify", host: null, stagingHost: null },
342
+ /** R12 ストアの素材(docs/design/creatives.md)。道を持たない。core が Service Binding CREATIVE_ADMIN で呼ぶ。R2 は appgrowstack-creative-assets */
343
+ creative: { name: "appgrowstack-creative", host: null, stagingHost: null, d1: "appgrowstack-creative" },
344
+ /** R13 分析(docs/design/insights.md)。道を持たない。core が INSIGHTS_ADMIN と INSIGHTS、notify と creative が INSIGHTS で呼ぶ。R2 は appgrowstack-insights-raw */
345
+ insights: { name: "appgrowstack-insights", host: null, stagingHost: null, d1: "appgrowstack-insights-production" },
346
+ playbook: { name: "appgrowstack-playbook", host: "playbook.appgrowstack.com", stagingHost: null },
347
+ /** ダッシュボード(docs/dashboard.md)。core の fetch を Service Binding CORE で呼ぶだけ。core は Access の AUD を ACCESS_AUDS(admin と console)で受ける(KD-7) */
348
+ console: { name: "appgrowstack-console", host: "console.appgrowstack.com", stagingHost: "console-staging.appgrowstack.com" },
349
+ };
@@ -0,0 +1,15 @@
1
+ export * from "./generated/schema.js";
2
+ export * from "./rpc.js";
3
+ export * from "./http.js";
4
+ export * from "./d1.js";
5
+ export * from "./events.js";
6
+ export * from "./touch.js";
7
+ export * from "./revenuecat.js";
8
+ export * from "./access.js";
9
+ export * from "./sessions.js";
10
+ export * from "./registry.js";
11
+ export * from "./reviews.js";
12
+ export * from "./prices.js";
13
+ export * from "./creatives.js";
14
+ export * from "./ledger.js";
15
+ export * from "./audience.js";
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ // app-growth の約束事。schema/ から作った型・RPC・HTTP の API・D1 の表・出来事の名前
2
+ export * from "./generated/schema.js";
3
+ export * from "./rpc.js";
4
+ export * from "./http.js";
5
+ export * from "./d1.js";
6
+ export * from "./events.js";
7
+ export * from "./touch.js";
8
+ export * from "./revenuecat.js";
9
+ export * from "./access.js";
10
+ export * from "./sessions.js";
11
+ export * from "./registry.js";
12
+ export * from "./reviews.js";
13
+ export * from "./prices.js";
14
+ export * from "./creatives.js";
15
+ export * from "./ledger.js";
16
+ export * from "./audience.js";
@@ -0,0 +1,16 @@
1
+ import type { LedgerOutcome, LedgerResult } from "./generated/schema.js";
2
+ /** outcome を決める確率の境。仮説の側が良い確率がこれを超えれば supported、比べる側が良い確率がこれを超えれば rejected */
3
+ export declare const LEDGER_OUTCOME_THRESHOLD = 0.95;
4
+ /** ledgerOutcome の入力。complete は数がそろって比べられたか(前か後の窓に記録が無い・実験の人数が足りない時は false) */
5
+ export interface LedgerOutcomeInput {
6
+ result: Pick<LedgerResult, "method" | "probability_better"> | null;
7
+ complete: boolean;
8
+ }
9
+ /**
10
+ * 写した数から outcome を決める。判定の表は schema/cases/insights/outcome.json。
11
+ * 数が無い・そろわなかった時は unmeasured(検証できなかった)。数がそろって比べたが、前後の比べ(無作為に分けていない)・確率が分からない・
12
+ * 95%に届かない時は inconclusive(差が分からない)。前後の比べの outcome は本人だけが変えられる
13
+ */
14
+ export declare function ledgerOutcome(input: LedgerOutcomeInput): LedgerOutcome;
15
+ /** 仮説の id の形(schema の LedgerHypothesisId) */
16
+ export declare const LEDGER_HYPOTHESIS_ID: RegExp;
package/dist/ledger.js ADDED
@@ -0,0 +1,21 @@
1
+ /** outcome を決める確率の境。仮説の側が良い確率がこれを超えれば supported、比べる側が良い確率がこれを超えれば rejected */
2
+ export const LEDGER_OUTCOME_THRESHOLD = 0.95;
3
+ /**
4
+ * 写した数から outcome を決める。判定の表は schema/cases/insights/outcome.json。
5
+ * 数が無い・そろわなかった時は unmeasured(検証できなかった)。数がそろって比べたが、前後の比べ(無作為に分けていない)・確率が分からない・
6
+ * 95%に届かない時は inconclusive(差が分からない)。前後の比べの outcome は本人だけが変えられる
7
+ */
8
+ export function ledgerOutcome(input) {
9
+ const { result } = input;
10
+ if (result === null || !input.complete)
11
+ return "unmeasured";
12
+ if (result.method !== "experiment" || result.probability_better === null)
13
+ return "inconclusive";
14
+ if (result.probability_better > LEDGER_OUTCOME_THRESHOLD)
15
+ return "supported";
16
+ if (1 - result.probability_better > LEDGER_OUTCOME_THRESHOLD)
17
+ return "rejected";
18
+ return "inconclusive";
19
+ }
20
+ /** 仮説の id の形(schema の LedgerHypothesisId) */
21
+ export const LEDGER_HYPOTHESIS_ID = /^hyp_[A-Za-z0-9]{16}$/;
@@ -0,0 +1,25 @@
1
+ /** 入力・出力の $/100万トークン(2026-11-21 に公式の頁で確かめた)。キャッシュの読みは入力の0.1倍・書きは1.25倍、Message Batches は半額 */
2
+ export declare const AI_PRICES: Readonly<Record<string, {
3
+ input: number;
4
+ output: number;
5
+ }>>;
6
+ /** AI を呼ぶ所と止める割合の鍵。notify_copy のほかは core の usage_ai.feature の値(notify_copy は notify の ai_usage に書く) */
7
+ export declare const AI_FEATURES: readonly ["support_draft", "support_review_draft", "support_feedback_topic", "session_summary", "session_summary_auto", "session_digest", "notify_copy"];
8
+ export type AiFeature = (typeof AI_FEATURES)[number];
9
+ /** 月の予算の何割で止めるか。自動の物は80%、人が待つ物は100% */
10
+ export declare const AI_BUDGET_STOP: Readonly<Record<AiFeature, number>>;
11
+ /** AI_MONTHLY_BUDGET_USD が無いときの月の予算(docs/cost.md 6.1節) */
12
+ export declare const DEFAULT_AI_MONTHLY_BUDGET_USD = 25;
13
+ /** Anthropic の response.usage のうち費用になる物 */
14
+ export interface AiUsage {
15
+ input_tokens: number;
16
+ output_tokens: number;
17
+ cache_creation_input_tokens?: number | null;
18
+ cache_read_input_tokens?: number | null;
19
+ }
20
+ /** 1回の呼び出しの費用(マイクロドル・切り上げ) */
21
+ export declare function aiCostMicros(model: string, usage: AiUsage, batch: boolean): number;
22
+ /** 月の予算(ドル)。vars の文字が数でなければ既定 */
23
+ export declare function aiMonthlyBudgetUsd(value: string | undefined): number;
24
+ /** usage_ai.month(UTC の YYYY-MM) */
25
+ export declare function aiMonth(now: number): string;
package/dist/prices.js ADDED
@@ -0,0 +1,41 @@
1
+ // Anthropic の値段の表と、AI の費用の数え方(docs/cost.md 3節・6.1節・6.4節の CS4・CS7)。
2
+ // core は呼ぶたびに response.usage を core の D1 の usage_ai に、notify は自分の D1 の ai_usage に1行書く。予算(AI_MONTHLY_BUDGET_USD)は core だけが持ち、
3
+ // notify の分を NOTIFY_ADMIN.aiUsage で読んで足した月の合計で判定し、notify の文面を止めるかは NOTIFY_ADMIN.setAiStop で渡す。
4
+ // 止める順: 予算の80%で自動の物(自動の要約・週のまとめ・声の話題・通知の文面)、100%で人が待つ物(問い合わせとレビューの下書き・その場の要約)
5
+ /** 入力・出力の $/100万トークン(2026-11-21 に公式の頁で確かめた)。キャッシュの読みは入力の0.1倍・書きは1.25倍、Message Batches は半額 */
6
+ export const AI_PRICES = {
7
+ "claude-opus-5-5": { input: 4, output: 20 },
8
+ "claude-sonnet-5-5": { input: 2, output: 10 },
9
+ "claude-haiku-5-5": { input: 0.1, output: 0.5 },
10
+ };
11
+ /** 表に無いモデル(fallbacks で替わった物など)は一番高い値段で数える。少なく数えて予算を越えないように */
12
+ const UNKNOWN_MODEL_PRICE = { input: 4, output: 20 };
13
+ /** AI を呼ぶ所と止める割合の鍵。notify_copy のほかは core の usage_ai.feature の値(notify_copy は notify の ai_usage に書く) */
14
+ export const AI_FEATURES = ["support_draft", "support_review_draft", "support_feedback_topic", "session_summary", "session_summary_auto", "session_digest", "notify_copy"];
15
+ /** 月の予算の何割で止めるか。自動の物は80%、人が待つ物は100% */
16
+ export const AI_BUDGET_STOP = {
17
+ support_draft: 1,
18
+ support_review_draft: 1,
19
+ session_summary: 1,
20
+ support_feedback_topic: 0.8,
21
+ session_summary_auto: 0.8,
22
+ session_digest: 0.8,
23
+ notify_copy: 0.8,
24
+ };
25
+ /** AI_MONTHLY_BUDGET_USD が無いときの月の予算(docs/cost.md 6.1節) */
26
+ export const DEFAULT_AI_MONTHLY_BUDGET_USD = 25;
27
+ /** 1回の呼び出しの費用(マイクロドル・切り上げ) */
28
+ export function aiCostMicros(model, usage, batch) {
29
+ const price = AI_PRICES[model] ?? UNKNOWN_MODEL_PRICE;
30
+ const input = usage.input_tokens * price.input + (usage.cache_creation_input_tokens ?? 0) * price.input * 1.25 + (usage.cache_read_input_tokens ?? 0) * price.input * 0.1;
31
+ return Math.ceil((input + usage.output_tokens * price.output) * (batch ? 0.5 : 1));
32
+ }
33
+ /** 月の予算(ドル)。vars の文字が数でなければ既定 */
34
+ export function aiMonthlyBudgetUsd(value) {
35
+ const n = Number(value);
36
+ return value !== undefined && value !== "" && Number.isFinite(n) && n > 0 ? n : DEFAULT_AI_MONTHLY_BUDGET_USD;
37
+ }
38
+ /** usage_ai.month(UTC の YYYY-MM) */
39
+ export function aiMonth(now) {
40
+ return new Date(now).toISOString().slice(0, 7);
41
+ }