@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/rpc.d.ts ADDED
@@ -0,0 +1,929 @@
1
+ import type { ApproveVariantResponse, AttributionResponse, CreateInviteInput, CreateLinkInput, CreateFeedbackInput, CreateFeedbackResponse, CreateTicketInput, CreateTicketResponse, ForgetInput, IdentifyInput, IdentifyResult, Link, NotifyCampaignState, NotifyCampaignStateList, ListArticlesResponse, ListTicketsResponse, PostTicketMessageRequest, TicketAttachment, TicketMessage, NotifyOpenedRequest, NotifyRunList, NotifyVariant, NotifyVariantList, NotifyVariantStatus, NotifyExplain, NotifyPreview, NotifyStats, NotifyGuardrailReport, SessionBatch, SessionBatchAnswer, PersonId, Project, RecordAttributionInput, RefreshWidgetsInput, RefreshWidgetsResult, RegisterDeviceInput, RegisterWidgetPushInput, SendInput, SendResult, SubscriptionInput, TouchInput, TouchResult, TraitValue, TrackInput, TrackResult, UnregisterDeviceInput, UnregisterWidgetPushInput, CaptureSet, CaptureFile, CaptureSetList, CreateCaptureSetRequest, CreateCaptureSetResult, CreativeBrand, CreativeBrandBody, CreateCreativeAssetUploadRequest, CreativeAssetList, CreativeAssetUpload, CreativePageList, CreativePage, PutCreativePageRequest, StoreTextList, StoreText, StoreTextField, StoreTextStatus, ProposeStoreTextRequest, GenerateCreativeVariantRequest, CreativeRun, CreativeSurface, CreativeVariantStatus, CreativeVariantList, CreativeVariant, SubmitCreativesRequest, SubmitCreativesResult, RegisterCreativeTestRequest, CreativeTest, CreativeTestStatus, CreativeTestList, CreativeTestDetail, CreativeMetricList, TagEffectSnapshot, CreativeKeywordList, CreativeKeywordSyncResult, CreativeStepList, CreativeStep, CompleteCreativeStepRequest, CreativeRunList, CreateReferenceRequest, CreateReferenceResult, CreativeReference, CreativeReferenceList, CreativeReferenceOrigin, CreativeReferenceSource, UpdateReferenceRequest, Platform, PersonKey, InsightsMetricAnswer, InsightsMetricCompare, InsightsSqlRequest, InsightsSqlResult, InsightsSignalKind, InsightsSignalList, InsightsFindingStatus, InsightsFindingList, InsightsFindingDetail, InsightsFindingDecision, InsightsFinding, PortfolioReport, CompetitorReport, InsightsCollectRequest, InsightsCollectResult, LedgerHypothesis, LedgerHypothesisList, LedgerHypothesisDetail, LedgerHypothesisInput, LedgerHypothesisUpdate, LedgerHypothesisStatus, LedgerAppliedRequest, LedgerConclusionInput, LedgerLearning, LedgerLearningInput, LedgerLearningList, LedgerLearningSource, LedgerLink, LedgerLinkKind, LedgerOutcome, LedgerSearchResult, LedgerSource, LedgerSurface, Audience } from "./generated/schema.js";
2
+ export declare const APPGROWSTACK_BINDING = "APPGROWSTACK";
3
+ export declare const APPGROWSTACK_SERVICE = "appgrowstack-core";
4
+ export declare const APPGROWSTACK_ENTRYPOINT = "AppGrowStackRpc";
5
+ /** アプリの Worker の APPGROWSTACK の binding の props(ctx.props)。core はこの project だけを受ける */
6
+ export interface AppGrowStackBindingProps {
7
+ project: string;
8
+ }
9
+ /** `env.APPGROWSTACK` の型 */
10
+ export interface AppGrowStackService {
11
+ /** 判定と成果に要る出来事を入れる。1回の呼び出しは1人分(100件まで) */
12
+ track(input: TrackInput): Promise<TrackResult>;
13
+ /** 今の値を入れ、install と uid をつなぐ。返る person_id を端末の SDK の person に渡す */
14
+ identify(input: IdentifyInput): Promise<IdentifyResult>;
15
+ /** アカウントの削除 */
16
+ forget(input: ForgetInput): Promise<void>;
17
+ /** アプリの Worker が受けた RevenueCat の webhook の1件 */
18
+ subscription(input: SubscriptionInput): Promise<void>;
19
+ /** 1人に触れた1回を数える(record)・触れる前に1回分を取る(reserve) */
20
+ touch(input: TouchInput): Promise<TouchResult>;
21
+ send(input: SendInput): Promise<SendResult>;
22
+ registerDevice(input: RegisterDeviceInput): Promise<void>;
23
+ unregisterDevice(input: UnregisterDeviceInput): Promise<void>;
24
+ registerWidgetPush(input: RegisterWidgetPushInput): Promise<void>;
25
+ unregisterWidgetPush(input: UnregisterWidgetPushInput): Promise<void>;
26
+ refreshWidgets(input: RefreshWidgetsInput): Promise<RefreshWidgetsResult>;
27
+ /** 短いリンクを作る(投稿のリンク・アプリの中へのリンク)。招待は createInvite */
28
+ createLink(input: CreateLinkInput): Promise<Link>;
29
+ /**
30
+ * 招待のリンクを作る。招いた人(actor)を code に結び、招かれた人が入れて最初に開くと招いた人に invite_accepted が付く。
31
+ * 同じ人の同じ url は前のリンクを返す。招く相手に特典は付けない
32
+ */
33
+ createInvite(input: CreateInviteInput): Promise<Link>;
34
+ /** アプリの Worker が自分の API で受けた流入元の手がかりを渡す */
35
+ recordAttribution(input: RecordAttributionInput): Promise<AttributionResponse>;
36
+ /** アプリの Worker が自分の画面(Web のフォーム)で受けた問い合わせを渡す */
37
+ createTicket(input: CreateTicketInput): Promise<CreateTicketResponse>;
38
+ }
39
+ /** RPC の名前と、入力と答えの schema(schema/ からの相対の道と $defs の名前)。core はこれで受けた値を確かめる */
40
+ export declare const rpcSchemas: {
41
+ readonly track: {
42
+ readonly input: readonly ["people/track.schema.json"];
43
+ readonly result: readonly ["people/track.schema.json", "result"];
44
+ };
45
+ readonly identify: {
46
+ readonly input: readonly ["people/identify.schema.json"];
47
+ readonly result: readonly ["people/identify.schema.json", "result"];
48
+ };
49
+ readonly forget: {
50
+ readonly input: readonly ["people/forget.schema.json"];
51
+ readonly result: null;
52
+ };
53
+ readonly subscription: {
54
+ readonly input: readonly ["people/subscription.schema.json"];
55
+ readonly result: null;
56
+ };
57
+ readonly touch: {
58
+ readonly input: readonly ["people/touch.schema.json"];
59
+ readonly result: readonly ["people/touch.schema.json", "result"];
60
+ };
61
+ readonly send: {
62
+ readonly input: readonly ["notify/send.schema.json"];
63
+ readonly result: readonly ["notify/send.schema.json", "result"];
64
+ };
65
+ readonly registerDevice: {
66
+ readonly input: readonly ["notify/device.schema.json"];
67
+ readonly result: null;
68
+ };
69
+ readonly unregisterDevice: {
70
+ readonly input: readonly ["notify/device.schema.json", "unregister"];
71
+ readonly result: null;
72
+ };
73
+ readonly registerWidgetPush: {
74
+ readonly input: readonly ["notify/device.schema.json", "registerWidgetPush"];
75
+ readonly result: null;
76
+ };
77
+ readonly unregisterWidgetPush: {
78
+ readonly input: readonly ["notify/device.schema.json", "unregisterWidgetPush"];
79
+ readonly result: null;
80
+ };
81
+ readonly refreshWidgets: {
82
+ readonly input: readonly ["notify/device.schema.json", "refreshWidgets"];
83
+ readonly result: readonly ["notify/device.schema.json", "refreshWidgetsResult"];
84
+ };
85
+ readonly createLink: {
86
+ readonly input: readonly ["links/link.schema.json", "createInput"];
87
+ readonly result: readonly ["links/link.schema.json"];
88
+ };
89
+ readonly createInvite: {
90
+ readonly input: readonly ["links/link.schema.json", "inviteInput"];
91
+ readonly result: readonly ["links/link.schema.json"];
92
+ };
93
+ readonly recordAttribution: {
94
+ readonly input: readonly ["links/attribution.schema.json", "recordInput"];
95
+ readonly result: readonly ["links/attribution.schema.json", "response"];
96
+ };
97
+ readonly createTicket: {
98
+ readonly input: readonly ["support/ticket.schema.json", "createInput"];
99
+ readonly result: readonly ["support/ticket.schema.json", "createResponse"];
100
+ };
101
+ };
102
+ /**
103
+ * Worker の間の RPC(アプリの APPGROWSTACK・api の CORE・core の NOTIFY と NOTIFY_ADMIN)が投げる誤りの code。
104
+ * Service Binding は Error の name を運ばない("Error" になり、message の頭に元の name が付く)ので、name では見分けない。
105
+ * 投げる側は AppGrowStackRpcError(message の頭に「[<code>] 」を書く)、受ける側は rpcErrorCode(error) で code を読む
106
+ */
107
+ export declare const RPC_ERROR_CODES: {
108
+ /** 入力が schema に合わない */
109
+ readonly input: "input";
110
+ /** 知らないプロジェクト・その機能が off */
111
+ readonly project: "project";
112
+ /** 外(Apple の AdServices など)がまだ答えない。何も残していないので、後で同じ物を送り直す */
113
+ readonly retryLater: "retry_later";
114
+ /** 回数の上限(問い合わせは install_id ごとに1時間に5件・添付は1件に4枚) */
115
+ readonly rateLimited: "rate_limited";
116
+ /** binding の props の project と入力の project が違う・props が無い(AC-7) */
117
+ readonly forbidden: "forbidden";
118
+ /** 知らない物(notify の施策・案・問い合わせ)。管理の道は 404 にする */
119
+ readonly notFound: "not_found";
120
+ /** 今の状態ではできない(proposed でない案の承認・解決にした問い合わせへの返事)。管理の道は 409 にする */
121
+ readonly conflict: "conflict";
122
+ /** 約束にはあるがまだ作っていない(型だけ通すスタブ・AGENTS.md)。api と管理の道は 501 にし、core_error として数えない */
123
+ readonly notImplemented: "not_implemented";
124
+ /** 撮影の組のファイルが、組を作った時の sha256・寸法と合わない(R12)。管理の道は 409 capture_mismatch にする。message の2行目からは1行に1つ「<locale>/<device>/<screen>/<kind>: <理由>」 */
125
+ readonly captureMismatch: "capture_mismatch";
126
+ /** 参考の素材の URL を読めない・ログインが要る(R12)。管理の道は 422 fetch_failed にする */
127
+ readonly fetchFailed: "fetch_failed";
128
+ /** 参考の素材のファイルが sha256 と合わない・R2 に無い(R12)。管理の道は 409 reference_mismatch にする */
129
+ readonly referenceMismatch: "reference_mismatch";
130
+ /** Web のページを撮る Browser Run のキーが無い・断られた(R12)。管理の道は 501 browser_unavailable にする */
131
+ readonly browserUnavailable: "browser_unavailable";
132
+ /** R13 の SQL が決まりに合わない(1つの SELECT でない・day の条件が無い・400日を超える・person_key を返す)。管理の道は 400 sql_refused にする */
133
+ readonly sqlRefused: "sql_refused";
134
+ /** R13 の1回か1日のスキャンの上限を超えた。管理の道は 429 scan_limit にする */
135
+ readonly scanLimit: "scan_limit";
136
+ };
137
+ export type RpcErrorCode = (typeof RPC_ERROR_CODES)[keyof typeof RPC_ERROR_CODES];
138
+ /**
139
+ * RPC で投げる誤り。message は「[<code>] <中身>」。name は既定の "Error" のまま(name を変えると workerd が message の頭に足す)。
140
+ * 同じ Worker の中では code の欄でも読めるが、Service Binding を越えると欄は運ばれないことがあるので、読むのはいつも rpcErrorCode
141
+ */
142
+ export declare class AppGrowStackRpcError extends Error {
143
+ readonly code: RpcErrorCode;
144
+ constructor(code: RpcErrorCode, message: string);
145
+ }
146
+ /** 約束にはあるがまだ作っていない物のスタブが投げる誤り(code not_implemented) */
147
+ export declare function notImplemented(what: string): AppGrowStackRpcError;
148
+ /** 受けた誤りの code。AppGrowStackRpcError でない誤り(通信の失敗・中の誤り)は null */
149
+ export declare function rpcErrorCode(error: unknown): RpcErrorCode | null;
150
+ /** 受けた誤りの中身(頭の「[<code>] 」を外した物)。人に見せる誤りの文に使う */
151
+ export declare function rpcErrorMessage(error: unknown): string;
152
+ export declare const APPGROWSTACK_API_ENTRYPOINT = "AppGrowStackApiRpc";
153
+ /** appgrowstack-api の CORE の binding の props。これが無い呼び出しを AppGrowStackApiRpc は断る(AC-7) */
154
+ export interface AppGrowStackApiBindingProps {
155
+ caller: "appgrowstack-api";
156
+ }
157
+ /** 端末に配る組(appgrowstack-api がキャッシュして返す) */
158
+ export interface ServedSet {
159
+ project: string;
160
+ version: number;
161
+ /** "v<version>"。止めている間は "v<version>-paused" */
162
+ etag: string;
163
+ /** 端末に返す組の JSON(CampaignSet)。何も外れなければ送った時の文字列そのもの(sha256 が push の答えと同じ) */
164
+ body: string;
165
+ }
166
+ /** appgrowstack-api の wrangler.jsonc: "services": [{ "binding": "CORE", "service": "appgrowstack-core", "entrypoint": "AppGrowStackApiRpc", "props": { "caller": "appgrowstack-api" } }] */
167
+ export interface AppGrowStackApiService {
168
+ /** 公開キー(active な物)からプロジェクト。知らない・revoke したキーは null */
169
+ projectForPublicKey(publicKey: string): Promise<Project | null>;
170
+ /** 端末に配る組。知らないキーは null(api が 404 unknown_key)。キャッシュは api が持つ */
171
+ readCampaignSet(publicKey: string): Promise<ServedSet | null>;
172
+ /** 端末に配る R9 の組(K6-3)。知らないキーは null。config が off・paused なら今のバージョンの番号のまま空の組(ETag の後ろに -paused)。形は ServedSet と同じ */
173
+ readConfigSet(publicKey: string): Promise<ServedSet | null>;
174
+ /**
175
+ * POST /v1/notify/opened(api が公開キーからプロジェクトを引き、notify が on のときだけ呼ぶ)。core が appgrowstack-notify に記録させ、
176
+ * 人の像の「最後に通知を開いた」を進める。知らない send_id・ほかのプロジェクトの send_id でも投げない(端末には 204)
177
+ */
178
+ notifyOpened(input: {
179
+ project: string;
180
+ request: NotifyOpenedRequest;
181
+ }): Promise<void>;
182
+ /** POST /v1/links/attributions(links が off なら api が呼ばずに organic)。同じ install_id の2回目は最初の答え */
183
+ recordAttribution(input: RecordAttributionInput): Promise<AttributionResponse>;
184
+ /** 製品のドメインの /l/:code・/go/:code。links_click に1行足し、行き先を返す。知らない・止めたリンクは製品のトップ。知らない Host は null */
185
+ openLink(input: OpenLinkInput): Promise<{
186
+ location: string;
187
+ } | null>;
188
+ /** POST /v1/support/tickets。install_id ごとに1時間に5件を超えたら code rate_limited */
189
+ createTicket(input: CreateTicketInput): Promise<CreateTicketResponse>;
190
+ /** GET /v1/support/tickets。その owner_token の問い合わせを新しい順に50件まで */
191
+ listTickets(input: {
192
+ project: string;
193
+ owner_token: string;
194
+ }): Promise<ListTicketsResponse>;
195
+ /** POST /v1/support/tickets/:ticket_id/messages。owner_token の問い合わせでなければ null(端末には 404) */
196
+ postTicketMessage(input: {
197
+ project: string;
198
+ owner_token: string;
199
+ ticket_id: string;
200
+ request: PostTicketMessageRequest;
201
+ }): Promise<TicketMessage | null>;
202
+ /**
203
+ * POST /v1/support/tickets/:ticket_id/attachments。owner_token の問い合わせでなければ null。
204
+ * 形の違う・大きすぎる画像は code input、4枚を超えたら code rate_limited
205
+ */
206
+ uploadAttachment(input: {
207
+ project: string;
208
+ owner_token: string;
209
+ ticket_id: string;
210
+ content_type: string;
211
+ body: ArrayBuffer;
212
+ }): Promise<TicketAttachment | null>;
213
+ /**
214
+ * POST /v1/support/feedback。アンケートで書いた文・設定から送った声を受け、AI に話題を付けさせる(Queue)。
215
+ * install_id ごとに1時間に5件を超えたら code rate_limited。support が off・paused なら code project
216
+ */
217
+ createFeedback(input: CreateFeedbackInput): Promise<CreateFeedbackResponse>;
218
+ /** GET /v1/support/articles?lang=。その言語が無い記事は言語の頭・en・その記事の最初の言語 */
219
+ listArticles(input: {
220
+ project: string;
221
+ lang: string;
222
+ }): Promise<ListArticlesResponse>;
223
+ /** POST /v1/sessions/batches。バッチを Cloudflare R2 に書き、索引と数を足す。始まりのバッチの答えに upload_token */
224
+ sessionBatch(input: {
225
+ project: string;
226
+ batch: SessionBatch;
227
+ received_at: number;
228
+ }): Promise<SessionBatchAnswer>;
229
+ /**
230
+ * PUT /v1/sessions/:session_id/segments/:seq。upload_token は api が HMAC で確かめてから渡す。
231
+ * 同じ seq の2回目は捨てる(端末には 204)。形の違う塊は code input
232
+ */
233
+ sessionSegment(input: {
234
+ project: string;
235
+ install_id: string;
236
+ session_id: string;
237
+ seq: number;
238
+ body: ReadableStream<Uint8Array>;
239
+ bytes: number;
240
+ }): Promise<void>;
241
+ /**
242
+ * 端末の SDK が頭 AppGrowStack-Device・AppGrowStack-Install を付けて api を呼んだ1回。api は答えを返した後(waitUntil)に呼び、待たない。
243
+ * install と端末をつなぎ(people_device)、ネットワーク(AS 番号)と端末のマークから人の audience を決める。開いた本人のリンクがあれば端末に owner のマークを付ける
244
+ */
245
+ observeDevice(input: ObserveDeviceInput): Promise<void>;
246
+ /** GET /v1/registry/owner-claims/:token。開いた IP と OS を残す。答えはページに書く状態 */
247
+ openOwnerClaim(input: {
248
+ token: string;
249
+ ip: string | null;
250
+ platform: "ios" | "android" | "other";
251
+ at: number;
252
+ }): Promise<OwnerClaimOpened>;
253
+ }
254
+ /** api が端末の1回から core に渡す物。IP そのものは本人のリンクを開いている間だけ比べ、残さない */
255
+ export interface ObserveDeviceInput {
256
+ project: string;
257
+ install_id: string;
258
+ /** DeviceHash */
259
+ device: string;
260
+ /** request.cf.asn。無ければ null */
261
+ asn: number | null;
262
+ /** request.cf.asOrganization。無ければ null */
263
+ as_org: string | null;
264
+ /** api の ipKey(IPv4 はそのまま・IPv6 は /64) */
265
+ ip: string | null;
266
+ /** AppGrowStack-Client の頭から */
267
+ platform: "ios" | "android" | "other";
268
+ at: number;
269
+ }
270
+ /** 本人のリンクを開いた答え。opened は今開いた、claimed はもう端末に付けた、expired は切れた・知らない */
271
+ export type OwnerClaimOpened = {
272
+ state: "opened";
273
+ project: string;
274
+ expires_at: number;
275
+ } | {
276
+ state: "claimed";
277
+ project: string;
278
+ } | {
279
+ state: "expired";
280
+ };
281
+ /** api の SESSION_LIVE の Durable Object の binding(script_name: appgrowstack-core・class SessionLive)。idFromName("<project>:<install_id>") */
282
+ export declare const SESSION_LIVE_BINDING = "SESSION_LIVE";
283
+ export declare const SESSION_LIVE_CLASS = "SessionLive";
284
+ /** appgrowstack-api が短いリンクの1回から core に渡す物。IP と User-Agent そのものは渡さない */
285
+ export interface OpenLinkInput {
286
+ /** リクエストの Host(registry_project.web_domain で製品を決める。www. は外して見る) */
287
+ host: string;
288
+ kind: "l" | "go";
289
+ code: string;
290
+ /** User-Agent から */
291
+ platform: "ios" | "android" | "other";
292
+ country: string | null;
293
+ referer_host: string | null;
294
+ at: number;
295
+ }
296
+ export declare const NOTIFY_BINDING = "NOTIFY";
297
+ export declare const NOTIFY_SERVICE = "appgrowstack-notify";
298
+ export declare const NOTIFY_ENTRYPOINT = "NotifyRpc";
299
+ /** actor を core が人の id にした形 */
300
+ export type WithPerson<T> = Omit<T, "actor"> & {
301
+ person_id: PersonId;
302
+ };
303
+ /** R2 が入れた出来事のうち、R5 が成果ときっかけに使う物 */
304
+ export interface NotifyEventsInput {
305
+ project: string;
306
+ person_id: PersonId;
307
+ events: {
308
+ id: string;
309
+ name: string;
310
+ at: number;
311
+ }[];
312
+ }
313
+ /** 通知の配信のうち、人に触れた1回(送った・送っている物)。core の touch が R4 の数と合わせて数える */
314
+ export interface PushTouch {
315
+ at: number;
316
+ class: "lifecycle" | "promotional" | "transactional";
317
+ campaign: string;
318
+ /** send_id */
319
+ key: string;
320
+ }
321
+ /**
322
+ * core の `NOTIFY` の型(appgrowstack-notify の NotifyRpc)。人は core が決めた person_id で渡す。
323
+ * notify は人の表(people_*)を書かず、core の D1 を読むだけ
324
+ */
325
+ export interface AppGrowStackNotifyService {
326
+ /** identify の trait をアプリの TraitSchema で確かめて返す(合わなければ code input)。notify が知らないプロジェクトはそのまま返す */
327
+ validateTraits(input: {
328
+ project: string;
329
+ traits: Record<string, TraitValue | null>;
330
+ }): Promise<Record<string, TraitValue | null>>;
331
+ /** core が入れた出来事のあと:成果を数え、event のきっかけの施策を判断する */
332
+ afterEvents(input: NotifyEventsInput): Promise<void>;
333
+ send(input: WithPerson<SendInput>): Promise<SendResult>;
334
+ registerDevice(input: WithPerson<RegisterDeviceInput>): Promise<void>;
335
+ unregisterDevice(input: UnregisterDeviceInput): Promise<void>;
336
+ registerWidgetPush(input: WithPerson<RegisterWidgetPushInput>): Promise<void>;
337
+ unregisterWidgetPush(input: UnregisterWidgetPushInput): Promise<void>;
338
+ refreshWidgets(input: WithPerson<RefreshWidgetsInput>): Promise<RefreshWidgetsResult>;
339
+ /** 通知を押した。そのプロジェクトの送った send_id なら、その人の id */
340
+ opened(input: {
341
+ project: string;
342
+ send_id: string;
343
+ }): Promise<{
344
+ person_id: PersonId;
345
+ } | null>;
346
+ /** アカウントの削除。端末を消し、配信の記録からその人の id を外す */
347
+ forget(input: {
348
+ project: string;
349
+ person_id: PersonId;
350
+ }): Promise<void>;
351
+ /** 人を寄せた(identify の merged_from)。from の端末・配信・入りを into に付け替える */
352
+ mergePerson(input: {
353
+ project: string;
354
+ from: PersonId;
355
+ into: PersonId;
356
+ }): Promise<void>;
357
+ /** since 以後にその人に触れた通知 */
358
+ pushTouches(input: {
359
+ project: string;
360
+ person_id: PersonId;
361
+ since: number;
362
+ }): Promise<PushTouch[]>;
363
+ }
364
+ export declare const NOTIFY_ADMIN_BINDING = "NOTIFY_ADMIN";
365
+ export declare const NOTIFY_ADMIN_ENTRYPOINT = "NotifyAdminRpc";
366
+ /**
367
+ * core の `NOTIFY_ADMIN` の型(appgrowstack-notify の NotifyAdminRpc)。文面の承認と施策の止める/再開と週の流れの結果。
368
+ * core が主体と権限(docs/access-control.md)とプロジェクトの有無を確かめてから呼ぶ。by は core が確かめた主体の id(usr_・agt_・sys:。AC-9)。
369
+ * 文面を live にしてよいかの決まりは notify の AppDefinition.review でなく、core の D1 の access_policy(notify は読むだけ)
370
+ */
371
+ export interface AppGrowStackNotifyAdminService {
372
+ listVariants(input: {
373
+ project: string;
374
+ campaign?: string;
375
+ status?: NotifyVariantStatus;
376
+ }): Promise<NotifyVariantList>;
377
+ getVariant(input: {
378
+ project: string;
379
+ variant_id: string;
380
+ }): Promise<NotifyVariant>;
381
+ approveVariant(input: {
382
+ project: string;
383
+ variant_id: string;
384
+ retire?: string;
385
+ by: string;
386
+ }): Promise<ApproveVariantResponse>;
387
+ rejectVariant(input: {
388
+ project: string;
389
+ variant_id: string;
390
+ by: string;
391
+ }): Promise<NotifyVariant>;
392
+ retireVariant(input: {
393
+ project: string;
394
+ variant_id: string;
395
+ by: string;
396
+ }): Promise<NotifyVariant>;
397
+ listCampaignStates(input: {
398
+ project: string;
399
+ }): Promise<NotifyCampaignStateList>;
400
+ setCampaignPaused(input: {
401
+ project: string;
402
+ campaign: string;
403
+ paused: boolean;
404
+ by: string;
405
+ }): Promise<NotifyCampaignState>;
406
+ listRuns(input: {
407
+ limit: number;
408
+ }): Promise<NotifyRunList>;
409
+ /** K2-8。その時刻にセグメントに入る人ごとに decide を書き込まずに回す */
410
+ preview(input: {
411
+ project: string;
412
+ campaign: string;
413
+ at: number;
414
+ }): Promise<NotifyPreview>;
415
+ /** K2-8。その人の施策ごとの入り・最後の配信・次の予定 */
416
+ explain(input: {
417
+ project: string;
418
+ person_id: PersonId;
419
+ }): Promise<NotifyExplain>;
420
+ /** KD-3。案ごとの配信の数 */
421
+ stats(input: {
422
+ project: string;
423
+ campaign: string;
424
+ days: number;
425
+ }): Promise<NotifyStats>;
426
+ /** R10。施策ごとの、自動で止める条件の数と当たった理由。止めるのは core(setCampaignPaused) */
427
+ guardrails(input: {
428
+ project: string;
429
+ }): Promise<NotifyGuardrailReport>;
430
+ /** CS4。その月(UTC の YYYY-MM)の notify の文面の AI の費用(マイクロドル)。core が自分の usage_ai に足して予算と比べる */
431
+ aiUsage(input: {
432
+ month: string;
433
+ }): Promise<{
434
+ month: string;
435
+ usd_micros: number;
436
+ }>;
437
+ /** CS4。core が月の合計から決めた、その月に notify の文面を AI に書かせないか。notify は予算を持たない */
438
+ setAiStop(input: {
439
+ month: string;
440
+ stop: boolean;
441
+ }): Promise<void>;
442
+ }
443
+ export declare const CREATIVE_ADMIN_BINDING = "CREATIVE_ADMIN";
444
+ export declare const CREATIVE_SERVICE = "appgrowstack-creative";
445
+ export declare const CREATIVE_ADMIN_ENTRYPOINT = "CreativeAdminRpc";
446
+ /** 撮影の組の一覧の絞り(?platform=&version=) */
447
+ export interface CaptureSetFilter {
448
+ platform?: Platform;
449
+ version?: string;
450
+ }
451
+ /** ストアの文字の1つの欄(製品 × OS × ページ × 言語 × 欄) */
452
+ export interface StoreTextSlot {
453
+ platform: Platform;
454
+ page: string;
455
+ locale: string;
456
+ field: StoreTextField;
457
+ }
458
+ /**
459
+ * core の `CREATIVE_ADMIN` の型(appgrowstack-creative の CreativeAdminRpc)。R12 ストアの素材の管理(docs/design/creatives.md 15節)。
460
+ * core が主体と権限とプロジェクトの有無を確かめてから呼ぶ。by は core が確かめた主体の id(usr_・agt_・sys:)。
461
+ * 誤りは AppGrowStackRpcError の code(not_found・conflict・not_implemented)で投げ、core が 404・409・501 にする。
462
+ * creative は core を呼ばず、core の D1 は CORE_DB で読むだけ(ADR 0027)
463
+ */
464
+ export interface AppGrowStackCreativeAdminService {
465
+ createCaptureSet(input: {
466
+ project: string;
467
+ request: CreateCaptureSetRequest;
468
+ by: string;
469
+ }): Promise<CreateCaptureSetResult>;
470
+ completeCaptureSet(input: {
471
+ project: string;
472
+ set: string;
473
+ by: string;
474
+ }): Promise<CaptureSet>;
475
+ /**
476
+ * PUT …/captures/:set/files/:locale/:device/:screen/:kind。core が本文を読まずに流したまま渡す。bytes は Content-Length。
477
+ * creative は組を作った時の sha256 を R2 の put に渡し、R2 が中身と照らす(違えば capture_mismatch)。組が uploading でなければ conflict、組に無いファイルは not_found
478
+ */
479
+ putCaptureFile(input: {
480
+ project: string;
481
+ set: string;
482
+ file: CaptureFile;
483
+ content_type: string;
484
+ bytes: number;
485
+ body: ReadableStream<Uint8Array>;
486
+ by: string;
487
+ }): Promise<void>;
488
+ listCaptureSets(input: {
489
+ project: string;
490
+ } & CaptureSetFilter): Promise<CaptureSetList>;
491
+ /** GET …/captures/:set/files/:locale/:device/:screen/:kind。組に無いファイル・まだ R2 に無いファイルは not_found */
492
+ getCaptureFile(input: {
493
+ project: string;
494
+ set: string;
495
+ file: CaptureFile;
496
+ }): Promise<{
497
+ content_type: string;
498
+ bytes: number;
499
+ body: ReadableStream<Uint8Array>;
500
+ }>;
501
+ getBrand(input: {
502
+ project: string;
503
+ }): Promise<CreativeBrand>;
504
+ putBrand(input: {
505
+ project: string;
506
+ body: CreativeBrandBody;
507
+ by: string;
508
+ }): Promise<CreativeBrand>;
509
+ createAssetUpload(input: {
510
+ project: string;
511
+ request: CreateCreativeAssetUploadRequest;
512
+ by: string;
513
+ }): Promise<CreativeAssetUpload>;
514
+ /**
515
+ * PUT …/assets/:asset。core が本文を読まずに流したまま渡す。bytes は Content-Length。
516
+ * creative は createAssetUpload の sha256 を R2 の put に渡し、R2 が中身と照らす(違えば capture_mismatch)。素材が無ければ not_found
517
+ */
518
+ putAssetFile(input: {
519
+ project: string;
520
+ asset: string;
521
+ content_type: string;
522
+ bytes: number;
523
+ body: ReadableStream<Uint8Array>;
524
+ by: string;
525
+ }): Promise<void>;
526
+ /** R2 のキーごとに新しい行だけ。種類 → 名前の順 */
527
+ listAssets(input: {
528
+ project: string;
529
+ }): Promise<CreativeAssetList>;
530
+ /** 同じキーの新しい素材に置き換わった物・まだ R2 に無い物は not_found */
531
+ getAssetFile(input: {
532
+ project: string;
533
+ asset: string;
534
+ }): Promise<{
535
+ content_type: string;
536
+ bytes: number;
537
+ body: ReadableStream<Uint8Array>;
538
+ }>;
539
+ listPages(input: {
540
+ project: string;
541
+ }): Promise<CreativePageList>;
542
+ putPage(input: {
543
+ project: string;
544
+ platform: Platform;
545
+ page: string;
546
+ request: PutCreativePageRequest;
547
+ by: string;
548
+ }): Promise<CreativePage>;
549
+ listStoreTexts(input: {
550
+ project: string;
551
+ platform?: Platform;
552
+ page?: string;
553
+ locale?: string;
554
+ field?: StoreTextField;
555
+ status?: StoreTextStatus;
556
+ }): Promise<StoreTextList>;
557
+ getStoreTextHistory(input: {
558
+ project: string;
559
+ } & StoreTextSlot): Promise<StoreTextList>;
560
+ proposeStoreText(input: {
561
+ project: string;
562
+ request: ProposeStoreTextRequest;
563
+ by: string;
564
+ } & StoreTextSlot): Promise<StoreText>;
565
+ approveStoreText(input: {
566
+ project: string;
567
+ revision: string;
568
+ by: string;
569
+ }): Promise<StoreText>;
570
+ rejectStoreText(input: {
571
+ project: string;
572
+ revision: string;
573
+ by: string;
574
+ }): Promise<StoreText>;
575
+ generateVariant(input: {
576
+ project: string;
577
+ request: GenerateCreativeVariantRequest;
578
+ by: string;
579
+ }): Promise<CreativeRun>;
580
+ listVariants(input: {
581
+ project: string;
582
+ platform?: Platform;
583
+ page?: string;
584
+ surface?: CreativeSurface;
585
+ status?: CreativeVariantStatus;
586
+ }): Promise<CreativeVariantList>;
587
+ getVariant(input: {
588
+ project: string;
589
+ variant: string;
590
+ }): Promise<CreativeVariant>;
591
+ /** 本人が採る。proposed でなければ conflict */
592
+ acceptVariant(input: {
593
+ project: string;
594
+ variant: string;
595
+ by: string;
596
+ }): Promise<CreativeVariant>;
597
+ /** 本人が断る。proposed でなければ conflict */
598
+ rejectVariant(input: {
599
+ project: string;
600
+ variant: string;
601
+ reason?: string;
602
+ by: string;
603
+ }): Promise<CreativeVariant>;
604
+ /** AI か作った人が取り下げる。generating・proposed でなければ conflict */
605
+ withdrawVariant(input: {
606
+ project: string;
607
+ variant: string;
608
+ reason: string;
609
+ by: string;
610
+ }): Promise<CreativeVariant>;
611
+ submitCreatives(input: {
612
+ project: string;
613
+ request: SubmitCreativesRequest;
614
+ by: string;
615
+ }): Promise<SubmitCreativesResult>;
616
+ registerTest(input: {
617
+ project: string;
618
+ test: string;
619
+ request: RegisterCreativeTestRequest;
620
+ by: string;
621
+ }): Promise<CreativeTest>;
622
+ stopTest(input: {
623
+ project: string;
624
+ test: string;
625
+ by: string;
626
+ }): Promise<CreativeTest>;
627
+ listTests(input: {
628
+ project: string;
629
+ status?: CreativeTestStatus;
630
+ }): Promise<CreativeTestList>;
631
+ getTest(input: {
632
+ project: string;
633
+ test: string;
634
+ }): Promise<CreativeTestDetail>;
635
+ listCreativeMetrics(input: {
636
+ project: string;
637
+ page?: string;
638
+ variant?: string;
639
+ since?: string;
640
+ country?: string;
641
+ source?: string;
642
+ }): Promise<CreativeMetricList>;
643
+ /** 全部の製品をまとめた値。製品の数は含まない */
644
+ getTagEffects(input: {
645
+ snapshot?: string;
646
+ }): Promise<TagEffectSnapshot>;
647
+ listKeywords(input: {
648
+ project: string;
649
+ country?: string;
650
+ week?: string;
651
+ }): Promise<CreativeKeywordList>;
652
+ syncKeywords(input: {
653
+ project: string;
654
+ by: string;
655
+ }): Promise<CreativeKeywordSyncResult>;
656
+ listSteps(input: {
657
+ project: string;
658
+ status?: "waiting" | "done" | "canceled";
659
+ }): Promise<CreativeStepList>;
660
+ completeStep(input: {
661
+ project: string;
662
+ step: string;
663
+ request: CompleteCreativeStepRequest;
664
+ by: string;
665
+ }): Promise<CreativeStep>;
666
+ /** projects は core が呼び手の組織と creatives.run で絞った物 */
667
+ runCreativeWeekly(input: {
668
+ projects: string[];
669
+ by: string;
670
+ }): Promise<CreativeRun>;
671
+ /** projects は core が呼び手の組織と creatives.read で絞った物。summary もその分だけ */
672
+ listCreativeRuns(input: {
673
+ limit: number;
674
+ projects: string[];
675
+ }): Promise<CreativeRunList>;
676
+ /** その月(UTC の YYYY-MM)の creative の AI の費用(マイクロドル)。予算は creative の分を core が別に持つ(docs/design/creatives.md 13.7節) */
677
+ aiUsage(input: {
678
+ month: string;
679
+ }): Promise<{
680
+ month: string;
681
+ usd_micros: number;
682
+ }>;
683
+ /** core が月の合計から決めた、その月に止める生成。weekly は週の流れの生成、all は手で依頼した生成も */
684
+ setAiStop(input: {
685
+ month: string;
686
+ stop: "none" | "weekly" | "all";
687
+ }): Promise<void>;
688
+ /**
689
+ * 参考の素材(docs/design/creatives.md 15節)。projects は core が呼び手の組織と権限で絞った物。project の無い参考の素材は誰にも見える。projects に無い製品の物は not_found。
690
+ * つなぐ仮説は仮説の記録(INSIGHTS.ledgerGet・ledgerLink)にあり、無い仮説は input。
691
+ * URL は creative が読み、読めなければ fetch_failed、Web のページを撮るキーが無ければ browser_unavailable
692
+ */
693
+ createReference(input: {
694
+ projects: string[];
695
+ request: CreateReferenceRequest;
696
+ by: string;
697
+ }): Promise<CreateReferenceResult>;
698
+ /** PUT …/references/:reference/files/:sha256。core が本文を読まずに流したまま渡す。中身が sha256 と合わなければ reference_mismatch。もう R2 にあれば読まずに捨てる */
699
+ putReferenceFile(input: {
700
+ projects: string[];
701
+ reference: string;
702
+ sha256: string;
703
+ content_type: string;
704
+ bytes: number;
705
+ body: ReadableStream<Uint8Array>;
706
+ by: string;
707
+ }): Promise<void>;
708
+ completeReference(input: {
709
+ projects: string[];
710
+ reference: string;
711
+ by: string;
712
+ }): Promise<CreativeReference>;
713
+ listReferences(input: {
714
+ projects: string[];
715
+ project?: string;
716
+ subject?: string;
717
+ tag?: string;
718
+ source?: CreativeReferenceSource;
719
+ origin?: CreativeReferenceOrigin;
720
+ since?: string;
721
+ q?: string;
722
+ cursor?: string;
723
+ }): Promise<CreativeReferenceList>;
724
+ getReference(input: {
725
+ projects: string[];
726
+ reference: string;
727
+ }): Promise<CreativeReference>;
728
+ getReferenceFile(input: {
729
+ projects: string[];
730
+ reference: string;
731
+ sha256: string;
732
+ }): Promise<{
733
+ content_type: string;
734
+ bytes: number;
735
+ body: ReadableStream<Uint8Array>;
736
+ }>;
737
+ updateReference(input: {
738
+ projects: string[];
739
+ reference: string;
740
+ request: UpdateReferenceRequest;
741
+ by: string;
742
+ }): Promise<CreativeReference>;
743
+ }
744
+ export declare const INSIGHTS_BINDING = "INSIGHTS";
745
+ export declare const INSIGHTS_SERVICE = "appgrowstack-insights";
746
+ export declare const INSIGHTS_ENTRYPOINT = "InsightsRpc";
747
+ /**
748
+ * core・notify・creative の `INSIGHTS` の型(appgrowstack-insights の InsightsRpc)。R13 分析(docs/design/insights.md 4.2節・10.2節)。
749
+ * insights はどの Worker も呼ばない。by は呼び手が決めた主体の id(sys:notify-weekly・sys:creatives-weekly・core が確かめた usr_・agt_)。
750
+ * 誤りは AppGrowStackRpcError の code(input・not_found・conflict・not_implemented)で投げる
751
+ */
752
+ export interface AppGrowStackInsightsService {
753
+ /** 人の id ごとの person_key。無ければ作る(core が track と subscription を受けた時に1回にまとめて呼ぶ)。返す物は person_ids と同じ並び */
754
+ personKeys(input: {
755
+ project: string;
756
+ person_ids: PersonId[];
757
+ }): Promise<PersonKey[]>;
758
+ /** 仮説を足す。creative と notify の週の流れの仮説は proposed で、source は agent */
759
+ ledgerPut(input: {
760
+ hypothesis: LedgerHypothesisInput;
761
+ source: LedgerSource;
762
+ by: string;
763
+ }): Promise<LedgerHypothesis>;
764
+ /** 学んだことを1行足す(追記だけ) */
765
+ ledgerLearn(input: {
766
+ learning: LedgerLearningInput;
767
+ source: LedgerLearningSource;
768
+ by: string;
769
+ }): Promise<LedgerLearning>;
770
+ /** 実験の答えから数の決まりで決めた outcome と写した数を書き、concluded にする。testing でない仮説は conflict。outcome が ledgerOutcome(result) と違えば input */
771
+ ledgerConclude(input: {
772
+ conclusion: LedgerConclusionInput;
773
+ by: string;
774
+ }): Promise<LedgerHypothesis>;
775
+ /** 仮説を1つ引く。無ければ null。creative と notify は案・実験・参考の素材の仮説の id をこれで確かめる(製品が合うかは呼び手が見る) */
776
+ ledgerGet(input: {
777
+ hypothesis: string;
778
+ }): Promise<LedgerHypothesis | null>;
779
+ /** 仮説につながる物を足す(あれば何もしない)。仮説が無ければ not_found */
780
+ ledgerLink(input: {
781
+ hypothesis: string;
782
+ links: LedgerLink[];
783
+ by: string;
784
+ }): Promise<void>;
785
+ /** つながる物の id から仮説の id を引く。返す物は ref ごとに、つないだ古い順 */
786
+ ledgerLinked(input: {
787
+ kind: LedgerLinkKind;
788
+ refs: string[];
789
+ }): Promise<{
790
+ ref: string;
791
+ hypothesis: string;
792
+ }[]>;
793
+ /** 検索の索引に、仮説の記録の外の物(R12 の参考の素材のメモとタグ)を入れ直す。body が空なら外す */
794
+ ledgerIndex(input: {
795
+ kind: "reference";
796
+ ref: string;
797
+ project: string | null;
798
+ body: string;
799
+ }): Promise<void>;
800
+ /** 新しい順の学んだこと。製品をまたいで読む(R5 の週の改善が AI に渡す) */
801
+ ledgerLearnings(input: {
802
+ limit: number;
803
+ surface?: LedgerSurface;
804
+ }): Promise<LedgerLearning[]>;
805
+ }
806
+ export declare const INSIGHTS_ADMIN_BINDING = "INSIGHTS_ADMIN";
807
+ export declare const INSIGHTS_ADMIN_ENTRYPOINT = "InsightsAdminRpc";
808
+ /** 指標の読みの絞り(?from=&to=&dims=&audience=) */
809
+ export interface InsightsMetricQuery {
810
+ project: string;
811
+ metric: string;
812
+ from?: string;
813
+ to?: string;
814
+ dims?: string[];
815
+ /** 無ければ real だけ */
816
+ audience?: Audience[];
817
+ }
818
+ /**
819
+ * core の `INSIGHTS_ADMIN` の型(appgrowstack-insights の InsightsAdminRpc)。R13 分析の読み取りと決定(docs/design/insights.md 13節)。
820
+ * core が主体と権限とプロジェクトの有無を確かめてから呼ぶ。projects は core が呼び手の組織と権限で絞った物。by は core が確かめた主体の id。
821
+ * メソッドの名前は core の管理のパスの名前(coreEndpoints)と同じ。誤りは AppGrowStackRpcError の code(input・not_found・conflict・sql_refused・scan_limit・not_implemented)
822
+ */
823
+ export interface AppGrowStackInsightsAdminService {
824
+ getInsightsMetric(input: InsightsMetricQuery & {
825
+ by: string;
826
+ }): Promise<InsightsMetricAnswer>;
827
+ compareInsightsMetric(input: {
828
+ project: string;
829
+ metric: string;
830
+ at: string;
831
+ weeks: number;
832
+ by: string;
833
+ }): Promise<InsightsMetricCompare>;
834
+ /** projects は insights.sql で見える物。SQL の中の project がこの外なら sql_refused */
835
+ runInsightsSql(input: {
836
+ request: InsightsSqlRequest;
837
+ projects: string[];
838
+ by: string;
839
+ }): Promise<InsightsSqlResult>;
840
+ listInsightsSignals(input: {
841
+ projects: string[];
842
+ kind?: InsightsSignalKind;
843
+ since?: string;
844
+ }): Promise<InsightsSignalList>;
845
+ listInsightsFindings(input: {
846
+ projects: string[];
847
+ status?: InsightsFindingStatus;
848
+ since?: string;
849
+ }): Promise<InsightsFindingList>;
850
+ /** projects の外の指摘は not_found */
851
+ getInsightsFinding(input: {
852
+ finding: string;
853
+ projects: string[];
854
+ }): Promise<InsightsFindingDetail>;
855
+ decideInsightsFinding(input: {
856
+ finding: string;
857
+ projects: string[];
858
+ request: InsightsFindingDecision;
859
+ by: string;
860
+ }): Promise<InsightsFinding>;
861
+ getInsightsPortfolio(input: {
862
+ projects: string[];
863
+ week?: string;
864
+ }): Promise<PortfolioReport>;
865
+ getCompetitors(input: {
866
+ project: string;
867
+ }): Promise<CompetitorReport>;
868
+ collectInsights(input: {
869
+ request: InsightsCollectRequest;
870
+ projects: string[];
871
+ by: string;
872
+ }): Promise<InsightsCollectResult>;
873
+ listLedgerHypotheses(input: {
874
+ projects: string[];
875
+ surface?: LedgerSurface;
876
+ status?: LedgerHypothesisStatus;
877
+ outcome?: LedgerOutcome;
878
+ }): Promise<LedgerHypothesisList>;
879
+ addLedgerHypothesis(input: {
880
+ request: LedgerHypothesisInput;
881
+ projects: string[];
882
+ by: string;
883
+ }): Promise<LedgerHypothesis>;
884
+ getLedgerHypothesis(input: {
885
+ hypothesis: string;
886
+ projects: string[];
887
+ }): Promise<LedgerHypothesisDetail>;
888
+ updateLedgerHypothesis(input: {
889
+ hypothesis: string;
890
+ request: LedgerHypothesisUpdate;
891
+ projects: string[];
892
+ by: string;
893
+ }): Promise<LedgerHypothesis>;
894
+ markLedgerApplied(input: {
895
+ hypothesis: string;
896
+ request: LedgerAppliedRequest;
897
+ projects: string[];
898
+ by: string;
899
+ }): Promise<LedgerHypothesis>;
900
+ listLedgerLearnings(input: {
901
+ projects: string[];
902
+ surface?: LedgerSurface;
903
+ since?: string;
904
+ }): Promise<LedgerLearningList>;
905
+ addLedgerLearning(input: {
906
+ request: LedgerLearningInput;
907
+ projects: string[];
908
+ by: string;
909
+ }): Promise<LedgerLearning>;
910
+ searchLedger(input: {
911
+ q: string;
912
+ projects: string[];
913
+ surface?: LedgerSurface;
914
+ kind?: "hypothesis" | "learning" | "reference";
915
+ limit: number;
916
+ }): Promise<LedgerSearchResult>;
917
+ /** その月(UTC の YYYY-MM)の insights の AI の費用(マイクロドル)。予算は core が insights の分を別に持つ(14節) */
918
+ aiUsage(input: {
919
+ month: string;
920
+ }): Promise<{
921
+ month: string;
922
+ usd_micros: number;
923
+ }>;
924
+ /** アカウントの削除。insights_person_key の対応の行を消す。データレイクの行は残るが、人をたどれなくなる(4.2節) */
925
+ forget(input: {
926
+ project: string;
927
+ person_id: PersonId;
928
+ }): Promise<void>;
929
+ }